Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

为 Geometry 添加动画 #1553

Merged
merged 30 commits into from
Oct 22, 2019
Merged

为 Geometry 添加动画 #1553

merged 30 commits into from
Oct 22, 2019

Conversation

simaQ
Copy link
Contributor

@simaQ simaQ commented Oct 17, 2019

🤔 This is a ...

  • Geometry 添加动画机制

引入数据更新机制后,Shape 的动画就可以在自定义 Shape 时直接实现了。如下代码所示:

registerShape('interval', 'rect', {
  draw(cfg: ShapeDrawCFG, element: Element) {
    // 创建对应的 shape
    // 创建完毕,按需进行动画
    const { animate } = cfg;
    if (animate) { // 需要执行动画
      shape.animate();
    }
  },
  update(cfg: ShapeDrawCFG, element: Element) {
    const { animate } = cfg;
    if (animate) { // 需要执行动画
      shape.animate();
    }
  },
  destroy(cfg: ShapeDrawCFG, element: Element) {
    
  }
});

默认 G2 的图表是会执行动画的,内部会有一份默认针对所有 shape 的动画配置,同时开放如下的几个动画配置接口:

chart.animate(boolean); // 开启和关闭动画 

// Geometry 实例上开放 animate() 接口,用于动画配置
chart.interval().animate(false); // 关闭 Geometry 上的动画
chart.interval().animate({
  enter: {
    animation: string, // 动画执行函数,默认会提供
    easing: string, // 缓动函数类型
    duration: number, // 动画执行时间
    delay: number, // 动画延迟时间
    callback: (...args) => any, // 动画执行结束的回调函数
  } || false, // 入场动画,false 表示关闭该类型动画
  update: {
    animation: string, // 动画执行函数,默认会提供
    easing: string, // 缓动函数类型
    duration: number, // 动画执行时间
    delay: number, // 动画延迟时间
    callback: (...args) => any, // 动画执行结束的回调函数
  } || false, // 更新动画,false 表示关闭该类型动画
  leave: {
    animation: string, // 动画执行函数,默认会提供
    easing: string, // 缓动函数类型
    duration: number, // 动画执行时间
    delay: number, // 动画延迟时间
    callback: (...args) => any, // 动画执行结束的回调函数
  } || false, // 销毁动画,false 表示关闭该类型动画
});

如果用户对动画进行任何配置,就执行 G2 默认的动画配置。
当然如果用户进行自定义 Shape,就完全可以自己写动画。

动画的配置优先级如下:
image.png

@simaQ simaQ requested a review from hustcc October 17, 2019 02:46
@auto-add-label auto-add-label bot added the WIP label Oct 17, 2019
@todo
Copy link

todo bot commented Oct 17, 2019

完善 callback 的类型定义

https://github.com/antvis/g2/blob/5571313310bc70f6d16091a437b7b9ff3a8e77a2/src/interface.ts#L51-L56


This comment was generated by todo based on a TODO comment in 5571313 in #1553. cc @antvis.

@antvis antvis deleted a comment from todo bot Oct 18, 2019
@simaQ
Copy link
Contributor Author

simaQ commented Oct 18, 2019

  • Animate 相关测试用例补充
  • 为所有默认的 shape 添加动画

这两个 todo 另起 PR

@todo
Copy link

todo bot commented Oct 21, 2019

待 G 4.0 修复,关联 issue antvis/G#218

https://github.com/antvis/g2/blob/c667a87b14967d552a0f3d62a4de737ea4a2c545/src/geometry/animate/action.ts#L81-L86


This comment was generated by todo based on a TODO comment in c667a87 in #1553. cc @antvis.

@todo
Copy link

todo bot commented Oct 21, 2019

待 G 4.0 修复,关联 issue antvis/G#218

https://github.com/antvis/g2/blob/c667a87b14967d552a0f3d62a4de737ea4a2c545/src/geometry/animate/action.ts#L103-L108


This comment was generated by todo based on a TODO comment in c667a87 in #1553. cc @antvis.

@simaQ simaQ changed the title WIP: 为 Geometry 添加动画 为 Geometry 添加动画 Oct 21, 2019
src/chart/view.ts Outdated Show resolved Hide resolved
@lgtm-com
Copy link

lgtm-com bot commented Oct 21, 2019

This pull request introduces 2 alerts and fixes 1 when merging 2eb7e4a into c816d55 - view on LGTM.com

new alerts:

  • 1 for Useless assignment to local variable
  • 1 for Unused variable, import, function or class

fixed alerts:

  • 1 for Unused variable, import, function or class

@lgtm-com
Copy link

lgtm-com bot commented Oct 21, 2019

This pull request introduces 2 alerts and fixes 1 when merging 5e8242c into c816d55 - view on LGTM.com

new alerts:

  • 1 for Useless assignment to local variable
  • 1 for Unused variable, import, function or class

fixed alerts:

  • 1 for Unused variable, import, function or class

@hustcc hustcc self-assigned this Oct 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants