@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.
Files changed (177) 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/elements/base-element.d.ts +5 -4
  4. package/dist/lib/plugins/fullscreen/index.d.ts +2 -0
  5. package/dist/lib/registry/index.d.ts +5 -1
  6. package/dist/lib/runtime/animation.d.ts +7 -0
  7. package/dist/lib/runtime/canvas.d.ts +27 -39
  8. package/dist/lib/runtime/element.d.ts +1 -1
  9. package/dist/lib/runtime/graph.d.ts +1 -17
  10. package/dist/lib/utils/print.d.ts +15 -0
  11. package/dist/lib/utils/shortcut.d.ts +1 -0
  12. package/dist/lib/utils/state.d.ts +9 -0
  13. package/dist/lib/version.d.ts +1 -1
  14. package/esm/behaviors/brush-select.js +1 -2
  15. package/esm/behaviors/brush-select.js.map +1 -1
  16. package/esm/behaviors/click-select.d.ts +8 -16
  17. package/esm/behaviors/click-select.js +108 -90
  18. package/esm/behaviors/click-select.js.map +1 -1
  19. package/esm/behaviors/drag-element-force.js +2 -1
  20. package/esm/behaviors/drag-element-force.js.map +1 -1
  21. package/esm/behaviors/drag-element.js +1 -2
  22. package/esm/behaviors/drag-element.js.map +1 -1
  23. package/esm/elements/base-element.d.ts +5 -4
  24. package/esm/elements/base-element.js +3 -0
  25. package/esm/elements/base-element.js.map +1 -1
  26. package/esm/elements/combos/base-combo.js +2 -2
  27. package/esm/elements/combos/base-combo.js.map +1 -1
  28. package/esm/elements/nodes/html.js +3 -5
  29. package/esm/elements/nodes/html.js.map +1 -1
  30. package/esm/elements/shapes/base-shape.js +27 -3
  31. package/esm/elements/shapes/base-shape.js.map +1 -1
  32. package/esm/plugins/contextmenu/index.js +1 -0
  33. package/esm/plugins/contextmenu/index.js.map +1 -1
  34. package/esm/plugins/fullscreen/index.d.ts +2 -0
  35. package/esm/plugins/fullscreen/index.js +15 -2
  36. package/esm/plugins/fullscreen/index.js.map +1 -1
  37. package/esm/registry/extension/index.js +2 -1
  38. package/esm/registry/extension/index.js.map +1 -1
  39. package/esm/registry/index.d.ts +5 -1
  40. package/esm/registry/index.js +8 -3
  41. package/esm/registry/index.js.map +1 -1
  42. package/esm/runtime/animation.d.ts +7 -0
  43. package/esm/runtime/animation.js +17 -0
  44. package/esm/runtime/animation.js.map +1 -1
  45. package/esm/runtime/canvas.d.ts +27 -39
  46. package/esm/runtime/canvas.js +128 -175
  47. package/esm/runtime/canvas.js.map +1 -1
  48. package/esm/runtime/data.js +4 -3
  49. package/esm/runtime/data.js.map +1 -1
  50. package/esm/runtime/element.d.ts +1 -1
  51. package/esm/runtime/element.js +2 -1
  52. package/esm/runtime/element.js.map +1 -1
  53. package/esm/runtime/graph.d.ts +1 -17
  54. package/esm/runtime/graph.js +8 -34
  55. package/esm/runtime/graph.js.map +1 -1
  56. package/esm/runtime/layout.js +5 -2
  57. package/esm/runtime/layout.js.map +1 -1
  58. package/esm/runtime/viewport.js +1 -1
  59. package/esm/runtime/viewport.js.map +1 -1
  60. package/esm/utils/animation.js +9 -3
  61. package/esm/utils/animation.js.map +1 -1
  62. package/esm/utils/id.js +2 -1
  63. package/esm/utils/id.js.map +1 -1
  64. package/esm/utils/layout.js +9 -1
  65. package/esm/utils/layout.js.map +1 -1
  66. package/esm/utils/palette.js +2 -1
  67. package/esm/utils/palette.js.map +1 -1
  68. package/esm/utils/print.d.ts +15 -0
  69. package/esm/utils/print.js +28 -0
  70. package/esm/utils/print.js.map +1 -0
  71. package/esm/utils/shortcut.d.ts +1 -0
  72. package/esm/utils/shortcut.js +7 -0
  73. package/esm/utils/shortcut.js.map +1 -1
  74. package/esm/utils/state.d.ts +9 -0
  75. package/esm/utils/state.js +11 -0
  76. package/esm/utils/state.js.map +1 -0
  77. package/esm/utils/theme.js +5 -1
  78. package/esm/utils/theme.js.map +1 -1
  79. package/esm/version.d.ts +1 -1
  80. package/esm/version.js +1 -1
  81. package/lib/behaviors/brush-select.js +1 -2
  82. package/lib/behaviors/brush-select.js.map +1 -1
  83. package/lib/behaviors/click-select.d.ts +8 -16
  84. package/lib/behaviors/click-select.js +106 -88
  85. package/lib/behaviors/click-select.js.map +1 -1
  86. package/lib/behaviors/drag-element-force.js +2 -1
  87. package/lib/behaviors/drag-element-force.js.map +1 -1
  88. package/lib/behaviors/drag-element.js +1 -2
  89. package/lib/behaviors/drag-element.js.map +1 -1
  90. package/lib/elements/base-element.d.ts +5 -4
  91. package/lib/elements/base-element.js +3 -0
  92. package/lib/elements/base-element.js.map +1 -1
  93. package/lib/elements/combos/base-combo.js +2 -2
  94. package/lib/elements/combos/base-combo.js.map +1 -1
  95. package/lib/elements/nodes/html.js +3 -5
  96. package/lib/elements/nodes/html.js.map +1 -1
  97. package/lib/elements/shapes/base-shape.js +27 -3
  98. package/lib/elements/shapes/base-shape.js.map +1 -1
  99. package/lib/plugins/contextmenu/index.js +1 -0
  100. package/lib/plugins/contextmenu/index.js.map +1 -1
  101. package/lib/plugins/fullscreen/index.d.ts +2 -0
  102. package/lib/plugins/fullscreen/index.js +15 -2
  103. package/lib/plugins/fullscreen/index.js.map +1 -1
  104. package/lib/registry/extension/index.js +2 -1
  105. package/lib/registry/extension/index.js.map +1 -1
  106. package/lib/registry/index.d.ts +5 -1
  107. package/lib/registry/index.js +8 -3
  108. package/lib/registry/index.js.map +1 -1
  109. package/lib/runtime/animation.d.ts +7 -0
  110. package/lib/runtime/animation.js +17 -0
  111. package/lib/runtime/animation.js.map +1 -1
  112. package/lib/runtime/canvas.d.ts +27 -39
  113. package/lib/runtime/canvas.js +127 -174
  114. package/lib/runtime/canvas.js.map +1 -1
  115. package/lib/runtime/data.js +4 -3
  116. package/lib/runtime/data.js.map +1 -1
  117. package/lib/runtime/element.d.ts +1 -1
  118. package/lib/runtime/element.js +2 -1
  119. package/lib/runtime/element.js.map +1 -1
  120. package/lib/runtime/graph.d.ts +1 -17
  121. package/lib/runtime/graph.js +8 -34
  122. package/lib/runtime/graph.js.map +1 -1
  123. package/lib/runtime/layout.js +5 -2
  124. package/lib/runtime/layout.js.map +1 -1
  125. package/lib/runtime/viewport.js +1 -1
  126. package/lib/runtime/viewport.js.map +1 -1
  127. package/lib/utils/animation.js +8 -2
  128. package/lib/utils/animation.js.map +1 -1
  129. package/lib/utils/id.js +2 -1
  130. package/lib/utils/id.js.map +1 -1
  131. package/lib/utils/layout.js +9 -1
  132. package/lib/utils/layout.js.map +1 -1
  133. package/lib/utils/palette.js +2 -1
  134. package/lib/utils/palette.js.map +1 -1
  135. package/lib/utils/print.d.ts +15 -0
  136. package/lib/utils/print.js +32 -0
  137. package/lib/utils/print.js.map +1 -0
  138. package/lib/utils/shortcut.d.ts +1 -0
  139. package/lib/utils/shortcut.js +7 -0
  140. package/lib/utils/shortcut.js.map +1 -1
  141. package/lib/utils/state.d.ts +9 -0
  142. package/lib/utils/state.js +14 -0
  143. package/lib/utils/state.js.map +1 -0
  144. package/lib/utils/theme.js +5 -1
  145. package/lib/utils/theme.js.map +1 -1
  146. package/lib/version.d.ts +1 -1
  147. package/lib/version.js +1 -1
  148. package/package.json +8 -8
  149. package/src/behaviors/brush-select.ts +1 -2
  150. package/src/behaviors/click-select.ts +117 -88
  151. package/src/behaviors/drag-element-force.ts +2 -1
  152. package/src/behaviors/drag-element.ts +1 -2
  153. package/src/elements/base-element.ts +8 -4
  154. package/src/elements/combos/base-combo.ts +2 -2
  155. package/src/elements/nodes/html.ts +3 -7
  156. package/src/elements/shapes/base-shape.ts +30 -3
  157. package/src/global.d.ts +12 -0
  158. package/src/plugins/contextmenu/index.ts +1 -0
  159. package/src/plugins/fullscreen/index.ts +18 -2
  160. package/src/registry/extension/index.ts +2 -1
  161. package/src/registry/index.ts +8 -2
  162. package/src/runtime/animation.ts +21 -0
  163. package/src/runtime/canvas.ts +140 -209
  164. package/src/runtime/data.ts +4 -3
  165. package/src/runtime/element.ts +3 -2
  166. package/src/runtime/graph.ts +8 -38
  167. package/src/runtime/layout.ts +5 -2
  168. package/src/runtime/viewport.ts +2 -2
  169. package/src/utils/animation.ts +9 -2
  170. package/src/utils/id.ts +2 -1
  171. package/src/utils/layout.ts +7 -1
  172. package/src/utils/palette.ts +2 -1
  173. package/src/utils/print.ts +30 -0
  174. package/src/utils/shortcut.ts +9 -0
  175. package/src/utils/state.ts +12 -0
  176. package/src/utils/theme.ts +6 -1
  177. package/src/version.ts +1 -1
@@ -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(scale, origin as Vector2);
148
+ this.camera.setZoomByViewportPoint(this.getZoomOptions(options), origin as Vector2);
149
149
  return;
150
150
  }
151
151
 
@@ -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],
@@ -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.7';
1
+ export const version = '5.0.8';