@antv/g6 5.0.0-beta.2 → 5.0.0-beta.21

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 (591) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/esm/api-doc/graph.d.ts +3 -3
  3. package/esm/api-doc/graph.js +3 -3
  4. package/esm/api-doc/graph.js.map +1 -1
  5. package/esm/api-doc/types.d.ts +1 -0
  6. package/esm/api-doc/types.js +1 -2
  7. package/esm/api-doc/types.js.map +1 -1
  8. package/esm/constant/shape.d.ts +3 -1
  9. package/esm/index.d.ts +33 -65
  10. package/esm/index.js +4 -5
  11. package/esm/index.js.map +1 -1
  12. package/esm/item/combo.d.ts +1 -1
  13. package/esm/item/combo.js +18 -14
  14. package/esm/item/combo.js.map +1 -1
  15. package/esm/item/edge.d.ts +19 -2
  16. package/esm/item/edge.js +100 -44
  17. package/esm/item/edge.js.map +1 -1
  18. package/esm/item/item.d.ts +3 -2
  19. package/esm/item/item.js +27 -13
  20. package/esm/item/item.js.map +1 -1
  21. package/esm/item/node.d.ts +2 -8
  22. package/esm/item/node.js +31 -19
  23. package/esm/item/node.js.map +1 -1
  24. package/esm/runtime/controller/data.d.ts +30 -16
  25. package/esm/runtime/controller/data.js +290 -422
  26. package/esm/runtime/controller/data.js.map +1 -1
  27. package/esm/runtime/controller/interaction.js +9 -4
  28. package/esm/runtime/controller/interaction.js.map +1 -1
  29. package/esm/runtime/controller/item.d.ts +1 -0
  30. package/esm/runtime/controller/item.js +285 -150
  31. package/esm/runtime/controller/item.js.map +1 -1
  32. package/esm/runtime/controller/layout.js +1 -3
  33. package/esm/runtime/controller/layout.js.map +1 -1
  34. package/esm/runtime/controller/plugin.js +9 -5
  35. package/esm/runtime/controller/plugin.js.map +1 -1
  36. package/esm/runtime/graph.d.ts +104 -24
  37. package/esm/runtime/graph.js +472 -94
  38. package/esm/runtime/graph.js.map +1 -1
  39. package/esm/stdlib/behavior/activate-relations.js +2 -2
  40. package/esm/stdlib/behavior/activate-relations.js.map +1 -1
  41. package/esm/stdlib/behavior/brush-select.d.ts +7 -1
  42. package/esm/stdlib/behavior/brush-select.js +10 -12
  43. package/esm/stdlib/behavior/brush-select.js.map +1 -1
  44. package/esm/stdlib/behavior/click-select.js +1 -1
  45. package/esm/stdlib/behavior/click-select.js.map +1 -1
  46. package/esm/stdlib/behavior/create-edge.d.ts +57 -0
  47. package/esm/stdlib/behavior/create-edge.js +215 -0
  48. package/esm/stdlib/behavior/create-edge.js.map +1 -0
  49. package/esm/stdlib/behavior/drag-canvas.d.ts +3 -1
  50. package/esm/stdlib/behavior/drag-canvas.js +78 -33
  51. package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
  52. package/esm/stdlib/behavior/drag-combo.d.ts +2 -2
  53. package/esm/stdlib/behavior/drag-combo.js +43 -32
  54. package/esm/stdlib/behavior/drag-combo.js.map +1 -1
  55. package/esm/stdlib/behavior/drag-node.d.ts +3 -3
  56. package/esm/stdlib/behavior/drag-node.js +80 -63
  57. package/esm/stdlib/behavior/drag-node.js.map +1 -1
  58. package/esm/stdlib/behavior/index.d.ts +3 -0
  59. package/esm/stdlib/behavior/index.js +3 -0
  60. package/esm/stdlib/behavior/index.js.map +1 -1
  61. package/esm/stdlib/behavior/lasso-select.d.ts +1 -1
  62. package/esm/stdlib/behavior/lasso-select.js +3 -4
  63. package/esm/stdlib/behavior/lasso-select.js.map +1 -1
  64. package/esm/stdlib/behavior/scroll-canvas.d.ts +67 -0
  65. package/esm/stdlib/behavior/scroll-canvas.js +266 -0
  66. package/esm/stdlib/behavior/scroll-canvas.js.map +1 -0
  67. package/esm/stdlib/behavior/shortcuts-call.d.ts +38 -0
  68. package/esm/stdlib/behavior/shortcuts-call.js +87 -0
  69. package/esm/stdlib/behavior/shortcuts-call.js.map +1 -0
  70. package/esm/stdlib/behavior/zoom-canvas-3d.js +4 -1
  71. package/esm/stdlib/behavior/zoom-canvas-3d.js.map +1 -1
  72. package/esm/stdlib/behavior/zoom-canvas.d.ts +3 -1
  73. package/esm/stdlib/behavior/zoom-canvas.js +70 -26
  74. package/esm/stdlib/behavior/zoom-canvas.js.map +1 -1
  75. package/esm/stdlib/data/index.d.ts +1 -0
  76. package/esm/stdlib/data/index.js +1 -0
  77. package/esm/stdlib/data/index.js.map +1 -1
  78. package/esm/stdlib/data/mapNodeSize.d.ts +4 -5
  79. package/esm/stdlib/data/mapNodeSize.js +12 -2
  80. package/esm/stdlib/data/mapNodeSize.js.map +1 -1
  81. package/esm/stdlib/data/processParallelEdges.d.ts +21 -0
  82. package/esm/stdlib/data/processParallelEdges.js +127 -0
  83. package/esm/stdlib/data/processParallelEdges.js.map +1 -0
  84. package/esm/stdlib/data/transformV4Data.d.ts +3 -4
  85. package/esm/stdlib/data/transformV4Data.js +10 -2
  86. package/esm/stdlib/data/transformV4Data.js.map +1 -1
  87. package/esm/stdlib/data/validateData.d.ts +4 -5
  88. package/esm/stdlib/data/validateData.js +22 -13
  89. package/esm/stdlib/data/validateData.js.map +1 -1
  90. package/esm/stdlib/index.d.ts +27 -8
  91. package/esm/stdlib/index.js +24 -11
  92. package/esm/stdlib/index.js.map +1 -1
  93. package/esm/stdlib/item/edge/base.d.ts +3 -5
  94. package/esm/stdlib/item/edge/base.js +32 -31
  95. package/esm/stdlib/item/edge/base.js.map +1 -1
  96. package/esm/stdlib/item/edge/cubic-horizontal.js.map +1 -1
  97. package/esm/stdlib/item/edge/cubic-vertical.js.map +1 -1
  98. package/esm/stdlib/item/edge/cubic.js +1 -1
  99. package/esm/stdlib/item/edge/cubic.js.map +1 -1
  100. package/esm/stdlib/item/edge/loop.js +1 -1
  101. package/esm/stdlib/item/edge/loop.js.map +1 -1
  102. package/esm/stdlib/item/node/base.d.ts +3 -6
  103. package/esm/stdlib/item/node/base.js +30 -60
  104. package/esm/stdlib/item/node/base.js.map +1 -1
  105. package/esm/stdlib/item/node/base3d.d.ts +1 -0
  106. package/esm/stdlib/item/node/base3d.js +1 -0
  107. package/esm/stdlib/item/node/base3d.js.map +1 -1
  108. package/esm/stdlib/item/node/cube.d.ts +35 -0
  109. package/esm/stdlib/item/node/cube.js +54 -0
  110. package/esm/stdlib/item/node/cube.js.map +1 -0
  111. package/esm/stdlib/item/node/diamond.js +1 -1
  112. package/esm/stdlib/item/node/ellipse.js +2 -2
  113. package/esm/stdlib/item/node/hexagon.js +6 -2
  114. package/esm/stdlib/item/node/hexagon.js.map +1 -1
  115. package/esm/stdlib/item/node/image.d.ts +40 -0
  116. package/esm/stdlib/item/node/image.js +110 -0
  117. package/esm/stdlib/item/node/image.js.map +1 -0
  118. package/esm/stdlib/item/node/index.d.ts +4 -0
  119. package/esm/stdlib/item/node/index.js +4 -0
  120. package/esm/stdlib/item/node/index.js.map +1 -1
  121. package/esm/stdlib/plugin/edgeFilterLens/index.d.ts +66 -0
  122. package/esm/stdlib/plugin/edgeFilterLens/index.js +309 -0
  123. package/esm/stdlib/plugin/edgeFilterLens/index.js.map +1 -0
  124. package/esm/stdlib/plugin/grid/index.d.ts +1 -1
  125. package/esm/stdlib/plugin/grid/index.js +3 -4
  126. package/esm/stdlib/plugin/grid/index.js.map +1 -1
  127. package/esm/stdlib/plugin/history/combo-command.js +2 -2
  128. package/esm/stdlib/plugin/history/combo-command.js.map +1 -1
  129. package/esm/stdlib/plugin/history/index.d.ts +10 -10
  130. package/esm/stdlib/plugin/history/index.js +14 -14
  131. package/esm/stdlib/plugin/history/index.js.map +1 -1
  132. package/esm/stdlib/plugin/history/item-data-command.js +25 -16
  133. package/esm/stdlib/plugin/history/item-data-command.js.map +1 -1
  134. package/esm/stdlib/plugin/history/layer-updated-command.js +2 -2
  135. package/esm/stdlib/plugin/history/layer-updated-command.js.map +1 -1
  136. package/esm/stdlib/plugin/history/state-updated-command.js +1 -1
  137. package/esm/stdlib/plugin/history/state-updated-command.js.map +1 -1
  138. package/esm/stdlib/plugin/history/visibility-updated-command.js +2 -2
  139. package/esm/stdlib/plugin/history/visibility-updated-command.js.map +1 -1
  140. package/esm/stdlib/plugin/hull/convexHull.d.ts +1 -1
  141. package/esm/stdlib/plugin/hull/hullComponent.d.ts +1 -1
  142. package/esm/stdlib/plugin/hull/hullComponent.js +5 -9
  143. package/esm/stdlib/plugin/hull/hullComponent.js.map +1 -1
  144. package/esm/stdlib/plugin/hull/util.d.ts +2 -2
  145. package/esm/stdlib/plugin/hull/util.js +6 -2
  146. package/esm/stdlib/plugin/hull/util.js.map +1 -1
  147. package/esm/stdlib/plugin/index.d.ts +2 -0
  148. package/esm/stdlib/plugin/index.js +2 -0
  149. package/esm/stdlib/plugin/index.js.map +1 -1
  150. package/esm/stdlib/plugin/legend/index.d.ts +2 -2
  151. package/esm/stdlib/plugin/legend/index.js +3 -3
  152. package/esm/stdlib/plugin/legend/index.js.map +1 -1
  153. package/esm/stdlib/plugin/menu/index.d.ts +4 -4
  154. package/esm/stdlib/plugin/menu/index.js +3 -3
  155. package/esm/stdlib/plugin/menu/index.js.map +1 -1
  156. package/esm/stdlib/plugin/minimap/index.d.ts +6 -2
  157. package/esm/stdlib/plugin/minimap/index.js +119 -12
  158. package/esm/stdlib/plugin/minimap/index.js.map +1 -1
  159. package/esm/stdlib/plugin/snapline/index.d.ts +167 -0
  160. package/esm/stdlib/plugin/snapline/index.js +1063 -0
  161. package/esm/stdlib/plugin/snapline/index.js.map +1 -0
  162. package/esm/stdlib/plugin/timebar/index.js +2 -2
  163. package/esm/stdlib/plugin/timebar/index.js.map +1 -1
  164. package/esm/stdlib/plugin/toolbar/index.d.ts +3 -3
  165. package/esm/stdlib/plugin/toolbar/index.js +4 -4
  166. package/esm/stdlib/plugin/toolbar/index.js.map +1 -1
  167. package/esm/stdlib/plugin/tooltip/index.d.ts +4 -4
  168. package/esm/stdlib/plugin/tooltip/index.js +3 -4
  169. package/esm/stdlib/plugin/tooltip/index.js.map +1 -1
  170. package/esm/stdlib/plugin/types.d.ts +2 -0
  171. package/esm/stdlib/plugin/watermaker/index.d.ts +78 -0
  172. package/esm/stdlib/plugin/watermaker/index.js +243 -0
  173. package/esm/stdlib/plugin/watermaker/index.js.map +1 -0
  174. package/esm/stdlib/theme/dark.js +42 -2
  175. package/esm/stdlib/theme/dark.js.map +1 -1
  176. package/esm/stdlib/theme/light.js +4 -4
  177. package/esm/types/data.d.ts +5 -0
  178. package/esm/types/event.d.ts +1 -0
  179. package/esm/types/graph.d.ts +48 -22
  180. package/esm/types/hook.d.ts +22 -2
  181. package/esm/types/index.d.ts +2 -1
  182. package/esm/types/index.js +1 -0
  183. package/esm/types/index.js.map +1 -1
  184. package/esm/types/item.d.ts +7 -1
  185. package/esm/types/item.js.map +1 -1
  186. package/esm/types/plugin.d.ts +1 -1
  187. package/esm/types/spec.d.ts +20 -3
  188. package/esm/types/view.d.ts +5 -0
  189. package/esm/util/array.d.ts +1 -0
  190. package/esm/util/array.js +3 -0
  191. package/esm/util/array.js.map +1 -1
  192. package/esm/util/bbox.d.ts +16 -1
  193. package/esm/util/bbox.js +33 -5
  194. package/esm/util/bbox.js.map +1 -1
  195. package/esm/util/behavior.d.ts +2 -2
  196. package/esm/util/behavior.js +2 -2
  197. package/esm/util/behavior.js.map +1 -1
  198. package/esm/util/data.d.ts +5 -2
  199. package/esm/util/data.js +15 -0
  200. package/esm/util/data.js.map +1 -1
  201. package/esm/util/dom.d.ts +15 -0
  202. package/esm/util/dom.js +29 -0
  203. package/esm/util/dom.js.map +1 -0
  204. package/esm/util/event.d.ts +3 -1
  205. package/esm/util/event.js +8 -1
  206. package/esm/util/event.js.map +1 -1
  207. package/esm/util/extend.d.ts +1 -1
  208. package/esm/util/extend.js +0 -1
  209. package/esm/util/extend.js.map +1 -1
  210. package/esm/util/index.d.ts +7 -52
  211. package/esm/util/index.js +7 -23
  212. package/esm/util/index.js.map +1 -1
  213. package/esm/util/item.d.ts +16 -1
  214. package/esm/util/item.js +31 -8
  215. package/esm/util/item.js.map +1 -1
  216. package/esm/util/layout.d.ts +12 -1
  217. package/esm/util/layout.js +45 -0
  218. package/esm/util/layout.js.map +1 -1
  219. package/esm/util/loop.d.ts +2 -1
  220. package/esm/util/loop.js +14 -0
  221. package/esm/util/loop.js.map +1 -1
  222. package/esm/util/math.d.ts +1 -1
  223. package/esm/util/matrix.d.ts +6 -0
  224. package/esm/util/matrix.js +48 -0
  225. package/esm/util/matrix.js.map +1 -0
  226. package/esm/util/path.js +1 -1
  227. package/esm/util/path.js.map +1 -1
  228. package/esm/util/point.d.ts +1 -1
  229. package/esm/util/point.js +9 -2
  230. package/esm/util/point.js.map +1 -1
  231. package/esm/util/polyline.d.ts +2 -1
  232. package/esm/util/polyline.js +2 -1
  233. package/esm/util/polyline.js.map +1 -1
  234. package/esm/util/router.d.ts +1 -1
  235. package/esm/util/shape.d.ts +3 -3
  236. package/esm/util/shape.js +17 -26
  237. package/esm/util/shape.js.map +1 -1
  238. package/esm/util/shape3d.d.ts +1 -1
  239. package/esm/util/shape3d.js +16 -17
  240. package/esm/util/shape3d.js.map +1 -1
  241. package/esm/util/text.d.ts +1 -1
  242. package/esm/util/text.js +3 -2
  243. package/esm/util/text.js.map +1 -1
  244. package/esm/util/warn.d.ts +14 -0
  245. package/esm/util/warn.js +4 -0
  246. package/esm/util/warn.js.map +1 -0
  247. package/lib/api-doc/graph.d.ts +3 -3
  248. package/lib/api-doc/graph.js +27 -7
  249. package/lib/api-doc/graph.js.map +1 -1
  250. package/lib/api-doc/types.d.ts +1 -0
  251. package/lib/api-doc/types.js +2 -2
  252. package/lib/api-doc/types.js.map +1 -1
  253. package/lib/constant/shape.d.ts +3 -1
  254. package/lib/index.d.ts +33 -65
  255. package/lib/index.js +18 -10
  256. package/lib/index.js.map +1 -1
  257. package/lib/item/combo.d.ts +1 -1
  258. package/lib/item/combo.js +18 -14
  259. package/lib/item/combo.js.map +1 -1
  260. package/lib/item/edge.d.ts +19 -2
  261. package/lib/item/edge.js +99 -43
  262. package/lib/item/edge.js.map +1 -1
  263. package/lib/item/item.d.ts +3 -2
  264. package/lib/item/item.js +27 -13
  265. package/lib/item/item.js.map +1 -1
  266. package/lib/item/node.d.ts +2 -8
  267. package/lib/item/node.js +31 -19
  268. package/lib/item/node.js.map +1 -1
  269. package/lib/runtime/controller/data.d.ts +30 -16
  270. package/lib/runtime/controller/data.js +288 -420
  271. package/lib/runtime/controller/data.js.map +1 -1
  272. package/lib/runtime/controller/interaction.js +9 -4
  273. package/lib/runtime/controller/interaction.js.map +1 -1
  274. package/lib/runtime/controller/item.d.ts +1 -0
  275. package/lib/runtime/controller/item.js +284 -149
  276. package/lib/runtime/controller/item.js.map +1 -1
  277. package/lib/runtime/controller/layout.js +1 -3
  278. package/lib/runtime/controller/layout.js.map +1 -1
  279. package/lib/runtime/controller/plugin.js +9 -5
  280. package/lib/runtime/controller/plugin.js.map +1 -1
  281. package/lib/runtime/graph.d.ts +104 -24
  282. package/lib/runtime/graph.js +473 -94
  283. package/lib/runtime/graph.js.map +1 -1
  284. package/lib/stdlib/behavior/activate-relations.js +2 -2
  285. package/lib/stdlib/behavior/activate-relations.js.map +1 -1
  286. package/lib/stdlib/behavior/brush-select.d.ts +7 -1
  287. package/lib/stdlib/behavior/brush-select.js +13 -12
  288. package/lib/stdlib/behavior/brush-select.js.map +1 -1
  289. package/lib/stdlib/behavior/click-select.js +1 -1
  290. package/lib/stdlib/behavior/click-select.js.map +1 -1
  291. package/lib/stdlib/behavior/create-edge.d.ts +57 -0
  292. package/lib/stdlib/behavior/create-edge.js +219 -0
  293. package/lib/stdlib/behavior/create-edge.js.map +1 -0
  294. package/lib/stdlib/behavior/drag-canvas.d.ts +3 -1
  295. package/lib/stdlib/behavior/drag-canvas.js +78 -33
  296. package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
  297. package/lib/stdlib/behavior/drag-combo.d.ts +2 -2
  298. package/lib/stdlib/behavior/drag-combo.js +43 -32
  299. package/lib/stdlib/behavior/drag-combo.js.map +1 -1
  300. package/lib/stdlib/behavior/drag-node.d.ts +3 -3
  301. package/lib/stdlib/behavior/drag-node.js +80 -63
  302. package/lib/stdlib/behavior/drag-node.js.map +1 -1
  303. package/lib/stdlib/behavior/index.d.ts +3 -0
  304. package/lib/stdlib/behavior/index.js +3 -0
  305. package/lib/stdlib/behavior/index.js.map +1 -1
  306. package/lib/stdlib/behavior/lasso-select.d.ts +1 -1
  307. package/lib/stdlib/behavior/lasso-select.js +6 -4
  308. package/lib/stdlib/behavior/lasso-select.js.map +1 -1
  309. package/lib/stdlib/behavior/scroll-canvas.d.ts +67 -0
  310. package/lib/stdlib/behavior/scroll-canvas.js +270 -0
  311. package/lib/stdlib/behavior/scroll-canvas.js.map +1 -0
  312. package/lib/stdlib/behavior/shortcuts-call.d.ts +38 -0
  313. package/lib/stdlib/behavior/shortcuts-call.js +91 -0
  314. package/lib/stdlib/behavior/shortcuts-call.js.map +1 -0
  315. package/lib/stdlib/behavior/zoom-canvas-3d.js +4 -1
  316. package/lib/stdlib/behavior/zoom-canvas-3d.js.map +1 -1
  317. package/lib/stdlib/behavior/zoom-canvas.d.ts +3 -1
  318. package/lib/stdlib/behavior/zoom-canvas.js +70 -26
  319. package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
  320. package/lib/stdlib/data/index.d.ts +1 -0
  321. package/lib/stdlib/data/index.js +1 -0
  322. package/lib/stdlib/data/index.js.map +1 -1
  323. package/lib/stdlib/data/mapNodeSize.d.ts +4 -5
  324. package/lib/stdlib/data/mapNodeSize.js +13 -3
  325. package/lib/stdlib/data/mapNodeSize.js.map +1 -1
  326. package/lib/stdlib/data/processParallelEdges.d.ts +21 -0
  327. package/lib/stdlib/data/processParallelEdges.js +131 -0
  328. package/lib/stdlib/data/processParallelEdges.js.map +1 -0
  329. package/lib/stdlib/data/transformV4Data.d.ts +3 -4
  330. package/lib/stdlib/data/transformV4Data.js +11 -3
  331. package/lib/stdlib/data/transformV4Data.js.map +1 -1
  332. package/lib/stdlib/data/validateData.d.ts +4 -5
  333. package/lib/stdlib/data/validateData.js +23 -14
  334. package/lib/stdlib/data/validateData.js.map +1 -1
  335. package/lib/stdlib/index.d.ts +27 -8
  336. package/lib/stdlib/index.js +24 -11
  337. package/lib/stdlib/index.js.map +1 -1
  338. package/lib/stdlib/item/edge/base.d.ts +3 -5
  339. package/lib/stdlib/item/edge/base.js +30 -29
  340. package/lib/stdlib/item/edge/base.js.map +1 -1
  341. package/lib/stdlib/item/edge/cubic-horizontal.js.map +1 -1
  342. package/lib/stdlib/item/edge/cubic-vertical.js.map +1 -1
  343. package/lib/stdlib/item/edge/cubic.js +2 -2
  344. package/lib/stdlib/item/edge/cubic.js.map +1 -1
  345. package/lib/stdlib/item/edge/loop.js +3 -3
  346. package/lib/stdlib/item/edge/loop.js.map +1 -1
  347. package/lib/stdlib/item/node/base.d.ts +3 -6
  348. package/lib/stdlib/item/node/base.js +29 -59
  349. package/lib/stdlib/item/node/base.js.map +1 -1
  350. package/lib/stdlib/item/node/base3d.d.ts +1 -0
  351. package/lib/stdlib/item/node/base3d.js +1 -0
  352. package/lib/stdlib/item/node/base3d.js.map +1 -1
  353. package/lib/stdlib/item/node/cube.d.ts +35 -0
  354. package/lib/stdlib/item/node/cube.js +58 -0
  355. package/lib/stdlib/item/node/cube.js.map +1 -0
  356. package/lib/stdlib/item/node/diamond.js +1 -1
  357. package/lib/stdlib/item/node/ellipse.js +2 -2
  358. package/lib/stdlib/item/node/hexagon.js +6 -2
  359. package/lib/stdlib/item/node/hexagon.js.map +1 -1
  360. package/lib/stdlib/item/node/image.d.ts +40 -0
  361. package/lib/stdlib/item/node/image.js +114 -0
  362. package/lib/stdlib/item/node/image.js.map +1 -0
  363. package/lib/stdlib/item/node/index.d.ts +4 -0
  364. package/lib/stdlib/item/node/index.js +4 -0
  365. package/lib/stdlib/item/node/index.js.map +1 -1
  366. package/lib/stdlib/plugin/edgeFilterLens/index.d.ts +66 -0
  367. package/lib/stdlib/plugin/edgeFilterLens/index.js +313 -0
  368. package/lib/stdlib/plugin/edgeFilterLens/index.js.map +1 -0
  369. package/lib/stdlib/plugin/grid/index.d.ts +1 -1
  370. package/lib/stdlib/plugin/grid/index.js +6 -7
  371. package/lib/stdlib/plugin/grid/index.js.map +1 -1
  372. package/lib/stdlib/plugin/history/combo-command.js +2 -2
  373. package/lib/stdlib/plugin/history/combo-command.js.map +1 -1
  374. package/lib/stdlib/plugin/history/index.d.ts +10 -10
  375. package/lib/stdlib/plugin/history/index.js +14 -14
  376. package/lib/stdlib/plugin/history/index.js.map +1 -1
  377. package/lib/stdlib/plugin/history/item-data-command.js +25 -16
  378. package/lib/stdlib/plugin/history/item-data-command.js.map +1 -1
  379. package/lib/stdlib/plugin/history/layer-updated-command.js +2 -2
  380. package/lib/stdlib/plugin/history/layer-updated-command.js.map +1 -1
  381. package/lib/stdlib/plugin/history/state-updated-command.js +1 -1
  382. package/lib/stdlib/plugin/history/state-updated-command.js.map +1 -1
  383. package/lib/stdlib/plugin/history/visibility-updated-command.js +2 -2
  384. package/lib/stdlib/plugin/history/visibility-updated-command.js.map +1 -1
  385. package/lib/stdlib/plugin/hull/convexHull.d.ts +1 -1
  386. package/lib/stdlib/plugin/hull/hullComponent.d.ts +1 -1
  387. package/lib/stdlib/plugin/hull/hullComponent.js +5 -9
  388. package/lib/stdlib/plugin/hull/hullComponent.js.map +1 -1
  389. package/lib/stdlib/plugin/hull/util.d.ts +2 -2
  390. package/lib/stdlib/plugin/hull/util.js +26 -22
  391. package/lib/stdlib/plugin/hull/util.js.map +1 -1
  392. package/lib/stdlib/plugin/index.d.ts +2 -0
  393. package/lib/stdlib/plugin/index.js +2 -0
  394. package/lib/stdlib/plugin/index.js.map +1 -1
  395. package/lib/stdlib/plugin/legend/index.d.ts +2 -2
  396. package/lib/stdlib/plugin/legend/index.js +3 -3
  397. package/lib/stdlib/plugin/legend/index.js.map +1 -1
  398. package/lib/stdlib/plugin/menu/index.d.ts +4 -4
  399. package/lib/stdlib/plugin/menu/index.js +6 -6
  400. package/lib/stdlib/plugin/menu/index.js.map +1 -1
  401. package/lib/stdlib/plugin/minimap/index.d.ts +6 -2
  402. package/lib/stdlib/plugin/minimap/index.js +121 -14
  403. package/lib/stdlib/plugin/minimap/index.js.map +1 -1
  404. package/lib/stdlib/plugin/snapline/index.d.ts +167 -0
  405. package/lib/stdlib/plugin/snapline/index.js +1067 -0
  406. package/lib/stdlib/plugin/snapline/index.js.map +1 -0
  407. package/lib/stdlib/plugin/timebar/index.js +2 -2
  408. package/lib/stdlib/plugin/timebar/index.js.map +1 -1
  409. package/lib/stdlib/plugin/toolbar/index.d.ts +3 -3
  410. package/lib/stdlib/plugin/toolbar/index.js +5 -5
  411. package/lib/stdlib/plugin/toolbar/index.js.map +1 -1
  412. package/lib/stdlib/plugin/tooltip/index.d.ts +4 -4
  413. package/lib/stdlib/plugin/tooltip/index.js +10 -11
  414. package/lib/stdlib/plugin/tooltip/index.js.map +1 -1
  415. package/lib/stdlib/plugin/types.d.ts +2 -0
  416. package/lib/stdlib/plugin/watermaker/index.d.ts +78 -0
  417. package/lib/stdlib/plugin/watermaker/index.js +247 -0
  418. package/lib/stdlib/plugin/watermaker/index.js.map +1 -0
  419. package/lib/stdlib/theme/dark.js +42 -2
  420. package/lib/stdlib/theme/dark.js.map +1 -1
  421. package/lib/stdlib/theme/light.js +4 -4
  422. package/lib/types/data.d.ts +5 -0
  423. package/lib/types/event.d.ts +1 -0
  424. package/lib/types/graph.d.ts +48 -22
  425. package/lib/types/hook.d.ts +22 -2
  426. package/lib/types/index.d.ts +2 -1
  427. package/lib/types/index.js +3 -1
  428. package/lib/types/index.js.map +1 -1
  429. package/lib/types/item.d.ts +7 -1
  430. package/lib/types/item.js.map +1 -1
  431. package/lib/types/plugin.d.ts +1 -1
  432. package/lib/types/spec.d.ts +20 -3
  433. package/lib/types/view.d.ts +5 -0
  434. package/lib/util/array.d.ts +1 -0
  435. package/lib/util/array.js +5 -1
  436. package/lib/util/array.js.map +1 -1
  437. package/lib/util/bbox.d.ts +16 -1
  438. package/lib/util/bbox.js +36 -6
  439. package/lib/util/bbox.js.map +1 -1
  440. package/lib/util/behavior.d.ts +2 -2
  441. package/lib/util/behavior.js +2 -2
  442. package/lib/util/behavior.js.map +1 -1
  443. package/lib/util/data.d.ts +5 -2
  444. package/lib/util/data.js +16 -1
  445. package/lib/util/data.js.map +1 -1
  446. package/lib/util/dom.d.ts +15 -0
  447. package/lib/util/dom.js +34 -0
  448. package/lib/util/dom.js.map +1 -0
  449. package/lib/util/event.d.ts +3 -1
  450. package/lib/util/event.js +8 -1
  451. package/lib/util/event.js.map +1 -1
  452. package/lib/util/extend.d.ts +1 -1
  453. package/lib/util/extend.js +0 -1
  454. package/lib/util/extend.js.map +1 -1
  455. package/lib/util/index.d.ts +7 -52
  456. package/lib/util/index.js +23 -23
  457. package/lib/util/index.js.map +1 -1
  458. package/lib/util/item.d.ts +16 -1
  459. package/lib/util/item.js +33 -9
  460. package/lib/util/item.js.map +1 -1
  461. package/lib/util/layout.d.ts +12 -1
  462. package/lib/util/layout.js +47 -1
  463. package/lib/util/layout.js.map +1 -1
  464. package/lib/util/loop.d.ts +2 -1
  465. package/lib/util/loop.js +15 -1
  466. package/lib/util/loop.js.map +1 -1
  467. package/lib/util/math.d.ts +1 -1
  468. package/lib/util/matrix.d.ts +6 -0
  469. package/lib/util/matrix.js +52 -0
  470. package/lib/util/matrix.js.map +1 -0
  471. package/lib/util/path.js +2 -2
  472. package/lib/util/path.js.map +1 -1
  473. package/lib/util/point.d.ts +1 -1
  474. package/lib/util/point.js +9 -2
  475. package/lib/util/point.js.map +1 -1
  476. package/lib/util/polyline.d.ts +2 -1
  477. package/lib/util/polyline.js +2 -1
  478. package/lib/util/polyline.js.map +1 -1
  479. package/lib/util/router.d.ts +1 -1
  480. package/lib/util/shape.d.ts +3 -3
  481. package/lib/util/shape.js +17 -26
  482. package/lib/util/shape.js.map +1 -1
  483. package/lib/util/shape3d.d.ts +1 -1
  484. package/lib/util/shape3d.js +15 -16
  485. package/lib/util/shape3d.js.map +1 -1
  486. package/lib/util/text.d.ts +1 -1
  487. package/lib/util/text.js +3 -2
  488. package/lib/util/text.js.map +1 -1
  489. package/lib/util/warn.d.ts +14 -0
  490. package/lib/util/warn.js +8 -0
  491. package/lib/util/warn.js.map +1 -0
  492. package/package.json +42 -51
  493. package/src/api-doc/graph.ts +4 -3
  494. package/src/api-doc/types.ts +1 -0
  495. package/src/constant/shape.ts +1 -1
  496. package/src/index.ts +5 -6
  497. package/src/item/combo.ts +16 -15
  498. package/src/item/edge.ts +135 -57
  499. package/src/item/item.ts +32 -19
  500. package/src/item/node.ts +36 -50
  501. package/src/runtime/controller/data.ts +371 -490
  502. package/src/runtime/controller/interaction.ts +10 -4
  503. package/src/runtime/controller/item.ts +261 -78
  504. package/src/runtime/controller/layout.ts +1 -5
  505. package/src/runtime/controller/plugin.ts +15 -4
  506. package/src/runtime/graph.ts +605 -103
  507. package/src/stdlib/behavior/activate-relations.ts +2 -2
  508. package/src/stdlib/behavior/brush-select.ts +14 -13
  509. package/src/stdlib/behavior/click-select.ts +1 -1
  510. package/src/stdlib/behavior/create-edge.ts +305 -0
  511. package/src/stdlib/behavior/drag-canvas.ts +107 -35
  512. package/src/stdlib/behavior/drag-combo.ts +10 -10
  513. package/src/stdlib/behavior/drag-node.ts +27 -18
  514. package/src/stdlib/behavior/index.ts +3 -0
  515. package/src/stdlib/behavior/lasso-select.ts +7 -5
  516. package/src/stdlib/behavior/scroll-canvas.ts +348 -0
  517. package/src/stdlib/behavior/shortcuts-call.ts +129 -0
  518. package/src/stdlib/behavior/zoom-canvas-3d.ts +4 -1
  519. package/src/stdlib/behavior/zoom-canvas.ts +98 -27
  520. package/src/stdlib/data/index.ts +1 -0
  521. package/src/stdlib/data/mapNodeSize.ts +22 -3
  522. package/src/stdlib/data/processParallelEdges.ts +203 -0
  523. package/src/stdlib/data/transformV4Data.ts +16 -3
  524. package/src/stdlib/data/validateData.ts +32 -18
  525. package/src/stdlib/index.ts +31 -8
  526. package/src/stdlib/item/edge/base.ts +32 -41
  527. package/src/stdlib/item/edge/cubic-horizontal.ts +0 -1
  528. package/src/stdlib/item/edge/cubic-vertical.ts +0 -1
  529. package/src/stdlib/item/edge/cubic.ts +1 -1
  530. package/src/stdlib/item/edge/loop.ts +1 -1
  531. package/src/stdlib/item/node/base.ts +38 -65
  532. package/src/stdlib/item/node/base3d.ts +1 -0
  533. package/src/stdlib/item/node/cube.ts +102 -0
  534. package/src/stdlib/item/node/diamond.ts +1 -1
  535. package/src/stdlib/item/node/ellipse.ts +2 -2
  536. package/src/stdlib/item/node/hexagon.ts +6 -2
  537. package/src/stdlib/item/node/image.ts +190 -0
  538. package/src/stdlib/item/node/index.ts +4 -0
  539. package/src/stdlib/plugin/edgeFilterLens/index.ts +387 -0
  540. package/src/stdlib/plugin/grid/index.ts +6 -6
  541. package/src/stdlib/plugin/history/combo-command.ts +2 -2
  542. package/src/stdlib/plugin/history/index.ts +14 -14
  543. package/src/stdlib/plugin/history/item-data-command.ts +35 -17
  544. package/src/stdlib/plugin/history/layer-updated-command.ts +2 -2
  545. package/src/stdlib/plugin/history/state-updated-command.ts +1 -1
  546. package/src/stdlib/plugin/history/visibility-updated-command.ts +2 -2
  547. package/src/stdlib/plugin/hull/convexHull.ts +1 -1
  548. package/src/stdlib/plugin/hull/hullComponent.ts +10 -8
  549. package/src/stdlib/plugin/hull/util.ts +6 -2
  550. package/src/stdlib/plugin/index.ts +2 -0
  551. package/src/stdlib/plugin/legend/index.ts +6 -6
  552. package/src/stdlib/plugin/menu/index.ts +13 -13
  553. package/src/stdlib/plugin/minimap/index.ts +126 -16
  554. package/src/stdlib/plugin/snapline/index.ts +1297 -0
  555. package/src/stdlib/plugin/timebar/index.ts +4 -4
  556. package/src/stdlib/plugin/toolbar/index.ts +8 -8
  557. package/src/stdlib/plugin/tooltip/index.ts +10 -10
  558. package/src/stdlib/plugin/types.ts +2 -0
  559. package/src/stdlib/plugin/watermaker/index.ts +302 -0
  560. package/src/stdlib/theme/dark.ts +66 -2
  561. package/src/stdlib/theme/light.ts +4 -4
  562. package/src/types/data.ts +6 -0
  563. package/src/types/event.ts +1 -0
  564. package/src/types/graph.ts +62 -25
  565. package/src/types/hook.ts +22 -2
  566. package/src/types/index.ts +2 -1
  567. package/src/types/item.ts +12 -1
  568. package/src/types/plugin.ts +1 -1
  569. package/src/types/spec.ts +23 -3
  570. package/src/types/view.ts +8 -3
  571. package/src/util/array.ts +12 -0
  572. package/src/util/bbox.ts +42 -6
  573. package/src/util/behavior.ts +4 -4
  574. package/src/util/data.ts +26 -4
  575. package/src/util/dom.ts +33 -0
  576. package/src/util/event.ts +14 -1
  577. package/src/util/extend.ts +2 -3
  578. package/src/util/index.ts +7 -24
  579. package/src/util/item.ts +65 -28
  580. package/src/util/layout.ts +48 -2
  581. package/src/util/loop.ts +16 -1
  582. package/src/util/math.ts +1 -1
  583. package/src/util/matrix.ts +66 -0
  584. package/src/util/path.ts +1 -1
  585. package/src/util/point.ts +9 -4
  586. package/src/util/polyline.ts +2 -1
  587. package/src/util/router.ts +1 -1
  588. package/src/util/shape.ts +23 -26
  589. package/src/util/shape3d.ts +20 -20
  590. package/src/util/text.ts +3 -1
  591. package/src/util/warn.ts +20 -0
