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

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 (246) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/esm/index.d.ts +15 -1
  3. package/esm/index.js +1 -1
  4. package/esm/item/combo.d.ts +1 -1
  5. package/esm/item/combo.js +16 -9
  6. package/esm/item/combo.js.map +1 -1
  7. package/esm/item/edge.d.ts +2 -1
  8. package/esm/item/edge.js +18 -8
  9. package/esm/item/edge.js.map +1 -1
  10. package/esm/item/item.d.ts +3 -2
  11. package/esm/item/item.js +12 -6
  12. package/esm/item/item.js.map +1 -1
  13. package/esm/item/node.d.ts +2 -1
  14. package/esm/item/node.js +19 -10
  15. package/esm/item/node.js.map +1 -1
  16. package/esm/runtime/controller/item.d.ts +1 -0
  17. package/esm/runtime/controller/item.js +271 -151
  18. package/esm/runtime/controller/item.js.map +1 -1
  19. package/esm/runtime/graph.d.ts +98 -18
  20. package/esm/runtime/graph.js +427 -75
  21. package/esm/runtime/graph.js.map +1 -1
  22. package/esm/stdlib/behavior/activate-relations.js +2 -2
  23. package/esm/stdlib/behavior/activate-relations.js.map +1 -1
  24. package/esm/stdlib/behavior/brush-select.js +1 -2
  25. package/esm/stdlib/behavior/brush-select.js.map +1 -1
  26. package/esm/stdlib/behavior/click-select.js +1 -1
  27. package/esm/stdlib/behavior/click-select.js.map +1 -1
  28. package/esm/stdlib/behavior/create-edge.d.ts +57 -0
  29. package/esm/stdlib/behavior/create-edge.js +206 -0
  30. package/esm/stdlib/behavior/create-edge.js.map +1 -0
  31. package/esm/stdlib/behavior/drag-canvas.d.ts +1 -1
  32. package/esm/stdlib/behavior/drag-canvas.js +51 -28
  33. package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
  34. package/esm/stdlib/behavior/drag-combo.d.ts +2 -2
  35. package/esm/stdlib/behavior/drag-combo.js +43 -32
  36. package/esm/stdlib/behavior/drag-combo.js.map +1 -1
  37. package/esm/stdlib/behavior/drag-node.d.ts +3 -3
  38. package/esm/stdlib/behavior/drag-node.js +76 -63
  39. package/esm/stdlib/behavior/drag-node.js.map +1 -1
  40. package/esm/stdlib/behavior/index.d.ts +2 -0
  41. package/esm/stdlib/behavior/index.js +2 -0
  42. package/esm/stdlib/behavior/index.js.map +1 -1
  43. package/esm/stdlib/behavior/lasso-select.d.ts +1 -1
  44. package/esm/stdlib/behavior/lasso-select.js +1 -2
  45. package/esm/stdlib/behavior/lasso-select.js.map +1 -1
  46. package/esm/stdlib/behavior/scroll-canvas.d.ts +67 -0
  47. package/esm/stdlib/behavior/scroll-canvas.js +266 -0
  48. package/esm/stdlib/behavior/scroll-canvas.js.map +1 -0
  49. package/esm/stdlib/behavior/zoom-canvas.d.ts +1 -1
  50. package/esm/stdlib/behavior/zoom-canvas.js +47 -24
  51. package/esm/stdlib/behavior/zoom-canvas.js.map +1 -1
  52. package/esm/stdlib/index.d.ts +6 -0
  53. package/esm/stdlib/index.js +15 -9
  54. package/esm/stdlib/index.js.map +1 -1
  55. package/esm/stdlib/item/edge/base.d.ts +1 -1
  56. package/esm/stdlib/item/edge/base.js +13 -4
  57. package/esm/stdlib/item/edge/base.js.map +1 -1
  58. package/esm/stdlib/item/node/base.d.ts +1 -1
  59. package/esm/stdlib/item/node/base.js +11 -12
  60. package/esm/stdlib/item/node/base.js.map +1 -1
  61. package/esm/stdlib/item/node/image.d.ts +1 -1
  62. package/esm/stdlib/item/node/image.js +1 -1
  63. package/esm/stdlib/item/node/image.js.map +1 -1
  64. package/esm/stdlib/plugin/history/combo-command.js +2 -2
  65. package/esm/stdlib/plugin/history/combo-command.js.map +1 -1
  66. package/esm/stdlib/plugin/history/index.d.ts +10 -10
  67. package/esm/stdlib/plugin/history/index.js +14 -14
  68. package/esm/stdlib/plugin/history/index.js.map +1 -1
  69. package/esm/stdlib/plugin/history/item-data-command.js +4 -4
  70. package/esm/stdlib/plugin/history/item-data-command.js.map +1 -1
  71. package/esm/stdlib/plugin/history/layer-updated-command.js +2 -2
  72. package/esm/stdlib/plugin/history/layer-updated-command.js.map +1 -1
  73. package/esm/stdlib/plugin/history/state-updated-command.js +1 -1
  74. package/esm/stdlib/plugin/history/state-updated-command.js.map +1 -1
  75. package/esm/stdlib/plugin/history/visibility-updated-command.js +2 -2
  76. package/esm/stdlib/plugin/history/visibility-updated-command.js.map +1 -1
  77. package/esm/stdlib/plugin/hull/hullComponent.d.ts +1 -1
  78. package/esm/stdlib/plugin/hull/hullComponent.js +3 -6
  79. package/esm/stdlib/plugin/hull/hullComponent.js.map +1 -1
  80. package/esm/stdlib/plugin/index.d.ts +1 -0
  81. package/esm/stdlib/plugin/index.js +1 -0
  82. package/esm/stdlib/plugin/index.js.map +1 -1
  83. package/esm/stdlib/plugin/minimap/index.d.ts +5 -1
  84. package/esm/stdlib/plugin/minimap/index.js +109 -8
  85. package/esm/stdlib/plugin/minimap/index.js.map +1 -1
  86. package/esm/stdlib/plugin/snapline/index.d.ts +163 -0
  87. package/esm/stdlib/plugin/snapline/index.js +1052 -0
  88. package/esm/stdlib/plugin/snapline/index.js.map +1 -0
  89. package/esm/stdlib/plugin/types.d.ts +1 -0
  90. package/esm/types/graph.d.ts +45 -19
  91. package/esm/types/hook.d.ts +22 -2
  92. package/esm/types/spec.d.ts +19 -3
  93. package/esm/util/bbox.d.ts +16 -1
  94. package/esm/util/bbox.js +29 -0
  95. package/esm/util/bbox.js.map +1 -1
  96. package/esm/util/item.d.ts +16 -1
  97. package/esm/util/item.js +31 -8
  98. package/esm/util/item.js.map +1 -1
  99. package/esm/util/shape.js +2 -2
  100. package/esm/util/shape.js.map +1 -1
  101. package/esm/util/warn.d.ts +14 -0
  102. package/esm/util/warn.js +4 -0
  103. package/esm/util/warn.js.map +1 -0
  104. package/lib/index.d.ts +15 -1
  105. package/lib/index.js +1 -1
  106. package/lib/item/combo.d.ts +1 -1
  107. package/lib/item/combo.js +16 -9
  108. package/lib/item/combo.js.map +1 -1
  109. package/lib/item/edge.d.ts +2 -1
  110. package/lib/item/edge.js +18 -8
  111. package/lib/item/edge.js.map +1 -1
  112. package/lib/item/item.d.ts +3 -2
  113. package/lib/item/item.js +12 -6
  114. package/lib/item/item.js.map +1 -1
  115. package/lib/item/node.d.ts +2 -1
  116. package/lib/item/node.js +19 -10
  117. package/lib/item/node.js.map +1 -1
  118. package/lib/runtime/controller/item.d.ts +1 -0
  119. package/lib/runtime/controller/item.js +270 -150
  120. package/lib/runtime/controller/item.js.map +1 -1
  121. package/lib/runtime/graph.d.ts +98 -18
  122. package/lib/runtime/graph.js +427 -75
  123. package/lib/runtime/graph.js.map +1 -1
  124. package/lib/stdlib/behavior/activate-relations.js +2 -2
  125. package/lib/stdlib/behavior/activate-relations.js.map +1 -1
  126. package/lib/stdlib/behavior/brush-select.js +1 -2
  127. package/lib/stdlib/behavior/brush-select.js.map +1 -1
  128. package/lib/stdlib/behavior/click-select.js +1 -1
  129. package/lib/stdlib/behavior/click-select.js.map +1 -1
  130. package/lib/stdlib/behavior/create-edge.d.ts +57 -0
  131. package/lib/stdlib/behavior/create-edge.js +210 -0
  132. package/lib/stdlib/behavior/create-edge.js.map +1 -0
  133. package/lib/stdlib/behavior/drag-canvas.d.ts +1 -1
  134. package/lib/stdlib/behavior/drag-canvas.js +51 -28
  135. package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
  136. package/lib/stdlib/behavior/drag-combo.d.ts +2 -2
  137. package/lib/stdlib/behavior/drag-combo.js +43 -32
  138. package/lib/stdlib/behavior/drag-combo.js.map +1 -1
  139. package/lib/stdlib/behavior/drag-node.d.ts +3 -3
  140. package/lib/stdlib/behavior/drag-node.js +76 -63
  141. package/lib/stdlib/behavior/drag-node.js.map +1 -1
  142. package/lib/stdlib/behavior/index.d.ts +2 -0
  143. package/lib/stdlib/behavior/index.js +2 -0
  144. package/lib/stdlib/behavior/index.js.map +1 -1
  145. package/lib/stdlib/behavior/lasso-select.d.ts +1 -1
  146. package/lib/stdlib/behavior/lasso-select.js +1 -2
  147. package/lib/stdlib/behavior/lasso-select.js.map +1 -1
  148. package/lib/stdlib/behavior/scroll-canvas.d.ts +67 -0
  149. package/lib/stdlib/behavior/scroll-canvas.js +270 -0
  150. package/lib/stdlib/behavior/scroll-canvas.js.map +1 -0
  151. package/lib/stdlib/behavior/zoom-canvas.d.ts +1 -1
  152. package/lib/stdlib/behavior/zoom-canvas.js +47 -24
  153. package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
  154. package/lib/stdlib/index.d.ts +6 -0
  155. package/lib/stdlib/index.js +15 -9
  156. package/lib/stdlib/index.js.map +1 -1
  157. package/lib/stdlib/item/edge/base.d.ts +1 -1
  158. package/lib/stdlib/item/edge/base.js +13 -4
  159. package/lib/stdlib/item/edge/base.js.map +1 -1
  160. package/lib/stdlib/item/node/base.d.ts +1 -1
  161. package/lib/stdlib/item/node/base.js +11 -12
  162. package/lib/stdlib/item/node/base.js.map +1 -1
  163. package/lib/stdlib/item/node/image.d.ts +1 -1
  164. package/lib/stdlib/item/node/image.js +1 -1
  165. package/lib/stdlib/item/node/image.js.map +1 -1
  166. package/lib/stdlib/plugin/history/combo-command.js +2 -2
  167. package/lib/stdlib/plugin/history/combo-command.js.map +1 -1
  168. package/lib/stdlib/plugin/history/index.d.ts +10 -10
  169. package/lib/stdlib/plugin/history/index.js +14 -14
  170. package/lib/stdlib/plugin/history/index.js.map +1 -1
  171. package/lib/stdlib/plugin/history/item-data-command.js +4 -4
  172. package/lib/stdlib/plugin/history/item-data-command.js.map +1 -1
  173. package/lib/stdlib/plugin/history/layer-updated-command.js +2 -2
  174. package/lib/stdlib/plugin/history/layer-updated-command.js.map +1 -1
  175. package/lib/stdlib/plugin/history/state-updated-command.js +1 -1
  176. package/lib/stdlib/plugin/history/state-updated-command.js.map +1 -1
  177. package/lib/stdlib/plugin/history/visibility-updated-command.js +2 -2
  178. package/lib/stdlib/plugin/history/visibility-updated-command.js.map +1 -1
  179. package/lib/stdlib/plugin/hull/hullComponent.d.ts +1 -1
  180. package/lib/stdlib/plugin/hull/hullComponent.js +3 -6
  181. package/lib/stdlib/plugin/hull/hullComponent.js.map +1 -1
  182. package/lib/stdlib/plugin/index.d.ts +1 -0
  183. package/lib/stdlib/plugin/index.js +1 -0
  184. package/lib/stdlib/plugin/index.js.map +1 -1
  185. package/lib/stdlib/plugin/minimap/index.d.ts +5 -1
  186. package/lib/stdlib/plugin/minimap/index.js +109 -8
  187. package/lib/stdlib/plugin/minimap/index.js.map +1 -1
  188. package/lib/stdlib/plugin/snapline/index.d.ts +163 -0
  189. package/lib/stdlib/plugin/snapline/index.js +1056 -0
  190. package/lib/stdlib/plugin/snapline/index.js.map +1 -0
  191. package/lib/stdlib/plugin/types.d.ts +1 -0
  192. package/lib/types/graph.d.ts +45 -19
  193. package/lib/types/hook.d.ts +22 -2
  194. package/lib/types/spec.d.ts +19 -3
  195. package/lib/util/bbox.d.ts +16 -1
  196. package/lib/util/bbox.js +32 -1
  197. package/lib/util/bbox.js.map +1 -1
  198. package/lib/util/item.d.ts +16 -1
  199. package/lib/util/item.js +33 -9
  200. package/lib/util/item.js.map +1 -1
  201. package/lib/util/shape.js +2 -2
  202. package/lib/util/shape.js.map +1 -1
  203. package/lib/util/warn.d.ts +14 -0
  204. package/lib/util/warn.js +8 -0
  205. package/lib/util/warn.js.map +1 -0
  206. package/package.json +2 -2
  207. package/src/index.ts +1 -1
  208. package/src/item/combo.ts +14 -9
  209. package/src/item/edge.ts +17 -8
  210. package/src/item/item.ts +11 -6
  211. package/src/item/node.ts +24 -16
  212. package/src/runtime/controller/item.ts +240 -72
  213. package/src/runtime/graph.ts +536 -80
  214. package/src/stdlib/behavior/activate-relations.ts +2 -2
  215. package/src/stdlib/behavior/brush-select.ts +4 -2
  216. package/src/stdlib/behavior/click-select.ts +1 -1
  217. package/src/stdlib/behavior/create-edge.ts +295 -0
  218. package/src/stdlib/behavior/drag-canvas.ts +67 -29
  219. package/src/stdlib/behavior/drag-combo.ts +10 -10
  220. package/src/stdlib/behavior/drag-node.ts +18 -18
  221. package/src/stdlib/behavior/index.ts +2 -0
  222. package/src/stdlib/behavior/lasso-select.ts +5 -3
  223. package/src/stdlib/behavior/scroll-canvas.ts +348 -0
  224. package/src/stdlib/behavior/zoom-canvas.ts +61 -25
  225. package/src/stdlib/index.ts +16 -7
  226. package/src/stdlib/item/edge/base.ts +13 -5
  227. package/src/stdlib/item/node/base.ts +15 -14
  228. package/src/stdlib/item/node/image.ts +1 -1
  229. package/src/stdlib/plugin/history/combo-command.ts +2 -2
  230. package/src/stdlib/plugin/history/index.ts +14 -14
  231. package/src/stdlib/plugin/history/item-data-command.ts +4 -4
  232. package/src/stdlib/plugin/history/layer-updated-command.ts +2 -2
  233. package/src/stdlib/plugin/history/state-updated-command.ts +1 -1
  234. package/src/stdlib/plugin/history/visibility-updated-command.ts +2 -2
  235. package/src/stdlib/plugin/hull/hullComponent.ts +8 -5
  236. package/src/stdlib/plugin/index.ts +1 -0
  237. package/src/stdlib/plugin/minimap/index.ts +113 -9
  238. package/src/stdlib/plugin/snapline/index.ts +1277 -0
  239. package/src/stdlib/plugin/types.ts +1 -0
  240. package/src/types/graph.ts +53 -22
  241. package/src/types/hook.ts +22 -2
  242. package/src/types/spec.ts +22 -3
  243. package/src/util/bbox.ts +38 -1
  244. package/src/util/item.ts +65 -28
  245. package/src/util/shape.ts +2 -2
  246. package/src/util/warn.ts +20 -0
