@antv/g6 4.8.14-beta.0 → 5.0.0-alpha.1

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 (595) hide show
  1. package/dist/g6.min.js +19 -3
  2. package/esm/constant/index.d.ts +1 -0
  3. package/esm/constant/index.js +2 -0
  4. package/esm/constant/index.js.map +1 -0
  5. package/esm/constant/shape.d.ts +27 -0
  6. package/esm/constant/shape.js +26 -0
  7. package/esm/constant/shape.js.map +1 -0
  8. package/esm/index.d.ts +124 -0
  9. package/esm/index.js +11 -0
  10. package/esm/index.js.map +1 -0
  11. package/esm/item/combo.d.ts +4 -0
  12. package/esm/item/combo.js +4 -0
  13. package/esm/item/combo.js.map +1 -0
  14. package/esm/item/edge.d.ts +54 -0
  15. package/esm/item/edge.js +113 -0
  16. package/esm/item/edge.js.map +1 -0
  17. package/esm/item/item.d.ts +189 -0
  18. package/esm/item/item.js +636 -0
  19. package/esm/item/item.js.map +1 -0
  20. package/esm/item/node.d.ts +54 -0
  21. package/esm/item/node.js +170 -0
  22. package/esm/item/node.js.map +1 -0
  23. package/esm/runtime/controller/data.d.ts +65 -0
  24. package/esm/runtime/controller/data.js +489 -0
  25. package/esm/runtime/controller/data.js.map +1 -0
  26. package/esm/runtime/controller/extension.d.ts +9 -0
  27. package/esm/runtime/controller/extension.js +11 -0
  28. package/esm/runtime/controller/extension.js.map +1 -0
  29. package/esm/runtime/controller/index.d.ts +7 -0
  30. package/esm/runtime/controller/index.js +8 -0
  31. package/esm/runtime/controller/index.js.map +1 -0
  32. package/esm/runtime/controller/interaction.d.ts +51 -0
  33. package/esm/runtime/controller/interaction.js +259 -0
  34. package/esm/runtime/controller/interaction.js.map +1 -0
  35. package/esm/runtime/controller/item.d.ts +101 -0
  36. package/esm/runtime/controller/item.js +537 -0
  37. package/esm/runtime/controller/item.js.map +1 -0
  38. package/esm/runtime/controller/layout.d.ts +30 -0
  39. package/esm/runtime/controller/layout.js +204 -0
  40. package/esm/runtime/controller/layout.js.map +1 -0
  41. package/esm/runtime/controller/plugin.d.ts +34 -0
  42. package/esm/runtime/controller/plugin.js +140 -0
  43. package/esm/runtime/controller/plugin.js.map +1 -0
  44. package/esm/runtime/controller/theme.d.ts +29 -0
  45. package/esm/runtime/controller/theme.js +54 -0
  46. package/esm/runtime/controller/theme.js.map +1 -0
  47. package/esm/runtime/controller/viewport.d.ts +11 -0
  48. package/esm/runtime/controller/viewport.js +102 -0
  49. package/esm/runtime/controller/viewport.js.map +1 -0
  50. package/esm/runtime/graph.d.ts +462 -0
  51. package/esm/runtime/graph.js +1077 -0
  52. package/esm/runtime/graph.js.map +1 -0
  53. package/esm/runtime/hooks.d.ts +33 -0
  54. package/esm/runtime/hooks.js +74 -0
  55. package/esm/runtime/hooks.js.map +1 -0
  56. package/esm/stdlib/behavior/activate-relations.d.ts +62 -0
  57. package/esm/stdlib/behavior/activate-relations.js +81 -0
  58. package/esm/stdlib/behavior/activate-relations.js.map +1 -0
  59. package/esm/stdlib/behavior/brush-select.d.ts +110 -0
  60. package/esm/stdlib/behavior/brush-select.js +268 -0
  61. package/esm/stdlib/behavior/brush-select.js.map +1 -0
  62. package/esm/stdlib/behavior/click-select.d.ts +71 -0
  63. package/esm/stdlib/behavior/click-select.js +143 -0
  64. package/esm/stdlib/behavior/click-select.js.map +1 -0
  65. package/esm/stdlib/behavior/drag-canvas.d.ts +82 -0
  66. package/esm/stdlib/behavior/drag-canvas.js +246 -0
  67. package/esm/stdlib/behavior/drag-canvas.js.map +1 -0
  68. package/esm/stdlib/behavior/drag-node.d.ts +80 -0
  69. package/esm/stdlib/behavior/drag-node.js +250 -0
  70. package/esm/stdlib/behavior/drag-node.js.map +1 -0
  71. package/esm/stdlib/behavior/hover-activate.d.ts +41 -0
  72. package/esm/stdlib/behavior/hover-activate.js +63 -0
  73. package/esm/stdlib/behavior/hover-activate.js.map +1 -0
  74. package/esm/stdlib/behavior/lasso-select.d.ts +27 -0
  75. package/esm/stdlib/behavior/lasso-select.js +79 -0
  76. package/esm/stdlib/behavior/lasso-select.js.map +1 -0
  77. package/esm/stdlib/behavior/orbit-canvas-3d.d.ts +37 -0
  78. package/esm/stdlib/behavior/orbit-canvas-3d.js +62 -0
  79. package/esm/stdlib/behavior/orbit-canvas-3d.js.map +1 -0
  80. package/esm/stdlib/behavior/rotate-canvas-3d.d.ts +61 -0
  81. package/esm/stdlib/behavior/rotate-canvas-3d.js +123 -0
  82. package/esm/stdlib/behavior/rotate-canvas-3d.js.map +1 -0
  83. package/esm/stdlib/behavior/track-canvas-3d.d.ts +37 -0
  84. package/esm/stdlib/behavior/track-canvas-3d.js +62 -0
  85. package/esm/stdlib/behavior/track-canvas-3d.js.map +1 -0
  86. package/esm/stdlib/behavior/zoom-canvas-3d.d.ts +51 -0
  87. package/esm/stdlib/behavior/zoom-canvas-3d.js +74 -0
  88. package/esm/stdlib/behavior/zoom-canvas-3d.js.map +1 -0
  89. package/esm/stdlib/behavior/zoom-canvas.d.ts +61 -0
  90. package/esm/stdlib/behavior/zoom-canvas.js +160 -0
  91. package/esm/stdlib/behavior/zoom-canvas.js.map +1 -0
  92. package/esm/stdlib/data/comboFromNode.d.ts +9 -0
  93. package/esm/stdlib/data/comboFromNode.js +28 -0
  94. package/esm/stdlib/data/comboFromNode.js.map +1 -0
  95. package/esm/stdlib/index.d.ts +80 -0
  96. package/esm/stdlib/index.js +82 -0
  97. package/esm/stdlib/index.js.map +1 -0
  98. package/esm/stdlib/item/edge/base.d.ts +111 -0
  99. package/esm/stdlib/item/edge/base.js +341 -0
  100. package/esm/stdlib/item/edge/base.js.map +1 -0
  101. package/esm/stdlib/item/edge/index.d.ts +1 -0
  102. package/esm/stdlib/item/edge/index.js +2 -0
  103. package/esm/stdlib/item/edge/index.js.map +1 -0
  104. package/esm/stdlib/item/edge/line.d.ts +33 -0
  105. package/esm/stdlib/item/edge/line.js +45 -0
  106. package/esm/stdlib/item/edge/line.js.map +1 -0
  107. package/esm/stdlib/item/node/base.d.ts +137 -0
  108. package/esm/stdlib/item/node/base.js +414 -0
  109. package/esm/stdlib/item/node/base.js.map +1 -0
  110. package/esm/stdlib/item/node/base3d.d.ts +72 -0
  111. package/esm/stdlib/item/node/base3d.js +113 -0
  112. package/esm/stdlib/item/node/base3d.js.map +1 -0
  113. package/esm/stdlib/item/node/circle.d.ts +30 -0
  114. package/esm/stdlib/item/node/circle.js +56 -0
  115. package/esm/stdlib/item/node/circle.js.map +1 -0
  116. package/esm/stdlib/item/node/index.d.ts +2 -0
  117. package/esm/stdlib/item/node/index.js +3 -0
  118. package/esm/stdlib/item/node/index.js.map +1 -0
  119. package/esm/stdlib/item/node/sphere.d.ts +33 -0
  120. package/esm/stdlib/item/node/sphere.js +52 -0
  121. package/esm/stdlib/item/node/sphere.js.map +1 -0
  122. package/esm/stdlib/plugin/legend/index.d.ts +121 -0
  123. package/esm/stdlib/plugin/legend/index.js +587 -0
  124. package/esm/stdlib/plugin/legend/index.js.map +1 -0
  125. package/esm/stdlib/plugin/minimap/index.d.ts +106 -0
  126. package/esm/stdlib/plugin/minimap/index.js +578 -0
  127. package/esm/stdlib/plugin/minimap/index.js.map +1 -0
  128. package/esm/stdlib/selector/lasso.d.ts +15 -0
  129. package/esm/stdlib/selector/lasso.js +61 -0
  130. package/esm/stdlib/selector/lasso.js.map +1 -0
  131. package/esm/stdlib/selector/rect.d.ts +16 -0
  132. package/esm/stdlib/selector/rect.js +54 -0
  133. package/esm/stdlib/selector/rect.js.map +1 -0
  134. package/esm/stdlib/theme/dark.d.ts +3 -0
  135. package/esm/stdlib/theme/dark.js +279 -0
  136. package/esm/stdlib/theme/dark.js.map +1 -0
  137. package/esm/stdlib/theme/light.d.ts +3 -0
  138. package/esm/stdlib/theme/light.js +274 -0
  139. package/esm/stdlib/theme/light.js.map +1 -0
  140. package/esm/stdlib/themeSolver/base.d.ts +15 -0
  141. package/esm/stdlib/themeSolver/base.js +11 -0
  142. package/esm/stdlib/themeSolver/base.js.map +1 -0
  143. package/esm/stdlib/themeSolver/spec.d.ts +37 -0
  144. package/esm/stdlib/themeSolver/spec.js +66 -0
  145. package/esm/stdlib/themeSolver/spec.js.map +1 -0
  146. package/esm/stdlib/themeSolver/subject.d.ts +43 -0
  147. package/esm/stdlib/themeSolver/subject.js +396 -0
  148. package/esm/stdlib/themeSolver/subject.js.map +1 -0
  149. package/esm/types/animate.d.ts +59 -0
  150. package/esm/types/animate.js +2 -0
  151. package/esm/types/animate.js.map +1 -0
  152. package/esm/types/behavior.d.ts +45 -0
  153. package/esm/types/behavior.js +14 -0
  154. package/esm/types/behavior.js.map +1 -0
  155. package/esm/types/combo.d.ts +87 -0
  156. package/esm/types/combo.js +2 -0
  157. package/esm/types/combo.js.map +1 -0
  158. package/esm/types/common.d.ts +6 -0
  159. package/esm/types/common.js +2 -0
  160. package/esm/types/common.js.map +1 -0
  161. package/esm/types/data.d.ts +21 -0
  162. package/esm/types/data.js +2 -0
  163. package/esm/types/data.js.map +1 -0
  164. package/esm/types/edge.d.ts +100 -0
  165. package/esm/types/edge.js +2 -0
  166. package/esm/types/edge.js.map +1 -0
  167. package/esm/types/event.d.ts +30 -0
  168. package/esm/types/event.js +31 -0
  169. package/esm/types/event.js.map +1 -0
  170. package/esm/types/graph.d.ts +445 -0
  171. package/esm/types/graph.js +2 -0
  172. package/esm/types/graph.js.map +1 -0
  173. package/esm/types/hook.d.ts +97 -0
  174. package/esm/types/hook.js +2 -0
  175. package/esm/types/hook.js.map +1 -0
  176. package/esm/types/index.d.ts +10 -0
  177. package/esm/types/index.js +2 -0
  178. package/esm/types/index.js.map +1 -0
  179. package/esm/types/item.d.ts +229 -0
  180. package/esm/types/item.js +16 -0
  181. package/esm/types/item.js.map +1 -0
  182. package/esm/types/layout.d.ts +69 -0
  183. package/esm/types/layout.js +20 -0
  184. package/esm/types/layout.js.map +1 -0
  185. package/esm/types/node.d.ts +134 -0
  186. package/esm/types/node.js +2 -0
  187. package/esm/types/node.js.map +1 -0
  188. package/esm/types/plugin.d.ts +40 -0
  189. package/esm/types/plugin.js +53 -0
  190. package/esm/types/plugin.js.map +1 -0
  191. package/esm/types/render.d.ts +1 -0
  192. package/esm/types/render.js +2 -0
  193. package/esm/types/render.js.map +1 -0
  194. package/esm/types/spec.d.ts +65 -0
  195. package/esm/types/spec.js +2 -0
  196. package/esm/types/spec.js.map +1 -0
  197. package/esm/types/stdlib.d.ts +13 -0
  198. package/esm/types/stdlib.js +2 -0
  199. package/esm/types/stdlib.js.map +1 -0
  200. package/esm/types/theme.d.ts +102 -0
  201. package/esm/types/theme.js +15 -0
  202. package/esm/types/theme.js.map +1 -0
  203. package/esm/types/view.d.ts +23 -0
  204. package/esm/types/view.js +2 -0
  205. package/esm/types/view.js.map +1 -0
  206. package/esm/util/animate.d.ts +101 -0
  207. package/esm/util/animate.js +350 -0
  208. package/esm/util/animate.js.map +1 -0
  209. package/esm/util/array.d.ts +20 -0
  210. package/esm/util/array.js +60 -0
  211. package/esm/util/array.js.map +1 -0
  212. package/esm/util/canvas.d.ts +20 -0
  213. package/esm/util/canvas.js +81 -0
  214. package/esm/util/canvas.js.map +1 -0
  215. package/esm/util/event.d.ts +12 -0
  216. package/esm/util/event.js +26 -0
  217. package/esm/util/event.js.map +1 -0
  218. package/esm/util/extend.d.ts +21 -0
  219. package/esm/util/extend.js +22 -0
  220. package/esm/util/extend.js.map +1 -0
  221. package/esm/util/extension.d.ts +10 -0
  222. package/esm/util/extension.js +24 -0
  223. package/esm/util/extension.js.map +1 -0
  224. package/esm/util/index.d.ts +14 -0
  225. package/esm/util/index.js +5 -0
  226. package/esm/util/index.js.map +1 -0
  227. package/esm/util/item.d.ts +14 -0
  228. package/esm/util/item.js +42 -0
  229. package/esm/util/item.js.map +1 -0
  230. package/esm/util/mapper.d.ts +17 -0
  231. package/esm/util/mapper.js +60 -0
  232. package/esm/util/mapper.js.map +1 -0
  233. package/esm/util/math.d.ts +8 -0
  234. package/esm/util/math.js +9 -0
  235. package/esm/util/math.js.map +1 -0
  236. package/esm/util/point.d.ts +61 -0
  237. package/esm/util/point.js +160 -0
  238. package/esm/util/point.js.map +1 -0
  239. package/esm/util/shape.d.ts +105 -0
  240. package/esm/util/shape.js +504 -0
  241. package/esm/util/shape.js.map +1 -0
  242. package/esm/util/shape3d.d.ts +23 -0
  243. package/esm/util/shape3d.js +147 -0
  244. package/esm/util/shape3d.js.map +1 -0
  245. package/esm/util/text.d.ts +18 -0
  246. package/esm/util/text.js +36 -0
  247. package/esm/util/text.js.map +1 -0
  248. package/esm/util/type.d.ts +2 -0
  249. package/esm/util/type.js +2 -0
  250. package/esm/util/type.js.map +1 -0
  251. package/esm/util/zoom.d.ts +17 -0
  252. package/esm/util/zoom.js +36 -0
  253. package/esm/util/zoom.js.map +1 -0
  254. package/lib/constant/index.d.ts +1 -0
  255. package/lib/constant/index.js +18 -0
  256. package/lib/constant/index.js.map +1 -0
  257. package/lib/constant/shape.d.ts +27 -0
  258. package/lib/constant/shape.js +29 -0
  259. package/lib/constant/shape.js.map +1 -0
  260. package/lib/index.d.ts +124 -4
  261. package/lib/index.js +30 -27
  262. package/lib/index.js.map +1 -0
  263. package/lib/item/combo.d.ts +4 -0
  264. package/lib/item/combo.js +10 -0
  265. package/lib/item/combo.js.map +1 -0
  266. package/lib/item/edge.d.ts +54 -0
  267. package/lib/item/edge.js +119 -0
  268. package/lib/item/edge.js.map +1 -0
  269. package/lib/item/item.d.ts +189 -0
  270. package/lib/item/item.js +639 -0
  271. package/lib/item/item.js.map +1 -0
  272. package/lib/item/node.d.ts +54 -0
  273. package/lib/item/node.js +176 -0
  274. package/lib/item/node.js.map +1 -0
  275. package/lib/runtime/controller/data.d.ts +65 -0
  276. package/lib/runtime/controller/data.js +493 -0
  277. package/lib/runtime/controller/data.js.map +1 -0
  278. package/lib/runtime/controller/extension.d.ts +9 -0
  279. package/lib/runtime/controller/extension.js +15 -0
  280. package/lib/runtime/controller/extension.js.map +1 -0
  281. package/lib/runtime/controller/index.d.ts +7 -0
  282. package/lib/runtime/controller/index.js +24 -0
  283. package/lib/runtime/controller/index.js.map +1 -0
  284. package/lib/runtime/controller/interaction.d.ts +51 -0
  285. package/lib/runtime/controller/interaction.js +263 -0
  286. package/lib/runtime/controller/interaction.js.map +1 -0
  287. package/lib/runtime/controller/item.d.ts +101 -0
  288. package/lib/runtime/controller/item.js +544 -0
  289. package/lib/runtime/controller/item.js.map +1 -0
  290. package/lib/runtime/controller/layout.d.ts +30 -0
  291. package/lib/runtime/controller/layout.js +208 -0
  292. package/lib/runtime/controller/layout.js.map +1 -0
  293. package/lib/runtime/controller/plugin.d.ts +34 -0
  294. package/lib/runtime/controller/plugin.js +147 -0
  295. package/lib/runtime/controller/plugin.js.map +1 -0
  296. package/lib/runtime/controller/theme.d.ts +29 -0
  297. package/lib/runtime/controller/theme.js +61 -0
  298. package/lib/runtime/controller/theme.js.map +1 -0
  299. package/lib/runtime/controller/viewport.d.ts +11 -0
  300. package/lib/runtime/controller/viewport.js +106 -0
  301. package/lib/runtime/controller/viewport.js.map +1 -0
  302. package/lib/runtime/graph.d.ts +462 -0
  303. package/lib/runtime/graph.js +1083 -0
  304. package/lib/runtime/graph.js.map +1 -0
  305. package/lib/runtime/hooks.d.ts +33 -0
  306. package/lib/runtime/hooks.js +77 -0
  307. package/lib/runtime/hooks.js.map +1 -0
  308. package/lib/stdlib/behavior/activate-relations.d.ts +62 -0
  309. package/lib/stdlib/behavior/activate-relations.js +84 -0
  310. package/lib/stdlib/behavior/activate-relations.js.map +1 -0
  311. package/lib/stdlib/behavior/brush-select.d.ts +110 -0
  312. package/lib/stdlib/behavior/brush-select.js +271 -0
  313. package/lib/stdlib/behavior/brush-select.js.map +1 -0
  314. package/lib/stdlib/behavior/click-select.d.ts +71 -0
  315. package/lib/stdlib/behavior/click-select.js +146 -0
  316. package/lib/stdlib/behavior/click-select.js.map +1 -0
  317. package/lib/stdlib/behavior/drag-canvas.d.ts +82 -0
  318. package/lib/stdlib/behavior/drag-canvas.js +249 -0
  319. package/lib/stdlib/behavior/drag-canvas.js.map +1 -0
  320. package/lib/stdlib/behavior/drag-node.d.ts +80 -0
  321. package/lib/stdlib/behavior/drag-node.js +253 -0
  322. package/lib/stdlib/behavior/drag-node.js.map +1 -0
  323. package/lib/stdlib/behavior/hover-activate.d.ts +41 -0
  324. package/lib/stdlib/behavior/hover-activate.js +67 -0
  325. package/lib/stdlib/behavior/hover-activate.js.map +1 -0
  326. package/lib/stdlib/behavior/lasso-select.d.ts +27 -0
  327. package/lib/stdlib/behavior/lasso-select.js +85 -0
  328. package/lib/stdlib/behavior/lasso-select.js.map +1 -0
  329. package/lib/stdlib/behavior/orbit-canvas-3d.d.ts +37 -0
  330. package/lib/stdlib/behavior/orbit-canvas-3d.js +68 -0
  331. package/lib/stdlib/behavior/orbit-canvas-3d.js.map +1 -0
  332. package/lib/stdlib/behavior/rotate-canvas-3d.d.ts +61 -0
  333. package/lib/stdlib/behavior/rotate-canvas-3d.js +126 -0
  334. package/lib/stdlib/behavior/rotate-canvas-3d.js.map +1 -0
  335. package/lib/stdlib/behavior/track-canvas-3d.d.ts +37 -0
  336. package/lib/stdlib/behavior/track-canvas-3d.js +68 -0
  337. package/lib/stdlib/behavior/track-canvas-3d.js.map +1 -0
  338. package/lib/stdlib/behavior/zoom-canvas-3d.d.ts +51 -0
  339. package/lib/stdlib/behavior/zoom-canvas-3d.js +77 -0
  340. package/lib/stdlib/behavior/zoom-canvas-3d.js.map +1 -0
  341. package/lib/stdlib/behavior/zoom-canvas.d.ts +61 -0
  342. package/lib/stdlib/behavior/zoom-canvas.js +163 -0
  343. package/lib/stdlib/behavior/zoom-canvas.js.map +1 -0
  344. package/lib/stdlib/data/comboFromNode.d.ts +9 -0
  345. package/lib/stdlib/data/comboFromNode.js +32 -0
  346. package/lib/stdlib/data/comboFromNode.js.map +1 -0
  347. package/lib/stdlib/index.d.ts +80 -0
  348. package/lib/stdlib/index.js +90 -0
  349. package/lib/stdlib/index.js.map +1 -0
  350. package/lib/stdlib/item/edge/base.d.ts +111 -0
  351. package/lib/stdlib/item/edge/base.js +345 -0
  352. package/lib/stdlib/item/edge/base.js.map +1 -0
  353. package/lib/stdlib/item/edge/index.d.ts +1 -0
  354. package/lib/stdlib/item/edge/index.js +18 -0
  355. package/lib/stdlib/item/edge/index.js.map +1 -0
  356. package/lib/stdlib/item/edge/line.d.ts +33 -0
  357. package/lib/stdlib/item/edge/line.js +49 -0
  358. package/lib/stdlib/item/edge/line.js.map +1 -0
  359. package/lib/stdlib/item/node/base.d.ts +137 -0
  360. package/lib/stdlib/item/node/base.js +418 -0
  361. package/lib/stdlib/item/node/base.js.map +1 -0
  362. package/lib/stdlib/item/node/base3d.d.ts +72 -0
  363. package/lib/stdlib/item/node/base3d.js +117 -0
  364. package/lib/stdlib/item/node/base3d.js.map +1 -0
  365. package/lib/stdlib/item/node/circle.d.ts +30 -0
  366. package/lib/stdlib/item/node/circle.js +60 -0
  367. package/lib/stdlib/item/node/circle.js.map +1 -0
  368. package/lib/stdlib/item/node/index.d.ts +2 -0
  369. package/lib/stdlib/item/node/index.js +19 -0
  370. package/lib/stdlib/item/node/index.js.map +1 -0
  371. package/lib/stdlib/item/node/sphere.d.ts +33 -0
  372. package/lib/stdlib/item/node/sphere.js +56 -0
  373. package/lib/stdlib/item/node/sphere.js.map +1 -0
  374. package/lib/stdlib/plugin/legend/index.d.ts +121 -0
  375. package/lib/stdlib/plugin/legend/index.js +590 -0
  376. package/lib/stdlib/plugin/legend/index.js.map +1 -0
  377. package/lib/stdlib/plugin/minimap/index.d.ts +106 -0
  378. package/lib/stdlib/plugin/minimap/index.js +581 -0
  379. package/lib/stdlib/plugin/minimap/index.js.map +1 -0
  380. package/lib/stdlib/selector/lasso.d.ts +15 -0
  381. package/lib/stdlib/selector/lasso.js +63 -0
  382. package/lib/stdlib/selector/lasso.js.map +1 -0
  383. package/lib/stdlib/selector/rect.d.ts +16 -0
  384. package/lib/stdlib/selector/rect.js +56 -0
  385. package/lib/stdlib/selector/rect.js.map +1 -0
  386. package/lib/stdlib/theme/dark.d.ts +3 -0
  387. package/lib/stdlib/theme/dark.js +281 -0
  388. package/lib/stdlib/theme/dark.js.map +1 -0
  389. package/lib/stdlib/theme/light.d.ts +3 -0
  390. package/lib/stdlib/theme/light.js +276 -0
  391. package/lib/stdlib/theme/light.js.map +1 -0
  392. package/lib/stdlib/themeSolver/base.d.ts +15 -0
  393. package/lib/stdlib/themeSolver/base.js +14 -0
  394. package/lib/stdlib/themeSolver/base.js.map +1 -0
  395. package/lib/stdlib/themeSolver/spec.d.ts +37 -0
  396. package/lib/stdlib/themeSolver/spec.js +72 -0
  397. package/lib/stdlib/themeSolver/spec.js.map +1 -0
  398. package/lib/stdlib/themeSolver/subject.d.ts +43 -0
  399. package/lib/stdlib/themeSolver/subject.js +404 -0
  400. package/lib/stdlib/themeSolver/subject.js.map +1 -0
  401. package/lib/types/animate.d.ts +59 -0
  402. package/lib/types/animate.js +3 -0
  403. package/lib/types/animate.js.map +1 -0
  404. package/lib/types/behavior.d.ts +45 -0
  405. package/lib/types/behavior.js +18 -0
  406. package/lib/types/behavior.js.map +1 -0
  407. package/lib/types/combo.d.ts +87 -0
  408. package/lib/types/combo.js +3 -0
  409. package/lib/types/combo.js.map +1 -0
  410. package/lib/types/common.d.ts +6 -0
  411. package/lib/types/common.js +3 -0
  412. package/lib/types/common.js.map +1 -0
  413. package/lib/types/data.d.ts +21 -0
  414. package/lib/types/data.js +3 -0
  415. package/lib/types/data.js.map +1 -0
  416. package/lib/types/edge.d.ts +100 -0
  417. package/lib/types/edge.js +3 -0
  418. package/lib/types/edge.js.map +1 -0
  419. package/lib/types/event.d.ts +30 -0
  420. package/lib/types/event.js +34 -0
  421. package/lib/types/event.js.map +1 -0
  422. package/lib/types/graph.d.ts +445 -0
  423. package/lib/types/graph.js +3 -0
  424. package/lib/types/graph.js.map +1 -0
  425. package/lib/types/hook.d.ts +97 -0
  426. package/lib/types/hook.js +3 -0
  427. package/lib/types/hook.js.map +1 -0
  428. package/lib/types/index.d.ts +10 -0
  429. package/lib/types/index.js +7 -0
  430. package/lib/types/index.js.map +1 -0
  431. package/lib/types/item.d.ts +229 -0
  432. package/lib/types/item.js +19 -0
  433. package/lib/types/item.js.map +1 -0
  434. package/lib/types/layout.d.ts +69 -0
  435. package/lib/types/layout.js +25 -0
  436. package/lib/types/layout.js.map +1 -0
  437. package/lib/types/node.d.ts +134 -0
  438. package/lib/types/node.js +3 -0
  439. package/lib/types/node.js.map +1 -0
  440. package/lib/types/plugin.d.ts +40 -0
  441. package/lib/types/plugin.js +57 -0
  442. package/lib/types/plugin.js.map +1 -0
  443. package/lib/types/render.d.ts +1 -0
  444. package/lib/types/render.js +3 -0
  445. package/lib/types/render.js.map +1 -0
  446. package/lib/types/spec.d.ts +65 -0
  447. package/lib/types/spec.js +3 -0
  448. package/lib/types/spec.js.map +1 -0
  449. package/lib/types/stdlib.d.ts +13 -0
  450. package/lib/types/stdlib.js +3 -0
  451. package/lib/types/stdlib.js.map +1 -0
  452. package/lib/types/theme.d.ts +102 -0
  453. package/lib/types/theme.js +19 -0
  454. package/lib/types/theme.js.map +1 -0
  455. package/lib/types/view.d.ts +23 -0
  456. package/lib/types/view.js +3 -0
  457. package/lib/types/view.js.map +1 -0
  458. package/lib/util/animate.d.ts +101 -0
  459. package/lib/util/animate.js +358 -0
  460. package/lib/util/animate.js.map +1 -0
  461. package/lib/util/array.d.ts +20 -0
  462. package/lib/util/array.js +68 -0
  463. package/lib/util/array.js.map +1 -0
  464. package/lib/util/canvas.d.ts +20 -0
  465. package/lib/util/canvas.js +86 -0
  466. package/lib/util/canvas.js.map +1 -0
  467. package/lib/util/event.d.ts +12 -0
  468. package/lib/util/event.js +30 -0
  469. package/lib/util/event.js.map +1 -0
  470. package/lib/util/extend.d.ts +21 -0
  471. package/lib/util/extend.js +29 -0
  472. package/lib/util/extend.js.map +1 -0
  473. package/lib/util/extension.d.ts +10 -0
  474. package/lib/util/extension.js +29 -0
  475. package/lib/util/extension.js.map +1 -0
  476. package/lib/util/index.d.ts +14 -0
  477. package/lib/util/index.js +7 -0
  478. package/lib/util/index.js.map +1 -0
  479. package/lib/util/item.d.ts +14 -0
  480. package/lib/util/item.js +47 -0
  481. package/lib/util/item.js.map +1 -0
  482. package/lib/util/mapper.d.ts +17 -0
  483. package/lib/util/mapper.js +63 -0
  484. package/lib/util/mapper.js.map +1 -0
  485. package/lib/util/math.d.ts +8 -0
  486. package/lib/util/math.js +13 -0
  487. package/lib/util/math.js.map +1 -0
  488. package/lib/util/point.d.ts +61 -0
  489. package/lib/util/point.js +169 -0
  490. package/lib/util/point.js.map +1 -0
  491. package/lib/util/shape.d.ts +105 -0
  492. package/lib/util/shape.js +519 -0
  493. package/lib/util/shape.js.map +1 -0
  494. package/lib/util/shape3d.d.ts +23 -0
  495. package/lib/util/shape3d.js +153 -0
  496. package/lib/util/shape3d.js.map +1 -0
  497. package/lib/util/text.d.ts +18 -0
  498. package/lib/util/text.js +41 -0
  499. package/lib/util/text.js.map +1 -0
  500. package/lib/util/type.d.ts +2 -0
  501. package/lib/util/type.js +6 -0
  502. package/lib/util/type.js.map +1 -0
  503. package/lib/util/zoom.d.ts +17 -0
  504. package/lib/util/zoom.js +41 -0
  505. package/lib/util/zoom.js.map +1 -0
  506. package/package.json +82 -50
  507. package/src/constant/index.ts +1 -0
  508. package/src/constant/shape.ts +33 -0
  509. package/src/index.ts +13 -0
  510. package/src/item/combo.ts +5 -0
  511. package/src/item/edge.ts +177 -0
  512. package/src/item/item.ts +812 -0
  513. package/src/item/node.ts +275 -0
  514. package/src/runtime/controller/data.ts +575 -0
  515. package/src/runtime/controller/extension.ts +14 -0
  516. package/src/runtime/controller/index.ts +7 -0
  517. package/src/runtime/controller/interaction.ts +343 -0
  518. package/src/runtime/controller/item.ts +780 -0
  519. package/src/runtime/controller/layout.ts +251 -0
  520. package/src/runtime/controller/plugin.ts +171 -0
  521. package/src/runtime/controller/theme.ts +69 -0
  522. package/src/runtime/controller/viewport.ts +131 -0
  523. package/src/runtime/graph.ts +1439 -0
  524. package/src/runtime/hooks.ts +64 -0
  525. package/src/stdlib/behavior/activate-relations.ts +139 -0
  526. package/src/stdlib/behavior/brush-select.ts +386 -0
  527. package/src/stdlib/behavior/click-select.ts +201 -0
  528. package/src/stdlib/behavior/drag-canvas.ts +333 -0
  529. package/src/stdlib/behavior/drag-node.ts +402 -0
  530. package/src/stdlib/behavior/hover-activate.ts +106 -0
  531. package/src/stdlib/behavior/lasso-select.ts +94 -0
  532. package/src/stdlib/behavior/orbit-canvas-3d.ts +104 -0
  533. package/src/stdlib/behavior/rotate-canvas-3d.ts +172 -0
  534. package/src/stdlib/behavior/track-canvas-3d.ts +104 -0
  535. package/src/stdlib/behavior/zoom-canvas-3d.ts +127 -0
  536. package/src/stdlib/behavior/zoom-canvas.ts +244 -0
  537. package/src/stdlib/data/comboFromNode.ts +28 -0
  538. package/src/stdlib/index.ts +87 -0
  539. package/src/stdlib/item/edge/base.ts +571 -0
  540. package/src/stdlib/item/edge/index.ts +1 -0
  541. package/src/stdlib/item/edge/line.ts +98 -0
  542. package/src/stdlib/item/node/base.ts +726 -0
  543. package/src/stdlib/item/node/base3d.ts +192 -0
  544. package/src/stdlib/item/node/circle.ts +113 -0
  545. package/src/stdlib/item/node/index.ts +2 -0
  546. package/src/stdlib/item/node/sphere.ts +99 -0
  547. package/src/stdlib/plugin/legend/index.ts +733 -0
  548. package/src/stdlib/plugin/minimap/index.ts +689 -0
  549. package/src/stdlib/selector/lasso.ts +75 -0
  550. package/src/stdlib/selector/rect.ts +78 -0
  551. package/src/stdlib/theme/dark.ts +340 -0
  552. package/src/stdlib/theme/light.ts +333 -0
  553. package/src/stdlib/themeSolver/base.ts +22 -0
  554. package/src/stdlib/themeSolver/spec.ts +110 -0
  555. package/src/stdlib/themeSolver/subject.ts +502 -0
  556. package/src/types/animate.ts +71 -0
  557. package/src/types/behavior.ts +49 -0
  558. package/src/types/combo.ts +120 -0
  559. package/src/types/common.ts +7 -0
  560. package/src/types/data.ts +35 -0
  561. package/src/types/edge.ts +119 -0
  562. package/src/types/event.ts +47 -0
  563. package/src/types/graph.ts +573 -0
  564. package/src/types/hook.ts +98 -0
  565. package/src/types/index.ts +29 -0
  566. package/src/types/item.ts +324 -0
  567. package/src/types/layout.ts +138 -0
  568. package/src/types/node.ts +162 -0
  569. package/src/types/plugin.ts +77 -0
  570. package/src/types/render.ts +1 -0
  571. package/src/types/spec.ts +116 -0
  572. package/src/types/stdlib.ts +25 -0
  573. package/src/types/theme.ts +101 -0
  574. package/src/types/view.ts +31 -0
  575. package/src/util/animate.ts +430 -0
  576. package/src/util/array.ts +57 -0
  577. package/src/util/canvas.ts +95 -0
  578. package/src/util/event.ts +34 -0
  579. package/src/util/extend.ts +42 -0
  580. package/src/util/extension.ts +29 -0
  581. package/src/util/index.ts +4 -0
  582. package/src/util/item.ts +70 -0
  583. package/src/util/mapper.ts +61 -0
  584. package/src/util/math.ts +9 -0
  585. package/src/util/point.ts +195 -0
  586. package/src/util/shape.ts +609 -0
  587. package/src/util/shape3d.ts +198 -0
  588. package/src/util/text.ts +49 -0
  589. package/src/util/type.ts +4 -0
  590. package/src/util/zoom.ts +39 -0
  591. package/README.en-US.md +0 -170
  592. package/README.md +0 -177
  593. package/dist/g6.min.js.map +0 -1
  594. package/es/index.d.ts +0 -4
  595. package/es/index.js +0 -5
