Skip to content

Commit

Permalink
feat: add view.animate()
Browse files Browse the repository at this point in the history
  • Loading branch information
simaQ committed Oct 17, 2019
1 parent eddd953 commit c02f0ec
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/chart/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export default class View extends EE {
// 生成的坐标系实例
protected coordinateInstance: Coordinate;

private doAnimation: boolean = true;

constructor(props: ViewCfg) {
super();

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();
});
}
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/chart/view/index-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down

0 comments on commit c02f0ec

Please sign in to comment.