@antv/g6 5.0.0-beta.1 → 5.0.0-beta.11

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 (409) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/esm/constant/shape.d.ts +4 -1
  3. package/esm/constant/shape.js.map +1 -1
  4. package/esm/index.d.ts +22 -7
  5. package/esm/index.js +3 -2
  6. package/esm/index.js.map +1 -1
  7. package/esm/item/combo.d.ts +1 -1
  8. package/esm/item/combo.js +16 -9
  9. package/esm/item/combo.js.map +1 -1
  10. package/esm/item/edge.d.ts +20 -3
  11. package/esm/item/edge.js +99 -43
  12. package/esm/item/edge.js.map +1 -1
  13. package/esm/item/item.d.ts +3 -2
  14. package/esm/item/item.js +21 -11
  15. package/esm/item/item.js.map +1 -1
  16. package/esm/item/node.d.ts +2 -1
  17. package/esm/item/node.js +32 -16
  18. package/esm/item/node.js.map +1 -1
  19. package/esm/runtime/controller/data.d.ts +7 -10
  20. package/esm/runtime/controller/data.js +125 -281
  21. package/esm/runtime/controller/data.js.map +1 -1
  22. package/esm/runtime/controller/item.d.ts +1 -0
  23. package/esm/runtime/controller/item.js +267 -151
  24. package/esm/runtime/controller/item.js.map +1 -1
  25. package/esm/runtime/graph.d.ts +103 -23
  26. package/esm/runtime/graph.js +460 -88
  27. package/esm/runtime/graph.js.map +1 -1
  28. package/esm/stdlib/behavior/activate-relations.d.ts +9 -9
  29. package/esm/stdlib/behavior/activate-relations.js +8 -8
  30. package/esm/stdlib/behavior/activate-relations.js.map +1 -1
  31. package/esm/stdlib/behavior/brush-select.js +1 -2
  32. package/esm/stdlib/behavior/brush-select.js.map +1 -1
  33. package/esm/stdlib/behavior/click-select.js +1 -1
  34. package/esm/stdlib/behavior/click-select.js.map +1 -1
  35. package/esm/stdlib/behavior/create-edge.d.ts +57 -0
  36. package/esm/stdlib/behavior/create-edge.js +207 -0
  37. package/esm/stdlib/behavior/create-edge.js.map +1 -0
  38. package/esm/stdlib/behavior/drag-canvas.d.ts +2 -1
  39. package/esm/stdlib/behavior/drag-canvas.js +59 -28
  40. package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
  41. package/esm/stdlib/behavior/drag-combo.d.ts +2 -2
  42. package/esm/stdlib/behavior/drag-combo.js +43 -32
  43. package/esm/stdlib/behavior/drag-combo.js.map +1 -1
  44. package/esm/stdlib/behavior/drag-node.d.ts +3 -3
  45. package/esm/stdlib/behavior/drag-node.js +76 -63
  46. package/esm/stdlib/behavior/drag-node.js.map +1 -1
  47. package/esm/stdlib/behavior/index.d.ts +3 -0
  48. package/esm/stdlib/behavior/index.js +3 -0
  49. package/esm/stdlib/behavior/index.js.map +1 -1
  50. package/esm/stdlib/behavior/lasso-select.d.ts +1 -1
  51. package/esm/stdlib/behavior/lasso-select.js +1 -2
  52. package/esm/stdlib/behavior/lasso-select.js.map +1 -1
  53. package/esm/stdlib/behavior/scroll-canvas.d.ts +67 -0
  54. package/esm/stdlib/behavior/scroll-canvas.js +266 -0
  55. package/esm/stdlib/behavior/scroll-canvas.js.map +1 -0
  56. package/esm/stdlib/behavior/shortcuts-call.d.ts +38 -0
  57. package/esm/stdlib/behavior/shortcuts-call.js +80 -0
  58. package/esm/stdlib/behavior/shortcuts-call.js.map +1 -0
  59. package/esm/stdlib/behavior/zoom-canvas.d.ts +2 -1
  60. package/esm/stdlib/behavior/zoom-canvas.js +55 -24
  61. package/esm/stdlib/behavior/zoom-canvas.js.map +1 -1
  62. package/esm/stdlib/data/mapNodeSize.d.ts +2 -2
  63. package/esm/stdlib/data/mapNodeSize.js +2 -2
  64. package/esm/stdlib/data/mapNodeSize.js.map +1 -1
  65. package/esm/stdlib/data/transformV4Data.d.ts +2 -2
  66. package/esm/stdlib/data/transformV4Data.js +2 -2
  67. package/esm/stdlib/data/transformV4Data.js.map +1 -1
  68. package/esm/stdlib/data/validateData.d.ts +2 -2
  69. package/esm/stdlib/data/validateData.js +9 -9
  70. package/esm/stdlib/data/validateData.js.map +1 -1
  71. package/esm/stdlib/index.d.ts +16 -6
  72. package/esm/stdlib/index.js +20 -10
  73. package/esm/stdlib/index.js.map +1 -1
  74. package/esm/stdlib/item/edge/base.d.ts +10 -1
  75. package/esm/stdlib/item/edge/base.js +20 -13
  76. package/esm/stdlib/item/edge/base.js.map +1 -1
  77. package/esm/stdlib/item/edge/line.js +5 -2
  78. package/esm/stdlib/item/edge/line.js.map +1 -1
  79. package/esm/stdlib/item/edge/polyline.d.ts +3 -2
  80. package/esm/stdlib/item/edge/polyline.js +3 -3
  81. package/esm/stdlib/item/edge/polyline.js.map +1 -1
  82. package/esm/stdlib/item/node/base.d.ts +1 -1
  83. package/esm/stdlib/item/node/base.js +18 -26
  84. package/esm/stdlib/item/node/base.js.map +1 -1
  85. package/esm/stdlib/item/node/base3d.d.ts +1 -0
  86. package/esm/stdlib/item/node/base3d.js +1 -0
  87. package/esm/stdlib/item/node/base3d.js.map +1 -1
  88. package/esm/stdlib/item/node/diamond.js +1 -1
  89. package/esm/stdlib/item/node/ellipse.js +2 -2
  90. package/esm/stdlib/item/node/hexagon.js +12 -5
  91. package/esm/stdlib/item/node/hexagon.js.map +1 -1
  92. package/esm/stdlib/item/node/image.d.ts +40 -0
  93. package/esm/stdlib/item/node/image.js +110 -0
  94. package/esm/stdlib/item/node/image.js.map +1 -0
  95. package/esm/stdlib/item/node/index.d.ts +1 -0
  96. package/esm/stdlib/item/node/index.js +1 -0
  97. package/esm/stdlib/item/node/index.js.map +1 -1
  98. package/esm/stdlib/plugin/history/combo-command.js +2 -2
  99. package/esm/stdlib/plugin/history/combo-command.js.map +1 -1
  100. package/esm/stdlib/plugin/history/index.d.ts +10 -10
  101. package/esm/stdlib/plugin/history/index.js +14 -14
  102. package/esm/stdlib/plugin/history/index.js.map +1 -1
  103. package/esm/stdlib/plugin/history/item-data-command.js +25 -16
  104. package/esm/stdlib/plugin/history/item-data-command.js.map +1 -1
  105. package/esm/stdlib/plugin/history/layer-updated-command.js +2 -2
  106. package/esm/stdlib/plugin/history/layer-updated-command.js.map +1 -1
  107. package/esm/stdlib/plugin/history/state-updated-command.js +1 -1
  108. package/esm/stdlib/plugin/history/state-updated-command.js.map +1 -1
  109. package/esm/stdlib/plugin/history/visibility-updated-command.js +2 -2
  110. package/esm/stdlib/plugin/history/visibility-updated-command.js.map +1 -1
  111. package/esm/stdlib/plugin/hull/hullComponent.d.ts +1 -1
  112. package/esm/stdlib/plugin/hull/hullComponent.js +3 -6
  113. package/esm/stdlib/plugin/hull/hullComponent.js.map +1 -1
  114. package/esm/stdlib/plugin/index.d.ts +2 -0
  115. package/esm/stdlib/plugin/index.js +2 -0
  116. package/esm/stdlib/plugin/index.js.map +1 -1
  117. package/esm/stdlib/plugin/legend/index.js +1 -1
  118. package/esm/stdlib/plugin/legend/index.js.map +1 -1
  119. package/esm/stdlib/plugin/map/index.d.ts +118 -0
  120. package/esm/stdlib/plugin/map/index.js +683 -0
  121. package/esm/stdlib/plugin/map/index.js.map +1 -0
  122. package/esm/stdlib/plugin/minimap/index.d.ts +5 -1
  123. package/esm/stdlib/plugin/minimap/index.js +116 -9
  124. package/esm/stdlib/plugin/minimap/index.js.map +1 -1
  125. package/esm/stdlib/plugin/snapline/index.d.ts +167 -0
  126. package/esm/stdlib/plugin/snapline/index.js +1063 -0
  127. package/esm/stdlib/plugin/snapline/index.js.map +1 -0
  128. package/esm/stdlib/plugin/timebar/index.d.ts +98 -0
  129. package/esm/stdlib/plugin/timebar/index.js +303 -0
  130. package/esm/stdlib/plugin/timebar/index.js.map +1 -0
  131. package/esm/stdlib/plugin/toolbar/index.js +1 -1
  132. package/esm/stdlib/plugin/toolbar/index.js.map +1 -1
  133. package/esm/stdlib/plugin/types.d.ts +2 -0
  134. package/esm/stdlib/theme/dark.js +42 -2
  135. package/esm/stdlib/theme/dark.js.map +1 -1
  136. package/esm/stdlib/theme/light.js +4 -4
  137. package/esm/types/common.d.ts +1 -0
  138. package/esm/types/event.d.ts +1 -0
  139. package/esm/types/graph.d.ts +48 -22
  140. package/esm/types/hook.d.ts +22 -2
  141. package/esm/types/item.d.ts +6 -0
  142. package/esm/types/item.js.map +1 -1
  143. package/esm/types/spec.d.ts +19 -3
  144. package/esm/types/view.d.ts +5 -0
  145. package/esm/util/bbox.d.ts +16 -1
  146. package/esm/util/bbox.js +29 -0
  147. package/esm/util/bbox.js.map +1 -1
  148. package/esm/util/canvas.d.ts +2 -2
  149. package/esm/util/canvas.js +5 -11
  150. package/esm/util/canvas.js.map +1 -1
  151. package/esm/util/event.d.ts +3 -1
  152. package/esm/util/event.js +8 -1
  153. package/esm/util/event.js.map +1 -1
  154. package/esm/util/item.d.ts +16 -1
  155. package/esm/util/item.js +31 -8
  156. package/esm/util/item.js.map +1 -1
  157. package/esm/util/layout.d.ts +11 -0
  158. package/esm/util/layout.js +45 -0
  159. package/esm/util/layout.js.map +1 -1
  160. package/esm/util/point.js +9 -2
  161. package/esm/util/point.js.map +1 -1
  162. package/esm/util/router.d.ts +4 -3
  163. package/esm/util/router.js +8 -5
  164. package/esm/util/router.js.map +1 -1
  165. package/esm/util/shape.d.ts +3 -3
  166. package/esm/util/shape.js +8 -12
  167. package/esm/util/shape.js.map +1 -1
  168. package/esm/util/warn.d.ts +14 -0
  169. package/esm/util/warn.js +4 -0
  170. package/esm/util/warn.js.map +1 -0
  171. package/lib/constant/shape.d.ts +4 -1
  172. package/lib/constant/shape.js.map +1 -1
  173. package/lib/index.d.ts +22 -7
  174. package/lib/index.js +4 -2
  175. package/lib/index.js.map +1 -1
  176. package/lib/item/combo.d.ts +1 -1
  177. package/lib/item/combo.js +16 -9
  178. package/lib/item/combo.js.map +1 -1
  179. package/lib/item/edge.d.ts +20 -3
  180. package/lib/item/edge.js +98 -42
  181. package/lib/item/edge.js.map +1 -1
  182. package/lib/item/item.d.ts +3 -2
  183. package/lib/item/item.js +21 -11
  184. package/lib/item/item.js.map +1 -1
  185. package/lib/item/node.d.ts +2 -1
  186. package/lib/item/node.js +32 -16
  187. package/lib/item/node.js.map +1 -1
  188. package/lib/runtime/controller/data.d.ts +7 -10
  189. package/lib/runtime/controller/data.js +125 -281
  190. package/lib/runtime/controller/data.js.map +1 -1
  191. package/lib/runtime/controller/item.d.ts +1 -0
  192. package/lib/runtime/controller/item.js +266 -150
  193. package/lib/runtime/controller/item.js.map +1 -1
  194. package/lib/runtime/graph.d.ts +103 -23
  195. package/lib/runtime/graph.js +460 -88
  196. package/lib/runtime/graph.js.map +1 -1
  197. package/lib/stdlib/behavior/activate-relations.d.ts +9 -9
  198. package/lib/stdlib/behavior/activate-relations.js +8 -8
  199. package/lib/stdlib/behavior/activate-relations.js.map +1 -1
  200. package/lib/stdlib/behavior/brush-select.js +1 -2
  201. package/lib/stdlib/behavior/brush-select.js.map +1 -1
  202. package/lib/stdlib/behavior/click-select.js +1 -1
  203. package/lib/stdlib/behavior/click-select.js.map +1 -1
  204. package/lib/stdlib/behavior/create-edge.d.ts +57 -0
  205. package/lib/stdlib/behavior/create-edge.js +211 -0
  206. package/lib/stdlib/behavior/create-edge.js.map +1 -0
  207. package/lib/stdlib/behavior/drag-canvas.d.ts +2 -1
  208. package/lib/stdlib/behavior/drag-canvas.js +59 -28
  209. package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
  210. package/lib/stdlib/behavior/drag-combo.d.ts +2 -2
  211. package/lib/stdlib/behavior/drag-combo.js +43 -32
  212. package/lib/stdlib/behavior/drag-combo.js.map +1 -1
  213. package/lib/stdlib/behavior/drag-node.d.ts +3 -3
  214. package/lib/stdlib/behavior/drag-node.js +76 -63
  215. package/lib/stdlib/behavior/drag-node.js.map +1 -1
  216. package/lib/stdlib/behavior/index.d.ts +3 -0
  217. package/lib/stdlib/behavior/index.js +3 -0
  218. package/lib/stdlib/behavior/index.js.map +1 -1
  219. package/lib/stdlib/behavior/lasso-select.d.ts +1 -1
  220. package/lib/stdlib/behavior/lasso-select.js +1 -2
  221. package/lib/stdlib/behavior/lasso-select.js.map +1 -1
  222. package/lib/stdlib/behavior/scroll-canvas.d.ts +67 -0
  223. package/lib/stdlib/behavior/scroll-canvas.js +270 -0
  224. package/lib/stdlib/behavior/scroll-canvas.js.map +1 -0
  225. package/lib/stdlib/behavior/shortcuts-call.d.ts +38 -0
  226. package/lib/stdlib/behavior/shortcuts-call.js +84 -0
  227. package/lib/stdlib/behavior/shortcuts-call.js.map +1 -0
  228. package/lib/stdlib/behavior/zoom-canvas.d.ts +2 -1
  229. package/lib/stdlib/behavior/zoom-canvas.js +55 -24
  230. package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
  231. package/lib/stdlib/data/mapNodeSize.d.ts +2 -2
  232. package/lib/stdlib/data/mapNodeSize.js +2 -2
  233. package/lib/stdlib/data/mapNodeSize.js.map +1 -1
  234. package/lib/stdlib/data/transformV4Data.d.ts +2 -2
  235. package/lib/stdlib/data/transformV4Data.js +2 -2
  236. package/lib/stdlib/data/transformV4Data.js.map +1 -1
  237. package/lib/stdlib/data/validateData.d.ts +2 -2
  238. package/lib/stdlib/data/validateData.js +9 -9
  239. package/lib/stdlib/data/validateData.js.map +1 -1
  240. package/lib/stdlib/index.d.ts +16 -6
  241. package/lib/stdlib/index.js +20 -10
  242. package/lib/stdlib/index.js.map +1 -1
  243. package/lib/stdlib/item/edge/base.d.ts +10 -1
  244. package/lib/stdlib/item/edge/base.js +20 -13
  245. package/lib/stdlib/item/edge/base.js.map +1 -1
  246. package/lib/stdlib/item/edge/line.js +5 -2
  247. package/lib/stdlib/item/edge/line.js.map +1 -1
  248. package/lib/stdlib/item/edge/polyline.d.ts +3 -2
  249. package/lib/stdlib/item/edge/polyline.js +3 -3
  250. package/lib/stdlib/item/edge/polyline.js.map +1 -1
  251. package/lib/stdlib/item/node/base.d.ts +1 -1
  252. package/lib/stdlib/item/node/base.js +18 -26
  253. package/lib/stdlib/item/node/base.js.map +1 -1
  254. package/lib/stdlib/item/node/base3d.d.ts +1 -0
  255. package/lib/stdlib/item/node/base3d.js +1 -0
  256. package/lib/stdlib/item/node/base3d.js.map +1 -1
  257. package/lib/stdlib/item/node/diamond.js +1 -1
  258. package/lib/stdlib/item/node/ellipse.js +2 -2
  259. package/lib/stdlib/item/node/hexagon.js +12 -5
  260. package/lib/stdlib/item/node/hexagon.js.map +1 -1
  261. package/lib/stdlib/item/node/image.d.ts +40 -0
  262. package/lib/stdlib/item/node/image.js +114 -0
  263. package/lib/stdlib/item/node/image.js.map +1 -0
  264. package/lib/stdlib/item/node/index.d.ts +1 -0
  265. package/lib/stdlib/item/node/index.js +1 -0
  266. package/lib/stdlib/item/node/index.js.map +1 -1
  267. package/lib/stdlib/plugin/history/combo-command.js +2 -2
  268. package/lib/stdlib/plugin/history/combo-command.js.map +1 -1
  269. package/lib/stdlib/plugin/history/index.d.ts +10 -10
  270. package/lib/stdlib/plugin/history/index.js +14 -14
  271. package/lib/stdlib/plugin/history/index.js.map +1 -1
  272. package/lib/stdlib/plugin/history/item-data-command.js +25 -16
  273. package/lib/stdlib/plugin/history/item-data-command.js.map +1 -1
  274. package/lib/stdlib/plugin/history/layer-updated-command.js +2 -2
  275. package/lib/stdlib/plugin/history/layer-updated-command.js.map +1 -1
  276. package/lib/stdlib/plugin/history/state-updated-command.js +1 -1
  277. package/lib/stdlib/plugin/history/state-updated-command.js.map +1 -1
  278. package/lib/stdlib/plugin/history/visibility-updated-command.js +2 -2
  279. package/lib/stdlib/plugin/history/visibility-updated-command.js.map +1 -1
  280. package/lib/stdlib/plugin/hull/hullComponent.d.ts +1 -1
  281. package/lib/stdlib/plugin/hull/hullComponent.js +3 -6
  282. package/lib/stdlib/plugin/hull/hullComponent.js.map +1 -1
  283. package/lib/stdlib/plugin/index.d.ts +2 -0
  284. package/lib/stdlib/plugin/index.js +2 -0
  285. package/lib/stdlib/plugin/index.js.map +1 -1
  286. package/lib/stdlib/plugin/legend/index.js +1 -1
  287. package/lib/stdlib/plugin/legend/index.js.map +1 -1
  288. package/lib/stdlib/plugin/map/index.d.ts +118 -0
  289. package/lib/stdlib/plugin/map/index.js +687 -0
  290. package/lib/stdlib/plugin/map/index.js.map +1 -0
  291. package/lib/stdlib/plugin/minimap/index.d.ts +5 -1
  292. package/lib/stdlib/plugin/minimap/index.js +116 -9
  293. package/lib/stdlib/plugin/minimap/index.js.map +1 -1
  294. package/lib/stdlib/plugin/snapline/index.d.ts +167 -0
  295. package/lib/stdlib/plugin/snapline/index.js +1067 -0
  296. package/lib/stdlib/plugin/snapline/index.js.map +1 -0
  297. package/lib/stdlib/plugin/timebar/index.d.ts +98 -0
  298. package/lib/stdlib/plugin/timebar/index.js +307 -0
  299. package/lib/stdlib/plugin/timebar/index.js.map +1 -0
  300. package/lib/stdlib/plugin/toolbar/index.js +1 -1
  301. package/lib/stdlib/plugin/toolbar/index.js.map +1 -1
  302. package/lib/stdlib/plugin/types.d.ts +2 -0
  303. package/lib/stdlib/theme/dark.js +42 -2
  304. package/lib/stdlib/theme/dark.js.map +1 -1
  305. package/lib/stdlib/theme/light.js +4 -4
  306. package/lib/types/common.d.ts +1 -0
  307. package/lib/types/event.d.ts +1 -0
  308. package/lib/types/graph.d.ts +48 -22
  309. package/lib/types/hook.d.ts +22 -2
  310. package/lib/types/item.d.ts +6 -0
  311. package/lib/types/item.js.map +1 -1
  312. package/lib/types/spec.d.ts +19 -3
  313. package/lib/types/view.d.ts +5 -0
  314. package/lib/util/bbox.d.ts +16 -1
  315. package/lib/util/bbox.js +32 -1
  316. package/lib/util/bbox.js.map +1 -1
  317. package/lib/util/canvas.d.ts +2 -2
  318. package/lib/util/canvas.js +5 -11
  319. package/lib/util/canvas.js.map +1 -1
  320. package/lib/util/event.d.ts +3 -1
  321. package/lib/util/event.js +8 -1
  322. package/lib/util/event.js.map +1 -1
  323. package/lib/util/item.d.ts +16 -1
  324. package/lib/util/item.js +33 -9
  325. package/lib/util/item.js.map +1 -1
  326. package/lib/util/layout.d.ts +11 -0
  327. package/lib/util/layout.js +47 -1
  328. package/lib/util/layout.js.map +1 -1
  329. package/lib/util/point.js +9 -2
  330. package/lib/util/point.js.map +1 -1
  331. package/lib/util/router.d.ts +4 -3
  332. package/lib/util/router.js +8 -5
  333. package/lib/util/router.js.map +1 -1
  334. package/lib/util/shape.d.ts +3 -3
  335. package/lib/util/shape.js +8 -12
  336. package/lib/util/shape.js.map +1 -1
  337. package/lib/util/warn.d.ts +14 -0
  338. package/lib/util/warn.js +8 -0
  339. package/lib/util/warn.js.map +1 -0
  340. package/package.json +10 -10
  341. package/src/constant/shape.ts +2 -1
  342. package/src/index.ts +4 -2
  343. package/src/item/combo.ts +14 -9
  344. package/src/item/edge.ts +131 -57
  345. package/src/item/item.ts +24 -15
  346. package/src/item/node.ts +37 -24
  347. package/src/runtime/controller/data.ts +140 -339
  348. package/src/runtime/controller/item.ts +236 -72
  349. package/src/runtime/graph.ts +592 -96
  350. package/src/stdlib/behavior/activate-relations.ts +8 -8
  351. package/src/stdlib/behavior/brush-select.ts +4 -2
  352. package/src/stdlib/behavior/click-select.ts +1 -1
  353. package/src/stdlib/behavior/create-edge.ts +296 -0
  354. package/src/stdlib/behavior/drag-canvas.ts +78 -29
  355. package/src/stdlib/behavior/drag-combo.ts +10 -10
  356. package/src/stdlib/behavior/drag-node.ts +18 -18
  357. package/src/stdlib/behavior/index.ts +3 -0
  358. package/src/stdlib/behavior/lasso-select.ts +5 -3
  359. package/src/stdlib/behavior/scroll-canvas.ts +348 -0
  360. package/src/stdlib/behavior/shortcuts-call.ts +120 -0
  361. package/src/stdlib/behavior/zoom-canvas.ts +72 -25
  362. package/src/stdlib/data/mapNodeSize.ts +2 -2
  363. package/src/stdlib/data/transformV4Data.ts +2 -2
  364. package/src/stdlib/data/validateData.ts +9 -9
  365. package/src/stdlib/index.ts +33 -9
  366. package/src/stdlib/item/edge/base.ts +26 -13
  367. package/src/stdlib/item/edge/line.ts +8 -2
  368. package/src/stdlib/item/edge/polyline.ts +7 -5
  369. package/src/stdlib/item/node/base.ts +24 -29
  370. package/src/stdlib/item/node/base3d.ts +1 -0
  371. package/src/stdlib/item/node/diamond.ts +1 -1
  372. package/src/stdlib/item/node/ellipse.ts +2 -2
  373. package/src/stdlib/item/node/hexagon.ts +14 -6
  374. package/src/stdlib/item/node/image.ts +190 -0
  375. package/src/stdlib/item/node/index.ts +1 -0
  376. package/src/stdlib/plugin/history/combo-command.ts +2 -2
  377. package/src/stdlib/plugin/history/index.ts +14 -14
  378. package/src/stdlib/plugin/history/item-data-command.ts +35 -17
  379. package/src/stdlib/plugin/history/layer-updated-command.ts +2 -2
  380. package/src/stdlib/plugin/history/state-updated-command.ts +1 -1
  381. package/src/stdlib/plugin/history/visibility-updated-command.ts +2 -2
  382. package/src/stdlib/plugin/hull/hullComponent.ts +8 -5
  383. package/src/stdlib/plugin/index.ts +2 -0
  384. package/src/stdlib/plugin/legend/index.ts +1 -1
  385. package/src/stdlib/plugin/map/index.ts +808 -0
  386. package/src/stdlib/plugin/minimap/index.ts +120 -10
  387. package/src/stdlib/plugin/snapline/index.ts +1297 -0
  388. package/src/stdlib/plugin/timebar/index.ts +473 -0
  389. package/src/stdlib/plugin/toolbar/index.ts +1 -1
  390. package/src/stdlib/plugin/types.ts +2 -0
  391. package/src/stdlib/theme/dark.ts +66 -2
  392. package/src/stdlib/theme/light.ts +4 -4
  393. package/src/types/common.ts +1 -0
  394. package/src/types/event.ts +1 -0
  395. package/src/types/graph.ts +59 -25
  396. package/src/types/hook.ts +22 -2
  397. package/src/types/item.ts +10 -0
  398. package/src/types/spec.ts +22 -3
  399. package/src/types/view.ts +8 -3
  400. package/src/util/bbox.ts +38 -1
  401. package/src/util/canvas.ts +5 -5
  402. package/src/util/event.ts +14 -1
  403. package/src/util/item.ts +65 -28
  404. package/src/util/layout.ts +45 -0
  405. package/src/util/point.ts +8 -3
  406. package/src/util/router.ts +15 -6
  407. package/src/util/shape.ts +16 -14
  408. package/src/util/warn.ts +20 -0
  409. package/src/api-doc/readme.md +0 -59
