@antv/g6 5.0.0-beta.31 → 5.0.0-beta.32

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 (264) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/dist/lib/behaviors/collapse-expand.d.ts +4 -5
  3. package/dist/lib/behaviors/create-edge.d.ts +55 -0
  4. package/dist/lib/behaviors/drag-canvas.d.ts +6 -6
  5. package/dist/lib/behaviors/drag-element.d.ts +5 -3
  6. package/dist/lib/behaviors/focus-element.d.ts +4 -3
  7. package/dist/lib/behaviors/hover-element.d.ts +4 -5
  8. package/dist/lib/behaviors/index.d.ts +2 -0
  9. package/dist/lib/behaviors/zoom-canvas.d.ts +7 -6
  10. package/dist/lib/constants/events/graph.d.ts +5 -13
  11. package/dist/lib/constants/index.d.ts +1 -0
  12. package/dist/lib/constants/registry.d.ts +20 -0
  13. package/dist/lib/elements/combos/base-combo.d.ts +21 -0
  14. package/dist/lib/elements/edges/base-edge.d.ts +21 -0
  15. package/dist/lib/elements/nodes/base-node.d.ts +22 -1
  16. package/dist/lib/exports.d.ts +16 -14
  17. package/dist/lib/plugins/camera-setting.d.ts +95 -0
  18. package/dist/lib/plugins/contextmenu.d.ts +8 -5
  19. package/dist/lib/plugins/index.d.ts +4 -0
  20. package/dist/lib/plugins/legend.d.ts +49 -0
  21. package/dist/lib/plugins/tooltip.d.ts +12 -10
  22. package/dist/lib/registry/extension/index.d.ts +2 -2
  23. package/dist/lib/registry/index.d.ts +6 -4
  24. package/dist/lib/registry/types.d.ts +0 -6
  25. package/dist/lib/runtime/canvas.d.ts +2 -1
  26. package/dist/lib/runtime/data.d.ts +1 -1
  27. package/dist/lib/runtime/element.d.ts +4 -5
  28. package/dist/lib/runtime/graph.d.ts +31 -4
  29. package/dist/lib/runtime/plugin.d.ts +1 -0
  30. package/dist/lib/types/event.d.ts +42 -7
  31. package/dist/lib/types/index.d.ts +0 -1
  32. package/dist/lib/utils/bbox.d.ts +1 -1
  33. package/dist/lib/utils/element.d.ts +19 -11
  34. package/dist/lib/utils/event/events.d.ts +8 -13
  35. package/dist/lib/utils/shortcut.d.ts +10 -0
  36. package/esm/behaviors/collapse-expand.d.ts +4 -5
  37. package/esm/behaviors/collapse-expand.js +8 -4
  38. package/esm/behaviors/collapse-expand.js.map +1 -1
  39. package/esm/behaviors/create-edge.d.ts +55 -0
  40. package/esm/behaviors/create-edge.js +141 -0
  41. package/esm/behaviors/create-edge.js.map +1 -0
  42. package/esm/behaviors/drag-canvas.d.ts +6 -6
  43. package/esm/behaviors/drag-canvas.js +15 -7
  44. package/esm/behaviors/drag-canvas.js.map +1 -1
  45. package/esm/behaviors/drag-element.d.ts +5 -3
  46. package/esm/behaviors/drag-element.js.map +1 -1
  47. package/esm/behaviors/focus-element.d.ts +4 -3
  48. package/esm/behaviors/focus-element.js.map +1 -1
  49. package/esm/behaviors/hover-element.d.ts +4 -5
  50. package/esm/behaviors/hover-element.js.map +1 -1
  51. package/esm/behaviors/index.d.ts +2 -0
  52. package/esm/behaviors/index.js +1 -0
  53. package/esm/behaviors/index.js.map +1 -1
  54. package/esm/behaviors/zoom-canvas.d.ts +7 -6
  55. package/esm/behaviors/zoom-canvas.js +6 -2
  56. package/esm/behaviors/zoom-canvas.js.map +1 -1
  57. package/esm/constants/events/graph.d.ts +5 -13
  58. package/esm/constants/events/graph.js +4 -12
  59. package/esm/constants/events/graph.js.map +1 -1
  60. package/esm/constants/index.d.ts +1 -0
  61. package/esm/constants/index.js +1 -0
  62. package/esm/constants/index.js.map +1 -1
  63. package/esm/constants/registry.d.ts +20 -0
  64. package/esm/constants/registry.js +22 -0
  65. package/esm/constants/registry.js.map +1 -0
  66. package/esm/elements/combos/base-combo.d.ts +21 -0
  67. package/esm/elements/combos/base-combo.js +21 -0
  68. package/esm/elements/combos/base-combo.js.map +1 -1
  69. package/esm/elements/edges/base-edge.d.ts +21 -0
  70. package/esm/elements/edges/base-edge.js +21 -0
  71. package/esm/elements/edges/base-edge.js.map +1 -1
  72. package/esm/elements/nodes/base-node.d.ts +22 -1
  73. package/esm/elements/nodes/base-node.js +21 -0
  74. package/esm/elements/nodes/base-node.js.map +1 -1
  75. package/esm/exports.d.ts +16 -14
  76. package/esm/exports.js +7 -6
  77. package/esm/exports.js.map +1 -1
  78. package/esm/plugins/camera-setting.d.ts +95 -0
  79. package/esm/plugins/camera-setting.js +65 -0
  80. package/esm/plugins/camera-setting.js.map +1 -0
  81. package/esm/plugins/contextmenu.d.ts +8 -5
  82. package/esm/plugins/contextmenu.js.map +1 -1
  83. package/esm/plugins/index.d.ts +4 -0
  84. package/esm/plugins/index.js +2 -0
  85. package/esm/plugins/index.js.map +1 -1
  86. package/esm/plugins/legend.d.ts +49 -0
  87. package/esm/plugins/legend.js +267 -0
  88. package/esm/plugins/legend.js.map +1 -0
  89. package/esm/plugins/tooltip.d.ts +12 -10
  90. package/esm/plugins/tooltip.js +0 -1
  91. package/esm/plugins/tooltip.js.map +1 -1
  92. package/esm/preset.js +2 -5
  93. package/esm/preset.js.map +1 -1
  94. package/esm/registry/build-in.js +4 -2
  95. package/esm/registry/build-in.js.map +1 -1
  96. package/esm/registry/extension/index.d.ts +2 -2
  97. package/esm/registry/extension/index.js.map +1 -1
  98. package/esm/registry/index.d.ts +6 -4
  99. package/esm/registry/index.js.map +1 -1
  100. package/esm/registry/types.d.ts +0 -6
  101. package/esm/runtime/behavior.js +3 -2
  102. package/esm/runtime/behavior.js.map +1 -1
  103. package/esm/runtime/canvas.d.ts +2 -1
  104. package/esm/runtime/canvas.js +68 -30
  105. package/esm/runtime/canvas.js.map +1 -1
  106. package/esm/runtime/data.d.ts +1 -1
  107. package/esm/runtime/element.d.ts +4 -5
  108. package/esm/runtime/element.js +32 -13
  109. package/esm/runtime/element.js.map +1 -1
  110. package/esm/runtime/graph.d.ts +31 -4
  111. package/esm/runtime/graph.js +48 -9
  112. package/esm/runtime/graph.js.map +1 -1
  113. package/esm/runtime/plugin.d.ts +1 -0
  114. package/esm/runtime/plugin.js +3 -0
  115. package/esm/runtime/plugin.js.map +1 -1
  116. package/esm/types/event.d.ts +42 -7
  117. package/esm/types/index.d.ts +0 -1
  118. package/esm/utils/bbox.d.ts +1 -1
  119. package/esm/utils/element.d.ts +19 -11
  120. package/esm/utils/element.js +19 -9
  121. package/esm/utils/element.js.map +1 -1
  122. package/esm/utils/event/events.d.ts +8 -13
  123. package/esm/utils/event/events.js +3 -8
  124. package/esm/utils/event/events.js.map +1 -1
  125. package/esm/utils/shortcut.d.ts +10 -0
  126. package/esm/utils/shortcut.js +24 -3
  127. package/esm/utils/shortcut.js.map +1 -1
  128. package/lib/behaviors/collapse-expand.d.ts +4 -5
  129. package/lib/behaviors/collapse-expand.js +8 -4
  130. package/lib/behaviors/collapse-expand.js.map +1 -1
  131. package/lib/behaviors/create-edge.d.ts +55 -0
  132. package/lib/behaviors/create-edge.js +145 -0
  133. package/lib/behaviors/create-edge.js.map +1 -0
  134. package/lib/behaviors/drag-canvas.d.ts +6 -6
  135. package/lib/behaviors/drag-canvas.js +15 -7
  136. package/lib/behaviors/drag-canvas.js.map +1 -1
  137. package/lib/behaviors/drag-element.d.ts +5 -3
  138. package/lib/behaviors/drag-element.js.map +1 -1
  139. package/lib/behaviors/focus-element.d.ts +4 -3
  140. package/lib/behaviors/focus-element.js.map +1 -1
  141. package/lib/behaviors/hover-element.d.ts +4 -5
  142. package/lib/behaviors/hover-element.js.map +1 -1
  143. package/lib/behaviors/index.d.ts +2 -0
  144. package/lib/behaviors/index.js +3 -1
  145. package/lib/behaviors/index.js.map +1 -1
  146. package/lib/behaviors/zoom-canvas.d.ts +7 -6
  147. package/lib/behaviors/zoom-canvas.js +6 -2
  148. package/lib/behaviors/zoom-canvas.js.map +1 -1
  149. package/lib/constants/events/graph.d.ts +5 -13
  150. package/lib/constants/events/graph.js +4 -12
  151. package/lib/constants/events/graph.js.map +1 -1
  152. package/lib/constants/index.d.ts +1 -0
  153. package/lib/constants/index.js +1 -0
  154. package/lib/constants/index.js.map +1 -1
  155. package/lib/constants/registry.d.ts +20 -0
  156. package/lib/constants/registry.js +25 -0
  157. package/lib/constants/registry.js.map +1 -0
  158. package/lib/elements/combos/base-combo.d.ts +21 -0
  159. package/lib/elements/combos/base-combo.js +21 -0
  160. package/lib/elements/combos/base-combo.js.map +1 -1
  161. package/lib/elements/edges/base-edge.d.ts +21 -0
  162. package/lib/elements/edges/base-edge.js +21 -0
  163. package/lib/elements/edges/base-edge.js.map +1 -1
  164. package/lib/elements/nodes/base-node.d.ts +22 -1
  165. package/lib/elements/nodes/base-node.js +21 -0
  166. package/lib/elements/nodes/base-node.js.map +1 -1
  167. package/lib/exports.d.ts +16 -14
  168. package/lib/exports.js +23 -1
  169. package/lib/exports.js.map +1 -1
  170. package/lib/plugins/camera-setting.d.ts +95 -0
  171. package/lib/plugins/camera-setting.js +69 -0
  172. package/lib/plugins/camera-setting.js.map +1 -0
  173. package/lib/plugins/contextmenu.d.ts +8 -5
  174. package/lib/plugins/contextmenu.js.map +1 -1
  175. package/lib/plugins/index.d.ts +4 -0
  176. package/lib/plugins/index.js +5 -1
  177. package/lib/plugins/index.js.map +1 -1
  178. package/lib/plugins/legend.d.ts +49 -0
  179. package/lib/plugins/legend.js +271 -0
  180. package/lib/plugins/legend.js.map +1 -0
  181. package/lib/plugins/tooltip.d.ts +12 -10
  182. package/lib/plugins/tooltip.js +0 -1
  183. package/lib/plugins/tooltip.js.map +1 -1
  184. package/lib/preset.js +2 -5
  185. package/lib/preset.js.map +1 -1
  186. package/lib/registry/build-in.js +2 -0
  187. package/lib/registry/build-in.js.map +1 -1
  188. package/lib/registry/extension/index.d.ts +2 -2
  189. package/lib/registry/extension/index.js.map +1 -1
  190. package/lib/registry/index.d.ts +6 -4
  191. package/lib/registry/index.js.map +1 -1
  192. package/lib/registry/types.d.ts +0 -6
  193. package/lib/runtime/behavior.js +3 -2
  194. package/lib/runtime/behavior.js.map +1 -1
  195. package/lib/runtime/canvas.d.ts +2 -1
  196. package/lib/runtime/canvas.js +68 -30
  197. package/lib/runtime/canvas.js.map +1 -1
  198. package/lib/runtime/data.d.ts +1 -1
  199. package/lib/runtime/element.d.ts +4 -5
  200. package/lib/runtime/element.js +31 -12
  201. package/lib/runtime/element.js.map +1 -1
  202. package/lib/runtime/graph.d.ts +31 -4
  203. package/lib/runtime/graph.js +47 -8
  204. package/lib/runtime/graph.js.map +1 -1
  205. package/lib/runtime/plugin.d.ts +1 -0
  206. package/lib/runtime/plugin.js +3 -0
  207. package/lib/runtime/plugin.js.map +1 -1
  208. package/lib/types/event.d.ts +42 -7
  209. package/lib/types/index.d.ts +0 -1
  210. package/lib/utils/bbox.d.ts +1 -1
  211. package/lib/utils/element.d.ts +19 -11
  212. package/lib/utils/element.js +21 -10
  213. package/lib/utils/element.js.map +1 -1
  214. package/lib/utils/event/events.d.ts +8 -13
  215. package/lib/utils/event/events.js +4 -10
  216. package/lib/utils/event/events.js.map +1 -1
  217. package/lib/utils/shortcut.d.ts +10 -0
  218. package/lib/utils/shortcut.js +24 -3
  219. package/lib/utils/shortcut.js.map +1 -1
  220. package/package.json +2 -2
  221. package/src/behaviors/collapse-expand.ts +13 -11
  222. package/src/behaviors/create-edge.ts +206 -0
  223. package/src/behaviors/drag-canvas.ts +22 -14
  224. package/src/behaviors/drag-element.ts +8 -11
  225. package/src/behaviors/focus-element.ts +7 -6
  226. package/src/behaviors/hover-element.ts +14 -10
  227. package/src/behaviors/index.ts +2 -0
  228. package/src/behaviors/zoom-canvas.ts +14 -9
  229. package/src/constants/events/graph.ts +4 -12
  230. package/src/constants/index.ts +1 -0
  231. package/src/constants/registry.ts +20 -0
  232. package/src/elements/combos/base-combo.ts +24 -0
  233. package/src/elements/edges/base-edge.ts +25 -1
  234. package/src/elements/nodes/base-node.ts +25 -1
  235. package/src/exports.ts +55 -12
  236. package/src/plugins/camera-setting.ts +153 -0
  237. package/src/plugins/contextmenu.ts +10 -7
  238. package/src/plugins/index.ts +4 -0
  239. package/src/plugins/legend.ts +321 -0
  240. package/src/plugins/tooltip.ts +16 -15
  241. package/src/preset.ts +2 -6
  242. package/src/registry/build-in.ts +12 -2
  243. package/src/registry/extension/index.ts +4 -4
  244. package/src/registry/index.ts +10 -4
  245. package/src/registry/types.ts +0 -7
  246. package/src/runtime/behavior.ts +3 -2
  247. package/src/runtime/canvas.ts +80 -40
  248. package/src/runtime/element.ts +52 -20
  249. package/src/runtime/graph.ts +56 -12
  250. package/src/runtime/plugin.ts +4 -0
  251. package/src/types/event.ts +62 -7
  252. package/src/types/index.ts +0 -1
  253. package/src/utils/bbox.ts +1 -1
  254. package/src/utils/element.ts +22 -11
  255. package/src/utils/event/events.ts +15 -17
  256. package/src/utils/shortcut.ts +28 -3
  257. package/dist/lib/types/behavior.d.ts +0 -5
  258. package/esm/types/behavior.d.ts +0 -5
  259. package/esm/types/behavior.js +0 -2
  260. package/esm/types/behavior.js.map +0 -1
  261. package/lib/types/behavior.d.ts +0 -5
  262. package/lib/types/behavior.js +0 -3
  263. package/lib/types/behavior.js.map +0 -1
  264. package/src/types/behavior.ts +0 -6