@@ -7,3 +7,4 @@ export type { MiniMapConfig } from './minimap';
7
7
  export type { ToolbarConfig } from './toolbar';
8
8
  export type { TooltipConfig } from './tooltip';
9
9
  export type { TimebarConfig } from './timebar';
10
+ export type { SnapLineConfig } from './snapline';
@@ -1,20 +1,20 @@
1
1
  import EventEmitter from '@antv/event-emitter';
2
- import { AABB, Canvas, DisplayObject, PointLike } from '@antv/g';
2
+ import { AABB, Canvas, Cursor, DisplayObject, PointLike } from '@antv/g';
3
3
  import { ID } from '@antv/graphlib';
4
4
  import { Command } from '../stdlib/plugin/history/command';
5
5
  import { Hooks } from '../types/hook';
6
6
  import { CameraAnimationOptions } from './animate';
7
7
  import { BehaviorOptionsOf, BehaviorRegistry } from './behavior';
8
- import { ComboDisplayModel, ComboModel, ComboUserModel } from './combo';
8
+ import { ComboModel, ComboUserModel } from './combo';
9
9
  import { Padding, Point } from './common';
10
10
  import { GraphData } from './data';
11
- import { EdgeDisplayModel, EdgeModel, EdgeUserModel } from './edge';
11
+ import { EdgeModel, EdgeUserModel } from './edge';
12
12
  import type { StackType } from './history';
