@antv/g6 5.0.7 → 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/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 -39
- package/dist/lib/runtime/element.d.ts +1 -1
- package/dist/lib/runtime/graph.d.ts +1 -17
- 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-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/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 +1 -0
- 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 -39
- 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.js +1 -1
- package/esm/runtime/viewport.js.map +1 -1
- 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/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-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/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 +1 -0
- 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 -39
- 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.js +1 -1
- package/lib/runtime/viewport.js.map +1 -1
- 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/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-element-force.ts +2 -1
- package/src/behaviors/drag-element.ts +1 -2
- 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 +1 -0
- 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 -209
- 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 +2 -2
- 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/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/viewport.ts
CHANGED
|
@@ -135,7 +135,7 @@ export class ViewportController {
|
|
|
135
135
|
|
|
136
136
|
private transformResolver?: () => void;
|
|
137
137
|
|
|
138
|
-
public async transform(options: TransformOptions, animation?: ViewportAnimationEffectTiming) {
|
|
138
|
+
public async transform(options: TransformOptions, animation?: ViewportAnimationEffectTiming): Promise<void> {
|
|
139
139
|
const { graph } = this.context;
|
|
140
140
|
const { translate, rotate, scale, origin } = options;
|
|
141
141
|
this.cancelAnimation();
|
|
@@ -145,7 +145,7 @@ export class ViewportController {
|
|
|
145
145
|
// 针对缩放操作,且不涉及平移、旋转、中心点、动画时,直接调用 setZoomByViewportPoint
|
|
146
146
|
// For zoom operations, and no translation, rotation, center point, and animation involved, call setZoomByViewportPoint directly
|
|
147
147
|
if (!rotate && scale && !translate && origin && !_animation) {
|
|
148
|
-
this.camera.setZoomByViewportPoint(
|
|
148
|
+
this.camera.setZoomByViewportPoint(this.getZoomOptions(options), origin as Vector2);
|
|
149
149
|
return;
|
|
150
150
|
}
|
|
151
151
|
|
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],
|
|
@@ -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';
|