@antv/g-base 0.5.10 → 0.5.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +5 -7
  2. package/esm/animate/register.d.ts +13 -0
  3. package/esm/animate/register.js +19 -0
  4. package/esm/animate/register.js.map +1 -0
  5. package/esm/animate/timeline.js +4 -3
  6. package/esm/animate/timeline.js.map +1 -1
  7. package/esm/index.d.ts +2 -1
  8. package/esm/index.js +2 -1
  9. package/esm/index.js.map +1 -1
  10. package/esm/interfaces.js +1 -0
  11. package/esm/types.js +1 -0
  12. package/lib/abstract/base.js +2 -2
  13. package/lib/abstract/base.js.map +1 -1
  14. package/lib/abstract/canvas.js +5 -5
  15. package/lib/abstract/canvas.js.map +1 -1
  16. package/lib/abstract/container.js +21 -21
  17. package/lib/abstract/container.js.map +1 -1
  18. package/lib/abstract/element.js +30 -30
  19. package/lib/abstract/element.js.map +1 -1
  20. package/lib/abstract/group.js +1 -1
  21. package/lib/abstract/group.js.map +1 -1
  22. package/lib/abstract/shape.js +5 -5
  23. package/lib/abstract/shape.js.map +1 -1
  24. package/lib/animate/register.d.ts +13 -0
  25. package/lib/animate/register.js +24 -0
  26. package/lib/animate/register.js.map +1 -0
  27. package/lib/animate/timeline.js +11 -10
  28. package/lib/animate/timeline.js.map +1 -1
  29. package/lib/bbox/index.js +10 -10
  30. package/lib/bbox/index.js.map +1 -1
  31. package/lib/bbox/line.js +1 -1
  32. package/lib/bbox/line.js.map +1 -1
  33. package/lib/bbox/path.js +7 -7
  34. package/lib/bbox/path.js.map +1 -1
  35. package/lib/bbox/polyline.js +1 -1
  36. package/lib/bbox/polyline.js.map +1 -1
  37. package/lib/bbox/text.js +3 -3
  38. package/lib/bbox/text.js.map +1 -1
  39. package/lib/event/event-contoller.js +3 -3
  40. package/lib/event/event-contoller.js.map +1 -1
  41. package/lib/index.d.ts +2 -1
  42. package/lib/index.js +6 -4
  43. package/lib/index.js.map +1 -1
  44. package/lib/util/color.js +4 -2
  45. package/lib/util/color.js.map +1 -1
  46. package/lib/util/path.js +3 -3
  47. package/lib/util/path.js.map +1 -1
  48. package/lib/util/text.js +5 -5
  49. package/lib/util/text.js.map +1 -1
  50. package/lib/util/util.js +1 -1
  51. package/package.json +1 -1
  52. package/src/animate/register.ts +27 -0
  53. package/src/animate/timeline.ts +5 -3
  54. package/src/index.ts +2 -1
@@ -0,0 +1,27 @@
1
+ import * as d3Ease from 'd3-ease';
2
+
3
+ type EaseFn = (t: number) => number;
4
+
5
+ interface EasingMap {
6
+ [key: string]: EaseFn;
7
+ }
8
+
9
+ const EASING_MAP: EasingMap = {};
10
+
11
+ /**
12
+ * 根据名称获取对应的动画缓动函数
13
+ * @param type 动画缓动函数名称
14
+ */
15
+ export function getEasing(type: string) {
16
+ // 默认从 d3-ease 中获取
17
+ return EASING_MAP[type.toLowerCase()] || d3Ease[type];
18
+ }
19
+
20
+ /**
21
+ * 注册动画缓动函数
22
+ * @param type 动画缓动函数名称
23
+ * @param easeFn 动画缓动函数
24
+ */
25
+ export function registerEasing(type: string, easeFn: EaseFn) {
26
+ EASING_MAP[type.toLowerCase()] = easeFn;
27
+ }
@@ -1,7 +1,7 @@
1
1
  import { isEqual, isNumber, isFunction } from '@antv/util';
2
2
  import * as d3Timer from 'd3-timer';
3
- import * as d3Ease from 'd3-ease';
4
3
  import { interpolate, interpolateArray } from 'd3-interpolate'; // 目前整体动画只需要数值和数组的差值计算
4
+ import { getEasing } from './register';
5
5
  import * as PathUtil from '../util/path';
6
6
  import { isColorProp, isGradientColor } from '../util/color';
7
7
  import { ICanvas, IElement } from '../interfaces';
@@ -94,17 +94,19 @@ function update(shape: IElement, animation: Animation, elapsed: number) {
94
94
  let ratio;
95
95
  const duration = animation.duration;
96
96
  const easing = animation.easing;
97
+ const easeFn = getEasing(easing);
98
+
97
99
  // 已执行时间
98
100
  elapsed = elapsed - startTime - animation.delay;
99
101
  if (animation.repeat) {
100
102
  // 如果动画重复执行,则 elapsed > duration,计算 ratio 时需取模
101
103
  ratio = (elapsed % duration) / duration;
102
- ratio = d3Ease[easing](ratio);
104
+ ratio = easeFn(ratio);
103
105
  } else {
104
106
  ratio = elapsed / duration;
105
107
  if (ratio < 1) {
106
108
  // 动画未执行完
107
- ratio = d3Ease[easing](ratio);
109
+ ratio = easeFn(ratio);
108
110
  } else {
109
111
  // 动画已执行完
110
112
  if (animation.onFrame) {
package/src/index.ts CHANGED
@@ -19,5 +19,6 @@ export { getTextHeight, assembleFont } from './util/text';
19
19
  export { isAllowCapture } from './util/util';
20
20
  export { multiplyVec2, invert } from './util/matrix';
21
21
  export { getOffScreenContext } from './util/offscreen';
22
+ export { registerEasing } from './animate/register';
22
23
 
23
- export const version = '0.5.9';
24
+ export const version = '0.5.11';