From c02f0ec2d1fd6ea8281367acfddf50f578fe20a0 Mon Sep 17 00:00:00 2001 From: simaQ Date: Thu, 17 Oct 2019 10:30:29 +0800 Subject: [PATCH] feat: add view.animate() --- src/chart/view.ts | 15 ++++++++++++++- tests/unit/chart/view/index-spec.ts | 10 ++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/chart/view.ts b/src/chart/view.ts index 440ae77151..fb31e2d97b 100644 --- a/src/chart/view.ts +++ b/src/chart/view.ts @@ -78,6 +78,8 @@ export default class View extends EE { // 生成的坐标系实例 protected coordinateInstance: Coordinate; + private doAnimation: boolean = true; + constructor(props: ViewCfg) { super(); @@ -300,7 +302,13 @@ export default class View extends EE { return this.coordinateInstance; } - public animate(): View { + /** + * 开启或者关闭动画 + * @param status 动画状态,true 表示开始,false 表示关闭 + * @returns + */ + public animate(status: boolean): View { + this.doAnimation = status; return this; } @@ -787,8 +795,13 @@ export default class View extends EE { * @private */ private paintGeometries() { + const doAnimation = this.doAnimation; // geometry 的 paint 阶段 this.geometries.map((geometry: Geometry) => { + if (!doAnimation) { + // 如果 view 不执行动画,那么 view 下所有的 geometry 都不执行动画 + geometry.animate(false); + } geometry.paint(); }); } diff --git a/tests/unit/chart/view/index-spec.ts b/tests/unit/chart/view/index-spec.ts index 8c27962cb6..9edf126f8b 100644 --- a/tests/unit/chart/view/index-spec.ts +++ b/tests/unit/chart/view/index-spec.ts @@ -92,6 +92,14 @@ describe('View', () => { expect(view.getCoordinate().getHeight()).toEqual(590); }); + it('animate', () => { + // @ts-ignore 默认执行动画 + expect(view.doAnimation).toBe(true); + view.animate(false); + // @ts-ignore + expect(view.doAnimation).toBe(false); + }); + it('geometry', () => { view // @ts-ignore @@ -104,6 +112,8 @@ describe('View', () => { expect(_.size(view.geometries[0].scales)).toEqual(3); expect(view.geometries[0].scales.city.ticks).toEqual(['杭州', '广州']); expect(view.geometries[0].scales.sale.values).toEqual([100, 30]); + // @ts-ignore + expect(view.geometries[0].animateOption).toBe(false); expect(view.getCoordinate().getWidth()).toBeWithin(714, 720); expect(view.getCoordinate().getHeight()).toEqual(566);