@antv/g6 5.0.0-beta.26 → 5.0.0-beta.27

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 (324) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/esm/constant/shape.d.ts +1 -1
  3. package/esm/index.d.ts +3 -1
  4. package/esm/index.js +1 -1
  5. package/esm/item/combo.d.ts +6 -4
  6. package/esm/item/combo.js +10 -3
  7. package/esm/item/combo.js.map +1 -1
  8. package/esm/item/edge.d.ts +12 -4
  9. package/esm/item/edge.js +100 -17
  10. package/esm/item/edge.js.map +1 -1
  11. package/esm/item/item.d.ts +18 -8
  12. package/esm/item/item.js +103 -59
  13. package/esm/item/item.js.map +1 -1
  14. package/esm/item/node.d.ts +10 -4
  15. package/esm/item/node.js +92 -8
  16. package/esm/item/node.js.map +1 -1
  17. package/esm/runtime/controller/data.d.ts +5 -1
  18. package/esm/runtime/controller/data.js +38 -1
  19. package/esm/runtime/controller/data.js.map +1 -1
  20. package/esm/runtime/controller/index.d.ts +1 -1
  21. package/esm/runtime/controller/index.js +1 -1
  22. package/esm/runtime/controller/index.js.map +1 -1
  23. package/esm/runtime/controller/item.d.ts +22 -11
  24. package/esm/runtime/controller/item.js +241 -96
  25. package/esm/runtime/controller/item.js.map +1 -1
  26. package/esm/runtime/controller/layout.d.ts +3 -0
  27. package/esm/runtime/controller/layout.js +178 -98
  28. package/esm/runtime/controller/layout.js.map +1 -1
  29. package/esm/runtime/controller/plugin.d.ts +3 -0
  30. package/esm/runtime/controller/plugin.js +66 -24
  31. package/esm/runtime/controller/plugin.js.map +1 -1
  32. package/esm/runtime/controller/viewport.js +9 -2
  33. package/esm/runtime/controller/viewport.js.map +1 -1
  34. package/esm/runtime/graph.d.ts +57 -26
  35. package/esm/runtime/graph.js +263 -139
  36. package/esm/runtime/graph.js.map +1 -1
  37. package/esm/stdlib/behavior/click-select.js +9 -3
  38. package/esm/stdlib/behavior/click-select.js.map +1 -1
  39. package/esm/stdlib/behavior/drag-canvas.js +6 -3
  40. package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
  41. package/esm/stdlib/behavior/drag-combo.js +8 -8
  42. package/esm/stdlib/behavior/drag-combo.js.map +1 -1
  43. package/esm/stdlib/behavior/drag-node.d.ts +4 -0
  44. package/esm/stdlib/behavior/drag-node.js +121 -27
  45. package/esm/stdlib/behavior/drag-node.js.map +1 -1
  46. package/esm/stdlib/behavior/scroll-canvas.js +3 -3
  47. package/esm/stdlib/behavior/scroll-canvas.js.map +1 -1
  48. package/esm/stdlib/behavior/zoom-canvas.js +3 -3
  49. package/esm/stdlib/behavior/zoom-canvas.js.map +1 -1
  50. package/esm/stdlib/data/mapNodeSize.js +2 -2
  51. package/esm/stdlib/data/mapNodeSize.js.map +1 -1
  52. package/esm/stdlib/data/validateData.js +2 -2
  53. package/esm/stdlib/data/validateData.js.map +1 -1
  54. package/esm/stdlib/index.d.ts +2 -0
  55. package/esm/stdlib/index.js +3 -1
  56. package/esm/stdlib/index.js.map +1 -1
  57. package/esm/stdlib/item/edge/base.d.ts +2 -11
  58. package/esm/stdlib/item/edge/base.js +12 -105
  59. package/esm/stdlib/item/edge/base.js.map +1 -1
  60. package/esm/stdlib/item/node/base.d.ts +2 -20
  61. package/esm/stdlib/item/node/base.js +10 -150
  62. package/esm/stdlib/item/node/base.js.map +1 -1
  63. package/esm/stdlib/plugin/edgeFilterLens/index.js +2 -2
  64. package/esm/stdlib/plugin/edgeFilterLens/index.js.map +1 -1
  65. package/esm/stdlib/plugin/fisheye/index.js +3 -2
  66. package/esm/stdlib/plugin/fisheye/index.js.map +1 -1
  67. package/esm/stdlib/plugin/history/visibility-updated-command.js +2 -2
  68. package/esm/stdlib/plugin/history/visibility-updated-command.js.map +1 -1
  69. package/esm/stdlib/plugin/hull/index.d.ts +1 -1
  70. package/esm/stdlib/plugin/index.d.ts +1 -0
  71. package/esm/stdlib/plugin/index.js +1 -0
  72. package/esm/stdlib/plugin/index.js.map +1 -1
  73. package/esm/stdlib/plugin/lodController/index.d.ts +73 -0
  74. package/esm/stdlib/plugin/lodController/index.js +556 -0
  75. package/esm/stdlib/plugin/lodController/index.js.map +1 -0
  76. package/esm/stdlib/plugin/minimap/index.js +12 -14
  77. package/esm/stdlib/plugin/minimap/index.js.map +1 -1
  78. package/esm/stdlib/plugin/toolbar/index.d.ts +2 -2
  79. package/esm/stdlib/plugin/toolbar/index.js +27 -29
  80. package/esm/stdlib/plugin/toolbar/index.js.map +1 -1
  81. package/esm/stdlib/theme/dark.js +32 -35
  82. package/esm/stdlib/theme/dark.js.map +1 -1
  83. package/esm/stdlib/theme/light.js +27 -30
  84. package/esm/stdlib/theme/light.js.map +1 -1
  85. package/esm/stdlib/themeSolver/spec.js +2 -2
  86. package/esm/stdlib/themeSolver/spec.js.map +1 -1
  87. package/esm/types/animate.d.ts +1 -1
  88. package/esm/types/combo.d.ts +2 -2
  89. package/esm/types/edge.d.ts +2 -2
  90. package/esm/types/graph.d.ts +62 -43
  91. package/esm/types/hook.d.ts +5 -0
  92. package/esm/types/item.d.ts +9 -15
  93. package/esm/types/layout.d.ts +7 -2
  94. package/esm/types/layout.js.map +1 -1
  95. package/esm/types/node.d.ts +3 -2
  96. package/esm/types/plugin.d.ts +1 -0
  97. package/esm/types/plugin.js +1 -0
  98. package/esm/types/plugin.js.map +1 -1
  99. package/esm/types/spec.d.ts +1 -0
  100. package/esm/types/theme.d.ts +7 -7
  101. package/esm/util/animate.d.ts +7 -2
  102. package/esm/util/animate.js +37 -23
  103. package/esm/util/animate.js.map +1 -1
  104. package/esm/util/bbox.d.ts +7 -1
  105. package/esm/util/bbox.js +16 -0
  106. package/esm/util/bbox.js.map +1 -1
  107. package/esm/util/data.d.ts +7 -1
  108. package/esm/util/data.js +17 -5
  109. package/esm/util/data.js.map +1 -1
  110. package/esm/util/dom.js +5 -5
  111. package/esm/util/dom.js.map +1 -1
  112. package/esm/util/item.d.ts +1 -1
  113. package/esm/util/item.js +8 -8
  114. package/esm/util/item.js.map +1 -1
  115. package/esm/util/mapper.js +1 -1
  116. package/esm/util/mapper.js.map +1 -1
  117. package/esm/util/path.d.ts +6 -1
  118. package/esm/util/path.js +72 -1
  119. package/esm/util/path.js.map +1 -1
  120. package/esm/util/polyline.d.ts +10 -0
  121. package/esm/util/polyline.js +22 -17
  122. package/esm/util/polyline.js.map +1 -1
  123. package/esm/util/router.d.ts +1 -1
  124. package/esm/util/router.js +19 -18
  125. package/esm/util/router.js.map +1 -1
  126. package/esm/util/shape.d.ts +1 -1
  127. package/esm/util/shape.js +28 -13
  128. package/esm/util/shape.js.map +1 -1
  129. package/esm/util/zoom.d.ts +5 -8
  130. package/esm/util/zoom.js +15 -20
  131. package/esm/util/zoom.js.map +1 -1
  132. package/lib/constant/shape.d.ts +1 -1
  133. package/lib/index.d.ts +3 -1
  134. package/lib/index.js +1 -1
  135. package/lib/item/combo.d.ts +6 -4
  136. package/lib/item/combo.js +10 -3
  137. package/lib/item/combo.js.map +1 -1
  138. package/lib/item/edge.d.ts +12 -4
  139. package/lib/item/edge.js +99 -16
  140. package/lib/item/edge.js.map +1 -1
  141. package/lib/item/item.d.ts +18 -8
  142. package/lib/item/item.js +101 -57
  143. package/lib/item/item.js.map +1 -1
  144. package/lib/item/node.d.ts +10 -4
  145. package/lib/item/node.js +92 -8
  146. package/lib/item/node.js.map +1 -1
  147. package/lib/runtime/controller/data.d.ts +5 -1
  148. package/lib/runtime/controller/data.js +38 -1
  149. package/lib/runtime/controller/data.js.map +1 -1
  150. package/lib/runtime/controller/index.d.ts +1 -1
  151. package/lib/runtime/controller/index.js +1 -1
  152. package/lib/runtime/controller/index.js.map +1 -1
  153. package/lib/runtime/controller/item.d.ts +22 -11
  154. package/lib/runtime/controller/item.js +238 -93
  155. package/lib/runtime/controller/item.js.map +1 -1
  156. package/lib/runtime/controller/layout.d.ts +3 -0
  157. package/lib/runtime/controller/layout.js +178 -98
  158. package/lib/runtime/controller/layout.js.map +1 -1
  159. package/lib/runtime/controller/plugin.d.ts +3 -0
  160. package/lib/runtime/controller/plugin.js +66 -24
  161. package/lib/runtime/controller/plugin.js.map +1 -1
  162. package/lib/runtime/controller/viewport.js +9 -2
  163. package/lib/runtime/controller/viewport.js.map +1 -1
  164. package/lib/runtime/graph.d.ts +57 -26
  165. package/lib/runtime/graph.js +263 -139
  166. package/lib/runtime/graph.js.map +1 -1
  167. package/lib/stdlib/behavior/click-select.js +9 -3
  168. package/lib/stdlib/behavior/click-select.js.map +1 -1
  169. package/lib/stdlib/behavior/drag-canvas.js +6 -3
  170. package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
  171. package/lib/stdlib/behavior/drag-combo.js +8 -8
  172. package/lib/stdlib/behavior/drag-combo.js.map +1 -1
  173. package/lib/stdlib/behavior/drag-node.d.ts +4 -0
  174. package/lib/stdlib/behavior/drag-node.js +121 -27
  175. package/lib/stdlib/behavior/drag-node.js.map +1 -1
  176. package/lib/stdlib/behavior/scroll-canvas.js +3 -3
  177. package/lib/stdlib/behavior/scroll-canvas.js.map +1 -1
  178. package/lib/stdlib/behavior/zoom-canvas.js +3 -3
  179. package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
  180. package/lib/stdlib/data/mapNodeSize.js +2 -2
  181. package/lib/stdlib/data/mapNodeSize.js.map +1 -1
  182. package/lib/stdlib/data/validateData.js +2 -2
  183. package/lib/stdlib/data/validateData.js.map +1 -1
  184. package/lib/stdlib/index.d.ts +2 -0
  185. package/lib/stdlib/index.js +3 -1
  186. package/lib/stdlib/index.js.map +1 -1
  187. package/lib/stdlib/item/edge/base.d.ts +2 -11
  188. package/lib/stdlib/item/edge/base.js +12 -105
  189. package/lib/stdlib/item/edge/base.js.map +1 -1
  190. package/lib/stdlib/item/node/base.d.ts +2 -20
  191. package/lib/stdlib/item/node/base.js +10 -150
  192. package/lib/stdlib/item/node/base.js.map +1 -1
  193. package/lib/stdlib/plugin/edgeFilterLens/index.js +2 -2
  194. package/lib/stdlib/plugin/edgeFilterLens/index.js.map +1 -1
  195. package/lib/stdlib/plugin/fisheye/index.js +2 -1
  196. package/lib/stdlib/plugin/fisheye/index.js.map +1 -1
  197. package/lib/stdlib/plugin/history/visibility-updated-command.js +2 -2
  198. package/lib/stdlib/plugin/history/visibility-updated-command.js.map +1 -1
  199. package/lib/stdlib/plugin/hull/index.d.ts +1 -1
  200. package/lib/stdlib/plugin/index.d.ts +1 -0
  201. package/lib/stdlib/plugin/index.js +1 -0
  202. package/lib/stdlib/plugin/index.js.map +1 -1
  203. package/lib/stdlib/plugin/lodController/index.d.ts +73 -0
  204. package/lib/stdlib/plugin/lodController/index.js +560 -0
  205. package/lib/stdlib/plugin/lodController/index.js.map +1 -0
  206. package/lib/stdlib/plugin/minimap/index.js +12 -14
  207. package/lib/stdlib/plugin/minimap/index.js.map +1 -1
  208. package/lib/stdlib/plugin/toolbar/index.d.ts +2 -2
  209. package/lib/stdlib/plugin/toolbar/index.js +27 -29
  210. package/lib/stdlib/plugin/toolbar/index.js.map +1 -1
  211. package/lib/stdlib/theme/dark.js +32 -35
  212. package/lib/stdlib/theme/dark.js.map +1 -1
  213. package/lib/stdlib/theme/light.js +27 -30
  214. package/lib/stdlib/theme/light.js.map +1 -1
  215. package/lib/stdlib/themeSolver/spec.js +2 -2
  216. package/lib/stdlib/themeSolver/spec.js.map +1 -1
  217. package/lib/types/animate.d.ts +1 -1
  218. package/lib/types/combo.d.ts +2 -2
  219. package/lib/types/edge.d.ts +2 -2
  220. package/lib/types/graph.d.ts +62 -43
  221. package/lib/types/hook.d.ts +5 -0
  222. package/lib/types/item.d.ts +9 -15
  223. package/lib/types/layout.d.ts +7 -2
  224. package/lib/types/layout.js.map +1 -1
  225. package/lib/types/node.d.ts +3 -2
  226. package/lib/types/plugin.d.ts +1 -0
  227. package/lib/types/plugin.js +1 -0
  228. package/lib/types/plugin.js.map +1 -1
  229. package/lib/types/spec.d.ts +1 -0
  230. package/lib/types/theme.d.ts +7 -7
  231. package/lib/util/animate.d.ts +7 -2
  232. package/lib/util/animate.js +37 -23
  233. package/lib/util/animate.js.map +1 -1
  234. package/lib/util/bbox.d.ts +7 -1
  235. package/lib/util/bbox.js +18 -1
  236. package/lib/util/bbox.js.map +1 -1
  237. package/lib/util/data.d.ts +7 -1
  238. package/lib/util/data.js +19 -6
  239. package/lib/util/data.js.map +1 -1
  240. package/lib/util/dom.js +5 -5
  241. package/lib/util/dom.js.map +1 -1
  242. package/lib/util/item.d.ts +1 -1
  243. package/lib/util/item.js +8 -8
  244. package/lib/util/item.js.map +1 -1
  245. package/lib/util/mapper.js +1 -1
  246. package/lib/util/mapper.js.map +1 -1
  247. package/lib/util/path.d.ts +6 -1
  248. package/lib/util/path.js +72 -1
  249. package/lib/util/path.js.map +1 -1
  250. package/lib/util/polyline.d.ts +10 -0
  251. package/lib/util/polyline.js +25 -18
  252. package/lib/util/polyline.js.map +1 -1
  253. package/lib/util/router.d.ts +1 -1
  254. package/lib/util/router.js +19 -18
  255. package/lib/util/router.js.map +1 -1
  256. package/lib/util/shape.d.ts +1 -1
  257. package/lib/util/shape.js +27 -12
  258. package/lib/util/shape.js.map +1 -1
  259. package/lib/util/zoom.d.ts +5 -8
  260. package/lib/util/zoom.js +17 -22
  261. package/lib/util/zoom.js.map +1 -1
  262. package/package.json +1 -1
  263. package/src/index.ts +1 -1
  264. package/src/item/combo.ts +13 -5
  265. package/src/item/edge.ts +126 -17
  266. package/src/item/item.ts +119 -57
  267. package/src/item/node.ts +108 -11
  268. package/src/runtime/controller/data.ts +64 -3
  269. package/src/runtime/controller/index.ts +1 -1
  270. package/src/runtime/controller/item.ts +321 -135
  271. package/src/runtime/controller/layout.ts +254 -113
  272. package/src/runtime/controller/plugin.ts +86 -33
  273. package/src/runtime/controller/viewport.ts +8 -2
  274. package/src/runtime/graph.ts +383 -158
  275. package/src/stdlib/behavior/click-select.ts +8 -3
  276. package/src/stdlib/behavior/drag-canvas.ts +6 -3
  277. package/src/stdlib/behavior/drag-combo.ts +8 -8
  278. package/src/stdlib/behavior/drag-node.ts +165 -50
  279. package/src/stdlib/behavior/scroll-canvas.ts +3 -3
  280. package/src/stdlib/behavior/zoom-canvas.ts +3 -3
  281. package/src/stdlib/data/mapNodeSize.ts +2 -2
  282. package/src/stdlib/data/validateData.ts +2 -2
  283. package/src/stdlib/index.ts +3 -0
  284. package/src/stdlib/item/edge/base.ts +15 -139
  285. package/src/stdlib/item/node/base.ts +20 -215
  286. package/src/stdlib/plugin/edgeFilterLens/index.ts +2 -2
  287. package/src/stdlib/plugin/fisheye/index.ts +3 -2
  288. package/src/stdlib/plugin/history/visibility-updated-command.ts +2 -2
  289. package/src/stdlib/plugin/index.ts +1 -0
  290. package/src/stdlib/plugin/lodController/index.ts +602 -0
  291. package/src/stdlib/plugin/minimap/index.ts +12 -14
  292. package/src/stdlib/plugin/toolbar/index.ts +29 -31
  293. package/src/stdlib/theme/dark.ts +32 -34
  294. package/src/stdlib/theme/light.ts +27 -29
  295. package/src/stdlib/themeSolver/spec.ts +2 -2
  296. package/src/types/animate.ts +1 -1
  297. package/src/types/combo.ts +2 -2
  298. package/src/types/edge.ts +2 -2
  299. package/src/types/graph.ts +65 -53
  300. package/src/types/hook.ts +5 -0
  301. package/src/types/item.ts +8 -14
  302. package/src/types/layout.ts +20 -15
  303. package/src/types/node.ts +3 -2
  304. package/src/types/plugin.ts +2 -0
  305. package/src/types/spec.ts +1 -0
  306. package/src/types/theme.ts +7 -7
  307. package/src/util/animate.ts +104 -78
  308. package/src/util/bbox.ts +26 -1
  309. package/src/util/data.ts +15 -6
  310. package/src/util/dom.ts +6 -6
  311. package/src/util/item.ts +15 -1
  312. package/src/util/mapper.ts +1 -1
  313. package/src/util/path.ts +72 -2
  314. package/src/util/polyline.ts +30 -23
  315. package/src/util/router.ts +21 -19
  316. package/src/util/shape.ts +27 -12
  317. package/src/util/zoom.ts +19 -25
  318. package/esm/runtime/controller/extension.d.ts +0 -9
  319. package/esm/runtime/controller/extension.js +0 -11
  320. package/esm/runtime/controller/extension.js.map +0 -1
  321. package/lib/runtime/controller/extension.d.ts +0 -9
  322. package/lib/runtime/controller/extension.js +0 -15
  323. package/lib/runtime/controller/extension.js.map +0 -1
  324. package/src/runtime/controller/extension.ts +0 -14
