@antv/g6 5.0.35 → 5.0.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/dist/g6.min.js +11 -11
  2. package/dist/lib/elements/shapes/base-shape.d.ts +0 -7
  3. package/dist/lib/layouts/types.d.ts +20 -0
  4. package/dist/lib/plugins/tooltip.d.ts +1 -1
  5. package/dist/lib/runtime/data.d.ts +2 -8
  6. package/dist/lib/runtime/element.d.ts +5 -2
  7. package/dist/lib/runtime/layout.d.ts +18 -1
  8. package/dist/lib/runtime/options.d.ts +9 -0
  9. package/dist/lib/runtime/transform.d.ts +2 -1
  10. package/dist/lib/spec/data.d.ts +0 -14
  11. package/dist/lib/spec/theme.d.ts +1 -1
  12. package/dist/lib/transforms/base-transform.d.ts +2 -1
  13. package/dist/lib/utils/element.d.ts +9 -1
  14. package/dist/lib/utils/layout.d.ts +13 -1
  15. package/dist/lib/utils/transform.d.ts +2 -2
  16. package/dist/lib/version.d.ts +1 -1
  17. package/esm/animations/executor.js +3 -2
  18. package/esm/animations/executor.js.map +1 -1
  19. package/esm/behaviors/drag-element.js +9 -2
  20. package/esm/behaviors/drag-element.js.map +1 -1
  21. package/esm/elements/combos/base-combo.js +1 -1
  22. package/esm/elements/combos/base-combo.js.map +1 -1
  23. package/esm/elements/edges/base-edge.js +8 -2
  24. package/esm/elements/edges/base-edge.js.map +1 -1
  25. package/esm/elements/shapes/base-shape.d.ts +0 -7
  26. package/esm/elements/shapes/base-shape.js +22 -19
  27. package/esm/elements/shapes/base-shape.js.map +1 -1
  28. package/esm/layouts/types.d.ts +20 -0
  29. package/esm/plugins/background/index.js +1 -0
  30. package/esm/plugins/background/index.js.map +1 -1
  31. package/esm/plugins/grid-line.js +1 -0
  32. package/esm/plugins/grid-line.js.map +1 -1
  33. package/esm/plugins/tooltip.d.ts +1 -1
  34. package/esm/plugins/tooltip.js +18 -16
  35. package/esm/plugins/tooltip.js.map +1 -1
  36. package/esm/runtime/data.d.ts +2 -8
  37. package/esm/runtime/data.js +14 -18
  38. package/esm/runtime/data.js.map +1 -1
  39. package/esm/runtime/element.d.ts +5 -2
  40. package/esm/runtime/element.js +45 -18
  41. package/esm/runtime/element.js.map +1 -1
  42. package/esm/runtime/graph.js +19 -7
  43. package/esm/runtime/graph.js.map +1 -1
  44. package/esm/runtime/layout.d.ts +18 -1
  45. package/esm/runtime/layout.js +85 -20
  46. package/esm/runtime/layout.js.map +1 -1
  47. package/esm/runtime/options.d.ts +9 -0
  48. package/esm/runtime/options.js +49 -0
  49. package/esm/runtime/options.js.map +1 -0
  50. package/esm/runtime/transform.d.ts +2 -1
  51. package/esm/runtime/transform.js.map +1 -1
  52. package/esm/spec/data.d.ts +0 -14
  53. package/esm/spec/theme.d.ts +1 -1
  54. package/esm/transforms/base-transform.d.ts +2 -1
  55. package/esm/transforms/base-transform.js +1 -1
  56. package/esm/transforms/base-transform.js.map +1 -1
  57. package/esm/utils/animation.js +2 -2
  58. package/esm/utils/animation.js.map +1 -1
  59. package/esm/utils/element.d.ts +9 -1
  60. package/esm/utils/element.js +35 -1
  61. package/esm/utils/element.js.map +1 -1
  62. package/esm/utils/layout.d.ts +13 -1
  63. package/esm/utils/layout.js +14 -0
  64. package/esm/utils/layout.js.map +1 -1
  65. package/esm/utils/transform.d.ts +2 -2
  66. package/esm/utils/transform.js +13 -8
  67. package/esm/utils/transform.js.map +1 -1
  68. package/esm/version.d.ts +1 -1
  69. package/esm/version.js +1 -1
  70. package/lib/animations/executor.js +3 -2
  71. package/lib/animations/executor.js.map +1 -1
  72. package/lib/behaviors/drag-element.js +9 -2
  73. package/lib/behaviors/drag-element.js.map +1 -1
  74. package/lib/elements/combos/base-combo.js +1 -1
  75. package/lib/elements/combos/base-combo.js.map +1 -1
  76. package/lib/elements/edges/base-edge.js +7 -1
  77. package/lib/elements/edges/base-edge.js.map +1 -1
  78. package/lib/elements/shapes/base-shape.d.ts +0 -7
  79. package/lib/elements/shapes/base-shape.js +21 -18
  80. package/lib/elements/shapes/base-shape.js.map +1 -1
  81. package/lib/layouts/types.d.ts +20 -0
  82. package/lib/plugins/background/index.js +1 -0
  83. package/lib/plugins/background/index.js.map +1 -1
  84. package/lib/plugins/grid-line.js +1 -0
  85. package/lib/plugins/grid-line.js.map +1 -1
  86. package/lib/plugins/tooltip.d.ts +1 -1
  87. package/lib/plugins/tooltip.js +18 -16
  88. package/lib/plugins/tooltip.js.map +1 -1
  89. package/lib/runtime/data.d.ts +2 -8
  90. package/lib/runtime/data.js +14 -18
  91. package/lib/runtime/data.js.map +1 -1
  92. package/lib/runtime/element.d.ts +5 -2
  93. package/lib/runtime/element.js +45 -18
  94. package/lib/runtime/element.js.map +1 -1
  95. package/lib/runtime/graph.js +21 -9
  96. package/lib/runtime/graph.js.map +1 -1
  97. package/lib/runtime/layout.d.ts +18 -1
  98. package/lib/runtime/layout.js +84 -19
  99. package/lib/runtime/layout.js.map +1 -1
  100. package/lib/runtime/options.d.ts +9 -0
  101. package/lib/runtime/options.js +52 -0
  102. package/lib/runtime/options.js.map +1 -0
  103. package/lib/runtime/transform.d.ts +2 -1
  104. package/lib/runtime/transform.js.map +1 -1
  105. package/lib/spec/data.d.ts +0 -14
  106. package/lib/spec/theme.d.ts +1 -1
  107. package/lib/transforms/base-transform.d.ts +2 -1
  108. package/lib/transforms/base-transform.js +1 -1
  109. package/lib/transforms/base-transform.js.map +1 -1
  110. package/lib/utils/animation.js +2 -2
  111. package/lib/utils/animation.js.map +1 -1
  112. package/lib/utils/element.d.ts +9 -1
  113. package/lib/utils/element.js +35 -0
  114. package/lib/utils/element.js.map +1 -1
  115. package/lib/utils/layout.d.ts +13 -1
  116. package/lib/utils/layout.js +15 -0
  117. package/lib/utils/layout.js.map +1 -1
  118. package/lib/utils/transform.d.ts +2 -2
  119. package/lib/utils/transform.js +13 -8
  120. package/lib/utils/transform.js.map +1 -1
  121. package/lib/version.d.ts +1 -1
  122. package/lib/version.js +1 -1
  123. package/package.json +1 -1
  124. package/src/animations/executor.ts +4 -4
  125. package/src/behaviors/drag-element.ts +9 -2
  126. package/src/elements/combos/base-combo.ts +1 -1
  127. package/src/elements/edges/base-edge.ts +9 -5
  128. package/src/elements/shapes/base-shape.ts +21 -19
  129. package/src/layouts/types.ts +20 -0
  130. package/src/plugins/background/index.ts +1 -0
  131. package/src/plugins/grid-line.ts +1 -0
  132. package/src/plugins/tooltip.ts +21 -15
  133. package/src/runtime/data.ts +14 -19
  134. package/src/runtime/element.ts +69 -18
  135. package/src/runtime/graph.ts +19 -8
  136. package/src/runtime/layout.ts +79 -23
  137. package/src/runtime/options.ts +52 -0
  138. package/src/runtime/transform.ts +2 -0
  139. package/src/spec/data.ts +0 -14
  140. package/src/spec/theme.ts +1 -1
  141. package/src/transforms/base-transform.ts +3 -1
  142. package/src/utils/animation.ts +1 -1
  143. package/src/utils/element.ts +21 -2
  144. package/src/utils/layout.ts +16 -1
  145. package/src/utils/transform.ts +13 -9
  146. package/src/version.ts +1 -1
