Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "fix: fix issue about animation params support function\n\n",
"type": "none",
"packageName": "@visactor/vrender-animate"
}
],
"packageName": "@visactor/vrender-animate",
"email": "lixuef1313@163.com"
}
23 changes: 11 additions & 12 deletions packages/vrender-animate/src/executor/animate-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {
IAnimationCustomConstructor,
IAnimationChannelInterpolator
} from './executor';
import { cloneDeep, isArray, isFunction } from '@visactor/vutils';
import { cloneDeep, isArray, isFunction, isValidNumber } from '@visactor/vutils';
import { getCustomType } from './utils';

interface IAnimateExecutor {
Expand Down Expand Up @@ -115,8 +115,8 @@ export class AnimateExecutor implements IAnimateExecutor {
}

parseParams(params: IAnimationConfig, isTimeline: boolean, child?: IGraphic): IAnimationConfig {
const totalTime = this.resolveValue(params.totalTime, undefined, undefined);
const startTime = this.resolveValue(params.startTime, undefined, 0);
const totalTime = this.resolveValue(params.totalTime, child, undefined);
const startTime = this.resolveValue(params.startTime, child, 0);

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

if (totalTime) {
const _totalTime = delay + delayAfter + duration + oneByOneDelay * (this._target.count - 2);
const scale = totalTime ? totalTime / _totalTime : 1;
parsedParams.delay = delay * scale;
parsedParams.delayAfter = delayAfter * scale;
parsedParams.duration = duration * scale;
parsedParams.oneByOneDelay = oneByOneDelay * scale;
(parsedParams as IAnimationTypeConfig).startTime = startTime;
}
const _totalTime = delay + delayAfter + duration + oneByOneDelay * (this._target.count - 2);
const scale = isValidNumber(totalTime) ? totalTime / _totalTime : 1;

parsedParams.delay = delay * scale;
parsedParams.delayAfter = delayAfter * scale;
parsedParams.duration = duration * scale;
parsedParams.oneByOneDelay = oneByOneDelay * scale;
(parsedParams as IAnimationTypeConfig).startTime = startTime;
}

return parsedParams;
Expand Down
3 changes: 3 additions & 0 deletions packages/vrender-core/src/graphic/glyph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ export class Glyph extends Graphic<IGlyphGraphicAttribute> implements IGlyph {

this.stopStateAnimates();

if (this.stateSort) {
states = states.sort(this.stateSort);
}
const stateAttrs = {};
const subAttrs = this.subGraphic.map(() => ({}));
states.forEach(stateName => {
Expand Down
7 changes: 7 additions & 0 deletions packages/vrender-core/src/graphic/graphic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ export abstract class Graphic<T extends Partial<IGraphicAttribute> = Partial<IGr
// 外部设置,用于选择所使用的textMeasureId
declare textMeasureId?: string;

// state 排序方法
protected stateSort?: (stateA: string, stateB: string) => number;

constructor(params: T = {} as T) {
super();
this._AABBBounds = new AABBBounds();
Expand Down Expand Up @@ -1177,7 +1180,11 @@ export abstract class Graphic<T extends Partial<IGraphicAttribute> = Partial<IGr
return;
}

if (this.stateSort) {
states = states.sort(this.stateSort);
}
const stateAttrs = {};
// sort state
states.forEach(stateName => {
const attrs = this.stateProxy ? this.stateProxy(stateName, states) : this.states?.[stateName];

Expand Down
Loading