@@ -59,26 +59,29 @@ import { changeRenderer, createCanvas } from '../util/canvas';
59
59
  import { createDOM } from '../util/dom';
60
60
  import { getLayoutBounds } from '../util/layout';
61
61
  import { formatPadding } from '../util/shape';
62
+ import Node from '../item/node';
63
+ import { cloneJSON, isEmptyGraph } from '../util/data';
64
+ import { getCombinedCanvasesBounds } from '../util/bbox';
62
65
  import {
63
66
  DataController,
64
- ExtensionController,
65
67
  InteractionController,
66
68
  ItemController,
67
69
  LayoutController,
68
70
  ThemeController,
69
71
  ViewportController,
72
+ PluginController,
70
73
  } from './controller';
71
- import { PluginController } from './controller/plugin';
72
74
  import Hook from './hooks';
73
- import { isEmptyGraph } from '../util/data';
74
75
 
75
76
  export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
76
77
  extends EventEmitter
77
78
  implements IGraph<B, T>
78
79
  {
79
80
  public hooks: Hooks;
80
- // for nodes and edges, which will be separate into groups
81
+ // for nodes and edges excluding their labels, which will be separate into groups
81
82
  public canvas: Canvas;
83
+ // for nodes' and edges' labels
84
+ public labelCanvas: Canvas;
82
85
  // the container dom for the graph canvas
83
86
  public container: HTMLElement;
84
87
  // the tag to indicate whether the graph instance is destroyed
@@ -87,6 +90,8 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
87
90
  public rendererType: RendererName;
88
91
  // for transient shapes for interactions, e.g. transient node and related edges while draging, delegates
89
92
  public transientCanvas: Canvas;
93
+ // for transient items' label shapes
94
+ public transientLabelCanvas: Canvas;
90
95
  // for background shapes, e.g. grid, pipe indices
91
96
  public backgroundCanvas: Canvas;
92
97
  // the tag indicates all the three canvases are all ready
@@ -98,7 +103,6 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
98
103
  private layoutController: LayoutController;
99
104
  private viewportController: ViewportController;
100
105
  private itemController: ItemController;
101
- private extensionController: ExtensionController;
102
106
  private themeController: ThemeController;
103
107
  private pluginController: PluginController;
104
108
 
@@ -127,7 +131,9 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
127
131
  canvases: {
128
132
  background: this.backgroundCanvas,
129
133
  main: this.canvas,
134
+ label: this.labelCanvas,
130
135
  transient: this.transientCanvas,
136
+ transientLabel: this.transientLabelCanvas,
131
137
  },
132
138
  });