13
- import { ITEM_TYPE, SHAPE_TYPE } from './item';
13
+ import { ITEM_TYPE, SHAPE_TYPE, ShapeStyle } from './item';
14
14
  import { LayoutOptions } from './layout';
15
- import { NodeDisplayModel, NodeModel, NodeUserModel } from './node';
15
+ import { NodeModel, NodeUserModel } from './node';
16
16
  import { RendererName } from './render';
17
- import { Specification } from './spec';
17
+ import { ComboMapper, EdgeMapper, NodeMapper, Specification } from './spec';
18
18
  import { ThemeOptionsOf, ThemeRegistry } from './theme';
19
19
  import { FitViewRules, GraphTransformOptions } from './view';
20
20
 
@@ -36,7 +36,7 @@ export interface IGraph<
36
36
  * @returns
37
37
  * @group Graph Instance
38
38
  */
39
- destroy: (callback?: Function) => void;
39
+ destroy: (callback?: () => void) => void;
40
40
  /**
41
41
  * Update the specs (configurations).
42
42
  */
@@ -45,6 +45,12 @@ export interface IGraph<
45
45
  * Update the theme specs (configurations).
46
46
  */
47
47
  updateTheme: (theme: ThemeOptionsOf<T>) => void;
48
+ /**
49
+ * Update the item display mapper for a specific item type.
50
+ * @param {ITEM_TYPE} type - The type of item (node, edge, or combo).
51
+ * @param {NodeMapper | EdgeMapper | ComboMapper} mapper - The mapper to be updated.
52
+ * */
53
+ updateMapper(type: ITEM_TYPE, mapper: NodeMapper | EdgeMapper | ComboMapper);
48
54
  /**
49
55
  * Get the copy of specs(configurations).
50
56
  * @returns graph specs
@@ -470,7 +476,11 @@ export interface IGraph<
470
476
  * @returns
471
477
  * @group Item
472
478
  */
