@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.
Files changed (203) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/dist/lib/behaviors/click-select.d.ts +8 -16
  3. package/dist/lib/behaviors/drag-canvas.d.ts +4 -0
  4. package/dist/lib/elements/base-element.d.ts +5 -4
  5. package/dist/lib/plugins/fullscreen/index.d.ts +2 -0
  6. package/dist/lib/registry/index.d.ts +5 -1
  7. package/dist/lib/runtime/animation.d.ts +7 -0
  8. package/dist/lib/runtime/canvas.d.ts +27 -38
  9. package/dist/lib/runtime/element.d.ts +1 -1
  10. package/dist/lib/runtime/graph.d.ts +1 -17
  11. package/dist/lib/runtime/viewport.d.ts +1 -0
  12. package/dist/lib/types/point.d.ts +5 -0
  13. package/dist/lib/utils/point.d.ts +4 -4
  14. package/dist/lib/utils/print.d.ts +15 -0
  15. package/dist/lib/utils/shortcut.d.ts +1 -0
  16. package/dist/lib/utils/state.d.ts +9 -0
  17. package/dist/lib/version.d.ts +1 -1
  18. package/esm/behaviors/brush-select.js +1 -2
  19. package/esm/behaviors/brush-select.js.map +1 -1
  20. package/esm/behaviors/click-select.d.ts +8 -16
  21. package/esm/behaviors/click-select.js +108 -90
  22. package/esm/behaviors/click-select.js.map +1 -1
  23. package/esm/behaviors/drag-canvas.d.ts +4 -0
  24. package/esm/behaviors/drag-canvas.js +29 -9
  25. package/esm/behaviors/drag-canvas.js.map +1 -1
  26. package/esm/behaviors/drag-element-force.js +2 -1
  27. package/esm/behaviors/drag-element-force.js.map +1 -1
  28. package/esm/behaviors/drag-element.js +1 -2
  29. package/esm/behaviors/drag-element.js.map +1 -1
  30. package/esm/behaviors/zoom-canvas.js.map +1 -1
  31. package/esm/elements/base-element.d.ts +5 -4
  32. package/esm/elements/base-element.js +3 -0
  33. package/esm/elements/base-element.js.map +1 -1
  34. package/esm/elements/combos/base-combo.js +2 -2
  35. package/esm/elements/combos/base-combo.js.map +1 -1
  36. package/esm/elements/nodes/html.js +3 -5
  37. package/esm/elements/nodes/html.js.map +1 -1
  38. package/esm/elements/shapes/base-shape.js +27 -3
  39. package/esm/elements/shapes/base-shape.js.map +1 -1
  40. package/esm/plugins/contextmenu/index.js +5 -2
  41. package/esm/plugins/contextmenu/index.js.map +1 -1
  42. package/esm/plugins/fullscreen/index.d.ts +2 -0
  43. package/esm/plugins/fullscreen/index.js +15 -2
  44. package/esm/plugins/fullscreen/index.js.map +1 -1
  45. package/esm/registry/extension/index.js +2 -1
  46. package/esm/registry/extension/index.js.map +1 -1
  47. package/esm/registry/index.d.ts +5 -1
  48. package/esm/registry/index.js +8 -3
  49. package/esm/registry/index.js.map +1 -1
  50. package/esm/runtime/animation.d.ts +7 -0
  51. package/esm/runtime/animation.js +17 -0
  52. package/esm/runtime/animation.js.map +1 -1
  53. package/esm/runtime/canvas.d.ts +27 -38
  54. package/esm/runtime/canvas.js +128 -175
  55. package/esm/runtime/canvas.js.map +1 -1
  56. package/esm/runtime/data.js +4 -3
  57. package/esm/runtime/data.js.map +1 -1
  58. package/esm/runtime/element.d.ts +1 -1
  59. package/esm/runtime/element.js +2 -1
  60. package/esm/runtime/element.js.map +1 -1
  61. package/esm/runtime/graph.d.ts +1 -17
  62. package/esm/runtime/graph.js +8 -34
  63. package/esm/runtime/graph.js.map +1 -1
  64. package/esm/runtime/layout.js +5 -2
  65. package/esm/runtime/layout.js.map +1 -1
  66. package/esm/runtime/viewport.d.ts +1 -0
  67. package/esm/runtime/viewport.js +13 -3
  68. package/esm/runtime/viewport.js.map +1 -1
  69. package/esm/types/point.d.ts +5 -0
  70. package/esm/utils/animation.js +9 -3
  71. package/esm/utils/animation.js.map +1 -1
  72. package/esm/utils/id.js +2 -1
  73. package/esm/utils/id.js.map +1 -1
  74. package/esm/utils/layout.js +9 -1
  75. package/esm/utils/layout.js.map +1 -1
  76. package/esm/utils/palette.js +2 -1
  77. package/esm/utils/palette.js.map +1 -1
  78. package/esm/utils/point.d.ts +4 -4
  79. package/esm/utils/point.js +2 -2
  80. package/esm/utils/point.js.map +1 -1
  81. package/esm/utils/print.d.ts +15 -0
  82. package/esm/utils/print.js +28 -0
  83. package/esm/utils/print.js.map +1 -0
  84. package/esm/utils/shortcut.d.ts +1 -0
  85. package/esm/utils/shortcut.js +7 -0
  86. package/esm/utils/shortcut.js.map +1 -1
  87. package/esm/utils/state.d.ts +9 -0
  88. package/esm/utils/state.js +11 -0
  89. package/esm/utils/state.js.map +1 -0
  90. package/esm/utils/theme.js +5 -1
  91. package/esm/utils/theme.js.map +1 -1
  92. package/esm/version.d.ts +1 -1
  93. package/esm/version.js +1 -1
  94. package/lib/behaviors/brush-select.js +1 -2
  95. package/lib/behaviors/brush-select.js.map +1 -1
  96. package/lib/behaviors/click-select.d.ts +8 -16
  97. package/lib/behaviors/click-select.js +106 -88
  98. package/lib/behaviors/click-select.js.map +1 -1
  99. package/lib/behaviors/drag-canvas.d.ts +4 -0
  100. package/lib/behaviors/drag-canvas.js +28 -8
  101. package/lib/behaviors/drag-canvas.js.map +1 -1
  102. package/lib/behaviors/drag-element-force.js +2 -1
  103. package/lib/behaviors/drag-element-force.js.map +1 -1
  104. package/lib/behaviors/drag-element.js +1 -2
  105. package/lib/behaviors/drag-element.js.map +1 -1
  106. package/lib/behaviors/zoom-canvas.js.map +1 -1
  107. package/lib/elements/base-element.d.ts +5 -4
  108. package/lib/elements/base-element.js +3 -0
  109. package/lib/elements/base-element.js.map +1 -1
  110. package/lib/elements/combos/base-combo.js +2 -2
  111. package/lib/elements/combos/base-combo.js.map +1 -1
  112. package/lib/elements/nodes/html.js +3 -5
  113. package/lib/elements/nodes/html.js.map +1 -1
  114. package/lib/elements/shapes/base-shape.js +27 -3
  115. package/lib/elements/shapes/base-shape.js.map +1 -1
  116. package/lib/plugins/contextmenu/index.js +5 -2
  117. package/lib/plugins/contextmenu/index.js.map +1 -1
  118. package/lib/plugins/fullscreen/index.d.ts +2 -0
  119. package/lib/plugins/fullscreen/index.js +15 -2
  120. package/lib/plugins/fullscreen/index.js.map +1 -1
  121. package/lib/registry/extension/index.js +2 -1
  122. package/lib/registry/extension/index.js.map +1 -1
  123. package/lib/registry/index.d.ts +5 -1
  124. package/lib/registry/index.js +8 -3
  125. package/lib/registry/index.js.map +1 -1
  126. package/lib/runtime/animation.d.ts +7 -0
  127. package/lib/runtime/animation.js +17 -0
  128. package/lib/runtime/animation.js.map +1 -1
  129. package/lib/runtime/canvas.d.ts +27 -38
  130. package/lib/runtime/canvas.js +127 -174
  131. package/lib/runtime/canvas.js.map +1 -1
  132. package/lib/runtime/data.js +4 -3
  133. package/lib/runtime/data.js.map +1 -1
  134. package/lib/runtime/element.d.ts +1 -1
  135. package/lib/runtime/element.js +2 -1
  136. package/lib/runtime/element.js.map +1 -1
  137. package/lib/runtime/graph.d.ts +1 -17
  138. package/lib/runtime/graph.js +8 -34
  139. package/lib/runtime/graph.js.map +1 -1
  140. package/lib/runtime/layout.js +5 -2
  141. package/lib/runtime/layout.js.map +1 -1
  142. package/lib/runtime/viewport.d.ts +1 -0
  143. package/lib/runtime/viewport.js +13 -3
  144. package/lib/runtime/viewport.js.map +1 -1
  145. package/lib/types/point.d.ts +5 -0
  146. package/lib/utils/animation.js +8 -2
  147. package/lib/utils/animation.js.map +1 -1
  148. package/lib/utils/id.js +2 -1
  149. package/lib/utils/id.js.map +1 -1
  150. package/lib/utils/layout.js +9 -1
  151. package/lib/utils/layout.js.map +1 -1
  152. package/lib/utils/palette.js +2 -1
  153. package/lib/utils/palette.js.map +1 -1
  154. package/lib/utils/point.d.ts +4 -4
  155. package/lib/utils/point.js +2 -2
  156. package/lib/utils/point.js.map +1 -1
  157. package/lib/utils/print.d.ts +15 -0
  158. package/lib/utils/print.js +32 -0
  159. package/lib/utils/print.js.map +1 -0
  160. package/lib/utils/shortcut.d.ts +1 -0
  161. package/lib/utils/shortcut.js +7 -0
  162. package/lib/utils/shortcut.js.map +1 -1
  163. package/lib/utils/state.d.ts +9 -0
  164. package/lib/utils/state.js +14 -0
  165. package/lib/utils/state.js.map +1 -0
  166. package/lib/utils/theme.js +5 -1
  167. package/lib/utils/theme.js.map +1 -1
  168. package/lib/version.d.ts +1 -1
  169. package/lib/version.js +1 -1
  170. package/package.json +8 -8
  171. package/src/behaviors/brush-select.ts +1 -2
  172. package/src/behaviors/click-select.ts +117 -88
  173. package/src/behaviors/drag-canvas.ts +32 -9
  174. package/src/behaviors/drag-element-force.ts +2 -1
  175. package/src/behaviors/drag-element.ts +1 -2
  176. package/src/behaviors/zoom-canvas.ts +2 -3
  177. package/src/elements/base-element.ts +8 -4
  178. package/src/elements/combos/base-combo.ts +2 -2
  179. package/src/elements/nodes/html.ts +3 -7
  180. package/src/elements/shapes/base-shape.ts +30 -3
  181. package/src/global.d.ts +12 -0
  182. package/src/plugins/contextmenu/index.ts +5 -2
  183. package/src/plugins/fullscreen/index.ts +18 -2
  184. package/src/registry/extension/index.ts +2 -1
  185. package/src/registry/index.ts +8 -2
  186. package/src/runtime/animation.ts +21 -0
  187. package/src/runtime/canvas.ts +140 -208
  188. package/src/runtime/data.ts +4 -3
  189. package/src/runtime/element.ts +3 -2
  190. package/src/runtime/graph.ts +8 -38
  191. package/src/runtime/layout.ts +5 -2
  192. package/src/runtime/viewport.ts +18 -5
  193. package/src/types/point.ts +6 -0
  194. package/src/utils/animation.ts +9 -2
  195. package/src/utils/id.ts +2 -1
  196. package/src/utils/layout.ts +7 -1
  197. package/src/utils/palette.ts +2 -1
  198. package/src/utils/point.ts +6 -6
  199. package/src/utils/print.ts +30 -0
  200. package/src/utils/shortcut.ts +9 -0
  201. package/src/utils/state.ts +12 -0
  202. package/src/utils/theme.ts +6 -1
  203. package/src/version.ts +1 -1
