@antv/g6 5.0.0-beta.6 → 5.0.0-beta.8

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 (151) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/esm/index.d.ts +8 -12
  3. package/esm/index.js +1 -1
  4. package/esm/item/edge.d.ts +21 -1
  5. package/esm/item/edge.js +78 -35
  6. package/esm/item/edge.js.map +1 -1
  7. package/esm/item/item.js +9 -5
  8. package/esm/item/item.js.map +1 -1
  9. package/esm/item/node.js +6 -6
  10. package/esm/item/node.js.map +1 -1
  11. package/esm/runtime/controller/data.d.ts +7 -10
  12. package/esm/runtime/controller/data.js +125 -281
  13. package/esm/runtime/controller/data.js.map +1 -1
  14. package/esm/runtime/controller/item.js +2 -6
  15. package/esm/runtime/controller/item.js.map +1 -1
  16. package/esm/runtime/graph.d.ts +5 -5
  17. package/esm/runtime/graph.js +35 -15
  18. package/esm/runtime/graph.js.map +1 -1
  19. package/esm/stdlib/behavior/create-edge.d.ts +2 -2
  20. package/esm/stdlib/behavior/create-edge.js +17 -16
  21. package/esm/stdlib/behavior/create-edge.js.map +1 -1
  22. package/esm/stdlib/behavior/drag-canvas.d.ts +1 -0
  23. package/esm/stdlib/behavior/drag-canvas.js +20 -12
  24. package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
  25. package/esm/stdlib/behavior/zoom-canvas.d.ts +1 -0
  26. package/esm/stdlib/behavior/zoom-canvas.js +24 -16
  27. package/esm/stdlib/behavior/zoom-canvas.js.map +1 -1
  28. package/esm/stdlib/data/mapNodeSize.d.ts +2 -2
  29. package/esm/stdlib/data/mapNodeSize.js +2 -2
  30. package/esm/stdlib/data/mapNodeSize.js.map +1 -1
  31. package/esm/stdlib/data/transformV4Data.d.ts +2 -2
  32. package/esm/stdlib/data/transformV4Data.js +2 -2
  33. package/esm/stdlib/data/transformV4Data.js.map +1 -1
  34. package/esm/stdlib/data/validateData.d.ts +2 -2
  35. package/esm/stdlib/data/validateData.js +9 -9
  36. package/esm/stdlib/data/validateData.js.map +1 -1
  37. package/esm/stdlib/index.d.ts +7 -7
  38. package/esm/stdlib/index.js +1 -1
  39. package/esm/stdlib/index.js.map +1 -1
  40. package/esm/stdlib/item/edge/base.js +4 -9
  41. package/esm/stdlib/item/edge/base.js.map +1 -1
  42. package/esm/stdlib/plugin/history/item-data-command.js +21 -12
  43. package/esm/stdlib/plugin/history/item-data-command.js.map +1 -1
  44. package/esm/stdlib/plugin/minimap/index.js +8 -2
  45. package/esm/stdlib/plugin/minimap/index.js.map +1 -1
  46. package/esm/stdlib/plugin/snapline/index.d.ts +5 -1
  47. package/esm/stdlib/plugin/snapline/index.js +23 -12
  48. package/esm/stdlib/plugin/snapline/index.js.map +1 -1
  49. package/esm/types/graph.d.ts +3 -3
  50. package/esm/types/view.d.ts +5 -0
  51. package/esm/util/event.d.ts +3 -1
  52. package/esm/util/event.js +8 -1
  53. package/esm/util/event.js.map +1 -1
  54. package/esm/util/item.js +1 -1
  55. package/esm/util/item.js.map +1 -1
  56. package/esm/util/layout.d.ts +11 -0
  57. package/esm/util/layout.js +45 -0
  58. package/esm/util/layout.js.map +1 -1
  59. package/esm/util/point.js +5 -1
  60. package/esm/util/point.js.map +1 -1
  61. package/esm/util/shape.d.ts +1 -1
  62. package/esm/util/shape.js +3 -7
  63. package/esm/util/shape.js.map +1 -1
  64. package/lib/index.d.ts +8 -12
  65. package/lib/index.js +1 -1
  66. package/lib/item/edge.d.ts +21 -1
  67. package/lib/item/edge.js +77 -34
  68. package/lib/item/edge.js.map +1 -1
  69. package/lib/item/item.js +9 -5
  70. package/lib/item/item.js.map +1 -1
  71. package/lib/item/node.js +6 -6
  72. package/lib/item/node.js.map +1 -1
  73. package/lib/runtime/controller/data.d.ts +7 -10
  74. package/lib/runtime/controller/data.js +125 -281
  75. package/lib/runtime/controller/data.js.map +1 -1
  76. package/lib/runtime/controller/item.js +2 -6
  77. package/lib/runtime/controller/item.js.map +1 -1
  78. package/lib/runtime/graph.d.ts +5 -5
  79. package/lib/runtime/graph.js +35 -15
  80. package/lib/runtime/graph.js.map +1 -1
  81. package/lib/stdlib/behavior/create-edge.d.ts +2 -2
  82. package/lib/stdlib/behavior/create-edge.js +17 -16
  83. package/lib/stdlib/behavior/create-edge.js.map +1 -1
  84. package/lib/stdlib/behavior/drag-canvas.d.ts +1 -0
  85. package/lib/stdlib/behavior/drag-canvas.js +20 -12
  86. package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
  87. package/lib/stdlib/behavior/zoom-canvas.d.ts +1 -0
  88. package/lib/stdlib/behavior/zoom-canvas.js +24 -16
  89. package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
  90. package/lib/stdlib/data/mapNodeSize.d.ts +2 -2
  91. package/lib/stdlib/data/mapNodeSize.js +2 -2
  92. package/lib/stdlib/data/mapNodeSize.js.map +1 -1
  93. package/lib/stdlib/data/transformV4Data.d.ts +2 -2
  94. package/lib/stdlib/data/transformV4Data.js +2 -2
  95. package/lib/stdlib/data/transformV4Data.js.map +1 -1
  96. package/lib/stdlib/data/validateData.d.ts +2 -2
  97. package/lib/stdlib/data/validateData.js +9 -9
  98. package/lib/stdlib/data/validateData.js.map +1 -1
  99. package/lib/stdlib/index.d.ts +7 -7
  100. package/lib/stdlib/index.js +1 -1
  101. package/lib/stdlib/index.js.map +1 -1
  102. package/lib/stdlib/item/edge/base.js +4 -9
  103. package/lib/stdlib/item/edge/base.js.map +1 -1
  104. package/lib/stdlib/plugin/history/item-data-command.js +21 -12
  105. package/lib/stdlib/plugin/history/item-data-command.js.map +1 -1
  106. package/lib/stdlib/plugin/minimap/index.js +8 -2
  107. package/lib/stdlib/plugin/minimap/index.js.map +1 -1
  108. package/lib/stdlib/plugin/snapline/index.d.ts +5 -1
  109. package/lib/stdlib/plugin/snapline/index.js +23 -12
  110. package/lib/stdlib/plugin/snapline/index.js.map +1 -1
  111. package/lib/types/graph.d.ts +3 -3
  112. package/lib/types/view.d.ts +5 -0
  113. package/lib/util/event.d.ts +3 -1
  114. package/lib/util/event.js +8 -1
  115. package/lib/util/event.js.map +1 -1
  116. package/lib/util/item.js +1 -1
  117. package/lib/util/item.js.map +1 -1
  118. package/lib/util/layout.d.ts +11 -0
  119. package/lib/util/layout.js +47 -1
  120. package/lib/util/layout.js.map +1 -1
  121. package/lib/util/point.js +5 -1
  122. package/lib/util/point.js.map +1 -1
  123. package/lib/util/shape.d.ts +1 -1
  124. package/lib/util/shape.js +3 -7
  125. package/lib/util/shape.js.map +1 -1
  126. package/package.json +1 -1
  127. package/src/index.ts +1 -1
  128. package/src/item/edge.ts +108 -48
  129. package/src/item/item.ts +13 -9
  130. package/src/item/node.ts +6 -6
  131. package/src/runtime/controller/data.ts +140 -339
  132. package/src/runtime/controller/item.ts +2 -6
  133. package/src/runtime/graph.ts +57 -17
  134. package/src/stdlib/behavior/create-edge.ts +21 -20
  135. package/src/stdlib/behavior/drag-canvas.ts +23 -12
  136. package/src/stdlib/behavior/zoom-canvas.ts +27 -16
  137. package/src/stdlib/data/mapNodeSize.ts +2 -2
  138. package/src/stdlib/data/transformV4Data.ts +2 -2
  139. package/src/stdlib/data/validateData.ts +9 -9
  140. package/src/stdlib/index.ts +1 -1
  141. package/src/stdlib/item/edge/base.ts +4 -8
  142. package/src/stdlib/plugin/history/item-data-command.ts +31 -13
  143. package/src/stdlib/plugin/minimap/index.ts +16 -10
  144. package/src/stdlib/plugin/snapline/index.ts +36 -16
  145. package/src/types/graph.ts +6 -3
  146. package/src/types/view.ts +8 -3
  147. package/src/util/event.ts +14 -1
  148. package/src/util/item.ts +1 -1
  149. package/src/util/layout.ts +45 -0
  150. package/src/util/point.ts +4 -2
  151. package/src/util/shape.ts +6 -7
