From 9b73ec3665ef00a19910dc0ab1f5a466b608b28e Mon Sep 17 00:00:00 2001 From: xiaoluoHe Date: Fri, 14 Mar 2025 14:09:15 +0800 Subject: [PATCH] fix: fix the issue where the bar chart grow animation does not work correctly when the axis `zero: false`, #3808 --- ...-bar-appear-growFrom_2025-03-14-06-09.json | 10 ++++++++++ packages/vchart/src/series/bar/bar.ts | 20 +++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 common/changes/@visactor/vchart/fix-bar-appear-growFrom_2025-03-14-06-09.json diff --git a/common/changes/@visactor/vchart/fix-bar-appear-growFrom_2025-03-14-06-09.json b/common/changes/@visactor/vchart/fix-bar-appear-growFrom_2025-03-14-06-09.json new file mode 100644 index 0000000000..953a52c7ea --- /dev/null +++ b/common/changes/@visactor/vchart/fix-bar-appear-growFrom_2025-03-14-06-09.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@visactor/vchart", + "comment": "fix: fix the issue where the bar chart grow animation does not work correctly when the axis `zero: false`, #3808", + "type": "none" + } + ], + "packageName": "@visactor/vchart" +} \ No newline at end of file diff --git a/packages/vchart/src/series/bar/bar.ts b/packages/vchart/src/series/bar/bar.ts index b8861164c5..e0b082d6f5 100644 --- a/packages/vchart/src/series/bar/bar.ts +++ b/packages/vchart/src/series/bar/bar.ts @@ -42,6 +42,7 @@ import { ComponentTypeEnum } from '../../component/interface'; import { RECT_X, RECT_X1, RECT_Y, RECT_Y1 } from '../base/constant'; import { createRect } from '@visactor/vrender-core'; import { registerCartesianLinearAxis, registerCartesianBandAxis } from '../../component/axis/cartesian'; +import { maxInArr, minInArr } from '../../util/array'; export const DefaultBandWidth = 6; // 默认的bandWidth,避免连续轴没有bandWidth @@ -678,10 +679,21 @@ export class BarSeries extends Cartes yField: this._fieldY[0], xField: this._fieldX[0], direction: this.direction, - growFrom: () => - this.direction === 'horizontal' - ? this._xAxisHelper?.getScale(0).scale(0) - : this._yAxisHelper?.getScale(0).scale(0) + growFrom: () => { + const scale = this.direction === 'horizontal' ? this._xAxisHelper?.getScale(0) : this._yAxisHelper.getScale(0); + if (scale) { + const domain = scale.domain(); + const domainMin = minInArr(domain); + const domainMax = maxInArr(domain); + if (domainMax < 0) { + return scale.scale(domainMax); + } else if (domainMin > 0) { + return scale.scale(domainMin); + } else { + return scale.scale(0); + } + } + } }; const appearPreset = (this._spec.animationAppear as IStateAnimateSpec)?.preset; const animationParams = getGroupAnimationParams(this);