@antv/g6 5.0.0-beta.5 → 5.0.0-beta.6
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 +13 -1
- 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 +1 -1
- package/esm/item/edge.js +15 -7
- package/esm/item/edge.js.map +1 -1
- package/esm/item/node.d.ts +1 -1
- package/esm/item/node.js +16 -9
- package/esm/item/node.js.map +1 -1
- package/esm/runtime/controller/item.d.ts +1 -0
- package/esm/runtime/controller/item.js +19 -3
- package/esm/runtime/controller/item.js.map +1 -1
- package/esm/runtime/graph.d.ts +82 -4
- package/esm/runtime/graph.js +361 -47
- 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 +206 -0
- package/esm/stdlib/behavior/create-edge.js.map +1 -0
- package/esm/stdlib/behavior/drag-canvas.d.ts +1 -1
- package/esm/stdlib/behavior/drag-canvas.js +7 -7
- 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 +1 -1
- package/esm/stdlib/behavior/zoom-canvas.js +7 -7
- package/esm/stdlib/behavior/zoom-canvas.js.map +1 -1
- package/esm/stdlib/index.d.ts +4 -0
- package/esm/stdlib/index.js +5 -1
- package/esm/stdlib/index.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 +109 -8
- package/esm/stdlib/plugin/minimap/index.js.map +1 -1
- package/esm/types/graph.d.ts +31 -5
- package/esm/types/hook.d.ts +16 -2
- package/esm/types/spec.d.ts +6 -3
- 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/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 +13 -1
- 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 +1 -1
- package/lib/item/edge.js +15 -7
- package/lib/item/edge.js.map +1 -1
- package/lib/item/node.d.ts +1 -1
- package/lib/item/node.js +16 -9
- package/lib/item/node.js.map +1 -1
- package/lib/runtime/controller/item.d.ts +1 -0
- package/lib/runtime/controller/item.js +19 -3
- package/lib/runtime/controller/item.js.map +1 -1
- package/lib/runtime/graph.d.ts +82 -4
- package/lib/runtime/graph.js +361 -47
- 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 +210 -0
- package/lib/stdlib/behavior/create-edge.js.map +1 -0
- package/lib/stdlib/behavior/drag-canvas.d.ts +1 -1
- package/lib/stdlib/behavior/drag-canvas.js +7 -7
- 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 +1 -1
- package/lib/stdlib/behavior/zoom-canvas.js +7 -7
- package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
- package/lib/stdlib/index.d.ts +4 -0
- package/lib/stdlib/index.js +5 -1
- package/lib/stdlib/index.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 +109 -8
- package/lib/stdlib/plugin/minimap/index.js.map +1 -1
- package/lib/types/graph.d.ts +31 -5
- package/lib/types/hook.d.ts +16 -2
- package/lib/types/spec.d.ts +6 -3
- 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/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 +13 -7
- package/src/item/node.ts +14 -9
- package/src/runtime/controller/item.ts +28 -6
- package/src/runtime/graph.ts +445 -51
- package/src/stdlib/behavior/brush-select.ts +4 -2
- package/src/stdlib/behavior/create-edge.ts +295 -0
- package/src/stdlib/behavior/drag-canvas.ts +8 -8
- 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 +8 -8
- package/src/stdlib/index.ts +6 -0
- package/src/stdlib/plugin/hull/hullComponent.ts +8 -5
- package/src/stdlib/plugin/minimap/index.ts +113 -9
- package/src/types/graph.ts +31 -5
- package/src/types/hook.ts +16 -2
- package/src/types/spec.ts +9 -3
- package/src/util/item.ts +65 -28
- package/src/util/warn.ts +20 -0
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import { isBoolean, isNumber, isObject } from '@antv/util';
|
|
2
|
+
import { Behavior } from '../../types/behavior';
|
|
3
|
+
import { ID, IG6GraphEvent } from '../../types';
|
|
4
|
+
|
|
5
|
+
interface ScrollCanvasOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The direction of dragging that is allowed. Options: 'x', 'y', 'both'. 'both' by default.
|
|
8
|
+
*/
|
|
9
|
+
direction?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Whether enable optimize strategies, which will hide all the shapes excluding node keyShape while scrolling.
|
|
12
|
+
*/
|
|
13
|
+
enableOptimize?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* When the zoom ratio of the graph is smaller than ```optimizeZoom```, all shapes except for node keyShape will always be hidden.
|
|
16
|
+
* This option requires ```enableOptimize=true```;
|
|
17
|
+
*/
|
|
18
|
+
optimizeZoom?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Switch to zooming while pressing the key and wheeling. Options: 'shift', 'ctrl', 'alt', 'control', 'meta', using an array of these options allows any of these keys to trigger zooming;
|
|
21
|
+
* Use ```'ctrl'``` by default;
|
|
22
|
+
*/
|
|
23
|
+
zoomKey?: string | string[];
|
|
24
|
+
/** Switch to zooming while pressing the key and wheeling. This option allows you to control the zoom ratio for each event.
|
|
25
|
+
* Use ```'0.05'``` by default;
|
|
26
|
+
*/
|
|
27
|
+
zoomRatio?: number;
|
|
28
|
+
/**
|
|
29
|
+
* The range of canvas to limit dragging, 0 by default, which means the graph cannot be dragged totally out of the view port range.
|
|
30
|
+
* If scalableRange is number or a string without 'px', means it is a ratio of the graph content.
|
|
31
|
+
* If scalableRange is a string with 'px', it is regarded as pixels.
|
|
32
|
+
* If scalableRange = 0, no constrains;
|
|
33
|
+
* If scalableRange > 0, the graph can be dragged out of the view port range
|
|
34
|
+
* If scalableRange < 0, the range is smaller than the view port.
|
|
35
|
+
* Refer to https://gw.alipayobjects.com/mdn/rms_f8c6a0/afts/img/A*IFfoS67_HssAAAAAAAAAAAAAARQnAQ
|
|
36
|
+
*/
|
|
37
|
+
scalableRange?: string | number;
|
|
38
|
+
/**
|
|
39
|
+
* Whether allow trigger this behavior when drag start on nodes / edges / combos.
|
|
40
|
+
*/
|
|
41
|
+
allowDragOnItem?:
|
|
42
|
+
| boolean
|
|
43
|
+
| {
|
|
44
|
+
node?: boolean;
|
|
45
|
+
edge?: boolean;
|
|
46
|
+
combo?: boolean;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const DEFAULT_OPTIONS: ScrollCanvasOptions = {
|
|
51
|
+
direction: 'both',
|
|
52
|
+
enableOptimize: false,
|
|
53
|
+
zoomKey: 'ctrl',
|
|
54
|
+
scalableRange: 0,
|
|
55
|
+
allowDragOnItem: true,
|
|
56
|
+
zoomRatio: 0.05,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export class ScrollCanvas extends Behavior {
|
|
60
|
+
private hiddenEdgeIds: ID[];
|
|
61
|
+
private hiddenNodeIds: ID[];
|
|
62
|
+
|
|
63
|
+
declare options: ScrollCanvasOptions;
|
|
64
|
+
timeout?: number;
|
|
65
|
+
optimized = false;
|
|
66
|
+
constructor(options: Partial<ScrollCanvasOptions>) {
|
|
67
|
+
const finalOptions = Object.assign({}, DEFAULT_OPTIONS, options, {
|
|
68
|
+
zoomKey: initZoomKey(options.zoomKey),
|
|
69
|
+
});
|
|
70
|
+
super(finalOptions);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
getEvents = () => {
|
|
74
|
+
return {
|
|
75
|
+
wheel: this.onWheel,
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
onWheel(ev: IG6GraphEvent & { deltaX?: number; deltaY?: number }) {
|
|
80
|
+
if (!this.allowDrag(ev)) return;
|
|
81
|
+
const graph = this.graph;
|
|
82
|
+
const { zoomKey, zoomRatio, enableOptimize } = this.options;
|
|
83
|
+
const zoomKeys = Array.isArray(zoomKey) ? [].concat(zoomKey) : [zoomKey];
|
|
84
|
+
if (zoomKeys.includes('control')) zoomKeys.push('ctrl');
|
|
85
|
+
const keyDown = zoomKeys.some((ele) => ev[`${ele}Key`]);
|
|
86
|
+
|
|
87
|
+
const nativeEvent = ev.nativeEvent as
|
|
88
|
+
| (WheelEvent & { wheelDelta: number })
|
|
89
|
+
| undefined;
|
|
90
|
+
|
|
91
|
+
if (keyDown) {
|
|
92
|
+
const canvas = graph.canvas;
|
|
93
|
+
const point = canvas.client2Viewport({ x: ev.client.x, y: ev.client.y });
|
|
94
|
+
let ratio = graph.getZoom();
|
|
95
|
+
if (nativeEvent && nativeEvent.wheelDelta > 0) {
|
|
96
|
+
ratio = ratio + ratio * zoomRatio;
|
|
97
|
+
} else {
|
|
98
|
+
ratio = ratio - ratio * zoomRatio;
|
|
99
|
+
}
|
|
100
|
+
graph.zoomTo(ratio, {
|
|
101
|
+
x: point.x,
|
|
102
|
+
y: point.y,
|
|
103
|
+
});
|
|
104
|
+
} else {
|
|
105
|
+
const diffX = ev.deltaX || ev.movement.x;
|
|
106
|
+
const diffY = ev.deltaY || ev.movement.y;
|
|
107
|
+
|
|
108
|
+
const { dx, dy } = this.formatDisplacement(diffX, diffY);
|
|
109
|
+
graph.translate({ dx: -dx, dy: -dy });
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (enableOptimize) {
|
|
113
|
+
const optimized = this.optimized;
|
|
114
|
+
|
|
115
|
+
// hiding
|
|
116
|
+
if (!optimized) {
|
|
117
|
+
this.hideShapes();
|
|
118
|
+
this.optimized = true;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// showing after 100ms
|
|
122
|
+
clearTimeout(this.timeout);
|
|
123
|
+
this.timeout = undefined;
|
|
124
|
+
const timeout = window.setTimeout(() => {
|
|
125
|
+
this.showShapes();
|
|
126
|
+
this.optimized = false;
|
|
127
|
+
}, 100);
|
|
128
|
+
this.timeout = timeout;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
private formatDisplacement(dx: number, dy: number) {
|
|
132
|
+
const { graph } = this;
|
|
133
|
+
const { scalableRange, direction } = this.options;
|
|
134
|
+
const [width, height] = graph.getSize();
|
|
135
|
+
const graphBBox = graph.canvas.getRoot().getRenderBounds();
|
|
136
|
+
let rangeNum = Number(scalableRange);
|
|
137
|
+
let isPixel;
|
|
138
|
+
if (typeof scalableRange === 'string') {
|
|
139
|
+
if (scalableRange.includes('px')) {
|
|
140
|
+
isPixel = scalableRange.includes('px');
|
|
141
|
+
rangeNum = Number(scalableRange.replace('px', ''));
|
|
142
|
+
}
|
|
143
|
+
if (scalableRange.includes('%')) {
|
|
144
|
+
rangeNum = Number(scalableRange.replace('%', '')) / 100;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
let expandWidth = rangeNum;
|
|
149
|
+
let expandHeight = rangeNum;
|
|
150
|
+
// If it is not a string with 'px', regard as ratio
|
|
151
|
+
if (!isPixel) {
|
|
152
|
+
expandWidth = width * rangeNum;
|
|
153
|
+
expandHeight = height * rangeNum;
|
|
154
|
+
}
|
|
155
|
+
const leftTopClient = graph.getViewportByCanvas({
|
|
156
|
+
x: graphBBox.min[0],
|
|
157
|
+
y: graphBBox.min[1],
|
|
158
|
+
});
|
|
159
|
+
const rightBottomClient = graph.getViewportByCanvas({
|
|
160
|
+
x: graphBBox.max[0],
|
|
161
|
+
y: graphBBox.max[1],
|
|
162
|
+
});
|
|
163
|
+
const minX = leftTopClient.x;
|
|
164
|
+
const minY = leftTopClient.y;
|
|
165
|
+
const maxX = rightBottomClient.x;
|
|
166
|
+
const maxY = rightBottomClient.y;
|
|
167
|
+
if (dx > 0) {
|
|
168
|
+
if (maxX < -expandWidth) {
|
|
169
|
+
dx = 0;
|
|
170
|
+
} else if (maxX - dx < -expandWidth) {
|
|
171
|
+
dx = maxX + expandWidth;
|
|
172
|
+
}
|
|
173
|
+
} else if (dx < 0) {
|
|
174
|
+
if (minX > width + expandWidth) {
|
|
175
|
+
dx = 0;
|
|
176
|
+
} else if (minX - dx > width + expandWidth) {
|
|
177
|
+
dx = minX - (width + expandWidth);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (dy > 0) {
|
|
182
|
+
if (maxY < -expandHeight) {
|
|
183
|
+
dy = 0;
|
|
184
|
+
} else if (maxY - dy < -expandHeight) {
|
|
185
|
+
dy = maxY + expandHeight;
|
|
186
|
+
}
|
|
187
|
+
} else if (dy < 0) {
|
|
188
|
+
if (minY > height + expandHeight) {
|
|
189
|
+
dy = 0;
|
|
190
|
+
} else if (minY - dy > height + expandHeight) {
|
|
191
|
+
dy = minY - (height + expandHeight);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (direction === 'x') {
|
|
196
|
+
dy = 0;
|
|
197
|
+
} else if (direction === 'y') {
|
|
198
|
+
dx = 0;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return { dx, dy };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
private allowDrag(evt: IG6GraphEvent) {
|
|
205
|
+
const { itemType } = evt;
|
|
206
|
+
const { allowDragOnItem } = this.options;
|
|
207
|
+
const targetIsCanvas = itemType === 'canvas';
|
|
208
|
+
if (isBoolean(allowDragOnItem) && !allowDragOnItem && !targetIsCanvas)
|
|
209
|
+
return false;
|
|
210
|
+
if (isObject(allowDragOnItem)) {
|
|
211
|
+
const { node, edge, combo } = allowDragOnItem;
|
|
212
|
+
if (!node && itemType === 'node') return false;
|
|
213
|
+
if (!edge && itemType === 'edge') return false;
|
|
214
|
+
if (!combo && itemType === 'combo') return false;
|
|
215
|
+
}
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
private hideShapes() {
|
|
220
|
+
const { graph, options } = this;
|
|
221
|
+
const { tileBehavior: graphBehaviorOptimize, tileBehaviorSize = 1000 } =
|
|
222
|
+
graph.getSpecification().optimize || {};
|
|
223
|
+
const { optimizeZoom } = options;
|
|
224
|
+
const optimize = this.options.enableOptimize || graphBehaviorOptimize;
|
|
225
|
+
const shouldOptimzie = isNumber(optimize)
|
|
226
|
+
? graph.getAllNodesData().length > optimize
|
|
227
|
+
: optimize;
|
|
228
|
+
if (shouldOptimzie) {
|
|
229
|
+
const currentZoom = graph.getZoom();
|
|
230
|
+
const newHiddenEdgeIds = graph
|
|
231
|
+
.getAllEdgesData()
|
|
232
|
+
.map((edge) => edge.id)
|
|
233
|
+
.filter((id) => graph.getItemVisible(id));
|
|
234
|
+
graph.hideItem(newHiddenEdgeIds, true);
|
|
235
|
+
|
|
236
|
+
if (currentZoom < optimizeZoom) {
|
|
237
|
+
this.hiddenEdgeIds.push(...newHiddenEdgeIds);
|
|
238
|
+
} else {
|
|
239
|
+
this.hiddenEdgeIds = newHiddenEdgeIds;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const newHiddenNodeIds = graph
|
|
243
|
+
.getAllNodesData()
|
|
244
|
+
.map((node) => node.id)
|
|
245
|
+
.filter((id) => graph.getItemVisible(id));
|
|
246
|
+
|
|
247
|
+
let requestId;
|
|
248
|
+
const sectionNum = Math.ceil(newHiddenNodeIds.length / tileBehaviorSize);
|
|
249
|
+
const sections = Array.from({ length: sectionNum }, (v, i) =>
|
|
250
|
+
newHiddenNodeIds.slice(
|
|
251
|
+
i * tileBehaviorSize,
|
|
252
|
+
i * tileBehaviorSize + tileBehaviorSize,
|
|
253
|
+
),
|
|
254
|
+
);
|
|
255
|
+
const update = () => {
|
|
256
|
+
if (!sections.length) {
|
|
257
|
+
cancelAnimationFrame(requestId);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
const section = sections.shift();
|
|
261
|
+
graph.startHistoryBatch();
|
|
262
|
+
graph.hideItem(section, false, true);
|
|
263
|
+
graph.stopHistoryBatch();
|
|
264
|
+
requestId = requestAnimationFrame(update);
|
|
265
|
+
};
|
|
266
|
+
requestId = requestAnimationFrame(update);
|
|
267
|
+
|
|
268
|
+
if (currentZoom < optimizeZoom) {
|
|
269
|
+
this.hiddenNodeIds.push(...newHiddenNodeIds);
|
|
270
|
+
} else {
|
|
271
|
+
this.hiddenNodeIds = newHiddenNodeIds;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
private showShapes() {
|
|
276
|
+
const { graph, hiddenEdgeIds, hiddenNodeIds } = this;
|
|
277
|
+
const currentZoom = graph.getZoom();
|
|
278
|
+
const { optimizeZoom } = this.options;
|
|
279
|
+
|
|
280
|
+
// hide the shapes when the zoom ratio is smaller than optimizeZoom
|
|
281
|
+
// hide the shapes when zoomming
|
|
282
|
+
if (currentZoom < optimizeZoom) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const { tileBehavior: graphBehaviorOptimize, tileBehaviorSize = 1000 } =
|
|
287
|
+
graph.getSpecification().optimize || {};
|
|
288
|
+
const optimize = this.options.enableOptimize || graphBehaviorOptimize;
|
|
289
|
+
const shouldOptimzie = isNumber(optimize)
|
|
290
|
+
? graph.getAllNodesData().length > optimize
|
|
291
|
+
: optimize;
|
|
292
|
+
if (!shouldOptimzie) {
|
|
293
|
+
this.hiddenEdgeIds = this.hiddenNodeIds = [];
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
let requestId;
|
|
298
|
+
const hiddenIds = [...hiddenNodeIds, ...hiddenEdgeIds];
|
|
299
|
+
const sectionNum = Math.ceil(hiddenIds.length / tileBehaviorSize);
|
|
300
|
+
const sections = Array.from({ length: sectionNum }, (v, i) =>
|
|
301
|
+
hiddenIds.slice(
|
|
302
|
+
i * tileBehaviorSize,
|
|
303
|
+
i * tileBehaviorSize + tileBehaviorSize,
|
|
304
|
+
),
|
|
305
|
+
);
|
|
306
|
+
const update = () => {
|
|
307
|
+
if (!sections.length) {
|
|
308
|
+
cancelAnimationFrame(requestId);
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
graph.executeWithNoStack(() => {
|
|
312
|
+
graph.showItem(sections.shift(), false);
|
|
313
|
+
});
|
|
314
|
+
requestId = requestAnimationFrame(update);
|
|
315
|
+
};
|
|
316
|
+
requestId = requestAnimationFrame(update);
|
|
317
|
+
|
|
318
|
+
this.hiddenEdgeIds = this.hiddenNodeIds = [];
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
const ALLOW_EVENTS = ['shift', 'ctrl', 'alt', 'control', 'meta'];
|
|
323
|
+
|
|
324
|
+
function initZoomKey(zoomKey?: string | string[]) {
|
|
325
|
+
const zoomKeys = zoomKey
|
|
326
|
+
? Array.isArray(zoomKey)
|
|
327
|
+
? zoomKey
|
|
328
|
+
: [zoomKey]
|
|
329
|
+
: [];
|
|
330
|
+
|
|
331
|
+
const validZoomKeys = zoomKeys.filter((zoomKey) => {
|
|
332
|
+
const keyIsValid = ALLOW_EVENTS.includes(zoomKey);
|
|
333
|
+
if (!keyIsValid)
|
|
334
|
+
console.warn(
|
|
335
|
+
`Invalid zoomKey: ${zoomKey}, please use a valid zoomKey: ${JSON.stringify(
|
|
336
|
+
ALLOW_EVENTS,
|
|
337
|
+
)}`,
|
|
338
|
+
);
|
|
339
|
+
|
|
340
|
+
return keyIsValid;
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
if (validZoomKeys.length === 0) {
|
|
344
|
+
validZoomKeys.push('ctrl');
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
return validZoomKeys;
|
|
348
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ID, IG6GraphEvent } from 'types';
|
|
2
|
-
import { Behavior } from '../../types/behavior';
|
|
3
1
|
import { isNumber } from '@antv/util';
|
|
2
|
+
import { ID, IG6GraphEvent } from '../../types';
|
|
3
|
+
import { Behavior } from '../../types/behavior';
|
|
4
4
|
|
|
5
5
|
const VALID_TRIGGERS = ['wheel', 'upDownKeys'];
|
|
6
6
|
export interface ZoomCanvasOptions {
|
|
@@ -146,12 +146,12 @@ export class ZoomCanvas extends Behavior {
|
|
|
146
146
|
return;
|
|
147
147
|
}
|
|
148
148
|
const section = sections.shift();
|
|
149
|
+
graph.startHistoryBatch();
|
|
149
150
|
graph.hideItem(section, false, true);
|
|
151
|
+
graph.stopHistoryBatch();
|
|
150
152
|
requestId = requestAnimationFrame(update);
|
|
151
153
|
};
|
|
152
|
-
graph.startHistoryBatch();
|
|
153
154
|
requestId = requestAnimationFrame(update);
|
|
154
|
-
graph.stopHistoryBatch();
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
157
|
|
|
@@ -180,12 +180,12 @@ export class ZoomCanvas extends Behavior {
|
|
|
180
180
|
cancelAnimationFrame(requestId);
|
|
181
181
|
return;
|
|
182
182
|
}
|
|
183
|
-
graph.
|
|
183
|
+
graph.executeWithNoStack(() => {
|
|
184
|
+
graph.showItem(sections.shift(), false);
|
|
185
|
+
});
|
|
184
186
|
requestId = requestAnimationFrame(update);
|
|
185
187
|
};
|
|
186
|
-
|
|
187
|
-
requestId = requestAnimationFrame(update);
|
|
188
|
-
});
|
|
188
|
+
requestId = requestAnimationFrame(update);
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
this.hiddenEdgeIds = [];
|
package/src/stdlib/index.ts
CHANGED
|
@@ -61,7 +61,9 @@ const {
|
|
|
61
61
|
DragNode,
|
|
62
62
|
DragCombo,
|
|
63
63
|
ClickSelect,
|
|
64
|
+
CreateEdge,
|
|
64
65
|
ShortcutsCall,
|
|
66
|
+
ScrollCanvas,
|
|
65
67
|
} = Behaviors;
|
|
66
68
|
const {
|
|
67
69
|
History,
|
|
@@ -121,9 +123,11 @@ const stdLib = {
|
|
|
121
123
|
'zoom-canvas': ZoomCanvas,
|
|
122
124
|
'drag-node': DragNode,
|
|
123
125
|
'drag-combo': DragCombo,
|
|
126
|
+
'create-edge': CreateEdge,
|
|
124
127
|
'collapse-expand-combo': CollapseExpandCombo,
|
|
125
128
|
'collapse-expand-tree': CollapseExpandTree,
|
|
126
129
|
'click-select': ClickSelect,
|
|
130
|
+
'scroll-canvas': ScrollCanvas,
|
|
127
131
|
},
|
|
128
132
|
plugins: {
|
|
129
133
|
history: History,
|
|
@@ -135,6 +139,7 @@ const stdLib = {
|
|
|
135
139
|
},
|
|
136
140
|
edges: {
|
|
137
141
|
'line-edge': LineEdge,
|
|
142
|
+
'loop-edge': LoopEdge,
|
|
138
143
|
},
|
|
139
144
|
combos: {
|
|
140
145
|
'circle-combo': CircleCombo,
|
|
@@ -269,6 +274,7 @@ const Extensions = {
|
|
|
269
274
|
CollapseExpandCombo,
|
|
270
275
|
DragNode,
|
|
271
276
|
DragCombo,
|
|
277
|
+
CreateEdge,
|
|
272
278
|
ShortcutsCall,
|
|
273
279
|
// plugins
|
|
274
280
|
BasePlugin,
|
|
@@ -51,7 +51,8 @@ interface HullComponentFullOptions extends HullComponentOptions {
|
|
|
51
51
|
export default class Hull {
|
|
52
52
|
graph: IGraph;
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
// TODO: PathArray is not exported by @antv/util 2.x but by 3.x. Correct the type String | PathArray after upgrading @antv/util
|
|
55
|
+
path: any;
|
|
55
56
|
|
|
56
57
|
members: (NodeModel | ComboModel)[];
|
|
57
58
|
|
|
@@ -172,9 +173,9 @@ export default class Hull {
|
|
|
172
173
|
const shape = this.graph.drawTransient('path', this.options.id, {
|
|
173
174
|
style: {
|
|
174
175
|
path: this.path,
|
|
176
|
+
pointerEvents: 'none',
|
|
175
177
|
...this.options.style,
|
|
176
178
|
},
|
|
177
|
-
capture: false,
|
|
178
179
|
});
|
|
179
180
|
const { labelShape } = this.options;
|
|
180
181
|
if (labelShape?.text) {
|
|
@@ -183,10 +184,10 @@ export default class Hull {
|
|
|
183
184
|
const formattedLabelStyle = this.getLabelStyle(labelShape, shapeBounds);
|
|
184
185
|
this.graph.drawTransient('text', `${this.options.id}-label`, {
|
|
185
186
|
style: {
|
|
187
|
+
pointerEvents: 'none',
|
|
186
188
|
...labelShapeStyle,
|
|
187
189
|
...formattedLabelStyle,
|
|
188
190
|
},
|
|
189
|
-
capture: false,
|
|
190
191
|
});
|
|
191
192
|
}
|
|
192
193
|
shape.toBack();
|
|
@@ -426,8 +427,10 @@ export default class Hull {
|
|
|
426
427
|
|
|
427
428
|
public updateStyle(style: ShapeStyle) {
|
|
428
429
|
this.graph.drawTransient('path', this.options.id, {
|
|
429
|
-
style
|
|
430
|
-
|
|
430
|
+
style: {
|
|
431
|
+
...style,
|
|
432
|
+
pointerEvents: 'none',
|
|
433
|
+
},
|
|
431
434
|
});
|
|
432
435
|
}
|
|
433
436
|
|
|
@@ -54,6 +54,8 @@ export class Minimap extends Base {
|
|
|
54
54
|
private dx: number;
|
|
55
55
|
/** Distance from left of minimap graph to the left of minimap container. */
|
|
56
56
|
private dy: number;
|
|
57
|
+
/** Cache the visibility while items' visibility changed. And apply them onto the minimap with debounce. */
|
|
58
|
+
private visibleCache: { [id: string]: boolean } = {};
|
|
57
59
|
|
|
58
60
|
constructor(options?: MiniMapConfig) {
|
|
59
61
|
super(options);
|
|
@@ -80,11 +82,11 @@ export class Minimap extends Base {
|
|
|
80
82
|
|
|
81
83
|
public getEvents() {
|
|
82
84
|
return {
|
|
83
|
-
afterupdateitem: this.handleUpdateCanvas,
|
|
84
85
|
afteritemstatechange: this.handleUpdateCanvas,
|
|
85
86
|
afterlayout: this.handleUpdateCanvas,
|
|
86
87
|
viewportchange: this.handleUpdateCanvas,
|
|
87
88
|
afteritemchange: this.handleUpdateCanvas,
|
|
89
|
+
afteritemvisibilitychange: this.handleVisibilityChange,
|
|
88
90
|
};
|
|
89
91
|
}
|
|
90
92
|
|
|
@@ -115,12 +117,12 @@ export class Minimap extends Base {
|
|
|
115
117
|
style='position:absolute;
|
|
116
118
|
left:0;
|
|
117
119
|
top:0;
|
|
118
|
-
box-sizing:border-box;
|
|
119
120
|
border: 2px solid #1980ff;
|
|
121
|
+
box-sizing:border-box;
|
|
120
122
|
background: rgba(0, 0, 255, 0.1);
|
|
121
123
|
cursor:move'
|
|
122
124
|
draggable=${isSafari || isFireFox ? false : true}
|
|
123
|
-
|
|
125
|
+
/>`);
|
|
124
126
|
|
|
125
127
|
// Last mouse x position
|
|
126
128
|
let x = 0;
|
|
@@ -128,11 +130,25 @@ export class Minimap extends Base {
|
|
|
128
130
|
let y = 0;
|
|
129
131
|
// Whether in dragging status
|
|
130
132
|
let dragging = false;
|
|
133
|
+
let resizing = false;
|
|
131
134
|
|
|
132
135
|
const dragstartevent = isSafari || isFireFox ? 'mousedown' : 'dragstart';
|
|
136
|
+
this.container.addEventListener('mousemove', (e) => {
|
|
137
|
+
const moveAtBorder = getMoveAtBorder(viewport, e);
|
|
138
|
+
if (moveAtBorder) {
|
|
139
|
+
this.container.style.cursor = cursorMap[moveAtBorder];
|
|
140
|
+
viewport.style.cursor = cursorMap[moveAtBorder];
|
|
141
|
+
} else {
|
|
142
|
+
this.container.style.cursor = 'unset';
|
|
143
|
+
viewport.style.cursor = 'move';
|
|
144
|
+
}
|
|
145
|
+
});
|
|
133
146
|
viewport.addEventListener(
|
|
134
147
|
dragstartevent,
|
|
135
148
|
((e: IG6GraphEvent) => {
|
|
149
|
+
resizing = getMoveAtBorder(viewport, e);
|
|
150
|
+
if (resizing) return;
|
|
151
|
+
|
|
136
152
|
if ((e as any).dataTransfer) {
|
|
137
153
|
const img = new Image();
|
|
138
154
|
img.src =
|
|
@@ -159,6 +175,30 @@ export class Minimap extends Base {
|
|
|
159
175
|
);
|
|
160
176
|
|
|
161
177
|
const dragListener = (e: IG6GraphEvent) => {
|
|
178
|
+
const { style } = viewport;
|
|
179
|
+
const left = parseInt(style.left, 10);
|
|
180
|
+
const top = parseInt(style.top, 10);
|
|
181
|
+
const width = parseInt(style.width, 10);
|
|
182
|
+
const height = parseInt(style.height, 10);
|
|
183
|
+
|
|
184
|
+
if (resizing) {
|
|
185
|
+
const { clientX, clientY } = e;
|
|
186
|
+
const afterResize = { left, top, width, height };
|
|
187
|
+
if (resizing.includes('left')) {
|
|
188
|
+
afterResize.left = `${clientX}px`;
|
|
189
|
+
afterResize.width = `${left + width - clientX}px`;
|
|
190
|
+
} else if (resizing.includes('right')) {
|
|
191
|
+
afterResize.width = `${clientX - left}px`;
|
|
192
|
+
}
|
|
193
|
+
if (resizing.includes('top')) {
|
|
194
|
+
afterResize.top = `${clientY}`;
|
|
195
|
+
afterResize.height = `${top + height - clientY}`;
|
|
196
|
+
} else if (resizing.includes('bottom')) {
|
|
197
|
+
afterResize.height = `${clientY - top}`;
|
|
198
|
+
}
|
|
199
|
+
modifyCSS(viewport, afterResize);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
162
202
|
if (!dragging || isNil(e.clientX) || isNil(e.clientY)) {
|
|
163
203
|
return;
|
|
164
204
|
}
|
|
@@ -168,12 +208,6 @@ export class Minimap extends Base {
|
|
|
168
208
|
let dx = x - e.clientX;
|
|
169
209
|
let dy = y - e.clientY;
|
|
170
210
|
|
|
171
|
-
const { style } = viewport;
|
|
172
|
-
const left = parseInt(style.left, 10);
|
|
173
|
-
const top = parseInt(style.top, 10);
|
|
174
|
-
const width = parseInt(style.width, 10);
|
|
175
|
-
const height = parseInt(style.height, 10);
|
|
176
|
-
|
|
177
211
|
// If the viewport is already on the left or right, stop moving x.
|
|
178
212
|
if (left - dx < 0 || left - dx + width >= size[0]) {
|
|
179
213
|
dx = 0;
|
|
@@ -201,6 +235,7 @@ export class Minimap extends Base {
|
|
|
201
235
|
|
|
202
236
|
const dragendListener = () => {
|
|
203
237
|
dragging = false;
|
|
238
|
+
resizing = false;
|
|
204
239
|
this.options.refresh = true;
|
|
205
240
|
};
|
|
206
241
|
const dragendevent = isSafari || isFireFox ? 'mouseup' : 'dragend';
|
|
@@ -549,6 +584,34 @@ export class Minimap extends Base {
|
|
|
549
584
|
false,
|
|
550
585
|
);
|
|
551
586
|
|
|
587
|
+
private handleVisibilityChange = (params) => {
|
|
588
|
+
const { ids, value } = params;
|
|
589
|
+
ids.forEach((id) => {
|
|
590
|
+
this.visibleCache[id] = value;
|
|
591
|
+
});
|
|
592
|
+
this.debounceCloneVisibility();
|
|
593
|
+
};
|
|
594
|
+
|
|
595
|
+
private debounceCloneVisibility = debounce(
|
|
596
|
+
() => {
|
|
597
|
+
const nodeGroup = this.canvas.getRoot().getElementById('node-group');
|
|
598
|
+
const edgeGroup = this.canvas.getRoot().getElementById('edge-group');
|
|
599
|
+
nodeGroup.childNodes.concat(edgeGroup.childNodes).forEach((child) => {
|
|
600
|
+
const id = child.getAttribute?.('data-item-id');
|
|
601
|
+
if (this.visibleCache.hasOwnProperty(id)) {
|
|
602
|
+
if (this.visibleCache[id]) {
|
|
603
|
+
child.childNodes.forEach((shape) => shape.show());
|
|
604
|
+
} else if (this.visibleCache[id] === false) {
|
|
605
|
+
child.childNodes.forEach((shape) => shape.hide());
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
});
|
|
609
|
+
this.visibleCache = {};
|
|
610
|
+
},
|
|
611
|
+
50,
|
|
612
|
+
false,
|
|
613
|
+
);
|
|
614
|
+
|
|
552
615
|
public init(graph: IGraph) {
|
|
553
616
|
super.init(graph);
|
|
554
617
|
const promise = this.initContainer();
|
|
@@ -696,3 +759,44 @@ export class Minimap extends Base {
|
|
|
696
759
|
if (container?.parentNode) container.parentNode.removeChild(container);
|
|
697
760
|
}
|
|
698
761
|
}
|
|
762
|
+
|
|
763
|
+
const getMoveAtBorder = (dom, evt) => {
|
|
764
|
+
const bounds = dom.getBoundingClientRect();
|
|
765
|
+
const { clientX, clientY } = evt;
|
|
766
|
+
if (Math.abs(clientX - bounds.x) < 4 && Math.abs(clientY - bounds.y) < 4) {
|
|
767
|
+
return 'left-top';
|
|
768
|
+
} else if (
|
|
769
|
+
Math.abs(clientX - bounds.x) < 4 &&
|
|
770
|
+
Math.abs(clientY - bounds.y - bounds.height) < 4
|
|
771
|
+
) {
|
|
772
|
+
return 'left-bottom';
|
|
773
|
+
} else if (
|
|
774
|
+
Math.abs(clientX - bounds.x - bounds.width) < 4 &&
|
|
775
|
+
Math.abs(clientY - bounds.y) < 4
|
|
776
|
+
) {
|
|
777
|
+
return 'right-top';
|
|
778
|
+
} else if (
|
|
779
|
+
Math.abs(clientX - bounds.x - bounds.width) < 4 &&
|
|
780
|
+
Math.abs(clientY - bounds.y - bounds.height) < 4
|
|
781
|
+
) {
|
|
782
|
+
return 'right-bottom';
|
|
783
|
+
} else if (Math.abs(clientX - bounds.x) < 4) {
|
|
784
|
+
return 'left';
|
|
785
|
+
} else if (Math.abs(clientY - bounds.y) < 4) {
|
|
786
|
+
return 'top';
|
|
787
|
+
} else if (Math.abs(clientY - bounds.y - bounds.height) < 4) {
|
|
788
|
+
return 'bottom';
|
|
789
|
+
}
|
|
790
|
+
return false;
|
|
791
|
+
};
|
|
792
|
+
|
|
793
|
+
const cursorMap = {
|
|
794
|
+
'left-top': 'nwse-resize',
|
|
795
|
+
'right-bottom': 'nwse-resize',
|
|
796
|
+
'right-top': 'nesw-resize',
|
|
797
|
+
'left-bottom': 'nesw-resize',
|
|
798
|
+
left: 'ew-resize',
|
|
799
|
+
right: 'ew-resize',
|
|
800
|
+
top: 'ns-resize',
|
|
801
|
+
bottom: 'ns-resize',
|
|
802
|
+
};
|