Skip to content

Commit 9f3a543

Browse files
authored
Merge pull request #2028 from VisActor/fix/animate-params-function
fix: fix issue about animation params support function
2 parents dd6050e + d0def18 commit 9f3a543

4 files changed

Lines changed: 32 additions & 12 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "fix: fix issue about animation params support function\n\n",
5+
"type": "none",
6+
"packageName": "@visactor/vrender-animate"
7+
}
8+
],
9+
"packageName": "@visactor/vrender-animate",
10+
"email": "lixuef1313@163.com"
11+
}

packages/vrender-animate/src/executor/animate-executor.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {
1111
IAnimationCustomConstructor,
1212
IAnimationChannelInterpolator
1313
} from './executor';
14-
import { cloneDeep, isArray, isFunction } from '@visactor/vutils';
14+
import { cloneDeep, isArray, isFunction, isValidNumber } from '@visactor/vutils';
1515
import { getCustomType } from './utils';
1616

1717
interface IAnimateExecutor {
@@ -115,8 +115,8 @@ export class AnimateExecutor implements IAnimateExecutor {
115115
}
116116

117117
parseParams(params: IAnimationConfig, isTimeline: boolean, child?: IGraphic): IAnimationConfig {
118-
const totalTime = this.resolveValue(params.totalTime, undefined, undefined);
119-
const startTime = this.resolveValue(params.startTime, undefined, 0);
118+
const totalTime = this.resolveValue(params.totalTime, child, undefined);
119+
const startTime = this.resolveValue(params.startTime, child, 0);
120120

121121
// execute只在mark层面调用,所以性能影响可以忽略
122122
// TODO 存在性能问题,如果后续调用频繁,需要重新修改
@@ -201,15 +201,14 @@ export class AnimateExecutor implements IAnimateExecutor {
201201
const customType = getCustomType(parsedParams.custom);
202202
parsedParams.customType = customType;
203203

204-
if (totalTime) {
205-
const _totalTime = delay + delayAfter + duration + oneByOneDelay * (this._target.count - 2);
206-
const scale = totalTime ? totalTime / _totalTime : 1;
207-
parsedParams.delay = delay * scale;
208-
parsedParams.delayAfter = delayAfter * scale;
209-
parsedParams.duration = duration * scale;
210-
parsedParams.oneByOneDelay = oneByOneDelay * scale;
211-
(parsedParams as IAnimationTypeConfig).startTime = startTime;
212-
}
204+
const _totalTime = delay + delayAfter + duration + oneByOneDelay * (this._target.count - 2);
205+
const scale = isValidNumber(totalTime) ? totalTime / _totalTime : 1;
206+
207+
parsedParams.delay = delay * scale;
208+
parsedParams.delayAfter = delayAfter * scale;
209+
parsedParams.duration = duration * scale;
210+
parsedParams.oneByOneDelay = oneByOneDelay * scale;
211+
(parsedParams as IAnimationTypeConfig).startTime = startTime;
213212
}
214213

215214
return parsedParams;

packages/vrender-core/src/graphic/glyph.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ export class Glyph extends Graphic<IGlyphGraphicAttribute> implements IGlyph {
205205

206206
this.stopStateAnimates();
207207

208+
if (this.stateSort) {
209+
states = states.sort(this.stateSort);
210+
}
208211
const stateAttrs = {};
209212
const subAttrs = this.subGraphic.map(() => ({}));
210213
states.forEach(stateName => {

packages/vrender-core/src/graphic/graphic.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ export abstract class Graphic<T extends Partial<IGraphicAttribute> = Partial<IGr
320320
// 外部设置,用于选择所使用的textMeasureId
321321
declare textMeasureId?: string;
322322

323+
// state 排序方法
324+
protected stateSort?: (stateA: string, stateB: string) => number;
325+
323326
constructor(params: T = {} as T) {
324327
super();
325328
this._AABBBounds = new AABBBounds();
@@ -1177,7 +1180,11 @@ export abstract class Graphic<T extends Partial<IGraphicAttribute> = Partial<IGr
11771180
return;
11781181
}
11791182

1183+
if (this.stateSort) {
1184+
states = states.sort(this.stateSort);
1185+
}
11801186
const stateAttrs = {};
1187+
// sort state
11811188
states.forEach(stateName => {
11821189
const attrs = this.stateProxy ? this.stateProxy(stateName, states) : this.states?.[stateName];
11831190

0 commit comments

Comments
 (0)