@antv/g6 5.0.6 → 5.0.8
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/click-select.d.ts +8 -16
- package/dist/lib/behaviors/drag-canvas.d.ts +4 -0
- package/dist/lib/elements/base-element.d.ts +5 -4
- package/dist/lib/plugins/fullscreen/index.d.ts +2 -0
- package/dist/lib/registry/index.d.ts +5 -1
- package/dist/lib/runtime/animation.d.ts +7 -0
- package/dist/lib/runtime/canvas.d.ts +27 -38
- package/dist/lib/runtime/element.d.ts +1 -1
- package/dist/lib/runtime/graph.d.ts +1 -17
- package/dist/lib/runtime/viewport.d.ts +1 -0
- package/dist/lib/types/point.d.ts +5 -0
- package/dist/lib/utils/point.d.ts +4 -4
- package/dist/lib/utils/print.d.ts +15 -0
- package/dist/lib/utils/shortcut.d.ts +1 -0
- package/dist/lib/utils/state.d.ts +9 -0
- package/dist/lib/version.d.ts +1 -1
- package/esm/behaviors/brush-select.js +1 -2
- package/esm/behaviors/brush-select.js.map +1 -1
- package/esm/behaviors/click-select.d.ts +8 -16
- package/esm/behaviors/click-select.js +108 -90
- package/esm/behaviors/click-select.js.map +1 -1
- package/esm/behaviors/drag-canvas.d.ts +4 -0
- package/esm/behaviors/drag-canvas.js +29 -9
- package/esm/behaviors/drag-canvas.js.map +1 -1
- package/esm/behaviors/drag-element-force.js +2 -1
- package/esm/behaviors/drag-element-force.js.map +1 -1
- package/esm/behaviors/drag-element.js +1 -2
- package/esm/behaviors/drag-element.js.map +1 -1
- package/esm/behaviors/zoom-canvas.js.map +1 -1
- package/esm/elements/base-element.d.ts +5 -4
- package/esm/elements/base-element.js +3 -0
- package/esm/elements/base-element.js.map +1 -1
- package/esm/elements/combos/base-combo.js +2 -2
- package/esm/elements/combos/base-combo.js.map +1 -1
- package/esm/elements/nodes/html.js +3 -5
- package/esm/elements/nodes/html.js.map +1 -1
- package/esm/elements/shapes/base-shape.js +27 -3
- package/esm/elements/shapes/base-shape.js.map +1 -1
- package/esm/plugins/contextmenu/index.js +5 -2
- package/esm/plugins/contextmenu/index.js.map +1 -1
- package/esm/plugins/fullscreen/index.d.ts +2 -0
- package/esm/plugins/fullscreen/index.js +15 -2
- package/esm/plugins/fullscreen/index.js.map +1 -1
- package/esm/registry/extension/index.js +2 -1
- package/esm/registry/extension/index.js.map +1 -1
- package/esm/registry/index.d.ts +5 -1
- package/esm/registry/index.js +8 -3
- package/esm/registry/index.js.map +1 -1
- package/esm/runtime/animation.d.ts +7 -0
- package/esm/runtime/animation.js +17 -0
- package/esm/runtime/animation.js.map +1 -1
- package/esm/runtime/canvas.d.ts +27 -38
- package/esm/runtime/canvas.js +128 -175
- package/esm/runtime/canvas.js.map +1 -1
- package/esm/runtime/data.js +4 -3
- package/esm/runtime/data.js.map +1 -1
- package/esm/runtime/element.d.ts +1 -1
- package/esm/runtime/element.js +2 -1
- package/esm/runtime/element.js.map +1 -1
- package/esm/runtime/graph.d.ts +1 -17
- package/esm/runtime/graph.js +8 -34
- package/esm/runtime/graph.js.map +1 -1
- package/esm/runtime/layout.js +5 -2
- package/esm/runtime/layout.js.map +1 -1
- package/esm/runtime/viewport.d.ts +1 -0
- package/esm/runtime/viewport.js +13 -3
- package/esm/runtime/viewport.js.map +1 -1
- package/esm/types/point.d.ts +5 -0
- package/esm/utils/animation.js +9 -3
- package/esm/utils/animation.js.map +1 -1
- package/esm/utils/id.js +2 -1
- package/esm/utils/id.js.map +1 -1
- package/esm/utils/layout.js +9 -1
- package/esm/utils/layout.js.map +1 -1
- package/esm/utils/palette.js +2 -1
- package/esm/utils/palette.js.map +1 -1
- package/esm/utils/point.d.ts +4 -4
- package/esm/utils/point.js +2 -2
- package/esm/utils/point.js.map +1 -1
- package/esm/utils/print.d.ts +15 -0
- package/esm/utils/print.js +28 -0
- package/esm/utils/print.js.map +1 -0
- package/esm/utils/shortcut.d.ts +1 -0
- package/esm/utils/shortcut.js +7 -0
- package/esm/utils/shortcut.js.map +1 -1
- package/esm/utils/state.d.ts +9 -0
- package/esm/utils/state.js +11 -0
- package/esm/utils/state.js.map +1 -0
- package/esm/utils/theme.js +5 -1
- package/esm/utils/theme.js.map +1 -1
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/lib/behaviors/brush-select.js +1 -2
- package/lib/behaviors/brush-select.js.map +1 -1
- package/lib/behaviors/click-select.d.ts +8 -16
- package/lib/behaviors/click-select.js +106 -88
- package/lib/behaviors/click-select.js.map +1 -1
- package/lib/behaviors/drag-canvas.d.ts +4 -0
- package/lib/behaviors/drag-canvas.js +28 -8
- package/lib/behaviors/drag-canvas.js.map +1 -1
- package/lib/behaviors/drag-element-force.js +2 -1
- package/lib/behaviors/drag-element-force.js.map +1 -1
- package/lib/behaviors/drag-element.js +1 -2
- package/lib/behaviors/drag-element.js.map +1 -1
- package/lib/behaviors/zoom-canvas.js.map +1 -1
- package/lib/elements/base-element.d.ts +5 -4
- package/lib/elements/base-element.js +3 -0
- package/lib/elements/base-element.js.map +1 -1
- package/lib/elements/combos/base-combo.js +2 -2
- package/lib/elements/combos/base-combo.js.map +1 -1
- package/lib/elements/nodes/html.js +3 -5
- package/lib/elements/nodes/html.js.map +1 -1
- package/lib/elements/shapes/base-shape.js +27 -3
- package/lib/elements/shapes/base-shape.js.map +1 -1
- package/lib/plugins/contextmenu/index.js +5 -2
- package/lib/plugins/contextmenu/index.js.map +1 -1
- package/lib/plugins/fullscreen/index.d.ts +2 -0
- package/lib/plugins/fullscreen/index.js +15 -2
- package/lib/plugins/fullscreen/index.js.map +1 -1
- package/lib/registry/extension/index.js +2 -1
- package/lib/registry/extension/index.js.map +1 -1
- package/lib/registry/index.d.ts +5 -1
- package/lib/registry/index.js +8 -3
- package/lib/registry/index.js.map +1 -1
- package/lib/runtime/animation.d.ts +7 -0
- package/lib/runtime/animation.js +17 -0
- package/lib/runtime/animation.js.map +1 -1
- package/lib/runtime/canvas.d.ts +27 -38
- package/lib/runtime/canvas.js +127 -174
- package/lib/runtime/canvas.js.map +1 -1
- package/lib/runtime/data.js +4 -3
- package/lib/runtime/data.js.map +1 -1
- package/lib/runtime/element.d.ts +1 -1
- package/lib/runtime/element.js +2 -1
- package/lib/runtime/element.js.map +1 -1
- package/lib/runtime/graph.d.ts +1 -17
- package/lib/runtime/graph.js +8 -34
- package/lib/runtime/graph.js.map +1 -1
- package/lib/runtime/layout.js +5 -2
- package/lib/runtime/layout.js.map +1 -1
- package/lib/runtime/viewport.d.ts +1 -0
- package/lib/runtime/viewport.js +13 -3
- package/lib/runtime/viewport.js.map +1 -1
- package/lib/types/point.d.ts +5 -0
- package/lib/utils/animation.js +8 -2
- package/lib/utils/animation.js.map +1 -1
- package/lib/utils/id.js +2 -1
- package/lib/utils/id.js.map +1 -1
- package/lib/utils/layout.js +9 -1
- package/lib/utils/layout.js.map +1 -1
- package/lib/utils/palette.js +2 -1
- package/lib/utils/palette.js.map +1 -1
- package/lib/utils/point.d.ts +4 -4
- package/lib/utils/point.js +2 -2
- package/lib/utils/point.js.map +1 -1
- package/lib/utils/print.d.ts +15 -0
- package/lib/utils/print.js +32 -0
- package/lib/utils/print.js.map +1 -0
- package/lib/utils/shortcut.d.ts +1 -0
- package/lib/utils/shortcut.js +7 -0
- package/lib/utils/shortcut.js.map +1 -1
- package/lib/utils/state.d.ts +9 -0
- package/lib/utils/state.js +14 -0
- package/lib/utils/state.js.map +1 -0
- package/lib/utils/theme.js +5 -1
- package/lib/utils/theme.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +8 -8
- package/src/behaviors/brush-select.ts +1 -2
- package/src/behaviors/click-select.ts +117 -88
- package/src/behaviors/drag-canvas.ts +32 -9
- package/src/behaviors/drag-element-force.ts +2 -1
- package/src/behaviors/drag-element.ts +1 -2
- package/src/behaviors/zoom-canvas.ts +2 -3
- package/src/elements/base-element.ts +8 -4
- package/src/elements/combos/base-combo.ts +2 -2
- package/src/elements/nodes/html.ts +3 -7
- package/src/elements/shapes/base-shape.ts +30 -3
- package/src/global.d.ts +12 -0
- package/src/plugins/contextmenu/index.ts +5 -2
- package/src/plugins/fullscreen/index.ts +18 -2
- package/src/registry/extension/index.ts +2 -1
- package/src/registry/index.ts +8 -2
- package/src/runtime/animation.ts +21 -0
- package/src/runtime/canvas.ts +140 -208
- package/src/runtime/data.ts +4 -3
- package/src/runtime/element.ts +3 -2
- package/src/runtime/graph.ts +8 -38
- package/src/runtime/layout.ts +5 -2
- package/src/runtime/viewport.ts +18 -5
- package/src/types/point.ts +6 -0
- package/src/utils/animation.ts +9 -2
- package/src/utils/id.ts +2 -1
- package/src/utils/layout.ts +7 -1
- package/src/utils/palette.ts +2 -1
- package/src/utils/point.ts +6 -6
- package/src/utils/print.ts +30 -0
- package/src/utils/shortcut.ts +9 -0
- package/src/utils/state.ts +12 -0
- package/src/utils/theme.ts +6 -1
- package/src/version.ts +1 -1
package/src/runtime/graph.ts
CHANGED
|
@@ -3,7 +3,6 @@ import type { AABB, BaseStyleProps } from '@antv/g';
|
|
|
3
3
|
import { debounce, isEqual, isFunction, isNumber, isObject, isString, omit } from '@antv/util';
|
|
4
4
|
import { COMBO_KEY, GraphEvent } from '../constants';
|
|
5
5
|
import type { Plugin } from '../plugins/types';
|
|
6
|
-
import { getExtension } from '../registry';
|
|
7
6
|
import type {
|
|
8
7
|
BehaviorOptions,
|
|
9
8
|
ComboData,
|
|
@@ -45,6 +44,7 @@ import { sizeOf } from '../utils/dom';
|
|
|
45
44
|
import { GraphLifeCycleEvent, emit } from '../utils/event';
|
|
46
45
|
import { idOf } from '../utils/id';
|
|
47
46
|
import { parsePoint, toPointObject } from '../utils/point';
|
|
47
|
+
import { format } from '../utils/print';
|
|
48
48
|
import { subtract } from '../utils/vector';
|
|
49
49
|
import { Animation } from './animation';
|
|
50
50
|
import { BatchController } from './batch';
|
|
@@ -118,12 +118,10 @@ export class Graph extends EventEmitter {
|
|
|
118
118
|
* @apiCategory option
|
|
119
119
|
*/
|
|
120
120
|
public setOptions(options: GraphOptions): void {
|
|
121
|
-
const {
|
|
122
|
-
options;
|
|
121
|
+
const { behaviors, combo, data, edge, height, layout, node, plugins, theme, transforms, width, renderer } = options;
|
|
123
122
|
|
|
124
123
|
Object.assign(this.options, options);
|
|
125
124
|
|
|
126
|
-
if (background) this.setBackground(background);
|
|
127
125
|
if (behaviors) this.setBehaviors(behaviors);
|
|
128
126
|
if (combo) this.setCombo(combo);
|
|
129
127
|
if (data) this.setData(data);
|
|
@@ -135,29 +133,7 @@ export class Graph extends EventEmitter {
|
|
|
135
133
|
if (transforms) this.setTransforms(transforms);
|
|
136
134
|
if (isNumber(width) || isNumber(height))
|
|
137
135
|
this.setSize(width ?? this.options.width ?? 0, height ?? this.options.height ?? 0);
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* <zh/> 设置画布背景色
|
|
142
|
-
*
|
|
143
|
-
* <en/> Set canvas background color
|
|
144
|
-
* @param background - <zh/> 背景色 | <en/> background color
|
|
145
|
-
* @apiCategory canvas
|
|
146
|
-
*/
|
|
147
|
-
public setBackground(background: GraphOptions['background']): void {
|
|
148
|
-
this.options.background = background;
|
|
149
|
-
this.context.canvas?.setBackground(background);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* <zh/> 获取画布背景色
|
|
154
|
-
*
|
|
155
|
-
* <en/> Get canvas background color
|
|
156
|
-
* @returns <zh/> 背景色 | <en/> background color
|
|
157
|
-
* @apiCategory canvas
|
|
158
|
-
*/
|
|
159
|
-
public getBackground(): GraphOptions['background'] {
|
|
160
|
-
return this.options.background;
|
|
136
|
+
if (renderer) this.context.canvas.setRenderer(renderer);
|
|
161
137
|
}
|
|
162
138
|
|
|
163
139
|
/**
|
|
@@ -279,11 +255,6 @@ export class Graph extends EventEmitter {
|
|
|
279
255
|
*/
|
|
280
256
|
public setTheme(theme: ThemeOptions | ((prev: ThemeOptions) => ThemeOptions)): void {
|
|
281
257
|
this.options.theme = isFunction(theme) ? theme(this.getTheme()) : theme;
|
|
282
|
-
|
|
283
|
-
const { background } = getExtension('theme', this.options.theme) || {};
|
|
284
|
-
if (background && !this.options.background) {
|
|
285
|
-
this.setBackground(background);
|
|
286
|
-
}
|
|
287
258
|
}
|
|
288
259
|
|
|
289
260
|
/**
|
|
@@ -512,7 +483,7 @@ export class Graph extends EventEmitter {
|
|
|
512
483
|
* <en/> Get the data of the current graph, including node, edge, and combo data
|
|
513
484
|
* @apiCategory data
|
|
514
485
|
*/
|
|
515
|
-
public getData(): GraphData {
|
|
486
|
+
public getData(): Required<GraphData> {
|
|
516
487
|
return this.context.model.getData();
|
|
517
488
|
}
|
|
518
489
|
|
|
@@ -1033,14 +1004,13 @@ export class Graph extends EventEmitter {
|
|
|
1033
1004
|
}
|
|
1034
1005
|
|
|
1035
1006
|
private async initCanvas() {
|
|
1036
|
-
if (this.context.canvas) return await this.context.canvas.
|
|
1007
|
+
if (this.context.canvas) return await this.context.canvas.ready;
|
|
1037
1008
|
|
|
1038
1009
|
const { container = 'container', width, height, renderer, background } = this.options;
|
|
1039
1010
|
|
|
1040
1011
|
if (container instanceof Canvas) {
|
|
1041
1012
|
this.context.canvas = container;
|
|
1042
|
-
container.
|
|
1043
|
-
await container.init();
|
|
1013
|
+
await container.ready;
|
|
1044
1014
|
} else {
|
|
1045
1015
|
const $container = isString(container) ? document.getElementById(container!) : container;
|
|
1046
1016
|
const containerSize = sizeOf($container!);
|
|
@@ -1056,7 +1026,7 @@ export class Graph extends EventEmitter {
|
|
|
1056
1026
|
});
|
|
1057
1027
|
|
|
1058
1028
|
this.context.canvas = canvas;
|
|
1059
|
-
await canvas.
|
|
1029
|
+
await canvas.ready;
|
|
1060
1030
|
this.emit(GraphEvent.AFTER_CANVAS_INIT, { canvas });
|
|
1061
1031
|
}
|
|
1062
1032
|
}
|
|
@@ -1078,7 +1048,7 @@ export class Graph extends EventEmitter {
|
|
|
1078
1048
|
// Wait for synchronous tasks to complete, to avoid problems caused by calling destroy immediately after render
|
|
1079
1049
|
await Promise.resolve();
|
|
1080
1050
|
|
|
1081
|
-
if (this.destroyed) throw new Error('
|
|
1051
|
+
if (this.destroyed) throw new Error(format('The graph instance has been destroyed'));
|
|
1082
1052
|
|
|
1083
1053
|
await this.initCanvas();
|
|
1084
1054
|
this.initRuntime();
|
package/src/runtime/layout.ts
CHANGED
|
@@ -15,6 +15,7 @@ import { GraphLifeCycleEvent, emit } from '../utils/event';
|
|
|
15
15
|
import { createTreeStructure } from '../utils/graphlib';
|
|
16
16
|
import { idOf } from '../utils/id';
|
|
17
17
|
import { isTreeLayout, layoutAdapter, layoutMapping2GraphData } from '../utils/layout';
|
|
18
|
+
import { print } from '../utils/print';
|
|
18
19
|
import { parseSize } from '../utils/size';
|
|
19
20
|
import { dfs } from '../utils/traverse';
|
|
20
21
|
import type { RuntimeContext } from './types';
|
|
@@ -103,6 +104,8 @@ export class LayoutController {
|
|
|
103
104
|
const { animation, enableWorker, iterations = 300 } = options;
|
|
104
105
|
|
|
105
106
|
const layout = this.initGraphLayout(options);
|
|
107
|
+
if (!layout) return {};
|
|
108
|
+
|
|
106
109
|
this.instances[index] = layout;
|
|
107
110
|
this.instance = layout;
|
|
108
111
|
|
|
@@ -142,7 +145,7 @@ export class LayoutController {
|
|
|
142
145
|
// @ts-expect-error @antv/hierarchy 布局格式与 @antv/layout 不一致,其导出的是一个方法,而非 class
|
|
143
146
|
// The layout format of @antv/hierarchy is inconsistent with @antv/layout, it exports a method instead of a class
|
|
144
147
|
const layout = getExtension('layout', type) as (tree: TreeData, options: STDLayoutOptions) => TreeData;
|
|
145
|
-
if (!layout)
|
|
148
|
+
if (!layout) return {};
|
|
146
149
|
|
|
147
150
|
const { nodes = [], edges = [] } = data;
|
|
148
151
|
|
|
@@ -256,7 +259,7 @@ export class LayoutController {
|
|
|
256
259
|
});
|
|
257
260
|
|
|
258
261
|
const Ctor = getExtension('layout', type);
|
|
259
|
-
if (!Ctor)
|
|
262
|
+
if (!Ctor) return print.warn(`The layout of ${type} is not registered.`);
|
|
260
263
|
|
|
261
264
|
const STDCtor =
|
|
262
265
|
Object.getPrototypeOf(Ctor.prototype) === BaseLayout.prototype
|
package/src/runtime/viewport.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AABB } from '@antv/g';
|
|
2
2
|
import { clamp, isNumber, pick } from '@antv/util';
|
|
3
3
|
import { AnimationType, GraphEvent } from '../constants';
|
|
4
|
-
import type { FitViewOptions, ID, Point, TransformOptions, ViewportAnimationEffectTiming } from '../types';
|
|
4
|
+
import type { FitViewOptions, ID, Point, TransformOptions, Vector2, ViewportAnimationEffectTiming } from '../types';
|
|
5
5
|
import { getAnimationOptions } from '../utils/animation';
|
|
6
6
|
import { getBBoxSize, getCombinedBBox } from '../utils/bbox';
|
|
7
7
|
import { AnimateEvent, ViewportEvent, emit } from '../utils/event';
|
|
@@ -133,14 +133,24 @@ export class ViewportController {
|
|
|
133
133
|
return clamp(mode === 'relative' ? currentZoom * scale : scale, ...zoomRange!);
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
|
|
136
|
+
private transformResolver?: () => void;
|
|
137
|
+
|
|
138
|
+
public async transform(options: TransformOptions, animation?: ViewportAnimationEffectTiming): Promise<void> {
|
|
137
139
|
const { graph } = this.context;
|
|
138
|
-
const { translate, rotate, scale } = options;
|
|
140
|
+
const { translate, rotate, scale, origin } = options;
|
|
139
141
|
this.cancelAnimation();
|
|
140
142
|
|
|
141
|
-
emit(graph, new ViewportEvent(GraphEvent.BEFORE_TRANSFORM, options));
|
|
142
143
|
const _animation = this.getAnimation(animation);
|
|
143
144
|
|
|
145
|
+
// 针对缩放操作,且不涉及平移、旋转、中心点、动画时,直接调用 setZoomByViewportPoint
|
|
146
|
+
// For zoom operations, and no translation, rotation, center point, and animation involved, call setZoomByViewportPoint directly
|
|
147
|
+
if (!rotate && scale && !translate && origin && !_animation) {
|
|
148
|
+
this.camera.setZoomByViewportPoint(this.getZoomOptions(options), origin as Vector2);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
emit(graph, new ViewportEvent(GraphEvent.BEFORE_TRANSFORM, options));
|
|
153
|
+
|
|
144
154
|
const landmarkOptions: Parameters<typeof this.camera.createLandmark>[1] = {};
|
|
145
155
|
if (translate) Object.assign(landmarkOptions, this.getTranslateOptions(options));
|
|
146
156
|
if (isNumber(rotate)) Object.assign(landmarkOptions, this.getRotateOptions(options));
|
|
@@ -150,11 +160,13 @@ export class ViewportController {
|
|
|
150
160
|
emit(graph, new AnimateEvent(GraphEvent.BEFORE_ANIMATE, AnimationType.TRANSFORM, null, options));
|
|
151
161
|
|
|
152
162
|
return new Promise<void>((resolve) => {
|
|
163
|
+
this.transformResolver = resolve;
|
|
153
164
|
this.camera.gotoLandmark(this.createLandmark(landmarkOptions), {
|
|
154
165
|
..._animation,
|
|
155
166
|
onfinish: () => {
|
|
156
167
|
emit(graph, new AnimateEvent(GraphEvent.AFTER_ANIMATE, AnimationType.TRANSFORM, null, options));
|
|
157
168
|
emit(graph, new ViewportEvent(GraphEvent.AFTER_TRANSFORM, options));
|
|
169
|
+
this.transformResolver = undefined;
|
|
158
170
|
resolve();
|
|
159
171
|
},
|
|
160
172
|
});
|
|
@@ -218,7 +230,7 @@ export class ViewportController {
|
|
|
218
230
|
}
|
|
219
231
|
|
|
220
232
|
private async focus(bbox: AABB, animation?: ViewportAnimationEffectTiming) {
|
|
221
|
-
const
|
|
233
|
+
const center = this.context.graph.getViewportByCanvas(bbox.center);
|
|
222
234
|
const canvasCenter = this.getCanvasCenter();
|
|
223
235
|
const delta = subtract(canvasCenter, center);
|
|
224
236
|
await this.transform({ mode: 'relative', translate: add(delta, this.paddingOffset) }, animation);
|
|
@@ -247,5 +259,6 @@ export class ViewportController {
|
|
|
247
259
|
if (this.camera.landmarks?.length) {
|
|
248
260
|
this.camera.cancelLandmarkAnimation();
|
|
249
261
|
}
|
|
262
|
+
this.transformResolver?.();
|
|
250
263
|
}
|
|
251
264
|
}
|
package/src/types/point.ts
CHANGED
package/src/utils/animation.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { IAnimation } from '@antv/g';
|
|
2
|
-
import { isEqual, isNil, isObject
|
|
2
|
+
import { isEqual, isNil, isObject } from '@antv/util';
|
|
3
3
|
import type { AnimationEffectTiming, AnimationOptions, STDAnimation } from '../animations/types';
|
|
4
4
|
import { DEFAULT_ANIMATION_OPTIONS, DEFAULT_ELEMENTS_ANIMATION_OPTIONS, ExtensionCategory } from '../constants';
|
|
5
5
|
import { getExtension } from '../registry';
|
|
6
6
|
import type { GraphOptions } from '../spec';
|
|
7
7
|
import type { AnimationStage } from '../spec/element/animation';
|
|
8
8
|
import type { ElementType, Keyframe } from '../types';
|
|
9
|
+
import { print } from './print';
|
|
9
10
|
import { themeOf } from './theme';
|
|
10
11
|
|
|
11
12
|
export function createAnimationsProxy(animations: IAnimation[]): IAnimation | null;
|
|
@@ -161,7 +162,13 @@ export function getAnimationOptions(
|
|
|
161
162
|
* @returns <zh/> 动画配置 | <en/> animation configuration
|
|
162
163
|
*/
|
|
163
164
|
function animationOf(options: string | AnimationOptions[]): STDAnimation {
|
|
164
|
-
if (
|
|
165
|
+
if (typeof options === 'string') {
|
|
166
|
+
const animation = getExtension(ExtensionCategory.ANIMATION, options);
|
|
167
|
+
if (animation) return animation;
|
|
168
|
+
|
|
169
|
+
print.warn(`The animation of ${options} is not registered.`);
|
|
170
|
+
return [];
|
|
171
|
+
}
|
|
165
172
|
return options;
|
|
166
173
|
}
|
|
167
174
|
|
package/src/utils/id.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ComboData, EdgeData, GraphData, NodeData } from '../spec';
|
|
2
2
|
import type { DataID, ID } from '../types';
|
|
3
|
+
import { format } from './print';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* <zh/> 获取节点/边/Combo 的 ID
|
|
@@ -12,7 +13,7 @@ export function idOf(data: Partial<NodeData | EdgeData | ComboData>): ID {
|
|
|
12
13
|
if (data.id !== undefined) return data.id;
|
|
13
14
|
if (data.source !== undefined && data.target !== undefined) return `${data.source}-${data.target}`;
|
|
14
15
|
|
|
15
|
-
throw new Error('The
|
|
16
|
+
throw new Error(format('The datum does not have available id.'));
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
/**
|
package/src/utils/layout.ts
CHANGED
|
@@ -148,7 +148,7 @@ export function layoutAdapter(
|
|
|
148
148
|
const nodesToLayout: LayoutNodeData[] = nodes.map((datum) => {
|
|
149
149
|
const id = idOf(datum);
|
|
150
150
|
const { data, style, combo } = datum;
|
|
151
|
-
|
|
151
|
+
const result = {
|
|
152
152
|
id,
|
|
153
153
|
data: {
|
|
154
154
|
...data,
|
|
@@ -158,6 +158,12 @@ export function layoutAdapter(
|
|
|
158
158
|
},
|
|
159
159
|
style: { ...style },
|
|
160
160
|
};
|
|
161
|
+
// 一些布局会从 data 中读取位置信息
|
|
162
|
+
if (style?.x) Object.assign(result.data, { x: style.x });
|
|
163
|
+
if (style?.y) Object.assign(result.data, { y: style.y });
|
|
164
|
+
if (style?.z) Object.assign(result.data, { z: style.z });
|
|
165
|
+
|
|
166
|
+
return result;
|
|
161
167
|
});
|
|
162
168
|
const nodesIdMap = new Map(nodesToLayout.map((node) => [node.id, node]));
|
|
163
169
|
|
package/src/utils/palette.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { PaletteOptions, STDPaletteOptions } from '../spec/element/palette'
|
|
|
5
5
|
import type { ID } from '../types';
|
|
6
6
|
import type { ElementData, ElementDatum } from '../types/data';
|
|
7
7
|
import { idOf } from './id';
|
|
8
|
+
import { format } from './print';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* <zh/> 解析色板配置
|
|
@@ -99,7 +100,7 @@ export function assignColorByPalette(data: ElementData, palette?: STDPaletteOpti
|
|
|
99
100
|
const [min, max] = data.reduce(
|
|
100
101
|
([min, max], datum) => {
|
|
101
102
|
const value = parseField(field, datum);
|
|
102
|
-
if (typeof value !== 'number') throw new Error(`Palette field ${field} is not a number`);
|
|
103
|
+
if (typeof value !== 'number') throw new Error(format(`Palette field ${field} is not a number`));
|
|
103
104
|
return [Math.min(min, value), Math.max(max, value)];
|
|
104
105
|
},
|
|
105
106
|
[Infinity, -Infinity],
|
package/src/utils/point.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AABB
|
|
2
|
-
import type { Point } from '../types';
|
|
1
|
+
import type { AABB } from '@antv/g';
|
|
2
|
+
import type { Point, PointObject } from '../types';
|
|
3
3
|
import { getBBoxHeight, getBBoxWidth } from './bbox';
|
|
4
4
|
import type { LineSegment } from './line';
|
|
5
5
|
import { getLinesIntersection, isLinesParallel } from './line';
|
|
@@ -12,8 +12,8 @@ import { add, distance, divide, normalize, subtract, toVector2 } from './vector'
|
|
|
12
12
|
* @param point - <zh/> 对象坐标 | <en/> object coordinates
|
|
13
13
|
* @returns <zh/> 数组坐标 | <en/> array coordinates
|
|
14
14
|
*/
|
|
15
|
-
export function parsePoint(point:
|
|
16
|
-
return [point.x, point.y];
|
|
15
|
+
export function parsePoint(point: PointObject): Point {
|
|
16
|
+
return [point.x, point.y, point.z ?? 0];
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -23,8 +23,8 @@ export function parsePoint(point: PointLike): Point {
|
|
|
23
23
|
* @param point - <zh/> 数组坐标 | <en/> array coordinates
|
|
24
24
|
* @returns <zh/> 对象坐标 | <en/> object coordinates
|
|
25
25
|
*/
|
|
26
|
-
export function toPointObject(point: Point):
|
|
27
|
-
return { x: point[0], y: point[1] };
|
|
26
|
+
export function toPointObject(point: Point): PointObject {
|
|
27
|
+
return { x: point[0], y: point[1], z: point[2] ?? 0 };
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
/**
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { version } from '../version';
|
|
2
|
+
|
|
3
|
+
const BRAND = 'G6';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* <zh/> 格式化打印
|
|
7
|
+
*
|
|
8
|
+
* <en/> Format print
|
|
9
|
+
* @param message - <zh/> 消息 | <en/> Message
|
|
10
|
+
* @returns <zh/> 格式化后的消息 | <en/> Formatted message
|
|
11
|
+
*/
|
|
12
|
+
export function format(message: string) {
|
|
13
|
+
return `[${BRAND} v${version}] ${message}`;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const print = {
|
|
17
|
+
mute: false,
|
|
18
|
+
debug: (message: string): void => {
|
|
19
|
+
!print.mute && console.debug(format(message));
|
|
20
|
+
},
|
|
21
|
+
info: (message: string): void => {
|
|
22
|
+
!print.mute && console.info(format(message));
|
|
23
|
+
},
|
|
24
|
+
warn: (message: string): void => {
|
|
25
|
+
!print.mute && console.warn(format(message));
|
|
26
|
+
},
|
|
27
|
+
error: (message: string): void => {
|
|
28
|
+
!print.mute && console.error(format(message));
|
|
29
|
+
},
|
|
30
|
+
};
|
package/src/utils/shortcut.ts
CHANGED
|
@@ -54,6 +54,10 @@ export class Shortcut {
|
|
|
54
54
|
emitter.on(CommonEvent.KEY_UP, this.onKeyUp);
|
|
55
55
|
emitter.on(CommonEvent.WHEEL, this.onWheel);
|
|
56
56
|
emitter.on(CommonEvent.DRAG, this.onDrag);
|
|
57
|
+
|
|
58
|
+
// 窗口重新获得焦点后清空按键,避免按键状态异常
|
|
59
|
+
// Clear the keys when the window regains focus to avoid abnormal key states
|
|
60
|
+
window.addEventListener('focus', this.onFocus);
|
|
57
61
|
}
|
|
58
62
|
|
|
59
63
|
private onKeyDown = (event: KeyboardEvent) => {
|
|
@@ -103,11 +107,16 @@ export class Shortcut {
|
|
|
103
107
|
this.triggerExtendKey(CommonEvent.DRAG, event);
|
|
104
108
|
};
|
|
105
109
|
|
|
110
|
+
private onFocus = () => {
|
|
111
|
+
this.recordKey.clear();
|
|
112
|
+
};
|
|
113
|
+
|
|
106
114
|
public destroy() {
|
|
107
115
|
this.unbindAll();
|
|
108
116
|
this.emitter.off(CommonEvent.KEY_DOWN, this.onKeyDown);
|
|
109
117
|
this.emitter.off(CommonEvent.KEY_UP, this.onKeyUp);
|
|
110
118
|
this.emitter.off(CommonEvent.WHEEL, this.onWheel);
|
|
111
119
|
this.emitter.off(CommonEvent.DRAG, this.onDrag);
|
|
120
|
+
window.removeEventListener('blur', this.onFocus);
|
|
112
121
|
}
|
|
113
122
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ElementDatum } from '../types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* <zh/> 获取元素的状态
|
|
5
|
+
*
|
|
6
|
+
* <en/> Get the state of the element
|
|
7
|
+
* @param datum - <zh/> 元素数据 <en/> Element data
|
|
8
|
+
* @returns <zh/> 状态列表 <en/> State list
|
|
9
|
+
*/
|
|
10
|
+
export function statesOf(datum: ElementDatum) {
|
|
11
|
+
return datum.states || [];
|
|
12
|
+
}
|
package/src/utils/theme.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ExtensionCategory } from '../constants';
|
|
2
2
|
import { getExtension } from '../registry';
|
|
3
3
|
import type { GraphOptions } from '../spec';
|
|
4
|
+
import { print } from './print';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* <zh/> 获取主题配置
|
|
@@ -14,5 +15,9 @@ export function themeOf(options: GraphOptions) {
|
|
|
14
15
|
if (!theme) return {};
|
|
15
16
|
|
|
16
17
|
const themeOptions = getExtension(ExtensionCategory.THEME, theme);
|
|
17
|
-
|
|
18
|
+
|
|
19
|
+
if (themeOptions) return themeOptions;
|
|
20
|
+
|
|
21
|
+
print.warn(`The theme of ${theme} is not registered.`);
|
|
22
|
+
return {};
|
|
18
23
|
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.0.
|
|
1
|
+
export const version = '5.0.8';
|