@antv/g6 5.0.0-beta.3 → 5.0.0-beta.5

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 (201) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/esm/constant/shape.d.ts +2 -0
  3. package/esm/index.d.ts +4 -1
  4. package/esm/index.js +1 -1
  5. package/esm/item/edge.d.ts +1 -0
  6. package/esm/item/edge.js +3 -1
  7. package/esm/item/edge.js.map +1 -1
  8. package/esm/item/item.d.ts +3 -2
  9. package/esm/item/item.js +12 -6
  10. package/esm/item/item.js.map +1 -1
  11. package/esm/item/node.d.ts +1 -0
  12. package/esm/item/node.js +11 -4
  13. package/esm/item/node.js.map +1 -1
  14. package/esm/runtime/controller/item.js +252 -148
  15. package/esm/runtime/controller/item.js.map +1 -1
  16. package/esm/runtime/graph.d.ts +16 -14
  17. package/esm/runtime/graph.js +66 -28
  18. package/esm/runtime/graph.js.map +1 -1
  19. package/esm/stdlib/behavior/activate-relations.js +2 -2
  20. package/esm/stdlib/behavior/activate-relations.js.map +1 -1
  21. package/esm/stdlib/behavior/click-select.js +1 -1
  22. package/esm/stdlib/behavior/click-select.js.map +1 -1
  23. package/esm/stdlib/behavior/drag-canvas.js +50 -27
  24. package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
  25. package/esm/stdlib/behavior/drag-combo.js +8 -8
  26. package/esm/stdlib/behavior/drag-combo.js.map +1 -1
  27. package/esm/stdlib/behavior/drag-node.js +10 -10
  28. package/esm/stdlib/behavior/drag-node.js.map +1 -1
  29. package/esm/stdlib/behavior/zoom-canvas.js +47 -24
  30. package/esm/stdlib/behavior/zoom-canvas.js.map +1 -1
  31. package/esm/stdlib/index.d.ts +3 -0
  32. package/esm/stdlib/index.js +12 -9
  33. package/esm/stdlib/index.js.map +1 -1
  34. package/esm/stdlib/item/edge/base.d.ts +1 -1
  35. package/esm/stdlib/item/edge/base.js +13 -4
  36. package/esm/stdlib/item/edge/base.js.map +1 -1
  37. package/esm/stdlib/item/node/base.d.ts +1 -1
  38. package/esm/stdlib/item/node/base.js +18 -26
  39. package/esm/stdlib/item/node/base.js.map +1 -1
  40. package/esm/stdlib/item/node/diamond.js +1 -1
  41. package/esm/stdlib/item/node/ellipse.js +2 -2
  42. package/esm/stdlib/item/node/hexagon.js +6 -2
  43. package/esm/stdlib/item/node/hexagon.js.map +1 -1
  44. package/esm/stdlib/item/node/image.d.ts +40 -0
  45. package/esm/stdlib/item/node/image.js +110 -0
  46. package/esm/stdlib/item/node/image.js.map +1 -0
  47. package/esm/stdlib/item/node/index.d.ts +1 -0
  48. package/esm/stdlib/item/node/index.js +1 -0
  49. package/esm/stdlib/item/node/index.js.map +1 -1
  50. package/esm/stdlib/plugin/history/combo-command.js +2 -2
  51. package/esm/stdlib/plugin/history/combo-command.js.map +1 -1
  52. package/esm/stdlib/plugin/history/index.d.ts +10 -10
  53. package/esm/stdlib/plugin/history/index.js +14 -14
  54. package/esm/stdlib/plugin/history/index.js.map +1 -1
  55. package/esm/stdlib/plugin/history/item-data-command.js +4 -4
  56. package/esm/stdlib/plugin/history/item-data-command.js.map +1 -1
  57. package/esm/stdlib/plugin/history/layer-updated-command.js +2 -2
  58. package/esm/stdlib/plugin/history/layer-updated-command.js.map +1 -1
  59. package/esm/stdlib/plugin/history/state-updated-command.js +1 -1
  60. package/esm/stdlib/plugin/history/state-updated-command.js.map +1 -1
  61. package/esm/stdlib/plugin/history/visibility-updated-command.js +2 -2
  62. package/esm/stdlib/plugin/history/visibility-updated-command.js.map +1 -1
  63. package/esm/stdlib/plugin/index.d.ts +1 -0
  64. package/esm/stdlib/plugin/index.js +1 -0
  65. package/esm/stdlib/plugin/index.js.map +1 -1
  66. package/esm/stdlib/plugin/snapline/index.d.ts +163 -0
  67. package/esm/stdlib/plugin/snapline/index.js +1052 -0
  68. package/esm/stdlib/plugin/snapline/index.js.map +1 -0
  69. package/esm/stdlib/plugin/types.d.ts +1 -0
  70. package/esm/stdlib/theme/dark.js +42 -2
  71. package/esm/stdlib/theme/dark.js.map +1 -1
  72. package/esm/stdlib/theme/light.js +4 -4
  73. package/esm/types/graph.d.ts +14 -14
  74. package/esm/types/hook.d.ts +6 -0
  75. package/esm/types/item.d.ts +6 -0
  76. package/esm/types/item.js.map +1 -1
  77. package/esm/types/spec.d.ts +13 -0
  78. package/esm/util/bbox.d.ts +16 -1
  79. package/esm/util/bbox.js +29 -0
  80. package/esm/util/bbox.js.map +1 -1
  81. package/esm/util/shape.js +2 -2
  82. package/esm/util/shape.js.map +1 -1
  83. package/lib/constant/shape.d.ts +2 -0
  84. package/lib/index.d.ts +4 -1
  85. package/lib/index.js +1 -1
  86. package/lib/item/edge.d.ts +1 -0
  87. package/lib/item/edge.js +3 -1
  88. package/lib/item/edge.js.map +1 -1
  89. package/lib/item/item.d.ts +3 -2
  90. package/lib/item/item.js +12 -6
  91. package/lib/item/item.js.map +1 -1
  92. package/lib/item/node.d.ts +1 -0
  93. package/lib/item/node.js +11 -4
  94. package/lib/item/node.js.map +1 -1
  95. package/lib/runtime/controller/item.js +251 -147
  96. package/lib/runtime/controller/item.js.map +1 -1
  97. package/lib/runtime/graph.d.ts +16 -14
  98. package/lib/runtime/graph.js +66 -28
  99. package/lib/runtime/graph.js.map +1 -1
  100. package/lib/stdlib/behavior/activate-relations.js +2 -2
  101. package/lib/stdlib/behavior/activate-relations.js.map +1 -1
  102. package/lib/stdlib/behavior/click-select.js +1 -1
  103. package/lib/stdlib/behavior/click-select.js.map +1 -1
  104. package/lib/stdlib/behavior/drag-canvas.js +50 -27
  105. package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
  106. package/lib/stdlib/behavior/drag-combo.js +8 -8
  107. package/lib/stdlib/behavior/drag-combo.js.map +1 -1
  108. package/lib/stdlib/behavior/drag-node.js +10 -10
  109. package/lib/stdlib/behavior/drag-node.js.map +1 -1
  110. package/lib/stdlib/behavior/zoom-canvas.js +47 -24
  111. package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
  112. package/lib/stdlib/index.d.ts +3 -0
  113. package/lib/stdlib/index.js +12 -9
  114. package/lib/stdlib/index.js.map +1 -1
  115. package/lib/stdlib/item/edge/base.d.ts +1 -1
  116. package/lib/stdlib/item/edge/base.js +13 -4
  117. package/lib/stdlib/item/edge/base.js.map +1 -1
  118. package/lib/stdlib/item/node/base.d.ts +1 -1
  119. package/lib/stdlib/item/node/base.js +18 -26
  120. package/lib/stdlib/item/node/base.js.map +1 -1
  121. package/lib/stdlib/item/node/diamond.js +1 -1
  122. package/lib/stdlib/item/node/ellipse.js +2 -2
  123. package/lib/stdlib/item/node/hexagon.js +6 -2
  124. package/lib/stdlib/item/node/hexagon.js.map +1 -1
  125. package/lib/stdlib/item/node/image.d.ts +40 -0
  126. package/lib/stdlib/item/node/image.js +114 -0
  127. package/lib/stdlib/item/node/image.js.map +1 -0
  128. package/lib/stdlib/item/node/index.d.ts +1 -0
  129. package/lib/stdlib/item/node/index.js +1 -0
  130. package/lib/stdlib/item/node/index.js.map +1 -1
  131. package/lib/stdlib/plugin/history/combo-command.js +2 -2
  132. package/lib/stdlib/plugin/history/combo-command.js.map +1 -1
  133. package/lib/stdlib/plugin/history/index.d.ts +10 -10
  134. package/lib/stdlib/plugin/history/index.js +14 -14
  135. package/lib/stdlib/plugin/history/index.js.map +1 -1
  136. package/lib/stdlib/plugin/history/item-data-command.js +4 -4
  137. package/lib/stdlib/plugin/history/item-data-command.js.map +1 -1
  138. package/lib/stdlib/plugin/history/layer-updated-command.js +2 -2
  139. package/lib/stdlib/plugin/history/layer-updated-command.js.map +1 -1
  140. package/lib/stdlib/plugin/history/state-updated-command.js +1 -1
  141. package/lib/stdlib/plugin/history/state-updated-command.js.map +1 -1
  142. package/lib/stdlib/plugin/history/visibility-updated-command.js +2 -2
  143. package/lib/stdlib/plugin/history/visibility-updated-command.js.map +1 -1
  144. package/lib/stdlib/plugin/index.d.ts +1 -0
  145. package/lib/stdlib/plugin/index.js +1 -0
  146. package/lib/stdlib/plugin/index.js.map +1 -1
  147. package/lib/stdlib/plugin/snapline/index.d.ts +163 -0
  148. package/lib/stdlib/plugin/snapline/index.js +1056 -0
  149. package/lib/stdlib/plugin/snapline/index.js.map +1 -0
  150. package/lib/stdlib/plugin/types.d.ts +1 -0
  151. package/lib/stdlib/theme/dark.js +42 -2
  152. package/lib/stdlib/theme/dark.js.map +1 -1
  153. package/lib/stdlib/theme/light.js +4 -4
  154. package/lib/types/graph.d.ts +14 -14
  155. package/lib/types/hook.d.ts +6 -0
  156. package/lib/types/item.d.ts +6 -0
  157. package/lib/types/item.js.map +1 -1
  158. package/lib/types/spec.d.ts +13 -0
  159. package/lib/util/bbox.d.ts +16 -1
  160. package/lib/util/bbox.js +32 -1
  161. package/lib/util/bbox.js.map +1 -1
  162. package/lib/util/shape.js +2 -2
  163. package/lib/util/shape.js.map +1 -1
  164. package/package.json +2 -2
  165. package/src/index.ts +1 -1
  166. package/src/item/edge.ts +4 -1
  167. package/src/item/item.ts +11 -6
  168. package/src/item/node.ts +18 -10
  169. package/src/runtime/controller/item.ts +212 -66
  170. package/src/runtime/graph.ts +91 -29
  171. package/src/stdlib/behavior/activate-relations.ts +2 -2
  172. package/src/stdlib/behavior/click-select.ts +1 -1
  173. package/src/stdlib/behavior/drag-canvas.ts +65 -27
  174. package/src/stdlib/behavior/drag-combo.ts +8 -8
  175. package/src/stdlib/behavior/drag-node.ts +10 -10
  176. package/src/stdlib/behavior/zoom-canvas.ts +60 -24
  177. package/src/stdlib/index.ts +12 -7
  178. package/src/stdlib/item/edge/base.ts +13 -5
  179. package/src/stdlib/item/node/base.ts +24 -29
  180. package/src/stdlib/item/node/diamond.ts +1 -1
  181. package/src/stdlib/item/node/ellipse.ts +2 -2
  182. package/src/stdlib/item/node/hexagon.ts +6 -2
  183. package/src/stdlib/item/node/image.ts +190 -0
  184. package/src/stdlib/item/node/index.ts +1 -0
  185. package/src/stdlib/plugin/history/combo-command.ts +2 -2
  186. package/src/stdlib/plugin/history/index.ts +14 -14
  187. package/src/stdlib/plugin/history/item-data-command.ts +4 -4
  188. package/src/stdlib/plugin/history/layer-updated-command.ts +2 -2
  189. package/src/stdlib/plugin/history/state-updated-command.ts +1 -1
  190. package/src/stdlib/plugin/history/visibility-updated-command.ts +2 -2
  191. package/src/stdlib/plugin/index.ts +1 -0
  192. package/src/stdlib/plugin/snapline/index.ts +1277 -0
  193. package/src/stdlib/plugin/types.ts +1 -0
  194. package/src/stdlib/theme/dark.ts +66 -2
  195. package/src/stdlib/theme/light.ts +4 -4
  196. package/src/types/graph.ts +22 -17
  197. package/src/types/hook.ts +6 -0
  198. package/src/types/item.ts +10 -0
  199. package/src/types/spec.ts +13 -0
  200. package/src/util/bbox.ts +38 -1
  201. package/src/util/shape.ts +2 -2
