diff --git a/packages/g6/src/runtime/layout.ts b/packages/g6/src/runtime/layout.ts index 061d2312172..46c8c4bf748 100644 --- a/packages/g6/src/runtime/layout.ts +++ b/packages/g6/src/runtime/layout.ts @@ -142,7 +142,8 @@ export class LayoutController { // 无迭代的布局,直接返回终态位置 / Layout without iteration, return final position directly const layoutResult = await layout.execute(data); if (animation) { - this.updateElementPosition(layoutResult, animation); + const animationResult = this.updateElementPosition(layoutResult, animation); + await animationResult?.finished; } return layoutResult; } @@ -200,7 +201,8 @@ export class LayoutController { applyTreeLayoutOffset(layoutPreset, offset); this.updateElementPosition(layoutPreset, false); - this.updateElementPosition(layoutResult, animation); + const animationResult = this.updateElementPosition(layoutResult, animation); + await animationResult?.finished; } return layoutResult; diff --git a/packages/g6/src/utils/layout.ts b/packages/g6/src/utils/layout.ts index 44088426466..ec1de9b0f7f 100644 --- a/packages/g6/src/utils/layout.ts +++ b/packages/g6/src/utils/layout.ts @@ -147,16 +147,21 @@ export function layoutAdapter( const { nodes = [], edges = [], combos = [] } = data; const nodesToLayout: LayoutNodeData[] = nodes.map((datum) => { const id = idOf(datum); - const { data, style, combo } = datum; + const { data, style, combo, ...rest } = datum; + const result = { id, data: { + // grid 布局会直接读取 data[sortBy],兼容处理,需要避免用户 data 下使用 data, style 等字段 + // The grid layout will directly read data[sortBy], compatible processing, need to avoid users using data, style and other fields under data ...data, + data, // antv-dagre 会读取 data.parentId // antv-dagre will read data.parentId ...(combo ? { parentId: combo } : {}), + style, + ...rest, }, - style: { ...style }, }; // 一些布局会从 data 中读取位置信息 if (style?.x) Object.assign(result.data, { x: style.x });