@antv/g6 5.0.0-beta.3 → 5.0.0-beta.5
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/constant/shape.d.ts +2 -0
- package/esm/index.d.ts +4 -1
- package/esm/index.js +1 -1
- package/esm/item/edge.d.ts +1 -0
- package/esm/item/edge.js +3 -1
- 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 +1 -0
- package/esm/item/node.js +11 -4
- package/esm/item/node.js.map +1 -1
- package/esm/runtime/controller/item.js +252 -148
- package/esm/runtime/controller/item.js.map +1 -1
- package/esm/runtime/graph.d.ts +16 -14
- package/esm/runtime/graph.js +66 -28
- 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/click-select.js +1 -1
- package/esm/stdlib/behavior/click-select.js.map +1 -1
- package/esm/stdlib/behavior/drag-canvas.js +50 -27
- package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
- package/esm/stdlib/behavior/drag-combo.js +8 -8
- package/esm/stdlib/behavior/drag-combo.js.map +1 -1
- package/esm/stdlib/behavior/drag-node.js +10 -10
- package/esm/stdlib/behavior/drag-node.js.map +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 +3 -0
- package/esm/stdlib/index.js +12 -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 +18 -26
- package/esm/stdlib/item/node/base.js.map +1 -1
- package/esm/stdlib/item/node/diamond.js +1 -1
- package/esm/stdlib/item/node/ellipse.js +2 -2
- package/esm/stdlib/item/node/hexagon.js +6 -2
- package/esm/stdlib/item/node/hexagon.js.map +1 -1
- package/esm/stdlib/item/node/image.d.ts +40 -0
- package/esm/stdlib/item/node/image.js +110 -0
- package/esm/stdlib/item/node/image.js.map +1 -0
- 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/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/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/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/stdlib/theme/dark.js +42 -2
- package/esm/stdlib/theme/dark.js.map +1 -1
- package/esm/stdlib/theme/light.js +4 -4
- package/esm/types/graph.d.ts +14 -14
- package/esm/types/hook.d.ts +6 -0
- package/esm/types/item.d.ts +6 -0
- package/esm/types/item.js.map +1 -1
- package/esm/types/spec.d.ts +13 -0
- 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/shape.js +2 -2
- package/esm/util/shape.js.map +1 -1
- package/lib/constant/shape.d.ts +2 -0
- package/lib/index.d.ts +4 -1
- package/lib/index.js +1 -1
- package/lib/item/edge.d.ts +1 -0
- package/lib/item/edge.js +3 -1
- 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 +1 -0
- package/lib/item/node.js +11 -4
- package/lib/item/node.js.map +1 -1
- package/lib/runtime/controller/item.js +251 -147
- package/lib/runtime/controller/item.js.map +1 -1
- package/lib/runtime/graph.d.ts +16 -14
- package/lib/runtime/graph.js +66 -28
- 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/click-select.js +1 -1
- package/lib/stdlib/behavior/click-select.js.map +1 -1
- package/lib/stdlib/behavior/drag-canvas.js +50 -27
- package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
- package/lib/stdlib/behavior/drag-combo.js +8 -8
- package/lib/stdlib/behavior/drag-combo.js.map +1 -1
- package/lib/stdlib/behavior/drag-node.js +10 -10
- package/lib/stdlib/behavior/drag-node.js.map +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 +3 -0
- package/lib/stdlib/index.js +12 -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 +18 -26
- package/lib/stdlib/item/node/base.js.map +1 -1
- package/lib/stdlib/item/node/diamond.js +1 -1
- package/lib/stdlib/item/node/ellipse.js +2 -2
- package/lib/stdlib/item/node/hexagon.js +6 -2
- package/lib/stdlib/item/node/hexagon.js.map +1 -1
- package/lib/stdlib/item/node/image.d.ts +40 -0
- package/lib/stdlib/item/node/image.js +114 -0
- package/lib/stdlib/item/node/image.js.map +1 -0
- 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/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/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/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/stdlib/theme/dark.js +42 -2
- package/lib/stdlib/theme/dark.js.map +1 -1
- package/lib/stdlib/theme/light.js +4 -4
- package/lib/types/graph.d.ts +14 -14
- package/lib/types/hook.d.ts +6 -0
- package/lib/types/item.d.ts +6 -0
- package/lib/types/item.js.map +1 -1
- package/lib/types/spec.d.ts +13 -0
- 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/shape.js +2 -2
- package/lib/util/shape.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +1 -1
- package/src/item/edge.ts +4 -1
- package/src/item/item.ts +11 -6
- package/src/item/node.ts +18 -10
- package/src/runtime/controller/item.ts +212 -66
- package/src/runtime/graph.ts +91 -29
- package/src/stdlib/behavior/activate-relations.ts +2 -2
- package/src/stdlib/behavior/click-select.ts +1 -1
- package/src/stdlib/behavior/drag-canvas.ts +65 -27
- package/src/stdlib/behavior/drag-combo.ts +8 -8
- package/src/stdlib/behavior/drag-node.ts +10 -10
- package/src/stdlib/behavior/zoom-canvas.ts +60 -24
- package/src/stdlib/index.ts +12 -7
- package/src/stdlib/item/edge/base.ts +13 -5
- package/src/stdlib/item/node/base.ts +24 -29
- package/src/stdlib/item/node/diamond.ts +1 -1
- package/src/stdlib/item/node/ellipse.ts +2 -2
- package/src/stdlib/item/node/hexagon.ts +6 -2
- package/src/stdlib/item/node/image.ts +190 -0
- package/src/stdlib/item/node/index.ts +1 -0
- 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/index.ts +1 -0
- package/src/stdlib/plugin/snapline/index.ts +1277 -0
- package/src/stdlib/plugin/types.ts +1 -0
- package/src/stdlib/theme/dark.ts +66 -2
- package/src/stdlib/theme/light.ts +4 -4
- package/src/types/graph.ts +22 -17
- package/src/types/hook.ts +6 -0
- package/src/types/item.ts +10 -0
- package/src/types/spec.ts +13 -0
- package/src/util/bbox.ts +38 -1
- package/src/util/shape.ts +2 -2
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { Group } from '@antv/g';
|
|
11
|
-
import { debounce, each, isArray, isObject, map, throttle, uniq, uniqueId, } from '@antv/util';
|
|
11
|
+
import { debounce, each, isArray, isNumber, isObject, map, throttle, uniq, uniqueId, } from '@antv/util';
|
|
12
12
|
import { DirectionalLight, AmbientLight } from '@antv/g-plugin-3d';
|
|
13
13
|
import registry from '../../stdlib';
|
|
14
14
|
import Node from '../../item/node';
|
|
@@ -21,6 +21,8 @@ import { formatLodStrategy } from '../../util/zoom';
|
|
|
21
21
|
import { deconstructData, graphComboTreeDfs, graphCoreTreeDfs, traverseAncestors, traverseAncestorsAndSucceeds, traverseGraphAncestors, } from '../../util/data';
|
|
22
22
|
import { getGroupedChanges } from '../../util/event';
|
|
23
23
|
import { EdgeCollisionChecker, QuadTree } from '../../util/polyline';
|
|
24
|
+
import { isBBoxInBBox, isPointInBBox } from '../../util/bbox';
|
|
25
|
+
import { convertToNumber } from '../../util/type';
|
|
24
26
|
/**
|
|
25
27
|
* Manages and stores the node / edge / combo items.
|
|
26
28
|
*/
|
|
@@ -39,11 +41,38 @@ export class ItemController {
|
|
|
39
41
|
// The G shapes or groups on transient map drawn by this controller
|
|
40
42
|
this.transientObjectMap = new Map();
|
|
41
43
|
this.transientItemMap = new Map();
|
|
42
|
-
this.onViewportChange = debounce(({ transform, effectTiming }) => {
|
|
44
|
+
this.onViewportChange = debounce(({ transform, effectTiming, tileLodSize = 1000, }) => {
|
|
43
45
|
const { zoom } = transform;
|
|
44
46
|
if (zoom) {
|
|
45
47
|
const zoomRatio = this.graph.getZoom();
|
|
46
|
-
this.
|
|
48
|
+
const range = this.graph.getCanvasRange();
|
|
49
|
+
const nodeItems = Array.from(this.itemMap, ([key, value]) => value);
|
|
50
|
+
const itemsInViewport = [];
|
|
51
|
+
const itemsOutViewport = [];
|
|
52
|
+
nodeItems.forEach((item) => {
|
|
53
|
+
const { keyShape } = item.shapeMap;
|
|
54
|
+
if (!keyShape)
|
|
55
|
+
return;
|
|
56
|
+
const renderBounds = keyShape.getRenderBounds();
|
|
57
|
+
if (isBBoxInBBox(renderBounds, range, 0.4))
|
|
58
|
+
itemsInViewport.push(item);
|
|
59
|
+
else
|
|
60
|
+
itemsOutViewport.push(item);
|
|
61
|
+
});
|
|
62
|
+
const sortedItems = itemsInViewport.concat(itemsOutViewport);
|
|
63
|
+
const sections = Math.ceil(nodeItems.length / tileLodSize);
|
|
64
|
+
const itemSections = Array.from({ length: sections }, (v, i) => sortedItems.slice(i * tileLodSize, i * tileLodSize + tileLodSize));
|
|
65
|
+
let requestId;
|
|
66
|
+
const update = () => {
|
|
67
|
+
if (!itemSections.length) {
|
|
68
|
+
cancelAnimationFrame(requestId);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
itemSections.shift().forEach((item) => item.updateZoom(zoomRatio));
|
|
72
|
+
requestId = requestAnimationFrame(update);
|
|
73
|
+
};
|
|
74
|
+
requestId = requestAnimationFrame(update);
|
|
75
|
+
// this.itemMap.forEach((item) => item.updateZoom(zoomRatio));
|
|
47
76
|
this.zoom = zoomRatio;
|
|
48
77
|
}
|
|
49
78
|
}, 500, false);
|
|
@@ -126,74 +155,82 @@ export class ItemController {
|
|
|
126
155
|
* @param param contains inner data stored in graphCore structure
|
|
127
156
|
*/
|
|
128
157
|
onRender(param) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
|
|
158
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
+
const { graphCore, theme = {}, transientCanvas, tileOptimize = {} } = param;
|
|
160
|
+
const { graph } = this;
|
|
161
|
+
// 0. clear groups on canvas, and create new groups
|
|
162
|
+
graph.canvas.removeChildren();
|
|
163
|
+
const comboGroup = new Group({ id: 'combo-group' });
|
|
164
|
+
const edgeGroup = new Group({ id: 'edge-group' });
|
|
165
|
+
const nodeGroup = new Group({ id: 'node-group' });
|
|
166
|
+
graph.canvas.appendChild(comboGroup);
|
|
167
|
+
graph.canvas.appendChild(edgeGroup);
|
|
168
|
+
graph.canvas.appendChild(nodeGroup);
|
|
169
|
+
this.nodeGroup = nodeGroup;
|
|
170
|
+
this.edgeGroup = edgeGroup;
|
|
171
|
+
this.comboGroup = comboGroup;
|
|
172
|
+
// Also create transient groups on transient canvas.
|
|
173
|
+
transientCanvas.removeChildren();
|
|
174
|
+
this.transientComboGroup = new Group({ id: 'combo-group' });
|
|
175
|
+
this.transientEdgeGroup = new Group({ id: 'edge-group' });
|
|
176
|
+
this.transientNodeGroup = new Group({ id: 'node-group' });
|
|
177
|
+
transientCanvas.appendChild(this.transientComboGroup);
|
|
178
|
+
transientCanvas.appendChild(this.transientEdgeGroup);
|
|
179
|
+
transientCanvas.appendChild(this.transientNodeGroup);
|
|
180
|
+
// 1. create lights for webgl 3d rendering
|
|
181
|
+
if (graph.rendererType === 'webgl-3d') {
|
|
182
|
+
const ambientLight = new AmbientLight({
|
|
183
|
+
style: {
|
|
184
|
+
fill: 'white',
|
|
185
|
+
intensity: Math.PI * 2,
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
const light = new DirectionalLight({
|
|
189
|
+
style: {
|
|
190
|
+
fill: 'white',
|
|
191
|
+
direction: [-1, 0, 1],
|
|
192
|
+
intensity: Math.PI * 0.7,
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
// @ts-ignore
|
|
196
|
+
graph.canvas.appendChild(ambientLight);
|
|
197
|
+
// @ts-ignore
|
|
198
|
+
graph.canvas.appendChild(light);
|
|
199
|
+
const { width, height } = graph.canvas.getConfig();
|
|
200
|
+
graph.canvas.getCamera().setPerspective(0.1, 50000, 45, width / height);
|
|
201
|
+
}
|
|
202
|
+
// 2. create node / edge / combo items, classes from ../../item, and element drawing and updating fns from node/edge/comboExtensions
|
|
203
|
+
const { nodes, edges, combos } = deconstructData({
|
|
204
|
+
nodes: graphCore.getAllNodes(),
|
|
205
|
+
edges: graphCore.getAllEdges(),
|
|
164
206
|
});
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
207
|
+
const renderNodesPromise = this.renderNodes(nodes, theme.node, tileOptimize);
|
|
208
|
+
if (renderNodesPromise) {
|
|
209
|
+
yield renderNodesPromise;
|
|
210
|
+
}
|
|
211
|
+
this.renderCombos(combos, theme.combo, graphCore);
|
|
212
|
+
const renderEdgesPromise = this.renderEdges(edges, theme.edge, tileOptimize);
|
|
213
|
+
if (renderEdgesPromise) {
|
|
214
|
+
yield renderEdgesPromise;
|
|
215
|
+
}
|
|
216
|
+
this.sortByComboTree(graphCore);
|
|
217
|
+
// collapse the combos which has 'collapsed' in initial data
|
|
218
|
+
if (graphCore.hasTreeStructure('combo')) {
|
|
219
|
+
graphCoreTreeDfs(graphCore, graphCore.getRoots('combo'), (child) => {
|
|
220
|
+
if (child.data.collapsed)
|
|
221
|
+
this.collapseCombo(graphCore, child);
|
|
222
|
+
}, 'BT', 'combo');
|
|
223
|
+
}
|
|
224
|
+
// collapse the sub tree which has 'collapsed' in initial data
|
|
225
|
+
if (graphCore.hasTreeStructure('tree')) {
|
|
226
|
+
const collapseNodes = [];
|
|
227
|
+
graphCoreTreeDfs(graphCore, graphCore.getRoots('tree'), (child) => {
|
|
228
|
+
if (child.data.collapsed)
|
|
229
|
+
collapseNodes.push(child);
|
|
230
|
+
}, 'BT', 'tree');
|
|
231
|
+
this.collapseSubTree(collapseNodes, graphCore, false);
|
|
232
|
+
}
|
|
176
233
|
});
|
|
177
|
-
this.renderNodes(nodes, theme.node);
|
|
178
|
-
this.renderCombos(combos, theme.combo, graphCore);
|
|
179
|
-
this.renderEdges(edges, theme.edge);
|
|
180
|
-
this.sortByComboTree(graphCore);
|
|
181
|
-
// collapse the combos which has 'collapsed' in initial data
|
|
182
|
-
if (graphCore.hasTreeStructure('combo')) {
|
|
183
|
-
graphCoreTreeDfs(graphCore, graphCore.getRoots('combo'), (child) => {
|
|
184
|
-
if (child.data.collapsed)
|
|
185
|
-
this.collapseCombo(graphCore, child);
|
|
186
|
-
}, 'BT', 'combo');
|
|
187
|
-
}
|
|
188
|
-
// collapse the sub tree which has 'collapsed' in initial data
|
|
189
|
-
if (graphCore.hasTreeStructure('tree')) {
|
|
190
|
-
const collapseNodes = [];
|
|
191
|
-
graphCoreTreeDfs(graphCore, graphCore.getRoots('tree'), (child) => {
|
|
192
|
-
if (child.data.collapsed)
|
|
193
|
-
collapseNodes.push(child);
|
|
194
|
-
}, 'BT', 'tree');
|
|
195
|
-
this.collapseSubTree(collapseNodes, graphCore, false);
|
|
196
|
-
}
|
|
197
234
|
}
|
|
198
235
|
/**
|
|
199
236
|
* Listener of runtime's itemchange lifecycle hook.
|
|
@@ -273,6 +310,10 @@ export class ItemController {
|
|
|
273
310
|
});
|
|
274
311
|
};
|
|
275
312
|
const debounceUpdateRelates = debounce(updateRelates, 16, false);
|
|
313
|
+
const throttleUpdateRelates = throttle(updateRelates, 16, {
|
|
314
|
+
leading: true,
|
|
315
|
+
trailing: true,
|
|
316
|
+
});
|
|
276
317
|
Object.values(nodeComboUpdate).forEach((updateObj) => {
|
|
277
318
|
var _a;
|
|
278
319
|
const { isReplace, previous, current, id } = updateObj;
|
|
@@ -284,12 +325,12 @@ export class ItemController {
|
|
|
284
325
|
return;
|
|
285
326
|
const type = item.getType();
|
|
286
327
|
const innerModel = graphCore.getNode(id);
|
|
287
|
-
if (onlyMove
|
|
288
|
-
|
|
289
|
-
isNaN(
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
328
|
+
if (type === 'node' && onlyMove) {
|
|
329
|
+
const { x, y, fx, fy } = current;
|
|
330
|
+
if (isNaN(x) && isNaN(y) && isNaN(fx) && isNaN(fy)) {
|
|
331
|
+
callback(innerModel, true);
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
293
334
|
}
|
|
294
335
|
const nodeRelatedIdsToUpdate = new Set();
|
|
295
336
|
// collapse and expand
|
|
@@ -350,7 +391,7 @@ export class ItemController {
|
|
|
350
391
|
edgeIdsToUpdate.add(edge.id);
|
|
351
392
|
nodeRelatedIdsToUpdate.add(edge.id);
|
|
352
393
|
});
|
|
353
|
-
item.onframe = () =>
|
|
394
|
+
item.onframe = () => throttleUpdateRelates(nodeRelatedIdsToUpdate);
|
|
354
395
|
let statesCache;
|
|
355
396
|
if (innerModel.data._isCombo &&
|
|
356
397
|
previous.collapsed !== current.collapsed) {
|
|
@@ -373,7 +414,7 @@ export class ItemController {
|
|
|
373
414
|
}));
|
|
374
415
|
const parentItem = this.itemMap.get(current.parentId);
|
|
375
416
|
if (current.parentId && (parentItem === null || parentItem === void 0 ? void 0 : parentItem.model.data.collapsed)) {
|
|
376
|
-
this.graph.
|
|
417
|
+
this.graph.executeWithNoStack(() => {
|
|
377
418
|
this.graph.hideItem(innerModel.id, false);
|
|
378
419
|
});
|
|
379
420
|
}
|
|
@@ -479,7 +520,7 @@ export class ItemController {
|
|
|
479
520
|
});
|
|
480
521
|
}
|
|
481
522
|
onItemVisibilityChange(param) {
|
|
482
|
-
const { ids, value, graphCore, animate = true } = param;
|
|
523
|
+
const { ids, value, graphCore, animate = true, keepKeyShape = false, } = param;
|
|
483
524
|
ids.forEach((id) => {
|
|
484
525
|
const item = this.itemMap.get(id);
|
|
485
526
|
if (!item) {
|
|
@@ -512,7 +553,7 @@ export class ItemController {
|
|
|
512
553
|
}
|
|
513
554
|
}
|
|
514
555
|
else {
|
|
515
|
-
item.hide(animate);
|
|
556
|
+
item.hide(animate, keepKeyShape);
|
|
516
557
|
if (type !== 'edge') {
|
|
517
558
|
const relatedEdges = graphCore.getRelatedEdges(id);
|
|
518
559
|
relatedEdges.forEach(({ id: edgeId }) => {
|
|
@@ -657,84 +698,128 @@ export class ItemController {
|
|
|
657
698
|
* Create nodes with inner data to canvas.
|
|
658
699
|
* @param models nodes' inner datas
|
|
659
700
|
*/
|
|
660
|
-
renderNodes(models, nodeTheme = {}) {
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
const
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
:
|
|
682
|
-
|
|
701
|
+
renderNodes(models, nodeTheme = {}, tileOptimize) {
|
|
702
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
703
|
+
const { nodeExtensions, nodeGroup, nodeDataTypeSet, graph } = this;
|
|
704
|
+
const { dataTypeField = '' } = nodeTheme;
|
|
705
|
+
const { tileFirstRender, tileFirstRenderSize = 1000 } = tileOptimize || {};
|
|
706
|
+
const zoom = graph.getZoom();
|
|
707
|
+
const delayFirstDraw = isNumber(tileFirstRender)
|
|
708
|
+
? models.length > tileFirstRender
|
|
709
|
+
: tileFirstRender;
|
|
710
|
+
const itemsInView = [];
|
|
711
|
+
const itemsOutView = [];
|
|
712
|
+
const viewRange = this.graph.getCanvasRange();
|
|
713
|
+
models.forEach((node) => {
|
|
714
|
+
// get the base styles from theme
|
|
715
|
+
let dataType;
|
|
716
|
+
if (dataTypeField)
|
|
717
|
+
dataType = node.data[dataTypeField];
|
|
718
|
+
const itemTheme = getItemTheme(nodeDataTypeSet, dataTypeField, dataType, nodeTheme);
|
|
719
|
+
const nodeItem = new Node({
|
|
720
|
+
delayFirstDraw,
|
|
721
|
+
model: node,
|
|
722
|
+
renderExtensions: nodeExtensions,
|
|
723
|
+
containerGroup: nodeGroup,
|
|
724
|
+
mapper: this.nodeMapper,
|
|
725
|
+
stateMapper: this.nodeStateMapper,
|
|
726
|
+
zoom,
|
|
727
|
+
theme: itemTheme,
|
|
728
|
+
device: graph.rendererType === 'webgl-3d'
|
|
729
|
+
? // TODO: G type
|
|
730
|
+
graph.canvas.context.deviceRendererPlugin.getDevice()
|
|
731
|
+
: undefined,
|
|
732
|
+
});
|
|
733
|
+
this.itemMap.set(node.id, nodeItem);
|
|
734
|
+
const { x, y } = nodeItem.model.data;
|
|
735
|
+
if (delayFirstDraw &&
|
|
736
|
+
isPointInBBox({ x: convertToNumber(x), y: convertToNumber(y) }, viewRange)) {
|
|
737
|
+
itemsInView.push(nodeItem);
|
|
738
|
+
}
|
|
739
|
+
else {
|
|
740
|
+
itemsOutView.push(nodeItem);
|
|
741
|
+
}
|
|
742
|
+
});
|
|
743
|
+
if (delayFirstDraw) {
|
|
744
|
+
let requestId;
|
|
745
|
+
const items = itemsInView.concat(itemsOutView);
|
|
746
|
+
const sectionNum = Math.ceil(items.length / tileFirstRenderSize);
|
|
747
|
+
const sections = Array.from({ length: sectionNum }, (v, i) => items.slice(i * tileFirstRenderSize, i * tileFirstRenderSize + tileFirstRenderSize));
|
|
748
|
+
const update = (resolve) => {
|
|
749
|
+
if (!sections.length) {
|
|
750
|
+
cancelAnimationFrame(requestId);
|
|
751
|
+
return resolve();
|
|
752
|
+
}
|
|
753
|
+
sections
|
|
754
|
+
.shift()
|
|
755
|
+
.forEach((item) => item.draw(item.displayModel, undefined, undefined, !item.displayModel.data.disableAnimate));
|
|
756
|
+
requestId = requestAnimationFrame(() => update(resolve));
|
|
757
|
+
};
|
|
758
|
+
return new Promise((resolve) => {
|
|
759
|
+
requestId = requestAnimationFrame(() => update(resolve));
|
|
760
|
+
});
|
|
761
|
+
}
|
|
683
762
|
});
|
|
684
763
|
}
|
|
685
764
|
renderCombos(models, comboTheme = {}, graphCore) {
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
const
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
765
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
766
|
+
const { comboExtensions, comboGroup, comboDataTypeSet, graph, itemMap } = this;
|
|
767
|
+
const { dataTypeField = '' } = comboTheme;
|
|
768
|
+
const zoom = graph.getZoom();
|
|
769
|
+
models.forEach((combo) => {
|
|
770
|
+
// get the base styles from theme
|
|
771
|
+
let dataType;
|
|
772
|
+
if (dataTypeField)
|
|
773
|
+
dataType = combo.data[dataTypeField];
|
|
774
|
+
const itemTheme = getItemTheme(comboDataTypeSet, dataTypeField, dataType, comboTheme);
|
|
775
|
+
const getCombinedBounds = () => {
|
|
776
|
+
// calculate the position of the combo according to its children
|
|
777
|
+
return getCombinedBoundsByData(graph, graphCore
|
|
778
|
+
.getChildren(combo.id, 'combo')
|
|
779
|
+
.map(({ id }) => itemMap.get(id))
|
|
780
|
+
.filter(Boolean));
|
|
781
|
+
};
|
|
782
|
+
const getChildren = () => {
|
|
783
|
+
const childModels = graphCore.getChildren(combo.id, 'combo');
|
|
784
|
+
return childModels.map(({ id }) => itemMap.get(id));
|
|
785
|
+
};
|
|
786
|
+
const comboItem = new Combo({
|
|
787
|
+
model: combo,
|
|
788
|
+
getCombinedBounds,
|
|
789
|
+
getChildren,
|
|
790
|
+
renderExtensions: comboExtensions,
|
|
791
|
+
containerGroup: comboGroup,
|
|
792
|
+
mapper: this.comboMapper,
|
|
793
|
+
stateMapper: this.comboStateMapper,
|
|
794
|
+
zoom,
|
|
795
|
+
theme: itemTheme,
|
|
796
|
+
device: graph.rendererType === 'webgl-3d'
|
|
797
|
+
? graph.canvas.context.deviceRendererPlugin.getDevice()
|
|
798
|
+
: undefined,
|
|
799
|
+
});
|
|
800
|
+
// ------- for integration tests -------
|
|
801
|
+
comboItem.getCombinedBounds = getCombinedBounds;
|
|
802
|
+
comboItem.getChildren = getChildren;
|
|
803
|
+
comboItem.type = 'combo';
|
|
804
|
+
// ------- for integration tests end-------
|
|
805
|
+
itemMap.set(combo.id, comboItem);
|
|
719
806
|
});
|
|
720
|
-
// ------- for integration tests -------
|
|
721
|
-
comboItem.getCombinedBounds = getCombinedBounds;
|
|
722
|
-
comboItem.getChildren = getChildren;
|
|
723
|
-
comboItem.type = 'combo';
|
|
724
|
-
// ------- for integration tests end-------
|
|
725
|
-
itemMap.set(combo.id, comboItem);
|
|
726
807
|
});
|
|
727
808
|
}
|
|
728
809
|
/**
|
|
729
810
|
* Create edges with inner data to canvas.
|
|
730
811
|
* @param models edges' inner datas
|
|
731
812
|
*/
|
|
732
|
-
renderEdges(models, edgeTheme = {}) {
|
|
813
|
+
renderEdges(models, edgeTheme = {}, tileOptimize) {
|
|
733
814
|
const { edgeExtensions, edgeGroup, itemMap, edgeDataTypeSet, graph } = this;
|
|
734
815
|
const { dataTypeField = '' } = edgeTheme;
|
|
816
|
+
const { tileFirstRender, tileFirstRenderSize = 1000 } = tileOptimize || {};
|
|
735
817
|
const zoom = graph.getZoom();
|
|
736
818
|
const nodeMap = filterItemMapByType(itemMap, 'node');
|
|
737
|
-
|
|
819
|
+
const delayFirstDraw = isNumber(tileFirstRender)
|
|
820
|
+
? models.length > tileFirstRender
|
|
821
|
+
: tileFirstRender;
|
|
822
|
+
const items = models.map((edge) => {
|
|
738
823
|
const { source, target, id } = edge;
|
|
739
824
|
const sourceItem = itemMap.get(source);
|
|
740
825
|
const targetItem = itemMap.get(target);
|
|
@@ -751,7 +836,8 @@ export class ItemController {
|
|
|
751
836
|
if (dataTypeField)
|
|
752
837
|
dataType = edge.data[dataTypeField];
|
|
753
838
|
const itemTheme = getItemTheme(edgeDataTypeSet, dataTypeField, dataType, edgeTheme);
|
|
754
|
-
|
|
839
|
+
const edgeItem = new Edge({
|
|
840
|
+
delayFirstDraw,
|
|
755
841
|
model: edge,
|
|
756
842
|
renderExtensions: edgeExtensions,
|
|
757
843
|
containerGroup: edgeGroup,
|
|
@@ -762,8 +848,26 @@ export class ItemController {
|
|
|
762
848
|
nodeMap,
|
|
763
849
|
zoom,
|
|
764
850
|
theme: itemTheme,
|
|
765
|
-
})
|
|
851
|
+
});
|
|
852
|
+
itemMap.set(id, edgeItem);
|
|
853
|
+
return edgeItem;
|
|
766
854
|
});
|
|
855
|
+
if (delayFirstDraw) {
|
|
856
|
+
let requestId;
|
|
857
|
+
const sectionNum = Math.ceil(items.length / tileFirstRenderSize);
|
|
858
|
+
const sections = Array.from({ length: sectionNum }, (v, i) => items.slice(i * tileFirstRenderSize, i * tileFirstRenderSize + tileFirstRenderSize));
|
|
859
|
+
const update = (resolve) => {
|
|
860
|
+
if (!sections.length) {
|
|
861
|
+
cancelAnimationFrame(requestId);
|
|
862
|
+
return resolve();
|
|
863
|
+
}
|
|
864
|
+
sections.shift().forEach((item) => item.draw(item.displayModel));
|
|
865
|
+
requestId = requestAnimationFrame(() => update(resolve));
|
|
866
|
+
};
|
|
867
|
+
return new Promise((resolve) => {
|
|
868
|
+
requestId = requestAnimationFrame(() => update(resolve));
|
|
869
|
+
});
|
|
870
|
+
}
|
|
767
871
|
}
|
|
768
872
|
/**
|
|
769
873
|
* Get the id of the item which have the state with true value
|
|
@@ -880,7 +984,7 @@ export class ItemController {
|
|
|
880
984
|
// find the succeeds in collapsed
|
|
881
985
|
graphComboTreeDfs(this.graph, [comboModel], (child) => {
|
|
882
986
|
if (child.id !== comboModel.id) {
|
|
883
|
-
this.graph.
|
|
987
|
+
this.graph.executeWithNoStack(() => {
|
|
884
988
|
this.graph.hideItem(child.id, false);
|
|
885
989
|
});
|
|
886
990
|
}
|
|
@@ -902,7 +1006,7 @@ export class ItemController {
|
|
|
902
1006
|
pairs.push({ source, target });
|
|
903
1007
|
});
|
|
904
1008
|
// each item in groupedEdges is a virtual edge
|
|
905
|
-
this.graph.
|
|
1009
|
+
this.graph.executeWithNoStack(() => {
|
|
906
1010
|
this.graph.addData('edge', groupVirtualEdges(pairs));
|
|
907
1011
|
});
|
|
908
1012
|
}
|
|
@@ -976,7 +1080,7 @@ export class ItemController {
|
|
|
976
1080
|
return false;
|
|
977
1081
|
}));
|
|
978
1082
|
// remove related virtual edges
|
|
979
|
-
this.graph.
|
|
1083
|
+
this.graph.executeWithNoStack(() => {
|
|
980
1084
|
this.graph.removeData('edge', uniq(relatedVirtualEdgeIds));
|
|
981
1085
|
this.graph.showItem(edgesToShow.concat(nodesToShow));
|
|
982
1086
|
// add virtual edges by grouping visible ancestor edges
|