@antv/g6 5.0.0-beta.12 → 5.0.0-beta.14
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/edge.js +1 -1
- package/esm/item/edge.js.map +1 -1
- package/esm/item/item.js +2 -1
- package/esm/item/item.js.map +1 -1
- package/esm/item/node.d.ts +0 -7
- package/esm/item/node.js +0 -3
- 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 +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/drag-node.js +1 -0
- package/esm/stdlib/behavior/drag-node.js.map +1 -1
- package/esm/stdlib/behavior/zoom-canvas.d.ts +1 -0
- package/esm/stdlib/behavior/zoom-canvas.js +13 -3
- 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/edge.js +1 -1
- package/lib/item/edge.js.map +1 -1
- package/lib/item/item.js +2 -1
- package/lib/item/item.js.map +1 -1
- package/lib/item/node.d.ts +0 -7
- package/lib/item/node.js +0 -3
- 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 +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/drag-node.js +1 -0
- package/lib/stdlib/behavior/drag-node.js.map +1 -1
- package/lib/stdlib/behavior/zoom-canvas.d.ts +1 -0
- package/lib/stdlib/behavior/zoom-canvas.js +13 -3
- 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/edge.ts +5 -1
- package/src/item/item.ts +2 -0
- package/src/item/node.ts +0 -26
- package/src/runtime/controller/interaction.ts +10 -4
- 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/drag-node.ts +1 -0
- package/src/stdlib/behavior/zoom-canvas.ts +28 -3
- 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
package/src/index.ts
CHANGED
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/item.ts
CHANGED
|
@@ -125,6 +125,7 @@ export default abstract class Item implements IItem {
|
|
|
125
125
|
const {
|
|
126
126
|
type = this.type === 'edge' ? 'line-edge' : `circle-${this.type}`,
|
|
127
127
|
lodStrategy: modelLodStrategy,
|
|
128
|
+
enableBalanceShape,
|
|
128
129
|
} = this.displayModel.data;
|
|
129
130
|
const RenderExtension = renderExtensions.find((ext) => ext.type === type);
|
|
130
131
|
this.themeStyles = theme.styles;
|
|
@@ -149,6 +150,7 @@ export default abstract class Item implements IItem {
|
|
|
149
150
|
this.renderExt = new RenderExtension({
|
|
150
151
|
themeStyles: this.themeStyles?.default,
|
|
151
152
|
lodStrategy,
|
|
153
|
+
enableBalanceShape,
|
|
152
154
|
device: this.device,
|
|
153
155
|
zoom: this.zoom,
|
|
154
156
|
});
|
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.
|
|
@@ -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) {
|
|
@@ -287,14 +287,16 @@ export class ItemController {
|
|
|
287
287
|
theme.node,
|
|
288
288
|
tileOptimize,
|
|
289
289
|
);
|
|
290
|
+
let nodesInView;
|
|
290
291
|
if (renderNodesPromise) {
|
|
291
|
-
await renderNodesPromise;
|
|
292
|
+
nodesInView = await renderNodesPromise;
|
|
292
293
|
}
|
|
293
294
|
this.renderCombos(combos, theme.combo, graphCore);
|
|
294
295
|
const renderEdgesPromise = this.renderEdges(
|
|
295
296
|
edges,
|
|
296
297
|
theme.edge,
|
|
297
298
|
tileOptimize,
|
|
299
|
+
nodesInView,
|
|
298
300
|
);
|
|
299
301
|
if (renderEdgesPromise) {
|
|
300
302
|
await renderEdgesPromise;
|
|
@@ -1124,18 +1126,18 @@ export class ItemController {
|
|
|
1124
1126
|
});
|
|
1125
1127
|
if (delayFirstDraw) {
|
|
1126
1128
|
let requestId;
|
|
1127
|
-
const
|
|
1128
|
-
const sectionNum = Math.ceil(items.length / tileFirstRenderSize);
|
|
1129
|
+
const sectionNum = Math.ceil(itemsOutView.length / tileFirstRenderSize);
|
|
1129
1130
|
const sections = Array.from({ length: sectionNum }, (v, i) =>
|
|
1130
|
-
|
|
1131
|
+
itemsOutView.slice(
|
|
1131
1132
|
i * tileFirstRenderSize,
|
|
1132
1133
|
i * tileFirstRenderSize + tileFirstRenderSize,
|
|
1133
1134
|
),
|
|
1134
1135
|
);
|
|
1136
|
+
sections.unshift(itemsInView);
|
|
1135
1137
|
const update = (resolve) => {
|
|
1136
1138
|
if (!sections.length) {
|
|
1137
1139
|
cancelAnimationFrame(requestId);
|
|
1138
|
-
return resolve();
|
|
1140
|
+
return resolve(itemsInView);
|
|
1139
1141
|
}
|
|
1140
1142
|
sections
|
|
1141
1143
|
.shift()
|
|
@@ -1230,6 +1232,7 @@ export class ItemController {
|
|
|
1230
1232
|
tileFirstRender?: boolean | number;
|
|
1231
1233
|
tileFirstRenderSize?: number;
|
|
1232
1234
|
},
|
|
1235
|
+
nodesInView?: Node[],
|
|
1233
1236
|
): Promise<any> | undefined {
|
|
1234
1237
|
const { edgeExtensions, edgeGroup, itemMap, edgeDataTypeSet, graph } = this;
|
|
1235
1238
|
const { dataTypeField = '' } = edgeTheme;
|
|
@@ -1239,7 +1242,10 @@ export class ItemController {
|
|
|
1239
1242
|
const delayFirstDraw = isNumber(tileFirstRender)
|
|
1240
1243
|
? models.length > tileFirstRender
|
|
1241
1244
|
: tileFirstRender;
|
|
1242
|
-
const
|
|
1245
|
+
const nodesInViewIds = new Set(nodesInView?.map((node) => node.getID()));
|
|
1246
|
+
const edgesInView = [];
|
|
1247
|
+
const edgesOutView = [];
|
|
1248
|
+
models.forEach((edge) => {
|
|
1243
1249
|
const { source, target, id } = edge;
|
|
1244
1250
|
const sourceItem = itemMap.get(source) as Node;
|
|
1245
1251
|
const targetItem = itemMap.get(target) as Node;
|
|
@@ -1285,18 +1291,22 @@ export class ItemController {
|
|
|
1285
1291
|
});
|
|
1286
1292
|
|
|
1287
1293
|
itemMap.set(id, edgeItem);
|
|
1294
|
+
if (nodesInViewIds.has(source) || nodesInViewIds.has(target))
|
|
1295
|
+
edgesInView.push(edgeItem);
|
|
1296
|
+
else edgesOutView.push(edgeItem);
|
|
1288
1297
|
return edgeItem;
|
|
1289
1298
|
});
|
|
1290
1299
|
|
|
1291
1300
|
if (delayFirstDraw) {
|
|
1292
1301
|
let requestId;
|
|
1293
|
-
const sectionNum = Math.ceil(
|
|
1302
|
+
const sectionNum = Math.ceil(edgesOutView.length / tileFirstRenderSize);
|
|
1294
1303
|
const sections = Array.from({ length: sectionNum }, (v, i) =>
|
|
1295
|
-
|
|
1304
|
+
edgesOutView.slice(
|
|
1296
1305
|
i * tileFirstRenderSize,
|
|
1297
1306
|
i * tileFirstRenderSize + tileFirstRenderSize,
|
|
1298
1307
|
),
|
|
1299
1308
|
);
|
|
1309
|
+
sections.unshift(edgesInView);
|
|
1300
1310
|
const update = (resolve) => {
|
|
1301
1311
|
if (!sections.length) {
|
|
1302
1312
|
cancelAnimationFrame(requestId);
|
|
@@ -116,7 +116,7 @@ export class PluginController {
|
|
|
116
116
|
if (action === 'add') {
|
|
117
117
|
pluginCfgs.forEach((config) => {
|
|
118
118
|
const { key, plugin } = this.initPlugin(config);
|
|
119
|
-
this.addListeners(key, plugin);
|
|
119
|
+
this.addListeners(key, plugin, false);
|
|
120
120
|
});
|
|
121
121
|
return;
|
|
122
122
|
}
|
|
@@ -158,7 +158,7 @@ export class PluginController {
|
|
|
158
158
|
const { plugin } = item;
|
|
159
159
|
plugin.updateCfgs(config);
|
|
160
160
|
this.removeListeners(key);
|
|
161
|
-
this.addListeners(key, plugin);
|
|
161
|
+
this.addListeners(key, plugin, false);
|
|
162
162
|
});
|
|
163
163
|
return;
|
|
164
164
|
}
|
|
@@ -184,7 +184,11 @@ export class PluginController {
|
|
|
184
184
|
return plugin;
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
private addListeners = (
|
|
187
|
+
private addListeners = (
|
|
188
|
+
key: string,
|
|
189
|
+
plugin: PluginBase,
|
|
190
|
+
initWithGraph: boolean = true,
|
|
191
|
+
) => {
|
|
188
192
|
const events = plugin.getEvents();
|
|
189
193
|
this.listenersMap[key] = {};
|
|
190
194
|
Object.keys(events).forEach((eventName) => {
|
|
@@ -196,6 +200,13 @@ export class PluginController {
|
|
|
196
200
|
);
|
|
197
201
|
this.graph.on(eventName, listener);
|
|
198
202
|
this.listenersMap[key][eventName] = listener;
|
|
203
|
+
// The plugin is not initiated with graph, some events are not listened, trigger them manually
|
|
204
|
+
if (
|
|
205
|
+
!initWithGraph &&
|
|
206
|
+
['afterrender', 'afterlayout'].includes(eventName)
|
|
207
|
+
) {
|
|
208
|
+
listener({} as IG6GraphEvent);
|
|
209
|
+
}
|
|
199
210
|
});
|
|
200
211
|
};
|
|
201
212
|
|
|
@@ -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.
|
|
@@ -75,6 +76,7 @@ export class DragCanvas extends Behavior {
|
|
|
75
76
|
private hiddenEdgeIds: ID[];
|
|
76
77
|
private hiddenNodeIds: ID[];
|
|
77
78
|
private tileRequestId?: number;
|
|
79
|
+
private lastDragTriggerTime?: number;
|
|
78
80
|
|
|
79
81
|
constructor(options: Partial<DragCanvasOptions>) {
|
|
80
82
|
const finalOptions = Object.assign({}, DEFAULT_OPTIONS, options);
|
|
@@ -236,6 +238,21 @@ export class DragCanvas extends Behavior {
|
|
|
236
238
|
const { eventName, direction, secondaryKeyToDisable } = this.options;
|
|
237
239
|
// disabled key is pressing
|
|
238
240
|
if (secondaryKeyToDisable && this.disableKeydown) return;
|
|
241
|
+
|
|
242
|
+
// begin dragging
|
|
243
|
+
if (!this.dragging) {
|
|
244
|
+
this.hideShapes();
|
|
245
|
+
this.dragging = true;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const now = Date.now();
|
|
249
|
+
if (
|
|
250
|
+
this.lastDragTriggerTime &&
|
|
251
|
+
now - this.lastDragTriggerTime < DRAG_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() {
|
|
@@ -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
|
};
|
|
@@ -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: 10,
|
|
63
64
|
trigger: 'wheel',
|
|
64
65
|
secondaryKey: '',
|
|
65
66
|
speedUpKey: 'shift',
|
|
@@ -77,6 +78,7 @@ export class ZoomCanvas extends Behavior {
|
|
|
77
78
|
private hiddenNodeIds: ID[];
|
|
78
79
|
private zoomTimer: ReturnType<typeof setTimeout>;
|
|
79
80
|
private tileRequestId?: number;
|
|
81
|
+
private lastWheelTriggerTime?: number;
|
|
80
82
|
|
|
81
83
|
constructor(options: Partial<ZoomCanvasOptions>) {
|
|
82
84
|
const finalOptions = Object.assign({}, DEFAULT_OPTIONS, options);
|
|
@@ -232,14 +234,37 @@ export class ZoomCanvas extends Behavior {
|
|
|
232
234
|
this.hideShapes();
|
|
233
235
|
this.zooming = true;
|
|
234
236
|
}
|
|
237
|
+
|
|
238
|
+
const now = Date.now();
|
|
239
|
+
if (
|
|
240
|
+
this.lastWheelTriggerTime &&
|
|
241
|
+
now - this.lastWheelTriggerTime < WHEEL_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
|
-
|
|
242
|
-
|
|
252
|
+
|
|
253
|
+
const { tileBehavior: graphBehaviorOptimize } =
|
|
254
|
+
graph.getSpecification().optimize || {};
|
|
255
|
+
|
|
256
|
+
const shouldAnimate =
|
|
257
|
+
typeof graphBehaviorOptimize === 'boolean'
|
|
258
|
+
? graphBehaviorOptimize
|
|
259
|
+
: graph.getAllNodesData().length < graphBehaviorOptimize;
|
|
260
|
+
|
|
261
|
+
graph.zoom(
|
|
262
|
+
zoomRatio,
|
|
263
|
+
{ x: client.x, y: client.y },
|
|
264
|
+
shouldAnimate ? { duration: WHEEL_DURATION / 5 } : undefined,
|
|
265
|
+
);
|
|
266
|
+
|
|
267
|
+
this.lastWheelTriggerTime = now;
|
|
243
268
|
|
|
244
269
|
clearTimeout(this.zoomTimer);
|
|
245
270
|
this.zoomTimer = setTimeout(() => {
|
|
@@ -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
|
-
}
|