@@ -1,13 +1,20 @@
1
1
  import { Graph as GraphLib, ID } from '@antv/graphlib';
2
- import { clone, isArray, isObject } from '@antv/util';
2
+ import { clone, isArray, isEmpty, isObject } from '@antv/util';
3
3
  import { registery as registry } from '../../stdlib';
4
- import { ComboModel, ComboUserModel, GraphData, IGraph } from '../../types';
4
+ import {
5
+ ComboModel,
6
+ ComboUserModel,
7
+ GraphData,
8
+ IGraph,
9
+ Specification,
10
+ } from '../../types';
5
11
  import { ComboUserModelData } from '../../types/combo';
6
12
  import {
7
13
  DataChangeType,
8
14
  DataConfig,
9
15
  FetchDataConfig,
10
16
  GraphCore,
17
+ GraphDataChanges,
11
18
  InlineGraphDataConfig,
12
19
  InlineTreeDataConfig,
13
20
  } from '../../types/data';
@@ -25,6 +32,9 @@ import {
25
32
  NodeUserModelData,
26
33
  } from '../../types/node';
27
34
  import {
35
+ AVAILABLE_DATA_LIFECYCLE,
36
+ DEFAULT_ACTIVE_DATA_LIFECYCLE,
37
+ dataLifecycleMap,
28
38
  deconstructData,
29
39
  graphComboTreeDfs,
30
40
  graphData2TreeData,
@@ -44,10 +54,6 @@ import { hasTreeBehaviors } from '../../util/behavior';
44
54
  export class DataController {
45
55
  public graph: IGraph;
46
56
  public extensions = [];
47
- /**
48
- * User input data.
49
- */
50
- public userGraphCore: GraphCore;
51
57
  /**
52
58
  * Inner data stored in graphCore structure.
53
59
  */
@@ -58,6 +64,11 @@ export class DataController {
58
64
  */
59
65
  private treeDirtyFlag: boolean;
60
66
 
67
+ /**
68
+ * Cache the current data type;
69
+ */
70
+ private dataType: 'treeData' | 'graphData' | 'fetch';
71
+
61
72
  constructor(graph: IGraph<any, any>) {
62
73
  this.graph = graph;
63
74
  this.tap();
@@ -181,15 +192,9 @@ export class DataController {
181
192
  */
182
193
  private onDataChange(param: { data: DataConfig; type: DataChangeType }) {
183
194
  const { data, type: changeType } = param;
184
- const { userGraphCore } = this;
195
+ const { graphCore } = this;
185
196
  const change = () => {
186
197
  switch (changeType) {
187
- case 'remove':
188
- this.removeData(data as GraphData);
189
- break;
190
- case 'update':
191
- this.updateData(data);
192
- break;
193
198
  case 'moveCombo':
194
199
  this.moveCombo(data as GraphData);
195
200
  break;
@@ -197,13 +202,13 @@ export class DataController {
197
202
  this.addCombo(data as GraphData);
198
203
  break;
199
204
  default:
200
- // changeType is 'replace' | 'mergeReplace' | 'union'
205
+ // changeType is 'replace' | 'mergeReplace' | 'union' | 'remove' | 'update'
201
206
  this.changeData(data, changeType);
202
207
  break;
203
208
  }
204
209
  };
205
- if (userGraphCore) {
206
- userGraphCore.batch(change);
210
+ if (graphCore) {
211
+ graphCore.batch(change);
207
212
  } else {
208
213
  change();
209
214
  }
@@ -215,7 +220,7 @@ export class DataController {
215
220
  }) {
216
221
  const { ids, action } = params;
217
222
  ids.forEach((id) => {
218
- this.userGraphCore.mergeNodeData(id, {
223
+ this.graphCore.mergeNodeData(id, {
219
224
  collapsed: action === 'collapse',
220
225
  });
221
226
  });
@@ -223,7 +228,7 @@ export class DataController {
223
228
 
224
229
  private onLayout({ options }) {
225
230
  if (this.treeDirtyFlag && isTreeLayout(options)) {
226
- this.establishUserGraphCoreTree();
231
+ this.establishGraphCoreTree();
227
232
  }
228
233
  }
229
234
 
@@ -231,7 +236,7 @@ export class DataController {
231
236
  const { modes = {} } = this.graph.getSpecification();
232
237
  const mode = this.graph.getMode() || 'default';
233
238
  if (hasTreeBehaviors(modes[mode])) {
234
- this.establishUserGraphCoreTree();
239
+ this.establishGraphCoreTree();
235
240
  }
236
241
  }
237
242
 
@@ -244,31 +249,29 @@ export class DataController {
244
249
  const mode = this.graph.getMode() || 'default';
245
250
  if (action !== 'add' || !modes.includes(mode)) return;
246
251
  if (hasTreeBehaviors(behaviors)) {
247
- this.establishUserGraphCoreTree();
252
+ this.establishGraphCoreTree();
248
253
  }
249
254
  }
250
255
 
251
256
  private onModeChange(param: { mode: string }) {
252
257
  const { modes = {} } = this.graph.getSpecification();
253
258
  if (hasTreeBehaviors(modes[param.mode])) {
254
- this.establishUserGraphCoreTree();
259
+ this.establishGraphCoreTree();
255
260
  }
256
261
  }
257
262
 
258
- private establishUserGraphCoreTree() {
263
+ private establishGraphCoreTree() {
259
264
  if (!this.treeDirtyFlag) return;
260
- const nodes = this.userGraphCore.getAllNodes();
261
- const edges = this.userGraphCore.getAllEdges();
262
- this.userGraphCore.batch(() => {
263
- // graph data to tree structure and storing
264
- const rootIds = nodes
265
- .filter((node) => node.data.isRoot)
266
- .map((node) => node.id);
267
- graphData2TreeData({}, { nodes, edges }, rootIds).forEach((tree) => {
268
- traverse(tree, (node) => {
269
- node.children?.forEach((child) => {
270
- this.userGraphCore.setParent(child.id, node.id, 'tree');
271
- });
265
+ const nodes = this.graphCore.getAllNodes();
266
+ const edges = this.graphCore.getAllEdges();
267
+ // graph data to tree structure and storing
268
+ const rootIds = nodes
269
+ .filter((node) => node.data.isRoot)
270
+ .map((node) => node.id);
271
+ graphData2TreeData({}, { nodes, edges }, rootIds).forEach((tree) => {
272
+ traverse(tree, (node) => {
273
+ node.children?.forEach((child) => {
274
+ this.graphCore.setParent(child.id, node.id, 'tree');
272
275
  });
273
276
  });
274
277
  });
@@ -276,30 +279,26 @@ export class DataController {
276
279
  }
277
280
 
278
281
  /**
279
- * Change data by replace, merge repalce, or union.
282
+ * Change data by replace, merge repalce, union, remove or update.
280
283
  * @param data new data
281
- * @param changeType type of data change, 'replace' means discard the old data. 'mergeReplace' means merge the common part. 'union' means merge whole sets of old and new one
284
+ * @param changeType type of data change, 'replace' means discard the old data. 'mergeReplace' means merge the common part. 'union' means merge whole sets of old and new one. 'remove' means remove the common part. 'update' means update the comme part.
282
285
  */
283
286
  private changeData(
284
287
  dataConfig: DataConfig,
285
- changeType: 'replace' | 'mergeReplace' | 'union',
288
+ changeType: 'replace' | 'mergeReplace' | 'union' | 'remove' | 'update',
286
289
  ) {
287
290
  const { type: dataType, data } = this.formatData(dataConfig) || {};
288
291
  if (!dataType) return;
292
+ this.dataType = dataType;
289
293
 
290
- const { nodes = [], edges = [], combos = [] } = this.transformData(data);
294
+ const preprocessedData = this.preprocessData(data, changeType);
295
+ const { dataAdded, dataRemoved, dataUpdated } = this.transformData(
296
+ preprocessedData,
297
+ changeType,
298
+ );
291
299
 
292
300
  if (changeType === 'replace') {
293
- this.userGraphCore = new GraphLib<NodeUserModelData, EdgeUserModelData>({
294
- nodes: nodes.concat(
295
- combos?.map((combo) => ({
296
- id: combo.id,
297
- data: { ...combo.data, _isCombo: true },
298
- })) || [],
299
- ),
300
- edges,
301
- onChanged: (event) => this.updateGraphCore(event),
302
- });
301
+ const { nodes, edges, combos } = dataAdded;
303
302
  this.graphCore = new GraphLib<NodeModelData, EdgeModelData>(
304
303
  clone({
305
304
  nodes: nodes.concat(
@@ -341,229 +340,205 @@ export class DataController {
341
340
  });
342
341
  }
343
342
  } else {
344
- const { userGraphCore } = this;
345
- const prevData = deconstructData({
346
- nodes: userGraphCore.getAllNodes(),
347
- edges: [],
348
- });
349
- const nodesAndCombos = nodes.concat(
350
- combos.map((combo) => ({
351
- id: combo.id,
352
- data: { ...combo.data, _isCombo: true },
353
- })),
354
- );
355
-
356
- // =========== node & combos ============
357
- if (!prevData.nodes.length) {
358
- userGraphCore.addNodes(nodesAndCombos);
359
- } else {
360
- if (changeType === 'mergeReplace') {
361
- // remove the nodes which are not in data but in userGraphCore
362
- const nodeAndComboIds = nodesAndCombos.map((node) => node.id);
363
- prevData.nodes.forEach((prevNode) => {
364
- if (!nodeAndComboIds.includes(prevNode.id))
365
- userGraphCore.removeNode(prevNode.id);
366
- });
367
- }
368
- // add or update node
369
- nodesAndCombos.forEach((item) => {
370
- if (userGraphCore.hasNode(item.id)) {
371
- // update node which is in the graphCore
372
- userGraphCore.mergeNodeData(item.id, item.data);
373
- } else {
374
- // add node which is in data but not in graphCore
375
- userGraphCore.addNode(item);
376
- }
377
- });
378
- }
379
-
380
- // =========== edge ============
381
- prevData.edges = userGraphCore.getAllEdges();
382
- if (!prevData.edges.length) {
383
- userGraphCore.addEdges(edges);
384
- } else {
385
- if (changeType === 'mergeReplace') {
386
- // remove the edges which are not in data but in userGraphCore
387
- const edgeIds = edges.map((edge) => edge.id);
388
- prevData.edges.forEach((prevEdge) => {
389
- if (!edgeIds.includes(prevEdge.id))
390
- userGraphCore.removeEdge(prevEdge.id);
391
- });
392
- }
393
- // add or update edge
394
- edges.forEach((edge) => {
395
- if (userGraphCore.hasEdge(edge.id)) {
396
- // update edge which is in the graphCore
397
- userGraphCore.mergeEdgeData(edge.id, edge.data);
398
- } else {
399
- // add edge which is in data but not in graphCore
400
- userGraphCore.addEdge(edge);
401
- }
402
- });
403
- }
343
+ this.doRemove(dataRemoved);
344
+ this.doAdd(dataAdded);
345
+ this.doUpdate(dataUpdated);
404
346
  }
405
347
 
406
- if (data.edges?.length) {
407
- const { userGraphCore } = this;
348
+ if (
349
+ data.edges?.filter(
350
+ (edge) =>
351
+ edge.hasOwnProperty('source') || edge.hasOwnProperty('target'),
352
+ ).length
353
+ ) {
408
354
  // convert and store tree structure to graphCore
409
355
  this.updateTreeGraph(dataType, {
410
- nodes: userGraphCore.getAllNodes(),
411
- edges: userGraphCore.getAllEdges(),
356
+ nodes: this.graphCore.getAllNodes(),
357
+ edges: this.graphCore.getAllEdges(),
412
358
  });
413
359
  }
414
360
  }
415
361
 
416
362
  /**
417
- * Remove part of old data.
418
- * @param data data to be removed which is part of old one
363
+ * Add new data.
364
+ * @param data data to be added which is not in graphCore
419
365
  */
420
- private removeData(data: GraphData) {
421
- const { userGraphCore } = this;
366
+ private doAdd(data: GraphData) {
367
+ if (isEmpty(data)) return;
368
+
369
+ const { graphCore } = this;
422
370
  const { nodes = [], edges = [], combos = [] } = data;
423
- const nodesAndCombos = nodes.concat(combos);
424
- const prevNodesAndCombos = userGraphCore.getAllNodes();
425
- const prevEdges = userGraphCore.getAllEdges();
426
- if (prevNodesAndCombos.length && nodesAndCombos.length) {
427
- // update the parentId
428
- if (this.graphCore.hasTreeStructure('combo')) {
429
- nodesAndCombos.forEach((item) => {
430
- const { parentId } = item.data;
431
- this.graphCore.getChildren(item.id, 'combo').forEach((child) => {
432
- userGraphCore.mergeNodeData(child.id, { parentId });
433
- });
434
- });
435
- }
436
- // remove the node
437
- userGraphCore.removeNodes(nodesAndCombos.map((node) => node.id));
371
+
372
+ if (nodes.length || combos.length) {
373
+ const nodesAndCombos = getNodesAndCombos(data);
374
+ graphCore.addNodes(nodesAndCombos);
438
375
  }
439
- if (prevEdges.length && edges.length) {
440
- // add or update edge
441
- const ids = edges
442
- .map((edge) => edge.id)
443
- .filter((id) => userGraphCore.hasEdge(id));
444
- userGraphCore.removeEdges(ids);
376
+
377
+ if (edges.length) {
378
+ graphCore.addEdges(edges);
445
379
  }
446
380
  }
447
381
 
448
382
  /**
449
383
  * Update part of old data.
450
- * @param data data to be updated which is part of old one
384
+ * @param data data to be updated which is part of old one in the graphCore
451
385
  */
452
- private updateData(dataConfig: DataConfig) {
453
- const { userGraphCore } = this;
454
- const { type: dataType, data } = this.formatData(dataConfig);
455
- if (!dataType) return;
456
- const { nodes = [], edges = [], combos = [] } = data; //this.transformData(data as GraphData);
457
- const {
458
- nodes: prevNodes,
459
- edges: prevEdges,
460
- combos: prevCombos,
461
- } = deconstructData({
462
- nodes: userGraphCore.getAllNodes(),
463
- edges: userGraphCore.getAllEdges(),
386
+ private doUpdate(data: GraphData) {
387
+ if (isEmpty(data)) return;
388
+
389
+ const { graphCore } = this;
390
+ const { nodes = [], edges = [], combos = [] } = data;
391
+
392
+ // update node
393
+ nodes.forEach((newModel) => {
394
+ const { id, data } = newModel;
395
+ if (data) {
396
+ const mergedData = mergeOneLevelData(graphCore.getNode(id), newModel);
397
+ graphCore.mergeNodeData(id, mergedData);
398
+ }
399
+ if (data.hasOwnProperty('parentId')) {
400
+ graphCore.setParent(id, data.parentId, 'combo');
401
+ }
464
402
  });
465
- if (prevNodes.length) {
466
- // update node
467
- nodes.forEach((newModel) => {
468
- const { id, data } = newModel;
469
- if (data) {
470
- const mergedData = mergeOneLevelData(
471
- userGraphCore.getNode(id),
472
- newModel,
473
- );
474
- userGraphCore.mergeNodeData(id, mergedData);
475
- }
476
- });
477
- }
478
- if (prevEdges.length) {
479
- // update edge
480
- edges.forEach((newModel) => {
481
- const oldModel = userGraphCore.getEdge(newModel.id);
482
- if (!oldModel) return;
483
- const { id, source, target, data } = newModel;
484
- if (source && oldModel.source !== source)
485
- userGraphCore.updateEdgeSource(id, source);
486
- if (target && oldModel.target !== target)
487
- userGraphCore.updateEdgeTarget(id, target);
488
- if (data) {
489
- const mergedData = mergeOneLevelData(
490
- userGraphCore.getEdge(id),
491
- newModel,
403
+
404
+ // update edge
405
+ edges.forEach((newModel) => {
406
+ const oldModel = graphCore.getEdge(newModel.id);
407
+ if (!oldModel) return;
408
+ const { id, source, target, data } = newModel;
409
+ if (source && oldModel.source !== source)
410
+ graphCore.updateEdgeSource(id, source);
411
+ if (target && oldModel.target !== target)
412
+ graphCore.updateEdgeTarget(id, target);
413
+ if (data) {
414
+ const mergedData = mergeOneLevelData(graphCore.getEdge(id), newModel);
415
+ graphCore.mergeEdgeData(id, mergedData);
416
+ }
417
+ });
418
+
419
+ // update combos
420
+ const modelsToMove = [];
421
+ combos.forEach((newModel) => {
422
+ const { id, data } = newModel;
423
+ const { x: comboNewX, y: comboNewY, ...others } = data;
424
+ if (comboNewX !== undefined || comboNewY !== undefined) {
425
+ if (this.graphCore.getChildren(id, 'combo').length) {
426
+ // combo's position is updated, update the succeed nodes' positions
427
+ const oldBounds = this.graph.getRenderBBox(id, true);
428
+ if (!oldBounds) return;
429
+ const [comboOldX, comboOldY] = oldBounds.center;
430
+ const dx = (comboNewX as number) - comboOldX;
431
+ const dy = (comboNewY as number) - comboOldY;
432
+ graphComboTreeDfs(
433
+ this.graph,
434
+ [newModel],
435
+ (succeed) => {
436
+ const { x, y, _isCombo } = succeed.data;
437
+ if (!_isCombo) {
438
+ modelsToMove.push({
439
+ id: succeed.id,
440
+ data: {
441
+ x: x + dx,
442
+ y: y + dy,
443
+ },
444
+ });
445
+ }
446
+ },
447
+ 'BT',
492
448
  );
493
- userGraphCore.mergeEdgeData(id, mergedData);
494
- }
495
- });
496
- }
497
- if (prevCombos.length) {
498
- // update combos
499
- const modelsToMove = [];
500
- combos.forEach((newModel) => {
501
- const { id, data } = newModel;
502
- const { x: comboNewX, y: comboNewY, ...others } = data;
503
- if (comboNewX !== undefined || comboNewY !== undefined) {
504
- if (this.graphCore.getChildren(id, 'combo').length) {
505
- // combo's position is updated, update the succeed nodes' positions
506
- const oldBounds = this.graph.getRenderBBox(id, true);
507
- if (!oldBounds) return;
508
- const [comboOldX, comboOldY] = oldBounds.center;
509
- const dx = (comboNewX as number) - comboOldX;
510
- const dy = (comboNewY as number) - comboOldY;
511
- graphComboTreeDfs(
512
- this.graph,
513
- [newModel],
514
- (succeed) => {
515
- const { x, y, _isCombo } = succeed.data;
516
- if (!_isCombo) {
517
- modelsToMove.push({
518
- id: succeed.id,
519
- data: {
520
- x: x + dx,
521
- y: y + dy,
522
- },
523
- });
524
- }
525
- },
526
- 'BT',
527
- );
528
- } else {
529
- // empty combo, modify the position directly
530
- modelsToMove.push({
531
- id,
532
- data: {
533
- x: comboNewX,
534
- y: comboNewY,
535
- },
536
- });
537
- }
538
- }
539
- // update other properties
540
- if (Object.keys(others).length) {
541
- const mergedData = mergeOneLevelData(userGraphCore.getNode(id), {
449
+ } else {
450
+ // empty combo, modify the position directly
451
+ modelsToMove.push({
542
452
  id,
543
- data: others,
453
+ data: {
454
+ x: comboNewX,
455
+ y: comboNewY,
456
+ },
544
457
  });
545
- userGraphCore.mergeNodeData(id, mergedData);
546
458
  }
547
- });
548
- // update succeed nodes
549
- modelsToMove.forEach((newModel) => {
550
- const { id, data } = newModel;
551
- userGraphCore.mergeNodeData(id, data);
552
- });
459
+ }
460
+ // update other properties
461
+ if (Object.keys(others).length) {
462
+ const mergedData = mergeOneLevelData(graphCore.getNode(id), {
463
+ id,
464
+ data: others,
465
+ });
466
+ graphCore.mergeNodeData(id, mergedData);
467
+ if (others.hasOwnProperty('parentId')) {
468
+ graphCore.setParent(id, others.parentId, 'combo');
469
+ }
470
+ }
471
+ });
472
+ // update succeed nodes
473
+ modelsToMove.forEach((newModel) => {
474
+ const { id, data } = newModel;
475
+ graphCore.mergeNodeData(id, data);
476
+ });
477
+ }
478
+
479
+ /**
480
+ * Remove part of old data.
481
+ * @param data data to be removed which is part of old one in the graphCore
482
+ */
483
+ private doRemove(data: GraphData) {
484
+ if (isEmpty(data)) return;
485
+
486
+ const { graphCore } = this;
487
+
488
+ if (data.edges.length) {
489
+ // add or update edge
490
+ const ids = data.edges.map((edge) => edge.id);
491
+ graphCore.removeEdges(ids);
553
492
  }
554
493
 
555
- if (
556
- edges?.filter(
557
- (edge) =>
558
- edge.hasOwnProperty('source') || edge.hasOwnProperty('target'),
559
- ).length
560
- ) {
561
- // convert and store tree structure to graphCore
562
- this.updateTreeGraph(dataType, {
563
- nodes: this.userGraphCore.getAllNodes(),
564
- edges: this.userGraphCore.getAllEdges(),
494
+ const nodesAndCombos = getNodesAndCombos(data);
495
+ // update combo tree view and tree graph view
496
+ nodesAndCombos?.forEach((item) => this.removeNode(item));
497
+ }
498
+
499
+ private removeNode(nodeModel: NodeModel) {
500
+ const { id, data } = nodeModel;
501
+ const { graphCore } = this;
502
+ if (graphCore.hasTreeStructure('combo')) {
503
+ // remove from its parent's children list
504
+ graphCore.setParent(id, undefined, 'combo');
505
+ const { parentId } = data;
506
+ // move the children to the grandparent's children list
507
+ graphCore.getChildren(id, 'combo').forEach((child) => {
508
+ graphCore.setParent(child.id, parentId, 'combo');
509
+ graphCore.mergeNodeData(child.id, { parentId });
565
510
  });
566
511
  }
512
+ if (graphCore.hasTreeStructure('tree')) {
513
+ const succeedIds = [];
514
+ graphCore.dfsTree(
515
+ id,
516
+ (child) => {
517
+ succeedIds.push(child.id);
518
+ },
519
+ 'tree',
520
+ );
521
+ const succeedEdgeIds = graphCore
522
+ .getAllEdges()
523
+ .filter(
524
+ ({ source, target }) =>
525
+ succeedIds.includes(source) && succeedIds.includes(target),
526
+ )
527
+ .map((edge) => edge.id);
528
+ this.graph.showItem(
529
+ succeedIds
530
+ .filter((succeedId) => succeedId !== id)
531
+ .concat(succeedEdgeIds),
532
+ );
533
+
534
+ // for tree graph view, remove the node from the parent's children list
535
+ graphCore.setParent(id, undefined, 'tree');
536
+ // for tree graph view, make the its children to be roots
537
+ graphCore
538
+ .getChildren(id, 'tree')
539
+ .forEach((child) => graphCore.setParent(child.id, undefined, 'tree'));
540
+ }
541
+ graphCore.removeNode(id);
567
542
  }
568
543
 
569
544
  private formatData(dataConfig: DataConfig): {
@@ -589,13 +564,13 @@ export class DataController {
589
564
  }
590
565
 
591
566
  return {
592
- type: type || 'graphData',
567
+ type: type || this.dataType || 'graphData',
593
568
  data: data as GraphData,
594
569
  };
595
570
  }
596
571
 
597
572
  /**
598
- * Relatively move the position of combo a dinstance (dx and dy in combo data).
573
+ * Relatively move the position of combo a distance (dx and dy in combo data).
599
574
  * @param data graph data which contains the combo dx dy info
600
575
  */
601
576
  private moveCombo(data: GraphData) {
@@ -640,15 +615,12 @@ export class DataController {
640
615
  }
641
616
  });
642
617
  // update succeed nodes
643
- const { userGraphCore } = this;
618
+ const { graphCore } = this;
644
619
  succeedNodesModels.forEach((newModel) => {
645
620
  const { id, data } = newModel;
646
621
  if (data) {
647
- const mergedData = mergeOneLevelData(
648
- userGraphCore.getNode(id),
649
- newModel,
650
- );
651
- userGraphCore.mergeNodeData(id, mergedData);
622
+ const mergedData = mergeOneLevelData(graphCore.getNode(id), newModel);
623
+ graphCore.mergeNodeData(id, mergedData);
652
624
  }
653
625
  });
654
626
  }
@@ -656,17 +628,21 @@ export class DataController {
656
628
  private addCombo(data: GraphData) {
657
629
  const { combos = [] } = data;
658
630
  if (!combos?.length) return;
659
- const { userGraphCore } = this;
631
+ const { graphCore } = this;
660
632
  const { id, data: comboData } = combos[0];
661
633
  const { _children = [], ...others } = comboData;
662
634
 
635
+ if (!graphCore.hasTreeStructure('combo')) {
636
+ graphCore.attachTreeStructure('combo');
637
+ }
638
+
663
639
  // add or update combo
664
- if (userGraphCore.hasNode(id)) {
640
+ if (graphCore.hasNode(id)) {
665
641
  // update node which is in the graphCore
666
- userGraphCore.mergeNodeData(id, { ...others, _isCombo: true });
642
+ graphCore.mergeNodeData(id, { ...others, _isCombo: true });
667
643
  } else {
668
644
  // add node which is in data but not in graphCore
669
- userGraphCore.addNode({ id, data: { ...others, _isCombo: true } });
645
+ graphCore.addNode({ id, data: { ...others, _isCombo: true } });
670
646
  }
671
647
 
672
648
  // update strucutre
@@ -677,254 +653,92 @@ export class DataController {
677
653
  );
678
654
  return;
679
655
  }
680
- userGraphCore.mergeNodeData(childId, { parentId: id });
656
+ graphCore.setParent(childId, id, 'combo');
657
+ graphCore.mergeNodeData(childId, { parentId: id });
681
658
  });
682
659
  }
683
660
 
684
661
  /**
685
- * Update graphCore with transformed userGraphCore data.
662
+ * Preprocess the data and divide the data into three categories: Add, Update, Delete according to the operation type.
663
+ * @param data new graph data
664
+ * @param type type of data change
686
665
  */
687
- private updateGraphCore(event) {
666
+ private preprocessData(
667
+ data: DataConfig,
668
+ type: DataChangeType,
669
+ ): GraphDataChanges {
688
670
  const { graphCore } = this;
689
-
690
- const {
691
- nodes = [],
692
- edges = [],
693
- combos = [],
694
- } = deconstructData({
695
- nodes: this.userGraphCore.getAllNodes(),
696
- edges: this.userGraphCore.getAllEdges(),
697
- });
698
-
699
- const prevNodesAndCombos = graphCore.getAllNodes();
700
-
701
- // function to update one data in graphCore with different model type ('node' or 'edge')
702
- const syncUpdateToGraphCore = (
703
- id,
704
- newValue,
705
- oldValue,
706
- isNodeOrCombo,
707
- diff = [],
708
- ) => {
709
- if (isNodeOrCombo) {
710
- if (newValue.data) graphCore.updateNodeData(id, { ...newValue.data });
711
- } else {
712
- if (diff.includes('data'))
713
- graphCore.updateEdgeData(id, { ...newValue.data });
714
- // source and target may be changed
715
- if (diff.includes('source'))
716
- graphCore.updateEdgeSource(id, newValue.source);
717
- if (diff.includes('target'))
718
- graphCore.updateEdgeTarget(id, newValue.target);
719
- }
671
+ const dataCloned: GraphData = clone(data);
672
+ const prevData = graphCore
673
+ ? deconstructData({
674
+ nodes: graphCore.getAllNodes(),
675
+ edges: graphCore.getAllEdges(),
676
+ })
677
+ : {};
678
+ const { prevMinusNew, newMinusPrev, intersectionOfPrevAndNew } =
679
+ diffGraphData(prevData, dataCloned);
680
+
681
+ const dataChangeMap: Record<string, GraphDataChanges> = {
682
+ replace: { dataAdded: dataCloned, dataUpdated: {}, dataRemoved: {} },
683
+ mergeReplace: {
684
+ dataAdded: newMinusPrev,
685
+ dataUpdated: intersectionOfPrevAndNew,
686
+ dataRemoved: prevMinusNew,
687
+ },
688
+ union: {
689
+ dataAdded: newMinusPrev,
690
+ dataUpdated: intersectionOfPrevAndNew,
691
+ dataRemoved: {},
692
+ },
693
+ remove: {
694
+ dataAdded: {},
695
+ dataUpdated: {},
696
+ dataRemoved: intersectionOfPrevAndNew,
697
+ },
698
+ update: {
699
+ dataAdded: {},
700
+ dataUpdated: intersectionOfPrevAndNew,
701
+ dataRemoved: {},
702
+ },
720
703
  };
721
704
 
722
- graphCore.batch(() => {
723
- // === step 3: sync to graphCore according to the changes in userGraphCore ==
724
- const newModelMap: {
725
- [id: string]: {
726
- type: 'node' | 'edge' | 'combo';
727
- model: NodeModel | EdgeModel | ComboModel;
728
- };
729
- } = {};
730
- const parentMap: {
731
- [id: string]: {
732
- new: ID;
733
- old?: ID;
734
- };
735
- } = {};
736
- const changeMap: {
737
- [id: string]: boolean;
738
- } = {};
739
- const treeChanges = [];
740
- event.changes.forEach((change) => {
741
- const id = change.id || change.value?.id;
742
- if (id !== undefined) {
743
- changeMap[id] = true;
744
- return;
745
- }
746
- if (
747
- [
748
- 'TreeStructureAttached',
749
- 'TreeStructureChanged',
750
- 'TreeStructureChanged',
751
- ].includes(change.type)
752
- ) {
753
- treeChanges.push(change);
754
- }
755
- });
756
- nodes.forEach((model) => {
757
- newModelMap[model.id] = { type: 'node', model };
758
- if (model.data.hasOwnProperty('parentId')) {
759
- parentMap[model.id] = {
760
- new: model.data.parentId,
761
- old: undefined,
762
- };
763
- }
764
- });
765
- edges.forEach(
766
- (model) => (newModelMap[model.id] = { type: 'edge', model }),
767
- );
768
- combos.forEach((model) => {
769
- newModelMap[model.id] = { type: 'combo', model };
770
- if (model.data.hasOwnProperty('parentId')) {
771
- parentMap[model.id] = {
772
- new: model.data.parentId,
773
- old: undefined,
774
- };
775
- }
776
- });
777
- prevNodesAndCombos.forEach((prevModel) => {
778
- const { id } = prevModel;
779
- if (
780
- parentMap[id]?.new !== undefined ||
781
- prevModel.data.parentId !== undefined
782
- ) {
783
- parentMap[id] = {
784
- new: parentMap[id]?.new,
785
- old: prevModel.data.parentId,
786
- };
787
- } else {
788
- delete parentMap[id];
789
- }
790
- const { model: newModel } = newModelMap[id] || {};
791
- // remove
792
- if (!newModel) {
793
- // remove a combo, put the children to upper parent
794
- if (prevModel.data._isCombo) {
795
- graphCore.getChildren(id, 'combo').forEach((child) => {
796
- parentMap[child.id] = {
797
- ...parentMap[child.id],
798
- new: prevModel.data.parentId,
799
- };
800
- });
801
- }
802
- // if it has combo parent, remove it from the parent's children list
803
- if (prevModel.data.parentId) {
804
- graphCore.setParent(id, undefined, 'combo');
805
- }
806
-
807
- // for tree graph view, show the succeed nodes and edges
808
- const succeedIds = [];
809
- if (graphCore.hasTreeStructure('tree')) {
810
- graphCore.dfsTree(
811
- id,
812
- (child) => {
813
- succeedIds.push(child.id);
814
- },
815
- 'tree',
816
- );
817
- const succeedEdgeIds = graphCore
818
- .getAllEdges()
819
- .filter(
820
- ({ source, target }) =>
821
- succeedIds.includes(source) && succeedIds.includes(target),
822
- )
823
- .map((edge) => edge.id);
824
- this.graph.showItem(
825
- succeedIds
826
- .filter((succeedId) => succeedId !== id)
827
- .concat(succeedEdgeIds),
828
- );
829
-
830
- // for tree graph view, remove the node from the parent's children list
831
- graphCore.setParent(id, undefined, 'tree');
832
- // for tree graph view, make the its children to be roots
833
- graphCore
834
- .getChildren(id, 'tree')
835
- .forEach((child) =>
836
- graphCore.setParent(child.id, undefined, 'tree'),
837
- );
838
- }
839
- // remove the node data
840
- graphCore.removeNode(id);
841
- delete parentMap[prevModel.id];
842
- }
843
- // update
844
- // || diffAt(newModel, prevModel, true)?.length
845
- else if (changeMap[id])
846
- syncUpdateToGraphCore(id, newModel, prevModel, true);
847
- // delete from the map indicates this model is visited
848
- delete newModelMap[id];
849
- });
850
- graphCore.getAllEdges().forEach((prevEdge) => {
851
- const { id } = prevEdge;
852
- const { model: newModel } = newModelMap[id] || {};
853
- // remove
854
- if (!newModel) graphCore.removeEdge(id);
855
- // update
856
- else {
857
- const diff = diffAt(newModel, prevEdge, false);
858
- if (diff?.length)
859
- syncUpdateToGraphCore(id, newModel, prevEdge, false, diff);
860
- }
861
- // delete from the map indicates this model is visited
862
- delete newModelMap[id];
863
- });
864
- // add
865
- Object.values(newModelMap).forEach(({ type, model }) => {
866
- if (type === 'node' || type === 'combo') graphCore.addNode(model);
867
- else if (type === 'edge') graphCore.addEdge(model as EdgeModel);
868
- });
869
- // update parents after adding all items
870
- Object.keys(parentMap).forEach((id) => {
871
- if (parentMap[id].new === parentMap[id].old) return;
872
- if (!validateComboStrucutre(this.graph, id, parentMap[id].new)) {
873
- graphCore.mergeNodeData(id, { parentId: parentMap[id].old });
874
- return;
875
- }
876
- graphCore.mergeNodeData(id, { parentId: parentMap[id].new });
877
- graphCore.setParent(id, parentMap[id].new, 'combo');
878
- // after remove from parent's children list, check whether the parent is empty
879
- // if so, update parent's position to be the child's
880
- if (parentMap[id].old !== undefined) {
881
- const parentChildren = graphCore.getChildren(
882
- parentMap[id].old,
883
- 'combo',
884
- );
885
- const {
886
- x = 0,
887
- y = 0,
888
- z = 0,
889
- } = this.graph.getDisplayModel(parentMap[id].old)?.data || {};
890
- if (!parentChildren.length) {
891
- graphCore.mergeNodeData(parentMap[id].old, {
892
- x: convertToNumber(x),
893
- y: convertToNumber(y),
894
- z: convertToNumber(z),
895
- });
896
- }
897
- }
898
- });
899
-
900
- // update tree structure
901
- treeChanges.forEach((change) => {
902
- const { type, treeKey, nodeId, newParentId } = change;
903
- if (type === 'TreeStructureAttached') {
904
- graphCore.attachTreeStructure(treeKey);
905
- return;
906
- } else if (type === 'TreeStructureChanged') {
907
- graphCore.setParent(nodeId, newParentId, treeKey);
908
- return;
909
- } else if (type === 'TreeStructureDetached') {
910
- graphCore.detachTreeStructure(treeKey);
911
- return;
912
- }
913
- });
914
- });
705
+ return dataChangeMap[type];
915
706
  }
916
707
 
917
708
  /**
918
- * Clone data from userGraphCore, and run transforms
709
+ * Determine whether to execute transform in the current data life cycle
710
+ * @param config transform plugin's configuration
711
+ * @param changeType type of data change
712
+ */
713
+ private isTransformActive = (config: any, changeType: DataChangeType) => {
714
+ let activeLifecycle =
715
+ isObject(config) && 'activeLifecycle' in config
716
+ ? (config as any).activeLifecycle
717
+ : DEFAULT_ACTIVE_DATA_LIFECYCLE;
718
+ activeLifecycle = Array.isArray(activeLifecycle)
719
+ ? activeLifecycle
720
+ : activeLifecycle === 'all'
721
+ ? AVAILABLE_DATA_LIFECYCLE
722
+ : [activeLifecycle];
723
+
724
+ return (activeLifecycle as string[]).includes(dataLifecycleMap[changeType]);
725
+ };
726
+
727
+ /**
728
+ * run transforms on preprocessed data
919
729
  * @returns transformed data and the id map list
920
730
  */
921
- private transformData(data): GraphData {
922
- let dataCloned: GraphData = clone(data);
731
+ private transformData(
732
+ data: GraphDataChanges,
733
+ changeType: DataChangeType,
734
+ ): GraphDataChanges {
923
735
  // transform the data with transform extensions, output innerData and idMaps ===
924
736
  this.extensions.forEach(({ func, config }) => {
925
- dataCloned = func(dataCloned, config, this.userGraphCore);
737
+ if (this.isTransformActive(config, changeType)) {
738
+ data = func(data, config, this.graphCore);
739
+ }
926
740
  });
927
- return dataCloned;
741
+ return data;
928
742
  }
929
743
 
930
744
  /**
@@ -933,12 +747,12 @@ export class DataController {
933
747
  * @param data
934
748
  */
935
749
  private updateTreeGraph(dataType, data) {
936
- this.userGraphCore.attachTreeStructure('tree');
750
+ this.graphCore.attachTreeStructure('tree');
937
751
  if (dataType === 'treeData') {
938
752
  // tree structure storing
939
753
  data.edges.forEach((edge) => {
940
754
  const { source, target } = edge;
941
- this.userGraphCore.setParent(target, source, 'tree');
755
+ this.graphCore.setParent(target, source, 'tree');
942
756
  });
943
757
  } else {
944
758
  this.treeDirtyFlag = true;
@@ -1047,3 +861,70 @@ const mergeOneLevelData = (
1047
861
  });
1048
862
  return mergedData;
1049
863
  };
864
+
865
+ type UserModels = (
866
+ | Partial<NodeUserModel>
867
+ | Partial<EdgeUserModel>
868
+ | Partial<ComboUserModel>
869
+ )[];
870
+
871
+ /**
872
+ * Generate the difference between two model list
873
+ * @param prevModels
874
+ * @param newModels
875
+ * @returns
876
+ */
877
+ const diffData = (
878
+ prevModels: UserModels = [],
879
+ newModels: UserModels = [],
880
+ ): {
881
+ prevMinusNew: UserModels;
882
+ newMinusPrev: UserModels;
883
+ intersectionOfPrevAndNew: UserModels;
884
+ } => {
885
+ const prevIds = new Set(prevModels?.map((item) => item.id));
886
+ const newIds = new Set(newModels?.map((item) => item.id));
887
+
888
+ return {
889
+ prevMinusNew: prevModels?.filter((item) => !newIds.has(item.id)),
890
+ newMinusPrev: newModels?.filter((item) => !prevIds.has(item.id)),
891
+ intersectionOfPrevAndNew: newModels?.filter((item) => prevIds.has(item.id)),
892
+ };
893
+ };
894
+
895
+ /**
896
+ * Compute the difference between two graph data structure.
897
+ * @param prevData
898
+ * @param newData
899
+ * @returns
900
+ */
901
+ const diffGraphData = (prevData: GraphData, newData: GraphData) => {
902
+ const result: {
903
+ prevMinusNew: GraphData;
904
+ newMinusPrev: GraphData;
905
+ intersectionOfPrevAndNew: GraphData;
906
+ } = {
907
+ newMinusPrev: { nodes: [], edges: [], combos: [] },
908
+ prevMinusNew: { nodes: [], edges: [], combos: [] },
909
+ intersectionOfPrevAndNew: { nodes: [], edges: [], combos: [] },
910
+ };
911
+
912
+ ['nodes', 'edges', 'combos'].forEach((key) => {
913
+ const diff = diffData(prevData[key], newData[key]);
914
+ result.newMinusPrev[key] = diff.newMinusPrev;
915
+ result.prevMinusNew[key] = diff.prevMinusNew;
916
+ result.intersectionOfPrevAndNew[key] = diff.intersectionOfPrevAndNew;
917
+ });
918
+
919
+ return result;
920
+ };
921
+
922
+ const getNodesAndCombos = (data: GraphData) => {
923
+ const { nodes = [], combos = [] } = data;
924
+ return nodes.concat(
925
+ combos.map((combo) => ({
926
+ id: combo.id,
927
+ data: { ...combo.data, _isCombo: true },
928
+ })),
929
+ );
930
+ };