@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
|
@@ -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);
|
|
@@ -64,6 +93,17 @@ export class ItemController {
|
|
|
64
93
|
item.update(item.model, undefined, false, itemTheme);
|
|
65
94
|
});
|
|
66
95
|
};
|
|
96
|
+
this.onMapperChange = ({ type, mapper }) => {
|
|
97
|
+
if (!mapper)
|
|
98
|
+
return;
|
|
99
|
+
this.itemMap.forEach((item) => {
|
|
100
|
+
const itemTye = item.getType();
|
|
101
|
+
if (itemTye !== type)
|
|
102
|
+
return;
|
|
103
|
+
item.mapper = mapper;
|
|
104
|
+
item.update(item.model, undefined, false);
|
|
105
|
+
});
|
|
106
|
+
};
|
|
67
107
|
this.onDestroy = () => {
|
|
68
108
|
Object.values(this.itemMap).forEach((item) => item.destroy());
|
|
69
109
|
// Fix OOM problem, since this map will hold all the refs of items.
|
|
@@ -97,6 +137,7 @@ export class ItemController {
|
|
|
97
137
|
this.graph.hooks.transientupdate.tap(this.onTransientUpdate.bind(this));
|
|
98
138
|
this.graph.hooks.viewportchange.tap(this.onViewportChange.bind(this));
|
|
99
139
|
this.graph.hooks.themechange.tap(this.onThemeChange.bind(this));
|
|
140
|
+
this.graph.hooks.mapperchange.tap(this.onMapperChange.bind(this));
|
|
100
141
|
this.graph.hooks.treecollapseexpand.tap(this.onTreeCollapseExpand.bind(this));
|
|
101
142
|
this.graph.hooks.destroy.tap(this.onDestroy.bind(this));
|
|
102
143
|
}
|
|
@@ -126,74 +167,82 @@ export class ItemController {
|
|
|
126
167
|
* @param param contains inner data stored in graphCore structure
|
|
127
168
|
*/
|
|
128
169
|
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
|
-
|
|
170
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
171
|
+
const { graphCore, theme = {}, transientCanvas, tileOptimize = {} } = param;
|
|
172
|
+
const { graph } = this;
|
|
173
|
+
// 0. clear groups on canvas, and create new groups
|
|
174
|
+
graph.canvas.removeChildren();
|
|
175
|
+
const comboGroup = new Group({ id: 'combo-group' });
|
|
176
|
+
const edgeGroup = new Group({ id: 'edge-group' });
|
|
177
|
+
const nodeGroup = new Group({ id: 'node-group' });
|
|
178
|
+
graph.canvas.appendChild(comboGroup);
|
|
179
|
+
graph.canvas.appendChild(edgeGroup);
|
|
180
|
+
graph.canvas.appendChild(nodeGroup);
|
|
181
|
+
this.nodeGroup = nodeGroup;
|
|
182
|
+
this.edgeGroup = edgeGroup;
|
|
183
|
+
this.comboGroup = comboGroup;
|
|
184
|
+
// Also create transient groups on transient canvas.
|
|
185
|
+
transientCanvas.removeChildren();
|
|
186
|
+
this.transientComboGroup = new Group({ id: 'combo-group' });
|
|
187
|
+
this.transientEdgeGroup = new Group({ id: 'edge-group' });
|
|
188
|
+
this.transientNodeGroup = new Group({ id: 'node-group' });
|
|
189
|
+
transientCanvas.appendChild(this.transientComboGroup);
|
|
190
|
+
transientCanvas.appendChild(this.transientEdgeGroup);
|
|
191
|
+
transientCanvas.appendChild(this.transientNodeGroup);
|
|
192
|
+
// 1. create lights for webgl 3d rendering
|
|
193
|
+
if (graph.rendererType === 'webgl-3d') {
|
|
194
|
+
const ambientLight = new AmbientLight({
|
|
195
|
+
style: {
|
|
196
|
+
fill: 'white',
|
|
197
|
+
intensity: Math.PI * 2,
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
const light = new DirectionalLight({
|
|
201
|
+
style: {
|
|
202
|
+
fill: 'white',
|
|
203
|
+
direction: [-1, 0, 1],
|
|
204
|
+
intensity: Math.PI * 0.7,
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
// @ts-ignore
|
|
208
|
+
graph.canvas.appendChild(ambientLight);
|
|
209
|
+
// @ts-ignore
|
|
210
|
+
graph.canvas.appendChild(light);
|
|
211
|
+
const { width, height } = graph.canvas.getConfig();
|
|
212
|
+
graph.canvas.getCamera().setPerspective(0.1, 50000, 45, width / height);
|
|
213
|
+
}
|
|
214
|
+
// 2. create node / edge / combo items, classes from ../../item, and element drawing and updating fns from node/edge/comboExtensions
|
|
215
|
+
const { nodes, edges, combos } = deconstructData({
|
|
216
|
+
nodes: graphCore.getAllNodes(),
|
|
217
|
+
edges: graphCore.getAllEdges(),
|
|
164
218
|
});
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
219
|
+
const renderNodesPromise = this.renderNodes(nodes, theme.node, tileOptimize);
|
|
220
|
+
if (renderNodesPromise) {
|
|
221
|
+
yield renderNodesPromise;
|
|
222
|
+
}
|
|
223
|
+
this.renderCombos(combos, theme.combo, graphCore);
|
|
224
|
+
const renderEdgesPromise = this.renderEdges(edges, theme.edge, tileOptimize);
|
|
225
|
+
if (renderEdgesPromise) {
|
|
226
|
+
yield renderEdgesPromise;
|
|
227
|
+
}
|
|
228
|
+
this.sortByComboTree(graphCore);
|
|
229
|
+
// collapse the combos which has 'collapsed' in initial data
|
|
230
|
+
if (graphCore.hasTreeStructure('combo')) {
|
|
231
|
+
graphCoreTreeDfs(graphCore, graphCore.getRoots('combo'), (child) => {
|
|
232
|
+
if (child.data.collapsed)
|
|
233
|
+
this.collapseCombo(graphCore, child);
|
|
234
|
+
}, 'BT', 'combo');
|
|
235
|
+
}
|
|
236
|
+
// collapse the sub tree which has 'collapsed' in initial data
|
|
237
|
+
if (graphCore.hasTreeStructure('tree')) {
|
|
238
|
+
const collapseNodes = [];
|
|
239
|
+
graphCoreTreeDfs(graphCore, graphCore.getRoots('tree'), (child) => {
|
|
240
|
+
if (child.data.collapsed)
|
|
241
|
+
collapseNodes.push(child);
|
|
242
|
+
}, 'BT', 'tree');
|
|
243
|
+
this.collapseSubTree(collapseNodes, graphCore, false);
|
|
244
|
+
}
|
|
176
245
|
});
|
|
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
246
|
}
|
|
198
247
|
/**
|
|
199
248
|
* Listener of runtime's itemchange lifecycle hook.
|
|
@@ -273,6 +322,10 @@ export class ItemController {
|
|
|
273
322
|
});
|
|
274
323
|
};
|
|
275
324
|
const debounceUpdateRelates = debounce(updateRelates, 16, false);
|
|
325
|
+
const throttleUpdateRelates = throttle(updateRelates, 16, {
|
|
326
|
+
leading: true,
|
|
327
|
+
trailing: true,
|
|
328
|
+
});
|
|
276
329
|
Object.values(nodeComboUpdate).forEach((updateObj) => {
|
|
277
330
|
var _a;
|
|
278
331
|
const { isReplace, previous, current, id } = updateObj;
|
|
@@ -284,12 +337,12 @@ export class ItemController {
|
|
|
284
337
|
return;
|
|
285
338
|
const type = item.getType();
|
|
286
339
|
const innerModel = graphCore.getNode(id);
|
|
287
|
-
if (onlyMove
|
|
288
|
-
|
|
289
|
-
isNaN(
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
340
|
+
if (type === 'node' && onlyMove) {
|
|
341
|
+
const { x, y, fx, fy } = current;
|
|
342
|
+
if (isNaN(x) && isNaN(y) && isNaN(fx) && isNaN(fy)) {
|
|
343
|
+
callback(innerModel, true);
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
293
346
|
}
|
|
294
347
|
const nodeRelatedIdsToUpdate = new Set();
|
|
295
348
|
// collapse and expand
|
|
@@ -350,7 +403,7 @@ export class ItemController {
|
|
|
350
403
|
edgeIdsToUpdate.add(edge.id);
|
|
351
404
|
nodeRelatedIdsToUpdate.add(edge.id);
|
|
352
405
|
});
|
|
353
|
-
item.onframe = () =>
|
|
406
|
+
item.onframe = () => throttleUpdateRelates(nodeRelatedIdsToUpdate);
|
|
354
407
|
let statesCache;
|
|
355
408
|
if (innerModel.data._isCombo &&
|
|
356
409
|
previous.collapsed !== current.collapsed) {
|
|
@@ -373,7 +426,7 @@ export class ItemController {
|
|
|
373
426
|
}));
|
|
374
427
|
const parentItem = this.itemMap.get(current.parentId);
|
|
375
428
|
if (current.parentId && (parentItem === null || parentItem === void 0 ? void 0 : parentItem.model.data.collapsed)) {
|
|
376
|
-
this.graph.
|
|
429
|
+
this.graph.executeWithNoStack(() => {
|
|
377
430
|
this.graph.hideItem(innerModel.id, false);
|
|
378
431
|
});
|
|
379
432
|
}
|
|
@@ -479,7 +532,7 @@ export class ItemController {
|
|
|
479
532
|
});
|
|
480
533
|
}
|
|
481
534
|
onItemVisibilityChange(param) {
|
|
482
|
-
const { ids, value, graphCore, animate = true } = param;
|
|
535
|
+
const { ids, value, graphCore, animate = true, keepKeyShape = false, } = param;
|
|
483
536
|
ids.forEach((id) => {
|
|
484
537
|
const item = this.itemMap.get(id);
|
|
485
538
|
if (!item) {
|
|
@@ -512,7 +565,7 @@ export class ItemController {
|
|
|
512
565
|
}
|
|
513
566
|
}
|
|
514
567
|
else {
|
|
515
|
-
item.hide(animate);
|
|
568
|
+
item.hide(animate, keepKeyShape);
|
|
516
569
|
if (type !== 'edge') {
|
|
517
570
|
const relatedEdges = graphCore.getRelatedEdges(id);
|
|
518
571
|
relatedEdges.forEach(({ id: edgeId }) => {
|
|
@@ -552,9 +605,10 @@ export class ItemController {
|
|
|
552
605
|
});
|
|
553
606
|
}
|
|
554
607
|
onTransientUpdate(param) {
|
|
608
|
+
var _a, _b;
|
|
555
609
|
const { transientObjectMap } = this;
|
|
556
610
|
const { type, id, config = {}, canvas, graphCore } = param;
|
|
557
|
-
const { style = {}, data = {}, capture, action,
|
|
611
|
+
const { style = {}, data = {}, capture, action, shapeIds, drawSource, drawTarget, upsertAncestors, visible = true, } = config;
|
|
558
612
|
const isItemType = type === 'node' || type === 'edge' || type === 'combo';
|
|
559
613
|
// Removing
|
|
560
614
|
if (action === 'remove') {
|
|
@@ -571,6 +625,9 @@ export class ItemController {
|
|
|
571
625
|
}, 'BT');
|
|
572
626
|
}
|
|
573
627
|
if (transientItem && !transientItem.destroyed) {
|
|
628
|
+
if (!((_b = (_a = transientItem).getType) === null || _b === void 0 ? void 0 : _b.call(_a))) {
|
|
629
|
+
transientItem.remove();
|
|
630
|
+
}
|
|
574
631
|
transientItem.destroy();
|
|
575
632
|
}
|
|
576
633
|
this.transientItemMap.delete(id);
|
|
@@ -591,8 +648,8 @@ export class ItemController {
|
|
|
591
648
|
console.warn(`Fail to draw transient item of ${id}, which is not exist.`);
|
|
592
649
|
return;
|
|
593
650
|
}
|
|
594
|
-
const transientItem = upsertTransientItem(item, this.transientNodeGroup, this.transientEdgeGroup, this.transientComboGroup, this.transientItemMap, this.itemMap, graphCore,
|
|
595
|
-
if (
|
|
651
|
+
const transientItem = upsertTransientItem(item, this.transientNodeGroup, this.transientEdgeGroup, this.transientComboGroup, this.transientItemMap, this.itemMap, graphCore, { shapeIds, drawSource, drawTarget, visible }, upsertAncestors);
|
|
652
|
+
if (shapeIds) {
|
|
596
653
|
// only update node positions to cloned node container(group)
|
|
597
654
|
if ((type === 'node' || type === 'combo') &&
|
|
598
655
|
data.hasOwnProperty('x') &&
|
|
@@ -657,84 +714,128 @@ export class ItemController {
|
|
|
657
714
|
* Create nodes with inner data to canvas.
|
|
658
715
|
* @param models nodes' inner datas
|
|
659
716
|
*/
|
|
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
|
-
|
|
717
|
+
renderNodes(models, nodeTheme = {}, tileOptimize) {
|
|
718
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
719
|
+
const { nodeExtensions, nodeGroup, nodeDataTypeSet, graph } = this;
|
|
720
|
+
const { dataTypeField = '' } = nodeTheme;
|
|
721
|
+
const { tileFirstRender, tileFirstRenderSize = 1000 } = tileOptimize || {};
|
|
722
|
+
const zoom = graph.getZoom();
|
|
723
|
+
const delayFirstDraw = isNumber(tileFirstRender)
|
|
724
|
+
? models.length > tileFirstRender
|
|
725
|
+
: tileFirstRender;
|
|
726
|
+
const itemsInView = [];
|
|
727
|
+
const itemsOutView = [];
|
|
728
|
+
const viewRange = this.graph.getCanvasRange();
|
|
729
|
+
models.forEach((node) => {
|
|
730
|
+
// get the base styles from theme
|
|
731
|
+
let dataType;
|
|
732
|
+
if (dataTypeField)
|
|
733
|
+
dataType = node.data[dataTypeField];
|
|
734
|
+
const itemTheme = getItemTheme(nodeDataTypeSet, dataTypeField, dataType, nodeTheme);
|
|
735
|
+
const nodeItem = new Node({
|
|
736
|
+
delayFirstDraw,
|
|
737
|
+
model: node,
|
|
738
|
+
renderExtensions: nodeExtensions,
|
|
739
|
+
containerGroup: nodeGroup,
|
|
740
|
+
mapper: this.nodeMapper,
|
|
741
|
+
stateMapper: this.nodeStateMapper,
|
|
742
|
+
zoom,
|
|
743
|
+
theme: itemTheme,
|
|
744
|
+
device: graph.rendererType === 'webgl-3d'
|
|
745
|
+
? // TODO: G type
|
|
746
|
+
graph.canvas.context.deviceRendererPlugin.getDevice()
|
|
747
|
+
: undefined,
|
|
748
|
+
});
|
|
749
|
+
this.itemMap.set(node.id, nodeItem);
|
|
750
|
+
const { x, y } = nodeItem.model.data;
|
|
751
|
+
if (delayFirstDraw &&
|
|
752
|
+
isPointInBBox({ x: convertToNumber(x), y: convertToNumber(y) }, viewRange)) {
|
|
753
|
+
itemsInView.push(nodeItem);
|
|
754
|
+
}
|
|
755
|
+
else {
|
|
756
|
+
itemsOutView.push(nodeItem);
|
|
757
|
+
}
|
|
758
|
+
});
|
|
759
|
+
if (delayFirstDraw) {
|
|
760
|
+
let requestId;
|
|
761
|
+
const items = itemsInView.concat(itemsOutView);
|
|
762
|
+
const sectionNum = Math.ceil(items.length / tileFirstRenderSize);
|
|
763
|
+
const sections = Array.from({ length: sectionNum }, (v, i) => items.slice(i * tileFirstRenderSize, i * tileFirstRenderSize + tileFirstRenderSize));
|
|
764
|
+
const update = (resolve) => {
|
|
765
|
+
if (!sections.length) {
|
|
766
|
+
cancelAnimationFrame(requestId);
|
|
767
|
+
return resolve();
|
|
768
|
+
}
|
|
769
|
+
sections
|
|
770
|
+
.shift()
|
|
771
|
+
.forEach((item) => item.draw(item.displayModel, undefined, undefined, !item.displayModel.data.disableAnimate));
|
|
772
|
+
requestId = requestAnimationFrame(() => update(resolve));
|
|
773
|
+
};
|
|
774
|
+
return new Promise((resolve) => {
|
|
775
|
+
requestId = requestAnimationFrame(() => update(resolve));
|
|
776
|
+
});
|
|
777
|
+
}
|
|
683
778
|
});
|
|
684
779
|
}
|
|
685
780
|
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
|
-
|
|
781
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
782
|
+
const { comboExtensions, comboGroup, comboDataTypeSet, graph, itemMap } = this;
|
|
783
|
+
const { dataTypeField = '' } = comboTheme;
|
|
784
|
+
const zoom = graph.getZoom();
|
|
785
|
+
models.forEach((combo) => {
|
|
786
|
+
// get the base styles from theme
|
|
787
|
+
let dataType;
|
|
788
|
+
if (dataTypeField)
|
|
789
|
+
dataType = combo.data[dataTypeField];
|
|
790
|
+
const itemTheme = getItemTheme(comboDataTypeSet, dataTypeField, dataType, comboTheme);
|
|
791
|
+
const getCombinedBounds = () => {
|
|
792
|
+
// calculate the position of the combo according to its children
|
|
793
|
+
return getCombinedBoundsByData(graph, graphCore
|
|
794
|
+
.getChildren(combo.id, 'combo')
|
|
795
|
+
.map(({ id }) => itemMap.get(id))
|
|
796
|
+
.filter(Boolean));
|
|
797
|
+
};
|
|
798
|
+
const getChildren = () => {
|
|
799
|
+
const childModels = graphCore.getChildren(combo.id, 'combo');
|
|
800
|
+
return childModels.map(({ id }) => itemMap.get(id));
|
|
801
|
+
};
|
|
802
|
+
const comboItem = new Combo({
|
|
803
|
+
model: combo,
|
|
804
|
+
getCombinedBounds,
|
|
805
|
+
getChildren,
|
|
806
|
+
renderExtensions: comboExtensions,
|
|
807
|
+
containerGroup: comboGroup,
|
|
808
|
+
mapper: this.comboMapper,
|
|
809
|
+
stateMapper: this.comboStateMapper,
|
|
810
|
+
zoom,
|
|
811
|
+
theme: itemTheme,
|
|
812
|
+
device: graph.rendererType === 'webgl-3d'
|
|
813
|
+
? graph.canvas.context.deviceRendererPlugin.getDevice()
|
|
814
|
+
: undefined,
|
|
815
|
+
});
|
|
816
|
+
// ------- for integration tests -------
|
|
817
|
+
comboItem.getCombinedBounds = getCombinedBounds;
|
|
818
|
+
comboItem.getChildren = getChildren;
|
|
819
|
+
comboItem.type = 'combo';
|
|
820
|
+
// ------- for integration tests end-------
|
|
821
|
+
itemMap.set(combo.id, comboItem);
|
|
719
822
|
});
|
|
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
823
|
});
|
|
727
824
|
}
|
|
728
825
|
/**
|
|
729
826
|
* Create edges with inner data to canvas.
|
|
730
827
|
* @param models edges' inner datas
|
|
731
828
|
*/
|
|
732
|
-
renderEdges(models, edgeTheme = {}) {
|
|
829
|
+
renderEdges(models, edgeTheme = {}, tileOptimize) {
|
|
733
830
|
const { edgeExtensions, edgeGroup, itemMap, edgeDataTypeSet, graph } = this;
|
|
734
831
|
const { dataTypeField = '' } = edgeTheme;
|
|
832
|
+
const { tileFirstRender, tileFirstRenderSize = 1000 } = tileOptimize || {};
|
|
735
833
|
const zoom = graph.getZoom();
|
|
736
834
|
const nodeMap = filterItemMapByType(itemMap, 'node');
|
|
737
|
-
|
|
835
|
+
const delayFirstDraw = isNumber(tileFirstRender)
|
|
836
|
+
? models.length > tileFirstRender
|
|
837
|
+
: tileFirstRender;
|
|
838
|
+
const items = models.map((edge) => {
|
|
738
839
|
const { source, target, id } = edge;
|
|
739
840
|
const sourceItem = itemMap.get(source);
|
|
740
841
|
const targetItem = itemMap.get(target);
|
|
@@ -751,7 +852,8 @@ export class ItemController {
|
|
|
751
852
|
if (dataTypeField)
|
|
752
853
|
dataType = edge.data[dataTypeField];
|
|
753
854
|
const itemTheme = getItemTheme(edgeDataTypeSet, dataTypeField, dataType, edgeTheme);
|
|
754
|
-
|
|
855
|
+
const edgeItem = new Edge({
|
|
856
|
+
delayFirstDraw,
|
|
755
857
|
model: edge,
|
|
756
858
|
renderExtensions: edgeExtensions,
|
|
757
859
|
containerGroup: edgeGroup,
|
|
@@ -762,8 +864,26 @@ export class ItemController {
|
|
|
762
864
|
nodeMap,
|
|
763
865
|
zoom,
|
|
764
866
|
theme: itemTheme,
|
|
765
|
-
})
|
|
867
|
+
});
|
|
868
|
+
itemMap.set(id, edgeItem);
|
|
869
|
+
return edgeItem;
|
|
766
870
|
});
|
|
871
|
+
if (delayFirstDraw) {
|
|
872
|
+
let requestId;
|
|
873
|
+
const sectionNum = Math.ceil(items.length / tileFirstRenderSize);
|
|
874
|
+
const sections = Array.from({ length: sectionNum }, (v, i) => items.slice(i * tileFirstRenderSize, i * tileFirstRenderSize + tileFirstRenderSize));
|
|
875
|
+
const update = (resolve) => {
|
|
876
|
+
if (!sections.length) {
|
|
877
|
+
cancelAnimationFrame(requestId);
|
|
878
|
+
return resolve();
|
|
879
|
+
}
|
|
880
|
+
sections.shift().forEach((item) => item.draw(item.displayModel));
|
|
881
|
+
requestId = requestAnimationFrame(() => update(resolve));
|
|
882
|
+
};
|
|
883
|
+
return new Promise((resolve) => {
|
|
884
|
+
requestId = requestAnimationFrame(() => update(resolve));
|
|
885
|
+
});
|
|
886
|
+
}
|
|
767
887
|
}
|
|
768
888
|
/**
|
|
769
889
|
* Get the id of the item which have the state with true value
|
|
@@ -880,7 +1000,7 @@ export class ItemController {
|
|
|
880
1000
|
// find the succeeds in collapsed
|
|
881
1001
|
graphComboTreeDfs(this.graph, [comboModel], (child) => {
|
|
882
1002
|
if (child.id !== comboModel.id) {
|
|
883
|
-
this.graph.
|
|
1003
|
+
this.graph.executeWithNoStack(() => {
|
|
884
1004
|
this.graph.hideItem(child.id, false);
|
|
885
1005
|
});
|
|
886
1006
|
}
|
|
@@ -902,7 +1022,7 @@ export class ItemController {
|
|
|
902
1022
|
pairs.push({ source, target });
|
|
903
1023
|
});
|
|
904
1024
|
// each item in groupedEdges is a virtual edge
|
|
905
|
-
this.graph.
|
|
1025
|
+
this.graph.executeWithNoStack(() => {
|
|
906
1026
|
this.graph.addData('edge', groupVirtualEdges(pairs));
|
|
907
1027
|
});
|
|
908
1028
|
}
|
|
@@ -976,7 +1096,7 @@ export class ItemController {
|
|
|
976
1096
|
return false;
|
|
977
1097
|
}));
|
|
978
1098
|
// remove related virtual edges
|
|
979
|
-
this.graph.
|
|
1099
|
+
this.graph.executeWithNoStack(() => {
|
|
980
1100
|
this.graph.removeData('edge', uniq(relatedVirtualEdgeIds));
|
|
981
1101
|
this.graph.showItem(edgesToShow.concat(nodesToShow));
|
|
982
1102
|
// add virtual edges by grouping visible ancestor edges
|