@antv/g6 5.0.0-beta.13 → 5.0.0-beta.15
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 +1 -6
- package/esm/api-doc/types.d.ts +1 -0
- package/esm/api-doc/types.js +1 -2
- package/esm/api-doc/types.js.map +1 -1
- package/esm/index.d.ts +1 -1
- package/esm/index.js +1 -1
- package/esm/item/combo.js +2 -5
- package/esm/item/combo.js.map +1 -1
- package/esm/item/edge.js +1 -1
- package/esm/item/edge.js.map +1 -1
- package/esm/item/node.d.ts +0 -7
- package/esm/item/node.js +0 -4
- package/esm/item/node.js.map +1 -1
- package/esm/runtime/controller/interaction.js +9 -4
- package/esm/runtime/controller/interaction.js.map +1 -1
- package/esm/runtime/controller/item.js +2 -1
- package/esm/runtime/controller/item.js.map +1 -1
- package/esm/runtime/controller/plugin.js.map +1 -1
- package/esm/runtime/graph.js +2 -2
- package/esm/runtime/graph.js.map +1 -1
- package/esm/stdlib/behavior/activate-relations.d.ts +1 -1
- package/esm/stdlib/behavior/brush-select.d.ts +9 -3
- package/esm/stdlib/behavior/brush-select.js +9 -10
- package/esm/stdlib/behavior/brush-select.js.map +1 -1
- package/esm/stdlib/behavior/click-select.d.ts +1 -1
- package/esm/stdlib/behavior/collapse-expand-combo.d.ts +1 -1
- package/esm/stdlib/behavior/collapse-expand-tree.d.ts +1 -1
- package/esm/stdlib/behavior/drag-canvas.js +10 -3
- package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
- package/esm/stdlib/behavior/drag-combo.d.ts +1 -1
- package/esm/stdlib/behavior/drag-node.d.ts +1 -1
- package/esm/stdlib/behavior/drag-node.js +4 -0
- package/esm/stdlib/behavior/drag-node.js.map +1 -1
- package/esm/stdlib/behavior/lasso-select.js +2 -2
- package/esm/stdlib/behavior/lasso-select.js.map +1 -1
- package/esm/stdlib/behavior/shortcuts-call.d.ts +1 -1
- package/esm/stdlib/behavior/zoom-canvas.js +11 -4
- package/esm/stdlib/behavior/zoom-canvas.js.map +1 -1
- package/esm/stdlib/item/edge/base.d.ts +2 -4
- package/esm/stdlib/item/edge/base.js +11 -18
- package/esm/stdlib/item/edge/base.js.map +1 -1
- package/esm/stdlib/item/node/base.d.ts +1 -5
- package/esm/stdlib/item/node/base.js +7 -32
- package/esm/stdlib/item/node/base.js.map +1 -1
- package/esm/stdlib/item/node/donut.d.ts +3 -3
- package/esm/stdlib/plugin/hull/hullComponent.d.ts +1 -1
- package/esm/stdlib/plugin/legend/index.d.ts +1 -1
- package/esm/stdlib/plugin/snapline/index.d.ts +2 -2
- package/esm/stdlib/plugin/snapline/index.js +239 -239
- package/esm/stdlib/plugin/snapline/index.js.map +1 -1
- package/esm/stdlib/plugin/timebar/index.d.ts +4 -4
- package/esm/stdlib/plugin/timebar/index.js +4 -4
- package/esm/stdlib/plugin/timebar/index.js.map +1 -1
- package/esm/stdlib/plugin/tooltip/index.d.ts +1 -1
- package/esm/stdlib/plugin/watermaker/index.d.ts +1 -1
- package/esm/types/animate.d.ts +2 -2
- package/esm/types/behavior.d.ts +1 -1
- package/esm/types/combo.d.ts +7 -7
- package/esm/types/common.d.ts +5 -5
- package/esm/types/data.d.ts +6 -6
- package/esm/types/edge.d.ts +9 -9
- package/esm/types/event.d.ts +1 -1
- package/esm/types/history.d.ts +2 -2
- package/esm/types/hook.d.ts +1 -1
- package/esm/types/item.d.ts +13 -13
- package/esm/types/layout.d.ts +6 -6
- package/esm/types/loop.d.ts +2 -2
- package/esm/types/node.d.ts +7 -7
- package/esm/types/render.d.ts +1 -1
- package/esm/types/spec.d.ts +3 -3
- package/esm/types/stdlib.d.ts +1 -1
- package/esm/types/theme.d.ts +8 -8
- package/esm/types/view.d.ts +2 -2
- package/esm/util/event.d.ts +2 -2
- package/esm/util/layout.d.ts +1 -1
- package/esm/util/loop.js +4 -0
- package/esm/util/loop.js.map +1 -1
- package/esm/util/shape.d.ts +0 -1
- package/esm/util/shape.js +0 -6
- package/esm/util/shape.js.map +1 -1
- package/esm/util/shape3d.js +1 -6
- package/esm/util/shape3d.js.map +1 -1
- package/esm/util/warn.d.ts +1 -1
- package/lib/api-doc/types.d.ts +1 -0
- package/lib/api-doc/types.js +2 -2
- package/lib/api-doc/types.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/item/combo.js +2 -5
- package/lib/item/combo.js.map +1 -1
- package/lib/item/edge.js +1 -1
- package/lib/item/edge.js.map +1 -1
- package/lib/item/node.d.ts +0 -7
- package/lib/item/node.js +0 -4
- package/lib/item/node.js.map +1 -1
- package/lib/runtime/controller/interaction.js +9 -4
- package/lib/runtime/controller/interaction.js.map +1 -1
- package/lib/runtime/controller/item.js +2 -1
- package/lib/runtime/controller/item.js.map +1 -1
- package/lib/runtime/controller/plugin.js.map +1 -1
- package/lib/runtime/graph.js +2 -2
- package/lib/runtime/graph.js.map +1 -1
- package/lib/stdlib/behavior/activate-relations.d.ts +1 -1
- package/lib/stdlib/behavior/brush-select.d.ts +9 -3
- package/lib/stdlib/behavior/brush-select.js +12 -10
- package/lib/stdlib/behavior/brush-select.js.map +1 -1
- package/lib/stdlib/behavior/click-select.d.ts +1 -1
- package/lib/stdlib/behavior/collapse-expand-combo.d.ts +1 -1
- package/lib/stdlib/behavior/collapse-expand-tree.d.ts +1 -1
- package/lib/stdlib/behavior/drag-canvas.js +10 -3
- package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
- package/lib/stdlib/behavior/drag-combo.d.ts +1 -1
- package/lib/stdlib/behavior/drag-node.d.ts +1 -1
- package/lib/stdlib/behavior/drag-node.js +4 -0
- package/lib/stdlib/behavior/drag-node.js.map +1 -1
- package/lib/stdlib/behavior/lasso-select.js +5 -2
- package/lib/stdlib/behavior/lasso-select.js.map +1 -1
- package/lib/stdlib/behavior/shortcuts-call.d.ts +1 -1
- package/lib/stdlib/behavior/zoom-canvas.js +11 -4
- package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
- package/lib/stdlib/item/edge/base.d.ts +2 -4
- package/lib/stdlib/item/edge/base.js +9 -16
- package/lib/stdlib/item/edge/base.js.map +1 -1
- package/lib/stdlib/item/node/base.d.ts +1 -5
- package/lib/stdlib/item/node/base.js +6 -31
- package/lib/stdlib/item/node/base.js.map +1 -1
- package/lib/stdlib/item/node/donut.d.ts +3 -3
- package/lib/stdlib/plugin/hull/hullComponent.d.ts +1 -1
- package/lib/stdlib/plugin/legend/index.d.ts +1 -1
- package/lib/stdlib/plugin/snapline/index.d.ts +2 -2
- package/lib/stdlib/plugin/snapline/index.js +239 -239
- package/lib/stdlib/plugin/snapline/index.js.map +1 -1
- package/lib/stdlib/plugin/timebar/index.d.ts +4 -4
- package/lib/stdlib/plugin/timebar/index.js +4 -4
- package/lib/stdlib/plugin/timebar/index.js.map +1 -1
- package/lib/stdlib/plugin/tooltip/index.d.ts +1 -1
- package/lib/stdlib/plugin/watermaker/index.d.ts +1 -1
- package/lib/types/animate.d.ts +2 -2
- package/lib/types/behavior.d.ts +1 -1
- package/lib/types/combo.d.ts +7 -7
- package/lib/types/common.d.ts +5 -5
- package/lib/types/data.d.ts +6 -6
- package/lib/types/edge.d.ts +9 -9
- package/lib/types/event.d.ts +1 -1
- package/lib/types/event.js +2 -2
- package/lib/types/event.js.map +1 -1
- package/lib/types/history.d.ts +2 -2
- package/lib/types/history.js +1 -1
- package/lib/types/history.js.map +1 -1
- package/lib/types/hook.d.ts +1 -1
- package/lib/types/item.d.ts +13 -13
- package/lib/types/item.js +1 -1
- package/lib/types/item.js.map +1 -1
- package/lib/types/layout.d.ts +6 -6
- package/lib/types/loop.d.ts +2 -2
- package/lib/types/loop.js +1 -1
- package/lib/types/loop.js.map +1 -1
- package/lib/types/node.d.ts +7 -7
- package/lib/types/render.d.ts +1 -1
- package/lib/types/spec.d.ts +3 -3
- package/lib/types/stdlib.d.ts +1 -1
- package/lib/types/theme.d.ts +8 -8
- package/lib/types/view.d.ts +2 -2
- package/lib/util/event.d.ts +2 -2
- package/lib/util/layout.d.ts +1 -1
- package/lib/util/loop.js +4 -0
- package/lib/util/loop.js.map +1 -1
- package/lib/util/shape.d.ts +0 -1
- package/lib/util/shape.js +1 -7
- package/lib/util/shape.js.map +1 -1
- package/lib/util/shape3d.js +0 -5
- package/lib/util/shape3d.js.map +1 -1
- package/lib/util/warn.d.ts +1 -1
- package/package.json +32 -32
- package/src/api-doc/types.ts +1 -0
- package/src/index.ts +1 -1
- package/src/item/combo.ts +2 -6
- package/src/item/edge.ts +5 -1
- package/src/item/node.ts +0 -27
- package/src/runtime/controller/interaction.ts +10 -4
- package/src/runtime/controller/item.ts +1 -1
- package/src/runtime/controller/plugin.ts +1 -1
- package/src/runtime/graph.ts +2 -2
- package/src/stdlib/behavior/brush-select.ts +10 -11
- package/src/stdlib/behavior/drag-canvas.ts +13 -2
- package/src/stdlib/behavior/drag-node.ts +9 -0
- package/src/stdlib/behavior/lasso-select.ts +2 -2
- package/src/stdlib/behavior/zoom-canvas.ts +14 -3
- package/src/stdlib/item/edge/base.ts +11 -27
- package/src/stdlib/item/node/base.ts +10 -36
- package/src/util/loop.ts +4 -0
- package/src/util/shape.ts +0 -7
- package/src/util/shape3d.ts +1 -10
package/src/api-doc/types.ts
CHANGED
package/src/index.ts
CHANGED
package/src/item/combo.ts
CHANGED
|
@@ -202,9 +202,7 @@ export default class Combo extends Node {
|
|
|
202
202
|
);
|
|
203
203
|
break;
|
|
204
204
|
default: {
|
|
205
|
-
const bbox =
|
|
206
|
-
this.renderExt.boundsCache?.keyShapeLocal ||
|
|
207
|
-
keyShape.getLocalBounds();
|
|
205
|
+
const bbox = keyShape.getLocalBounds();
|
|
208
206
|
|
|
209
207
|
intersectPoint = getRectIntersectByPoint(
|
|
210
208
|
collapsed
|
|
@@ -227,9 +225,7 @@ export default class Combo extends Node {
|
|
|
227
225
|
|
|
228
226
|
let anchorPointsPositions = this.anchorPointsCache;
|
|
229
227
|
if (!anchorPointsPositions) {
|
|
230
|
-
const keyShapeBBox =
|
|
231
|
-
this.renderExt.boundsCache?.keyShapeLocal ||
|
|
232
|
-
this.shapeMap.keyShape.getLocalBounds();
|
|
228
|
+
const keyShapeBBox = this.shapeMap.keyShape.getLocalBounds();
|
|
233
229
|
const keyShapeWidth = keyShapeBBox.max[0] - keyShapeBBox.min[0];
|
|
234
230
|
const keyShapeHeight = keyShapeBBox.max[1] - keyShapeBBox.min[1];
|
|
235
231
|
anchorPointsPositions = anchorPoints.map((pointRatio) => {
|
package/src/item/edge.ts
CHANGED
|
@@ -94,7 +94,11 @@ export default class Edge extends Item {
|
|
|
94
94
|
);
|
|
95
95
|
|
|
96
96
|
// add shapes to group, and update shapeMap
|
|
97
|
-
this.shapeMap = updateShapes(
|
|
97
|
+
this.shapeMap = updateShapes(
|
|
98
|
+
this.shapeMap,
|
|
99
|
+
{ ...shapeMap, ...this.afterDrawShapeMap },
|
|
100
|
+
this.group,
|
|
101
|
+
);
|
|
98
102
|
|
|
99
103
|
// handle shape's and group's animate
|
|
100
104
|
const { animates, disableAnimate } = displayModel.data;
|
package/src/item/node.ts
CHANGED
|
@@ -114,32 +114,6 @@ export default class Node extends Item {
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
public update(
|
|
118
|
-
model: NodeModel,
|
|
119
|
-
diffData?: {
|
|
120
|
-
previous: NodeModelData | ComboModelData;
|
|
121
|
-
current: NodeModelData | ComboModelData;
|
|
122
|
-
},
|
|
123
|
-
isReplace?: boolean,
|
|
124
|
-
theme?: {
|
|
125
|
-
styles: NodeStyleSet;
|
|
126
|
-
lodStrategy: LodStrategyObj;
|
|
127
|
-
},
|
|
128
|
-
onlyMove?: boolean,
|
|
129
|
-
animate?: boolean,
|
|
130
|
-
onfinish?: Function,
|
|
131
|
-
) {
|
|
132
|
-
super.update(
|
|
133
|
-
model,
|
|
134
|
-
diffData,
|
|
135
|
-
isReplace,
|
|
136
|
-
theme,
|
|
137
|
-
onlyMove,
|
|
138
|
-
animate,
|
|
139
|
-
onfinish,
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
117
|
/**
|
|
144
118
|
* Update the node's position,
|
|
145
119
|
* do not update other styles which leads to better performance than updating position by updateData.
|
|
@@ -308,7 +282,6 @@ export default class Node extends Item {
|
|
|
308
282
|
intersectPoint = innerPoint;
|
|
309
283
|
break;
|
|
310
284
|
default: {
|
|
311
|
-
// boundsCache can be removed here since `getBounds` has already done.
|
|
312
285
|
intersectPoint = getRectIntersectByPoint(
|
|
313
286
|
{
|
|
314
287
|
x: keyShapeRenderBBox.min[0],
|
|
@@ -297,13 +297,17 @@ export class InteractionController {
|
|
|
297
297
|
} as FederatedPointerEvent);
|
|
298
298
|
}
|
|
299
299
|
|
|
300
|
+
const isRightClick = event.type === 'click' && event.button === 2;
|
|
301
|
+
|
|
300
302
|
// Canvas Events
|
|
301
303
|
if (event.itemType === 'canvas') {
|
|
302
304
|
if (event.type === 'pointermove') {
|
|
303
305
|
this.handlePointerMove(event);
|
|
304
306
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
+
if (!isRightClick) {
|
|
308
|
+
this.graph.emit(`canvas:${gEvent.type}`, event);
|
|
309
|
+
this.graph.emit(`${gEvent.type}`, event);
|
|
310
|
+
}
|
|
307
311
|
|
|
308
312
|
// contextmenu event for canvas
|
|
309
313
|
if (event.type === 'pointerdown' && event.button === 2) {
|
|
@@ -320,8 +324,10 @@ export class InteractionController {
|
|
|
320
324
|
if (event.type === 'pointermove' || event.type === 'pointerleave') {
|
|
321
325
|
this.handlePointerMove(event);
|
|
322
326
|
}
|
|
323
|
-
|
|
324
|
-
|
|
327
|
+
if (!isRightClick) {
|
|
328
|
+
this.graph.emit(`${itemType}:${gEvent.type}`, event);
|
|
329
|
+
this.graph.emit(`${gEvent.type}`, event);
|
|
330
|
+
}
|
|
325
331
|
|
|
326
332
|
// contextmenu event for node, edge, or combo
|
|
327
333
|
if (event.type === 'pointerdown' && event.button === 2) {
|
|
@@ -1044,7 +1044,7 @@ export class ItemController {
|
|
|
1044
1044
|
);
|
|
1045
1045
|
transientObjectMap.set(idStr, shape);
|
|
1046
1046
|
shape.style.pointerEvents = capture ? 'auto' : 'none';
|
|
1047
|
-
canvas.getRoot().appendChild(shape);
|
|
1047
|
+
if (shape.parentNode === null) canvas.getRoot().appendChild(shape);
|
|
1048
1048
|
}
|
|
1049
1049
|
public getTransient(id: string) {
|
|
1050
1050
|
return this.transientObjectMap.get(id);
|
package/src/runtime/graph.ts
CHANGED
|
@@ -241,7 +241,7 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
241
241
|
$domElement.style.outline = 'none';
|
|
242
242
|
$domElement.tabIndex = 1; // Enable keyboard events
|
|
243
243
|
// Transient canvas should let interactive events go through.
|
|
244
|
-
if (i
|
|
244
|
+
if (i !== 1) {
|
|
245
245
|
$domElement.style.pointerEvents = 'none';
|
|
246
246
|
}
|
|
247
247
|
}
|
|
@@ -1405,7 +1405,7 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1405
1405
|
const modelArr = isArray(models) ? models : [models];
|
|
1406
1406
|
const { graphCore } = this.dataController;
|
|
1407
1407
|
const { specification } = this.themeController;
|
|
1408
|
-
graphCore
|
|
1408
|
+
graphCore?.once('changed', (event) => {
|
|
1409
1409
|
if (!event.changes.length) return;
|
|
1410
1410
|
const changes = event.changes.filter(
|
|
1411
1411
|
(change) => !isEqual(change.newValue, change.oldValue),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DisplayObject } from '@antv/g';
|
|
2
2
|
import { ID } from '@antv/graphlib';
|
|
3
|
-
import
|
|
3
|
+
import rectSelector from '../selector/rect';
|
|
4
4
|
import { Behavior } from '../../types/behavior';
|
|
5
5
|
import { Point } from '../../types/common';
|
|
6
6
|
import { IG6GraphEvent } from '../../types/event';
|
|
@@ -125,6 +125,7 @@ export class BrushSelect extends Behavior {
|
|
|
125
125
|
pointerdown: this.onMouseDown,
|
|
126
126
|
pointermove: this.onMouseMove,
|
|
127
127
|
pointerup: this.onMouseUp,
|
|
128
|
+
'canvas:click': this.onCanvasClick,
|
|
128
129
|
};
|
|
129
130
|
};
|
|
130
131
|
|
|
@@ -140,6 +141,10 @@ export class BrushSelect extends Behavior {
|
|
|
140
141
|
return keyMap[trigger];
|
|
141
142
|
}
|
|
142
143
|
|
|
144
|
+
public onCanvasClick(event: IG6GraphEvent) {
|
|
145
|
+
this.clearStates();
|
|
146
|
+
}
|
|
147
|
+
|
|
143
148
|
public onMouseDown(event: IG6GraphEvent) {
|
|
144
149
|
if (!this.options.shouldBegin(event)) return;
|
|
145
150
|
const { itemId, itemType, canvas } = event;
|
|
@@ -151,11 +156,6 @@ export class BrushSelect extends Behavior {
|
|
|
151
156
|
y: canvas.y,
|
|
152
157
|
};
|
|
153
158
|
|
|
154
|
-
if (!this.isKeydown(event as any)) {
|
|
155
|
-
this.clearStates();
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
159
|
const { brush } = this;
|
|
160
160
|
if (!brush) {
|
|
161
161
|
this.brush = this.createBrush();
|
|
@@ -180,13 +180,12 @@ export class BrushSelect extends Behavior {
|
|
|
180
180
|
|
|
181
181
|
public onMouseUp(event: IG6GraphEvent) {
|
|
182
182
|
if (!this.mousedown) return;
|
|
183
|
-
if (!this.isKeydown(event as any)) {
|
|
184
|
-
this.clearStates();
|
|
185
|
-
}
|
|
186
183
|
|
|
187
184
|
this.removeBrush();
|
|
188
185
|
this.brush = undefined;
|
|
189
|
-
|
|
186
|
+
if (this.isKeydown(event as any)) {
|
|
187
|
+
this.selectedIds = this.selectItems(event);
|
|
188
|
+
}
|
|
190
189
|
this.dragging = false;
|
|
191
190
|
this.mousedown = false;
|
|
192
191
|
}
|
|
@@ -373,7 +372,7 @@ export class BrushSelect extends Behavior {
|
|
|
373
372
|
}
|
|
374
373
|
|
|
375
374
|
public getSelector() {
|
|
376
|
-
return
|
|
375
|
+
return rectSelector;
|
|
377
376
|
}
|
|
378
377
|
|
|
379
378
|
public getPoints(event: IG6GraphEvent) {
|
|
@@ -4,6 +4,7 @@ import { Point } from '../../types/common';
|
|
|
4
4
|
import { ID, IG6GraphEvent } from '../../types';
|
|
5
5
|
|
|
6
6
|
const VALID_TRIGGERS = ['drag', 'directionKeys'];
|
|
7
|
+
const DRAG_DURATION = 250;
|
|
7
8
|
export interface DragCanvasOptions {
|
|
8
9
|
/**
|
|
9
10
|
* Whether enable optimize strategies, which will hide all the shapes excluding node keyShape while dragging.
|
|
@@ -242,13 +243,22 @@ export class DragCanvas extends Behavior {
|
|
|
242
243
|
if (!this.dragging) {
|
|
243
244
|
this.hideShapes();
|
|
244
245
|
this.dragging = true;
|
|
246
|
+
this.graph.canvas.getConfig().disableHitTesting = false;
|
|
245
247
|
}
|
|
246
248
|
|
|
249
|
+
const { tileBehavior: graphBehaviorOptimize } =
|
|
250
|
+
this.graph.getSpecification().optimize || {};
|
|
251
|
+
|
|
252
|
+
const shouldDebounce =
|
|
253
|
+
typeof graphBehaviorOptimize === 'boolean'
|
|
254
|
+
? graphBehaviorOptimize
|
|
255
|
+
: this.graph.getAllNodesData().length < graphBehaviorOptimize;
|
|
256
|
+
|
|
247
257
|
const now = Date.now();
|
|
248
|
-
const MOUSE_ZOOM_DURATION = 250;
|
|
249
258
|
if (
|
|
259
|
+
shouldDebounce &&
|
|
250
260
|
this.lastDragTriggerTime &&
|
|
251
|
-
now - this.lastDragTriggerTime <
|
|
261
|
+
now - this.lastDragTriggerTime < DRAG_DURATION / 5
|
|
252
262
|
) {
|
|
253
263
|
return;
|
|
254
264
|
}
|
|
@@ -276,6 +286,7 @@ export class DragCanvas extends Behavior {
|
|
|
276
286
|
public onPointerUp() {
|
|
277
287
|
this.pointerDownAt = undefined;
|
|
278
288
|
this.dragging = false;
|
|
289
|
+
this.graph.canvas.getConfig().disableHitTesting = false;
|
|
279
290
|
|
|
280
291
|
const { graph, hiddenNodeIds, hiddenEdgeIds = [] } = this;
|
|
281
292
|
const { tileBehavior: graphBehaviorOptimize, tileBehaviorSize = 1000 } =
|
|
@@ -125,6 +125,7 @@ export class DragNode extends Behavior {
|
|
|
125
125
|
'node:pointerdown': this.onPointerDown,
|
|
126
126
|
pointermove: this.onPointerMove,
|
|
127
127
|
click: this.onClick,
|
|
128
|
+
'node:pointerup': this.onPointerUp,
|
|
128
129
|
// FIXME: IG6Event -> keyboard event
|
|
129
130
|
keydown: this.onKeydown as any,
|
|
130
131
|
};
|
|
@@ -198,6 +199,14 @@ export class DragNode extends Behavior {
|
|
|
198
199
|
if (!this.options.shouldBegin(event)) return;
|
|
199
200
|
this.pointerDown = { x: event.canvas.x, y: event.canvas.y };
|
|
200
201
|
this.dragging = false;
|
|
202
|
+
|
|
203
|
+
document.addEventListener(
|
|
204
|
+
'mouseup',
|
|
205
|
+
(evt) => {
|
|
206
|
+
this.onPointerUp(event);
|
|
207
|
+
},
|
|
208
|
+
{ once: true },
|
|
209
|
+
);
|
|
201
210
|
}
|
|
202
211
|
|
|
203
212
|
public onPointerMove(event: IG6GraphEvent) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DisplayObject } from '@antv/g';
|
|
2
2
|
import { ID } from '@antv/graphlib';
|
|
3
3
|
import { IG6GraphEvent } from '../../types/event';
|
|
4
|
-
import
|
|
4
|
+
import lassoSelector from '../selector/lasso';
|
|
5
5
|
import { Point } from '../../types/common';
|
|
6
6
|
import { IGraph } from '../../types';
|
|
7
7
|
import { BrushSelect } from './brush-select';
|
|
@@ -50,7 +50,7 @@ export class LassoSelect extends BrushSelect {
|
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
public getSelector() {
|
|
53
|
-
return
|
|
53
|
+
return lassoSelector;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
public getPoints() {
|
|
@@ -3,6 +3,7 @@ import { ID, IG6GraphEvent } from '../../types';
|
|
|
3
3
|
import { Behavior } from '../../types/behavior';
|
|
4
4
|
|
|
5
5
|
const VALID_TRIGGERS = ['wheel', 'upDownKeys'];
|
|
6
|
+
const WHEEL_DURATION = 250;
|
|
6
7
|
export interface ZoomCanvasOptions {
|
|
7
8
|
/**
|
|
8
9
|
* Whether enable optimize strategies, which will hide all the shapes excluding node keyShape while zooming.
|
|
@@ -59,7 +60,7 @@ export interface ZoomCanvasOptions {
|
|
|
59
60
|
const DEFAULT_OPTIONS: Required<ZoomCanvasOptions> = {
|
|
60
61
|
enableOptimize: undefined,
|
|
61
62
|
triggerOnItems: true,
|
|
62
|
-
sensitivity:
|
|
63
|
+
sensitivity: 6,
|
|
63
64
|
trigger: 'wheel',
|
|
64
65
|
secondaryKey: '',
|
|
65
66
|
speedUpKey: 'shift',
|
|
@@ -230,15 +231,24 @@ export class ZoomCanvas extends Behavior {
|
|
|
230
231
|
|
|
231
232
|
// begin zooming
|
|
232
233
|
if (!this.zooming) {
|
|
234
|
+
this.graph.canvas.getConfig().disableHitTesting = true;
|
|
233
235
|
this.hideShapes();
|
|
234
236
|
this.zooming = true;
|
|
235
237
|
}
|
|
236
238
|
|
|
239
|
+
const { tileBehavior: graphBehaviorOptimize } =
|
|
240
|
+
graph.getSpecification().optimize || {};
|
|
241
|
+
|
|
242
|
+
const shouldDebounce =
|
|
243
|
+
typeof graphBehaviorOptimize === 'boolean'
|
|
244
|
+
? graphBehaviorOptimize
|
|
245
|
+
: graph.getAllNodesData().length < graphBehaviorOptimize;
|
|
246
|
+
|
|
237
247
|
const now = Date.now();
|
|
238
|
-
const MOUSE_ZOOM_DURATION = 250;
|
|
239
248
|
if (
|
|
249
|
+
shouldDebounce &&
|
|
240
250
|
this.lastWheelTriggerTime &&
|
|
241
|
-
now - this.lastWheelTriggerTime <
|
|
251
|
+
now - this.lastWheelTriggerTime < WHEEL_DURATION / 5
|
|
242
252
|
) {
|
|
243
253
|
return;
|
|
244
254
|
}
|
|
@@ -257,6 +267,7 @@ export class ZoomCanvas extends Behavior {
|
|
|
257
267
|
clearTimeout(this.zoomTimer);
|
|
258
268
|
this.zoomTimer = setTimeout(() => {
|
|
259
269
|
this.endZoom();
|
|
270
|
+
this.graph.canvas.getConfig().disableHitTesting = false;
|
|
260
271
|
}, 300);
|
|
261
272
|
|
|
262
273
|
// Emit event.
|
|
@@ -21,12 +21,7 @@ import {
|
|
|
21
21
|
State,
|
|
22
22
|
LodStrategyObj,
|
|
23
23
|
} from '../../../types/item';
|
|
24
|
-
import {
|
|
25
|
-
LOCAL_BOUNDS_DIRTY_FLAG_KEY,
|
|
26
|
-
formatPadding,
|
|
27
|
-
mergeStyles,
|
|
28
|
-
upsertShape,
|
|
29
|
-
} from '../../../util/shape';
|
|
24
|
+
import { formatPadding, mergeStyles, upsertShape } from '../../../util/shape';
|
|
30
25
|
import { DEFAULT_ANIMATE_CFG, fadeIn, fadeOut } from '../../../util/animate';
|
|
31
26
|
import { getWordWrapWidthByEnds } from '../../../util/text';
|
|
32
27
|
import { AnimateCfg } from '../../../types/animate';
|
|
@@ -49,9 +44,7 @@ export abstract class BaseEdge {
|
|
|
49
44
|
transform: string;
|
|
50
45
|
isRevert: boolean;
|
|
51
46
|
};
|
|
52
|
-
|
|
53
|
-
labelShapeGeometry?: AABB;
|
|
54
|
-
labelBackgroundShapeGeometry?: AABB;
|
|
47
|
+
transformCache: {
|
|
55
48
|
labelShapeTransform?: string;
|
|
56
49
|
labelBackgroundShapeTransform?: string;
|
|
57
50
|
};
|
|
@@ -89,7 +82,7 @@ export abstract class BaseEdge {
|
|
|
89
82
|
const { themeStyles, lodStrategy, zoom } = props;
|
|
90
83
|
if (themeStyles) this.themeStyles = themeStyles;
|
|
91
84
|
this.lodStrategy = lodStrategy;
|
|
92
|
-
this.
|
|
85
|
+
this.transformCache = {};
|
|
93
86
|
this.zoomCache.zoom = zoom;
|
|
94
87
|
this.zoomCache.balanceRatio = 1 / zoom;
|
|
95
88
|
this.zoomCache.animateConfig = {
|
|
@@ -147,10 +140,8 @@ export abstract class BaseEdge {
|
|
|
147
140
|
public updateCache(shapeMap) {
|
|
148
141
|
['labelShape', 'labelBackgroundShape'].forEach((id) => {
|
|
149
142
|
const shape = shapeMap[id];
|
|
150
|
-
if (shape
|
|
151
|
-
this.
|
|
152
|
-
this.boundsCache[`${id}Transform`] = shape.style.transform;
|
|
153
|
-
shape.setAttribute(LOCAL_BOUNDS_DIRTY_FLAG_KEY, false);
|
|
143
|
+
if (shape) {
|
|
144
|
+
this.transformCache[`${id}Transform`] = shape.style.transform;
|
|
154
145
|
}
|
|
155
146
|
});
|
|
156
147
|
|
|
@@ -262,7 +253,7 @@ export abstract class BaseEdge {
|
|
|
262
253
|
offsetY: 0,
|
|
263
254
|
pointRatio: [0.5, 0.501],
|
|
264
255
|
};
|
|
265
|
-
if (
|
|
256
|
+
if (typeof position === 'number') {
|
|
266
257
|
positionPreset.pointRatio = [position, position + 0.01];
|
|
267
258
|
}
|
|
268
259
|
switch (position) {
|
|
@@ -341,7 +332,7 @@ export abstract class BaseEdge {
|
|
|
341
332
|
...positionStyle,
|
|
342
333
|
...otherStyle,
|
|
343
334
|
};
|
|
344
|
-
this.
|
|
335
|
+
this.transformCache.labelShapeTransform = style.transform;
|
|
345
336
|
return this.upsertShape('text', 'labelShape', style, shapeMap, model);
|
|
346
337
|
}
|
|
347
338
|
|
|
@@ -365,8 +356,7 @@ export abstract class BaseEdge {
|
|
|
365
356
|
const { labelBackgroundShape, labelShape: labelShapeStyle } =
|
|
366
357
|
this.mergedStyles;
|
|
367
358
|
|
|
368
|
-
const textBBox =
|
|
369
|
-
this.boundsCache.labelShapeGeometry || labelShape.getGeometryBounds();
|
|
359
|
+
const textBBox = labelShape.getGeometryBounds();
|
|
370
360
|
const { x, y, transform, isRevert } = this.labelPosition;
|
|
371
361
|
const { padding, ...backgroundStyle } = labelBackgroundShape;
|
|
372
362
|
const { balanceRatio = 1 } = this.zoomCache;
|
|
@@ -451,15 +441,9 @@ export abstract class BaseEdge {
|
|
|
451
441
|
shapeStyle.height = h;
|
|
452
442
|
}
|
|
453
443
|
|
|
454
|
-
if (labelShape) {
|
|
455
|
-
const referShape = labelBackgroundShape || labelShape;
|
|
456
|
-
}
|
|
457
444
|
if (labelShapeProps) {
|
|
458
445
|
const referShape = labelBackgroundShape || labelShape;
|
|
459
|
-
const referBounds =
|
|
460
|
-
this.boundsCache.labelBackgroundShapeGeometry ||
|
|
461
|
-
this.boundsCache.labelShapeGeometry ||
|
|
462
|
-
referShape.getGeometryBounds();
|
|
446
|
+
const referBounds = referShape.getGeometryBounds();
|
|
463
447
|
const {
|
|
464
448
|
min: referMin,
|
|
465
449
|
max: referMax,
|
|
@@ -632,7 +616,7 @@ export abstract class BaseEdge {
|
|
|
632
616
|
if (position === 'bottom') labelShape.style.transformOrigin = '0';
|
|
633
617
|
else labelShape.style.transformOrigin = '';
|
|
634
618
|
|
|
635
|
-
const oriTransform = this.
|
|
619
|
+
const oriTransform = this.transformCache.labelShapeTransform;
|
|
636
620
|
labelShape.style.transform = `${oriTransform} scale(${balanceRatio}, ${balanceRatio})`;
|
|
637
621
|
|
|
638
622
|
const wordWrapWidth = this.zoomCache.wordWrapWidth * zoom;
|
|
@@ -640,7 +624,7 @@ export abstract class BaseEdge {
|
|
|
640
624
|
|
|
641
625
|
if (!labelBackgroundShape) return;
|
|
642
626
|
|
|
643
|
-
const oriBgTransform = this.
|
|
627
|
+
const oriBgTransform = this.transformCache.labelBackgroundShapeTransform;
|
|
644
628
|
labelBackgroundShape.style.transform = `${oriBgTransform} scale(${balanceRatio}, ${balanceRatio})`;
|
|
645
629
|
}
|
|
646
630
|
|
|
@@ -23,7 +23,6 @@ import {
|
|
|
23
23
|
ComboShapeMap,
|
|
24
24
|
} from '../../../types/combo';
|
|
25
25
|
import {
|
|
26
|
-
LOCAL_BOUNDS_DIRTY_FLAG_KEY,
|
|
27
26
|
formatPadding,
|
|
28
27
|
getShapeLocalBoundsByStyle,
|
|
29
28
|
mergeStyles,
|
|
@@ -42,10 +41,6 @@ export abstract class BaseNode {
|
|
|
42
41
|
mergedStyles: NodeShapeStyles | ComboShapeStyles;
|
|
43
42
|
lodStrategy?: LodStrategyObj;
|
|
44
43
|
enableBalanceShape?: boolean;
|
|
45
|
-
boundsCache: {
|
|
46
|
-
keyShapeLocal?: AABB;
|
|
47
|
-
labelShapeGeometry?: AABB;
|
|
48
|
-
};
|
|
49
44
|
//vertex coordinate
|
|
50
45
|
|
|
51
46
|
/**
|
|
@@ -89,7 +84,6 @@ export abstract class BaseNode {
|
|
|
89
84
|
if (themeStyles) this.themeStyles = themeStyles;
|
|
90
85
|
this.lodStrategy = lodStrategy;
|
|
91
86
|
this.enableBalanceShape = enableBalanceShape;
|
|
92
|
-
this.boundsCache = {};
|
|
93
87
|
this.zoomCache.zoom = zoom;
|
|
94
88
|
this.zoomCache.balanceRatio = 1 / zoom;
|
|
95
89
|
this.zoomCache.animateConfig = {
|
|
@@ -163,21 +157,6 @@ export abstract class BaseNode {
|
|
|
163
157
|
* @param shapeMap The shape map that contains all of the elements to show on the node.
|
|
164
158
|
*/
|
|
165
159
|
public updateCache(shapeMap) {
|
|
166
|
-
['keyShape', 'labelShape']
|
|
167
|
-
.concat(Object.keys(BadgePosition))
|
|
168
|
-
.map((pos) => `${pos}BadgeShape`)
|
|
169
|
-
.forEach((id) => {
|
|
170
|
-
const shape = shapeMap[id];
|
|
171
|
-
if (shape?.getAttribute(LOCAL_BOUNDS_DIRTY_FLAG_KEY)) {
|
|
172
|
-
if (id === 'labelShape') {
|
|
173
|
-
this.boundsCache[`${id}Geometry`] = shape.getGeometryBounds();
|
|
174
|
-
} else {
|
|
175
|
-
this.boundsCache[`${id}Local`] = shape.getLocalBounds();
|
|
176
|
-
}
|
|
177
|
-
shape.setAttribute(LOCAL_BOUNDS_DIRTY_FLAG_KEY, false);
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
|
|
181
160
|
const levelShapes = {};
|
|
182
161
|
Object.keys(shapeMap).forEach((shapeId) => {
|
|
183
162
|
const { lod } = shapeMap[shapeId].attributes;
|
|
@@ -394,15 +373,8 @@ export abstract class BaseNode {
|
|
|
394
373
|
): DisplayObject {
|
|
395
374
|
const { labelShape } = shapeMap;
|
|
396
375
|
if (!labelShape || !labelShape.style.text || !model.data.labelShape) return;
|
|
397
|
-
if (
|
|
398
|
-
!this.boundsCache.labelShapeGeometry ||
|
|
399
|
-
labelShape.getAttribute(LOCAL_BOUNDS_DIRTY_FLAG_KEY)
|
|
400
|
-
) {
|
|
401
|
-
this.boundsCache.labelShapeGeometry = labelShape.getGeometryBounds();
|
|
402
|
-
labelShape.setAttribute(LOCAL_BOUNDS_DIRTY_FLAG_KEY, false);
|
|
403
|
-
}
|
|
404
376
|
// label's local bounds, will take scale into acount
|
|
405
|
-
const
|
|
377
|
+
const textBBoxGeo = labelShape.getGeometryBounds();
|
|
406
378
|
const height = textBBoxGeo.max[1] - textBBoxGeo.min[1];
|
|
407
379
|
const width = Math.min(
|
|
408
380
|
textBBoxGeo.max[0] - textBBoxGeo.min[0] + 2,
|
|
@@ -549,13 +521,15 @@ export abstract class BaseNode {
|
|
|
549
521
|
(style) => style.tag === 'anchorShape',
|
|
550
522
|
);
|
|
551
523
|
if (!individualConfigs.length) return;
|
|
552
|
-
this.boundsCache.keyShapeLocal =
|
|
553
|
-
this.boundsCache.keyShapeLocal || shapeMap.keyShape.getLocalBounds();
|
|
554
524
|
const shapes = {};
|
|
555
525
|
const anchorPositionMap = this.calculateAnchorPosition(keyShapeStyle);
|
|
556
526
|
individualConfigs.forEach((config, i) => {
|
|
557
527
|
const { position, fill = keyShapeStyle.fill, ...style } = config;
|
|
558
|
-
const [cx, cy] = this.getAnchorPosition(
|
|
528
|
+
const [cx, cy] = this.getAnchorPosition(
|
|
529
|
+
position,
|
|
530
|
+
anchorPositionMap,
|
|
531
|
+
shapeMap,
|
|
532
|
+
);
|
|
559
533
|
const id = `anchorShape${i}`;
|
|
560
534
|
shapes[id] = this.upsertShape(
|
|
561
535
|
'circle',
|
|
@@ -577,8 +551,9 @@ export abstract class BaseNode {
|
|
|
577
551
|
private getAnchorPosition(
|
|
578
552
|
position: string | [number, number],
|
|
579
553
|
anchorPositionMap: IAnchorPositionMap,
|
|
554
|
+
shapeMap: NodeShapeMap | ComboShapeMap,
|
|
580
555
|
): [number, number] {
|
|
581
|
-
const keyShapeBBox =
|
|
556
|
+
const keyShapeBBox = shapeMap.keyShape.getLocalBounds();
|
|
582
557
|
const keyShapeWidth = keyShapeBBox.max[0] - keyShapeBBox.min[0];
|
|
583
558
|
const keyShapeHeight = keyShapeBBox.max[1] - keyShapeBBox.min[1];
|
|
584
559
|
const defaultPosition: [number, number] = [
|
|
@@ -750,8 +725,7 @@ export abstract class BaseNode {
|
|
|
750
725
|
shapeMap,
|
|
751
726
|
model,
|
|
752
727
|
);
|
|
753
|
-
|
|
754
|
-
const bbox = this.boundsCache[`${id}Local`];
|
|
728
|
+
const bbox = shapes[id].getLocalBounds();
|
|
755
729
|
|
|
756
730
|
const bgShapeId = `${position}BadgeBackgroundShape`;
|
|
757
731
|
const bgWidth =
|
|
@@ -966,7 +940,7 @@ export abstract class BaseNode {
|
|
|
966
940
|
} ${paddingTop + (height - paddingTop - paddingBottom) / 2}`;
|
|
967
941
|
}
|
|
968
942
|
|
|
969
|
-
const
|
|
943
|
+
const labelBBox = labelShape.getGeometryBounds();
|
|
970
944
|
const labelWidth = labelBBox.max[0] - labelBBox.min[0];
|
|
971
945
|
const xAxistRatio = (labelWidth * balanceRatio + sidePadding) / width;
|
|
972
946
|
|
package/src/util/loop.ts
CHANGED
|
@@ -69,6 +69,7 @@ export const calculatePointForOtherShapes = (
|
|
|
69
69
|
[center[0] - pointPadding, center[1] - halfOfHeight],
|
|
70
70
|
[center[0] + pointPadding, center[1] - halfOfHeight],
|
|
71
71
|
],
|
|
72
|
+
// @ts-ignore
|
|
72
73
|
[LOOP_POSITION['top-right']]: [
|
|
73
74
|
[center[0] + halfOfWidth - pointPadding, center[1] - halfOfHeight],
|
|
74
75
|
[center[0] + halfOfWidth, center[1] - halfOfHeight + pointPadding],
|
|
@@ -77,6 +78,7 @@ export const calculatePointForOtherShapes = (
|
|
|
77
78
|
[center[0] + halfOfWidth, center[1] - pointPadding],
|
|
78
79
|
[center[0] + halfOfWidth, center[1] + pointPadding],
|
|
79
80
|
],
|
|
81
|
+
// @ts-ignore
|
|
80
82
|
[LOOP_POSITION['bottom-right']]: [
|
|
81
83
|
[center[0] + halfOfWidth, center[1] + halfOfHeight - pointPadding],
|
|
82
84
|
[center[0] + halfOfWidth - pointPadding, center[1] + halfOfHeight],
|
|
@@ -85,6 +87,7 @@ export const calculatePointForOtherShapes = (
|
|
|
85
87
|
[center[0] + pointPadding, center[1] + halfOfHeight],
|
|
86
88
|
[center[0] - pointPadding, center[1] + halfOfHeight],
|
|
87
89
|
],
|
|
90
|
+
// @ts-ignore
|
|
88
91
|
[LOOP_POSITION['bottom-left']]: [
|
|
89
92
|
[center[0] - halfOfWidth + pointPadding, center[1] + halfOfHeight],
|
|
90
93
|
[center[0] - halfOfWidth, center[1] + halfOfHeight - pointPadding],
|
|
@@ -93,6 +96,7 @@ export const calculatePointForOtherShapes = (
|
|
|
93
96
|
[center[0] - halfOfWidth, center[1] + pointPadding],
|
|
94
97
|
[center[0] - halfOfWidth, center[1] - pointPadding],
|
|
95
98
|
],
|
|
99
|
+
// @ts-ignore
|
|
96
100
|
[LOOP_POSITION['top-left']]: [
|
|
97
101
|
[center[0] - halfOfWidth, center[1] - halfOfHeight + pointPadding],
|
|
98
102
|
[center[0] - halfOfWidth + pointPadding, center[1] - halfOfHeight],
|
package/src/util/shape.ts
CHANGED
|
@@ -48,8 +48,6 @@ export const ShapeTagMap = {
|
|
|
48
48
|
|
|
49
49
|
const LINE_TYPES = ['line', 'polyline', 'path'];
|
|
50
50
|
|
|
51
|
-
export const LOCAL_BOUNDS_DIRTY_FLAG_KEY = 'data-item-local-bounds-dirty';
|
|
52
|
-
|
|
53
51
|
export const createShape = (
|
|
54
52
|
type: SHAPE_TYPE,
|
|
55
53
|
style: GShapeStyle,
|
|
@@ -132,12 +130,10 @@ export const upsertShape = (
|
|
|
132
130
|
shape.style[key] = initShapeStyles[key];
|
|
133
131
|
});
|
|
134
132
|
}
|
|
135
|
-
shape.setAttribute(LOCAL_BOUNDS_DIRTY_FLAG_KEY, true);
|
|
136
133
|
} else if (shape.nodeName !== type) {
|
|
137
134
|
// remove and create for the shape changed type
|
|
138
135
|
shape.remove();
|
|
139
136
|
shape = createShape(type, style, id);
|
|
140
|
-
shape.setAttribute(LOCAL_BOUNDS_DIRTY_FLAG_KEY, true);
|
|
141
137
|
} else {
|
|
142
138
|
const updateStyles = {};
|
|
143
139
|
const oldStyles = shape.attributes;
|
|
@@ -162,9 +158,6 @@ export const upsertShape = (
|
|
|
162
158
|
}
|
|
163
159
|
});
|
|
164
160
|
}
|
|
165
|
-
if (isStyleAffectBBox(type, updateStyles)) {
|
|
166
|
-
shape.setAttribute(LOCAL_BOUNDS_DIRTY_FLAG_KEY, true);
|
|
167
|
-
}
|
|
168
161
|
if (style.interactive === false) shape.interactive = false;
|
|
169
162
|
else shape.interactive = true;
|
|
170
163
|
}
|