@@ -0,0 +1,1077 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import EventEmitter from '@antv/event-emitter';
11
+ import { runtime } from '@antv/g';
12
+ import { isArray, isNil, isNumber, isObject, isString } from '@antv/util';
13
+ import { changeRenderer, createCanvas } from '../util/canvas';
14
+ import { formatPadding } from '../util/shape';
15
+ import { DataController, ExtensionController, InteractionController, ItemController, LayoutController, ThemeController, ViewportController, } from './controller';
16
+ import { PluginController } from './controller/plugin';
17
+ import Hook from './hooks';
18
+ /**
19
+ * Disable CSS parsing for better performance.
20
+ */
21
+ runtime.enableCSSParsing = false;
22
+ export default class Graph extends EventEmitter {
23
+ constructor(spec) {
24
+ super();
25
+ this.defaultSpecification = {
26
+ theme: {
27
+ type: 'spec',
28
+ base: 'light',
29
+ },
30
+ };
31
+ // TODO: analyse cfg
32
+ this.specification = Object.assign({}, this.defaultSpecification, spec);
33
+ this.initHooks();
34
+ this.initCanvas();
35
+ this.initControllers();
36
+ this.hooks.init.emit({
37
+ canvases: {
38
+ background: this.backgroundCanvas,
39
+ main: this.canvas,
40
+ transient: this.transientCanvas,
41
+ },
42
+ });
43
+ const { data } = spec;
44
+ if (data) {
45
+ // TODO: handle multiple type data configs
46
+ this.read(data);
47
+ }
48
+ }
49
+ /**
50
+ * Initialize the controllers for different plugins.
51
+ */
52
+ initControllers() {
53
+ this.dataController = new DataController(this);
54
+ this.interactionController = new InteractionController(this);
55
+ this.layoutController = new LayoutController(this);
56
+ this.themeController = new ThemeController(this);
57
+ this.itemController = new ItemController(this);
58
+ this.viewportController = new ViewportController(this);
59
+ this.extensionController = new ExtensionController(this);
60
+ this.pluginController = new PluginController(this);
61
+ }
62
+ initCanvas() {
63
+ const { renderer, container, width, height } = this.specification;
64
+ let pixelRatio;
65
+ if (renderer && !isString(renderer)) {
66
+ // @ts-ignore
67
+ this.rendererType = renderer.type || 'canvas';
68
+ // @ts-ignore
69
+ pixelRatio = renderer.pixelRatio;
70
+ }
71
+ else {
72
+ // @ts-ignore
73
+ this.rendererType = renderer || 'canvas';
74
+ }
75
+ const containerDOM = isString(container)
76
+ ? document.getElementById(container)
77
+ : container;
78
+ if (!containerDOM) {
79
+ console.error(`Create graph failed. The container for graph ${containerDOM} is not exist.`);
80
+ this.destroy();
81
+ return;
82
+ }
83
+ this.container = containerDOM;
84
+ const size = [width, height];
85
+ if (size[0] === undefined) {
86
+ size[0] = containerDOM.scrollWidth;
87
+ }
88
+ if (size[1] === undefined) {
89
+ size[1] = containerDOM.scrollHeight;
90
+ }
91
+ this.backgroundCanvas = createCanvas(this.rendererType, containerDOM, size[0], size[1], pixelRatio);
92
+ this.canvas = createCanvas(this.rendererType, containerDOM, size[0], size[1], pixelRatio);
93
+ this.transientCanvas = createCanvas(this.rendererType, containerDOM, size[0], size[1], pixelRatio, true, {
94
+ pointerEvents: 'none',
95
+ });
96
+ Promise.all([this.backgroundCanvas, this.canvas, this.transientCanvas].map((canvas) => canvas.ready)).then(() => (this.canvasReady = true));
97
+ }
98
+ /**
99
+ * Change the renderer at runtime.
100
+ * @param type renderer name
101
+ * @returns
102
+ */
103
+ changeRenderer(type) {
104
+ this.rendererType = type || 'canvas';
105
+ changeRenderer(this.rendererType, this.canvas);
106
+ }
107
+ /**
108
+ * Initialize the hooks for graph's lifecycles.
109
+ */
110
+ initHooks() {
111
+ this.hooks = {
112
+ init: new Hook({ name: 'init' }),
113
+ datachange: new Hook({
114
+ name: 'datachange',
115
+ }),
116
+ itemchange: new Hook({ name: 'itemchange' }),
117
+ render: new Hook({
118
+ name: 'render',
119
+ }),
120
+ layout: new Hook({ name: 'layout' }),
121
+ viewportchange: new Hook({ name: 'viewport' }),
122
+ modechange: new Hook({ name: 'modechange' }),
123
+ behaviorchange: new Hook({ name: 'behaviorchange' }),
124
+ itemstatechange: new Hook({
125
+ name: 'itemstatechange',
126
+ }),
127
+ itemvisibilitychange: new Hook({
128
+ name: 'itemvisibilitychange',
129
+ }),
130
+ transientupdate: new Hook({ name: 'transientupdate' }),
131
+ pluginchange: new Hook({ name: 'pluginchange' }),
132
+ themechange: new Hook({ name: 'init' }),
133
+ destroy: new Hook({ name: 'destroy' }),
134
+ };
135
+ }
136
+ /**
137
+ * Update the specs(configurations).
138
+ */
139
+ updateSpecification(spec) {
140
+ return Object.assign(this.specification, spec);
141
+ }
142
+ /**
143
+ * Update the theme specs (configurations).
144
+ */
145
+ updateTheme(theme) {
146
+ this.specification.theme = theme;
147
+ // const { specification } = this.themeController;
148
+ // notifiying the themeController
149
+ this.hooks.themechange.emit({
150
+ canvases: {
151
+ background: this.backgroundCanvas,
152
+ main: this.canvas,
153
+ transient: this.transientCanvas,
154
+ },
155
+ });
156
+ // theme is formatted by themeController, notify the item controller to update the items
157
+ this.hooks.themechange.emit({
158
+ theme: this.themeController.specification,
159
+ });
160
+ }
161
+ /**
162
+ * Get the copy of specs(configurations).
163
+ * @returns graph specs
164
+ */
165
+ getSpecification() {
166
+ return this.specification;
167
+ }
168
+ /**
169
+ * Input data and render the graph.
170
+ * If there is old data, diffs and changes it.
171
+ * @param data
172
+ * @returns
173
+ * @group Data
174
+ */
175
+ read(data) {
176
+ return __awaiter(this, void 0, void 0, function* () {
177
+ this.hooks.datachange.emit({ data, type: 'replace' });
178
+ const emitRender = () => __awaiter(this, void 0, void 0, function* () {
179
+ this.hooks.render.emit({
180
+ graphCore: this.dataController.graphCore,
181
+ theme: this.themeController.specification,
182
+ transientCanvas: this.transientCanvas,
183
+ });
184
+ this.emit('afterrender');
185
+ yield this.layout();
186
+ });
187
+ if (this.canvasReady) {
188
+ yield emitRender();
189
+ }
190
+ else {
191
+ yield Promise.all([this.backgroundCanvas, this.canvas, this.transientCanvas].map((canvas) => canvas.ready));
192
+ yield emitRender();
193
+ }
194
+ });
195
+ }
196
+ /**
197
+ * Change graph data.
198
+ * @param data new data
199
+ * @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)
200
+ * @returns
201
+ * @group Data
202
+ */
203
+ changeData(data, type = 'mergeReplace') {
204
+ return __awaiter(this, void 0, void 0, function* () {
205
+ this.hooks.datachange.emit({ data, type });
206
+ this.hooks.render.emit({
207
+ graphCore: this.dataController.graphCore,
208
+ theme: this.themeController.specification,
209
+ transientCanvas: this.transientCanvas,
210
+ });
211
+ this.emit('afterrender');
212
+ yield this.layout();
213
+ });
214
+ }
215
+ /**
216
+ * Clear the graph, means remove all the items on the graph.
217
+ * @returns
218
+ */
219
+ clear() {
220
+ // TODO
221
+ }
222
+ getViewportCenter() {
223
+ const { width, height } = this.canvas.getConfig();
224
+ return { x: width / 2, y: height / 2 };
225
+ }
226
+ transform(options, effectTiming) {
227
+ return __awaiter(this, void 0, void 0, function* () {
228
+ yield this.hooks.viewportchange.emitLinearAsync({
229
+ transform: options,
230
+ effectTiming,
231
+ });
232
+ this.emit('viewportchange', options);
233
+ });
234
+ }
235
+ /**
236
+ * Stop the current transition of transform immediately.
237
+ */
238
+ stopTransformTransition() {
239
+ this.canvas.getCamera().cancelLandmarkAnimation();
240
+ }
241
+ /**
242
+ * Move the graph with a relative distance under viewport coordinates.
243
+ * @param dx x of the relative distance
244
+ * @param dy y of the relative distance
245
+ * @param effectTiming animation configurations
246
+ */
247
+ translate(distance, effectTiming) {
248
+ return __awaiter(this, void 0, void 0, function* () {
249
+ yield this.transform({
250
+ translate: distance,
251
+ }, effectTiming);
252
+ });
253
+ }
254
+ /**
255
+ * Move the graph to destination under viewport coordinates.
256
+ * @param destination destination under viewport coordinates.
257
+ * @param effectTiming animation configurations
258
+ */
259
+ translateTo({ x, y }, effectTiming) {
260
+ return __awaiter(this, void 0, void 0, function* () {
261
+ const { x: cx, y: cy } = this.getViewportCenter();
262
+ yield this.translate({ dx: cx - x, dy: cy - y }, effectTiming);
263
+ });
264
+ }
265
+ /**
266
+ * Zoom the graph with a relative ratio.
267
+ * @param ratio relative ratio to zoom
268
+ * @param origin origin under viewport coordinates.
269
+ * @param effectTiming animation configurations
270
+ */
271
+ zoom(ratio, origin, effectTiming) {
272
+ return __awaiter(this, void 0, void 0, function* () {
273
+ yield this.transform({
274
+ zoom: {
275
+ ratio,
276
+ },
277
+ origin,
278
+ }, effectTiming);
279
+ });
280
+ }
281
+ /**
282
+ * Zoom the graph to a specified ratio.
283
+ * @param zoom specified ratio
284
+ * @param origin zoom center
285
+ * @param effectTiming animation configurations
286
+ */
287
+ zoomTo(zoom, origin, effectTiming) {
288
+ return __awaiter(this, void 0, void 0, function* () {
289
+ yield this.zoom(zoom / this.canvas.getCamera().getZoom(), origin, effectTiming);
290
+ });
291
+ }
292
+ /**
293
+ * Return the current zoom level of camera.
294
+ * @returns current zoom
295
+ */
296
+ getZoom() {
297
+ return this.canvas.getCamera().getZoom();
298
+ }
299
+ /**
300
+ * Rotate the graph with a relative angle.
301
+ * @param angle
302
+ * @param origin
303
+ * @param effectTiming
304
+ */
305
+ rotate(angle, origin, effectTiming) {
306
+ return __awaiter(this, void 0, void 0, function* () {
307
+ yield this.transform({
308
+ rotate: {
309
+ angle,
310
+ },
311
+ origin,
312
+ }, effectTiming);
313
+ });
314
+ }
315
+ /**
316
+ * Rotate the graph to an absolute angle.
317
+ * @param angle
318
+ * @param origin
319
+ * @param effectTiming
320
+ */
321
+ rotateTo(angle, origin, effectTiming) {
322
+ return __awaiter(this, void 0, void 0, function* () {
323
+ yield this.rotate(angle - this.canvas.getCamera().getRoll(), origin, effectTiming);
324
+ });
325
+ }
326
+ /**
327
+ * Fit the graph content to the view.
328
+ * @param options.padding padding while fitting
329
+ * @param options.rules rules for fitting
330
+ * @param effectTiming animation configurations
331
+ */
332
+ fitView(options, effectTiming) {
333
+ return __awaiter(this, void 0, void 0, function* () {
334
+ const { padding, rules } = options || {};
335
+ const [top, right, bottom, left] = padding
336
+ ? formatPadding(padding)
337
+ : [0, 0, 0, 0];
338
+ const { direction = 'both', ratioRule = 'min' } = rules || {};
339
+ // Get the bounds of the whole graph.
340
+ const { center: [graphCenterX, graphCenterY], halfExtents, } = this.canvas.document.documentElement.getBounds();
341
+ const origin = this.canvas.canvas2Viewport({
342
+ x: graphCenterX,
343
+ y: graphCenterY,
344
+ });
345
+ const { width: viewportWidth, height: viewportHeight } = this.canvas.getConfig();
346
+ const graphWidth = halfExtents[0] * 2;
347
+ const graphHeight = halfExtents[1] * 2;
348
+ const tlInCanvas = this.canvas.viewport2Canvas({ x: left, y: top });
349
+ const brInCanvas = this.canvas.viewport2Canvas({
350
+ x: viewportWidth - right,
351
+ y: viewportHeight - bottom,
352
+ });
353
+ const targetViewWidth = brInCanvas.x - tlInCanvas.x;
354
+ const targetViewHeight = brInCanvas.y - tlInCanvas.y;
355
+ const wRatio = targetViewWidth / graphWidth;
356
+ const hRatio = targetViewHeight / graphHeight;
357
+ let ratio;
358
+ if (direction === 'x') {
359
+ ratio = wRatio;
360
+ }
361
+ else if (direction === 'y') {
362
+ ratio = hRatio;
363
+ }
364
+ else {
365
+ ratio =
366
+ ratioRule === 'max'
367
+ ? Math.max(wRatio, hRatio)
368
+ : Math.min(wRatio, hRatio);
369
+ }
370
+ yield this.transform({
371
+ translate: {
372
+ dx: viewportWidth / 2 - origin.x,
373
+ dy: viewportHeight / 2 - origin.y,
374
+ },
375
+ zoom: {
376
+ ratio,
377
+ },
378
+ }, effectTiming);
379
+ });
380
+ }
381
+ /**
382
+ * Fit the graph center to the view center.
383
+ * @param effectTiming animation configurations
384
+ */
385
+ fitCenter(effectTiming) {
386
+ return __awaiter(this, void 0, void 0, function* () {
387
+ // Get the bounds of the whole graph.
388
+ const { center: [graphCenterX, graphCenterY], } = this.canvas.document.documentElement.getBounds();
389
+ yield this.translateTo(this.canvas.canvas2Viewport({ x: graphCenterX, y: graphCenterY }), effectTiming);
390
+ });
391
+ }
392
+ /**
393
+ * Move the graph to make the item align the view center.
394
+ * @param item node/edge/combo item or its id
395
+ * @param effectTiming animation configurations
396
+ */
397
+ focusItem(id, effectTiming) {
398
+ return __awaiter(this, void 0, void 0, function* () {
399
+ let bounds = null;
400
+ for (const itemId of !isArray(id) ? [id] : id) {
401
+ const item = this.itemController.getItemById(itemId);
402
+ if (item) {
403
+ const itemBounds = item.group.getBounds();
404
+ if (!bounds) {
405
+ bounds = itemBounds;
406
+ }
407
+ else {
408
+ bounds.add(itemBounds);
409
+ }
410
+ }
411
+ }
412
+ if (bounds) {
413
+ const { center: [itemCenterX, itemCenterY], } = bounds;
414
+ yield this.translateTo(this.canvas.canvas2Viewport({ x: itemCenterX, y: itemCenterY }), effectTiming);
415
+ }
416
+ });
417
+ }
418
+ /**
419
+ * Get the size of the graph canvas.
420
+ * @returns [width, height]
421
+ * @group View
422
+ */
423
+ getSize() {
424
+ const { width = 500, height = 500 } = this.specification;
425
+ return [width, height];
426
+ }
427
+ /**
428
+ * Set the size for the graph canvas.
429
+ * @param number[] [width, height]
430
+ * @group View
431
+ */
432
+ setSize(size) {
433
+ if (!isArray(size) || size.length < 2) {
434
+ console.warn(`Failed to setSize. The parameter size: ${size} is invalid. It must be an array with 2 number elements.`);
435
+ return;
436
+ }
437
+ this.specification.width = size[0];
438
+ this.specification.height = size[1];
439
+ this.canvas.resize(size[0], size[1]);
440
+ }
441
+ /**
442
+ * Get the rendering coordinate according to the canvas dom (viewport) coordinate.
443
+ * @param Point rendering coordinate
444
+ * @returns canvas dom (viewport) coordinate
445
+ * @group View
446
+ */
447
+ getCanvasByViewport(viewportPoint) {
448
+ return this.canvas.viewport2Canvas(viewportPoint);
449
+ }
450
+ /**
451
+ * Get the canvas dom (viewport) coordinate according to the rendering coordinate.
452
+ * @param Point canvas dom (viewport) coordinate
453
+ * @returns rendering coordinate
454
+ * @group View
455
+ */
456
+ getViewportByCanvas(canvasPoint) {
457
+ return this.canvas.canvas2Viewport(canvasPoint);
458
+ }
459
+ /**
460
+ * Get the browser coordinate according to the rendering coordinate.
461
+ * @param Point rendering coordinate
462
+ * @returns browser coordinate
463
+ * @group View
464
+ */
465
+ getClientByCanvas(canvasPoint) {
466
+ const viewportPoint = this.canvas.canvas2Viewport(canvasPoint);
467
+ return this.canvas.viewport2Client(viewportPoint);
468
+ }
469
+ /**
470
+ * Get the rendering coordinate according to the browser coordinate.
471
+ * @param Point browser coordinate
472
+ * @returns rendering coordinate
473
+ * @group View
474
+ */
475
+ getCanvasByClient(clientPoint) {
476
+ const viewportPoint = this.canvas.client2Viewport(clientPoint);
477
+ return this.canvas.viewport2Canvas(viewportPoint);
478
+ }
479
+ // ===== item operations =====
480
+ /**
481
+ * Find a node's inner data according to id or function.
482
+ * @param { ID | Function } condition id or condition function
483
+ * @returns result node's inner data
484
+ * @group Data
485
+ */
486
+ getNodeData(condition) {
487
+ var _a;
488
+ const conds = isString(condition) || isNumber(condition) ? [condition] : condition;
489
+ return (_a = this.dataController.findData('node', conds)) === null || _a === void 0 ? void 0 : _a[0];
490
+ }
491
+ /**
492
+ * Find an edge's inner data according to id or function.
493
+ * @param { ID | Function } condition id or condition function
494
+ * @returns result edge's inner data
495
+ * @group Data
496
+ */
497
+ getEdgeData(condition) {
498
+ var _a;
499
+ const conds = isString(condition) || isNumber(condition) || isNumber(condition)
500
+ ? [condition]
501
+ : condition;
502
+ return (_a = this.dataController.findData('edge', conds)) === null || _a === void 0 ? void 0 : _a[0];
503
+ }
504
+ /**
505
+ * Find an combo's inner data according to id or function.
506
+ * @param { ID | Function } condition id or condition function
507
+ * @returns result combo's inner data
508
+ * @group Data
509
+ */
510
+ getComboData(condition) {
511
+ var _a;
512
+ const conds = isString(condition) || isNumber(condition) ? [condition] : condition;
513
+ return (_a = this.dataController.findData('combo', conds)) === null || _a === void 0 ? void 0 : _a[0];
514
+ }
515
+ /**
516
+ * Get all the nodes' inner data
517
+ * @returns all nodes' inner data on the graph
518
+ * @group Data
519
+ */
520
+ getAllNodesData() {
521
+ return this.dataController.findAllData('node');
522
+ }
523
+ /**
524
+ * Get all the edges' inner data
525
+ * @returns all edges' inner data on the graph
526
+ * @group Data
527
+ */
528
+ getAllEdgesData() {
529
+ return this.dataController.findAllData('edge');
530
+ }
531
+ /**
532
+ * Get all the combos' inner data
533
+ * @returns all combos' inner data on the graph
534
+ * @group Data
535
+ */
536
+ getAllCombosData() {
537
+ return this.dataController.findAllData('combo');
538
+ }
539
+ /**
540
+ * Get one-hop edge ids from a start node.
541
+ * @param nodeId id of the start node
542
+ * @returns one-hop edge ids
543
+ * @group Data
544
+ */
545
+ getRelatedEdgesData(nodeId, direction = 'both') {
546
+ return this.dataController.findRelatedEdgeIds(nodeId, direction);
547
+ }
548
+ /**
549
+ * Get one-hop node ids from a start node.
550
+ * @param nodeId id of the start node
551
+ * @returns one-hop node ids
552
+ * @group Data
553
+ */
554
+ getNeighborNodesData(nodeId, direction = 'both') {
555
+ return this.dataController.findNeighborNodeIds(nodeId, direction);
556
+ }
557
+ /**
558
+ * Find items which has the state.
559
+ * @param itemType item type
560
+ * @param state state name
561
+ * @param additionalFilter additional filter function
562
+ * @returns items that is the type and has the state
563
+ * @group Item
564
+ */
565
+ findIdByState(itemType, state, value = true, additionalFilter) {
566
+ let ids = this.itemController.findIdByState(itemType, state, value);
567
+ if (additionalFilter) {
568
+ const getDataFunc = itemType === 'node' ? this.getNodeData : this.getEdgeData; // TODO: combo
569
+ ids = ids.filter((id) => additionalFilter(getDataFunc(id)));
570
+ }
571
+ return ids;
572
+ }
573
+ /**
574
+ * Add one or more node/edge/combo data to the graph.
575
+ * @param itemType item type
576
+ * @param model user data
577
+ * @param stack whether push this operation to stack
578
+ * @returns whether success
579
+ * @group Data
580
+ */
581
+ addData(itemType, models, stack) {
582
+ // data controller and item controller subscribe additem in order
583
+ const { graphCore } = this.dataController;
584
+ const { specification } = this.themeController;
585
+ graphCore.once('changed', (event) => {
586
+ if (!event.changes.length)
587
+ return;
588
+ this.hooks.itemchange.emit({
589
+ type: itemType,
590
+ changes: graphCore.reduceChanges(event.changes),
591
+ graphCore,
592
+ theme: specification,
593
+ });
594
+ this.emit('afteritemchange', { type: itemType, action: 'add', models });
595
+ });
596
+ const modelArr = isArray(models) ? models : [models];
597
+ const data = { nodes: [], edges: [], combos: [] };
598
+ data[`${itemType}s`] = modelArr;
599
+ this.hooks.datachange.emit({
600
+ data,
601
+ type: 'union',
602
+ });
603
+ const dataList = this.dataController.findData(itemType, modelArr.map((model) => model.id));
604
+ return isArray(models) ? dataList : dataList[0];
605
+ }
606
+ /**
607
+ * Remove one or more node/edge/combo data from the graph.
608
+ * @param item the item to be removed
609
+ * @param stack whether push this operation to stack
610
+ * @returns whether success
611
+ * @group Data
612
+ */
613
+ removeData(itemType, ids, stack) {
614
+ const idArr = isArray(ids) ? ids : [ids];
615
+ const data = { nodes: [], edges: [], combos: [] };
616
+ const { userGraphCore, graphCore } = this.dataController;
617
+ const { specification } = this.themeController;
618
+ const getItem = itemType === 'edge' ? userGraphCore.getEdge : userGraphCore.getNode; // TODO: combo
619
+ data[`${itemType}s`] = idArr.map((id) => getItem.bind(userGraphCore)(id));
620
+ graphCore.once('changed', (event) => {
621
+ if (!event.changes.length)
622
+ return;
623
+ this.hooks.itemchange.emit({
624
+ type: itemType,
625
+ changes: event.changes,
626
+ graphCore,
627
+ theme: specification,
628
+ });
629
+ this.emit('afteritemchange', { type: itemType, action: 'remove', ids });
630
+ });
631
+ this.hooks.datachange.emit({
632
+ data,
633
+ type: 'remove',
634
+ });
635
+ }
636
+ /**
637
+ * Update one or more node/edge/combo data on the graph.
638
+ * @param {ITEM_TYPE} itemType 'node' | 'edge' | 'combo'
639
+ * @param models new configurations for every node/edge/combo, which has id field to indicate the specific item
640
+ * @param {boolean} stack whether push this operation into graph's stack, true by default
641
+ * @group Data
642
+ */
643
+ updateData(itemType, models, stack) {
644
+ const modelArr = isArray(models) ? models : [models];
645
+ const data = { nodes: [], edges: [], combos: [] };
646
+ data[`${itemType}s`] = modelArr;
647
+ const { graphCore } = this.dataController;
648
+ const { specification } = this.themeController;
649
+ graphCore.once('changed', (event) => {
650
+ this.hooks.itemchange.emit({
651
+ type: itemType,
652
+ changes: event.changes,
653
+ graphCore,
654
+ theme: specification,
655
+ });
656
+ this.emit('afteritemchange', {
657
+ type: itemType,
658
+ action: 'update',
659
+ models,
660
+ });
661
+ });
662
+ this.hooks.datachange.emit({
663
+ data,
664
+ type: 'update',
665
+ });
666
+ const dataList = this.dataController.findData(itemType, modelArr.map((model) => model.id));
667
+ return isArray(models) ? dataList : dataList[0];
668
+ }
669
+ /**
670
+ * Update one or more nodes' positions,
671
+ * do not update other styles which leads to better performance than updating positions by updateData.
672
+ * @param models new configurations with x and y for every node, which has id field to indicate the specific item
673
+ * @param {boolean} stack whether push this operation into graph's stack, true by default
674
+ * @group Data
675
+ */
676
+ updateNodePosition(models, stack) {
677
+ const modelArr = isArray(models) ? models : [models];
678
+ const { graphCore } = this.dataController;
679
+ const { specification } = this.themeController;
680
+ graphCore.once('changed', (event) => {
681
+ if (!event.changes.length)
682
+ return;
683
+ this.hooks.itemchange.emit({
684
+ type: 'node',
685
+ changes: event.changes,
686
+ graphCore,
687
+ theme: specification,
688
+ action: 'updateNodePosition',
689
+ });
690
+ this.emit('afteritemchange', {
691
+ type: 'node',
692
+ action: 'updateNodePosition',
693
+ models,
694
+ });
695
+ });
696
+ this.hooks.datachange.emit({
697
+ data: {
698
+ nodes: modelArr,
699
+ edges: [],
700
+ },
701
+ type: 'update',
702
+ });
703
+ const dataList = this.dataController.findData('node', modelArr.map((model) => model.id));
704
+ return isArray(models) ? dataList : dataList[0];
705
+ }
706
+ /**
707
+ * Show the item(s).
708
+ * @param item the item to be shown
709
+ * @returns
710
+ * @group Item
711
+ */
712
+ showItem(ids, disableAniamte) {
713
+ const idArr = isArray(ids) ? ids : [ids];
714
+ this.hooks.itemvisibilitychange.emit({
715
+ ids: idArr,
716
+ value: true,
717
+ animate: !disableAniamte,
718
+ });
719
+ }
720
+ /**
721
+ * Hide the item(s).
722
+ * @param item the item to be hidden
723
+ * @returns
724
+ * @group Item
725
+ */
726
+ hideItem(ids, disableAniamte) {
727
+ const idArr = isArray(ids) ? ids : [ids];
728
+ this.hooks.itemvisibilitychange.emit({
729
+ ids: idArr,
730
+ value: false,
731
+ animate: !disableAniamte,
732
+ });
733
+ }
734
+ /**
735
+ * Set state for the item.
736
+ * @param item the item to be set
737
+ * @param state the state name
738
+ * @param value state value
739
+ * @returns
740
+ * @group Item
741
+ */
742
+ setItemState(ids, states, value) {
743
+ const idArr = isArray(ids) ? ids : [ids];
744
+ const stateArr = isArray(states) ? states : [states];
745
+ this.hooks.itemstatechange.emit({
746
+ ids: idArr,
747
+ states: stateArr,
748
+ value,
749
+ });
750
+ this.emit('afteritemstatechange', { ids, states, value });
751
+ }
752
+ /**
753
+ * Get the state value for an item.
754
+ * @param id the id for the item
755
+ * @param states the state name
756
+ * @returns {boolean} the state value
757
+ * @group Item
758
+ */
759
+ getItemState(id, state) {
760
+ return this.itemController.getItemState(id, state);
761
+ }
762
+ /**
763
+ * Clear all the states for item(s).
764
+ * @param ids the id(s) for the item(s) to be clear
765
+ * @param states the states' names, all the states wil be cleared if states is not assigned
766
+ * @returns
767
+ * @group Item
768
+ */
769
+ clearItemState(ids, states) {
770
+ const idArr = isArray(ids) ? ids : [ids];
771
+ this.hooks.itemstatechange.emit({
772
+ ids: idArr,
773
+ states,
774
+ value: false,
775
+ });
776
+ this.emit('afteritemstatechange', { ids, states, value: false });
777
+ }
778
+ /**
779
+ * Get the rendering bbox for a node / edge / combo, or the graph (when the id is not assigned).
780
+ * @param id the id for the node / edge / combo, undefined for the whole graph
781
+ * @returns rendering bounding box. returns false if the item is not exist
782
+ * @group Item
783
+ */
784
+ getRenderBBox(id) {
785
+ if (!id)
786
+ return this.canvas.getRoot().getRenderBounds();
787
+ return this.itemController.getItemBBox(id);
788
+ }
789
+ /**
790
+ * Get the visibility for a node / edge / combo.
791
+ * @param id the id for the node / edge / combo
792
+ * @returns visibility for the item, false for invisible or unexistence for the item
793
+ * @group Item
794
+ */
795
+ getItemVisible(id) {
796
+ return this.itemController.getItemVisible(id);
797
+ }
798
+ // ===== combo operations =====
799
+ /**
800
+ * Create a new combo with existing child nodes and combos.
801
+ * @param combo combo ID or Combo model
802
+ * @param childrenIds id array of children of the new combo
803
+ * @group Combo
804
+ */
805
+ createCombo(combo, childrenIds, stack) {
806
+ // TODO
807
+ }
808
+ /**
809
+ * dissolve combo
810
+ * @param {String | ICombo} item combo item or id to be dissolve
811
+ * @group Combo
812
+ */
813
+ uncombo(comboId, stack) {
814
+ // TODO
815
+ }
816
+ /**
817
+ * Collapse a combo.
818
+ * @param comboId combo id or item
819
+ * @group Combo
820
+ */
821
+ collapseCombo(comboId, stack) {
822
+ // TODO
823
+ }
824
+ /**
825
+ * Expand a combo.
826
+ * @param combo combo ID 或 combo 实例
827
+ * @group Combo
828
+ */
829
+ expandCombo(comboId, stack) {
830
+ // TODO
831
+ }
832
+ // ===== layout =====
833
+ /**
834
+ * Layout the graph (with current configurations if cfg is not assigned).
835
+ */
836
+ layout(options) {
837
+ return __awaiter(this, void 0, void 0, function* () {
838
+ const { graphCore } = this.dataController;
839
+ const formattedOptions = Object.assign(Object.assign({}, this.getSpecification().layout), options);
840
+ const layoutUnset = !options && !this.getSpecification().layout;
841
+ if (layoutUnset) {
842
+ const nodes = graphCore.getAllNodes();
843
+ if (nodes.every((node) => isNil(node.data.x) && isNil(node.data.y))) {
844
+ // Use `grid` layout as default when x/y of each node is unset.
845
+ formattedOptions.type = 'grid';
846
+ }
847
+ else {
848
+ // Use user-defined position(x/y default to 0).
849
+ formattedOptions.execute = (graph) => __awaiter(this, void 0, void 0, function* () {
850
+ const nodes = graph.getAllNodes();
851
+ return {
852
+ nodes: nodes.map((node) => ({
853
+ id: node.id,
854
+ data: {
855
+ x: Number(node.data.x) || 0,
856
+ y: Number(node.data.y) || 0,
857
+ },
858
+ })),
859
+ edges: [],
860
+ };
861
+ });
862
+ }
863
+ }
864
+ yield this.hooks.layout.emitLinearAsync({
865
+ graphCore,
866
+ options: formattedOptions,
867
+ });
868
+ this.emit('afterlayout');
869
+ });
870
+ }
871
+ /**
872
+ * Some layout algorithms has many iterations which can be stopped at any time.
873
+ */
874
+ stopLayout() {
875
+ this.layoutController.stopLayout();
876
+ }
877
+ /**
878
+ * Switch mode.
879
+ * @param mode mode name
880
+ * @returns
881
+ * @group Interaction
882
+ */
883
+ setMode(mode) {
884
+ this.hooks.modechange.emit({ mode });
885
+ }
886
+ /**
887
+ * Add behavior(s) to mode(s).
888
+ * @param behaviors behavior names or configs
889
+ * @param modes mode names
890
+ * @returns
891
+ * @group Interaction
892
+ */
893
+ addBehaviors(behaviors, modes) {
894
+ const modesArr = isArray(modes) ? modes : [modes];
895
+ const behaviorsArr = isArray(behaviors) ? behaviors : [behaviors];
896
+ this.hooks.behaviorchange.emit({
897
+ action: 'add',
898
+ modes: modesArr,
899
+ // TODO: update type define.
900
+ // @ts-ignore
901
+ behaviors: behaviorsArr,
902
+ });
903
+ // update the graph specification
904
+ modesArr.forEach((mode) => {
905
+ this.specification.modes[mode] =
906
+ this.specification.modes[mode].concat(behaviorsArr);
907
+ });
908
+ }
909
+ /**
910
+ * Remove behavior(s) from mode(s).
911
+ * @param behaviors behavior configs with unique key
912
+ * @param modes mode names
913
+ * @returns
914
+ * @group Interaction
915
+ */
916
+ removeBehaviors(behaviorKeys, modes) {
917
+ const modesArr = isArray(modes) ? modes : [modes];
918
+ this.hooks.behaviorchange.emit({
919
+ action: 'remove',
920
+ modes: modesArr,
921
+ behaviors: behaviorKeys,
922
+ });
923
+ // update the graph specification
924
+ modesArr.forEach((mode) => {
925
+ behaviorKeys.forEach((key) => {
926
+ const oldBehavior = this.specification.modes[mode].find((behavior) => isObject(behavior) && behavior.key === key);
927
+ const indexOfOldBehavior = this.specification.modes[mode].indexOf(oldBehavior);
928
+ this.specification.modes[mode].splice(indexOfOldBehavior, 1);
929
+ });
930
+ });
931
+ }
932
+ /**
933
+ * Update a behavior on a mode.
934
+ * @param behavior behavior configs, whose name indicates the behavior to be updated
935
+ * @param mode mode name
936
+ * @returns
937
+ * @group Interaction
938
+ */
939
+ updateBehavior(behavior, mode) {
940
+ this.hooks.behaviorchange.emit({
941
+ action: 'update',
942
+ modes: [mode],
943
+ // TODO: update type define.
944
+ // @ts-ignore
945
+ behaviors: [behavior],
946
+ });
947
+ // no need to update specification since the corresponding part is the same object as the behavior's option
948
+ // this.specification.modes[mode].forEach((b, i) => {
949
+ // if (isObject(b) && b.key === behavior.key) {
950
+ // this.specification.modes[mode][i] = behavior;
951
+ // }
952
+ // });
953
+ }
954
+ /**
955
+ * Add plugin(s) to graph.
956
+ * @param pluginCfgs
957
+ * @returns
958
+ * @group Plugin
959
+ */
960
+ addPlugins(pluginCfgs) {
961
+ const pluginsArr = isArray(pluginCfgs) ? pluginCfgs : [pluginCfgs];
962
+ // update the graph specification
963
+ if (!this.specification.plugins)
964
+ this.specification.plugins = [];
965
+ const oldPlugins = this.specification.plugins;
966
+ const validPlugins = [];
967
+ pluginsArr.forEach((config) => {
968
+ const oldPlugin = oldPlugins.find((oldPlugin) => {
969
+ if (typeof oldPlugin === 'string' || typeof config === 'string')
970
+ return false;
971
+ return oldPlugin.key === config.key;
972
+ });
973
+ if (oldPlugin) {
974
+ console.warn(`Add plugin with key ${config.key} failed, the key is duplicated to the existing plugins on the graph.`);
975
+ return;
976
+ }
977
+ validPlugins.push(config);
978
+ });
979
+ this.specification.plugins = oldPlugins.concat(validPlugins);
980
+ this.hooks.pluginchange.emit({
981
+ action: 'add',
982
+ plugins: validPlugins,
983
+ });
984
+ }
985
+ /**
986
+ * Remove plugin(s) from graph.
987
+ * @param pluginKeys
988
+ * @returns
989
+ * @group Plugin
990
+ */
991
+ removePlugins(pluginKeys) {
992
+ this.hooks.pluginchange.emit({
993
+ action: 'remove',
994
+ plugins: pluginKeys,
995
+ });
996
+ // update the graph specification
997
+ const { plugins } = this.specification;
998
+ this.specification.plugins = plugins === null || plugins === void 0 ? void 0 : plugins.filter((plugin) => {
999
+ if (isObject(plugin))
1000
+ return !pluginKeys.includes(plugin.key);
1001
+ return !pluginKeys.includes(plugin);
1002
+ });
1003
+ }
1004
+ /**
1005
+ * Update a plugin of the graph.
1006
+ * @param plugin plugin configs, whose key indicates the behavior to be updated
1007
+ * @returns
1008
+ * @group Interaction
1009
+ */
1010
+ updatePlugin(plugin) {
1011
+ const { key } = plugin;
1012
+ if (!key) {
1013
+ console.warn('Update plugin failed, the key for the plugin to be updated should be assign.');
1014
+ return;
1015
+ }
1016
+ const { plugins } = this.specification;
1017
+ if (!plugins) {
1018
+ console.warn('Update plugin failed, the plugin to be updated does not exist.');
1019
+ return;
1020
+ }
1021
+ const oldPlugin = plugins === null || plugins === void 0 ? void 0 : plugins.find((p) => {
1022
+ if (typeof p === 'string')
1023
+ return p === key;
1024
+ return p.key === key;
1025
+ });
1026
+ if (!oldPlugin) {
1027
+ console.warn('Update plugin failed, the key for the plugin to be updated should be assign.');
1028
+ return;
1029
+ }
1030
+ const idx = plugins.indexOf(oldPlugin);
1031
+ plugins[idx] = Object.assign(Object.assign({}, oldPlugin), plugin);
1032
+ this.hooks.pluginchange.emit({
1033
+ action: 'update',
1034
+ plugins: [plugin],
1035
+ });
1036
+ }
1037
+ /**
1038
+ * Draw or update a G shape or group to the transient canvas.
1039
+ * @param type shape type or item type
1040
+ * @param id new shape id or updated shape id for a interation shape, node/edge/combo id for item interaction group drawing
1041
+ * @returns upserted shape or group
1042
+ * @group Interaction
1043
+ */
1044
+ drawTransient(type, id, config) {
1045
+ this.hooks.transientupdate.emit({
1046
+ type,
1047
+ id,
1048
+ config,
1049
+ canvas: this.transientCanvas,
1050
+ });
1051
+ return this.itemController.getTransient(String(id));
1052
+ }
1053
+ /**
1054
+ * Destroy the graph instance and remove the related canvases.
1055
+ * @returns
1056
+ * @group Graph Instance
1057
+ */
1058
+ destroy(callback) {
1059
+ // TODO: call the destroy functions after items' buildOut animations finished
1060
+ setTimeout(() => {
1061
+ this.canvas.destroy();
1062
+ this.backgroundCanvas.destroy();
1063
+ this.transientCanvas.destroy();
1064
+ callback === null || callback === void 0 ? void 0 : callback();
1065
+ }, 500);
1066
+ this.hooks.destroy.emit({});
1067
+ // TODO: destroy controllers and off the listeners
1068
+ // this.dataController.destroy();
1069
+ // this.interactionController.destroy();
1070
+ // this.layoutController.destroy();
1071
+ // this.themeController.destroy();
1072
+ // this.itemController.destroy();
1073
+ // this.extensionController.destroy();
1074
+ this.destroyed = true;
1075
+ }
1076
+ }
1077
+ //# sourceMappingURL=graph.js.map