@antv/g6 5.0.0-alpha.8 → 5.0.0-alpha.9
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 +6 -19
- package/esm/index.d.ts +26 -6
- package/esm/item/combo.d.ts +72 -2
- package/esm/item/combo.js +122 -2
- package/esm/item/combo.js.map +1 -1
- package/esm/item/edge.d.ts +3 -3
- package/esm/item/edge.js +4 -5
- package/esm/item/edge.js.map +1 -1
- package/esm/item/item.d.ts +4 -4
- package/esm/item/item.js +38 -9
- package/esm/item/item.js.map +1 -1
- package/esm/item/node.d.ts +20 -16
- package/esm/item/node.js +14 -8
- package/esm/item/node.js.map +1 -1
- package/esm/runtime/controller/data.d.ts +12 -4
- package/esm/runtime/controller/data.js +354 -62
- package/esm/runtime/controller/data.js.map +1 -1
- package/esm/runtime/controller/interaction.js +16 -4
- package/esm/runtime/controller/interaction.js.map +1 -1
- package/esm/runtime/controller/item.d.ts +11 -2
- package/esm/runtime/controller/item.js +344 -52
- package/esm/runtime/controller/item.js.map +1 -1
- package/esm/runtime/controller/layout.js +19 -5
- package/esm/runtime/controller/layout.js.map +1 -1
- package/esm/runtime/graph.d.ts +54 -17
- package/esm/runtime/graph.js +165 -34
- package/esm/runtime/graph.js.map +1 -1
- package/esm/stdlib/behavior/click-select.d.ts +3 -0
- package/esm/stdlib/behavior/click-select.js +13 -1
- package/esm/stdlib/behavior/click-select.js.map +1 -1
- package/esm/stdlib/behavior/collapse-expand-combo.d.ts +29 -0
- package/esm/stdlib/behavior/collapse-expand-combo.js +35 -0
- package/esm/stdlib/behavior/collapse-expand-combo.js.map +1 -0
- package/esm/stdlib/behavior/drag-combo.d.ts +99 -0
- package/esm/stdlib/behavior/drag-combo.js +341 -0
- package/esm/stdlib/behavior/drag-combo.js.map +1 -0
- package/esm/stdlib/behavior/drag-node.d.ts +14 -10
- package/esm/stdlib/behavior/drag-node.js +134 -37
- package/esm/stdlib/behavior/drag-node.js.map +1 -1
- package/esm/stdlib/behavior/hover-activate.d.ts +3 -1
- package/esm/stdlib/behavior/hover-activate.js +3 -1
- package/esm/stdlib/behavior/hover-activate.js.map +1 -1
- package/esm/stdlib/behavior/orbit-canvas-3d.js +1 -1
- package/esm/stdlib/behavior/orbit-canvas-3d.js.map +1 -1
- package/esm/stdlib/behavior/track-canvas-3d.js +1 -1
- package/esm/stdlib/behavior/track-canvas-3d.js.map +1 -1
- package/esm/stdlib/index.d.ts +25 -3
- package/esm/stdlib/index.js +25 -3
- package/esm/stdlib/index.js.map +1 -1
- package/esm/stdlib/item/combo/circle.d.ts +29 -0
- package/esm/stdlib/item/combo/circle.js +56 -0
- package/esm/stdlib/item/combo/circle.js.map +1 -0
- package/esm/stdlib/item/edge/base.d.ts +2 -2
- package/esm/stdlib/item/edge/base.js +3 -0
- package/esm/stdlib/item/edge/base.js.map +1 -1
- package/esm/stdlib/item/edge/cubic-horizon.d.ts +37 -0
- package/esm/stdlib/item/edge/cubic-horizon.js +71 -0
- package/esm/stdlib/item/edge/cubic-horizon.js.map +1 -0
- package/esm/stdlib/item/edge/cubic-vertical.d.ts +37 -0
- package/esm/stdlib/item/edge/cubic-vertical.js +71 -0
- package/esm/stdlib/item/edge/cubic-vertical.js.map +1 -0
- package/esm/stdlib/item/edge/cubic.d.ts +60 -0
- package/esm/stdlib/item/edge/cubic.js +99 -0
- package/esm/stdlib/item/edge/cubic.js.map +1 -0
- package/esm/stdlib/item/edge/index.d.ts +1 -0
- package/esm/stdlib/item/edge/index.js +1 -0
- package/esm/stdlib/item/edge/index.js.map +1 -1
- package/esm/stdlib/item/edge/line.d.ts +1 -1
- package/esm/stdlib/item/edge/quadratic.d.ts +41 -0
- package/esm/stdlib/item/edge/quadratic.js +66 -0
- package/esm/stdlib/item/edge/quadratic.js.map +1 -0
- package/esm/stdlib/item/node/base.d.ts +38 -37
- package/esm/stdlib/item/node/base.js +4 -4
- package/esm/stdlib/item/node/base.js.map +1 -1
- package/esm/stdlib/item/node/index.d.ts +1 -0
- package/esm/stdlib/item/node/index.js +1 -0
- package/esm/stdlib/item/node/index.js.map +1 -1
- package/esm/stdlib/item/node/rect.d.ts +31 -0
- package/esm/stdlib/item/node/rect.js +59 -0
- package/esm/stdlib/item/node/rect.js.map +1 -0
- package/esm/stdlib/plugin/fisheye/index.d.ts +102 -0
- package/esm/stdlib/plugin/fisheye/index.js +487 -0
- package/esm/stdlib/plugin/fisheye/index.js.map +1 -0
- package/esm/stdlib/plugin/menu/index.d.ts +42 -0
- package/esm/stdlib/plugin/menu/index.js +236 -0
- package/esm/stdlib/plugin/menu/index.js.map +1 -0
- package/esm/stdlib/plugin/tooltip/index.d.ts +75 -0
- package/esm/stdlib/plugin/tooltip/index.js +377 -0
- package/esm/stdlib/plugin/tooltip/index.js.map +1 -0
- package/esm/stdlib/theme/dark.js +4 -0
- package/esm/stdlib/theme/dark.js.map +1 -1
- package/esm/stdlib/theme/light.js +54 -9
- package/esm/stdlib/theme/light.js.map +1 -1
- package/esm/types/combo.d.ts +52 -3
- package/esm/types/data.d.ts +4 -4
- package/esm/types/edge.d.ts +2 -3
- package/esm/types/event.d.ts +9 -1
- package/esm/types/event.js +8 -8
- package/esm/types/event.js.map +1 -1
- package/esm/types/graph.d.ts +49 -13
- package/esm/types/hook.d.ts +8 -1
- package/esm/types/item.d.ts +4 -4
- package/esm/types/node.d.ts +4 -5
- package/esm/types/theme.d.ts +1 -1
- package/esm/util/animate.js.map +1 -1
- package/esm/util/canvas.js +8 -0
- package/esm/util/canvas.js.map +1 -1
- package/esm/util/data.d.ts +65 -0
- package/esm/util/data.js +150 -0
- package/esm/util/data.js.map +1 -0
- package/esm/util/event.d.ts +8 -0
- package/esm/util/event.js +16 -0
- package/esm/util/event.js.map +1 -1
- package/esm/util/item.d.ts +2 -1
- package/esm/util/item.js +36 -13
- package/esm/util/item.js.map +1 -1
- package/esm/util/shape.d.ts +39 -4
- package/esm/util/shape.js +101 -1
- package/esm/util/shape.js.map +1 -1
- package/esm/util/zoom.d.ts +2 -2
- package/lib/index.d.ts +26 -6
- package/lib/item/combo.d.ts +72 -2
- package/lib/item/combo.js +122 -2
- package/lib/item/combo.js.map +1 -1
- package/lib/item/edge.d.ts +3 -3
- package/lib/item/edge.js +4 -5
- package/lib/item/edge.js.map +1 -1
- package/lib/item/item.d.ts +4 -4
- package/lib/item/item.js +37 -8
- package/lib/item/item.js.map +1 -1
- package/lib/item/node.d.ts +20 -16
- package/lib/item/node.js +14 -8
- package/lib/item/node.js.map +1 -1
- package/lib/runtime/controller/data.d.ts +12 -4
- package/lib/runtime/controller/data.js +353 -61
- package/lib/runtime/controller/data.js.map +1 -1
- package/lib/runtime/controller/interaction.js +15 -3
- package/lib/runtime/controller/interaction.js.map +1 -1
- package/lib/runtime/controller/item.d.ts +11 -2
- package/lib/runtime/controller/item.js +342 -50
- package/lib/runtime/controller/item.js.map +1 -1
- package/lib/runtime/controller/layout.js +19 -5
- package/lib/runtime/controller/layout.js.map +1 -1
- package/lib/runtime/graph.d.ts +54 -17
- package/lib/runtime/graph.js +165 -34
- package/lib/runtime/graph.js.map +1 -1
- package/lib/stdlib/behavior/click-select.d.ts +3 -0
- package/lib/stdlib/behavior/click-select.js +13 -1
- package/lib/stdlib/behavior/click-select.js.map +1 -1
- package/lib/stdlib/behavior/collapse-expand-combo.d.ts +29 -0
- package/lib/stdlib/behavior/collapse-expand-combo.js +38 -0
- package/lib/stdlib/behavior/collapse-expand-combo.js.map +1 -0
- package/lib/stdlib/behavior/drag-combo.d.ts +99 -0
- package/lib/stdlib/behavior/drag-combo.js +344 -0
- package/lib/stdlib/behavior/drag-combo.js.map +1 -0
- package/lib/stdlib/behavior/drag-node.d.ts +14 -10
- package/lib/stdlib/behavior/drag-node.js +134 -37
- package/lib/stdlib/behavior/drag-node.js.map +1 -1
- package/lib/stdlib/behavior/hover-activate.d.ts +3 -1
- package/lib/stdlib/behavior/hover-activate.js +3 -2
- package/lib/stdlib/behavior/hover-activate.js.map +1 -1
- package/lib/stdlib/behavior/orbit-canvas-3d.js +1 -1
- package/lib/stdlib/behavior/orbit-canvas-3d.js.map +1 -1
- package/lib/stdlib/behavior/track-canvas-3d.js +1 -1
- package/lib/stdlib/behavior/track-canvas-3d.js.map +1 -1
- package/lib/stdlib/index.d.ts +25 -3
- package/lib/stdlib/index.js +25 -3
- package/lib/stdlib/index.js.map +1 -1
- package/lib/stdlib/item/combo/circle.d.ts +29 -0
- package/lib/stdlib/item/combo/circle.js +60 -0
- package/lib/stdlib/item/combo/circle.js.map +1 -0
- package/lib/stdlib/item/edge/base.d.ts +2 -2
- package/lib/stdlib/item/edge/base.js +3 -0
- package/lib/stdlib/item/edge/base.js.map +1 -1
- package/lib/stdlib/item/edge/cubic-horizon.d.ts +37 -0
- package/lib/stdlib/item/edge/cubic-horizon.js +75 -0
- package/lib/stdlib/item/edge/cubic-horizon.js.map +1 -0
- package/lib/stdlib/item/edge/cubic-vertical.d.ts +37 -0
- package/lib/stdlib/item/edge/cubic-vertical.js +75 -0
- package/lib/stdlib/item/edge/cubic-vertical.js.map +1 -0
- package/lib/stdlib/item/edge/cubic.d.ts +60 -0
- package/lib/stdlib/item/edge/cubic.js +103 -0
- package/lib/stdlib/item/edge/cubic.js.map +1 -0
- package/lib/stdlib/item/edge/index.d.ts +1 -0
- package/lib/stdlib/item/edge/index.js +1 -0
- package/lib/stdlib/item/edge/index.js.map +1 -1
- package/lib/stdlib/item/edge/line.d.ts +1 -1
- package/lib/stdlib/item/edge/quadratic.d.ts +41 -0
- package/lib/stdlib/item/edge/quadratic.js +70 -0
- package/lib/stdlib/item/edge/quadratic.js.map +1 -0
- package/lib/stdlib/item/node/base.d.ts +38 -37
- package/lib/stdlib/item/node/base.js +4 -4
- package/lib/stdlib/item/node/base.js.map +1 -1
- package/lib/stdlib/item/node/index.d.ts +1 -0
- package/lib/stdlib/item/node/index.js +1 -0
- package/lib/stdlib/item/node/index.js.map +1 -1
- package/lib/stdlib/item/node/rect.d.ts +31 -0
- package/lib/stdlib/item/node/rect.js +63 -0
- package/lib/stdlib/item/node/rect.js.map +1 -0
- package/lib/stdlib/plugin/fisheye/index.d.ts +102 -0
- package/lib/stdlib/plugin/fisheye/index.js +490 -0
- package/lib/stdlib/plugin/fisheye/index.js.map +1 -0
- package/lib/stdlib/plugin/menu/index.d.ts +42 -0
- package/lib/stdlib/plugin/menu/index.js +242 -0
- package/lib/stdlib/plugin/menu/index.js.map +1 -0
- package/lib/stdlib/plugin/tooltip/index.d.ts +75 -0
- package/lib/stdlib/plugin/tooltip/index.js +383 -0
- package/lib/stdlib/plugin/tooltip/index.js.map +1 -0
- package/lib/stdlib/theme/dark.js +4 -0
- package/lib/stdlib/theme/dark.js.map +1 -1
- package/lib/stdlib/theme/light.js +54 -9
- package/lib/stdlib/theme/light.js.map +1 -1
- package/lib/types/combo.d.ts +52 -3
- package/lib/types/data.d.ts +4 -4
- package/lib/types/edge.d.ts +2 -3
- package/lib/types/event.d.ts +9 -1
- package/lib/types/event.js +10 -10
- package/lib/types/event.js.map +1 -1
- package/lib/types/graph.d.ts +49 -13
- package/lib/types/hook.d.ts +8 -1
- package/lib/types/item.d.ts +4 -4
- package/lib/types/item.js +1 -1
- package/lib/types/item.js.map +1 -1
- package/lib/types/node.d.ts +4 -5
- package/lib/types/theme.d.ts +1 -1
- package/lib/util/animate.js.map +1 -1
- package/lib/util/canvas.js +8 -0
- package/lib/util/canvas.js.map +1 -1
- package/lib/util/data.d.ts +65 -0
- package/lib/util/data.js +161 -0
- package/lib/util/data.js.map +1 -0
- package/lib/util/event.d.ts +8 -0
- package/lib/util/event.js +18 -1
- package/lib/util/event.js.map +1 -1
- package/lib/util/item.d.ts +2 -1
- package/lib/util/item.js +36 -13
- package/lib/util/item.js.map +1 -1
- package/lib/util/shape.d.ts +39 -4
- package/lib/util/shape.js +105 -2
- package/lib/util/shape.js.map +1 -1
- package/lib/util/zoom.d.ts +2 -2
- package/package.json +13 -13
- package/src/item/combo.ts +220 -2
- package/src/item/edge.ts +7 -8
- package/src/item/item.ts +58 -15
- package/src/item/node.ts +47 -24
- package/src/runtime/controller/data.ts +390 -68
- package/src/runtime/controller/interaction.ts +23 -3
- package/src/runtime/controller/item.ts +444 -64
- package/src/runtime/controller/layout.ts +24 -5
- package/src/runtime/graph.ts +225 -38
- package/src/stdlib/behavior/click-select.ts +15 -2
- package/src/stdlib/behavior/collapse-expand-combo.ts +59 -0
- package/src/stdlib/behavior/drag-combo.ts +533 -0
- package/src/stdlib/behavior/drag-node.ts +195 -62
- package/src/stdlib/behavior/hover-activate.ts +4 -5
- package/src/stdlib/behavior/orbit-canvas-3d.ts +1 -1
- package/src/stdlib/behavior/track-canvas-3d.ts +1 -1
- package/src/stdlib/index.ts +25 -3
- package/src/stdlib/item/combo/circle.ts +113 -0
- package/src/stdlib/item/edge/base.ts +5 -2
- package/src/stdlib/item/edge/cubic-horizon.ts +114 -0
- package/src/stdlib/item/edge/cubic-vertical.ts +116 -0
- package/src/stdlib/item/edge/cubic.ts +198 -0
- package/src/stdlib/item/edge/index.ts +1 -0
- package/src/stdlib/item/edge/quadratic.ts +136 -0
- package/src/stdlib/item/node/base.ts +79 -41
- package/src/stdlib/item/node/index.ts +1 -0
- package/src/stdlib/item/node/rect.ts +124 -0
- package/src/stdlib/plugin/fisheye/index.ts +578 -0
- package/src/stdlib/plugin/menu/index.ts +260 -0
- package/src/stdlib/plugin/tooltip/index.ts +424 -0
- package/src/stdlib/theme/dark.ts +4 -0
- package/src/stdlib/theme/light.ts +77 -9
- package/src/types/combo.ts +61 -3
- package/src/types/data.ts +6 -4
- package/src/types/edge.ts +2 -2
- package/src/types/event.ts +8 -8
- package/src/types/graph.ts +73 -16
- package/src/types/hook.ts +8 -1
- package/src/types/item.ts +10 -9
- package/src/types/node.ts +4 -4
- package/src/types/theme.ts +1 -1
- package/src/util/animate.ts +2 -3
- package/src/util/canvas.ts +10 -0
- package/src/util/data.ts +178 -0
- package/src/util/event.ts +29 -0
- package/src/util/item.ts +75 -12
- package/src/util/shape.ts +142 -5
- package/src/util/zoom.ts +2 -2
package/src/util/data.ts
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { NodeUserModel } from 'types';
|
|
2
|
+
import { IGraph } from '../types/graph';
|
|
3
|
+
import { GraphCore } from '../types/data';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Deconstruct data and distinguish nodes and combos from graphcore data.
|
|
7
|
+
* @param data data from graphcore
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export const deconstructData = (data) => {
|
|
11
|
+
const { nodes: nodesAndCombos = [], edges = [] } = data;
|
|
12
|
+
const nodes = [];
|
|
13
|
+
const combos = [];
|
|
14
|
+
nodesAndCombos.forEach((item) => {
|
|
15
|
+
if (item.data._isCombo) combos.push(item);
|
|
16
|
+
else nodes.push(item);
|
|
17
|
+
});
|
|
18
|
+
return {
|
|
19
|
+
nodes,
|
|
20
|
+
edges,
|
|
21
|
+
combos,
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Depth first search begin from nodes in graphCore data.
|
|
27
|
+
* @param graphCore graphlib data structure
|
|
28
|
+
* @param nodes begin nodes
|
|
29
|
+
* @param fn will be called while visiting each node
|
|
30
|
+
* @param mode 'TB' - visit from top to bottom; 'BT' - visit from bottom to top;
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
export const graphCoreTreeDfs = (
|
|
34
|
+
graphCore: GraphCore,
|
|
35
|
+
nodes: NodeUserModel[],
|
|
36
|
+
fn,
|
|
37
|
+
mode: 'TB' | 'BT' = 'TB',
|
|
38
|
+
) => {
|
|
39
|
+
if (!nodes?.length) return;
|
|
40
|
+
nodes.forEach((node) => {
|
|
41
|
+
if (!graphCore.hasNode(node.id)) return;
|
|
42
|
+
if (mode === 'TB') fn(node); // Traverse from top to bottom
|
|
43
|
+
graphCoreTreeDfs(
|
|
44
|
+
graphCore,
|
|
45
|
+
graphCore.getChildren(node.id, 'combo'),
|
|
46
|
+
fn,
|
|
47
|
+
mode,
|
|
48
|
+
);
|
|
49
|
+
if (mode !== 'TB') fn(node); // Traverse from bottom to top
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Depth first search begin from nodes in g6 graph data.
|
|
55
|
+
* @param graph G6 graph instance
|
|
56
|
+
* @param nodes begin nodes
|
|
57
|
+
* @param fn will be called while visiting each node
|
|
58
|
+
* @param mode 'TB' - visit from top to bottom; 'BT' - visit from bottom to top;
|
|
59
|
+
* @returns
|
|
60
|
+
*/
|
|
61
|
+
export const graphComboTreeDfs = (
|
|
62
|
+
graph: IGraph,
|
|
63
|
+
nodes: NodeUserModel[],
|
|
64
|
+
fn,
|
|
65
|
+
mode: 'TB' | 'BT' = 'TB',
|
|
66
|
+
) => {
|
|
67
|
+
if (!nodes?.length) return;
|
|
68
|
+
nodes.forEach((node) => {
|
|
69
|
+
if (mode === 'TB') fn(node); // Traverse from top to bottom
|
|
70
|
+
graphComboTreeDfs(graph, graph.getComboChildrenData(node.id), fn, mode);
|
|
71
|
+
if (mode !== 'TB') fn(node); // Traverse from bottom to top
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Depth first search begin from nodes in g6 graph data, and then search the ancestirs from begin nodes.
|
|
77
|
+
* @param graph G6 graph instance
|
|
78
|
+
* @param graphCore graphlib data structure
|
|
79
|
+
* @param nodes begin ndoes
|
|
80
|
+
* @param fn will be called while visiting each node
|
|
81
|
+
* @param mode 'TB' - visit from top to bottom; 'BT' - visit from bottom to top;
|
|
82
|
+
* @returns
|
|
83
|
+
*/
|
|
84
|
+
export const traverseAncestorsAndSucceeds = (
|
|
85
|
+
graph: IGraph,
|
|
86
|
+
graphCore: GraphCore,
|
|
87
|
+
nodes: NodeUserModel[],
|
|
88
|
+
fn,
|
|
89
|
+
mode: 'TB' | 'BT' = 'TB',
|
|
90
|
+
) => {
|
|
91
|
+
if (!nodes?.length) return;
|
|
92
|
+
graphComboTreeDfs(graph, nodes, fn, mode);
|
|
93
|
+
traverseAncestors(graphCore, nodes, fn);
|
|
94
|
+
return;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export const traverseGraphAncestors = (
|
|
98
|
+
graph: IGraph,
|
|
99
|
+
nodes: NodeUserModel[],
|
|
100
|
+
fn,
|
|
101
|
+
) => {
|
|
102
|
+
if (!nodes?.length) return;
|
|
103
|
+
nodes.forEach((node) => {
|
|
104
|
+
if (!node.data.parentId) return;
|
|
105
|
+
let ancestor = graph.getComboData(node.data.parentId);
|
|
106
|
+
while (ancestor) {
|
|
107
|
+
if (fn(ancestor)) return;
|
|
108
|
+
if (!ancestor.data.parentId) return;
|
|
109
|
+
ancestor = graph.getComboData(ancestor.data.parentId);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Traverse the ancestors from the begin nodes.
|
|
116
|
+
* @param graphCore graphlib data structure
|
|
117
|
+
* @param nodes begin ndoes
|
|
118
|
+
* @param fn will be called while visiting each node
|
|
119
|
+
*/
|
|
120
|
+
export const traverseAncestors = (graphCore, nodes, fn) => {
|
|
121
|
+
nodes.forEach((node) => {
|
|
122
|
+
let ancestor = graphCore.getParent(node.id, 'combo');
|
|
123
|
+
while (ancestor) {
|
|
124
|
+
if (fn(ancestor)) return;
|
|
125
|
+
ancestor = graphCore.getParent(ancestor.id, 'combo');
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Whether the test succeed is a parent of the test parent.
|
|
132
|
+
* @param graph G6 graph instance
|
|
133
|
+
* @param testParent id of the node to be the parent
|
|
134
|
+
* @param parentId id of the node to be the succeed
|
|
135
|
+
* @returns
|
|
136
|
+
*/
|
|
137
|
+
export const isSucceed = (graph, testParent, testSucceed): boolean => {
|
|
138
|
+
const succeedIds = [];
|
|
139
|
+
if (graph.getNodeData(testParent)) return false;
|
|
140
|
+
graphComboTreeDfs(graph, [graph.getComboData(testParent)], (node) => {
|
|
141
|
+
succeedIds.push(node.id);
|
|
142
|
+
});
|
|
143
|
+
if (succeedIds.includes(testSucceed)) return true;
|
|
144
|
+
return false;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Check the validation if move the child into the subtree of parent. e.g. If the new parent (toBeAncestorId) is a succeed of new child (toBeSucceedId), it is invalid.
|
|
149
|
+
* @param graph G6 graph instance
|
|
150
|
+
* @param toBeSucceedId id of the new child to check if it is valid to be a child of the node with id toBeAncestorId
|
|
151
|
+
* @param toBeAncestorId id of the new parent to check if it is valid to be a parent of the node with id toBeSucceedId
|
|
152
|
+
* @returns
|
|
153
|
+
*/
|
|
154
|
+
export const validateComboStrucutre = (
|
|
155
|
+
graph,
|
|
156
|
+
toBeSucceedId,
|
|
157
|
+
toBeAncestorId,
|
|
158
|
+
): boolean => {
|
|
159
|
+
if (toBeAncestorId && !graph.getComboData(toBeAncestorId)) {
|
|
160
|
+
console.warn(
|
|
161
|
+
`Setting parent combo failed. The parent combo with id ${toBeAncestorId} does not exist`,
|
|
162
|
+
);
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
if (toBeSucceedId === toBeAncestorId) {
|
|
166
|
+
console.warn(
|
|
167
|
+
`Setting parent combo failed. Cannot set combo/node with id ${toBeSucceedId} to be the child of itself.`,
|
|
168
|
+
);
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
if (toBeAncestorId && isSucceed(graph, toBeSucceedId, toBeAncestorId)) {
|
|
172
|
+
console.warn(
|
|
173
|
+
`Setting parent combo failed, since the parent combo with id ${toBeAncestorId} is a succeed of the combo with id ${toBeSucceedId}.`,
|
|
174
|
+
);
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
return true;
|
|
178
|
+
};
|
package/src/util/event.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { IElement } from '@antv/g';
|
|
2
2
|
import { ID } from '@antv/graphlib';
|
|
3
|
+
import { IG6GraphEvent, IGraph } from 'types';
|
|
3
4
|
|
|
4
5
|
export type ItemInfo = {
|
|
5
6
|
itemType: 'canvas' | 'node' | 'edge' | 'combo';
|
|
@@ -32,3 +33,31 @@ export const getItemInfoFromElement = (element: IElement): ItemInfo | null => {
|
|
|
32
33
|
groupElement: parent,
|
|
33
34
|
};
|
|
34
35
|
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Returns the event props for graph's contextmenu event.
|
|
39
|
+
* @param event Original g6 event props.
|
|
40
|
+
* @param graph Graph instance.
|
|
41
|
+
* @returns Contextmenu event props.
|
|
42
|
+
*/
|
|
43
|
+
export const getContextMenuEventProps = (
|
|
44
|
+
event: IG6GraphEvent,
|
|
45
|
+
graph: IGraph,
|
|
46
|
+
): IG6GraphEvent => {
|
|
47
|
+
return {
|
|
48
|
+
...event,
|
|
49
|
+
type: 'contextmenu',
|
|
50
|
+
preventDefault: () => {
|
|
51
|
+
graph.canvas
|
|
52
|
+
.getContextService()
|
|
53
|
+
.getDomElement()
|
|
54
|
+
.addEventListener(
|
|
55
|
+
'contextmenu',
|
|
56
|
+
(e) => {
|
|
57
|
+
e.preventDefault();
|
|
58
|
+
},
|
|
59
|
+
{ once: true },
|
|
60
|
+
);
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
};
|
package/src/util/item.ts
CHANGED
|
@@ -4,6 +4,8 @@ import { IGraph } from '../types';
|
|
|
4
4
|
import Combo from '../item/combo';
|
|
5
5
|
import Edge from '../item/edge';
|
|
6
6
|
import Node from '../item/node';
|
|
7
|
+
import { GraphCore } from '../types/data';
|
|
8
|
+
import { getCombinedBoundsByItem } from './shape';
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* Find the edges whose source and target are both in the ids.
|
|
@@ -28,43 +30,104 @@ export const upsertTransientItem = (
|
|
|
28
30
|
item: Node | Edge | Combo,
|
|
29
31
|
nodeGroup: Group,
|
|
30
32
|
edgeGroup: Group,
|
|
33
|
+
comboGroup: Group,
|
|
31
34
|
transientItemMap: Record<string, Node | Edge | Combo | Group>,
|
|
35
|
+
itemMap: Record<string, Node | Edge | Combo>,
|
|
36
|
+
graphCore?: GraphCore,
|
|
32
37
|
onlyDrawKeyShape?: boolean,
|
|
38
|
+
upsertAncestors = true,
|
|
33
39
|
) => {
|
|
34
|
-
|
|
40
|
+
let transientItem = transientItemMap[item.model.id];
|
|
35
41
|
if (transientItem) {
|
|
36
42
|
return transientItem;
|
|
37
43
|
}
|
|
38
44
|
if (item.type === 'node') {
|
|
39
|
-
|
|
40
|
-
transientItemMap[item.model.id] = transientNode;
|
|
41
|
-
transientNode.transient = true;
|
|
42
|
-
return transientNode;
|
|
45
|
+
transientItem = item.clone(nodeGroup, onlyDrawKeyShape, true) as Node;
|
|
43
46
|
} else if (item.type === 'edge') {
|
|
44
47
|
const source = upsertTransientItem(
|
|
45
48
|
item.sourceItem,
|
|
46
49
|
nodeGroup,
|
|
47
50
|
edgeGroup,
|
|
51
|
+
comboGroup,
|
|
48
52
|
transientItemMap,
|
|
53
|
+
itemMap,
|
|
54
|
+
graphCore,
|
|
49
55
|
onlyDrawKeyShape,
|
|
50
|
-
|
|
56
|
+
false,
|
|
57
|
+
) as Node | Combo;
|
|
51
58
|
const target = upsertTransientItem(
|
|
52
59
|
item.targetItem,
|
|
53
60
|
nodeGroup,
|
|
54
61
|
edgeGroup,
|
|
62
|
+
comboGroup,
|
|
55
63
|
transientItemMap,
|
|
64
|
+
itemMap,
|
|
65
|
+
graphCore,
|
|
56
66
|
onlyDrawKeyShape,
|
|
57
|
-
|
|
58
|
-
|
|
67
|
+
false,
|
|
68
|
+
) as Node | Combo;
|
|
69
|
+
transientItem = item.clone(
|
|
59
70
|
edgeGroup,
|
|
60
71
|
source,
|
|
61
72
|
target,
|
|
62
73
|
undefined,
|
|
63
74
|
true,
|
|
64
75
|
) as Edge;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
76
|
+
} else {
|
|
77
|
+
// find the succeeds to upsert transients
|
|
78
|
+
const childItems = [];
|
|
79
|
+
const children = graphCore.getChildren(item.model.id, 'combo');
|
|
80
|
+
children.forEach((childModel) => {
|
|
81
|
+
const childItem = itemMap[childModel.id];
|
|
82
|
+
if (childItem) {
|
|
83
|
+
childItems.push(
|
|
84
|
+
upsertTransientItem(
|
|
85
|
+
childItem,
|
|
86
|
+
nodeGroup,
|
|
87
|
+
edgeGroup,
|
|
88
|
+
comboGroup,
|
|
89
|
+
transientItemMap,
|
|
90
|
+
itemMap,
|
|
91
|
+
graphCore,
|
|
92
|
+
onlyDrawKeyShape,
|
|
93
|
+
false,
|
|
94
|
+
),
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
transientItem = (item as Combo).clone(
|
|
99
|
+
comboGroup,
|
|
100
|
+
onlyDrawKeyShape,
|
|
101
|
+
true,
|
|
102
|
+
() => getCombinedBoundsByItem(childItems), // getCombinedBounds
|
|
103
|
+
() => childItems,
|
|
104
|
+
) as Combo;
|
|
105
|
+
transientItem.toBack();
|
|
68
106
|
}
|
|
69
|
-
|
|
107
|
+
transientItemMap[item.model.id] = transientItem;
|
|
108
|
+
transientItem.transient = true;
|
|
109
|
+
|
|
110
|
+
if (item.type !== 'edge' && upsertAncestors) {
|
|
111
|
+
// find the ancestors to upsert transients
|
|
112
|
+
let currentAncestor = graphCore.getParent(item.model.id, 'combo');
|
|
113
|
+
while (currentAncestor) {
|
|
114
|
+
const ancestorItem = itemMap[currentAncestor.id];
|
|
115
|
+
if (ancestorItem) {
|
|
116
|
+
const transientAncestor = upsertTransientItem(
|
|
117
|
+
ancestorItem,
|
|
118
|
+
nodeGroup,
|
|
119
|
+
edgeGroup,
|
|
120
|
+
comboGroup,
|
|
121
|
+
transientItemMap,
|
|
122
|
+
itemMap,
|
|
123
|
+
graphCore,
|
|
124
|
+
onlyDrawKeyShape,
|
|
125
|
+
);
|
|
126
|
+
transientAncestor.toBack();
|
|
127
|
+
}
|
|
128
|
+
currentAncestor = graphCore.getParent(currentAncestor.id, 'combo');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return transientItem;
|
|
70
133
|
};
|
package/src/util/shape.ts
CHANGED
|
@@ -12,9 +12,10 @@ import {
|
|
|
12
12
|
Image,
|
|
13
13
|
Path,
|
|
14
14
|
AABB,
|
|
15
|
+
Tuple3Number,
|
|
15
16
|
} from '@antv/g';
|
|
16
17
|
import { clone, isArray, isNumber } from '@antv/util';
|
|
17
|
-
import { DEFAULT_LABEL_BG_PADDING
|
|
18
|
+
import { DEFAULT_LABEL_BG_PADDING } from '../constant';
|
|
18
19
|
import { Point } from '../types/common';
|
|
19
20
|
import { EdgeDisplayModel, EdgeShapeMap } from '../types/edge';
|
|
20
21
|
import {
|
|
@@ -23,13 +24,16 @@ import {
|
|
|
23
24
|
ItemShapeStyles,
|
|
24
25
|
ShapeStyle,
|
|
25
26
|
SHAPE_TYPE_3D,
|
|
27
|
+
ItemModel,
|
|
26
28
|
} from '../types/item';
|
|
27
29
|
import { NodeDisplayModel, NodeShapeMap } from '../types/node';
|
|
28
|
-
import { ComboDisplayModel } from '../types';
|
|
30
|
+
import { ComboDisplayModel, IGraph } from '../types';
|
|
29
31
|
import { getShapeAnimateBeginStyles } from './animate';
|
|
30
32
|
import { isArrayOverlap } from './array';
|
|
31
33
|
import { isBetween } from './math';
|
|
32
|
-
import
|
|
34
|
+
import Node from '../item/node';
|
|
35
|
+
import Edge from '../item/edge';
|
|
36
|
+
import Combo from '../item/combo';
|
|
33
37
|
|
|
34
38
|
export const ShapeTagMap = {
|
|
35
39
|
circle: Circle,
|
|
@@ -54,6 +58,8 @@ export const createShape = (
|
|
|
54
58
|
) => {
|
|
55
59
|
const ShapeClass = ShapeTagMap[type];
|
|
56
60
|
const shape = new ShapeClass({ id, style });
|
|
61
|
+
if (style.draggable === undefined) shape.style.draggable = true;
|
|
62
|
+
if (style.droppable === undefined) shape.style.droppable = true;
|
|
57
63
|
if (LINE_TYPES.includes(type)) {
|
|
58
64
|
shape.style.increasedLineWidthForHitTesting = Math.max(
|
|
59
65
|
shape.style.lineWidth as number,
|
|
@@ -108,13 +114,19 @@ export const upsertShape = (
|
|
|
108
114
|
model?: NodeDisplayModel | EdgeDisplayModel | ComboDisplayModel,
|
|
109
115
|
): DisplayObject => {
|
|
110
116
|
let shape = shapeMap[id];
|
|
117
|
+
// TODO: it is not decoupling with the shape name 'keyShape'
|
|
118
|
+
const firstRendering = !shapeMap.keyShape;
|
|
111
119
|
const { animates, disableAnimate } = model?.data || {};
|
|
112
120
|
if (!shape) {
|
|
113
121
|
// create
|
|
114
122
|
shape = createShape(type, style, id);
|
|
115
123
|
// find the animate styles, set them to be INIT_SHAPE_STYLES
|
|
116
124
|
if (!disableAnimate && animates) {
|
|
117
|
-
const animateFields = findAnimateFields(
|
|
125
|
+
const animateFields = findAnimateFields(
|
|
126
|
+
animates,
|
|
127
|
+
firstRendering ? 'buildIn' : 'update',
|
|
128
|
+
id,
|
|
129
|
+
);
|
|
118
130
|
const initShapeStyles = getShapeAnimateBeginStyles(shape);
|
|
119
131
|
animateFields.forEach((key) => {
|
|
120
132
|
shape.style[key] = initShapeStyles[key];
|
|
@@ -292,7 +304,7 @@ const merge2Styles = (
|
|
|
292
304
|
export const isPolygonsIntersect = (
|
|
293
305
|
points1: number[][],
|
|
294
306
|
points2: number[][],
|
|
295
|
-
):
|
|
307
|
+
): boolean => {
|
|
296
308
|
const getBBox = (points): Partial<AABB> => {
|
|
297
309
|
const xArr = points.map((p) => p[0]);
|
|
298
310
|
const yArr = points.map((p) => p[1]);
|
|
@@ -607,3 +619,128 @@ export const getShapeLocalBoundsByStyle = (
|
|
|
607
619
|
return bbox || shape.getLocalBounds();
|
|
608
620
|
}
|
|
609
621
|
};
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Combine multiple bounds into one.
|
|
625
|
+
* @param bounds bounds' array
|
|
626
|
+
* @returns combined bounds
|
|
627
|
+
*/
|
|
628
|
+
export const combineBounds = (
|
|
629
|
+
bounds: {
|
|
630
|
+
min: number[];
|
|
631
|
+
max: number[];
|
|
632
|
+
center: number[];
|
|
633
|
+
}[],
|
|
634
|
+
): {
|
|
635
|
+
min: number[];
|
|
636
|
+
max: number[];
|
|
637
|
+
center: number[];
|
|
638
|
+
} => {
|
|
639
|
+
const res = {
|
|
640
|
+
center: [0, 0, 0],
|
|
641
|
+
min: [Infinity, Infinity, Infinity],
|
|
642
|
+
max: [-Infinity, -Infinity, -Infinity],
|
|
643
|
+
size: [0, 0, 0],
|
|
644
|
+
};
|
|
645
|
+
bounds.forEach((bound) => {
|
|
646
|
+
const { min, max } = bound;
|
|
647
|
+
min.forEach((val, i) => {
|
|
648
|
+
if (val < res.min[i]) res.min[i] = val;
|
|
649
|
+
});
|
|
650
|
+
max.forEach((val, i) => {
|
|
651
|
+
if (val > res.max[i]) res.max[i] = val;
|
|
652
|
+
});
|
|
653
|
+
});
|
|
654
|
+
res.center = res.center.map((val, i) => (res.max[i] + res.min[i]) / 2);
|
|
655
|
+
return res;
|
|
656
|
+
};
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* Calculate the combined bounds according to the sub data models.
|
|
660
|
+
* @param graph graph instance
|
|
661
|
+
* @param models sub data models
|
|
662
|
+
* @returns combined bounds
|
|
663
|
+
*/
|
|
664
|
+
export const getCombinedBoundsByData = (
|
|
665
|
+
graph: IGraph,
|
|
666
|
+
models: ItemModel[],
|
|
667
|
+
):
|
|
668
|
+
| {
|
|
669
|
+
center: Tuple3Number;
|
|
670
|
+
min: Tuple3Number;
|
|
671
|
+
max: Tuple3Number;
|
|
672
|
+
size: Tuple3Number;
|
|
673
|
+
}
|
|
674
|
+
| false => {
|
|
675
|
+
if (!models.length) return false;
|
|
676
|
+
const resBounds = {
|
|
677
|
+
center: [0, 0, 0],
|
|
678
|
+
min: [Infinity, Infinity, Infinity],
|
|
679
|
+
max: [-Infinity, -Infinity, -Infinity],
|
|
680
|
+
size: [0, 0, 0],
|
|
681
|
+
};
|
|
682
|
+
let validCounts = 0;
|
|
683
|
+
models.forEach(({ id }) => {
|
|
684
|
+
const bounds = graph.getRenderBBox(id);
|
|
685
|
+
if (bounds) {
|
|
686
|
+
validCounts++;
|
|
687
|
+
const { min, max } = bounds;
|
|
688
|
+
min.forEach((val, i) => {
|
|
689
|
+
if (val < resBounds.min[i]) resBounds.min[i] = val;
|
|
690
|
+
});
|
|
691
|
+
max.forEach((val, i) => {
|
|
692
|
+
if (val > resBounds.max[i]) resBounds.max[i] = val;
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
});
|
|
696
|
+
if (!validCounts) return false;
|
|
697
|
+
resBounds.size = resBounds.size.map(
|
|
698
|
+
(val, i) => resBounds.max[i] - resBounds.min[i],
|
|
699
|
+
);
|
|
700
|
+
resBounds.center = resBounds.center.map(
|
|
701
|
+
(val, i) => (resBounds.max[i] + resBounds.min[i]) / 2,
|
|
702
|
+
);
|
|
703
|
+
return resBounds as {
|
|
704
|
+
center: Tuple3Number;
|
|
705
|
+
min: Tuple3Number;
|
|
706
|
+
max: Tuple3Number;
|
|
707
|
+
size: Tuple3Number;
|
|
708
|
+
};
|
|
709
|
+
};
|
|
710
|
+
|
|
711
|
+
export const getCombinedBoundsByItem = (items: (Node | Combo | Edge)[]) => {
|
|
712
|
+
if (!items.length) return false;
|
|
713
|
+
const resBounds = {
|
|
714
|
+
center: [0, 0, 0],
|
|
715
|
+
min: [Infinity, Infinity, Infinity],
|
|
716
|
+
max: [-Infinity, -Infinity, -Infinity],
|
|
717
|
+
size: [0, 0, 0],
|
|
718
|
+
};
|
|
719
|
+
let validCounts = 0;
|
|
720
|
+
items.forEach((item) => {
|
|
721
|
+
const bounds = item.getBBox();
|
|
722
|
+
if (bounds) {
|
|
723
|
+
validCounts++;
|
|
724
|
+
const { min, max } = bounds;
|
|
725
|
+
min.forEach((val, i) => {
|
|
726
|
+
if (val < resBounds.min[i]) resBounds.min[i] = val;
|
|
727
|
+
});
|
|
728
|
+
max.forEach((val, i) => {
|
|
729
|
+
if (val > resBounds.max[i]) resBounds.max[i] = val;
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
});
|
|
733
|
+
if (!validCounts) return false;
|
|
734
|
+
resBounds.size = resBounds.size.map(
|
|
735
|
+
(val, i) => resBounds.max[i] - resBounds.min[i],
|
|
736
|
+
);
|
|
737
|
+
resBounds.center = resBounds.center.map(
|
|
738
|
+
(val, i) => (resBounds.max[i] + resBounds.min[i]) / 2,
|
|
739
|
+
);
|
|
740
|
+
return resBounds as {
|
|
741
|
+
center: Tuple3Number;
|
|
742
|
+
min: Tuple3Number;
|
|
743
|
+
max: Tuple3Number;
|
|
744
|
+
size: Tuple3Number;
|
|
745
|
+
};
|
|
746
|
+
};
|
package/src/util/zoom.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { LodStrategy,
|
|
1
|
+
import { LodStrategy, LodStrategyObj } from '../types/item';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Format lodStrategy to the pattern that ratio 1 (primary level) at level 0, and higher the ratio, higher the level.
|
|
5
5
|
* @param lodStrategy
|
|
6
6
|
* @returns
|
|
7
7
|
*/
|
|
8
|
-
export const formatLodStrategy = (lodStrategy: LodStrategy):
|
|
8
|
+
export const formatLodStrategy = (lodStrategy: LodStrategy): LodStrategyObj => {
|
|
9
9
|
const { levels, animateCfg } = lodStrategy || {};
|
|
10
10
|
if (!levels) return undefined;
|
|
11
11
|
const primaryLevel = levels.find((level) => level.primary);
|