@antv/g6 5.0.9 → 5.0.10
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/dist/lib/behaviors/fix-element-size.d.ts +82 -0
- package/dist/lib/behaviors/index.d.ts +4 -0
- package/dist/lib/behaviors/optimize-viewport-transform.d.ts +54 -0
- package/dist/lib/constants/events/graph.d.ts +13 -1
- package/dist/lib/exports.d.ts +3 -2
- package/dist/lib/plugins/history/index.d.ts +3 -4
- package/dist/lib/runtime/canvas.d.ts +28 -7
- package/dist/lib/utils/bbox.d.ts +10 -0
- package/dist/lib/utils/visibility.d.ts +2 -1
- package/dist/lib/version.d.ts +1 -1
- package/esm/behaviors/create-edge.js +6 -4
- package/esm/behaviors/create-edge.js.map +1 -1
- package/esm/behaviors/fix-element-size.d.ts +82 -0
- package/esm/behaviors/fix-element-size.js +101 -0
- package/esm/behaviors/fix-element-size.js.map +1 -0
- package/esm/behaviors/index.d.ts +4 -0
- package/esm/behaviors/index.js +2 -0
- package/esm/behaviors/index.js.map +1 -1
- package/esm/behaviors/optimize-viewport-transform.d.ts +54 -0
- package/esm/behaviors/optimize-viewport-transform.js +71 -0
- package/esm/behaviors/optimize-viewport-transform.js.map +1 -0
- package/esm/constants/events/graph.d.ts +13 -1
- package/esm/constants/events/graph.js +12 -0
- package/esm/constants/events/graph.js.map +1 -1
- package/esm/elements/nodes/html.js +1 -1
- package/esm/elements/nodes/html.js.map +1 -1
- package/esm/elements/shapes/label.js +1 -1
- package/esm/elements/shapes/label.js.map +1 -1
- package/esm/exports.d.ts +3 -2
- package/esm/exports.js +1 -1
- package/esm/exports.js.map +1 -1
- package/esm/plugins/history/index.d.ts +3 -4
- package/esm/plugins/history/index.js +6 -7
- package/esm/plugins/history/index.js.map +1 -1
- package/esm/registry/build-in.js +11 -9
- package/esm/registry/build-in.js.map +1 -1
- package/esm/runtime/canvas.d.ts +28 -7
- package/esm/runtime/canvas.js +63 -32
- package/esm/runtime/canvas.js.map +1 -1
- package/esm/runtime/element.js +4 -0
- package/esm/runtime/element.js.map +1 -1
- package/esm/runtime/graph.js +12 -10
- package/esm/runtime/graph.js.map +1 -1
- package/esm/runtime/viewport.js +2 -1
- package/esm/runtime/viewport.js.map +1 -1
- package/esm/utils/bbox.d.ts +10 -0
- package/esm/utils/bbox.js +15 -0
- package/esm/utils/bbox.js.map +1 -1
- package/esm/utils/router/orth.js +4 -4
- package/esm/utils/router/orth.js.map +1 -1
- package/esm/utils/visibility.d.ts +2 -1
- package/esm/utils/visibility.js +5 -2
- package/esm/utils/visibility.js.map +1 -1
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/esm/version.js.map +1 -1
- package/lib/behaviors/create-edge.js +6 -4
- package/lib/behaviors/create-edge.js.map +1 -1
- package/lib/behaviors/fix-element-size.d.ts +82 -0
- package/lib/behaviors/fix-element-size.js +105 -0
- package/lib/behaviors/fix-element-size.js.map +1 -0
- package/lib/behaviors/index.d.ts +4 -0
- package/lib/behaviors/index.js +5 -1
- package/lib/behaviors/index.js.map +1 -1
- package/lib/behaviors/optimize-viewport-transform.d.ts +54 -0
- package/lib/behaviors/optimize-viewport-transform.js +75 -0
- package/lib/behaviors/optimize-viewport-transform.js.map +1 -0
- package/lib/constants/events/graph.d.ts +13 -1
- package/lib/constants/events/graph.js +12 -0
- package/lib/constants/events/graph.js.map +1 -1
- package/lib/elements/nodes/html.js +1 -1
- package/lib/elements/nodes/html.js.map +1 -1
- package/lib/elements/shapes/label.js +1 -1
- package/lib/elements/shapes/label.js.map +1 -1
- package/lib/exports.d.ts +3 -2
- package/lib/exports.js +4 -2
- package/lib/exports.js.map +1 -1
- package/lib/plugins/history/index.d.ts +3 -4
- package/lib/plugins/history/index.js +6 -7
- package/lib/plugins/history/index.js.map +1 -1
- package/lib/registry/build-in.js +10 -8
- package/lib/registry/build-in.js.map +1 -1
- package/lib/runtime/canvas.d.ts +28 -7
- package/lib/runtime/canvas.js +63 -32
- package/lib/runtime/canvas.js.map +1 -1
- package/lib/runtime/element.js +4 -0
- package/lib/runtime/element.js.map +1 -1
- package/lib/runtime/graph.js +12 -10
- package/lib/runtime/graph.js.map +1 -1
- package/lib/runtime/viewport.js +2 -1
- package/lib/runtime/viewport.js.map +1 -1
- package/lib/utils/bbox.d.ts +10 -0
- package/lib/utils/bbox.js +16 -0
- package/lib/utils/bbox.js.map +1 -1
- package/lib/utils/router/orth.js +3 -3
- package/lib/utils/router/orth.js.map +1 -1
- package/lib/utils/visibility.d.ts +2 -1
- package/lib/utils/visibility.js +5 -2
- package/lib/utils/visibility.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/lib/version.js.map +1 -1
- package/package.json +2 -1
- package/src/behaviors/create-edge.ts +6 -4
- package/src/behaviors/fix-element-size.ts +178 -0
- package/src/behaviors/index.ts +4 -0
- package/src/behaviors/optimize-viewport-transform.ts +127 -0
- package/src/constants/events/graph.ts +12 -0
- package/src/elements/nodes/html.ts +1 -1
- package/src/elements/shapes/label.ts +1 -1
- package/src/exports.ts +5 -0
- package/src/plugins/history/index.ts +9 -10
- package/src/registry/build-in.ts +12 -8
- package/src/runtime/canvas.ts +80 -31
- package/src/runtime/element.ts +4 -0
- package/src/runtime/graph.ts +13 -9
- package/src/runtime/viewport.ts +3 -2
- package/src/utils/bbox.ts +21 -0
- package/src/utils/router/orth.ts +5 -3
- package/src/utils/visibility.ts +9 -2
- package/src/version.ts +1 -1
|
@@ -28,13 +28,13 @@ export interface HistoryOptions extends BasePluginOptions {
|
|
|
28
28
|
*
|
|
29
29
|
* <en/> Called before a command is added to the Undo/Redo queue. If this method returns false, the command will not be added to the queue. revert is true for undo operations and false for redo operations
|
|
30
30
|
*/
|
|
31
|
-
beforeAddCommand?: (cmd: Command, revert
|
|
31
|
+
beforeAddCommand?: (cmd: Command, revert: boolean) => boolean | void;
|
|
32
32
|
/**
|
|
33
33
|
* <zh/> 当一个命令被添加到 Undo/Redo 队列后被调用。revert 为 true 时表示撤销操作,为 false 时表示重做操作
|
|
34
34
|
*
|
|
35
35
|
* <en/> Called after a command is added to the Undo/Redo queue. revert is true for undo operations and false for redo operations
|
|
36
36
|
*/
|
|
37
|
-
afterAddCommand?: (cmd: Command, revert
|
|
37
|
+
afterAddCommand?: (cmd: Command, revert: boolean) => void;
|
|
38
38
|
/**
|
|
39
39
|
* <zh/> 执行命令时的回调函数
|
|
40
40
|
*
|
|
@@ -61,7 +61,6 @@ export class History extends BasePlugin<HistoryOptions> {
|
|
|
61
61
|
private batchAnimation = false;
|
|
62
62
|
public undoStack: Command[] = [];
|
|
63
63
|
public redoStack: Command[] = [];
|
|
64
|
-
private isFirstDraw = true;
|
|
65
64
|
private freezed = false;
|
|
66
65
|
|
|
67
66
|
constructor(context: RuntimeContext, options: HistoryOptions) {
|
|
@@ -105,7 +104,10 @@ export class History extends BasePlugin<HistoryOptions> {
|
|
|
105
104
|
const cmd = this.undoStack.pop();
|
|
106
105
|
if (cmd) {
|
|
107
106
|
this.executeCommand(cmd);
|
|
108
|
-
|
|
107
|
+
|
|
108
|
+
const before = this.options.beforeAddCommand?.(cmd, false);
|
|
109
|
+
if (before === false) return;
|
|
110
|
+
|
|
109
111
|
this.redoStack.push(cmd);
|
|
110
112
|
this.options.afterAddCommand?.(cmd, false);
|
|
111
113
|
this.notify(HistoryEvent.UNDO, cmd);
|
|
@@ -160,11 +162,6 @@ export class History extends BasePlugin<HistoryOptions> {
|
|
|
160
162
|
};
|
|
161
163
|
|
|
162
164
|
private addCommand = (event: GraphLifeCycleEvent) => {
|
|
163
|
-
if (this.isFirstDraw) {
|
|
164
|
-
this.isFirstDraw = false;
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
165
|
if (this.freezed) return;
|
|
169
166
|
|
|
170
167
|
if (event.type === GraphEvent.AFTER_DRAW) {
|
|
@@ -202,7 +199,9 @@ export class History extends BasePlugin<HistoryOptions> {
|
|
|
202
199
|
this.undoStack.shift();
|
|
203
200
|
}
|
|
204
201
|
|
|
205
|
-
this.options.beforeAddCommand?.(cmd, true);
|
|
202
|
+
const before = this.options.beforeAddCommand?.(cmd, true);
|
|
203
|
+
if (before === false) return;
|
|
204
|
+
|
|
206
205
|
this.undoStack.push(cmd);
|
|
207
206
|
this.options.afterAddCommand?.(cmd, true);
|
|
208
207
|
}
|
package/src/registry/build-in.ts
CHANGED
|
@@ -7,9 +7,11 @@ import {
|
|
|
7
7
|
DragCanvas,
|
|
8
8
|
DragElement,
|
|
9
9
|
DragElementForce,
|
|
10
|
+
FixElementSize,
|
|
10
11
|
FocusElement,
|
|
11
12
|
HoverActivate,
|
|
12
13
|
LassoSelect,
|
|
14
|
+
OptimizeViewportTransform,
|
|
13
15
|
ScrollCanvas,
|
|
14
16
|
ZoomCanvas,
|
|
15
17
|
} from '../behaviors';
|
|
@@ -94,18 +96,20 @@ export const BUILT_IN_EXTENSIONS: ExtensionRegistry = {
|
|
|
94
96
|
translate: Translate,
|
|
95
97
|
},
|
|
96
98
|
behavior: {
|
|
97
|
-
'
|
|
99
|
+
'brush-select': BrushSelect,
|
|
100
|
+
'click-select': ClickSelect,
|
|
101
|
+
'collapse-expand': CollapseExpand,
|
|
102
|
+
'create-edge': CreateEdge,
|
|
98
103
|
'drag-canvas': DragCanvas,
|
|
99
|
-
'drag-element': DragElement,
|
|
100
104
|
'drag-element-force': DragElementForce,
|
|
101
|
-
'
|
|
102
|
-
'
|
|
103
|
-
'click-select': ClickSelect,
|
|
104
|
-
'hover-activate': HoverActivate,
|
|
105
|
+
'drag-element': DragElement,
|
|
106
|
+
'fix-element-size': FixElementSize,
|
|
105
107
|
'focus-element': FocusElement,
|
|
106
|
-
'
|
|
107
|
-
'brush-select': BrushSelect,
|
|
108
|
+
'hover-activate': HoverActivate,
|
|
108
109
|
'lasso-select': LassoSelect,
|
|
110
|
+
'optimize-viewport-transform': OptimizeViewportTransform,
|
|
111
|
+
'scroll-canvas': ScrollCanvas,
|
|
112
|
+
'zoom-canvas': ZoomCanvas,
|
|
109
113
|
},
|
|
110
114
|
combo: {
|
|
111
115
|
circle: CircleCombo,
|
package/src/runtime/canvas.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import type { DisplayObject, CanvasConfig as GCanvasConfig, IChildNode } from '@antv/g';
|
|
1
|
+
import type { Cursor, DisplayObject, CanvasConfig as GCanvasConfig, IChildNode } from '@antv/g';
|
|
2
2
|
import { CanvasEvent, Canvas as GCanvas } from '@antv/g';
|
|
3
3
|
import { Renderer as CanvasRenderer } from '@antv/g-canvas';
|
|
4
4
|
import { Plugin as DragNDropPlugin } from '@antv/g-plugin-dragndrop';
|
|
5
5
|
import { createDOM } from '@antv/util';
|
|
6
6
|
import type { CanvasOptions } from '../spec/canvas';
|
|
7
|
-
import type { CanvasLayer } from '../types';
|
|
7
|
+
import type { CanvasLayer, Point } from '../types';
|
|
8
8
|
import { getBBoxSize, getCombinedBBox } from '../utils/bbox';
|
|
9
|
+
import { parsePoint, toPointObject } from '../utils/point';
|
|
9
10
|
|
|
10
11
|
export interface CanvasConfig
|
|
11
12
|
extends Pick<GCanvasConfig, 'container' | 'devicePixelRatio' | 'width' | 'height' | 'cursor' | 'background'> {
|
|
@@ -40,7 +41,7 @@ export interface DataURLOptions {
|
|
|
40
41
|
|
|
41
42
|
const layersName: CanvasLayer[] = ['background', 'main', 'label', 'transient'];
|
|
42
43
|
|
|
43
|
-
export class Canvas
|
|
44
|
+
export class Canvas {
|
|
44
45
|
private extends: {
|
|
45
46
|
config: CanvasConfig;
|
|
46
47
|
renderer: CanvasOptions['renderer'];
|
|
@@ -48,7 +49,13 @@ export class Canvas extends GCanvas {
|
|
|
48
49
|
layers: Record<CanvasLayer, GCanvas>;
|
|
49
50
|
};
|
|
50
51
|
|
|
51
|
-
|
|
52
|
+
private config: CanvasConfig;
|
|
53
|
+
|
|
54
|
+
public getConfig() {
|
|
55
|
+
return this.config;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public getLayer(layer: CanvasLayer = 'main') {
|
|
52
59
|
return this.extends.layers[layer];
|
|
53
60
|
}
|
|
54
61
|
|
|
@@ -73,17 +80,46 @@ export class Canvas extends GCanvas {
|
|
|
73
80
|
return this.extends.renderers[layer];
|
|
74
81
|
}
|
|
75
82
|
|
|
83
|
+
/**
|
|
84
|
+
* <zh/> 获取相机
|
|
85
|
+
*
|
|
86
|
+
* <en/> Get camera
|
|
87
|
+
* @param layer - <zh/> 图层 <en/> Layer
|
|
88
|
+
* @returns <zh/> 相机 <en/> Camera
|
|
89
|
+
*/
|
|
90
|
+
public getCamera(layer: CanvasLayer = 'main') {
|
|
91
|
+
return this.getLayer(layer).getCamera();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public getRoot(layer: CanvasLayer = 'main') {
|
|
95
|
+
return this.getLayer(layer).getRoot();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public getContextService(layer: CanvasLayer = 'main') {
|
|
99
|
+
return this.getLayer(layer).getContextService();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public setCursor(cursor: Cursor): void {
|
|
103
|
+
this.config.cursor = cursor;
|
|
104
|
+
this.getLayer().setCursor(cursor);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public get document() {
|
|
108
|
+
return this.getLayer().document;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
public get context() {
|
|
112
|
+
return this.getLayer().context;
|
|
113
|
+
}
|
|
114
|
+
|
|
76
115
|
constructor(config: CanvasConfig) {
|
|
116
|
+
this.config = config;
|
|
117
|
+
|
|
77
118
|
const { renderer, background, cursor, ...restConfig } = config;
|
|
78
119
|
const renderers = createRenderers(renderer);
|
|
79
120
|
|
|
80
|
-
// init main canvas
|
|
81
|
-
super({ ...restConfig, supportsMutipleCanvasesInOneContainer: true, cursor, renderer: renderers.main });
|
|
82
|
-
|
|
83
121
|
const layers = Object.fromEntries(
|
|
84
122
|
layersName.map((layer) => {
|
|
85
|
-
if (layer === 'main') return [layer, this];
|
|
86
|
-
|
|
87
123
|
const canvas = new GCanvas({
|
|
88
124
|
...restConfig,
|
|
89
125
|
supportsMutipleCanvasesInOneContainer: true,
|
|
@@ -106,20 +142,12 @@ export class Canvas extends GCanvas {
|
|
|
106
142
|
}
|
|
107
143
|
|
|
108
144
|
public get ready() {
|
|
109
|
-
return Promise.all([
|
|
110
|
-
super.ready,
|
|
111
|
-
...Object.entries(this.getLayers()).map(([layer, canvas]) =>
|
|
112
|
-
layer === 'main' ? Promise.resolve() : canvas.ready,
|
|
113
|
-
),
|
|
114
|
-
]);
|
|
145
|
+
return Promise.all(Object.entries(this.getLayers()).map(([, canvas]) => canvas.ready));
|
|
115
146
|
}
|
|
116
147
|
|
|
117
148
|
public resize(width: number, height: number) {
|
|
118
149
|
Object.assign(this.extends.config, { width, height });
|
|
119
|
-
Object.values(this.getLayers()).forEach((canvas) =>
|
|
120
|
-
if (canvas === this) super.resize(width, height);
|
|
121
|
-
else canvas.resize(width, height);
|
|
122
|
-
});
|
|
150
|
+
Object.values(this.getLayers()).forEach((canvas) => canvas.resize(width, height));
|
|
123
151
|
}
|
|
124
152
|
|
|
125
153
|
public getBounds() {
|
|
@@ -142,19 +170,41 @@ export class Canvas extends GCanvas {
|
|
|
142
170
|
|
|
143
171
|
public appendChild<T extends IChildNode>(child: T, index?: number): T {
|
|
144
172
|
const layer = ((child as unknown as DisplayObject).style?.$layer || 'main') as CanvasLayer;
|
|
145
|
-
if (layer === 'main') return super.appendChild(child, index);
|
|
146
173
|
return this.getLayer(layer).appendChild(child, index);
|
|
147
174
|
}
|
|
148
175
|
|
|
149
|
-
public setRenderer(renderer:
|
|
176
|
+
public setRenderer(renderer: CanvasOptions['renderer']) {
|
|
150
177
|
if (renderer === this.extends.renderer) return;
|
|
151
178
|
const renderers = createRenderers(renderer);
|
|
152
179
|
this.extends.renderers = renderers;
|
|
180
|
+
Object.entries(renderers).forEach(([layer, instance]) => this.getLayer(layer as CanvasLayer).setRenderer(instance));
|
|
181
|
+
configCanvasDom(this.getLayers());
|
|
182
|
+
}
|
|
153
183
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
184
|
+
public getCanvasByViewport(point: Point): Point {
|
|
185
|
+
return parsePoint(this.getLayer().viewport2Canvas(toPointObject(point)));
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
public getViewportByCanvas(point: Point): Point {
|
|
189
|
+
return parsePoint(this.getLayer().canvas2Viewport(toPointObject(point)));
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
public getViewportByClient(point: Point): Point {
|
|
193
|
+
return parsePoint(this.getLayer().client2Viewport(toPointObject(point)));
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
public getClientByViewport(point: Point): Point {
|
|
197
|
+
return parsePoint(this.getLayer().viewport2Client(toPointObject(point)));
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
public getClientByCanvas(point: Point): Point {
|
|
201
|
+
return this.getClientByViewport(this.getViewportByCanvas(point));
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
public getCanvasByClient(point: Point): Point {
|
|
205
|
+
const main = this.getLayer();
|
|
206
|
+
const viewportPoint = main.client2Viewport(toPointObject(point));
|
|
207
|
+
return parsePoint(main.viewport2Canvas(viewportPoint));
|
|
158
208
|
}
|
|
159
209
|
|
|
160
210
|
public async toDataURL(options: Partial<DataURLOptions> = {}) {
|
|
@@ -190,10 +240,10 @@ export class Canvas extends GCanvas {
|
|
|
190
240
|
// Handle label canvas
|
|
191
241
|
const label = this.getLayer('label').getRoot().cloneNode(true);
|
|
192
242
|
const originCanvasPosition = offscreenCanvas.viewport2Canvas({ x: 0, y: 0 });
|
|
193
|
-
const currentCanvasPosition = this.
|
|
243
|
+
const currentCanvasPosition = this.getCanvasByViewport([0, 0]);
|
|
194
244
|
label.translate([
|
|
195
|
-
currentCanvasPosition
|
|
196
|
-
currentCanvasPosition
|
|
245
|
+
currentCanvasPosition[0] - originCanvasPosition.x,
|
|
246
|
+
currentCanvasPosition[1] - originCanvasPosition.y,
|
|
197
247
|
]);
|
|
198
248
|
label.scale(1 / this.getCamera().getZoom());
|
|
199
249
|
offscreenCanvas.appendChild(label);
|
|
@@ -226,12 +276,11 @@ export class Canvas extends GCanvas {
|
|
|
226
276
|
});
|
|
227
277
|
}
|
|
228
278
|
|
|
229
|
-
public destroy(
|
|
279
|
+
public destroy() {
|
|
230
280
|
Object.values(this.getLayers()).forEach((canvas) => {
|
|
231
281
|
const camera = canvas.getCamera();
|
|
232
282
|
camera.cancelLandmarkAnimation();
|
|
233
|
-
|
|
234
|
-
else canvas.destroy(cleanUp, skipTriggerEvent);
|
|
283
|
+
canvas.destroy();
|
|
235
284
|
});
|
|
236
285
|
}
|
|
237
286
|
}
|
package/src/runtime/element.ts
CHANGED
|
@@ -451,6 +451,9 @@ export class ElementController {
|
|
|
451
451
|
},
|
|
452
452
|
{
|
|
453
453
|
before: () => {
|
|
454
|
+
// 通过 elementMap[id] 访问最新的 element,防止 type 不同导致的 element 丢失
|
|
455
|
+
// Access the latest element through elementMap[id] to prevent the loss of element caused by different types
|
|
456
|
+
const element = this.elementMap[id];
|
|
454
457
|
if (stage !== 'collapse') updateStyle(element, style);
|
|
455
458
|
|
|
456
459
|
if (stage === 'visibility') {
|
|
@@ -462,6 +465,7 @@ export class ElementController {
|
|
|
462
465
|
}
|
|
463
466
|
},
|
|
464
467
|
after: () => {
|
|
468
|
+
const element = this.elementMap[id];
|
|
465
469
|
if (stage === 'collapse') updateStyle(element, style);
|
|
466
470
|
if (exactStage === 'hide') updateStyle(element, { visibility: getCachedStyle(element, 'visibility') });
|
|
467
471
|
this.emit(new ElementLifeCycleEvent(GraphEvent.AFTER_ELEMENT_UPDATE, elementType, datum), context);
|
package/src/runtime/graph.ts
CHANGED
|
@@ -43,7 +43,6 @@ import { isCollapsed } from '../utils/collapsibility';
|
|
|
43
43
|
import { sizeOf } from '../utils/dom';
|
|
44
44
|
import { GraphLifeCycleEvent, emit } from '../utils/event';
|
|
45
45
|
import { idOf } from '../utils/id';
|
|
46
|
-
import { parsePoint, toPointObject } from '../utils/point';
|
|
47
46
|
import { format } from '../utils/print';
|
|
48
47
|
import { subtract } from '../utils/vector';
|
|
49
48
|
import { Animation } from './animation';
|
|
@@ -120,6 +119,15 @@ export class Graph extends EventEmitter {
|
|
|
120
119
|
public setOptions(options: GraphOptions): void {
|
|
121
120
|
const { behaviors, combo, data, edge, height, layout, node, plugins, theme, transforms, width, renderer } = options;
|
|
122
121
|
|
|
122
|
+
if (renderer) {
|
|
123
|
+
const canvas = this.context.canvas;
|
|
124
|
+
if (canvas) {
|
|
125
|
+
this.emit(GraphEvent.BEFORE_RENDERER_CHANGE, { renderer: this.options.renderer });
|
|
126
|
+
canvas.setRenderer(renderer);
|
|
127
|
+
this.emit(GraphEvent.AFTER_RENDERER_CHANGE, { renderer });
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
123
131
|
Object.assign(this.options, options);
|
|
124
132
|
|
|
125
133
|
if (behaviors) this.setBehaviors(behaviors);
|
|
@@ -133,7 +141,6 @@ export class Graph extends EventEmitter {
|
|
|
133
141
|
if (transforms) this.setTransforms(transforms);
|
|
134
142
|
if (isNumber(width) || isNumber(height))
|
|
135
143
|
this.setSize(width ?? this.options.width ?? 0, height ?? this.options.height ?? 0);
|
|
136
|
-
if (renderer) this.context.canvas?.setRenderer(renderer);
|
|
137
144
|
}
|
|
138
145
|
|
|
139
146
|
/**
|
|
@@ -1095,7 +1102,6 @@ export class Graph extends EventEmitter {
|
|
|
1095
1102
|
public async draw(): Promise<void> {
|
|
1096
1103
|
await this.prepare();
|
|
1097
1104
|
await this.context.element!.draw()?.finished;
|
|
1098
|
-
await this.autoFit();
|
|
1099
1105
|
}
|
|
1100
1106
|
|
|
1101
1107
|
/**
|
|
@@ -1786,7 +1792,7 @@ export class Graph extends EventEmitter {
|
|
|
1786
1792
|
* @apiCategory viewport
|
|
1787
1793
|
*/
|
|
1788
1794
|
public getCanvasByViewport(point: Point): Point {
|
|
1789
|
-
return
|
|
1795
|
+
return this.context.canvas.getCanvasByViewport(point);
|
|
1790
1796
|
}
|
|
1791
1797
|
|
|
1792
1798
|
/**
|
|
@@ -1798,7 +1804,7 @@ export class Graph extends EventEmitter {
|
|
|
1798
1804
|
* @apiCategory viewport
|
|
1799
1805
|
*/
|
|
1800
1806
|
public getViewportByCanvas(point: Point): Point {
|
|
1801
|
-
return
|
|
1807
|
+
return this.context.canvas.getViewportByCanvas(point);
|
|
1802
1808
|
}
|
|
1803
1809
|
|
|
1804
1810
|
/**
|
|
@@ -1810,8 +1816,7 @@ export class Graph extends EventEmitter {
|
|
|
1810
1816
|
* @apiCategory viewport
|
|
1811
1817
|
*/
|
|
1812
1818
|
public getClientByCanvas(point: Point): Point {
|
|
1813
|
-
|
|
1814
|
-
return parsePoint(this.context.canvas.viewport2Canvas(viewportPoint));
|
|
1819
|
+
return this.context.canvas.getClientByCanvas(point);
|
|
1815
1820
|
}
|
|
1816
1821
|
|
|
1817
1822
|
/**
|
|
@@ -1823,8 +1828,7 @@ export class Graph extends EventEmitter {
|
|
|
1823
1828
|
* @apiCategory viewport
|
|
1824
1829
|
*/
|
|
1825
1830
|
public getCanvasByClient(point: Point): Point {
|
|
1826
|
-
|
|
1827
|
-
return parsePoint(this.context.canvas.viewport2Canvas(viewportPoint));
|
|
1831
|
+
return this.context.canvas.getCanvasByClient(point);
|
|
1828
1832
|
}
|
|
1829
1833
|
|
|
1830
1834
|
/**
|
package/src/runtime/viewport.ts
CHANGED
|
@@ -142,15 +142,16 @@ export class ViewportController {
|
|
|
142
142
|
|
|
143
143
|
const _animation = this.getAnimation(animation);
|
|
144
144
|
|
|
145
|
+
emit(graph, new ViewportEvent(GraphEvent.BEFORE_TRANSFORM, options));
|
|
146
|
+
|
|
145
147
|
// 针对缩放操作,且不涉及平移、旋转、中心点、动画时,直接调用 setZoomByViewportPoint
|
|
146
148
|
// For zoom operations, and no translation, rotation, center point, and animation involved, call setZoomByViewportPoint directly
|
|
147
149
|
if (!rotate && scale && !translate && origin && !_animation) {
|
|
148
150
|
this.camera.setZoomByViewportPoint(this.getZoomOptions(options), origin as Vector2);
|
|
151
|
+
emit(graph, new ViewportEvent(GraphEvent.AFTER_TRANSFORM, options));
|
|
149
152
|
return;
|
|
150
153
|
}
|
|
151
154
|
|
|
152
|
-
emit(graph, new ViewportEvent(GraphEvent.BEFORE_TRANSFORM, options));
|
|
153
|
-
|
|
154
155
|
const landmarkOptions: Parameters<typeof this.camera.createLandmark>[1] = {};
|
|
155
156
|
if (translate) Object.assign(landmarkOptions, this.getTranslateOptions(options));
|
|
156
157
|
if (isNumber(rotate)) Object.assign(landmarkOptions, this.getRotateOptions(options));
|
package/src/utils/bbox.ts
CHANGED
|
@@ -117,6 +117,27 @@ export function isPointInBBox(point: Point, bbox: AABB) {
|
|
|
117
117
|
return isBetween(point[0], bbox.min[0], bbox.max[0]) && isBetween(point[1], bbox.min[1], bbox.max[1]);
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
+
/**
|
|
121
|
+
* <zh/> 判断点是否在给定的包围盒的边界或边界的延长线上
|
|
122
|
+
*
|
|
123
|
+
* <en/> Whether the point is on the boundary or extension line of the given box
|
|
124
|
+
* @param point - <zh/> 点 | <en/> Point
|
|
125
|
+
* @param bbox - <zh/> 包围盒 | <en/> Bounding box
|
|
126
|
+
* @param extended - <zh/> 是否判断边界的延长线 | <en/> Whether to judge the extension line of the boundary
|
|
127
|
+
* @returns <zh/> 如果点在包围盒的边界或边界的延长线上返回 true,否则返回 false | <en/> Returns true if the point is on the boundary or extension line of the bounding box, false otherwise
|
|
128
|
+
*/
|
|
129
|
+
export function isPointOnBBoxBoundary(point: Point, bbox: AABB, extended = false): boolean {
|
|
130
|
+
const {
|
|
131
|
+
min: [minX, minY],
|
|
132
|
+
max: [maxX, maxY],
|
|
133
|
+
} = bbox;
|
|
134
|
+
|
|
135
|
+
const onTopOrBottomLine = (point[1] === minY || point[1] === maxY) && (extended || isBetween(point[0], minX, maxX));
|
|
136
|
+
const onLeftOrRightLine = (point[0] === minX || point[0] === maxX) && (extended || isBetween(point[1], minY, maxY));
|
|
137
|
+
|
|
138
|
+
return onTopOrBottomLine || onLeftOrRightLine;
|
|
139
|
+
}
|
|
140
|
+
|
|
120
141
|
/**
|
|
121
142
|
* <zh/> 判断点是否在给定的包围盒外
|
|
122
143
|
*
|
package/src/utils/router/orth.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
getNearestPointToPoint,
|
|
9
9
|
getNodeBBox,
|
|
10
10
|
isPointInBBox,
|
|
11
|
+
isPointOnBBoxBoundary,
|
|
11
12
|
isPointOutsideBBox,
|
|
12
13
|
} from '../bbox';
|
|
13
14
|
import { isOrthogonal, moveTo, round } from '../point';
|
|
@@ -199,7 +200,8 @@ export function pointToNode(from: Point, to: Point, toBBox: AABB, direction: Dir
|
|
|
199
200
|
[to[0], from[1]],
|
|
200
201
|
[from[0], to[1]],
|
|
201
202
|
];
|
|
202
|
-
const freePoints = points.filter((p) => isPointOutsideBBox(p, toBBox));
|
|
203
|
+
const freePoints = points.filter((p) => isPointOutsideBBox(p, toBBox) && !isPointOnBBoxBoundary(p, toBBox, true));
|
|
204
|
+
|
|
203
205
|
const freeDirectionPoints = freePoints.filter((p) => getDirection(p, from) !== direction);
|
|
204
206
|
|
|
205
207
|
if (freeDirectionPoints.length > 0) {
|
|
@@ -243,8 +245,8 @@ export function nodeToNode(from: Point, to: Point, fromBBox: AABB, toBBox: AABB)
|
|
|
243
245
|
const p2 = toVector3(route.points[0]);
|
|
244
246
|
|
|
245
247
|
if (isPointInBBox(p2, fromBBox)) {
|
|
246
|
-
const fromBorder = moveTo(from,
|
|
247
|
-
const toBorder = moveTo(to,
|
|
248
|
+
const fromBorder = moveTo(from, p1, getBBoxSize(fromBBox, getDirection(from, p1)) / 2);
|
|
249
|
+
const toBorder = moveTo(to, p2, getBBoxSize(toBBox, getDirection(to, p2)) / 2);
|
|
248
250
|
const midPoint: Point = [(fromBorder[0] + toBorder[0]) / 2, (fromBorder[1] + toBorder[1]) / 2];
|
|
249
251
|
|
|
250
252
|
const startRoute = nodeToPoint(from, midPoint, fromBBox);
|
package/src/utils/visibility.ts
CHANGED
|
@@ -10,13 +10,20 @@ const PropertyKey = 'visibility';
|
|
|
10
10
|
* <en/> Set the visibility of the shape instance
|
|
11
11
|
* @param shape - <zh/> 图形实例 | <en/> shape instance
|
|
12
12
|
* @param visibility - <zh/> 可见性 | <en/> visibility
|
|
13
|
+
* @param filter - <zh/> 筛选出需要设置可见性的图形 | <en/> Filter out the shapes that need to set visibility
|
|
13
14
|
* @remarks
|
|
14
15
|
* <zh/> 在设置 enableCSSParsing 为 false 的情况下,复合图形无法继承父属性,因此需要对所有子图形应用相同的可见性
|
|
15
16
|
*
|
|
16
17
|
* <en/> After setting enableCSSParsing to false, the compound shape cannot inherit the parent attribute, so the same visibility needs to be applied to all child shapes
|
|
17
18
|
*/
|
|
18
|
-
export function setVisibility(
|
|
19
|
-
|
|
19
|
+
export function setVisibility(
|
|
20
|
+
shape: DisplayObject,
|
|
21
|
+
visibility: BaseStyleProps['visibility'],
|
|
22
|
+
filter?: (shapes: DisplayObject[]) => DisplayObject[],
|
|
23
|
+
) {
|
|
24
|
+
let shapes = [shape, ...getDescendantShapes(shape)];
|
|
25
|
+
|
|
26
|
+
if (filter) shapes = filter?.(shapes);
|
|
20
27
|
|
|
21
28
|
shapes.forEach((sp) => {
|
|
22
29
|
if (!hasCachedStyle(sp, PropertyKey)) cacheStyle(sp, PropertyKey);
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.0.
|
|
1
|
+
export const version = '5.0.10';
|