@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
|
@@ -0,0 +1,602 @@
|
|
|
1
|
+
import { debounce, uniqueId, throttle, isArray } from '@antv/util';
|
|
2
|
+
import { AABB } from '@antv/g';
|
|
3
|
+
import {
|
|
4
|
+
ComboDisplayModel,
|
|
5
|
+
ComboModel,
|
|
6
|
+
EdgeDisplayModel,
|
|
7
|
+
EdgeModel,
|
|
8
|
+
ID,
|
|
9
|
+
IGraph,
|
|
10
|
+
NodeDisplayModel,
|
|
11
|
+
NodeModel,
|
|
12
|
+
} from '../../../types';
|
|
13
|
+
import { Plugin as Base, IPluginBaseConfig } from '../../../types/plugin';
|
|
14
|
+
import { intersectBBox } from '../../../util/shape';
|
|
15
|
+
import { getZoomLevel } from '../../../util/zoom';
|
|
16
|
+
import { GraphTransformOptions } from '../../../types/view';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* This is an interface named `LodControllerConfig`, which extends the `IPluginBaseConfig` interface. It contains the following properties:
|
|
20
|
+
* cellSize
|
|
21
|
+
* numberPerCell
|
|
22
|
+
*/
|
|
23
|
+
export interface LodControllerConfig extends IPluginBaseConfig {
|
|
24
|
+
cellSize?: number;
|
|
25
|
+
numberPerCell?: number;
|
|
26
|
+
disableLod?: boolean;
|
|
27
|
+
debounce?: number | 'auto';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class LodController extends Base {
|
|
31
|
+
static required: boolean = true;
|
|
32
|
+
private shownIds = new Map();
|
|
33
|
+
private cacheViewModels: {
|
|
34
|
+
inView: (NodeModel | EdgeModel | ComboModel)[];
|
|
35
|
+
outView: (NodeModel | EdgeModel | ComboModel)[];
|
|
36
|
+
newlyOutView: (NodeModel | EdgeModel | ComboModel)[];
|
|
37
|
+
newlyInView: (NodeModel | EdgeModel | ComboModel)[];
|
|
38
|
+
};
|
|
39
|
+
private displayModelCache: Map<
|
|
40
|
+
ID,
|
|
41
|
+
NodeDisplayModel | EdgeDisplayModel | ComboDisplayModel
|
|
42
|
+
> = new Map();
|
|
43
|
+
private renderBoundsCache: Map<ID, AABB | false> = new Map();
|
|
44
|
+
private canvasCellDirty: boolean = true;
|
|
45
|
+
private canvasCellSize = 100;
|
|
46
|
+
private modelCanvasIdxMap: Map<ID, { rowIdx: number; colIdx: number }>;
|
|
47
|
+
private labelPositionDirty: Map<ID, boolean> = new Map();
|
|
48
|
+
private debounce = 16;
|
|
49
|
+
private animationUpdateTimer: number = 0;
|
|
50
|
+
|
|
51
|
+
constructor(options?: LodControllerConfig) {
|
|
52
|
+
super(options);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public getDefaultCfgs(): LodControllerConfig {
|
|
56
|
+
return {
|
|
57
|
+
key: `lodController-${uniqueId()}`,
|
|
58
|
+
cellSize: 200,
|
|
59
|
+
numberPerCell: 1,
|
|
60
|
+
disableLod: false,
|
|
61
|
+
disableAnimate: true,
|
|
62
|
+
debounce: 'auto',
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public init(graph: IGraph) {
|
|
67
|
+
super.init(graph);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public getEvents() {
|
|
71
|
+
if (this.graph.rendererType === 'webgl-3d') return {};
|
|
72
|
+
return {
|
|
73
|
+
afterrender: this.onAfterRender,
|
|
74
|
+
afterlayout: this.onAfterLayout,
|
|
75
|
+
aftersetsize: this.updateCells,
|
|
76
|
+
viewportchange: this.updateCells,
|
|
77
|
+
afteritemchange: this.updateCacheModels,
|
|
78
|
+
beforeviewportanimation: this.beforeViewportAnimation,
|
|
79
|
+
afterviewportanimation: this.afterViewportAnimation,
|
|
80
|
+
cancelviewportanimation: this.afterViewportAnimation,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
protected onAfterRender = () => {
|
|
85
|
+
// show the shapes with lod when diableLod is true
|
|
86
|
+
const { graph, options } = this;
|
|
87
|
+
|
|
88
|
+
this.clearCache();
|
|
89
|
+
|
|
90
|
+
this.debounce = 80;
|
|
91
|
+
if (options.debounce === undefined || options.debounce === 'auto') {
|
|
92
|
+
const nodes = graph.getAllNodesData();
|
|
93
|
+
this.debounce = Math.min(Math.floor(nodes.length / 100), 80);
|
|
94
|
+
}
|
|
95
|
+
this.debounceUpdateVisible = this.getDebounceFn(
|
|
96
|
+
this.updateVisible.bind(this),
|
|
97
|
+
);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
protected onAfterLayout = () => {
|
|
101
|
+
this.canvasCellDirty = true;
|
|
102
|
+
this.updateLabelPositions(1);
|
|
103
|
+
this.updateCells();
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Update grid.
|
|
107
|
+
* @param param
|
|
108
|
+
*/
|
|
109
|
+
protected updateCells = (params?: GraphTransformOptions) => {
|
|
110
|
+
if (!this.graph.canvasReady) return;
|
|
111
|
+
const { zoom } = params || {};
|
|
112
|
+
if (params) {
|
|
113
|
+
this.updateLabelPositions(zoom?.ratio);
|
|
114
|
+
}
|
|
115
|
+
// @ts-ignore
|
|
116
|
+
if (!this.options.disableLod) this.debounceUpdateVisible(zoom?.ratio);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
private getDebounceFn = (fn) => {
|
|
120
|
+
return debounce(fn, this.debounce, false);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
private updateVisible = (zoomRatio = 1) => {
|
|
124
|
+
const { graph, cacheViewModels, options } = this;
|
|
125
|
+
const { cellSize, numberPerCell, disableAnimate, disableLod } = options;
|
|
126
|
+
const graphZoom = graph.getZoom();
|
|
127
|
+
const { inView } = cacheViewModels || this.groupItemsByView(1);
|
|
128
|
+
|
|
129
|
+
const cells = new Map<string, ID[]>();
|
|
130
|
+
const candidateShapeMap = new Map<
|
|
131
|
+
ID,
|
|
132
|
+
{
|
|
133
|
+
lodVisibleShapeIds: string[];
|
|
134
|
+
autoVisibleShapeIds: string[];
|
|
135
|
+
invisibleShapeIds: string[];
|
|
136
|
+
}
|
|
137
|
+
>();
|
|
138
|
+
const lodVisibleIds = [];
|
|
139
|
+
const lodInvisibleIds = new Map<ID, string[]>();
|
|
140
|
+
inView.forEach((model) => {
|
|
141
|
+
const displayModel = this.getDisplayModel(model.id);
|
|
142
|
+
const { lodLevels, x, y, z, ...others } = displayModel.data;
|
|
143
|
+
const lodLevelsEmpty = isEmptyObj(lodLevels);
|
|
144
|
+
const currentZoomLevel = lodLevelsEmpty
|
|
145
|
+
? 0
|
|
146
|
+
: getZoomLevel(lodLevels as any, graphZoom);
|
|
147
|
+
const autoVisibleShapeIds = [];
|
|
148
|
+
const lodVisibleShapeIds = [];
|
|
149
|
+
const invisibleShapeIds = [];
|
|
150
|
+
Object.keys(others).forEach((shapeId) => {
|
|
151
|
+
if (shapeId === 'keyShape') return;
|
|
152
|
+
const val = others[shapeId] as any;
|
|
153
|
+
if (
|
|
154
|
+
!val ||
|
|
155
|
+
typeof val !== 'object' ||
|
|
156
|
+
!Object.keys(val).length ||
|
|
157
|
+
isArray(val)
|
|
158
|
+
) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const { lod, visible } = val;
|
|
162
|
+
if (visible === false) return;
|
|
163
|
+
if (lodLevelsEmpty || lod === 'auto') {
|
|
164
|
+
autoVisibleShapeIds.push(shapeId);
|
|
165
|
+
} else if (lod <= currentZoomLevel) {
|
|
166
|
+
lodVisibleShapeIds.push(shapeId);
|
|
167
|
+
} else {
|
|
168
|
+
invisibleShapeIds.push(shapeId);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
if (!lodVisibleShapeIds.length && !autoVisibleShapeIds.length) {
|
|
173
|
+
lodInvisibleIds.set(model.id, invisibleShapeIds);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const bounds = this.getRenderBBox(model.id);
|
|
178
|
+
if (!bounds || !graph.getItemVisible(model.id)) {
|
|
179
|
+
lodInvisibleIds.set(model.id, invisibleShapeIds);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (!autoVisibleShapeIds.length) {
|
|
184
|
+
lodVisibleIds.push(model.id);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const { center } = bounds;
|
|
188
|
+
const param = graphZoom / cellSize;
|
|
189
|
+
// rowIdx = (center[i] * graphZoom + offset[i]) - offset[i] / cellSize = center[i] * param
|
|
190
|
+
const rowIdx = Math.floor((center[0] || x) * param);
|
|
191
|
+
const colIdx = Math.floor((center[1] || y) * param);
|
|
192
|
+
const cellIdx = `${rowIdx}-${colIdx}`;
|
|
193
|
+
const cellNodeIds = cells.get(cellIdx) || [];
|
|
194
|
+
cellNodeIds.push(model.id);
|
|
195
|
+
cells.set(cellIdx, cellNodeIds);
|
|
196
|
+
candidateShapeMap.set(model.id, {
|
|
197
|
+
lodVisibleShapeIds,
|
|
198
|
+
autoVisibleShapeIds,
|
|
199
|
+
invisibleShapeIds,
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
const shownIds = new Map();
|
|
203
|
+
cells.forEach((cell) => {
|
|
204
|
+
// priority: lod Visible > shown last time > rest auto
|
|
205
|
+
cell.sort((a, b) => {
|
|
206
|
+
const { lodVisibleShapeIds: aLodVisibleShapeIds } =
|
|
207
|
+
candidateShapeMap.get(a);
|
|
208
|
+
const { lodVisibleShapeIds: bLodVisibleShapeIds } =
|
|
209
|
+
candidateShapeMap.get(b);
|
|
210
|
+
if (lodVisibleIds.includes(b) && bLodVisibleShapeIds.length) return 1;
|
|
211
|
+
if (lodVisibleIds.includes(a) && aLodVisibleShapeIds.length) return -1;
|
|
212
|
+
const bShownLastTime = this.shownIds.has(b) && !lodInvisibleIds.has(b);
|
|
213
|
+
if (bShownLastTime) return 1;
|
|
214
|
+
const aShownLastTime = this.shownIds.has(a) && !lodInvisibleIds.has(a);
|
|
215
|
+
if (aShownLastTime) return -1;
|
|
216
|
+
return 0;
|
|
217
|
+
});
|
|
218
|
+
let rest = numberPerCell;
|
|
219
|
+
cell.forEach((id) => {
|
|
220
|
+
const { lodVisibleShapeIds, autoVisibleShapeIds, invisibleShapeIds } =
|
|
221
|
+
candidateShapeMap.get(id);
|
|
222
|
+
|
|
223
|
+
if (!disableLod && invisibleShapeIds.length) {
|
|
224
|
+
graph.hideItem(id, { shapeIds: invisibleShapeIds, disableAnimate });
|
|
225
|
+
}
|
|
226
|
+
const item = graph.itemController.itemMap.get(id);
|
|
227
|
+
if (
|
|
228
|
+
disableLod ||
|
|
229
|
+
(item.labelGroup.children.length &&
|
|
230
|
+
(rest > 0 || (zoomRatio >= 1 && this.shownIds.has(id))))
|
|
231
|
+
) {
|
|
232
|
+
const shapeIdsToShow = lodVisibleShapeIds.concat(autoVisibleShapeIds);
|
|
233
|
+
if (shapeIdsToShow.length) {
|
|
234
|
+
graph.showItem(id, {
|
|
235
|
+
shapeIds: lodVisibleShapeIds.concat(autoVisibleShapeIds),
|
|
236
|
+
disableAnimate,
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
if (this.labelPositionDirty.has(id)) {
|
|
240
|
+
item.updateLabelPosition(disableLod);
|
|
241
|
+
this.labelPositionDirty.delete(id);
|
|
242
|
+
}
|
|
243
|
+
shownIds.set(id, 1);
|
|
244
|
+
rest--;
|
|
245
|
+
} else {
|
|
246
|
+
if (
|
|
247
|
+
lodVisibleShapeIds.includes('labelShape') &&
|
|
248
|
+
this.labelPositionDirty.has(id)
|
|
249
|
+
) {
|
|
250
|
+
item.updateLabelPosition(disableLod);
|
|
251
|
+
this.labelPositionDirty.delete(id);
|
|
252
|
+
}
|
|
253
|
+
lodVisibleShapeIds.length &&
|
|
254
|
+
graph.showItem(id, {
|
|
255
|
+
shapeIds: lodVisibleShapeIds,
|
|
256
|
+
disableAnimate,
|
|
257
|
+
});
|
|
258
|
+
if (!disableLod && autoVisibleShapeIds.length) {
|
|
259
|
+
graph.hideItem(id, {
|
|
260
|
+
shapeIds: autoVisibleShapeIds,
|
|
261
|
+
disableAnimate,
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
if (!disableLod) {
|
|
268
|
+
lodInvisibleIds.forEach((shapeIds, id) => {
|
|
269
|
+
shapeIds.length && graph.hideItem(id, { shapeIds, disableAnimate });
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
this.shownIds = shownIds;
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
private debounceUpdateVisible = this.getDebounceFn(
|
|
276
|
+
this.updateVisible.bind(this),
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
private updateLabelPositions = throttle(
|
|
280
|
+
(zoomRatio) => {
|
|
281
|
+
const { graph, options } = this;
|
|
282
|
+
const { inView, newlyOutView, newlyInView } =
|
|
283
|
+
this.groupItemsByView(zoomRatio);
|
|
284
|
+
const graphZoom = graph.getZoom();
|
|
285
|
+
const levelCache = {};
|
|
286
|
+
this.labelPositionDirty.clear();
|
|
287
|
+
|
|
288
|
+
// 1. inside current view &&
|
|
289
|
+
// 2. lod is number and matches the current zoom ratio
|
|
290
|
+
// 3. lod is 'auto' and filtered by cells)
|
|
291
|
+
// 1 && (2 || 3)
|
|
292
|
+
inView.forEach((model) => {
|
|
293
|
+
this.labelPositionDirty.set(model.id, true);
|
|
294
|
+
const item = graph.itemController.itemMap.get(model.id);
|
|
295
|
+
if (
|
|
296
|
+
!item ||
|
|
297
|
+
!item.labelGroup.children.length ||
|
|
298
|
+
!item.shapeMap.labelShape ||
|
|
299
|
+
(!options.disableLod &&
|
|
300
|
+
(item.labelGroup.style.visibility === 'hidden' ||
|
|
301
|
+
item.shapeMap.labelShape.style.visibility === 'hidden'))
|
|
302
|
+
) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
const displayModel = this.getDisplayModel(model.id);
|
|
306
|
+
const { labelShape, lodLevels } = displayModel.data;
|
|
307
|
+
if (!labelShape) return;
|
|
308
|
+
const updatePosition = () => {
|
|
309
|
+
// adjust labels'positions for visible items
|
|
310
|
+
item.updateLabelPosition(options.disableLod);
|
|
311
|
+
this.labelPositionDirty.delete(model.id);
|
|
312
|
+
};
|
|
313
|
+
const { visible, lod } = labelShape;
|
|
314
|
+
if (visible === false) return;
|
|
315
|
+
if (lod === undefined) {
|
|
316
|
+
updatePosition();
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
if (lod === 'auto') {
|
|
320
|
+
updatePosition();
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
if (typeof lod !== 'number' || item.animations?.length) {
|
|
324
|
+
// lod is 'auto' / lod is not defined / during animating
|
|
325
|
+
updatePosition();
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
const lodLevelsEmpty = isEmptyObj(lodLevels);
|
|
329
|
+
if (lodLevelsEmpty) {
|
|
330
|
+
updatePosition();
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
const levelsKey = JSON.stringify(lodLevels);
|
|
334
|
+
const currentZoomLevel =
|
|
335
|
+
levelCache[levelsKey] || lodLevelsEmpty
|
|
336
|
+
? 0
|
|
337
|
+
: getZoomLevel(lodLevels as any, graphZoom);
|
|
338
|
+
levelCache[levelsKey] = currentZoomLevel;
|
|
339
|
+
if (lod <= currentZoomLevel) {
|
|
340
|
+
// lod visible
|
|
341
|
+
updatePosition();
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
newlyOutView.forEach((model) => {
|
|
345
|
+
graph.hideItem(model.id, {
|
|
346
|
+
shapeIds: ['labelShape', 'labelBackgroundShape'],
|
|
347
|
+
disableAnimate: true,
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
if (options.disableLod) {
|
|
351
|
+
newlyInView.forEach((model) => {
|
|
352
|
+
graph.showItem(model.id, {
|
|
353
|
+
shapeIds: ['labelShape', 'labelBackgroundShape'],
|
|
354
|
+
disableAnimate: true,
|
|
355
|
+
});
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
},
|
|
359
|
+
16,
|
|
360
|
+
{
|
|
361
|
+
leading: true,
|
|
362
|
+
trailing: true,
|
|
363
|
+
},
|
|
364
|
+
);
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* get the items inside viewport
|
|
368
|
+
* @returns
|
|
369
|
+
*/
|
|
370
|
+
private groupItemsByView = (ratio: number = 1) => {
|
|
371
|
+
const { graph } = this;
|
|
372
|
+
const range = graph.getCanvasRange();
|
|
373
|
+
const models = graph.getAllNodesData().concat(graph.getAllEdgesData());
|
|
374
|
+
let { inView, outView } = this.cacheViewModels || {};
|
|
375
|
+
if (this.canvasCellDirty) this.updateCanvasCells();
|
|
376
|
+
const canvasCellRowRange = [
|
|
377
|
+
Math.floor(range.min[0] / this.canvasCellSize),
|
|
378
|
+
Math.ceil(range.max[0] / this.canvasCellSize),
|
|
379
|
+
];
|
|
380
|
+
const canvasCellColRange = [
|
|
381
|
+
Math.floor(range.min[1] / this.canvasCellSize),
|
|
382
|
+
Math.ceil(range.max[1] / this.canvasCellSize),
|
|
383
|
+
];
|
|
384
|
+
const atBoundary = (rowIdx, colIdx) => {
|
|
385
|
+
if (
|
|
386
|
+
rowIdx > canvasCellRowRange[0] &&
|
|
387
|
+
rowIdx < canvasCellRowRange[1] &&
|
|
388
|
+
(Math.abs(colIdx - canvasCellColRange[0]) < 2 ||
|
|
389
|
+
Math.abs(colIdx - canvasCellColRange[1]) < 2)
|
|
390
|
+
) {
|
|
391
|
+
return true;
|
|
392
|
+
} else if (
|
|
393
|
+
colIdx > canvasCellColRange[0] &&
|
|
394
|
+
colIdx < canvasCellColRange[1] &&
|
|
395
|
+
(Math.abs(rowIdx - canvasCellRowRange[0]) < 2 ||
|
|
396
|
+
Math.abs(rowIdx - canvasCellRowRange[1]) < 2)
|
|
397
|
+
) {
|
|
398
|
+
return true;
|
|
399
|
+
}
|
|
400
|
+
return false;
|
|
401
|
+
};
|
|
402
|
+
const outBoundary = (rowIdx, colIdx) => {
|
|
403
|
+
return (
|
|
404
|
+
rowIdx <= canvasCellRowRange[0] ||
|
|
405
|
+
rowIdx >= canvasCellRowRange[1] ||
|
|
406
|
+
colIdx <= canvasCellColRange[0] ||
|
|
407
|
+
colIdx >= canvasCellColRange[1]
|
|
408
|
+
);
|
|
409
|
+
};
|
|
410
|
+
const newlyOutView = [];
|
|
411
|
+
const newlyInView = [];
|
|
412
|
+
const cacheIsEmpty =
|
|
413
|
+
!this.cacheViewModels || (!inView.length && !outView.length);
|
|
414
|
+
if (!ratio || ratio === 1 || cacheIsEmpty) {
|
|
415
|
+
const previousOutView = new Map();
|
|
416
|
+
const previousInView = new Map();
|
|
417
|
+
outView?.forEach((model) => previousOutView.set(model.id, true));
|
|
418
|
+
inView?.forEach((model) => previousInView.set(model.id, true));
|
|
419
|
+
inView = [];
|
|
420
|
+
outView = [];
|
|
421
|
+
models.forEach((model) => {
|
|
422
|
+
if (!this.modelCanvasIdxMap.get(model.id)) {
|
|
423
|
+
outView.push(model);
|
|
424
|
+
if (!previousOutView.has(model.id)) newlyOutView.push(model);
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
const { rowIdx, colIdx } = this.modelCanvasIdxMap.get(model.id);
|
|
428
|
+
if (atBoundary(rowIdx, colIdx)) {
|
|
429
|
+
const renderBounds = this.getRenderBBox(model.id);
|
|
430
|
+
if (!renderBounds) return;
|
|
431
|
+
if (intersectBBox(renderBounds, range)) {
|
|
432
|
+
inView.push(model);
|
|
433
|
+
if (!previousInView.has(model.id)) newlyInView.push(model);
|
|
434
|
+
} else {
|
|
435
|
+
outView.push(model);
|
|
436
|
+
if (!previousOutView.has(model.id)) newlyOutView.push(model);
|
|
437
|
+
}
|
|
438
|
+
} else if (outBoundary(rowIdx, colIdx)) {
|
|
439
|
+
outView.push(model);
|
|
440
|
+
if (!previousOutView.has(model.id)) newlyOutView.push(model);
|
|
441
|
+
} else {
|
|
442
|
+
inView.push(model);
|
|
443
|
+
if (!previousInView.has(model.id)) newlyInView.push(model);
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
} else if (ratio < 1) {
|
|
447
|
+
// zoom-out
|
|
448
|
+
const outViewNew = [];
|
|
449
|
+
outView.forEach((model) => {
|
|
450
|
+
if (!this.modelCanvasIdxMap.get(model.id)) {
|
|
451
|
+
outViewNew.push(model);
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
const { rowIdx, colIdx } = this.modelCanvasIdxMap.get(model.id);
|
|
455
|
+
if (atBoundary(rowIdx, colIdx)) {
|
|
456
|
+
const renderBounds = this.getRenderBBox(model.id);
|
|
457
|
+
if (!renderBounds) return;
|
|
458
|
+
if (intersectBBox(renderBounds, range)) {
|
|
459
|
+
inView.push(model);
|
|
460
|
+
newlyInView.push(model);
|
|
461
|
+
} else {
|
|
462
|
+
outViewNew.push(model);
|
|
463
|
+
}
|
|
464
|
+
} else if (outBoundary(rowIdx, colIdx)) {
|
|
465
|
+
outViewNew.push(model);
|
|
466
|
+
} else {
|
|
467
|
+
inView.push(model);
|
|
468
|
+
newlyInView.push(model);
|
|
469
|
+
}
|
|
470
|
+
});
|
|
471
|
+
outView = outViewNew;
|
|
472
|
+
} else if (ratio > 1) {
|
|
473
|
+
// zoom-in
|
|
474
|
+
const inViewNew = [];
|
|
475
|
+
inView.forEach((model) => {
|
|
476
|
+
if (!this.modelCanvasIdxMap.get(model.id)) {
|
|
477
|
+
outView.push(model);
|
|
478
|
+
newlyOutView.push(model);
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
const { rowIdx, colIdx } = this.modelCanvasIdxMap.get(model.id);
|
|
482
|
+
if (atBoundary(rowIdx, colIdx)) {
|
|
483
|
+
const renderBounds = this.getRenderBBox(model.id);
|
|
484
|
+
if (!renderBounds) return;
|
|
485
|
+
if (!intersectBBox(renderBounds, range)) {
|
|
486
|
+
outView.push(model);
|
|
487
|
+
newlyOutView.push(model);
|
|
488
|
+
} else {
|
|
489
|
+
inViewNew.push(model);
|
|
490
|
+
}
|
|
491
|
+
} else if (outBoundary(rowIdx, colIdx)) {
|
|
492
|
+
outView.push(model);
|
|
493
|
+
newlyOutView.push(model);
|
|
494
|
+
} else {
|
|
495
|
+
inViewNew.push(model);
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
inView = inViewNew;
|
|
499
|
+
}
|
|
500
|
+
this.cacheViewModels = { inView, outView, newlyOutView, newlyInView };
|
|
501
|
+
return this.cacheViewModels;
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
private updateCanvasCells = () => {
|
|
505
|
+
const canvasCells = new Map();
|
|
506
|
+
const idxMap = new Map();
|
|
507
|
+
const { graph, canvasCellSize } = this;
|
|
508
|
+
graph.getAllNodesData().forEach((model) => {
|
|
509
|
+
const { x, y } = model.data;
|
|
510
|
+
const rowIdx = Math.floor(x / canvasCellSize);
|
|
511
|
+
const colIdx = Math.floor(y / canvasCellSize);
|
|
512
|
+
const cellIdx = `${rowIdx}-${colIdx}`;
|
|
513
|
+
const cell = canvasCells.get(cellIdx) || [];
|
|
514
|
+
cell.push(model.id);
|
|
515
|
+
canvasCells.set(cellIdx, cell);
|
|
516
|
+
idxMap.set(model.id, { rowIdx, colIdx });
|
|
517
|
+
});
|
|
518
|
+
graph.getAllEdgesData().forEach((model) => {
|
|
519
|
+
const { source, target } = model;
|
|
520
|
+
const { rowIdx: sourceRowIdx, colIdx: sourceColIdx } = idxMap.get(source);
|
|
521
|
+
const { rowIdx: targetRowIdx, colIdx: targetColIdx } = idxMap.get(target);
|
|
522
|
+
const centerRowIdx = Math.round((sourceRowIdx + targetRowIdx) / 2);
|
|
523
|
+
const centerColIdx = Math.round((sourceColIdx + targetColIdx) / 2);
|
|
524
|
+
const cellIdx = `${centerRowIdx}-${centerColIdx}`;
|
|
525
|
+
const cell = canvasCells.get(cellIdx) || [];
|
|
526
|
+
cell.push(model.id);
|
|
527
|
+
canvasCells.set(cellIdx, cell);
|
|
528
|
+
idxMap.set(model.id, { rowIdx: centerRowIdx, colIdx: centerColIdx });
|
|
529
|
+
});
|
|
530
|
+
this.modelCanvasIdxMap = idxMap;
|
|
531
|
+
this.canvasCellDirty = false;
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
protected updateCacheModels = (params) => {
|
|
535
|
+
const { models, action } = params;
|
|
536
|
+
this.canvasCellDirty = true;
|
|
537
|
+
models?.forEach((model) => {
|
|
538
|
+
this.renderBoundsCache.delete(model.id);
|
|
539
|
+
if (action !== 'updatePosition') {
|
|
540
|
+
this.displayModelCache.delete(model.id);
|
|
541
|
+
}
|
|
542
|
+
if (this.options.disableLod) {
|
|
543
|
+
this.graph.showItem(model.id, {
|
|
544
|
+
shapeIds: ['labelShape', 'labelBackgroundShape'],
|
|
545
|
+
disableAnimate: true,
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
});
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
protected beforeViewportAnimation = () => {
|
|
552
|
+
if (this.animationUpdateTimer) return;
|
|
553
|
+
this.animationUpdateTimer = setInterval(() => {
|
|
554
|
+
this.updateLabelPositions();
|
|
555
|
+
}, 16);
|
|
556
|
+
};
|
|
557
|
+
|
|
558
|
+
protected afterViewportAnimation = () => {
|
|
559
|
+
if (this.animationUpdateTimer) {
|
|
560
|
+
clearInterval(this.animationUpdateTimer);
|
|
561
|
+
this.animationUpdateTimer = 0;
|
|
562
|
+
}
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
protected clearCache = () => {
|
|
566
|
+
this.displayModelCache.clear();
|
|
567
|
+
this.renderBoundsCache.clear();
|
|
568
|
+
this.cacheViewModels = {
|
|
569
|
+
inView: [],
|
|
570
|
+
outView: [],
|
|
571
|
+
newlyOutView: [],
|
|
572
|
+
newlyInView: [],
|
|
573
|
+
};
|
|
574
|
+
};
|
|
575
|
+
private getDisplayModel = (id) => {
|
|
576
|
+
let displayModel = this.displayModelCache.get(id);
|
|
577
|
+
if (!displayModel) {
|
|
578
|
+
displayModel = this.graph.getDisplayModel(id);
|
|
579
|
+
this.displayModelCache.set(id, displayModel);
|
|
580
|
+
}
|
|
581
|
+
return displayModel;
|
|
582
|
+
};
|
|
583
|
+
private getRenderBBox = (id) => {
|
|
584
|
+
let renderBounds;
|
|
585
|
+
if (!this.renderBoundsCache.has(id)) {
|
|
586
|
+
renderBounds = this.graph.getRenderBBox(id, true);
|
|
587
|
+
this.renderBoundsCache.set(id, renderBounds);
|
|
588
|
+
} else {
|
|
589
|
+
renderBounds = this.renderBoundsCache.get(id);
|
|
590
|
+
}
|
|
591
|
+
return renderBounds;
|
|
592
|
+
};
|
|
593
|
+
|
|
594
|
+
public destroy() {
|
|
595
|
+
super.destroy();
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
const isEmptyObj = (obj) => {
|
|
600
|
+
if (!obj) return true;
|
|
601
|
+
return !Object.keys(obj).length;
|
|
602
|
+
};
|
|
@@ -12,7 +12,6 @@ import { createDOM, modifyCSS } from '../../../util/dom';
|
|
|
12
12
|
const DEFAULT_MODE = 'default';
|
|
13
13
|
const KEYSHAPE_MODE = 'keyShape';
|
|
14
14
|
const DELEGATE_MODE = 'delegate';
|
|
15
|
-
const SVG = 'svg';
|
|
16
15
|
|
|
17
16
|
export interface MiniMapConfig extends IPluginBaseConfig {
|
|
18
17
|
/** Class name of viewport */
|
|
@@ -111,18 +110,17 @@ export class Minimap extends Base {
|
|
|
111
110
|
const containerDOM = canvas.context.config.container as HTMLElement;
|
|
112
111
|
const isFireFox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
|
|
113
112
|
const isSafari = navigator.userAgent.toLowerCase().indexOf('safari') > -1;
|
|
114
|
-
const viewport = createDOM(
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
/>`);
|
|
113
|
+
const viewport = createDOM(`<div
|
|
114
|
+
class=${viewportClassName}
|
|
115
|
+
style='position:absolute;
|
|
116
|
+
left:0;
|
|
117
|
+
top:0;
|
|
118
|
+
border: 2px solid #1980ff;
|
|
119
|
+
box-sizing:border-box;
|
|
120
|
+
background: rgba(0, 0, 255, 0.1);
|
|
121
|
+
cursor:move'
|
|
122
|
+
draggable=${isSafari || isFireFox ? false : true}
|
|
123
|
+
/>`);
|
|
126
124
|
|
|
127
125
|
// Last mouse x position
|
|
128
126
|
let x = 0;
|
|
@@ -653,7 +651,7 @@ export class Minimap extends Base {
|
|
|
653
651
|
}
|
|
654
652
|
this.container = container;
|
|
655
653
|
|
|
656
|
-
const containerDOM =
|
|
654
|
+
const containerDOM = createDOM(
|
|
657
655
|
'<div class="g6-minimap-container" style="position: relative;"></div>',
|
|
658
656
|
);
|
|
659
657
|
container.appendChild(containerDOM);
|