@antv/g6 5.0.0-beta.4 → 5.0.0-beta.6
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 -1
- 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 +2 -1
- package/esm/item/edge.js +18 -8
- package/esm/item/edge.js.map +1 -1
- package/esm/item/item.d.ts +3 -2
- package/esm/item/item.js +12 -6
- package/esm/item/item.js.map +1 -1
- package/esm/item/node.d.ts +2 -1
- package/esm/item/node.js +19 -10
- package/esm/item/node.js.map +1 -1
- package/esm/runtime/controller/item.d.ts +1 -0
- package/esm/runtime/controller/item.js +271 -151
- package/esm/runtime/controller/item.js.map +1 -1
- package/esm/runtime/graph.d.ts +98 -18
- package/esm/runtime/graph.js +427 -75
- package/esm/runtime/graph.js.map +1 -1
- package/esm/stdlib/behavior/activate-relations.js +2 -2
- package/esm/stdlib/behavior/activate-relations.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/click-select.js +1 -1
- package/esm/stdlib/behavior/click-select.js.map +1 -1
- package/esm/stdlib/behavior/create-edge.d.ts +57 -0
- package/esm/stdlib/behavior/create-edge.js +206 -0
- package/esm/stdlib/behavior/create-edge.js.map +1 -0
- package/esm/stdlib/behavior/drag-canvas.d.ts +1 -1
- package/esm/stdlib/behavior/drag-canvas.js +51 -28
- 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 +43 -32
- 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 +76 -63
- 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 +1 -1
- package/esm/stdlib/behavior/zoom-canvas.js +47 -24
- package/esm/stdlib/behavior/zoom-canvas.js.map +1 -1
- package/esm/stdlib/index.d.ts +6 -0
- package/esm/stdlib/index.js +15 -9
- package/esm/stdlib/index.js.map +1 -1
- package/esm/stdlib/item/edge/base.d.ts +1 -1
- package/esm/stdlib/item/edge/base.js +13 -4
- package/esm/stdlib/item/edge/base.js.map +1 -1
- package/esm/stdlib/item/node/base.d.ts +1 -1
- package/esm/stdlib/item/node/base.js +11 -12
- package/esm/stdlib/item/node/base.js.map +1 -1
- package/esm/stdlib/item/node/image.d.ts +1 -1
- package/esm/stdlib/item/node/image.js +1 -1
- package/esm/stdlib/item/node/image.js.map +1 -1
- package/esm/stdlib/plugin/history/combo-command.js +2 -2
- package/esm/stdlib/plugin/history/combo-command.js.map +1 -1
- package/esm/stdlib/plugin/history/index.d.ts +10 -10
- package/esm/stdlib/plugin/history/index.js +14 -14
- package/esm/stdlib/plugin/history/index.js.map +1 -1
- package/esm/stdlib/plugin/history/item-data-command.js +4 -4
- package/esm/stdlib/plugin/history/item-data-command.js.map +1 -1
- package/esm/stdlib/plugin/history/layer-updated-command.js +2 -2
- package/esm/stdlib/plugin/history/layer-updated-command.js.map +1 -1
- package/esm/stdlib/plugin/history/state-updated-command.js +1 -1
- package/esm/stdlib/plugin/history/state-updated-command.js.map +1 -1
- package/esm/stdlib/plugin/history/visibility-updated-command.js +2 -2
- package/esm/stdlib/plugin/history/visibility-updated-command.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/index.d.ts +1 -0
- package/esm/stdlib/plugin/index.js +1 -0
- package/esm/stdlib/plugin/index.js.map +1 -1
- package/esm/stdlib/plugin/minimap/index.d.ts +5 -1
- package/esm/stdlib/plugin/minimap/index.js +109 -8
- package/esm/stdlib/plugin/minimap/index.js.map +1 -1
- package/esm/stdlib/plugin/snapline/index.d.ts +163 -0
- package/esm/stdlib/plugin/snapline/index.js +1052 -0
- package/esm/stdlib/plugin/snapline/index.js.map +1 -0
- package/esm/stdlib/plugin/types.d.ts +1 -0
- package/esm/types/graph.d.ts +45 -19
- package/esm/types/hook.d.ts +22 -2
- package/esm/types/spec.d.ts +19 -3
- package/esm/util/bbox.d.ts +16 -1
- package/esm/util/bbox.js +29 -0
- package/esm/util/bbox.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/shape.js +2 -2
- 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 -1
- 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 +2 -1
- package/lib/item/edge.js +18 -8
- package/lib/item/edge.js.map +1 -1
- package/lib/item/item.d.ts +3 -2
- package/lib/item/item.js +12 -6
- package/lib/item/item.js.map +1 -1
- package/lib/item/node.d.ts +2 -1
- package/lib/item/node.js +19 -10
- package/lib/item/node.js.map +1 -1
- package/lib/runtime/controller/item.d.ts +1 -0
- package/lib/runtime/controller/item.js +270 -150
- package/lib/runtime/controller/item.js.map +1 -1
- package/lib/runtime/graph.d.ts +98 -18
- package/lib/runtime/graph.js +427 -75
- package/lib/runtime/graph.js.map +1 -1
- package/lib/stdlib/behavior/activate-relations.js +2 -2
- package/lib/stdlib/behavior/activate-relations.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/click-select.js +1 -1
- package/lib/stdlib/behavior/click-select.js.map +1 -1
- package/lib/stdlib/behavior/create-edge.d.ts +57 -0
- package/lib/stdlib/behavior/create-edge.js +210 -0
- package/lib/stdlib/behavior/create-edge.js.map +1 -0
- package/lib/stdlib/behavior/drag-canvas.d.ts +1 -1
- package/lib/stdlib/behavior/drag-canvas.js +51 -28
- 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 +43 -32
- 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 +76 -63
- 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 +1 -1
- package/lib/stdlib/behavior/zoom-canvas.js +47 -24
- package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
- package/lib/stdlib/index.d.ts +6 -0
- package/lib/stdlib/index.js +15 -9
- package/lib/stdlib/index.js.map +1 -1
- package/lib/stdlib/item/edge/base.d.ts +1 -1
- package/lib/stdlib/item/edge/base.js +13 -4
- package/lib/stdlib/item/edge/base.js.map +1 -1
- package/lib/stdlib/item/node/base.d.ts +1 -1
- package/lib/stdlib/item/node/base.js +11 -12
- package/lib/stdlib/item/node/base.js.map +1 -1
- package/lib/stdlib/item/node/image.d.ts +1 -1
- package/lib/stdlib/item/node/image.js +1 -1
- package/lib/stdlib/item/node/image.js.map +1 -1
- package/lib/stdlib/plugin/history/combo-command.js +2 -2
- package/lib/stdlib/plugin/history/combo-command.js.map +1 -1
- package/lib/stdlib/plugin/history/index.d.ts +10 -10
- package/lib/stdlib/plugin/history/index.js +14 -14
- package/lib/stdlib/plugin/history/index.js.map +1 -1
- package/lib/stdlib/plugin/history/item-data-command.js +4 -4
- package/lib/stdlib/plugin/history/item-data-command.js.map +1 -1
- package/lib/stdlib/plugin/history/layer-updated-command.js +2 -2
- package/lib/stdlib/plugin/history/layer-updated-command.js.map +1 -1
- package/lib/stdlib/plugin/history/state-updated-command.js +1 -1
- package/lib/stdlib/plugin/history/state-updated-command.js.map +1 -1
- package/lib/stdlib/plugin/history/visibility-updated-command.js +2 -2
- package/lib/stdlib/plugin/history/visibility-updated-command.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/index.d.ts +1 -0
- package/lib/stdlib/plugin/index.js +1 -0
- package/lib/stdlib/plugin/index.js.map +1 -1
- package/lib/stdlib/plugin/minimap/index.d.ts +5 -1
- package/lib/stdlib/plugin/minimap/index.js +109 -8
- package/lib/stdlib/plugin/minimap/index.js.map +1 -1
- package/lib/stdlib/plugin/snapline/index.d.ts +163 -0
- package/lib/stdlib/plugin/snapline/index.js +1056 -0
- package/lib/stdlib/plugin/snapline/index.js.map +1 -0
- package/lib/stdlib/plugin/types.d.ts +1 -0
- package/lib/types/graph.d.ts +45 -19
- package/lib/types/hook.d.ts +22 -2
- package/lib/types/spec.d.ts +19 -3
- package/lib/util/bbox.d.ts +16 -1
- package/lib/util/bbox.js +32 -1
- package/lib/util/bbox.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/shape.js +2 -2
- 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 +2 -2
- package/src/index.ts +1 -1
- package/src/item/combo.ts +14 -9
- package/src/item/edge.ts +17 -8
- package/src/item/item.ts +11 -6
- package/src/item/node.ts +24 -16
- package/src/runtime/controller/item.ts +240 -72
- package/src/runtime/graph.ts +536 -80
- package/src/stdlib/behavior/activate-relations.ts +2 -2
- package/src/stdlib/behavior/brush-select.ts +4 -2
- package/src/stdlib/behavior/click-select.ts +1 -1
- package/src/stdlib/behavior/create-edge.ts +295 -0
- package/src/stdlib/behavior/drag-canvas.ts +67 -29
- package/src/stdlib/behavior/drag-combo.ts +10 -10
- package/src/stdlib/behavior/drag-node.ts +18 -18
- 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 +61 -25
- package/src/stdlib/index.ts +16 -7
- package/src/stdlib/item/edge/base.ts +13 -5
- package/src/stdlib/item/node/base.ts +15 -14
- package/src/stdlib/item/node/image.ts +1 -1
- package/src/stdlib/plugin/history/combo-command.ts +2 -2
- package/src/stdlib/plugin/history/index.ts +14 -14
- package/src/stdlib/plugin/history/item-data-command.ts +4 -4
- package/src/stdlib/plugin/history/layer-updated-command.ts +2 -2
- package/src/stdlib/plugin/history/state-updated-command.ts +1 -1
- package/src/stdlib/plugin/history/visibility-updated-command.ts +2 -2
- package/src/stdlib/plugin/hull/hullComponent.ts +8 -5
- package/src/stdlib/plugin/index.ts +1 -0
- package/src/stdlib/plugin/minimap/index.ts +113 -9
- package/src/stdlib/plugin/snapline/index.ts +1277 -0
- package/src/stdlib/plugin/types.ts +1 -0
- package/src/types/graph.ts +53 -22
- package/src/types/hook.ts +22 -2
- package/src/types/spec.ts +22 -3
- package/src/util/bbox.ts +38 -1
- package/src/util/item.ts +65 -28
- package/src/util/shape.ts +2 -2
- package/src/util/warn.ts +20 -0
|
@@ -27,6 +27,8 @@ const zoom_1 = require("../../util/zoom");
|
|
|
27
27
|
const data_1 = require("../../util/data");
|
|
28
28
|
const event_1 = require("../../util/event");
|
|
29
29
|
const polyline_1 = require("../../util/polyline");
|
|
30
|
+
const bbox_1 = require("../../util/bbox");
|
|
31
|
+
const type_1 = require("../../util/type");
|
|
30
32
|
/**
|
|
31
33
|
* Manages and stores the node / edge / combo items.
|
|
32
34
|
*/
|
|
@@ -45,11 +47,38 @@ class ItemController {
|
|
|
45
47
|
// The G shapes or groups on transient map drawn by this controller
|
|
46
48
|
this.transientObjectMap = new Map();
|
|
47
49
|
this.transientItemMap = new Map();
|
|
48
|
-
this.onViewportChange = (0, util_1.debounce)(({ transform, effectTiming }) => {
|
|
50
|
+
this.onViewportChange = (0, util_1.debounce)(({ transform, effectTiming, tileLodSize = 1000, }) => {
|
|
49
51
|
const { zoom } = transform;
|
|
50
52
|
if (zoom) {
|
|
51
53
|
const zoomRatio = this.graph.getZoom();
|
|
52
|
-
this.
|
|
54
|
+
const range = this.graph.getCanvasRange();
|
|
55
|
+
const nodeItems = Array.from(this.itemMap, ([key, value]) => value);
|
|
56
|
+
const itemsInViewport = [];
|
|
57
|
+
const itemsOutViewport = [];
|
|
58
|
+
nodeItems.forEach((item) => {
|
|
59
|
+
const { keyShape } = item.shapeMap;
|
|
60
|
+
if (!keyShape)
|
|
61
|
+
return;
|
|
62
|
+
const renderBounds = keyShape.getRenderBounds();
|
|
63
|
+
if ((0, bbox_1.isBBoxInBBox)(renderBounds, range, 0.4))
|
|
64
|
+
itemsInViewport.push(item);
|
|
65
|
+
else
|
|
66
|
+
itemsOutViewport.push(item);
|
|
67
|
+
});
|
|
68
|
+
const sortedItems = itemsInViewport.concat(itemsOutViewport);
|
|
69
|
+
const sections = Math.ceil(nodeItems.length / tileLodSize);
|
|
70
|
+
const itemSections = Array.from({ length: sections }, (v, i) => sortedItems.slice(i * tileLodSize, i * tileLodSize + tileLodSize));
|
|
71
|
+
let requestId;
|
|
72
|
+
const update = () => {
|
|
73
|
+
if (!itemSections.length) {
|
|
74
|
+
cancelAnimationFrame(requestId);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
itemSections.shift().forEach((item) => item.updateZoom(zoomRatio));
|
|
78
|
+
requestId = requestAnimationFrame(update);
|
|
79
|
+
};
|
|
80
|
+
requestId = requestAnimationFrame(update);
|
|
81
|
+
// this.itemMap.forEach((item) => item.updateZoom(zoomRatio));
|
|
53
82
|
this.zoom = zoomRatio;
|
|
54
83
|
}
|
|
55
84
|
}, 500, false);
|
|
@@ -70,6 +99,17 @@ class ItemController {
|
|
|
70
99
|
item.update(item.model, undefined, false, itemTheme);
|
|
71
100
|
});
|
|
72
101
|
};
|
|
102
|
+
this.onMapperChange = ({ type, mapper }) => {
|
|
103
|
+
if (!mapper)
|
|
104
|
+
return;
|
|
105
|
+
this.itemMap.forEach((item) => {
|
|
106
|
+
const itemTye = item.getType();
|
|
107
|
+
if (itemTye !== type)
|
|
108
|
+
return;
|
|
109
|
+
item.mapper = mapper;
|
|
110
|
+
item.update(item.model, undefined, false);
|
|
111
|
+
});
|
|
112
|
+
};
|
|
73
113
|
this.onDestroy = () => {
|
|
74
114
|
Object.values(this.itemMap).forEach((item) => item.destroy());
|
|
75
115
|
// Fix OOM problem, since this map will hold all the refs of items.
|
|
@@ -103,6 +143,7 @@ class ItemController {
|
|
|
103
143
|
this.graph.hooks.transientupdate.tap(this.onTransientUpdate.bind(this));
|
|
104
144
|
this.graph.hooks.viewportchange.tap(this.onViewportChange.bind(this));
|
|
105
145
|
this.graph.hooks.themechange.tap(this.onThemeChange.bind(this));
|
|
146
|
+
this.graph.hooks.mapperchange.tap(this.onMapperChange.bind(this));
|
|
106
147
|
this.graph.hooks.treecollapseexpand.tap(this.onTreeCollapseExpand.bind(this));
|
|
107
148
|
this.graph.hooks.destroy.tap(this.onDestroy.bind(this));
|
|
108
149
|
}
|
|
@@ -132,74 +173,82 @@ class ItemController {
|
|
|
132
173
|
* @param param contains inner data stored in graphCore structure
|
|
133
174
|
*/
|
|
134
175
|
onRender(param) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
176
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
177
|
+
const { graphCore, theme = {}, transientCanvas, tileOptimize = {} } = param;
|
|
178
|
+
const { graph } = this;
|
|
179
|
+
// 0. clear groups on canvas, and create new groups
|
|
180
|
+
graph.canvas.removeChildren();
|
|
181
|
+
const comboGroup = new g_1.Group({ id: 'combo-group' });
|
|
182
|
+
const edgeGroup = new g_1.Group({ id: 'edge-group' });
|
|
183
|
+
const nodeGroup = new g_1.Group({ id: 'node-group' });
|
|
184
|
+
graph.canvas.appendChild(comboGroup);
|
|
185
|
+
graph.canvas.appendChild(edgeGroup);
|
|
186
|
+
graph.canvas.appendChild(nodeGroup);
|
|
187
|
+
this.nodeGroup = nodeGroup;
|
|
188
|
+
this.edgeGroup = edgeGroup;
|
|
189
|
+
this.comboGroup = comboGroup;
|
|
190
|
+
// Also create transient groups on transient canvas.
|
|
191
|
+
transientCanvas.removeChildren();
|
|
192
|
+
this.transientComboGroup = new g_1.Group({ id: 'combo-group' });
|
|
193
|
+
this.transientEdgeGroup = new g_1.Group({ id: 'edge-group' });
|
|
194
|
+
this.transientNodeGroup = new g_1.Group({ id: 'node-group' });
|
|
195
|
+
transientCanvas.appendChild(this.transientComboGroup);
|
|
196
|
+
transientCanvas.appendChild(this.transientEdgeGroup);
|
|
197
|
+
transientCanvas.appendChild(this.transientNodeGroup);
|
|
198
|
+
// 1. create lights for webgl 3d rendering
|
|
199
|
+
if (graph.rendererType === 'webgl-3d') {
|
|
200
|
+
const ambientLight = new g_plugin_3d_1.AmbientLight({
|
|
201
|
+
style: {
|
|
202
|
+
fill: 'white',
|
|
203
|
+
intensity: Math.PI * 2,
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
const light = new g_plugin_3d_1.DirectionalLight({
|
|
207
|
+
style: {
|
|
208
|
+
fill: 'white',
|
|
209
|
+
direction: [-1, 0, 1],
|
|
210
|
+
intensity: Math.PI * 0.7,
|
|
211
|
+
},
|
|
212
|
+
});
|
|
213
|
+
// @ts-ignore
|
|
214
|
+
graph.canvas.appendChild(ambientLight);
|
|
215
|
+
// @ts-ignore
|
|
216
|
+
graph.canvas.appendChild(light);
|
|
217
|
+
const { width, height } = graph.canvas.getConfig();
|
|
218
|
+
graph.canvas.getCamera().setPerspective(0.1, 50000, 45, width / height);
|
|
219
|
+
}
|
|
220
|
+
// 2. create node / edge / combo items, classes from ../../item, and element drawing and updating fns from node/edge/comboExtensions
|
|
221
|
+
const { nodes, edges, combos } = (0, data_1.deconstructData)({
|
|
222
|
+
nodes: graphCore.getAllNodes(),
|
|
223
|
+
edges: graphCore.getAllEdges(),
|
|
170
224
|
});
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
225
|
+
const renderNodesPromise = this.renderNodes(nodes, theme.node, tileOptimize);
|
|
226
|
+
if (renderNodesPromise) {
|
|
227
|
+
yield renderNodesPromise;
|
|
228
|
+
}
|
|
229
|
+
this.renderCombos(combos, theme.combo, graphCore);
|
|
230
|
+
const renderEdgesPromise = this.renderEdges(edges, theme.edge, tileOptimize);
|
|
231
|
+
if (renderEdgesPromise) {
|
|
232
|
+
yield renderEdgesPromise;
|
|
233
|
+
}
|
|
234
|
+
this.sortByComboTree(graphCore);
|
|
235
|
+
// collapse the combos which has 'collapsed' in initial data
|
|
236
|
+
if (graphCore.hasTreeStructure('combo')) {
|
|
237
|
+
(0, data_1.graphCoreTreeDfs)(graphCore, graphCore.getRoots('combo'), (child) => {
|
|
238
|
+
if (child.data.collapsed)
|
|
239
|
+
this.collapseCombo(graphCore, child);
|
|
240
|
+
}, 'BT', 'combo');
|
|
241
|
+
}
|
|
242
|
+
// collapse the sub tree which has 'collapsed' in initial data
|
|
243
|
+
if (graphCore.hasTreeStructure('tree')) {
|
|
244
|
+
const collapseNodes = [];
|
|
245
|
+
(0, data_1.graphCoreTreeDfs)(graphCore, graphCore.getRoots('tree'), (child) => {
|
|
246
|
+
if (child.data.collapsed)
|
|
247
|
+
collapseNodes.push(child);
|
|
248
|
+
}, 'BT', 'tree');
|
|
249
|
+
this.collapseSubTree(collapseNodes, graphCore, false);
|
|
250
|
+
}
|
|
182
251
|
});
|
|
183
|
-
this.renderNodes(nodes, theme.node);
|
|
184
|
-
this.renderCombos(combos, theme.combo, graphCore);
|
|
185
|
-
this.renderEdges(edges, theme.edge);
|
|
186
|
-
this.sortByComboTree(graphCore);
|
|
187
|
-
// collapse the combos which has 'collapsed' in initial data
|
|
188
|
-
if (graphCore.hasTreeStructure('combo')) {
|
|
189
|
-
(0, data_1.graphCoreTreeDfs)(graphCore, graphCore.getRoots('combo'), (child) => {
|
|
190
|
-
if (child.data.collapsed)
|
|
191
|
-
this.collapseCombo(graphCore, child);
|
|
192
|
-
}, 'BT', 'combo');
|
|
193
|
-
}
|
|
194
|
-
// collapse the sub tree which has 'collapsed' in initial data
|
|
195
|
-
if (graphCore.hasTreeStructure('tree')) {
|
|
196
|
-
const collapseNodes = [];
|
|
197
|
-
(0, data_1.graphCoreTreeDfs)(graphCore, graphCore.getRoots('tree'), (child) => {
|
|
198
|
-
if (child.data.collapsed)
|
|
199
|
-
collapseNodes.push(child);
|
|
200
|
-
}, 'BT', 'tree');
|
|
201
|
-
this.collapseSubTree(collapseNodes, graphCore, false);
|
|
202
|
-
}
|
|
203
252
|
}
|
|
204
253
|
/**
|
|
205
254
|
* Listener of runtime's itemchange lifecycle hook.
|
|
@@ -279,6 +328,10 @@ class ItemController {
|
|
|
279
328
|
});
|
|
280
329
|
};
|
|
281
330
|
const debounceUpdateRelates = (0, util_1.debounce)(updateRelates, 16, false);
|
|
331
|
+
const throttleUpdateRelates = (0, util_1.throttle)(updateRelates, 16, {
|
|
332
|
+
leading: true,
|
|
333
|
+
trailing: true,
|
|
334
|
+
});
|
|
282
335
|
Object.values(nodeComboUpdate).forEach((updateObj) => {
|
|
283
336
|
var _a;
|
|
284
337
|
const { isReplace, previous, current, id } = updateObj;
|
|
@@ -290,12 +343,12 @@ class ItemController {
|
|
|
290
343
|
return;
|
|
291
344
|
const type = item.getType();
|
|
292
345
|
const innerModel = graphCore.getNode(id);
|
|
293
|
-
if (onlyMove
|
|
294
|
-
|
|
295
|
-
isNaN(
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
346
|
+
if (type === 'node' && onlyMove) {
|
|
347
|
+
const { x, y, fx, fy } = current;
|
|
348
|
+
if (isNaN(x) && isNaN(y) && isNaN(fx) && isNaN(fy)) {
|
|
349
|
+
callback(innerModel, true);
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
299
352
|
}
|
|
300
353
|
const nodeRelatedIdsToUpdate = new Set();
|
|
301
354
|
// collapse and expand
|
|
@@ -356,7 +409,7 @@ class ItemController {
|
|
|
356
409
|
edgeIdsToUpdate.add(edge.id);
|
|
357
410
|
nodeRelatedIdsToUpdate.add(edge.id);
|
|
358
411
|
});
|
|
359
|
-
item.onframe = () =>
|
|
412
|
+
item.onframe = () => throttleUpdateRelates(nodeRelatedIdsToUpdate);
|
|
360
413
|
let statesCache;
|
|
361
414
|
if (innerModel.data._isCombo &&
|
|
362
415
|
previous.collapsed !== current.collapsed) {
|
|
@@ -379,7 +432,7 @@ class ItemController {
|
|
|
379
432
|
}));
|
|
380
433
|
const parentItem = this.itemMap.get(current.parentId);
|
|
381
434
|
if (current.parentId && (parentItem === null || parentItem === void 0 ? void 0 : parentItem.model.data.collapsed)) {
|
|
382
|
-
this.graph.
|
|
435
|
+
this.graph.executeWithNoStack(() => {
|
|
383
436
|
this.graph.hideItem(innerModel.id, false);
|
|
384
437
|
});
|
|
385
438
|
}
|
|
@@ -485,7 +538,7 @@ class ItemController {
|
|
|
485
538
|
});
|
|
486
539
|
}
|
|
487
540
|
onItemVisibilityChange(param) {
|
|
488
|
-
const { ids, value, graphCore, animate = true } = param;
|
|
541
|
+
const { ids, value, graphCore, animate = true, keepKeyShape = false, } = param;
|
|
489
542
|
ids.forEach((id) => {
|
|
490
543
|
const item = this.itemMap.get(id);
|
|
491
544
|
if (!item) {
|
|
@@ -518,7 +571,7 @@ class ItemController {
|
|
|
518
571
|
}
|
|
519
572
|
}
|
|
520
573
|
else {
|
|
521
|
-
item.hide(animate);
|
|
574
|
+
item.hide(animate, keepKeyShape);
|
|
522
575
|
if (type !== 'edge') {
|
|
523
576
|
const relatedEdges = graphCore.getRelatedEdges(id);
|
|
524
577
|
relatedEdges.forEach(({ id: edgeId }) => {
|
|
@@ -558,9 +611,10 @@ class ItemController {
|
|
|
558
611
|
});
|
|
559
612
|
}
|
|
560
613
|
onTransientUpdate(param) {
|
|
614
|
+
var _a, _b;
|
|
561
615
|
const { transientObjectMap } = this;
|
|
562
616
|
const { type, id, config = {}, canvas, graphCore } = param;
|
|
563
|
-
const { style = {}, data = {}, capture, action,
|
|
617
|
+
const { style = {}, data = {}, capture, action, shapeIds, drawSource, drawTarget, upsertAncestors, visible = true, } = config;
|
|
564
618
|
const isItemType = type === 'node' || type === 'edge' || type === 'combo';
|
|
565
619
|
// Removing
|
|
566
620
|
if (action === 'remove') {
|
|
@@ -577,6 +631,9 @@ class ItemController {
|
|
|
577
631
|
}, 'BT');
|
|
578
632
|
}
|
|
579
633
|
if (transientItem && !transientItem.destroyed) {
|
|
634
|
+
if (!((_b = (_a = transientItem).getType) === null || _b === void 0 ? void 0 : _b.call(_a))) {
|
|
635
|
+
transientItem.remove();
|
|
636
|
+
}
|
|
580
637
|
transientItem.destroy();
|
|
581
638
|
}
|
|
582
639
|
this.transientItemMap.delete(id);
|
|
@@ -597,8 +654,8 @@ class ItemController {
|
|
|
597
654
|
console.warn(`Fail to draw transient item of ${id}, which is not exist.`);
|
|
598
655
|
return;
|
|
599
656
|
}
|
|
600
|
-
const transientItem = (0, item_1.upsertTransientItem)(item, this.transientNodeGroup, this.transientEdgeGroup, this.transientComboGroup, this.transientItemMap, this.itemMap, graphCore,
|
|
601
|
-
if (
|
|
657
|
+
const transientItem = (0, item_1.upsertTransientItem)(item, this.transientNodeGroup, this.transientEdgeGroup, this.transientComboGroup, this.transientItemMap, this.itemMap, graphCore, { shapeIds, drawSource, drawTarget, visible }, upsertAncestors);
|
|
658
|
+
if (shapeIds) {
|
|
602
659
|
// only update node positions to cloned node container(group)
|
|
603
660
|
if ((type === 'node' || type === 'combo') &&
|
|
604
661
|
data.hasOwnProperty('x') &&
|
|
@@ -663,84 +720,128 @@ class ItemController {
|
|
|
663
720
|
* Create nodes with inner data to canvas.
|
|
664
721
|
* @param models nodes' inner datas
|
|
665
722
|
*/
|
|
666
|
-
renderNodes(models, nodeTheme = {}) {
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
const
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
:
|
|
688
|
-
|
|
723
|
+
renderNodes(models, nodeTheme = {}, tileOptimize) {
|
|
724
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
725
|
+
const { nodeExtensions, nodeGroup, nodeDataTypeSet, graph } = this;
|
|
726
|
+
const { dataTypeField = '' } = nodeTheme;
|
|
727
|
+
const { tileFirstRender, tileFirstRenderSize = 1000 } = tileOptimize || {};
|
|
728
|
+
const zoom = graph.getZoom();
|
|
729
|
+
const delayFirstDraw = (0, util_1.isNumber)(tileFirstRender)
|
|
730
|
+
? models.length > tileFirstRender
|
|
731
|
+
: tileFirstRender;
|
|
732
|
+
const itemsInView = [];
|
|
733
|
+
const itemsOutView = [];
|
|
734
|
+
const viewRange = this.graph.getCanvasRange();
|
|
735
|
+
models.forEach((node) => {
|
|
736
|
+
// get the base styles from theme
|
|
737
|
+
let dataType;
|
|
738
|
+
if (dataTypeField)
|
|
739
|
+
dataType = node.data[dataTypeField];
|
|
740
|
+
const itemTheme = getItemTheme(nodeDataTypeSet, dataTypeField, dataType, nodeTheme);
|
|
741
|
+
const nodeItem = new node_1.default({
|
|
742
|
+
delayFirstDraw,
|
|
743
|
+
model: node,
|
|
744
|
+
renderExtensions: nodeExtensions,
|
|
745
|
+
containerGroup: nodeGroup,
|
|
746
|
+
mapper: this.nodeMapper,
|
|
747
|
+
stateMapper: this.nodeStateMapper,
|
|
748
|
+
zoom,
|
|
749
|
+
theme: itemTheme,
|
|
750
|
+
device: graph.rendererType === 'webgl-3d'
|
|
751
|
+
? // TODO: G type
|
|
752
|
+
graph.canvas.context.deviceRendererPlugin.getDevice()
|
|
753
|
+
: undefined,
|
|
754
|
+
});
|
|
755
|
+
this.itemMap.set(node.id, nodeItem);
|
|
756
|
+
const { x, y } = nodeItem.model.data;
|
|
757
|
+
if (delayFirstDraw &&
|
|
758
|
+
(0, bbox_1.isPointInBBox)({ x: (0, type_1.convertToNumber)(x), y: (0, type_1.convertToNumber)(y) }, viewRange)) {
|
|
759
|
+
itemsInView.push(nodeItem);
|
|
760
|
+
}
|
|
761
|
+
else {
|
|
762
|
+
itemsOutView.push(nodeItem);
|
|
763
|
+
}
|
|
764
|
+
});
|
|
765
|
+
if (delayFirstDraw) {
|
|
766
|
+
let requestId;
|
|
767
|
+
const items = itemsInView.concat(itemsOutView);
|
|
768
|
+
const sectionNum = Math.ceil(items.length / tileFirstRenderSize);
|
|
769
|
+
const sections = Array.from({ length: sectionNum }, (v, i) => items.slice(i * tileFirstRenderSize, i * tileFirstRenderSize + tileFirstRenderSize));
|
|
770
|
+
const update = (resolve) => {
|
|
771
|
+
if (!sections.length) {
|
|
772
|
+
cancelAnimationFrame(requestId);
|
|
773
|
+
return resolve();
|
|
774
|
+
}
|
|
775
|
+
sections
|
|
776
|
+
.shift()
|
|
777
|
+
.forEach((item) => item.draw(item.displayModel, undefined, undefined, !item.displayModel.data.disableAnimate));
|
|
778
|
+
requestId = requestAnimationFrame(() => update(resolve));
|
|
779
|
+
};
|
|
780
|
+
return new Promise((resolve) => {
|
|
781
|
+
requestId = requestAnimationFrame(() => update(resolve));
|
|
782
|
+
});
|
|
783
|
+
}
|
|
689
784
|
});
|
|
690
785
|
}
|
|
691
786
|
renderCombos(models, comboTheme = {}, graphCore) {
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
.
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
const
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
787
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
788
|
+
const { comboExtensions, comboGroup, comboDataTypeSet, graph, itemMap } = this;
|
|
789
|
+
const { dataTypeField = '' } = comboTheme;
|
|
790
|
+
const zoom = graph.getZoom();
|
|
791
|
+
models.forEach((combo) => {
|
|
792
|
+
// get the base styles from theme
|
|
793
|
+
let dataType;
|
|
794
|
+
if (dataTypeField)
|
|
795
|
+
dataType = combo.data[dataTypeField];
|
|
796
|
+
const itemTheme = getItemTheme(comboDataTypeSet, dataTypeField, dataType, comboTheme);
|
|
797
|
+
const getCombinedBounds = () => {
|
|
798
|
+
// calculate the position of the combo according to its children
|
|
799
|
+
return (0, shape_1.getCombinedBoundsByData)(graph, graphCore
|
|
800
|
+
.getChildren(combo.id, 'combo')
|
|
801
|
+
.map(({ id }) => itemMap.get(id))
|
|
802
|
+
.filter(Boolean));
|
|
803
|
+
};
|
|
804
|
+
const getChildren = () => {
|
|
805
|
+
const childModels = graphCore.getChildren(combo.id, 'combo');
|
|
806
|
+
return childModels.map(({ id }) => itemMap.get(id));
|
|
807
|
+
};
|
|
808
|
+
const comboItem = new combo_1.default({
|
|
809
|
+
model: combo,
|
|
810
|
+
getCombinedBounds,
|
|
811
|
+
getChildren,
|
|
812
|
+
renderExtensions: comboExtensions,
|
|
813
|
+
containerGroup: comboGroup,
|
|
814
|
+
mapper: this.comboMapper,
|
|
815
|
+
stateMapper: this.comboStateMapper,
|
|
816
|
+
zoom,
|
|
817
|
+
theme: itemTheme,
|
|
818
|
+
device: graph.rendererType === 'webgl-3d'
|
|
819
|
+
? graph.canvas.context.deviceRendererPlugin.getDevice()
|
|
820
|
+
: undefined,
|
|
821
|
+
});
|
|
822
|
+
// ------- for integration tests -------
|
|
823
|
+
comboItem.getCombinedBounds = getCombinedBounds;
|
|
824
|
+
comboItem.getChildren = getChildren;
|
|
825
|
+
comboItem.type = 'combo';
|
|
826
|
+
// ------- for integration tests end-------
|
|
827
|
+
itemMap.set(combo.id, comboItem);
|
|
725
828
|
});
|
|
726
|
-
// ------- for integration tests -------
|
|
727
|
-
comboItem.getCombinedBounds = getCombinedBounds;
|
|
728
|
-
comboItem.getChildren = getChildren;
|
|
729
|
-
comboItem.type = 'combo';
|
|
730
|
-
// ------- for integration tests end-------
|
|
731
|
-
itemMap.set(combo.id, comboItem);
|
|
732
829
|
});
|
|
733
830
|
}
|
|
734
831
|
/**
|
|
735
832
|
* Create edges with inner data to canvas.
|
|
736
833
|
* @param models edges' inner datas
|
|
737
834
|
*/
|
|
738
|
-
renderEdges(models, edgeTheme = {}) {
|
|
835
|
+
renderEdges(models, edgeTheme = {}, tileOptimize) {
|
|
739
836
|
const { edgeExtensions, edgeGroup, itemMap, edgeDataTypeSet, graph } = this;
|
|
740
837
|
const { dataTypeField = '' } = edgeTheme;
|
|
838
|
+
const { tileFirstRender, tileFirstRenderSize = 1000 } = tileOptimize || {};
|
|
741
839
|
const zoom = graph.getZoom();
|
|
742
840
|
const nodeMap = filterItemMapByType(itemMap, 'node');
|
|
743
|
-
|
|
841
|
+
const delayFirstDraw = (0, util_1.isNumber)(tileFirstRender)
|
|
842
|
+
? models.length > tileFirstRender
|
|
843
|
+
: tileFirstRender;
|
|
844
|
+
const items = models.map((edge) => {
|
|
744
845
|
const { source, target, id } = edge;
|
|
745
846
|
const sourceItem = itemMap.get(source);
|
|
746
847
|
const targetItem = itemMap.get(target);
|
|
@@ -757,7 +858,8 @@ class ItemController {
|
|
|
757
858
|
if (dataTypeField)
|
|
758
859
|
dataType = edge.data[dataTypeField];
|
|
759
860
|
const itemTheme = getItemTheme(edgeDataTypeSet, dataTypeField, dataType, edgeTheme);
|
|
760
|
-
|
|
861
|
+
const edgeItem = new edge_1.default({
|
|
862
|
+
delayFirstDraw,
|
|
761
863
|
model: edge,
|
|
762
864
|
renderExtensions: edgeExtensions,
|
|
763
865
|
containerGroup: edgeGroup,
|
|
@@ -768,8 +870,26 @@ class ItemController {
|
|
|
768
870
|
nodeMap,
|
|
769
871
|
zoom,
|
|
770
872
|
theme: itemTheme,
|
|
771
|
-
})
|
|
873
|
+
});
|
|
874
|
+
itemMap.set(id, edgeItem);
|
|
875
|
+
return edgeItem;
|
|
772
876
|
});
|
|
877
|
+
if (delayFirstDraw) {
|
|
878
|
+
let requestId;
|
|
879
|
+
const sectionNum = Math.ceil(items.length / tileFirstRenderSize);
|
|
880
|
+
const sections = Array.from({ length: sectionNum }, (v, i) => items.slice(i * tileFirstRenderSize, i * tileFirstRenderSize + tileFirstRenderSize));
|
|
881
|
+
const update = (resolve) => {
|
|
882
|
+
if (!sections.length) {
|
|
883
|
+
cancelAnimationFrame(requestId);
|
|
884
|
+
return resolve();
|
|
885
|
+
}
|
|
886
|
+
sections.shift().forEach((item) => item.draw(item.displayModel));
|
|
887
|
+
requestId = requestAnimationFrame(() => update(resolve));
|
|
888
|
+
};
|
|
889
|
+
return new Promise((resolve) => {
|
|
890
|
+
requestId = requestAnimationFrame(() => update(resolve));
|
|
891
|
+
});
|
|
892
|
+
}
|
|
773
893
|
}
|
|
774
894
|
/**
|
|
775
895
|
* Get the id of the item which have the state with true value
|
|
@@ -886,7 +1006,7 @@ class ItemController {
|
|
|
886
1006
|
// find the succeeds in collapsed
|
|
887
1007
|
(0, data_1.graphComboTreeDfs)(this.graph, [comboModel], (child) => {
|
|
888
1008
|
if (child.id !== comboModel.id) {
|
|
889
|
-
this.graph.
|
|
1009
|
+
this.graph.executeWithNoStack(() => {
|
|
890
1010
|
this.graph.hideItem(child.id, false);
|
|
891
1011
|
});
|
|
892
1012
|
}
|
|
@@ -908,7 +1028,7 @@ class ItemController {
|
|
|
908
1028
|
pairs.push({ source, target });
|
|
909
1029
|
});
|
|
910
1030
|
// each item in groupedEdges is a virtual edge
|
|
911
|
-
this.graph.
|
|
1031
|
+
this.graph.executeWithNoStack(() => {
|
|
912
1032
|
this.graph.addData('edge', groupVirtualEdges(pairs));
|
|
913
1033
|
});
|
|
914
1034
|
}
|
|
@@ -982,7 +1102,7 @@ class ItemController {
|
|
|
982
1102
|
return false;
|
|
983
1103
|
}));
|
|
984
1104
|
// remove related virtual edges
|
|
985
|
-
this.graph.
|
|
1105
|
+
this.graph.executeWithNoStack(() => {
|
|
986
1106
|
this.graph.removeData('edge', (0, util_1.uniq)(relatedVirtualEdgeIds));
|
|
987
1107
|
this.graph.showItem(edgesToShow.concat(nodesToShow));
|
|
988
1108
|
// add virtual edges by grouping visible ancestor edges
|