@antv/g6 5.0.0-beta.26 → 5.0.0-beta.27
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 +1 -1
- package/esm/index.d.ts +3 -1
- package/esm/index.js +1 -1
- package/esm/item/combo.d.ts +6 -4
- package/esm/item/combo.js +10 -3
- package/esm/item/combo.js.map +1 -1
- package/esm/item/edge.d.ts +12 -4
- package/esm/item/edge.js +100 -17
- package/esm/item/edge.js.map +1 -1
- package/esm/item/item.d.ts +18 -8
- package/esm/item/item.js +103 -59
- package/esm/item/item.js.map +1 -1
- package/esm/item/node.d.ts +10 -4
- package/esm/item/node.js +92 -8
- package/esm/item/node.js.map +1 -1
- package/esm/runtime/controller/data.d.ts +5 -1
- package/esm/runtime/controller/data.js +38 -1
- package/esm/runtime/controller/data.js.map +1 -1
- package/esm/runtime/controller/index.d.ts +1 -1
- package/esm/runtime/controller/index.js +1 -1
- package/esm/runtime/controller/index.js.map +1 -1
- package/esm/runtime/controller/item.d.ts +22 -11
- package/esm/runtime/controller/item.js +241 -96
- package/esm/runtime/controller/item.js.map +1 -1
- package/esm/runtime/controller/layout.d.ts +3 -0
- package/esm/runtime/controller/layout.js +178 -98
- package/esm/runtime/controller/layout.js.map +1 -1
- package/esm/runtime/controller/plugin.d.ts +3 -0
- package/esm/runtime/controller/plugin.js +66 -24
- package/esm/runtime/controller/plugin.js.map +1 -1
- package/esm/runtime/controller/viewport.js +9 -2
- package/esm/runtime/controller/viewport.js.map +1 -1
- package/esm/runtime/graph.d.ts +57 -26
- package/esm/runtime/graph.js +263 -139
- package/esm/runtime/graph.js.map +1 -1
- package/esm/stdlib/behavior/click-select.js +9 -3
- package/esm/stdlib/behavior/click-select.js.map +1 -1
- package/esm/stdlib/behavior/drag-canvas.js +6 -3
- 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.d.ts +4 -0
- package/esm/stdlib/behavior/drag-node.js +121 -27
- package/esm/stdlib/behavior/drag-node.js.map +1 -1
- package/esm/stdlib/behavior/scroll-canvas.js +3 -3
- package/esm/stdlib/behavior/scroll-canvas.js.map +1 -1
- package/esm/stdlib/behavior/zoom-canvas.js +3 -3
- package/esm/stdlib/behavior/zoom-canvas.js.map +1 -1
- package/esm/stdlib/data/mapNodeSize.js +2 -2
- package/esm/stdlib/data/mapNodeSize.js.map +1 -1
- package/esm/stdlib/data/validateData.js +2 -2
- package/esm/stdlib/data/validateData.js.map +1 -1
- package/esm/stdlib/index.d.ts +2 -0
- package/esm/stdlib/index.js +3 -1
- package/esm/stdlib/index.js.map +1 -1
- package/esm/stdlib/item/edge/base.d.ts +2 -11
- package/esm/stdlib/item/edge/base.js +12 -105
- package/esm/stdlib/item/edge/base.js.map +1 -1
- package/esm/stdlib/item/node/base.d.ts +2 -20
- package/esm/stdlib/item/node/base.js +10 -150
- package/esm/stdlib/item/node/base.js.map +1 -1
- package/esm/stdlib/plugin/edgeFilterLens/index.js +2 -2
- package/esm/stdlib/plugin/edgeFilterLens/index.js.map +1 -1
- package/esm/stdlib/plugin/fisheye/index.js +3 -2
- package/esm/stdlib/plugin/fisheye/index.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/index.d.ts +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/lodController/index.d.ts +73 -0
- package/esm/stdlib/plugin/lodController/index.js +556 -0
- package/esm/stdlib/plugin/lodController/index.js.map +1 -0
- package/esm/stdlib/plugin/minimap/index.js +12 -14
- package/esm/stdlib/plugin/minimap/index.js.map +1 -1
- package/esm/stdlib/plugin/toolbar/index.d.ts +2 -2
- package/esm/stdlib/plugin/toolbar/index.js +27 -29
- package/esm/stdlib/plugin/toolbar/index.js.map +1 -1
- package/esm/stdlib/theme/dark.js +32 -35
- package/esm/stdlib/theme/dark.js.map +1 -1
- package/esm/stdlib/theme/light.js +27 -30
- package/esm/stdlib/theme/light.js.map +1 -1
- package/esm/stdlib/themeSolver/spec.js +2 -2
- package/esm/stdlib/themeSolver/spec.js.map +1 -1
- package/esm/types/animate.d.ts +1 -1
- package/esm/types/combo.d.ts +2 -2
- package/esm/types/edge.d.ts +2 -2
- package/esm/types/graph.d.ts +62 -43
- package/esm/types/hook.d.ts +5 -0
- package/esm/types/item.d.ts +9 -15
- package/esm/types/layout.d.ts +7 -2
- package/esm/types/layout.js.map +1 -1
- package/esm/types/node.d.ts +3 -2
- package/esm/types/plugin.d.ts +1 -0
- package/esm/types/plugin.js +1 -0
- package/esm/types/plugin.js.map +1 -1
- package/esm/types/spec.d.ts +1 -0
- package/esm/types/theme.d.ts +7 -7
- package/esm/util/animate.d.ts +7 -2
- package/esm/util/animate.js +37 -23
- package/esm/util/animate.js.map +1 -1
- package/esm/util/bbox.d.ts +7 -1
- package/esm/util/bbox.js +16 -0
- package/esm/util/bbox.js.map +1 -1
- package/esm/util/data.d.ts +7 -1
- package/esm/util/data.js +17 -5
- package/esm/util/data.js.map +1 -1
- package/esm/util/dom.js +5 -5
- package/esm/util/dom.js.map +1 -1
- package/esm/util/item.d.ts +1 -1
- package/esm/util/item.js +8 -8
- package/esm/util/item.js.map +1 -1
- package/esm/util/mapper.js +1 -1
- package/esm/util/mapper.js.map +1 -1
- package/esm/util/path.d.ts +6 -1
- package/esm/util/path.js +72 -1
- package/esm/util/path.js.map +1 -1
- package/esm/util/polyline.d.ts +10 -0
- package/esm/util/polyline.js +22 -17
- package/esm/util/polyline.js.map +1 -1
- package/esm/util/router.d.ts +1 -1
- package/esm/util/router.js +19 -18
- package/esm/util/router.js.map +1 -1
- package/esm/util/shape.d.ts +1 -1
- package/esm/util/shape.js +28 -13
- package/esm/util/shape.js.map +1 -1
- package/esm/util/zoom.d.ts +5 -8
- package/esm/util/zoom.js +15 -20
- package/esm/util/zoom.js.map +1 -1
- package/lib/constant/shape.d.ts +1 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.js +1 -1
- package/lib/item/combo.d.ts +6 -4
- package/lib/item/combo.js +10 -3
- package/lib/item/combo.js.map +1 -1
- package/lib/item/edge.d.ts +12 -4
- package/lib/item/edge.js +99 -16
- package/lib/item/edge.js.map +1 -1
- package/lib/item/item.d.ts +18 -8
- package/lib/item/item.js +101 -57
- package/lib/item/item.js.map +1 -1
- package/lib/item/node.d.ts +10 -4
- package/lib/item/node.js +92 -8
- package/lib/item/node.js.map +1 -1
- package/lib/runtime/controller/data.d.ts +5 -1
- package/lib/runtime/controller/data.js +38 -1
- package/lib/runtime/controller/data.js.map +1 -1
- package/lib/runtime/controller/index.d.ts +1 -1
- package/lib/runtime/controller/index.js +1 -1
- package/lib/runtime/controller/index.js.map +1 -1
- package/lib/runtime/controller/item.d.ts +22 -11
- package/lib/runtime/controller/item.js +238 -93
- package/lib/runtime/controller/item.js.map +1 -1
- package/lib/runtime/controller/layout.d.ts +3 -0
- package/lib/runtime/controller/layout.js +178 -98
- package/lib/runtime/controller/layout.js.map +1 -1
- package/lib/runtime/controller/plugin.d.ts +3 -0
- package/lib/runtime/controller/plugin.js +66 -24
- package/lib/runtime/controller/plugin.js.map +1 -1
- package/lib/runtime/controller/viewport.js +9 -2
- package/lib/runtime/controller/viewport.js.map +1 -1
- package/lib/runtime/graph.d.ts +57 -26
- package/lib/runtime/graph.js +263 -139
- package/lib/runtime/graph.js.map +1 -1
- package/lib/stdlib/behavior/click-select.js +9 -3
- package/lib/stdlib/behavior/click-select.js.map +1 -1
- package/lib/stdlib/behavior/drag-canvas.js +6 -3
- 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.d.ts +4 -0
- package/lib/stdlib/behavior/drag-node.js +121 -27
- package/lib/stdlib/behavior/drag-node.js.map +1 -1
- package/lib/stdlib/behavior/scroll-canvas.js +3 -3
- package/lib/stdlib/behavior/scroll-canvas.js.map +1 -1
- package/lib/stdlib/behavior/zoom-canvas.js +3 -3
- package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
- package/lib/stdlib/data/mapNodeSize.js +2 -2
- package/lib/stdlib/data/mapNodeSize.js.map +1 -1
- package/lib/stdlib/data/validateData.js +2 -2
- package/lib/stdlib/data/validateData.js.map +1 -1
- package/lib/stdlib/index.d.ts +2 -0
- package/lib/stdlib/index.js +3 -1
- package/lib/stdlib/index.js.map +1 -1
- package/lib/stdlib/item/edge/base.d.ts +2 -11
- package/lib/stdlib/item/edge/base.js +12 -105
- package/lib/stdlib/item/edge/base.js.map +1 -1
- package/lib/stdlib/item/node/base.d.ts +2 -20
- package/lib/stdlib/item/node/base.js +10 -150
- package/lib/stdlib/item/node/base.js.map +1 -1
- package/lib/stdlib/plugin/edgeFilterLens/index.js +2 -2
- package/lib/stdlib/plugin/edgeFilterLens/index.js.map +1 -1
- package/lib/stdlib/plugin/fisheye/index.js +2 -1
- package/lib/stdlib/plugin/fisheye/index.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/index.d.ts +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/lodController/index.d.ts +73 -0
- package/lib/stdlib/plugin/lodController/index.js +560 -0
- package/lib/stdlib/plugin/lodController/index.js.map +1 -0
- package/lib/stdlib/plugin/minimap/index.js +12 -14
- package/lib/stdlib/plugin/minimap/index.js.map +1 -1
- package/lib/stdlib/plugin/toolbar/index.d.ts +2 -2
- package/lib/stdlib/plugin/toolbar/index.js +27 -29
- package/lib/stdlib/plugin/toolbar/index.js.map +1 -1
- package/lib/stdlib/theme/dark.js +32 -35
- package/lib/stdlib/theme/dark.js.map +1 -1
- package/lib/stdlib/theme/light.js +27 -30
- package/lib/stdlib/theme/light.js.map +1 -1
- package/lib/stdlib/themeSolver/spec.js +2 -2
- package/lib/stdlib/themeSolver/spec.js.map +1 -1
- package/lib/types/animate.d.ts +1 -1
- package/lib/types/combo.d.ts +2 -2
- package/lib/types/edge.d.ts +2 -2
- package/lib/types/graph.d.ts +62 -43
- package/lib/types/hook.d.ts +5 -0
- package/lib/types/item.d.ts +9 -15
- package/lib/types/layout.d.ts +7 -2
- package/lib/types/layout.js.map +1 -1
- package/lib/types/node.d.ts +3 -2
- package/lib/types/plugin.d.ts +1 -0
- package/lib/types/plugin.js +1 -0
- package/lib/types/plugin.js.map +1 -1
- package/lib/types/spec.d.ts +1 -0
- package/lib/types/theme.d.ts +7 -7
- package/lib/util/animate.d.ts +7 -2
- package/lib/util/animate.js +37 -23
- package/lib/util/animate.js.map +1 -1
- package/lib/util/bbox.d.ts +7 -1
- package/lib/util/bbox.js +18 -1
- package/lib/util/bbox.js.map +1 -1
- package/lib/util/data.d.ts +7 -1
- package/lib/util/data.js +19 -6
- package/lib/util/data.js.map +1 -1
- package/lib/util/dom.js +5 -5
- package/lib/util/dom.js.map +1 -1
- package/lib/util/item.d.ts +1 -1
- package/lib/util/item.js +8 -8
- package/lib/util/item.js.map +1 -1
- package/lib/util/mapper.js +1 -1
- package/lib/util/mapper.js.map +1 -1
- package/lib/util/path.d.ts +6 -1
- package/lib/util/path.js +72 -1
- package/lib/util/path.js.map +1 -1
- package/lib/util/polyline.d.ts +10 -0
- package/lib/util/polyline.js +25 -18
- package/lib/util/polyline.js.map +1 -1
- package/lib/util/router.d.ts +1 -1
- package/lib/util/router.js +19 -18
- package/lib/util/router.js.map +1 -1
- package/lib/util/shape.d.ts +1 -1
- package/lib/util/shape.js +27 -12
- package/lib/util/shape.js.map +1 -1
- package/lib/util/zoom.d.ts +5 -8
- package/lib/util/zoom.js +17 -22
- package/lib/util/zoom.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/item/combo.ts +13 -5
- package/src/item/edge.ts +126 -17
- package/src/item/item.ts +119 -57
- package/src/item/node.ts +108 -11
- package/src/runtime/controller/data.ts +64 -3
- package/src/runtime/controller/index.ts +1 -1
- package/src/runtime/controller/item.ts +321 -135
- package/src/runtime/controller/layout.ts +254 -113
- package/src/runtime/controller/plugin.ts +86 -33
- package/src/runtime/controller/viewport.ts +8 -2
- package/src/runtime/graph.ts +383 -158
- package/src/stdlib/behavior/click-select.ts +8 -3
- package/src/stdlib/behavior/drag-canvas.ts +6 -3
- package/src/stdlib/behavior/drag-combo.ts +8 -8
- package/src/stdlib/behavior/drag-node.ts +165 -50
- package/src/stdlib/behavior/scroll-canvas.ts +3 -3
- package/src/stdlib/behavior/zoom-canvas.ts +3 -3
- package/src/stdlib/data/mapNodeSize.ts +2 -2
- package/src/stdlib/data/validateData.ts +2 -2
- package/src/stdlib/index.ts +3 -0
- package/src/stdlib/item/edge/base.ts +15 -139
- package/src/stdlib/item/node/base.ts +20 -215
- package/src/stdlib/plugin/edgeFilterLens/index.ts +2 -2
- package/src/stdlib/plugin/fisheye/index.ts +3 -2
- package/src/stdlib/plugin/history/visibility-updated-command.ts +2 -2
- package/src/stdlib/plugin/index.ts +1 -0
- package/src/stdlib/plugin/lodController/index.ts +602 -0
- package/src/stdlib/plugin/minimap/index.ts +12 -14
- package/src/stdlib/plugin/toolbar/index.ts +29 -31
- package/src/stdlib/theme/dark.ts +32 -34
- package/src/stdlib/theme/light.ts +27 -29
- package/src/stdlib/themeSolver/spec.ts +2 -2
- package/src/types/animate.ts +1 -1
- package/src/types/combo.ts +2 -2
- package/src/types/edge.ts +2 -2
- package/src/types/graph.ts +65 -53
- package/src/types/hook.ts +5 -0
- package/src/types/item.ts +8 -14
- package/src/types/layout.ts +20 -15
- package/src/types/node.ts +3 -2
- package/src/types/plugin.ts +2 -0
- package/src/types/spec.ts +1 -0
- package/src/types/theme.ts +7 -7
- package/src/util/animate.ts +104 -78
- package/src/util/bbox.ts +26 -1
- package/src/util/data.ts +15 -6
- package/src/util/dom.ts +6 -6
- package/src/util/item.ts +15 -1
- package/src/util/mapper.ts +1 -1
- package/src/util/path.ts +72 -2
- package/src/util/polyline.ts +30 -23
- package/src/util/router.ts +21 -19
- package/src/util/shape.ts +27 -12
- package/src/util/zoom.ts +19 -25
- package/esm/runtime/controller/extension.d.ts +0 -9
- package/esm/runtime/controller/extension.js +0 -11
- package/esm/runtime/controller/extension.js.map +0 -1
- package/lib/runtime/controller/extension.d.ts +0 -9
- package/lib/runtime/controller/extension.js +0 -15
- package/lib/runtime/controller/extension.js.map +0 -1
- package/src/runtime/controller/extension.ts +0 -14
package/esm/runtime/graph.js
CHANGED
|
@@ -25,10 +25,10 @@ import { changeRenderer, createCanvas } from '../util/canvas';
|
|
|
25
25
|
import { createDOM } from '../util/dom';
|
|
26
26
|
import { getLayoutBounds } from '../util/layout';
|
|
27
27
|
import { formatPadding } from '../util/shape';
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
28
|
+
import { cloneJSON, isEmptyGraph } from '../util/data';
|
|
29
|
+
import { getCombinedCanvasesBounds } from '../util/bbox';
|
|
30
|
+
import { DataController, InteractionController, ItemController, LayoutController, ThemeController, ViewportController, PluginController, } from './controller';
|
|
30
31
|
import Hook from './hooks';
|
|
31
|
-
import { isEmptyGraph } from '../util/data';
|
|
32
32
|
export class Graph extends EventEmitter {
|
|
33
33
|
constructor(spec) {
|
|
34
34
|
super();
|
|
@@ -62,7 +62,9 @@ export class Graph extends EventEmitter {
|
|
|
62
62
|
canvases: {
|
|
63
63
|
background: this.backgroundCanvas,
|
|
64
64
|
main: this.canvas,
|
|
65
|
+
label: this.labelCanvas,
|
|
65
66
|
transient: this.transientCanvas,
|
|
67
|
+
transientLabel: this.transientLabelCanvas,
|
|
66
68
|
},
|
|
67
69
|
});
|
|
68
70
|
const { data } = spec;
|
|
@@ -79,13 +81,12 @@ export class Graph extends EventEmitter {
|
|
|
79
81
|
this.interactionController = new InteractionController(this);
|
|
80
82
|
this.layoutController = new LayoutController(this);
|
|
81
83
|
this.themeController = new ThemeController(this);
|
|
82
|
-
this.itemController = new ItemController(this);
|
|
83
84
|
this.viewportController = new ViewportController(this);
|
|
84
|
-
this.
|
|
85
|
+
this.itemController = new ItemController(this);
|
|
85
86
|
this.pluginController = new PluginController(this);
|
|
86
87
|
}
|
|
87
88
|
initCanvas() {
|
|
88
|
-
const { renderer, container, canvas, backgroundCanvas, transientCanvas, width, height, } = this.specification;
|
|
89
|
+
const { renderer, container, canvas, backgroundCanvas, transientCanvas, transientLabelCanvas, width, height, } = this.specification;
|
|
89
90
|
let pixelRatio;
|
|
90
91
|
if (renderer && !isString(renderer)) {
|
|
91
92
|
// @ts-ignore
|
|
@@ -104,6 +105,7 @@ export class Graph extends EventEmitter {
|
|
|
104
105
|
this.canvas = canvas;
|
|
105
106
|
this.backgroundCanvas = backgroundCanvas;
|
|
106
107
|
this.transientCanvas = transientCanvas;
|
|
108
|
+
this.transientLabelCanvas = transientLabelCanvas;
|
|
107
109
|
this.container = container;
|
|
108
110
|
}
|
|
109
111
|
else {
|
|
@@ -125,10 +127,24 @@ export class Graph extends EventEmitter {
|
|
|
125
127
|
}
|
|
126
128
|
this.backgroundCanvas = createCanvas(this.rendererType, containerDOM, size[0], size[1], pixelRatio);
|
|
127
129
|
this.canvas = createCanvas(this.rendererType, containerDOM, size[0], size[1], pixelRatio);
|
|
130
|
+
this.labelCanvas = createCanvas('canvas', containerDOM, size[0], size[1], pixelRatio);
|
|
128
131
|
this.transientCanvas = createCanvas(this.rendererType, containerDOM, size[0], size[1], pixelRatio);
|
|
132
|
+
this.transientLabelCanvas = createCanvas('canvas', containerDOM, size[0], size[1], pixelRatio);
|
|
129
133
|
}
|
|
130
|
-
Promise.all([
|
|
131
|
-
|
|
134
|
+
Promise.all([
|
|
135
|
+
this.backgroundCanvas,
|
|
136
|
+
this.canvas,
|
|
137
|
+
this.labelCanvas,
|
|
138
|
+
this.transientCanvas,
|
|
139
|
+
this.transientLabelCanvas,
|
|
140
|
+
].map((canvas) => canvas.ready)).then(() => {
|
|
141
|
+
[
|
|
142
|
+
this.backgroundCanvas,
|
|
143
|
+
this.canvas,
|
|
144
|
+
this.labelCanvas,
|
|
145
|
+
this.transientCanvas,
|
|
146
|
+
this.transientLabelCanvas,
|
|
147
|
+
].forEach((canvas, i) => {
|
|
132
148
|
const $domElement = canvas
|
|
133
149
|
.getContextService()
|
|
134
150
|
.getDomElement();
|
|
@@ -280,6 +296,7 @@ export class Graph extends EventEmitter {
|
|
|
280
296
|
graphCore: this.dataController.graphCore,
|
|
281
297
|
theme: this.themeController.specification,
|
|
282
298
|
transientCanvas: this.transientCanvas,
|
|
299
|
+
transientLabelCanvas: this.transientLabelCanvas,
|
|
283
300
|
tileOptimize: {
|
|
284
301
|
tileFirstRender,
|
|
285
302
|
tileFirstRenderSize,
|
|
@@ -320,7 +337,13 @@ export class Graph extends EventEmitter {
|
|
|
320
337
|
yield emitRender();
|
|
321
338
|
}
|
|
322
339
|
else {
|
|
323
|
-
yield Promise.all([
|
|
340
|
+
yield Promise.all([
|
|
341
|
+
this.backgroundCanvas,
|
|
342
|
+
this.canvas,
|
|
343
|
+
this.labelCanvas,
|
|
344
|
+
this.transientCanvas,
|
|
345
|
+
this.transientLabelCanvas,
|
|
346
|
+
].map((canvas) => canvas.ready));
|
|
324
347
|
yield emitRender();
|
|
325
348
|
}
|
|
326
349
|
});
|
|
@@ -329,10 +352,11 @@ export class Graph extends EventEmitter {
|
|
|
329
352
|
* Change graph data.
|
|
330
353
|
* @param data new data
|
|
331
354
|
* @param type the way to change data, 'replace' means discard the old data and use the new one; 'mergeReplace' means merge the common part, remove (old - new), add (new - old)
|
|
355
|
+
* @param relayout whether relayout the nodes after data changing
|
|
332
356
|
* @returns
|
|
333
357
|
* @group Data
|
|
334
358
|
*/
|
|
335
|
-
changeData(data, type = 'mergeReplace') {
|
|
359
|
+
changeData(data, type = 'mergeReplace', relayout = true) {
|
|
336
360
|
return __awaiter(this, void 0, void 0, function* () {
|
|
337
361
|
const { tileFirstRender, tileFirstRenderSize } = this.specification.optimize || {};
|
|
338
362
|
this.hooks.datachange.emit({ data, type });
|
|
@@ -340,13 +364,16 @@ export class Graph extends EventEmitter {
|
|
|
340
364
|
graphCore: this.dataController.graphCore,
|
|
341
365
|
theme: this.themeController.specification,
|
|
342
366
|
transientCanvas: this.transientCanvas,
|
|
367
|
+
transientLabelCanvas: this.transientLabelCanvas,
|
|
343
368
|
tileOptimize: {
|
|
344
369
|
tileFirstRender,
|
|
345
370
|
tileFirstRenderSize,
|
|
346
371
|
},
|
|
347
372
|
});
|
|
348
373
|
this.emit('afterrender');
|
|
349
|
-
|
|
374
|
+
if (relayout) {
|
|
375
|
+
yield this.layout();
|
|
376
|
+
}
|
|
350
377
|
});
|
|
351
378
|
}
|
|
352
379
|
/**
|
|
@@ -499,8 +526,8 @@ export class Graph extends EventEmitter {
|
|
|
499
526
|
const { direction = 'both', ratioRule = 'min', boundsType = 'render', onlyOutOfViewport = false, onlyZoomAtLargerThanViewport = false, } = rules || {};
|
|
500
527
|
const { min, max, center: [graphCenterX, graphCenterY], halfExtents, } = boundsType === 'render'
|
|
501
528
|
? // Get the bounds of the whole graph content.
|
|
502
|
-
this.canvas.
|
|
503
|
-
: // Get the
|
|
529
|
+
getCombinedCanvasesBounds([this.canvas, this.labelCanvas])
|
|
530
|
+
: // Get the b ounds of the nodes positions while the graph content is not ready.
|
|
504
531
|
getLayoutBounds(this);
|
|
505
532
|
const origin = this.canvas.canvas2Viewport({
|
|
506
533
|
x: graphCenterX,
|
|
@@ -560,7 +587,7 @@ export class Graph extends EventEmitter {
|
|
|
560
587
|
return __awaiter(this, void 0, void 0, function* () {
|
|
561
588
|
const { center: [graphCenterX, graphCenterY], } = boundsType === 'render'
|
|
562
589
|
? // Get the bounds of the whole graph content.
|
|
563
|
-
this.canvas.
|
|
590
|
+
getCombinedCanvasesBounds([this.canvas, this.labelCanvas])
|
|
564
591
|
: // Get the bounds of the nodes positions while the graph content is not ready.
|
|
565
592
|
getLayoutBounds(this);
|
|
566
593
|
yield this.translateTo(this.canvas.canvas2Viewport({ x: graphCenterX, y: graphCenterY }), effectTiming);
|
|
@@ -623,9 +650,15 @@ export class Graph extends EventEmitter {
|
|
|
623
650
|
this.emit('beforesetsize', { oldSize, size: size });
|
|
624
651
|
this.specification.width = size[0];
|
|
625
652
|
this.specification.height = size[1];
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
653
|
+
[
|
|
654
|
+
this.canvas,
|
|
655
|
+
this.labelCanvas,
|
|
656
|
+
this.transientCanvas,
|
|
657
|
+
this.transientLabelCanvas,
|
|
658
|
+
this.backgroundCanvas,
|
|
659
|
+
].forEach((canvas) => {
|
|
660
|
+
canvas.resize(size[0], size[1]);
|
|
661
|
+
});
|
|
629
662
|
this.emit('aftersetsize', { oldSize, size: size });
|
|
630
663
|
}
|
|
631
664
|
getCanvasRange() {
|
|
@@ -754,6 +787,16 @@ export class Graph extends EventEmitter {
|
|
|
754
787
|
getRelatedEdgesData(nodeId, direction = 'both') {
|
|
755
788
|
return this.dataController.findRelatedEdges(nodeId, direction);
|
|
756
789
|
}
|
|
790
|
+
/**
|
|
791
|
+
* Get nearby edges from a start node using quadtree collision detection.
|
|
792
|
+
* @param nodeId id of the start node
|
|
793
|
+
* @returns nearby edges' data array
|
|
794
|
+
*/
|
|
795
|
+
getNearEdgesData(nodeId, shouldBegin) {
|
|
796
|
+
const transientItem = this.itemController.getTransientItem(nodeId);
|
|
797
|
+
const itemMap = this.itemController.getItemMap();
|
|
798
|
+
return this.dataController.findNearEdges(nodeId, itemMap, transientItem, shouldBegin);
|
|
799
|
+
}
|
|
757
800
|
/**
|
|
758
801
|
* Get one-hop node ids from a start node.
|
|
759
802
|
* @param nodeId id of the start node
|
|
@@ -791,15 +834,6 @@ export class Graph extends EventEmitter {
|
|
|
791
834
|
getDisplayModel(id) {
|
|
792
835
|
return this.itemController.findDisplayModel(id);
|
|
793
836
|
}
|
|
794
|
-
/**
|
|
795
|
-
* Retrieve the nearby edges for a given node using quadtree collision detection.
|
|
796
|
-
* @param nodeId node id
|
|
797
|
-
* @group Data
|
|
798
|
-
*/
|
|
799
|
-
getNearEdgesForNode(nodeId) {
|
|
800
|
-
const { graphCore } = this.dataController;
|
|
801
|
-
return this.itemController.findNearEdgesByNode(nodeId, graphCore);
|
|
802
|
-
}
|
|
803
837
|
/**
|
|
804
838
|
* Find items which has the state.
|
|
805
839
|
* @param itemType item type
|
|
@@ -831,6 +865,7 @@ export class Graph extends EventEmitter {
|
|
|
831
865
|
// data controller and item controller subscribe additem in order
|
|
832
866
|
const { graphCore } = this.dataController;
|
|
833
867
|
const { specification } = this.themeController;
|
|
868
|
+
const modelArr = isArray(models) ? models : [models];
|
|
834
869
|
graphCore.once('changed', (event) => {
|
|
835
870
|
if (!event.changes.length)
|
|
836
871
|
return;
|
|
@@ -838,7 +873,7 @@ export class Graph extends EventEmitter {
|
|
|
838
873
|
const timingParameters = {
|
|
839
874
|
type: itemType,
|
|
840
875
|
action: 'add',
|
|
841
|
-
models,
|
|
876
|
+
models: modelArr,
|
|
842
877
|
apiName: 'addData',
|
|
843
878
|
changes,
|
|
844
879
|
};
|
|
@@ -851,7 +886,6 @@ export class Graph extends EventEmitter {
|
|
|
851
886
|
});
|
|
852
887
|
this.emit('afteritemchange', timingParameters);
|
|
853
888
|
});
|
|
854
|
-
const modelArr = isArray(models) ? models : [models];
|
|
855
889
|
const data = { nodes: [], edges: [], combos: [] };
|
|
856
890
|
data[`${itemType}s`] = modelArr;
|
|
857
891
|
this.hooks.datachange.emit({
|
|
@@ -863,7 +897,8 @@ export class Graph extends EventEmitter {
|
|
|
863
897
|
}
|
|
864
898
|
/**
|
|
865
899
|
* Remove one or more node/edge/combo data from the graph.
|
|
866
|
-
* @param
|
|
900
|
+
* @param itemType the type the item(s) to be removed.
|
|
901
|
+
* @param id the id or the ids' array of the items to be removed.
|
|
867
902
|
* @returns whether success
|
|
868
903
|
* @group Data
|
|
869
904
|
*/
|
|
@@ -957,8 +992,8 @@ export class Graph extends EventEmitter {
|
|
|
957
992
|
}
|
|
958
993
|
/**
|
|
959
994
|
* Update one or more node/edge/combo data on the graph.
|
|
960
|
-
* @param {ITEM_TYPE} itemType
|
|
961
|
-
* @param models
|
|
995
|
+
* @param {ITEM_TYPE} itemType the type the item(s) to be udated.
|
|
996
|
+
* @param models update configs.
|
|
962
997
|
* @group Data
|
|
963
998
|
*/
|
|
964
999
|
updateData(itemType, models) {
|
|
@@ -968,11 +1003,11 @@ export class Graph extends EventEmitter {
|
|
|
968
1003
|
const { graphCore } = this.dataController;
|
|
969
1004
|
const { specification } = this.themeController;
|
|
970
1005
|
graphCore.once('changed', (event) => {
|
|
971
|
-
const changes = this.extendChanges(
|
|
1006
|
+
const changes = this.extendChanges(cloneJSON(event.changes));
|
|
972
1007
|
const timingParameters = {
|
|
973
1008
|
type: itemType,
|
|
974
1009
|
action: 'update',
|
|
975
|
-
models,
|
|
1010
|
+
models: modelArr,
|
|
976
1011
|
apiName: 'updateData',
|
|
977
1012
|
changes,
|
|
978
1013
|
};
|
|
@@ -995,21 +1030,27 @@ export class Graph extends EventEmitter {
|
|
|
995
1030
|
/**
|
|
996
1031
|
* Update one or more nodes' positions,
|
|
997
1032
|
* do not update other styles which leads to better performance than updating positions by updateData.
|
|
998
|
-
* @param models new configurations with x and y for every node, which has id field to indicate the specific item
|
|
1033
|
+
* @param models new configurations with x and y for every node, which has id field to indicate the specific item.
|
|
1034
|
+
* @param upsertAncestors whether update the ancestors in combo tree.
|
|
1035
|
+
* @param disableAnimate whether disable the animation for this call.
|
|
1036
|
+
* @param callback callback function after update nodes done.
|
|
999
1037
|
* @group Data
|
|
1000
1038
|
*/
|
|
1001
|
-
updateNodePosition(models, upsertAncestors, disableAnimate = false, callback
|
|
1002
|
-
return this.updatePosition('node', models, upsertAncestors, disableAnimate, callback
|
|
1039
|
+
updateNodePosition(models, upsertAncestors, disableAnimate = false, callback) {
|
|
1040
|
+
return this.updatePosition('node', models, upsertAncestors, disableAnimate, callback);
|
|
1003
1041
|
}
|
|
1004
1042
|
/**
|
|
1005
1043
|
* Update one or more combos' positions,
|
|
1006
1044
|
* do not update other styles which leads to better performance than updating positions by updateData.
|
|
1007
1045
|
* In fact, it changes the succeed nodes positions to affect the combo's position, but not modify the combo's position directly.
|
|
1008
|
-
* @param models new configurations with x and y for every combo, which has id field to indicate the specific item
|
|
1046
|
+
* @param models new configurations with x and y for every combo, which has id field to indicate the specific item.
|
|
1047
|
+
* @param upsertAncestors whether update the ancestors in combo tree.
|
|
1048
|
+
* @param disableAnimate whether disable the animation for this call.
|
|
1049
|
+
* @param callback callback function after update combos done.
|
|
1009
1050
|
* @group Data
|
|
1010
1051
|
*/
|
|
1011
|
-
updateComboPosition(models, upsertAncestors, disableAnimate = false, callback
|
|
1012
|
-
return this.updatePosition('combo', models, upsertAncestors, disableAnimate, callback
|
|
1052
|
+
updateComboPosition(models, upsertAncestors, disableAnimate = false, callback) {
|
|
1053
|
+
return this.updatePosition('combo', models, upsertAncestors, disableAnimate, callback);
|
|
1013
1054
|
}
|
|
1014
1055
|
/**
|
|
1015
1056
|
* Get history plugin instance
|
|
@@ -1022,7 +1063,7 @@ export class Graph extends EventEmitter {
|
|
|
1022
1063
|
}
|
|
1023
1064
|
return this.pluginController.getPlugin('history');
|
|
1024
1065
|
}
|
|
1025
|
-
updatePosition(type, models, upsertAncestors, disableAnimate = false, callback
|
|
1066
|
+
updatePosition(type, models, upsertAncestors, disableAnimate = false, callback) {
|
|
1026
1067
|
const modelArr = isArray(models) ? models : [models];
|
|
1027
1068
|
const { graphCore } = this.dataController;
|
|
1028
1069
|
const { specification } = this.themeController;
|
|
@@ -1034,7 +1075,7 @@ export class Graph extends EventEmitter {
|
|
|
1034
1075
|
type,
|
|
1035
1076
|
action: 'updatePosition',
|
|
1036
1077
|
upsertAncestors,
|
|
1037
|
-
models,
|
|
1078
|
+
models: modelArr,
|
|
1038
1079
|
apiName: 'updatePosition',
|
|
1039
1080
|
changes,
|
|
1040
1081
|
};
|
|
@@ -1080,22 +1121,40 @@ export class Graph extends EventEmitter {
|
|
|
1080
1121
|
* @returns
|
|
1081
1122
|
* @group Item
|
|
1082
1123
|
*/
|
|
1083
|
-
showItem(ids,
|
|
1124
|
+
showItem(ids, options) {
|
|
1125
|
+
const { disableAnimate = false, shapeIds } = options || {};
|
|
1084
1126
|
const idArr = isArray(ids) ? ids : [ids];
|
|
1085
1127
|
if (isEmpty(idArr))
|
|
1086
1128
|
return;
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1129
|
+
let changes;
|
|
1130
|
+
if (shapeIds === null || shapeIds === void 0 ? void 0 : shapeIds.length) {
|
|
1131
|
+
const shapeIdsArr = isArray(shapeIds) ? shapeIds : [shapeIds];
|
|
1132
|
+
changes = {
|
|
1133
|
+
newValue: [{ ids: idArr, visible: true, shapeIds: shapeIdsArr }],
|
|
1134
|
+
oldValue: this.getItemPreviousVisibility(idArr),
|
|
1135
|
+
};
|
|
1136
|
+
this.hooks.itemvisibilitychange.emit({
|
|
1137
|
+
ids: idArr,
|
|
1138
|
+
value: true,
|
|
1139
|
+
graphCore: this.dataController.graphCore,
|
|
1140
|
+
animate: !disableAnimate,
|
|
1141
|
+
shapeIds: shapeIdsArr,
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
1144
|
+
else {
|
|
1145
|
+
changes = {
|
|
1146
|
+
newValue: [{ ids: idArr, visible: true }],
|
|
1147
|
+
oldValue: this.getItemPreviousVisibility(idArr),
|
|
1148
|
+
};
|
|
1149
|
+
this.hooks.itemvisibilitychange.emit({
|
|
1150
|
+
ids: idArr,
|
|
1151
|
+
value: true,
|
|
1152
|
+
graphCore: this.dataController.graphCore,
|
|
1153
|
+
animate: !disableAnimate,
|
|
1154
|
+
});
|
|
1155
|
+
}
|
|
1097
1156
|
this.emit('afteritemvisibilitychange', {
|
|
1098
|
-
ids,
|
|
1157
|
+
ids: idArr,
|
|
1099
1158
|
value: true,
|
|
1100
1159
|
animate: !disableAnimate,
|
|
1101
1160
|
action: 'updateVisibility',
|
|
@@ -1105,27 +1164,49 @@ export class Graph extends EventEmitter {
|
|
|
1105
1164
|
}
|
|
1106
1165
|
/**
|
|
1107
1166
|
* Hide the item(s).
|
|
1108
|
-
* @param
|
|
1167
|
+
* @param id the id for the item to be hidden.
|
|
1168
|
+
* @param disableAnimate whether disable the hidden animations.
|
|
1169
|
+
* @param keepKeyShape whether keep the keyShape.
|
|
1170
|
+
* @param keepRelated whether keep the related nodes for edge.
|
|
1109
1171
|
* @returns
|
|
1110
1172
|
* @group Item
|
|
1111
1173
|
*/
|
|
1112
|
-
hideItem(ids,
|
|
1174
|
+
hideItem(ids, options) {
|
|
1175
|
+
const { disableAnimate = false, keepKeyShape = false, keepRelated = false, shapeIds, } = options || {};
|
|
1113
1176
|
const idArr = isArray(ids) ? ids : [ids];
|
|
1114
1177
|
if (isEmpty(idArr))
|
|
1115
1178
|
return;
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1179
|
+
let changes;
|
|
1180
|
+
if (shapeIds === null || shapeIds === void 0 ? void 0 : shapeIds.length) {
|
|
1181
|
+
const shapeIdsArr = isArray(shapeIds) ? shapeIds : [shapeIds];
|
|
1182
|
+
changes = {
|
|
1183
|
+
newValue: [{ ids: idArr, visible: false, shapeIds: shapeIdsArr }],
|
|
1184
|
+
oldValue: this.getItemPreviousVisibility(idArr),
|
|
1185
|
+
};
|
|
1186
|
+
this.hooks.itemvisibilitychange.emit({
|
|
1187
|
+
ids: idArr,
|
|
1188
|
+
value: false,
|
|
1189
|
+
graphCore: this.dataController.graphCore,
|
|
1190
|
+
animate: !disableAnimate,
|
|
1191
|
+
shapeIds: shapeIdsArr,
|
|
1192
|
+
});
|
|
1193
|
+
}
|
|
1194
|
+
else {
|
|
1195
|
+
changes = {
|
|
1196
|
+
newValue: [{ ids: idArr, visible: false }],
|
|
1197
|
+
oldValue: this.getItemPreviousVisibility(idArr),
|
|
1198
|
+
};
|
|
1199
|
+
this.hooks.itemvisibilitychange.emit({
|
|
1200
|
+
ids: idArr,
|
|
1201
|
+
value: false,
|
|
1202
|
+
graphCore: this.dataController.graphCore,
|
|
1203
|
+
animate: !disableAnimate,
|
|
1204
|
+
keepKeyShape,
|
|
1205
|
+
keepRelated,
|
|
1206
|
+
});
|
|
1207
|
+
}
|
|
1127
1208
|
this.emit('afteritemvisibilitychange', {
|
|
1128
|
-
ids,
|
|
1209
|
+
ids: idArr,
|
|
1129
1210
|
value: false,
|
|
1130
1211
|
animate: !disableAnimate,
|
|
1131
1212
|
action: 'updateVisibility',
|
|
@@ -1286,11 +1367,20 @@ export class Graph extends EventEmitter {
|
|
|
1286
1367
|
getItemVisible(id) {
|
|
1287
1368
|
return this.itemController.getItemVisible(id);
|
|
1288
1369
|
}
|
|
1370
|
+
/**
|
|
1371
|
+
* Get the visible shape ids in a node / edge / combo.
|
|
1372
|
+
* @param id the id for the node / edge / combo
|
|
1373
|
+
* @returns ids of the visible shapes
|
|
1374
|
+
*/
|
|
1375
|
+
getItemVisibleShapeIds(id) {
|
|
1376
|
+
return this.itemController.getItemVisibleShapeIds(id);
|
|
1377
|
+
}
|
|
1289
1378
|
// ===== combo operations =====
|
|
1290
1379
|
/**
|
|
1291
1380
|
* Add a new combo to the graph, and update the structure of the existed child in childrenIds to be the children of the new combo.
|
|
1292
1381
|
* Different from addData with combo type, this API update the succeeds' combo tree strucutres in the same time.
|
|
1293
|
-
* @param model combo user data
|
|
1382
|
+
* @param model combo user data.
|
|
1383
|
+
* @param childrenIds the ids of the children nodes / combos to move into the new combo.
|
|
1294
1384
|
* @returns whether success
|
|
1295
1385
|
* @group Combo
|
|
1296
1386
|
*/
|
|
@@ -1332,7 +1422,7 @@ export class Graph extends EventEmitter {
|
|
|
1332
1422
|
}
|
|
1333
1423
|
/**
|
|
1334
1424
|
* Collapse a combo.
|
|
1335
|
-
* @param comboId combo ids
|
|
1425
|
+
* @param comboId combo id or ids' array.
|
|
1336
1426
|
* @group Combo
|
|
1337
1427
|
*/
|
|
1338
1428
|
collapseCombo(comboIds) {
|
|
@@ -1349,7 +1439,7 @@ export class Graph extends EventEmitter {
|
|
|
1349
1439
|
}
|
|
1350
1440
|
/**
|
|
1351
1441
|
* Expand a combo.
|
|
1352
|
-
* @param
|
|
1442
|
+
* @param comboId combo id or ids' array.
|
|
1353
1443
|
* @group Combo
|
|
1354
1444
|
*/
|
|
1355
1445
|
expandCombo(comboIds) {
|
|
@@ -1368,7 +1458,11 @@ export class Graph extends EventEmitter {
|
|
|
1368
1458
|
* Move one or more combos a distance (dx, dy) relatively,
|
|
1369
1459
|
* do not update other styles which leads to better performance than updating positions by updateData.
|
|
1370
1460
|
* In fact, it changes the succeed nodes positions to affect the combo's position, but not modify the combo's position directly.
|
|
1371
|
-
* @param models new configurations with x and y for every combo, which has id field to indicate the specific item
|
|
1461
|
+
* @param models new configurations with x and y for every combo, which has id field to indicate the specific item.
|
|
1462
|
+
* @param dx the distance alone x-axis to move the combo.
|
|
1463
|
+
* @param dy the distance alone y-axis to move the combo.
|
|
1464
|
+
* @param upsertAncestors whether update the ancestors in the combo tree.
|
|
1465
|
+
* @param callback callback function after move combo done.
|
|
1372
1466
|
* @group Combo
|
|
1373
1467
|
*/
|
|
1374
1468
|
moveCombo(ids, dx, dy, upsertAncestors, callback) {
|
|
@@ -1490,7 +1584,9 @@ export class Graph extends EventEmitter {
|
|
|
1490
1584
|
*/
|
|
1491
1585
|
setCursor(cursor) {
|
|
1492
1586
|
this.canvas.setCursor(cursor);
|
|
1587
|
+
this.labelCanvas.setCursor(cursor);
|
|
1493
1588
|
this.transientCanvas.setCursor(cursor);
|
|
1589
|
+
this.transientLabelCanvas.setCursor(cursor);
|
|
1494
1590
|
}
|
|
1495
1591
|
/**
|
|
1496
1592
|
* Add behavior(s) to mode(s).
|
|
@@ -1622,10 +1718,9 @@ export class Graph extends EventEmitter {
|
|
|
1622
1718
|
*/
|
|
1623
1719
|
updatePlugin(plugin) {
|
|
1624
1720
|
const { plugins } = this.specification;
|
|
1625
|
-
const { key } = plugin;
|
|
1721
|
+
const { key, type } = plugin;
|
|
1626
1722
|
if (!key) {
|
|
1627
|
-
console.warn(
|
|
1628
|
-
return;
|
|
1723
|
+
console.warn(`The key for the plugin is not found. G6 will update the first plugin with type ${type}`);
|
|
1629
1724
|
}
|
|
1630
1725
|
if (!plugins) {
|
|
1631
1726
|
console.warn('Update plugin failed, the plugin to be updated does not exist.');
|
|
@@ -1633,11 +1728,12 @@ export class Graph extends EventEmitter {
|
|
|
1633
1728
|
}
|
|
1634
1729
|
const oldPlugin = plugins === null || plugins === void 0 ? void 0 : plugins.find((p) => {
|
|
1635
1730
|
if (typeof p === 'string')
|
|
1636
|
-
return p === key;
|
|
1637
|
-
return p.key === key
|
|
1731
|
+
return p === key || p === type;
|
|
1732
|
+
return (p.key === key ||
|
|
1733
|
+
p.type === type);
|
|
1638
1734
|
});
|
|
1639
1735
|
if (!oldPlugin) {
|
|
1640
|
-
console.warn(
|
|
1736
|
+
console.warn(`Update plugin failed, the plugin with key ${key} or type ${type} is not found.`);
|
|
1641
1737
|
return;
|
|
1642
1738
|
}
|
|
1643
1739
|
const idx = plugins.indexOf(oldPlugin);
|
|
@@ -1673,45 +1769,62 @@ export class Graph extends EventEmitter {
|
|
|
1673
1769
|
*/
|
|
1674
1770
|
toDataURL(type) {
|
|
1675
1771
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1676
|
-
const backgroundCanvas = this
|
|
1677
|
-
const canvas = this.canvas;
|
|
1678
|
-
const transientCanvas = this.transientCanvas;
|
|
1679
|
-
const rendererType = this.rendererType;
|
|
1772
|
+
const { backgroundCanvas, canvas, transientCanvas, labelCanvas, rendererType, } = this;
|
|
1680
1773
|
const pixelRatio = typeof window !== 'undefined' ? window.devicePixelRatio : 1;
|
|
1681
|
-
const width = this.getSize()
|
|
1682
|
-
const height = this.getSize()[1];
|
|
1774
|
+
const [width, height] = this.getSize();
|
|
1683
1775
|
const vContainerDOM = createDOM('<div id="virtual-image"></div>');
|
|
1776
|
+
const camera = canvas.getCamera();
|
|
1684
1777
|
const vCanvas = createCanvas(rendererType, vContainerDOM, width, height, pixelRatio);
|
|
1778
|
+
yield vCanvas.ready;
|
|
1779
|
+
const backgroundClonedGroup = backgroundCanvas.getRoot().cloneNode(true);
|
|
1780
|
+
const clonedGroup = canvas.getRoot().cloneNode(true);
|
|
1781
|
+
const transientClonedGroup = transientCanvas.getRoot().cloneNode(true);
|
|
1782
|
+
const labelClonedGroup = labelCanvas.getRoot().cloneNode(true);
|
|
1783
|
+
const originViewportLTCanvas = vCanvas.viewport2Canvas({ x: 0, y: 0 });
|
|
1784
|
+
const currentViewportLTCanvas = canvas.viewport2Canvas({ x: 0, y: 0 });
|
|
1785
|
+
labelClonedGroup.translate([
|
|
1786
|
+
currentViewportLTCanvas.x - originViewportLTCanvas.x,
|
|
1787
|
+
currentViewportLTCanvas.y - originViewportLTCanvas.y,
|
|
1788
|
+
]);
|
|
1789
|
+
labelClonedGroup.scale(1 / canvas.getCamera().getZoom());
|
|
1790
|
+
// TODO: after cloning, label background with rotation take a wrong place, remove it to temporary solve.
|
|
1791
|
+
labelClonedGroup.children[0].children.forEach((childGroup) => {
|
|
1792
|
+
childGroup.children.forEach((shape) => {
|
|
1793
|
+
if (shape.getAttribute('data-is-label-background') &&
|
|
1794
|
+
shape.style.transform)
|
|
1795
|
+
shape.remove();
|
|
1796
|
+
});
|
|
1797
|
+
});
|
|
1798
|
+
vCanvas.appendChild(backgroundClonedGroup);
|
|
1799
|
+
vCanvas.appendChild(clonedGroup);
|
|
1800
|
+
vCanvas.appendChild(labelClonedGroup);
|
|
1801
|
+
vCanvas.appendChild(transientClonedGroup);
|
|
1802
|
+
const vCamera = vCanvas.getCamera();
|
|
1803
|
+
vCamera.setZoom(camera.getZoom());
|
|
1804
|
+
vCamera.setPosition(camera.getPosition());
|
|
1805
|
+
vCamera.setFocalPoint(camera.getFocalPoint());
|
|
1685
1806
|
const vCanvasContextService = vCanvas.getContextService();
|
|
1686
1807
|
let bgRect;
|
|
1687
1808
|
if (rendererType !== 'svg') {
|
|
1809
|
+
const backPositionCanvas = canvas.viewport2Canvas({ x: 0, y: 0 });
|
|
1688
1810
|
bgRect = new Rect({
|
|
1689
|
-
style: {
|
|
1690
|
-
x: 0,
|
|
1691
|
-
y: 0,
|
|
1692
|
-
z: -1,
|
|
1693
|
-
width: vCanvasContextService.getDomElement().width,
|
|
1694
|
-
height: vCanvasContextService.getDomElement().height,
|
|
1811
|
+
style: Object.assign(Object.assign({}, backPositionCanvas), { z: -1, width: vCanvasContextService.getDomElement().width, height: vCanvasContextService.getDomElement().height,
|
|
1695
1812
|
//@ts-ignore
|
|
1696
|
-
fill: backgroundCanvas.getContextService().getDomElement().style['background-color'],
|
|
1697
|
-
},
|
|
1813
|
+
fill: backgroundCanvas.getContextService().getDomElement().style['background-color'], zIndex: -10 }),
|
|
1698
1814
|
});
|
|
1699
1815
|
vCanvas.appendChild(bgRect);
|
|
1700
1816
|
}
|
|
1701
|
-
const backgroundClonedGroup = backgroundCanvas.getRoot().cloneNode(true);
|
|
1702
|
-
const clonedGroup = canvas.getRoot().cloneNode(true);
|
|
1703
|
-
const transientClonedGroup = transientCanvas.getRoot().cloneNode(true);
|
|
1704
|
-
vCanvas.appendChild(backgroundClonedGroup);
|
|
1705
|
-
vCanvas.appendChild(clonedGroup);
|
|
1706
|
-
vCanvas.appendChild(transientClonedGroup);
|
|
1707
|
-
vCanvas.render();
|
|
1708
1817
|
if (!type)
|
|
1709
1818
|
type = 'image/png';
|
|
1710
1819
|
let dataURL = '';
|
|
1711
|
-
|
|
1712
|
-
|
|
1820
|
+
return new Promise((resolve) => {
|
|
1821
|
+
setTimeout(() => {
|
|
1822
|
+
vCanvasContextService.toDataURL({ type }).then((url) => {
|
|
1823
|
+
dataURL = url;
|
|
1824
|
+
resolve(dataURL);
|
|
1825
|
+
});
|
|
1826
|
+
}, 50);
|
|
1713
1827
|
});
|
|
1714
|
-
return dataURL;
|
|
1715
1828
|
});
|
|
1716
1829
|
}
|
|
1717
1830
|
/**
|
|
@@ -1723,16 +1836,15 @@ export class Graph extends EventEmitter {
|
|
|
1723
1836
|
*/
|
|
1724
1837
|
toFullDataURL(type, imageConfig) {
|
|
1725
1838
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1726
|
-
const backgroundCanvas = this
|
|
1727
|
-
const
|
|
1728
|
-
const transientCanvas = this.transientCanvas;
|
|
1729
|
-
const backgroundRoot = canvas.getRoot();
|
|
1839
|
+
const { backgroundCanvas, canvas, transientCanvas, labelCanvas, rendererType, } = this;
|
|
1840
|
+
const backgroundRoot = backgroundCanvas.getRoot();
|
|
1730
1841
|
const root = canvas.getRoot();
|
|
1731
1842
|
const transientRoot = transientCanvas.getRoot();
|
|
1732
|
-
const
|
|
1733
|
-
const backgroundBBox = backgroundRoot.
|
|
1734
|
-
const BBox = root.
|
|
1735
|
-
const transientBBox = transientRoot.
|
|
1843
|
+
const labelRoot = labelCanvas.getRoot();
|
|
1844
|
+
const backgroundBBox = backgroundRoot.getRenderBounds();
|
|
1845
|
+
const BBox = root.getRenderBounds();
|
|
1846
|
+
const transientBBox = transientRoot.getRenderBounds();
|
|
1847
|
+
const labelBBox = labelRoot.getRenderBounds();
|
|
1736
1848
|
let padding = imageConfig ? imageConfig.padding : undefined;
|
|
1737
1849
|
if (!padding) {
|
|
1738
1850
|
padding = [0, 0, 0, 0];
|
|
@@ -1740,26 +1852,10 @@ export class Graph extends EventEmitter {
|
|
|
1740
1852
|
else if (isNumber(padding)) {
|
|
1741
1853
|
padding = [padding, padding, padding, padding];
|
|
1742
1854
|
}
|
|
1743
|
-
const left = (transientBBox.
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
: BBox.left) - padding[3];
|
|
1748
|
-
const right = (transientBBox.right
|
|
1749
|
-
? backgroundBBox.right
|
|
1750
|
-
? Math.max(backgroundBBox.right, BBox.right, transientBBox.right)
|
|
1751
|
-
: Math.max(BBox.right, transientBBox.right)
|
|
1752
|
-
: BBox.right) + padding[1];
|
|
1753
|
-
const top = (transientBBox.top
|
|
1754
|
-
? backgroundBBox.top
|
|
1755
|
-
? Math.min(backgroundBBox.top, BBox.top, transientBBox.top)
|
|
1756
|
-
: Math.min(BBox.top, transientBBox.top)
|
|
1757
|
-
: BBox.top) - padding[0];
|
|
1758
|
-
const bottom = (transientBBox.bottom
|
|
1759
|
-
? backgroundBBox.bottom
|
|
1760
|
-
? Math.max(backgroundBBox.bottom, BBox.bottom, transientBBox.bottom)
|
|
1761
|
-
: Math.max(BBox.bottom, transientBBox.bottom)
|
|
1762
|
-
: BBox.bottom) + padding[2];
|
|
1855
|
+
const left = Math.min(backgroundBBox.min[0] || Infinity, BBox.min[0] || Infinity, transientBBox.min[0] || Infinity, labelBBox.min[0] || Infinity) - padding[3];
|
|
1856
|
+
const right = Math.max(backgroundBBox.max[0] || -Infinity, BBox.max[0] || -Infinity, transientBBox.max[0] || -Infinity, labelBBox.max[0] || -Infinity) - padding[1];
|
|
1857
|
+
const top = Math.min(backgroundBBox.min[1] || Infinity, BBox.min[1] || Infinity, transientBBox.min[1] || Infinity, labelBBox.min[1] || Infinity) - padding[0];
|
|
1858
|
+
const bottom = Math.max(backgroundBBox.max[1] || -Infinity, BBox.max[1] || -Infinity, transientBBox.max[1] || -Infinity, labelBBox.max[1] || -Infinity) - padding[2];
|
|
1763
1859
|
const graphCenterX = (left + right) / 2;
|
|
1764
1860
|
const graphCenterY = (top + bottom) / 2;
|
|
1765
1861
|
const halfX = (right - left) / 2;
|
|
@@ -1769,6 +1865,7 @@ export class Graph extends EventEmitter {
|
|
|
1769
1865
|
const vHeight = halfY * 2;
|
|
1770
1866
|
const vContainerDOM = createDOM('<div id="virtual-image"></div>');
|
|
1771
1867
|
const vCanvas = createCanvas(rendererType, vContainerDOM, vWidth, vHeight, pixelRatio);
|
|
1868
|
+
yield vCanvas.ready;
|
|
1772
1869
|
const vCanvasContextService = vCanvas.getContextService();
|
|
1773
1870
|
if (rendererType !== 'svg') {
|
|
1774
1871
|
const bgRect = new Rect({
|
|
@@ -1787,6 +1884,7 @@ export class Graph extends EventEmitter {
|
|
|
1787
1884
|
const backgroundClonedGroup = backgroundRoot.cloneNode(true);
|
|
1788
1885
|
const clonedGroup = root.cloneNode(true);
|
|
1789
1886
|
const transientClonedGroup = transientRoot.cloneNode(true);
|
|
1887
|
+
const labelClonedGroup = labelRoot.cloneNode(true);
|
|
1790
1888
|
const transPosition = [
|
|
1791
1889
|
-graphCenterX + halfX,
|
|
1792
1890
|
-graphCenterY + halfY,
|
|
@@ -1794,17 +1892,36 @@ export class Graph extends EventEmitter {
|
|
|
1794
1892
|
backgroundClonedGroup.setPosition(transPosition);
|
|
1795
1893
|
clonedGroup.setPosition(transPosition);
|
|
1796
1894
|
transientClonedGroup.setPosition(transPosition);
|
|
1895
|
+
const currentViewportLTCanvas = canvas.viewport2Canvas({ x: 0, y: 0 });
|
|
1896
|
+
const labelTransPosition = [
|
|
1897
|
+
transPosition[0] + currentViewportLTCanvas.x,
|
|
1898
|
+
transPosition[1] + currentViewportLTCanvas.y,
|
|
1899
|
+
];
|
|
1900
|
+
labelClonedGroup.setPosition(labelTransPosition);
|
|
1901
|
+
labelClonedGroup.scale(1 / canvas.getCamera().getZoom());
|
|
1902
|
+
// TODO: after cloning, label background with rotation take a wrong place, remove it to temporary solve.
|
|
1903
|
+
labelClonedGroup.children[0].children.forEach((childGroup) => {
|
|
1904
|
+
childGroup.children.forEach((shape) => {
|
|
1905
|
+
if (shape.getAttribute('data-is-label-background') &&
|
|
1906
|
+
shape.style.transform)
|
|
1907
|
+
shape.remove();
|
|
1908
|
+
});
|
|
1909
|
+
});
|
|
1797
1910
|
vCanvas.appendChild(backgroundClonedGroup);
|
|
1798
1911
|
vCanvas.appendChild(clonedGroup);
|
|
1912
|
+
vCanvas.appendChild(labelClonedGroup);
|
|
1799
1913
|
vCanvas.appendChild(transientClonedGroup);
|
|
1800
|
-
vCanvas.render();
|
|
1801
1914
|
if (!type)
|
|
1802
1915
|
type = 'image/png';
|
|
1803
1916
|
let dataURL = '';
|
|
1804
|
-
|
|
1805
|
-
|
|
1917
|
+
return new Promise((resolve) => {
|
|
1918
|
+
setTimeout(() => {
|
|
1919
|
+
vCanvasContextService.toDataURL({ type }).then((url) => {
|
|
1920
|
+
dataURL = url;
|
|
1921
|
+
resolve(dataURL);
|
|
1922
|
+
});
|
|
1923
|
+
}, 50);
|
|
1806
1924
|
});
|
|
1807
|
-
return dataURL;
|
|
1808
1925
|
});
|
|
1809
1926
|
}
|
|
1810
1927
|
/**
|
|
@@ -2066,7 +2183,7 @@ export class Graph extends EventEmitter {
|
|
|
2066
2183
|
* @returns
|
|
2067
2184
|
* @group Tree
|
|
2068
2185
|
*/
|
|
2069
|
-
collapse(ids, disableAnimate = false
|
|
2186
|
+
collapse(ids, disableAnimate = false) {
|
|
2070
2187
|
this.hooks.treecollapseexpand.emit({
|
|
2071
2188
|
ids: isArray(ids) ? ids : [ids],
|
|
2072
2189
|
action: 'collapse',
|
|
@@ -2082,7 +2199,7 @@ export class Graph extends EventEmitter {
|
|
|
2082
2199
|
* @returns
|
|
2083
2200
|
* @group Tree
|
|
2084
2201
|
*/
|
|
2085
|
-
expand(ids, disableAnimate = false
|
|
2202
|
+
expand(ids, disableAnimate = false) {
|
|
2086
2203
|
this.hooks.treecollapseexpand.emit({
|
|
2087
2204
|
ids: isArray(ids) ? ids : [ids],
|
|
2088
2205
|
action: 'expand',
|
|
@@ -2096,15 +2213,23 @@ export class Graph extends EventEmitter {
|
|
|
2096
2213
|
* @group Graph Instance
|
|
2097
2214
|
*/
|
|
2098
2215
|
destroy(callback) {
|
|
2099
|
-
|
|
2100
|
-
|
|
2216
|
+
var _a;
|
|
2217
|
+
const camera = this.canvas.getCamera();
|
|
2218
|
+
const transientCamera = this.transientCanvas.getCamera();
|
|
2219
|
+
// @ts-ignore
|
|
2220
|
+
if ((_a = camera.landmarks) === null || _a === void 0 ? void 0 : _a.length) {
|
|
2221
|
+
camera.cancelLandmarkAnimation();
|
|
2222
|
+
transientCamera.cancelLandmarkAnimation();
|
|
2223
|
+
this.emit('cancelviewportanimation');
|
|
2224
|
+
}
|
|
2101
2225
|
this.canvas.destroy();
|
|
2226
|
+
this.labelCanvas.destroy();
|
|
2102
2227
|
this.backgroundCanvas.destroy();
|
|
2103
2228
|
this.transientCanvas.destroy();
|
|
2229
|
+
this.transientLabelCanvas.destroy();
|
|
2104
2230
|
// clear history stack
|
|
2105
2231
|
this.cleanHistory();
|
|
2106
2232
|
callback === null || callback === void 0 ? void 0 : callback();
|
|
2107
|
-
// }, 500);
|
|
2108
2233
|
this.hooks.destroy.emit({});
|
|
2109
2234
|
// TODO: destroy controllers and off the listeners
|
|
2110
2235
|
// this.dataController.destroy();
|
|
@@ -2112,7 +2237,6 @@ export class Graph extends EventEmitter {
|
|
|
2112
2237
|
// this.layoutController.destroy();
|
|
2113
2238
|
// this.themeController.destroy();
|
|
2114
2239
|
// this.itemController.destroy();
|
|
2115
|
-
// this.extensionController.destroy();
|
|
2116
2240
|
this.destroyed = true;
|
|
2117
2241
|
}
|
|
2118
2242
|
}
|