@@ -19,9 +19,12 @@ var __rest = (this && this.__rest) || function (s, e) {
19
19
  return t;
20
20
  };
21
21
  import EventEmitter from '@antv/event-emitter';
22
+ import { Rect, } from '@antv/g';
22
23
  import { clone, groupBy, isArray, isEmpty, isEqual, isNil, isNumber, isObject, isString, map, } from '@antv/util';
24
+ import { createDom } from '@antv/dom-util';
23
25
  import { changeRenderer, createCanvas } from '../util/canvas';
24
26
  import { formatPadding } from '../util/shape';
27
+ import { getLayoutBounds } from '../util/layout';
25
28
  import { DataController, ExtensionController, InteractionController, ItemController, LayoutController, ThemeController, ViewportController, } from './controller';
26
29
  import { PluginController } from './controller/plugin';
27
30
  import Hook from './hooks';
@@ -39,17 +42,17 @@ export default class Graph extends EventEmitter {
39
42
  * Execute a callback without allowing any stacking operations.
40
43
  * @param callback
41
44
  */
42
- this.executeWithoutStacking = (callback) => {
45
+ this.executeWithNoStack = (callback) => {
43
46
  const history = this.getHistoryPlugin();
44
- history === null || history === void 0 ? void 0 : history.pauseStacking();
47
+ history === null || history === void 0 ? void 0 : history.pauseStack();
45
48
  try {
46
49
  callback();
47
50
  }
48
51
  finally {
49
- history === null || history === void 0 ? void 0 : history.resumeStacking();
52
+ history === null || history === void 0 ? void 0 : history.resumeStack();
50
53
  }
51
54
  };
52
- this.specification = Object.assign({}, this.defaultSpecification, spec);
55
+ this.specification = Object.assign({}, this.defaultSpecification, this.formatSpecification(spec));
53
56
  this.initHooks();
54
57
  this.initCanvas();
55
58
  this.initControllers();
@@ -193,16 +196,23 @@ export default class Graph extends EventEmitter {
193
196
  }),
194
197
  transientupdate: new Hook({ name: 'transientupdate' }),
195
198
  pluginchange: new Hook({ name: 'pluginchange' }),
196
- themechange: new Hook({ name: 'init' }),
199
+ themechange: new Hook({ name: 'themechange' }),
200
+ mapperchange: new Hook({ name: 'mapperchange' }),
197
201
  treecollapseexpand: new Hook({ name: 'treecollapseexpand' }),
198
202
  destroy: new Hook({ name: 'destroy' }),
199
203
  };
