@antv/g6 4.8.14 → 5.0.0-alpha.2

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,1439 @@
1
+ import EventEmitter from '@antv/event-emitter';
2
+ import { AABB, Canvas, DisplayObject, PointLike, runtime } from '@antv/g';
3
+ import { GraphChange, ID } from '@antv/graphlib';
4
+ import { isArray, isNil, isNumber, isObject, isString } from '@antv/util';
5
+ import {
6
+ ComboUserModel,
7
+ EdgeUserModel,
8
+ GraphData,
9
+ IGraph,
10
+ NodeUserModel,
11
+ Specification,
12
+ } from '../types';
13
+ import { CameraAnimationOptions } from '../types/animate';
14
+ import { BehaviorOptionsOf, BehaviorRegistry } from '../types/behavior';
15
+ import { ComboModel } from '../types/combo';
16
+ import { Padding, Point } from '../types/common';
17
+ import { DataChangeType, GraphCore } from '../types/data';
18
+ import { EdgeModel, EdgeModelData } from '../types/edge';
19
+ import { Hooks, ViewportChangeHookParams } from '../types/hook';
20
+ import { ITEM_TYPE, ShapeStyle, SHAPE_TYPE } from '../types/item';
21
+ import {
22
+ ImmediatelyInvokedLayoutOptions,
23
+ LayoutOptions,
24
+ StandardLayoutOptions,
25
+ } from '../types/layout';
26
+ import { NodeModel, NodeModelData } from '../types/node';
27
+ import { RendererName } from '../types/render';
28
+ import {
29
+ ThemeOptionsOf,
30
+ ThemeRegistry,
31
+ ThemeSpecification,
32
+ } from '../types/theme';
33
+ import { FitViewRules, GraphTransformOptions } from '../types/view';
34
+ import { changeRenderer, createCanvas } from '../util/canvas';
35
+ import { formatPadding } from '../util/shape';
36
+ import {
37
+ DataController,
38
+ ExtensionController,
39
+ InteractionController,
40
+ ItemController,
41
+ LayoutController,
42
+ ThemeController,
43
+ ViewportController,
44
+ } from './controller';
45
+ import { PluginController } from './controller/plugin';
46
+ import Hook from './hooks';
47
+
48
+ /**
49
+ * Disable CSS parsing for better performance.
50
+ */
51
+ runtime.enableCSSParsing = false;
52
+
53
+ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
54
+ extends EventEmitter
55
+ implements IGraph<B, T>
56
+ {
57
+ public hooks: Hooks;
58
+ // for nodes and edges, which will be separate into groups
59
+ public canvas: Canvas;
60
+ // the container dom for the graph canvas
61
+ public container: HTMLElement;
62
+ // the tag to indicate whether the graph instance is destroyed
63
+ public destroyed: boolean;
64
+ // the renderer type of current graph
65
+ public rendererType: RendererName;
66
+ // for transient shapes for interactions, e.g. transient node and related edges while draging, delegates
67
+ public transientCanvas: Canvas;
68
+ // for background shapes, e.g. grid, pipe indices
69
+ public backgroundCanvas: Canvas;
70
+ // the tag indicates all the three canvases are all ready
71
+ private canvasReady: boolean;
72
+ private specification: Specification<B, T>;
73
+ private dataController: DataController;
74
+ private interactionController: InteractionController;
75
+ private layoutController: LayoutController;
76
+ private viewportController: ViewportController;
77
+ private itemController: ItemController;
78
+ private extensionController: ExtensionController;
79
+ private themeController: ThemeController;
80
+ private pluginController: PluginController;
81
+
82
+ private defaultSpecification = {
83
+ theme: {
84
+ type: 'spec',
85
+ base: 'light',
86
+ },
87
+ };
88
+
89
+ constructor(spec: Specification<B, T>) {
90
+ super();
91
+ // TODO: analyse cfg
92
+
93
+ this.specification = Object.assign({}, this.defaultSpecification, spec);
94
+ this.initHooks();
95
+ this.initCanvas();
96
+ this.initControllers();
97
+
98
+ this.hooks.init.emit({
99
+ canvases: {
100
+ background: this.backgroundCanvas,
101
+ main: this.canvas,
102
+ transient: this.transientCanvas,
103
+ },
104
+ });
105
+
106
+ const { data } = spec;
107
+ if (data) {
108
+ // TODO: handle multiple type data configs
109
+ this.read(data as GraphData);
110
+ }
111
+ }
112
+
113
+ /**
114
+ * Initialize the controllers for different plugins.
115
+ */
116
+ private initControllers() {
117
+ this.dataController = new DataController(this);
118
+ this.interactionController = new InteractionController(this);
119
+ this.layoutController = new LayoutController(this);
120
+ this.themeController = new ThemeController(this);
121
+ this.itemController = new ItemController(this);
122
+ this.viewportController = new ViewportController(this);
123
+ this.extensionController = new ExtensionController(this);
124
+ this.pluginController = new PluginController(this);
125
+ }
126
+
127
+ private initCanvas() {
128
+ const { renderer, container, width, height } = this.specification;
129
+ let pixelRatio;
130
+ if (renderer && !isString(renderer)) {
131
+ // @ts-ignore
132
+ this.rendererType = renderer.type || 'canvas';
133
+ // @ts-ignore
134
+ pixelRatio = renderer.pixelRatio;
135
+ } else {
136
+ // @ts-ignore
137
+ this.rendererType = renderer || 'canvas';
138
+ }
139
+ const containerDOM = isString(container)
140
+ ? document.getElementById(container as string)
141
+ : container;
142
+ if (!containerDOM) {
143
+ console.error(
144
+ `Create graph failed. The container for graph ${containerDOM} is not exist.`,
145
+ );
146
+ this.destroy();
147
+ return;
148
+ }
149
+ this.container = containerDOM;
150
+ const size = [width, height];
151
+ if (size[0] === undefined) {
152
+ size[0] = containerDOM.scrollWidth;
153
+ }
154
+ if (size[1] === undefined) {
155
+ size[1] = containerDOM.scrollHeight;
156
+ }
157
+
158
+ this.backgroundCanvas = createCanvas(
159
+ this.rendererType,
160
+ containerDOM,
161
+ size[0],
162
+ size[1],
163
+ pixelRatio,
164
+ );
165
+ this.canvas = createCanvas(
166
+ this.rendererType,
167
+ containerDOM,
168
+ size[0],
169
+ size[1],
170
+ pixelRatio,
171
+ );
172
+ this.transientCanvas = createCanvas(
173
+ this.rendererType,
174
+ containerDOM,
175
+ size[0],
176
+ size[1],
177
+ pixelRatio,
178
+ true,
179
+ {
180
+ pointerEvents: 'none',
181
+ },
182
+ );
183
+ Promise.all(
184
+ [this.backgroundCanvas, this.canvas, this.transientCanvas].map(
185
+ (canvas) => canvas.ready,
186
+ ),
187
+ ).then(() => (this.canvasReady = true));
188
+ }
189
+
190
+ /**
191
+ * Change the renderer at runtime.
192
+ * @param type renderer name
193
+ * @returns
194
+ */
195
+ public changeRenderer(type) {
196
+ this.rendererType = type || 'canvas';
197
+ changeRenderer(this.rendererType, this.canvas);
198
+ }
199
+
200
+ /**
201
+ * Initialize the hooks for graph's lifecycles.
202
+ */
203
+ private initHooks() {
204
+ this.hooks = {
205
+ init: new Hook<{
206
+ canvases: {
207
+ background: Canvas;
208
+ main: Canvas;
209
+ transient: Canvas;
210
+ };
211
+ }>({ name: 'init' }),
212
+ datachange: new Hook<{ data: GraphData; type: DataChangeType }>({
213
+ name: 'datachange',
214
+ }),
215
+ itemchange: new Hook<{
216
+ type: ITEM_TYPE;
217
+ changes: GraphChange<NodeModelData, EdgeModelData>[];
218
+ graphCore: GraphCore;
219
+ theme: ThemeSpecification;
220
+ }>({ name: 'itemchange' }),
221
+ render: new Hook<{
222
+ graphCore: GraphCore;
223
+ theme: ThemeSpecification;
224
+ transientCanvas: Canvas;
225
+ }>({
226
+ name: 'render',
227
+ }),
228
+ layout: new Hook<{ graphCore: GraphCore }>({ name: 'layout' }),
229
+ viewportchange: new Hook<ViewportChangeHookParams>({ name: 'viewport' }),
230
+ modechange: new Hook<{ mode: string }>({ name: 'modechange' }),
231
+ behaviorchange: new Hook<{
232
+ action: 'update' | 'add' | 'remove';
233
+ modes: string[];
234
+ behaviors: (string | BehaviorOptionsOf<{}>)[];
235
+ }>({ name: 'behaviorchange' }),
236
+ itemstatechange: new Hook<{
237
+ ids: ID[];
238
+ states?: string[];
239
+ value?: boolean;
240
+ }>({
241
+ name: 'itemstatechange',
242
+ }),
243
+ itemvisibilitychange: new Hook<{ ids: ID[]; value: boolean }>({
244
+ name: 'itemvisibilitychange',
245
+ }),
246
+ transientupdate: new Hook<{
247
+ type: ITEM_TYPE | SHAPE_TYPE;
248
+ id: ID;
249
+ config: {
250
+ style: ShapeStyle;
251
+ action: 'remove' | 'add' | 'update' | undefined;
252
+ };
253
+ canvas: Canvas;
254
+ }>({ name: 'transientupdate' }),
255
+ pluginchange: new Hook<{
256
+ action: 'update' | 'add' | 'remove';
257
+ plugins: (
258
+ | string
259
+ | { key: string; type: string; [cfgName: string]: unknown }
260
+ )[];
261
+ }>({ name: 'pluginchange' }),
262
+ themechange: new Hook<{
263
+ theme: ThemeSpecification;
264
+ canvases: {
265
+ background: Canvas;
266
+ main: Canvas;
267
+ transient: Canvas;
268
+ };
269
+ }>({ name: 'init' }),
270
+ destroy: new Hook<{}>({ name: 'destroy' }),
271
+ };
272
+ }
273
+
274
+ /**
275
+ * Update the specs(configurations).
276
+ */
277
+ public updateSpecification(spec: Specification<B, T>): Specification<B, T> {
278
+ return Object.assign(this.specification, spec);
279
+ }
280
+
281
+ /**
282
+ * Update the theme specs (configurations).
283
+ */
284
+ public updateTheme(theme: ThemeOptionsOf<T>) {
285
+ this.specification.theme = theme;
286
+ // const { specification } = this.themeController;
287
+ // notifiying the themeController
288
+ this.hooks.themechange.emit({
289
+ canvases: {
290
+ background: this.backgroundCanvas,
291
+ main: this.canvas,
292
+ transient: this.transientCanvas,
293
+ },
294
+ });
295
+ // theme is formatted by themeController, notify the item controller to update the items
296
+ this.hooks.themechange.emit({
297
+ theme: this.themeController.specification,
298
+ });
299
+ }
300
+
301
+ /**
302
+ * Get the copy of specs(configurations).
303
+ * @returns graph specs
304
+ */
305
+ public getSpecification(): Specification<B, T> {
306
+ return this.specification;
307
+ }
308
+
309
+ /**
310
+ * Input data and render the graph.
311
+ * If there is old data, diffs and changes it.
312
+ * @param data
313
+ * @returns
314
+ * @group Data
315
+ */
316
+ public async read(data: GraphData) {
317
+ this.hooks.datachange.emit({ data, type: 'replace' });
318
+ const emitRender = async () => {
319
+ this.hooks.render.emit({
320
+ graphCore: this.dataController.graphCore,
321
+ theme: this.themeController.specification,
322
+ transientCanvas: this.transientCanvas,
323
+ });
324
+ this.emit('afterrender');
325
+
326
+ await this.layout();
327
+ };
328
+ if (this.canvasReady) {
329
+ await emitRender();
330
+ } else {
331
+ await Promise.all(
332
+ [this.backgroundCanvas, this.canvas, this.transientCanvas].map(
333
+ (canvas) => canvas.ready,
334
+ ),
335
+ );
336
+ await emitRender();
337
+ }
338
+ }
339
+
340
+ /**
341
+ * Change graph data.
342
+ * @param data new data
343
+ * @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)
344
+ * @returns
345
+ * @group Data
346
+ */
347
+ public async changeData(
348
+ data: GraphData,
349
+ type: 'replace' | 'mergeReplace' = 'mergeReplace',
350
+ ) {
351
+ this.hooks.datachange.emit({ data, type });
352
+ this.hooks.render.emit({
353
+ graphCore: this.dataController.graphCore,
354
+ theme: this.themeController.specification,
355
+ transientCanvas: this.transientCanvas,
356
+ });
357
+ this.emit('afterrender');
358
+
359
+ await this.layout();
360
+ }
361
+
362
+ /**
363
+ * Clear the graph, means remove all the items on the graph.
364
+ * @returns
365
+ */
366
+ public clear() {
367
+ // TODO
368
+ }
369
+
370
+ public getViewportCenter(): PointLike {
371
+ const { width, height } = this.canvas.getConfig();
372
+ return { x: width! / 2, y: height! / 2 };
373
+ }
374
+ public async transform(
375
+ options: GraphTransformOptions,
376
+ effectTiming?: CameraAnimationOptions,
377
+ ): Promise<void> {
378
+ await this.hooks.viewportchange.emitLinearAsync({
379
+ transform: options,
380
+ effectTiming,
381
+ });
382
+ this.emit('viewportchange', options);
383
+ }
384
+
385
+ /**
386
+ * Stop the current transition of transform immediately.
387
+ */
388
+ public stopTransformTransition() {
389
+ this.canvas.getCamera().cancelLandmarkAnimation();
390
+ }
391
+
392
+ /**
393
+ * Move the graph with a relative distance under viewport coordinates.
394
+ * @param dx x of the relative distance
395
+ * @param dy y of the relative distance
396
+ * @param effectTiming animation configurations
397
+ */
398
+ public async translate(
399
+ distance: Partial<{
400
+ dx: number;
401
+ dy: number;
402
+ dz: number;
403
+ }>,
404
+ effectTiming?: CameraAnimationOptions,
405
+ ) {
406
+ await this.transform(
407
+ {
408
+ translate: distance,
409
+ },
410
+ effectTiming,
411
+ );
412
+ }
413
+
414
+ /**
415
+ * Move the graph to destination under viewport coordinates.
416
+ * @param destination destination under viewport coordinates.
417
+ * @param effectTiming animation configurations
418
+ */
419
+ public async translateTo(
420
+ { x, y }: PointLike,
421
+ effectTiming?: CameraAnimationOptions,
422
+ ) {
423
+ const { x: cx, y: cy } = this.getViewportCenter();
424
+ await this.translate({ dx: cx - x, dy: cy - y }, effectTiming);
425
+ }
426
+
427
+ /**
428
+ * Zoom the graph with a relative ratio.
429
+ * @param ratio relative ratio to zoom
430
+ * @param origin origin under viewport coordinates.
431
+ * @param effectTiming animation configurations
432
+ */
433
+ public async zoom(
434
+ ratio: number,
435
+ origin?: PointLike,
436
+ effectTiming?: CameraAnimationOptions,
437
+ ) {
438
+ await this.transform(
439
+ {
440
+ zoom: {
441
+ ratio,
442
+ },
443
+ origin,
444
+ },
445
+ effectTiming,
446
+ );
447
+ }
448
+
449
+ /**
450
+ * Zoom the graph to a specified ratio.
451
+ * @param zoom specified ratio
452
+ * @param origin zoom center
453
+ * @param effectTiming animation configurations
454
+ */
455
+ public async zoomTo(
456
+ zoom: number,
457
+ origin?: PointLike,
458
+ effectTiming?: CameraAnimationOptions,
459
+ ) {
460
+ await this.zoom(
461
+ zoom / this.canvas.getCamera().getZoom(),
462
+ origin,
463
+ effectTiming,
464
+ );
465
+ }
466
+
467
+ /**
468
+ * Return the current zoom level of camera.
469
+ * @returns current zoom
470
+ */
471
+ public getZoom() {
472
+ return this.canvas.getCamera().getZoom();
473
+ }
474
+
475
+ /**
476
+ * Rotate the graph with a relative angle.
477
+ * @param angle
478
+ * @param origin
479
+ * @param effectTiming
480
+ */
481
+ public async rotate(
482
+ angle: number,
483
+ origin?: PointLike,
484
+ effectTiming?: CameraAnimationOptions,
485
+ ) {
486
+ await this.transform(
487
+ {
488
+ rotate: {
489
+ angle,
490
+ },
491
+ origin,
492
+ },
493
+ effectTiming,
494
+ );
495
+ }
496
+
497
+ /**
498
+ * Rotate the graph to an absolute angle.
499
+ * @param angle
500
+ * @param origin
501
+ * @param effectTiming
502
+ */
503
+ public async rotateTo(
504
+ angle: number,
505
+ origin?: PointLike,
506
+ effectTiming?: CameraAnimationOptions,
507
+ ) {
508
+ await this.rotate(
509
+ angle - this.canvas.getCamera().getRoll(),
510
+ origin,
511
+ effectTiming,
512
+ );
513
+ }
514
+
515
+ /**
516
+ * Fit the graph content to the view.
517
+ * @param options.padding padding while fitting
518
+ * @param options.rules rules for fitting
519
+ * @param effectTiming animation configurations
520
+ */
521
+ public async fitView(
522
+ options?: {
523
+ padding: Padding;
524
+ rules: FitViewRules;
525
+ },
526
+ effectTiming?: CameraAnimationOptions,
527
+ ) {
528
+ const { padding, rules } = options || {};
529
+ const [top, right, bottom, left] = padding
530
+ ? formatPadding(padding)
531
+ : [0, 0, 0, 0];
532
+ const { direction = 'both', ratioRule = 'min' } = rules || {};
533
+
534
+ // Get the bounds of the whole graph.
535
+ const {
536
+ center: [graphCenterX, graphCenterY],
537
+ halfExtents,
538
+ } = this.canvas.document.documentElement.getBounds();
539
+ const origin = this.canvas.canvas2Viewport({
540
+ x: graphCenterX,
541
+ y: graphCenterY,
542
+ });
543
+ const { width: viewportWidth, height: viewportHeight } =
544
+ this.canvas.getConfig();
545
+
546
+ const graphWidth = halfExtents[0] * 2;
547
+ const graphHeight = halfExtents[1] * 2;
548
+ const tlInCanvas = this.canvas.viewport2Canvas({ x: left, y: top });
549
+ const brInCanvas = this.canvas.viewport2Canvas({
550
+ x: viewportWidth! - right,
551
+ y: viewportHeight! - bottom,
552
+ });
553
+
554
+ const targetViewWidth = brInCanvas.x - tlInCanvas.x;
555
+ const targetViewHeight = brInCanvas.y - tlInCanvas.y;
556
+
557
+ const wRatio = targetViewWidth / graphWidth;
558
+ const hRatio = targetViewHeight / graphHeight;
559
+
560
+ let ratio: number;
561
+ if (direction === 'x') {
562
+ ratio = wRatio;
563
+ } else if (direction === 'y') {
564
+ ratio = hRatio;
565
+ } else {
566
+ ratio =
567
+ ratioRule === 'max'
568
+ ? Math.max(wRatio, hRatio)
569
+ : Math.min(wRatio, hRatio);
570
+ }
571
+
572
+ await this.transform(
573
+ {
574
+ translate: {
575
+ dx: viewportWidth! / 2 - origin.x,
576
+ dy: viewportHeight! / 2 - origin.y,
577
+ },
578
+ zoom: {
579
+ ratio,
580
+ },
581
+ },
582
+ effectTiming,
583
+ );
584
+ }
585
+ /**
586
+ * Fit the graph center to the view center.
587
+ * @param effectTiming animation configurations
588
+ */
589
+ public async fitCenter(effectTiming?: CameraAnimationOptions) {
590
+ // Get the bounds of the whole graph.
591
+ const {
592
+ center: [graphCenterX, graphCenterY],
593
+ } = this.canvas.document.documentElement.getBounds();
594
+ await this.translateTo(
595
+ this.canvas.canvas2Viewport({ x: graphCenterX, y: graphCenterY }),
596
+ effectTiming,
597
+ );
598
+ }
599
+ /**
600
+ * Move the graph to make the item align the view center.
601
+ * @param item node/edge/combo item or its id
602
+ * @param effectTiming animation configurations
603
+ */
604
+ public async focusItem(id: ID | ID[], effectTiming?: CameraAnimationOptions) {
605
+ let bounds: AABB | null = null;
606
+ for (const itemId of !isArray(id) ? [id] : id) {
607
+ const item = this.itemController.getItemById(itemId);
608
+ if (item) {
609
+ const itemBounds = item.group.getBounds();
610
+ if (!bounds) {
611
+ bounds = itemBounds;
612
+ } else {
613
+ bounds.add(itemBounds);
614
+ }
615
+ }
616
+ }
617
+
618
+ if (bounds) {
619
+ const {
620
+ center: [itemCenterX, itemCenterY],
621
+ } = bounds;
622
+ await this.translateTo(
623
+ this.canvas.canvas2Viewport({ x: itemCenterX, y: itemCenterY }),
624
+ effectTiming,
625
+ );
626
+ }
627
+ }
628
+
629
+ /**
630
+ * Get the size of the graph canvas.
631
+ * @returns [width, height]
632
+ * @group View
633
+ */
634
+ public getSize(): number[] {
635
+ const { width = 500, height = 500 } = this.specification;
636
+ return [width, height];
637
+ }
638
+
639
+ /**
640
+ * Set the size for the graph canvas.
641
+ * @param number[] [width, height]
642
+ * @group View
643
+ */
644
+ public setSize(size: number[]) {
645
+ if (!isArray(size) || size.length < 2) {
646
+ console.warn(
647
+ `Failed to setSize. The parameter size: ${size} is invalid. It must be an array with 2 number elements.`,
648
+ );
649
+ return;
650
+ }
651
+ this.specification.width = size[0];
652
+ this.specification.height = size[1];
653
+ this.canvas.resize(size[0], size[1]);
654
+ }
655
+
656
+ /**
657
+ * Get the rendering coordinate according to the canvas dom (viewport) coordinate.
658
+ * @param Point rendering coordinate
659
+ * @returns canvas dom (viewport) coordinate
660
+ * @group View
661
+ */
662
+ public getCanvasByViewport(viewportPoint: Point): Point {
663
+ return this.canvas.viewport2Canvas(viewportPoint);
664
+ }
665
+
666
+ /**
667
+ * Get the canvas dom (viewport) coordinate according to the rendering coordinate.
668
+ * @param Point canvas dom (viewport) coordinate
669
+ * @returns rendering coordinate
670
+ * @group View
671
+ */
672
+ public getViewportByCanvas(canvasPoint: Point): Point {
673
+ return this.canvas.canvas2Viewport(canvasPoint);
674
+ }
675
+
676
+ /**
677
+ * Get the browser coordinate according to the rendering coordinate.
678
+ * @param Point rendering coordinate
679
+ * @returns browser coordinate
680
+ * @group View
681
+ */
682
+ public getClientByCanvas(canvasPoint: Point): Point {
683
+ const viewportPoint = this.canvas.canvas2Viewport(canvasPoint);
684
+ return this.canvas.viewport2Client(viewportPoint as any);
685
+ }
686
+
687
+ /**
688
+ * Get the rendering coordinate according to the browser coordinate.
689
+ * @param Point browser coordinate
690
+ * @returns rendering coordinate
691
+ * @group View
692
+ */
693
+ public getCanvasByClient(clientPoint: Point): Point {
694
+ const viewportPoint = this.canvas.client2Viewport(clientPoint);
695
+ return this.canvas.viewport2Canvas(viewportPoint as any);
696
+ }
697
+
698
+ // ===== item operations =====
699
+ /**
700
+ * Find a node's inner data according to id or function.
701
+ * @param { ID | Function } condition id or condition function
702
+ * @returns result node's inner data
703
+ * @group Data
704
+ */
705
+ public getNodeData(condition: ID | Function): NodeModel | undefined {
706
+ const conds =
707
+ isString(condition) || isNumber(condition) ? [condition] : condition;
708
+ return this.dataController.findData('node', conds)?.[0] as NodeModel;
709
+ }
710
+ /**
711
+ * Find an edge's inner data according to id or function.
712
+ * @param { ID | Function } condition id or condition function
713
+ * @returns result edge's inner data
714
+ * @group Data
715
+ */
716
+ public getEdgeData(condition: ID | Function): EdgeModel | undefined {
717
+ const conds =
718
+ isString(condition) || isNumber(condition) || isNumber(condition)
719
+ ? [condition]
720
+ : condition;
721
+ return this.dataController.findData('edge', conds)?.[0] as EdgeModel;
722
+ }
723
+ /**
724
+ * Find an combo's inner data according to id or function.
725
+ * @param { ID | Function } condition id or condition function
726
+ * @returns result combo's inner data
727
+ * @group Data
728
+ */
729
+ public getComboData(condition: ID | Function): ComboModel | undefined {
730
+ const conds =
731
+ isString(condition) || isNumber(condition) ? [condition] : condition;
732
+ return this.dataController.findData('combo', conds)?.[0] as ComboModel;
733
+ }
734
+ /**
735
+ * Get all the nodes' inner data
736
+ * @returns all nodes' inner data on the graph
737
+ * @group Data
738
+ */
739
+ public getAllNodesData(): NodeModel[] {
740
+ return this.dataController.findAllData('node');
741
+ }
742
+ /**
743
+ * Get all the edges' inner data
744
+ * @returns all edges' inner data on the graph
745
+ * @group Data
746
+ */
747
+ public getAllEdgesData(): EdgeModel[] {
748
+ return this.dataController.findAllData('edge') as EdgeModel[];
749
+ }
750
+ /**
751
+ * Get all the combos' inner data
752
+ * @returns all combos' inner data on the graph
753
+ * @group Data
754
+ */
755
+ public getAllCombosData(): ComboModel[] {
756
+ return this.dataController.findAllData('combo') as ComboModel[];
757
+ }
758
+ /**
759
+ * Get one-hop edge ids from a start node.
760
+ * @param nodeId id of the start node
761
+ * @returns one-hop edge ids
762
+ * @group Data
763
+ */
764
+ public getRelatedEdgesData(
765
+ nodeId: ID,
766
+ direction: 'in' | 'out' | 'both' = 'both',
767
+ ): EdgeModel[] {
768
+ return this.dataController.findRelatedEdgeIds(nodeId, direction);
769
+ }
770
+ /**
771
+ * Get one-hop node ids from a start node.
772
+ * @param nodeId id of the start node
773
+ * @returns one-hop node ids
774
+ * @group Data
775
+ */
776
+ public getNeighborNodesData(
777
+ nodeId: ID,
778
+ direction: 'in' | 'out' | 'both' = 'both',
779
+ ): NodeModel[] {
780
+ return this.dataController.findNeighborNodeIds(nodeId, direction);
781
+ }
782
+
783
+ /**
784
+ * Find items which has the state.
785
+ * @param itemType item type
786
+ * @param state state name
787
+ * @param additionalFilter additional filter function
788
+ * @returns items that is the type and has the state
789
+ * @group Item
790
+ */
791
+ public findIdByState(
792
+ itemType: ITEM_TYPE,
793
+ state: string,
794
+ value: string | boolean = true,
795
+ additionalFilter?: (item: NodeModel | EdgeModel | ComboModel) => boolean,
796
+ ): ID[] {
797
+ let ids = this.itemController.findIdByState(itemType, state, value);
798
+ if (additionalFilter) {
799
+ const getDataFunc =
800
+ itemType === 'node' ? this.getNodeData : this.getEdgeData; // TODO: combo
801
+ ids = ids.filter((id) => additionalFilter(getDataFunc(id)));
802
+ }
803
+ return ids;
804
+ }
805
+ /**
806
+ * Add one or more node/edge/combo data to the graph.
807
+ * @param itemType item type
808
+ * @param model user data
809
+ * @param stack whether push this operation to stack
810
+ * @returns whether success
811
+ * @group Data
812
+ */
813
+ public addData(
814
+ itemType: ITEM_TYPE,
815
+ models:
816
+ | NodeUserModel
817
+ | EdgeUserModel
818
+ | ComboUserModel
819
+ | NodeUserModel[]
820
+ | EdgeUserModel[]
821
+ | ComboUserModel[],
822
+ stack?: boolean,
823
+ ):
824
+ | NodeModel
825
+ | EdgeModel
826
+ | ComboModel
827
+ | NodeModel[]
828
+ | EdgeModel[]
829
+ | ComboModel[] {
830
+ // data controller and item controller subscribe additem in order
831
+
832
+ const { graphCore } = this.dataController;
833
+ const { specification } = this.themeController;
834
+ graphCore.once('changed', (event) => {
835
+ if (!event.changes.length) return;
836
+ this.hooks.itemchange.emit({
837
+ type: itemType,
838
+ changes: graphCore.reduceChanges(event.changes),
839
+ graphCore,
840
+ theme: specification,
841
+ });
842
+ this.emit('afteritemchange', { type: itemType, action: 'add', models });
843
+ });
844
+
845
+ const modelArr = isArray(models) ? models : [models];
846
+ const data = { nodes: [], edges: [], combos: [] };
847
+ data[`${itemType}s`] = modelArr;
848
+ this.hooks.datachange.emit({
849
+ data,
850
+ type: 'union',
851
+ });
852
+ const dataList = this.dataController.findData(
853
+ itemType,
854
+ modelArr.map((model) => model.id),
855
+ );
856
+ return isArray(models) ? dataList : dataList[0];
857
+ }
858
+ /**
859
+ * Remove one or more node/edge/combo data from the graph.
860
+ * @param item the item to be removed
861
+ * @param stack whether push this operation to stack
862
+ * @returns whether success
863
+ * @group Data
864
+ */
865
+ public removeData(itemType: ITEM_TYPE, ids: ID | ID[], stack?: boolean) {
866
+ const idArr = isArray(ids) ? ids : [ids];
867
+ const data = { nodes: [], edges: [], combos: [] };
868
+ const { userGraphCore, graphCore } = this.dataController;
869
+ const { specification } = this.themeController;
870
+ const getItem =
871
+ itemType === 'edge' ? userGraphCore.getEdge : userGraphCore.getNode; // TODO: combo
872
+ data[`${itemType}s`] = idArr.map((id) => getItem.bind(userGraphCore)(id));
873
+ graphCore.once('changed', (event) => {
874
+ if (!event.changes.length) return;
875
+ this.hooks.itemchange.emit({
876
+ type: itemType,
877
+ changes: event.changes,
878
+ graphCore,
879
+ theme: specification,
880
+ });
881
+ this.emit('afteritemchange', { type: itemType, action: 'remove', ids });
882
+ });
883
+ this.hooks.datachange.emit({
884
+ data,
885
+ type: 'remove',
886
+ });
887
+ }
888
+ /**
889
+ * Update one or more node/edge/combo data on the graph.
890
+ * @param {ITEM_TYPE} itemType 'node' | 'edge' | 'combo'
891
+ * @param models new configurations for every node/edge/combo, which has id field to indicate the specific item
892
+ * @param {boolean} stack whether push this operation into graph's stack, true by default
893
+ * @group Data
894
+ */
895
+ public updateData(
896
+ itemType: ITEM_TYPE,
897
+ models:
898
+ | Partial<NodeUserModel>
899
+ | Partial<EdgeUserModel>
900
+ | Partial<
901
+ | ComboUserModel
902
+ | Partial<NodeUserModel>[]
903
+ | Partial<EdgeUserModel>[]
904
+ | Partial<ComboUserModel>[]
905
+ >,
906
+ stack?: boolean,
907
+ ):
908
+ | NodeModel
909
+ | EdgeModel
910
+ | ComboModel
911
+ | NodeModel[]
912
+ | EdgeModel[]
913
+ | ComboModel[] {
914
+ const modelArr = isArray(models) ? models : [models];
915
+ const data = { nodes: [], edges: [], combos: [] };
916
+ data[`${itemType}s`] = modelArr;
917
+
918
+ const { graphCore } = this.dataController;
919
+ const { specification } = this.themeController;
920
+ graphCore.once('changed', (event) => {
921
+ this.hooks.itemchange.emit({
922
+ type: itemType,
923
+ changes: event.changes,
924
+ graphCore,
925
+ theme: specification,
926
+ });
927
+ this.emit('afteritemchange', {
928
+ type: itemType,
929
+ action: 'update',
930
+ models,
931
+ });
932
+ });
933
+
934
+ this.hooks.datachange.emit({
935
+ data,
936
+ type: 'update',
937
+ });
938
+ const dataList = this.dataController.findData(
939
+ itemType,
940
+ modelArr.map((model) => model.id),
941
+ );
942
+ return isArray(models) ? dataList : dataList[0];
943
+ }
944
+
945
+ /**
946
+ * Update one or more nodes' positions,
947
+ * do not update other styles which leads to better performance than updating positions by updateData.
948
+ * @param models new configurations with x and y for every node, which has id field to indicate the specific item
949
+ * @param {boolean} stack whether push this operation into graph's stack, true by default
950
+ * @group Data
951
+ */
952
+ public updateNodePosition(
953
+ models:
954
+ | Partial<NodeUserModel>
955
+ | Partial<
956
+ ComboUserModel | Partial<NodeUserModel>[] | Partial<ComboUserModel>[]
957
+ >,
958
+ stack?: boolean,
959
+ ) {
960
+ const modelArr = isArray(models) ? models : [models];
961
+ const { graphCore } = this.dataController;
962
+ const { specification } = this.themeController;
963
+ graphCore.once('changed', (event) => {
964
+ if (!event.changes.length) return;
965
+ this.hooks.itemchange.emit({
966
+ type: 'node',
967
+ changes: event.changes,
968
+ graphCore,
969
+ theme: specification,
970
+ action: 'updateNodePosition',
971
+ });
972
+ this.emit('afteritemchange', {
973
+ type: 'node',
974
+ action: 'updateNodePosition',
975
+ models,
976
+ });
977
+ });
978
+
979
+ this.hooks.datachange.emit({
980
+ data: {
981
+ nodes: modelArr as NodeUserModel[],
982
+ edges: [],
983
+ },
984
+ type: 'update',
985
+ });
986
+ const dataList = this.dataController.findData(
987
+ 'node',
988
+ modelArr.map((model) => model.id),
989
+ );
990
+ return isArray(models) ? dataList : dataList[0];
991
+ }
992
+ /**
993
+ * Show the item(s).
994
+ * @param item the item to be shown
995
+ * @returns
996
+ * @group Item
997
+ */
998
+ public showItem(ids: ID | ID[], disableAniamte?: boolean) {
999
+ const idArr = isArray(ids) ? ids : [ids];
1000
+ this.hooks.itemvisibilitychange.emit({
1001
+ ids: idArr as ID[],
1002
+ value: true,
1003
+ animate: !disableAniamte,
1004
+ });
1005
+ }
1006
+ /**
1007
+ * Hide the item(s).
1008
+ * @param item the item to be hidden
1009
+ * @returns
1010
+ * @group Item
1011
+ */
1012
+ public hideItem(ids: ID | ID[], disableAniamte?: boolean) {
1013
+ const idArr = isArray(ids) ? ids : [ids];
1014
+ this.hooks.itemvisibilitychange.emit({
1015
+ ids: idArr as ID[],
1016
+ value: false,
1017
+ animate: !disableAniamte,
1018
+ });
1019
+ }
1020
+ /**
1021
+ * Set state for the item.
1022
+ * @param item the item to be set
1023
+ * @param state the state name
1024
+ * @param value state value
1025
+ * @returns
1026
+ * @group Item
1027
+ */
1028
+ public setItemState(
1029
+ ids: ID | ID[],
1030
+ states: string | string[],
1031
+ value: boolean,
1032
+ ) {
1033
+ const idArr = isArray(ids) ? ids : [ids];
1034
+ const stateArr = isArray(states) ? states : [states];
1035
+ this.hooks.itemstatechange.emit({
1036
+ ids: idArr as ID[],
1037
+ states: stateArr as string[],
1038
+ value,
1039
+ });
1040
+ this.emit('afteritemstatechange', { ids, states, value });
1041
+ }
1042
+ /**
1043
+ * Get the state value for an item.
1044
+ * @param id the id for the item
1045
+ * @param states the state name
1046
+ * @returns {boolean} the state value
1047
+ * @group Item
1048
+ */
1049
+ public getItemState(id: ID, state: string) {
1050
+ return this.itemController.getItemState(id, state);
1051
+ }
1052
+
1053
+ /**
1054
+ * Clear all the states for item(s).
1055
+ * @param ids the id(s) for the item(s) to be clear
1056
+ * @param states the states' names, all the states wil be cleared if states is not assigned
1057
+ * @returns
1058
+ * @group Item
1059
+ */
1060
+ public clearItemState(ids: ID | ID[], states?: string[]) {
1061
+ const idArr = isArray(ids) ? ids : [ids];
1062
+ this.hooks.itemstatechange.emit({
1063
+ ids: idArr as ID[],
1064
+ states,
1065
+ value: false,
1066
+ });
1067
+ this.emit('afteritemstatechange', { ids, states, value: false });
1068
+ }
1069
+
1070
+ /**
1071
+ * Get the rendering bbox for a node / edge / combo, or the graph (when the id is not assigned).
1072
+ * @param id the id for the node / edge / combo, undefined for the whole graph
1073
+ * @returns rendering bounding box. returns false if the item is not exist
1074
+ * @group Item
1075
+ */
1076
+ public getRenderBBox(id: ID | undefined): AABB | false {
1077
+ if (!id) return this.canvas.getRoot().getRenderBounds();
1078
+ return this.itemController.getItemBBox(id);
1079
+ }
1080
+
1081
+ /**
1082
+ * Get the visibility for a node / edge / combo.
1083
+ * @param id the id for the node / edge / combo
1084
+ * @returns visibility for the item, false for invisible or unexistence for the item
1085
+ * @group Item
1086
+ */
1087
+ public getItemVisible(id: ID) {
1088
+ return this.itemController.getItemVisible(id);
1089
+ }
1090
+
1091
+ // ===== combo operations =====
1092
+ /**
1093
+ * Create a new combo with existing child nodes and combos.
1094
+ * @param combo combo ID or Combo model
1095
+ * @param childrenIds id array of children of the new combo
1096
+ * @group Combo
1097
+ */
1098
+ public createCombo(
1099
+ combo: string | ComboUserModel,
1100
+ childrenIds: string[],
1101
+ stack?: boolean,
1102
+ ) {
1103
+ // TODO
1104
+ }
1105
+ /**
1106
+ * dissolve combo
1107
+ * @param {String | ICombo} item combo item or id to be dissolve
1108
+ * @group Combo
1109
+ */
1110
+ public uncombo(comboId: ID, stack?: boolean) {
1111
+ // TODO
1112
+ }
1113
+ /**
1114
+ * Collapse a combo.
1115
+ * @param comboId combo id or item
1116
+ * @group Combo
1117
+ */
1118
+ public collapseCombo(comboId: ID, stack?: boolean) {
1119
+ // TODO
1120
+ }
1121
+ /**
1122
+ * Expand a combo.
1123
+ * @param combo combo ID 或 combo 实例
1124
+ * @group Combo
1125
+ */
1126
+ public expandCombo(comboId: ID, stack?: boolean) {
1127
+ // TODO
1128
+ }
1129
+
1130
+ // ===== layout =====
1131
+ /**
1132
+ * Layout the graph (with current configurations if cfg is not assigned).
1133
+ */
1134
+ public async layout(options?: LayoutOptions) {
1135
+ const { graphCore } = this.dataController;
1136
+ const formattedOptions = {
1137
+ ...this.getSpecification().layout,
1138
+ ...options,
1139
+ } as LayoutOptions;
1140
+
1141
+ const layoutUnset = !options && !this.getSpecification().layout;
1142
+ if (layoutUnset) {
1143
+ const nodes = graphCore.getAllNodes();
1144
+ if (nodes.every((node) => isNil(node.data.x) && isNil(node.data.y))) {
1145
+ // Use `grid` layout as default when x/y of each node is unset.
1146
+ (formattedOptions as StandardLayoutOptions).type = 'grid';
1147
+ } else {
1148
+ // Use user-defined position(x/y default to 0).
1149
+ (formattedOptions as ImmediatelyInvokedLayoutOptions).execute = async (
1150
+ graph,
1151
+ ) => {
1152
+ const nodes = graph.getAllNodes();
1153
+ return {
1154
+ nodes: nodes.map((node) => ({
1155
+ id: node.id,
1156
+ data: {
1157
+ x: Number(node.data.x) || 0,
1158
+ y: Number(node.data.y) || 0,
1159
+ },
1160
+ })),
1161
+ edges: [],
1162
+ };
1163
+ };
1164
+ }
1165
+ }
1166
+
1167
+ await this.hooks.layout.emitLinearAsync({
1168
+ graphCore,
1169
+ options: formattedOptions,
1170
+ });
1171
+ this.emit('afterlayout');
1172
+ }
1173
+
1174
+ /**
1175
+ * Some layout algorithms has many iterations which can be stopped at any time.
1176
+ */
1177
+ public stopLayout() {
1178
+ this.layoutController.stopLayout();
1179
+ }
1180
+
1181
+ /**
1182
+ * Switch mode.
1183
+ * @param mode mode name
1184
+ * @returns
1185
+ * @group Interaction
1186
+ */
1187
+ public setMode(mode: string) {
1188
+ this.hooks.modechange.emit({ mode });
1189
+ }
1190
+
1191
+ /**
1192
+ * Add behavior(s) to mode(s).
1193
+ * @param behaviors behavior names or configs
1194
+ * @param modes mode names
1195
+ * @returns
1196
+ * @group Interaction
1197
+ */
1198
+ public addBehaviors(
1199
+ behaviors: BehaviorOptionsOf<B>[],
1200
+ modes: string | string[],
1201
+ ) {
1202
+ const modesArr = isArray(modes) ? modes : [modes];
1203
+ const behaviorsArr = isArray(behaviors) ? behaviors : [behaviors];
1204
+ this.hooks.behaviorchange.emit({
1205
+ action: 'add',
1206
+ modes: modesArr,
1207
+ // TODO: update type define.
1208
+ // @ts-ignore
1209
+ behaviors: behaviorsArr,
1210
+ });
1211
+ // update the graph specification
1212
+ modesArr.forEach((mode) => {
1213
+ this.specification.modes[mode] =
1214
+ this.specification.modes[mode].concat(behaviorsArr);
1215
+ });
1216
+ }
1217
+ /**
1218
+ * Remove behavior(s) from mode(s).
1219
+ * @param behaviors behavior configs with unique key
1220
+ * @param modes mode names
1221
+ * @returns
1222
+ * @group Interaction
1223
+ */
1224
+ public removeBehaviors(behaviorKeys: string[], modes: string | string[]) {
1225
+ const modesArr = isArray(modes) ? modes : [modes];
1226
+ this.hooks.behaviorchange.emit({
1227
+ action: 'remove',
1228
+ modes: modesArr,
1229
+ behaviors: behaviorKeys,
1230
+ });
1231
+ // update the graph specification
1232
+ modesArr.forEach((mode) => {
1233
+ behaviorKeys.forEach((key) => {
1234
+ const oldBehavior = this.specification.modes[mode].find(
1235
+ (behavior) => isObject(behavior) && behavior.key === key,
1236
+ );
1237
+ const indexOfOldBehavior =
1238
+ this.specification.modes[mode].indexOf(oldBehavior);
1239
+ this.specification.modes[mode].splice(indexOfOldBehavior, 1);
1240
+ });
1241
+ });
1242
+ }
1243
+
1244
+ /**
1245
+ * Update a behavior on a mode.
1246
+ * @param behavior behavior configs, whose name indicates the behavior to be updated
1247
+ * @param mode mode name
1248
+ * @returns
1249
+ * @group Interaction
1250
+ */
1251
+ public updateBehavior(behavior: BehaviorOptionsOf<B>, mode?: string) {
1252
+ this.hooks.behaviorchange.emit({
1253
+ action: 'update',
1254
+ modes: [mode],
1255
+ // TODO: update type define.
1256
+ // @ts-ignore
1257
+ behaviors: [behavior],
1258
+ });
1259
+ // no need to update specification since the corresponding part is the same object as the behavior's option
1260
+ // this.specification.modes[mode].forEach((b, i) => {
1261
+ // if (isObject(b) && b.key === behavior.key) {
1262
+ // this.specification.modes[mode][i] = behavior;
1263
+ // }
1264
+ // });
1265
+ }
1266
+
1267
+ /**
1268
+ * Add plugin(s) to graph.
1269
+ * @param pluginCfgs
1270
+ * @returns
1271
+ * @group Plugin
1272
+ */
1273
+ public addPlugins(
1274
+ pluginCfgs: (
1275
+ | {
1276
+ key: string;
1277
+ type: string;
1278
+ [cfgName: string]: unknown; // TODO: configs from plugins
1279
+ }
1280
+ | string
1281
+ )[],
1282
+ ) {
1283
+ const pluginsArr = isArray(pluginCfgs) ? pluginCfgs : [pluginCfgs];
1284
+
1285
+ // update the graph specification
1286
+ if (!this.specification.plugins) this.specification.plugins = [];
1287
+ const oldPlugins = this.specification.plugins;
1288
+ const validPlugins: (
1289
+ | {
1290
+ key: string;
1291
+ type: string;
1292
+ [cfgName: string]: unknown; // TODO: configs from plugins
1293
+ }
1294
+ | string
1295
+ )[] = [];
1296
+ pluginsArr.forEach((config) => {
1297
+ const oldPlugin = oldPlugins.find((oldPlugin) => {
1298
+ if (typeof oldPlugin === 'string' || typeof config === 'string')
1299
+ return false;
1300
+ return oldPlugin.key === config.key;
1301
+ });
1302
+ if (oldPlugin) {
1303
+ console.warn(
1304
+ `Add plugin with key ${
1305
+ (config as any).key
1306
+ } failed, the key is duplicated to the existing plugins on the graph.`,
1307
+ );
1308
+ return;
1309
+ }
1310
+ validPlugins.push(config);
1311
+ });
1312
+ this.specification.plugins = oldPlugins.concat(validPlugins);
1313
+
1314
+ this.hooks.pluginchange.emit({
1315
+ action: 'add',
1316
+ plugins: validPlugins,
1317
+ });
1318
+ }
1319
+
1320
+ /**
1321
+ * Remove plugin(s) from graph.
1322
+ * @param pluginKeys
1323
+ * @returns
1324
+ * @group Plugin
1325
+ */
1326
+ public removePlugins(pluginKeys: string[]) {
1327
+ this.hooks.pluginchange.emit({
1328
+ action: 'remove',
1329
+ plugins: pluginKeys,
1330
+ });
1331
+ // update the graph specification
1332
+ const { plugins } = this.specification;
1333
+ this.specification.plugins = plugins?.filter((plugin) => {
1334
+ if (isObject(plugin)) return !pluginKeys.includes(plugin.key);
1335
+ return !pluginKeys.includes(plugin);
1336
+ });
1337
+ }
1338
+
1339
+ /**
1340
+ * Update a plugin of the graph.
1341
+ * @param plugin plugin configs, whose key indicates the behavior to be updated
1342
+ * @returns
1343
+ * @group Interaction
1344
+ */
1345
+ public updatePlugin(plugin: {
1346
+ key: string;
1347
+ type: string;
1348
+ [cfg: string]: unknown;
1349
+ }) {
1350
+ const { key } = plugin;
1351
+ if (!key) {
1352
+ console.warn(
1353
+ 'Update plugin failed, the key for the plugin to be updated should be assign.',
1354
+ );
1355
+ return;
1356
+ }
1357
+ const { plugins } = this.specification;
1358
+ if (!plugins) {
1359
+ console.warn(
1360
+ 'Update plugin failed, the plugin to be updated does not exist.',
1361
+ );
1362
+ return;
1363
+ }
1364
+ const oldPlugin = plugins?.find((p) => {
1365
+ if (typeof p === 'string') return p === key;
1366
+ return p.key === key;
1367
+ });
1368
+ if (!oldPlugin) {
1369
+ console.warn(
1370
+ 'Update plugin failed, the key for the plugin to be updated should be assign.',
1371
+ );
1372
+ return;
1373
+ }
1374
+ const idx = plugins.indexOf(oldPlugin);
1375
+ plugins[idx] = {
1376
+ // TODO: update type define.
1377
+ // @ts-ignore
1378
+ ...oldPlugin,
1379
+ ...plugin,
1380
+ };
1381
+
1382
+ this.hooks.pluginchange.emit({
1383
+ action: 'update',
1384
+ plugins: [plugin],
1385
+ });
1386
+ }
1387
+
1388
+ /**
1389
+ * Draw or update a G shape or group to the transient canvas.
1390
+ * @param type shape type or item type
1391
+ * @param id new shape id or updated shape id for a interation shape, node/edge/combo id for item interaction group drawing
1392
+ * @returns upserted shape or group
1393
+ * @group Interaction
1394
+ */
1395
+ public drawTransient(
1396
+ type: ITEM_TYPE | SHAPE_TYPE,
1397
+ id: ID,
1398
+ config: {
1399
+ action: 'remove' | 'add' | 'update' | undefined;
1400
+ style: ShapeStyle;
1401
+ onlyDrawKeyShape?: boolean;
1402
+ },
1403
+ ): DisplayObject {
1404
+ this.hooks.transientupdate.emit({
1405
+ type,
1406
+ id,
1407
+ config,
1408
+ canvas: this.transientCanvas,
1409
+ });
1410
+ return this.itemController.getTransient(String(id));
1411
+ }
1412
+
1413
+ /**
1414
+ * Destroy the graph instance and remove the related canvases.
1415
+ * @returns
1416
+ * @group Graph Instance
1417
+ */
1418
+ public destroy(callback?: Function) {
1419
+ // TODO: call the destroy functions after items' buildOut animations finished
1420
+ setTimeout(() => {
1421
+ this.canvas.destroy();
1422
+ this.backgroundCanvas.destroy();
1423
+ this.transientCanvas.destroy();
1424
+ callback?.();
1425
+ }, 500);
1426
+
1427
+ this.hooks.destroy.emit({});
1428
+
1429
+ // TODO: destroy controllers and off the listeners
1430
+ // this.dataController.destroy();
1431
+ // this.interactionController.destroy();
1432
+ // this.layoutController.destroy();
1433
+ // this.themeController.destroy();
1434
+ // this.itemController.destroy();
1435
+ // this.extensionController.destroy();
1436
+
1437
+ this.destroyed = true;
1438
+ }
1439
+ }