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 of animation channel\n\n",
"type": "none",
"packageName": "@visactor/vrender-animate"
}
],
"packageName": "@visactor/vrender-animate",
"email": "lixuef1313@163.com"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "fix: fix issue of animation channel\n\n",
"type": "none",
"packageName": "@visactor/vrender-components"
}
],
"packageName": "@visactor/vrender-components",
"email": "lixuef1313@163.com"
}
88 changes: 58 additions & 30 deletions packages/vrender-animate/src/executor/animate-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ export class AnimateExecutor implements IAnimateExecutor {
}
from = parsedFromProps.from;
}
if (parsedFromProps.attrOutChannel) {
graphic.setAttributes(parsedFromProps.attrOutChannel);
}

this._handleRunAnimate(
animate,
Expand Down Expand Up @@ -559,6 +562,9 @@ export class AnimateExecutor implements IAnimateExecutor {
}
from = parsedFromProps.from;
}
if (parsedFromProps.attrOutChannel) {
graphic.setAttributes(parsedFromProps.attrOutChannel);
}
const custom = effect.custom ?? AnimateExecutor.builtInAnimateMap[type];
const customType = effect.custom ? (effect as any).customType : getCustomType(custom);
this._handleRunAnimate(
Expand Down Expand Up @@ -645,51 +651,73 @@ export class AnimateExecutor implements IAnimateExecutor {
private createPropsFromChannel(
channel: IAnimationChannelAttrs | IAnimationChannelAttributes | undefined,
graphic: IGraphic
): { from: Record<string, any> | null; props: Record<string, any> } {
): {
from: Record<string, any> | null;
props: Record<string, any>;
attrOutChannel: Record<string, any> | null;
} {
const props: Record<string, any> = {};
let from: Record<string, any> | null = null;

if (!channel) {
return {
from,
props
props,
attrOutChannel: null
};
}

if (!Array.isArray(channel)) {
// 如果是对象,解析 from/to 配置
Object.keys(channel).forEach(key => {
const config = channel[key];
if (config.to !== undefined) {
if (typeof config.to === 'function') {
props[key] = config.to((graphic.context as any)?.data?.[0], graphic, {});
} else {
props[key] = config.to;
}
const attrOutChannel: Record<string, any> | null = {};
let hasAttrs = false;
const diffAttrs = graphic.context?.diffAttrs;
if (Array.isArray(channel)) {
channel = channel.reduce((res, key) => {
if (diffAttrs[key] === undefined) {
return res;
}
if (config.from !== undefined) {
if (!from) {
from = {};
}
if (typeof config.from === 'function') {
from[key] = config.from((graphic.context as any)?.data?.[0], graphic, {});
} else {
from[key] = config.from;
}
res[key] = { to: diffAttrs[key] };
return res;
}, {} as Record<string, any>);
}

// 对象,解析 from/to 配置
Object.keys(channel).forEach(key => {
const config = channel[key];
if (config.to !== undefined) {
if (typeof config.to === 'function') {
props[key] = config.to((graphic.context as any)?.data?.[0], graphic, {});
} else {
props[key] = config.to;
}
});
} else {
channel.forEach(key => {
const value = graphic.context?.diffAttrs?.[key];
if (value !== undefined) {
props[key] = value;
}
if (config.from !== undefined) {
if (!from) {
from = {};
}
});
if (typeof config.from === 'function') {
from[key] = config.from((graphic.context as any)?.data?.[0], graphic, {});
} else {
from[key] = config.from;
}
}
});

if (diffAttrs) {
for (const key in diffAttrs) {
const value = (diffAttrs as any)[key];
if (value === undefined) {
continue;
}
if (!props.hasOwnProperty(key)) {
attrOutChannel[key] = value;
hasAttrs = true;
}
}
}

return {
from,
props
props,
attrOutChannel: hasAttrs ? attrOutChannel : null
};
}

Expand Down
Loading