133
139
 
@@ -146,9 +152,8 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
146
152
  this.interactionController = new InteractionController(this);
147
153
  this.layoutController = new LayoutController(this);
148
154
  this.themeController = new ThemeController(this);
149
- this.itemController = new ItemController(this);
150
155
  this.viewportController = new ViewportController(this);
151
- this.extensionController = new ExtensionController(this);
156
+ this.itemController = new ItemController(this);
152
157
  this.pluginController = new PluginController(this);
153
158
  }
154
159
 
@@ -159,6 +164,7 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
159
164
  canvas,
160
165
  backgroundCanvas,
161
166
  transientCanvas,
167
+ transientLabelCanvas,
162
168
  width,
163
169
  height,
164
170
  } = this.specification;
@@ -181,6 +187,7 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
181
187
  this.canvas = canvas;
182
188
  this.backgroundCanvas = backgroundCanvas;
183
189
  this.transientCanvas = transientCanvas;
190
+ this.transientLabelCanvas = transientLabelCanvas;
184
191
  this.container = container as HTMLElement;
185
192
  } else {
186
193
  const containerDOM = isString(container)
@@ -217,6 +224,13 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
217
224
  size[1],
218
225
  pixelRatio,
219
226
  );
227
+ this.labelCanvas = createCanvas(
228
+ 'canvas',
229
+ containerDOM,
230
+ size[0],
231
+ size[1],
232
+ pixelRatio,
233
+ );
220
234
  this.transientCanvas = createCanvas(
221
235
  this.rendererType,
222
236
  containerDOM,
@@ -224,30 +238,45 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
224
238
  size[1],
225
239
  pixelRatio,
226
240
  );