@@ -428,10 +428,6 @@ export class ItemController {
428
428
  });
429
429
  };
430
430
  const debounceUpdateRelates = debounce(updateRelates, 16, false);
431
- const throttleUpdateRelates = throttle(updateRelates, 16, {
432
- leading: true,
433
- trailing: true,
434
- });
435
431
 
436
432
  Object.values(nodeComboUpdate).forEach((updateObj: any) => {
437
433
  const { isReplace, previous, current, id } = updateObj;
@@ -527,7 +523,7 @@ export class ItemController {
527
523
  nodeRelatedIdsToUpdate.add(edge.id);
528
524
  });
529
525
 
530
- item.onframe = () => throttleUpdateRelates(nodeRelatedIdsToUpdate);
526
+ item.onframe = () => updateRelates(nodeRelatedIdsToUpdate);
531
527
  let statesCache;
532
528
  if (
533
529
  innerModel.data._isCombo &&
@@ -557,7 +553,7 @@ export class ItemController {
557
553
  },
558
554
  500,
559
555
  {
560
- leading: false,
556
+ leading: true,
561
557
  trailing: true,
562
558
  },
563
559
  ),
@@ -56,6 +56,7 @@ import type {
56
56
  import { FitViewRules, GraphTransformOptions } from '../types/view';
57
57
  import { changeRenderer, createCanvas } from '../util/canvas';
58
58
  import { formatPadding } from '../util/shape';
59
+ import { getLayoutBounds } from '../util/layout';
59
60
  import { Plugin as PluginBase } from '../types/plugin';
60
61
  import { ComboMapper, EdgeMapper, NodeMapper } from '../types/spec';
61
62
  import {
@@ -376,12 +377,14 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
376
377
 
377
378
  private formatSpecification(spec: Specification<B, T>) {
378
379
  return {
380
+ ...this.specification,
379
381
  ...spec,
380
382
  optimize: {
381
383
  tileBehavior: 2000,
382
384
  tileBehaviorSize: 1000,
383
385
  tileFirstRender: 10000,
384
386
  tileFirstRenderSize: 1000,
387
+ ...this.specification?.optimize,
385
388
  ...spec.optimize,
386
389
  },
387
390
  };
@@ -479,15 +482,28 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
479
482
  const { autoFit } = this.specification;
480
483
  if (autoFit) {
481
484
  if (autoFit === 'view') {
482
- await this.fitView();
485
+ await this.fitView({ rules: { boundsType: 'layout' } });
483
486
  } else if (autoFit === 'center') {
484
- await this.fitCenter();
487
+ await this.fitCenter('layout');
485
488
  } else {
486
489
  const { type, effectTiming, ...others } = autoFit;
487
490
  if (type === 'view') {
488
- await this.fitView(others as any, effectTiming);
491
+ const { padding, rules } = others as {
492
+ padding: Padding;
493
+ rules: FitViewRules;
494
+ };
495
+ await this.fitView(
496
+ {
497
+ padding,
498
+ rules: {
499
+ ...rules,
500
+ boundsType: 'layout',
501
+ },
502
+ },
503
+ effectTiming,
504
+ );
489
505
  } else if (type === 'center') {
490
- await this.fitCenter(effectTiming);
506
+ await this.fitCenter('layout', effectTiming);
491
507
  } else if (type === 'position') {
492
508
  // TODO: align
493
509
  await this.translateTo((others as any).position, effectTiming);
@@ -713,8 +729,8 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
713
729
  */
714
730
  public async fitView(
715
731
  options?: {
716
- padding: Padding;
717
- rules: FitViewRules;
732
+ padding?: Padding;
733
+ rules?: FitViewRules;
718
734
  },
719
735
  effectTiming?: CameraAnimationOptions,
720
736
  ) {
@@ -722,13 +738,21 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
722
738
  const [top, right, bottom, left] = padding
723
739
  ? formatPadding(padding)
724
740
  : [0, 0, 0, 0];
725
- const { direction = 'both', ratioRule = 'min' } = rules || {};
741
+ const {
742
+ direction = 'both',
743
+ ratioRule = 'min',
744
+ boundsType = 'render',
745
+ } = rules || {};
726
746
 
727
- // Get the bounds of the whole graph.
728
747
  const {
729
748
  center: [graphCenterX, graphCenterY],
730
749
  halfExtents,
731
- } = this.canvas.document.documentElement.getBounds();
750
+ } =
751
+ boundsType === 'render'
752
+ ? // Get the bounds of the whole graph content.
753
+ this.canvas.document.documentElement.getBounds()
754
+ : // Get the bounds of the nodes positions while the graph content is not ready.
755
+ getLayoutBounds(this);
732
756
  const origin = this.canvas.canvas2Viewport({
733
757
  x: graphCenterX,
734
758
  y: graphCenterY,
@@ -779,11 +803,18 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
779
803
  * Fit the graph center to the view center.
780
804
  * @param effectTiming animation configurations
781
805
  */
782
- public async fitCenter(effectTiming?: CameraAnimationOptions) {
783
- // Get the bounds of the whole graph.
806
+ public async fitCenter(
807
+ boundsType: 'render' | 'layout' = 'render',
808
+ effectTiming?: CameraAnimationOptions,
809
+ ) {
784
810
  const {
785
811
  center: [graphCenterX, graphCenterY],
786
- } = this.canvas.document.documentElement.getBounds();
812
+ } =
813
+ boundsType === 'render'
814
+ ? // Get the bounds of the whole graph content.
815
+ this.canvas.document.documentElement.getBounds()
816
+ : // Get the bounds of the nodes positions while the graph content is not ready.
817
+ getLayoutBounds(this);
787
818
  await this.translateTo(
788
819
  this.canvas.canvas2Viewport({ x: graphCenterX, y: graphCenterY }),
789
820
  effectTiming,
@@ -1083,7 +1114,6 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1083
1114
 
1084
1115
  const { graphCore } = this.dataController;
1085
1116
  const { specification } = this.themeController;
1086
- // debugger;
1087
1117
  graphCore.once('changed', (event) => {
1088
1118
  if (!event.changes.length) return;
1089
1119
  const changes = event.changes;
@@ -1126,11 +1156,21 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1126
1156
  public removeData(itemType: ITEM_TYPE, ids: ID | ID[]) {
1127
1157
  const idArr = isArray(ids) ? ids : [ids];
1128
1158
  const data = { nodes: [], edges: [], combos: [] };
1129
- const { userGraphCore, graphCore } = this.dataController;
1159
+ const { graphCore } = this.dataController;
1130
1160
  const { specification } = this.themeController;
1131
- const getItem =
1132
- itemType === 'edge' ? userGraphCore.getEdge : userGraphCore.getNode;
1133
- data[`${itemType}s`] = idArr.map((id) => getItem.bind(userGraphCore)(id));
1161
+ const getItem = itemType === 'edge' ? graphCore.getEdge : graphCore.getNode;
1162
+ const hasItem = itemType === 'edge' ? graphCore.hasEdge : graphCore.hasNode;
1163
+ data[`${itemType}s`] = idArr
1164
+ .map((id) => {
1165
+ if (!hasItem.bind(graphCore)(id)) {
1166
+ console.warn(
1167
+ `The ${itemType} data with id ${id} does not exist. It will be ignored`,
1168
+ );
1169
+ return;
1170
+ }
1171
+ return getItem.bind(graphCore)(id);
1172
+ })
1173
+ .filter(Boolean);
1134
1174
  graphCore.once('changed', (event) => {
1135
1175
  if (!event.changes.length) return;
1136
1176
  const changes = event.changes;
@@ -18,13 +18,11 @@ interface CreateEdgeOptions {
18
18
  * Default to `click`.
19
19
  */
20
20
  trigger: (typeof EVENT_TRIGGERS)[number];
21
-
22
21
  /**
23
- * Keyboard keys serve as auxiliary triggers for this interaction.
22
+ * The assistant secondary key on keyboard. If it is not assigned, the behavior will be triggered when trigger happens.
24
23
  * cound be 'shift', 'ctrl', 'control', 'alt', 'meta', undefined.
25
24
  */
26
- key?: (typeof KEYBOARD_TRIGGERS)[number];
27
-
25
+ secondaryKey?: (typeof KEYBOARD_TRIGGERS)[number];
28
26
  /**
29
27
  * Config of the created edge.
30
28
  */
@@ -54,7 +52,7 @@ interface CreateEdgeOptions {
54
52
 
55
53
  const DEFAULT_OPTIONS: CreateEdgeOptions = {
56
54
  trigger: 'click',
57
- key: undefined,
55
+ secondaryKey: undefined,
58
56
  shouldBegin: () => true,
59
57
  shouldEnd: () => false,
60
58
  edgeConfig: {},
@@ -82,19 +80,22 @@ export class CreateEdge extends Behavior {
82
80
  this.options.trigger = DEFAULT_OPTIONS.trigger;
83
81
  }
84
82
 
85
- if (options.key && !KEYBOARD_TRIGGERS.includes(options.key)) {
83
+ if (
84
+ options.secondaryKey &&
85
+ !KEYBOARD_TRIGGERS.includes(options.secondaryKey)
86
+ ) {
86
87
  warn({
87
- optionName: `create-edge.key`,
88
+ optionName: `create-edge.secondaryKey`,
88
89
  shouldBe: KEYBOARD_TRIGGERS,
89
- now: options.key,
90
+ now: options.secondaryKey,
90
91
  scope: 'behavior',
91
92
  });
92
- this.options.key = DEFAULT_OPTIONS.key;
93
+ this.options.secondaryKey = DEFAULT_OPTIONS.secondaryKey;
93
94
  }
94
95
  }
95
96
 
96
97
  getEvents = () => {
97
- const { trigger, key } = this.options;
98
+ const { trigger, secondaryKey } = this.options;
98
99
  const [CLICK_NAME] = EVENT_TRIGGERS;
99
100
 
100
101
  const triggerEvents =
@@ -113,7 +114,7 @@ export class CreateEdge extends Behavior {
113
114
  drop: this.onDrop,
114
115
  };
115
116
 
116
- const keyboardEvents = key
117
+ const keyboardEvents = secondaryKey
117
118
  ? {
118
119
  keydown: this.onKeyDown,
119
120
  keyup: this.onKeyUp,
@@ -127,7 +128,7 @@ export class CreateEdge extends Behavior {
127
128
  };
128
129
 
129
130
  handleCreateEdge = (e: IG6GraphEvent) => {
130
- if (this.options.key && !this.isKeyDown) {
131
+ if (this.options.secondaryKey && !this.isKeyDown) {
131
132
  return;
132
133
  }
133
134
 
@@ -143,7 +144,7 @@ export class CreateEdge extends Behavior {
143
144
 
144
145
  if (addingEdge) {
145
146
  // create edge end, add the actual edge to graph and remove the virtual edge and node
146
- graph.addData('edge', {
147
+ const actualEdge = graph.addData('edge', {
147
148
  id: generateEdgeID(addingEdge.source, currentNodeId),
148
149
  source: addingEdge.source,
149
150
  target: currentNodeId,
@@ -154,7 +155,7 @@ export class CreateEdge extends Behavior {
154
155
  },
155
156
  });
156
157
  if (createActualEventName) {
157
- graph.emit(createActualEventName, { edge: addingEdge });
158
+ graph.emit(createActualEventName, { edge: actualEdge });
158
159
  }
159
160
  this.cancelCreating();
160
161
 
@@ -192,8 +193,8 @@ export class CreateEdge extends Behavior {
192
193
  onDrop = async (e: IG6GraphEvent) => {
193
194
  const { addingEdge, options, graph } = this;
194
195
 
195
- const { edgeConfig, key, createActualEventName } = options;
196
- if (key && !this.isKeyDown) {
196
+ const { edgeConfig, secondaryKey, createActualEventName } = options;
197
+ if (secondaryKey && !this.isKeyDown) {
197
198
  return;
198
199
  }
199
200
 
@@ -218,7 +219,7 @@ export class CreateEdge extends Behavior {
218
219
  return;
219
220
  }
220
221
 
221
- graph.addData('edge', {
222
+ const actualEdge = graph.addData('edge', {
222
223
  id: generateEdgeID(addingEdge.source, dropId),
223
224
  source: addingEdge.source,
224
225
  target: dropId,
@@ -228,14 +229,14 @@ export class CreateEdge extends Behavior {
228
229
  },
229
230
  });
230
231
  if (createActualEventName) {
231
- graph.emit(createActualEventName, { edge: addingEdge });
232
+ graph.emit(createActualEventName, { edge: actualEdge });
232
233
  }
233
234
  this.cancelCreating();
234
235
  };
235
236
 
236
237
  updateEndPoint = (e: IG6GraphEvent) => {
237
238
  const { options, graph, addingEdge, isKeyDown } = this;
238
- if (options.key && !isKeyDown) {
239
+ if (options.secondaryKey && !isKeyDown) {
239
240
  return;
240
241
  }
241
242
 
@@ -281,7 +282,7 @@ export class CreateEdge extends Behavior {
281
282
  return;
282
283
  }
283
284
 
284
- if (code.toLocaleLowerCase() === this.options.key) {
285
+ if (code.toLocaleLowerCase() === this.options.secondaryKey) {
285
286
  this.isKeyDown = true;
286
287
  }
287
288
  };
@@ -74,6 +74,7 @@ export class DragCanvas extends Behavior {
74
74
  private disableKeydown: boolean;
75
75
  private hiddenEdgeIds: ID[];
76
76
  private hiddenNodeIds: ID[];
77
+ private tileRequestId?: number;
77
78
 
78
79
  constructor(options: Partial<DragCanvasOptions>) {
79
80
  const finalOptions = Object.assign({}, DEFAULT_OPTIONS, options);
@@ -136,7 +137,10 @@ export class DragCanvas extends Behavior {
136
137
 
137
138
  const { tileBehavior: graphBehaviorOptimize, tileBehaviorSize = 1000 } =
138
139
  graph.getSpecification().optimize || {};
139
- const optimize = this.options.enableOptimize || graphBehaviorOptimize;
140
+ const optimize =
141
+ this.options.enableOptimize !== undefined
142
+ ? this.options.enableOptimize
143
+ : graphBehaviorOptimize;
140
144
  const shouldOptimize = isNumber(optimize)
141
145
  ? graph.getAllNodesData().length > optimize
142
146
  : optimize;
@@ -150,7 +154,6 @@ export class DragCanvas extends Behavior {
150
154
  .getAllNodesData()
151
155
  .map((node) => node.id)
152
156
  .filter((id) => graph.getItemVisible(id) === true);
153
- let requestId;
154
157
  const hiddenIds = [...this.hiddenNodeIds];
155
158
  const sectionNum = Math.ceil(hiddenIds.length / tileBehaviorSize);
156
159
  const sections = Array.from({ length: sectionNum }, (v, i) =>
@@ -160,17 +163,18 @@ export class DragCanvas extends Behavior {
160
163
  ),
161
164
  );
162
165
  const update = () => {
163
- if (!sections.length) {
164
- cancelAnimationFrame(requestId);
166
+ if (!sections.length && this.tileRequestId) {
167
+ cancelAnimationFrame(this.tileRequestId);
168
+ this.tileRequestId = undefined;
165
169
  return;
166
170
  }
167
171
  const section = sections.shift();
168
172
  graph.executeWithNoStack(() => {
169
173
  graph.hideItem(section, false, true);
170
174
  });
171
- requestId = requestAnimationFrame(update);
175
+ this.tileRequestId = requestAnimationFrame(update);
172
176
  };
173
- requestId = requestAnimationFrame(update);
177
+ this.tileRequestId = requestAnimationFrame(update);
174
178
  }
175
179
  }
176
180
 
@@ -264,14 +268,20 @@ export class DragCanvas extends Behavior {
264
268
  const { graph, hiddenNodeIds, hiddenEdgeIds = [] } = this;
265
269
  const { tileBehavior: graphBehaviorOptimize, tileBehaviorSize = 1000 } =
266
270
  graph.getSpecification().optimize || {};
267
- const optimize = this.options.enableOptimize || graphBehaviorOptimize;
271
+ const optimize =
272
+ this.options.enableOptimize !== undefined
273
+ ? this.options.enableOptimize
274
+ : graphBehaviorOptimize;
268
275
  const shouldOptimize = isNumber(optimize)
269
276
  ? graph.getAllNodesData().length > optimize
270
277
  : optimize;
271
278
 
272
279
  if (shouldOptimize) {
280
+ if (this.tileRequestId) {
281
+ cancelAnimationFrame(this.tileRequestId);
282
+ this.tileRequestId = undefined;
283
+ }
273
284
  if (hiddenNodeIds) {
274
- let requestId;
275
285
  const hiddenIds = [...hiddenNodeIds, ...hiddenEdgeIds];
276
286
  const sectionNum = Math.ceil(hiddenIds.length / tileBehaviorSize);
277
287
  const sections = Array.from({ length: sectionNum }, (v, i) =>
@@ -281,16 +291,17 @@ export class DragCanvas extends Behavior {
281
291
  ),
282
292
  );
283
293
  const update = () => {
284
- if (!sections.length) {
285
- cancelAnimationFrame(requestId);
294
+ if (!sections.length && this.tileRequestId) {
295
+ cancelAnimationFrame(this.tileRequestId);
296
+ this.tileRequestId = undefined;
286
297
  return;
287
298
  }
288
299
  graph.startHistoryBatch();
289
300
  graph.showItem(sections.shift(), false);
290
301
  graph.stopHistoryBatch();
291
- requestId = requestAnimationFrame(update);
302
+ this.tileRequestId = requestAnimationFrame(update);
292
303
  };
293
- requestId = requestAnimationFrame(update);
304
+ this.tileRequestId = requestAnimationFrame(update);
294
305
  }
295
306
  }
296
307
  }
@@ -76,6 +76,7 @@ export class ZoomCanvas extends Behavior {
76
76
  private hiddenEdgeIds: ID[];
77
77
  private hiddenNodeIds: ID[];
78
78
  private zoomTimer: ReturnType<typeof setTimeout>;
79
+ private tileRequestId?: number;
79
80
 
80
81
  constructor(options: Partial<ZoomCanvasOptions>) {
81
82
  const finalOptions = Object.assign({}, DEFAULT_OPTIONS, options);
@@ -117,11 +118,14 @@ export class ZoomCanvas extends Behavior {
117
118
  const { graph } = this;
118
119
  const { tileBehavior: graphBehaviorOptimize, tileBehaviorSize = 1000 } =
119
120
  graph.getSpecification().optimize || {};
120
- const optimize = this.options.enableOptimize || graphBehaviorOptimize;
121
- const shouldOptimzie = isNumber(optimize)
121
+ const optimize =
122
+ this.options.enableOptimize !== undefined
123
+ ? this.options.enableOptimize
124
+ : graphBehaviorOptimize;
125
+ const shouldOptimze = isNumber(optimize)
122
126
  ? graph.getAllNodesData().length > optimize
123
127
  : optimize;
124
- if (shouldOptimzie) {
128
+ if (shouldOptimze) {
125
129
  this.hiddenEdgeIds = graph
126
130
  .getAllEdgesData()
127
131
  .map((edge) => edge.id)
@@ -131,7 +135,6 @@ export class ZoomCanvas extends Behavior {
131
135
  .map((node) => node.id)
132
136
  .filter((id) => graph.getItemVisible(id) === true);
133
137
 
134
- let requestId;
135
138
  const hiddenIds = [...this.hiddenNodeIds];
136
139
  const sectionNum = Math.ceil(hiddenIds.length / tileBehaviorSize);
137
140
  const sections = Array.from({ length: sectionNum }, (v, i) =>
@@ -141,17 +144,18 @@ export class ZoomCanvas extends Behavior {
141
144
  ),
142
145
  );
143
146
  const update = () => {
144
- if (!sections.length) {
145
- cancelAnimationFrame(requestId);
147
+ if (!sections.length && this.tileRequestId) {
148
+ cancelAnimationFrame(this.tileRequestId);
149
+ this.tileRequestId = undefined;
146
150
  return;
147
151
  }
148
152
  const section = sections.shift();
149
153
  graph.startHistoryBatch();
150
154
  graph.hideItem(section, false, true);
151
155
  graph.stopHistoryBatch();
152
- requestId = requestAnimationFrame(update);
156
+ this.tileRequestId = requestAnimationFrame(update);
153
157
  };
154
- requestId = requestAnimationFrame(update);
158
+ this.tileRequestId = requestAnimationFrame(update);
155
159
  }
156
160
  }
157
161
 
@@ -159,14 +163,20 @@ export class ZoomCanvas extends Behavior {
159
163
  const { graph, hiddenEdgeIds = [], hiddenNodeIds } = this;
160
164
  const { tileBehavior: graphBehaviorOptimize, tileBehaviorSize = 1000 } =
161
165
  graph.getSpecification().optimize || {};
162
- const optimize = this.options.enableOptimize || graphBehaviorOptimize;
163
- const shouldOptimzie = isNumber(optimize)
166
+ const optimize =
167
+ this.options.enableOptimize !== undefined
168
+ ? this.options.enableOptimize
169
+ : graphBehaviorOptimize;
170
+ const shouldOptimze = isNumber(optimize)
164
171
  ? graph.getAllNodesData().length > optimize
165
172
  : optimize;
166
173
  this.zooming = false;
167
- if (shouldOptimzie) {
174
+ if (shouldOptimze) {
175
+ if (this.tileRequestId) {
176
+ cancelAnimationFrame(this.tileRequestId);
177
+ this.tileRequestId = undefined;
178
+ }
168
179
  if (hiddenNodeIds) {
169
- let requestId;
170
180
  const hiddenIds = [...hiddenNodeIds, ...hiddenEdgeIds];
171
181
  const sectionNum = Math.ceil(hiddenIds.length / tileBehaviorSize);
172
182
  const sections = Array.from({ length: sectionNum }, (v, i) =>
@@ -176,16 +186,17 @@ export class ZoomCanvas extends Behavior {
176
186
  ),
177
187
  );
178
188
  const update = () => {
179
- if (!sections.length) {
180
- cancelAnimationFrame(requestId);
189
+ if (!sections.length && this.tileRequestId) {
190
+ cancelAnimationFrame(this.tileRequestId);
191
+ this.tileRequestId = undefined;
181
192
  return;
182
193
  }
183
194
  graph.executeWithNoStack(() => {
184
195
  graph.showItem(sections.shift(), false);
185
196
  });
186
- requestId = requestAnimationFrame(update);
197
+ this.tileRequestId = requestAnimationFrame(update);
187
198
  };
188
- requestId = requestAnimationFrame(update);
199
+ this.tileRequestId = requestAnimationFrame(update);
189
200
  }
190
201
  }
191
202
  this.hiddenEdgeIds = [];
@@ -9,7 +9,7 @@ import {
9
9
  /**
10
10
  * Validate and format the graph data.
11
11
  * @param data input user data.
12
- * @param userGraphCore the graph core stores the previous data.
12
+ * @param graphCore the graph core stores the previous data.
13
13
  * @returns formatted data.
14
14
  */
15
15
  export const MapNodeSize = (
@@ -18,7 +18,7 @@ export const MapNodeSize = (
18
18
  field?: string;
19
19
  range?: [number, number];
20
20
  } = {},
21
- userGraphCore?: GraphCore,
21
+ graphCore?: GraphCore,
22
22
  ): GraphData => {
23
23
  const { field, range = [8, 40] } = options;
24
24
  if (!field) return data;
@@ -10,13 +10,13 @@ import {
10
10
  /**
11
11
  * Validate and format the graph data.
12
12
  * @param data input user data.
13
- * @param userGraphCore the graph core stores the previous data.
13
+ * @param graphCore the graph core stores the previous data.
14
14
  * @returns formatted data.
15
15
  */
16
16
  export const TransformV4Data = (
17
17
  data: GraphData,
18
18
  options = {},
19
- userGraphCore?: GraphCore,
19
+ graphCore?: GraphCore,
20
20
  ): GraphData => {
21
21
  const { nodes = [], edges = [], combos = [] } = data;
22
22
  const formattedNodes = nodes.map((node: any) => {
@@ -10,13 +10,13 @@ import {
10
10
  /**
11
11
  * Validate and format the graph data.
12
12
  * @param data input user data.
13
- * @param userGraphCore the graph core stores the previous data.
13
+ * @param graphCore the graph core stores the previous data.
14
14
  * @returns formatted data.
15
15
  */
16
16
  export const ValidateData = (
17
17
  data: GraphData,
18
18
  options = {},
19
- userGraphCore?: GraphCore,
19
+ graphCore?: GraphCore,
20
20
  ): GraphData => {
21
21
  const { nodes, edges, combos } = data;
22
22
  const idMap = new Map();
@@ -64,7 +64,7 @@ export const ValidateData = (
64
64
  if (
65
65
  parentId !== undefined &&
66
66
  !comboIdMap.has(parentId) &&
67
- (!userGraphCore || !userGraphCore.hasNode(parentId))
67
+ (!graphCore || !graphCore.hasNode(parentId))
68
68
  ) {
69
69
  console.error(
70
70
  `The parentId of combo with id ${combo.id} will be removed since it is not exist in combos.`,
@@ -80,9 +80,9 @@ export const ValidateData = (
80
80
  if (
81
81
  parentId !== undefined &&
82
82
  !comboIdMap.has(parentId) &&
83
- (!userGraphCore || !userGraphCore.hasNode(parentId))
83
+ (!graphCore || !graphCore.hasNode(parentId))
84
84
  ) {
85
- // TODO: parentId is a node in userGraphCore
85
+ // TODO: parentId is a node in graphCore
86
86
  console.error(
87
87
  `The parentId of node with id ${node.id} will be removed since it is not exist in combos.`,
88
88
  );
@@ -100,8 +100,8 @@ export const ValidateData = (
100
100
  let { source, target } = edge;
101
101
  if (!idAndDataCheck(edge, 'edge', true)) return false;
102
102
 
103
- if (userGraphCore?.hasEdge(id)) {
104
- const existEdge = userGraphCore?.getEdge(id);
103
+ if (graphCore?.hasEdge(id)) {
104
+ const existEdge = graphCore?.getEdge(id);
105
105
  if (source === undefined) source = existEdge.source;
106
106
  if (target === undefined) target = existEdge.target;
107
107
  }
@@ -121,7 +121,7 @@ export const ValidateData = (
121
121
  if (
122
122
  !nodeIdMap.has(source) &&
123
123
  !comboIdMap.has(source) &&
124
- (!userGraphCore || !userGraphCore.hasNode(source))
124
+ (!graphCore || !graphCore.hasNode(source))
125
125
  ) {
126
126
  console.error(
127
127
  `The edge with id ${id} will be ignored since its source ${source} is not existed in nodes and combos.`,
@@ -131,7 +131,7 @@ export const ValidateData = (
131
131
  if (
132
132
  !nodeIdMap.has(target) &&
133
133
  !comboIdMap.has(target) &&
134
- (!userGraphCore || !userGraphCore.hasNode(target))
134
+ (!graphCore || !graphCore.hasNode(target))
135
135
  ) {
136
136
  console.error(
137
137
  `The edge with id ${id} will be ignored since its target ${target} is not existed in nodes and combos.`,
@@ -127,7 +127,6 @@ const stdLib = {
127
127
  'collapse-expand-combo': CollapseExpandCombo,
128
128
  'collapse-expand-tree': CollapseExpandTree,
129
129
  'click-select': ClickSelect,
130
- 'scroll-canvas': ScrollCanvas,
131
130
  },
132
131
  plugins: {
133
132
  history: History,
@@ -276,6 +275,7 @@ const Extensions = {
276
275
  DragCombo,
277
276
  CreateEdge,
278
277
  ShortcutsCall,
278
+ ScrollCanvas,
279
279
  // plugins
280
280
  BasePlugin,
281
281
  History,
@@ -686,12 +686,9 @@ export abstract class BaseEdge {
686
686
  resultStyle[`${markerField}Offset`] = 0;
687
687
  return;
688
688
  }
689
- let arrowStyle = {} as ArrowStyle;
690
- if (isBoolean(arrowConfig)) {
691
- arrowStyle = { ...DEFAULT_ARROW_CONFIG } as ArrowStyle;
692
- } else {
693
- arrowStyle = arrowConfig;
694
- }
689
+ const arrowStyle = isBoolean(arrowConfig)
690
+ ? ({ ...DEFAULT_ARROW_CONFIG } as ArrowStyle)
691
+ : arrowConfig;
695
692
  const {
696
693
  type = 'triangle',
697
694
  width = 10,
@@ -700,14 +697,13 @@ export abstract class BaseEdge {
700
697
  offset = 0,
701
698
  ...others
702
699
  } = arrowStyle;
703
- const path = propPath ? propPath : getArrowPath(type, width, height);
704
700
  resultStyle[markerField] = this.upsertShape(
705
701
  'path',
706
702
  `${markerField}Shape`,
707
703
  {
708
704
  ...bodyStyle,
709
705
  fill: type === 'simple' ? '' : bodyStyle.stroke,
710
- path,
706
+ path: propPath || getArrowPath(type, width, height),
711
707
  anchor: '0.5 0.5',
712
708
  transformOrigin: 'center',
713
709
  ...others,