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

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 (221) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/esm/index.d.ts +15 -7
  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 +22 -2
  8. package/esm/item/edge.js +93 -42
  9. package/esm/item/edge.js.map +1 -1
  10. package/esm/item/item.js +9 -5
  11. package/esm/item/item.js.map +1 -1
  12. package/esm/item/node.d.ts +1 -1
  13. package/esm/item/node.js +22 -15
  14. package/esm/item/node.js.map +1 -1
  15. package/esm/runtime/controller/data.d.ts +7 -10
  16. package/esm/runtime/controller/data.js +123 -281
  17. package/esm/runtime/controller/data.js.map +1 -1
  18. package/esm/runtime/controller/item.d.ts +1 -0
  19. package/esm/runtime/controller/item.js +21 -9
  20. package/esm/runtime/controller/item.js.map +1 -1
  21. package/esm/runtime/graph.d.ts +85 -7
  22. package/esm/runtime/graph.js +396 -61
  23. package/esm/runtime/graph.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/create-edge.d.ts +57 -0
  27. package/esm/stdlib/behavior/create-edge.js +207 -0
  28. package/esm/stdlib/behavior/create-edge.js.map +1 -0
  29. package/esm/stdlib/behavior/drag-canvas.d.ts +2 -1
  30. package/esm/stdlib/behavior/drag-canvas.js +26 -18
  31. package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
  32. package/esm/stdlib/behavior/drag-combo.d.ts +2 -2
  33. package/esm/stdlib/behavior/drag-combo.js +35 -24
  34. package/esm/stdlib/behavior/drag-combo.js.map +1 -1
  35. package/esm/stdlib/behavior/drag-node.d.ts +3 -3
  36. package/esm/stdlib/behavior/drag-node.js +70 -57
  37. package/esm/stdlib/behavior/drag-node.js.map +1 -1
  38. package/esm/stdlib/behavior/index.d.ts +2 -0
  39. package/esm/stdlib/behavior/index.js +2 -0
  40. package/esm/stdlib/behavior/index.js.map +1 -1
  41. package/esm/stdlib/behavior/lasso-select.d.ts +1 -1
  42. package/esm/stdlib/behavior/lasso-select.js +1 -2
  43. package/esm/stdlib/behavior/lasso-select.js.map +1 -1
  44. package/esm/stdlib/behavior/scroll-canvas.d.ts +67 -0
  45. package/esm/stdlib/behavior/scroll-canvas.js +266 -0
  46. package/esm/stdlib/behavior/scroll-canvas.js.map +1 -0
  47. package/esm/stdlib/behavior/zoom-canvas.d.ts +2 -1
  48. package/esm/stdlib/behavior/zoom-canvas.js +30 -22
  49. package/esm/stdlib/behavior/zoom-canvas.js.map +1 -1
  50. package/esm/stdlib/data/mapNodeSize.d.ts +2 -2
  51. package/esm/stdlib/data/mapNodeSize.js +2 -2
  52. package/esm/stdlib/data/mapNodeSize.js.map +1 -1
  53. package/esm/stdlib/data/transformV4Data.d.ts +2 -2
  54. package/esm/stdlib/data/transformV4Data.js +2 -2
  55. package/esm/stdlib/data/transformV4Data.js.map +1 -1
  56. package/esm/stdlib/data/validateData.d.ts +2 -2
  57. package/esm/stdlib/data/validateData.js +9 -9
  58. package/esm/stdlib/data/validateData.js.map +1 -1
  59. package/esm/stdlib/index.d.ts +10 -6
  60. package/esm/stdlib/index.js +5 -1
  61. package/esm/stdlib/index.js.map +1 -1
  62. package/esm/stdlib/item/edge/base.js +4 -9
  63. package/esm/stdlib/item/edge/base.js.map +1 -1
  64. package/esm/stdlib/plugin/hull/hullComponent.d.ts +1 -1
  65. package/esm/stdlib/plugin/hull/hullComponent.js +3 -6
  66. package/esm/stdlib/plugin/hull/hullComponent.js.map +1 -1
  67. package/esm/stdlib/plugin/minimap/index.d.ts +5 -1
  68. package/esm/stdlib/plugin/minimap/index.js +116 -9
  69. package/esm/stdlib/plugin/minimap/index.js.map +1 -1
  70. package/esm/stdlib/plugin/snapline/index.d.ts +5 -1
  71. package/esm/stdlib/plugin/snapline/index.js +23 -12
  72. package/esm/stdlib/plugin/snapline/index.js.map +1 -1
  73. package/esm/types/graph.d.ts +34 -8
  74. package/esm/types/hook.d.ts +16 -2
  75. package/esm/types/spec.d.ts +6 -3
  76. package/esm/types/view.d.ts +5 -0
  77. package/esm/util/event.d.ts +3 -1
  78. package/esm/util/event.js +8 -1
  79. package/esm/util/event.js.map +1 -1
  80. package/esm/util/item.d.ts +16 -1
  81. package/esm/util/item.js +31 -8
  82. package/esm/util/item.js.map +1 -1
  83. package/esm/util/layout.d.ts +11 -0
  84. package/esm/util/layout.js +45 -0
  85. package/esm/util/layout.js.map +1 -1
  86. package/esm/util/point.js +5 -1
  87. package/esm/util/point.js.map +1 -1
  88. package/esm/util/shape.d.ts +1 -1
  89. package/esm/util/shape.js +3 -7
  90. package/esm/util/shape.js.map +1 -1
  91. package/esm/util/warn.d.ts +14 -0
  92. package/esm/util/warn.js +4 -0
  93. package/esm/util/warn.js.map +1 -0
  94. package/lib/index.d.ts +15 -7
  95. package/lib/index.js +1 -1
  96. package/lib/item/combo.d.ts +1 -1
  97. package/lib/item/combo.js +16 -9
  98. package/lib/item/combo.js.map +1 -1
  99. package/lib/item/edge.d.ts +22 -2
  100. package/lib/item/edge.js +92 -41
  101. package/lib/item/edge.js.map +1 -1
  102. package/lib/item/item.js +9 -5
  103. package/lib/item/item.js.map +1 -1
  104. package/lib/item/node.d.ts +1 -1
  105. package/lib/item/node.js +22 -15
  106. package/lib/item/node.js.map +1 -1
  107. package/lib/runtime/controller/data.d.ts +7 -10
  108. package/lib/runtime/controller/data.js +123 -281
  109. package/lib/runtime/controller/data.js.map +1 -1
  110. package/lib/runtime/controller/item.d.ts +1 -0
  111. package/lib/runtime/controller/item.js +21 -9
  112. package/lib/runtime/controller/item.js.map +1 -1
  113. package/lib/runtime/graph.d.ts +85 -7
  114. package/lib/runtime/graph.js +396 -61
  115. package/lib/runtime/graph.js.map +1 -1
  116. package/lib/stdlib/behavior/brush-select.js +1 -2
  117. package/lib/stdlib/behavior/brush-select.js.map +1 -1
  118. package/lib/stdlib/behavior/create-edge.d.ts +57 -0
  119. package/lib/stdlib/behavior/create-edge.js +211 -0
  120. package/lib/stdlib/behavior/create-edge.js.map +1 -0
  121. package/lib/stdlib/behavior/drag-canvas.d.ts +2 -1
  122. package/lib/stdlib/behavior/drag-canvas.js +26 -18
  123. package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
  124. package/lib/stdlib/behavior/drag-combo.d.ts +2 -2
  125. package/lib/stdlib/behavior/drag-combo.js +35 -24
  126. package/lib/stdlib/behavior/drag-combo.js.map +1 -1
  127. package/lib/stdlib/behavior/drag-node.d.ts +3 -3
  128. package/lib/stdlib/behavior/drag-node.js +70 -57
  129. package/lib/stdlib/behavior/drag-node.js.map +1 -1
  130. package/lib/stdlib/behavior/index.d.ts +2 -0
  131. package/lib/stdlib/behavior/index.js +2 -0
  132. package/lib/stdlib/behavior/index.js.map +1 -1
  133. package/lib/stdlib/behavior/lasso-select.d.ts +1 -1
  134. package/lib/stdlib/behavior/lasso-select.js +1 -2
  135. package/lib/stdlib/behavior/lasso-select.js.map +1 -1
  136. package/lib/stdlib/behavior/scroll-canvas.d.ts +67 -0
  137. package/lib/stdlib/behavior/scroll-canvas.js +270 -0
  138. package/lib/stdlib/behavior/scroll-canvas.js.map +1 -0
  139. package/lib/stdlib/behavior/zoom-canvas.d.ts +2 -1
  140. package/lib/stdlib/behavior/zoom-canvas.js +30 -22
  141. package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
  142. package/lib/stdlib/data/mapNodeSize.d.ts +2 -2
  143. package/lib/stdlib/data/mapNodeSize.js +2 -2
  144. package/lib/stdlib/data/mapNodeSize.js.map +1 -1
  145. package/lib/stdlib/data/transformV4Data.d.ts +2 -2
  146. package/lib/stdlib/data/transformV4Data.js +2 -2
  147. package/lib/stdlib/data/transformV4Data.js.map +1 -1
  148. package/lib/stdlib/data/validateData.d.ts +2 -2
  149. package/lib/stdlib/data/validateData.js +9 -9
  150. package/lib/stdlib/data/validateData.js.map +1 -1
  151. package/lib/stdlib/index.d.ts +10 -6
  152. package/lib/stdlib/index.js +5 -1
  153. package/lib/stdlib/index.js.map +1 -1
  154. package/lib/stdlib/item/edge/base.js +4 -9
  155. package/lib/stdlib/item/edge/base.js.map +1 -1
  156. package/lib/stdlib/plugin/hull/hullComponent.d.ts +1 -1
  157. package/lib/stdlib/plugin/hull/hullComponent.js +3 -6
  158. package/lib/stdlib/plugin/hull/hullComponent.js.map +1 -1
  159. package/lib/stdlib/plugin/minimap/index.d.ts +5 -1
  160. package/lib/stdlib/plugin/minimap/index.js +116 -9
  161. package/lib/stdlib/plugin/minimap/index.js.map +1 -1
  162. package/lib/stdlib/plugin/snapline/index.d.ts +5 -1
  163. package/lib/stdlib/plugin/snapline/index.js +23 -12
  164. package/lib/stdlib/plugin/snapline/index.js.map +1 -1
  165. package/lib/types/graph.d.ts +34 -8
  166. package/lib/types/hook.d.ts +16 -2
  167. package/lib/types/spec.d.ts +6 -3
  168. package/lib/types/view.d.ts +5 -0
  169. package/lib/util/event.d.ts +3 -1
  170. package/lib/util/event.js +8 -1
  171. package/lib/util/event.js.map +1 -1
  172. package/lib/util/item.d.ts +16 -1
  173. package/lib/util/item.js +33 -9
  174. package/lib/util/item.js.map +1 -1
  175. package/lib/util/layout.d.ts +11 -0
  176. package/lib/util/layout.js +47 -1
  177. package/lib/util/layout.js.map +1 -1
  178. package/lib/util/point.js +5 -1
  179. package/lib/util/point.js.map +1 -1
  180. package/lib/util/shape.d.ts +1 -1
  181. package/lib/util/shape.js +3 -7
  182. package/lib/util/shape.js.map +1 -1
  183. package/lib/util/warn.d.ts +14 -0
  184. package/lib/util/warn.js +8 -0
  185. package/lib/util/warn.js.map +1 -0
  186. package/package.json +1 -1
  187. package/src/index.ts +1 -1
  188. package/src/item/combo.ts +14 -9
  189. package/src/item/edge.ts +121 -55
  190. package/src/item/item.ts +13 -9
  191. package/src/item/node.ts +20 -15
  192. package/src/runtime/controller/data.ts +139 -339
  193. package/src/runtime/controller/item.ts +30 -12
  194. package/src/runtime/graph.ts +502 -67
  195. package/src/stdlib/behavior/brush-select.ts +4 -2
  196. package/src/stdlib/behavior/create-edge.ts +296 -0
  197. package/src/stdlib/behavior/drag-canvas.ts +30 -19
  198. package/src/stdlib/behavior/drag-combo.ts +2 -2
  199. package/src/stdlib/behavior/drag-node.ts +8 -8
  200. package/src/stdlib/behavior/index.ts +2 -0
  201. package/src/stdlib/behavior/lasso-select.ts +5 -3
  202. package/src/stdlib/behavior/scroll-canvas.ts +348 -0
  203. package/src/stdlib/behavior/zoom-canvas.ts +34 -23
  204. package/src/stdlib/data/mapNodeSize.ts +2 -2
  205. package/src/stdlib/data/transformV4Data.ts +2 -2
  206. package/src/stdlib/data/validateData.ts +9 -9
  207. package/src/stdlib/index.ts +6 -0
  208. package/src/stdlib/item/edge/base.ts +4 -8
  209. package/src/stdlib/plugin/hull/hullComponent.ts +8 -5
  210. package/src/stdlib/plugin/minimap/index.ts +120 -10
  211. package/src/stdlib/plugin/snapline/index.ts +36 -16
  212. package/src/types/graph.ts +37 -8
  213. package/src/types/hook.ts +16 -2
  214. package/src/types/spec.ts +9 -3
  215. package/src/types/view.ts +8 -3
  216. package/src/util/event.ts +14 -1
  217. package/src/util/item.ts +65 -28
  218. package/src/util/layout.ts +45 -0
  219. package/src/util/point.ts +4 -2
  220. package/src/util/shape.ts +6 -7
  221. package/src/util/warn.ts +20 -0
