@antv/g6 5.0.0-alpha.8 → 5.0.0-alpha.9

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 (290) hide show
  1. package/dist/g6.min.js +6 -19
  2. package/esm/index.d.ts +26 -6
  3. package/esm/item/combo.d.ts +72 -2
  4. package/esm/item/combo.js +122 -2
  5. package/esm/item/combo.js.map +1 -1
  6. package/esm/item/edge.d.ts +3 -3
  7. package/esm/item/edge.js +4 -5
  8. package/esm/item/edge.js.map +1 -1
  9. package/esm/item/item.d.ts +4 -4
  10. package/esm/item/item.js +38 -9
  11. package/esm/item/item.js.map +1 -1
  12. package/esm/item/node.d.ts +20 -16
  13. package/esm/item/node.js +14 -8
  14. package/esm/item/node.js.map +1 -1
  15. package/esm/runtime/controller/data.d.ts +12 -4
  16. package/esm/runtime/controller/data.js +354 -62
  17. package/esm/runtime/controller/data.js.map +1 -1
  18. package/esm/runtime/controller/interaction.js +16 -4
  19. package/esm/runtime/controller/interaction.js.map +1 -1
  20. package/esm/runtime/controller/item.d.ts +11 -2
  21. package/esm/runtime/controller/item.js +344 -52
  22. package/esm/runtime/controller/item.js.map +1 -1
  23. package/esm/runtime/controller/layout.js +19 -5
  24. package/esm/runtime/controller/layout.js.map +1 -1
  25. package/esm/runtime/graph.d.ts +54 -17
  26. package/esm/runtime/graph.js +165 -34
  27. package/esm/runtime/graph.js.map +1 -1
  28. package/esm/stdlib/behavior/click-select.d.ts +3 -0
  29. package/esm/stdlib/behavior/click-select.js +13 -1
  30. package/esm/stdlib/behavior/click-select.js.map +1 -1
  31. package/esm/stdlib/behavior/collapse-expand-combo.d.ts +29 -0
  32. package/esm/stdlib/behavior/collapse-expand-combo.js +35 -0
  33. package/esm/stdlib/behavior/collapse-expand-combo.js.map +1 -0
  34. package/esm/stdlib/behavior/drag-combo.d.ts +99 -0
  35. package/esm/stdlib/behavior/drag-combo.js +341 -0
  36. package/esm/stdlib/behavior/drag-combo.js.map +1 -0
  37. package/esm/stdlib/behavior/drag-node.d.ts +14 -10
  38. package/esm/stdlib/behavior/drag-node.js +134 -37
  39. package/esm/stdlib/behavior/drag-node.js.map +1 -1
  40. package/esm/stdlib/behavior/hover-activate.d.ts +3 -1
  41. package/esm/stdlib/behavior/hover-activate.js +3 -1
  42. package/esm/stdlib/behavior/hover-activate.js.map +1 -1
  43. package/esm/stdlib/behavior/orbit-canvas-3d.js +1 -1
  44. package/esm/stdlib/behavior/orbit-canvas-3d.js.map +1 -1
  45. package/esm/stdlib/behavior/track-canvas-3d.js +1 -1
  46. package/esm/stdlib/behavior/track-canvas-3d.js.map +1 -1
  47. package/esm/stdlib/index.d.ts +25 -3
  48. package/esm/stdlib/index.js +25 -3
  49. package/esm/stdlib/index.js.map +1 -1
  50. package/esm/stdlib/item/combo/circle.d.ts +29 -0
  51. package/esm/stdlib/item/combo/circle.js +56 -0
  52. package/esm/stdlib/item/combo/circle.js.map +1 -0
  53. package/esm/stdlib/item/edge/base.d.ts +2 -2
  54. package/esm/stdlib/item/edge/base.js +3 -0
  55. package/esm/stdlib/item/edge/base.js.map +1 -1
  56. package/esm/stdlib/item/edge/cubic-horizon.d.ts +37 -0
  57. package/esm/stdlib/item/edge/cubic-horizon.js +71 -0
  58. package/esm/stdlib/item/edge/cubic-horizon.js.map +1 -0
  59. package/esm/stdlib/item/edge/cubic-vertical.d.ts +37 -0
  60. package/esm/stdlib/item/edge/cubic-vertical.js +71 -0
  61. package/esm/stdlib/item/edge/cubic-vertical.js.map +1 -0
  62. package/esm/stdlib/item/edge/cubic.d.ts +60 -0
  63. package/esm/stdlib/item/edge/cubic.js +99 -0
  64. package/esm/stdlib/item/edge/cubic.js.map +1 -0
  65. package/esm/stdlib/item/edge/index.d.ts +1 -0
  66. package/esm/stdlib/item/edge/index.js +1 -0
  67. package/esm/stdlib/item/edge/index.js.map +1 -1
  68. package/esm/stdlib/item/edge/line.d.ts +1 -1
  69. package/esm/stdlib/item/edge/quadratic.d.ts +41 -0
  70. package/esm/stdlib/item/edge/quadratic.js +66 -0
  71. package/esm/stdlib/item/edge/quadratic.js.map +1 -0
  72. package/esm/stdlib/item/node/base.d.ts +38 -37
  73. package/esm/stdlib/item/node/base.js +4 -4
  74. package/esm/stdlib/item/node/base.js.map +1 -1
  75. package/esm/stdlib/item/node/index.d.ts +1 -0
  76. package/esm/stdlib/item/node/index.js +1 -0
  77. package/esm/stdlib/item/node/index.js.map +1 -1
  78. package/esm/stdlib/item/node/rect.d.ts +31 -0
  79. package/esm/stdlib/item/node/rect.js +59 -0
  80. package/esm/stdlib/item/node/rect.js.map +1 -0
  81. package/esm/stdlib/plugin/fisheye/index.d.ts +102 -0
  82. package/esm/stdlib/plugin/fisheye/index.js +487 -0
  83. package/esm/stdlib/plugin/fisheye/index.js.map +1 -0
  84. package/esm/stdlib/plugin/menu/index.d.ts +42 -0
  85. package/esm/stdlib/plugin/menu/index.js +236 -0
  86. package/esm/stdlib/plugin/menu/index.js.map +1 -0
  87. package/esm/stdlib/plugin/tooltip/index.d.ts +75 -0
  88. package/esm/stdlib/plugin/tooltip/index.js +377 -0
  89. package/esm/stdlib/plugin/tooltip/index.js.map +1 -0
  90. package/esm/stdlib/theme/dark.js +4 -0
  91. package/esm/stdlib/theme/dark.js.map +1 -1
  92. package/esm/stdlib/theme/light.js +54 -9
  93. package/esm/stdlib/theme/light.js.map +1 -1
  94. package/esm/types/combo.d.ts +52 -3
  95. package/esm/types/data.d.ts +4 -4
  96. package/esm/types/edge.d.ts +2 -3
  97. package/esm/types/event.d.ts +9 -1
  98. package/esm/types/event.js +8 -8
  99. package/esm/types/event.js.map +1 -1
  100. package/esm/types/graph.d.ts +49 -13
  101. package/esm/types/hook.d.ts +8 -1
  102. package/esm/types/item.d.ts +4 -4
  103. package/esm/types/node.d.ts +4 -5
  104. package/esm/types/theme.d.ts +1 -1
  105. package/esm/util/animate.js.map +1 -1
  106. package/esm/util/canvas.js +8 -0
  107. package/esm/util/canvas.js.map +1 -1
  108. package/esm/util/data.d.ts +65 -0
  109. package/esm/util/data.js +150 -0
  110. package/esm/util/data.js.map +1 -0
  111. package/esm/util/event.d.ts +8 -0
  112. package/esm/util/event.js +16 -0
  113. package/esm/util/event.js.map +1 -1
  114. package/esm/util/item.d.ts +2 -1
  115. package/esm/util/item.js +36 -13
  116. package/esm/util/item.js.map +1 -1
  117. package/esm/util/shape.d.ts +39 -4
  118. package/esm/util/shape.js +101 -1
  119. package/esm/util/shape.js.map +1 -1
  120. package/esm/util/zoom.d.ts +2 -2
  121. package/lib/index.d.ts +26 -6
  122. package/lib/item/combo.d.ts +72 -2
  123. package/lib/item/combo.js +122 -2
  124. package/lib/item/combo.js.map +1 -1
  125. package/lib/item/edge.d.ts +3 -3
  126. package/lib/item/edge.js +4 -5
  127. package/lib/item/edge.js.map +1 -1
  128. package/lib/item/item.d.ts +4 -4
  129. package/lib/item/item.js +37 -8
  130. package/lib/item/item.js.map +1 -1
  131. package/lib/item/node.d.ts +20 -16
  132. package/lib/item/node.js +14 -8
  133. package/lib/item/node.js.map +1 -1
  134. package/lib/runtime/controller/data.d.ts +12 -4
  135. package/lib/runtime/controller/data.js +353 -61
  136. package/lib/runtime/controller/data.js.map +1 -1
  137. package/lib/runtime/controller/interaction.js +15 -3
  138. package/lib/runtime/controller/interaction.js.map +1 -1
  139. package/lib/runtime/controller/item.d.ts +11 -2
  140. package/lib/runtime/controller/item.js +342 -50
  141. package/lib/runtime/controller/item.js.map +1 -1
  142. package/lib/runtime/controller/layout.js +19 -5
  143. package/lib/runtime/controller/layout.js.map +1 -1
  144. package/lib/runtime/graph.d.ts +54 -17
  145. package/lib/runtime/graph.js +165 -34
  146. package/lib/runtime/graph.js.map +1 -1
  147. package/lib/stdlib/behavior/click-select.d.ts +3 -0
  148. package/lib/stdlib/behavior/click-select.js +13 -1
  149. package/lib/stdlib/behavior/click-select.js.map +1 -1
  150. package/lib/stdlib/behavior/collapse-expand-combo.d.ts +29 -0
  151. package/lib/stdlib/behavior/collapse-expand-combo.js +38 -0
  152. package/lib/stdlib/behavior/collapse-expand-combo.js.map +1 -0
  153. package/lib/stdlib/behavior/drag-combo.d.ts +99 -0
  154. package/lib/stdlib/behavior/drag-combo.js +344 -0
  155. package/lib/stdlib/behavior/drag-combo.js.map +1 -0
  156. package/lib/stdlib/behavior/drag-node.d.ts +14 -10
  157. package/lib/stdlib/behavior/drag-node.js +134 -37
  158. package/lib/stdlib/behavior/drag-node.js.map +1 -1
  159. package/lib/stdlib/behavior/hover-activate.d.ts +3 -1
  160. package/lib/stdlib/behavior/hover-activate.js +3 -2
  161. package/lib/stdlib/behavior/hover-activate.js.map +1 -1
  162. package/lib/stdlib/behavior/orbit-canvas-3d.js +1 -1
  163. package/lib/stdlib/behavior/orbit-canvas-3d.js.map +1 -1
  164. package/lib/stdlib/behavior/track-canvas-3d.js +1 -1
  165. package/lib/stdlib/behavior/track-canvas-3d.js.map +1 -1
  166. package/lib/stdlib/index.d.ts +25 -3
  167. package/lib/stdlib/index.js +25 -3
  168. package/lib/stdlib/index.js.map +1 -1
  169. package/lib/stdlib/item/combo/circle.d.ts +29 -0
  170. package/lib/stdlib/item/combo/circle.js +60 -0
  171. package/lib/stdlib/item/combo/circle.js.map +1 -0
  172. package/lib/stdlib/item/edge/base.d.ts +2 -2
  173. package/lib/stdlib/item/edge/base.js +3 -0
  174. package/lib/stdlib/item/edge/base.js.map +1 -1
  175. package/lib/stdlib/item/edge/cubic-horizon.d.ts +37 -0
  176. package/lib/stdlib/item/edge/cubic-horizon.js +75 -0
  177. package/lib/stdlib/item/edge/cubic-horizon.js.map +1 -0
  178. package/lib/stdlib/item/edge/cubic-vertical.d.ts +37 -0
  179. package/lib/stdlib/item/edge/cubic-vertical.js +75 -0
  180. package/lib/stdlib/item/edge/cubic-vertical.js.map +1 -0
  181. package/lib/stdlib/item/edge/cubic.d.ts +60 -0
  182. package/lib/stdlib/item/edge/cubic.js +103 -0
  183. package/lib/stdlib/item/edge/cubic.js.map +1 -0
  184. package/lib/stdlib/item/edge/index.d.ts +1 -0
  185. package/lib/stdlib/item/edge/index.js +1 -0
  186. package/lib/stdlib/item/edge/index.js.map +1 -1
  187. package/lib/stdlib/item/edge/line.d.ts +1 -1
  188. package/lib/stdlib/item/edge/quadratic.d.ts +41 -0
  189. package/lib/stdlib/item/edge/quadratic.js +70 -0
  190. package/lib/stdlib/item/edge/quadratic.js.map +1 -0
  191. package/lib/stdlib/item/node/base.d.ts +38 -37
  192. package/lib/stdlib/item/node/base.js +4 -4
  193. package/lib/stdlib/item/node/base.js.map +1 -1
  194. package/lib/stdlib/item/node/index.d.ts +1 -0
  195. package/lib/stdlib/item/node/index.js +1 -0
  196. package/lib/stdlib/item/node/index.js.map +1 -1
  197. package/lib/stdlib/item/node/rect.d.ts +31 -0
  198. package/lib/stdlib/item/node/rect.js +63 -0
  199. package/lib/stdlib/item/node/rect.js.map +1 -0
  200. package/lib/stdlib/plugin/fisheye/index.d.ts +102 -0
  201. package/lib/stdlib/plugin/fisheye/index.js +490 -0
  202. package/lib/stdlib/plugin/fisheye/index.js.map +1 -0
  203. package/lib/stdlib/plugin/menu/index.d.ts +42 -0
  204. package/lib/stdlib/plugin/menu/index.js +242 -0
  205. package/lib/stdlib/plugin/menu/index.js.map +1 -0
  206. package/lib/stdlib/plugin/tooltip/index.d.ts +75 -0
  207. package/lib/stdlib/plugin/tooltip/index.js +383 -0
  208. package/lib/stdlib/plugin/tooltip/index.js.map +1 -0
  209. package/lib/stdlib/theme/dark.js +4 -0
  210. package/lib/stdlib/theme/dark.js.map +1 -1
  211. package/lib/stdlib/theme/light.js +54 -9
  212. package/lib/stdlib/theme/light.js.map +1 -1
  213. package/lib/types/combo.d.ts +52 -3
  214. package/lib/types/data.d.ts +4 -4
  215. package/lib/types/edge.d.ts +2 -3
  216. package/lib/types/event.d.ts +9 -1
  217. package/lib/types/event.js +10 -10
  218. package/lib/types/event.js.map +1 -1
  219. package/lib/types/graph.d.ts +49 -13
  220. package/lib/types/hook.d.ts +8 -1
  221. package/lib/types/item.d.ts +4 -4
  222. package/lib/types/item.js +1 -1
  223. package/lib/types/item.js.map +1 -1
  224. package/lib/types/node.d.ts +4 -5
  225. package/lib/types/theme.d.ts +1 -1
  226. package/lib/util/animate.js.map +1 -1
  227. package/lib/util/canvas.js +8 -0
  228. package/lib/util/canvas.js.map +1 -1
  229. package/lib/util/data.d.ts +65 -0
  230. package/lib/util/data.js +161 -0
  231. package/lib/util/data.js.map +1 -0
  232. package/lib/util/event.d.ts +8 -0
  233. package/lib/util/event.js +18 -1
  234. package/lib/util/event.js.map +1 -1
  235. package/lib/util/item.d.ts +2 -1
  236. package/lib/util/item.js +36 -13
  237. package/lib/util/item.js.map +1 -1
  238. package/lib/util/shape.d.ts +39 -4
  239. package/lib/util/shape.js +105 -2
  240. package/lib/util/shape.js.map +1 -1
  241. package/lib/util/zoom.d.ts +2 -2
  242. package/package.json +13 -13
  243. package/src/item/combo.ts +220 -2
  244. package/src/item/edge.ts +7 -8
  245. package/src/item/item.ts +58 -15
  246. package/src/item/node.ts +47 -24
  247. package/src/runtime/controller/data.ts +390 -68
  248. package/src/runtime/controller/interaction.ts +23 -3
  249. package/src/runtime/controller/item.ts +444 -64
  250. package/src/runtime/controller/layout.ts +24 -5
  251. package/src/runtime/graph.ts +225 -38
  252. package/src/stdlib/behavior/click-select.ts +15 -2
  253. package/src/stdlib/behavior/collapse-expand-combo.ts +59 -0
  254. package/src/stdlib/behavior/drag-combo.ts +533 -0
  255. package/src/stdlib/behavior/drag-node.ts +195 -62
  256. package/src/stdlib/behavior/hover-activate.ts +4 -5
  257. package/src/stdlib/behavior/orbit-canvas-3d.ts +1 -1
  258. package/src/stdlib/behavior/track-canvas-3d.ts +1 -1
  259. package/src/stdlib/index.ts +25 -3
  260. package/src/stdlib/item/combo/circle.ts +113 -0
  261. package/src/stdlib/item/edge/base.ts +5 -2
  262. package/src/stdlib/item/edge/cubic-horizon.ts +114 -0
  263. package/src/stdlib/item/edge/cubic-vertical.ts +116 -0
  264. package/src/stdlib/item/edge/cubic.ts +198 -0
  265. package/src/stdlib/item/edge/index.ts +1 -0
  266. package/src/stdlib/item/edge/quadratic.ts +136 -0
  267. package/src/stdlib/item/node/base.ts +79 -41
  268. package/src/stdlib/item/node/index.ts +1 -0
  269. package/src/stdlib/item/node/rect.ts +124 -0
  270. package/src/stdlib/plugin/fisheye/index.ts +578 -0
  271. package/src/stdlib/plugin/menu/index.ts +260 -0
  272. package/src/stdlib/plugin/tooltip/index.ts +424 -0
  273. package/src/stdlib/theme/dark.ts +4 -0
  274. package/src/stdlib/theme/light.ts +77 -9
  275. package/src/types/combo.ts +61 -3
  276. package/src/types/data.ts +6 -4
  277. package/src/types/edge.ts +2 -2
  278. package/src/types/event.ts +8 -8
  279. package/src/types/graph.ts +73 -16
  280. package/src/types/hook.ts +8 -1
  281. package/src/types/item.ts +10 -9
  282. package/src/types/node.ts +4 -4
  283. package/src/types/theme.ts +1 -1
  284. package/src/util/animate.ts +2 -3
  285. package/src/util/canvas.ts +10 -0
  286. package/src/util/data.ts +178 -0
  287. package/src/util/event.ts +29 -0
  288. package/src/util/item.ts +75 -12
  289. package/src/util/shape.ts +142 -5
  290. package/src/util/zoom.ts +2 -2
