From 1f07d67746a000cd0ca42ce55c07a363945e259f Mon Sep 17 00:00:00 2001 From: Chandrasekaran Akash Date: Wed, 26 Mar 2025 05:04:21 +0800 Subject: [PATCH 1/3] fix(bar): animate bars from 'bottom' --- src/chart/bar/BarView.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/chart/bar/BarView.ts b/src/chart/bar/BarView.ts index a34cc153a0..c3209e1fbe 100644 --- a/src/chart/bar/BarView.ts +++ b/src/chart/bar/BarView.ts @@ -783,9 +783,18 @@ const elementCreator: { rect.name = 'item'; if (animationModel) { + const isStacked = seriesModel.get('stack') !== undefined; 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' + const stackAnimateProperty = isHorizontal ? 'y' : 'x' as 'y' | 'x'; + const coordSys = (seriesModel.coordinateSystem as Cartesian2D); + const extent = coordSys.getOtherAxis(coordSys.getBaseAxis()).getGlobalExtent()[0]; + rectShape[stackAnimateProperty] = extent; + } } return rect; }, From 444c75dbf0d9e43635580d307a6c6b5e3da88701 Mon Sep 17 00:00:00 2001 From: Chandrasekaran Akash Date: Sat, 29 Mar 2025 00:37:18 +0800 Subject: [PATCH 2/3] fix(bar): start animation from valueAxisStart --- src/chart/bar/BarView.ts | 11 ++++++----- src/layout/barGrid.ts | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/chart/bar/BarView.ts b/src/chart/bar/BarView.ts index c3209e1fbe..5a6e17ee1b 100644 --- a/src/chart/bar/BarView.ts +++ b/src/chart/bar/BarView.ts @@ -783,17 +783,18 @@ const elementCreator: { rect.name = 'item'; if (animationModel) { - const isStacked = seriesModel.get('stack') !== undefined; + const isStacked = seriesModel.get('stack') != null; 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' + // 'bottom' of the value axis, regardless of 'inverse' const stackAnimateProperty = isHorizontal ? 'y' : 'x' as 'y' | 'x'; - const coordSys = (seriesModel.coordinateSystem as Cartesian2D); - const extent = coordSys.getOtherAxis(coordSys.getBaseAxis()).getGlobalExtent()[0]; - rectShape[stackAnimateProperty] = extent; + const itemLayout = data.getItemLayout(newIndex); + // valueAxisStart is unset only when `large` is true, + // in which case this branch is not taken + rectShape[stackAnimateProperty] = itemLayout.valueAxisStart; } } return rect; diff --git a/src/layout/barGrid.ts b/src/layout/barGrid.ts index 3f6aeb4fb6..b478b487bd 100644 --- a/src/layout/barGrid.ts +++ b/src/layout/barGrid.ts @@ -559,7 +559,7 @@ export function createProgressiveLayout(seriesType: string): StageHandler { } if (!isLarge) { - data.setItemLayout(dataIndex, { x, y, width, height }); + data.setItemLayout(dataIndex, { x, y, width, height, valueAxisStart }); } else { largePoints[idxOffset] = x; From 26faaa42f1088271056af0ad554e80d368598a2b Mon Sep 17 00:00:00 2001 From: Chandrasekaran Akash Date: Sun, 30 Mar 2025 02:41:01 +0800 Subject: [PATCH 3/3] feat(bar): add stack bar anim test, fit to grid --- src/chart/bar/BarView.ts | 11 +- test/bar-cartesian-stack-anim.html | 457 +++++++++++++++++++++++++++++ 2 files changed, 467 insertions(+), 1 deletion(-) create mode 100644 test/bar-cartesian-stack-anim.html diff --git a/src/chart/bar/BarView.ts b/src/chart/bar/BarView.ts index 5a6e17ee1b..c7c65225a9 100644 --- a/src/chart/bar/BarView.ts +++ b/src/chart/bar/BarView.ts @@ -794,7 +794,16 @@ const elementCreator: { const itemLayout = data.getItemLayout(newIndex); // valueAxisStart is unset only when `large` is true, // in which case this branch is not taken - rectShape[stackAnimateProperty] = itemLayout.valueAxisStart; + const valueAxisStart = itemLayout.valueAxisStart; + + // make sure we don't go beyond the grid + const coordSys = (seriesModel.coordinateSystem as Cartesian2D); + const valueAxis = coordSys.getOtherAxis(coordSys.getBaseAxis()); + const extentStart = valueAxis.getGlobalExtent()[0]; + // compare with extentStart in the same direction as the stackAnimateProperty + const cmpFn = (valueAxis.inverse === isHorizontal) ? mathMax : mathMin; + + rectShape[stackAnimateProperty] = cmpFn(valueAxisStart, extentStart); } } return rect; diff --git a/test/bar-cartesian-stack-anim.html b/test/bar-cartesian-stack-anim.html new file mode 100644 index 0000000000..c512cd8cfc --- /dev/null +++ b/test/bar-cartesian-stack-anim.html @@ -0,0 +1,457 @@ + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +