@antv/g6 5.0.0-beta.12 → 5.0.0-beta.13
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 +1 -1
- package/esm/index.js +1 -1
- package/esm/item/item.js +2 -1
- package/esm/item/item.js.map +1 -1
- package/esm/runtime/controller/item.js +19 -10
- package/esm/runtime/controller/item.js.map +1 -1
- package/esm/runtime/controller/plugin.js +8 -3
- package/esm/runtime/controller/plugin.js.map +1 -1
- package/esm/stdlib/behavior/drag-canvas.d.ts +1 -0
- package/esm/stdlib/behavior/drag-canvas.js +12 -5
- package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
- package/esm/stdlib/behavior/zoom-canvas.d.ts +1 -0
- package/esm/stdlib/behavior/zoom-canvas.js +8 -2
- package/esm/stdlib/behavior/zoom-canvas.js.map +1 -1
- package/esm/stdlib/item/node/base.d.ts +1 -0
- package/esm/stdlib/item/node/base.js +5 -2
- package/esm/stdlib/item/node/base.js.map +1 -1
- package/esm/types/index.d.ts +2 -1
- package/esm/types/index.js +1 -0
- package/esm/types/index.js.map +1 -1
- package/esm/util/shape.js +12 -12
- package/esm/util/shape.js.map +1 -1
- package/esm/util/shape3d.js +14 -10
- package/esm/util/shape3d.js.map +1 -1
- package/esm/util/text.d.ts +1 -1
- package/esm/util/text.js +3 -2
- package/esm/util/text.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/item/item.js +2 -1
- package/lib/item/item.js.map +1 -1
- package/lib/runtime/controller/item.js +19 -10
- package/lib/runtime/controller/item.js.map +1 -1
- package/lib/runtime/controller/plugin.js +8 -3
- package/lib/runtime/controller/plugin.js.map +1 -1
- package/lib/stdlib/behavior/drag-canvas.d.ts +1 -0
- package/lib/stdlib/behavior/drag-canvas.js +12 -5
- package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
- package/lib/stdlib/behavior/zoom-canvas.d.ts +1 -0
- package/lib/stdlib/behavior/zoom-canvas.js +8 -2
- package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
- package/lib/stdlib/item/node/base.d.ts +1 -0
- package/lib/stdlib/item/node/base.js +5 -2
- package/lib/stdlib/item/node/base.js.map +1 -1
- package/lib/types/index.d.ts +2 -1
- package/lib/types/index.js +3 -1
- package/lib/types/index.js.map +1 -1
- package/lib/util/shape.js +12 -12
- package/lib/util/shape.js.map +1 -1
- package/lib/util/shape3d.js +14 -10
- package/lib/util/shape3d.js.map +1 -1
- package/lib/util/text.d.ts +1 -1
- package/lib/util/text.js +3 -2
- package/lib/util/text.js.map +1 -1
- package/package.json +3 -2
- package/src/index.ts +1 -1
- package/src/item/item.ts +2 -0
- package/src/runtime/controller/item.ts +18 -8
- package/src/runtime/controller/plugin.ts +14 -3
- package/src/stdlib/behavior/drag-canvas.ts +18 -6
- package/src/stdlib/behavior/zoom-canvas.ts +15 -2
- package/src/stdlib/item/node/base.ts +5 -1
- package/src/types/index.ts +2 -1
- package/src/util/shape.ts +16 -11
- package/src/util/shape3d.ts +18 -9
- package/src/util/text.ts +3 -1
- package/esm/stdlib/plugin/map/index.d.ts +0 -118
- package/esm/stdlib/plugin/map/index.js +0 -683
- package/esm/stdlib/plugin/map/index.js.map +0 -1
- package/lib/stdlib/plugin/map/index.d.ts +0 -118
- package/lib/stdlib/plugin/map/index.js +0 -687
- package/lib/stdlib/plugin/map/index.js.map +0 -1
- package/src/stdlib/plugin/map/index.ts +0 -808
|
@@ -75,6 +75,7 @@ export class DragCanvas extends Behavior {
|
|
|
75
75
|
private hiddenEdgeIds: ID[];
|
|
76
76
|
private hiddenNodeIds: ID[];
|
|
77
77
|
private tileRequestId?: number;
|
|
78
|
+
private lastDragTriggerTime?: number;
|
|
78
79
|
|
|
79
80
|
constructor(options: Partial<DragCanvasOptions>) {
|
|
80
81
|
const finalOptions = Object.assign({}, DEFAULT_OPTIONS, options);
|
|
@@ -236,6 +237,22 @@ export class DragCanvas extends Behavior {
|
|
|
236
237
|
const { eventName, direction, secondaryKeyToDisable } = this.options;
|
|
237
238
|
// disabled key is pressing
|
|
238
239
|
if (secondaryKeyToDisable && this.disableKeydown) return;
|
|
240
|
+
|
|
241
|
+
// begin dragging
|
|
242
|
+
if (!this.dragging) {
|
|
243
|
+
this.hideShapes();
|
|
244
|
+
this.dragging = true;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const now = Date.now();
|
|
248
|
+
const MOUSE_ZOOM_DURATION = 250;
|
|
249
|
+
if (
|
|
250
|
+
this.lastDragTriggerTime &&
|
|
251
|
+
now - this.lastDragTriggerTime < MOUSE_ZOOM_DURATION / 5
|
|
252
|
+
) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
|
|
239
256
|
const { graph } = this;
|
|
240
257
|
const { client } = event;
|
|
241
258
|
const diffX = client.x - this.pointerDownAt.x;
|
|
@@ -244,12 +261,6 @@ export class DragCanvas extends Behavior {
|
|
|
244
261
|
if (direction === 'y' && !diffY) return;
|
|
245
262
|
if (direction === 'both' && !diffX && !diffY) return;
|
|
246
263
|
|
|
247
|
-
// begin dragging
|
|
248
|
-
if (!this.dragging) {
|
|
249
|
-
this.hideShapes();
|
|
250
|
-
this.dragging = true;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
264
|
const { dx, dy } = this.formatDisplacement(diffX, diffY);
|
|
254
265
|
graph.translate({ dx, dy });
|
|
255
266
|
|
|
@@ -259,6 +270,7 @@ export class DragCanvas extends Behavior {
|
|
|
259
270
|
if (eventName) {
|
|
260
271
|
this.graph.emit(eventName, { translate: { dx, dy } });
|
|
261
272
|
}
|
|
273
|
+
this.lastDragTriggerTime = now;
|
|
262
274
|
}
|
|
263
275
|
|
|
264
276
|
public onPointerUp() {
|
|
@@ -59,7 +59,7 @@ export interface ZoomCanvasOptions {
|
|
|
59
59
|
const DEFAULT_OPTIONS: Required<ZoomCanvasOptions> = {
|
|
60
60
|
enableOptimize: undefined,
|
|
61
61
|
triggerOnItems: true,
|
|
62
|
-
sensitivity:
|
|
62
|
+
sensitivity: 10,
|
|
63
63
|
trigger: 'wheel',
|
|
64
64
|
secondaryKey: '',
|
|
65
65
|
speedUpKey: 'shift',
|
|
@@ -77,6 +77,7 @@ export class ZoomCanvas extends Behavior {
|
|
|
77
77
|
private hiddenNodeIds: ID[];
|
|
78
78
|
private zoomTimer: ReturnType<typeof setTimeout>;
|
|
79
79
|
private tileRequestId?: number;
|
|
80
|
+
private lastWheelTriggerTime?: number;
|
|
80
81
|
|
|
81
82
|
constructor(options: Partial<ZoomCanvasOptions>) {
|
|
82
83
|
const finalOptions = Object.assign({}, DEFAULT_OPTIONS, options);
|
|
@@ -232,15 +233,27 @@ export class ZoomCanvas extends Behavior {
|
|
|
232
233
|
this.hideShapes();
|
|
233
234
|
this.zooming = true;
|
|
234
235
|
}
|
|
236
|
+
|
|
237
|
+
const now = Date.now();
|
|
238
|
+
const MOUSE_ZOOM_DURATION = 250;
|
|
239
|
+
if (
|
|
240
|
+
this.lastWheelTriggerTime &&
|
|
241
|
+
now - this.lastWheelTriggerTime < MOUSE_ZOOM_DURATION / 5
|
|
242
|
+
) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
|
|
235
246
|
let zoomRatio = 1;
|
|
236
247
|
if (deltaY < 0) zoomRatio = (100 + sensitivity) / 100;
|
|
237
248
|
if (deltaY > 0) zoomRatio = 100 / (100 + sensitivity);
|
|
238
249
|
const zoomTo = zoomRatio * graph.getZoom();
|
|
239
250
|
if (minZoom && zoomTo < minZoom) return;
|
|
240
251
|
if (maxZoom && zoomTo > maxZoom) return;
|
|
241
|
-
|
|
252
|
+
|
|
242
253
|
graph.zoom(zoomRatio, { x: client.x, y: client.y });
|
|
243
254
|
|
|
255
|
+
this.lastWheelTriggerTime = now;
|
|
256
|
+
|
|
244
257
|
clearTimeout(this.zoomTimer);
|
|
245
258
|
this.zoomTimer = setTimeout(() => {
|
|
246
259
|
this.endZoom();
|
|
@@ -41,6 +41,7 @@ export abstract class BaseNode {
|
|
|
41
41
|
themeStyles: NodeShapeStyles | ComboShapeStyles;
|
|
42
42
|
mergedStyles: NodeShapeStyles | ComboShapeStyles;
|
|
43
43
|
lodStrategy?: LodStrategyObj;
|
|
44
|
+
enableBalanceShape?: boolean;
|
|
44
45
|
boundsCache: {
|
|
45
46
|
keyShapeLocal?: AABB;
|
|
46
47
|
labelShapeGeometry?: AABB;
|
|
@@ -84,9 +85,10 @@ export abstract class BaseNode {
|
|
|
84
85
|
};
|
|
85
86
|
|
|
86
87
|
constructor(props) {
|
|
87
|
-
const { themeStyles, lodStrategy, zoom } = props;
|
|
88
|
+
const { themeStyles, lodStrategy, enableBalanceShape, zoom } = props;
|
|
88
89
|
if (themeStyles) this.themeStyles = themeStyles;
|
|
89
90
|
this.lodStrategy = lodStrategy;
|
|
91
|
+
this.enableBalanceShape = enableBalanceShape;
|
|
90
92
|
this.boundsCache = {};
|
|
91
93
|
this.zoomCache.zoom = zoom;
|
|
92
94
|
this.zoomCache.balanceRatio = 1 / zoom;
|
|
@@ -306,6 +308,7 @@ export abstract class BaseNode {
|
|
|
306
308
|
keyShapeBox as AABB,
|
|
307
309
|
maxWidth,
|
|
308
310
|
this.zoomCache.zoom,
|
|
311
|
+
this.enableBalanceShape,
|
|
309
312
|
);
|
|
310
313
|
|
|
311
314
|
const positionPreset = {
|
|
@@ -873,6 +876,7 @@ export abstract class BaseNode {
|
|
|
873
876
|
shapeMap: NodeShapeMap | ComboShapeMap,
|
|
874
877
|
zoom: number,
|
|
875
878
|
) {
|
|
879
|
+
if (!this.enableBalanceShape) return;
|
|
876
880
|
// balance the size for label, badges
|
|
877
881
|
const { keyShape, labelShape, labelBackgroundShape } = shapeMap;
|
|
878
882
|
const balanceRatio = 1 / zoom || 1;
|
package/src/types/index.ts
CHANGED
|
@@ -49,6 +49,7 @@ export type {
|
|
|
49
49
|
LayoutOptions,
|
|
50
50
|
StandardLayoutOptions,
|
|
51
51
|
} from './layout';
|
|
52
|
-
export type {
|
|
52
|
+
export type { IPluginBaseConfig } from './plugin';
|
|
53
|
+
export { Plugin as PluginBase } from './plugin';
|
|
53
54
|
export type { Specification } from './spec';
|
|
54
55
|
export type { ThemeSpecification } from './theme';
|
package/src/util/shape.ts
CHANGED
|
@@ -211,22 +211,27 @@ export const updateShapes = (
|
|
|
211
211
|
const prevShape = prevShapeMap[id];
|
|
212
212
|
const newShape = newShapeMap[id];
|
|
213
213
|
if (newShape && !shouldUpdate(id)) return;
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
if (prevShape !== newShape) {
|
|
214
|
+
|
|
215
|
+
if (newShape) {
|
|
216
|
+
// Remove dirty shape first.
|
|
217
|
+
if (prevShape && prevShape !== newShape) {
|
|
218
218
|
prevShape.remove();
|
|
219
219
|
}
|
|
220
|
-
if (!newShape.destroyed && newShape.style.display !== 'none') {
|
|
221
|
-
group.appendChild(newShape);
|
|
222
|
-
}
|
|
223
|
-
} else if (!prevShape && newShape) {
|
|
224
|
-
// add newShapeMap - prevShapeMap
|
|
225
220
|
finalShapeMap[id] = newShape;
|
|
226
|
-
if (
|
|
221
|
+
if (
|
|
222
|
+
// NewShape is already in the group, no need to reappend.
|
|
223
|
+
// Note: If the given child is a reference to an existing node in the document,
|
|
224
|
+
// appendChild() moves it from its current position to the new position.
|
|
225
|
+
// @see https://developer.mozilla.org/en-US/docs/Web/API/Node/appendChild
|
|
226
|
+
newShape.parentElement !== group &&
|
|
227
|
+
!newShape.destroyed &&
|
|
228
|
+
newShape.style.display !== 'none'
|
|
229
|
+
) {
|
|
227
230
|
group.appendChild(newShape);
|
|
228
231
|
}
|
|
229
|
-
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (prevShape && !newShape && removeDiff) {
|
|
230
235
|
// remove prevShapeMap - newShapeMap
|
|
231
236
|
delete finalShapeMap[id];
|
|
232
237
|
prevShape.remove();
|
package/src/util/shape3d.ts
CHANGED
|
@@ -182,18 +182,27 @@ export const updateShapes3D = (
|
|
|
182
182
|
const prevShape = prevShapeMap[id];
|
|
183
183
|
const newShape = newShapeMap[id];
|
|
184
184
|
if (newShape && !shouldUpdate(id)) return;
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
if (prevShape !== newShape) {
|
|
185
|
+
|
|
186
|
+
if (newShape) {
|
|
187
|
+
// Remove dirty shape first.
|
|
188
|
+
if (prevShape && prevShape !== newShape) {
|
|
189
189
|
prevShape.remove();
|
|
190
190
|
}
|
|
191
|
-
group.appendChild(newShape);
|
|
192
|
-
} else if (!prevShape && newShape) {
|
|
193
|
-
// add newShapeMap - prevShapeMap
|
|
194
191
|
finalShapeMap[id] = newShape;
|
|
195
|
-
|
|
196
|
-
|
|
192
|
+
if (
|
|
193
|
+
// NewShape is already in the group, no need to reappend.
|
|
194
|
+
// Note: If the given child is a reference to an existing node in the document,
|
|
195
|
+
// appendChild() moves it from its current position to the new position.
|
|
196
|
+
// @see https://developer.mozilla.org/en-US/docs/Web/API/Node/appendChild
|
|
197
|
+
newShape.parentElement !== group &&
|
|
198
|
+
!newShape.destroyed &&
|
|
199
|
+
newShape.style.display !== 'none'
|
|
200
|
+
) {
|
|
201
|
+
group.appendChild(newShape);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (prevShape && !newShape && removeDiff) {
|
|
197
206
|
// remove prevShapeMap - newShapeMap
|
|
198
207
|
delete finalShapeMap[id];
|
|
199
208
|
prevShape.remove();
|
package/src/util/text.ts
CHANGED
|
@@ -13,8 +13,10 @@ export const getWordWrapWidthByBox = (
|
|
|
13
13
|
keyShapeBox: AABB,
|
|
14
14
|
maxWidth: string | number,
|
|
15
15
|
zoom = 1,
|
|
16
|
+
enableBalanceShape = false,
|
|
16
17
|
) => {
|
|
17
|
-
const
|
|
18
|
+
const balanceZoom = enableBalanceShape ? zoom : 1;
|
|
19
|
+
const keyShapeWidth = (keyShapeBox.max[0] - keyShapeBox.min[0]) * balanceZoom;
|
|
18
20
|
return getWordWrapWidthWithBase(keyShapeWidth, maxWidth);
|
|
19
21
|
};
|
|
20
22
|
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { Canvas } from '@antv/g';
|
|
2
|
-
import { IGraph } from '../../../types';
|
|
3
|
-
import { ShapeStyle } from '../../../types/item';
|
|
4
|
-
import { Plugin as Base, IPluginBaseConfig } from '../../../types/plugin';
|
|
5
|
-
export interface MiniMapConfig extends IPluginBaseConfig {
|
|
6
|
-
/** Class name of viewport */
|
|
7
|
-
viewportClassName?: string;
|
|
8
|
-
/** Class name of minimap */
|
|
9
|
-
className?: string;
|
|
10
|
-
/** Mode of minimap */
|
|
11
|
-
mode?: 'default' | 'keyShape' | 'delegate';
|
|
12
|
-
/** Size of minimap */
|
|
13
|
-
size?: number[];
|
|
14
|
-
/** Style of delegate shape */
|
|
15
|
-
delegateStyle?: ShapeStyle;
|
|
16
|
-
/** Whether to refresh minimap */
|
|
17
|
-
refresh?: boolean;
|
|
18
|
-
/** Padding of minimap */
|
|
19
|
-
padding?: number;
|
|
20
|
-
/** Whether to hide edges on minimap to enhance performance */
|
|
21
|
-
hideEdge?: boolean;
|
|
22
|
-
/** Container for minimap */
|
|
23
|
-
container?: HTMLElement | null;
|
|
24
|
-
}
|
|
25
|
-
export declare class Minimap extends Base {
|
|
26
|
-
private canvas;
|
|
27
|
-
/** The viewport DOM on the minimap. */
|
|
28
|
-
private viewport;
|
|
29
|
-
/** Cache the mapping of graphics of nodes/edges/combos on main graph and minimap graph. */
|
|
30
|
-
private itemMap;
|
|
31
|
-
private container;
|
|
32
|
-
/** Ratio of (minimap graph size / main graph size). */
|
|
33
|
-
private ratio;
|
|
34
|
-
/** Distance from top of minimap graph to the top of minimap container. */
|
|
35
|
-
private dx;
|
|
36
|
-
/** Distance from left of minimap graph to the left of minimap container. */
|
|
37
|
-
private dy;
|
|
38
|
-
/** Cache the visibility while items' visibility changed. And apply them onto the minimap with debounce. */
|
|
39
|
-
private visibleCache;
|
|
40
|
-
constructor(options?: MiniMapConfig);
|
|
41
|
-
getDefaultCfgs(): MiniMapConfig;
|
|
42
|
-
getEvents(): {
|
|
43
|
-
afteritemstatechange: () => void;
|
|
44
|
-
afterlayout: () => void;
|
|
45
|
-
viewportchange: () => void;
|
|
46
|
-
afteritemchange: () => void;
|
|
47
|
-
afteritemvisibilitychange: (params: any) => void;
|
|
48
|
-
};
|
|
49
|
-
/**
|
|
50
|
-
* If it is animating, disable refresh.
|
|
51
|
-
*/
|
|
52
|
-
protected disableRefresh(): void;
|
|
53
|
-
protected enableRefresh(): void;
|
|
54
|
-
private initViewport;
|
|
55
|
-
/**
|
|
56
|
-
* Update the viewport DOM.
|
|
57
|
-
*/
|
|
58
|
-
private updateViewport;
|
|
59
|
-
/**
|
|
60
|
-
* Clone all the graphic from main graph to the minimap graph.
|
|
61
|
-
*/
|
|
62
|
-
private updateGraphShapes;
|
|
63
|
-
/**
|
|
64
|
-
* Only draw keyShapes on the minimap.
|
|
65
|
-
*/
|
|
66
|
-
private updateKeyShapes;
|
|
67
|
-
/**
|
|
68
|
-
* Add or update keyShape of one node.
|
|
69
|
-
* @param nodeModel node data model
|
|
70
|
-
* @param group container graphics group on minimap
|
|
71
|
-
*/
|
|
72
|
-
private updateOneNodeKeyShape;
|
|
73
|
-
/**
|
|
74
|
-
* Draw the delegate rects for nodes and line edges on minimap.
|
|
75
|
-
*/
|
|
76
|
-
private updateDelegateShapes;
|
|
77
|
-
private clearDestroyedShapes;
|
|
78
|
-
/**
|
|
79
|
-
* Add or update keyShape of one edge.
|
|
80
|
-
* @param edgeModel edge data model
|
|
81
|
-
* @param group container graphics group on minimap
|
|
82
|
-
*/
|
|
83
|
-
private updateOneEdgeKeyShape;
|
|
84
|
-
/**
|
|
85
|
-
* Add or update delegate rect of one node.
|
|
86
|
-
* @param nodeModel node data model
|
|
87
|
-
* @param group container graphics group on minimap
|
|
88
|
-
*/
|
|
89
|
-
private updateOneNodeDelegateShape;
|
|
90
|
-
/**
|
|
91
|
-
* Listener for main graph updating, update the viewport DOM.
|
|
92
|
-
*/
|
|
93
|
-
private handleUpdateCanvas;
|
|
94
|
-
private handleVisibilityChange;
|
|
95
|
-
private debounceCloneVisibility;
|
|
96
|
-
init(graph: IGraph): void;
|
|
97
|
-
/**
|
|
98
|
-
* Init the DOM container for minimap.
|
|
99
|
-
*/
|
|
100
|
-
initContainer(): Promise<any>;
|
|
101
|
-
updateCanvas(): void;
|
|
102
|
-
/**
|
|
103
|
-
* Get the canvas of the minimap.
|
|
104
|
-
* @return {Canvas} G Canvas
|
|
105
|
-
*/
|
|
106
|
-
getCanvas(): Canvas;
|
|
107
|
-
/**
|
|
108
|
-
* Get the viewport DOM of the minimap.
|
|
109
|
-
* @return {HTMLElement} viewport DOM
|
|
110
|
-
*/
|
|
111
|
-
getViewport(): HTMLElement;
|
|
112
|
-
/**
|
|
113
|
-
* Get the container DOM of the minimap.
|
|
114
|
-
* @return {HTMLElement} container DOM
|
|
115
|
-
*/
|
|
116
|
-
getContainer(): HTMLElement;
|
|
117
|
-
destroy(): void;
|
|
118
|
-
}
|