@@ -1,7 +1,19 @@
1
- import { Graph as GraphLib } from '@antv/graphlib';
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { Graph as GraphLib, GraphView } from '@antv/graphlib';
2
13
  import { clone, isArray, isObject, } from '@antv/util';
3
14
  import { registery as registry } from '../../stdlib';
4
15
  import { getExtension } from '../../util/extension';
16
+ import { deconstructData, graphComboTreeDfs, validateComboStrucutre, } from '../../util/data';
5
17
  /**
6
18
  * Manages the data transform extensions;
7
19
  * Storages user data and inner data.
@@ -22,12 +34,25 @@ export class DataController {
22
34
  const ids = conditionIsArray ? condition : [condition];
23
35
  switch (type) {
24
36
  case 'node':
25
- return ids.map((id) => graphCore.hasNode(id) ? graphCore.getNode(id) : undefined);
37
+ return ids.map((id) => {
38
+ if (!graphCore.hasNode(id))
39
+ return undefined;
40
+ const model = graphCore.getNode(id);
41
+ if (model.data._isCombo)
42
+ return undefined;
43
+ return model;
44
+ });
26
45
  case 'edge':
27
46
  return ids.map((id) => graphCore.hasEdge(id) ? graphCore.getEdge(id) : undefined);
28
47
  case 'combo':
29
- // TODO;
30
- return;
48
+ return ids.map((id) => {
49
+ if (!graphCore.hasNode(id))
50
+ return undefined;
51
+ const model = graphCore.getNode(id);
52
+ if (!model.data._isCombo)
53
+ return undefined;
54
+ return model;
55
+ });
31
56
  }
32
57
  }
33
58
  else if (conditionType === 'function') {
@@ -53,16 +78,21 @@ export class DataController {
53
78
  return [];
54
79
  }
55
80
  }
56
- findRelatedEdgeIds(nodeId, direction = 'both') {
81
+ findRelatedEdges(nodeId, direction = 'both') {
57
82
  return this.graphCore.getRelatedEdges(nodeId, direction);
58
83
  }
59
- findNeighborNodeIds(nodeId, direction = 'both') {
84
+ findNeighborNodes(nodeId, direction = 'both') {
60
85
  if (direction === 'in')
61
86
  return this.graphCore.getAncestors(nodeId);
62
87
  if (direction === 'out')
63
88
  return this.graphCore.getSuccessors(nodeId);
64
89
  return this.graphCore.getNeighbors(nodeId);
65
90
  }
91
+ findChildren(comboId, treeKey) {
92
+ if (!this.graphCore.hasNode(comboId))
93
+ return;
94
+ return this.graphCore.getChildren(comboId, treeKey);
95
+ }
66
96
  /**
67
97
  * Subscribe the lifecycle of graph.
68
98
  */