@@ -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 { background, behaviors, combo, data, edge, height, layout, node, plugins, theme, transforms, width } =
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.init();
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.setBackground(background);
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.init();
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('Graph has been destroyed');
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();
@@ -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) throw new Error(`The layout type ${type} is not found`);
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) throw new Error(`The layout type ${type} is not found`);
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
@@ -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
- public async transform(options: TransformOptions, animation?: ViewportAnimationEffectTiming) {
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 { center } = this.getBBoxInViewport(bbox);
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
  }
@@ -1 +1,7 @@
1
1
  export type Point = [number, number] | [number, number, number] | Float32Array;
2
+
3
+ export type PointObject = {
4
+ x: number;
5
+ y: number;
6
+ z?: number;
7
+ };
@@ -1,11 +1,12 @@
1
1
  import type { IAnimation } from '@antv/g';
2
- import { isEqual, isNil, isObject, isString } from '@antv/util';
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 (isString(options)) return getExtension(ExtensionCategory.ANIMATION, options) || [];
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 data does not have available id.');
16
+ throw new Error(format('The datum does not have available id.'));
16
17
  }
17
18
 
18
19
  /**
@@ -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
- return {
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
 
@@ -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],
@@ -1,5 +1,5 @@
1
- import type { AABB, PointLike } from '@antv/g';
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: PointLike): 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): PointLike {
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
+ };
@@ -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
+ }
@@ -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
- return themeOptions ?? {};
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.6';
1
+ export const version = '5.0.8';