200
204
  }
205
+ formatSpecification(spec) {
206
+ var _a;
207
+ return Object.assign(Object.assign(Object.assign({}, this.specification), spec), { optimize: Object.assign(Object.assign({ tileBehavior: 2000, tileBehaviorSize: 1000, tileFirstRender: 10000, tileFirstRenderSize: 1000 }, (_a = this.specification) === null || _a === void 0 ? void 0 : _a.optimize), spec.optimize) });
208
+ }
201
209
  /**
202
210
  * Update the specs(configurations).
203
211
  */
204
212
  updateSpecification(spec) {
205
- return Object.assign(this.specification, spec);
213
+ const newSpec = Object.assign(this.specification, this.formatSpecification(spec));
214
+ // TODO: update something
215
+ return newSpec;
206
216
  }
207
217
  /**
208
218
  * Update the theme specs (configurations).
@@ -223,6 +233,28 @@ export default class Graph extends EventEmitter {
223
233
  theme: this.themeController.specification,
224
234
  });
225
235
  }
236
+ /**
237
+ * Update the item display mapper for a specific item type.
238
+ * @param {ITEM_TYPE} type - The type of item (node, edge, or combo).
239
+ * @param {NodeMapper | EdgeMapper | ComboMapper} mapper - The mapper to be updated.
240
+ * */
241
+ updateMapper(type, mapper) {
242
+ switch (type) {
243
+ case 'node':
244
+ this.specification.node = mapper;
245
+ break;
246
+ case 'edge':
247
+ this.specification.edge = mapper;
248
+ break;
249
+ case 'combo':
250
+ this.specification.combo = mapper;
251
+ break;
252
+ }
253
+ this.hooks.mapperchange.emit({
254
+ type,
255
+ mapper,
256
+ });
257
+ }
226
258
  /**
227
259
  * Get the copy of specs(configurations).
228
260
  * @returns graph specs
@@ -239,30 +271,39 @@ export default class Graph extends EventEmitter {
239
271
  */
