@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.
- package/README.md +5 -7
- package/esm/animate/register.d.ts +13 -0
- package/esm/animate/register.js +19 -0
- package/esm/animate/register.js.map +1 -0
- package/esm/animate/timeline.js +4 -3
- package/esm/animate/timeline.js.map +1 -1
- package/esm/index.d.ts +2 -1
- package/esm/index.js +2 -1
- package/esm/index.js.map +1 -1
- package/esm/interfaces.js +1 -0
- package/esm/types.js +1 -0
- package/lib/abstract/base.js +2 -2
- package/lib/abstract/base.js.map +1 -1
- package/lib/abstract/canvas.js +5 -5
- package/lib/abstract/canvas.js.map +1 -1
- package/lib/abstract/container.js +21 -21
- package/lib/abstract/container.js.map +1 -1
- package/lib/abstract/element.js +30 -30
- package/lib/abstract/element.js.map +1 -1
- package/lib/abstract/group.js +1 -1
- package/lib/abstract/group.js.map +1 -1
- package/lib/abstract/shape.js +5 -5
- package/lib/abstract/shape.js.map +1 -1
- package/lib/animate/register.d.ts +13 -0
- package/lib/animate/register.js +24 -0
- package/lib/animate/register.js.map +1 -0
- package/lib/animate/timeline.js +11 -10
- package/lib/animate/timeline.js.map +1 -1
- package/lib/bbox/index.js +10 -10
- package/lib/bbox/index.js.map +1 -1
- package/lib/bbox/line.js +1 -1
- package/lib/bbox/line.js.map +1 -1
- package/lib/bbox/path.js +7 -7
- package/lib/bbox/path.js.map +1 -1
- package/lib/bbox/polyline.js +1 -1
- package/lib/bbox/polyline.js.map +1 -1
- package/lib/bbox/text.js +3 -3
- package/lib/bbox/text.js.map +1 -1
- package/lib/event/event-contoller.js +3 -3
- package/lib/event/event-contoller.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +6 -4
- package/lib/index.js.map +1 -1
- package/lib/util/color.js +4 -2
- package/lib/util/color.js.map +1 -1
- package/lib/util/path.js +3 -3
- package/lib/util/path.js.map +1 -1
- package/lib/util/text.js +5 -5
- package/lib/util/text.js.map +1 -1
- package/lib/util/util.js +1 -1
- package/package.json +1 -1
- package/src/animate/register.ts +27 -0
- package/src/animate/timeline.ts +5 -3
- 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
|
+
}
|
package/src/animate/timeline.ts
CHANGED
|
@@ -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 =
|
|
104
|
+
ratio = easeFn(ratio);
|
|
103
105
|
} else {
|
|
104
106
|
ratio = elapsed / duration;
|
|
105
107
|
if (ratio < 1) {
|
|
106
108
|
// 动画未执行完
|
|
107
|
-
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.
|
|
24
|
+
export const version = '0.5.11';
|