@@ -1,8 +1,8 @@
1
- import type { Cursor, FederatedMouseEvent } from '@antv/g';
1
+ import type { Cursor } from '@antv/g';
2
2
  import { isFunction, isObject } from '@antv/util';
3
3
  import { CanvasEvent } from '../constants';
4
- import { RuntimeContext } from '../runtime/types';
5
- import type { BehaviorEvent, Point, ViewportAnimationEffectTiming } from '../types';
4
+ import type { RuntimeContext } from '../runtime/types';
5
+ import type { IKeyboardEvent, IPointerEvent, Vector2, ViewportAnimationEffectTiming } from '../types';
6
6
  import type { ShortcutKey } from '../utils/shortcut';
7
7
  import { Shortcut } from '../utils/shortcut';
8
8
  import { multiply } from '../utils/vector';
@@ -21,7 +21,7 @@ export interface DragCanvasOptions extends BaseBehaviorOptions {
21
21
  *
22
22
  * <en/> Whether to enable the function of dragging the canvas
23
23
  */
24
- enable?: boolean | ((event: BehaviorEvent<FederatedMouseEvent> | BehaviorEvent<KeyboardEvent>) => boolean);
24
+ enable?: boolean | ((event: IPointerEvent | IKeyboardEvent) => boolean);
25
25
  /**
26
26
  * <zh/> 触发拖拽的方式,默认使用指针按下拖拽
27
27
  *
@@ -39,7 +39,7 @@ export interface DragCanvasOptions extends BaseBehaviorOptions {
39
39
  *
40
40
  * <en/> Callback when dragging is completed
41
41
  */
42
- onfinish?: () => void;
42
+ onFinish?: () => void;
43
43
  }