473
- hideItem: (ids: ID | ID[], disableAnimate?: boolean) => void;
479
+ hideItem: (
480
+ ids: ID | ID[],
481
+ disableAnimate?: boolean,
482
+ keepKeyShape?: boolean,
483
+ ) => void;
474
484
  /**
475
485
  * Make the item(s) to the front.
476
486
  * @param ids the item id(s) to front
@@ -591,6 +601,11 @@ export interface IGraph<
591
601
  * @group Interaction
592
602
  */
593
603
  getMode: () => string;
604
+ /**
605
+ * Set the cursor. But the cursor in item's style has higher priority.
606
+ * @param cursor
607
+ */
608
+ setCursor: (cursor: Cursor) => void;
594
609
  /**
595
610
  * Add behavior(s) to mode(s).
596
611
  * @param behaviors behavior names or configs
@@ -628,7 +643,22 @@ export interface IGraph<
628
643
  drawTransient: (
629
644
  type: ITEM_TYPE | SHAPE_TYPE,
630
645
  id: ID,
631
- config: any,
646
+ config: {
647
+ action?: 'remove' | 'add' | 'update' | undefined;
648
+ /** Data to be merged into the transient item. */
649
+ data?: Record<string, any>;
650
+ /** Style to be merged into the transient shape. */
651
+ style?: ShapeStyle;
652
+ /** For type: 'edge' */
653
+ drawSource?: boolean;
654
+ /** For type: 'edge' */
655
+ drawTarget?: boolean;
656
+ /** Only shape with id in shapeIds will be cloned while type is ITEM_TYPE. If shapeIds is not assigned, the whole item will be cloned. */
657
+ shapeIds?: string[];
658
+ /** Whether show the shapes in shapeIds. True by default. */
659
+ visible?: boolean;
660
+ upsertAncestors?: boolean;
661
+ },
632
662
  canvas?: Canvas,