241
+ this.transientLabelCanvas = createCanvas(
242
+ 'canvas',
243
+ containerDOM,
244
+ size[0],
245
+ size[1],
246
+ pixelRatio,
247
+ );
227
248
  }
228
249
 
229
250
  Promise.all(
230
- [this.backgroundCanvas, this.canvas, this.transientCanvas].map(
231
- (canvas) => canvas.ready,
232
- ),
251
+ [
252
+ this.backgroundCanvas,
253
+ this.canvas,
254
+ this.labelCanvas,
255
+ this.transientCanvas,
256
+ this.transientLabelCanvas,
257
+ ].map((canvas) => canvas.ready),
233
258
  ).then(() => {
234
- [this.backgroundCanvas, this.canvas, this.transientCanvas].forEach(
235
- (canvas, i) => {
236
- const $domElement = canvas
237
- .getContextService()
238
- .getDomElement() as unknown as HTMLElement;
239
- if ($domElement && $domElement.style) {
240
- // Make all these 3 canvas doms overlap each other. The container already has `position: relative` style.
241
- $domElement.style.position = 'absolute';
242
- $domElement.style.outline = 'none';
243
- $domElement.tabIndex = 1; // Enable keyboard events
244
- // Transient canvas should let interactive events go through.
245
- if (i !== 1) {
246
- $domElement.style.pointerEvents = 'none';
247
- }
259
+ [
260
+ this.backgroundCanvas,
261
+ this.canvas,
262
+ this.labelCanvas,
263
+ this.transientCanvas,
264
+ this.transientLabelCanvas,
265
+ ].forEach((canvas, i) => {
266
+ const $domElement = canvas
267
+ .getContextService()
268
+ .getDomElement() as unknown as HTMLElement;
269
+ if ($domElement && $domElement.style) {
270
+ // Make all these 3 canvas doms overlap each other. The container already has `position: relative` style.
271
+ $domElement.style.position = 'absolute';
272
+ $domElement.style.outline = 'none';
273
+ $domElement.tabIndex = 1; // Enable keyboard events
274
+ // Transient canvas should let interactive events go through.
275
+ if (i !== 1) {
276
+ $domElement.style.pointerEvents = 'none';
248
277
  }
249
- },
250
- );
278
+ }
279
+ });
251
280
 
252
281
  this.canvasReady = true;
253
282
  });
@@ -287,8 +316,10 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
287
316
  init: new Hook<{
288
317
  canvases: {
289
318
  background: Canvas;
319
+ label: Canvas;
290
320
  main: Canvas;
291
321
  transient: Canvas;
322
+ transientLabel: Canvas;
292
323
  };
293
324
  }>({ name: 'init' }),
294
325
  datachange: new Hook<{ data: GraphData; type: DataChangeType }>({
@@ -306,6 +337,7 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
306
337
  graphCore: GraphCore;
307
338
  theme: ThemeSpecification;
308
339
  transientCanvas: Canvas;
340
+ transientLabelCanvas: Canvas;
309
341
  }>({
310
342
  name: 'render',
311
343
  }),
@@ -473,6 +505,7 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
473
505
  graphCore: this.dataController.graphCore,
474
506
  theme: this.themeController.specification,
475
507
  transientCanvas: this.transientCanvas,
508
+ transientLabelCanvas: this.transientLabelCanvas,
476
509
  tileOptimize: {
477
510
  tileFirstRender,
478
511
  tileFirstRenderSize,
@@ -518,9 +551,13 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
518
551
  await emitRender();
519
552
  } else {
520
553
  await Promise.all(
521
- [this.backgroundCanvas, this.canvas, this.transientCanvas].map(
522
- (canvas) => canvas.ready,
523
- ),
554
+ [
555
+ this.backgroundCanvas,
556
+ this.canvas,
557
+ this.labelCanvas,
558
+ this.transientCanvas,
559
+ this.transientLabelCanvas,
560
+ ].map((canvas) => canvas.ready),
524
561
  );
525
562
  await emitRender();
526
563
  }
@@ -530,12 +567,14 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
530
567
  * Change graph data.
531
568
  * @param data new data
532
569
  * @param type the way to change data, 'replace' means discard the old data and use the new one; 'mergeReplace' means merge the common part, remove (old - new), add (new - old)
570
+ * @param relayout whether relayout the nodes after data changing
533
571
  * @returns
534
572
  * @group Data
535
573
  */
536
574
  public async changeData(
537
575
  data: DataConfig,
538
576
  type: 'replace' | 'mergeReplace' = 'mergeReplace',
577
+ relayout: boolean = true,
539
578
  ) {
540
579
  const { tileFirstRender, tileFirstRenderSize } =
541
580
  this.specification.optimize || {};
@@ -544,6 +583,7 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
544
583
  graphCore: this.dataController.graphCore,
545
584
  theme: this.themeController.specification,
546
585
  transientCanvas: this.transientCanvas,
586
+ transientLabelCanvas: this.transientLabelCanvas,
547
587
  tileOptimize: {
548
588
  tileFirstRender,
549
589
  tileFirstRenderSize,
@@ -551,7 +591,9 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
551
591
  });
552
592
  this.emit('afterrender');
553
593
 
554
- await this.layout();
594
+ if (relayout) {
595
+ await this.layout();
596
+ }
555
597
  }
556
598
 
557
599
  /**
@@ -775,10 +817,9 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
775
817
  halfExtents,
776
818
  } = boundsType === 'render'
777
819
  ? // Get the bounds of the whole graph content.
778
- this.canvas.document.documentElement.getBounds()
779
- : // Get the bounds of the nodes positions while the graph content is not ready.
820
+ getCombinedCanvasesBounds([this.canvas, this.labelCanvas])
821
+ : // Get the b ounds of the nodes positions while the graph content is not ready.
780
822
  getLayoutBounds(this);
781
-
782
823
  const origin = this.canvas.canvas2Viewport({
783
824
  x: graphCenterX,
784
825
  y: graphCenterY,
@@ -849,7 +890,7 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
849
890
  } =
850
891
  boundsType === 'render'
851
892
  ? // Get the bounds of the whole graph content.
852
- this.canvas.document.documentElement.getBounds()
893
+ getCombinedCanvasesBounds([this.canvas, this.labelCanvas])
853
894
  : // Get the bounds of the nodes positions while the graph content is not ready.
854
895
  getLayoutBounds(this);
855
896
  await this.translateTo(
@@ -922,9 +963,15 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
922
963
  this.emit('beforesetsize', { oldSize, size: size });
923
964
  this.specification.width = size[0];
924
965
  this.specification.height = size[1];
925
- this.canvas.resize(size[0], size[1]);
926
- this.transientCanvas.resize(size[0], size[1]);
927
- this.backgroundCanvas.resize(size[0], size[1]);
966
+ [
967
+ this.canvas,
968
+ this.labelCanvas,
969
+ this.transientCanvas,
970
+ this.transientLabelCanvas,
971
+ this.backgroundCanvas,
972
+ ].forEach((canvas) => {
973
+ canvas.resize(size[0], size[1]);
974
+ });
928
975
  this.emit('aftersetsize', { oldSize, size: size });
929
976
  }
930
977
 
@@ -1062,6 +1109,26 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1062
1109
  ): EdgeModel[] {
1063
1110
  return this.dataController.findRelatedEdges(nodeId, direction);
1064
1111
  }
1112
+ /**
1113
+ * Get nearby edges from a start node using quadtree collision detection.
1114
+ * @param nodeId id of the start node
1115
+ * @returns nearby edges' data array
1116
+ */
1117
+ public getNearEdgesData(
1118
+ nodeId: ID,
1119
+ shouldBegin?: (edge: EdgeDisplayModel) => boolean,
1120
+ ): EdgeModel[] {
1121
+ const transientItem = this.itemController.getTransientItem(
1122
+ nodeId,
1123
+ ) as unknown as Node;
1124
+ const itemMap = this.itemController.getItemMap();
1125
+ return this.dataController.findNearEdges(
1126
+ nodeId,
1127
+ itemMap,
1128
+ transientItem,
1129
+ shouldBegin,
1130
+ );
1131
+ }
1065
1132
  /**
1066
1133
  * Get one-hop node ids from a start node.
1067
1134
  * @param nodeId id of the start node
@@ -1106,16 +1173,6 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1106
1173
  return this.itemController.findDisplayModel(id);
1107
1174
  }
1108
1175
 
1109
- /**
1110
- * Retrieve the nearby edges for a given node using quadtree collision detection.
1111
- * @param nodeId node id
1112
- * @group Data
1113
- */
1114
- public getNearEdgesForNode(nodeId: ID): EdgeModel[] {
1115
- const { graphCore } = this.dataController;
1116
- return this.itemController.findNearEdgesByNode(nodeId, graphCore);
1117
- }
1118
-
1119
1176
  /**
1120
1177
  * Find items which has the state.
1121
1178
  * @param itemType item type
@@ -1166,13 +1223,14 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1166
1223
 
1167
1224
  const { graphCore } = this.dataController;
1168
1225
  const { specification } = this.themeController;
1226
+ const modelArr = isArray(models) ? models : [models];
1169
1227
  graphCore.once('changed', (event) => {
1170
1228
  if (!event.changes.length) return;
1171
1229
  const changes = event.changes;
1172
1230
  const timingParameters = {
1173
1231
  type: itemType,
1174
1232
  action: 'add',
1175
- models,
1233
+ models: modelArr,
1176
1234
  apiName: 'addData',
1177
1235
  changes,
1178
1236
  };
@@ -1186,7 +1244,6 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1186
1244
  this.emit('afteritemchange', timingParameters);
1187
1245
  });
1188
1246
 
1189
- const modelArr = isArray(models) ? models : [models];
1190
1247
  const data = { nodes: [], edges: [], combos: [] };
1191
1248
  data[`${itemType}s`] = modelArr;
1192
1249
  this.hooks.datachange.emit({
@@ -1201,7 +1258,8 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1201
1258
  }
1202
1259
  /**
1203
1260
  * Remove one or more node/edge/combo data from the graph.
1204
- * @param item the item to be removed
1261
+ * @param itemType the type the item(s) to be removed.
1262
+ * @param id the id or the ids' array of the items to be removed.
1205
1263
  * @returns whether success
1206
1264
  * @group Data
1207
1265
  */
@@ -1303,8 +1361,8 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1303
1361
  }