44
44
 
45
45
  type CombinationKey = {
@@ -78,29 +78,36 @@ export class DragCanvas extends BaseBehavior<DragCanvasOptions> {
78
78
  graph.off(CanvasEvent.DRAG, this.onDrag);
79
79
  const { up = [], down = [], left = [], right = [] } = trigger;
80
80
 
81
- this.shortcut.bind(up, (event) => this.translate([0, 1], event));
82
- this.shortcut.bind(down, (event) => this.translate([0, -1], event));
83
- this.shortcut.bind(left, (event) => this.translate([1, 0], event));
84
- this.shortcut.bind(right, (event) => this.translate([-1, 0], event));
81
+ this.shortcut.bind(up, (event) => this.onTranslate([0, 1], event));
82
+ this.shortcut.bind(down, (event) => this.onTranslate([0, -1], event));
83
+ this.shortcut.bind(left, (event) => this.onTranslate([1, 0], event));
84
+ this.shortcut.bind(right, (event) => this.onTranslate([-1, 0], event));
85
85
  } else {
86
86
  graph.on(CanvasEvent.DRAG, this.onDrag);
87
87
  }
88
88
  }
89
89
 
90
- private onDrag = (event: BehaviorEvent<FederatedMouseEvent>) => {
90
+ private onDrag = (event: IPointerEvent) => {
91
+ if (!this.validate(event)) return;
91
92
  if (event.targetType === 'canvas') {
92
- this.context.graph.translateBy([event.movement.x, event.movement.y], false);
93
+ this.translate([event.movement.x, event.movement.y], false);
94
+ this.options.onFinish?.();
93
95
  }
94
96
  };
95
97
 
96
- private translate(value: Point, event: BehaviorEvent<FederatedMouseEvent> | BehaviorEvent<KeyboardEvent>) {
98
+ private async onTranslate(value: Vector2, event: IPointerEvent | IKeyboardEvent) {
97
99
  if (!this.validate(event)) return;
98
100
  const { sensitivity } = this.options;
99
101
  const delta = sensitivity * -1;
100
- this.context.graph.translateBy(multiply(value, delta), this.options.animation);
102
+ await this.translate(multiply(value, delta) as Vector2, this.options.animation);
103
+ this.options.onFinish?.();
104
+ }
105
+
106
+ protected async translate(offset: Vector2, animation?: ViewportAnimationEffectTiming) {
107
+ await this.context.graph.translateBy(offset, animation);
101
108
  }
102
109
 
103
- private validate(event: BehaviorEvent<FederatedMouseEvent> | BehaviorEvent<KeyboardEvent>) {
110
+ private validate(event: IPointerEvent | IKeyboardEvent) {
104
111
  if (this.destroyed) return false;
105
112
  const { enable } = this.options;
106
113
  if (isFunction(enable)) return enable(event);
@@ -108,6 +115,7 @@ export class DragCanvas extends BaseBehavior<DragCanvasOptions> {
108
115
  }
109
116
 
110
117
  public destroy(): void {
118
+ this.shortcut.destroy();
111
119
  this.context.canvas.setCursor(this.defaultCursor);
112
120
  super.destroy();
113
121
  }
@@ -1,10 +1,10 @@
1
- import type { BaseStyleProps, FederatedMouseEvent } from '@antv/g';
1
+ import type { BaseStyleProps } from '@antv/g';
2
2
  import { Rect } from '@antv/g';
3
3
  import { ID } from '@antv/graphlib';
4
4
  import { isFunction } from '@antv/util';
5
5
  import { COMBO_KEY, CommonEvent } from '../constants';
6
6
  import { RuntimeContext } from '../runtime/types';
7
- import type { BehaviorEvent, EdgeDirection, Point, PrefixObject } from '../types';
7
+ import type { EdgeDirection, Element, IDragEvent, Point, PrefixObject } from '../types';
8
8
  import { getBBoxSize, getCombinedBBox } from '../utils/bbox';
9
9
  import { idOf } from '../utils/id';
10
10
  import { subStyleProps } from '../utils/prefix';
@@ -24,7 +24,7 @@ export interface DragElementOptions extends BaseBehaviorOptions, PrefixObject<Ba
24
24
  *
25
25
  * <en/> Whether to enable the function of dragging the node
26
26
  */
27
- enable?: boolean | ((event: BehaviorEvent<FederatedMouseEvent> | BehaviorEvent<KeyboardEvent>) => boolean);
27
+ enable?: boolean | ((event: IElementDragEvent) => boolean);
28
28
  /**
29
29
  * <zh/> 拖拽操作效果
30
30
  * - link: 将拖拽元素置入为目标元素的子元素
@@ -150,7 +150,7 @@ export class DragElement extends BaseBehavior<DragElementOptions> {
150
150
  );
151
151
  }
152
152
 
153
- private onDragStart = (event: DragEvent) => {
153
+ private onDragStart = (event: IElementDragEvent) => {
154
154
  this.enable = this.validate(event);
155
155
  if (!this.enable) return;
156
156
 
@@ -160,7 +160,7 @@ export class DragElement extends BaseBehavior<DragElementOptions> {
160
160
  if (this.options.shadow) this.createShadow(this.target);
161
161
  };
162
162
 
163
- private onDrag = (event: DragEvent) => {
163
+ private onDrag = (event: IElementDragEvent) => {
164
164
  if (!this.enable) return;
165
165
  const zoom = this.context.graph.getZoom();
166
166
  const { dx, dy } = event;
@@ -184,7 +184,7 @@ export class DragElement extends BaseBehavior<DragElementOptions> {
184
184
  this.target = [];
185
185
  };
186
186
 
187
- private onDrop = async (event: DragEvent) => {
187
+ private onDrop = async (event: IElementDragEvent) => {
188
188
  if (this.options.dropEffect !== 'link') return;
189
189
  const { model, element } = this.context;
190
190
  const modifiedParentId = event.target.id;
@@ -200,7 +200,7 @@ export class DragElement extends BaseBehavior<DragElementOptions> {
200
200
  await element?.draw({ animation: true });
201
201
  };
202
202
 
203
- private validate(event: DragEvent) {
203
+ private validate(event: IElementDragEvent) {
204
204
  if (this.destroyed) return false;
205
205
  const { enable } = this.options;
206
206
  if (isFunction(enable)) return enable(event);
@@ -295,7 +295,4 @@ export class DragElement extends BaseBehavior<DragElementOptions> {
295
295
  }
296
296
  }
297
297
 
298
- interface DragEvent extends BehaviorEvent<FederatedMouseEvent> {
299
- dx: number;
300
- dy: number;
301
- }
298
+ type IElementDragEvent = IDragEvent<Element>;
@@ -1,9 +1,8 @@
1
- import type { FederatedMouseEvent } from '@antv/g';
2
1
  import type { ID } from '@antv/graphlib';
3
2
  import { isFunction } from '@antv/util';
4
3
  import { CommonEvent } from '../constants';
5
4
  import type { RuntimeContext } from '../runtime/types';
6
- import type { BehaviorEvent, ViewportAnimationEffectTiming } from '../types';
5
+ import type { Element, IPointerEvent, ViewportAnimationEffectTiming } from '../types';
7
6
  import type { BaseBehaviorOptions } from './base-behavior';
8
7
  import { BaseBehavior } from './base-behavior';
9
8
 
@@ -21,7 +20,7 @@ export interface FocusElementOptions extends BaseBehaviorOptions {
21
20
  *
22
21
  * <en/> Whether to enable the function of dragging the node
23
22
  */
24
- enable?: boolean | ((event: BehaviorEvent<FederatedMouseEvent> | BehaviorEvent<KeyboardEvent>) => boolean);
23
+ enable?: boolean | ((event: IElementEvent) => boolean);
25
24
  }
26
25
 
27
26
  export class FocusElement extends BaseBehavior<FocusElementOptions> {
@@ -58,16 +57,16 @@ export class FocusElement extends BaseBehavior<FocusElementOptions> {
58
57
  );
59
58
  }
60
59
 
61
- private clickFocusElement = async (event: BehaviorEvent<FederatedMouseEvent>) => {
60
+ private clickFocusElement = async (event: IElementEvent) => {
62
61
  if (!this.validate(event)) return;
63
62
  const { animation } = this.options;
64
63
  const { graph } = this.context;
65
- const id = this.getSelectedNodeIDs([event.target.id]);
64
+ const id = this.getSelectedNodeIDs([(event.target as Element).id]);
66
65
 
67
66
  await graph.focusElement(id, animation);
68
67
  };
69
68
 
70
- private validate(event: BehaviorEvent<FederatedMouseEvent>) {
69
+ private validate(event: IElementEvent) {
71
70
  if (this.destroyed) return false;
72
71
  const { enable } = this.options;
73
72
  if (isFunction(enable)) return enable(event);
@@ -87,3 +86,5 @@ export class FocusElement extends BaseBehavior<FocusElementOptions> {
87
86
  super.destroy();
88
87
  }
89
88
  }
89
+
90
+ type IElementEvent = IPointerEvent<Element>;
@@ -1,10 +1,9 @@
1
- import type { FederatedMouseEvent } from '@antv/g';
2
1
  import type { ID } from '@antv/graphlib';
3
2
  import { isFunction } from '@antv/util';
4
3
  import { CommonEvent } from '../constants';
5
4
  import { ELEMENT_TYPES } from '../constants/element';
6
5
  import type { RuntimeContext } from '../runtime/types';
7
- import type { BehaviorEvent, ElementType, State } from '../types';
6
+ import type { Element, ElementType, IPointerEvent, State } from '../types';
8
7
  import { getIds } from '../utils/id';
9
8
  import { getElementNthDegreeIds } from '../utils/relation';
10
9
  import type { BaseBehaviorOptions } from './base-behavior';
@@ -22,7 +21,7 @@ export interface HoverElementOptions extends BaseBehaviorOptions {
22
21
  *
23
22
  * <en/> Whether to enable hover element function
24
23
  */
25
- enable?: boolean | ((event: BehaviorEvent<FederatedMouseEvent>) => boolean);
24
+ enable?: boolean | ((event: IPointerEvent) => boolean);
26
25
  /**
27
26
  * <zh/> 激活元素的n度关系,默认为0,表示只激活当前节点,1表示激活当前节点及其直接相邻的节点和边,以此类推
28
27
  *
@@ -46,13 +45,13 @@ export interface HoverElementOptions extends BaseBehaviorOptions {
46
45
  *
47
46
  * <en/> Callback when the element is hovered
48
47
  */
49
- onHover?: (event: BehaviorEvent<FederatedMouseEvent>) => void;
48
+ onHover?: (event: IPointerEvent) => void;
50
49
  /**
51
50
  * <zh/> 当悬停结束时的回调
52
51
  *
53
52
  * <en/> Callback when the hover ends
54
53
  */
55
- onHoverEnd?: (event: BehaviorEvent<FederatedMouseEvent>) => void;
54
+ onHoverEnd?: (event: IPointerEvent) => void;
56
55
  }
57
56
 
58
57
  export class HoverElement extends BaseBehavior<HoverElementOptions> {
@@ -79,25 +78,30 @@ export class HoverElement extends BaseBehavior<HoverElementOptions> {
79
78
  });
80
79
  }
81
80
 
82
- private hoverElement = (event: BehaviorEvent<FederatedMouseEvent>) => {
81
+ private hoverElement = (event: IPointerEvent) => {
83
82
  if (!this.validate(event)) return;
84
83
  this.updateElementsState(event, true);
85
84
  this.options.onHover?.(event);
86
85
  };
87
86
 
88
- private hoverEndElement = (event: BehaviorEvent<FederatedMouseEvent>) => {
87
+ private hoverEndElement = (event: IPointerEvent) => {
89
88
  if (!this.validate(event)) return;
90
89
  this.updateElementsState(event, false);
91
90
  this.options.onHoverEnd?.(event);
92
91
  };
93
92
 
94
- private updateElementsState = (event: BehaviorEvent<FederatedMouseEvent>, add: boolean) => {
93
+ private updateElementsState = (event: IPointerEvent, add: boolean) => {
95
94
  if (!this.options.activeState && !this.options.inactiveState) return;
96
95
 
97
96
  const { graph } = this.context;
98
97
  const { targetType, target } = event;
99
98
 
100
- const activeIds = getElementNthDegreeIds(graph, targetType as ElementType, target.id, this.options.degree);
99
+ const activeIds = getElementNthDegreeIds(
100
+ graph,
101
+ targetType as ElementType,
102
+ (target as Element).id,
103
+ this.options.degree,
104
+ );
101
105
 
102
106
  const states: Record<ID, State[]> = {};
103
107
 
@@ -124,7 +128,7 @@ export class HoverElement extends BaseBehavior<HoverElementOptions> {
124
128
  return states;
125
129
  };
126
130
 
127
- private validate(event: BehaviorEvent<FederatedMouseEvent>) {
131
+ private validate(event: IPointerEvent) {
128
132
  if (this.destroyed) return false;
129
133
  const { enable } = this.options;
130
134
  if (isFunction(enable)) return enable(event);
@@ -1,5 +1,6 @@
1
1
  export { BaseBehavior } from './base-behavior';
2
2
  export { CollapseExpand } from './collapse-expand';
3
+ export { CreateEdge } from './create-edge';
3
4
  export { DragCanvas } from './drag-canvas';
4
5
  export { DragElement } from './drag-element';
5
6
  export { FocusElement } from './focus-element';
@@ -8,6 +9,7 @@ export { ZoomCanvas } from './zoom-canvas';
8
9
 
9
10
  export type { BaseBehaviorOptions } from './base-behavior';
10
11
  export type { CollapseExpandOptions } from './collapse-expand';
12
+ export type { CreateEdgeOptions } from './create-edge';
11
13
  export type { DragCanvasOptions } from './drag-canvas';
12
14
  export type { DragElementOptions } from './drag-element';
13
15
  export type { FocusElementOptions } from './focus-element';
@@ -2,7 +2,7 @@ import type { PointLike } from '@antv/g';
2
2
  import { clamp, isArray, isFunction, isObject } from '@antv/util';
3
3
  import { CanvasEvent } from '../constants';
4
4
  import type { RuntimeContext } from '../runtime/types';
5
- import type { BehaviorEvent, Point, ViewportAnimationEffectTiming } from '../types';
5
+ import type { IKeyboardEvent, IWheelEvent, Point, ViewportAnimationEffectTiming } from '../types';
6
6
  import { parsePoint } from '../utils/point';
7
7
  import type { ShortcutKey } from '../utils/shortcut';
8
8
  import { Shortcut } from '../utils/shortcut';
@@ -21,7 +21,7 @@ export interface ZoomCanvasOptions extends BaseBehaviorOptions {
21
21
  *
22
22
  * <en/> Whether to enable the function of zooming the canvas
23
23
  */
24
- enable?: boolean | ((event: BehaviorEvent<WheelEvent> | BehaviorEvent<KeyboardEvent>) => boolean);
24
+ enable?: boolean | ((event: IWheelEvent | IKeyboardEvent) => boolean);
25
25
  /**
26
26
  * <zh/> 触发缩放的方式
27
27
  *
@@ -47,7 +47,7 @@ export interface ZoomCanvasOptions extends BaseBehaviorOptions {
47
47
  *
48
48
  * <en/> Callback when zooming is completed
49
49
  */
50
- onfinish?: () => void;
50
+ onFinish?: () => void;
51
51
  }
52
52
 
53
53
  type CombinationKey = {
@@ -107,9 +107,9 @@ export class ZoomCanvas extends BaseBehavior<ZoomCanvasOptions> {
107
107
  * @param event - <zh/> 事件对象 | <en/> Event object
108
108
  * @param animation - <zh/> 缩放动画配置 | <en/> Zoom animation configuration
109
109
  */
110
- private zoom = async (
110
+ protected zoom = async (
111
111
  value: number,
112
- event: BehaviorEvent<WheelEvent> | BehaviorEvent<KeyboardEvent>,
112
+ event: IWheelEvent | IKeyboardEvent,
113
113
  animation: ZoomCanvasOptions['animation'],
114
114
  ) => {
115
115
  if (!this.validate(event)) return;
@@ -120,19 +120,19 @@ export class ZoomCanvas extends BaseBehavior<ZoomCanvasOptions> {
120
120
  origin = parsePoint(event.viewport as PointLike);
121
121
  }
122
122
 
123
- const { sensitivity, onfinish } = this.options;
123
+ const { sensitivity, onFinish } = this.options;
124
124
  const ratio = 1 + (clamp(value, -50, 50) * sensitivity) / 100;
125
125
  const zoom = graph.getZoom();
126
126
  await graph.zoomTo(zoom * ratio, animation, origin);
127
127
 
128
- onfinish?.();
128
+ onFinish?.();
129
129
  };
130
130
 
131
- private onReset = async () => {
131
+ protected onReset = async () => {
132
132
  await this.context.graph.zoomTo(1, this.options.animation);
133
133
  };
134
134
 
135
- private validate(event: BehaviorEvent<WheelEvent> | BehaviorEvent<KeyboardEvent>) {
135
+ protected validate(event: IWheelEvent | IKeyboardEvent) {
136
136
  if (this.destroyed) return false;
137
137
  const { enable } = this.options;
138
138
  if (isFunction(enable)) return enable(event);
@@ -145,4 +145,9 @@ export class ZoomCanvas extends BaseBehavior<ZoomCanvasOptions> {
145
145
  if (!container) return;
146
146
  container.addEventListener(eventName, listener);
147
147
  }
148
+
149
+ public destroy() {
150
+ this.shortcut.destroy();
151
+ super.destroy();
152
+ }
148
153
  }
@@ -1,4 +1,8 @@
1
1
  export enum GraphEvent {
2
+ /** <zh/> 画布初始化之前 | <en/> Before the canvas is initialized */
3
+ BEFORE_CANVAS_INIT = 'beforecanvasinit',
4
+ /** <zh/> 画布初始化之后 | <en/> After the canvas is initialized */
5
+ AFTER_CANVAS_INIT = 'aftercanvasinit',
2
6
  /** <zh/> 视口尺寸变更之前 | <en/> Before the viewport size changes */
3
7
  BEFORE_SIZE_CHANGE = 'beforesizechange',
4
8
  /** <zh/> 视口尺寸变更之后 | <en/> After the viewport size changes */
@@ -39,18 +43,6 @@ export enum GraphEvent {
39
43
  BEFORE_TRANSFORM = 'beforetransform',
40
44
  /** <zh/> 可视区域变化之后 | <en/> After the visible area changes */
41
45
  AFTER_TRANSFORM = 'aftertransform',
42
- /** <zh/> 元素可见性变化之前 | <en/> Before the visibility of the element changes */
43
- BEFORE_ELEMENT_VISIBILITY_CHANGE = 'beforeelementvisibilitychange',
44
- /** <zh/> 元素可见性变化之后 | <en/> After the visibility of the element changes */
45
- AFTER_ELEMENT_VISIBILITY_CHANGE = 'afterelementvisibilitychange',
46
- /** <zh/> 元素层级变化之前 | <en/> Before the layer of the element changes */
47
- BEFORE_ELEMENT_Z_INDEX_CHANGE = 'beforeelementzindexchange',
48
- /** <zh/> 元素层级变化之后 | <en/> After the layer of the element changes */
49
- AFTER_ELEMENT_Z_INDEX_CHANGE = 'afterelementzindexchange',
50
- /** <zh/> 状态变化之前 | <en/> Before the state changes */
51
- BEFORE_ELEMENT_STATE_CHANGE = 'beforeelementstatechange',
52
- /** <zh/> 状态变化之后 | <en/> After the state changes */
53
- AFTER_ELEMENT_STATE_CHANGE = 'afterelementstatechange',
54
46
  }
55
47
 
56
48
  export const enum AnimationTypeEnum {
@@ -2,3 +2,4 @@ export * from './animation';
2
2
  export * from './change';
3
3
  export * from './events';
4
4
  export * from './graphlib';
5
+ export * from './registry';
@@ -0,0 +1,20 @@
1
+ export enum ExtensionCategory {
2
+ /** <zh/> 节点元素 | <en/> Node element */
3
+ NODE = 'node',
4
+ /** <zh/> 边元素 | <en/> Edge element */
5
+ EDGE = 'edge',
6
+ /** <zh/> 组合元素 | <en/> Combination element */
7
+ COMBO = 'combo',
8
+ /** <zh/> 主题 | <en/> Theme */
9
+ THEME = 'theme',
10
+ /** <zh/> 色板 | <en/> Palette */
11
+ PALETTE = 'palette',
12
+ /** <zh/> 布局 | <en/> Layout */
13
+ LAYOUT = 'layout',
14
+ /** <zh/> 交互 | <en/> Behavior */
15
+ BEHAVIOR = 'behavior',
16
+ /** <zh/> 插件 | <en/> Plugin */
17
+ PLUGIN = 'plugin',
18
+ /** <zh/> 动画 | <en/> Animation */
19
+ ANIMATION = 'animation',
20
+ }
@@ -183,4 +183,28 @@ export abstract class BaseCombo<S extends BaseComboStyleProps = BaseComboStylePr
183
183
  // collapsed marker
184
184
  this.drawCollapsedMarkerShape(attributes, container);
185
185
  }
186
+
187
+ /**
188
+ * <zh/> 在元素完成创建并执行完入场动画后调用
189
+ *
190
+ * <en/> Called after the element is created and the entrance animation is completed
191
+ * @override
192
+ */
193
+ public onCreate() {}
194
+
195
+ /**
196
+ * <zh/> 在元素更新并执行完过渡动画后调用
197
+ *
198
+ * <en/> Called after the element is updated and the transition animation is completed
199
+ * @override
200
+ */
201
+ public onUpdate() {}
202
+
203
+ /**
204
+ * <zh/> 在元素完成退场动画并销毁后调用
205
+ *
206
+ * <en/> Called after the element completes the exit animation and is destroyed
207
+ * @override
208
+ */
209
+ public onDestroy() {}
186
210
  }
@@ -227,7 +227,31 @@ export abstract class BaseEdge extends BaseShape<BaseEdgeStyleProps> {
227
227
  this.drawHaloShape(attributes, container);
228
228
  }
229
229
 
230
- animate(keyframes: Keyframe[], options?: number | KeyframeAnimationOptions) {
230
+ /**
231
+ * <zh/> 在元素完成创建并执行完入场动画后调用
232
+ *
233
+ * <en/> Called after the element is created and the entrance animation is completed
234
+ * @override
235
+ */
236
+ public onCreate() {}
237
+
238
+ /**
239
+ * <zh/> 在元素更新并执行完过渡动画后调用
240
+ *
241
+ * <en/> Called after the element is updated and the transition animation is completed
242
+ * @override
243
+ */
244
+ public onUpdate() {}
245
+
246
+ /**
247
+ * <zh/> 在元素完成退场动画并销毁后调用
248
+ *
249
+ * <en/> Called after the element completes the exit animation and is destroyed
250
+ * @override
251
+ */
252
+ public onDestroy() {}
253
+
254
+ public animate(keyframes: Keyframe[], options?: number | KeyframeAnimationOptions) {
231
255
  const result = super.animate(keyframes, options);
232
256
 
233
257
  if (result) {
@@ -283,7 +283,31 @@ export abstract class BaseNode<S extends BaseNodeStyleProps = any> extends BaseS
283
283
  this.drawPortShapes(attributes, container);
284
284
  }
285
285
 
286
- animate(keyframes: Keyframe[], options?: number | KeyframeAnimationOptions) {
286
+ /**
287
+ * <zh/> 在元素完成创建并执行完入场动画后调用
288
+ *
289
+ * <en/> Called after the element is created and the entrance animation is completed
290
+ * @override
291
+ */
292
+ public onCreate() {}
293
+
294
+ /**
295
+ * <zh/> 在元素更新并执行完过渡动画后调用
296
+ *
297
+ * <en/> Called after the element is updated and the transition animation is completed
298
+ * @override
299
+ */
300
+ public onUpdate() {}
301
+
302
+ /**
303
+ * <zh/> 在元素完成退场动画并销毁后调用
304
+ *
305
+ * <en/> Called after the element completes the exit animation and is destroyed
306
+ * @override
307
+ */
308
+ public onDestroy() {}
309
+
310
+ public animate(keyframes: Keyframe[], options?: number | KeyframeAnimationOptions) {
287
311
  const result = super.animate(keyframes, options);
288
312
 
289
313
  if (result) {
package/src/exports.ts CHANGED
@@ -3,22 +3,50 @@ import { idOf } from './utils/id';
3
3
  import { omitStyleProps, subStyleProps } from './utils/prefix';
4
4
  import { treeToGraphData } from './utils/tree';
5
5
 
6
- export { BaseBehavior } from './behaviors';
7
- export { CanvasEvent, ComboEvent, CommonEvent, ContainerEvent, EdgeEvent, GraphEvent, NodeEvent } from './constants';
8
- export { BaseCombo } from './elements/combos';
9
- export { BaseEdge } from './elements/edges';
10
- export { BaseNode } from './elements/nodes';
6
+ export { BaseBehavior, DragCanvas, ZoomCanvas } from './behaviors';
7
+ export {
8
+ CanvasEvent,
9
+ ComboEvent,
10
+ CommonEvent,
11
+ ContainerEvent,
12
+ EdgeEvent,
13
+ ExtensionCategory,
14
+ GraphEvent,
15
+ NodeEvent,
16
+ } from './constants';
17
+ export { BaseCombo, CircleCombo, RectCombo } from './elements/combos';
18
+ export { BaseEdge, Cubic, CubicHorizontal, CubicVertical, Line, Polyline, Quadratic } from './elements/edges';
19
+ export { BaseNode, Circle, Diamond, Ellipse, Hexagon, Image, Rect, Star, Triangle } from './elements/nodes';
11
20
  export { BaseShape } from './elements/shapes';
12
- export { BasePlugin } from './plugins';
21
+ export { BasePlugin, CameraSetting } from './plugins';
13
22
  export { getExtension, getExtensions, register } from './registry';
14
23
  export { Graph } from './runtime/graph';
24
+ export { Shortcut } from './utils/shortcut';
15
25
 
16
- export type { BaseBehaviorOptions } from './behaviors';
17
- export type { BaseComboStyleProps } from './elements/combos';
18
- export type { BaseEdgeStyleProps } from './elements/edges';
19
- export type { BaseNodeStyleProps } from './elements/nodes';
26
+ export type { BaseBehaviorOptions, DragCanvasOptions, ZoomCanvasOptions } from './behaviors';
27
+ export type { BaseComboStyleProps, CircleComboStyleProps, RectComboStyleProps } from './elements/combos';
28
+ export type {
29
+ BaseEdgeStyleProps,
30
+ CubicHorizontalStyleProps,
31
+ CubicStyleProps,
32
+ CubicVerticalStyleProps,
33
+ LineStyleProps,
34
+ PolylineStyleProps,
35
+ QuadraticStyleProps,
36
+ } from './elements/edges';
37
+ export type {
38
+ BaseNodeStyleProps,
39
+ CircleStyleProps,
40
+ DiamondStyleProps,
41
+ EllipseStyleProps,
42
+ HexagonStyleProps,
43
+ ImageStyleProps,
44
+ RectStyleProps,
45
+ StarStyleProps,
46
+ TriangleStyleProps,
47
+ } from './elements/nodes';
20
48
  export type { BaseShapeStyleProps } from './elements/shapes';
21
- export type { BasePluginOptions } from './plugins';
49
+ export type { BasePluginOptions, CameraSettingOptions } from './plugins';
22
50
  export type { RuntimeContext } from './runtime/types';
23
51
  export type {
24
52
  BehaviorOptions,
@@ -36,7 +64,22 @@ export type {
36
64
  ThemeOptions,
37
65
  ViewportOptions,
38
66
  } from './spec';
39
- export type { Point, Vector2, Vector3 } from './types';
67
+ export type {
68
+ IAnimateEvent,
69
+ IDragEvent,
70
+ IElementLifeCycleEvent,
71
+ IEvent,
72
+ IGraphLifeCycleEvent,
73
+ IKeyboardEvent,
74
+ IPointerEvent,
75
+ IViewportEvent,
76
+ IWheelEvent,
77
+ Point,
78
+ Vector2,
79
+ Vector3,
80
+ ViewportAnimationEffectTiming,
81
+ } from './types';
82
+ export type { ShortcutKey } from './utils/shortcut';
40
83
 
41
84
  const Utils = {
42
85
  idOf,