Skip to content

Commit 9be7f4f

Browse files
authored
perf: optimize performance when disable animation (#6651)
* perf: optimize style clone perf * refactor: update theme options type
1 parent e7862dd commit 9be7f4f

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

packages/g6/src/runtime/element.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -432,23 +432,25 @@ export class ElementController {
432432
new Ctor({
433433
id,
434434
context: this.context,
435-
style: {
436-
...style,
437-
},
435+
style,
438436
}),
439437
) as Element;
440438

441439
this.shapeTypeMap[id] = type;
442440
this.elementMap[id] = element;
443441

444-
const { stage = 'enter' } = context;
442+
const { stage = 'enter', animation } = context;
443+
444+
const enableAnimation = animation && this.context.options.animation;
445445

446446
this.context.animation?.add(
447447
{
448448
element,
449449
elementType,
450450
stage,
451-
originalStyle: { ...element.attributes },
451+
// <zh/> 当关闭动画时,不需要深拷贝样式
452+
// <en/> When the animation is turned off, there is no need to deep copy the style
453+
originalStyle: enableAnimation ? { ...element.attributes } : element.attributes,
452454
updatedStyle: style,
453455
},
454456
{

packages/g6/src/spec/theme.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
* <en/> Theme Options
55
* @public
66
*/
7-
export type ThemeOptions = 'light' | 'dark' | string;
7+
export type ThemeOptions = false | 'light' | 'dark' | string;

packages/g6/src/utils/animation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,12 @@ export function getElementAnimationOptions(
189189
localAnimation?: AnimationEffectTiming | boolean,
190190
): STDAnimation {
191191
const { animation: globalAnimation } = options;
192+
if (globalAnimation === false || localAnimation === false) return [];
192193

193194
const userElementAnimation = options?.[elementType]?.animation;
194195
if (userElementAnimation === false) return [];
195196
const useElementStageAnimation = userElementAnimation?.[stage];
196197
if (useElementStageAnimation === false) return [];
197-
if (globalAnimation === false || localAnimation === false) return [];
198198

199199
// 优先级:用户局部动画配置 > 用户动画配置 > 全局动画配置 > 主题动画配置 > 默认动画配置
200200
// Priority: user local animation configuration > user animation configuration > global animation configuration > theme animation configuration > default animation configuration

0 commit comments

Comments
 (0)