@@ -7,6 +7,6 @@ import type { TransformArray } from '@antv/g';
7
7
  * @param y - <zh/> y | <en/> y
8
8
  * @param z - <zh/> z | <en/> z
9
9
  * @param transform - <zh/> transform 字符串 | <en/> transform string
10
- * @returns <zh/> 替换后的 transform 字符串 | <en/> replaced transform string
10
+ * @returns <zh/> 替换后的 transform 字符串,返回 null 表示无需替换 | <en/> the replaced transform string, return null means no need to replace
11
11
  */
12
- export declare function replaceTranslateInTransform(x: number, y: number, z: number, transform: string | TransformArray): string | TransformArray | null;
12
+ export declare function replaceTranslateInTransform(x: number, y: number, z?: number, transform?: string | TransformArray): string | TransformArray | null;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.replaceTranslateInTransform = replaceTranslateInTransform;
4
+ const util_1 = require("@antv/util");
4
5
  /**
5
6
  * <zh/> 从 transform 字符串中替换 translate 部分
6
7
  *
@@ -9,33 +10,37 @@ exports.replaceTranslateInTransform = replaceTranslateInTransform;
9
10
  * @param y - <zh/> y | <en/> y
10
11
  * @param z - <zh/> z | <en/> z
11
12
  * @param transform - <zh/> transform 字符串 | <en/> transform string
12
- * @returns <zh/> 替换后的 transform 字符串 | <en/> replaced transform string
13
+ * @returns <zh/> 替换后的 transform 字符串,返回 null 表示无需替换 | <en/> the replaced transform string, return null means no need to replace
13
14
  */
