@antv/g6 5.0.0-alpha.7 → 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/base3d.d.ts +1 -0
- package/esm/stdlib/item/node/base3d.js +1 -0
- package/esm/stdlib/item/node/base3d.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/base3d.d.ts +1 -0
- package/lib/stdlib/item/node/base3d.js +1 -0
- package/lib/stdlib/item/node/base3d.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 +15 -18
- 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/base3d.ts +2 -0
- 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
|
@@ -0,0 +1,533 @@
|
|
|
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 DELEGATE_SHAPE_ID = 'g6-drag-combo-delegate-shape';
|
|
10
|
+
|
|
11
|
+
export interface DragComboOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Whether to draw dragging nodes in transient layer.
|
|
14
|
+
* Ignored when enableDelegate is true.
|
|
15
|
+
* Defaults to true.
|
|
16
|
+
*/
|
|
17
|
+
enableTransient?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Whether to use a virtual rect moved with the dragging mouse instead of the node.
|
|
20
|
+
* Defaults to false.
|
|
21
|
+
*/
|
|
22
|
+
enableDelegate?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* The drawing properties when the nodes are dragged.
|
|
25
|
+
* Only used when enableDelegate is true.
|
|
26
|
+
*/
|
|
27
|
+
delegateStyle?: {
|
|
28
|
+
fill?: string;
|
|
29
|
+
stroke?: string;
|
|
30
|
+
fillOpacity?: number;
|
|
31
|
+
strokeOpacity?: number;
|
|
32
|
+
lineWidth?: number;
|
|
33
|
+
lineDash?: [number, number];
|
|
34
|
+
[key: string]: unknown;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* The time in milliseconds to throttle moving. Useful to avoid the frequent calculation.
|
|
38
|
+
* Defaults to 0.
|
|
39
|
+
*/
|
|
40
|
+
throttle?: number;
|
|
41
|
+
/**
|
|
42
|
+
* Whether to hide the related edges to avoid calculation while dragging nodes.
|
|
43
|
+
* Ignored when enableTransient or enableDelegate is true.
|
|
44
|
+
* Defaults to false.
|
|
45
|
+
*/
|
|
46
|
+
hideRelatedEdges?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* The state name to be considered as "selected".
|
|
49
|
+
* Defaults to "selected".
|
|
50
|
+
*/
|
|
51
|
+
selectedState?: string;
|
|
52
|
+
/**
|
|
53
|
+
* The event name to trigger when drag end.
|
|
54
|
+
*/
|
|
55
|
+
eventName?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Whether change the combo hierarchy structure or only change size.
|
|
58
|
+
*/
|
|
59
|
+
updateComboStructure?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Whether allow the behavior happen on the current item.
|
|
62
|
+
*/
|
|
63
|
+
shouldBegin?: (event: IG6GraphEvent) => boolean;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const DEFAULT_OPTIONS: Required<DragComboOptions> = {
|
|
67
|
+
enableTransient: true,
|
|
68
|
+
enableDelegate: false,
|
|
69
|
+
delegateStyle: {
|
|
70
|
+
fill: '#F3F9FF',
|
|
71
|
+
fillOpacity: 0.5,
|
|
72
|
+
stroke: '#1890FF',
|
|
73
|
+
strokeOpacity: 0.9,
|
|
74
|
+
lineDash: [5, 5],
|
|
75
|
+
},
|
|
76
|
+
throttle: 16,
|
|
77
|
+
hideRelatedEdges: false,
|
|
78
|
+
selectedState: 'selected',
|
|
79
|
+
eventName: '',
|
|
80
|
+
updateComboStructure: true,
|
|
81
|
+
shouldBegin: () => true,
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export default class DragCombo extends Behavior {
|
|
85
|
+
options: DragComboOptions;
|
|
86
|
+
|
|
87
|
+
// Private states
|
|
88
|
+
private hiddenEdges: EdgeModel[] = [];
|
|
89
|
+
private hiddenComboTreeRoots: (ComboModel | NodeModel)[] = [];
|
|
90
|
+
private originX: number;
|
|
91
|
+
private originY: number;
|
|
92
|
+
private previousX: number;
|
|
93
|
+
private previousY: number;
|
|
94
|
+
private originPositions: Array<{
|
|
95
|
+
id: ID;
|
|
96
|
+
x: number;
|
|
97
|
+
y: number;
|
|
98
|
+
// The following fields only have values when delegate is enabled.
|
|
99
|
+
minX?: number;
|
|
100
|
+
maxX?: number;
|
|
101
|
+
minY?: number;
|
|
102
|
+
maxY?: number;
|
|
103
|
+
}> = [];
|
|
104
|
+
private selectedComboIds: ID[];
|
|
105
|
+
private pointerDown: Point | undefined = undefined;
|
|
106
|
+
private dragging = false;
|
|
107
|
+
|
|
108
|
+
constructor(options: Partial<DragComboOptions>) {
|
|
109
|
+
const finalOptions = Object.assign({}, DEFAULT_OPTIONS, options);
|
|
110
|
+
if (finalOptions.enableDelegate) {
|
|
111
|
+
finalOptions.enableTransient = false;
|
|
112
|
+
}
|
|
113
|
+
if (finalOptions.enableDelegate || finalOptions.enableTransient) {
|
|
114
|
+
finalOptions.hideRelatedEdges = false;
|
|
115
|
+
}
|
|
116
|
+
super(finalOptions);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
getEvents = () => {
|
|
120
|
+
const events = {
|
|
121
|
+
'combo:pointerdown': this.onPointerDown,
|
|
122
|
+
pointermove: this.onPointerMove,
|
|
123
|
+
click: this.onPointerUp,
|
|
124
|
+
// FIXME: IG6Event -> keyboard event
|
|
125
|
+
keydown: this.onKeydown as any,
|
|
126
|
+
};
|
|
127
|
+
if (this.options.updateComboStructure) {
|
|
128
|
+
return {
|
|
129
|
+
'combo:drop': this.onDropCombo,
|
|
130
|
+
'canvas:drop': this.onDropCanvas,
|
|
131
|
+
...events,
|
|
132
|
+
};
|
|
133
|
+
} else {
|
|
134
|
+
return {
|
|
135
|
+
pointerup: this.onPointerUp,
|
|
136
|
+
...events,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/** Given selected node ids, get their related visible edges. */
|
|
142
|
+
private getRelatedEdges(
|
|
143
|
+
selectedComboIds: ID[],
|
|
144
|
+
comboTreeRoots: (ComboModel | NodeModel)[],
|
|
145
|
+
) {
|
|
146
|
+
let edges = selectedComboIds.flatMap((comboId) =>
|
|
147
|
+
this.graph.getRelatedEdgesData(comboId),
|
|
148
|
+
);
|
|
149
|
+
graphComboTreeDfs(this.graph, comboTreeRoots, (child) => {
|
|
150
|
+
edges = edges.concat(this.graph.getRelatedEdgesData(child.id));
|
|
151
|
+
});
|
|
152
|
+
return uniq(edges).filter((edgeData) => {
|
|
153
|
+
return this.graph.getItemVisible(edgeData.id);
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
private getComboTreeItems(selectedComboIds: ID[]) {
|
|
158
|
+
let begins = [];
|
|
159
|
+
if (!this.options.updateComboStructure) {
|
|
160
|
+
// do not change the combo structure, begins are the roots
|
|
161
|
+
selectedComboIds.forEach((id) => {
|
|
162
|
+
const comboData = this.graph.getComboData(id);
|
|
163
|
+
let rootAncestor = comboData;
|
|
164
|
+
let parentId = comboData.data.parentId;
|
|
165
|
+
while (parentId) {
|
|
166
|
+
const parentData = this.graph.getComboData(parentId);
|
|
167
|
+
if (!parentData) break;
|
|
168
|
+
parentId = parentData.data.parentId;
|
|
169
|
+
rootAncestor = parentData;
|
|
170
|
+
}
|
|
171
|
+
begins.push(rootAncestor);
|
|
172
|
+
});
|
|
173
|
+
} else {
|
|
174
|
+
begins = selectedComboIds.map((id) => this.graph.getComboData(id));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const items = begins;
|
|
178
|
+
graphComboTreeDfs(this.graph, begins, (child) => items.push(child), 'TB');
|
|
179
|
+
return uniq(items).filter(
|
|
180
|
+
(item) =>
|
|
181
|
+
!selectedComboIds.includes(item.id) &&
|
|
182
|
+
this.graph.getItemVisible(item.id),
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
public onPointerDown(event: IG6GraphEvent) {
|
|
187
|
+
if (!this.options.shouldBegin(event)) return;
|
|
188
|
+
this.pointerDown = { x: event.canvas.x, y: event.canvas.y };
|
|
189
|
+
this.dragging = false;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
public onPointerMove(event: IG6GraphEvent) {
|
|
193
|
+
if (!this.pointerDown) return;
|
|
194
|
+
|
|
195
|
+
const beginDeltaX = Math.abs(this.pointerDown.x - event.canvas.x);
|
|
196
|
+
const beginDeltaY = Math.abs(this.pointerDown.y - event.canvas.y);
|
|
197
|
+
if (beginDeltaX < 1 && beginDeltaY < 1) return;
|
|
198
|
+
|
|
199
|
+
const enableTransient =
|
|
200
|
+
this.options.enableTransient && this.graph.rendererType !== 'webgl-3d';
|
|
201
|
+
|
|
202
|
+
if (this.dragging) {
|
|
203
|
+
this.originPositions = this.selectedComboIds
|
|
204
|
+
.map((id) => {
|
|
205
|
+
if (!this.graph.getComboData(id)) {
|
|
206
|
+
console.warn('combo does not exist', id);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
const bounds = this.graph.getRenderBBox(id, true, enableTransient);
|
|
210
|
+
if (!bounds) return;
|
|
211
|
+
const [x, y] = bounds.center;
|
|
212
|
+
// If delegate is enabled, record bbox together.
|
|
213
|
+
if (this.options.enableDelegate) {
|
|
214
|
+
const [minX, minY] = bounds.min;
|
|
215
|
+
const [maxX, maxY] = bounds.max;
|
|
216
|
+
return { id, x, y, minX, minY, maxX, maxY };
|
|
217
|
+
}
|
|
218
|
+
return { id, x, y };
|
|
219
|
+
})
|
|
220
|
+
.filter(Boolean);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// pointerDown + first move = dragstart
|
|
224
|
+
if (!this.dragging) {
|
|
225
|
+
this.dragging = true;
|
|
226
|
+
|
|
227
|
+
const currentComboId = event.itemId;
|
|
228
|
+
let selectedComboIds = this.graph.findIdByState(
|
|
229
|
+
'combo',
|
|
230
|
+
this.options.selectedState,
|
|
231
|
+
true,
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
// If current node is selected, drag all the selected nodes together.
|
|
235
|
+
// Otherwise drag current node.
|
|
236
|
+
if (
|
|
237
|
+
currentComboId &&
|
|
238
|
+
event.itemType === 'combo' &&
|
|
239
|
+
!selectedComboIds.includes(currentComboId)
|
|
240
|
+
) {
|
|
241
|
+
selectedComboIds = [currentComboId];
|
|
242
|
+
}
|
|
243
|
+
this.selectedComboIds = selectedComboIds;
|
|
244
|
+
|
|
245
|
+
// Hide related edge.
|
|
246
|
+
if (this.options.hideRelatedEdges && !enableTransient) {
|
|
247
|
+
this.hiddenComboTreeRoots = this.getComboTreeItems(selectedComboIds);
|
|
248
|
+
this.hiddenEdges = this.getRelatedEdges(
|
|
249
|
+
selectedComboIds,
|
|
250
|
+
this.hiddenComboTreeRoots,
|
|
251
|
+
);
|
|
252
|
+
this.graph.hideItem(
|
|
253
|
+
this.hiddenEdges.map((edge) => edge.id),
|
|
254
|
+
true,
|
|
255
|
+
);
|
|
256
|
+
this.graph.hideItem(
|
|
257
|
+
this.hiddenComboTreeRoots.map((child) => child.id),
|
|
258
|
+
true,
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// Draw transient nodes and edges.
|
|
263
|
+
if (enableTransient) {
|
|
264
|
+
// Draw transient edges and nodes.
|
|
265
|
+
this.hiddenComboTreeRoots = this.getComboTreeItems(selectedComboIds);
|
|
266
|
+
this.hiddenEdges = this.getRelatedEdges(
|
|
267
|
+
selectedComboIds,
|
|
268
|
+
this.hiddenComboTreeRoots,
|
|
269
|
+
);
|
|
270
|
+
selectedComboIds.forEach((comboId) => {
|
|
271
|
+
this.graph.drawTransient('combo', comboId, {
|
|
272
|
+
upsertAncestors: !this.options.updateComboStructure,
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
this.hiddenEdges.forEach((edge) => {
|
|
276
|
+
this.graph.drawTransient('edge', edge.id, {});
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
// Hide original edges and nodes. They will be restored when pointerup.
|
|
280
|
+
this.graph.hideItem(selectedComboIds, true);
|
|
281
|
+
this.graph.hideItem(
|
|
282
|
+
this.hiddenEdges.map((edge) => edge.id),
|
|
283
|
+
true,
|
|
284
|
+
);
|
|
285
|
+
this.graph.hideItem(
|
|
286
|
+
this.hiddenComboTreeRoots.map((child) => child.id),
|
|
287
|
+
true,
|
|
288
|
+
);
|
|
289
|
+
} else {
|
|
290
|
+
this.graph.frontItem(selectedComboIds);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// Throttle moving.
|
|
294
|
+
if (this.options.throttle > 0) {
|
|
295
|
+
this.throttledMoveCombos = throttle(
|
|
296
|
+
this.moveCombos,
|
|
297
|
+
this.options.throttle,
|
|
298
|
+
{ leading: true, trailing: true },
|
|
299
|
+
);
|
|
300
|
+
} else {
|
|
301
|
+
this.throttledMoveCombos = this.moveCombos;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
this.originX = event.canvas.x;
|
|
305
|
+
this.originY = event.canvas.y;
|
|
306
|
+
this.previousX = event.canvas.x;
|
|
307
|
+
this.previousY = event.canvas.y;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
if (!this.originPositions.length || !this.dragging) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// @ts-ignore FIXME: type
|
|
315
|
+
const pointerEvent = event as PointerEvent;
|
|
316
|
+
// @ts-ignore FIXME: Type
|
|
317
|
+
const deltaX = pointerEvent.canvas.x - this.previousX;
|
|
318
|
+
// @ts-ignore FIXME: Type
|
|
319
|
+
const deltaY = pointerEvent.canvas.y - this.previousY;
|
|
320
|
+
|
|
321
|
+
if (this.options.enableDelegate) {
|
|
322
|
+
this.moveDelegate(deltaX, deltaY);
|
|
323
|
+
} else {
|
|
324
|
+
const enableTransient =
|
|
325
|
+
this.options.enableTransient && this.graph.rendererType !== 'webgl-3d';
|
|
326
|
+
this.throttledMoveCombos(
|
|
327
|
+
deltaX,
|
|
328
|
+
deltaY,
|
|
329
|
+
enableTransient,
|
|
330
|
+
!this.options.updateComboStructure,
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
public moveCombos(
|
|
336
|
+
deltaX: number,
|
|
337
|
+
deltaY: number,
|
|
338
|
+
transient: boolean,
|
|
339
|
+
upsertAncestors = true,
|
|
340
|
+
) {
|
|
341
|
+
if (transient) {
|
|
342
|
+
// Move transient nodes
|
|
343
|
+
this.originPositions.forEach(({ id, x, y }) => {
|
|
344
|
+
this.graph.drawTransient('combo', id, {
|
|
345
|
+
data: {
|
|
346
|
+
x: x + deltaX,
|
|
347
|
+
y: y + deltaY,
|
|
348
|
+
},
|
|
349
|
+
upsertAncestors,
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
// Update transient edges.
|
|
353
|
+
this.hiddenEdges.forEach((edge) => {
|
|
354
|
+
this.graph.drawTransient('edge', edge.id, {});
|
|
355
|
+
});
|
|
356
|
+
} else {
|
|
357
|
+
this.graph.moveCombo(
|
|
358
|
+
this.originPositions.map(({ id }) => id),
|
|
359
|
+
deltaX,
|
|
360
|
+
deltaY,
|
|
361
|
+
upsertAncestors,
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
this.previousX += deltaX;
|
|
366
|
+
this.previousY += deltaY;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
public throttledMoveCombos: Function = (
|
|
370
|
+
deltaX: number,
|
|
371
|
+
deltaY: number,
|
|
372
|
+
transient: boolean,
|
|
373
|
+
upsertAncestors = true,
|
|
374
|
+
) => {
|
|
375
|
+
// Should be overrided when drag start.
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
public moveDelegate(deltaX: number, deltaY: number) {
|
|
379
|
+
const x1 = Math.min(
|
|
380
|
+
...this.originPositions.map((position) => position.minX),
|
|
381
|
+
);
|
|
382
|
+
const y1 = Math.min(
|
|
383
|
+
...this.originPositions.map((position) => position.minY),
|
|
384
|
+
);
|
|
385
|
+
const x2 = Math.max(
|
|
386
|
+
...this.originPositions.map((position) => position.maxX),
|
|
387
|
+
);
|
|
388
|
+
const y2 = Math.max(
|
|
389
|
+
...this.originPositions.map((position) => position.maxY),
|
|
390
|
+
);
|
|
391
|
+
this.graph.drawTransient('rect', DELEGATE_SHAPE_ID, {
|
|
392
|
+
style: {
|
|
393
|
+
x: x1 + deltaX,
|
|
394
|
+
y: y1 + deltaY,
|
|
395
|
+
width: x2 - x1,
|
|
396
|
+
height: y2 - y1,
|
|
397
|
+
...this.options.delegateStyle,
|
|
398
|
+
},
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
public clearDelegate() {
|
|
403
|
+
this.graph.drawTransient('rect', DELEGATE_SHAPE_ID, { action: 'remove' });
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
public clearTransientItems() {
|
|
407
|
+
this.hiddenEdges.forEach((edge) => {
|
|
408
|
+
this.graph.drawTransient('combo', edge.source, { action: 'remove' });
|
|
409
|
+
this.graph.drawTransient('combo', edge.target, { action: 'remove' });
|
|
410
|
+
this.graph.drawTransient('edge', edge.id, { action: 'remove' });
|
|
411
|
+
});
|
|
412
|
+
this.hiddenComboTreeRoots.forEach((item) => {
|
|
413
|
+
const isCombo = item.data._isCombo;
|
|
414
|
+
this.graph.drawTransient(isCombo ? 'combo' : 'node', item.id, {
|
|
415
|
+
action: 'remove',
|
|
416
|
+
});
|
|
417
|
+
});
|
|
418
|
+
this.originPositions.forEach(({ id }) => {
|
|
419
|
+
this.graph.drawTransient('combo', id, { action: 'remove' });
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
public restoreHiddenItems() {
|
|
424
|
+
if (this.hiddenEdges.length) {
|
|
425
|
+
this.graph.showItem(
|
|
426
|
+
this.hiddenEdges.map((edge) => edge.id),
|
|
427
|
+
true,
|
|
428
|
+
);
|
|
429
|
+
this.hiddenEdges = [];
|
|
430
|
+
}
|
|
431
|
+
if (this.hiddenComboTreeRoots.length) {
|
|
432
|
+
this.graph.showItem(
|
|
433
|
+
this.hiddenComboTreeRoots.map((model) => model.id),
|
|
434
|
+
true,
|
|
435
|
+
);
|
|
436
|
+
this.hiddenComboTreeRoots = [];
|
|
437
|
+
}
|
|
438
|
+
const enableTransient =
|
|
439
|
+
this.options.enableTransient && this.graph.rendererType !== 'webgl-3d';
|
|
440
|
+
if (enableTransient) {
|
|
441
|
+
this.graph.showItem(
|
|
442
|
+
this.originPositions.map((position) => position.id),
|
|
443
|
+
true,
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
public onPointerUp(event: IG6GraphEvent) {
|
|
449
|
+
this.pointerDown = undefined;
|
|
450
|
+
this.dragging = false;
|
|
451
|
+
const enableTransient =
|
|
452
|
+
this.options.enableTransient && this.graph.rendererType !== 'webgl-3d';
|
|
453
|
+
// If transient or delegate was enabled, move the real nodes.
|
|
454
|
+
// if (enableTransient || this.options.enableDelegate) {
|
|
455
|
+
// @ts-ignore FIXME: type
|
|
456
|
+
const pointerEvent = event as PointerEvent;
|
|
457
|
+
const baseX = enableTransient ? this.originX : this.previousX;
|
|
458
|
+
const baseY = enableTransient ? this.originY : this.previousY;
|
|
459
|
+
// @ts-ignore FIXME: Type
|
|
460
|
+
const deltaX = pointerEvent.canvas.x - baseX + 0.01;
|
|
461
|
+
// @ts-ignore FIXME: Type
|
|
462
|
+
const deltaY = pointerEvent.canvas.y - baseY + 0.01;
|
|
463
|
+
this.moveCombos(deltaX, deltaY, false, true);
|
|
464
|
+
// }
|
|
465
|
+
|
|
466
|
+
if (enableTransient) {
|
|
467
|
+
this.clearTransientItems();
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
if (this.options.enableDelegate) {
|
|
471
|
+
this.clearDelegate();
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// Restore all hidden items.
|
|
475
|
+
// For all hideRelatedEdges, enableTransient and enableDelegate cases.
|
|
476
|
+
this.restoreHiddenItems();
|
|
477
|
+
|
|
478
|
+
// Emit event.
|
|
479
|
+
if (this.options.eventName) {
|
|
480
|
+
this.graph.emit(this.options.eventName, {
|
|
481
|
+
itemIds: this.originPositions.map((position) => position.id),
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
// Reset state.
|
|
486
|
+
this.originPositions = [];
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
public onKeydown(event: KeyboardEvent) {
|
|
490
|
+
if (event.key !== 'Escape' && event.key !== 'Esc') {
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
this.clearDelegate();
|
|
494
|
+
this.clearTransientItems();
|
|
495
|
+
this.restoreHiddenItems();
|
|
496
|
+
|
|
497
|
+
const enableTransient =
|
|
498
|
+
this.options.enableTransient && this.graph.rendererType !== 'webgl-3d';
|
|
499
|
+
// Restore node positions.
|
|
500
|
+
if (!enableTransient && !this.options.enableDelegate) {
|
|
501
|
+
const positionChanges = this.originPositions.map(({ id, x, y }) => {
|
|
502
|
+
return { id, data: { x, y } };
|
|
503
|
+
});
|
|
504
|
+
this.graph.updateComboPosition(positionChanges);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
this.originPositions = [];
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
public onDropCombo(event: IG6GraphEvent) {
|
|
511
|
+
const newParentId = event.itemId;
|
|
512
|
+
this.originPositions.forEach(({ id }) => {
|
|
513
|
+
const model = this.graph.getComboData(id);
|
|
514
|
+
if (!model || model.id === newParentId) return;
|
|
515
|
+
const { parentId } = model.data;
|
|
516
|
+
if (parentId === newParentId) return;
|
|
517
|
+
// event.stopPropagation();
|
|
518
|
+
this.graph.updateData('combo', { id, data: { parentId: newParentId } });
|
|
519
|
+
});
|
|
520
|
+
this.onPointerUp(event);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
public onDropCanvas(event: IG6GraphEvent) {
|
|
524
|
+
this.originPositions.forEach(({ id }) => {
|
|
525
|
+
const model = this.graph.getComboData(id);
|
|
526
|
+
if (!model) return;
|
|
527
|
+
const { parentId } = model.data;
|
|
528
|
+
if (!parentId) return;
|
|
529
|
+
this.graph.updateData('combo', { id, data: { parentId: undefined } });
|
|
530
|
+
});
|
|
531
|
+
this.onPointerUp(event);
|
|
532
|
+
}
|
|
533
|
+
}
|