Skip to content

Commit

Permalink
fix: 修复数据为 0 时动画更新出错 (#3378)
Browse files Browse the repository at this point in the history
* fix: 修复动画更新位置计算出错

* fix: 删除 log 信息

Co-authored-by: liufu.lf <liufu.lf@antfin.com>
  • Loading branch information
lxfu1 and liufu.lf authored Apr 16, 2021
1 parent 2d1ef8d commit e132a30
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/animate/animation/sector-path-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ export function sectorPathUpdate(shape: IShape, animateCfg: GAnimateCfg, cfg: An
const center = coordinate.getCenter();
const diffStartAngle = curStartAngle - preStartAngle;
const diffEndAngle = curEndAngle - preEndAngle;
// 没有 diff 时直接返回最终 attrs,不需要额外动画
if (diffStartAngle === 0 && diffEndAngle === 0) {
shape.attr('path', path);
return;
}

shape.animate(
(ratio) => {
Expand Down
39 changes: 39 additions & 0 deletions tests/bugs/charts-574-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Chart } from '../../src';
import { createDiv } from '../util/dom';

describe('574', () => {
it('574', () => {
const data = [
{ type: '一线城市', value: 20 },
{ type: '二线城市', value: 0 },
{ type: '三线城市', value: 10 },
];
const chart = new Chart({
container: createDiv(),
width: 600,
height: 300,
autoFit: true,
});
chart.data(data);

chart.coordinate('theta', {
radius: 0.75,
});

chart.interval().adjust('stack').position('value').color('type', ['blue', 'green', 'yellow']);
chart.render();
const fn = jest.fn();
chart.geometries[0].elements[2].shape.animate = fn;
chart.changeData([
{ type: '一线城市', value: 20 },
{ type: '三线城市', value: 10 },
]);
expect(fn).not.toBeCalled();
chart.changeData([
{ type: '一线城市', value: 20 },
{ type: '三线城市', value: 15 },
]);
expect(fn).toBeCalled();
chart.destroy();
});
});

0 comments on commit e132a30

Please sign in to comment.