adityajai119 opened a new pull request, #21831:
URL: https://github.com/apache/echarts/pull/21831
<!-- Please fill in the following information to help us review your PR more
efficiently. -->
## Brief Information
This pull request is in the type of:
- [x] bug fixing
- [ ] new feature
- [ ] others
### What does this PR do?
Makes a stacked bar start at the end of the bar it is stacked on when that
bar is raised by `barMinHeight`, so the two bars no longer overlap.
### Fixed issues
- #20480: In a stacked bar chart, a bar raised by `barMinHeight` overlaps
the bar stacked on it (regression since 5.3.0)
## Details
### Before: What was the problem?
Since 5.3.0, the cartesian bar layout places a stacked bar at the coordinate
of the value it is stacked over (the stack result minus its own value).
`barMinHeight` only changes the size of the small bar itself, so the next bar
in the stack still starts at the data coordinate and overlaps the raised bar.
Before 5.3.0 the layout accumulated the pixel end of each stack
(`lastStackCoords`), so the extra height was passed on. That accumulation was
removed in 20eaa3d56e ("fix(bar): merge logic of layout large and normal
bars"). Polar bars still accumulate pixels and are not affected.
### After: How does it behave after the fixing?
A stacked bar is shifted by the extra height that `barMinHeight` added to
the bars below it, so it starts where the bar it is stacked on ends. Its own
size is unchanged, and the shift carries up through all bars above. When no bar
below has `barMinHeight`, the layout is computed exactly as before.
How the bar below is found: the layout uses the same rule as the stack
calculation in `processor/dataStack.ts`. I moved the strategy check there into
one function and added `findStackedOnItem`, which walks down the
`stackedOnSeries` chain and returns the first item that the stack calculation
stacked the current item on:
- `samesign`: the nearest lower item whose stacked value has the same sign
as the current value.
- `all`: the nearest lower item whose stacked value is not empty.
- `positive` / `negative`: the nearest lower item whose stacked value is
positive / negative.
Items are matched by raw index or by the `stackedBy` dimension value, as in
the stack calculation. The extra height of each bar found this way is computed
from its own data and axis, not from its rendered layout, so the result does
not depend on the order in which the series are laid out (for example with
`stackOrder: 'seriesDesc'`). The walk stops at a series that is not a cartesian
bar (such as a line in the same stack), because that series is drawn at its
data position.
If you prefer another approach, for example recording the matched item
during the stack calculation instead of finding it again in the layout, I'm
happy to change it.
## Document Info
One of the following should be checked.
- [x] This PR doesn't relate to document changes
- [ ] The document should be updated later
- [ ] The document changes have been made in apache/echarts-doc#xxx
## Misc
### Security Checking
- [ ] This PR uses security-sensitive Web APIs.
### ZRender Changes
- [ ] This PR depends on ZRender changes (ecomfe/zrender#xxx).
### Related test cases or examples to use the new APIs
Added `test/ut/spec/series/barStackMinHeight.test.ts`. It reads the laid-out
bar rectangles of a vertical bar chart (category x axis) and a horizontal bar
chart and checks that:
- the bar stacked on a bar raised by `barMinHeight` starts at its end and
keeps its own size, for `stackStrategy` `samesign`, `all`, `positive` and
`negative`, with positive and negative values;
- the shift carries up through a third bar, and works with `stackOrder:
'seriesDesc'`;
- a bar that is not stacked on the raised bar is not moved;
- stacked bars without `barMinHeight`, or with a `barMinHeight` that does
not apply, keep their data coordinates.
12 of the 16 tests fail on `release` without this change; the "not moved"
and "keeps the layout" tests pass on both.
Ran locally on this branch: the full unit suite (`npx jest --config
test/ut/jest.config.cjs`, 34 suites / 242 tests pass), `eslint` on the changed
files, and `tsc --noEmit` (passes with the repo's own `@types`; on this machine
the unrestricted run only fails on an unrelated `@types/mdx` package outside
the repo, the same as on `release`). `npm run lint` reports 6 errors in
`extension-src/bmap/BMapCoordSys.ts`, the same as on `release` without this
change.
### Merging options
- [ ] Please squash the commits into a single one when merging.
### Other information
This targets `release`, where the recent stacked bar fixes (#21702, #21697)
were merged. The change touches the same layout code as #21811, which leaves
the `barMinHeight` layout unchanged.
AI-assisted: drafted with an AI coding agent (see the `Generated-by`
trailer, per the ASF generative tooling guidance); the tests above were run
locally.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]