@antv/g6 5.0.0-beta.5 → 5.0.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/g6.min.js +2 -2
- package/esm/index.d.ts +15 -7
- package/esm/index.js +1 -1
- package/esm/item/combo.d.ts +1 -1
- package/esm/item/combo.js +16 -9
- package/esm/item/combo.js.map +1 -1
- package/esm/item/edge.d.ts +22 -2
- package/esm/item/edge.js +93 -42
- package/esm/item/edge.js.map +1 -1
- package/esm/item/item.js +9 -5
- package/esm/item/item.js.map +1 -1
- package/esm/item/node.d.ts +1 -1
- package/esm/item/node.js +22 -15
- package/esm/item/node.js.map +1 -1
- package/esm/runtime/controller/data.d.ts +7 -10
- package/esm/runtime/controller/data.js +123 -281
- package/esm/runtime/controller/data.js.map +1 -1
- package/esm/runtime/controller/item.d.ts +1 -0
- package/esm/runtime/controller/item.js +21 -9
- package/esm/runtime/controller/item.js.map +1 -1
- package/esm/runtime/graph.d.ts +85 -7
- package/esm/runtime/graph.js +396 -61
- package/esm/runtime/graph.js.map +1 -1
- package/esm/stdlib/behavior/brush-select.js +1 -2
- package/esm/stdlib/behavior/brush-select.js.map +1 -1
- package/esm/stdlib/behavior/create-edge.d.ts +57 -0
- package/esm/stdlib/behavior/create-edge.js +207 -0
- package/esm/stdlib/behavior/create-edge.js.map +1 -0
- package/esm/stdlib/behavior/drag-canvas.d.ts +2 -1
- package/esm/stdlib/behavior/drag-canvas.js +26 -18
- package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
- package/esm/stdlib/behavior/drag-combo.d.ts +2 -2
- package/esm/stdlib/behavior/drag-combo.js +35 -24
- package/esm/stdlib/behavior/drag-combo.js.map +1 -1
- package/esm/stdlib/behavior/drag-node.d.ts +3 -3
- package/esm/stdlib/behavior/drag-node.js +70 -57
- package/esm/stdlib/behavior/drag-node.js.map +1 -1
- package/esm/stdlib/behavior/index.d.ts +2 -0
- package/esm/stdlib/behavior/index.js +2 -0
- package/esm/stdlib/behavior/index.js.map +1 -1
- package/esm/stdlib/behavior/lasso-select.d.ts +1 -1
- package/esm/stdlib/behavior/lasso-select.js +1 -2
- package/esm/stdlib/behavior/lasso-select.js.map +1 -1
- package/esm/stdlib/behavior/scroll-canvas.d.ts +67 -0
- package/esm/stdlib/behavior/scroll-canvas.js +266 -0
- package/esm/stdlib/behavior/scroll-canvas.js.map +1 -0
- package/esm/stdlib/behavior/zoom-canvas.d.ts +2 -1
- package/esm/stdlib/behavior/zoom-canvas.js +30 -22
- package/esm/stdlib/behavior/zoom-canvas.js.map +1 -1
- package/esm/stdlib/data/mapNodeSize.d.ts +2 -2
- package/esm/stdlib/data/mapNodeSize.js +2 -2
- package/esm/stdlib/data/mapNodeSize.js.map +1 -1
- package/esm/stdlib/data/transformV4Data.d.ts +2 -2
- package/esm/stdlib/data/transformV4Data.js +2 -2
- package/esm/stdlib/data/transformV4Data.js.map +1 -1
- package/esm/stdlib/data/validateData.d.ts +2 -2
- package/esm/stdlib/data/validateData.js +9 -9
- package/esm/stdlib/data/validateData.js.map +1 -1
- package/esm/stdlib/index.d.ts +10 -6
- package/esm/stdlib/index.js +5 -1
- package/esm/stdlib/index.js.map +1 -1
- package/esm/stdlib/item/edge/base.js +4 -9
- package/esm/stdlib/item/edge/base.js.map +1 -1
- package/esm/stdlib/plugin/hull/hullComponent.d.ts +1 -1
- package/esm/stdlib/plugin/hull/hullComponent.js +3 -6
- package/esm/stdlib/plugin/hull/hullComponent.js.map +1 -1
- package/esm/stdlib/plugin/minimap/index.d.ts +5 -1
- package/esm/stdlib/plugin/minimap/index.js +116 -9
- package/esm/stdlib/plugin/minimap/index.js.map +1 -1
- package/esm/stdlib/plugin/snapline/index.d.ts +5 -1
- package/esm/stdlib/plugin/snapline/index.js +23 -12
- package/esm/stdlib/plugin/snapline/index.js.map +1 -1
- package/esm/types/graph.d.ts +34 -8
- package/esm/types/hook.d.ts +16 -2
- package/esm/types/spec.d.ts +6 -3
- package/esm/types/view.d.ts +5 -0
- package/esm/util/event.d.ts +3 -1
- package/esm/util/event.js +8 -1
- package/esm/util/event.js.map +1 -1
- package/esm/util/item.d.ts +16 -1
- package/esm/util/item.js +31 -8
- package/esm/util/item.js.map +1 -1
- package/esm/util/layout.d.ts +11 -0
- package/esm/util/layout.js +45 -0
- package/esm/util/layout.js.map +1 -1
- package/esm/util/point.js +5 -1
- package/esm/util/point.js.map +1 -1
- package/esm/util/shape.d.ts +1 -1
- package/esm/util/shape.js +3 -7
- package/esm/util/shape.js.map +1 -1
- package/esm/util/warn.d.ts +14 -0
- package/esm/util/warn.js +4 -0
- package/esm/util/warn.js.map +1 -0
- package/lib/index.d.ts +15 -7
- package/lib/index.js +1 -1
- package/lib/item/combo.d.ts +1 -1
- package/lib/item/combo.js +16 -9
- package/lib/item/combo.js.map +1 -1
- package/lib/item/edge.d.ts +22 -2
- package/lib/item/edge.js +92 -41
- package/lib/item/edge.js.map +1 -1
- package/lib/item/item.js +9 -5
- package/lib/item/item.js.map +1 -1
- package/lib/item/node.d.ts +1 -1
- package/lib/item/node.js +22 -15
- package/lib/item/node.js.map +1 -1
- package/lib/runtime/controller/data.d.ts +7 -10
- package/lib/runtime/controller/data.js +123 -281
- package/lib/runtime/controller/data.js.map +1 -1
- package/lib/runtime/controller/item.d.ts +1 -0
- package/lib/runtime/controller/item.js +21 -9
- package/lib/runtime/controller/item.js.map +1 -1
- package/lib/runtime/graph.d.ts +85 -7
- package/lib/runtime/graph.js +396 -61
- package/lib/runtime/graph.js.map +1 -1
- package/lib/stdlib/behavior/brush-select.js +1 -2
- package/lib/stdlib/behavior/brush-select.js.map +1 -1
- package/lib/stdlib/behavior/create-edge.d.ts +57 -0
- package/lib/stdlib/behavior/create-edge.js +211 -0
- package/lib/stdlib/behavior/create-edge.js.map +1 -0
- package/lib/stdlib/behavior/drag-canvas.d.ts +2 -1
- package/lib/stdlib/behavior/drag-canvas.js +26 -18
- package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
- package/lib/stdlib/behavior/drag-combo.d.ts +2 -2
- package/lib/stdlib/behavior/drag-combo.js +35 -24
- package/lib/stdlib/behavior/drag-combo.js.map +1 -1
- package/lib/stdlib/behavior/drag-node.d.ts +3 -3
- package/lib/stdlib/behavior/drag-node.js +70 -57
- package/lib/stdlib/behavior/drag-node.js.map +1 -1
- package/lib/stdlib/behavior/index.d.ts +2 -0
- package/lib/stdlib/behavior/index.js +2 -0
- package/lib/stdlib/behavior/index.js.map +1 -1
- package/lib/stdlib/behavior/lasso-select.d.ts +1 -1
- package/lib/stdlib/behavior/lasso-select.js +1 -2
- package/lib/stdlib/behavior/lasso-select.js.map +1 -1
- package/lib/stdlib/behavior/scroll-canvas.d.ts +67 -0
- package/lib/stdlib/behavior/scroll-canvas.js +270 -0
- package/lib/stdlib/behavior/scroll-canvas.js.map +1 -0
- package/lib/stdlib/behavior/zoom-canvas.d.ts +2 -1
- package/lib/stdlib/behavior/zoom-canvas.js +30 -22
- package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
- package/lib/stdlib/data/mapNodeSize.d.ts +2 -2
- package/lib/stdlib/data/mapNodeSize.js +2 -2
- package/lib/stdlib/data/mapNodeSize.js.map +1 -1
- package/lib/stdlib/data/transformV4Data.d.ts +2 -2
- package/lib/stdlib/data/transformV4Data.js +2 -2
- package/lib/stdlib/data/transformV4Data.js.map +1 -1
- package/lib/stdlib/data/validateData.d.ts +2 -2
- package/lib/stdlib/data/validateData.js +9 -9
- package/lib/stdlib/data/validateData.js.map +1 -1
- package/lib/stdlib/index.d.ts +10 -6
- package/lib/stdlib/index.js +5 -1
- package/lib/stdlib/index.js.map +1 -1
- package/lib/stdlib/item/edge/base.js +4 -9
- package/lib/stdlib/item/edge/base.js.map +1 -1
- package/lib/stdlib/plugin/hull/hullComponent.d.ts +1 -1
- package/lib/stdlib/plugin/hull/hullComponent.js +3 -6
- package/lib/stdlib/plugin/hull/hullComponent.js.map +1 -1
- package/lib/stdlib/plugin/minimap/index.d.ts +5 -1
- package/lib/stdlib/plugin/minimap/index.js +116 -9
- package/lib/stdlib/plugin/minimap/index.js.map +1 -1
- package/lib/stdlib/plugin/snapline/index.d.ts +5 -1
- package/lib/stdlib/plugin/snapline/index.js +23 -12
- package/lib/stdlib/plugin/snapline/index.js.map +1 -1
- package/lib/types/graph.d.ts +34 -8
- package/lib/types/hook.d.ts +16 -2
- package/lib/types/spec.d.ts +6 -3
- package/lib/types/view.d.ts +5 -0
- package/lib/util/event.d.ts +3 -1
- package/lib/util/event.js +8 -1
- package/lib/util/event.js.map +1 -1
- package/lib/util/item.d.ts +16 -1
- package/lib/util/item.js +33 -9
- package/lib/util/item.js.map +1 -1
- package/lib/util/layout.d.ts +11 -0
- package/lib/util/layout.js +47 -1
- package/lib/util/layout.js.map +1 -1
- package/lib/util/point.js +5 -1
- package/lib/util/point.js.map +1 -1
- package/lib/util/shape.d.ts +1 -1
- package/lib/util/shape.js +3 -7
- package/lib/util/shape.js.map +1 -1
- package/lib/util/warn.d.ts +14 -0
- package/lib/util/warn.js +8 -0
- package/lib/util/warn.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/item/combo.ts +14 -9
- package/src/item/edge.ts +121 -55
- package/src/item/item.ts +13 -9
- package/src/item/node.ts +20 -15
- package/src/runtime/controller/data.ts +139 -339
- package/src/runtime/controller/item.ts +30 -12
- package/src/runtime/graph.ts +502 -67
- package/src/stdlib/behavior/brush-select.ts +4 -2
- package/src/stdlib/behavior/create-edge.ts +296 -0
- package/src/stdlib/behavior/drag-canvas.ts +30 -19
- package/src/stdlib/behavior/drag-combo.ts +2 -2
- package/src/stdlib/behavior/drag-node.ts +8 -8
- package/src/stdlib/behavior/index.ts +2 -0
- package/src/stdlib/behavior/lasso-select.ts +5 -3
- package/src/stdlib/behavior/scroll-canvas.ts +348 -0
- package/src/stdlib/behavior/zoom-canvas.ts +34 -23
- package/src/stdlib/data/mapNodeSize.ts +2 -2
- package/src/stdlib/data/transformV4Data.ts +2 -2
- package/src/stdlib/data/validateData.ts +9 -9
- package/src/stdlib/index.ts +6 -0
- package/src/stdlib/item/edge/base.ts +4 -8
- package/src/stdlib/plugin/hull/hullComponent.ts +8 -5
- package/src/stdlib/plugin/minimap/index.ts +120 -10
- package/src/stdlib/plugin/snapline/index.ts +36 -16
- package/src/types/graph.ts +37 -8
- package/src/types/hook.ts +16 -2
- package/src/types/spec.ts +9 -3
- package/src/types/view.ts +8 -3
- package/src/util/event.ts +14 -1
- package/src/util/item.ts +65 -28
- package/src/util/layout.ts +45 -0
- package/src/util/point.ts +4 -2
- package/src/util/shape.ts +6 -7
- package/src/util/warn.ts +20 -0
|
@@ -345,8 +345,10 @@ export class BrushSelect extends Behavior {
|
|
|
345
345
|
const { graph, options } = this;
|
|
346
346
|
const { brushStyle } = options;
|
|
347
347
|
const brush = graph.drawTransient('rect', BRUSH_SHAPE_ID, {
|
|
348
|
-
style:
|
|
349
|
-
|
|
348
|
+
style: {
|
|
349
|
+
...brushStyle,
|
|
350
|
+
pointerEvents: 'none',
|
|
351
|
+
},
|
|
350
352
|
});
|
|
351
353
|
return brush;
|
|
352
354
|
}
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import type { IG6GraphEvent } from '../../types';
|
|
2
|
+
import { warn } from '../../util/warn';
|
|
3
|
+
import { generateEdgeID } from '../../util/item';
|
|
4
|
+
import { Behavior } from '../../types/behavior';
|
|
5
|
+
import { EdgeDisplayModelData } from '../../types/edge';
|
|
6
|
+
|
|
7
|
+
const KEYBOARD_TRIGGERS = ['shift', 'ctrl', 'control', 'alt', 'meta'] as const;
|
|
8
|
+
const EVENT_TRIGGERS = ['click', 'drag'] as const;
|
|
9
|
+
|
|
10
|
+
const VIRTUAL_EDGE_ID = 'g6-create-edge-virtual-edge';
|
|
11
|
+
const DUMMY_NODE_ID = 'g6-create-edge-dummy-node';
|
|
12
|
+
|
|
13
|
+
// type Trigger = (typeof EVENT_TRIGGERS)[number];
|
|
14
|
+
|
|
15
|
+
interface CreateEdgeOptions {
|
|
16
|
+
/**
|
|
17
|
+
* The triggering conditions for this interaction can be either 'click' or 'drag'.
|
|
18
|
+
* Default to `click`.
|
|
19
|
+
*/
|
|
20
|
+
trigger: (typeof EVENT_TRIGGERS)[number];
|
|
21
|
+
/**
|
|
22
|
+
* The assistant secondary key on keyboard. If it is not assigned, the behavior will be triggered when trigger happens.
|
|
23
|
+
* cound be 'shift', 'ctrl', 'control', 'alt', 'meta', undefined.
|
|
24
|
+
*/
|
|
25
|
+
secondaryKey?: (typeof KEYBOARD_TRIGGERS)[number];
|
|
26
|
+
/**
|
|
27
|
+
* Config of the created edge.
|
|
28
|
+
*/
|
|
29
|
+
edgeConfig: EdgeDisplayModelData;
|
|
30
|
+
/**
|
|
31
|
+
* The event name to trigger after creating the virtual edge.
|
|
32
|
+
*/
|
|
33
|
+
createVirtualEventName?: string;
|
|
34
|
+
/**
|
|
35
|
+
* The event name to trigger after creating the actual edge.
|
|
36
|
+
*/
|
|
37
|
+
createActualEventName?: string;
|
|
38
|
+
/**
|
|
39
|
+
* The event name to trigger after canceling the behavior.
|
|
40
|
+
*/
|
|
41
|
+
cancelCreateEventName?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Whether allow the behavior happen on the current item.
|
|
44
|
+
*/
|
|
45
|
+
shouldBegin: (event: IG6GraphEvent) => boolean;
|
|
46
|
+
/**
|
|
47
|
+
*
|
|
48
|
+
* Whether it is allowed to end the creation of edges under the current conditions being operated.
|
|
49
|
+
*/
|
|
50
|
+
shouldEnd: (event: IG6GraphEvent) => boolean;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const DEFAULT_OPTIONS: CreateEdgeOptions = {
|
|
54
|
+
trigger: 'click',
|
|
55
|
+
secondaryKey: undefined,
|
|
56
|
+
shouldBegin: () => true,
|
|
57
|
+
shouldEnd: () => false,
|
|
58
|
+
edgeConfig: {},
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export class CreateEdge extends Behavior {
|
|
62
|
+
isKeyDown = false;
|
|
63
|
+
addingEdge = null;
|
|
64
|
+
dummyNode = null;
|
|
65
|
+
|
|
66
|
+
constructor(options: Partial<CreateEdgeOptions>) {
|
|
67
|
+
super(Object.assign({}, DEFAULT_OPTIONS, options));
|
|
68
|
+
this.validateOptions(options);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
validateOptions(options: Partial<CreateEdgeOptions>) {
|
|
72
|
+
if (options.trigger && !EVENT_TRIGGERS.includes(options.trigger)) {
|
|
73
|
+
warn({
|
|
74
|
+
optionName: `create-edge.trigger`,
|
|
75
|
+
shouldBe: EVENT_TRIGGERS,
|
|
76
|
+
now: options.trigger,
|
|
77
|
+
scope: 'behavior',
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
this.options.trigger = DEFAULT_OPTIONS.trigger;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (
|
|
84
|
+
options.secondaryKey &&
|
|
85
|
+
!KEYBOARD_TRIGGERS.includes(options.secondaryKey)
|
|
86
|
+
) {
|
|
87
|
+
warn({
|
|
88
|
+
optionName: `create-edge.secondaryKey`,
|
|
89
|
+
shouldBe: KEYBOARD_TRIGGERS,
|
|
90
|
+
now: options.secondaryKey,
|
|
91
|
+
scope: 'behavior',
|
|
92
|
+
});
|
|
93
|
+
this.options.secondaryKey = DEFAULT_OPTIONS.secondaryKey;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
getEvents = () => {
|
|
98
|
+
const { trigger, secondaryKey } = this.options;
|
|
99
|
+
const [CLICK_NAME] = EVENT_TRIGGERS;
|
|
100
|
+
|
|
101
|
+
const triggerEvents =
|
|
102
|
+
trigger === CLICK_NAME
|
|
103
|
+
? {
|
|
104
|
+
'node:click': this.handleCreateEdge,
|
|
105
|
+
pointermove: this.updateEndPoint,
|
|
106
|
+
'edge:click': this.cancelCreating,
|
|
107
|
+
'canvas:click': this.cancelCreating,
|
|
108
|
+
'combo:click': this.handleCreateEdge,
|
|
109
|
+
}
|
|
110
|
+
: {
|
|
111
|
+
'node:dragstart': this.handleCreateEdge,
|
|
112
|
+
'combo:dragstart': this.handleCreateEdge,
|
|
113
|
+
drag: this.updateEndPoint,
|
|
114
|
+
drop: this.onDrop,
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const keyboardEvents = secondaryKey
|
|
118
|
+
? {
|
|
119
|
+
keydown: this.onKeyDown,
|
|
120
|
+
keyup: this.onKeyUp,
|
|
121
|
+
}
|
|
122
|
+
: {};
|
|
123
|
+
|
|
124
|
+
return { ...triggerEvents, ...keyboardEvents } as Record<
|
|
125
|
+
string,
|
|
126
|
+
(e: IG6GraphEvent) => void
|
|
127
|
+
>;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
handleCreateEdge = (e: IG6GraphEvent) => {
|
|
131
|
+
if (this.options.secondaryKey && !this.isKeyDown) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (this.options.shouldEnd(e)) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const { graph, options, addingEdge } = this;
|
|
140
|
+
const currentNodeId = e.itemId;
|
|
141
|
+
|
|
142
|
+
const { edgeConfig, createVirtualEventName, createActualEventName } =
|
|
143
|
+
options;
|
|
144
|
+
|
|
145
|
+
if (addingEdge) {
|
|
146
|
+
// create edge end, add the actual edge to graph and remove the virtual edge and node
|
|
147
|
+
const actualEdge = graph.addData('edge', {
|
|
148
|
+
id: generateEdgeID(addingEdge.source, currentNodeId),
|
|
149
|
+
source: addingEdge.source,
|
|
150
|
+
target: currentNodeId,
|
|
151
|
+
data: {
|
|
152
|
+
...edgeConfig,
|
|
153
|
+
type:
|
|
154
|
+
currentNodeId === addingEdge.source ? 'loop-edge' : edgeConfig.type,
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
if (createActualEventName) {
|
|
158
|
+
graph.emit(createActualEventName, { edge: actualEdge });
|
|
159
|
+
}
|
|
160
|
+
this.cancelCreating();
|
|
161
|
+
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
this.dummyNode = graph.addData('node', {
|
|
166
|
+
id: DUMMY_NODE_ID,
|
|
167
|
+
data: {
|
|
168
|
+
x: e.canvas.x,
|
|
169
|
+
y: e.canvas.y,
|
|
170
|
+
keyShape: {
|
|
171
|
+
opacity: 0,
|
|
172
|
+
interactive: false,
|
|
173
|
+
},
|
|
174
|
+
labelShape: {
|
|
175
|
+
opacity: 0,
|
|
176
|
+
},
|
|
177
|
+
anchorPoints: [[0.5, 0.5]],
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
this.addingEdge = graph.addData('edge', {
|
|
181
|
+
id: VIRTUAL_EDGE_ID,
|
|
182
|
+
source: currentNodeId,
|
|
183
|
+
target: DUMMY_NODE_ID,
|
|
184
|
+
data: {
|
|
185
|
+
...edgeConfig,
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
if (createVirtualEventName) {
|
|
189
|
+
graph.emit(createVirtualEventName, { edge: this.addingEdge });
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
onDrop = async (e: IG6GraphEvent) => {
|
|
194
|
+
const { addingEdge, options, graph } = this;
|
|
195
|
+
|
|
196
|
+
const { edgeConfig, secondaryKey, createActualEventName } = options;
|
|
197
|
+
if (secondaryKey && !this.isKeyDown) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (!addingEdge) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const elements = await this.graph.canvas.document.elementsFromPoint(
|
|
206
|
+
e.canvas.x,
|
|
207
|
+
e.canvas.y,
|
|
208
|
+
);
|
|
209
|
+
const currentIds = elements
|
|
210
|
+
// @ts-ignore TODO: G type
|
|
211
|
+
.map((ele) => ele.parentNode.getAttribute?.('data-item-id'))
|
|
212
|
+
.filter((id) => id !== undefined && !DUMMY_NODE_ID !== id);
|
|
213
|
+
const dropId = currentIds.find(
|
|
214
|
+
(id) => this.graph.getComboData(id) || this.graph.getNodeData(id),
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
if (!dropId) {
|
|
218
|
+
this.cancelCreating();
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const actualEdge = graph.addData('edge', {
|
|
223
|
+
id: generateEdgeID(addingEdge.source, dropId),
|
|
224
|
+
source: addingEdge.source,
|
|
225
|
+
target: dropId,
|
|
226
|
+
data: {
|
|
227
|
+
...edgeConfig,
|
|
228
|
+
type: dropId === addingEdge.source ? 'loop-edge' : edgeConfig.type,
|
|
229
|
+
},
|
|
230
|
+
});
|
|
231
|
+
if (createActualEventName) {
|
|
232
|
+
graph.emit(createActualEventName, { edge: actualEdge });
|
|
233
|
+
}
|
|
234
|
+
this.cancelCreating();
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
updateEndPoint = (e: IG6GraphEvent) => {
|
|
238
|
+
const { options, graph, addingEdge, isKeyDown } = this;
|
|
239
|
+
if (options.secondaryKey && !isKeyDown) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (!addingEdge) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const sourceId = addingEdge.source,
|
|
248
|
+
targetId = addingEdge.target;
|
|
249
|
+
|
|
250
|
+
if (!graph.getItemById(sourceId)) {
|
|
251
|
+
this.addingEdge = null;
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
graph.updatePosition('node', {
|
|
256
|
+
id: targetId,
|
|
257
|
+
data: {
|
|
258
|
+
x: e.canvas.x,
|
|
259
|
+
y: e.canvas.y,
|
|
260
|
+
},
|
|
261
|
+
});
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
cancelCreating = () => {
|
|
265
|
+
if (this.addingEdge) {
|
|
266
|
+
this.graph.removeData('edge', VIRTUAL_EDGE_ID);
|
|
267
|
+
this.addingEdge = null;
|
|
268
|
+
}
|
|
269
|
+
if (this.dummyNode) {
|
|
270
|
+
this.graph.removeData('node', DUMMY_NODE_ID);
|
|
271
|
+
this.dummyNode = null;
|
|
272
|
+
}
|
|
273
|
+
if (this.options.cancelCreateEventName) {
|
|
274
|
+
this.graph.emit(this.options.cancelCreateEventName, {});
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
onKeyDown = (e: KeyboardEvent) => {
|
|
279
|
+
const code = e.key;
|
|
280
|
+
|
|
281
|
+
if (!code) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (code.toLocaleLowerCase() === this.options.secondaryKey) {
|
|
286
|
+
this.isKeyDown = true;
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
onKeyUp = (e: IG6GraphEvent) => {
|
|
291
|
+
if (this.addingEdge) {
|
|
292
|
+
this.cancelCreating();
|
|
293
|
+
}
|
|
294
|
+
this.isKeyDown = false;
|
|
295
|
+
};
|
|
296
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isNumber } from '@antv/util';
|
|
2
|
+
import { ID, IG6GraphEvent } from '../../types';
|
|
2
3
|
import { Behavior } from '../../types/behavior';
|
|
3
4
|
import { Point } from '../../types/common';
|
|
4
|
-
import { isNumber } from '@antv/util';
|
|
5
5
|
|
|
6
6
|
const VALID_TRIGGERS = ['drag', 'directionKeys'];
|
|
7
7
|
export interface DragCanvasOptions {
|
|
@@ -74,6 +74,7 @@ export class DragCanvas extends Behavior {
|
|
|
74
74
|
private disableKeydown: boolean;
|
|
75
75
|
private hiddenEdgeIds: ID[];
|
|
76
76
|
private hiddenNodeIds: ID[];
|
|
77
|
+
private tileRequestId?: number;
|
|
77
78
|
|
|
78
79
|
constructor(options: Partial<DragCanvasOptions>) {
|
|
79
80
|
const finalOptions = Object.assign({}, DEFAULT_OPTIONS, options);
|
|
@@ -136,7 +137,10 @@ export class DragCanvas extends Behavior {
|
|
|
136
137
|
|
|
137
138
|
const { tileBehavior: graphBehaviorOptimize, tileBehaviorSize = 1000 } =
|
|
138
139
|
graph.getSpecification().optimize || {};
|
|
139
|
-
const optimize =
|
|
140
|
+
const optimize =
|
|
141
|
+
this.options.enableOptimize !== undefined
|
|
142
|
+
? this.options.enableOptimize
|
|
143
|
+
: graphBehaviorOptimize;
|
|
140
144
|
const shouldOptimize = isNumber(optimize)
|
|
141
145
|
? graph.getAllNodesData().length > optimize
|
|
142
146
|
: optimize;
|
|
@@ -150,7 +154,6 @@ export class DragCanvas extends Behavior {
|
|
|
150
154
|
.getAllNodesData()
|
|
151
155
|
.map((node) => node.id)
|
|
152
156
|
.filter((id) => graph.getItemVisible(id) === true);
|
|
153
|
-
let requestId;
|
|
154
157
|
const hiddenIds = [...this.hiddenNodeIds];
|
|
155
158
|
const sectionNum = Math.ceil(hiddenIds.length / tileBehaviorSize);
|
|
156
159
|
const sections = Array.from({ length: sectionNum }, (v, i) =>
|
|
@@ -160,17 +163,18 @@ export class DragCanvas extends Behavior {
|
|
|
160
163
|
),
|
|
161
164
|
);
|
|
162
165
|
const update = () => {
|
|
163
|
-
if (!sections.length) {
|
|
164
|
-
cancelAnimationFrame(
|
|
166
|
+
if (!sections.length && this.tileRequestId) {
|
|
167
|
+
cancelAnimationFrame(this.tileRequestId);
|
|
168
|
+
this.tileRequestId = undefined;
|
|
165
169
|
return;
|
|
166
170
|
}
|
|
167
171
|
const section = sections.shift();
|
|
168
|
-
graph.
|
|
169
|
-
|
|
172
|
+
graph.executeWithNoStack(() => {
|
|
173
|
+
graph.hideItem(section, false, true);
|
|
174
|
+
});
|
|
175
|
+
this.tileRequestId = requestAnimationFrame(update);
|
|
170
176
|
};
|
|
171
|
-
|
|
172
|
-
requestId = requestAnimationFrame(update);
|
|
173
|
-
});
|
|
177
|
+
this.tileRequestId = requestAnimationFrame(update);
|
|
174
178
|
}
|
|
175
179
|
}
|
|
176
180
|
|
|
@@ -264,14 +268,20 @@ export class DragCanvas extends Behavior {
|
|
|
264
268
|
const { graph, hiddenNodeIds, hiddenEdgeIds = [] } = this;
|
|
265
269
|
const { tileBehavior: graphBehaviorOptimize, tileBehaviorSize = 1000 } =
|
|
266
270
|
graph.getSpecification().optimize || {};
|
|
267
|
-
const optimize =
|
|
271
|
+
const optimize =
|
|
272
|
+
this.options.enableOptimize !== undefined
|
|
273
|
+
? this.options.enableOptimize
|
|
274
|
+
: graphBehaviorOptimize;
|
|
268
275
|
const shouldOptimize = isNumber(optimize)
|
|
269
276
|
? graph.getAllNodesData().length > optimize
|
|
270
277
|
: optimize;
|
|
271
278
|
|
|
272
279
|
if (shouldOptimize) {
|
|
280
|
+
if (this.tileRequestId) {
|
|
281
|
+
cancelAnimationFrame(this.tileRequestId);
|
|
282
|
+
this.tileRequestId = undefined;
|
|
283
|
+
}
|
|
273
284
|
if (hiddenNodeIds) {
|
|
274
|
-
let requestId;
|
|
275
285
|
const hiddenIds = [...hiddenNodeIds, ...hiddenEdgeIds];
|
|
276
286
|
const sectionNum = Math.ceil(hiddenIds.length / tileBehaviorSize);
|
|
277
287
|
const sections = Array.from({ length: sectionNum }, (v, i) =>
|
|
@@ -281,16 +291,17 @@ export class DragCanvas extends Behavior {
|
|
|
281
291
|
),
|
|
282
292
|
);
|
|
283
293
|
const update = () => {
|
|
284
|
-
if (!sections.length) {
|
|
285
|
-
cancelAnimationFrame(
|
|
294
|
+
if (!sections.length && this.tileRequestId) {
|
|
295
|
+
cancelAnimationFrame(this.tileRequestId);
|
|
296
|
+
this.tileRequestId = undefined;
|
|
286
297
|
return;
|
|
287
298
|
}
|
|
299
|
+
graph.startHistoryBatch();
|
|
288
300
|
graph.showItem(sections.shift(), false);
|
|
289
|
-
|
|
301
|
+
graph.stopHistoryBatch();
|
|
302
|
+
this.tileRequestId = requestAnimationFrame(update);
|
|
290
303
|
};
|
|
291
|
-
|
|
292
|
-
requestId = requestAnimationFrame(update);
|
|
293
|
-
graph.stopHistoryBatch();
|
|
304
|
+
this.tileRequestId = requestAnimationFrame(update);
|
|
294
305
|
}
|
|
295
306
|
}
|
|
296
307
|
}
|
|
@@ -526,8 +526,8 @@ export class DragCombo extends Behavior {
|
|
|
526
526
|
this.originPositions = [];
|
|
527
527
|
}
|
|
528
528
|
|
|
529
|
-
public onDropNode(event: IG6GraphEvent) {
|
|
530
|
-
const elements = this.graph.canvas.document.
|
|
529
|
+
public async onDropNode(event: IG6GraphEvent) {
|
|
530
|
+
const elements = await this.graph.canvas.document.elementsFromPoint(
|
|
531
531
|
event.canvas.x,
|
|
532
532
|
event.canvas.y,
|
|
533
533
|
);
|
|
@@ -457,7 +457,7 @@ export class DragNode extends Behavior {
|
|
|
457
457
|
this.graph.drawTransient('rect', DELEGATE_SHAPE_ID, { action: 'remove' });
|
|
458
458
|
}
|
|
459
459
|
|
|
460
|
-
public clearTransientItems() {
|
|
460
|
+
public clearTransientItems(positions: Array<Position>) {
|
|
461
461
|
this.hiddenEdges.forEach((edge) => {
|
|
462
462
|
this.graph.drawTransient('node', edge.source, { action: 'remove' });
|
|
463
463
|
this.graph.drawTransient('node', edge.target, { action: 'remove' });
|
|
@@ -472,7 +472,7 @@ export class DragNode extends Behavior {
|
|
|
472
472
|
action: 'remove',
|
|
473
473
|
});
|
|
474
474
|
});
|
|
475
|
-
|
|
475
|
+
positions.forEach(({ id }) => {
|
|
476
476
|
this.graph.drawTransient('node', id, { action: 'remove' });
|
|
477
477
|
});
|
|
478
478
|
}
|
|
@@ -543,7 +543,7 @@ export class DragNode extends Behavior {
|
|
|
543
543
|
debounce((positions) => {
|
|
544
544
|
// restore the hidden items after move real nodes done
|
|
545
545
|
if (enableTransient) {
|
|
546
|
-
this.clearTransientItems();
|
|
546
|
+
this.clearTransientItems(positions);
|
|
547
547
|
}
|
|
548
548
|
|
|
549
549
|
if (this.options.enableDelegate) {
|
|
@@ -573,7 +573,7 @@ export class DragNode extends Behavior {
|
|
|
573
573
|
return;
|
|
574
574
|
}
|
|
575
575
|
this.clearDelegate();
|
|
576
|
-
this.clearTransientItems();
|
|
576
|
+
this.clearTransientItems(this.originPositions);
|
|
577
577
|
this.restoreHiddenItems();
|
|
578
578
|
|
|
579
579
|
const enableTransient =
|
|
@@ -589,8 +589,8 @@ export class DragNode extends Behavior {
|
|
|
589
589
|
this.clearState();
|
|
590
590
|
}
|
|
591
591
|
|
|
592
|
-
public onDropNode(event: IG6GraphEvent) {
|
|
593
|
-
const elements = this.graph.canvas.document.
|
|
592
|
+
public async onDropNode(event: IG6GraphEvent) {
|
|
593
|
+
const elements = await this.graph.canvas.document.elementsFromPoint(
|
|
594
594
|
event.canvas.x,
|
|
595
595
|
event.canvas.y,
|
|
596
596
|
);
|
|
@@ -640,8 +640,8 @@ export class DragNode extends Behavior {
|
|
|
640
640
|
this.graph.stopHistoryBatch();
|
|
641
641
|
}
|
|
642
642
|
|
|
643
|
-
public onDropCanvas(event: IG6GraphEvent) {
|
|
644
|
-
const elements = this.graph.canvas.document.
|
|
643
|
+
public async onDropCanvas(event: IG6GraphEvent) {
|
|
644
|
+
const elements = await this.graph.canvas.document.elementsFromPoint(
|
|
645
645
|
event.canvas.x,
|
|
646
646
|
event.canvas.y,
|
|
647
647
|
);
|
|
@@ -61,8 +61,10 @@ export class LassoSelect extends BrushSelect {
|
|
|
61
61
|
const { graph, options } = this;
|
|
62
62
|
const { brushStyle } = options;
|
|
63
63
|
return graph.drawTransient('path', LASSO_SHAPE_ID, {
|
|
64
|
-
style:
|
|
65
|
-
|
|
64
|
+
style: {
|
|
65
|
+
pointerEvents: 'none',
|
|
66
|
+
...brushStyle,
|
|
67
|
+
},
|
|
66
68
|
});
|
|
67
69
|
}
|
|
68
70
|
|
|
@@ -82,7 +84,7 @@ export class LassoSelect extends BrushSelect {
|
|
|
82
84
|
|
|
83
85
|
getLassoPath = () => {
|
|
84
86
|
const points: Point[] = this.points;
|
|
85
|
-
const path = [];
|
|
87
|
+
const path: any = [];
|
|
86
88
|
if (points.length) {
|
|
87
89
|
points.forEach((point, index) => {
|
|
88
90
|
if (index === 0) {
|