@antv/g6 5.0.0-beta.6 → 5.0.0-beta.7
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.
- package/dist/g6.min.js +2 -2
- package/esm/index.d.ts +8 -12
- package/esm/index.js +1 -1
- package/esm/item/edge.d.ts +21 -1
- package/esm/item/edge.js +78 -35
- package/esm/item/edge.js.map +1 -1
- package/esm/item/item.js +9 -5
- package/esm/item/item.js.map +1 -1
- package/esm/item/node.js +6 -6
- package/esm/item/node.js.map +1 -1
- package/esm/runtime/controller/data.d.ts +7 -10
- package/esm/runtime/controller/data.js +123 -281
- package/esm/runtime/controller/data.js.map +1 -1
- package/esm/runtime/controller/item.js +2 -6
- package/esm/runtime/controller/item.js.map +1 -1
- package/esm/runtime/graph.d.ts +3 -3
- package/esm/runtime/graph.js +35 -14
- package/esm/runtime/graph.js.map +1 -1
- package/esm/stdlib/behavior/create-edge.d.ts +2 -2
- package/esm/stdlib/behavior/create-edge.js +17 -16
- package/esm/stdlib/behavior/create-edge.js.map +1 -1
- package/esm/stdlib/behavior/drag-canvas.d.ts +1 -0
- package/esm/stdlib/behavior/drag-canvas.js +20 -12
- package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
- package/esm/stdlib/behavior/zoom-canvas.d.ts +1 -0
- package/esm/stdlib/behavior/zoom-canvas.js +24 -16
- package/esm/stdlib/behavior/zoom-canvas.js.map +1 -1
- package/esm/stdlib/data/mapNodeSize.d.ts +2 -2
- package/esm/stdlib/data/mapNodeSize.js +2 -2
- package/esm/stdlib/data/mapNodeSize.js.map +1 -1
- package/esm/stdlib/data/transformV4Data.d.ts +2 -2
- package/esm/stdlib/data/transformV4Data.js +2 -2
- package/esm/stdlib/data/transformV4Data.js.map +1 -1
- package/esm/stdlib/data/validateData.d.ts +2 -2
- package/esm/stdlib/data/validateData.js +9 -9
- package/esm/stdlib/data/validateData.js.map +1 -1
- package/esm/stdlib/index.d.ts +7 -7
- package/esm/stdlib/index.js +1 -1
- package/esm/stdlib/index.js.map +1 -1
- package/esm/stdlib/item/edge/base.js +4 -9
- package/esm/stdlib/item/edge/base.js.map +1 -1
- package/esm/stdlib/plugin/minimap/index.js +8 -2
- package/esm/stdlib/plugin/minimap/index.js.map +1 -1
- package/esm/stdlib/plugin/snapline/index.d.ts +5 -1
- package/esm/stdlib/plugin/snapline/index.js +23 -12
- package/esm/stdlib/plugin/snapline/index.js.map +1 -1
- package/esm/types/graph.d.ts +3 -3
- package/esm/types/view.d.ts +5 -0
- package/esm/util/event.d.ts +3 -1
- package/esm/util/event.js +8 -1
- package/esm/util/event.js.map +1 -1
- package/esm/util/item.js +1 -1
- package/esm/util/item.js.map +1 -1
- package/esm/util/layout.d.ts +11 -0
- package/esm/util/layout.js +45 -0
- package/esm/util/layout.js.map +1 -1
- package/esm/util/point.js +5 -1
- package/esm/util/point.js.map +1 -1
- package/esm/util/shape.d.ts +1 -1
- package/esm/util/shape.js +3 -7
- package/esm/util/shape.js.map +1 -1
- package/lib/index.d.ts +8 -12
- package/lib/index.js +1 -1
- package/lib/item/edge.d.ts +21 -1
- package/lib/item/edge.js +77 -34
- package/lib/item/edge.js.map +1 -1
- package/lib/item/item.js +9 -5
- package/lib/item/item.js.map +1 -1
- package/lib/item/node.js +6 -6
- package/lib/item/node.js.map +1 -1
- package/lib/runtime/controller/data.d.ts +7 -10
- package/lib/runtime/controller/data.js +123 -281
- package/lib/runtime/controller/data.js.map +1 -1
- package/lib/runtime/controller/item.js +2 -6
- package/lib/runtime/controller/item.js.map +1 -1
- package/lib/runtime/graph.d.ts +3 -3
- package/lib/runtime/graph.js +35 -14
- package/lib/runtime/graph.js.map +1 -1
- package/lib/stdlib/behavior/create-edge.d.ts +2 -2
- package/lib/stdlib/behavior/create-edge.js +17 -16
- package/lib/stdlib/behavior/create-edge.js.map +1 -1
- package/lib/stdlib/behavior/drag-canvas.d.ts +1 -0
- package/lib/stdlib/behavior/drag-canvas.js +20 -12
- package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
- package/lib/stdlib/behavior/zoom-canvas.d.ts +1 -0
- package/lib/stdlib/behavior/zoom-canvas.js +24 -16
- package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
- package/lib/stdlib/data/mapNodeSize.d.ts +2 -2
- package/lib/stdlib/data/mapNodeSize.js +2 -2
- package/lib/stdlib/data/mapNodeSize.js.map +1 -1
- package/lib/stdlib/data/transformV4Data.d.ts +2 -2
- package/lib/stdlib/data/transformV4Data.js +2 -2
- package/lib/stdlib/data/transformV4Data.js.map +1 -1
- package/lib/stdlib/data/validateData.d.ts +2 -2
- package/lib/stdlib/data/validateData.js +9 -9
- package/lib/stdlib/data/validateData.js.map +1 -1
- package/lib/stdlib/index.d.ts +7 -7
- package/lib/stdlib/index.js +1 -1
- package/lib/stdlib/index.js.map +1 -1
- package/lib/stdlib/item/edge/base.js +4 -9
- package/lib/stdlib/item/edge/base.js.map +1 -1
- package/lib/stdlib/plugin/minimap/index.js +8 -2
- package/lib/stdlib/plugin/minimap/index.js.map +1 -1
- package/lib/stdlib/plugin/snapline/index.d.ts +5 -1
- package/lib/stdlib/plugin/snapline/index.js +23 -12
- package/lib/stdlib/plugin/snapline/index.js.map +1 -1
- package/lib/types/graph.d.ts +3 -3
- package/lib/types/view.d.ts +5 -0
- package/lib/util/event.d.ts +3 -1
- package/lib/util/event.js +8 -1
- package/lib/util/event.js.map +1 -1
- package/lib/util/item.js +1 -1
- package/lib/util/item.js.map +1 -1
- package/lib/util/layout.d.ts +11 -0
- package/lib/util/layout.js +47 -1
- package/lib/util/layout.js.map +1 -1
- package/lib/util/point.js +5 -1
- package/lib/util/point.js.map +1 -1
- package/lib/util/shape.d.ts +1 -1
- package/lib/util/shape.js +3 -7
- package/lib/util/shape.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/item/edge.ts +108 -48
- package/src/item/item.ts +13 -9
- package/src/item/node.ts +6 -6
- package/src/runtime/controller/data.ts +139 -339
- package/src/runtime/controller/item.ts +2 -6
- package/src/runtime/graph.ts +57 -16
- package/src/stdlib/behavior/create-edge.ts +21 -20
- package/src/stdlib/behavior/drag-canvas.ts +23 -12
- package/src/stdlib/behavior/zoom-canvas.ts +27 -16
- package/src/stdlib/data/mapNodeSize.ts +2 -2
- package/src/stdlib/data/transformV4Data.ts +2 -2
- package/src/stdlib/data/validateData.ts +9 -9
- package/src/stdlib/index.ts +1 -1
- package/src/stdlib/item/edge/base.ts +4 -8
- package/src/stdlib/plugin/minimap/index.ts +16 -10
- package/src/stdlib/plugin/snapline/index.ts +36 -16
- package/src/types/graph.ts +6 -3
- package/src/types/view.ts +8 -3
- package/src/util/event.ts +14 -1
- package/src/util/item.ts +1 -1
- package/src/util/layout.ts +45 -0
- package/src/util/point.ts +4 -2
- package/src/util/shape.ts +6 -7
|
@@ -44,10 +44,6 @@ import { hasTreeBehaviors } from '../../util/behavior';
|
|
|
44
44
|
export class DataController {
|
|
45
45
|
public graph: IGraph;
|
|
46
46
|
public extensions = [];
|
|
47
|
-
/**
|
|
48
|
-
* User input data.
|
|
49
|
-
*/
|
|
50
|
-
public userGraphCore: GraphCore;
|
|
51
47
|
/**
|
|
52
48
|
* Inner data stored in graphCore structure.
|
|
53
49
|
*/
|
|
@@ -58,6 +54,11 @@ export class DataController {
|
|
|
58
54
|
*/
|
|
59
55
|
private treeDirtyFlag: boolean;
|
|
60
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Cache the current data type;
|
|
59
|
+
*/
|
|
60
|
+
private dataType: 'treeData' | 'graphData' | 'fetch';
|
|
61
|
+
|
|
61
62
|
constructor(graph: IGraph<any, any>) {
|
|
62
63
|
this.graph = graph;
|
|
63
64
|
this.tap();
|
|
@@ -181,7 +182,7 @@ export class DataController {
|
|
|
181
182
|
*/
|
|
182
183
|
private onDataChange(param: { data: DataConfig; type: DataChangeType }) {
|
|
183
184
|
const { data, type: changeType } = param;
|
|
184
|
-
const {
|
|
185
|
+
const { graphCore } = this;
|
|
185
186
|
const change = () => {
|
|
186
187
|
switch (changeType) {
|
|
187
188
|
case 'remove':
|
|
@@ -202,8 +203,8 @@ export class DataController {
|
|
|
202
203
|
break;
|
|
203
204
|
}
|
|
204
205
|
};
|
|
205
|
-
if (
|
|
206
|
-
|
|
206
|
+
if (graphCore) {
|
|
207
|
+
graphCore.batch(change);
|
|
207
208
|
} else {
|
|
208
209
|
change();
|
|
209
210
|
}
|
|
@@ -215,7 +216,7 @@ export class DataController {
|
|
|
215
216
|
}) {
|
|
216
217
|
const { ids, action } = params;
|
|
217
218
|
ids.forEach((id) => {
|
|
218
|
-
this.
|
|
219
|
+
this.graphCore.mergeNodeData(id, {
|
|
219
220
|
collapsed: action === 'collapse',
|
|
220
221
|
});
|
|
221
222
|
});
|
|
@@ -223,7 +224,7 @@ export class DataController {
|
|
|
223
224
|
|
|
224
225
|
private onLayout({ options }) {
|
|
225
226
|
if (this.treeDirtyFlag && isTreeLayout(options)) {
|
|
226
|
-
this.
|
|
227
|
+
this.establishGraphCoreTree();
|
|
227
228
|
}
|
|
228
229
|
}
|
|
229
230
|
|
|
@@ -231,7 +232,7 @@ export class DataController {
|
|
|
231
232
|
const { modes = {} } = this.graph.getSpecification();
|
|
232
233
|
const mode = this.graph.getMode() || 'default';
|
|
233
234
|
if (hasTreeBehaviors(modes[mode])) {
|
|
234
|
-
this.
|
|
235
|
+
this.establishGraphCoreTree();
|
|
235
236
|
}
|
|
236
237
|
}
|
|
237
238
|
|
|
@@ -244,31 +245,29 @@ export class DataController {
|
|
|
244
245
|
const mode = this.graph.getMode() || 'default';
|
|
245
246
|
if (action !== 'add' || !modes.includes(mode)) return;
|
|
246
247
|
if (hasTreeBehaviors(behaviors)) {
|
|
247
|
-
this.
|
|
248
|
+
this.establishGraphCoreTree();
|
|
248
249
|
}
|
|
249
250
|
}
|
|
250
251
|
|
|
251
252
|
private onModeChange(param: { mode: string }) {
|
|
252
253
|
const { modes = {} } = this.graph.getSpecification();
|
|
253
254
|
if (hasTreeBehaviors(modes[param.mode])) {
|
|
254
|
-
this.
|
|
255
|
+
this.establishGraphCoreTree();
|
|
255
256
|
}
|
|
256
257
|
}
|
|
257
258
|
|
|
258
|
-
private
|
|
259
|
+
private establishGraphCoreTree() {
|
|
259
260
|
if (!this.treeDirtyFlag) return;
|
|
260
|
-
const nodes = this.
|
|
261
|
-
const edges = this.
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
this.userGraphCore.setParent(child.id, node.id, 'tree');
|
|
271
|
-
});
|
|
261
|
+
const nodes = this.graphCore.getAllNodes();
|
|
262
|
+
const edges = this.graphCore.getAllEdges();
|
|
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.graphCore.setParent(child.id, node.id, 'tree');
|
|
272
271
|
});
|
|
273
272
|
});
|
|
274
273
|
});
|
|
@@ -286,20 +285,11 @@ export class DataController {
|
|
|
286
285
|
) {
|
|
287
286
|
const { type: dataType, data } = this.formatData(dataConfig) || {};
|
|
288
287
|
if (!dataType) return;
|
|
288
|
+
this.dataType = dataType;
|
|
289
289
|
|
|
290
290
|
const { nodes = [], edges = [], combos = [] } = this.transformData(data);
|
|
291
291
|
|
|
292
292
|
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
|
-
});
|
|
303
293
|
this.graphCore = new GraphLib<NodeModelData, EdgeModelData>(
|
|
304
294
|
clone({
|
|
305
295
|
nodes: nodes.concat(
|
|
@@ -341,9 +331,9 @@ export class DataController {
|
|
|
341
331
|
});
|
|
342
332
|
}
|
|
343
333
|
} else {
|
|
344
|
-
const {
|
|
334
|
+
const { graphCore } = this;
|
|
345
335
|
const prevData = deconstructData({
|
|
346
|
-
nodes:
|
|
336
|
+
nodes: graphCore.getAllNodes(),
|
|
347
337
|
edges: [],
|
|
348
338
|
});
|
|
349
339
|
const nodesAndCombos = nodes.concat(
|
|
@@ -355,62 +345,108 @@ export class DataController {
|
|
|
355
345
|
|
|
356
346
|
// =========== node & combos ============
|
|
357
347
|
if (!prevData.nodes.length) {
|
|
358
|
-
|
|
348
|
+
graphCore.addNodes(nodesAndCombos);
|
|
359
349
|
} else {
|
|
360
350
|
if (changeType === 'mergeReplace') {
|
|
361
|
-
// remove the nodes which are not in data but in
|
|
351
|
+
// remove the nodes which are not in incoming data but in graphCore
|
|
362
352
|
const nodeAndComboIds = nodesAndCombos.map((node) => node.id);
|
|
363
353
|
prevData.nodes.forEach((prevNode) => {
|
|
364
|
-
if (!nodeAndComboIds.includes(prevNode.id))
|
|
365
|
-
|
|
354
|
+
if (!nodeAndComboIds.includes(prevNode.id)) {
|
|
355
|
+
this.removeNode(prevNode);
|
|
356
|
+
}
|
|
366
357
|
});
|
|
367
358
|
}
|
|
368
359
|
// add or update node
|
|
369
360
|
nodesAndCombos.forEach((item) => {
|
|
370
|
-
if (
|
|
361
|
+
if (graphCore.hasNode(item.id)) {
|
|
371
362
|
// update node which is in the graphCore
|
|
372
|
-
|
|
363
|
+
graphCore.mergeNodeData(item.id, item.data);
|
|
373
364
|
} else {
|
|
374
365
|
// add node which is in data but not in graphCore
|
|
375
|
-
|
|
366
|
+
graphCore.addNode(item);
|
|
376
367
|
}
|
|
377
368
|
});
|
|
378
369
|
}
|
|
379
370
|
|
|
380
371
|
// =========== edge ============
|
|
381
|
-
prevData.edges =
|
|
372
|
+
prevData.edges = graphCore.getAllEdges();
|
|
382
373
|
if (!prevData.edges.length) {
|
|
383
|
-
|
|
374
|
+
graphCore.addEdges(edges);
|
|
384
375
|
} else {
|
|
385
376
|
if (changeType === 'mergeReplace') {
|
|
386
|
-
// remove the edges which are not in data but in
|
|
377
|
+
// remove the edges which are not in incoming data but in graphCore
|
|
387
378
|
const edgeIds = edges.map((edge) => edge.id);
|
|
388
379
|
prevData.edges.forEach((prevEdge) => {
|
|
389
380
|
if (!edgeIds.includes(prevEdge.id))
|
|
390
|
-
|
|
381
|
+
graphCore.removeEdge(prevEdge.id);
|
|
391
382
|
});
|
|
392
383
|
}
|
|
393
384
|
// add or update edge
|
|
394
385
|
edges.forEach((edge) => {
|
|
395
|
-
if (
|
|
386
|
+
if (graphCore.hasEdge(edge.id)) {
|
|
396
387
|
// update edge which is in the graphCore
|
|
397
|
-
|
|
388
|
+
graphCore.mergeEdgeData(edge.id, edge.data);
|
|
398
389
|
} else {
|
|
399
390
|
// add edge which is in data but not in graphCore
|
|
400
|
-
|
|
391
|
+
graphCore.addEdge(edge);
|
|
401
392
|
}
|
|
402
393
|
});
|
|
403
394
|
}
|
|
404
395
|
}
|
|
405
396
|
|
|
406
397
|
if (data.edges?.length) {
|
|
407
|
-
const {
|
|
398
|
+
const { graphCore } = this;
|
|
408
399
|
// convert and store tree structure to graphCore
|
|
409
400
|
this.updateTreeGraph(dataType, {
|
|
410
|
-
nodes:
|
|
411
|
-
edges:
|
|
401
|
+
nodes: graphCore.getAllNodes(),
|
|
402
|
+
edges: graphCore.getAllEdges(),
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
private removeNode(nodeModel: NodeModel) {
|
|
408
|
+
const { id, data } = nodeModel;
|
|
409
|
+
const { graphCore } = this;
|
|
410
|
+
if (graphCore.hasTreeStructure('combo')) {
|
|
411
|
+
// remove from its parent's children list
|
|
412
|
+
graphCore.setParent(id, undefined, 'combo');
|
|
413
|
+
const { parentId } = data;
|
|
414
|
+
// move the children to the grandparent's children list
|
|
415
|
+
graphCore.getChildren(id, 'combo').forEach((child) => {
|
|
416
|
+
graphCore.setParent(child.id, parentId, 'combo');
|
|
417
|
+
graphCore.mergeNodeData(child.id, { parentId });
|
|
412
418
|
});
|
|
413
419
|
}
|
|
420
|
+
if (graphCore.hasTreeStructure('tree')) {
|
|
421
|
+
const succeedIds = [];
|
|
422
|
+
graphCore.dfsTree(
|
|
423
|
+
id,
|
|
424
|
+
(child) => {
|
|
425
|
+
succeedIds.push(child.id);
|
|
426
|
+
},
|
|
427
|
+
'tree',
|
|
428
|
+
);
|
|
429
|
+
const succeedEdgeIds = graphCore
|
|
430
|
+
.getAllEdges()
|
|
431
|
+
.filter(
|
|
432
|
+
({ source, target }) =>
|
|
433
|
+
succeedIds.includes(source) && succeedIds.includes(target),
|
|
434
|
+
)
|
|
435
|
+
.map((edge) => edge.id);
|
|
436
|
+
this.graph.showItem(
|
|
437
|
+
succeedIds
|
|
438
|
+
.filter((succeedId) => succeedId !== id)
|
|
439
|
+
.concat(succeedEdgeIds),
|
|
440
|
+
);
|
|
441
|
+
|
|
442
|
+
// for tree graph view, remove the node from the parent's children list
|
|
443
|
+
graphCore.setParent(id, undefined, 'tree');
|
|
444
|
+
// for tree graph view, make the its children to be roots
|
|
445
|
+
graphCore
|
|
446
|
+
.getChildren(id, 'tree')
|
|
447
|
+
.forEach((child) => graphCore.setParent(child.id, undefined, 'tree'));
|
|
448
|
+
}
|
|
449
|
+
graphCore.removeNode(id);
|
|
414
450
|
}
|
|
415
451
|
|
|
416
452
|
/**
|
|
@@ -418,30 +454,25 @@ export class DataController {
|
|
|
418
454
|
* @param data data to be removed which is part of old one
|
|
419
455
|
*/
|
|
420
456
|
private removeData(data: GraphData) {
|
|
421
|
-
const {
|
|
457
|
+
const { graphCore } = this;
|
|
422
458
|
const { nodes = [], edges = [], combos = [] } = data;
|
|
423
459
|
const nodesAndCombos = nodes.concat(combos);
|
|
424
|
-
const prevNodesAndCombos =
|
|
425
|
-
const prevEdges =
|
|
460
|
+
const prevNodesAndCombos = graphCore.getAllNodes();
|
|
461
|
+
const prevEdges = graphCore.getAllEdges();
|
|
426
462
|
if (prevNodesAndCombos.length && nodesAndCombos.length) {
|
|
427
|
-
// update
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
this.graphCore.getChildren(item.id, 'combo').forEach((child) => {
|
|
432
|
-
userGraphCore.mergeNodeData(child.id, { parentId });
|
|
433
|
-
});
|
|
434
|
-
});
|
|
435
|
-
}
|
|
463
|
+
// update combo tree view and tree graph view
|
|
464
|
+
nodesAndCombos.forEach((item) => {
|
|
465
|
+
this.removeNode(item);
|
|
466
|
+
});
|
|
436
467
|
// remove the node
|
|
437
|
-
|
|
468
|
+
// graphCore.removeNodes(nodesAndCombos.map((node) => node.id));
|
|
438
469
|
}
|
|
439
470
|
if (prevEdges.length && edges.length) {
|
|
440
471
|
// add or update edge
|
|
441
472
|
const ids = edges
|
|
442
473
|
.map((edge) => edge.id)
|
|
443
|
-
.filter((id) =>
|
|
444
|
-
|
|
474
|
+
.filter((id) => graphCore.hasEdge(id));
|
|
475
|
+
graphCore.removeEdges(ids);
|
|
445
476
|
}
|
|
446
477
|
}
|
|
447
478
|
|
|
@@ -450,7 +481,7 @@ export class DataController {
|
|
|
450
481
|
* @param data data to be updated which is part of old one
|
|
451
482
|
*/
|
|
452
483
|
private updateData(dataConfig: DataConfig) {
|
|
453
|
-
const {
|
|
484
|
+
const { graphCore } = this;
|
|
454
485
|
const { type: dataType, data } = this.formatData(dataConfig);
|
|
455
486
|
if (!dataType) return;
|
|
456
487
|
const { nodes = [], edges = [], combos = [] } = data; //this.transformData(data as GraphData);
|
|
@@ -459,38 +490,35 @@ export class DataController {
|
|
|
459
490
|
edges: prevEdges,
|
|
460
491
|
combos: prevCombos,
|
|
461
492
|
} = deconstructData({
|
|
462
|
-
nodes:
|
|
463
|
-
edges:
|
|
493
|
+
nodes: graphCore.getAllNodes(),
|
|
494
|
+
edges: graphCore.getAllEdges(),
|
|
464
495
|
});
|
|
465
496
|
if (prevNodes.length) {
|
|
466
497
|
// update node
|
|
467
498
|
nodes.forEach((newModel) => {
|
|
468
499
|
const { id, data } = newModel;
|
|
469
500
|
if (data) {
|
|
470
|
-
const mergedData = mergeOneLevelData(
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
501
|
+
const mergedData = mergeOneLevelData(graphCore.getNode(id), newModel);
|
|
502
|
+
graphCore.mergeNodeData(id, mergedData);
|
|
503
|
+
}
|
|
504
|
+
if (data.hasOwnProperty('parentId')) {
|
|
505
|
+
graphCore.setParent(id, data.parentId, 'combo');
|
|
475
506
|
}
|
|
476
507
|
});
|
|
477
508
|
}
|
|
478
509
|
if (prevEdges.length) {
|
|
479
510
|
// update edge
|
|
480
511
|
edges.forEach((newModel) => {
|
|
481
|
-
const oldModel =
|
|
512
|
+
const oldModel = graphCore.getEdge(newModel.id);
|
|
482
513
|
if (!oldModel) return;
|
|
483
514
|
const { id, source, target, data } = newModel;
|
|
484
515
|
if (source && oldModel.source !== source)
|
|
485
|
-
|
|
516
|
+
graphCore.updateEdgeSource(id, source);
|
|
486
517
|
if (target && oldModel.target !== target)
|
|
487
|
-
|
|
518
|
+
graphCore.updateEdgeTarget(id, target);
|
|
488
519
|
if (data) {
|
|
489
|
-
const mergedData = mergeOneLevelData(
|
|
490
|
-
|
|
491
|
-
newModel,
|
|
492
|
-
);
|
|
493
|
-
userGraphCore.mergeEdgeData(id, mergedData);
|
|
520
|
+
const mergedData = mergeOneLevelData(graphCore.getEdge(id), newModel);
|
|
521
|
+
graphCore.mergeEdgeData(id, mergedData);
|
|
494
522
|
}
|
|
495
523
|
});
|
|
496
524
|
}
|
|
@@ -538,17 +566,20 @@ export class DataController {
|
|
|
538
566
|
}
|
|
539
567
|
// update other properties
|
|
540
568
|
if (Object.keys(others).length) {
|
|
541
|
-
const mergedData = mergeOneLevelData(
|
|
569
|
+
const mergedData = mergeOneLevelData(graphCore.getNode(id), {
|
|
542
570
|
id,
|
|
543
571
|
data: others,
|
|
544
572
|
});
|
|
545
|
-
|
|
573
|
+
graphCore.mergeNodeData(id, mergedData);
|
|
574
|
+
if (others.hasOwnProperty('parentId')) {
|
|
575
|
+
graphCore.setParent(id, others.parentId, 'combo');
|
|
576
|
+
}
|
|
546
577
|
}
|
|
547
578
|
});
|
|
548
579
|
// update succeed nodes
|
|
549
580
|
modelsToMove.forEach((newModel) => {
|
|
550
581
|
const { id, data } = newModel;
|
|
551
|
-
|
|
582
|
+
graphCore.mergeNodeData(id, data);
|
|
552
583
|
});
|
|
553
584
|
}
|
|
554
585
|
|
|
@@ -560,8 +591,8 @@ export class DataController {
|
|
|
560
591
|
) {
|
|
561
592
|
// convert and store tree structure to graphCore
|
|
562
593
|
this.updateTreeGraph(dataType, {
|
|
563
|
-
nodes: this.
|
|
564
|
-
edges: this.
|
|
594
|
+
nodes: this.graphCore.getAllNodes(),
|
|
595
|
+
edges: this.graphCore.getAllEdges(),
|
|
565
596
|
});
|
|
566
597
|
}
|
|
567
598
|
}
|
|
@@ -589,7 +620,7 @@ export class DataController {
|
|
|
589
620
|
}
|
|
590
621
|
|
|
591
622
|
return {
|
|
592
|
-
type: type || 'graphData',
|
|
623
|
+
type: type || this.dataType || 'graphData',
|
|
593
624
|
data: data as GraphData,
|
|
594
625
|
};
|
|
595
626
|
}
|
|
@@ -640,15 +671,12 @@ export class DataController {
|
|
|
640
671
|
}
|
|
641
672
|
});
|
|
642
673
|
// update succeed nodes
|
|
643
|
-
const {
|
|
674
|
+
const { graphCore } = this;
|
|
644
675
|
succeedNodesModels.forEach((newModel) => {
|
|
645
676
|
const { id, data } = newModel;
|
|
646
677
|
if (data) {
|
|
647
|
-
const mergedData = mergeOneLevelData(
|
|
648
|
-
|
|
649
|
-
newModel,
|
|
650
|
-
);
|
|
651
|
-
userGraphCore.mergeNodeData(id, mergedData);
|
|
678
|
+
const mergedData = mergeOneLevelData(graphCore.getNode(id), newModel);
|
|
679
|
+
graphCore.mergeNodeData(id, mergedData);
|
|
652
680
|
}
|
|
653
681
|
});
|
|
654
682
|
}
|
|
@@ -656,17 +684,21 @@ export class DataController {
|
|
|
656
684
|
private addCombo(data: GraphData) {
|
|
657
685
|
const { combos = [] } = data;
|
|
658
686
|
if (!combos?.length) return;
|
|
659
|
-
const {
|
|
687
|
+
const { graphCore } = this;
|
|
660
688
|
const { id, data: comboData } = combos[0];
|
|
661
689
|
const { _children = [], ...others } = comboData;
|
|
662
690
|
|
|
691
|
+
if (!graphCore.hasTreeStructure('combo')) {
|
|
692
|
+
graphCore.attachTreeStructure('combo');
|
|
693
|
+
}
|
|
694
|
+
|
|
663
695
|
// add or update combo
|
|
664
|
-
if (
|
|
696
|
+
if (graphCore.hasNode(id)) {
|
|
665
697
|
// update node which is in the graphCore
|
|
666
|
-
|
|
698
|
+
graphCore.mergeNodeData(id, { ...others, _isCombo: true });
|
|
667
699
|
} else {
|
|
668
700
|
// add node which is in data but not in graphCore
|
|
669
|
-
|
|
701
|
+
graphCore.addNode({ id, data: { ...others, _isCombo: true } });
|
|
670
702
|
}
|
|
671
703
|
|
|
672
704
|
// update strucutre
|
|
@@ -677,252 +709,20 @@ export class DataController {
|
|
|
677
709
|
);
|
|
678
710
|
return;
|
|
679
711
|
}
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
/**
|
|
685
|
-
* Update graphCore with transformed userGraphCore data.
|
|
686
|
-
*/
|
|
687
|
-
private updateGraphCore(event) {
|
|
688
|
-
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
|
-
}
|
|
720
|
-
};
|
|
721
|
-
|
|
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
|
-
});
|
|
712
|
+
graphCore.setParent(childId, id, 'combo');
|
|
713
|
+
graphCore.mergeNodeData(childId, { parentId: id });
|
|
914
714
|
});
|
|
915
715
|
}
|
|
916
716
|
|
|
917
717
|
/**
|
|
918
|
-
* Clone data from
|
|
718
|
+
* Clone data from graphCore, and run transforms
|
|
919
719
|
* @returns transformed data and the id map list
|
|
920
720
|
*/
|
|
921
721
|
private transformData(data): GraphData {
|
|
922
722
|
let dataCloned: GraphData = clone(data);
|
|
923
723
|
// transform the data with transform extensions, output innerData and idMaps ===
|
|
924
724
|
this.extensions.forEach(({ func, config }) => {
|
|
925
|
-
dataCloned = func(dataCloned, config, this.
|
|
725
|
+
dataCloned = func(dataCloned, config, this.graphCore);
|
|
926
726
|
});
|
|
927
727
|
return dataCloned;
|
|
928
728
|
}
|
|
@@ -933,12 +733,12 @@ export class DataController {
|
|
|
933
733
|
* @param data
|
|
934
734
|
*/
|
|
935
735
|
private updateTreeGraph(dataType, data) {
|
|
936
|
-
this.
|
|
736
|
+
this.graphCore.attachTreeStructure('tree');
|
|
937
737
|
if (dataType === 'treeData') {
|
|
938
738
|
// tree structure storing
|
|
939
739
|
data.edges.forEach((edge) => {
|
|
940
740
|
const { source, target } = edge;
|
|
941
|
-
this.
|
|
741
|
+
this.graphCore.setParent(target, source, 'tree');
|
|
942
742
|
});
|
|
943
743
|
} else {
|
|
944
744
|
this.treeDirtyFlag = true;
|