633
663
  ) => DisplayObject;
634
664
 
@@ -682,16 +712,16 @@ export interface IGraph<
682
712
  /**
683
713
  * Pause stacking operation.
684
714
  */
685
- pauseStacking: () => void;
715
+ pauseStack: () => void;
686
716
  /**
687
717
  * Resume stacking operation.
688
718
  */
689
- resumeStacking: () => void;
719
+ resumeStack: () => void;
690
720
  /**
691
721
  * Execute a callback without allowing any stacking operations.
692
722
  * @param callback
693
723
  */
694
- executeWithoutStacking: (callback: () => void) => void;
724
+ executeWithNoStack: (callback: () => void) => void;
695
725
  /**
696
726
  * Retrieve the current redo stack which consists of operations that could be undone
697
727
  */
@@ -731,33 +761,34 @@ export interface IGraph<
731
761
  canRedo: () => void;
732
762
 
733
763
  /**
734
- * Begin a batch operation.
735
- * Any operations performed between `startBatch` and `stopBatch` are grouped together.
764
+ * Begin a historyBatch operation.
765
+ * Any operations performed between `startHistoryBatch` and `stopHistoryBatch` are grouped together.
736
766
  * treated as a single operation when undoing or redoing.
737
767
  */
738
- startBatch: () => void;
768
+ startHistoryBatch: () => void;
739
769
 
740
770
  /**
741
- * End a batch operation.
742
- * Any operations performed between `startBatch` and `stopBatch` are grouped together.
771
+ * End a historyBatch operation.
772
+ * Any operations performed between `startHistoryBatch` and `stopHistoryBatch` are grouped together.
743
773
  * treated as a single operation when undoing or redoing.
744
774
  */
745
- stopBatch: () => void;
775
+ stopHistoryBatch: () => void;
746
776
 
747
777
  /**
748
778
  * Execute a provided function within a batched context
749
779
  * All operations performed inside callback will be treated as a composite operation
750
- * more convenient way without manually invoking `startBatch` and `stopBatch`.
780
+ * more convenient way without manually invoking `startHistoryBatch` and `stopHistoryBatch`.
751
781
  * @param callback The func containing operations to be batched together.
752
782
  */
753
- batch: (callback: () => void) => void;
783
+ historyBatch: (callback: () => void) => void;
784
+
754
785
  /**
755
786
  * Execute a provided function within a batched context
756
787
  * All operations performed inside callback will be treated as a composite operation
757
- * more convenient way without manually invoking `startBatch` and `stopBatch`.
788
+ * more convenient way without manually invoking `startHistoryBatch` and `stopHistoryBatch`.
758
789
  * @param callback The func containing operations to be batched together.
759
790
  */