@@ -96,6 +126,12 @@ export class DataController {
96
126
  case 'update':
97
127
  this.updateData(data);
98
128
  break;
129
+ case 'moveCombo':
130
+ this.moveCombo(data);
131
+ break;
132
+ case 'addCombo':
133
+ this.addCombo(data);
134
+ break;
99
135
  default:
100
136
  // 'replace' | 'mergeReplace' | 'union'
101
137
  this.changeData(data, changeType);
@@ -116,49 +152,98 @@ export class DataController {
116
152
  * @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
117
153
  */
118
154
  changeData(data, changeType) {
155
+ var _a;
119
156
  const { userGraphCore } = this;
120
157
  if (changeType === 'replace') {
121
- this.userGraphCore = new GraphLib(Object.assign(Object.assign({}, data), { onChanged: (event) => this.updateGraphCore(event) }));
158
+ this.userGraphCore = new GraphLib({
159
+ nodes: data.nodes.concat(((_a = data.combos) === null || _a === void 0 ? void 0 : _a.map((combo) => ({
160
+ id: combo.id,
161
+ data: Object.assign(Object.assign({}, combo.data), { _isCombo: true }),
162
+ }))) || []),
163
+ edges: data.edges,
164
+ onChanged: (event) => this.updateGraphCore(event),
165
+ });
122
166
  const { data: transformedData } = this.transformData();
123
- this.graphCore = new GraphLib(Object.assign({}, transformedData));
167
+ const { nodes = [], edges = [], combos = [] } = transformedData;
168
+ this.graphCore = new GraphLib({
169
+ nodes: nodes.concat((combos === null || combos === void 0 ? void 0 : combos.map((combo) => ({
170
+ id: combo.id,
171
+ data: Object.assign(Object.assign({}, combo.data), { _isCombo: true }),
172
+ }))) || []),
173
+ edges,
174
+ });
175
+ if (combos === null || combos === void 0 ? void 0 : combos.length) {
176
+ this.comboTreeView = new GraphView({
177
+ graph: this.graphCore,
178
+ cache: 'manual',
179
+ });
180
+ this.graphCore.attachTreeStructure('combo');
181
+ nodes.forEach((node) => {
182
+ if (node.data.parentId) {
183
+ if (validateComboStrucutre(this.graph, node.id, node.data.parentId)) {
184
+ this.graphCore.setParent(node.id, node.data.parentId, 'combo');
185
+ }
186
+ else {
187
+ this.graphCore.mergeNodeData(node.id, { parentId: undefined });
188
+ }
189
+ }
190
+ });
191
+ combos.forEach((combo) => {
192
+ if (combo.data.parentId) {
193
+ if (validateComboStrucutre(this.graph, combo.id, combo.data.parentId)) {
194
+ this.graphCore.setParent(combo.id, combo.data.parentId, 'combo');
195
+ }
196
+ else {
197
+ this.graphCore.mergeNodeData(combo.id, { parentId: undefined });
198
+ }
199
+ }
200
+ });
201
+ }
124
202
  }
125
203
  else {
126
- const prevNodes = userGraphCore.getAllNodes();
127
- const { nodes, edges, combos } = data;
128
- // TODO: distinguish combos
129
- if (!prevNodes.length) {
130
- userGraphCore.addNodes(nodes);
204
+ const prevData = deconstructData({
205
+ nodes: userGraphCore.getAllNodes(),
206
+ edges: userGraphCore.getAllEdges(),
207
+ });
208
+ const { nodes = [], edges = [], combos = [] } = data;
209
+ const nodesAndCombos = nodes.concat(combos.map((combo) => ({
210
+ id: combo.id,
211
+ data: Object.assign(Object.assign({}, combo.data), { _isCombo: true }),
212
+ })));
213
+ // =========== node & combos ============
214
+ if (!prevData.nodes.length) {
215
+ userGraphCore.addNodes(nodesAndCombos);
131
216
  }
132
217
  else {
133
218
  if (changeType === 'mergeReplace') {
134
219
  // remove the nodes which are not in data but in userGraphCore
135
- const nodeIds = nodes.map((node) => node.id);
136
- prevNodes.forEach((prevNode) => {
137
- if (!nodeIds.includes(prevNode.id))
220
+ const nodeAndComboIds = nodesAndCombos.map((node) => node.id);
221
+ prevData.nodes.forEach((prevNode) => {
222
+ if (!nodeAndComboIds.includes(prevNode.id))
138
223
  userGraphCore.removeNode(prevNode.id);
139
224
  });
140
225
  }
141
226
  // add or update node
142
- nodes.forEach((node) => {
143
- if (userGraphCore.hasNode(node.id)) {
227
+ nodesAndCombos.forEach((item) => {
228
+ if (userGraphCore.hasNode(item.id)) {
144
229
  // update node which is in the graphCore
145
- userGraphCore.mergeNodeData(node.id, node.data);
230
+ userGraphCore.mergeNodeData(item.id, item.data);
146
231
  }
147
232
  else {
148
233
  // add node which is in data but not in graphCore
149
- userGraphCore.addNode(node);
234
+ userGraphCore.addNode(item);
150
235
  }
151
236
  });
152
237
  }
153
- const prevEdges = userGraphCore.getAllEdges();
154
- if (!prevEdges.length) {
238
+ // =========== edge ============
239
+ if (!prevData.edges.length) {
155
240
  userGraphCore.addEdges(edges);
156
241
  }
157
242
  else {
158
243
  if (changeType === 'mergeReplace') {
159
244
  // remove the edges which are not in data but in userGraphCore
160
245
  const edgeIds = edges.map((edge) => edge.id);
161
- prevEdges.forEach((prevEdge) => {
246
+ prevData.edges.forEach((prevEdge) => {
162
247
  if (!edgeIds.includes(prevEdge.id))
163
248
  userGraphCore.removeEdge(prevEdge.id);
164
249
  });
@@ -183,19 +268,28 @@ export class DataController {
183
268
  */
184
269
  removeData(data) {
185
270
  const { userGraphCore } = this;
186
- const { nodes, edges, combos } = data;
187
- const prevNodes = userGraphCore.getAllNodes();
271
+ const { nodes = [], edges = [], combos = [] } = data;
272
+ const nodesAndCombos = nodes.concat(combos);
273
+ const prevNodesAndCombos = userGraphCore.getAllNodes();
188
274
  const prevEdges = userGraphCore.getAllEdges();
189
- // TODO: distinguish combos
190
- if (prevNodes.length && nodes.length) {
275
+ if (prevNodesAndCombos.length && nodesAndCombos.length) {
276
+ // update the parentId
277
+ nodesAndCombos.forEach((item) => {
278
+ const { parentId } = item.data;
279
+ this.graphCore.getChildren(item.id, 'combo').forEach((child) => {
280
+ userGraphCore.mergeNodeData(child.id, { parentId });
281
+ });
282
+ });
191
283
  // remove the node
192
- userGraphCore.removeNodes(nodes.map((node) => node.id));
284
+ userGraphCore.removeNodes(nodesAndCombos.map((node) => node.id));
193
285
  }
194
286
  if (prevEdges.length && edges.length) {
195
287
  // add or update edge
196
- userGraphCore.removeEdges(edges.map((edge) => edge.id));
288
+ const ids = edges
289
+ .map((edge) => edge.id)
290
+ .filter((id) => userGraphCore.hasEdge(id));
291
+ userGraphCore.removeEdges(ids);
197
292
  }
198
- // TODO: combo
199
293
  }
200
294
  /**
201
295
  * Update part of old data.
@@ -203,10 +297,11 @@ export class DataController {
203
297
  */
204
298
  updateData(data) {
205
299
  const { userGraphCore } = this;
206
- const { nodes, edges, combos } = data;
207
- const prevNodes = userGraphCore.getAllNodes();
208
- const prevEdges = userGraphCore.getAllEdges();
209
- // TODO: distinguish combos
300
+ const { nodes = [], edges = [], combos = [] } = data;
301
+ const { nodes: prevNodes, edges: prevEdges, combos: prevCombos, } = deconstructData({
302
+ nodes: userGraphCore.getAllNodes(),
303
+ edges: userGraphCore.getAllEdges(),
304
+ });
210
305
  if (prevNodes.length) {
211
306
  // update node
212
307
  nodes.forEach((newModel) => {
@@ -234,7 +329,135 @@ export class DataController {
234
329
  }
235
330
  });
236
331
  }
237
- // TODO: combo
332
+ if (prevCombos.length) {
333
+ // update combos
334
+ const modelsToMove = [];
335
+ combos.forEach((newModel) => {
336
+ const { id, data } = newModel;
337
+ const { x: comboNewX, y: comboNewY } = data, others = __rest(data, ["x", "y"]);
338
+ if (comboNewX !== undefined || comboNewY !== undefined) {
339
+ if (this.graphCore.getChildren(id, 'combo').length) {
340
+ // combo's position is updated, update the succeed nodes' positions
341
+ const oldBounds = this.graph.getRenderBBox(id, true);
342
+ if (!oldBounds)
343
+ return;
344
+ const [comboOldX, comboOldY] = oldBounds.center;
345
+ const dx = comboNewX - comboOldX;
346
+ const dy = comboNewY - comboOldY;
347
+ graphComboTreeDfs(this.graph, [newModel], (succeed) => {
348
+ const { x, y, _isCombo } = succeed.data;
349
+ if (!_isCombo) {
350
+ modelsToMove.push({
351
+ id: succeed.id,
352
+ data: {
353
+ x: x + dx,
354
+ y: y + dy,
355
+ },
356
+ });
357
+ }
358
+ }, 'BT');
359
+ }
360
+ else {
361
+ // empty combo, modify the position directly
362
+ modelsToMove.push({
363
+ id,
364
+ data: {
365
+ x: comboNewX,
366
+ y: comboNewY,
367
+ },
368
+ });
369
+ }
370
+ }
371
+ // update other properties
372
+ if (Object.keys(others).length) {
373
+ const mergedData = mergeOneLevelData(userGraphCore.getNode(id), {
374
+ id,
375
+ data: others,
376
+ });
377
+ userGraphCore.mergeNodeData(id, mergedData);
378
+ }
379
+ });
380
+ // update succeed nodes
381
+ modelsToMove.forEach((newModel) => {
382
+ const { id, data } = newModel;
383
+ userGraphCore.mergeNodeData(id, data);
384
+ });
385
+ }
386
+ }
387
+ /**
388
+ * Relatively move the position of combo a dinstance (dx and dy in combo data).
389
+ * @param data graph data which contains the combo dx dy info
390
+ */
391
+ moveCombo(data) {
392
+ const { combos = [] } = data;
393
+ const succeedNodesModels = [];
394
+ combos.forEach((newModel) => {
395
+ const { dx = 0, dy = 0 } = newModel.data;
396
+ if (!dx && !dy)
397
+ return;
398
+ if (this.graphCore.getChildren(newModel.id, 'combo').length) {
399
+ // combo's position is updated, update the succeed nodes' positions
400
+ graphComboTreeDfs(this.graph, [newModel], (succeed) => {
401
+ const { x, y, _isCombo } = succeed.data;
402
+ if (!_isCombo ||
403
+ !this.graphCore.getChildren(succeed.id, 'combo').length) {
404
+ succeedNodesModels.push({
405
+ id: succeed.id,
406
+ data: {
407
+ x: x + dx,
408
+ y: y + dy,
409
+ },
410
+ });
411
+ }
412
+ }, 'BT');
413
+ }
414
+ else {
415
+ // empty combo, move it directly
416
+ const comboModel = this.graphCore.getNode(newModel.id);
417
+ const { x = 0, y = 0 } = comboModel.data;
418
+ succeedNodesModels.push({
419
+ id: newModel.id,
420
+ data: {
421
+ x: x + dx,
422
+ y: y + dy,
423
+ },
424
+ });
425
+ }
426
+ });
427
+ // update succeed nodes
428
+ const { userGraphCore } = this;
429
+ succeedNodesModels.forEach((newModel) => {
430
+ const { id, data } = newModel;
431
+ if (data) {
432
+ const mergedData = mergeOneLevelData(userGraphCore.getNode(id), newModel);
433
+ userGraphCore.mergeNodeData(id, mergedData);
434
+ }
435
+ });
436
+ }
437
+ addCombo(data) {
438
+ const { combos = [] } = data;
439
+ if (!(combos === null || combos === void 0 ? void 0 : combos.length))
440
+ return;
441
+ const { userGraphCore } = this;
442
+ const { id, data: comboData } = combos[0];
443
+ const { _children = [] } = comboData, others = __rest(comboData, ["_children"]);
444
+ // add or update combo
445
+ if (userGraphCore.hasNode(id)) {
446
+ // update node which is in the graphCore
447
+ userGraphCore.mergeNodeData(id, Object.assign(Object.assign({}, others), { _isCombo: true }));
448
+ }
449
+ else {
450
+ // add node which is in data but not in graphCore
451
+ userGraphCore.addNode({ id, data: Object.assign(Object.assign({}, others), { _isCombo: true }) });
452
+ }
453
+ // update strucutre
454
+ _children.forEach((childId) => {
455
+ if (!this.graphCore.hasNode(childId)) {
456
+ console.warn(`Adding child ${childId} to combo ${id} failed. The child ${childId} does not exist`);
457
+ return;
458
+ }
459
+ userGraphCore.mergeNodeData(childId, { parentId: id });
460
+ });
238
461
  }
239
462
  /**
240
463
  * Update graphCore with transformed userGraphCore data.
@@ -244,11 +467,11 @@ export class DataController {
244
467
  // === step 1: clone data from userGraphCore (userData) ===
245
468
  // === step 2: transform the data with transform extensions, output innerData and idMaps ===
246
469
  const { data: transformedData, idMaps } = this.transformData();
247
- const { nodes, edges, combos } = transformedData;
248
- const prevNodes = graphCore.getAllNodes();
470
+ const { nodes = [], edges = [], combos = [] } = transformedData;
471
+ const prevNodesAndCombos = graphCore.getAllNodes();
249
472
  // function to update one data in graphCore with different model type ('node' or 'edge')
250
- const syncUpdateToGraphCore = (id, newValue, oldValue, isNode, diff = []) => {
251
- if (isNode) {
473
+ const syncUpdateToGraphCore = (id, newValue, oldValue, isNodeOrCombo, diff = []) => {
474
+ if (isNodeOrCombo) {
252
475
  if (newValue.data)
253
476
  graphCore.updateNodeData(id, newValue.data);
254
477
  }
@@ -261,26 +484,69 @@ export class DataController {
261
484
  if (diff.includes('target'))
262
485
  graphCore.updateEdgeTarget(id, newValue.target);
263
486
  }
264
- // TODO: combo
265
487
  };
266
488
  graphCore.batch(() => {
489
+ var _a;
267
490
  // === step 3: sync to graphCore according to the changes in userGraphCore ==
268
491
  if (!(idMaps === null || idMaps === void 0 ? void 0 : idMaps.length) || idMaps.length !== this.extensions.length) {
269
492
  // situation 1: not every extension has corresponding idMap, use default mapping: suppose id is not changed by transforms
270
493
  // and diff the value in graphCore whose id is not in userGraphCore
271
494
  const newModelMap = {};
272
- nodes.forEach((model) => (newModelMap[model.id] = { type: 'node', model }));
495
+ const parentMap = {};
496
+ const changeMap = {};
497
+ event.changes.forEach((change) => {
498
+ const { value, id } = change;
499
+ changeMap[id || value.id] = true;
500
+ });
501
+ nodes.forEach((model) => {
502
+ newModelMap[model.id] = { type: 'node', model };
503
+ if (model.data.hasOwnProperty('parentId')) {
504
+ parentMap[model.id] = {
505
+ new: model.data.parentId,
506
+ old: undefined,
507
+ };
508
+ }
509
+ });
273
510
  edges.forEach((model) => (newModelMap[model.id] = { type: 'edge', model }));
274
- prevNodes.forEach((prevNode) => {
275
- var _a;
276
- const { id } = prevNode;
511
+ combos.forEach((model) => {
512
+ newModelMap[model.id] = { type: 'combo', model };
513
+ if (model.data.hasOwnProperty('parentId')) {
514
+ parentMap[model.id] = {
515
+ new: model.data.parentId,
516
+ old: undefined,
517
+ };
518
+ }
519
+ });
520
+ prevNodesAndCombos.forEach((prevModel) => {
521
+ var _a, _b, _c;
522
+ const { id } = prevModel;
523
+ if (((_a = parentMap[id]) === null || _a === void 0 ? void 0 : _a.new) !== undefined ||
524
+ prevModel.data.parentId !== undefined) {
525
+ parentMap[id] = {
526
+ new: (_b = parentMap[id]) === null || _b === void 0 ? void 0 : _b.new,
527
+ old: prevModel.data.parentId,
528
+ };
529
+ }
530
+ else {
531
+ delete parentMap[id];
532
+ }
277
533
  const { model: newModel } = newModelMap[id] || {};
278
534
  // remove
279
- if (!newModel)
535
+ if (!newModel) {
536
+ if (prevModel.data._isCombo) {
537
+ graphCore.getChildren(id, 'combo').forEach((child) => {
538
+ parentMap[child.id] = Object.assign(Object.assign({}, parentMap[child.id]), { new: prevModel.data.parentId });
539
+ });
540
+ }
541
+ if (prevModel.data.parentId) {
542
+ graphCore.setParent(id, undefined, 'combo');
543
+ }
280
544
  graphCore.removeNode(id);
545
+ delete parentMap[prevModel.id];
546
+ }
281
547
  // update
282
- else if ((_a = diffAt(newModel, prevNode, true)) === null || _a === void 0 ? void 0 : _a.length)
283
- syncUpdateToGraphCore(id, newModel, prevNode, true);
548
+ else if (((_c = diffAt(newModel, prevModel, true)) === null || _c === void 0 ? void 0 : _c.length) || changeMap[id])
549
+ syncUpdateToGraphCore(id, newModel, prevModel, true);
284
550
  // delete from the map indicates this model is visited
285
551
  delete newModelMap[id];
286
552
  });
@@ -301,11 +567,21 @@ export class DataController {
301
567
  });
302
568
  // add
303
569
  Object.values(newModelMap).forEach(({ type, model }) => {
304
- if (type === 'node')
570
+ if (type === 'node' || type === 'combo')
305
571
  graphCore.addNode(model);
306
572
  else if (type === 'edge')
307
573
  graphCore.addEdge(model);
308
- // TODO: combo
574
+ });
575
+ // update parents after adding all items
576
+ Object.keys(parentMap).forEach((id) => {
577
+ if (parentMap[id].new === parentMap[id].old)
578
+ return;
579
+ if (!validateComboStrucutre(this.graph, id, parentMap[id].new)) {
580
+ graphCore.mergeNodeData(id, { parentId: parentMap[id].old });
581
+ return;
582
+ }
583
+ graphCore.mergeNodeData(id, { parentId: parentMap[id].new });
584
+ graphCore.setParent(id, parentMap[id].new, 'combo');
309
585
  });
310
586
  }
311
587
  else {
@@ -314,14 +590,16 @@ export class DataController {
314
590
  const finalIdMap = {};
315
591
  const newModelMap = {};
316
592
  const prevModelMap = {};
317
- nodes.concat(edges).forEach((model) => {
593
+ nodes
594
+ .concat(edges)
595
+ .concat(combos)
596
+ .forEach((model) => {
318
597
  finalIdMap[model.id] = getComesFromLinkedList(model.id, idMaps);
319
598
  newModelMap[model.id] = model;
320
599
  });
321
- prevNodes.concat(graphCore.getAllEdges()).forEach((model) => {
600
+ prevNodesAndCombos.concat(graphCore.getAllEdges()).forEach((model) => {
322
601
  prevModelMap[model.id] = model;
323
602
  });
324
- // TODO: combo
325
603
  // map changes for search
326
604
  const changeMap = {};
327
605
  const { changes } = event;
@@ -345,13 +623,15 @@ export class DataController {
345
623
  const comesFromIds = finalIdMap[newId];
346
624
  const newValue = newModelMap[newId];
347
625
  const oldValue = prevModelMap[newId];
348
- const isNode = graphCore.hasNode(newId);
626
+ const isNodeOrCombo = graphCore.hasNode(newId);
349
627
  if (newValue && !oldValue) {
350
- const addFunc = isNode ? graphCore.addNode : graphCore.addEdge;
628
+ const addFunc = isNodeOrCombo
629
+ ? graphCore.addNode
630
+ : graphCore.addEdge;
351
631
  addFunc(newValue);
352
632
  }
353
633
  else if (!newValue && oldValue) {
354
- const removeFunc = isNode
634
+ const removeFunc = isNodeOrCombo
355
635
  ? graphCore.removeNode
356
636
  : graphCore.removeEdge;
357
637
  removeFunc(newId);
@@ -359,19 +639,31 @@ export class DataController {
359
639
  else {
360
640
  if (!(comesFromIds === null || comesFromIds === void 0 ? void 0 : comesFromIds.length)) {
361
641
  // no comesForm, find same id in userGraphCore to follow the change, if it not found, diff new and old data value of graphCore (inner data)
362
- const diff = diffAt(newValue, oldValue, isNode);
642
+ const diff = diffAt(newValue, oldValue, isNodeOrCombo);
363
643
  if (diff === null || diff === void 0 ? void 0 : diff.length)
364
- syncUpdateToGraphCore(newId, newValue, oldValue, isNode, diff);
644
+ syncUpdateToGraphCore(newId, newValue, oldValue, isNodeOrCombo, diff);
365
645
  }
366
646
  else {
367
647
  // follow the corresponding data event in userGraphCore
368
648
  const comesFromChanges = changeMap[comesFromIds[0]];
369
649
  if (comesFromChanges === null || comesFromChanges === void 0 ? void 0 : comesFromChanges.length)
370
- syncUpdateToGraphCore(newId, newValue, oldValue, isNode);
650
+ syncUpdateToGraphCore(newId, newValue, oldValue, isNodeOrCombo);
371
651
  }
372
652
  }
373
653
  });
654
+ // update parents after updating all items
655
+ graphCore.getAllNodes().forEach((node) => {
656
+ if (!validateComboStrucutre(this.graph, node.id, node.data.parentId)) {
657
+ // restore if the new parent is invalid
658
+ graphCore.mergeNodeData(node.id, {
659
+ parentId: prevModelMap[node.id].data.parentId,
660
+ });
661
+ return;
662
+ }
663
+ graphCore.setParent(node.id, node.data.parentId, 'combo');
664
+ });
374
665
  }
666
+ (_a = this.comboTreeView) === null || _a === void 0 ? void 0 : _a.refreshCache();
375
667
  });
376
668
  }
377
669
  /**
@@ -381,12 +673,10 @@ export class DataController {
381
673
  transformData() {
382
674
  const { userGraphCore } = this;
383
675
  // === step 1: clone data from userGraphCore (userData) ===
384
- const userData = {
385
- // TODO: should be deepClone
676
+ const userData = deconstructData({
386
677
  nodes: userGraphCore.getAllNodes(),
387
678
  edges: userGraphCore.getAllEdges(),
388
- // combos:
389
- };
679
+ });
390
680
  let dataCloned = clone(userData);
391
681
  // === step 2: transform the data with transform extensions, output innerData and idMaps ===
392
682
  const idMaps = [];
@@ -457,6 +747,8 @@ const diffAt = (newModel, oldModel, isNode) => {
457
747
  else
458
748
  continue;
459
749
  }
750
+ if (isNaN(newValue) && isNaN(oldValue))
751
+ continue;
460
752
  if (newValue !== oldValue)
461
753
  return diff.concat('data');
462
754
  }