@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
@@ -31,10 +31,10 @@ const canvas_1 = require("../util/canvas");
31
31
  const dom_1 = require("../util/dom");
32
32
  const layout_1 = require("../util/layout");
33
33
  const shape_1 = require("../util/shape");
34
+ const data_1 = require("../util/data");
35
+ const bbox_1 = require("../util/bbox");
34
36
  const controller_1 = require("./controller");
35
- const plugin_1 = require("./controller/plugin");
36
37
  const hooks_1 = __importDefault(require("./hooks"));
37
- const data_1 = require("../util/data");
38
38
  class Graph extends event_emitter_1.default {
39
39
  constructor(spec) {
40
40
  super();
@@ -68,7 +68,9 @@ class Graph extends event_emitter_1.default {
68
68
  canvases: {
69
69
  background: this.backgroundCanvas,
70
70
  main: this.canvas,
71
+ label: this.labelCanvas,
71
72
  transient: this.transientCanvas,
73
+ transientLabel: this.transientLabelCanvas,
72
74
  },
73
75
  });
74
76
  const { data } = spec;
@@ -85,13 +87,12 @@ class Graph extends event_emitter_1.default {
85
87
  this.interactionController = new controller_1.InteractionController(this);
86
88
  this.layoutController = new controller_1.LayoutController(this);
87
89
  this.themeController = new controller_1.ThemeController(this);
88
- this.itemController = new controller_1.ItemController(this);
89
90
  this.viewportController = new controller_1.ViewportController(this);
90
- this.extensionController = new controller_1.ExtensionController(this);
91
- this.pluginController = new plugin_1.PluginController(this);
91
+ this.itemController = new controller_1.ItemController(this);
92
+ this.pluginController = new controller_1.PluginController(this);
92
93
  }
93
94
  initCanvas() {
94
- const { renderer, container, canvas, backgroundCanvas, transientCanvas, width, height, } = this.specification;
95
+ const { renderer, container, canvas, backgroundCanvas, transientCanvas, transientLabelCanvas, width, height, } = this.specification;
95
96
  let pixelRatio;
96
97
  if (renderer && !(0, util_1.isString)(renderer)) {
97
98
  // @ts-ignore
@@ -110,6 +111,7 @@ class Graph extends event_emitter_1.default {
110
111
  this.canvas = canvas;
111
112
  this.backgroundCanvas = backgroundCanvas;
112
113
  this.transientCanvas = transientCanvas;
114
+ this.transientLabelCanvas = transientLabelCanvas;
113
115
  this.container = container;
114
116
  }
115
117
  else {
@@ -131,10 +133,24 @@ class Graph extends event_emitter_1.default {
131
133
  }
132
134
  this.backgroundCanvas = (0, canvas_1.createCanvas)(this.rendererType, containerDOM, size[0], size[1], pixelRatio);
133
135
  this.canvas = (0, canvas_1.createCanvas)(this.rendererType, containerDOM, size[0], size[1], pixelRatio);
136
+ this.labelCanvas = (0, canvas_1.createCanvas)('canvas', containerDOM, size[0], size[1], pixelRatio);
134
137
  this.transientCanvas = (0, canvas_1.createCanvas)(this.rendererType, containerDOM, size[0], size[1], pixelRatio);
138
+ this.transientLabelCanvas = (0, canvas_1.createCanvas)('canvas', containerDOM, size[0], size[1], pixelRatio);
135
139
  }
136
- Promise.all([this.backgroundCanvas, this.canvas, this.transientCanvas].map((canvas) => canvas.ready)).then(() => {
137
- [this.backgroundCanvas, this.canvas, this.transientCanvas].forEach((canvas, i) => {
140
+ Promise.all([
141
+ this.backgroundCanvas,
142
+ this.canvas,
143
+ this.labelCanvas,
144
+ this.transientCanvas,
145
+ this.transientLabelCanvas,
146
+ ].map((canvas) => canvas.ready)).then(() => {
147
+ [
148
+ this.backgroundCanvas,
149
+ this.canvas,
150
+ this.labelCanvas,
151
+ this.transientCanvas,
152
+ this.transientLabelCanvas,
153
+ ].forEach((canvas, i) => {
138
154
  const $domElement = canvas
139
155
  .getContextService()
140
156
  .getDomElement();
@@ -286,6 +302,7 @@ class Graph extends event_emitter_1.default {
286
302
  graphCore: this.dataController.graphCore,
287
303
  theme: this.themeController.specification,
288
304
  transientCanvas: this.transientCanvas,
305
+ transientLabelCanvas: this.transientLabelCanvas,
289
306
  tileOptimize: {
290
307
  tileFirstRender,
291
308
  tileFirstRenderSize,
@@ -326,7 +343,13 @@ class Graph extends event_emitter_1.default {
326
343
  yield emitRender();
327
344
  }
328
345
  else {
329
- yield Promise.all([this.backgroundCanvas, this.canvas, this.transientCanvas].map((canvas) => canvas.ready));
346
+ yield Promise.all([
347
+ this.backgroundCanvas,
348
+ this.canvas,
349
+ this.labelCanvas,
350
+ this.transientCanvas,
351
+ this.transientLabelCanvas,
352
+ ].map((canvas) => canvas.ready));
330
353
  yield emitRender();
331
354
  }
332
355
  });
@@ -335,10 +358,11 @@ class Graph extends event_emitter_1.default {
335
358
  * Change graph data.
336
359
  * @param data new data
337
360
  * @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)
361
+ * @param relayout whether relayout the nodes after data changing
338
362
  * @returns
339
363
  * @group Data
340
364
  */
341
- changeData(data, type = 'mergeReplace') {
365
+ changeData(data, type = 'mergeReplace', relayout = true) {
342
366
  return __awaiter(this, void 0, void 0, function* () {
343
367
  const { tileFirstRender, tileFirstRenderSize } = this.specification.optimize || {};
344
368
  this.hooks.datachange.emit({ data, type });
@@ -346,13 +370,16 @@ class Graph extends event_emitter_1.default {
346
370
  graphCore: this.dataController.graphCore,
347
371
  theme: this.themeController.specification,
348
372
  transientCanvas: this.transientCanvas,
373
+ transientLabelCanvas: this.transientLabelCanvas,
349
374
  tileOptimize: {
350
375
  tileFirstRender,
351
376
  tileFirstRenderSize,
352
377
  },
353
378
  });
354
379
  this.emit('afterrender');
355
- yield this.layout();
380
+ if (relayout) {
381
+ yield this.layout();
382
+ }
356
383
  });
357
384
  }
358
385
  /**
@@ -505,8 +532,8 @@ class Graph extends event_emitter_1.default {
505
532
  const { direction = 'both', ratioRule = 'min', boundsType = 'render', onlyOutOfViewport = false, onlyZoomAtLargerThanViewport = false, } = rules || {};
506
533
  const { min, max, center: [graphCenterX, graphCenterY], halfExtents, } = boundsType === 'render'
507
534
  ? // Get the bounds of the whole graph content.
508
- this.canvas.document.documentElement.getBounds()
509
- : // Get the bounds of the nodes positions while the graph content is not ready.
535
+ (0, bbox_1.getCombinedCanvasesBounds)([this.canvas, this.labelCanvas])
536
+ : // Get the b ounds of the nodes positions while the graph content is not ready.
510
537
  (0, layout_1.getLayoutBounds)(this);
511
538
  const origin = this.canvas.canvas2Viewport({
512
539
  x: graphCenterX,
@@ -566,7 +593,7 @@ class Graph extends event_emitter_1.default {
566
593
  return __awaiter(this, void 0, void 0, function* () {
567
594
  const { center: [graphCenterX, graphCenterY], } = boundsType === 'render'
568
595
  ? // Get the bounds of the whole graph content.
569
- this.canvas.document.documentElement.getBounds()
596
+ (0, bbox_1.getCombinedCanvasesBounds)([this.canvas, this.labelCanvas])
570
597
  : // Get the bounds of the nodes positions while the graph content is not ready.
571
598
  (0, layout_1.getLayoutBounds)(this);
572
599
  yield this.translateTo(this.canvas.canvas2Viewport({ x: graphCenterX, y: graphCenterY }), effectTiming);
@@ -629,9 +656,15 @@ class Graph extends event_emitter_1.default {
629
656
  this.emit('beforesetsize', { oldSize, size: size });
630
657
  this.specification.width = size[0];
631
658
  this.specification.height = size[1];
632
- this.canvas.resize(size[0], size[1]);
633
- this.transientCanvas.resize(size[0], size[1]);
634
- this.backgroundCanvas.resize(size[0], size[1]);
659
+ [
660
+ this.canvas,
661
+ this.labelCanvas,
662
+ this.transientCanvas,
663
+ this.transientLabelCanvas,
664
+ this.backgroundCanvas,
665
+ ].forEach((canvas) => {
666
+ canvas.resize(size[0], size[1]);
667
+ });
635
668
  this.emit('aftersetsize', { oldSize, size: size });
636
669
  }
637
670
  getCanvasRange() {
@@ -760,6 +793,16 @@ class Graph extends event_emitter_1.default {
760
793
  getRelatedEdgesData(nodeId, direction = 'both') {
761
794
  return this.dataController.findRelatedEdges(nodeId, direction);
762
795
  }
796
+ /**
797
+ * Get nearby edges from a start node using quadtree collision detection.
798
+ * @param nodeId id of the start node
799
+ * @returns nearby edges' data array
800
+ */
801
+ getNearEdgesData(nodeId, shouldBegin) {
802
+ const transientItem = this.itemController.getTransientItem(nodeId);
803
+ const itemMap = this.itemController.getItemMap();
804
+ return this.dataController.findNearEdges(nodeId, itemMap, transientItem, shouldBegin);
805
+ }
763
806
  /**
764
807
  * Get one-hop node ids from a start node.
765
808
  * @param nodeId id of the start node
@@ -797,15 +840,6 @@ class Graph extends event_emitter_1.default {
797
840
  getDisplayModel(id) {
798
841
  return this.itemController.findDisplayModel(id);
799
842
  }
800
- /**
801
- * Retrieve the nearby edges for a given node using quadtree collision detection.
802
- * @param nodeId node id
803
- * @group Data
804
- */
805
- getNearEdgesForNode(nodeId) {
806
- const { graphCore } = this.dataController;
807
- return this.itemController.findNearEdgesByNode(nodeId, graphCore);
808
- }
809
843
  /**
810
844
  * Find items which has the state.
811
845
  * @param itemType item type
@@ -837,6 +871,7 @@ class Graph extends event_emitter_1.default {
837
871
  // data controller and item controller subscribe additem in order
838
872
  const { graphCore } = this.dataController;
839
873
  const { specification } = this.themeController;
874
+ const modelArr = (0, util_1.isArray)(models) ? models : [models];
840
875
  graphCore.once('changed', (event) => {
841
876
  if (!event.changes.length)
842
877
  return;
@@ -844,7 +879,7 @@ class Graph extends event_emitter_1.default {
844
879
  const timingParameters = {
845
880
  type: itemType,
846
881
  action: 'add',
847
- models,
882
+ models: modelArr,
848
883
  apiName: 'addData',
849
884
  changes,
850
885
  };
@@ -857,7 +892,6 @@ class Graph extends event_emitter_1.default {
857
892
  });
858
893
  this.emit('afteritemchange', timingParameters);
859
894
  });
860
- const modelArr = (0, util_1.isArray)(models) ? models : [models];
861
895
  const data = { nodes: [], edges: [], combos: [] };
862
896
  data[`${itemType}s`] = modelArr;
863
897
  this.hooks.datachange.emit({
@@ -869,7 +903,8 @@ class Graph extends event_emitter_1.default {
869
903
  }
870
904
  /**
871
905
  * Remove one or more node/edge/combo data from the graph.
872
- * @param item the item to be removed
906
+ * @param itemType the type the item(s) to be removed.
907
+ * @param id the id or the ids' array of the items to be removed.
873
908
  * @returns whether success
874
909
  * @group Data
875
910
  */
@@ -963,8 +998,8 @@ class Graph extends event_emitter_1.default {
963
998
  }
964
999
  /**
965
1000
  * Update one or more node/edge/combo data on the graph.
966
- * @param {ITEM_TYPE} itemType 'node' | 'edge' | 'combo'
967
- * @param models new configurations for every node/edge/combo, which has id field to indicate the specific item
1001
+ * @param {ITEM_TYPE} itemType the type the item(s) to be udated.
1002
+ * @param models update configs.
968
1003
  * @group Data
969
1004
  */
970
1005
  updateData(itemType, models) {
@@ -974,11 +1009,11 @@ class Graph extends event_emitter_1.default {
974
1009
  const { graphCore } = this.dataController;
975
1010
  const { specification } = this.themeController;
976
1011
  graphCore.once('changed', (event) => {
977
- const changes = this.extendChanges((0, util_1.clone)(event.changes));
1012
+ const changes = this.extendChanges((0, data_1.cloneJSON)(event.changes));
978
1013
  const timingParameters = {
979
1014
  type: itemType,
980
1015
  action: 'update',
981
- models,
1016
+ models: modelArr,
982
1017
  apiName: 'updateData',
983
1018
  changes,
984
1019
  };
@@ -1001,21 +1036,27 @@ class Graph extends event_emitter_1.default {
1001
1036
  /**
1002
1037
  * Update one or more nodes' positions,
1003
1038
  * do not update other styles which leads to better performance than updating positions by updateData.
1004
- * @param models new configurations with x and y for every node, which has id field to indicate the specific item
1039
+ * @param models new configurations with x and y for every node, which has id field to indicate the specific item.
1040
+ * @param upsertAncestors whether update the ancestors in combo tree.
1041
+ * @param disableAnimate whether disable the animation for this call.
1042
+ * @param callback callback function after update nodes done.
1005
1043
  * @group Data
1006
1044
  */
1007
- updateNodePosition(models, upsertAncestors, disableAnimate = false, callback, stack) {
1008
- return this.updatePosition('node', models, upsertAncestors, disableAnimate, callback, stack);
1045
+ updateNodePosition(models, upsertAncestors, disableAnimate = false, callback) {
1046
+ return this.updatePosition('node', models, upsertAncestors, disableAnimate, callback);
1009
1047
  }
1010
1048
  /**
1011
1049
  * Update one or more combos' positions,
1012
1050
  * do not update other styles which leads to better performance than updating positions by updateData.
1013
1051
  * In fact, it changes the succeed nodes positions to affect the combo's position, but not modify the combo's position directly.
1014
- * @param models new configurations with x and y for every combo, which has id field to indicate the specific item
1052
+ * @param models new configurations with x and y for every combo, which has id field to indicate the specific item.
1053
+ * @param upsertAncestors whether update the ancestors in combo tree.
1054
+ * @param disableAnimate whether disable the animation for this call.
1055
+ * @param callback callback function after update combos done.
1015
1056
  * @group Data
1016
1057
  */
1017
- updateComboPosition(models, upsertAncestors, disableAnimate = false, callback, stack) {
1018
- return this.updatePosition('combo', models, upsertAncestors, disableAnimate, callback, stack);
1058
+ updateComboPosition(models, upsertAncestors, disableAnimate = false, callback) {
1059
+ return this.updatePosition('combo', models, upsertAncestors, disableAnimate, callback);
1019
1060
  }
1020
1061
  /**
1021
1062
  * Get history plugin instance
@@ -1028,7 +1069,7 @@ class Graph extends event_emitter_1.default {
1028
1069
  }
1029
1070
  return this.pluginController.getPlugin('history');
1030
1071
  }
1031
- updatePosition(type, models, upsertAncestors, disableAnimate = false, callback, stack) {
1072
+ updatePosition(type, models, upsertAncestors, disableAnimate = false, callback) {
1032
1073
  const modelArr = (0, util_1.isArray)(models) ? models : [models];
1033
1074
  const { graphCore } = this.dataController;
1034
1075
  const { specification } = this.themeController;
@@ -1040,7 +1081,7 @@ class Graph extends event_emitter_1.default {
1040
1081
  type,
1041
1082
  action: 'updatePosition',
1042
1083
  upsertAncestors,
1043
- models,
1084
+ models: modelArr,
1044
1085
  apiName: 'updatePosition',
1045
1086
  changes,
1046
1087
  };
@@ -1086,22 +1127,40 @@ class Graph extends event_emitter_1.default {
1086
1127
  * @returns
1087
1128
  * @group Item
1088
1129
  */
1089
- showItem(ids, disableAnimate = false) {
1130
+ showItem(ids, options) {
1131
+ const { disableAnimate = false, shapeIds } = options || {};
1090
1132
  const idArr = (0, util_1.isArray)(ids) ? ids : [ids];
1091
1133
  if ((0, util_1.isEmpty)(idArr))
1092
1134
  return;
1093
- const changes = {
1094
- newValue: [{ ids: idArr, visible: true }],
1095
- oldValue: this.getItemPreviousVisibility(idArr),
1096
- };
1097
- this.hooks.itemvisibilitychange.emit({
1098
- ids: idArr,
1099
- value: true,
1100
- graphCore: this.dataController.graphCore,
1101
- animate: !disableAnimate,
1102
- });
1135
+ let changes;
1136
+ if (shapeIds === null || shapeIds === void 0 ? void 0 : shapeIds.length) {
1137
+ const shapeIdsArr = (0, util_1.isArray)(shapeIds) ? shapeIds : [shapeIds];
1138
+ changes = {
1139
+ newValue: [{ ids: idArr, visible: true, shapeIds: shapeIdsArr }],
1140
+ oldValue: this.getItemPreviousVisibility(idArr),
1141
+ };
1142
+ this.hooks.itemvisibilitychange.emit({
1143
+ ids: idArr,
1144
+ value: true,
1145
+ graphCore: this.dataController.graphCore,
1146
+ animate: !disableAnimate,
1147
+ shapeIds: shapeIdsArr,
1148
+ });
1149
+ }
1150
+ else {
1151
+ changes = {
1152
+ newValue: [{ ids: idArr, visible: true }],
1153
+ oldValue: this.getItemPreviousVisibility(idArr),
1154
+ };
1155
+ this.hooks.itemvisibilitychange.emit({
1156
+ ids: idArr,
1157
+ value: true,
1158
+ graphCore: this.dataController.graphCore,
1159
+ animate: !disableAnimate,
1160
+ });
1161
+ }
1103
1162
  this.emit('afteritemvisibilitychange', {
1104
- ids,
1163
+ ids: idArr,
1105
1164
  value: true,
1106
1165
  animate: !disableAnimate,
1107
1166
  action: 'updateVisibility',
@@ -1111,27 +1170,49 @@ class Graph extends event_emitter_1.default {
1111
1170
  }
1112
1171
  /**
1113
1172
  * Hide the item(s).
1114
- * @param item the item to be hidden
1173
+ * @param id the id for the item to be hidden.
1174
+ * @param disableAnimate whether disable the hidden animations.
1175
+ * @param keepKeyShape whether keep the keyShape.
1176
+ * @param keepRelated whether keep the related nodes for edge.
1115
1177
  * @returns
1116
1178
  * @group Item
1117
1179
  */
1118
- hideItem(ids, disableAnimate = false, keepKeyShape = false) {
1180
+ hideItem(ids, options) {
1181
+ const { disableAnimate = false, keepKeyShape = false, keepRelated = false, shapeIds, } = options || {};
1119
1182
  const idArr = (0, util_1.isArray)(ids) ? ids : [ids];
1120
1183
  if ((0, util_1.isEmpty)(idArr))
1121
1184
  return;
1122
- const changes = {
1123
- newValue: [{ ids: idArr, visible: false }],
1124
- oldValue: this.getItemPreviousVisibility(idArr),
1125
- };
1126
- this.hooks.itemvisibilitychange.emit({
1127
- ids: idArr,
1128
- value: false,
1129
- graphCore: this.dataController.graphCore,
1130
- animate: !disableAnimate,
1131
- keepKeyShape,
1132
- });
1185
+ let changes;
1186
+ if (shapeIds === null || shapeIds === void 0 ? void 0 : shapeIds.length) {
1187
+ const shapeIdsArr = (0, util_1.isArray)(shapeIds) ? shapeIds : [shapeIds];
1188
+ changes = {
1189
+ newValue: [{ ids: idArr, visible: false, shapeIds: shapeIdsArr }],
1190
+ oldValue: this.getItemPreviousVisibility(idArr),
1191
+ };
1192
+ this.hooks.itemvisibilitychange.emit({
1193
+ ids: idArr,
1194
+ value: false,
1195
+ graphCore: this.dataController.graphCore,
1196
+ animate: !disableAnimate,
1197
+ shapeIds: shapeIdsArr,
1198
+ });
1199
+ }
1200
+ else {
1201
+ changes = {
1202
+ newValue: [{ ids: idArr, visible: false }],
1203
+ oldValue: this.getItemPreviousVisibility(idArr),
1204
+ };
1205
+ this.hooks.itemvisibilitychange.emit({
1206
+ ids: idArr,
1207
+ value: false,
1208
+ graphCore: this.dataController.graphCore,
1209
+ animate: !disableAnimate,
1210
+ keepKeyShape,
1211
+ keepRelated,
1212
+ });
1213
+ }
1133
1214
  this.emit('afteritemvisibilitychange', {
1134
- ids,
1215
+ ids: idArr,
1135
1216
  value: false,
1136
1217
  animate: !disableAnimate,
1137
1218
  action: 'updateVisibility',
@@ -1292,11 +1373,20 @@ class Graph extends event_emitter_1.default {
1292
1373
  getItemVisible(id) {
1293
1374
  return this.itemController.getItemVisible(id);
1294
1375
  }
1376
+ /**
1377
+ * Get the visible shape ids in a node / edge / combo.
1378
+ * @param id the id for the node / edge / combo
1379
+ * @returns ids of the visible shapes
1380
+ */
1381
+ getItemVisibleShapeIds(id) {
1382
+ return this.itemController.getItemVisibleShapeIds(id);
1383
+ }
1295
1384
  // ===== combo operations =====
1296
1385
  /**
1297
1386
  * 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.
1298
1387
  * Different from addData with combo type, this API update the succeeds' combo tree strucutres in the same time.
1299
- * @param model combo user data
1388
+ * @param model combo user data.
1389
+ * @param childrenIds the ids of the children nodes / combos to move into the new combo.
1300
1390
  * @returns whether success
1301
1391
  * @group Combo
1302
1392
  */
@@ -1338,7 +1428,7 @@ class Graph extends event_emitter_1.default {
1338
1428
  }
1339
1429
  /**
1340
1430
  * Collapse a combo.
1341
- * @param comboId combo ids
1431
+ * @param comboId combo id or ids' array.
1342
1432
  * @group Combo
1343
1433
  */
1344
1434
  collapseCombo(comboIds) {
@@ -1355,7 +1445,7 @@ class Graph extends event_emitter_1.default {
1355
1445
  }
1356
1446
  /**
1357
1447
  * Expand a combo.
1358
- * @param combo combo ids
1448
+ * @param comboId combo id or ids' array.
1359
1449
  * @group Combo
1360
1450
  */
1361
1451
  expandCombo(comboIds) {
@@ -1374,7 +1464,11 @@ class Graph extends event_emitter_1.default {
1374
1464
  * Move one or more combos a distance (dx, dy) relatively,
1375
1465
  * do not update other styles which leads to better performance than updating positions by updateData.
1376
1466
  * In fact, it changes the succeed nodes positions to affect the combo's position, but not modify the combo's position directly.
1377
- * @param models new configurations with x and y for every combo, which has id field to indicate the specific item
1467
+ * @param models new configurations with x and y for every combo, which has id field to indicate the specific item.
1468
+ * @param dx the distance alone x-axis to move the combo.
1469
+ * @param dy the distance alone y-axis to move the combo.
1470
+ * @param upsertAncestors whether update the ancestors in the combo tree.
1471
+ * @param callback callback function after move combo done.
1378
1472
  * @group Combo
1379
1473
  */
1380
1474
  moveCombo(ids, dx, dy, upsertAncestors, callback) {
@@ -1496,7 +1590,9 @@ class Graph extends event_emitter_1.default {
1496
1590
  */
1497
1591
  setCursor(cursor) {
1498
1592
  this.canvas.setCursor(cursor);
1593
+ this.labelCanvas.setCursor(cursor);
1499
1594
  this.transientCanvas.setCursor(cursor);
1595
+ this.transientLabelCanvas.setCursor(cursor);
1500
1596
  }
1501
1597
  /**
1502
1598
  * Add behavior(s) to mode(s).
@@ -1628,10 +1724,9 @@ class Graph extends event_emitter_1.default {
1628
1724
  */
1629
1725
  updatePlugin(plugin) {
1630
1726
  const { plugins } = this.specification;
1631
- const { key } = plugin;
1727
+ const { key, type } = plugin;
1632
1728
  if (!key) {
1633
- console.warn('Update plugin failed, the key for the plugin to be updated should be assign.');
1634
- return;
1729
+ console.warn(`The key for the plugin is not found. G6 will update the first plugin with type ${type}`);
1635
1730
  }
1636
1731
  if (!plugins) {
1637
1732
  console.warn('Update plugin failed, the plugin to be updated does not exist.');
@@ -1639,11 +1734,12 @@ class Graph extends event_emitter_1.default {
1639
1734
  }
1640
1735
  const oldPlugin = plugins === null || plugins === void 0 ? void 0 : plugins.find((p) => {
1641
1736
  if (typeof p === 'string')
1642
- return p === key;
1643
- return p.key === key;
1737
+ return p === key || p === type;
1738
+ return (p.key === key ||
1739
+ p.type === type);
1644
1740
  });
1645
1741
  if (!oldPlugin) {
1646
- console.warn('Update plugin failed, the key for the plugin to be updated should be assign.');
1742
+ console.warn(`Update plugin failed, the plugin with key ${key} or type ${type} is not found.`);
1647
1743
  return;
1648
1744
  }
1649
1745
  const idx = plugins.indexOf(oldPlugin);
@@ -1679,45 +1775,62 @@ class Graph extends event_emitter_1.default {
1679
1775
  */
1680
1776
  toDataURL(type) {
1681
1777
  return __awaiter(this, void 0, void 0, function* () {
1682
- const backgroundCanvas = this.backgroundCanvas;
1683
- const canvas = this.canvas;
1684
- const transientCanvas = this.transientCanvas;
1685
- const rendererType = this.rendererType;
1778
+ const { backgroundCanvas, canvas, transientCanvas, labelCanvas, rendererType, } = this;
1686
1779
  const pixelRatio = typeof window !== 'undefined' ? window.devicePixelRatio : 1;
1687
- const width = this.getSize()[0];
1688
- const height = this.getSize()[1];
1780
+ const [width, height] = this.getSize();
1689
1781
  const vContainerDOM = (0, dom_1.createDOM)('<div id="virtual-image"></div>');
1782
+ const camera = canvas.getCamera();
1690
1783
  const vCanvas = (0, canvas_1.createCanvas)(rendererType, vContainerDOM, width, height, pixelRatio);
1784
+ yield vCanvas.ready;
1785
+ const backgroundClonedGroup = backgroundCanvas.getRoot().cloneNode(true);
1786
+ const clonedGroup = canvas.getRoot().cloneNode(true);
1787
+ const transientClonedGroup = transientCanvas.getRoot().cloneNode(true);
1788
+ const labelClonedGroup = labelCanvas.getRoot().cloneNode(true);
1789
+ const originViewportLTCanvas = vCanvas.viewport2Canvas({ x: 0, y: 0 });
1790
+ const currentViewportLTCanvas = canvas.viewport2Canvas({ x: 0, y: 0 });
1791
+ labelClonedGroup.translate([
1792
+ currentViewportLTCanvas.x - originViewportLTCanvas.x,
1793
+ currentViewportLTCanvas.y - originViewportLTCanvas.y,
1794
+ ]);
1795
+ labelClonedGroup.scale(1 / canvas.getCamera().getZoom());
1796
+ // TODO: after cloning, label background with rotation take a wrong place, remove it to temporary solve.
1797
+ labelClonedGroup.children[0].children.forEach((childGroup) => {
1798
+ childGroup.children.forEach((shape) => {
1799
+ if (shape.getAttribute('data-is-label-background') &&
1800
+ shape.style.transform)
1801
+ shape.remove();
1802
+ });
1803
+ });
1804
+ vCanvas.appendChild(backgroundClonedGroup);
1805
+ vCanvas.appendChild(clonedGroup);
1806
+ vCanvas.appendChild(labelClonedGroup);
1807
+ vCanvas.appendChild(transientClonedGroup);
1808
+ const vCamera = vCanvas.getCamera();
1809
+ vCamera.setZoom(camera.getZoom());
1810
+ vCamera.setPosition(camera.getPosition());
1811
+ vCamera.setFocalPoint(camera.getFocalPoint());
1691
1812
  const vCanvasContextService = vCanvas.getContextService();
1692
1813
  let bgRect;
1693
1814
  if (rendererType !== 'svg') {
1815
+ const backPositionCanvas = canvas.viewport2Canvas({ x: 0, y: 0 });
1694
1816
  bgRect = new g_1.Rect({
1695
- style: {
1696
- x: 0,
1697
- y: 0,
1698
- z: -1,
1699
- width: vCanvasContextService.getDomElement().width,
1700
- height: vCanvasContextService.getDomElement().height,
1817
+ style: Object.assign(Object.assign({}, backPositionCanvas), { z: -1, width: vCanvasContextService.getDomElement().width, height: vCanvasContextService.getDomElement().height,
1701
1818
  //@ts-ignore
1702
- fill: backgroundCanvas.getContextService().getDomElement().style['background-color'],
1703
- },
1819
+ fill: backgroundCanvas.getContextService().getDomElement().style['background-color'], zIndex: -10 }),
1704
1820
  });
1705
1821
  vCanvas.appendChild(bgRect);
1706
1822
  }
1707
- const backgroundClonedGroup = backgroundCanvas.getRoot().cloneNode(true);
1708
- const clonedGroup = canvas.getRoot().cloneNode(true);
1709
- const transientClonedGroup = transientCanvas.getRoot().cloneNode(true);
1710
- vCanvas.appendChild(backgroundClonedGroup);
1711
- vCanvas.appendChild(clonedGroup);
1712
- vCanvas.appendChild(transientClonedGroup);
1713
- vCanvas.render();
1714
1823
  if (!type)
1715
1824
  type = 'image/png';
1716
1825
  let dataURL = '';
1717
- yield vCanvasContextService.toDataURL({ type }).then((url) => {
1718
- dataURL = url;
1826
+ return new Promise((resolve) => {
1827
+ setTimeout(() => {
1828
+ vCanvasContextService.toDataURL({ type }).then((url) => {
1829
+ dataURL = url;
1830
+ resolve(dataURL);
1831
+ });
1832
+ }, 50);
1719
1833
  });
1720
- return dataURL;
1721
1834
  });
1722
1835
  }
1723
1836
  /**
@@ -1729,16 +1842,15 @@ class Graph extends event_emitter_1.default {
1729
1842
  */
1730
1843
  toFullDataURL(type, imageConfig) {
1731
1844
  return __awaiter(this, void 0, void 0, function* () {
1732
- const backgroundCanvas = this.backgroundCanvas;
1733
- const canvas = this.canvas;
1734
- const transientCanvas = this.transientCanvas;
1735
- const backgroundRoot = canvas.getRoot();
1845
+ const { backgroundCanvas, canvas, transientCanvas, labelCanvas, rendererType, } = this;
1846
+ const backgroundRoot = backgroundCanvas.getRoot();
1736
1847
  const root = canvas.getRoot();
1737
1848
  const transientRoot = transientCanvas.getRoot();
1738
- const rendererType = this.rendererType;
1739
- const backgroundBBox = backgroundRoot.getBBox();
1740
- const BBox = root.getBBox();
1741
- const transientBBox = transientRoot.getBBox();
1849
+ const labelRoot = labelCanvas.getRoot();
1850
+ const backgroundBBox = backgroundRoot.getRenderBounds();
1851
+ const BBox = root.getRenderBounds();
1852
+ const transientBBox = transientRoot.getRenderBounds();
1853
+ const labelBBox = labelRoot.getRenderBounds();
1742
1854
  let padding = imageConfig ? imageConfig.padding : undefined;
1743
1855
  if (!padding) {
1744
1856
  padding = [0, 0, 0, 0];
@@ -1746,26 +1858,10 @@ class Graph extends event_emitter_1.default {
1746
1858
  else if ((0, util_1.isNumber)(padding)) {
1747
1859
  padding = [padding, padding, padding, padding];
1748
1860
  }
1749
- const left = (transientBBox.left
1750
- ? backgroundBBox.left
1751
- ? Math.min(backgroundBBox.left, BBox.left, transientBBox.left)
1752
- : Math.min(BBox.left, transientBBox.left)
1753
- : BBox.left) - padding[3];
1754
- const right = (transientBBox.right
1755
- ? backgroundBBox.right
1756
- ? Math.max(backgroundBBox.right, BBox.right, transientBBox.right)
1757
- : Math.max(BBox.right, transientBBox.right)
1758
- : BBox.right) + padding[1];
1759
- const top = (transientBBox.top
1760
- ? backgroundBBox.top
1761
- ? Math.min(backgroundBBox.top, BBox.top, transientBBox.top)
1762
- : Math.min(BBox.top, transientBBox.top)
1763
- : BBox.top) - padding[0];
1764
- const bottom = (transientBBox.bottom
1765
- ? backgroundBBox.bottom
1766
- ? Math.max(backgroundBBox.bottom, BBox.bottom, transientBBox.bottom)
1767
- : Math.max(BBox.bottom, transientBBox.bottom)
1768
- : BBox.bottom) + padding[2];
1861
+ const left = Math.min(backgroundBBox.min[0] || Infinity, BBox.min[0] || Infinity, transientBBox.min[0] || Infinity, labelBBox.min[0] || Infinity) - padding[3];
1862
+ const right = Math.max(backgroundBBox.max[0] || -Infinity, BBox.max[0] || -Infinity, transientBBox.max[0] || -Infinity, labelBBox.max[0] || -Infinity) - padding[1];
1863
+ const top = Math.min(backgroundBBox.min[1] || Infinity, BBox.min[1] || Infinity, transientBBox.min[1] || Infinity, labelBBox.min[1] || Infinity) - padding[0];
1864
+ const bottom = Math.max(backgroundBBox.max[1] || -Infinity, BBox.max[1] || -Infinity, transientBBox.max[1] || -Infinity, labelBBox.max[1] || -Infinity) - padding[2];
1769
1865
  const graphCenterX = (left + right) / 2;
1770
1866
  const graphCenterY = (top + bottom) / 2;
1771
1867
  const halfX = (right - left) / 2;
@@ -1775,6 +1871,7 @@ class Graph extends event_emitter_1.default {
1775
1871
  const vHeight = halfY * 2;
1776
1872
  const vContainerDOM = (0, dom_1.createDOM)('<div id="virtual-image"></div>');
1777
1873
  const vCanvas = (0, canvas_1.createCanvas)(rendererType, vContainerDOM, vWidth, vHeight, pixelRatio);
1874
+ yield vCanvas.ready;
1778
1875
  const vCanvasContextService = vCanvas.getContextService();
1779
1876
  if (rendererType !== 'svg') {
1780
1877
  const bgRect = new g_1.Rect({
@@ -1793,6 +1890,7 @@ class Graph extends event_emitter_1.default {
1793
1890
  const backgroundClonedGroup = backgroundRoot.cloneNode(true);
1794
1891
  const clonedGroup = root.cloneNode(true);
1795
1892
  const transientClonedGroup = transientRoot.cloneNode(true);
1893
+ const labelClonedGroup = labelRoot.cloneNode(true);
1796
1894
  const transPosition = [
1797
1895
  -graphCenterX + halfX,
1798
1896
  -graphCenterY + halfY,
@@ -1800,17 +1898,36 @@ class Graph extends event_emitter_1.default {
1800
1898
  backgroundClonedGroup.setPosition(transPosition);
1801
1899
  clonedGroup.setPosition(transPosition);
1802
1900
  transientClonedGroup.setPosition(transPosition);
1901
+ const currentViewportLTCanvas = canvas.viewport2Canvas({ x: 0, y: 0 });
1902
+ const labelTransPosition = [
1903
+ transPosition[0] + currentViewportLTCanvas.x,
1904
+ transPosition[1] + currentViewportLTCanvas.y,
1905
+ ];
1906
+ labelClonedGroup.setPosition(labelTransPosition);
1907
+ labelClonedGroup.scale(1 / canvas.getCamera().getZoom());
1908
+ // TODO: after cloning, label background with rotation take a wrong place, remove it to temporary solve.
1909
+ labelClonedGroup.children[0].children.forEach((childGroup) => {
1910
+ childGroup.children.forEach((shape) => {
1911
+ if (shape.getAttribute('data-is-label-background') &&
1912
+ shape.style.transform)
1913
+ shape.remove();
1914
+ });
1915
+ });
1803
1916
  vCanvas.appendChild(backgroundClonedGroup);
1804
1917
  vCanvas.appendChild(clonedGroup);
1918
+ vCanvas.appendChild(labelClonedGroup);
1805
1919
  vCanvas.appendChild(transientClonedGroup);
1806
- vCanvas.render();
1807
1920
  if (!type)
1808
1921
  type = 'image/png';
1809
1922
  let dataURL = '';
1810
- yield vCanvasContextService.toDataURL({ type }).then((url) => {
1811
- dataURL = url;
1923
+ return new Promise((resolve) => {
1924
+ setTimeout(() => {
1925
+ vCanvasContextService.toDataURL({ type }).then((url) => {
1926
+ dataURL = url;
1927
+ resolve(dataURL);
1928
+ });
1929
+ }, 50);
1812
1930
  });
1813
- return dataURL;
1814
1931
  });
1815
1932
  }
1816
1933
  /**
@@ -2072,7 +2189,7 @@ class Graph extends event_emitter_1.default {
2072
2189
  * @returns
2073
2190
  * @group Tree
2074
2191
  */
2075
- collapse(ids, disableAnimate = false, stack) {
2192
+ collapse(ids, disableAnimate = false) {
2076
2193
  this.hooks.treecollapseexpand.emit({
2077
2194
  ids: (0, util_1.isArray)(ids) ? ids : [ids],
2078
2195
  action: 'collapse',
@@ -2088,7 +2205,7 @@ class Graph extends event_emitter_1.default {
2088
2205
  * @returns
2089
2206
  * @group Tree
2090
2207
  */
2091
- expand(ids, disableAnimate = false, stack) {
2208
+ expand(ids, disableAnimate = false) {
2092
2209
  this.hooks.treecollapseexpand.emit({
2093
2210
  ids: (0, util_1.isArray)(ids) ? ids : [ids],
2094
2211
  action: 'expand',
@@ -2102,15 +2219,23 @@ class Graph extends event_emitter_1.default {
2102
2219
  * @group Graph Instance
2103
2220
  */
2104
2221
  destroy(callback) {
2105
- // TODO: call the destroy functions after items' buildOut animations finished
2106
- // setTimeout(() => {
2222
+ var _a;
2223
+ const camera = this.canvas.getCamera();
2224
+ const transientCamera = this.transientCanvas.getCamera();
2225
+ // @ts-ignore
2226
+ if ((_a = camera.landmarks) === null || _a === void 0 ? void 0 : _a.length) {
2227
+ camera.cancelLandmarkAnimation();
2228
+ transientCamera.cancelLandmarkAnimation();
2229
+ this.emit('cancelviewportanimation');
2230
+ }
2107
2231
  this.canvas.destroy();
2232
+ this.labelCanvas.destroy();
2108
2233
  this.backgroundCanvas.destroy();
2109
2234
  this.transientCanvas.destroy();
2235
+ this.transientLabelCanvas.destroy();
2110
2236
  // clear history stack
2111
2237
  this.cleanHistory();
2112
2238
  callback === null || callback === void 0 ? void 0 : callback();
2113
- // }, 500);
2114
2239
  this.hooks.destroy.emit({});
2115
2240
  // TODO: destroy controllers and off the listeners
2116
2241
  // this.dataController.destroy();
@@ -2118,7 +2243,6 @@ class Graph extends event_emitter_1.default {
2118
2243
  // this.layoutController.destroy();
2119
2244
  // this.themeController.destroy();
2120
2245
  // this.itemController.destroy();
2121
- // this.extensionController.destroy();
2122
2246
  this.destroyed = true;
2123
2247
  }
2124
2248
  }