760
- clearStack: (stackType?: StackType) => void;
791
+ cleanHistory: (stackType?: StackType) => void;
761
792
  // ===== tree operations =====
762
793
  /**
763
794
  * Collapse sub tree(s).
package/src/types/hook.ts CHANGED
@@ -11,6 +11,7 @@ import { ThemeSpecification } from './theme';
11
11
  import { GraphTransformOptions } from './view';
12
12
  import { ComboModel } from './combo';
13
13
  import { Plugin as PluginBase } from './plugin';
14
+ import { ComboMapper, EdgeMapper, NodeMapper } from './spec';
14
15
 
15
16
  export interface IHook<T> {
16
17
  name: string;
@@ -24,6 +25,7 @@ export interface IHook<T> {
24
25
  export type ViewportChangeHookParams = {
25
26
  transform: GraphTransformOptions;
26
27
  effectTiming?: Partial<CameraAnimationOptions>;
28
+ tileLodSize?: number;
27
29
  };
28
30
 
29
31
  export interface Hooks {
@@ -53,6 +55,10 @@ export interface Hooks {
53
55
  graphCore: GraphCore;
54
56
  theme: ThemeSpecification;
55
57
  transientCanvas: Canvas;
58
+ tileOptimize?: {
59
+ tileFirstRender?: boolean | number;
60
+ tileFirstRenderSize?: number;
61
+ };
56
62
  }>; // TODO: define param template
57
63
  layout: IHook<{
58
64
  graphCore: GraphCore;
@@ -82,6 +88,7 @@ export interface Hooks {
82
88
  action?: string;
83
89
  enableStack?: boolean;
84
90
  changes?: any;
91
+ keepKeyShape?: boolean;
85
92
  }>;
86
93
  itemzindexchange: IHook<{
87
94
  ids: ID[];
@@ -95,8 +102,17 @@ export interface Hooks {
95
102
  id: ID;
96
103
  canvas: Canvas;
97
104
  config: {
98
- style: ShapeStyle;
99
- action: 'remove' | 'add' | 'update' | undefined;
105
+ style?: ShapeStyle;
106
+ action?: 'remove' | 'add' | 'update';
107
+ /** For type: 'edge' */
108
+ drawSource?: boolean;
109
+ /** For type: 'edge' */
110
+ drawTarget?: boolean;
111
+ /** Only shape with id in shapeIds will be cloned while type is ITEM_TYPE. If shapeIds is not assigned, the whole item will be cloned. */
112
+ shapeIds?: string[];
113
+ /** Whether show the shapes in shapeIds. True by default. */
114
+ visible?: boolean;
115
+ upsertAncestors?: boolean;
100
116
  };
101
117
  graphCore: GraphCore;
102
118
  }>;
@@ -118,6 +134,10 @@ export interface Hooks {
118
134
  transient: Canvas;
119
135
  };
120
136
  }>;
137
+ mapperchange: IHook<{
138
+ type: ITEM_TYPE;
139
+ mapper: NodeMapper | EdgeMapper | ComboMapper;
140
+ }>;
121
141
  treecollapseexpand: IHook<{
122
142
  ids: ID[];
123
143
  action: 'collapse' | 'expand';
package/src/types/spec.ts CHANGED
@@ -29,6 +29,12 @@ import { RendererName } from './render';
29
29
  import { StackCfg } from './history';
30
30
  import { Plugin } from './plugin';
31
31
 
32
+ export type NodeMapper = ((data: NodeModel) => NodeDisplayModel) | NodeEncode;
33
+ export type EdgeMapper = ((data: EdgeModel) => EdgeDisplayModel) | EdgeEncode;
34
+ export type ComboMapper =
35
+ | ((data: ComboModel) => ComboDisplayModel)
36
+ | ComboEncode;
37
+
32
38
  export interface Specification<
33
39
  B extends BehaviorRegistry,
34
40
  T extends ThemeRegistry,
@@ -47,6 +53,19 @@ export interface Specification<
47
53
  headless: boolean;
48
54
  };
49
55
  zoom?: number;
56
+ /** Global optimize configuration. */
57
+ optimize?: {
58
+ /** Whether enable tile rendering for first time. */
59
+ tileFirstRender?: boolean | number;
60
+ /** Tile size for first rendering. */
61
+ tileFirstRenderSize?: number;
62
+ /** Whether enable tile hiding / showing for behaivors, e.g. hiding shapes while drag-canvas, zoom-canvas. The enableOptimize in behavior configuration has higher priority. */
63
+ tileBehavior?: boolean | number;
64
+ /** Tile size for shape optimizing by behaviors, e.g. hiding shapes while drag-canvas, zoom-canvas. The enableOptimize in behavior configuration has higher priority. */
65
+ tileBehaviorSize?: number;
66
+ /** Tile size for level of detial changing. */
67
+ tileLodSize?: number;
68
+ };
50
69
  autoFit?:
