-
Notifications
You must be signed in to change notification settings - Fork 19.7k
Animate stacked bars in Bar Series from the 'bottom' #20862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Thanks for your contribution! |
The changes brought by this PR can be previewed at: https://echarts.apache.org/examples/editor?version=PR-20862@26faaa4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a bug with stacked bar chart animations by ensuring that bars animate from the bottom of the value axis regardless of the Cartesian2D axis configuration.
- Introduces a check for whether the series is stacked and adjusts the animated property accordingly.
- Sets the initial coordinate for stacked bars to the lower bound of the related axis.
Comments suppressed due to low confidence (1)
src/chart/bar/BarView.ts:790
- Consider adding tests to verify the animation behavior for stacked bars, especially in scenarios involving inverse axes.
if (isStacked) {
src/chart/bar/BarView.ts
Outdated
const rectShape = rect.shape; | ||
const animateProperty = isHorizontal ? 'height' : 'width' as 'width' | 'height'; | ||
rectShape[animateProperty] = 0; | ||
if (isStacked) { | ||
// if it's stacked, the bar will be animated from the | ||
// 'bottom' of the value axis, irregardless of 'inverse' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Replace 'irregardless' with 'regardless' for clarity and formal tone.
// 'bottom' of the value axis, irregardless of 'inverse' | |
// 'bottom' of the value axis, regardless of 'inverse' |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in 444c75d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a nice feature to have! Thanks for your contribution.
Please add test cases for this PR and it would be nice if polar bars can also support this feature.
src/chart/bar/BarView.ts
Outdated
// 'bottom' of the value axis, irregardless of 'inverse' | ||
const stackAnimateProperty = isHorizontal ? 'y' : 'x' as 'y' | 'x'; | ||
const coordSys = (seriesModel.coordinateSystem as Cartesian2D); | ||
const extent = coordSys.getOtherAxis(coordSys.getBaseAxis()).getGlobalExtent()[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extent[0]
is the minimum value of the axis, which may not be expected to be the starting point of bar growing in the case with negative axes. Consider using startValue instead. Make sure you test the cases in varied value ranges.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep seems like you are correct, for test/bar-stack.html
I edited the yAxis to have a startValue: -30
and min: -100
and it animates from the bottom (first 2s):
nani.mp4
The other half of the video describes a bug (not sure): the right most bar stack in that video isn't placed correctly (not respecting startValue
). And by toggling the 'bottom'-most series of the stacked bar chart, the problem fixes itself. I can raise this in a issue if this is confirmed to be a bug.
I'll fix the startValue issue in a bit;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in 444c75d - but will add tests in another commit
src/chart/bar/BarView.ts
Outdated
@@ -783,9 +783,18 @@ const elementCreator: { | |||
rect.name = 'item'; | |||
|
|||
if (animationModel) { | |||
const isStacked = seriesModel.get('stack') !== undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!= null
should be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in 444c75d
Hmm, might need some help with this PR. Seems like Series add (e.g. toggling from chart legend) triggers the animation, which makes it look very awkward. But currently there is no way to differentiate this from the initial renders' Series add |
Yes, the problem happens if we create 3 series ABC and hide the middle one B and then show it from legend.
I don't think is an issue related to legend logic. What happens when we click the legend item to show B is that, series A and C calls So I guess when in But I'm not sure if this should work. Be careful to have a complete visual test with Bar series, taking special care for bar-race situations. And I should also think about whether this change may break other cases or bring performance issues. Let's see later after you come up with more ideas. |
Brief Information
This pull request is in the type of:
What does this PR do?
Fixes gaps in animation in stacked bar charts. Works irregardless of horizontal/vertical cartesian axis, inverse axis.
Fixed issues
Fixes #19095
Details
Before: What was the problem?
Stacked bar chart animations are strange in ECharts since only the value axis value (height for horizontal base axis, else width) is animated for Cartesian2D. So the animations have a weird effect where the stacked bars are hovering in the air with gaps before the animation completes.
before.mp4
After: How does it behave after the fixing?
after.mp4
Document Info
One of the following should be checked.
Misc
ZRender Changes
Related test cases or examples to use the new APIs
N.A.
Others
Merging options
Other information