@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
|
@@ -17,7 +17,6 @@ const util_1 = require("@antv/util");
|
|
|
17
17
|
const stdlib_1 = require("../../stdlib");
|
|
18
18
|
const data_1 = require("../../util/data");
|
|
19
19
|
const extension_1 = require("../../util/extension");
|
|
20
|
-
const type_1 = require("../../util/type");
|
|
21
20
|
const layout_1 = require("../../util/layout");
|
|
22
21
|
const behavior_1 = require("../../util/behavior");
|
|
23
22
|
/**
|
|
@@ -132,7 +131,7 @@ class DataController {
|
|
|
132
131
|
*/
|
|
133
132
|
onDataChange(param) {
|
|
134
133
|
const { data, type: changeType } = param;
|
|
135
|
-
const {
|
|
134
|
+
const { graphCore } = this;
|
|
136
135
|
const change = () => {
|
|
137
136
|
switch (changeType) {
|
|
138
137
|
case 'remove':
|
|
@@ -153,8 +152,8 @@ class DataController {
|
|
|
153
152
|
break;
|
|
154
153
|
}
|
|
155
154
|
};
|
|
156
|
-
if (
|
|
157
|
-
|
|
155
|
+
if (graphCore) {
|
|
156
|
+
graphCore.batch(change);
|
|
158
157
|
}
|
|
159
158
|
else {
|
|
160
159
|
change();
|
|
@@ -163,21 +162,21 @@ class DataController {
|
|
|
163
162
|
onTreeCollapseExpand(params) {
|
|
164
163
|
const { ids, action } = params;
|
|
165
164
|
ids.forEach((id) => {
|
|
166
|
-
this.
|
|
165
|
+
this.graphCore.mergeNodeData(id, {
|
|
167
166
|
collapsed: action === 'collapse',
|
|
168
167
|
});
|
|
169
168
|
});
|
|
170
169
|
}
|
|
171
170
|
onLayout({ options }) {
|
|
172
171
|
if (this.treeDirtyFlag && (0, layout_1.isTreeLayout)(options)) {
|
|
173
|
-
this.
|
|
172
|
+
this.establishGraphCoreTree();
|
|
174
173
|
}
|
|
175
174
|
}
|
|
176
175
|
onGraphInit() {
|
|
177
176
|
const { modes = {} } = this.graph.getSpecification();
|
|
178
177
|
const mode = this.graph.getMode() || 'default';
|
|
179
178
|
if ((0, behavior_1.hasTreeBehaviors)(modes[mode])) {
|
|
180
|
-
this.
|
|
179
|
+
this.establishGraphCoreTree();
|
|
181
180
|
}
|
|
182
181
|
}
|
|
183
182
|
onBehaviorChange(param) {
|
|
@@ -186,31 +185,29 @@ class DataController {
|
|
|
186
185
|
if (action !== 'add' || !modes.includes(mode))
|
|
187
186
|
return;
|
|
188
187
|
if ((0, behavior_1.hasTreeBehaviors)(behaviors)) {
|
|
189
|
-
this.
|
|
188
|
+
this.establishGraphCoreTree();
|
|
190
189
|
}
|
|
191
190
|
}
|
|
192
191
|
onModeChange(param) {
|
|
193
192
|
const { modes = {} } = this.graph.getSpecification();
|
|
194
193
|
if ((0, behavior_1.hasTreeBehaviors)(modes[param.mode])) {
|
|
195
|
-
this.
|
|
194
|
+
this.establishGraphCoreTree();
|
|
196
195
|
}
|
|
197
196
|
}
|
|
198
|
-
|
|
197
|
+
establishGraphCoreTree() {
|
|
199
198
|
if (!this.treeDirtyFlag)
|
|
200
199
|
return;
|
|
201
|
-
const nodes = this.
|
|
202
|
-
const edges = this.
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
(0, data_1.
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
(
|
|
212
|
-
this.userGraphCore.setParent(child.id, node.id, 'tree');
|
|
213
|
-
});
|
|
200
|
+
const nodes = this.graphCore.getAllNodes();
|
|
201
|
+
const edges = this.graphCore.getAllEdges();
|
|
202
|
+
// graph data to tree structure and storing
|
|
203
|
+
const rootIds = nodes
|
|
204
|
+
.filter((node) => node.data.isRoot)
|
|
205
|
+
.map((node) => node.id);
|
|
206
|
+
(0, data_1.graphData2TreeData)({}, { nodes, edges }, rootIds).forEach((tree) => {
|
|
207
|
+
(0, data_1.traverse)(tree, (node) => {
|
|
208
|
+
var _a;
|
|
209
|
+
(_a = node.children) === null || _a === void 0 ? void 0 : _a.forEach((child) => {
|
|
210
|
+
this.graphCore.setParent(child.id, node.id, 'tree');
|
|
214
211
|
});
|
|
215
212
|
});
|
|
216
213
|
});
|
|
@@ -226,16 +223,9 @@ class DataController {
|
|
|
226
223
|
const { type: dataType, data } = this.formatData(dataConfig) || {};
|
|
227
224
|
if (!dataType)
|
|
228
225
|
return;
|
|
226
|
+
this.dataType = dataType;
|
|
229
227
|
const { nodes = [], edges = [], combos = [] } = this.transformData(data);
|
|
230
228
|
if (changeType === 'replace') {
|
|
231
|
-
this.userGraphCore = new graphlib_1.Graph({
|
|
232
|
-
nodes: nodes.concat((combos === null || combos === void 0 ? void 0 : combos.map((combo) => ({
|
|
233
|
-
id: combo.id,
|
|
234
|
-
data: Object.assign(Object.assign({}, combo.data), { _isCombo: true }),
|
|
235
|
-
}))) || []),
|
|
236
|
-
edges,
|
|
237
|
-
onChanged: (event) => this.updateGraphCore(event),
|
|
238
|
-
});
|
|
239
229
|
this.graphCore = new graphlib_1.Graph((0, util_1.clone)({
|
|
240
230
|
nodes: nodes.concat((combos === null || combos === void 0 ? void 0 : combos.map((combo) => ({
|
|
241
231
|
id: combo.id,
|
|
@@ -268,9 +258,9 @@ class DataController {
|
|
|
268
258
|
}
|
|
269
259
|
}
|
|
270
260
|
else {
|
|
271
|
-
const {
|
|
261
|
+
const { graphCore } = this;
|
|
272
262
|
const prevData = (0, data_1.deconstructData)({
|
|
273
|
-
nodes:
|
|
263
|
+
nodes: graphCore.getAllNodes(),
|
|
274
264
|
edges: [],
|
|
275
265
|
});
|
|
276
266
|
const nodesAndCombos = nodes.concat(combos.map((combo) => ({
|
|
@@ -279,94 +269,124 @@ class DataController {
|
|
|
279
269
|
})));
|
|
280
270
|
// =========== node & combos ============
|
|
281
271
|
if (!prevData.nodes.length) {
|
|
282
|
-
|
|
272
|
+
graphCore.addNodes(nodesAndCombos);
|
|
283
273
|
}
|
|
284
274
|
else {
|
|
285
275
|
if (changeType === 'mergeReplace') {
|
|
286
|
-
// remove the nodes which are not in data but in
|
|
276
|
+
// remove the nodes which are not in incoming data but in graphCore
|
|
287
277
|
const nodeAndComboIds = nodesAndCombos.map((node) => node.id);
|
|
288
278
|
prevData.nodes.forEach((prevNode) => {
|
|
289
|
-
if (!nodeAndComboIds.includes(prevNode.id))
|
|
290
|
-
|
|
279
|
+
if (!nodeAndComboIds.includes(prevNode.id)) {
|
|
280
|
+
this.removeNode(prevNode);
|
|
281
|
+
}
|
|
291
282
|
});
|
|
292
283
|
}
|
|
293
284
|
// add or update node
|
|
294
285
|
nodesAndCombos.forEach((item) => {
|
|
295
|
-
if (
|
|
286
|
+
if (graphCore.hasNode(item.id)) {
|
|
296
287
|
// update node which is in the graphCore
|
|
297
|
-
|
|
288
|
+
graphCore.mergeNodeData(item.id, item.data);
|
|
298
289
|
}
|
|
299
290
|
else {
|
|
300
291
|
// add node which is in data but not in graphCore
|
|
301
|
-
|
|
292
|
+
graphCore.addNode(item);
|
|
302
293
|
}
|
|
303
294
|
});
|
|
304
295
|
}
|
|
305
296
|
// =========== edge ============
|
|
306
|
-
prevData.edges =
|
|
297
|
+
prevData.edges = graphCore.getAllEdges();
|
|
307
298
|
if (!prevData.edges.length) {
|
|
308
|
-
|
|
299
|
+
graphCore.addEdges(edges);
|
|
309
300
|
}
|
|
310
301
|
else {
|
|
311
302
|
if (changeType === 'mergeReplace') {
|
|
312
|
-
// remove the edges which are not in data but in
|
|
303
|
+
// remove the edges which are not in incoming data but in graphCore
|
|
313
304
|
const edgeIds = edges.map((edge) => edge.id);
|
|
314
305
|
prevData.edges.forEach((prevEdge) => {
|
|
315
306
|
if (!edgeIds.includes(prevEdge.id))
|
|
316
|
-
|
|
307
|
+
graphCore.removeEdge(prevEdge.id);
|
|
317
308
|
});
|
|
318
309
|
}
|
|
319
310
|
// add or update edge
|
|
320
311
|
edges.forEach((edge) => {
|
|
321
|
-
if (
|
|
312
|
+
if (graphCore.hasEdge(edge.id)) {
|
|
322
313
|
// update edge which is in the graphCore
|
|
323
|
-
|
|
314
|
+
graphCore.mergeEdgeData(edge.id, edge.data);
|
|
324
315
|
}
|
|
325
316
|
else {
|
|
326
317
|
// add edge which is in data but not in graphCore
|
|
327
|
-
|
|
318
|
+
graphCore.addEdge(edge);
|
|
328
319
|
}
|
|
329
320
|
});
|
|
330
321
|
}
|
|
331
322
|
}
|
|
332
323
|
if ((_a = data.edges) === null || _a === void 0 ? void 0 : _a.length) {
|
|
333
|
-
const {
|
|
324
|
+
const { graphCore } = this;
|
|
334
325
|
// convert and store tree structure to graphCore
|
|
335
326
|
this.updateTreeGraph(dataType, {
|
|
336
|
-
nodes:
|
|
337
|
-
edges:
|
|
327
|
+
nodes: graphCore.getAllNodes(),
|
|
328
|
+
edges: graphCore.getAllEdges(),
|
|
338
329
|
});
|
|
339
330
|
}
|
|
340
331
|
}
|
|
332
|
+
removeNode(nodeModel) {
|
|
333
|
+
const { id, data } = nodeModel;
|
|
334
|
+
const { graphCore } = this;
|
|
335
|
+
if (graphCore.hasTreeStructure('combo')) {
|
|
336
|
+
// remove from its parent's children list
|
|
337
|
+
graphCore.setParent(id, undefined, 'combo');
|
|
338
|
+
const { parentId } = data;
|
|
339
|
+
// move the children to the grandparent's children list
|
|
340
|
+
graphCore.getChildren(id, 'combo').forEach((child) => {
|
|
341
|
+
graphCore.setParent(child.id, parentId, 'combo');
|
|
342
|
+
graphCore.mergeNodeData(child.id, { parentId });
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
if (graphCore.hasTreeStructure('tree')) {
|
|
346
|
+
const succeedIds = [];
|
|
347
|
+
graphCore.dfsTree(id, (child) => {
|
|
348
|
+
succeedIds.push(child.id);
|
|
349
|
+
}, 'tree');
|
|
350
|
+
const succeedEdgeIds = graphCore
|
|
351
|
+
.getAllEdges()
|
|
352
|
+
.filter(({ source, target }) => succeedIds.includes(source) && succeedIds.includes(target))
|
|
353
|
+
.map((edge) => edge.id);
|
|
354
|
+
this.graph.showItem(succeedIds
|
|
355
|
+
.filter((succeedId) => succeedId !== id)
|
|
356
|
+
.concat(succeedEdgeIds));
|
|
357
|
+
// for tree graph view, remove the node from the parent's children list
|
|
358
|
+
graphCore.setParent(id, undefined, 'tree');
|
|
359
|
+
// for tree graph view, make the its children to be roots
|
|
360
|
+
graphCore
|
|
361
|
+
.getChildren(id, 'tree')
|
|
362
|
+
.forEach((child) => graphCore.setParent(child.id, undefined, 'tree'));
|
|
363
|
+
}
|
|
364
|
+
graphCore.removeNode(id);
|
|
365
|
+
}
|
|
341
366
|
/**
|
|
342
367
|
* Remove part of old data.
|
|
343
368
|
* @param data data to be removed which is part of old one
|
|
344
369
|
*/
|
|
345
370
|
removeData(data) {
|
|
346
|
-
const {
|
|
371
|
+
const { graphCore } = this;
|
|
347
372
|
const { nodes = [], edges = [], combos = [] } = data;
|
|
348
373
|
const nodesAndCombos = nodes.concat(combos);
|
|
349
|
-
const prevNodesAndCombos =
|
|
350
|
-
const prevEdges =
|
|
374
|
+
const prevNodesAndCombos = graphCore.getAllNodes();
|
|
375
|
+
const prevEdges = graphCore.getAllEdges();
|
|
351
376
|
if (prevNodesAndCombos.length && nodesAndCombos.length) {
|
|
352
|
-
// update
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
this.graphCore.getChildren(item.id, 'combo').forEach((child) => {
|
|
357
|
-
userGraphCore.mergeNodeData(child.id, { parentId });
|
|
358
|
-
});
|
|
359
|
-
});
|
|
360
|
-
}
|
|
377
|
+
// update combo tree view and tree graph view
|
|
378
|
+
nodesAndCombos.forEach((item) => {
|
|
379
|
+
this.removeNode(item);
|
|
380
|
+
});
|
|
361
381
|
// remove the node
|
|
362
|
-
|
|
382
|
+
// graphCore.removeNodes(nodesAndCombos.map((node) => node.id));
|
|
363
383
|
}
|
|
364
384
|
if (prevEdges.length && edges.length) {
|
|
365
385
|
// add or update edge
|
|
366
386
|
const ids = edges
|
|
367
387
|
.map((edge) => edge.id)
|
|
368
|
-
.filter((id) =>
|
|
369
|
-
|
|
388
|
+
.filter((id) => graphCore.hasEdge(id));
|
|
389
|
+
graphCore.removeEdges(ids);
|
|
370
390
|
}
|
|
371
391
|
}
|
|
372
392
|
/**
|
|
@@ -374,39 +394,42 @@ class DataController {
|
|
|
374
394
|
* @param data data to be updated which is part of old one
|
|
375
395
|
*/
|
|
376
396
|
updateData(dataConfig) {
|
|
377
|
-
const {
|
|
397
|
+
const { graphCore } = this;
|
|
378
398
|
const { type: dataType, data } = this.formatData(dataConfig);
|
|
379
399
|
if (!dataType)
|
|
380
400
|
return;
|
|
381
401
|
const { nodes = [], edges = [], combos = [] } = data; //this.transformData(data as GraphData);
|
|
382
402
|
const { nodes: prevNodes, edges: prevEdges, combos: prevCombos, } = (0, data_1.deconstructData)({
|
|
383
|
-
nodes:
|
|
384
|
-
edges:
|
|
403
|
+
nodes: graphCore.getAllNodes(),
|
|
404
|
+
edges: graphCore.getAllEdges(),
|
|
385
405
|
});
|
|
386
406
|
if (prevNodes.length) {
|
|
387
407
|
// update node
|
|
388
408
|
nodes.forEach((newModel) => {
|
|
389
409
|
const { id, data } = newModel;
|
|
390
410
|
if (data) {
|
|
391
|
-
const mergedData = mergeOneLevelData(
|
|
392
|
-
|
|
411
|
+
const mergedData = mergeOneLevelData(graphCore.getNode(id), newModel);
|
|
412
|
+
graphCore.mergeNodeData(id, mergedData);
|
|
413
|
+
}
|
|
414
|
+
if (data.hasOwnProperty('parentId')) {
|
|
415
|
+
graphCore.setParent(id, data.parentId, 'combo');
|
|
393
416
|
}
|
|
394
417
|
});
|
|
395
418
|
}
|
|
396
419
|
if (prevEdges.length) {
|
|
397
420
|
// update edge
|
|
398
421
|
edges.forEach((newModel) => {
|
|
399
|
-
const oldModel =
|
|
422
|
+
const oldModel = graphCore.getEdge(newModel.id);
|
|
400
423
|
if (!oldModel)
|
|
401
424
|
return;
|
|
402
425
|
const { id, source, target, data } = newModel;
|
|
403
426
|
if (source && oldModel.source !== source)
|
|
404
|
-
|
|
427
|
+
graphCore.updateEdgeSource(id, source);
|
|
405
428
|
if (target && oldModel.target !== target)
|
|
406
|
-
|
|
429
|
+
graphCore.updateEdgeTarget(id, target);
|
|
407
430
|
if (data) {
|
|
408
|
-
const mergedData = mergeOneLevelData(
|
|
409
|
-
|
|
431
|
+
const mergedData = mergeOneLevelData(graphCore.getEdge(id), newModel);
|
|
432
|
+
graphCore.mergeEdgeData(id, mergedData);
|
|
410
433
|
}
|
|
411
434
|
});
|
|
412
435
|
}
|
|
@@ -451,24 +474,27 @@ class DataController {
|
|
|
451
474
|
}
|
|
452
475
|
// update other properties
|
|
453
476
|
if (Object.keys(others).length) {
|
|
454
|
-
const mergedData = mergeOneLevelData(
|
|
477
|
+
const mergedData = mergeOneLevelData(graphCore.getNode(id), {
|
|
455
478
|
id,
|
|
456
479
|
data: others,
|
|
457
480
|
});
|
|
458
|
-
|
|
481
|
+
graphCore.mergeNodeData(id, mergedData);
|
|
482
|
+
if (others.hasOwnProperty('parentId')) {
|
|
483
|
+
graphCore.setParent(id, others.parentId, 'combo');
|
|
484
|
+
}
|
|
459
485
|
}
|
|
460
486
|
});
|
|
461
487
|
// update succeed nodes
|
|
462
488
|
modelsToMove.forEach((newModel) => {
|
|
463
489
|
const { id, data } = newModel;
|
|
464
|
-
|
|
490
|
+
graphCore.mergeNodeData(id, data);
|
|
465
491
|
});
|
|
466
492
|
}
|
|
467
493
|
if (edges === null || edges === void 0 ? void 0 : edges.filter((edge) => edge.hasOwnProperty('source') || edge.hasOwnProperty('target')).length) {
|
|
468
494
|
// convert and store tree structure to graphCore
|
|
469
495
|
this.updateTreeGraph(dataType, {
|
|
470
|
-
nodes: this.
|
|
471
|
-
edges: this.
|
|
496
|
+
nodes: this.graphCore.getAllNodes(),
|
|
497
|
+
edges: this.graphCore.getAllEdges(),
|
|
472
498
|
});
|
|
473
499
|
}
|
|
474
500
|
}
|
|
@@ -489,7 +515,7 @@ class DataController {
|
|
|
489
515
|
return;
|
|
490
516
|
}
|
|
491
517
|
return {
|
|
492
|
-
type: type || 'graphData',
|
|
518
|
+
type: type || this.dataType || 'graphData',
|
|
493
519
|
data: data,
|
|
494
520
|
};
|
|
495
521
|
}
|
|
@@ -534,12 +560,12 @@ class DataController {
|
|
|
534
560
|
}
|
|
535
561
|
});
|
|
536
562
|
// update succeed nodes
|
|
537
|
-
const {
|
|
563
|
+
const { graphCore } = this;
|
|
538
564
|
succeedNodesModels.forEach((newModel) => {
|
|
539
565
|
const { id, data } = newModel;
|
|
540
566
|
if (data) {
|
|
541
|
-
const mergedData = mergeOneLevelData(
|
|
542
|
-
|
|
567
|
+
const mergedData = mergeOneLevelData(graphCore.getNode(id), newModel);
|
|
568
|
+
graphCore.mergeNodeData(id, mergedData);
|
|
543
569
|
}
|
|
544
570
|
});
|
|
545
571
|
}
|
|
@@ -547,17 +573,20 @@ class DataController {
|
|
|
547
573
|
const { combos = [] } = data;
|
|
548
574
|
if (!(combos === null || combos === void 0 ? void 0 : combos.length))
|
|
549
575
|
return;
|
|
550
|
-
const {
|
|
576
|
+
const { graphCore } = this;
|
|
551
577
|
const { id, data: comboData } = combos[0];
|
|
552
578
|
const { _children = [] } = comboData, others = __rest(comboData, ["_children"]);
|
|
579
|
+
if (!graphCore.hasTreeStructure('combo')) {
|
|
580
|
+
graphCore.attachTreeStructure('combo');
|
|
581
|
+
}
|
|
553
582
|
// add or update combo
|
|
554
|
-
if (
|
|
583
|
+
if (graphCore.hasNode(id)) {
|
|
555
584
|
// update node which is in the graphCore
|
|
556
|
-
|
|
585
|
+
graphCore.mergeNodeData(id, Object.assign(Object.assign({}, others), { _isCombo: true }));
|
|
557
586
|
}
|
|
558
587
|
else {
|
|
559
588
|
// add node which is in data but not in graphCore
|
|
560
|
-
|
|
589
|
+
graphCore.addNode({ id, data: Object.assign(Object.assign({}, others), { _isCombo: true }) });
|
|
561
590
|
}
|
|
562
591
|
// update strucutre
|
|
563
592
|
_children.forEach((childId) => {
|
|
@@ -565,206 +594,19 @@ class DataController {
|
|
|
565
594
|
console.warn(`Adding child ${childId} to combo ${id} failed. The child ${childId} does not exist`);
|
|
566
595
|
return;
|
|
567
596
|
}
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
}
|
|
571
|
-
/**
|
|
572
|
-
* Update graphCore with transformed userGraphCore data.
|
|
573
|
-
*/
|
|
574
|
-
updateGraphCore(event) {
|
|
575
|
-
const { graphCore } = this;
|
|
576
|
-
const { nodes = [], edges = [], combos = [], } = (0, data_1.deconstructData)({
|
|
577
|
-
nodes: this.userGraphCore.getAllNodes(),
|
|
578
|
-
edges: this.userGraphCore.getAllEdges(),
|
|
579
|
-
});
|
|
580
|
-
const prevNodesAndCombos = graphCore.getAllNodes();
|
|
581
|
-
// function to update one data in graphCore with different model type ('node' or 'edge')
|
|
582
|
-
const syncUpdateToGraphCore = (id, newValue, oldValue, isNodeOrCombo, diff = []) => {
|
|
583
|
-
if (isNodeOrCombo) {
|
|
584
|
-
if (newValue.data)
|
|
585
|
-
graphCore.updateNodeData(id, Object.assign({}, newValue.data));
|
|
586
|
-
}
|
|
587
|
-
else {
|
|
588
|
-
if (diff.includes('data'))
|
|
589
|
-
graphCore.updateEdgeData(id, Object.assign({}, newValue.data));
|
|
590
|
-
// source and target may be changed
|
|
591
|
-
if (diff.includes('source'))
|
|
592
|
-
graphCore.updateEdgeSource(id, newValue.source);
|
|
593
|
-
if (diff.includes('target'))
|
|
594
|
-
graphCore.updateEdgeTarget(id, newValue.target);
|
|
595
|
-
}
|
|
596
|
-
};
|
|
597
|
-
graphCore.batch(() => {
|
|
598
|
-
// === step 3: sync to graphCore according to the changes in userGraphCore ==
|
|
599
|
-
const newModelMap = {};
|
|
600
|
-
const parentMap = {};
|
|
601
|
-
const changeMap = {};
|
|
602
|
-
const treeChanges = [];
|
|
603
|
-
event.changes.forEach((change) => {
|
|
604
|
-
var _a;
|
|
605
|
-
const id = change.id || ((_a = change.value) === null || _a === void 0 ? void 0 : _a.id);
|
|
606
|
-
if (id !== undefined) {
|
|
607
|
-
changeMap[id] = true;
|
|
608
|
-
return;
|
|
609
|
-
}
|
|
610
|
-
if ([
|
|
611
|
-
'TreeStructureAttached',
|
|
612
|
-
'TreeStructureChanged',
|
|
613
|
-
'TreeStructureChanged',
|
|
614
|
-
].includes(change.type)) {
|
|
615
|
-
treeChanges.push(change);
|
|
616
|
-
}
|
|
617
|
-
});
|
|
618
|
-
nodes.forEach((model) => {
|
|
619
|
-
newModelMap[model.id] = { type: 'node', model };
|
|
620
|
-
if (model.data.hasOwnProperty('parentId')) {
|
|
621
|
-
parentMap[model.id] = {
|
|
622
|
-
new: model.data.parentId,
|
|
623
|
-
old: undefined,
|
|
624
|
-
};
|
|
625
|
-
}
|
|
626
|
-
});
|
|
627
|
-
edges.forEach((model) => (newModelMap[model.id] = { type: 'edge', model }));
|
|
628
|
-
combos.forEach((model) => {
|
|
629
|
-
newModelMap[model.id] = { type: 'combo', model };
|
|
630
|
-
if (model.data.hasOwnProperty('parentId')) {
|
|
631
|
-
parentMap[model.id] = {
|
|
632
|
-
new: model.data.parentId,
|
|
633
|
-
old: undefined,
|
|
634
|
-
};
|
|
635
|
-
}
|
|
636
|
-
});
|
|
637
|
-
prevNodesAndCombos.forEach((prevModel) => {
|
|
638
|
-
var _a, _b;
|
|
639
|
-
const { id } = prevModel;
|
|
640
|
-
if (((_a = parentMap[id]) === null || _a === void 0 ? void 0 : _a.new) !== undefined ||
|
|
641
|
-
prevModel.data.parentId !== undefined) {
|
|
642
|
-
parentMap[id] = {
|
|
643
|
-
new: (_b = parentMap[id]) === null || _b === void 0 ? void 0 : _b.new,
|
|
644
|
-
old: prevModel.data.parentId,
|
|
645
|
-
};
|
|
646
|
-
}
|
|
647
|
-
else {
|
|
648
|
-
delete parentMap[id];
|
|
649
|
-
}
|
|
650
|
-
const { model: newModel } = newModelMap[id] || {};
|
|
651
|
-
// remove
|
|
652
|
-
if (!newModel) {
|
|
653
|
-
// remove a combo, put the children to upper parent
|
|
654
|
-
if (prevModel.data._isCombo) {
|
|
655
|
-
graphCore.getChildren(id, 'combo').forEach((child) => {
|
|
656
|
-
parentMap[child.id] = Object.assign(Object.assign({}, parentMap[child.id]), { new: prevModel.data.parentId });
|
|
657
|
-
});
|
|
658
|
-
}
|
|
659
|
-
// if it has combo parent, remove it from the parent's children list
|
|
660
|
-
if (prevModel.data.parentId) {
|
|
661
|
-
graphCore.setParent(id, undefined, 'combo');
|
|
662
|
-
}
|
|
663
|
-
// for tree graph view, show the succeed nodes and edges
|
|
664
|
-
const succeedIds = [];
|
|
665
|
-
if (graphCore.hasTreeStructure('tree')) {
|
|
666
|
-
graphCore.dfsTree(id, (child) => {
|
|
667
|
-
succeedIds.push(child.id);
|
|
668
|
-
}, 'tree');
|
|
669
|
-
const succeedEdgeIds = graphCore
|
|
670
|
-
.getAllEdges()
|
|
671
|
-
.filter(({ source, target }) => succeedIds.includes(source) && succeedIds.includes(target))
|
|
672
|
-
.map((edge) => edge.id);
|
|
673
|
-
this.graph.showItem(succeedIds
|
|
674
|
-
.filter((succeedId) => succeedId !== id)
|
|
675
|
-
.concat(succeedEdgeIds));
|
|
676
|
-
// for tree graph view, remove the node from the parent's children list
|
|
677
|
-
graphCore.setParent(id, undefined, 'tree');
|
|
678
|
-
// for tree graph view, make the its children to be roots
|
|
679
|
-
graphCore
|
|
680
|
-
.getChildren(id, 'tree')
|
|
681
|
-
.forEach((child) => graphCore.setParent(child.id, undefined, 'tree'));
|
|
682
|
-
}
|
|
683
|
-
// remove the node data
|
|
684
|
-
graphCore.removeNode(id);
|
|
685
|
-
delete parentMap[prevModel.id];
|
|
686
|
-
}
|
|
687
|
-
// update
|
|
688
|
-
// || diffAt(newModel, prevModel, true)?.length
|
|
689
|
-
else if (changeMap[id])
|
|
690
|
-
syncUpdateToGraphCore(id, newModel, prevModel, true);
|
|
691
|
-
// delete from the map indicates this model is visited
|
|
692
|
-
delete newModelMap[id];
|
|
693
|
-
});
|
|
694
|
-
graphCore.getAllEdges().forEach((prevEdge) => {
|
|
695
|
-
const { id } = prevEdge;
|
|
696
|
-
const { model: newModel } = newModelMap[id] || {};
|
|
697
|
-
// remove
|
|
698
|
-
if (!newModel)
|
|
699
|
-
graphCore.removeEdge(id);
|
|
700
|
-
// update
|
|
701
|
-
else {
|
|
702
|
-
const diff = diffAt(newModel, prevEdge, false);
|
|
703
|
-
if (diff === null || diff === void 0 ? void 0 : diff.length)
|
|
704
|
-
syncUpdateToGraphCore(id, newModel, prevEdge, false, diff);
|
|
705
|
-
}
|
|
706
|
-
// delete from the map indicates this model is visited
|
|
707
|
-
delete newModelMap[id];
|
|
708
|
-
});
|
|
709
|
-
// add
|
|
710
|
-
Object.values(newModelMap).forEach(({ type, model }) => {
|
|
711
|
-
if (type === 'node' || type === 'combo')
|
|
712
|
-
graphCore.addNode(model);
|
|
713
|
-
else if (type === 'edge')
|
|
714
|
-
graphCore.addEdge(model);
|
|
715
|
-
});
|
|
716
|
-
// update parents after adding all items
|
|
717
|
-
Object.keys(parentMap).forEach((id) => {
|
|
718
|
-
var _a;
|
|
719
|
-
if (parentMap[id].new === parentMap[id].old)
|
|
720
|
-
return;
|
|
721
|
-
if (!(0, data_1.validateComboStrucutre)(this.graph, id, parentMap[id].new)) {
|
|
722
|
-
graphCore.mergeNodeData(id, { parentId: parentMap[id].old });
|
|
723
|
-
return;
|
|
724
|
-
}
|
|
725
|
-
graphCore.mergeNodeData(id, { parentId: parentMap[id].new });
|
|
726
|
-
graphCore.setParent(id, parentMap[id].new, 'combo');
|
|
727
|
-
// after remove from parent's children list, check whether the parent is empty
|
|
728
|
-
// if so, update parent's position to be the child's
|
|
729
|
-
if (parentMap[id].old !== undefined) {
|
|
730
|
-
const parentChildren = graphCore.getChildren(parentMap[id].old, 'combo');
|
|
731
|
-
const { x = 0, y = 0, z = 0, } = ((_a = this.graph.getDisplayModel(parentMap[id].old)) === null || _a === void 0 ? void 0 : _a.data) || {};
|
|
732
|
-
if (!parentChildren.length) {
|
|
733
|
-
graphCore.mergeNodeData(parentMap[id].old, {
|
|
734
|
-
x: (0, type_1.convertToNumber)(x),
|
|
735
|
-
y: (0, type_1.convertToNumber)(y),
|
|
736
|
-
z: (0, type_1.convertToNumber)(z),
|
|
737
|
-
});
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
});
|
|
741
|
-
// update tree structure
|
|
742
|
-
treeChanges.forEach((change) => {
|
|
743
|
-
const { type, treeKey, nodeId, newParentId } = change;
|
|
744
|
-
if (type === 'TreeStructureAttached') {
|
|
745
|
-
graphCore.attachTreeStructure(treeKey);
|
|
746
|
-
return;
|
|
747
|
-
}
|
|
748
|
-
else if (type === 'TreeStructureChanged') {
|
|
749
|
-
graphCore.setParent(nodeId, newParentId, treeKey);
|
|
750
|
-
return;
|
|
751
|
-
}
|
|
752
|
-
else if (type === 'TreeStructureDetached') {
|
|
753
|
-
graphCore.detachTreeStructure(treeKey);
|
|
754
|
-
return;
|
|
755
|
-
}
|
|
756
|
-
});
|
|
597
|
+
graphCore.setParent(childId, id, 'combo');
|
|
598
|
+
graphCore.mergeNodeData(childId, { parentId: id });
|
|
757
599
|
});
|
|
758
600
|
}
|
|
759
601
|
/**
|
|
760
|
-
* Clone data from
|
|
602
|
+
* Clone data from graphCore, and run transforms
|
|
761
603
|
* @returns transformed data and the id map list
|
|
762
604
|
*/
|
|
763
605
|
transformData(data) {
|
|
764
606
|
let dataCloned = (0, util_1.clone)(data);
|
|
765
607
|
// transform the data with transform extensions, output innerData and idMaps ===
|
|
766
608
|
this.extensions.forEach(({ func, config }) => {
|
|
767
|
-
dataCloned = func(dataCloned, config, this.
|
|
609
|
+
dataCloned = func(dataCloned, config, this.graphCore);
|
|
768
610
|
});
|
|
769
611
|
return dataCloned;
|
|
770
612
|
}
|
|
@@ -774,12 +616,12 @@ class DataController {
|
|
|
774
616
|
* @param data
|
|
775
617
|
*/
|
|
776
618
|
updateTreeGraph(dataType, data) {
|
|
777
|
-
this.
|
|
619
|
+
this.graphCore.attachTreeStructure('tree');
|
|
778
620
|
if (dataType === 'treeData') {
|
|
779
621
|
// tree structure storing
|
|
780
622
|
data.edges.forEach((edge) => {
|
|
781
623
|
const { source, target } = edge;
|
|
782
|
-
this.
|
|
624
|
+
this.graphCore.setParent(target, source, 'tree');
|
|
783
625
|
});
|
|
784
626
|
}
|
|
785
627
|
else {
|