51
70
  | 'view'
52
71
  | 'center'
@@ -79,9 +98,9 @@ export interface Specification<
79
98
  | TransformerFn[];
80
99
 
81
100
  /** item */
82
- node?: ((data: NodeModel) => NodeDisplayModel) | NodeEncode;
83
- edge?: ((data: EdgeModel) => EdgeDisplayModel) | EdgeEncode;
84
- combo?: ((data: ComboModel) => ComboDisplayModel) | ComboEncode;
101
+ node?: NodeMapper;
102
+ edge?: EdgeMapper;
103
+ combo?: ComboMapper;
85
104
 
86
105
  /** item state styles */
87
106
  nodeState?: {
package/src/util/bbox.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable prefer-spread */
2
2
  import { AABB } from '@antv/g';
3
- import { PolyPoint } from 'types/common';
3
+ import { Point, PolyPoint } from 'types/common';
4
4
 
5
5
  /**
6
6
  * Retrieve the width of a bounding box
@@ -296,3 +296,40 @@ export const isSegmentCrossingBBox = (
296
296
  }
297
297
  return false;
298
298
  };
299
+
300
+ /**
301
+ Determines whether a given point is inside a given bounding box.
302
+ @param {Point} point - The point to be checked.
303
+ @param {AABB} bbox - The bounding box.
304
+ @returns {boolean} - Returns true if the point is inside the bounding box, false otherwise.
305
+ */
306
+ export const isPointInBBox = (point: Point, bbox: AABB) => {
307
+ const { x, y } = point;
308
+ return (
309
+ x > bbox.min[0] && x < bbox.max[0] && y > bbox.min[1] && y < bbox.max[1]
310
+ );
311
+ };
312
+
313
+ /**
314
+ Determines whether a given sub-bounding box is fully contained within a given bounding box.
315
+ @param {AABB} subBBox - The sub-bounding box to be checked.
316
+ @param {AABB} bbox - The bounding box.
317
+ @param {number} [scale] - Optional scaling factor to adjust the size of the bounding box.
318
+ @returns {boolean} - Returns true if the sub-bounding box is fully contained within the bounding box, false otherwise.
319
+ */
320
+ export const isBBoxInBBox = (subBBox: AABB, bbox: AABB, scale?: number) => {
321
+ if (scale) {
322
+ return (
323
+ subBBox.min[0] > bbox.min[0] - bbox.halfExtents[0] * scale &&
324
+ subBBox.max[0] < bbox.max[0] + bbox.halfExtents[0] * scale &&
325
+ subBBox.min[1] > bbox.min[1] - bbox.halfExtents[1] * scale &&
326
+ subBBox.max[1] < bbox.max[1] + bbox.halfExtents[1] * scale
327
+ );
328
+ }
329
+ return (
330
+ subBBox.min[0] > bbox.min[0] &&
331
+ subBBox.max[0] < bbox.max[0] &&
332
+ subBBox.min[1] > bbox.min[1] &&
333
+ subBBox.max[1] < bbox.max[1]
334
+ );
335
+ };
package/src/util/item.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { ID } from '@antv/graphlib';
2
2
  import { Group } from '@antv/g';
3
+ import { uniqueId } from '@antv/util';
3
4
  import { IGraph } from '../types';
4
5
  import Combo from '../item/combo';
5
6
  import Edge from '../item/edge';
@@ -34,43 +35,62 @@ export const upsertTransientItem = (
34
35
  transientItemMap: Map<ID, Node | Edge | Combo | Group>,
35
36
  itemMap: Map<ID, Node | Edge | Combo>,
36
37
  graphCore?: GraphCore,
37
- onlyDrawKeyShape?: boolean,
38
+ drawOptions: {
39
+ shapeIds?: string[];
40
+ /** For transient edge */
41
+ drawSource?: boolean;
42
+ /** For transient edge */
43
+ drawTarget?: boolean;
44
+ visible?: boolean;
45
+ } = {},
38
46
  upsertAncestors = true,
39
47
  ) => {
40
48
  let transientItem = transientItemMap.get(item.model.id);
41
49
  if (transientItem) {
42
50
  return transientItem;
43
51
  }
52
+ const {
53
+ shapeIds,
54
+ drawSource = true,
55
+ drawTarget = true,
56
+ visible = true,
57
+ } = drawOptions;
44
58
  if (item.type === 'node') {
45
- transientItem = item.clone(nodeGroup, onlyDrawKeyShape, true) as Node;
59
+ transientItem = item.clone(nodeGroup, shapeIds, true);
46
60
  } else if (item.type === 'edge') {
47
- const source = upsertTransientItem(
48
- item.sourceItem,
49
- nodeGroup,
50
- edgeGroup,
51
- comboGroup,
52
- transientItemMap,
53
- itemMap,
54
- graphCore,
55
- onlyDrawKeyShape,
56
- false,
57
- ) as Node | Combo;
58
- const target = upsertTransientItem(
59
- item.targetItem,
60
- nodeGroup,
61
- edgeGroup,
62
- comboGroup,
63
- transientItemMap,
64
- itemMap,
65
- graphCore,
66
- onlyDrawKeyShape,
67
- false,
68
- ) as Node | Combo;
61
+ let source;
62
+ let target;
63
+ if (drawSource) {
64
+ source = upsertTransientItem(
65
+ item.sourceItem,
66
+ nodeGroup,
67
+ edgeGroup,
68
+ comboGroup,
69
+ transientItemMap,
70
+ itemMap,
71
+ graphCore,
72
+ drawOptions,
73
+ false,
74
+ ) as Node | Combo;
75
+ }
76
+ if (drawTarget) {
77
+ target = upsertTransientItem(
78
+ item.targetItem,
79
+ nodeGroup,
80
+ edgeGroup,
81
+ comboGroup,
82
+ transientItemMap,
83
+ itemMap,
84
+ graphCore,
85
+ drawOptions,
86
+ false,
87
+ ) as Node | Combo;
88
+ }
69
89
  transientItem = item.clone(
70
90
  edgeGroup,
71
91
  source,
72
92
  target,
73
- undefined,
93
+ shapeIds,
74
94
  true,
75
95
  ) as Edge;
76
96
  } else {
@@ -89,7 +109,7 @@ export const upsertTransientItem = (
89
109
  transientItemMap,
90
110
  itemMap,
91
111
  graphCore,
92
- onlyDrawKeyShape,
112
+ drawOptions,
93
113
  false,
94
114
  ),
95
115
  );
@@ -97,7 +117,7 @@ export const upsertTransientItem = (
97
117
  });
98
118
  transientItem = (item as Combo).clone(
99
119
  comboGroup,
100
- onlyDrawKeyShape,
120
+ shapeIds,
101
121
  true,
102
122
  () => getCombinedBoundsByItem(childItems), // getCombinedBounds
103
123
  () => childItems,
@@ -105,6 +125,7 @@ export const upsertTransientItem = (
105
125
  transientItem.toBack();
106
126
  }
107
127
  transientItemMap.set(item.model.id, transientItem);
128
+ // @ts-ignore
108
129
  transientItem.transient = true;
109
130
 
110
131
  if (
@@ -125,12 +146,28 @@ export const upsertTransientItem = (
125
146
  transientItemMap,
126
147
  itemMap,
127
148
  graphCore,
128
- onlyDrawKeyShape,
149
+ drawOptions,
129
150
  );
130
151
  transientAncestor.toBack();
131
152
  }
132
153
  currentAncestor = graphCore.getParent(currentAncestor.id, 'combo');
133
154
  }
134
155
  }