@@ -54,6 +54,8 @@ export class Minimap extends Base {
54
54
  private dx: number;
55
55
  /** Distance from left of minimap graph to the left of minimap container. */
56
56
  private dy: number;
57
+ /** Cache the visibility while items' visibility changed. And apply them onto the minimap with debounce. */
58
+ private visibleCache: { [id: string]: boolean } = {};
57
59
 
58
60
  constructor(options?: MiniMapConfig) {
59
61
  super(options);
@@ -80,11 +82,11 @@ export class Minimap extends Base {
80
82
 
81
83
  public getEvents() {
82
84
  return {
83
- afterupdateitem: this.handleUpdateCanvas,
84
85
  afteritemstatechange: this.handleUpdateCanvas,
85
86
  afterlayout: this.handleUpdateCanvas,
86
87
  viewportchange: this.handleUpdateCanvas,
87
88
  afteritemchange: this.handleUpdateCanvas,
89
+ afteritemvisibilitychange: this.handleVisibilityChange,
88
90
  };
89
91
  }
90
92
 
@@ -115,12 +117,12 @@ export class Minimap extends Base {
115
117
  style='position:absolute;
116
118
  left:0;
117
119
  top:0;
118
- box-sizing:border-box;
119
120
  border: 2px solid #1980ff;
121
+ box-sizing:border-box;
120
122
  background: rgba(0, 0, 255, 0.1);
121
123
  cursor:move'
122
124
  draggable=${isSafari || isFireFox ? false : true}
123
- </div>`);
125
+ />`);
124
126
 
125
127
  // Last mouse x position
126
128
  let x = 0;
@@ -128,11 +130,25 @@ export class Minimap extends Base {
128
130
  let y = 0;
129
131
  // Whether in dragging status
130
132
  let dragging = false;
133
+ let resizing = false;
131
134
 
132
135
  const dragstartevent = isSafari || isFireFox ? 'mousedown' : 'dragstart';
136
+ this.container.addEventListener('mousemove', (e) => {
137
+ const moveAtBorder = getMoveAtBorder(viewport, e);
138
+ if (moveAtBorder) {
139
+ this.container.style.cursor = cursorMap[moveAtBorder];
140
+ viewport.style.cursor = cursorMap[moveAtBorder];
141
+ } else {
142
+ this.container.style.cursor = 'unset';
143
+ viewport.style.cursor = 'move';
144
+ }
145
+ });
133
146
  viewport.addEventListener(
134
147
  dragstartevent,
135
148
  ((e: IG6GraphEvent) => {
149
+ resizing = getMoveAtBorder(viewport, e);
150
+ if (resizing) return;
151
+
136
152
  if ((e as any).dataTransfer) {
137
153
  const img = new Image();
138
154
  img.src =
@@ -159,6 +175,30 @@ export class Minimap extends Base {
159
175
  );
160
176
 
161
177
  const dragListener = (e: IG6GraphEvent) => {
178
+ const { style } = viewport;
179
+ const left = parseInt(style.left, 10);
180
+ const top = parseInt(style.top, 10);
181
+ const width = parseInt(style.width, 10);
182
+ const height = parseInt(style.height, 10);
183
+
184
+ if (resizing) {
185
+ const { clientX, clientY } = e;
186
+ const afterResize = { left, top, width, height };
187
+ if (resizing.includes('left')) {
188
+ afterResize.left = `${clientX}px`;
189
+ afterResize.width = `${left + width - clientX}px`;
190
+ } else if (resizing.includes('right')) {
191
+ afterResize.width = `${clientX - left}px`;
192
+ }
193
+ if (resizing.includes('top')) {
194
+ afterResize.top = `${clientY}`;
195
+ afterResize.height = `${top + height - clientY}`;
196
+ } else if (resizing.includes('bottom')) {
197
+ afterResize.height = `${clientY - top}`;
198
+ }
199
+ modifyCSS(viewport, afterResize);
200
+ return;
201
+ }
162
202
  if (!dragging || isNil(e.clientX) || isNil(e.clientY)) {
163
203
  return;
164
204
  }
@@ -168,12 +208,6 @@ export class Minimap extends Base {
168
208
  let dx = x - e.clientX;
169
209
  let dy = y - e.clientY;
170
210
 
171
- const { style } = viewport;
172
- const left = parseInt(style.left, 10);
173
- const top = parseInt(style.top, 10);
174
- const width = parseInt(style.width, 10);
175
- const height = parseInt(style.height, 10);
176
-
177
211
  // If the viewport is already on the left or right, stop moving x.
178
212
  if (left - dx < 0 || left - dx + width >= size[0]) {
179
213
  dx = 0;
@@ -201,6 +235,7 @@ export class Minimap extends Base {
201
235
 
202
236
  const dragendListener = () => {
203
237
  dragging = false;
238
+ resizing = false;
204
239
  this.options.refresh = true;
205
240
  };
206
241
  const dragendevent = isSafari || isFireFox ? 'mouseup' : 'dragend';
@@ -467,8 +502,12 @@ export class Minimap extends Base {
467
502
  if (!graphEdgeGroup) return;
468
503
  let { minimapItem, graphItem } = itemMap.get(edgeModel.id) || {};
469
504
  if (minimapItem && !minimapItem.destroyed) {
470
- const path = graphItem.style.path;
505
+ const { path, x1, x2, y1, y2 } = graphItem.style;
471
506
  minimapItem.style.path = path;
507
+ minimapItem.style.x1 = x1;
508
+ minimapItem.style.x2 = x2;
509
+ minimapItem.style.y1 = y1;
510
+ minimapItem.style.y2 = y2;
472
511
  } else {
473
512
  graphItem = graphEdgeGroup
474
513
  .find((ele) => ele.getAttribute('data-item-id') === edgeModel.id)
@@ -549,6 +588,36 @@ export class Minimap extends Base {
549
588
  false,
550
589
  );
551
590
 
591
+ private handleVisibilityChange = (params) => {
592
+ const { ids, value } = params;
593
+ ids.forEach((id) => {
594
+ this.visibleCache[id] = value;
595
+ });
596
+ this.debounceCloneVisibility();
597
+ };
598
+
599
+ private debounceCloneVisibility = debounce(
600
+ () => {
601
+ const nodeGroup = this.canvas.getRoot().getElementById('node-group');
602
+ const edgeGroup = this.canvas.getRoot().getElementById('edge-group');
603
+ (nodeGroup?.childNodes || [])
604
+ .concat(edgeGroup?.childNodes || [])
605
+ .forEach((child) => {
606
+ const id = child.getAttribute?.('data-item-id');
607
+ if (this.visibleCache.hasOwnProperty(id)) {
608
+ if (this.visibleCache[id]) {
609
+ child.childNodes.forEach((shape) => shape.show());
610
+ } else if (this.visibleCache[id] === false) {
611
+ child.childNodes.forEach((shape) => shape.hide());
612
+ }
613
+ }
614
+ });
615
+ this.visibleCache = {};
616
+ },
617
+ 50,
618
+ false,
619
+ );
620
+
552
621
  public init(graph: IGraph) {
553
622
  super.init(graph);
554
623
  const promise = this.initContainer();
@@ -696,3 +765,44 @@ export class Minimap extends Base {
696
765
  if (container?.parentNode) container.parentNode.removeChild(container);
697
766
  }
698
767
  }
768
+
769
+ const getMoveAtBorder = (dom, evt) => {
770
+ const bounds = dom.getBoundingClientRect();
771
+ const { clientX, clientY } = evt;
772
+ if (Math.abs(clientX - bounds.x) < 4 && Math.abs(clientY - bounds.y) < 4) {
773
+ return 'left-top';
774
+ } else if (
775
+ Math.abs(clientX - bounds.x) < 4 &&
776
+ Math.abs(clientY - bounds.y - bounds.height) < 4
777
+ ) {
778
+ return 'left-bottom';
779
+ } else if (
780
+ Math.abs(clientX - bounds.x - bounds.width) < 4 &&
781
+ Math.abs(clientY - bounds.y) < 4
782
+ ) {
783
+ return 'right-top';
784
+ } else if (
785
+ Math.abs(clientX - bounds.x - bounds.width) < 4 &&
786
+ Math.abs(clientY - bounds.y - bounds.height) < 4
787
+ ) {
788
+ return 'right-bottom';
789
+ } else if (Math.abs(clientX - bounds.x) < 4) {
790
+ return 'left';
791
+ } else if (Math.abs(clientY - bounds.y) < 4) {
792
+ return 'top';
793
+ } else if (Math.abs(clientY - bounds.y - bounds.height) < 4) {
794
+ return 'bottom';
795
+ }
796
+ return false;
797
+ };
798
+
799
+ const cursorMap = {
800
+ 'left-top': 'nwse-resize',
801
+ 'right-bottom': 'nwse-resize',
802
+ 'right-top': 'nesw-resize',
803
+ 'left-bottom': 'nesw-resize',
804
+ left: 'ew-resize',
805
+ right: 'ew-resize',
806
+ top: 'ns-resize',
807
+ bottom: 'ns-resize',
808
+ };
@@ -2,7 +2,7 @@ import { ID } from '@antv/graphlib';
2
2
  import { AABB, DisplayObject } from '@antv/g';
3
3
  import { throttle } from '@antv/util';
4
4
  import { ITEM_TYPE, ShapeStyle } from '../../../types/item';
5
- import { IG6GraphEvent, IGraph } from '../../../types';
5
+ import { IG6GraphEvent, IGraph, NodeModel } from '../../../types';
6
6
  import { Plugin as Base, IPluginBaseConfig } from '../../../types/plugin';
7
7
  import { Point } from '../../../types/common';
8
8
 
@@ -46,6 +46,11 @@ export class Snapline extends Base {
46
46
  offsetY: number | undefined,
47
47
  ] = [undefined, undefined];
48
48
 
49
+ /**
50
+ * Cache the nodes' positions to be throttly updated.
51
+ */
52
+ private updateCache: Map<ID, NodeModel> = new Map();
53
+
49
54
  /**
50
55
  * Gets the current cursor node and center offset and then with initialOffset difference
51
56
  */
@@ -70,14 +75,9 @@ export class Snapline extends Base {
70
75
  ];
71
76
  };
72
77
 
73
- //#endregion
74
-
75
78
  private dragging = false;
76
79
  private draggingBBox: AABB = undefined;
77
80
 
78
- // the offset(cursor and draggingbox) when start to drag
79
- private nonAbosorbOffset: Point = undefined;
80
-
81
81
  // Gets the offset between the cursor and draggingItem
82
82
  private getPointerOffsetWithItem = (pointer: {
83
83
  x: number;
@@ -118,6 +118,7 @@ export class Snapline extends Base {
118
118
  * @param dl drawLine
119
119
  */
120
120
  getDrawLineIdByDrawLine(dl: DrawLine): ID {
121
+ if (!dl) return;
121
122
  return `${dl.line[0].x}-${dl.line[0].y}-${dl.line[1].x}-${dl.line[1].y}`;
122
123
  }
123
124
  /**
@@ -777,11 +778,6 @@ export class Snapline extends Base {
777
778
  event.canvas.x - this.draggingBBox.center[0],
778
779
  event.canvas.y - this.draggingBBox.center[1],
779
780
  ];
780
-
781
- this.nonAbosorbOffset = this.getPointerOffsetWithItem({
782
- x: event.canvas.x,
783
- y: event.canvas.y,
784
- });
785
781
  }
786
782
 
787
783
  onDrag = throttle(
@@ -790,7 +786,7 @@ export class Snapline extends Base {
790
786
 
791
787
  this.initAlignLinesForChoose();
792
788
 
793
- // control layer:Check to delete existing line & drawed line & adsorption
789
+ // control layer: Check to delete existing line & drawed line & adsorption
794
790
  // set historyPoints
795
791
 
796
792
  this.historyPoints[0] = this.historyPoints[1];
@@ -936,10 +932,10 @@ export class Snapline extends Base {
936
932
  }
937
933
  }
938
934
  }).bind(this),
939
- 10,
935
+ 16,
940
936
  {
941
- leading: true,
942
- trailing: false,
937
+ leading: false,
938
+ trailing: true,
943
939
  },
944
940
  );
945
941
 
@@ -1272,6 +1268,30 @@ export class Snapline extends Base {
1272
1268
  }
1273
1269
 
1274
1270
  doUpdatePosition(data) {
1275
- this.graph.updateNodePosition({ id: this.dragItemId, data }, false, true);
1271
+ const cache = this.updateCache.get(this.dragItemId);
1272
+ this.updateCache.set(this.dragItemId, {
1273
+ id: this.dragItemId,
1274
+ data: {
1275
+ ...cache?.data,
1276
+ ...data,
1277
+ },
1278
+ });
1279
+ this.throttleUpdate();
1276
1280
  }
1281
+
1282
+ throttleUpdate = throttle(
1283
+ () => {
1284
+ this.graph.updateNodePosition(
1285
+ Array.from(this.updateCache.values()),
1286
+ false,
1287
+ true,
1288
+ );
1289
+ this.updateCache.clear();
1290
+ },
1291
+ 16,
1292
+ {
1293
+ leading: true,
1294
+ trailing: true,
1295
+ },
1296
+ );
1277
1297
  }
@@ -1,5 +1,5 @@
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';
@@ -10,11 +10,11 @@ import { Padding, Point } from './common';
10
10
  import { GraphData } from './data';
11
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
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
@@ -389,8 +395,8 @@ export interface IGraph<
389
395
  */
390
396
  fitView: (
391
397
  options?: {
392
- padding: Padding;
393
- rules: FitViewRules;
398
+ padding?: Padding;
399
+ rules?: FitViewRules;
394
400
  },
395
401
  effectTiming?: CameraAnimationOptions,
396
402
  ) => Promise<void>;
@@ -400,7 +406,10 @@ export interface IGraph<
400
406
  * @returns
401
407
  * @group View
402
408
  */
403
- fitCenter: (effectTiming?: CameraAnimationOptions) => Promise<void>;
409
+ fitCenter: (
410
+ boundsType?: 'render' | 'layout',
411
+ effectTiming?: CameraAnimationOptions,
412
+ ) => Promise<void>;
404
413
  /**
405
414
  * Move the graph to make the item align the view center.
406
415
  * @param item node/edge/combo item or its id
@@ -595,6 +604,11 @@ export interface IGraph<
595
604
  * @group Interaction
596
605
  */
597
606
  getMode: () => string;
607
+ /**
608
+ * Set the cursor. But the cursor in item's style has higher priority.
609
+ * @param cursor
610
+ */
611
+ setCursor: (cursor: Cursor) => void;
598
612
  /**
599
613
  * Add behavior(s) to mode(s).
600
614
  * @param behaviors behavior names or configs
@@ -632,7 +646,22 @@ export interface IGraph<
632
646
  drawTransient: (
633
647
  type: ITEM_TYPE | SHAPE_TYPE,
634
648
  id: ID,
635
- config: any,
649
+ config: {
650
+ action?: 'remove' | 'add' | 'update' | undefined;
651
+ /** Data to be merged into the transient item. */
652
+ data?: Record<string, any>;
653
+ /** Style to be merged into the transient shape. */
654
+ style?: ShapeStyle;
655
+ /** For type: 'edge' */
656
+ drawSource?: boolean;
657
+ /** For type: 'edge' */
658
+ drawTarget?: boolean;
659
+ /** 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. */
660
+ shapeIds?: string[];
661
+ /** Whether show the shapes in shapeIds. True by default. */
662
+ visible?: boolean;
663
+ upsertAncestors?: boolean;
664
+ },
636
665
  canvas?: Canvas,
637
666
  ) => DisplayObject;
638
667
 
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;
@@ -101,8 +102,17 @@ export interface Hooks {
101
102
  id: ID;
102
103
  canvas: Canvas;
103
104
  config: {
104
- style: ShapeStyle;
105
- 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;
106
116
  };
107
117
  graphCore: GraphCore;
108
118
  }>;
@@ -124,6 +134,10 @@ export interface Hooks {
124
134
  transient: Canvas;
125
135
  };
126
136
  }>;
137
+ mapperchange: IHook<{
138
+ type: ITEM_TYPE;
139
+ mapper: NodeMapper | EdgeMapper | ComboMapper;
140
+ }>;
127
141
  treecollapseexpand: IHook<{
128
142
  ids: ID[];
129
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,
@@ -92,9 +98,9 @@ export interface Specification<
92
98
  | TransformerFn[];
93
99
 
94
100
  /** item */
95
- node?: ((data: NodeModel) => NodeDisplayModel) | NodeEncode;
96
- edge?: ((data: EdgeModel) => EdgeDisplayModel) | EdgeEncode;
97
- combo?: ((data: ComboModel) => ComboDisplayModel) | ComboEncode;
101
+ node?: NodeMapper;
102
+ edge?: EdgeMapper;
103
+ combo?: ComboMapper;
98
104
 
99
105
  /** item state styles */
100
106
  nodeState?: {
package/src/types/view.ts CHANGED
@@ -1,7 +1,12 @@
1
1
  export interface FitViewRules {
2
- onlyOutOfViewPort?: boolean; // Whehter fit it only when the graph is out of the view.
3
- direction?: 'x' | 'y' | 'both'; // Axis to fit.
4
- ratioRule?: 'max' | 'min'; // Ratio rule to fit.
2
+ /** Whehter fit it only when the graph is out of the view. */
3
+ onlyOutOfViewPort?: boolean;
4
+ /** Axis to fit. */
5
+ direction?: 'x' | 'y' | 'both';
6
+ /** Ratio rule to fit. */
7
+ ratioRule?: 'max' | 'min';
8
+ /** Bounds type. 'render' means calculate the bounds by get rendering bounds. 'layout' for the situation that layout algorithm is done but the positions are not animated rendered. */
9
+ boundsType?: 'render' | 'layout';
5
10
  }
6
11
 
7
12
  export type GraphAlignment =
package/src/util/event.ts CHANGED
@@ -9,6 +9,8 @@ import {
9
9
  NodeDataUpdated,
10
10
  NodeRemoved,
11
11
  TreeStructureChanged,
12
+ TreeStructureAttached,
13
+ TreeStructureDetached,
12
14
  } from '@antv/graphlib';
13
15
  import { IG6GraphEvent, IGraph, NodeModelData } from '../types';
14
16
  import { GraphCore } from '../types/data';
@@ -84,6 +86,8 @@ export type GroupedChanges = {
84
86
  EdgeDataUpdated: EdgeDataUpdated<EdgeModelData>[];
85
87
  TreeStructureChanged: TreeStructureChanged[];
86
88
  ComboStructureChanged: TreeStructureChanged[];
89
+ TreeStructureAttached: TreeStructureAttached[];
90
+ TreeStructureDetached: TreeStructureDetached[];
87
91
  };
88
92
 
89
93
  /**
@@ -106,6 +110,8 @@ export const getGroupedChanges = (
106
110
  EdgeDataUpdated: [],
107
111
  TreeStructureChanged: [],
108
112
  ComboStructureChanged: [],
113
+ TreeStructureAttached: [],
114
+ TreeStructureDetached: [],
109
115
  };
110
116
  changes.forEach((change) => {
111
117
  const { type: changeType } = change;
@@ -126,7 +132,14 @@ export const getGroupedChanges = (
126
132
  else if (change.treeKey === 'tree')
127
133
  groupedChanges.TreeStructureChanged.push(change);
128
134
  return;
129
- } else if (['NodeRemoved', 'EdgeRemoved'].includes(changeType)) {
135
+ } else if (
136
+ [
137
+ 'NodeRemoved',
138
+ 'EdgeRemoved',
139
+ 'TreeStructureAttached',
140
+ 'TreeStructureDetached',
141
+ ].includes(changeType)
142
+ ) {
130
143
  groupedChanges[changeType].push(change);
131
144
  } else {
132
145
  const { id: oid } = change.value;
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, uniqueId(), target].join('->');
173
+ }