@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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Animation, DisplayObject, IAnimationEffectTiming } from '@antv/g';
|
|
2
|
+
import { Graph as GraphLib } from '@antv/graphlib';
|
|
2
3
|
import {
|
|
3
4
|
isLayoutWithIterations,
|
|
4
5
|
Layout,
|
|
@@ -12,8 +13,10 @@ import {
|
|
|
12
13
|
isImmediatelyInvokedLayoutOptions,
|
|
13
14
|
isLayoutWorkerized,
|
|
14
15
|
LayoutOptions,
|
|
16
|
+
NodeModelData,
|
|
15
17
|
} from '../../types';
|
|
16
18
|
import { GraphCore } from '../../types/data';
|
|
19
|
+
import { EdgeModelData } from '../../types/edge';
|
|
17
20
|
|
|
18
21
|
/**
|
|
19
22
|
* Manages layout extensions and graph layout.
|
|
@@ -54,6 +57,20 @@ export class LayoutController {
|
|
|
54
57
|
this.stopLayout();
|
|
55
58
|
|
|
56
59
|
const { graphCore, options } = params;
|
|
60
|
+
const layoutNodes = graphCore
|
|
61
|
+
.getAllNodes()
|
|
62
|
+
.filter((node) => node.data.visible !== false && !node.data._isCombo);
|
|
63
|
+
const layoutNodesIdMap = {};
|
|
64
|
+
layoutNodes.forEach((node) => (layoutNodesIdMap[node.id] = true));
|
|
65
|
+
const layoutGraphCore = new GraphLib<NodeModelData, EdgeModelData>({
|
|
66
|
+
nodes: layoutNodes,
|
|
67
|
+
edges: graphCore
|
|
68
|
+
.getAllEdges()
|
|
69
|
+
.filter(
|
|
70
|
+
(edge) =>
|
|
71
|
+
layoutNodesIdMap[edge.source] && layoutNodesIdMap[edge.target],
|
|
72
|
+
),
|
|
73
|
+
});
|
|
57
74
|
|
|
58
75
|
this.graph.emit('startlayout');
|
|
59
76
|
|
|
@@ -68,7 +85,7 @@ export class LayoutController {
|
|
|
68
85
|
} = options;
|
|
69
86
|
|
|
70
87
|
// It will ignore some layout options such as `type` and `workerEnabled`.
|
|
71
|
-
positions = await execute(
|
|
88
|
+
positions = await execute(layoutGraphCore, rest);
|
|
72
89
|
|
|
73
90
|
if (animated) {
|
|
74
91
|
await this.animateLayoutWithoutIterations(
|
|
@@ -108,7 +125,9 @@ export class LayoutController {
|
|
|
108
125
|
/**
|
|
109
126
|
* Run algorithm in WebWorker, `animated` option will be ignored.
|
|
110
127
|
*/
|
|
111
|
-
const supervisor = new Supervisor(
|
|
128
|
+
const supervisor = new Supervisor(layoutGraphCore, layout, {
|
|
129
|
+
iterations,
|
|
130
|
+
});
|
|
112
131
|
this.currentSupervisor = supervisor;
|
|
113
132
|
positions = await supervisor.execute();
|
|
114
133
|
} else {
|
|
@@ -118,7 +137,7 @@ export class LayoutController {
|
|
|
118
137
|
/**
|
|
119
138
|
* `onTick` will get triggered in this case.
|
|
120
139
|
*/
|
|
121
|
-
positions = await layout.execute(
|
|
140
|
+
positions = await layout.execute(layoutGraphCore, {
|
|
122
141
|
onTick: (positionsOnTick: LayoutMapping) => {
|
|
123
142
|
// Display the animated process of layout.
|
|
124
143
|
this.updateNodesPosition(positionsOnTick);
|
|
@@ -130,12 +149,12 @@ export class LayoutController {
|
|
|
130
149
|
* Manually step simulation in a sync way. `onTick` won't get triggered in this case,
|
|
131
150
|
* there will be no animation either.
|
|
132
151
|
*/
|
|
133
|
-
layout.execute(
|
|
152
|
+
layout.execute(layoutGraphCore);
|
|
134
153
|
layout.stop();
|
|
135
154
|
positions = layout.tick(iterations);
|
|
136
155
|
}
|
|
137
156
|
} else {
|
|
138
|
-
positions = await layout.execute(
|
|
157
|
+
positions = await layout.execute(layoutGraphCore);
|
|
139
158
|
|
|
140
159
|
if (animated) {
|
|
141
160
|
await this.animateLayoutWithoutIterations(
|
package/src/runtime/graph.ts
CHANGED
|
@@ -44,6 +44,7 @@ import {
|
|
|
44
44
|
} from './controller';
|
|
45
45
|
import { PluginController } from './controller/plugin';
|
|
46
46
|
import Hook from './hooks';
|
|
47
|
+
import { graphComboTreeDfs } from '../util/data';
|
|
47
48
|
|
|
48
49
|
/**
|
|
49
50
|
* Disable CSS parsing for better performance.
|
|
@@ -88,7 +89,6 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
88
89
|
|
|
89
90
|
constructor(spec: Specification<B, T>) {
|
|
90
91
|
super();
|
|
91
|
-
// TODO: analyse cfg
|
|
92
92
|
|
|
93
93
|
this.specification = Object.assign({}, this.defaultSpecification, spec);
|
|
94
94
|
this.initHooks();
|
|
@@ -217,6 +217,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
217
217
|
changes: GraphChange<NodeModelData, EdgeModelData>[];
|
|
218
218
|
graphCore: GraphCore;
|
|
219
219
|
theme: ThemeSpecification;
|
|
220
|
+
upsertAncestors?: boolean;
|
|
220
221
|
}>({ name: 'itemchange' }),
|
|
221
222
|
render: new Hook<{
|
|
222
223
|
graphCore: GraphCore;
|
|
@@ -243,6 +244,9 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
243
244
|
itemvisibilitychange: new Hook<{ ids: ID[]; value: boolean }>({
|
|
244
245
|
name: 'itemvisibilitychange',
|
|
245
246
|
}),
|
|
247
|
+
itemzindexchange: new Hook<{ ids: ID[]; action: 'front' | 'back' }>({
|
|
248
|
+
name: 'itemzindexchange',
|
|
249
|
+
}),
|
|
246
250
|
transientupdate: new Hook<{
|
|
247
251
|
type: ITEM_TYPE | SHAPE_TYPE;
|
|
248
252
|
id: ID;
|
|
@@ -251,6 +255,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
251
255
|
action: 'remove' | 'add' | 'update' | undefined;
|
|
252
256
|
};
|
|
253
257
|
canvas: Canvas;
|
|
258
|
+
graphCore: GraphCore;
|
|
254
259
|
}>({ name: 'transientupdate' }),
|
|
255
260
|
pluginchange: new Hook<{
|
|
256
261
|
action: 'update' | 'add' | 'remove';
|
|
@@ -364,7 +369,18 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
364
369
|
* @returns
|
|
365
370
|
*/
|
|
366
371
|
public clear() {
|
|
367
|
-
|
|
372
|
+
this.removeData(
|
|
373
|
+
'edge',
|
|
374
|
+
this.getAllEdgesData().map((edge) => edge.id),
|
|
375
|
+
);
|
|
376
|
+
this.removeData(
|
|
377
|
+
'node',
|
|
378
|
+
this.getAllNodesData().map((node) => node.id),
|
|
379
|
+
);
|
|
380
|
+
this.removeData(
|
|
381
|
+
'combo',
|
|
382
|
+
this.getAllCombosData().map((combo) => combo.id),
|
|
383
|
+
);
|
|
368
384
|
}
|
|
369
385
|
|
|
370
386
|
public getViewportCenter(): PointLike {
|
|
@@ -737,7 +753,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
737
753
|
* @group Data
|
|
738
754
|
*/
|
|
739
755
|
public getAllNodesData(): NodeModel[] {
|
|
740
|
-
return this.dataController.findAllData('node');
|
|
756
|
+
return this.dataController.findAllData('node') as NodeModel[];
|
|
741
757
|
}
|
|
742
758
|
/**
|
|
743
759
|
* Get all the edges' inner data
|
|
@@ -758,26 +774,35 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
758
774
|
/**
|
|
759
775
|
* Get one-hop edge ids from a start node.
|
|
760
776
|
* @param nodeId id of the start node
|
|
761
|
-
* @returns one-hop
|
|
777
|
+
* @returns one-hop edges' data array
|
|
762
778
|
* @group Data
|
|
763
779
|
*/
|
|
764
780
|
public getRelatedEdgesData(
|
|
765
781
|
nodeId: ID,
|
|
766
782
|
direction: 'in' | 'out' | 'both' = 'both',
|
|
767
783
|
): EdgeModel[] {
|
|
768
|
-
return this.dataController.
|
|
784
|
+
return this.dataController.findRelatedEdges(nodeId, direction);
|
|
769
785
|
}
|
|
770
786
|
/**
|
|
771
787
|
* Get one-hop node ids from a start node.
|
|
772
788
|
* @param nodeId id of the start node
|
|
773
|
-
* @returns one-hop
|
|
789
|
+
* @returns one-hop nodes' data array
|
|
774
790
|
* @group Data
|
|
775
791
|
*/
|
|
776
792
|
public getNeighborNodesData(
|
|
777
793
|
nodeId: ID,
|
|
778
794
|
direction: 'in' | 'out' | 'both' = 'both',
|
|
779
795
|
): NodeModel[] {
|
|
780
|
-
return this.dataController.
|
|
796
|
+
return this.dataController.findNeighborNodes(nodeId, direction);
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* Get the children's data of a combo.
|
|
800
|
+
* @param comboId combo id
|
|
801
|
+
* @returns children's data array
|
|
802
|
+
* @group Data
|
|
803
|
+
*/
|
|
804
|
+
public getComboChildrenData(comboId: ID): (ComboModel | NodeModel)[] {
|
|
805
|
+
return this.dataController.findChildren(comboId, 'combo');
|
|
781
806
|
}
|
|
782
807
|
|
|
783
808
|
/**
|
|
@@ -796,8 +821,9 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
796
821
|
): ID[] {
|
|
797
822
|
let ids = this.itemController.findIdByState(itemType, state, value);
|
|
798
823
|
if (additionalFilter) {
|
|
799
|
-
|
|
800
|
-
|
|
824
|
+
let getDataFunc: any = this.getEdgeData;
|
|
825
|
+
if (itemType === 'node') getDataFunc = this.getNodeData;
|
|
826
|
+
else if (itemType === 'combo') getDataFunc = this.getComboData;
|
|
801
827
|
ids = ids.filter((id) => additionalFilter(getDataFunc(id)));
|
|
802
828
|
}
|
|
803
829
|
return ids;
|
|
@@ -868,7 +894,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
868
894
|
const { userGraphCore, graphCore } = this.dataController;
|
|
869
895
|
const { specification } = this.themeController;
|
|
870
896
|
const getItem =
|
|
871
|
-
itemType === 'edge' ? userGraphCore.getEdge : userGraphCore.getNode;
|
|
897
|
+
itemType === 'edge' ? userGraphCore.getEdge : userGraphCore.getNode;
|
|
872
898
|
data[`${itemType}s`] = idArr.map((id) => getItem.bind(userGraphCore)(id));
|
|
873
899
|
graphCore.once('changed', (event) => {
|
|
874
900
|
if (!event.changes.length) return;
|
|
@@ -955,6 +981,40 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
955
981
|
| Partial<
|
|
956
982
|
ComboUserModel | Partial<NodeUserModel>[] | Partial<ComboUserModel>[]
|
|
957
983
|
>,
|
|
984
|
+
upsertAncestors?: boolean,
|
|
985
|
+
stack?: boolean,
|
|
986
|
+
) {
|
|
987
|
+
return this.updatePosition('node', models, upsertAncestors, stack);
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
/**
|
|
991
|
+
* Update one or more combos' positions,
|
|
992
|
+
* do not update other styles which leads to better performance than updating positions by updateData.
|
|
993
|
+
* In fact, it changes the succeed nodes positions to affect the combo's position, but not modify the combo's position directly.
|
|
994
|
+
* @param models new configurations with x and y for every combo, which has id field to indicate the specific item
|
|
995
|
+
* @param {boolean} stack whether push this operation into graph's stack, true by default
|
|
996
|
+
* @group Data
|
|
997
|
+
*/
|
|
998
|
+
public updateComboPosition(
|
|
999
|
+
models:
|
|
1000
|
+
| Partial<NodeUserModel>
|
|
1001
|
+
| Partial<
|
|
1002
|
+
ComboUserModel | Partial<NodeUserModel>[] | Partial<ComboUserModel>[]
|
|
1003
|
+
>,
|
|
1004
|
+
upsertAncestors?: boolean,
|
|
1005
|
+
stack?: boolean,
|
|
1006
|
+
) {
|
|
1007
|
+
return this.updatePosition('combo', models, upsertAncestors, stack);
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
private updatePosition(
|
|
1011
|
+
type: 'node' | 'combo',
|
|
1012
|
+
models:
|
|
1013
|
+
| Partial<NodeUserModel>
|
|
1014
|
+
| Partial<
|
|
1015
|
+
ComboUserModel | Partial<NodeUserModel>[] | Partial<ComboUserModel>[]
|
|
1016
|
+
>,
|
|
1017
|
+
upsertAncestors?: boolean,
|
|
958
1018
|
stack?: boolean,
|
|
959
1019
|
) {
|
|
960
1020
|
const modelArr = isArray(models) ? models : [models];
|
|
@@ -963,32 +1023,36 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
963
1023
|
graphCore.once('changed', (event) => {
|
|
964
1024
|
if (!event.changes.length) return;
|
|
965
1025
|
this.hooks.itemchange.emit({
|
|
966
|
-
type
|
|
1026
|
+
type,
|
|
967
1027
|
changes: event.changes,
|
|
968
1028
|
graphCore,
|
|
969
1029
|
theme: specification,
|
|
970
|
-
|
|
1030
|
+
upsertAncestors,
|
|
1031
|
+
action: 'updatePosition',
|
|
971
1032
|
});
|
|
972
1033
|
this.emit('afteritemchange', {
|
|
973
|
-
type
|
|
974
|
-
action: '
|
|
1034
|
+
type,
|
|
1035
|
+
action: 'updatePosition',
|
|
1036
|
+
upsertAncestors,
|
|
975
1037
|
models,
|
|
976
1038
|
});
|
|
977
1039
|
});
|
|
978
1040
|
|
|
979
1041
|
this.hooks.datachange.emit({
|
|
980
1042
|
data: {
|
|
981
|
-
nodes: modelArr as NodeUserModel[],
|
|
1043
|
+
nodes: type === 'node' ? (modelArr as NodeUserModel[]) : [],
|
|
982
1044
|
edges: [],
|
|
1045
|
+
combos: type === 'combo' ? (modelArr as ComboUserModel[]) : [],
|
|
983
1046
|
},
|
|
984
1047
|
type: 'update',
|
|
985
1048
|
});
|
|
986
1049
|
const dataList = this.dataController.findData(
|
|
987
|
-
|
|
1050
|
+
type,
|
|
988
1051
|
modelArr.map((model) => model.id),
|
|
989
1052
|
);
|
|
990
1053
|
return isArray(models) ? dataList : dataList[0];
|
|
991
1054
|
}
|
|
1055
|
+
|
|
992
1056
|
/**
|
|
993
1057
|
* Show the item(s).
|
|
994
1058
|
* @param item the item to be shown
|
|
@@ -1000,6 +1064,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1000
1064
|
this.hooks.itemvisibilitychange.emit({
|
|
1001
1065
|
ids: idArr as ID[],
|
|
1002
1066
|
value: true,
|
|
1067
|
+
graphCore: this.dataController.graphCore,
|
|
1003
1068
|
animate: !disableAniamte,
|
|
1004
1069
|
});
|
|
1005
1070
|
}
|
|
@@ -1014,9 +1079,37 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1014
1079
|
this.hooks.itemvisibilitychange.emit({
|
|
1015
1080
|
ids: idArr as ID[],
|
|
1016
1081
|
value: false,
|
|
1082
|
+
graphCore: this.dataController.graphCore,
|
|
1017
1083
|
animate: !disableAniamte,
|
|
1018
1084
|
});
|
|
1019
1085
|
}
|
|
1086
|
+
|
|
1087
|
+
/**
|
|
1088
|
+
* Make the item(s) to the front.
|
|
1089
|
+
* @param ids
|
|
1090
|
+
* @returns
|
|
1091
|
+
* @group Item
|
|
1092
|
+
*/
|
|
1093
|
+
public frontItem(ids: ID | ID[]) {
|
|
1094
|
+
const idArr = isArray(ids) ? ids : [ids];
|
|
1095
|
+
this.hooks.itemzindexchange.emit({
|
|
1096
|
+
ids: idArr as ID[],
|
|
1097
|
+
action: 'front',
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
1100
|
+
/**
|
|
1101
|
+
* Make the item(s) to the back.
|
|
1102
|
+
* @param ids
|
|
1103
|
+
* @returns
|
|
1104
|
+
* @group Item
|
|
1105
|
+
*/
|
|
1106
|
+
public backItem(ids: ID | ID[]) {
|
|
1107
|
+
const idArr = isArray(ids) ? ids : [ids];
|
|
1108
|
+
this.hooks.itemzindexchange.emit({
|
|
1109
|
+
ids: idArr as ID[],
|
|
1110
|
+
action: 'back',
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1020
1113
|
/**
|
|
1021
1114
|
* Set state for the item.
|
|
1022
1115
|
* @param item the item to be set
|
|
@@ -1073,9 +1166,13 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1073
1166
|
* @returns rendering bounding box. returns false if the item is not exist
|
|
1074
1167
|
* @group Item
|
|
1075
1168
|
*/
|
|
1076
|
-
public getRenderBBox(
|
|
1169
|
+
public getRenderBBox(
|
|
1170
|
+
id: ID | undefined,
|
|
1171
|
+
onlyKeyShape = false,
|
|
1172
|
+
isTransient = false,
|
|
1173
|
+
): AABB | false {
|
|
1077
1174
|
if (!id) return this.canvas.getRoot().getRenderBounds();
|
|
1078
|
-
return this.itemController.getItemBBox(id);
|
|
1175
|
+
return this.itemController.getItemBBox(id, onlyKeyShape, isTransient);
|
|
1079
1176
|
}
|
|
1080
1177
|
|
|
1081
1178
|
/**
|
|
@@ -1089,42 +1186,130 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1089
1186
|
}
|
|
1090
1187
|
|
|
1091
1188
|
// ===== combo operations =====
|
|
1189
|
+
|
|
1092
1190
|
/**
|
|
1093
|
-
*
|
|
1094
|
-
*
|
|
1095
|
-
* @param
|
|
1191
|
+
* 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.
|
|
1192
|
+
* Different from addData with combo type, this API update the succeeds' combo tree strucutres in the same time.
|
|
1193
|
+
* @param model combo user data
|
|
1194
|
+
* @param stack whether push this operation to stack
|
|
1195
|
+
* @returns whether success
|
|
1096
1196
|
* @group Combo
|
|
1097
1197
|
*/
|
|
1098
|
-
public
|
|
1099
|
-
|
|
1100
|
-
childrenIds:
|
|
1198
|
+
public addCombo(
|
|
1199
|
+
model: ComboUserModel,
|
|
1200
|
+
childrenIds: ID[],
|
|
1101
1201
|
stack?: boolean,
|
|
1102
|
-
) {
|
|
1103
|
-
|
|
1202
|
+
): ComboModel {
|
|
1203
|
+
const { graphCore } = this.dataController;
|
|
1204
|
+
const { specification } = this.themeController;
|
|
1205
|
+
graphCore.once('changed', (event) => {
|
|
1206
|
+
if (!event.changes.length) return;
|
|
1207
|
+
this.hooks.itemchange.emit({
|
|
1208
|
+
type: 'combo',
|
|
1209
|
+
changes: graphCore.reduceChanges(event.changes),
|
|
1210
|
+
graphCore,
|
|
1211
|
+
theme: specification,
|
|
1212
|
+
});
|
|
1213
|
+
this.emit('afteritemchange', {
|
|
1214
|
+
type: 'combo',
|
|
1215
|
+
action: 'add',
|
|
1216
|
+
models: [model],
|
|
1217
|
+
});
|
|
1218
|
+
});
|
|
1219
|
+
|
|
1220
|
+
const data = {
|
|
1221
|
+
nodes: [],
|
|
1222
|
+
edges: [],
|
|
1223
|
+
combos: [
|
|
1224
|
+
{
|
|
1225
|
+
...model,
|
|
1226
|
+
data: {
|
|
1227
|
+
...model.data,
|
|
1228
|
+
_children: childrenIds,
|
|
1229
|
+
},
|
|
1230
|
+
},
|
|
1231
|
+
],
|
|
1232
|
+
};
|
|
1233
|
+
this.hooks.datachange.emit({
|
|
1234
|
+
data,
|
|
1235
|
+
type: 'addCombo',
|
|
1236
|
+
});
|
|
1237
|
+
return this.dataController.findData('combo', [model.id])[0] as ComboModel;
|
|
1104
1238
|
}
|
|
1105
1239
|
/**
|
|
1106
|
-
*
|
|
1107
|
-
* @param
|
|
1240
|
+
* Collapse a combo.
|
|
1241
|
+
* @param comboId combo ids
|
|
1108
1242
|
* @group Combo
|
|
1109
1243
|
*/
|
|
1110
|
-
public
|
|
1111
|
-
|
|
1244
|
+
public collapseCombo(comboIds: ID | ID[], stack?: boolean) {
|
|
1245
|
+
const ids = isArray(comboIds) ? comboIds : [comboIds];
|
|
1246
|
+
this.updateData(
|
|
1247
|
+
'combo',
|
|
1248
|
+
ids.map((id) => ({ id, data: { collapsed: true } })),
|
|
1249
|
+
);
|
|
1250
|
+
// emit collapse event?
|
|
1112
1251
|
}
|
|
1113
1252
|
/**
|
|
1114
|
-
*
|
|
1115
|
-
* @param
|
|
1253
|
+
* Expand a combo.
|
|
1254
|
+
* @param combo combo ids
|
|
1116
1255
|
* @group Combo
|
|
1117
1256
|
*/
|
|
1118
|
-
public
|
|
1119
|
-
|
|
1257
|
+
public expandCombo(comboIds: ID | ID[], stack?: boolean) {
|
|
1258
|
+
const ids = isArray(comboIds) ? comboIds : [comboIds];
|
|
1259
|
+
this.updateData(
|
|
1260
|
+
'combo',
|
|
1261
|
+
ids.map((id) => ({ id, data: { collapsed: false } })),
|
|
1262
|
+
);
|
|
1263
|
+
// emit expand event?
|
|
1120
1264
|
}
|
|
1265
|
+
|
|
1121
1266
|
/**
|
|
1122
|
-
*
|
|
1123
|
-
*
|
|
1267
|
+
* Move one or more combos a distance (dx, dy) relatively,
|
|
1268
|
+
* do not update other styles which leads to better performance than updating positions by updateData.
|
|
1269
|
+
* In fact, it changes the succeed nodes positions to affect the combo's position, but not modify the combo's position directly.
|
|
1270
|
+
* @param models new configurations with x and y for every combo, which has id field to indicate the specific item
|
|
1271
|
+
* @param {boolean} stack whether push this operation into graph's stack, true by default
|
|
1124
1272
|
* @group Combo
|
|
1125
1273
|
*/
|
|
1126
|
-
public
|
|
1127
|
-
|
|
1274
|
+
public moveCombo(
|
|
1275
|
+
ids: ID | ID[],
|
|
1276
|
+
dx: number,
|
|
1277
|
+
dy: number,
|
|
1278
|
+
upsertAncestors?: boolean,
|
|
1279
|
+
stack?: boolean,
|
|
1280
|
+
): ComboModel[] {
|
|
1281
|
+
const idArr = isArray(ids) ? ids : [ids];
|
|
1282
|
+
const { graphCore } = this.dataController;
|
|
1283
|
+
const { specification } = this.themeController;
|
|
1284
|
+
graphCore.once('changed', (event) => {
|
|
1285
|
+
if (!event.changes.length) return;
|
|
1286
|
+
this.hooks.itemchange.emit({
|
|
1287
|
+
type: 'combo',
|
|
1288
|
+
changes: event.changes,
|
|
1289
|
+
graphCore,
|
|
1290
|
+
theme: specification,
|
|
1291
|
+
upsertAncestors,
|
|
1292
|
+
action: 'updatePosition',
|
|
1293
|
+
});
|
|
1294
|
+
this.emit('afteritemchange', {
|
|
1295
|
+
type: 'combo',
|
|
1296
|
+
ids: idArr,
|
|
1297
|
+
dx,
|
|
1298
|
+
dy,
|
|
1299
|
+
action: 'updatePosition',
|
|
1300
|
+
upsertAncestors,
|
|
1301
|
+
});
|
|
1302
|
+
});
|
|
1303
|
+
|
|
1304
|
+
this.hooks.datachange.emit({
|
|
1305
|
+
data: {
|
|
1306
|
+
nodes: [],
|
|
1307
|
+
edges: [],
|
|
1308
|
+
combos: idArr.map((id) => ({ id, data: { dx, dy } })),
|
|
1309
|
+
},
|
|
1310
|
+
type: 'moveCombo',
|
|
1311
|
+
});
|
|
1312
|
+
return this.dataController.findData('combo', idArr) as ComboModel[];
|
|
1128
1313
|
}
|
|
1129
1314
|
|
|
1130
1315
|
// ===== layout =====
|
|
@@ -1399,6 +1584,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1399
1584
|
action: 'remove' | 'add' | 'update' | undefined;
|
|
1400
1585
|
style: ShapeStyle;
|
|
1401
1586
|
onlyDrawKeyShape?: boolean;
|
|
1587
|
+
upsertAncestors?: boolean;
|
|
1402
1588
|
},
|
|
1403
1589
|
): DisplayObject {
|
|
1404
1590
|
this.hooks.transientupdate.emit({
|
|
@@ -1406,6 +1592,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1406
1592
|
id,
|
|
1407
1593
|
config,
|
|
1408
1594
|
canvas: this.transientCanvas,
|
|
1595
|
+
graphCore: this.dataController.graphCore,
|
|
1409
1596
|
});
|
|
1410
1597
|
return this.itemController.getTransient(String(id));
|
|
1411
1598
|
}
|
|
@@ -67,7 +67,8 @@ export default class ClickSelect extends Behavior {
|
|
|
67
67
|
* Two flag to avoid onCanvasClick triggered while dragging canvas
|
|
68
68
|
*/
|
|
69
69
|
private canvasPointerDown: Point | undefined = undefined;
|
|
70
|
-
private canvasPointerMove
|
|
70
|
+
private canvasPointerMove = false;
|
|
71
|
+
private timeout: NodeJS.Timeout = undefined;
|
|
71
72
|
|
|
72
73
|
constructor(options: Partial<ClickSelectOptions>) {
|
|
73
74
|
super(Object.assign({}, DEFAULT_OPTIONS, options));
|
|
@@ -84,6 +85,7 @@ export default class ClickSelect extends Behavior {
|
|
|
84
85
|
return {
|
|
85
86
|
'node:click': this.onClick,
|
|
86
87
|
'edge:click': this.onClick,
|
|
88
|
+
'combo:click': this.onClickBesideDblClick,
|
|
87
89
|
'canvas:pointerdown': this.onCanvasPointerDown,
|
|
88
90
|
'canvas:pointermove': this.onCanvasPointerMove,
|
|
89
91
|
'canvas:pointerup': this.onCanvasPointerUp,
|
|
@@ -92,7 +94,6 @@ export default class ClickSelect extends Behavior {
|
|
|
92
94
|
|
|
93
95
|
private isMultipleSelect(event: MouseEvent) {
|
|
94
96
|
if (!this.options.multiple) return false;
|
|
95
|
-
const key = this.options.trigger;
|
|
96
97
|
const keyMap: Record<Trigger, boolean> = {
|
|
97
98
|
shift: event.shiftKey,
|
|
98
99
|
ctrl: event.ctrlKey,
|
|
@@ -102,6 +103,18 @@ export default class ClickSelect extends Behavior {
|
|
|
102
103
|
return keyMap[this.options.trigger];
|
|
103
104
|
}
|
|
104
105
|
|
|
106
|
+
public onClickBesideDblClick(event: IG6GraphEvent) {
|
|
107
|
+
if (this.timeout) {
|
|
108
|
+
clearTimeout(this.timeout);
|
|
109
|
+
this.timeout = undefined;
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
this.timeout = setTimeout(() => {
|
|
113
|
+
this.timeout = undefined;
|
|
114
|
+
this.onClick(event);
|
|
115
|
+
}, 200);
|
|
116
|
+
}
|
|
117
|
+
|
|
105
118
|
public onClick(event: IG6GraphEvent) {
|
|
106
119
|
if (!this.options.shouldBegin(event)) return;
|
|
107
120
|
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ID } from '@antv/graphlib';
|
|
2
|
+
import { throttle, uniq } from '@antv/util';
|
|
3
|
+
import { ComboModel, EdgeModel, NodeModel } from '../../types';
|
|
4
|
+
import { Behavior } from '../../types/behavior';
|
|
5
|
+
import { IG6GraphEvent } from '../../types/event';
|
|
6
|
+
import { Point } from '../../types/common';
|
|
7
|
+
import { graphComboTreeDfs } from '../../util/data';
|
|
8
|
+
|
|
9
|
+
const ALLOWED_TRIGGERS = ['dblclick', 'click'] as const;
|
|
10
|
+
type Trigger = (typeof ALLOWED_TRIGGERS)[number];
|
|
11
|
+
|
|
12
|
+
export interface CollapseExpandComboOptions {
|
|
13
|
+
/**
|
|
14
|
+
* The key to pressed with mouse click to apply multiple selection.
|
|
15
|
+
* Defaults to `"dblclick"`.
|
|
16
|
+
* Could be "dblclick", "click".
|
|
17
|
+
*/
|
|
18
|
+
trigger: Trigger;
|
|
19
|
+
/**
|
|
20
|
+
* Whether allow the behavior happen on the current item.
|
|
21
|
+
*/
|
|
22
|
+
shouldBegin?: (event: IG6GraphEvent) => boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const DEFAULT_OPTIONS: Required<CollapseExpandComboOptions> = {
|
|
26
|
+
trigger: 'dblclick',
|
|
27
|
+
shouldBegin: () => true,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export default class CollapseExpandCombo extends Behavior {
|
|
31
|
+
options: CollapseExpandComboOptions;
|
|
32
|
+
|
|
33
|
+
constructor(options: Partial<CollapseExpandComboOptions>) {
|
|
34
|
+
const finalOptions = Object.assign({}, DEFAULT_OPTIONS, options);
|
|
35
|
+
super(finalOptions);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
getEvents = () => {
|
|
39
|
+
if (this.options.trigger === 'dblclick') {
|
|
40
|
+
return {
|
|
41
|
+
'combo:dblclick': this.collapseExpandCombo,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
'combo:click': this.collapseExpandCombo,
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
public collapseExpandCombo(event: IG6GraphEvent) {
|
|
50
|
+
if (!this.options.shouldBegin(event)) return;
|
|
51
|
+
const { itemId } = event;
|
|
52
|
+
const model = this.graph.getComboData(itemId);
|
|
53
|
+
if (model.data.collapsed) {
|
|
54
|
+
this.graph.expandCombo(itemId);
|
|
55
|
+
} else {
|
|
56
|
+
this.graph.collapseCombo(itemId);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|