@antv/g6 5.0.0-beta.5 → 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 +15 -7
- package/esm/index.js +1 -1
- package/esm/item/combo.d.ts +1 -1
- package/esm/item/combo.js +16 -9
- package/esm/item/combo.js.map +1 -1
- package/esm/item/edge.d.ts +22 -2
- package/esm/item/edge.js +93 -42
- 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.d.ts +1 -1
- package/esm/item/node.js +22 -15
- 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.d.ts +1 -0
- package/esm/runtime/controller/item.js +21 -9
- package/esm/runtime/controller/item.js.map +1 -1
- package/esm/runtime/graph.d.ts +85 -7
- package/esm/runtime/graph.js +396 -61
- package/esm/runtime/graph.js.map +1 -1
- package/esm/stdlib/behavior/brush-select.js +1 -2
- package/esm/stdlib/behavior/brush-select.js.map +1 -1
- package/esm/stdlib/behavior/create-edge.d.ts +57 -0
- package/esm/stdlib/behavior/create-edge.js +207 -0
- package/esm/stdlib/behavior/create-edge.js.map +1 -0
- package/esm/stdlib/behavior/drag-canvas.d.ts +2 -1
- package/esm/stdlib/behavior/drag-canvas.js +26 -18
- package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
- package/esm/stdlib/behavior/drag-combo.d.ts +2 -2
- package/esm/stdlib/behavior/drag-combo.js +35 -24
- package/esm/stdlib/behavior/drag-combo.js.map +1 -1
- package/esm/stdlib/behavior/drag-node.d.ts +3 -3
- package/esm/stdlib/behavior/drag-node.js +70 -57
- package/esm/stdlib/behavior/drag-node.js.map +1 -1
- package/esm/stdlib/behavior/index.d.ts +2 -0
- package/esm/stdlib/behavior/index.js +2 -0
- package/esm/stdlib/behavior/index.js.map +1 -1
- package/esm/stdlib/behavior/lasso-select.d.ts +1 -1
- package/esm/stdlib/behavior/lasso-select.js +1 -2
- package/esm/stdlib/behavior/lasso-select.js.map +1 -1
- package/esm/stdlib/behavior/scroll-canvas.d.ts +67 -0
- package/esm/stdlib/behavior/scroll-canvas.js +266 -0
- package/esm/stdlib/behavior/scroll-canvas.js.map +1 -0
- package/esm/stdlib/behavior/zoom-canvas.d.ts +2 -1
- package/esm/stdlib/behavior/zoom-canvas.js +30 -22
- 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 +10 -6
- package/esm/stdlib/index.js +5 -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/hull/hullComponent.d.ts +1 -1
- package/esm/stdlib/plugin/hull/hullComponent.js +3 -6
- package/esm/stdlib/plugin/hull/hullComponent.js.map +1 -1
- package/esm/stdlib/plugin/minimap/index.d.ts +5 -1
- package/esm/stdlib/plugin/minimap/index.js +116 -9
- 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 +34 -8
- package/esm/types/hook.d.ts +16 -2
- package/esm/types/spec.d.ts +6 -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.d.ts +16 -1
- package/esm/util/item.js +31 -8
- 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/esm/util/warn.d.ts +14 -0
- package/esm/util/warn.js +4 -0
- package/esm/util/warn.js.map +1 -0
- package/lib/index.d.ts +15 -7
- package/lib/index.js +1 -1
- package/lib/item/combo.d.ts +1 -1
- package/lib/item/combo.js +16 -9
- package/lib/item/combo.js.map +1 -1
- package/lib/item/edge.d.ts +22 -2
- package/lib/item/edge.js +92 -41
- 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.d.ts +1 -1
- package/lib/item/node.js +22 -15
- 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.d.ts +1 -0
- package/lib/runtime/controller/item.js +21 -9
- package/lib/runtime/controller/item.js.map +1 -1
- package/lib/runtime/graph.d.ts +85 -7
- package/lib/runtime/graph.js +396 -61
- package/lib/runtime/graph.js.map +1 -1
- package/lib/stdlib/behavior/brush-select.js +1 -2
- package/lib/stdlib/behavior/brush-select.js.map +1 -1
- package/lib/stdlib/behavior/create-edge.d.ts +57 -0
- package/lib/stdlib/behavior/create-edge.js +211 -0
- package/lib/stdlib/behavior/create-edge.js.map +1 -0
- package/lib/stdlib/behavior/drag-canvas.d.ts +2 -1
- package/lib/stdlib/behavior/drag-canvas.js +26 -18
- package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
- package/lib/stdlib/behavior/drag-combo.d.ts +2 -2
- package/lib/stdlib/behavior/drag-combo.js +35 -24
- package/lib/stdlib/behavior/drag-combo.js.map +1 -1
- package/lib/stdlib/behavior/drag-node.d.ts +3 -3
- package/lib/stdlib/behavior/drag-node.js +70 -57
- package/lib/stdlib/behavior/drag-node.js.map +1 -1
- package/lib/stdlib/behavior/index.d.ts +2 -0
- package/lib/stdlib/behavior/index.js +2 -0
- package/lib/stdlib/behavior/index.js.map +1 -1
- package/lib/stdlib/behavior/lasso-select.d.ts +1 -1
- package/lib/stdlib/behavior/lasso-select.js +1 -2
- package/lib/stdlib/behavior/lasso-select.js.map +1 -1
- package/lib/stdlib/behavior/scroll-canvas.d.ts +67 -0
- package/lib/stdlib/behavior/scroll-canvas.js +270 -0
- package/lib/stdlib/behavior/scroll-canvas.js.map +1 -0
- package/lib/stdlib/behavior/zoom-canvas.d.ts +2 -1
- package/lib/stdlib/behavior/zoom-canvas.js +30 -22
- 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 +10 -6
- package/lib/stdlib/index.js +5 -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/hull/hullComponent.d.ts +1 -1
- package/lib/stdlib/plugin/hull/hullComponent.js +3 -6
- package/lib/stdlib/plugin/hull/hullComponent.js.map +1 -1
- package/lib/stdlib/plugin/minimap/index.d.ts +5 -1
- package/lib/stdlib/plugin/minimap/index.js +116 -9
- 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 +34 -8
- package/lib/types/hook.d.ts +16 -2
- package/lib/types/spec.d.ts +6 -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.d.ts +16 -1
- package/lib/util/item.js +33 -9
- 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/lib/util/warn.d.ts +14 -0
- package/lib/util/warn.js +8 -0
- package/lib/util/warn.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/item/combo.ts +14 -9
- package/src/item/edge.ts +121 -55
- package/src/item/item.ts +13 -9
- package/src/item/node.ts +20 -15
- package/src/runtime/controller/data.ts +139 -339
- package/src/runtime/controller/item.ts +30 -12
- package/src/runtime/graph.ts +502 -67
- package/src/stdlib/behavior/brush-select.ts +4 -2
- package/src/stdlib/behavior/create-edge.ts +296 -0
- package/src/stdlib/behavior/drag-canvas.ts +30 -19
- package/src/stdlib/behavior/drag-combo.ts +2 -2
- package/src/stdlib/behavior/drag-node.ts +8 -8
- package/src/stdlib/behavior/index.ts +2 -0
- package/src/stdlib/behavior/lasso-select.ts +5 -3
- package/src/stdlib/behavior/scroll-canvas.ts +348 -0
- package/src/stdlib/behavior/zoom-canvas.ts +34 -23
- 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 +6 -0
- package/src/stdlib/item/edge/base.ts +4 -8
- package/src/stdlib/plugin/hull/hullComponent.ts +8 -5
- package/src/stdlib/plugin/minimap/index.ts +120 -10
- package/src/stdlib/plugin/snapline/index.ts +36 -16
- package/src/types/graph.ts +37 -8
- package/src/types/hook.ts +16 -2
- package/src/types/spec.ts +9 -3
- package/src/types/view.ts +8 -3
- package/src/util/event.ts +14 -1
- package/src/util/item.ts +65 -28
- package/src/util/layout.ts +45 -0
- package/src/util/point.ts +4 -2
- package/src/util/shape.ts +6 -7
- package/src/util/warn.ts +20 -0
|
@@ -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 {
|
|
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 (
|
|
154
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
191
|
+
this.establishGraphCoreTree();
|
|
193
192
|
}
|
|
194
193
|
}
|
|
195
|
-
|
|
194
|
+
establishGraphCoreTree() {
|
|
196
195
|
if (!this.treeDirtyFlag)
|
|
197
196
|
return;
|
|
198
|
-
const nodes = this.
|
|
199
|
-
const edges = this.
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
(
|
|
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 {
|
|
258
|
+
const { graphCore } = this;
|
|
269
259
|
const prevData = deconstructData({
|
|
270
|
-
nodes:
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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 (
|
|
283
|
+
if (graphCore.hasNode(item.id)) {
|
|
293
284
|
// update node which is in the graphCore
|
|
294
|
-
|
|
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
|
-
|
|
289
|
+
graphCore.addNode(item);
|
|
299
290
|
}
|
|
300
291
|
});
|
|
301
292
|
}
|
|
302
293
|
// =========== edge ============
|
|
303
|
-
prevData.edges =
|
|
294
|
+
prevData.edges = graphCore.getAllEdges();
|
|
304
295
|
if (!prevData.edges.length) {
|
|
305
|
-
|
|
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
|
|
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
|
-
|
|
304
|
+
graphCore.removeEdge(prevEdge.id);
|
|
314
305
|
});
|
|
315
306
|
}
|
|
316
307
|
// add or update edge
|
|
317
308
|
edges.forEach((edge) => {
|
|
318
|
-
if (
|
|
309
|
+
if (graphCore.hasEdge(edge.id)) {
|
|
319
310
|
// update edge which is in the graphCore
|
|
320
|
-
|
|
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
|
-
|
|
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 {
|
|
321
|
+
const { graphCore } = this;
|
|
331
322
|
// convert and store tree structure to graphCore
|
|
332
323
|
this.updateTreeGraph(dataType, {
|
|
333
|
-
nodes:
|
|
334
|
-
edges:
|
|
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 {
|
|
368
|
+
const { graphCore } = this;
|
|
344
369
|
const { nodes = [], edges = [], combos = [] } = data;
|
|
345
370
|
const nodesAndCombos = nodes.concat(combos);
|
|
346
|
-
const prevNodesAndCombos =
|
|
347
|
-
const prevEdges =
|
|
371
|
+
const prevNodesAndCombos = graphCore.getAllNodes();
|
|
372
|
+
const prevEdges = graphCore.getAllEdges();
|
|
348
373
|
if (prevNodesAndCombos.length && nodesAndCombos.length) {
|
|
349
|
-
// update
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
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
|
-
|
|
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) =>
|
|
366
|
-
|
|
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 {
|
|
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:
|
|
381
|
-
edges:
|
|
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(
|
|
389
|
-
|
|
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 =
|
|
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
|
-
|
|
424
|
+
graphCore.updateEdgeSource(id, source);
|
|
402
425
|
if (target && oldModel.target !== target)
|
|
403
|
-
|
|
426
|
+
graphCore.updateEdgeTarget(id, target);
|
|
404
427
|
if (data) {
|
|
405
|
-
const mergedData = mergeOneLevelData(
|
|
406
|
-
|
|
428
|
+
const mergedData = mergeOneLevelData(graphCore.getEdge(id), newModel);
|
|
429
|
+
graphCore.mergeEdgeData(id, mergedData);
|
|
407
430
|
}
|
|
408
431
|
});
|
|
409
432
|
}
|
|
@@ -448,24 +471,27 @@ export class DataController {
|
|
|
448
471
|
}
|
|
449
472
|
// update other properties
|
|
450
473
|
if (Object.keys(others).length) {
|
|
451
|
-
const mergedData = mergeOneLevelData(
|
|
474
|
+
const mergedData = mergeOneLevelData(graphCore.getNode(id), {
|
|
452
475
|
id,
|
|
453
476
|
data: others,
|
|
454
477
|
});
|
|
455
|
-
|
|
478
|
+
graphCore.mergeNodeData(id, mergedData);
|
|
479
|
+
if (others.hasOwnProperty('parentId')) {
|
|
480
|
+
graphCore.setParent(id, others.parentId, 'combo');
|
|
481
|
+
}
|
|
456
482
|
}
|
|
457
483
|
});
|
|
458
484
|
// update succeed nodes
|
|
459
485
|
modelsToMove.forEach((newModel) => {
|
|
460
486
|
const { id, data } = newModel;
|
|
461
|
-
|
|
487
|
+
graphCore.mergeNodeData(id, data);
|
|
462
488
|
});
|
|
463
489
|
}
|
|
464
490
|
if (edges === null || edges === void 0 ? void 0 : edges.filter((edge) => edge.hasOwnProperty('source') || edge.hasOwnProperty('target')).length) {
|
|
465
491
|
// convert and store tree structure to graphCore
|
|
466
492
|
this.updateTreeGraph(dataType, {
|
|
467
|
-
nodes: this.
|
|
468
|
-
edges: this.
|
|
493
|
+
nodes: this.graphCore.getAllNodes(),
|
|
494
|
+
edges: this.graphCore.getAllEdges(),
|
|
469
495
|
});
|
|
470
496
|
}
|
|
471
497
|
}
|
|
@@ -486,7 +512,7 @@ export class DataController {
|
|
|
486
512
|
return;
|
|
487
513
|
}
|
|
488
514
|
return {
|
|
489
|
-
type: type || 'graphData',
|
|
515
|
+
type: type || this.dataType || 'graphData',
|
|
490
516
|
data: data,
|
|
491
517
|
};
|
|
492
518
|
}
|
|
@@ -531,12 +557,12 @@ export class DataController {
|
|
|
531
557
|
}
|
|
532
558
|
});
|
|
533
559
|
// update succeed nodes
|
|
534
|
-
const {
|
|
560
|
+
const { graphCore } = this;
|
|
535
561
|
succeedNodesModels.forEach((newModel) => {
|
|
536
562
|
const { id, data } = newModel;
|
|
537
563
|
if (data) {
|
|
538
|
-
const mergedData = mergeOneLevelData(
|
|
539
|
-
|
|
564
|
+
const mergedData = mergeOneLevelData(graphCore.getNode(id), newModel);
|
|
565
|
+
graphCore.mergeNodeData(id, mergedData);
|
|
540
566
|
}
|
|
541
567
|
});
|
|
542
568
|
}
|
|
@@ -544,17 +570,20 @@ export class DataController {
|
|
|
544
570
|
const { combos = [] } = data;
|
|
545
571
|
if (!(combos === null || combos === void 0 ? void 0 : combos.length))
|
|
546
572
|
return;
|
|
547
|
-
const {
|
|
573
|
+
const { graphCore } = this;
|
|
548
574
|
const { id, data: comboData } = combos[0];
|
|
549
575
|
const { _children = [] } = comboData, others = __rest(comboData, ["_children"]);
|
|
576
|
+
if (!graphCore.hasTreeStructure('combo')) {
|
|
577
|
+
graphCore.attachTreeStructure('combo');
|
|
578
|
+
}
|
|
550
579
|
// add or update combo
|
|
551
|
-
if (
|
|
580
|
+
if (graphCore.hasNode(id)) {
|
|
552
581
|
// update node which is in the graphCore
|
|
553
|
-
|
|
582
|
+
graphCore.mergeNodeData(id, Object.assign(Object.assign({}, others), { _isCombo: true }));
|
|
554
583
|
}
|
|
555
584
|
else {
|
|
556
585
|
// add node which is in data but not in graphCore
|
|
557
|
-
|
|
586
|
+
graphCore.addNode({ id, data: Object.assign(Object.assign({}, others), { _isCombo: true }) });
|
|
558
587
|
}
|
|
559
588
|
// update strucutre
|
|
560
589
|
_children.forEach((childId) => {
|
|
@@ -562,206 +591,19 @@ export class DataController {
|
|
|
562
591
|
console.warn(`Adding child ${childId} to combo ${id} failed. The child ${childId} does not exist`);
|
|
563
592
|
return;
|
|
564
593
|
}
|
|
565
|
-
|
|
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
|
-
});
|
|
594
|
+
graphCore.setParent(childId, id, 'combo');
|
|
595
|
+
graphCore.mergeNodeData(childId, { parentId: id });
|
|
754
596
|
});
|
|
755
597
|
}
|
|
756
598
|
/**
|
|
757
|
-
* Clone data from
|
|
599
|
+
* Clone data from graphCore, and run transforms
|
|
758
600
|
* @returns transformed data and the id map list
|
|
759
601
|
*/
|
|
760
602
|
transformData(data) {
|
|
761
603
|
let dataCloned = clone(data);
|
|
762
604
|
// transform the data with transform extensions, output innerData and idMaps ===
|
|
763
605
|
this.extensions.forEach(({ func, config }) => {
|
|
764
|
-
dataCloned = func(dataCloned, config, this.
|
|
606
|
+
dataCloned = func(dataCloned, config, this.graphCore);
|
|
765
607
|
});
|
|
766
608
|
return dataCloned;
|
|
767
609
|
}
|
|
@@ -771,12 +613,12 @@ export class DataController {
|
|
|
771
613
|
* @param data
|
|
772
614
|
*/
|
|
773
615
|
updateTreeGraph(dataType, data) {
|
|
774
|
-
this.
|
|
616
|
+
this.graphCore.attachTreeStructure('tree');
|
|
775
617
|
if (dataType === 'treeData') {
|
|
776
618
|
// tree structure storing
|
|
777
619
|
data.edges.forEach((edge) => {
|
|
778
620
|
const { source, target } = edge;
|
|
779
|
-
this.
|
|
621
|
+
this.graphCore.setParent(target, source, 'tree');
|
|
780
622
|
});
|
|
781
623
|
}
|
|
782
624
|
else {
|