@antv/g6 5.0.0-beta.6 → 5.0.0-beta.8

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 (151) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/esm/index.d.ts +8 -12
  3. package/esm/index.js +1 -1
  4. package/esm/item/edge.d.ts +21 -1
  5. package/esm/item/edge.js +78 -35
  6. package/esm/item/edge.js.map +1 -1
  7. package/esm/item/item.js +9 -5
  8. package/esm/item/item.js.map +1 -1
  9. package/esm/item/node.js +6 -6
  10. package/esm/item/node.js.map +1 -1
  11. package/esm/runtime/controller/data.d.ts +7 -10
  12. package/esm/runtime/controller/data.js +125 -281
  13. package/esm/runtime/controller/data.js.map +1 -1
  14. package/esm/runtime/controller/item.js +2 -6
  15. package/esm/runtime/controller/item.js.map +1 -1
  16. package/esm/runtime/graph.d.ts +5 -5
  17. package/esm/runtime/graph.js +35 -15
  18. package/esm/runtime/graph.js.map +1 -1
  19. package/esm/stdlib/behavior/create-edge.d.ts +2 -2
  20. package/esm/stdlib/behavior/create-edge.js +17 -16
  21. package/esm/stdlib/behavior/create-edge.js.map +1 -1
  22. package/esm/stdlib/behavior/drag-canvas.d.ts +1 -0
  23. package/esm/stdlib/behavior/drag-canvas.js +20 -12
  24. package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
  25. package/esm/stdlib/behavior/zoom-canvas.d.ts +1 -0
  26. package/esm/stdlib/behavior/zoom-canvas.js +24 -16
  27. package/esm/stdlib/behavior/zoom-canvas.js.map +1 -1
  28. package/esm/stdlib/data/mapNodeSize.d.ts +2 -2
  29. package/esm/stdlib/data/mapNodeSize.js +2 -2
  30. package/esm/stdlib/data/mapNodeSize.js.map +1 -1
  31. package/esm/stdlib/data/transformV4Data.d.ts +2 -2
  32. package/esm/stdlib/data/transformV4Data.js +2 -2
  33. package/esm/stdlib/data/transformV4Data.js.map +1 -1
  34. package/esm/stdlib/data/validateData.d.ts +2 -2
  35. package/esm/stdlib/data/validateData.js +9 -9
  36. package/esm/stdlib/data/validateData.js.map +1 -1
  37. package/esm/stdlib/index.d.ts +7 -7
  38. package/esm/stdlib/index.js +1 -1
  39. package/esm/stdlib/index.js.map +1 -1
  40. package/esm/stdlib/item/edge/base.js +4 -9
  41. package/esm/stdlib/item/edge/base.js.map +1 -1
  42. package/esm/stdlib/plugin/history/item-data-command.js +21 -12
  43. package/esm/stdlib/plugin/history/item-data-command.js.map +1 -1
  44. package/esm/stdlib/plugin/minimap/index.js +8 -2
  45. package/esm/stdlib/plugin/minimap/index.js.map +1 -1
  46. package/esm/stdlib/plugin/snapline/index.d.ts +5 -1
  47. package/esm/stdlib/plugin/snapline/index.js +23 -12
  48. package/esm/stdlib/plugin/snapline/index.js.map +1 -1
  49. package/esm/types/graph.d.ts +3 -3
  50. package/esm/types/view.d.ts +5 -0
  51. package/esm/util/event.d.ts +3 -1
  52. package/esm/util/event.js +8 -1
  53. package/esm/util/event.js.map +1 -1
  54. package/esm/util/item.js +1 -1
  55. package/esm/util/item.js.map +1 -1
  56. package/esm/util/layout.d.ts +11 -0
  57. package/esm/util/layout.js +45 -0
  58. package/esm/util/layout.js.map +1 -1
  59. package/esm/util/point.js +5 -1
  60. package/esm/util/point.js.map +1 -1
  61. package/esm/util/shape.d.ts +1 -1
  62. package/esm/util/shape.js +3 -7
  63. package/esm/util/shape.js.map +1 -1
  64. package/lib/index.d.ts +8 -12
  65. package/lib/index.js +1 -1
  66. package/lib/item/edge.d.ts +21 -1
  67. package/lib/item/edge.js +77 -34
  68. package/lib/item/edge.js.map +1 -1
  69. package/lib/item/item.js +9 -5
  70. package/lib/item/item.js.map +1 -1
  71. package/lib/item/node.js +6 -6
  72. package/lib/item/node.js.map +1 -1
  73. package/lib/runtime/controller/data.d.ts +7 -10
  74. package/lib/runtime/controller/data.js +125 -281
  75. package/lib/runtime/controller/data.js.map +1 -1
  76. package/lib/runtime/controller/item.js +2 -6
  77. package/lib/runtime/controller/item.js.map +1 -1
  78. package/lib/runtime/graph.d.ts +5 -5
  79. package/lib/runtime/graph.js +35 -15
  80. package/lib/runtime/graph.js.map +1 -1
  81. package/lib/stdlib/behavior/create-edge.d.ts +2 -2
  82. package/lib/stdlib/behavior/create-edge.js +17 -16
  83. package/lib/stdlib/behavior/create-edge.js.map +1 -1
  84. package/lib/stdlib/behavior/drag-canvas.d.ts +1 -0
  85. package/lib/stdlib/behavior/drag-canvas.js +20 -12
  86. package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
  87. package/lib/stdlib/behavior/zoom-canvas.d.ts +1 -0
  88. package/lib/stdlib/behavior/zoom-canvas.js +24 -16
  89. package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
  90. package/lib/stdlib/data/mapNodeSize.d.ts +2 -2
  91. package/lib/stdlib/data/mapNodeSize.js +2 -2
  92. package/lib/stdlib/data/mapNodeSize.js.map +1 -1
  93. package/lib/stdlib/data/transformV4Data.d.ts +2 -2
  94. package/lib/stdlib/data/transformV4Data.js +2 -2
  95. package/lib/stdlib/data/transformV4Data.js.map +1 -1
  96. package/lib/stdlib/data/validateData.d.ts +2 -2
  97. package/lib/stdlib/data/validateData.js +9 -9
  98. package/lib/stdlib/data/validateData.js.map +1 -1
  99. package/lib/stdlib/index.d.ts +7 -7
  100. package/lib/stdlib/index.js +1 -1
  101. package/lib/stdlib/index.js.map +1 -1
  102. package/lib/stdlib/item/edge/base.js +4 -9
  103. package/lib/stdlib/item/edge/base.js.map +1 -1
  104. package/lib/stdlib/plugin/history/item-data-command.js +21 -12
  105. package/lib/stdlib/plugin/history/item-data-command.js.map +1 -1
  106. package/lib/stdlib/plugin/minimap/index.js +8 -2
  107. package/lib/stdlib/plugin/minimap/index.js.map +1 -1
  108. package/lib/stdlib/plugin/snapline/index.d.ts +5 -1
  109. package/lib/stdlib/plugin/snapline/index.js +23 -12
  110. package/lib/stdlib/plugin/snapline/index.js.map +1 -1
  111. package/lib/types/graph.d.ts +3 -3
  112. package/lib/types/view.d.ts +5 -0
  113. package/lib/util/event.d.ts +3 -1
  114. package/lib/util/event.js +8 -1
  115. package/lib/util/event.js.map +1 -1
  116. package/lib/util/item.js +1 -1
  117. package/lib/util/item.js.map +1 -1
  118. package/lib/util/layout.d.ts +11 -0
  119. package/lib/util/layout.js +47 -1
  120. package/lib/util/layout.js.map +1 -1
  121. package/lib/util/point.js +5 -1
  122. package/lib/util/point.js.map +1 -1
  123. package/lib/util/shape.d.ts +1 -1
  124. package/lib/util/shape.js +3 -7
  125. package/lib/util/shape.js.map +1 -1
  126. package/package.json +1 -1
  127. package/src/index.ts +1 -1
  128. package/src/item/edge.ts +108 -48
  129. package/src/item/item.ts +13 -9
  130. package/src/item/node.ts +6 -6
  131. package/src/runtime/controller/data.ts +140 -339
  132. package/src/runtime/controller/item.ts +2 -6
  133. package/src/runtime/graph.ts +57 -17
  134. package/src/stdlib/behavior/create-edge.ts +21 -20
  135. package/src/stdlib/behavior/drag-canvas.ts +23 -12
  136. package/src/stdlib/behavior/zoom-canvas.ts +27 -16
  137. package/src/stdlib/data/mapNodeSize.ts +2 -2
  138. package/src/stdlib/data/transformV4Data.ts +2 -2
  139. package/src/stdlib/data/validateData.ts +9 -9
  140. package/src/stdlib/index.ts +1 -1
  141. package/src/stdlib/item/edge/base.ts +4 -8
  142. package/src/stdlib/plugin/history/item-data-command.ts +31 -13
  143. package/src/stdlib/plugin/minimap/index.ts +16 -10
  144. package/src/stdlib/plugin/snapline/index.ts +36 -16
  145. package/src/types/graph.ts +6 -3
  146. package/src/types/view.ts +8 -3
  147. package/src/util/event.ts +14 -1
  148. package/src/util/item.ts +1 -1
  149. package/src/util/layout.ts +45 -0
  150. package/src/util/point.ts +4 -2
  151. package/src/util/shape.ts +6 -7