1304
1362
  /**
1305
1363
  * Update one or more node/edge/combo data on the graph.
1306
- * @param {ITEM_TYPE} itemType 'node' | 'edge' | 'combo'
1307
- * @param models new configurations for every node/edge/combo, which has id field to indicate the specific item
1364
+ * @param {ITEM_TYPE} itemType the type the item(s) to be udated.
1365
+ * @param models update configs.
1308
1366
  * @group Data
1309
1367
  */
1310
1368
  public updateData(
@@ -1332,11 +1390,11 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1332
1390
  const { graphCore } = this.dataController;
1333
1391
  const { specification } = this.themeController;
1334
1392
  graphCore.once('changed', (event) => {
1335
- const changes = this.extendChanges(clone(event.changes));
1393
+ const changes = this.extendChanges(cloneJSON(event.changes));
1336
1394
  const timingParameters = {
1337
1395
  type: itemType,
1338
1396
  action: 'update',
1339
- models,
1397
+ models: modelArr,
1340
1398
  apiName: 'updateData',
1341
1399
  changes,
1342
1400
  };
@@ -1364,7 +1422,10 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1364
1422
  /**
1365
1423
  * Update one or more nodes' positions,
1366
1424
  * do not update other styles which leads to better performance than updating positions by updateData.
1367
- * @param models new configurations with x and y for every node, which has id field to indicate the specific item
1425
+ * @param models new configurations with x and y for every node, which has id field to indicate the specific item.
1426
+ * @param upsertAncestors whether update the ancestors in combo tree.
1427
+ * @param disableAnimate whether disable the animation for this call.
1428
+ * @param callback callback function after update nodes done.
1368
1429
  * @group Data
1369
1430
  */
1370
1431
  public updateNodePosition(
@@ -1379,7 +1440,6 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1379
1440
  model: NodeModel | EdgeModel | ComboModel,
1380
1441
  canceled?: boolean,
1381
1442
  ) => void,
1382
- stack?: boolean,
1383
1443
  ) {
1384
1444
  return this.updatePosition(
1385
1445
  'node',
@@ -1387,7 +1447,6 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1387
1447
  upsertAncestors,
1388
1448
  disableAnimate,
1389
1449
  callback,
1390
- stack,
1391
1450
  );
1392
1451
  }
1393
1452
 
@@ -1395,7 +1454,10 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1395
1454
  * Update one or more combos' positions,
1396
1455
  * do not update other styles which leads to better performance than updating positions by updateData.
1397
1456
  * In fact, it changes the succeed nodes positions to affect the combo's position, but not modify the combo's position directly.
1398
- * @param models new configurations with x and y for every combo, which has id field to indicate the specific item
1457
+ * @param models new configurations with x and y for every combo, which has id field to indicate the specific item.
1458
+ * @param upsertAncestors whether update the ancestors in combo tree.
1459
+ * @param disableAnimate whether disable the animation for this call.
1460
+ * @param callback callback function after update combos done.
1399
1461
  * @group Data
1400
1462
  */
1401
1463
  public updateComboPosition(
@@ -1407,7 +1469,6 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1407
1469
  upsertAncestors?: boolean,
1408
1470
  disableAnimate = false,
1409
1471
  callback?: (model: NodeModel | EdgeModel | ComboModel) => void,
1410
- stack?: boolean,
1411
1472
  ) {
1412
1473
  return this.updatePosition(
1413
1474
  'combo',
@@ -1415,7 +1476,6 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1415
1476
  upsertAncestors,
1416
1477
  disableAnimate,
1417
1478
  callback,
1418
- stack,
1419
1479
  );
1420
1480
  }
1421
1481
 
@@ -1446,7 +1506,6 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1446
1506
  model: NodeModel | EdgeModel | ComboModel,
1447
1507
  canceled?: boolean,
1448
1508
  ) => void,
1449
- stack?: boolean,
1450
1509
  ) {
1451
1510
  const modelArr = isArray(models) ? models : [models];
1452
1511
  const { graphCore } = this.dataController;
@@ -1460,7 +1519,7 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1460
1519
  type,
1461
1520
  action: 'updatePosition',
1462
1521
  upsertAncestors,
1463
- models,
1522
+ models: modelArr,
1464
1523
  apiName: 'updatePosition',
1465
1524
  changes,
1466
1525
  };
@@ -1513,21 +1572,46 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1513
1572
  * @returns
1514
1573
  * @group Item
1515
1574
  */