156
+
157
+ if (shapeIds?.length && visible) {
158
+ // @ts-ignore
159
+ (transientItem as Group).childNodes.forEach((shape) => shape.show());
160
+ }
135
161
  return transientItem;
136
162
  };
163
+
164
+ /**
165
+ * generate unique edge id
166
+ * @todo consider edges with same source and target
167
+ * @param source
168
+ * @param target
169
+ * @returns
170
+ */
171
+ export function generateEdgeID(source: ID, target: ID) {
172
+ return [source, target, uniqueId()].join('->');
173
+ }
package/src/util/shape.ts CHANGED
@@ -218,13 +218,13 @@ export const updateShapes = (
218
218
  if (prevShape !== newShape) {
219
219
  prevShape.remove();
220
220
  }
221
- if (newShape.style.display !== 'none') {
221
+ if (!newShape.destroyed && newShape.style.display !== 'none') {
222
222
  group.appendChild(newShape);
223
223
  }
224
224
  } else if (!prevShape && newShape) {
225
225
  // add newShapeMap - prevShapeMap
226
226
  finalShapeMap[id] = newShape;
227
- if (newShape.style.display !== 'none') {
227
+ if (!newShape.destroyed && newShape.style.display !== 'none') {
228
228
  group.appendChild(newShape);
229
229
  }
230
230
  } else if (prevShape && !newShape && removeDiff) {
@@ -0,0 +1,20 @@
1
+ /**
2
+ * optionName: 选项名
3
+ * shouldBe: 合法的输入参数
4
+ * now: 当前用户输入值
5
+ * scope: 选项所属的模块
6
+ */
7
+ type WarnOption = {
8
+ optionName: string;
9
+ shouldBe: any;
10
+ now: string | number;
11
+ scope: string;
12
+ };
13
+
14
+ export function warn({ optionName, shouldBe, now, scope }: WarnOption) {
15
+ console.warn(
16
+ `G6 [${scope}]: Invalid option, ${optionName} must be one of ${shouldBe.join(
17
+ ', ',
18
+ )}, but got ${now}`,
19
+ );
20
+ }