240
272
  read(data) {
241
273
  return __awaiter(this, void 0, void 0, function* () {
274
+ const { tileFirstRender, tileFirstRenderSize } = this.specification.optimize || {};
242
275
  this.hooks.datachange.emit({ data, type: 'replace' });
243
276
  const emitRender = () => __awaiter(this, void 0, void 0, function* () {
244
- this.hooks.render.emit({
277
+ yield this.hooks.render.emitLinearAsync({
245
278
  graphCore: this.dataController.graphCore,
246
279
  theme: this.themeController.specification,
247
280
  transientCanvas: this.transientCanvas,
281
+ tileOptimize: {
282
+ tileFirstRender,
283
+ tileFirstRenderSize,
284
+ },
248
285
  });
249
286
  this.emit('afterrender');
250
287
  this.once('afterlayout', () => __awaiter(this, void 0, void 0, function* () {
251
288
  const { autoFit } = this.specification;
252
289
  if (autoFit) {
253
290
  if (autoFit === 'view') {
254
- yield this.fitView();
291
+ yield this.fitView({ rules: { boundsType: 'layout' } });
255
292
  }
256
293
  else if (autoFit === 'center') {
257
- yield this.fitCenter();
294
+ yield this.fitCenter('layout');
258
295
  }
259
296
  else {
260
297
  const { type, effectTiming } = autoFit, others = __rest(autoFit, ["type", "effectTiming"]);
261
298
  if (type === 'view') {
262
- yield this.fitView(others, effectTiming);
299
+ const { padding, rules } = others;
300
+ yield this.fitView({
301
+ padding,
302
+ rules: Object.assign(Object.assign({}, rules), { boundsType: 'layout' }),
303
+ }, effectTiming);
263
304
  }
264
305
  else if (type === 'center') {
265
- yield this.fitCenter(effectTiming);
306
+ yield this.fitCenter('layout', effectTiming);
266
307
  }
267
308
  else if (type === 'position') {
268
309
  // TODO: align
@@ -291,11 +332,16 @@ export default class Graph extends EventEmitter {
291
332
  */
292
333
  changeData(data, type = 'mergeReplace') {
293
334
  return __awaiter(this, void 0, void 0, function* () {
335
+ const { tileFirstRender, tileFirstRenderSize } = this.specification.optimize || {};
294
336
  this.hooks.datachange.emit({ data, type });
295
337
  this.hooks.render.emit({
296
338
  graphCore: this.dataController.graphCore,
297
339
  theme: this.themeController.specification,
298
340
  transientCanvas: this.transientCanvas,
341
+ tileOptimize: {
342
+ tileFirstRender,
343
+ tileFirstRenderSize,
344
+ },
299
345
  });
300
346
  this.emit('afterrender');
301
347
  yield this.layout();
@@ -306,11 +352,11 @@ export default class Graph extends EventEmitter {
306
352
  * @returns
307
353
  */
308
354
  clear() {
309
- this.startBatch();
355
+ this.startHistoryBatch();
310
356
  this.removeData('edge', this.getAllEdgesData().map((edge) => edge.id));
311
357
  this.removeData('node', this.getAllNodesData().map((node) => node.id));
312
358
  this.removeData('combo', this.getAllCombosData().map((combo) => combo.id));
313
- this.stopBatch();
359
+ this.stopHistoryBatch();
314
360
  }
315
361
  getViewportCenter() {
316
362
  const { width, height } = this.canvas.getConfig();
@@ -318,9 +364,11 @@ export default class Graph extends EventEmitter {
318
364
  }
319
365
  transform(options, effectTiming) {
320
366
  return __awaiter(this, void 0, void 0, function* () {
367
+ const { tileLodSize } = this.specification.optimize || {};
321
368
  yield this.hooks.viewportchange.emitLinearAsync({
322
369
  transform: options,
323
370
  effectTiming,
371
+ tileLodSize,
324
372
  });
325
373
  this.emit('viewportchange', options);
326
374
  });
@@ -428,9 +476,12 @@ export default class Graph extends EventEmitter {
428
476
  const [top, right, bottom, left] = padding
429
477
  ? formatPadding(padding)
430
478
  : [0, 0, 0, 0];
431
- const { direction = 'both', ratioRule = 'min' } = rules || {};
432
- // Get the bounds of the whole graph.
433
- const { center: [graphCenterX, graphCenterY], halfExtents, } = this.canvas.document.documentElement.getBounds();
479
+ const { direction = 'both', ratioRule = 'min', boundsType = 'render', } = rules || {};
480
+ const { center: [graphCenterX, graphCenterY], halfExtents, } = boundsType === 'render'
481
+ ? // Get the bounds of the whole graph content.
482
+ this.canvas.document.documentElement.getBounds()
483
+ : // Get the bounds of the nodes positions while the graph content is not ready.
484
+ getLayoutBounds(this);
434
485
  const origin = this.canvas.canvas2Viewport({
435
486
  x: graphCenterX,
436
487
  y: graphCenterY,
@@ -475,10 +526,13 @@ export default class Graph extends EventEmitter {
475
526
  * Fit the graph center to the view center.
476
527
  * @param effectTiming animation configurations
477
528
  */
478
- fitCenter(effectTiming) {
529
+ fitCenter(boundsType = 'render', effectTiming) {
479
530
  return __awaiter(this, void 0, void 0, function* () {
480
- // Get the bounds of the whole graph.
481
- const { center: [graphCenterX, graphCenterY], } = this.canvas.document.documentElement.getBounds();
531
+ const { center: [graphCenterX, graphCenterY], } = boundsType === 'render'
532
+ ? // Get the bounds of the whole graph content.
533
+ this.canvas.document.documentElement.getBounds()
534
+ : // Get the bounds of the nodes positions while the graph content is not ready.
535
+ getLayoutBounds(this);
482
536
  yield this.translateTo(this.canvas.canvas2Viewport({ x: graphCenterX, y: graphCenterY }), effectTiming);
483
537
  });
484
538
  }
@@ -539,6 +593,25 @@ export default class Graph extends EventEmitter {
539
593
  this.specification.height = size[1];
540
594
  this.canvas.resize(size[0], size[1]);
541
595
  }
596
+ getCanvasRange() {
597
+ const [width, height] = this.getSize();
598
+ const leftTop = this.getCanvasByViewport({ x: 0, y: 0 });
599
+ const rightBottom = this.getCanvasByViewport({ x: width, y: height });
600
+ return {
601
+ min: [leftTop.x, leftTop.y, leftTop.z],
602
+ max: [rightBottom.x, rightBottom.y, rightBottom.z],
603
+ center: [
604
+ (leftTop.x + rightBottom.x) / 2,
605
+ (leftTop.y + rightBottom.y) / 2,
606
+ (leftTop.z + rightBottom.z) / 2,
607
+ ],
608
+ halfExtents: [
609
+ (rightBottom.x - leftTop.x) / 2,
610
+ (rightBottom.y - leftTop.y) / 2,
611
+ (rightBottom.z - leftTop.z) / 2,
612
+ ],
613
+ };
614
+ }
542
615
  /**
543
616
  * Get the rendering coordinate according to the canvas dom (viewport) coordinate.
544
617
  * @param Point rendering coordinate
@@ -717,19 +790,21 @@ export default class Graph extends EventEmitter {
717
790
  if (!event.changes.length)
718
791
  return;
719
792
  const changes = event.changes;
720
- this.hooks.itemchange.emit({
721
- type: itemType,
722
- changes: graphCore.reduceChanges(event.changes),
723
- graphCore,
724
- theme: specification,
725
- });
726
- this.emit('afteritemchange', {
793
+ const timingParameters = {
727
794
  type: itemType,
728
795
  action: 'add',
729
796
  models,
730
797
  apiName: 'addData',
731
798
  changes,
799
+ };
800
+ this.emit('beforeitemchange', timingParameters);
801
+ this.hooks.itemchange.emit({
802
+ type: itemType,
803
+ changes: graphCore.reduceChanges(event.changes),
804
+ graphCore,
805
+ theme: specification,
732
806
  });
807
+ this.emit('afteritemchange', timingParameters);
733
808
  });
734
809
  const modelArr = isArray(models) ? models : [models];
735
810
  const data = { nodes: [], edges: [], combos: [] };
@@ -750,27 +825,38 @@ export default class Graph extends EventEmitter {
750
825
  removeData(itemType, ids) {
751
826
  const idArr = isArray(ids) ? ids : [ids];
752
827
  const data = { nodes: [], edges: [], combos: [] };
753
- const { userGraphCore, graphCore } = this.dataController;
828
+ const { graphCore } = this.dataController;
754
829
  const { specification } = this.themeController;
755
- const getItem = itemType === 'edge' ? userGraphCore.getEdge : userGraphCore.getNode;
756
- data[`${itemType}s`] = idArr.map((id) => getItem.bind(userGraphCore)(id));
830
+ const getItem = itemType === 'edge' ? graphCore.getEdge : graphCore.getNode;
831
+ const hasItem = itemType === 'edge' ? graphCore.hasEdge : graphCore.hasNode;
832
+ data[`${itemType}s`] = idArr
833
+ .map((id) => {
834
+ if (!hasItem.bind(graphCore)(id)) {
835
+ console.warn(`The ${itemType} data with id ${id} does not exist. It will be ignored`);
836
+ return;
837
+ }
838
+ return getItem.bind(graphCore)(id);
839
+ })
840
+ .filter(Boolean);
757
841
  graphCore.once('changed', (event) => {
758
842
  if (!event.changes.length)
759
843
  return;
760
844
  const changes = event.changes;
761
- this.hooks.itemchange.emit({
762
- type: itemType,
763
- changes: event.changes,
764
- graphCore,
765
- theme: specification,
766
- });
767
- this.emit('afteritemchange', {
845
+ const timingParameters = {
768
846
  type: itemType,
769
847
  action: 'remove',
770
848
  ids: idArr,
771
849
  apiName: 'removeData',
772
850
  changes,
851
+ };
852
+ this.emit('beforeitemchange', timingParameters);
853
+ this.hooks.itemchange.emit({
854
+ type: itemType,
855
+ changes: event.changes,
856
+ graphCore,
857
+ theme: specification,
773
858
  });
859
+ this.emit('afteritemchange', timingParameters);
774
860
  });
775
861
  this.hooks.datachange.emit({
776
862
  data,
@@ -838,19 +924,21 @@ export default class Graph extends EventEmitter {
838
924
  const { specification } = this.themeController;
839
925
  graphCore.once('changed', (event) => {
840
926
  const changes = this.extendChanges(clone(event.changes));
841
- this.hooks.itemchange.emit({
842
- type: itemType,
843
- changes: event.changes,
844
- graphCore,
845
- theme: specification,
846
- });
847
- this.emit('afteritemchange', {
927
+ const timingParameters = {
848
928
  type: itemType,
849
929
  action: 'update',
850
930
  models,
851
931
  apiName: 'updateData',
852
932
  changes,
933
+ };
934
+ this.emit('beforeitemchange', timingParameters);
935
+ this.hooks.itemchange.emit({
936
+ type: itemType,
937
+ changes: event.changes,
938
+ graphCore,
939
+ theme: specification,
853
940
  });
941
+ this.emit('afteritemchange', timingParameters);
854
942
  });
855
943
  this.hooks.datachange.emit({
856
944
  data,
@@ -897,6 +985,15 @@ export default class Graph extends EventEmitter {
897
985
  if (!event.changes.length)
898
986
  return;
899
987
  const changes = event.changes.filter((change) => !isEqual(change.newValue, change.oldValue));
988
+ const timingParameters = {
989
+ type,
990
+ action: 'updatePosition',
991
+ upsertAncestors,
992
+ models,
993
+ apiName: 'updatePosition',
994
+ changes,
995
+ };
996
+ this.emit('beforeitemchange', timingParameters);
900
997
  this.hooks.itemchange.emit({
901
998
  type,
902
999
  changes: event.changes,
@@ -907,14 +1004,7 @@ export default class Graph extends EventEmitter {
907
1004
  animate: !disableAnimate,
908
1005
  callback,
909
1006
  });
910
- this.emit('afteritemchange', {
911
- type,
912
- action: 'updatePosition',
913
- upsertAncestors,
914
- models,
915
- apiName: 'updatePosition',
916
- changes,
917
- });
1007
+ this.emit('afteritemchange', timingParameters);
918
1008
  });
919
1009
  this.hooks.datachange.emit({
920
1010
  data: {
@@ -974,7 +1064,7 @@ export default class Graph extends EventEmitter {
974
1064
  * @returns
975
1065
  * @group Item
976
1066
  */
977
- hideItem(ids, disableAnimate = false) {
1067
+ hideItem(ids, disableAnimate = false, keepKeyShape = false) {
978
1068
  const idArr = isArray(ids) ? ids : [ids];
979
1069
  if (isEmpty(idArr))
980
1070
  return;
@@ -987,6 +1077,7 @@ export default class Graph extends EventEmitter {
987
1077
  value: false,
988
1078
  graphCore: this.dataController.graphCore,
989
1079
  animate: !disableAnimate,
1080
+ keepKeyShape,
990
1081
  });
991
1082
  this.emit('afteritemvisibilitychange', {
992
1083
  ids,
@@ -994,6 +1085,7 @@ export default class Graph extends EventEmitter {
994
1085
  animate: !disableAnimate,
995
1086
  action: 'updateVisibility',
996
1087
  apiName: 'hideItem',
1088
+ keepKeyShape,
997
1089
  changes,
998
1090
  });
999
1091
  }
@@ -1161,19 +1253,21 @@ export default class Graph extends EventEmitter {
1161
1253
  if (!event.changes.length)
1162
1254
  return;
1163
1255
  const changes = event.changes;
1164
- this.hooks.itemchange.emit({
1165
- type: 'combo',
1166
- changes: graphCore.reduceChanges(event.changes),
1167
- graphCore,
1168
- theme: specification,
1169
- });
1170
- this.emit('afteritemchange', {
1256
+ const timingParameters = {
1171
1257
  type: 'combo',
1172
1258
  action: 'add',
1173
1259
  models: [model],
1174
1260
  apiName: 'addCombo',
1175
1261
  changes,
1262
+ };
1263
+ this.emit('beforeitemchange', timingParameters);
1264
+ this.hooks.itemchange.emit({
1265
+ type: 'combo',
1266
+ changes: graphCore.reduceChanges(event.changes),
1267
+ graphCore,
1268
+ theme: specification,
1176
1269
  });
1270
+ this.emit('afteritemchange', timingParameters);
1177
1271
  });
1178
1272
  const data = {
1179
1273
  nodes: [],
@@ -1195,7 +1289,7 @@ export default class Graph extends EventEmitter {
1195
1289
  */
1196
1290
  collapseCombo(comboIds) {
1197
1291
  const ids = isArray(comboIds) ? comboIds : [comboIds];
1198
- this.executeWithoutStacking(() => {
1292
+ this.executeWithNoStack(() => {
1199
1293
  this.updateData('combo', ids.map((id) => ({ id, data: { collapsed: true } })));
1200
1294
  });
1201
1295
  this.emit('aftercollapsecombo', {
@@ -1212,7 +1306,7 @@ export default class Graph extends EventEmitter {
1212
1306
  */
1213
1307
  expandCombo(comboIds) {
1214
1308
  const ids = isArray(comboIds) ? comboIds : [comboIds];
1215
- this.executeWithoutStacking(() => {
1309
+ this.executeWithNoStack(() => {
1216
1310
  this.updateData('combo', ids.map((id) => ({ id, data: { collapsed: false } })));
1217
1311
  });
1218
1312
  this.emit('afterexpandcombo', {
@@ -1237,16 +1331,7 @@ export default class Graph extends EventEmitter {
1237
1331
  if (!event.changes.length)
1238
1332
  return;
1239
1333
  const changes = this.extendChanges(clone(event.changes));
1240
- this.hooks.itemchange.emit({
1241
- type: 'combo',
1242
- changes: event.changes,
1243
- graphCore,
1244
- theme: specification,
1245
- upsertAncestors,
1246
- action: 'updatePosition',
1247
- callback,
1248
- });
1249
- this.emit('afteritemchange', {
1334
+ const timingParameters = {
1250
1335
  type: 'combo',
1251
1336
  ids: idArr,
1252
1337
  dx,
@@ -1255,7 +1340,18 @@ export default class Graph extends EventEmitter {
1255
1340
  upsertAncestors,
1256
1341
  apiName: 'moveCombo',
1257
1342
  changes,
1343
+ };
1344
+ this.emit('beforeitemchange', timingParameters);
1345
+ this.hooks.itemchange.emit({
1346
+ type: 'combo',
1347
+ changes: event.changes,
1348
+ graphCore,
1349
+ theme: specification,
1350
+ upsertAncestors,
1351
+ action: 'updatePosition',
1352
+ callback,
1258
1353
  });
1354
+ this.emit('afteritemchange', timingParameters);
1259
1355
  });
1260
1356
  this.hooks.datachange.emit({
1261
1357
  data: {
@@ -1340,6 +1436,14 @@ export default class Graph extends EventEmitter {
1340
1436
  getMode() {
1341
1437
  return this.interactionController.getMode();
1342
1438
  }
1439
+ /**
1440
+ * Set the cursor. But the cursor in item's style has higher priority.
1441
+ * @param cursor
1442
+ */
1443
+ setCursor(cursor) {
1444
+ this.canvas.setCursor(cursor);
1445
+ this.transientCanvas.setCursor(cursor);
1446
+ }
1343
1447
  /**
1344
1448
  * Add behavior(s) to mode(s).
1345
1449
  * @param behaviors behavior names or configs
@@ -1510,6 +1614,274 @@ export default class Graph extends EventEmitter {
1510
1614
  });
1511
1615
  return this.itemController.getTransient(String(id));
1512
1616
  }
1617
+ // ===== download operations =====
1618
+ /**
1619
+ * Asynchronously generates a Data URL representation of the canvas content, including
1620
+ * background, main content, and transient canvas.
1621
+ * @param The type of the Data URL (e.g., 'image/png', 'image/jpeg').
1622
+ * @returns A Promise that resolves to the Data URL string.
1623
+ */
1624
+ toDataURL(type) {
1625
+ return __awaiter(this, void 0, void 0, function* () {
1626
+ const backgroundCanvas = this.backgroundCanvas;
1627
+ const canvas = this.canvas;
1628
+ const transientCanvas = this.transientCanvas;
1629
+ const rendererType = this.rendererType;
1630
+ const pixelRatio = typeof window !== 'undefined' ? window.devicePixelRatio : 1;
1631
+ const width = this.getSize()[0];
1632
+ const height = this.getSize()[1];
1633
+ const vContainerDOM = createDom('<div id="virtual-image"></div>');
1634
+ const vCanvas = createCanvas(rendererType, vContainerDOM, width, height, pixelRatio);
1635
+ const vCanvasContextService = vCanvas.getContextService();
1636
+ let bgRect;
1637
+ if (rendererType !== 'svg') {
1638
+ bgRect = new Rect({
1639
+ style: {
1640
+ x: 0,
1641
+ y: 0,
1642
+ z: -1,
1643
+ width: vCanvasContextService.getDomElement().width,
1644
+ height: vCanvasContextService.getDomElement().height,
1645
+ //@ts-ignore
1646
+ fill: backgroundCanvas.getContextService().getDomElement().style['background-color'],
1647
+ },
1648
+ });
1649
+ vCanvas.appendChild(bgRect);
1650
+ }
1651
+ const backgroundClonedGroup = backgroundCanvas.getRoot().cloneNode(true);
1652
+ const clonedGroup = canvas.getRoot().cloneNode(true);
1653
+ const transientClonedGroup = transientCanvas.getRoot().cloneNode(true);
1654
+ vCanvas.appendChild(backgroundClonedGroup);
1655
+ vCanvas.appendChild(clonedGroup);
1656
+ vCanvas.appendChild(transientClonedGroup);
1657
+ vCanvas.render();
1658
+ if (!type)
1659
+ type = 'image/png';
1660
+ let dataURL = '';
1661
+ yield vCanvasContextService.toDataURL({ type }).then((url) => {
1662
+ dataURL = url;
1663
+ });
1664
+ return dataURL;
1665
+ });
1666
+ }
1667
+ /**
1668
+ * Asynchronously generates a Data URL representation of the full canvas content,
1669
+ * including background, main content, and transient canvas, with optional padding.
1670
+ * @param type The type of the Data URL (e.g., 'image/png', 'image/jpeg').
1671
+ * @param imageConfig Configuration options for the image (optional).
1672
+ * @returns A Promise that resolves to the Data URL string.
1673
+ */
1674
+ toFullDataURL(type, imageConfig) {
1675
+ return __awaiter(this, void 0, void 0, function* () {
1676
+ const backgroundCanvas = this.backgroundCanvas;
1677
+ const canvas = this.canvas;
1678
+ const transientCanvas = this.transientCanvas;
1679
+ const backgroundRoot = canvas.getRoot();
1680
+ const root = canvas.getRoot();
1681
+ const transientRoot = transientCanvas.getRoot();
1682
+ const rendererType = this.rendererType;
1683
+ const backgroundBBox = backgroundRoot.getBBox();
1684
+ const BBox = root.getBBox();
1685
+ const transientBBox = transientRoot.getBBox();
1686
+ let padding = imageConfig ? imageConfig.padding : undefined;
1687
+ if (!padding) {
1688
+ padding = [0, 0, 0, 0];
1689
+ }
1690
+ else if (isNumber(padding)) {
1691
+ padding = [padding, padding, padding, padding];
1692
+ }
1693
+ const left = (transientBBox.left
1694
+ ? backgroundBBox.left
1695
+ ? Math.min(backgroundBBox.left, BBox.left, transientBBox.left)
1696
+ : Math.min(BBox.left, transientBBox.left)
1697
+ : BBox.left) - padding[3];
1698
+ const right = (transientBBox.right
1699
+ ? backgroundBBox.right
1700
+ ? Math.max(backgroundBBox.right, BBox.right, transientBBox.right)
1701
+ : Math.max(BBox.right, transientBBox.right)
1702
+ : BBox.right) + padding[1];
1703
+ const top = (transientBBox.top
1704
+ ? backgroundBBox.top
1705
+ ? Math.min(backgroundBBox.top, BBox.top, transientBBox.top)
1706
+ : Math.min(BBox.top, transientBBox.top)
1707
+ : BBox.top) - padding[0];
1708
+ const bottom = (transientBBox.bottom
1709
+ ? backgroundBBox.bottom
1710
+ ? Math.max(backgroundBBox.bottom, BBox.bottom, transientBBox.bottom)
1711
+ : Math.max(BBox.bottom, transientBBox.bottom)
1712
+ : BBox.bottom) + padding[2];
1713
+ const graphCenterX = (left + right) / 2;
1714
+ const graphCenterY = (top + bottom) / 2;
1715
+ const halfX = (right - left) / 2;
1716
+ const halfY = (bottom - top) / 2;
1717
+ const pixelRatio = typeof window !== 'undefined' ? window.devicePixelRatio : 1;
1718
+ const vWidth = halfX * 2;
1719
+ const vHeight = halfY * 2;
1720
+ const vContainerDOM = createDom('<div id="virtual-image"></div>');
1721
+ const vCanvas = createCanvas(rendererType, vContainerDOM, vWidth, vHeight, pixelRatio);
1722
+ const vCanvasContextService = vCanvas.getContextService();
1723
+ if (rendererType !== 'svg') {
1724
+ const bgRect = new Rect({
1725
+ style: {
1726
+ x: 0,
1727
+ y: 0,
1728
+ z: -1,
1729
+ width: vCanvasContextService.getDomElement().width,
1730
+ height: vCanvasContextService.getDomElement().height,
1731
+ //@ts-ignore
1732
+ fill: backgroundCanvas.getContextService().getDomElement().style['background-color'],
1733
+ },
1734
+ });
1735
+ vCanvas.appendChild(bgRect);
1736
+ }
1737
+ const backgroundClonedGroup = backgroundRoot.cloneNode(true);
1738
+ const clonedGroup = root.cloneNode(true);
1739
+ const transientClonedGroup = transientRoot.cloneNode(true);
1740
+ const transPosition = [
1741
+ -graphCenterX + halfX,
1742
+ -graphCenterY + halfY,
1743
+ ];
1744
+ backgroundClonedGroup.setPosition(transPosition);
1745
+ clonedGroup.setPosition(transPosition);
1746
+ transientClonedGroup.setPosition(transPosition);
1747
+ vCanvas.appendChild(backgroundClonedGroup);
1748
+ vCanvas.appendChild(clonedGroup);
1749
+ vCanvas.appendChild(transientClonedGroup);
1750
+ vCanvas.render();
1751
+ if (!type)
1752
+ type = 'image/png';
1753
+ let dataURL = '';
1754
+ yield vCanvasContextService.toDataURL({ type }).then((url) => {
1755
+ dataURL = url;
1756
+ });
1757
+ return dataURL;
1758
+ });
1759
+ }
1760
+ /**
1761
+ * Converts a Data URL to an image file and handles the download of the image.
1762
+ * @param dataURL The Data URL of the image to be converted and downloaded.
1763
+ * @param renderer The renderer type ('svg' or other) used for the canvas.
1764
+ * @param link The HTML link element used for image download.
1765
+ * @param fileName The desired name for the downloaded image file.
1766
+ */
1767
+ dataURLToImage(dataURL, renderer, link, fileName) {
1768
+ if (!dataURL || dataURL === 'data:') {
1769
+ console.error('Download image failed. The graph is too large or there is invalid attribute values in graph items');
1770
+ return;
1771
+ }
1772
+ if (typeof window !== 'undefined') {
1773
+ if (window.Blob && window.URL && renderer !== 'svg') {
1774
+ const arr = dataURL.split(',');
1775
+ let mime = '';
1776
+ if (arr && arr.length > 0) {
1777
+ const match = arr[0].match(/:(.*?);/);
1778
+ // eslint-disable-next-line prefer-destructuring
1779
+ if (match && match.length >= 2)
1780
+ mime = match[1];
1781
+ }
1782
+ const bstr = atob(arr[1]);
1783
+ let n = bstr.length;
1784
+ const u8arr = new Uint8Array(n);
1785
+ while (n--) {
1786
+ u8arr[n] = bstr.charCodeAt(n);
1787
+ }
1788
+ const blobObj = new Blob([u8arr], { type: mime });
1789
+ if (window.navigator.msSaveBlob) {
1790
+ window.navigator.msSaveBlob(blobObj, fileName);
1791
+ }
1792
+ else {
1793
+ link.addEventListener('click', () => {
1794
+ link.download = fileName;
1795
+ link.href = window.URL.createObjectURL(blobObj);
1796
+ });
1797
+ }
1798
+ }
1799
+ else {
1800
+ link.addEventListener('click', () => {
1801
+ link.download = fileName;
1802
+ link.href = dataURL;
1803
+ });
1804
+ }
1805
+ }
1806
+ }
1807
+ /**
1808
+ * Initiates the download of the graph as an image with an optional name and type.
1809
+ * @param name The desired name for the downloaded image file (optional).
1810
+ * @param type The type of the image to download (optional, defaults to 'image/png').
1811
+ */
1812
+ downloadImage(name, type) {
1813
+ const self = this;
1814
+ // self.stopAnimate();
1815
+ const rendererType = this.rendererType;
1816
+ if (!type)
1817
+ type = 'image/png';
1818
+ const fileName = (name || 'graph') +
1819
+ (rendererType === 'svg' ? '.svg' : type.split('/')[1]);
1820
+ const link = document.createElement('a');
1821
+ self.asyncToDataUrl(type, (dataURL) => {
1822
+ this.dataURLToImage(dataURL, rendererType, link, fileName);
1823
+ const e = document.createEvent('MouseEvents');
1824
+ e.initEvent('click', false, false);
1825
+ link.dispatchEvent(e);
1826
+ });
1827
+ }
1828
+ /**
1829
+ * Initiates the download of the entire graph as an image with optional name, type, and padding configuration.
1830
+ * @param name The desired name for the downloaded image file (optional).
1831
+ * @param type The type of the image to download (optional, defaults to 'image/png').
1832
+ * @param imageConfig Configuration options for the image (optional).
1833
+ */
1834
+ downloadFullImage(name, type, imageConfig) {
1835
+ const self = this;
1836
+ const rendererType = this.rendererType;
1837
+ if (!type)
1838
+ type = 'image/png';
1839
+ const fileName = (name || 'graph') +
1840
+ (rendererType === 'svg' ? '.svg' : type.split('/')[1]);
1841
+ const link = document.createElement('a');
1842
+ self.asyncToFullDataUrl(type, imageConfig, (dataURL) => {
1843
+ this.dataURLToImage(dataURL, rendererType, link, fileName);
1844
+ const e = document.createEvent('MouseEvents');
1845
+ e.initEvent('click', false, false);
1846
+ link.dispatchEvent(e);
1847
+ });
1848
+ }
1849
+ /**
1850
+ * Asynchronously converts the canvas content to a Data URL of the specified type and invokes the provided callback.
1851
+ * @param type The type of the Data URL (optional, defaults to 'image/png').
1852
+ * @param callback A callback function to handle the Data URL (optional).
1853
+ */
1854
+ asyncToDataUrl(type, callback) {
1855
+ let dataURL = '';
1856
+ if (!type)
1857
+ type = 'image/png';
1858
+ setTimeout(() => __awaiter(this, void 0, void 0, function* () {
1859
+ yield this.toDataURL(type).then((url) => {
1860
+ dataURL = url;
1861
+ });
1862
+ if (callback)
1863
+ callback(dataURL);
1864
+ }), 16);
1865
+ }
1866
+ /**
1867
+ * Asynchronously converts the entire canvas content to a Data URL of the specified type
1868
+ * with optional padding, and invokes the provided callback.
1869
+ * @param type The type of the Data URL (optional, defaults to 'image/png').
1870
+ * @param imageConfig Configuration options for the image (optional).
1871
+ * @param callback A callback function to handle the Data URL (optional).
1872
+ */
1873
+ asyncToFullDataUrl(type, imageConfig, callback) {
1874
+ let dataURL = '';
1875
+ if (!type)
1876
+ type = 'image/png';
1877
+ setTimeout(() => __awaiter(this, void 0, void 0, function* () {
1878
+ yield this.toFullDataURL(type, imageConfig).then((url) => {
1879
+ dataURL = url;
1880
+ });
1881
+ if (callback)
1882
+ callback(dataURL);
1883
+ }), 16);
1884
+ }
1513
1885
  // ===== history operations =====
1514
1886
  /**
1515
1887
  * Determine if history (redo/undo) is enabled.
@@ -1531,16 +1903,16 @@ export default class Graph extends EventEmitter {
1531
1903
  /**
1532
1904
  * Pause stacking operation.
1533
1905
  */
1534
- pauseStacking() {
1906
+ pauseStack() {
1535
1907
  const history = this.getHistoryPlugin();
1536
- return history === null || history === void 0 ? void 0 : history.pauseStacking();
1908
+ return history === null || history === void 0 ? void 0 : history.pauseStack();
1537
1909
  }
1538
1910
  /**
1539
1911
  * Resume stacking operation.
1540
1912
  */
1541
- resumeStacking() {
1913
+ resumeStack() {
1542
1914
  const history = this.getHistoryPlugin();
1543
- return history === null || history === void 0 ? void 0 : history.resumeStacking();
1915
+ return history === null || history === void 0 ? void 0 : history.resumeStack();
1544
1916
  }
1545
1917
  /**
1546
1918
  * Retrieve the current redo stack which consists of operations that could be undone
@@ -1597,38 +1969,38 @@ export default class Graph extends EventEmitter {
1597
1969
  return history === null || history === void 0 ? void 0 : history.canRedo();
1598
1970
  }
1599
1971
  /**
1600
- * Begin a batch operation.
1601
- * Any operations performed between `startBatch` and `stopBatch` are grouped together.
1972
+ * Begin a historyBatch operation.
1973
+ * Any operations performed between `startHistoryBatch` and `stopHistoryBatch` are grouped together.
1602
1974
  * treated as a single operation when undoing or redoing.
1603
1975
  */
1604
- startBatch() {
1976
+ startHistoryBatch() {
1605
1977
  const history = this.getHistoryPlugin();
1606
- history === null || history === void 0 ? void 0 : history.startBatch();
1978
+ history === null || history === void 0 ? void 0 : history.startHistoryBatch();
1607
1979
  }
1608
1980
  /**
1609
- * End a batch operation.
1610
- * Any operations performed between `startBatch` and `stopBatch` are grouped together.
1981
+ * End a historyBatch operation.
1982
+ * Any operations performed between `startHistoryBatch` and `stopHistoryBatch` are grouped together.
1611
1983
  * treated as a single operation when undoing or redoing.
1612
1984
  */
1613
- stopBatch() {
1985
+ stopHistoryBatch() {
1614
1986
  const history = this.getHistoryPlugin();
1615
- history === null || history === void 0 ? void 0 : history.stopBatch();
1987
+ history === null || history === void 0 ? void 0 : history.stopHistoryBatch();
1616
1988
  }
1617
1989
  /**
1618
1990
  * Execute a provided function within a batched context
1619
1991
  * All operations performed inside callback will be treated as a composite operation
1620
- * more convenient way without manually invoking `startBatch` and `stopBatch`.
1992
+ * more convenient way without manually invoking `startHistoryBatch` and `stopHistoryBatch`.
1621
1993
  * @param callback The func containing operations to be batched together.
1622
1994
  */
1623
- batch(callback) {
1995
+ historyBatch(callback) {
1624
1996
  const history = this.getHistoryPlugin();
1625
- history === null || history === void 0 ? void 0 : history.batch(callback);
1997
+ history === null || history === void 0 ? void 0 : history.historyBatch(callback);
1626
1998
  }
1627
1999
  /**
1628
2000
  * Clear history stack
1629
2001
  * @param {StackType} stackType undo/redo stack
1630
2002
  */
1631
- clearStack(stackType) {
2003
+ cleanHistory(stackType) {
1632
2004
  const history = this.getHistoryPlugin();
1633
2005
  if (!stackType)
1634
2006
  return history === null || history === void 0 ? void 0 : history.clear();
@@ -1680,7 +2052,7 @@ export default class Graph extends EventEmitter {
1680
2052
  this.backgroundCanvas.destroy();
1681
2053
  this.transientCanvas.destroy();
1682
2054
  // clear history stack
1683
- this.clearStack();
2055
+ this.cleanHistory();
1684
2056
  callback === null || callback === void 0 ? void 0 : callback();
1685
2057
  // }, 500);
1686
2058
  this.hooks.destroy.emit({});