14
- function replaceTranslateInTransform(x, y, z, transform) {
15
+ function replaceTranslateInTransform(x, y, z, transform = []) {
16
+ if (!transform && x === 0 && y === 0 && z === 0)
17
+ return null;
15
18
  if (Array.isArray(transform)) {
16
- let hasTranslate = false;
19
+ let translateIndex = -1;
17
20
  const newTransform = [];
18
21
  for (let i = 0; i < transform.length; i++) {
19
22
  const t = transform[i];
20
23
  if (t[0] === 'translate') {
21
24
  if (t[1] === x && t[2] === y)
22
25
  return null;
23
- hasTranslate = true;
26
+ translateIndex = i;
24
27
  newTransform.push(['translate', x, y]);
25
28
  }
26
29
  else if (t[0] === 'translate3d') {
27
30
  if (t[1] === x && t[2] === y && t[3] === z)
28
31
  return null;
29
- hasTranslate = true;
30
- newTransform.push(['translate3d', x, y, z]);
32
+ translateIndex = i;
33
+ newTransform.push(['translate3d', x, y, z !== null && z !== void 0 ? z : 0]);
31
34
  }
32
35
  else {
33
36
  newTransform.push(t);
34
37
  }
35
38
  }
36
- if (!hasTranslate) {
37
- newTransform.splice(0, 0, z === 0 ? ['translate', x, y] : ['translate3d', x, y, z]);
39
+ if (translateIndex === -1) {
40
+ newTransform.splice(0, 0, (0, util_1.isNumber)(z) ? ['translate3d', x, y, z !== null && z !== void 0 ? z : 0] : ['translate', x, y]);
38
41
  }
42
+ if (newTransform.length === 0)
43
+ return null;
39
44
  return newTransform;
40
45
  }
41
46
  const removedTranslate = transform ? transform.replace(/translate(3d)?\([^)]*\)/g, '') : '';
@@ -1 +1 @@
1
- {"version":3,"file":"transform.js","sourceRoot":"src/","sources":["utils/transform.ts"],"names":[],"mappings":";;AAYA,kEAq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,0BAA0B,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5F,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACZ,OAAO,aAAa,CAAC,KAAK,CAAC,IAAI,gBAAgB,EAAE,CAAC;IACpD,CAAC;SAAM,CAAC;QACN,OAAO,eAAe,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,gBAAgB,EAAE,CAAC;IAC5D,CAAC;AACH,CAAC"}
package/lib/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "5.0.35";
1
+ export declare const version = "5.0.37";
package/lib/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = void 0;
4
- exports.version = '5.0.35';
4
+ exports.version = '5.0.37';
5
5
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/g6",
3
- "version": "5.0.35",
3
+ "version": "5.0.37",
4
4
  "description": "A Graph Visualization Framework in JavaScript",
5
5
  "keywords": [
6
6
  "antv",
@@ -64,13 +64,13 @@ export const executor: AnimationExecutor = (element, keyframes, options) => {
64
64
 
65
65
  // x/y -> translate
66
66
  if (keyframes.some((keyframe) => Object.keys(keyframe).some((attr) => ['x', 'y', 'z'].includes(attr)))) {
67
- const { x = 0, y = 0, z = 0, transform = '' } = shape.attributes || {};
67
+ const { x = 0, y = 0, z, transform = '' } = shape.attributes || {};
68
68
  keyframes.forEach((keyframe) => {
69
69
  // @ts-expect-error ignore type error
70
70
  keyframe.transform = replaceTranslateInTransform(
71
- (keyframe.x as number) || (x as number),
72
- (keyframe.y as number) || (y as number),
73
- (keyframe.z as number) || (z as number),
71
+ (keyframe.x as number) ?? (x as number),
72
+ (keyframe.y as number) ?? (y as number),
73
+ (keyframe.z as number) ?? (z as number),
74
74
  transform,
75
75
  );
76
76
  });
@@ -242,11 +242,18 @@ export class DragElement extends BaseBehavior<DragElementOptions> {
242
242
  this.enable = this.validate(event);
243
243
  if (!this.enable) return;
244
244
 
245
- const { batch, canvas } = this.context;
245
+ const { batch, canvas, graph } = this.context;
246
246
  canvas.setCursor(this.options!.cursor?.grabbing || 'grabbing');
247
247
  this.isDragging = true;
248
248
  batch!.startBatch();
249
- this.target = this.getSelectedNodeIDs([event.target.id]);
249
+
250
+ // 如果当前节点是选中状态,则查询出画布中所有选中的节点,否则只拖拽当前节点
251
+ // If the current node is selected, query all selected nodes in the canvas, otherwise only drag the current node
252
+ const id = event.target.id;
253
+ const states = graph.getElementState(id);
254
+ if (states.includes(this.options.state)) this.target = this.getSelectedNodeIDs([id]);
255
+ else this.target = [id];
256
+
250
257
  this.hideEdge();
251
258
  this.context.graph.frontElement(this.target);
252
259
  if (this.options.shadow) this.createShadow(this.target);
@@ -227,7 +227,7 @@ export abstract class BaseCombo<S extends BaseComboStyleProps = BaseComboStylePr
227
227
  Object.assign(this.style, comboStyle);
228
228
  // Sync combo position to model
229
229
  const { x, y } = comboStyle;
230
- this.context.model.syncComboDatum({ id: this.id, style: { x, y } });
230
+ this.context.model.syncNodeLikeDatum({ id: this.id, style: { x, y } });
231
231
  dispatchPositionChange(this);
232
232
  }
233
233
 
@@ -18,7 +18,7 @@ import type {
18
18
  import { getBBoxHeight, getBBoxWidth, getNodeBBox } from '../../utils/bbox';
19
19
  import { getArrowSize, getBadgePositionStyle, getCubicLoopPath, getLabelPositionStyle } from '../../utils/edge';
20
20
  import { findPorts, getConnectionPoint, getPortPosition, isSameNode } from '../../utils/element';
21
- import { omitStyleProps, subStyleProps } from '../../utils/prefix';
21
+ import { subStyleProps } from '../../utils/prefix';
22
22
  import { parseSize } from '../../utils/size';
23
23
  import { mergeOptions } from '../../utils/style';
24
24
  import * as Symbol from '../../utils/symbol';
@@ -233,10 +233,14 @@ export abstract class BaseEdge extends BaseElement<BaseEdgeStyleProps> implement
233
233
 
234
234
  const d = loop && isSameNode(sourceNode, targetNode) ? this.getLoopPath(attributes) : this.getKeyPath(attributes);
235
235
 
236
- return {
237
- d,
238
- ...omitStyleProps(style, ['halo', 'label', 'startArrow', 'endArrow']),
239
- };
236
+ const keyStyle: PathStyleProps = { d };
237
+
238
+ Path.PARSED_STYLE_LIST.forEach((key) => {
239
+ // @ts-expect-error skip type error
240
+ if (key in style) keyStyle[key] = style[key];
241
+ });
242
+
243
+ return keyStyle;
240
244
  }
241
245
 
242
246
  protected abstract getKeyPath(attributes: ParsedBaseEdgeStyleProps): PathArray;
@@ -4,7 +4,7 @@ import { isEmpty, isFunction, upperFirst } from '@antv/util';
4
4
  import { ExtensionCategory } from '../../constants';
5
5
  import type { Keyframe } from '../../types';
6
6
  import { createAnimationsProxy, preprocessKeyframes } from '../../utils/animation';
7
- import { updateStyle } from '../../utils/element';
7
+ import { setAttributes, updateStyle } from '../../utils/element';
8
8
  import { subObject } from '../../utils/prefix';
9
9
  import { format } from '../../utils/print';
10
10
  import { getSubShapeStyle } from '../../utils/style';
@@ -21,8 +21,8 @@ export interface BaseShapeStyleProps extends BaseStyleProps {}
21
21
  */
22
22
  export abstract class BaseShape<StyleProps extends BaseShapeStyleProps> extends CustomElement<StyleProps> {
23
23
  constructor(options: DisplayObjectConfig<StyleProps>) {
24
+ applyTransform(options.style);
24
25
  super(options);
25
- this.transformPosition(this.attributes);
26
26
  this.render(this.attributes as Required<StyleProps>, this);
27
27
  this.setVisibility();
28
28
  this.bindEvents();
@@ -116,26 +116,11 @@ export abstract class BaseShape<StyleProps extends BaseShapeStyleProps> extends
116
116
  return target;
117
117
  }
118
118
 
119
- /**
120
- * <zh/> 使用 transform 更新图形位置
121
- *
122
- * <en/> Update the position of the shape using transform
123
- * @param attributes - <zh/> 样式属性 | <en/> style attributes
124
- */
125
- protected transformPosition(attributes: Partial<StyleProps>) {
126
- // Use `transform: translate3d()` instead of `x/y/z`
127
- if ('x' in attributes || 'y' in attributes || 'z' in attributes) {
128
- const { x = 0, y = 0, z = 0, transform } = attributes as any;
129
- const newTransform = replaceTranslateInTransform(+x, +y, +z, transform);
130
- if (newTransform) this.style.transform = newTransform;
131
- }
132
- }
133
-
134
119
  public update(attr: Partial<StyleProps> = {}): void {
135
120
  const attributes = Object.assign({}, this.attributes, attr) as Required<StyleProps>;
136
- this.attr(attributes);
121
+ applyTransform(attributes);
122
+ setAttributes(this, attributes);
137
123
  this.render(attributes, this);
138
- this.transformPosition(attributes);
139
124
  this.setVisibility();
140
125
  }
141
126
 
@@ -331,3 +316,20 @@ export interface UpsertHooks {
331
316
  */
332
317
  afterDestroy?: (instance: DisplayObject) => void;
333
318
  }
319
+
320
+ /**
321
+ * <zh/> 应用 transform
322
+ *
323
+ * <en/> Apply transform
324
+ * @param style - <zh/> 样式 | <en/> style
325
+ * @returns <zh/> 样式 | <en/> style
326
+ */
327
+ function applyTransform(style?: BaseShapeStyleProps) {
328
+ if (!style) return {};
329
+ if ('x' in style || 'y' in style || 'z' in style) {
330
+ const { x = 0, y = 0, z, transform } = style as any;
331
+ const newTransform = replaceTranslateInTransform(x, y, z, transform);
332
+ if (newTransform) style.transform = newTransform;
333
+ }
334
+ return style;
335
+ }
@@ -52,6 +52,26 @@ export interface BaseLayoutOptions extends AnimationOptions, WebWorkerLayoutOpti
52
52
  * @returns <zh/> 是否参与布局 | <en/> Whether to participate in the layout
53
53
  */
54
54
  nodeFilter?: (node: NodeData) => boolean;
55
+ /**
56
+ * <zh/> 使用前布局,在初始化元素前计算布局
57
+ *
58
+ * <en/> Use pre-layout to calculate the layout before initializing the elements
59
+ * @remarks
60
+ * <zh/> 不适用于流水线布局
61
+ *
62
+ * <en/> Not applicable to pipeline layout
63
+ */
64
+ preLayout?: boolean;
65
+ /**
66
+ * <zh/> 不可见节点是否参与布局
67
+ *
68
+ * <en/> Whether invisible nodes participate in the layout
69
+ * @remarks
70
+ * <zh/> 当 preLayout 为 true 时生效
71
+ *
72
+ * <en/> Takes effect when preLayout is true
73
+ */
74
+ isLayoutInvisibleNodes?: boolean;
55
75
  }
56
76
 
57
77
  interface CircularLayout extends BaseLayoutOptions, CircularLayoutOptions {
@@ -24,6 +24,7 @@ export class Background extends BasePlugin<BackgroundOptions> {
24
24
  static defaultOptions: Partial<BackgroundOptions> = {
25
25
  transition: 'background 0.5s',
26
26
  backgroundSize: 'cover',
27
+ zIndex: '-1', // aviod to cover the other plugin's dom, eg: grid-line.
27
28
  };
28
29
 
29
30
  private $element: HTMLElement = createPluginContainer('background');
@@ -136,6 +136,7 @@ export class GridLine extends BasePlugin<GridLineOptions> {
136
136
  border: border ? `${borderLineWidth}px ${borderStyle} ${borderStroke}` : 'none',
137
137
  backgroundImage: `linear-gradient(${stroke} ${lineWidth}px, transparent ${lineWidth}px), linear-gradient(90deg, ${stroke} ${lineWidth}px, transparent ${lineWidth}px)`,
138
138
  backgroundSize: `${size}px ${size}px`,
139
+ backgroundRepeat: 'repeat',
139
140
  });
140
141
  }
141
142
 
@@ -38,7 +38,7 @@ export interface TooltipOptions
38
38
  * <en/> Is enable
39
39
  * @defaultValue true
40
40
  */
41
- enable?: boolean | ((event: IElementEvent) => boolean);
41
+ enable?: boolean | ((event: IElementEvent, items: ElementDatum[]) => boolean);
42
42
  /**
43
43
  * <zh/> 显示隐藏的回调
44
44
  *
@@ -147,10 +147,10 @@ export class Tooltip extends BasePlugin<TooltipOptions> {
147
147
  });
148
148
  }
149
149
 
150
- private isEnable = (event: IElementEvent) => {
150
+ private isEnable = (event: IElementEvent, items: ElementDatum[]) => {
151
151
  const { enable } = this.options;
152
152
  if (typeof enable === 'function') {
153
- return enable(event);
153
+ return enable(event, items);
154
154
  }
155
155
  return enable;
156
156
  };
@@ -249,25 +249,17 @@ export class Tooltip extends BasePlugin<TooltipOptions> {
249
249
  target: { id },
250
250
  } = event;
251
251
  if (isToBeDestroyed(event.target)) return;
252
- if (!this.tooltipElement || !this.isEnable(event)) return;
253
252
 
254
253
  const targetType = this.context.graph.getElementType(id);
255
254
  const { getContent, title } = this.options;
256
- this.currentTarget = id;
257
255
  const items: ElementDatum[] = this.getElementData(id, targetType as ElementType);
258
- let x;
259
- let y;
260
- if (client) {
261
- x = client.x;
262
- y = client.y;
263
- } else {
264
- const style = get(items, '0.style', { x: 0, y: 0 });
265
- x = style.x;
266
- y = style.y;
267
- }
256
+
257
+ if (!this.tooltipElement || !this.isEnable(event, items)) return;
258
+
268
259
  let tooltipContent: { [key: string]: unknown } = {};
269
260
  if (getContent) {
270
261
  tooltipContent.content = getContent(event, items);
262
+ if (!tooltipContent.content) return;
271
263
  } else {
272
264
  const style = this.context.graph.getElementRenderStyle(id);
273
265
  const color = targetType === 'node' ? style.fill : style.stroke;
@@ -282,6 +274,20 @@ export class Tooltip extends BasePlugin<TooltipOptions> {
282
274
  }),
283
275
  };
284
276
  }
277
+
278
+ this.currentTarget = id;
279
+
280
+ let x;
281
+ let y;
282
+ if (client) {
283
+ x = client.x;
284
+ y = client.y;
285
+ } else {
286
+ const style = get(items, '0.style', { x: 0, y: 0 });
287
+ x = style.x;
288
+ y = style.y;
289
+ }
290
+
285
291
  this.options.onOpenChange?.(true);
286
292
  this.tooltipElement.update({
287
293
  ...this.tooltipStyleProps,
@@ -608,15 +608,26 @@ export class DataController {
608
608
  });
609
609
  }
610
610
 
611
- public syncNodeDatum(datum: PartialNodeLikeData<NodeData>) {
611
+ public syncNodeLikeDatum(datum: PartialNodeLikeData<NodeData>) {
612
612
  const { model } = this;
613
613
 
614
614
  const id = idOf(datum);
615
+ if (!model.hasNode(id)) return;
615
616
  const original = toG6Data(model.getNode(id));
616
617
  const value = mergeElementsData(original, datum);
617
618
  model.mergeNodeData(id, value);
618
619
  }
619
620
 
621
+ public syncEdgeDatum(datum: PartialEdgeData<EdgeData>) {
622
+ const { model } = this;
623
+
624
+ const id = idOf(datum);
625
+ if (!model.hasEdge(id)) return;
626
+ const original = toG6Data(model.getEdge(id));
627
+ const value = mergeElementsData(original, datum);
628
+ model.mergeEdgeData(id, value);
629
+ }
630
+
620
631
  public updateEdgeData(edges: PartialEdgeData<EdgeData>[] = []) {
621
632
  if (!edges.length) return;
622
633
  const { model } = this;
@@ -679,8 +690,8 @@ export class DataController {
679
690
 
680
691
  if (originalParentId !== parent && hierarchyKey === COMBO_KEY) {
681
692
  const modifiedDatum = { id, combo: parent };
682
- if (this.isCombo(id)) this.syncComboDatum(modifiedDatum);
683
- else this.syncNodeDatum(modifiedDatum);
693
+ if (this.isCombo(id)) this.syncNodeLikeDatum(modifiedDatum);
694
+ else this.syncNodeLikeDatum(modifiedDatum);
684
695
  }
685
696
 
686
697
  this.model.setParent(id, parent, hierarchyKey);
@@ -713,22 +724,6 @@ export class DataController {
713
724
  });
714
725
  }
715
726
 
716
- /**
717
- * <zh/> 将 combo 数据同步到 model 中
718
- *
719
- * <en/> Synchronize combo data to the model
720
- * @param datum - <zh/> combo 数据 | <en/> combo data
721
- */
722
- public syncComboDatum(datum: PartialNodeLikeData<ComboData>) {
723
- const { model } = this;
724
-
725
- const id = idOf(datum);
726
- if (!model.hasNode(id)) return;
727
- const original = toG6Data(model.getNode(id));
728
- const value = mergeElementsData(original, datum);
729
- model.mergeNodeData(id, value);
730
- }
731
-
732
727
  public getElementPosition(id: ID): Point {
733
728
  const datum = this.getElementDataById(id) as NodeLikeData;
734
729
  return positionOf(datum);
@@ -262,28 +262,68 @@ export class ElementController {
262
262
  return style;
263
263
  }
264
264
 
265
+ private getDrawData(context: DrawContext): DrawPayload | null {
266
+ this.init();
267
+
268
+ const data = this.computeChangesAndDrawData(context);
269
+ if (!data) return null;
270
+
271
+ const { type = 'draw', stage = type } = context;
272
+ this.markDestroyElement(data.drawData);
273
+ // 计算样式 / Calculate style
274
+ this.computeStyle(stage);
275
+
276
+ return { type, stage, data };
277
+ }
278
+
265
279
  /**
266
280
  * <zh/> 开始绘制流程
267
281
  *
268
282
  * <en/> start render process
269
283
  */
270
284
  public draw(context: DrawContext = { animation: true }) {
271
- this.init();
285
+ const drawData = this.getDrawData(context);
286
+ if (!drawData) return;
272
287
 
273
- const data = this.computeChangesAndDrawData(context);
274
- if (!data) return null;
288
+ const {
289
+ data: {
290
+ drawData: { add, update, remove },
291
+ },
292
+ } = drawData;
293
+
294
+ this.destroyElements(remove, context);
295
+ this.createElements(add, context);
296
+ this.updateElements(update, context);
297
+
298
+ return this.setAnimationTask(context, drawData);
299
+ }
300
+
301
+ public async preLayoutDraw(context: DrawContext = { animation: true }) {
302
+ const preResult = this.getDrawData(context);
303
+ if (!preResult) return;
304
+
305
+ const {
306
+ data: { drawData },
307
+ } = preResult;
308
+
309
+ await this.context.layout?.preLayout?.(drawData);
275
310
 
276
- const { type = 'draw', stage = type, animation, silence } = context;
277
- const { dataChanges, drawData } = data;
278
- this.markDestroyElement(drawData);
279
- // 计算样式 / Calculate style
280
- this.computeStyle(stage);
281
- // 创建渲染任务 / Create render task
282
311
  const { add, update, remove } = drawData;
283
312
  this.destroyElements(remove, context);
284
313
  this.createElements(add, context);
285
314
  this.updateElements(update, context);
286
315
 
316
+ return this.setAnimationTask(context, preResult);
317
+ }
318
+
319
+ private setAnimationTask(context: DrawContext, data: DrawPayload) {
320
+ const { animation, silence } = context;
321
+ const {
322
+ data: { dataChanges, drawData },
323
+ stage,
324
+ type,
325
+ } = data;
326
+
287
327
  return this.context.animation!.animate(
288
328
  animation,
289
329
  silence
@@ -392,23 +432,25 @@ export class ElementController {
392
432
  new Ctor({
393
433
  id,
394
434
  context: this.context,
395
- style: {
396
- ...style,
397
- },
435
+ style,
398
436
  }),
399
437
  ) as Element;
400
438
 
401
439
  this.shapeTypeMap[id] = type;
402
440
  this.elementMap[id] = element;
403
441
 
404
- const { stage = 'enter' } = context;
442
+ const { stage = 'enter', animation } = context;
443
+
444
+ const enableAnimation = animation && this.context.options.animation;
405
445
 
406
446
  this.context.animation?.add(
407
447
  {
408
448
  element,
409
449
  elementType,
410
450
  stage,
411
- 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,
412
454
  updatedStyle: style,
413
455
  },
414
456
  {
@@ -618,17 +660,17 @@ export class ElementController {
618
660
  *
619
661
  * <en/> collapse node
620
662
  * @param id - <zh/> 元素 ID | <en/> element ID
621
- * @param animation - <zh/> 是否使用动画,默认为 true | <en/> Whether to use animation, default is true
663
+ * @param options - <zh/> 选项 | <en/> options
622
664
  */
623
665
  public async collapseNode(id: ID, options: CollapseExpandNodeOptions): Promise<void> {
624
666
  const { animation, align } = options;
625
667
 
626
668
  const { model, layout } = this.context;
627
669
 
628
- const preLayoutData = this.computeChangesAndDrawData({ stage: 'collapse', animation });
629
- if (!preLayoutData) return;
670
+ const simulateLayoutData = this.computeChangesAndDrawData({ stage: 'collapse', animation });
671
+ if (!simulateLayoutData) return;
630
672
 
631
- this.markDestroyElement(preLayoutData.drawData);
673
+ this.markDestroyElement(simulateLayoutData.drawData);
632
674
 
633
675
  // 进行预布局,计算出所有元素的位置
634
676
  // Perform pre-layout to calculate the position of all elements
@@ -837,6 +879,15 @@ export interface DrawContext {
837
879
  target?: ID;
838
880
  }
839
881
 
882
+ interface DrawPayload {
883
+ data: {
884
+ dataChanges: DataChange[];
885
+ drawData: DrawData;
886
+ };
887
+ stage: AnimationStage;
888
+ type: 'render' | 'draw';
889
+ }
890
+
840
891
  /**
841
892
  * <zh/> 展开/收起节点选项
842
893
  *
@@ -44,6 +44,7 @@ import { sizeOf } from '../utils/dom';
44
44
  import { getSubgraphRelatedEdges } from '../utils/edge';
45
45
  import { GraphLifeCycleEvent, emit } from '../utils/event';
46
46
  import { idOf } from '../utils/id';
47
+ import { isPreLayout } from '../utils/layout';
47
48
  import { format } from '../utils/print';
48
49
  import { subtract } from '../utils/vector';
49
50
  import { getZIndexOf } from '../utils/z-index';
@@ -56,13 +57,14 @@ import { DataController } from './data';
56
57
  import type { CollapseExpandNodeOptions } from './element';
57
58
  import { ElementController } from './element';
58
59
  import { LayoutController } from './layout';
60
+ import { inferOptions } from './options';
59
61
  import { PluginController } from './plugin';
60
62
  import { TransformController } from './transform';
61
63
  import { RuntimeContext } from './types';
62
64
  import { ViewportController } from './viewport';
63
65
 
64
66
  export class Graph extends EventEmitter {
65
- private options: GraphOptions;
67
+ private options: GraphOptions = {};
66
68
 
67
69
  /**
68
70
  * @internal
@@ -96,8 +98,7 @@ export class Graph extends EventEmitter {
96
98
 
97
99
  constructor(options: GraphOptions) {
98
100
  super();
99
- this.options = Object.assign({}, Graph.defaultOptions, options);
100
- this._setOptions(this.options, true);
101
+ this._setOptions(Object.assign({}, Graph.defaultOptions, options), true);
101
102
  this.context.graph = this;
102
103
 
103
104
  // Listening resize to autoResize.
@@ -132,13 +133,13 @@ export class Graph extends EventEmitter {
132
133
 
133
134
  private _setOptions(options: GraphOptions, isInit: boolean) {
134
135
  this.updateCanvas(options);
136
+ Object.assign(this.options, inferOptions(options));
135
137
 
136
138
  if (isInit) {
137
139
  const { data } = options;
138
140
  if (data) this.addData(data);
139
141
  return;
140
142
  }
141
- Object.assign(this.options, options);
142
143
  const { behaviors, combo, data, edge, layout, node, plugins, theme, transforms } = options;
143
144
  if (behaviors) this.setBehaviors(behaviors);
144
145
  if (data) this.setData(data);
@@ -1131,9 +1132,19 @@ export class Graph extends EventEmitter {
1131
1132
  public async render(): Promise<void> {
1132
1133
  await this.prepare();
1133
1134
  emit(this, new GraphLifeCycleEvent(GraphEvent.BEFORE_RENDER));
1134
- const animation = this.context.element!.draw({ type: 'render' });
1135
- await Promise.all([animation?.finished, this.context.layout!.layout()]);
1136
- await this.autoFit();
1135
+
1136
+ if (!this.options.layout) {
1137
+ const animation = this.context.element!.draw({ type: 'render' });
1138
+ await Promise.all([animation?.finished, this.autoFit()]);
1139
+ } else if (!this.rendered && isPreLayout(this.options.layout)) {
1140
+ const animation = await this.context.element!.preLayoutDraw({ type: 'render' });
1141
+ await Promise.all([animation?.finished, this.autoFit()]);
1142
+ } else {
1143
+ const animation = this.context.element!.draw({ type: 'render' });
1144
+ await Promise.all([animation?.finished, this.context.layout!.postLayout()]);
1145
+ await this.autoFit();
1146
+ }
1147
+
1137
1148
  this.rendered = true;
1138
1149
  emit(this, new GraphLifeCycleEvent(GraphEvent.AFTER_RENDER));
1139
1150
  }
@@ -1165,7 +1176,7 @@ export class Graph extends EventEmitter {
1165
1176
  * @apiCategory layout
1166
1177
  */
1167
1178
  public async layout() {
1168
- await this.context.layout!.layout();
1179
+ await this.context.layout!.postLayout();
1169
1180
  }
1170
1181
 
1171
1182
  /**