@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
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
debounce,
|
|
5
5
|
each,
|
|
6
6
|
isArray,
|
|
7
|
+
isNumber,
|
|
7
8
|
isObject,
|
|
8
9
|
map,
|
|
9
10
|
throttle,
|
|
@@ -64,6 +65,8 @@ import { getGroupedChanges } from '../../util/event';
|
|
|
64
65
|
import { BaseNode } from '../../stdlib/item/node/base';
|
|
65
66
|
import { BaseEdge } from '../../stdlib/item/edge/base';
|
|
66
67
|
import { EdgeCollisionChecker, QuadTree } from '../../util/polyline';
|
|
68
|
+
import { isBBoxInBBox, isPointInBBox } from '../../util/bbox';
|
|
69
|
+
import { convertToNumber } from '../../util/type';
|
|
67
70
|
|
|
68
71
|
/**
|
|
69
72
|
* Manages and stores the node / edge / combo items.
|
|
@@ -174,6 +177,7 @@ export class ItemController {
|
|
|
174
177
|
this.graph.hooks.transientupdate.tap(this.onTransientUpdate.bind(this));
|
|
175
178
|
this.graph.hooks.viewportchange.tap(this.onViewportChange.bind(this));
|
|
176
179
|
this.graph.hooks.themechange.tap(this.onThemeChange.bind(this));
|
|
180
|
+
this.graph.hooks.mapperchange.tap(this.onMapperChange.bind(this));
|
|
177
181
|
this.graph.hooks.treecollapseexpand.tap(
|
|
178
182
|
this.onTreeCollapseExpand.bind(this),
|
|
179
183
|
);
|
|
@@ -207,12 +211,16 @@ export class ItemController {
|
|
|
207
211
|
* Listener of runtime's render hook.
|
|
208
212
|
* @param param contains inner data stored in graphCore structure
|
|
209
213
|
*/
|
|
210
|
-
private onRender(param: {
|
|
214
|
+
private async onRender(param: {
|
|
211
215
|
graphCore: GraphCore;
|
|
212
216
|
theme: ThemeSpecification;
|
|
213
217
|
transientCanvas: Canvas;
|
|
218
|
+
tileOptimize?: {
|
|
219
|
+
tileFirstRender?: boolean | number;
|
|
220
|
+
tileFirstRenderSize?: number;
|
|
221
|
+
};
|
|
214
222
|
}) {
|
|
215
|
-
const { graphCore, theme = {}, transientCanvas } = param;
|
|
223
|
+
const { graphCore, theme = {}, transientCanvas, tileOptimize = {} } = param;
|
|
216
224
|
const { graph } = this;
|
|
217
225
|
|
|
218
226
|
// 0. clear groups on canvas, and create new groups
|
|
@@ -265,9 +273,23 @@ export class ItemController {
|
|
|
265
273
|
edges: graphCore.getAllEdges(),
|
|
266
274
|
});
|
|
267
275
|
|
|
268
|
-
this.renderNodes(
|
|
276
|
+
const renderNodesPromise = this.renderNodes(
|
|
277
|
+
nodes,
|
|
278
|
+
theme.node,
|
|
279
|
+
tileOptimize,
|
|
280
|
+
);
|
|
281
|
+
if (renderNodesPromise) {
|
|
282
|
+
await renderNodesPromise;
|
|
283
|
+
}
|
|
269
284
|
this.renderCombos(combos, theme.combo, graphCore);
|
|
270
|
-
this.renderEdges(
|
|
285
|
+
const renderEdgesPromise = this.renderEdges(
|
|
286
|
+
edges,
|
|
287
|
+
theme.edge,
|
|
288
|
+
tileOptimize,
|
|
289
|
+
);
|
|
290
|
+
if (renderEdgesPromise) {
|
|
291
|
+
await renderEdgesPromise;
|
|
292
|
+
}
|
|
271
293
|
this.sortByComboTree(graphCore);
|
|
272
294
|
// collapse the combos which has 'collapsed' in initial data
|
|
273
295
|
if (graphCore.hasTreeStructure('combo')) {
|
|
@@ -406,6 +428,10 @@ export class ItemController {
|
|
|
406
428
|
});
|
|
407
429
|
};
|
|
408
430
|
const debounceUpdateRelates = debounce(updateRelates, 16, false);
|
|
431
|
+
const throttleUpdateRelates = throttle(updateRelates, 16, {
|
|
432
|
+
leading: true,
|
|
433
|
+
trailing: true,
|
|
434
|
+
});
|
|
409
435
|
|
|
410
436
|
Object.values(nodeComboUpdate).forEach((updateObj: any) => {
|
|
411
437
|
const { isReplace, previous, current, id } = updateObj;
|
|
@@ -415,14 +441,12 @@ export class ItemController {
|
|
|
415
441
|
if (!item || item.destroyed) return;
|
|
416
442
|
const type = item.getType();
|
|
417
443
|
const innerModel = graphCore.getNode(id);
|
|
418
|
-
if (
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
callback(innerModel, true);
|
|
425
|
-
return;
|
|
444
|
+
if (type === 'node' && onlyMove) {
|
|
445
|
+
const { x, y, fx, fy } = current;
|
|
446
|
+
if (isNaN(x) && isNaN(y) && isNaN(fx) && isNaN(fy)) {
|
|
447
|
+
callback(innerModel, true);
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
426
450
|
}
|
|
427
451
|
|
|
428
452
|
const nodeRelatedIdsToUpdate: Set<ID> = new Set<ID>();
|
|
@@ -503,7 +527,7 @@ export class ItemController {
|
|
|
503
527
|
nodeRelatedIdsToUpdate.add(edge.id);
|
|
504
528
|
});
|
|
505
529
|
|
|
506
|
-
item.onframe = () =>
|
|
530
|
+
item.onframe = () => throttleUpdateRelates(nodeRelatedIdsToUpdate);
|
|
507
531
|
let statesCache;
|
|
508
532
|
if (
|
|
509
533
|
innerModel.data._isCombo &&
|
|
@@ -541,7 +565,7 @@ export class ItemController {
|
|
|
541
565
|
|
|
542
566
|
const parentItem = this.itemMap.get(current.parentId);
|
|
543
567
|
if (current.parentId && parentItem?.model.data.collapsed) {
|
|
544
|
-
this.graph.
|
|
568
|
+
this.graph.executeWithNoStack(() => {
|
|
545
569
|
this.graph.hideItem(innerModel.id, false);
|
|
546
570
|
});
|
|
547
571
|
}
|
|
@@ -669,8 +693,15 @@ export class ItemController {
|
|
|
669
693
|
value: boolean;
|
|
670
694
|
graphCore: GraphCore;
|
|
671
695
|
animate?: boolean;
|
|
696
|
+
keepKeyShape?: boolean;
|
|
672
697
|
}) {
|
|
673
|
-
const {
|
|
698
|
+
const {
|
|
699
|
+
ids,
|
|
700
|
+
value,
|
|
701
|
+
graphCore,
|
|
702
|
+
animate = true,
|
|
703
|
+
keepKeyShape = false,
|
|
704
|
+
} = param;
|
|
674
705
|
ids.forEach((id) => {
|
|
675
706
|
const item = this.itemMap.get(id);
|
|
676
707
|
if (!item) {
|
|
@@ -700,7 +731,7 @@ export class ItemController {
|
|
|
700
731
|
});
|
|
701
732
|
}
|
|
702
733
|
} else {
|
|
703
|
-
item.hide(animate);
|
|
734
|
+
item.hide(animate, keepKeyShape);
|
|
704
735
|
if (type !== 'edge') {
|
|
705
736
|
const relatedEdges = graphCore.getRelatedEdges(id);
|
|
706
737
|
relatedEdges.forEach(({ id: edgeId }) => {
|
|
@@ -747,11 +778,42 @@ export class ItemController {
|
|
|
747
778
|
}
|
|
748
779
|
|
|
749
780
|
private onViewportChange = debounce(
|
|
750
|
-
({
|
|
781
|
+
({
|
|
782
|
+
transform,
|
|
783
|
+
effectTiming,
|
|
784
|
+
tileLodSize = 1000,
|
|
785
|
+
}: ViewportChangeHookParams) => {
|
|
751
786
|
const { zoom } = transform;
|
|
752
787
|
if (zoom) {
|
|
753
788
|
const zoomRatio = this.graph.getZoom();
|
|
754
|
-
this.
|
|
789
|
+
const range = this.graph.getCanvasRange();
|
|
790
|
+
const nodeItems = Array.from(this.itemMap, ([key, value]) => value);
|
|
791
|
+
const itemsInViewport = [];
|
|
792
|
+
const itemsOutViewport = [];
|
|
793
|
+
nodeItems.forEach((item) => {
|
|
794
|
+
const { keyShape } = item.shapeMap;
|
|
795
|
+
if (!keyShape) return;
|
|
796
|
+
const renderBounds = keyShape.getRenderBounds();
|
|
797
|
+
if (isBBoxInBBox(renderBounds, range, 0.4))
|
|
798
|
+
itemsInViewport.push(item);
|
|
799
|
+
else itemsOutViewport.push(item);
|
|
800
|
+
});
|
|
801
|
+
const sortedItems = itemsInViewport.concat(itemsOutViewport);
|
|
802
|
+
const sections = Math.ceil(nodeItems.length / tileLodSize);
|
|
803
|
+
const itemSections = Array.from({ length: sections }, (v, i) =>
|
|
804
|
+
sortedItems.slice(i * tileLodSize, i * tileLodSize + tileLodSize),
|
|
805
|
+
);
|
|
806
|
+
let requestId;
|
|
807
|
+
const update = () => {
|
|
808
|
+
if (!itemSections.length) {
|
|
809
|
+
cancelAnimationFrame(requestId);
|
|
810
|
+
return;
|
|
811
|
+
}
|
|
812
|
+
itemSections.shift().forEach((item) => item.updateZoom(zoomRatio));
|
|
813
|
+
requestId = requestAnimationFrame(update);
|
|
814
|
+
};
|
|
815
|
+
requestId = requestAnimationFrame(update);
|
|
816
|
+
// this.itemMap.forEach((item) => item.updateZoom(zoomRatio));
|
|
755
817
|
this.zoom = zoomRatio;
|
|
756
818
|
}
|
|
757
819
|
},
|
|
@@ -789,6 +851,16 @@ export class ItemController {
|
|
|
789
851
|
});
|
|
790
852
|
};
|
|
791
853
|
|
|
854
|
+
private onMapperChange = ({ type, mapper }) => {
|
|
855
|
+
if (!mapper) return;
|
|
856
|
+
this.itemMap.forEach((item) => {
|
|
857
|
+
const itemTye = item.getType();
|
|
858
|
+
if (itemTye !== type) return;
|
|
859
|
+
item.mapper = mapper;
|
|
860
|
+
item.update(item.model, undefined, false);
|
|
861
|
+
});
|
|
862
|
+
};
|
|
863
|
+
|
|
792
864
|
private onDestroy = () => {
|
|
793
865
|
Object.values(this.itemMap).forEach((item) => item.destroy());
|
|
794
866
|
// Fix OOM problem, since this map will hold all the refs of items.
|
|
@@ -799,12 +871,17 @@ export class ItemController {
|
|
|
799
871
|
type: ITEM_TYPE | SHAPE_TYPE;
|
|
800
872
|
id: ID;
|
|
801
873
|
config: {
|
|
874
|
+
action: 'remove' | 'add' | 'update' | undefined;
|
|
802
875
|
style?: ShapeStyle;
|
|
803
|
-
|
|
876
|
+
/** Data to be merged into the transient item. */
|
|
804
877
|
data?: Record<string, any>;
|
|
805
|
-
|
|
806
|
-
|
|
878
|
+
shapeIds?: string[];
|
|
879
|
+
/** For type: 'edge' */
|
|
880
|
+
drawSource?: boolean;
|
|
881
|
+
/** For type: 'edge' */
|
|
882
|
+
drawTarget?: boolean;
|
|
807
883
|
upsertAncestors?: boolean;
|
|
884
|
+
visible?: boolean;
|
|
808
885
|
[shapeConfig: string]: unknown;
|
|
809
886
|
};
|
|
810
887
|
canvas: Canvas;
|
|
@@ -817,8 +894,11 @@ export class ItemController {
|
|
|
817
894
|
data = {},
|
|
818
895
|
capture,
|
|
819
896
|
action,
|
|
820
|
-
|
|
897
|
+
shapeIds,
|
|
898
|
+
drawSource,
|
|
899
|
+
drawTarget,
|
|
821
900
|
upsertAncestors,
|
|
901
|
+
visible = true,
|
|
822
902
|
} = config as any;
|
|
823
903
|
const isItemType = type === 'node' || type === 'edge' || type === 'combo';
|
|
824
904
|
// Removing
|
|
@@ -841,6 +921,9 @@ export class ItemController {
|
|
|
841
921
|
);
|
|
842
922
|
}
|
|
843
923
|
if (transientItem && !transientItem.destroyed) {
|
|
924
|
+
if (!(transientItem as Node | Edge | Combo).getType?.()) {
|
|
925
|
+
(transientItem as Group).remove();
|
|
926
|
+
}
|
|
844
927
|
transientItem.destroy();
|
|
845
928
|
}
|
|
846
929
|
this.transientItemMap.delete(id);
|
|
@@ -869,11 +952,11 @@ export class ItemController {
|
|
|
869
952
|
this.transientItemMap,
|
|
870
953
|
this.itemMap,
|
|
871
954
|
graphCore,
|
|
872
|
-
|
|
955
|
+
{ shapeIds, drawSource, drawTarget, visible },
|
|
873
956
|
upsertAncestors,
|
|
874
957
|
);
|
|
875
958
|
|
|
876
|
-
if (
|
|
959
|
+
if (shapeIds) {
|
|
877
960
|
// only update node positions to cloned node container(group)
|
|
878
961
|
if (
|
|
879
962
|
(type === 'node' || type === 'combo') &&
|
|
@@ -972,13 +1055,24 @@ export class ItemController {
|
|
|
972
1055
|
* Create nodes with inner data to canvas.
|
|
973
1056
|
* @param models nodes' inner datas
|
|
974
1057
|
*/
|
|
975
|
-
private renderNodes(
|
|
1058
|
+
private async renderNodes(
|
|
976
1059
|
models: NodeModel[],
|
|
977
1060
|
nodeTheme: NodeThemeSpecifications = {},
|
|
978
|
-
|
|
1061
|
+
tileOptimize?: {
|
|
1062
|
+
tileFirstRender?: boolean | number;
|
|
1063
|
+
tileFirstRenderSize?: number;
|
|
1064
|
+
},
|
|
1065
|
+
): Promise<any> | undefined {
|
|
979
1066
|
const { nodeExtensions, nodeGroup, nodeDataTypeSet, graph } = this;
|
|
980
1067
|
const { dataTypeField = '' } = nodeTheme;
|
|
1068
|
+
const { tileFirstRender, tileFirstRenderSize = 1000 } = tileOptimize || {};
|
|
981
1069
|
const zoom = graph.getZoom();
|
|
1070
|
+
const delayFirstDraw = isNumber(tileFirstRender)
|
|
1071
|
+
? models.length > tileFirstRender
|
|
1072
|
+
: tileFirstRender;
|
|
1073
|
+
const itemsInView = [];
|
|
1074
|
+
const itemsOutView = [];
|
|
1075
|
+
const viewRange = this.graph.getCanvasRange();
|
|
982
1076
|
models.forEach((node) => {
|
|
983
1077
|
// get the base styles from theme
|
|
984
1078
|
let dataType;
|
|
@@ -990,30 +1084,73 @@ export class ItemController {
|
|
|
990
1084
|
nodeTheme,
|
|
991
1085
|
);
|
|
992
1086
|
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
);
|
|
1087
|
+
const nodeItem = new Node({
|
|
1088
|
+
delayFirstDraw,
|
|
1089
|
+
model: node,
|
|
1090
|
+
renderExtensions: nodeExtensions,
|
|
1091
|
+
containerGroup: nodeGroup,
|
|
1092
|
+
mapper: this.nodeMapper,
|
|
1093
|
+
stateMapper: this.nodeStateMapper,
|
|
1094
|
+
zoom,
|
|
1095
|
+
theme: itemTheme as {
|
|
1096
|
+
styles: NodeStyleSet;
|
|
1097
|
+
lodStrategy: LodStrategyObj;
|
|
1098
|
+
},
|
|
1099
|
+
device:
|
|
1100
|
+
graph.rendererType === 'webgl-3d'
|
|
1101
|
+
? // TODO: G type
|
|
1102
|
+
(graph.canvas.context as any).deviceRendererPlugin.getDevice()
|
|
1103
|
+
: undefined,
|
|
1104
|
+
});
|
|
1105
|
+
|
|
1106
|
+
this.itemMap.set(node.id, nodeItem);
|
|
1107
|
+
const { x, y } = nodeItem.model.data;
|
|
1108
|
+
if (
|
|
1109
|
+
delayFirstDraw &&
|
|
1110
|
+
isPointInBBox(
|
|
1111
|
+
{ x: convertToNumber(x), y: convertToNumber(y) },
|
|
1112
|
+
viewRange,
|
|
1113
|
+
)
|
|
1114
|
+
) {
|
|
1115
|
+
itemsInView.push(nodeItem);
|
|
1116
|
+
} else {
|
|
1117
|
+
itemsOutView.push(nodeItem);
|
|
1118
|
+
}
|
|
1013
1119
|
});
|
|
1120
|
+
if (delayFirstDraw) {
|
|
1121
|
+
let requestId;
|
|
1122
|
+
const items = itemsInView.concat(itemsOutView);
|
|
1123
|
+
const sectionNum = Math.ceil(items.length / tileFirstRenderSize);
|
|
1124
|
+
const sections = Array.from({ length: sectionNum }, (v, i) =>
|
|
1125
|
+
items.slice(
|
|
1126
|
+
i * tileFirstRenderSize,
|
|
1127
|
+
i * tileFirstRenderSize + tileFirstRenderSize,
|
|
1128
|
+
),
|
|
1129
|
+
);
|
|
1130
|
+
const update = (resolve) => {
|
|
1131
|
+
if (!sections.length) {
|
|
1132
|
+
cancelAnimationFrame(requestId);
|
|
1133
|
+
return resolve();
|
|
1134
|
+
}
|
|
1135
|
+
sections
|
|
1136
|
+
.shift()
|
|
1137
|
+
.forEach((item) =>
|
|
1138
|
+
item.draw(
|
|
1139
|
+
item.displayModel as NodeDisplayModel | ComboDisplayModel,
|
|
1140
|
+
undefined,
|
|
1141
|
+
undefined,
|
|
1142
|
+
!item.displayModel.data.disableAnimate,
|
|
1143
|
+
),
|
|
1144
|
+
);
|
|
1145
|
+
requestId = requestAnimationFrame(() => update(resolve));
|
|
1146
|
+
};
|
|
1147
|
+
return new Promise((resolve) => {
|
|
1148
|
+
requestId = requestAnimationFrame(() => update(resolve));
|
|
1149
|
+
});
|
|
1150
|
+
}
|
|
1014
1151
|
}
|
|
1015
1152
|
|
|
1016
|
-
private renderCombos(
|
|
1153
|
+
private async renderCombos(
|
|
1017
1154
|
models: ComboModel[],
|
|
1018
1155
|
comboTheme: ComboThemeSpecifications = {},
|
|
1019
1156
|
graphCore: GraphCore,
|
|
@@ -1084,12 +1221,20 @@ export class ItemController {
|
|
|
1084
1221
|
private renderEdges(
|
|
1085
1222
|
models: EdgeModel[],
|
|
1086
1223
|
edgeTheme: EdgeThemeSpecifications = {},
|
|
1087
|
-
|
|
1224
|
+
tileOptimize?: {
|
|
1225
|
+
tileFirstRender?: boolean | number;
|
|
1226
|
+
tileFirstRenderSize?: number;
|
|
1227
|
+
},
|
|
1228
|
+
): Promise<any> | undefined {
|
|
1088
1229
|
const { edgeExtensions, edgeGroup, itemMap, edgeDataTypeSet, graph } = this;
|
|
1089
1230
|
const { dataTypeField = '' } = edgeTheme;
|
|
1231
|
+
const { tileFirstRender, tileFirstRenderSize = 1000 } = tileOptimize || {};
|
|
1090
1232
|
const zoom = graph.getZoom();
|
|
1091
1233
|
const nodeMap = filterItemMapByType(itemMap, 'node') as Map<ID, Node>;
|
|
1092
|
-
|
|
1234
|
+
const delayFirstDraw = isNumber(tileFirstRender)
|
|
1235
|
+
? models.length > tileFirstRender
|
|
1236
|
+
: tileFirstRender;
|
|
1237
|
+
const items = models.map((edge) => {
|
|
1093
1238
|
const { source, target, id } = edge;
|
|
1094
1239
|
const sourceItem = itemMap.get(source) as Node;
|
|
1095
1240
|
const targetItem = itemMap.get(target) as Node;
|
|
@@ -1115,27 +1260,50 @@ export class ItemController {
|
|
|
1115
1260
|
edgeTheme,
|
|
1116
1261
|
);
|
|
1117
1262
|
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
);
|
|
1263
|
+
const edgeItem = new Edge({
|
|
1264
|
+
delayFirstDraw,
|
|
1265
|
+
model: edge,
|
|
1266
|
+
renderExtensions: edgeExtensions,
|
|
1267
|
+
containerGroup: edgeGroup,
|
|
1268
|
+
mapper: this.edgeMapper as DisplayMapper,
|
|
1269
|
+
stateMapper: this.edgeStateMapper as {
|
|
1270
|
+
[stateName: string]: DisplayMapper;
|
|
1271
|
+
},
|
|
1272
|
+
sourceItem,
|
|
1273
|
+
targetItem,
|
|
1274
|
+
nodeMap,
|
|
1275
|
+
zoom,
|
|
1276
|
+
theme: itemTheme as {
|
|
1277
|
+
styles: EdgeStyleSet;
|
|
1278
|
+
lodStrategy: LodStrategyObj;
|
|
1279
|
+
},
|
|
1280
|
+
});
|
|
1281
|
+
|
|
1282
|
+
itemMap.set(id, edgeItem);
|
|
1283
|
+
return edgeItem;
|
|
1138
1284
|
});
|
|
1285
|
+
|
|
1286
|
+
if (delayFirstDraw) {
|
|
1287
|
+
let requestId;
|
|
1288
|
+
const sectionNum = Math.ceil(items.length / tileFirstRenderSize);
|
|
1289
|
+
const sections = Array.from({ length: sectionNum }, (v, i) =>
|
|
1290
|
+
items.slice(
|
|
1291
|
+
i * tileFirstRenderSize,
|
|
1292
|
+
i * tileFirstRenderSize + tileFirstRenderSize,
|
|
1293
|
+
),
|
|
1294
|
+
);
|
|
1295
|
+
const update = (resolve) => {
|
|
1296
|
+
if (!sections.length) {
|
|
1297
|
+
cancelAnimationFrame(requestId);
|
|
1298
|
+
return resolve();
|
|
1299
|
+
}
|
|
1300
|
+
sections.shift().forEach((item) => item.draw(item.displayModel));
|
|
1301
|
+
requestId = requestAnimationFrame(() => update(resolve));
|
|
1302
|
+
};
|
|
1303
|
+
return new Promise((resolve) => {
|
|
1304
|
+
requestId = requestAnimationFrame(() => update(resolve));
|
|
1305
|
+
});
|
|
1306
|
+
}
|
|
1139
1307
|
}
|
|
1140
1308
|
|
|
1141
1309
|
/**
|
|
@@ -1288,7 +1456,7 @@ export class ItemController {
|
|
|
1288
1456
|
// find the succeeds in collapsed
|
|
1289
1457
|
graphComboTreeDfs(this.graph, [comboModel], (child) => {
|
|
1290
1458
|
if (child.id !== comboModel.id) {
|
|
1291
|
-
this.graph.
|
|
1459
|
+
this.graph.executeWithNoStack(() => {
|
|
1292
1460
|
this.graph.hideItem(child.id, false);
|
|
1293
1461
|
});
|
|
1294
1462
|
}
|
|
@@ -1308,7 +1476,7 @@ export class ItemController {
|
|
|
1308
1476
|
pairs.push({ source, target });
|
|
1309
1477
|
});
|
|
1310
1478
|
// each item in groupedEdges is a virtual edge
|
|
1311
|
-
this.graph.
|
|
1479
|
+
this.graph.executeWithNoStack(() => {
|
|
1312
1480
|
this.graph.addData('edge', groupVirtualEdges(pairs));
|
|
1313
1481
|
});
|
|
1314
1482
|
}
|
|
@@ -1391,7 +1559,7 @@ export class ItemController {
|
|
|
1391
1559
|
);
|
|
1392
1560
|
|
|
1393
1561
|
// remove related virtual edges
|
|
1394
|
-
this.graph.
|
|
1562
|
+
this.graph.executeWithNoStack(() => {
|
|
1395
1563
|
this.graph.removeData('edge', uniq(relatedVirtualEdgeIds));
|
|
1396
1564
|
this.graph.showItem(edgesToShow.concat(nodesToShow));
|
|
1397
1565
|
// add virtual edges by grouping visible ancestor edges
|