1516
- public showItem(ids: ID | ID[], disableAnimate = false) {
1575
+ public showItem(
1576
+ ids: ID | ID[],
1577
+ options?: {
1578
+ disableAnimate?: boolean;
1579
+ shapeIds?: string | string[];
1580
+ },
1581
+ ) {
1582
+ const { disableAnimate = false, shapeIds } = options || {};
1517
1583
  const idArr = isArray(ids) ? ids : [ids];
1518
1584
  if (isEmpty(idArr)) return;
1519
- const changes = {
1520
- newValue: [{ ids: idArr, visible: true }],
1521
- oldValue: this.getItemPreviousVisibility(idArr),
1522
- };
1523
- this.hooks.itemvisibilitychange.emit({
1524
- ids: idArr as ID[],
1525
- value: true,
1526
- graphCore: this.dataController.graphCore,
1527
- animate: !disableAnimate,
1528
- });
1585
+
1586
+ let changes;
1587
+ if (shapeIds?.length) {
1588
+ const shapeIdsArr = isArray(shapeIds) ? shapeIds : [shapeIds];
1589
+ changes = {
1590
+ newValue: [{ ids: idArr, visible: true, shapeIds: shapeIdsArr }],
1591
+ oldValue: this.getItemPreviousVisibility(idArr),
1592
+ };
1593
+ this.hooks.itemvisibilitychange.emit({
1594
+ ids: idArr as ID[],
1595
+ value: true,
1596
+ graphCore: this.dataController.graphCore,
1597
+ animate: !disableAnimate,
1598
+ shapeIds: shapeIdsArr,
1599
+ });
1600
+ } else {
1601
+ changes = {
1602
+ newValue: [{ ids: idArr, visible: true }],
1603
+ oldValue: this.getItemPreviousVisibility(idArr),
1604
+ };
1605
+ this.hooks.itemvisibilitychange.emit({
1606
+ ids: idArr as ID[],
1607
+ value: true,
1608
+ graphCore: this.dataController.graphCore,
1609
+ animate: !disableAnimate,
1610
+ });
1611
+ }
1612
+
1529
1613
  this.emit('afteritemvisibilitychange', {
1530
- ids,
1614
+ ids: idArr as ID[],
1531
1615
  value: true,
1532
1616
  animate: !disableAnimate,
1533
1617
  action: 'updateVisibility',
@@ -1537,30 +1621,62 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1537
1621
  }
1538
1622
  /**
1539
1623
  * Hide the item(s).
1540
- * @param item the item to be hidden
1624
+ * @param id the id for the item to be hidden.
1625
+ * @param disableAnimate whether disable the hidden animations.
1626
+ * @param keepKeyShape whether keep the keyShape.
1627
+ * @param keepRelated whether keep the related nodes for edge.
1541
1628
  * @returns
1542
1629
  * @group Item
1543
1630
  */
1544
1631
  public hideItem(
1545
1632
  ids: ID | ID[],
1546
- disableAnimate = false,
1547
- keepKeyShape = false,
1633
+ options?: {
1634
+ disableAnimate?: boolean;
1635
+ keepKeyShape?: boolean;
1636
+ keepRelated?: boolean;
1637
+ shapeIds?: string[];
1638
+ },
1548
1639
  ) {
1549
- const idArr = isArray(ids) ? ids : [ids];
1640
+ const {
1641
+ disableAnimate = false,
1642
+ keepKeyShape = false,
1643
+ keepRelated = false,
1644
+ shapeIds,
1645
+ } = options || {};
1646
+ const idArr: ID[] = isArray(ids) ? ids : [ids];
1550
1647
  if (isEmpty(idArr)) return;
1551
- const changes = {
1552
- newValue: [{ ids: idArr, visible: false }],
1553
- oldValue: this.getItemPreviousVisibility(idArr),
1554
- };
1555
- this.hooks.itemvisibilitychange.emit({
1556
- ids: idArr as ID[],
1557
- value: false,
1558
- graphCore: this.dataController.graphCore,
1559
- animate: !disableAnimate,
1560
- keepKeyShape,
1561
- });
1648
+
1649
+ let changes;
1650
+ if (shapeIds?.length) {
1651
+ const shapeIdsArr = isArray(shapeIds) ? shapeIds : [shapeIds];
1652
+ changes = {
1653
+ newValue: [{ ids: idArr, visible: false, shapeIds: shapeIdsArr }],
1654
+ oldValue: this.getItemPreviousVisibility(idArr),
1655
+ };
1656
+ this.hooks.itemvisibilitychange.emit({
1657
+ ids: idArr,
1658
+ value: false,
1659
+ graphCore: this.dataController.graphCore,
1660
+ animate: !disableAnimate,
1661
+ shapeIds: shapeIdsArr,
1662
+ });
1663
+ } else {
1664
+ changes = {
1665
+ newValue: [{ ids: idArr, visible: false }],
1666
+ oldValue: this.getItemPreviousVisibility(idArr),
1667
+ };
1668
+ this.hooks.itemvisibilitychange.emit({
1669
+ ids: idArr,
1670
+ value: false,
1671
+ graphCore: this.dataController.graphCore,
1672
+ animate: !disableAnimate,
1673
+ keepKeyShape,
1674
+ keepRelated,
1675
+ });
1676
+ }
1677
+
1562
1678
  this.emit('afteritemvisibilitychange', {
1563
- ids,
1679
+ ids: idArr,
1564
1680
  value: false,
1565
1681
  animate: !disableAnimate,
1566
1682
  action: 'updateVisibility',
@@ -1737,12 +1853,22 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1737
1853
  return this.itemController.getItemVisible(id);
1738
1854
  }
1739
1855
 
1856
+ /**
1857
+ * Get the visible shape ids in a node / edge / combo.
1858
+ * @param id the id for the node / edge / combo
1859
+ * @returns ids of the visible shapes
1860
+ */
1861
+ public getItemVisibleShapeIds(id: ID) {
1862
+ return this.itemController.getItemVisibleShapeIds(id);
1863
+ }
1864
+
1740
1865
  // ===== combo operations =====
1741
1866
 
1742
1867
  /**
1743
1868
  * Add a new combo to the graph, and update the structure of the existed child in childrenIds to be the children of the new combo.
1744
1869
  * Different from addData with combo type, this API update the succeeds' combo tree strucutres in the same time.
1745
- * @param model combo user data
1870
+ * @param model combo user data.
1871
+ * @param childrenIds the ids of the children nodes / combos to move into the new combo.
1746
1872
  * @returns whether success
1747
1873
  * @group Combo
1748
1874
  */
@@ -1790,7 +1916,7 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1790
1916
  }
1791
1917
  /**
1792
1918
  * Collapse a combo.
1793
- * @param comboId combo ids
1919
+ * @param comboId combo id or ids' array.
1794
1920
  * @group Combo
1795
1921
  */
1796
1922
  public collapseCombo(comboIds: ID | ID[]) {
@@ -1810,7 +1936,7 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1810
1936
  }
1811
1937
  /**
1812
1938
  * Expand a combo.
1813
- * @param combo combo ids
1939
+ * @param comboId combo id or ids' array.
1814
1940
  * @group Combo
1815
1941
  */
1816
1942
  public expandCombo(comboIds: ID | ID[]) {
@@ -1833,7 +1959,11 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1833
1959
  * Move one or more combos a distance (dx, dy) relatively,
1834
1960
  * do not update other styles which leads to better performance than updating positions by updateData.
1835
1961
  * In fact, it changes the succeed nodes positions to affect the combo's position, but not modify the combo's position directly.
1836
- * @param models new configurations with x and y for every combo, which has id field to indicate the specific item
1962
+ * @param models new configurations with x and y for every combo, which has id field to indicate the specific item.
1963
+ * @param dx the distance alone x-axis to move the combo.
1964
+ * @param dy the distance alone y-axis to move the combo.
1965
+ * @param upsertAncestors whether update the ancestors in the combo tree.
1966
+ * @param callback callback function after move combo done.
1837
1967
  * @group Combo
1838
1968
  */
1839
1969
  public moveCombo(
@@ -1890,7 +2020,10 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1890
2020
  /**
1891
2021
  * Layout the graph (with current configurations if cfg is not assigned).
1892
2022
  */
1893
- public async layout(options?: LayoutOptions, disableAnimate = false) {
2023
+ public async layout(
2024
+ options?: Partial<LayoutOptions>,
2025
+ disableAnimate = false,
2026
+ ) {
1894
2027
  this.emit('beforelayout');
1895
2028
  const { graphCore } = this.dataController;
1896
2029
  const formattedOptions = {
@@ -1977,7 +2110,9 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1977
2110
  */
1978
2111
  public setCursor(cursor: Cursor) {
1979
2112
  this.canvas.setCursor(cursor);
2113
+ this.labelCanvas.setCursor(cursor);
1980
2114
  this.transientCanvas.setCursor(cursor);
2115
+ this.transientLabelCanvas.setCursor(cursor);
1981
2116
  }
1982
2117
 
1983
2118
  /**
@@ -2153,12 +2288,15 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
2153
2288
  | PluginBase,
2154
2289
  ) {
2155
2290
  const { plugins } = this.specification;
2156
- const { key } = plugin;
2291
+ const { key, type } = plugin as {
2292
+ key: string;
2293
+ type: string;
2294
+ [cfg: string]: unknown;
2295
+ };
2157
2296
  if (!key) {
2158
2297
  console.warn(
2159
- 'Update plugin failed, the key for the plugin to be updated should be assign.',
2298
+ `The key for the plugin is not found. G6 will update the first plugin with type ${type}`,
2160
2299
  );
2161
- return;
2162
2300
  }
2163
2301
  if (!plugins) {
2164
2302
  console.warn(
@@ -2167,12 +2305,21 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
2167
2305
  return;
2168
2306
  }
2169
2307
  const oldPlugin = plugins?.find((p) => {
2170
- if (typeof p === 'string') return p === key;
2171
- return p.key === key;
2308
+ if (typeof p === 'string') return p === key || p === type;
2309
+ return (
2310
+ p.key === key ||
2311
+ (
2312
+ p as {
2313
+ key: string;
2314
+ type: string;
2315
+ [cfg: string]: unknown;
2316
+ }
2317
+ ).type === type
2318
+ );
2172
2319
  });
2173
2320
  if (!oldPlugin) {
2174
2321
  console.warn(
2175
- 'Update plugin failed, the key for the plugin to be updated should be assign.',
2322
+ `Update plugin failed, the plugin with key ${key} or type ${type} is not found.`,
2176
2323
  );
2177
2324
  return;
2178
2325
  }
@@ -2236,19 +2383,23 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
2236
2383
  * @returns A Promise that resolves to the Data URL string.
2237
2384
  */
2238
2385
  public async toDataURL(type?: DataURLType): Promise<string> {
2239
- const backgroundCanvas = this.backgroundCanvas;
2240
- const canvas = this.canvas;
2241
- const transientCanvas = this.transientCanvas;
2242
- const rendererType = this.rendererType;
2386
+ const {
2387
+ backgroundCanvas,
2388
+ canvas,
2389
+ transientCanvas,
2390
+ labelCanvas,
2391
+ rendererType,
2392
+ } = this;
2243
2393
 
2244
2394
  const pixelRatio =
2245
2395
  typeof window !== 'undefined' ? window.devicePixelRatio : 1;
2246
- const width = this.getSize()[0];
2247
- const height = this.getSize()[1];
2396
+ const [width, height] = this.getSize();
2248
2397
 
2249
2398
  const vContainerDOM: HTMLElement = createDOM(
2250
2399
  '<div id="virtual-image"></div>',
2251
2400
  );
2401
+
2402
+ const camera = canvas.getCamera();
2252
2403
  const vCanvas = createCanvas(
2253
2404
  rendererType,
2254
2405
  vContainerDOM,
@@ -2256,13 +2407,48 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
2256
2407
  height,
2257
2408
  pixelRatio,
2258
2409
  );
2410
+ await vCanvas.ready;
2411
+
2412
+ const backgroundClonedGroup = backgroundCanvas.getRoot().cloneNode(true);
2413
+ const clonedGroup = canvas.getRoot().cloneNode(true);
2414
+ const transientClonedGroup = transientCanvas.getRoot().cloneNode(true);
2415
+ const labelClonedGroup = labelCanvas.getRoot().cloneNode(true);
2416
+
2417
+ const originViewportLTCanvas = vCanvas.viewport2Canvas({ x: 0, y: 0 });
2418
+ const currentViewportLTCanvas = canvas.viewport2Canvas({ x: 0, y: 0 });
2419
+ labelClonedGroup.translate([
2420
+ currentViewportLTCanvas.x - originViewportLTCanvas.x,
2421
+ currentViewportLTCanvas.y - originViewportLTCanvas.y,
2422
+ ]);
2423
+ labelClonedGroup.scale(1 / canvas.getCamera().getZoom());
2424
+ // TODO: after cloning, label background with rotation take a wrong place, remove it to temporary solve.
2425
+ labelClonedGroup.children[0].children.forEach((childGroup) => {
2426
+ childGroup.children.forEach((shape) => {
2427
+ if (
2428
+ shape.getAttribute('data-is-label-background') &&
2429
+ shape.style.transform
2430
+ )
2431
+ shape.remove();
2432
+ });
2433
+ });
2434
+
2435
+ vCanvas.appendChild(backgroundClonedGroup);
2436
+ vCanvas.appendChild(clonedGroup);
2437
+ vCanvas.appendChild(labelClonedGroup);
2438
+ vCanvas.appendChild(transientClonedGroup);
2439
+
2440
+ const vCamera = vCanvas.getCamera();
2441
+ vCamera.setZoom(camera.getZoom());
2442
+ vCamera.setPosition(camera.getPosition());
2443
+ vCamera.setFocalPoint(camera.getFocalPoint());
2444
+
2259
2445
  const vCanvasContextService = vCanvas.getContextService();
2260
2446
  let bgRect;
2261
2447
  if (rendererType !== 'svg') {
2448
+ const backPositionCanvas = canvas.viewport2Canvas({ x: 0, y: 0 });
2262
2449
  bgRect = new Rect({
2263
2450
  style: {
2264
- x: 0,
2265
- y: 0,
2451
+ ...backPositionCanvas,
2266
2452
  z: -1,
2267
2453
  width: vCanvasContextService.getDomElement().width,
2268
2454
  height: vCanvasContextService.getDomElement().height,
@@ -2270,24 +2456,22 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
2270
2456
  fill: backgroundCanvas.getContextService().getDomElement().style[
2271
2457
  'background-color'
2272
2458
  ],
2459
+ zIndex: -10,
2273
2460
  },
2274
2461
  });
2275
2462
  vCanvas.appendChild(bgRect);
2276
2463
  }
2277
- const backgroundClonedGroup = backgroundCanvas.getRoot().cloneNode(true);
2278
- const clonedGroup = canvas.getRoot().cloneNode(true);
2279
- const transientClonedGroup = transientCanvas.getRoot().cloneNode(true);
2280
- vCanvas.appendChild(backgroundClonedGroup);
2281
- vCanvas.appendChild(clonedGroup);
2282
- vCanvas.appendChild(transientClonedGroup);
2283
- vCanvas.render();
2284
2464
 
2285
2465
  if (!type) type = 'image/png';
2286
2466
  let dataURL = '';
2287
- await vCanvasContextService.toDataURL({ type }).then((url) => {
2288
- dataURL = url;
2467
+ return new Promise((resolve) => {
2468
+ setTimeout(() => {
2469
+ vCanvasContextService.toDataURL({ type }).then((url) => {
2470
+ dataURL = url;
2471
+ resolve(dataURL);
2472
+ });
2473
+ }, 50);
2289
2474
  });
2290
- return dataURL;
2291
2475
  }
2292
2476
 
2293
2477
  /**
@@ -2301,17 +2485,22 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
2301
2485
  type?: DataURLType,
2302
2486
  imageConfig?: { padding?: number | number[] },
2303
2487
  ) {
2304
- const backgroundCanvas = this.backgroundCanvas;
2305
- const canvas = this.canvas;
2306
- const transientCanvas = this.transientCanvas;
2307
- const backgroundRoot = canvas.getRoot();
2488
+ const {
2489
+ backgroundCanvas,
2490
+ canvas,
2491
+ transientCanvas,
2492
+ labelCanvas,
2493
+ rendererType,
2494
+ } = this;
2495
+ const backgroundRoot = backgroundCanvas.getRoot();
2308
2496
  const root = canvas.getRoot();
2309
2497
  const transientRoot = transientCanvas.getRoot();
2310
- const rendererType = this.rendererType;
2498
+ const labelRoot = labelCanvas.getRoot();
2311
2499
 
2312
- const backgroundBBox = backgroundRoot.getBBox();
2313
- const BBox = root.getBBox();
2314
- const transientBBox = transientRoot.getBBox();
2500
+ const backgroundBBox = backgroundRoot.getRenderBounds();
2501
+ const BBox = root.getRenderBounds();
2502
+ const transientBBox = transientRoot.getRenderBounds();
2503
+ const labelBBox = labelRoot.getRenderBounds();
2315
2504
 
2316
2505
  let padding = imageConfig ? imageConfig.padding : undefined;
2317
2506
  if (!padding) {
@@ -2321,29 +2510,33 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
2321
2510
  }
2322
2511
 
2323
2512
  const left =
2324
- (transientBBox.left
2325
- ? backgroundBBox.left
2326
- ? Math.min(backgroundBBox.left, BBox.left, transientBBox.left)
2327
- : Math.min(BBox.left, transientBBox.left)
2328
- : BBox.left) - padding[3];
2513
+ Math.min(
2514
+ backgroundBBox.min[0] || Infinity,
2515
+ BBox.min[0] || Infinity,
2516
+ transientBBox.min[0] || Infinity,
2517
+ labelBBox.min[0] || Infinity,
2518
+ ) - padding[3];
2329
2519
  const right =
2330
- (transientBBox.right
2331
- ? backgroundBBox.right
2332
- ? Math.max(backgroundBBox.right, BBox.right, transientBBox.right)
2333
- : Math.max(BBox.right, transientBBox.right)
2334
- : BBox.right) + padding[1];
2520
+ Math.max(
2521
+ backgroundBBox.max[0] || -Infinity,
2522
+ BBox.max[0] || -Infinity,
2523
+ transientBBox.max[0] || -Infinity,
2524
+ labelBBox.max[0] || -Infinity,
2525
+ ) - padding[1];
2335
2526
  const top =
2336
- (transientBBox.top
2337
- ? backgroundBBox.top
2338
- ? Math.min(backgroundBBox.top, BBox.top, transientBBox.top)
2339
- : Math.min(BBox.top, transientBBox.top)
2340
- : BBox.top) - padding[0];
2527
+ Math.min(
2528
+ backgroundBBox.min[1] || Infinity,
2529
+ BBox.min[1] || Infinity,
2530
+ transientBBox.min[1] || Infinity,
2531
+ labelBBox.min[1] || Infinity,
2532
+ ) - padding[0];
2341
2533
  const bottom =
2342
- (transientBBox.bottom
2343
- ? backgroundBBox.bottom
2344
- ? Math.max(backgroundBBox.bottom, BBox.bottom, transientBBox.bottom)
2345
- : Math.max(BBox.bottom, transientBBox.bottom)
2346
- : BBox.bottom) + padding[2];
2534
+ Math.max(
2535
+ backgroundBBox.max[1] || -Infinity,
2536
+ BBox.max[1] || -Infinity,
2537
+ transientBBox.max[1] || -Infinity,
2538
+ labelBBox.max[1] || -Infinity,
2539
+ ) - padding[2];
2347
2540
 
2348
2541
  const graphCenterX = (left + right) / 2;
2349
2542
  const graphCenterY = (top + bottom) / 2;
@@ -2364,6 +2557,7 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
2364
2557
  vHeight,
2365
2558
  pixelRatio,
2366
2559
  );
2560
+ await vCanvas.ready;
2367
2561
  const vCanvasContextService = vCanvas.getContextService();
2368
2562
  if (rendererType !== 'svg') {
2369
2563
  const bgRect = new Rect({
@@ -2384,6 +2578,7 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
2384
2578
  const backgroundClonedGroup = backgroundRoot.cloneNode(true);
2385
2579
  const clonedGroup = root.cloneNode(true);
2386
2580
  const transientClonedGroup = transientRoot.cloneNode(true);
2581
+ const labelClonedGroup = labelRoot.cloneNode(true);
2387
2582
  const transPosition: [number, number] = [
2388
2583
  -graphCenterX + halfX,
2389
2584
  -graphCenterY + halfY,
@@ -2391,17 +2586,40 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
2391
2586
  backgroundClonedGroup.setPosition(transPosition);
2392
2587
  clonedGroup.setPosition(transPosition);
2393
2588
  transientClonedGroup.setPosition(transPosition);
2589
+
2590
+ const currentViewportLTCanvas = canvas.viewport2Canvas({ x: 0, y: 0 });
2591
+ const labelTransPosition: [number, number] = [
2592
+ transPosition[0] + currentViewportLTCanvas.x,
2593
+ transPosition[1] + currentViewportLTCanvas.y,
2594
+ ];
2595
+ labelClonedGroup.setPosition(labelTransPosition);
2596
+ labelClonedGroup.scale(1 / canvas.getCamera().getZoom());
2597
+ // TODO: after cloning, label background with rotation take a wrong place, remove it to temporary solve.
2598
+ labelClonedGroup.children[0].children.forEach((childGroup) => {
2599
+ childGroup.children.forEach((shape) => {
2600
+ if (
2601
+ shape.getAttribute('data-is-label-background') &&
2602
+ shape.style.transform
2603
+ )
2604
+ shape.remove();
2605
+ });
2606
+ });
2607
+
2394
2608
  vCanvas.appendChild(backgroundClonedGroup);
2395
2609
  vCanvas.appendChild(clonedGroup);
2610
+ vCanvas.appendChild(labelClonedGroup);
2396
2611
  vCanvas.appendChild(transientClonedGroup);
2397
- vCanvas.render();
2398
2612
 
2399
2613
  if (!type) type = 'image/png';
2400
2614
  let dataURL = '';
2401
- await vCanvasContextService.toDataURL({ type }).then((url) => {
2402
- dataURL = url;
2615
+ return new Promise((resolve) => {
2616
+ setTimeout(() => {
2617
+ vCanvasContextService.toDataURL({ type }).then((url) => {
2618
+ dataURL = url;
2619
+ resolve(dataURL);
2620
+ });
2621
+ }, 50);
2403
2622
  });
2404
- return dataURL;
2405
2623
  }
2406
2624
 
2407
2625
  /**
@@ -2544,7 +2762,7 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
2544
2762
 
2545
2763
  setTimeout(async () => {
2546
2764
  await this.toFullDataURL(type, imageConfig).then((url) => {
2547
- dataURL = url;
2765
+ dataURL = url as string;
2548
2766
  });
2549
2767
  if (callback) callback(dataURL);
2550
2768
  }, 16);
@@ -2713,7 +2931,7 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
2713
2931
  * @returns
2714
2932
  * @group Tree
2715
2933
  */
2716
- public collapse(ids: ID | ID[], disableAnimate = false, stack?: boolean) {
2934
+ public collapse(ids: ID | ID[], disableAnimate = false) {
2717
2935
  this.hooks.treecollapseexpand.emit({
2718
2936
  ids: isArray(ids) ? ids : [ids],
2719
2937
  action: 'collapse',
@@ -2729,7 +2947,7 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
2729
2947
  * @returns
2730
2948
  * @group Tree
2731
2949
  */
2732
- public expand(ids: ID | ID[], disableAnimate = false, stack?: boolean) {
2950
+ public expand(ids: ID | ID[], disableAnimate = false) {
2733
2951
  this.hooks.treecollapseexpand.emit({
2734
2952
  ids: isArray(ids) ? ids : [ids],
2735
2953
  action: 'expand',
@@ -2744,17 +2962,25 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
2744
2962
  * @group Graph Instance
2745
2963
  */
2746
2964
  public destroy(callback?: Function) {
2747
- // TODO: call the destroy functions after items' buildOut animations finished
2748
- // setTimeout(() => {
2965
+ const camera = this.canvas.getCamera();
2966
+ const transientCamera = this.transientCanvas.getCamera();
2967
+ // @ts-ignore
2968
+ if (camera.landmarks?.length) {
2969
+ camera.cancelLandmarkAnimation();
2970
+ transientCamera.cancelLandmarkAnimation();
2971
+ this.emit('cancelviewportanimation');
2972
+ }
2973
+
2749
2974
  this.canvas.destroy();
2975
+ this.labelCanvas.destroy();
2750
2976
  this.backgroundCanvas.destroy();
2751
2977
  this.transientCanvas.destroy();
2978
+ this.transientLabelCanvas.destroy();
2752
2979
 
2753
2980
  // clear history stack
2754
2981
  this.cleanHistory();
2755
2982
 
2756
2983
  callback?.();
2757
- // }, 500);
2758
2984
 
2759
2985
  this.hooks.destroy.emit({});
2760
2986
 
@@ -2764,7 +2990,6 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
2764
2990
  // this.layoutController.destroy();
2765
2991
  // this.themeController.destroy();
2766
2992
  // this.itemController.destroy();
2767
- // this.extensionController.destroy();
2768
2993
 
2769
2994
  this.destroyed = true;
2770
2995
  }