@@ -26,7 +26,7 @@ import type {
26
26
  import type { CameraAnimationOptions } from '../types/animate';
27
27
  import type { BehaviorOptionsOf, BehaviorRegistry } from '../types/behavior';
28
28
  import type { ComboDisplayModel, ComboModel } from '../types/combo';
29
- import type { Padding, Point } from '../types/common';
29
+ import type { Bounds, Padding, Point } from '../types/common';
30
30
  import type { DataChangeType, DataConfig, GraphCore } from '../types/data';
31
31
  import type { EdgeDisplayModel, EdgeModel, EdgeModelData } from '../types/edge';
32
32
  import type { StackType } from '../types/history';
@@ -101,7 +101,11 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
101
101
  constructor(spec: Specification<B, T>) {
102
102
  super();
103
103
 
104
- this.specification = Object.assign({}, this.defaultSpecification, spec);
104
+ this.specification = Object.assign(
105
+ {},
106
+ this.defaultSpecification,
107
+ this.formatSpecification(spec),
108
+ );
105
109
  this.initHooks();
106
110
  this.initCanvas();
107
111
  this.initControllers();
@@ -356,11 +360,29 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
356
360
  };
357
361
  }
358
362
 
363
+ private formatSpecification(spec: Specification<B, T>) {
364
+ return {
365
+ ...spec,
366
+ optimize: {
367
+ tileBehavior: 2000,
368
+ tileBehaviorSize: 1000,
369
+ tileFirstRender: 10000,
370
+ tileFirstRenderSize: 1000,
371
+ ...spec.optimize,
372
+ },
373
+ };
374
+ }
375
+
359
376
  /**
360
377
  * Update the specs(configurations).
361
378
  */