@@ -14,7 +14,6 @@ import { clone, isArray, isObject } from '@antv/util';
14
14
  import { registery as registry } from '../../stdlib';
15
15
  import { deconstructData, graphComboTreeDfs, graphData2TreeData, traverse, treeData2GraphData, validateComboStrucutre, } from '../../util/data';
16
16
  import { getExtension } from '../../util/extension';
17
- import { convertToNumber } from '../../util/type';
18
17
  import { isTreeLayout } from '../../util/layout';
19
18
  import { hasTreeBehaviors } from '../../util/behavior';
20
19
  /**
@@ -129,7 +128,7 @@ export class DataController {
129
128
  */
130
129
  onDataChange(param) {
131
130
  const { data, type: changeType } = param;
132
- const { userGraphCore } = this;
131
+ const { graphCore } = this;
133
132
  const change = () => {
134
133
  switch (changeType) {
135
134
  case 'remove':
@@ -150,8 +149,8 @@ export class DataController {
150
149
  break;
151
150
  }
152
151
  };
153
- if (userGraphCore) {
154
- userGraphCore.batch(change);
152
+ if (graphCore) {
153
+ graphCore.batch(change);
155
154
  }
156
155
  else {
157
156
  change();
@@ -160,21 +159,21 @@ export class DataController {
160
159
  onTreeCollapseExpand(params) {
161
160
  const { ids, action } = params;
162
161
  ids.forEach((id) => {
163
- this.userGraphCore.mergeNodeData(id, {
162
+ this.graphCore.mergeNodeData(id, {
164
163
  collapsed: action === 'collapse',
165
164
  });
166
165
  });
167
166
  }
168
167
  onLayout({ options }) {
169
168
  if (this.treeDirtyFlag && isTreeLayout(options)) {
170
- this.establishUserGraphCoreTree();
169
+ this.establishGraphCoreTree();
171
170
  }
172
171
  }
173
172
  onGraphInit() {
174
173
  const { modes = {} } = this.graph.getSpecification();
175
174
  const mode = this.graph.getMode() || 'default';
176
175
  if (hasTreeBehaviors(modes[mode])) {
177
- this.establishUserGraphCoreTree();
176
+ this.establishGraphCoreTree();
178
177
  }
179
178
  }
180
179
  onBehaviorChange(param) {
@@ -183,31 +182,29 @@ export class DataController {
183
182
  if (action !== 'add' || !modes.includes(mode))
184
183
  return;
185
184
  if (hasTreeBehaviors(behaviors)) {
186
- this.establishUserGraphCoreTree();
185
+ this.establishGraphCoreTree();
187
186
  }
188
187
  }
189
188
  onModeChange(param) {
190
189
  const { modes = {} } = this.graph.getSpecification();
191
190
  if (hasTreeBehaviors(modes[param.mode])) {
192
- this.establishUserGraphCoreTree();
191
+ this.establishGraphCoreTree();
193
192
  }
194
193
  }
195
- establishUserGraphCoreTree() {
194
+ establishGraphCoreTree() {
196
195
  if (!this.treeDirtyFlag)
197
196
  return;
198
- const nodes = this.userGraphCore.getAllNodes();
199
- const edges = this.userGraphCore.getAllEdges();
200
- this.userGraphCore.batch(() => {
201
- // graph data to tree structure and storing
202
- const rootIds = nodes
203
- .filter((node) => node.data.isRoot)
204
- .map((node) => node.id);
205
- graphData2TreeData({}, { nodes, edges }, rootIds).forEach((tree) => {
206
- traverse(tree, (node) => {
207
- var _a;
208
- (_a = node.children) === null || _a === void 0 ? void 0 : _a.forEach((child) => {
209
- this.userGraphCore.setParent(child.id, node.id, 'tree');
210
- });
197
+ const nodes = this.graphCore.getAllNodes();
198
+ const edges = this.graphCore.getAllEdges();
199
+ // graph data to tree structure and storing
200
+ const rootIds = nodes
201
+ .filter((node) => node.data.isRoot)
202
+ .map((node) => node.id);
203
+ graphData2TreeData({}, { nodes, edges }, rootIds).forEach((tree) => {
204
+ traverse(tree, (node) => {
205
+ var _a;
206
+ (_a = node.children) === null || _a === void 0 ? void 0 : _a.forEach((child) => {
207
+ this.graphCore.setParent(child.id, node.id, 'tree');
211
208
  });
212
209
  });
213
210
  });
@@ -223,16 +220,9 @@ export class DataController {
223
220
  const { type: dataType, data } = this.formatData(dataConfig) || {};
224
221
  if (!dataType)
225
222
  return;
223
+ this.dataType = dataType;
226
224
  const { nodes = [], edges = [], combos = [] } = this.transformData(data);
227
225
  if (changeType === 'replace') {
228
- this.userGraphCore = new GraphLib({
229
- nodes: nodes.concat((combos === null || combos === void 0 ? void 0 : combos.map((combo) => ({
230
- id: combo.id,
231
- data: Object.assign(Object.assign({}, combo.data), { _isCombo: true }),
232
- }))) || []),
233
- edges,
234
- onChanged: (event) => this.updateGraphCore(event),
235
- });
236
226
  this.graphCore = new GraphLib(clone({
237
227
  nodes: nodes.concat((combos === null || combos === void 0 ? void 0 : combos.map((combo) => ({
238
228
  id: combo.id,
@@ -265,9 +255,9 @@ export class DataController {
265
255
  }
266
256
  }
267
257
  else {
268
- const { userGraphCore } = this;
258
+ const { graphCore } = this;
269
259
  const prevData = deconstructData({
270
- nodes: userGraphCore.getAllNodes(),
260
+ nodes: graphCore.getAllNodes(),
271
261
  edges: [],
272
262
  });
273
263
  const nodesAndCombos = nodes.concat(combos.map((combo) => ({
@@ -276,94 +266,124 @@ export class DataController {
276
266
  })));
277
267
  // =========== node & combos ============
278
268
  if (!prevData.nodes.length) {
279
- userGraphCore.addNodes(nodesAndCombos);
269
+ graphCore.addNodes(nodesAndCombos);
280
270
  }
281
271
  else {
282
272
  if (changeType === 'mergeReplace') {
283
- // remove the nodes which are not in data but in userGraphCore
273
+ // remove the nodes which are not in incoming data but in graphCore
284
274
  const nodeAndComboIds = nodesAndCombos.map((node) => node.id);
285
275
  prevData.nodes.forEach((prevNode) => {
286
- if (!nodeAndComboIds.includes(prevNode.id))
287
- userGraphCore.removeNode(prevNode.id);
276
+ if (!nodeAndComboIds.includes(prevNode.id)) {
277
+ this.removeNode(prevNode);
278
+ }
288
279
  });
289
280
  }
290
281
  // add or update node
291
282
  nodesAndCombos.forEach((item) => {
292
- if (userGraphCore.hasNode(item.id)) {
283
+ if (graphCore.hasNode(item.id)) {
293
284
  // update node which is in the graphCore
294
- userGraphCore.mergeNodeData(item.id, item.data);
285
+ graphCore.mergeNodeData(item.id, item.data);
295
286
  }
296
287
  else {
297
288
  // add node which is in data but not in graphCore
298
- userGraphCore.addNode(item);
289
+ graphCore.addNode(item);
299
290
  }
300
291
  });
301
292
  }
302
293
  // =========== edge ============
303
- prevData.edges = userGraphCore.getAllEdges();
294
+ prevData.edges = graphCore.getAllEdges();
304
295
  if (!prevData.edges.length) {
305
- userGraphCore.addEdges(edges);
296
+ graphCore.addEdges(edges);
306
297
  }
307
298
  else {
308
299
  if (changeType === 'mergeReplace') {
309
- // remove the edges which are not in data but in userGraphCore
300
+ // remove the edges which are not in incoming data but in graphCore
310
301
  const edgeIds = edges.map((edge) => edge.id);
311
302
  prevData.edges.forEach((prevEdge) => {
312
303
  if (!edgeIds.includes(prevEdge.id))
313
- userGraphCore.removeEdge(prevEdge.id);
304
+ graphCore.removeEdge(prevEdge.id);
314
305
  });
315
306
  }
316
307
  // add or update edge
317
308
  edges.forEach((edge) => {
318
- if (userGraphCore.hasEdge(edge.id)) {
309
+ if (graphCore.hasEdge(edge.id)) {
319
310
  // update edge which is in the graphCore
320
- userGraphCore.mergeEdgeData(edge.id, edge.data);
311
+ graphCore.mergeEdgeData(edge.id, edge.data);
321
312
  }
322
313
  else {
323
314
  // add edge which is in data but not in graphCore
324
- userGraphCore.addEdge(edge);
315
+ graphCore.addEdge(edge);
325
316
  }
326
317
  });
327
318
  }
328
319
  }
329
320
  if ((_a = data.edges) === null || _a === void 0 ? void 0 : _a.length) {
330
- const { userGraphCore } = this;
321
+ const { graphCore } = this;
331
322
  // convert and store tree structure to graphCore
332
323
  this.updateTreeGraph(dataType, {
333
- nodes: userGraphCore.getAllNodes(),
334
- edges: userGraphCore.getAllEdges(),
324
+ nodes: graphCore.getAllNodes(),
325
+ edges: graphCore.getAllEdges(),
335
326
  });
336
327
  }
337
328
  }
329
+ removeNode(nodeModel) {
330
+ const { id, data } = nodeModel;
331
+ const { graphCore } = this;
332
+ if (graphCore.hasTreeStructure('combo')) {
333
+ // remove from its parent's children list
334
+ graphCore.setParent(id, undefined, 'combo');
335
+ const { parentId } = data;
336
+ // move the children to the grandparent's children list
337
+ graphCore.getChildren(id, 'combo').forEach((child) => {
338
+ graphCore.setParent(child.id, parentId, 'combo');
339
+ graphCore.mergeNodeData(child.id, { parentId });
340
+ });
341
+ }
342
+ if (graphCore.hasTreeStructure('tree')) {
343
+ const succeedIds = [];
344
+ graphCore.dfsTree(id, (child) => {
345
+ succeedIds.push(child.id);
346
+ }, 'tree');
347
+ const succeedEdgeIds = graphCore
348
+ .getAllEdges()
349
+ .filter(({ source, target }) => succeedIds.includes(source) && succeedIds.includes(target))
350
+ .map((edge) => edge.id);
351
+ this.graph.showItem(succeedIds
352
+ .filter((succeedId) => succeedId !== id)
353
+ .concat(succeedEdgeIds));
354
+ // for tree graph view, remove the node from the parent's children list
355
+ graphCore.setParent(id, undefined, 'tree');
356
+ // for tree graph view, make the its children to be roots
357
+ graphCore
358
+ .getChildren(id, 'tree')
359
+ .forEach((child) => graphCore.setParent(child.id, undefined, 'tree'));
360
+ }
361
+ graphCore.removeNode(id);
362
+ }
338
363
  /**
339
364
  * Remove part of old data.
340
365
  * @param data data to be removed which is part of old one
341
366
  */
342
367
  removeData(data) {
343
- const { userGraphCore } = this;
368
+ const { graphCore } = this;
344
369
  const { nodes = [], edges = [], combos = [] } = data;
345
370
  const nodesAndCombos = nodes.concat(combos);
346
- const prevNodesAndCombos = userGraphCore.getAllNodes();
347
- const prevEdges = userGraphCore.getAllEdges();
371
+ const prevNodesAndCombos = graphCore.getAllNodes();
372
+ const prevEdges = graphCore.getAllEdges();
348
373
  if (prevNodesAndCombos.length && nodesAndCombos.length) {
349
- // update the parentId
350
- if (this.graphCore.hasTreeStructure('combo')) {
351
- nodesAndCombos.forEach((item) => {
352
- const { parentId } = item.data;
353
- this.graphCore.getChildren(item.id, 'combo').forEach((child) => {
354
- userGraphCore.mergeNodeData(child.id, { parentId });
355
- });
356
- });
357
- }
374
+ // update combo tree view and tree graph view
375
+ nodesAndCombos.forEach((item) => {
376
+ this.removeNode(item);
377
+ });
358
378
  // remove the node
359
- userGraphCore.removeNodes(nodesAndCombos.map((node) => node.id));
379
+ // graphCore.removeNodes(nodesAndCombos.map((node) => node.id));
360
380
  }
361
381
  if (prevEdges.length && edges.length) {
362
382
  // add or update edge
363
383
  const ids = edges
364
384
  .map((edge) => edge.id)
365
- .filter((id) => userGraphCore.hasEdge(id));
366
- userGraphCore.removeEdges(ids);
385
+ .filter((id) => graphCore.hasEdge(id));
386
+ graphCore.removeEdges(ids);
367
387
  }
368
388
  }
369
389
  /**
@@ -371,39 +391,42 @@ export class DataController {
371
391
  * @param data data to be updated which is part of old one
372
392
  */
373
393
  updateData(dataConfig) {
374
- const { userGraphCore } = this;
394
+ const { graphCore } = this;
375
395
  const { type: dataType, data } = this.formatData(dataConfig);
376
396
  if (!dataType)
377
397
  return;
378
398
  const { nodes = [], edges = [], combos = [] } = data; //this.transformData(data as GraphData);
379
399
  const { nodes: prevNodes, edges: prevEdges, combos: prevCombos, } = deconstructData({
380
- nodes: userGraphCore.getAllNodes(),
381
- edges: userGraphCore.getAllEdges(),
400
+ nodes: graphCore.getAllNodes(),
401
+ edges: graphCore.getAllEdges(),
382
402
  });
383
403
  if (prevNodes.length) {
384
404
  // update node
385
405
  nodes.forEach((newModel) => {
386
406
  const { id, data } = newModel;
387
407
  if (data) {
388
- const mergedData = mergeOneLevelData(userGraphCore.getNode(id), newModel);
389
- userGraphCore.mergeNodeData(id, mergedData);
408
+ const mergedData = mergeOneLevelData(graphCore.getNode(id), newModel);
409
+ graphCore.mergeNodeData(id, mergedData);
410
+ }
411
+ if (data.hasOwnProperty('parentId')) {
412
+ graphCore.setParent(id, data.parentId, 'combo');
390
413
  }
391
414
  });
392
415
  }
393
416
  if (prevEdges.length) {
394
417
  // update edge
395
418
  edges.forEach((newModel) => {
396
- const oldModel = userGraphCore.getEdge(newModel.id);
419
+ const oldModel = graphCore.getEdge(newModel.id);
397
420
  if (!oldModel)
398
421
  return;
399
422
  const { id, source, target, data } = newModel;
400
423
  if (source && oldModel.source !== source)
401
- userGraphCore.updateEdgeSource(id, source);
424
+ graphCore.updateEdgeSource(id, source);
402
425
  if (target && oldModel.target !== target)
403
- userGraphCore.updateEdgeTarget(id, target);
426
+ graphCore.updateEdgeTarget(id, target);
404
427
  if (data) {
405
- const mergedData = mergeOneLevelData(userGraphCore.getEdge(id), newModel);
406
- userGraphCore.mergeEdgeData(id, mergedData);
428
+ const mergedData = mergeOneLevelData(graphCore.getEdge(id), newModel);
429
+ graphCore.mergeEdgeData(id, mergedData);
407
430
  }
408
431
  });
409
432
  }
@@ -412,6 +435,8 @@ export class DataController {
412
435
  const modelsToMove = [];
413
436
  combos.forEach((newModel) => {
414
437
  const { id, data } = newModel;
438
+ if (!data)
439
+ return;
415
440
  const { x: comboNewX, y: comboNewY } = data, others = __rest(data, ["x", "y"]);
416
441
  if (comboNewX !== undefined || comboNewY !== undefined) {
417
442
  if (this.graphCore.getChildren(id, 'combo').length) {
@@ -448,24 +473,27 @@ export class DataController {
448
473
  }
449
474
  // update other properties
450
475
  if (Object.keys(others).length) {
451
- const mergedData = mergeOneLevelData(userGraphCore.getNode(id), {
476
+ const mergedData = mergeOneLevelData(graphCore.getNode(id), {
452
477
  id,
453
478
  data: others,
454
479
  });
455
- userGraphCore.mergeNodeData(id, mergedData);
480
+ graphCore.mergeNodeData(id, mergedData);
481
+ if (others.hasOwnProperty('parentId')) {
482
+ graphCore.setParent(id, others.parentId, 'combo');
483
+ }
456
484
  }
457
485
  });
458
486
  // update succeed nodes
459
487
  modelsToMove.forEach((newModel) => {
460
488
  const { id, data } = newModel;
461
- userGraphCore.mergeNodeData(id, data);
489
+ graphCore.mergeNodeData(id, data);
462
490
  });
463
491
  }
464
492
  if (edges === null || edges === void 0 ? void 0 : edges.filter((edge) => edge.hasOwnProperty('source') || edge.hasOwnProperty('target')).length) {
465
493
  // convert and store tree structure to graphCore
466
494
  this.updateTreeGraph(dataType, {
467
- nodes: this.userGraphCore.getAllNodes(),
468
- edges: this.userGraphCore.getAllEdges(),
495
+ nodes: this.graphCore.getAllNodes(),
496
+ edges: this.graphCore.getAllEdges(),
469
497
  });
470
498
  }
471
499
  }
@@ -486,7 +514,7 @@ export class DataController {
486
514
  return;
487
515
  }
488
516
  return {
489
- type: type || 'graphData',
517
+ type: type || this.dataType || 'graphData',
490
518
  data: data,
491
519
  };
492
520
  }
@@ -531,12 +559,12 @@ export class DataController {
531
559
  }
532
560
  });
533
561
  // update succeed nodes
534
- const { userGraphCore } = this;
562
+ const { graphCore } = this;
535
563
  succeedNodesModels.forEach((newModel) => {
536
564
  const { id, data } = newModel;
537
565
  if (data) {
538
- const mergedData = mergeOneLevelData(userGraphCore.getNode(id), newModel);
539
- userGraphCore.mergeNodeData(id, mergedData);
566
+ const mergedData = mergeOneLevelData(graphCore.getNode(id), newModel);
567
+ graphCore.mergeNodeData(id, mergedData);
540
568
  }
541
569
  });
542
570
  }
@@ -544,17 +572,20 @@ export class DataController {
544
572
  const { combos = [] } = data;
545
573
  if (!(combos === null || combos === void 0 ? void 0 : combos.length))
546
574
  return;
547
- const { userGraphCore } = this;
575
+ const { graphCore } = this;
548
576
  const { id, data: comboData } = combos[0];
549
577
  const { _children = [] } = comboData, others = __rest(comboData, ["_children"]);
578
+ if (!graphCore.hasTreeStructure('combo')) {
579
+ graphCore.attachTreeStructure('combo');
580
+ }
550
581
  // add or update combo
551
- if (userGraphCore.hasNode(id)) {
582
+ if (graphCore.hasNode(id)) {
552
583
  // update node which is in the graphCore
553
- userGraphCore.mergeNodeData(id, Object.assign(Object.assign({}, others), { _isCombo: true }));
584
+ graphCore.mergeNodeData(id, Object.assign(Object.assign({}, others), { _isCombo: true }));
554
585
  }
555
586
  else {
556
587
  // add node which is in data but not in graphCore
557
- userGraphCore.addNode({ id, data: Object.assign(Object.assign({}, others), { _isCombo: true }) });
588
+ graphCore.addNode({ id, data: Object.assign(Object.assign({}, others), { _isCombo: true }) });
558
589
  }
559
590
  // update strucutre
560
591
  _children.forEach((childId) => {
@@ -562,206 +593,19 @@ export class DataController {
562
593
  console.warn(`Adding child ${childId} to combo ${id} failed. The child ${childId} does not exist`);
563
594
  return;
564
595
  }
565
- userGraphCore.mergeNodeData(childId, { parentId: id });
566
- });
567
- }
568
- /**
569
- * Update graphCore with transformed userGraphCore data.
570
- */
571
- updateGraphCore(event) {
572
- const { graphCore } = this;
573
- const { nodes = [], edges = [], combos = [], } = deconstructData({
574
- nodes: this.userGraphCore.getAllNodes(),
575
- edges: this.userGraphCore.getAllEdges(),
576
- });
577
- const prevNodesAndCombos = graphCore.getAllNodes();
578
- // function to update one data in graphCore with different model type ('node' or 'edge')
579
- const syncUpdateToGraphCore = (id, newValue, oldValue, isNodeOrCombo, diff = []) => {
580
- if (isNodeOrCombo) {
581
- if (newValue.data)
582
- graphCore.updateNodeData(id, Object.assign({}, newValue.data));
583
- }
584
- else {
585
- if (diff.includes('data'))
586
- graphCore.updateEdgeData(id, Object.assign({}, newValue.data));
587
- // source and target may be changed
588
- if (diff.includes('source'))
589
- graphCore.updateEdgeSource(id, newValue.source);
590
- if (diff.includes('target'))
591
- graphCore.updateEdgeTarget(id, newValue.target);
592
- }
593
- };
594
- graphCore.batch(() => {
595
- // === step 3: sync to graphCore according to the changes in userGraphCore ==
596
- const newModelMap = {};
597
- const parentMap = {};
598
- const changeMap = {};
599
- const treeChanges = [];
600
- event.changes.forEach((change) => {
601
- var _a;
602
- const id = change.id || ((_a = change.value) === null || _a === void 0 ? void 0 : _a.id);
603
- if (id !== undefined) {
604
- changeMap[id] = true;
605
- return;
606
- }
607
- if ([
608
- 'TreeStructureAttached',
609
- 'TreeStructureChanged',
610
- 'TreeStructureChanged',
611
- ].includes(change.type)) {
612
- treeChanges.push(change);
613
- }
614
- });
615
- nodes.forEach((model) => {
616
- newModelMap[model.id] = { type: 'node', model };
617
- if (model.data.hasOwnProperty('parentId')) {
618
- parentMap[model.id] = {
619
- new: model.data.parentId,
620
- old: undefined,
621
- };
622
- }
623
- });
624
- edges.forEach((model) => (newModelMap[model.id] = { type: 'edge', model }));
625
- combos.forEach((model) => {
626
- newModelMap[model.id] = { type: 'combo', model };
627
- if (model.data.hasOwnProperty('parentId')) {
628
- parentMap[model.id] = {
629
- new: model.data.parentId,
630
- old: undefined,
631
- };
632
- }
633
- });
634
- prevNodesAndCombos.forEach((prevModel) => {
635
- var _a, _b;
636
- const { id } = prevModel;
637
- if (((_a = parentMap[id]) === null || _a === void 0 ? void 0 : _a.new) !== undefined ||
638
- prevModel.data.parentId !== undefined) {
639
- parentMap[id] = {
640
- new: (_b = parentMap[id]) === null || _b === void 0 ? void 0 : _b.new,
641
- old: prevModel.data.parentId,
642
- };
643
- }
644
- else {
645
- delete parentMap[id];
646
- }
647
- const { model: newModel } = newModelMap[id] || {};
648
- // remove
649
- if (!newModel) {
650
- // remove a combo, put the children to upper parent
651
- if (prevModel.data._isCombo) {
652
- graphCore.getChildren(id, 'combo').forEach((child) => {
653
- parentMap[child.id] = Object.assign(Object.assign({}, parentMap[child.id]), { new: prevModel.data.parentId });
654
- });
655
- }
656
- // if it has combo parent, remove it from the parent's children list
657
- if (prevModel.data.parentId) {
658
- graphCore.setParent(id, undefined, 'combo');
659
- }
660
- // for tree graph view, show the succeed nodes and edges
661
- const succeedIds = [];
662
- if (graphCore.hasTreeStructure('tree')) {
663
- graphCore.dfsTree(id, (child) => {
664
- succeedIds.push(child.id);
665
- }, 'tree');
666
- const succeedEdgeIds = graphCore
667
- .getAllEdges()
668
- .filter(({ source, target }) => succeedIds.includes(source) && succeedIds.includes(target))
669
- .map((edge) => edge.id);
670
- this.graph.showItem(succeedIds
671
- .filter((succeedId) => succeedId !== id)
672
- .concat(succeedEdgeIds));
673
- // for tree graph view, remove the node from the parent's children list
674
- graphCore.setParent(id, undefined, 'tree');
675
- // for tree graph view, make the its children to be roots
676
- graphCore
677
- .getChildren(id, 'tree')
678
- .forEach((child) => graphCore.setParent(child.id, undefined, 'tree'));
679
- }
680
- // remove the node data
681
- graphCore.removeNode(id);
682
- delete parentMap[prevModel.id];
683
- }
684
- // update
685
- // || diffAt(newModel, prevModel, true)?.length
686
- else if (changeMap[id])
687
- syncUpdateToGraphCore(id, newModel, prevModel, true);
688
- // delete from the map indicates this model is visited
689
- delete newModelMap[id];
690
- });
691
- graphCore.getAllEdges().forEach((prevEdge) => {
692
- const { id } = prevEdge;
693
- const { model: newModel } = newModelMap[id] || {};
694
- // remove
695
- if (!newModel)
696
- graphCore.removeEdge(id);
697
- // update
698
- else {
699
- const diff = diffAt(newModel, prevEdge, false);
700
- if (diff === null || diff === void 0 ? void 0 : diff.length)
701
- syncUpdateToGraphCore(id, newModel, prevEdge, false, diff);
702
- }
703
- // delete from the map indicates this model is visited
704
- delete newModelMap[id];
705
- });
706
- // add
707
- Object.values(newModelMap).forEach(({ type, model }) => {
708
- if (type === 'node' || type === 'combo')
709
- graphCore.addNode(model);
710
- else if (type === 'edge')
711
- graphCore.addEdge(model);
712
- });
713
- // update parents after adding all items
714
- Object.keys(parentMap).forEach((id) => {
715
- var _a;
716
- if (parentMap[id].new === parentMap[id].old)
717
- return;
718
- if (!validateComboStrucutre(this.graph, id, parentMap[id].new)) {
719
- graphCore.mergeNodeData(id, { parentId: parentMap[id].old });
720
- return;
721
- }
722
- graphCore.mergeNodeData(id, { parentId: parentMap[id].new });
723
- graphCore.setParent(id, parentMap[id].new, 'combo');
724
- // after remove from parent's children list, check whether the parent is empty
725
- // if so, update parent's position to be the child's
726
- if (parentMap[id].old !== undefined) {
727
- const parentChildren = graphCore.getChildren(parentMap[id].old, 'combo');
728
- const { x = 0, y = 0, z = 0, } = ((_a = this.graph.getDisplayModel(parentMap[id].old)) === null || _a === void 0 ? void 0 : _a.data) || {};
729
- if (!parentChildren.length) {
730
- graphCore.mergeNodeData(parentMap[id].old, {
731
- x: convertToNumber(x),
732
- y: convertToNumber(y),
733
- z: convertToNumber(z),
734
- });
735
- }
736
- }
737
- });
738
- // update tree structure
739
- treeChanges.forEach((change) => {
740
- const { type, treeKey, nodeId, newParentId } = change;
741
- if (type === 'TreeStructureAttached') {
742
- graphCore.attachTreeStructure(treeKey);
743
- return;
744
- }
745
- else if (type === 'TreeStructureChanged') {
746
- graphCore.setParent(nodeId, newParentId, treeKey);
747
- return;
748
- }
749
- else if (type === 'TreeStructureDetached') {
750
- graphCore.detachTreeStructure(treeKey);
751
- return;
752
- }
753
- });
596
+ graphCore.setParent(childId, id, 'combo');
597
+ graphCore.mergeNodeData(childId, { parentId: id });
754
598
  });
755
599
  }
756
600
  /**
757
- * Clone data from userGraphCore, and run transforms
601
+ * Clone data from graphCore, and run transforms
758
602
  * @returns transformed data and the id map list
759
603
  */
760
604
  transformData(data) {
761
605
  let dataCloned = clone(data);
762
606
  // transform the data with transform extensions, output innerData and idMaps ===
763
607
  this.extensions.forEach(({ func, config }) => {
764
- dataCloned = func(dataCloned, config, this.userGraphCore);
608
+ dataCloned = func(dataCloned, config, this.graphCore);
765
609
  });
766
610
  return dataCloned;
767
611
  }
@@ -771,12 +615,12 @@ export class DataController {
771
615
  * @param data
772
616
  */
773
617
  updateTreeGraph(dataType, data) {
774
- this.userGraphCore.attachTreeStructure('tree');
618
+ this.graphCore.attachTreeStructure('tree');
775
619
  if (dataType === 'treeData') {
776
620
  // tree structure storing
777
621
  data.edges.forEach((edge) => {
778
622
  const { source, target } = edge;
779
- this.userGraphCore.setParent(target, source, 'tree');
623
+ this.graphCore.setParent(target, source, 'tree');
780
624
  });
781
625
  }
782
626
  else {