@antv/g6 5.0.0-alpha.7 → 5.0.0-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/g6.min.js +6 -19
- package/esm/index.d.ts +26 -6
- package/esm/item/combo.d.ts +72 -2
- package/esm/item/combo.js +122 -2
- package/esm/item/combo.js.map +1 -1
- package/esm/item/edge.d.ts +3 -3
- package/esm/item/edge.js +4 -5
- package/esm/item/edge.js.map +1 -1
- package/esm/item/item.d.ts +4 -4
- package/esm/item/item.js +38 -9
- package/esm/item/item.js.map +1 -1
- package/esm/item/node.d.ts +20 -16
- package/esm/item/node.js +14 -8
- package/esm/item/node.js.map +1 -1
- package/esm/runtime/controller/data.d.ts +12 -4
- package/esm/runtime/controller/data.js +354 -62
- package/esm/runtime/controller/data.js.map +1 -1
- package/esm/runtime/controller/interaction.js +16 -4
- package/esm/runtime/controller/interaction.js.map +1 -1
- package/esm/runtime/controller/item.d.ts +11 -2
- package/esm/runtime/controller/item.js +344 -52
- package/esm/runtime/controller/item.js.map +1 -1
- package/esm/runtime/controller/layout.js +19 -5
- package/esm/runtime/controller/layout.js.map +1 -1
- package/esm/runtime/graph.d.ts +54 -17
- package/esm/runtime/graph.js +165 -34
- package/esm/runtime/graph.js.map +1 -1
- package/esm/stdlib/behavior/click-select.d.ts +3 -0
- package/esm/stdlib/behavior/click-select.js +13 -1
- package/esm/stdlib/behavior/click-select.js.map +1 -1
- package/esm/stdlib/behavior/collapse-expand-combo.d.ts +29 -0
- package/esm/stdlib/behavior/collapse-expand-combo.js +35 -0
- package/esm/stdlib/behavior/collapse-expand-combo.js.map +1 -0
- package/esm/stdlib/behavior/drag-combo.d.ts +99 -0
- package/esm/stdlib/behavior/drag-combo.js +341 -0
- package/esm/stdlib/behavior/drag-combo.js.map +1 -0
- package/esm/stdlib/behavior/drag-node.d.ts +14 -10
- package/esm/stdlib/behavior/drag-node.js +134 -37
- package/esm/stdlib/behavior/drag-node.js.map +1 -1
- package/esm/stdlib/behavior/hover-activate.d.ts +3 -1
- package/esm/stdlib/behavior/hover-activate.js +3 -1
- package/esm/stdlib/behavior/hover-activate.js.map +1 -1
- package/esm/stdlib/behavior/orbit-canvas-3d.js +1 -1
- package/esm/stdlib/behavior/orbit-canvas-3d.js.map +1 -1
- package/esm/stdlib/behavior/track-canvas-3d.js +1 -1
- package/esm/stdlib/behavior/track-canvas-3d.js.map +1 -1
- package/esm/stdlib/index.d.ts +25 -3
- package/esm/stdlib/index.js +25 -3
- package/esm/stdlib/index.js.map +1 -1
- package/esm/stdlib/item/combo/circle.d.ts +29 -0
- package/esm/stdlib/item/combo/circle.js +56 -0
- package/esm/stdlib/item/combo/circle.js.map +1 -0
- package/esm/stdlib/item/edge/base.d.ts +2 -2
- package/esm/stdlib/item/edge/base.js +3 -0
- package/esm/stdlib/item/edge/base.js.map +1 -1
- package/esm/stdlib/item/edge/cubic-horizon.d.ts +37 -0
- package/esm/stdlib/item/edge/cubic-horizon.js +71 -0
- package/esm/stdlib/item/edge/cubic-horizon.js.map +1 -0
- package/esm/stdlib/item/edge/cubic-vertical.d.ts +37 -0
- package/esm/stdlib/item/edge/cubic-vertical.js +71 -0
- package/esm/stdlib/item/edge/cubic-vertical.js.map +1 -0
- package/esm/stdlib/item/edge/cubic.d.ts +60 -0
- package/esm/stdlib/item/edge/cubic.js +99 -0
- package/esm/stdlib/item/edge/cubic.js.map +1 -0
- package/esm/stdlib/item/edge/index.d.ts +1 -0
- package/esm/stdlib/item/edge/index.js +1 -0
- package/esm/stdlib/item/edge/index.js.map +1 -1
- package/esm/stdlib/item/edge/line.d.ts +1 -1
- package/esm/stdlib/item/edge/quadratic.d.ts +41 -0
- package/esm/stdlib/item/edge/quadratic.js +66 -0
- package/esm/stdlib/item/edge/quadratic.js.map +1 -0
- package/esm/stdlib/item/node/base.d.ts +38 -37
- package/esm/stdlib/item/node/base.js +4 -4
- package/esm/stdlib/item/node/base.js.map +1 -1
- package/esm/stdlib/item/node/base3d.d.ts +1 -0
- package/esm/stdlib/item/node/base3d.js +1 -0
- package/esm/stdlib/item/node/base3d.js.map +1 -1
- package/esm/stdlib/item/node/index.d.ts +1 -0
- package/esm/stdlib/item/node/index.js +1 -0
- package/esm/stdlib/item/node/index.js.map +1 -1
- package/esm/stdlib/item/node/rect.d.ts +31 -0
- package/esm/stdlib/item/node/rect.js +59 -0
- package/esm/stdlib/item/node/rect.js.map +1 -0
- package/esm/stdlib/plugin/fisheye/index.d.ts +102 -0
- package/esm/stdlib/plugin/fisheye/index.js +487 -0
- package/esm/stdlib/plugin/fisheye/index.js.map +1 -0
- package/esm/stdlib/plugin/menu/index.d.ts +42 -0
- package/esm/stdlib/plugin/menu/index.js +236 -0
- package/esm/stdlib/plugin/menu/index.js.map +1 -0
- package/esm/stdlib/plugin/tooltip/index.d.ts +75 -0
- package/esm/stdlib/plugin/tooltip/index.js +377 -0
- package/esm/stdlib/plugin/tooltip/index.js.map +1 -0
- package/esm/stdlib/theme/dark.js +4 -0
- package/esm/stdlib/theme/dark.js.map +1 -1
- package/esm/stdlib/theme/light.js +54 -9
- package/esm/stdlib/theme/light.js.map +1 -1
- package/esm/types/combo.d.ts +52 -3
- package/esm/types/data.d.ts +4 -4
- package/esm/types/edge.d.ts +2 -3
- package/esm/types/event.d.ts +9 -1
- package/esm/types/event.js +8 -8
- package/esm/types/event.js.map +1 -1
- package/esm/types/graph.d.ts +49 -13
- package/esm/types/hook.d.ts +8 -1
- package/esm/types/item.d.ts +4 -4
- package/esm/types/node.d.ts +4 -5
- package/esm/types/theme.d.ts +1 -1
- package/esm/util/animate.js.map +1 -1
- package/esm/util/canvas.js +8 -0
- package/esm/util/canvas.js.map +1 -1
- package/esm/util/data.d.ts +65 -0
- package/esm/util/data.js +150 -0
- package/esm/util/data.js.map +1 -0
- package/esm/util/event.d.ts +8 -0
- package/esm/util/event.js +16 -0
- package/esm/util/event.js.map +1 -1
- package/esm/util/item.d.ts +2 -1
- package/esm/util/item.js +36 -13
- package/esm/util/item.js.map +1 -1
- package/esm/util/shape.d.ts +39 -4
- package/esm/util/shape.js +101 -1
- package/esm/util/shape.js.map +1 -1
- package/esm/util/zoom.d.ts +2 -2
- package/lib/index.d.ts +26 -6
- package/lib/item/combo.d.ts +72 -2
- package/lib/item/combo.js +122 -2
- package/lib/item/combo.js.map +1 -1
- package/lib/item/edge.d.ts +3 -3
- package/lib/item/edge.js +4 -5
- package/lib/item/edge.js.map +1 -1
- package/lib/item/item.d.ts +4 -4
- package/lib/item/item.js +37 -8
- package/lib/item/item.js.map +1 -1
- package/lib/item/node.d.ts +20 -16
- package/lib/item/node.js +14 -8
- package/lib/item/node.js.map +1 -1
- package/lib/runtime/controller/data.d.ts +12 -4
- package/lib/runtime/controller/data.js +353 -61
- package/lib/runtime/controller/data.js.map +1 -1
- package/lib/runtime/controller/interaction.js +15 -3
- package/lib/runtime/controller/interaction.js.map +1 -1
- package/lib/runtime/controller/item.d.ts +11 -2
- package/lib/runtime/controller/item.js +342 -50
- package/lib/runtime/controller/item.js.map +1 -1
- package/lib/runtime/controller/layout.js +19 -5
- package/lib/runtime/controller/layout.js.map +1 -1
- package/lib/runtime/graph.d.ts +54 -17
- package/lib/runtime/graph.js +165 -34
- package/lib/runtime/graph.js.map +1 -1
- package/lib/stdlib/behavior/click-select.d.ts +3 -0
- package/lib/stdlib/behavior/click-select.js +13 -1
- package/lib/stdlib/behavior/click-select.js.map +1 -1
- package/lib/stdlib/behavior/collapse-expand-combo.d.ts +29 -0
- package/lib/stdlib/behavior/collapse-expand-combo.js +38 -0
- package/lib/stdlib/behavior/collapse-expand-combo.js.map +1 -0
- package/lib/stdlib/behavior/drag-combo.d.ts +99 -0
- package/lib/stdlib/behavior/drag-combo.js +344 -0
- package/lib/stdlib/behavior/drag-combo.js.map +1 -0
- package/lib/stdlib/behavior/drag-node.d.ts +14 -10
- package/lib/stdlib/behavior/drag-node.js +134 -37
- package/lib/stdlib/behavior/drag-node.js.map +1 -1
- package/lib/stdlib/behavior/hover-activate.d.ts +3 -1
- package/lib/stdlib/behavior/hover-activate.js +3 -2
- package/lib/stdlib/behavior/hover-activate.js.map +1 -1
- package/lib/stdlib/behavior/orbit-canvas-3d.js +1 -1
- package/lib/stdlib/behavior/orbit-canvas-3d.js.map +1 -1
- package/lib/stdlib/behavior/track-canvas-3d.js +1 -1
- package/lib/stdlib/behavior/track-canvas-3d.js.map +1 -1
- package/lib/stdlib/index.d.ts +25 -3
- package/lib/stdlib/index.js +25 -3
- package/lib/stdlib/index.js.map +1 -1
- package/lib/stdlib/item/combo/circle.d.ts +29 -0
- package/lib/stdlib/item/combo/circle.js +60 -0
- package/lib/stdlib/item/combo/circle.js.map +1 -0
- package/lib/stdlib/item/edge/base.d.ts +2 -2
- package/lib/stdlib/item/edge/base.js +3 -0
- package/lib/stdlib/item/edge/base.js.map +1 -1
- package/lib/stdlib/item/edge/cubic-horizon.d.ts +37 -0
- package/lib/stdlib/item/edge/cubic-horizon.js +75 -0
- package/lib/stdlib/item/edge/cubic-horizon.js.map +1 -0
- package/lib/stdlib/item/edge/cubic-vertical.d.ts +37 -0
- package/lib/stdlib/item/edge/cubic-vertical.js +75 -0
- package/lib/stdlib/item/edge/cubic-vertical.js.map +1 -0
- package/lib/stdlib/item/edge/cubic.d.ts +60 -0
- package/lib/stdlib/item/edge/cubic.js +103 -0
- package/lib/stdlib/item/edge/cubic.js.map +1 -0
- package/lib/stdlib/item/edge/index.d.ts +1 -0
- package/lib/stdlib/item/edge/index.js +1 -0
- package/lib/stdlib/item/edge/index.js.map +1 -1
- package/lib/stdlib/item/edge/line.d.ts +1 -1
- package/lib/stdlib/item/edge/quadratic.d.ts +41 -0
- package/lib/stdlib/item/edge/quadratic.js +70 -0
- package/lib/stdlib/item/edge/quadratic.js.map +1 -0
- package/lib/stdlib/item/node/base.d.ts +38 -37
- package/lib/stdlib/item/node/base.js +4 -4
- package/lib/stdlib/item/node/base.js.map +1 -1
- package/lib/stdlib/item/node/base3d.d.ts +1 -0
- package/lib/stdlib/item/node/base3d.js +1 -0
- package/lib/stdlib/item/node/base3d.js.map +1 -1
- package/lib/stdlib/item/node/index.d.ts +1 -0
- package/lib/stdlib/item/node/index.js +1 -0
- package/lib/stdlib/item/node/index.js.map +1 -1
- package/lib/stdlib/item/node/rect.d.ts +31 -0
- package/lib/stdlib/item/node/rect.js +63 -0
- package/lib/stdlib/item/node/rect.js.map +1 -0
- package/lib/stdlib/plugin/fisheye/index.d.ts +102 -0
- package/lib/stdlib/plugin/fisheye/index.js +490 -0
- package/lib/stdlib/plugin/fisheye/index.js.map +1 -0
- package/lib/stdlib/plugin/menu/index.d.ts +42 -0
- package/lib/stdlib/plugin/menu/index.js +242 -0
- package/lib/stdlib/plugin/menu/index.js.map +1 -0
- package/lib/stdlib/plugin/tooltip/index.d.ts +75 -0
- package/lib/stdlib/plugin/tooltip/index.js +383 -0
- package/lib/stdlib/plugin/tooltip/index.js.map +1 -0
- package/lib/stdlib/theme/dark.js +4 -0
- package/lib/stdlib/theme/dark.js.map +1 -1
- package/lib/stdlib/theme/light.js +54 -9
- package/lib/stdlib/theme/light.js.map +1 -1
- package/lib/types/combo.d.ts +52 -3
- package/lib/types/data.d.ts +4 -4
- package/lib/types/edge.d.ts +2 -3
- package/lib/types/event.d.ts +9 -1
- package/lib/types/event.js +10 -10
- package/lib/types/event.js.map +1 -1
- package/lib/types/graph.d.ts +49 -13
- package/lib/types/hook.d.ts +8 -1
- package/lib/types/item.d.ts +4 -4
- package/lib/types/item.js +1 -1
- package/lib/types/item.js.map +1 -1
- package/lib/types/node.d.ts +4 -5
- package/lib/types/theme.d.ts +1 -1
- package/lib/util/animate.js.map +1 -1
- package/lib/util/canvas.js +8 -0
- package/lib/util/canvas.js.map +1 -1
- package/lib/util/data.d.ts +65 -0
- package/lib/util/data.js +161 -0
- package/lib/util/data.js.map +1 -0
- package/lib/util/event.d.ts +8 -0
- package/lib/util/event.js +18 -1
- package/lib/util/event.js.map +1 -1
- package/lib/util/item.d.ts +2 -1
- package/lib/util/item.js +36 -13
- package/lib/util/item.js.map +1 -1
- package/lib/util/shape.d.ts +39 -4
- package/lib/util/shape.js +105 -2
- package/lib/util/shape.js.map +1 -1
- package/lib/util/zoom.d.ts +2 -2
- package/package.json +15 -18
- package/src/item/combo.ts +220 -2
- package/src/item/edge.ts +7 -8
- package/src/item/item.ts +58 -15
- package/src/item/node.ts +47 -24
- package/src/runtime/controller/data.ts +390 -68
- package/src/runtime/controller/interaction.ts +23 -3
- package/src/runtime/controller/item.ts +444 -64
- package/src/runtime/controller/layout.ts +24 -5
- package/src/runtime/graph.ts +225 -38
- package/src/stdlib/behavior/click-select.ts +15 -2
- package/src/stdlib/behavior/collapse-expand-combo.ts +59 -0
- package/src/stdlib/behavior/drag-combo.ts +533 -0
- package/src/stdlib/behavior/drag-node.ts +195 -62
- package/src/stdlib/behavior/hover-activate.ts +4 -5
- package/src/stdlib/behavior/orbit-canvas-3d.ts +1 -1
- package/src/stdlib/behavior/track-canvas-3d.ts +1 -1
- package/src/stdlib/index.ts +25 -3
- package/src/stdlib/item/combo/circle.ts +113 -0
- package/src/stdlib/item/edge/base.ts +5 -2
- package/src/stdlib/item/edge/cubic-horizon.ts +114 -0
- package/src/stdlib/item/edge/cubic-vertical.ts +116 -0
- package/src/stdlib/item/edge/cubic.ts +198 -0
- package/src/stdlib/item/edge/index.ts +1 -0
- package/src/stdlib/item/edge/quadratic.ts +136 -0
- package/src/stdlib/item/node/base.ts +79 -41
- package/src/stdlib/item/node/base3d.ts +2 -0
- package/src/stdlib/item/node/index.ts +1 -0
- package/src/stdlib/item/node/rect.ts +124 -0
- package/src/stdlib/plugin/fisheye/index.ts +578 -0
- package/src/stdlib/plugin/menu/index.ts +260 -0
- package/src/stdlib/plugin/tooltip/index.ts +424 -0
- package/src/stdlib/theme/dark.ts +4 -0
- package/src/stdlib/theme/light.ts +77 -9
- package/src/types/combo.ts +61 -3
- package/src/types/data.ts +6 -4
- package/src/types/edge.ts +2 -2
- package/src/types/event.ts +8 -8
- package/src/types/graph.ts +73 -16
- package/src/types/hook.ts +8 -1
- package/src/types/item.ts +10 -9
- package/src/types/node.ts +4 -4
- package/src/types/theme.ts +1 -1
- package/src/util/animate.ts +2 -3
- package/src/util/canvas.ts +10 -0
- package/src/util/data.ts +178 -0
- package/src/util/event.ts +29 -0
- package/src/util/item.ts +75 -12
- package/src/util/shape.ts +142 -5
- package/src/util/zoom.ts +2 -2
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { AABB, Canvas, DisplayObject, Group } from '@antv/g';
|
|
2
|
-
import { GraphChange, ID } from '@antv/graphlib';
|
|
3
|
-
import {
|
|
2
|
+
import { GraphChange, GraphView, ID } from '@antv/graphlib';
|
|
3
|
+
import {
|
|
4
|
+
debounce,
|
|
5
|
+
isArray,
|
|
6
|
+
isObject,
|
|
7
|
+
throttle,
|
|
8
|
+
uniq,
|
|
9
|
+
uniqueId,
|
|
10
|
+
} from '@antv/util';
|
|
11
|
+
import { DirectionalLight, AmbientLight } from '@antv/g-plugin-3d';
|
|
4
12
|
import registry from '../../stdlib';
|
|
5
13
|
import {
|
|
6
14
|
ComboModel,
|
|
@@ -21,14 +29,14 @@ import {
|
|
|
21
29
|
import Node from '../../item/node';
|
|
22
30
|
import Edge from '../../item/edge';
|
|
23
31
|
import Combo from '../../item/combo';
|
|
24
|
-
import { upsertShape } from '../../util/shape';
|
|
32
|
+
import { getCombinedBoundsByData, upsertShape } from '../../util/shape';
|
|
25
33
|
import { getExtension } from '../../util/extension';
|
|
26
34
|
import { upsertTransientItem } from '../../util/item';
|
|
27
35
|
import {
|
|
28
36
|
ITEM_TYPE,
|
|
29
37
|
ShapeStyle,
|
|
30
38
|
SHAPE_TYPE,
|
|
31
|
-
|
|
39
|
+
LodStrategyObj,
|
|
32
40
|
} from '../../types/item';
|
|
33
41
|
import {
|
|
34
42
|
ThemeSpecification,
|
|
@@ -36,10 +44,19 @@ import {
|
|
|
36
44
|
EdgeThemeSpecifications,
|
|
37
45
|
NodeStyleSet,
|
|
38
46
|
EdgeStyleSet,
|
|
47
|
+
ComboThemeSpecifications,
|
|
48
|
+
ComboStyleSet,
|
|
39
49
|
} from '../../types/theme';
|
|
40
|
-
import { DirectionalLight, AmbientLight } from '@antv/g-plugin-3d';
|
|
41
50
|
import { ViewportChangeHookParams } from '../../types/hook';
|
|
42
51
|
import { formatLodStrategy } from '../../util/zoom';
|
|
52
|
+
import {
|
|
53
|
+
deconstructData,
|
|
54
|
+
graphComboTreeDfs,
|
|
55
|
+
graphCoreTreeDfs,
|
|
56
|
+
traverseAncestors,
|
|
57
|
+
traverseAncestorsAndSucceeds,
|
|
58
|
+
traverseGraphAncestors,
|
|
59
|
+
} from '../../util/data';
|
|
43
60
|
|
|
44
61
|
/**
|
|
45
62
|
* Manages and stores the node / edge / combo items.
|
|
@@ -76,14 +93,17 @@ export class ItemController {
|
|
|
76
93
|
| ComboEncode;
|
|
77
94
|
};
|
|
78
95
|
|
|
96
|
+
// if the graph has combos, nodeGroup/edgeGroup/comboGroup point to the same group, so as transient groups.
|
|
79
97
|
private nodeGroup: Group;
|
|
80
98
|
private edgeGroup: Group;
|
|
99
|
+
private comboGroup: Group;
|
|
81
100
|
private transientNodeGroup: Group;
|
|
82
101
|
private transientEdgeGroup: Group;
|
|
83
|
-
|
|
102
|
+
private transientComboGroup: Group;
|
|
84
103
|
|
|
85
104
|
private nodeDataTypeSet: Set<string> = new Set();
|
|
86
105
|
private edgeDataTypeSet: Set<string> = new Set();
|
|
106
|
+
private comboDataTypeSet: Set<string> = new Set();
|
|
87
107
|
|
|
88
108
|
// The G shapes or groups on transient map drawn by this controller
|
|
89
109
|
private transientObjectMap: {
|
|
@@ -93,6 +113,8 @@ export class ItemController {
|
|
|
93
113
|
[id: string]: Node | Edge | Combo | Group;
|
|
94
114
|
} = {};
|
|
95
115
|
|
|
116
|
+
// private comboTreeView: GraphView<any, any>;
|
|
117
|
+
|
|
96
118
|
constructor(graph: IGraph<any, any>) {
|
|
97
119
|
this.graph = graph;
|
|
98
120
|
// get mapper for node / edge / combo
|
|
@@ -123,6 +145,7 @@ export class ItemController {
|
|
|
123
145
|
this.graph.hooks.itemvisibilitychange.tap(
|
|
124
146
|
this.onItemVisibilityChange.bind(this),
|
|
125
147
|
);
|
|
148
|
+
this.graph.hooks.itemzindexchange.tap(this.onItemZIndexChange.bind(this));
|
|
126
149
|
this.graph.hooks.transientupdate.tap(this.onTransientUpdate.bind(this));
|
|
127
150
|
this.graph.hooks.viewportchange.tap(this.onViewportChange.bind(this));
|
|
128
151
|
this.graph.hooks.themechange.tap(this.onThemeChange.bind(this));
|
|
@@ -166,17 +189,22 @@ export class ItemController {
|
|
|
166
189
|
|
|
167
190
|
// 0. clear groups on canvas, and create new groups
|
|
168
191
|
graph.canvas.removeChildren();
|
|
192
|
+
const comboGroup = new Group({ id: 'combo-group' });
|
|
169
193
|
const edgeGroup = new Group({ id: 'edge-group' });
|
|
170
194
|
const nodeGroup = new Group({ id: 'node-group' });
|
|
195
|
+
graph.canvas.appendChild(comboGroup);
|
|
171
196
|
graph.canvas.appendChild(edgeGroup);
|
|
172
197
|
graph.canvas.appendChild(nodeGroup);
|
|
173
198
|
this.nodeGroup = nodeGroup;
|
|
174
199
|
this.edgeGroup = edgeGroup;
|
|
200
|
+
this.comboGroup = comboGroup;
|
|
175
201
|
|
|
176
202
|
// Also create transient groups on transient canvas.
|
|
177
203
|
transientCanvas.removeChildren();
|
|
204
|
+
this.transientComboGroup = new Group({ id: 'combo-group' });
|
|
178
205
|
this.transientEdgeGroup = new Group({ id: 'edge-group' });
|
|
179
206
|
this.transientNodeGroup = new Group({ id: 'node-group' });
|
|
207
|
+
transientCanvas.appendChild(this.transientComboGroup);
|
|
180
208
|
transientCanvas.appendChild(this.transientEdgeGroup);
|
|
181
209
|
transientCanvas.appendChild(this.transientNodeGroup);
|
|
182
210
|
|
|
@@ -202,13 +230,25 @@ export class ItemController {
|
|
|
202
230
|
}
|
|
203
231
|
|
|
204
232
|
// 2. create node / edge / combo items, classes from ../../item, and element drawing and updating fns from node/edge/comboExtensions
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
233
|
+
const { nodes, edges, combos } = deconstructData({
|
|
234
|
+
nodes: graphCore.getAllNodes(),
|
|
235
|
+
edges: graphCore.getAllEdges(),
|
|
236
|
+
});
|
|
208
237
|
|
|
209
|
-
this.renderNodes(
|
|
210
|
-
this.
|
|
211
|
-
|
|
238
|
+
this.renderNodes(nodes, theme.node);
|
|
239
|
+
this.renderCombos(combos, theme.combo, graphCore);
|
|
240
|
+
this.renderEdges(edges, theme.edge);
|
|
241
|
+
this.sortByComboTree(graphCore);
|
|
242
|
+
if (graphCore.hasTreeStructure('combo')) {
|
|
243
|
+
graphCoreTreeDfs(
|
|
244
|
+
graphCore,
|
|
245
|
+
graphCore.getRoots('combo'),
|
|
246
|
+
(child) => {
|
|
247
|
+
if (child.data.collapsed) this.collapseCombo(graphCore, child);
|
|
248
|
+
},
|
|
249
|
+
'BT',
|
|
250
|
+
);
|
|
251
|
+
}
|
|
212
252
|
}
|
|
213
253
|
|
|
214
254
|
/**
|
|
@@ -220,9 +260,16 @@ export class ItemController {
|
|
|
220
260
|
changes: GraphChange<NodeModelData, EdgeModelData>[];
|
|
221
261
|
graphCore: GraphCore;
|
|
222
262
|
theme: ThemeSpecification;
|
|
223
|
-
|
|
263
|
+
upsertAncestors?: boolean;
|
|
264
|
+
action?: 'updatePosition';
|
|
224
265
|
}) {
|
|
225
|
-
const {
|
|
266
|
+
const {
|
|
267
|
+
changes,
|
|
268
|
+
graphCore,
|
|
269
|
+
action,
|
|
270
|
+
upsertAncestors = true,
|
|
271
|
+
theme = {},
|
|
272
|
+
} = param;
|
|
226
273
|
const groupedChanges = {
|
|
227
274
|
NodeRemoved: [],
|
|
228
275
|
EdgeRemoved: [],
|
|
@@ -231,6 +278,7 @@ export class ItemController {
|
|
|
231
278
|
NodeDataUpdated: [],
|
|
232
279
|
EdgeUpdated: [],
|
|
233
280
|
EdgeDataUpdated: [],
|
|
281
|
+
TreeStructureChanged: [],
|
|
234
282
|
};
|
|
235
283
|
changes.forEach((change) => {
|
|
236
284
|
const { type: changeType } = change;
|
|
@@ -251,14 +299,28 @@ export class ItemController {
|
|
|
251
299
|
},
|
|
252
300
|
);
|
|
253
301
|
|
|
254
|
-
const {
|
|
302
|
+
const {
|
|
303
|
+
node: nodeTheme = {},
|
|
304
|
+
edge: edgeTheme = {},
|
|
305
|
+
combo: comboTheme = {},
|
|
306
|
+
} = theme;
|
|
255
307
|
|
|
256
308
|
// === 3. add nodes ===
|
|
257
309
|
if (groupedChanges.NodeAdded.length) {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
310
|
+
const newNodes = [];
|
|
311
|
+
const newCombos = [];
|
|
312
|
+
groupedChanges.NodeAdded.map((change) => change.value).forEach(
|
|
313
|
+
(model) => {
|
|
314
|
+
if (model.data._isCombo) newCombos.push(model);
|
|
315
|
+
else newNodes.push(model);
|
|
316
|
+
},
|
|
261
317
|
);
|
|
318
|
+
if (newNodes.length) {
|
|
319
|
+
this.renderNodes(newNodes, nodeTheme);
|
|
320
|
+
}
|
|
321
|
+
if (newCombos.length) {
|
|
322
|
+
this.renderCombos(newCombos, comboTheme, graphCore);
|
|
323
|
+
}
|
|
262
324
|
}
|
|
263
325
|
// === 4. add edges ===
|
|
264
326
|
if (groupedChanges.EdgeAdded.length) {
|
|
@@ -269,31 +331,37 @@ export class ItemController {
|
|
|
269
331
|
}
|
|
270
332
|
|
|
271
333
|
// === 5. update nodes's data ===
|
|
272
|
-
// merge changes for each node
|
|
334
|
+
// merge changes for each node or combo
|
|
273
335
|
if (groupedChanges.NodeDataUpdated.length) {
|
|
274
|
-
const
|
|
336
|
+
const nodeComboUpdate = {};
|
|
275
337
|
groupedChanges.NodeDataUpdated.forEach((change) => {
|
|
276
338
|
const { id, propertyName, newValue, oldValue } = change;
|
|
277
|
-
|
|
339
|
+
nodeComboUpdate[id] = nodeComboUpdate[id] || {
|
|
340
|
+
previous: {},
|
|
341
|
+
current: {},
|
|
342
|
+
};
|
|
278
343
|
if (!propertyName) {
|
|
279
|
-
|
|
344
|
+
nodeComboUpdate[id] = {
|
|
280
345
|
isReplace: true, // whether replace the whole data
|
|
281
346
|
previous: oldValue,
|
|
282
347
|
current: newValue,
|
|
283
348
|
};
|
|
284
349
|
} else {
|
|
285
|
-
|
|
286
|
-
|
|
350
|
+
nodeComboUpdate[id].previous[propertyName] = oldValue;
|
|
351
|
+
nodeComboUpdate[id].current[propertyName] = newValue;
|
|
287
352
|
}
|
|
288
353
|
});
|
|
289
354
|
const { dataTypeField: nodeDataTypeField } = nodeTheme;
|
|
290
355
|
const edgeToUpdate = {};
|
|
291
|
-
const
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
356
|
+
const comboToUpdate = {};
|
|
357
|
+
const updateRelates = throttle(
|
|
358
|
+
(edgeMap) => {
|
|
359
|
+
Object.keys(comboToUpdate)
|
|
360
|
+
.concat(Object.keys(edgeMap || edgeToUpdate))
|
|
361
|
+
.forEach((id) => {
|
|
362
|
+
const item = itemMap[id] as Edge | Combo;
|
|
363
|
+
if (item && !item.destroyed) item.forceUpdate();
|
|
364
|
+
});
|
|
297
365
|
},
|
|
298
366
|
16,
|
|
299
367
|
{
|
|
@@ -301,8 +369,14 @@ export class ItemController {
|
|
|
301
369
|
trailing: true,
|
|
302
370
|
},
|
|
303
371
|
);
|
|
304
|
-
Object.keys(
|
|
305
|
-
|
|
372
|
+
Object.keys(nodeComboUpdate).forEach((id) => {
|
|
373
|
+
if (!graphCore.hasNode(id)) return;
|
|
374
|
+
const { isReplace, previous, current } = nodeComboUpdate[id];
|
|
375
|
+
const onlyMove = action === 'updatePosition';
|
|
376
|
+
const item = itemMap[id] as Node | Combo;
|
|
377
|
+
const type = item.getType();
|
|
378
|
+
if (onlyMove && type === 'node' && isNaN(current.x) && isNaN(current.y))
|
|
379
|
+
return;
|
|
306
380
|
// update the theme if the dataType value is changed
|
|
307
381
|
let itemTheme;
|
|
308
382
|
if (
|
|
@@ -316,39 +390,86 @@ export class ItemController {
|
|
|
316
390
|
nodeTheme,
|
|
317
391
|
);
|
|
318
392
|
}
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
try {
|
|
322
|
-
innerModel = graphCore.getNode(id);
|
|
323
|
-
} catch (e) {
|
|
324
|
-
innerModel = graphCore.getNode(Number(id));
|
|
325
|
-
}
|
|
326
|
-
let relatedEdgeInnerModels;
|
|
327
|
-
try {
|
|
328
|
-
relatedEdgeInnerModels = graphCore.getRelatedEdges(id);
|
|
329
|
-
} catch (e) {
|
|
330
|
-
relatedEdgeInnerModels = graphCore.getRelatedEdges(Number(id));
|
|
331
|
-
}
|
|
393
|
+
const innerModel = graphCore.getNode(id);
|
|
394
|
+
const relatedEdgeInnerModels = graphCore.getRelatedEdges(id);
|
|
332
395
|
const nodeRelatedToUpdate = {};
|
|
333
396
|
relatedEdgeInnerModels.forEach((edge) => {
|
|
334
397
|
edgeToUpdate[edge.id] = edge;
|
|
335
398
|
nodeRelatedToUpdate[edge.id] = edge;
|
|
336
399
|
});
|
|
337
400
|
|
|
338
|
-
|
|
339
|
-
|
|
401
|
+
const previousParentId = item.displayModel.data.parentId;
|
|
402
|
+
|
|
403
|
+
item.onframe = () => {
|
|
404
|
+
updateRelates(nodeRelatedToUpdate);
|
|
405
|
+
};
|
|
406
|
+
item.update(
|
|
340
407
|
innerModel,
|
|
341
408
|
{ previous, current },
|
|
342
409
|
isReplace,
|
|
343
410
|
itemTheme,
|
|
344
|
-
|
|
411
|
+
onlyMove,
|
|
345
412
|
// call after updating finished
|
|
346
413
|
() => {
|
|
347
|
-
|
|
414
|
+
item.onframe();
|
|
415
|
+
item.onframe = undefined;
|
|
348
416
|
},
|
|
349
417
|
);
|
|
418
|
+
|
|
419
|
+
if (graphCore.hasTreeStructure('combo')) {
|
|
420
|
+
if (type === 'combo' && current.collapsed !== previous.collapsed) {
|
|
421
|
+
if (current.collapsed) {
|
|
422
|
+
this.collapseCombo(graphCore, innerModel as ComboModel);
|
|
423
|
+
} else if (current.collapsed === false) {
|
|
424
|
+
this.expandCombo(graphCore, innerModel as ComboModel);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// update the current parent combo tree
|
|
429
|
+
// if the node has previous parent, related previous parent combo should be updated to
|
|
430
|
+
if (upsertAncestors) {
|
|
431
|
+
const begins = [innerModel];
|
|
432
|
+
if (
|
|
433
|
+
previousParentId &&
|
|
434
|
+
previousParentId !== current.parentId &&
|
|
435
|
+
graphCore.hasNode(previousParentId as ID)
|
|
436
|
+
) {
|
|
437
|
+
begins.push(graphCore.getNode(previousParentId as ID));
|
|
438
|
+
}
|
|
439
|
+
// ancestors and suceeds combos should be updated
|
|
440
|
+
traverseAncestorsAndSucceeds(
|
|
441
|
+
this.graph,
|
|
442
|
+
graphCore,
|
|
443
|
+
begins,
|
|
444
|
+
(treeItem) => {
|
|
445
|
+
if (treeItem.data._isCombo && treeItem.id !== innerModel.id)
|
|
446
|
+
comboToUpdate[treeItem.id] = treeItem;
|
|
447
|
+
const relatedEdges = graphCore.getRelatedEdges(treeItem.id);
|
|
448
|
+
relatedEdges.forEach((edge) => {
|
|
449
|
+
edgeToUpdate[edge.id] = edge;
|
|
450
|
+
nodeRelatedToUpdate[edge.id] = edge;
|
|
451
|
+
});
|
|
452
|
+
},
|
|
453
|
+
);
|
|
454
|
+
} else if (type === 'combo') {
|
|
455
|
+
// only the succeed combos should be updated
|
|
456
|
+
graphComboTreeDfs(this.graph, [innerModel], (child) => {
|
|
457
|
+
const relatedEdges = graphCore.getRelatedEdges(child.id);
|
|
458
|
+
relatedEdges.forEach((edge) => {
|
|
459
|
+
edgeToUpdate[edge.id] = edge;
|
|
460
|
+
nodeRelatedToUpdate[edge.id] = edge;
|
|
461
|
+
});
|
|
462
|
+
if (child.data._isCombo && child.id !== innerModel.id)
|
|
463
|
+
comboToUpdate[child.id] = child;
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
const parentItem = this.itemMap[current.parentId];
|
|
468
|
+
if (current.parentId && parentItem?.model.data.collapsed) {
|
|
469
|
+
this.graph.hideItem(innerModel.id);
|
|
470
|
+
}
|
|
350
471
|
});
|
|
351
|
-
|
|
472
|
+
updateRelates();
|
|
352
473
|
}
|
|
353
474
|
|
|
354
475
|
// === 6. update edges' data ===
|
|
@@ -407,6 +528,11 @@ export class ItemController {
|
|
|
407
528
|
item.updateEnd('target', this.itemMap[target] as Node);
|
|
408
529
|
});
|
|
409
530
|
}
|
|
531
|
+
|
|
532
|
+
// === 8. combo tree structure change, resort the shapes ===
|
|
533
|
+
if (groupedChanges.TreeStructureChanged.length) {
|
|
534
|
+
this.sortByComboTree(graphCore);
|
|
535
|
+
}
|
|
410
536
|
}
|
|
411
537
|
|
|
412
538
|
/**
|
|
@@ -442,9 +568,10 @@ export class ItemController {
|
|
|
442
568
|
private onItemVisibilityChange(param: {
|
|
443
569
|
ids: ID[];
|
|
444
570
|
value: boolean;
|
|
571
|
+
graphCore: GraphCore;
|
|
445
572
|
animate?: boolean;
|
|
446
573
|
}) {
|
|
447
|
-
const { ids, value, animate = true } = param;
|
|
574
|
+
const { ids, value, graphCore, animate = true } = param;
|
|
448
575
|
ids.forEach((id) => {
|
|
449
576
|
const item = this.itemMap[id];
|
|
450
577
|
if (!item) {
|
|
@@ -453,10 +580,60 @@ export class ItemController {
|
|
|
453
580
|
);
|
|
454
581
|
return;
|
|
455
582
|
}
|
|
583
|
+
const type = item.getType();
|
|
456
584
|
if (value) {
|
|
457
|
-
|
|
585
|
+
if (type === 'edge') {
|
|
586
|
+
item.show(animate);
|
|
587
|
+
} else {
|
|
588
|
+
let anccestorCollapsed = false;
|
|
589
|
+
traverseAncestors(graphCore, [item.model], (model) => {
|
|
590
|
+
if (model.data.collapsed) anccestorCollapsed = true;
|
|
591
|
+
return anccestorCollapsed;
|
|
592
|
+
});
|
|
593
|
+
if (anccestorCollapsed) return;
|
|
594
|
+
const relatedEdges = graphCore.getRelatedEdges(id);
|
|
595
|
+
|
|
596
|
+
item.show(animate);
|
|
597
|
+
relatedEdges.forEach(({ id: edgeId, source, target }) => {
|
|
598
|
+
if (this.getItemVisible(source) && this.getItemVisible(target))
|
|
599
|
+
this.itemMap[edgeId]?.show();
|
|
600
|
+
});
|
|
601
|
+
}
|
|
458
602
|
} else {
|
|
459
603
|
item.hide(animate);
|
|
604
|
+
if (type !== 'edge') {
|
|
605
|
+
const relatedEdges = graphCore.getRelatedEdges(id);
|
|
606
|
+
relatedEdges.forEach(({ id: edgeId }) => {
|
|
607
|
+
this.itemMap[edgeId]?.hide();
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
private onItemZIndexChange(params: { ids: ID[]; action: 'front' | 'back' }) {
|
|
615
|
+
const { ids = [], action } = params;
|
|
616
|
+
ids.forEach((id) => {
|
|
617
|
+
const item = this.itemMap[id];
|
|
618
|
+
if (item) {
|
|
619
|
+
if (action === 'front') {
|
|
620
|
+
graphComboTreeDfs(
|
|
621
|
+
this.graph,
|
|
622
|
+
[item.model],
|
|
623
|
+
(model) => {
|
|
624
|
+
if (model.data._isCombo) {
|
|
625
|
+
const subCombo = this.itemMap[model.id];
|
|
626
|
+
subCombo && subCombo.toFront();
|
|
627
|
+
}
|
|
628
|
+
},
|
|
629
|
+
'TB',
|
|
630
|
+
);
|
|
631
|
+
} else {
|
|
632
|
+
item.toBack();
|
|
633
|
+
traverseGraphAncestors(this.graph, [item.model], (model) => {
|
|
634
|
+
this.itemMap[model.id]?.toBack();
|
|
635
|
+
});
|
|
636
|
+
}
|
|
460
637
|
}
|
|
461
638
|
});
|
|
462
639
|
}
|
|
@@ -500,7 +677,7 @@ export class ItemController {
|
|
|
500
677
|
false,
|
|
501
678
|
itemTheme as {
|
|
502
679
|
styles: NodeStyleSet;
|
|
503
|
-
lodStrategy:
|
|
680
|
+
lodStrategy: LodStrategyObj;
|
|
504
681
|
},
|
|
505
682
|
);
|
|
506
683
|
});
|
|
@@ -519,18 +696,21 @@ export class ItemController {
|
|
|
519
696
|
data?: Record<string, any>;
|
|
520
697
|
action: 'remove' | 'add' | 'update' | undefined;
|
|
521
698
|
onlyDrawKeyShape?: boolean;
|
|
699
|
+
upsertAncestors?: boolean;
|
|
522
700
|
[shapeConfig: string]: unknown;
|
|
523
701
|
};
|
|
524
702
|
canvas: Canvas;
|
|
703
|
+
graphCore: GraphCore;
|
|
525
704
|
}) {
|
|
526
705
|
const { transientObjectMap } = this;
|
|
527
|
-
const { type, id, config = {}, canvas } = param;
|
|
706
|
+
const { type, id, config = {}, canvas, graphCore } = param;
|
|
528
707
|
const {
|
|
529
708
|
style = {},
|
|
530
709
|
data = {},
|
|
531
710
|
capture,
|
|
532
711
|
action,
|
|
533
712
|
onlyDrawKeyShape,
|
|
713
|
+
upsertAncestors,
|
|
534
714
|
} = config as any;
|
|
535
715
|
const isItemType = type === 'node' || type === 'edge' || type === 'combo';
|
|
536
716
|
|
|
@@ -538,6 +718,21 @@ export class ItemController {
|
|
|
538
718
|
if (action === 'remove') {
|
|
539
719
|
if (isItemType) {
|
|
540
720
|
const transientItem = this.transientItemMap[id];
|
|
721
|
+
if (type === 'combo') {
|
|
722
|
+
// remove children from bottom to top
|
|
723
|
+
graphCoreTreeDfs(
|
|
724
|
+
graphCore,
|
|
725
|
+
[graphCore.getNode(id)],
|
|
726
|
+
(child) => {
|
|
727
|
+
const transientChild = this.transientItemMap[child.id];
|
|
728
|
+
if (transientChild && !transientChild.destroyed) {
|
|
729
|
+
transientChild.destroy();
|
|
730
|
+
}
|
|
731
|
+
delete this.transientItemMap[child.id];
|
|
732
|
+
},
|
|
733
|
+
'BT',
|
|
734
|
+
);
|
|
735
|
+
}
|
|
541
736
|
if (transientItem && !transientItem.destroyed) {
|
|
542
737
|
transientItem.destroy();
|
|
543
738
|
}
|
|
@@ -545,9 +740,7 @@ export class ItemController {
|
|
|
545
740
|
return;
|
|
546
741
|
} else {
|
|
547
742
|
const preObj = transientObjectMap[id];
|
|
548
|
-
if (preObj && !preObj.destroyed)
|
|
549
|
-
preObj.destroy();
|
|
550
|
-
}
|
|
743
|
+
if (preObj && !preObj.destroyed) preObj.destroy();
|
|
551
744
|
delete transientObjectMap[id];
|
|
552
745
|
return;
|
|
553
746
|
}
|
|
@@ -566,13 +759,17 @@ export class ItemController {
|
|
|
566
759
|
item,
|
|
567
760
|
this.transientNodeGroup,
|
|
568
761
|
this.transientEdgeGroup,
|
|
762
|
+
this.transientComboGroup,
|
|
569
763
|
this.transientItemMap,
|
|
764
|
+
this.itemMap,
|
|
765
|
+
graphCore,
|
|
570
766
|
onlyDrawKeyShape,
|
|
767
|
+
upsertAncestors,
|
|
571
768
|
);
|
|
572
769
|
if (onlyDrawKeyShape) {
|
|
573
770
|
// only update node positions to cloned node container(group)
|
|
574
771
|
if (
|
|
575
|
-
type === 'node' &&
|
|
772
|
+
(type === 'node' || type === 'combo') &&
|
|
576
773
|
data.hasOwnProperty('x') &&
|
|
577
774
|
data.hasOwnProperty('y')
|
|
578
775
|
) {
|
|
@@ -582,6 +779,50 @@ export class ItemController {
|
|
|
582
779
|
// TODO: edge onlyDrawKeyShape?
|
|
583
780
|
} else {
|
|
584
781
|
const transItem = transientItem as Node | Edge | Combo;
|
|
782
|
+
const positionChanged =
|
|
783
|
+
data.hasOwnProperty('x') && data.hasOwnProperty('y');
|
|
784
|
+
if (type === 'combo' && positionChanged) {
|
|
785
|
+
const { x, y } = data;
|
|
786
|
+
const { x: ox = x, y: oy = y } = transItem.displayModel.data;
|
|
787
|
+
const dx = x - ox;
|
|
788
|
+
const dy = y - oy;
|
|
789
|
+
// move combo = move children nodes from bottom to top
|
|
790
|
+
graphCoreTreeDfs(
|
|
791
|
+
graphCore,
|
|
792
|
+
[transItem.model],
|
|
793
|
+
(node) => {
|
|
794
|
+
const transChild = this.transientItemMap[node.id] as Node;
|
|
795
|
+
if (!transChild) return;
|
|
796
|
+
const { x: childX, y: childY } = transChild.model
|
|
797
|
+
.data as NodeModelData;
|
|
798
|
+
|
|
799
|
+
transChild?.update({
|
|
800
|
+
...transChild.model,
|
|
801
|
+
data: {
|
|
802
|
+
...transChild.model.data,
|
|
803
|
+
x: childX + dx,
|
|
804
|
+
y: childY + dy,
|
|
805
|
+
},
|
|
806
|
+
});
|
|
807
|
+
},
|
|
808
|
+
'BT',
|
|
809
|
+
);
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
if (type !== 'edge' && positionChanged) {
|
|
813
|
+
// force update ancestor combos in the sametime
|
|
814
|
+
let currentAncestor = graphCore.getParent(
|
|
815
|
+
transItem.model.id,
|
|
816
|
+
'combo',
|
|
817
|
+
);
|
|
818
|
+
while (currentAncestor) {
|
|
819
|
+
const ancestorItem = this.transientItemMap[currentAncestor.id];
|
|
820
|
+
if (ancestorItem) (ancestorItem as Combo).forceUpdate();
|
|
821
|
+
currentAncestor = graphCore.getParent(currentAncestor.id, 'combo');
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
// Update the target combo's posiiton and other props
|
|
585
826
|
transItem.update({
|
|
586
827
|
...transItem.model,
|
|
587
828
|
data: {
|
|
@@ -632,7 +873,7 @@ export class ItemController {
|
|
|
632
873
|
zoom,
|
|
633
874
|
theme: itemTheme as {
|
|
634
875
|
styles: NodeStyleSet;
|
|
635
|
-
lodStrategy:
|
|
876
|
+
lodStrategy: LodStrategyObj;
|
|
636
877
|
},
|
|
637
878
|
device:
|
|
638
879
|
graph.rendererType === 'webgl-3d'
|
|
@@ -643,6 +884,54 @@ export class ItemController {
|
|
|
643
884
|
});
|
|
644
885
|
}
|
|
645
886
|
|
|
887
|
+
private renderCombos(
|
|
888
|
+
models: ComboModel[],
|
|
889
|
+
comboTheme: ComboThemeSpecifications = {},
|
|
890
|
+
graphCore: GraphCore,
|
|
891
|
+
) {
|
|
892
|
+
const { comboExtensions, comboGroup, comboDataTypeSet, graph, itemMap } =
|
|
893
|
+
this;
|
|
894
|
+
const { dataTypeField } = comboTheme;
|
|
895
|
+
const zoom = graph.getZoom();
|
|
896
|
+
models.forEach((combo) => {
|
|
897
|
+
// get the base styles from theme
|
|
898
|
+
let dataType;
|
|
899
|
+
if (dataTypeField) dataType = combo.data[dataTypeField] as string;
|
|
900
|
+
const itemTheme = getItemTheme(
|
|
901
|
+
comboDataTypeSet,
|
|
902
|
+
dataTypeField,
|
|
903
|
+
dataType,
|
|
904
|
+
comboTheme,
|
|
905
|
+
);
|
|
906
|
+
|
|
907
|
+
itemMap[combo.id] = new Combo({
|
|
908
|
+
model: combo,
|
|
909
|
+
getCombinedBounds: () => {
|
|
910
|
+
// calculate the position of the combo according to its children
|
|
911
|
+
const childModels = graphCore.getChildren(combo.id, 'combo');
|
|
912
|
+
return getCombinedBoundsByData(graph, childModels);
|
|
913
|
+
},
|
|
914
|
+
getChildren: () => {
|
|
915
|
+
const childModels = graphCore.getChildren(combo.id, 'combo');
|
|
916
|
+
return childModels.map(({ id }) => itemMap[id]) as (Node | Combo)[];
|
|
917
|
+
},
|
|
918
|
+
renderExtensions: comboExtensions,
|
|
919
|
+
containerGroup: comboGroup,
|
|
920
|
+
mapper: this.comboMapper,
|
|
921
|
+
stateMapper: this.comboStateMapper,
|
|
922
|
+
zoom,
|
|
923
|
+
theme: itemTheme as {
|
|
924
|
+
styles: ComboStyleSet;
|
|
925
|
+
lodStrategy: LodStrategyObj;
|
|
926
|
+
},
|
|
927
|
+
device:
|
|
928
|
+
graph.rendererType === 'webgl-3d'
|
|
929
|
+
? (graph.canvas.context as any).deviceRendererPlugin.getDevice()
|
|
930
|
+
: undefined,
|
|
931
|
+
});
|
|
932
|
+
});
|
|
933
|
+
}
|
|
934
|
+
|
|
646
935
|
/**
|
|
647
936
|
* Create edges with inner data to canvas.
|
|
648
937
|
* @param models edges' inner datas
|
|
@@ -689,7 +978,7 @@ export class ItemController {
|
|
|
689
978
|
zoom,
|
|
690
979
|
theme: itemTheme as {
|
|
691
980
|
styles: EdgeStyleSet;
|
|
692
|
-
lodStrategy:
|
|
981
|
+
lodStrategy: LodStrategyObj;
|
|
693
982
|
},
|
|
694
983
|
});
|
|
695
984
|
});
|
|
@@ -736,14 +1025,19 @@ export class ItemController {
|
|
|
736
1025
|
return this.itemMap[id];
|
|
737
1026
|
}
|
|
738
1027
|
|
|
739
|
-
public getItemBBox(
|
|
740
|
-
|
|
1028
|
+
public getItemBBox(
|
|
1029
|
+
id: ID,
|
|
1030
|
+
isKeyShape = false,
|
|
1031
|
+
isTransient = false,
|
|
1032
|
+
): AABB | false {
|
|
1033
|
+
const item = isTransient ? this.transientItemMap[id] : this.itemMap[id];
|
|
741
1034
|
if (!item) {
|
|
742
1035
|
console.warn(
|
|
743
1036
|
`Fail to get item bbox, the item with id ${id} does not exist.`,
|
|
744
1037
|
);
|
|
745
1038
|
return false;
|
|
746
1039
|
}
|
|
1040
|
+
if (item instanceof Group) return item.getRenderBounds();
|
|
747
1041
|
return isKeyShape ? item.getKeyBBox() : item.getBBox();
|
|
748
1042
|
}
|
|
749
1043
|
|
|
@@ -757,16 +1051,102 @@ export class ItemController {
|
|
|
757
1051
|
}
|
|
758
1052
|
return item.isVisible();
|
|
759
1053
|
}
|
|
1054
|
+
|
|
1055
|
+
public sortByComboTree(graphCore: GraphCore) {
|
|
1056
|
+
if (!graphCore.hasTreeStructure('combo')) return;
|
|
1057
|
+
graphCoreTreeDfs(graphCore, graphCore.getRoots('combo'), (node) => {
|
|
1058
|
+
const nodeItem = this.itemMap[node.id];
|
|
1059
|
+
if (node.data._isCombo && nodeItem) {
|
|
1060
|
+
nodeItem.toFront();
|
|
1061
|
+
}
|
|
1062
|
+
});
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
private collapseCombo(graphCore: GraphCore, comboModel: ComboModel) {
|
|
1066
|
+
let relatedEdges = [];
|
|
1067
|
+
const succeedIds = [];
|
|
1068
|
+
// hide the succeeds
|
|
1069
|
+
graphComboTreeDfs(this.graph, [comboModel], (child) => {
|
|
1070
|
+
if (child.id !== comboModel.id) this.graph.hideItem(child.id);
|
|
1071
|
+
relatedEdges = relatedEdges.concat(graphCore.getRelatedEdges(child.id));
|
|
1072
|
+
succeedIds.push(child.id);
|
|
1073
|
+
});
|
|
1074
|
+
const virtualEdges = [];
|
|
1075
|
+
const groupedEdges = new Map();
|
|
1076
|
+
uniq(relatedEdges).forEach((edge) => {
|
|
1077
|
+
const { source: s, target: t, data } = edge;
|
|
1078
|
+
if (data._virtual) return;
|
|
1079
|
+
const sourceIsSucceed = succeedIds.includes(s);
|
|
1080
|
+
const targetIsSucceed = succeedIds.includes(t);
|
|
1081
|
+
// do not add virtual edge if the source and target are both the succeed
|
|
1082
|
+
if (sourceIsSucceed && targetIsSucceed) return;
|
|
1083
|
+
const source = sourceIsSucceed ? comboModel.id : s;
|
|
1084
|
+
const target = targetIsSucceed ? comboModel.id : t;
|
|
1085
|
+
const key = `${source}_${target}`;
|
|
1086
|
+
const group = groupedEdges.get(key) || { edges: [], source, target };
|
|
1087
|
+
group.edges.push(edge);
|
|
1088
|
+
groupedEdges.set(key, group);
|
|
1089
|
+
});
|
|
1090
|
+
// each item in groupedEdges is a virtual edge
|
|
1091
|
+
groupedEdges.forEach((group) => {
|
|
1092
|
+
const { source, target, edges } = group;
|
|
1093
|
+
virtualEdges.push({
|
|
1094
|
+
id: `virtual-${uniqueId()}`,
|
|
1095
|
+
source,
|
|
1096
|
+
target,
|
|
1097
|
+
data: {
|
|
1098
|
+
_virtual: true,
|
|
1099
|
+
keyShape: {
|
|
1100
|
+
lineWidth: edges.length,
|
|
1101
|
+
},
|
|
1102
|
+
},
|
|
1103
|
+
});
|
|
1104
|
+
});
|
|
1105
|
+
this.graph.addData('edge', virtualEdges);
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
private expandCombo(graphCore: GraphCore, comboModel: ComboModel) {
|
|
1109
|
+
let isAncestorCollapsed = false;
|
|
1110
|
+
traverseAncestors(graphCore, [comboModel], (anccestor) => {
|
|
1111
|
+
if (anccestor.data.collapsed) {
|
|
1112
|
+
isAncestorCollapsed = true;
|
|
1113
|
+
return true;
|
|
1114
|
+
}
|
|
1115
|
+
return false;
|
|
1116
|
+
});
|
|
1117
|
+
if (isAncestorCollapsed) return;
|
|
1118
|
+
const relatedVirtualEdgeIds = [];
|
|
1119
|
+
// show the succeeds
|
|
1120
|
+
graphComboTreeDfs(this.graph, [comboModel], (child) => {
|
|
1121
|
+
graphCore.getRelatedEdges(child.id).forEach((edge) => {
|
|
1122
|
+
if (edge.data._virtual) relatedVirtualEdgeIds.push(edge.id);
|
|
1123
|
+
});
|
|
1124
|
+
if (child.id !== comboModel.id) {
|
|
1125
|
+
if (!graphCore.getNode(child.data.parentId).data.collapsed) {
|
|
1126
|
+
this.graph.showItem(child.id);
|
|
1127
|
+
}
|
|
1128
|
+
// re-add collapsed succeeds' virtual edges by calling collapseCombo
|
|
1129
|
+
if (child.data._isCombo && child.data.collapsed) {
|
|
1130
|
+
this.collapseCombo(graphCore, child);
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
});
|
|
1134
|
+
// remove related virtual edges
|
|
1135
|
+
this.graph.removeData('edge', uniq(relatedVirtualEdgeIds));
|
|
1136
|
+
}
|
|
760
1137
|
}
|
|
761
1138
|
|
|
762
1139
|
const getItemTheme = (
|
|
763
1140
|
dataTypeSet: Set<string>,
|
|
764
1141
|
dataTypeField: string,
|
|
765
1142
|
dataType: string,
|
|
766
|
-
itemTheme:
|
|
1143
|
+
itemTheme:
|
|
1144
|
+
| NodeThemeSpecifications
|
|
1145
|
+
| EdgeThemeSpecifications
|
|
1146
|
+
| ComboThemeSpecifications,
|
|
767
1147
|
): {
|
|
768
1148
|
styles: NodeStyleSet | EdgeStyleSet;
|
|
769
|
-
lodStrategy:
|
|
1149
|
+
lodStrategy: LodStrategyObj;
|
|
770
1150
|
} => {
|
|
771
1151
|
const { styles: themeStyles, lodStrategy } = itemTheme;
|
|
772
1152
|
const formattedLodStrategy = formatLodStrategy(lodStrategy);
|