362
379
  public updateSpecification(spec: Specification<B, T>): Specification<B, T> {
363
- return Object.assign(this.specification, spec);
380
+ const newSpec = Object.assign(
381
+ this.specification,
382
+ this.formatSpecification(spec),
383
+ );
384
+ // TODO: update something
385
+ return newSpec;
364
386
  }
365
387
  /**
366
388
  * Update the theme specs (configurations).
@@ -398,12 +420,18 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
398
420
  * @group Data
399
421
  */
400
422
  public async read(data: DataConfig) {
423
+ const { tileFirstRender, tileFirstRenderSize } =
424
+ this.specification.optimize || {};
401
425
  this.hooks.datachange.emit({ data, type: 'replace' });
402
426
  const emitRender = async () => {
403
- this.hooks.render.emit({
427
+ await this.hooks.render.emitLinearAsync({
404
428
  graphCore: this.dataController.graphCore,
405
429
  theme: this.themeController.specification,
406
430
  transientCanvas: this.transientCanvas,
431
+ tileOptimize: {
432
+ tileFirstRender,
433
+ tileFirstRenderSize,
434
+ },
407
435
  });
408
436
  this.emit('afterrender');
409
437
 
@@ -452,11 +480,17 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
452
480
  data: DataConfig,
453
481
  type: 'replace' | 'mergeReplace' = 'mergeReplace',
454
482
  ) {
483
+ const { tileFirstRender, tileFirstRenderSize } =
484
+ this.specification.optimize || {};
455
485
  this.hooks.datachange.emit({ data, type });
456
486
  this.hooks.render.emit({
457
487
  graphCore: this.dataController.graphCore,
458
488
  theme: this.themeController.specification,
459
489
  transientCanvas: this.transientCanvas,
490
+ tileOptimize: {
491
+ tileFirstRender,
492
+ tileFirstRenderSize,
493
+ },
460
494
  });
461
495
  this.emit('afterrender');
462
496
 
@@ -468,7 +502,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
468
502
  * @returns
469
503
  */
470
504
  public clear() {
471
- this.startBatch();
505
+ this.startHistoryBatch();
472
506
  this.removeData(
473
507
  'edge',
474
508
  this.getAllEdgesData().map((edge) => edge.id),
@@ -481,7 +515,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
481
515
  'combo',
482
516
  this.getAllCombosData().map((combo) => combo.id),
483
517
  );
484
- this.stopBatch();
518
+ this.stopHistoryBatch();
485
519
  }
486
520
 
487
521
  public getViewportCenter(): PointLike {
@@ -492,9 +526,11 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
492
526
  options: GraphTransformOptions,
493
527
  effectTiming?: CameraAnimationOptions,
494
528
  ): Promise<void> {
529
+ const { tileLodSize } = this.specification.optimize || {};
495
530
  await this.hooks.viewportchange.emitLinearAsync({
496
531
  transform: options,
497
532
  effectTiming,
533
+ tileLodSize,
498
534
  });
499
535
  this.emit('viewportchange', options);
500
536
  }
@@ -779,6 +815,26 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
779
815
  this.canvas.resize(size[0], size[1]);
780
816
  }
781
817
 
818
+ public getCanvasRange(): Bounds {
819
+ const [width, height] = this.getSize();
820
+ const leftTop = this.getCanvasByViewport({ x: 0, y: 0 });
821
+ const rightBottom = this.getCanvasByViewport({ x: width, y: height });
822
+ return {
823
+ min: [leftTop.x, leftTop.y, leftTop.z],
824
+ max: [rightBottom.x, rightBottom.y, rightBottom.z],
825
+ center: [
826
+ (leftTop.x + rightBottom.x) / 2,
827
+ (leftTop.y + rightBottom.y) / 2,
828
+ (leftTop.z + rightBottom.z) / 2,
829
+ ],
830
+ halfExtents: [
831
+ (rightBottom.x - leftTop.x) / 2,
832
+ (rightBottom.y - leftTop.y) / 2,
833
+ (rightBottom.z - leftTop.z) / 2,
834
+ ],
835
+ };
836
+ }
837
+
782
838
  /**
783
839
  * Get the rendering coordinate according to the canvas dom (viewport) coordinate.
784
840
  * @param Point rendering coordinate
@@ -1344,7 +1400,11 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1344
1400
  * @returns
1345
1401
  * @group Item
1346
1402
  */
1347
- public hideItem(ids: ID | ID[], disableAnimate = false) {
1403
+ public hideItem(
1404
+ ids: ID | ID[],
1405
+ disableAnimate = false,
1406
+ keepKeyShape = false,
1407
+ ) {
1348
1408
  const idArr = isArray(ids) ? ids : [ids];
1349
1409
  if (isEmpty(idArr)) return;
1350
1410
  const changes = {
@@ -1356,6 +1416,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1356
1416
  value: false,
1357
1417
  graphCore: this.dataController.graphCore,
1358
1418
  animate: !disableAnimate,
1419
+ keepKeyShape,
1359
1420
  });
1360
1421
  this.emit('afteritemvisibilitychange', {
1361
1422
  ids,
@@ -1363,6 +1424,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1363
1424
  animate: !disableAnimate,
1364
1425
  action: 'updateVisibility',
1365
1426
  apiName: 'hideItem',
1427
+ keepKeyShape,
1366
1428
  changes,
1367
1429
  });
1368
1430
  }
@@ -1588,7 +1650,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1588
1650
  */
1589
1651
  public collapseCombo(comboIds: ID | ID[]) {
1590
1652
  const ids = isArray(comboIds) ? comboIds : [comboIds];
1591
- this.executeWithoutStacking(() => {
1653
+ this.executeWithNoStack(() => {
1592
1654
  this.updateData(
1593
1655
  'combo',
1594
1656
  ids.map((id) => ({ id, data: { collapsed: true } })),
@@ -1608,7 +1670,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1608
1670
  */
1609
1671
  public expandCombo(comboIds: ID | ID[]) {
1610
1672
  const ids = isArray(comboIds) ? comboIds : [comboIds];
1611
- this.executeWithoutStacking(() => {
1673
+ this.executeWithNoStack(() => {
1612
1674
  this.updateData(
1613
1675
  'combo',
1614
1676
  ids.map((id) => ({ id, data: { collapsed: false } })),
@@ -2020,30 +2082,30 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
2020
2082
  /**
2021
2083
  * Pause stacking operation.
2022
2084
  */
2023
- public pauseStacking(): void {
2085
+ public pauseStack(): void {
2024
2086
  const history = this.getHistoryPlugin();
2025
- return history?.pauseStacking();
2087
+ return history?.pauseStack();
2026
2088
  }
2027
2089
 
2028
2090
  /**
2029
2091
  * Resume stacking operation.
2030
2092
  */
2031
- public resumeStacking(): void {
2093
+ public resumeStack(): void {
2032
2094
  const history = this.getHistoryPlugin();
2033
- return history?.resumeStacking();
2095
+ return history?.resumeStack();
2034
2096
  }
2035
2097
 
2036
2098
  /**
2037
2099
  * Execute a callback without allowing any stacking operations.
2038
2100
  * @param callback
2039
2101
  */
2040
- public executeWithoutStacking = (callback: () => void): void => {
2102
+ public executeWithNoStack = (callback: () => void): void => {
2041
2103
  const history = this.getHistoryPlugin();
2042
- history?.pauseStacking();
2104
+ history?.pauseStack();
2043
2105
  try {
2044
2106
  callback();
2045
2107
  } finally {
2046
- history?.resumeStacking();
2108
+ history?.resumeStack();
2047
2109
  }
2048
2110
  };
2049
2111
 
@@ -2109,41 +2171,41 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
2109
2171
  }
2110
2172
 
2111
2173
  /**
2112
- * Begin a batch operation.
2113
- * Any operations performed between `startBatch` and `stopBatch` are grouped together.
2174
+ * Begin a historyBatch operation.
2175
+ * Any operations performed between `startHistoryBatch` and `stopHistoryBatch` are grouped together.
2114
2176
  * treated as a single operation when undoing or redoing.
2115
2177
  */
2116
- public startBatch() {
2178
+ public startHistoryBatch() {
2117
2179
  const history = this.getHistoryPlugin();
2118
- history?.startBatch();
2180
+ history?.startHistoryBatch();
2119
2181
  }
2120
2182
 
2121
2183
  /**
2122
- * End a batch operation.
2123
- * Any operations performed between `startBatch` and `stopBatch` are grouped together.
2184
+ * End a historyBatch operation.
2185
+ * Any operations performed between `startHistoryBatch` and `stopHistoryBatch` are grouped together.
2124
2186
  * treated as a single operation when undoing or redoing.
2125
2187
  */
2126
- public stopBatch() {
2188
+ public stopHistoryBatch() {
2127
2189
  const history = this.getHistoryPlugin();
2128
- history?.stopBatch();
2190
+ history?.stopHistoryBatch();
2129
2191
  }
2130
2192
 
2131
2193
  /**
2132
2194
  * Execute a provided function within a batched context
2133
2195
  * All operations performed inside callback will be treated as a composite operation
2134
- * more convenient way without manually invoking `startBatch` and `stopBatch`.
2196
+ * more convenient way without manually invoking `startHistoryBatch` and `stopHistoryBatch`.
2135
2197
  * @param callback The func containing operations to be batched together.
2136
2198
  */
2137
- public batch(callback: () => void) {
2199
+ public historyBatch(callback: () => void) {
2138
2200
  const history = this.getHistoryPlugin();
2139
- history?.batch(callback);
2201
+ history?.historyBatch(callback);
2140
2202
  }
2141
2203
 
2142
2204
  /**
2143
2205
  * Clear history stack
2144
2206
  * @param {StackType} stackType undo/redo stack
2145
2207
  */
2146
- public clearStack(stackType?: StackType) {
2208
+ public cleanHistory(stackType?: StackType) {
2147
2209
  const history = this.getHistoryPlugin();
2148
2210
  if (!stackType) return history?.clear();
2149
2211
  return stackType === 'undo'
@@ -2197,7 +2259,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
2197
2259
  this.transientCanvas.destroy();
2198
2260
 
2199
2261
  // clear history stack
2200
- this.clearStack();
2262
+ this.cleanHistory();
2201
2263
 
2202
2264
  callback?.();
2203
2265
  // }, 500);
@@ -118,7 +118,7 @@ export class ActivateRelations extends Behavior {
118
118
  edgeIds,
119
119
  );
120
120
 
121
- graph.batch(() => {
121
+ graph.historyBatch(() => {
122
122
  /** 节点 */
123
123
  graph.setItemState(activeNodeIds, ACTIVE_STATE, true);
124
124
  graph.setItemState(inactiveNodeIds, ACTIVE_STATE, false);
@@ -132,7 +132,7 @@ export class ActivateRelations extends Behavior {
132
132
  }
133
133
  public clearActiveState(e: any) {
134
134
  const { activeState: ACTIVE_STATE } = this.options;
135
- this.graph.batch(() => {
135
+ this.graph.historyBatch(() => {
136
136
  this.graph.setItemState(this.prevNodeIds, ACTIVE_STATE, false);
137
137
  this.graph.setItemState(this.prevEdgeIds, ACTIVE_STATE, false);
138
138
  });
@@ -136,7 +136,7 @@ export class ClickSelect extends Behavior {
136
136
 
137
137
  // Select/Unselect item.
138
138
  if (this.options.shouldUpdate(event)) {
139
- this.graph.batch(() => {
139
+ this.graph.historyBatch(() => {
140
140
  if (!multiple) {
141
141
  // Not multiple, clear all currently selected items
142
142
  this.graph.setItemState(this.selectedIds, state, false);
@@ -1,6 +1,7 @@
1
1
  import { ID, IG6GraphEvent } from 'types';
2
2
  import { Behavior } from '../../types/behavior';
3
3
  import { Point } from '../../types/common';
4
+ import { isNumber } from '@antv/util';
4
5
 
5
6
  const VALID_TRIGGERS = ['drag', 'directionKeys'];
6
7
  export interface DragCanvasOptions {
@@ -53,7 +54,7 @@ export interface DragCanvasOptions {
53
54
  }
54
55
 
55
56
  const DEFAULT_OPTIONS: Required<DragCanvasOptions> = {
56
- enableOptimize: false,
57
+ enableOptimize: undefined,
57
58
  dragOnItems: false,
58
59
  trigger: 'drag',
59
60
  direction: 'both',
@@ -132,24 +133,43 @@ export class DragCanvas extends Behavior {
132
133
 
133
134
  private hideShapes() {
134
135
  const { graph } = this;
135
- if (this.options.enableOptimize) {
136
+
137
+ const { tileBehavior: graphBehaviorOptimize, tileBehaviorSize = 1000 } =
138
+ graph.getSpecification().optimize || {};
139
+ const optimize = this.options.enableOptimize || graphBehaviorOptimize;
140
+ const shouldOptimize = isNumber(optimize)
141
+ ? graph.getAllNodesData().length > optimize
142
+ : optimize;
143
+
144
+ if (shouldOptimize) {
136
145
  this.hiddenEdgeIds = graph
137
146
  .getAllEdgesData()
138
147
  .map((edge) => edge.id)
139
148
  .filter((id) => graph.getItemVisible(id) === true);
140
- graph.executeWithoutStacking(() => {
141
- graph.hideItem(this.hiddenEdgeIds, true);
142
- this.hiddenNodeIds = graph
143
- .getAllNodesData()
144
- .map((node) => node.id)
145
- .filter((id) => graph.getItemVisible(id) === true);
146
- // draw node's keyShapes on transient, and then hidden the real nodes;
147
- // this.hiddenNodeIds.forEach((id) => {
148
- // graph.drawTransient('node', id, {
149
- // onlyDrawKeyShape: true,
150
- // });
151
- // });
152
- // graph.hideItem(this.hiddenNodeIds, true);
149
+ this.hiddenNodeIds = graph
150
+ .getAllNodesData()
151
+ .map((node) => node.id)
152
+ .filter((id) => graph.getItemVisible(id) === true);
153
+ let requestId;
154
+ const hiddenIds = [...this.hiddenNodeIds];
155
+ const sectionNum = Math.ceil(hiddenIds.length / tileBehaviorSize);
156
+ const sections = Array.from({ length: sectionNum }, (v, i) =>
157
+ hiddenIds.slice(
158
+ i * tileBehaviorSize,
159
+ i * tileBehaviorSize + tileBehaviorSize,
160
+ ),
161
+ );
162
+ const update = () => {
163
+ if (!sections.length) {
164
+ cancelAnimationFrame(requestId);
165
+ return;
166
+ }
167
+ const section = sections.shift();
168
+ graph.hideItem(section, false, true);
169
+ requestId = requestAnimationFrame(update);
170
+ };
171
+ graph.executeWithNoStack(() => {
172
+ requestId = requestAnimationFrame(update);
153
173
  });
154
174
  }
155
175
  }
@@ -241,19 +261,37 @@ export class DragCanvas extends Behavior {
241
261
  this.pointerDownAt = undefined;
242
262
  this.dragging = false;
243
263
 
244
- const { graph } = this;
245
- if (this.options.enableOptimize) {
246
- graph.startBatch();
247
- if (this.hiddenEdgeIds) {
248
- graph.showItem(this.hiddenEdgeIds, true);
264
+ const { graph, hiddenNodeIds, hiddenEdgeIds = [] } = this;
265
+ const { tileBehavior: graphBehaviorOptimize, tileBehaviorSize = 1000 } =
266
+ graph.getSpecification().optimize || {};
267
+ const optimize = this.options.enableOptimize || graphBehaviorOptimize;
268
+ const shouldOptimize = isNumber(optimize)
269
+ ? graph.getAllNodesData().length > optimize
270
+ : optimize;
271
+
272
+ if (shouldOptimize) {
273
+ if (hiddenNodeIds) {
274
+ let requestId;
275
+ const hiddenIds = [...hiddenNodeIds, ...hiddenEdgeIds];
276
+ const sectionNum = Math.ceil(hiddenIds.length / tileBehaviorSize);
277
+ const sections = Array.from({ length: sectionNum }, (v, i) =>
278
+ hiddenIds.slice(
279
+ i * tileBehaviorSize,
280
+ i * tileBehaviorSize + tileBehaviorSize,
281
+ ),
282
+ );
283
+ const update = () => {
284
+ if (!sections.length) {
285
+ cancelAnimationFrame(requestId);
286
+ return;
287
+ }
288
+ graph.showItem(sections.shift(), false);
289
+ requestId = requestAnimationFrame(update);
290
+ };
291
+ graph.startHistoryBatch();
292
+ requestId = requestAnimationFrame(update);
293
+ graph.stopHistoryBatch();
249
294
  }
250
- // if (this.hiddenNodeIds) {
251
- // this.hiddenNodeIds.forEach((id) => {
252
- // this.graph.drawTransient('node', id, { action: 'remove' });
253
- // });
254
- // graph.showItem(this.hiddenNodeIds, true);
255
- // }
256
- graph.stopBatch();
257
295
  }
258
296
  }
259
297
 
@@ -250,7 +250,7 @@ export class DragCombo extends Behavior {
250
250
  selectedComboIds,
251
251
  this.hiddenComboTreeRoots,
252
252
  );
253
- this.graph.executeWithoutStacking(() => {
253
+ this.graph.executeWithNoStack(() => {
254
254
  this.graph.hideItem(
255
255
  this.hiddenEdges.map((edge) => edge.id),
256
256
  true,
@@ -280,7 +280,7 @@ export class DragCombo extends Behavior {
280
280
  });
281
281
 
282
282
  // Hide original edges and nodes. They will be restored when pointerup.
283
- this.graph.executeWithoutStacking(() => {
283
+ this.graph.executeWithNoStack(() => {
284
284
  this.graph.hideItem(selectedComboIds, true);
285
285
  this.graph.hideItem(
286
286
  this.hiddenEdges.map((edge) => edge.id),
@@ -429,7 +429,7 @@ export class DragCombo extends Behavior {
429
429
  }
430
430
 
431
431
  public restoreHiddenItems(positions?: Position[]) {
432
- this.graph.pauseStacking();
432
+ this.graph.pauseStack();
433
433
  if (this.hiddenEdges.length) {
434
434
  this.graph.showItem(
435
435
  this.hiddenEdges.map((edge) => edge.id),
@@ -452,7 +452,7 @@ export class DragCombo extends Behavior {
452
452
  true,
453
453
  );
454
454
  }
455
- this.graph.resumeStacking();
455
+ this.graph.resumeStack();
456
456
  }
457
457
 
458
458
  public onPointerUp(event: IG6GraphEvent) {
@@ -561,7 +561,7 @@ export class DragCombo extends Behavior {
561
561
 
562
562
  public onDropCombo(event: IG6GraphEvent) {
563
563
  const newParentId = event.itemId;
564
- this.graph.startBatch();
564
+ this.graph.startHistoryBatch();
565
565
  this.originPositions.forEach(({ id }) => {
566
566
  const model = this.graph.getComboData(id);
567
567
  if (!model || model.id === newParentId) return;
@@ -570,12 +570,12 @@ export class DragCombo extends Behavior {
570
570
  // event.stopPropagation();
571
571
  this.graph.updateData('combo', { id, data: { parentId: newParentId } });
572
572
  });
573
- this.graph.stopBatch();
573
+ this.graph.stopHistoryBatch();
574
574
  this.onPointerUp(event);
575
575
  }
576
576
 
577
577
  public onDropCanvas(event: IG6GraphEvent) {
578
- this.graph.startBatch();
578
+ this.graph.startHistoryBatch();
579
579
  this.originPositions.forEach(({ id }) => {
580
580
  const model = this.graph.getComboData(id);
581
581
  if (!model) return;
@@ -583,7 +583,7 @@ export class DragCombo extends Behavior {
583
583
  if (!parentId) return;
584
584
  this.graph.updateData('combo', { id, data: { parentId: undefined } });
585
585
  });
586
- this.graph.stopBatch();
586
+ this.graph.stopHistoryBatch();
587
587
  this.onPointerUp(event);
588
588
  }
589
589
  }
@@ -258,7 +258,7 @@ export class DragNode extends Behavior {
258
258
  this.selectedNodeIds,
259
259
  this.hiddenComboTreeItems,
260
260
  );
261
- this.graph.executeWithoutStacking(() => {
261
+ this.graph.executeWithNoStack(() => {
262
262
  this.graph.hideItem(
263
263
  this.hiddenEdges.map((edge) => edge.id),
264
264
  true,
@@ -292,7 +292,7 @@ export class DragNode extends Behavior {
292
292
  });
293
293
 
294
294
  // Hide original edges and nodes. They will be restored when pointerup.
295
- this.graph.executeWithoutStacking(() => {
295
+ this.graph.executeWithNoStack(() => {
296
296
  this.graph.hideItem(this.selectedNodeIds, true);
297
297
  this.graph.hideItem(
298
298
  this.hiddenEdges.map((edge) => edge.id),
@@ -478,7 +478,7 @@ export class DragNode extends Behavior {
478
478
  }
479
479
 
480
480
  public restoreHiddenItems(positions?: Position[]) {
481
- this.graph.pauseStacking();
481
+ this.graph.pauseStack();
482
482
  if (this.hiddenEdges.length) {
483
483
  this.graph.showItem(
484
484
  this.hiddenEdges.map((edge) => edge.id),
@@ -508,7 +508,7 @@ export class DragNode extends Behavior {
508
508
  true,
509
509
  );
510
510
  }
511
- this.graph.resumeStacking();
511
+ this.graph.resumeStack();
512
512
  }
513
513
 
514
514
  public clearState() {
@@ -608,7 +608,7 @@ export class DragNode extends Behavior {
608
608
  ? this.graph.getNodeData(dropId).data.parentId
609
609
  : dropId;
610
610
 
611
- this.graph.startBatch();
611
+ this.graph.startHistoryBatch();
612
612
  this.originPositions.forEach(({ id }) => {
613
613
  const model = this.graph.getNodeData(id);
614
614
  if (!model) return;
@@ -621,13 +621,13 @@ export class DragNode extends Behavior {
621
621
  this.graph.updateData('node', { id, data: { parentId: newParentId } });
622
622
  });
623
623
  this.onPointerUp(event);
624
- this.graph.stopBatch();
624
+ this.graph.stopHistoryBatch();
625
625
  }
626
626
 
627
627
  public onDropCombo(event: IG6GraphEvent) {
628
628
  event.stopPropagation();
629
629
  const newParentId = event.itemId;
630
- this.graph.startBatch();
630
+ this.graph.startHistoryBatch();
631
631
  this.onPointerUp(event);
632
632
  this.originPositions.forEach(({ id }) => {
633
633
  const model = this.graph.getNodeData(id);
@@ -637,7 +637,7 @@ export class DragNode extends Behavior {
637
637
  this.graph.updateData('node', { id, data: { parentId: newParentId } });
638
638
  });
639
639
  this.clearState();
640
- this.graph.stopBatch();
640
+ this.graph.stopHistoryBatch();
641
641
  }
642
642
 
643
643
  public onDropCanvas(event: IG6GraphEvent) {
@@ -657,7 +657,7 @@ export class DragNode extends Behavior {
657
657
  const parentId = this.graph.getNodeData(dropId)
658
658
  ? this.graph.getNodeData(dropId).data.parentId
659
659
  : dropId;
660
- this.graph.startBatch();
660
+ this.graph.startHistoryBatch();
661
661
  this.onPointerUp(event);
662
662
  const nodeToUpdate = [];
663
663
  this.originPositions.forEach(({ id }) => {
@@ -671,6 +671,6 @@ export class DragNode extends Behavior {
671
671
  });
672
672
  if (nodeToUpdate.length) this.graph.updateData('node', nodeToUpdate);
673
673
  this.clearState();
674
- this.graph.stopBatch();
674
+ this.graph.stopHistoryBatch();
675
675
  }
676
676
  }