@antv/g6 5.0.20 → 5.0.22

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 (300) hide show
  1. package/README.en-US.md +1 -1
  2. package/README.md +1 -1
  3. package/dist/g6.min.js +2 -2
  4. package/dist/lib/behaviors/base-behavior.d.ts +10 -0
  5. package/dist/lib/behaviors/collapse-expand.d.ts +4 -4
  6. package/dist/lib/behaviors/drag-canvas.d.ts +1 -1
  7. package/dist/lib/behaviors/hover-activate.d.ts +3 -2
  8. package/dist/lib/elements/edges/line.d.ts +0 -2
  9. package/dist/lib/elements/shapes/base-shape.d.ts +29 -14
  10. package/dist/lib/exports.d.ts +4 -4
  11. package/dist/lib/layouts/base-layout.d.ts +5 -0
  12. package/dist/lib/plugins/background/index.d.ts +1 -0
  13. package/dist/lib/plugins/base-plugin.d.ts +5 -0
  14. package/dist/lib/plugins/bubble-sets.d.ts +1 -0
  15. package/dist/lib/plugins/contextmenu/index.d.ts +1 -0
  16. package/dist/lib/plugins/grid-line.d.ts +1 -0
  17. package/dist/lib/plugins/history/index.d.ts +1 -0
  18. package/dist/lib/plugins/hull/index.d.ts +1 -0
  19. package/dist/lib/plugins/legend.d.ts +1 -0
  20. package/dist/lib/plugins/minimap/index.d.ts +17 -2
  21. package/dist/lib/plugins/snapline/index.d.ts +10 -0
  22. package/dist/lib/plugins/timebar.d.ts +1 -0
  23. package/dist/lib/plugins/toolbar/index.d.ts +1 -0
  24. package/dist/lib/plugins/tooltip.d.ts +11 -0
  25. package/dist/lib/plugins/watermark/index.d.ts +1 -0
  26. package/dist/lib/transforms/base-transform.d.ts +5 -0
  27. package/dist/lib/transforms/index.d.ts +2 -2
  28. package/dist/lib/transforms/{position-radial-labels.d.ts → place-radial-labels.d.ts} +4 -4
  29. package/dist/lib/transforms/process-parallel-edges.d.ts +7 -9
  30. package/dist/lib/transforms/utils.d.ts +5 -5
  31. package/dist/lib/utils/bbox.d.ts +12 -3
  32. package/dist/lib/utils/padding.d.ts +4 -4
  33. package/dist/lib/utils/prefix.d.ts +1 -1
  34. package/dist/lib/utils/router/orth.d.ts +1 -1
  35. package/dist/lib/utils/size.d.ts +3 -1
  36. package/dist/lib/utils/transform.d.ts +5 -5
  37. package/dist/lib/version.d.ts +1 -1
  38. package/esm/behaviors/base-behavior.d.ts +10 -0
  39. package/esm/behaviors/base-behavior.js +5 -0
  40. package/esm/behaviors/base-behavior.js.map +1 -1
  41. package/esm/behaviors/collapse-expand.d.ts +4 -4
  42. package/esm/behaviors/collapse-expand.js +4 -4
  43. package/esm/behaviors/drag-canvas.d.ts +1 -1
  44. package/esm/behaviors/drag-canvas.js +1 -1
  45. package/esm/behaviors/drag-canvas.js.map +1 -1
  46. package/esm/behaviors/drag-element.js +1 -0
  47. package/esm/behaviors/drag-element.js.map +1 -1
  48. package/esm/behaviors/hover-activate.d.ts +3 -2
  49. package/esm/behaviors/hover-activate.js +24 -14
  50. package/esm/behaviors/hover-activate.js.map +1 -1
  51. package/esm/elements/edges/line.d.ts +0 -2
  52. package/esm/elements/edges/line.js +0 -2
  53. package/esm/elements/edges/line.js.map +1 -1
  54. package/esm/elements/edges/polyline.js.map +1 -1
  55. package/esm/elements/nodes/html.js +4 -1
  56. package/esm/elements/nodes/html.js.map +1 -1
  57. package/esm/elements/shapes/base-shape.d.ts +29 -14
  58. package/esm/elements/shapes/base-shape.js +29 -14
  59. package/esm/elements/shapes/base-shape.js.map +1 -1
  60. package/esm/exports.d.ts +4 -4
  61. package/esm/exports.js +2 -2
  62. package/esm/exports.js.map +1 -1
  63. package/esm/layouts/base-layout.d.ts +5 -0
  64. package/esm/layouts/base-layout.js +5 -0
  65. package/esm/layouts/base-layout.js.map +1 -1
  66. package/esm/plugins/background/index.d.ts +1 -0
  67. package/esm/plugins/background/index.js +1 -0
  68. package/esm/plugins/background/index.js.map +1 -1
  69. package/esm/plugins/base-plugin.d.ts +5 -0
  70. package/esm/plugins/base-plugin.js +5 -0
  71. package/esm/plugins/base-plugin.js.map +1 -1
  72. package/esm/plugins/bubble-sets.d.ts +1 -0
  73. package/esm/plugins/bubble-sets.js +1 -0
  74. package/esm/plugins/bubble-sets.js.map +1 -1
  75. package/esm/plugins/contextmenu/index.d.ts +1 -0
  76. package/esm/plugins/contextmenu/index.js +1 -0
  77. package/esm/plugins/contextmenu/index.js.map +1 -1
  78. package/esm/plugins/grid-line.d.ts +1 -0
  79. package/esm/plugins/grid-line.js +1 -0
  80. package/esm/plugins/grid-line.js.map +1 -1
  81. package/esm/plugins/history/index.d.ts +1 -0
  82. package/esm/plugins/history/index.js +1 -0
  83. package/esm/plugins/history/index.js.map +1 -1
  84. package/esm/plugins/hull/index.d.ts +1 -0
  85. package/esm/plugins/hull/index.js +1 -0
  86. package/esm/plugins/hull/index.js.map +1 -1
  87. package/esm/plugins/legend.d.ts +1 -0
  88. package/esm/plugins/legend.js +1 -0
  89. package/esm/plugins/legend.js.map +1 -1
  90. package/esm/plugins/minimap/index.d.ts +17 -2
  91. package/esm/plugins/minimap/index.js +25 -6
  92. package/esm/plugins/minimap/index.js.map +1 -1
  93. package/esm/plugins/snapline/index.d.ts +10 -0
  94. package/esm/plugins/snapline/index.js +5 -0
  95. package/esm/plugins/snapline/index.js.map +1 -1
  96. package/esm/plugins/timebar.d.ts +1 -0
  97. package/esm/plugins/timebar.js +1 -0
  98. package/esm/plugins/timebar.js.map +1 -1
  99. package/esm/plugins/toolbar/index.d.ts +1 -0
  100. package/esm/plugins/toolbar/index.js +1 -0
  101. package/esm/plugins/toolbar/index.js.map +1 -1
  102. package/esm/plugins/tooltip.d.ts +11 -0
  103. package/esm/plugins/tooltip.js +6 -0
  104. package/esm/plugins/tooltip.js.map +1 -1
  105. package/esm/plugins/watermark/index.d.ts +1 -0
  106. package/esm/plugins/watermark/index.js +1 -0
  107. package/esm/plugins/watermark/index.js.map +1 -1
  108. package/esm/registry/build-in.js +2 -2
  109. package/esm/registry/build-in.js.map +1 -1
  110. package/esm/runtime/data.js +14 -2
  111. package/esm/runtime/data.js.map +1 -1
  112. package/esm/transforms/base-transform.d.ts +5 -0
  113. package/esm/transforms/base-transform.js +5 -0
  114. package/esm/transforms/base-transform.js.map +1 -1
  115. package/esm/transforms/index.d.ts +2 -2
  116. package/esm/transforms/index.js +1 -1
  117. package/esm/transforms/index.js.map +1 -1
  118. package/esm/transforms/{position-radial-labels.d.ts → place-radial-labels.d.ts} +4 -4
  119. package/esm/transforms/{position-radial-labels.js → place-radial-labels.js} +3 -3
  120. package/esm/transforms/place-radial-labels.js.map +1 -0
  121. package/esm/transforms/process-parallel-edges.d.ts +7 -9
  122. package/esm/transforms/process-parallel-edges.js.map +1 -1
  123. package/esm/transforms/utils.d.ts +5 -5
  124. package/esm/transforms/utils.js +5 -5
  125. package/esm/utils/bbox.d.ts +12 -3
  126. package/esm/utils/bbox.js +16 -4
  127. package/esm/utils/bbox.js.map +1 -1
  128. package/esm/utils/edge.js +4 -4
  129. package/esm/utils/edge.js.map +1 -1
  130. package/esm/utils/padding.d.ts +4 -4
  131. package/esm/utils/padding.js +4 -4
  132. package/esm/utils/point.js +3 -0
  133. package/esm/utils/point.js.map +1 -1
  134. package/esm/utils/prefix.d.ts +1 -1
  135. package/esm/utils/prefix.js +1 -1
  136. package/esm/utils/router/orth.d.ts +1 -1
  137. package/esm/utils/router/orth.js +27 -11
  138. package/esm/utils/router/orth.js.map +1 -1
  139. package/esm/utils/size.d.ts +3 -1
  140. package/esm/utils/size.js +3 -1
  141. package/esm/utils/size.js.map +1 -1
  142. package/esm/utils/transform.d.ts +5 -5
  143. package/esm/utils/transform.js +5 -5
  144. package/esm/utils/visibility.js.map +1 -1
  145. package/esm/version.d.ts +1 -1
  146. package/esm/version.js +1 -1
  147. package/lib/behaviors/base-behavior.d.ts +10 -0
  148. package/lib/behaviors/base-behavior.js +5 -0
  149. package/lib/behaviors/base-behavior.js.map +1 -1
  150. package/lib/behaviors/collapse-expand.d.ts +4 -4
  151. package/lib/behaviors/collapse-expand.js +4 -4
  152. package/lib/behaviors/drag-canvas.d.ts +1 -1
  153. package/lib/behaviors/drag-canvas.js +1 -1
  154. package/lib/behaviors/drag-canvas.js.map +1 -1
  155. package/lib/behaviors/drag-element.js +1 -0
  156. package/lib/behaviors/drag-element.js.map +1 -1
  157. package/lib/behaviors/hover-activate.d.ts +3 -2
  158. package/lib/behaviors/hover-activate.js +24 -14
  159. package/lib/behaviors/hover-activate.js.map +1 -1
  160. package/lib/elements/edges/line.d.ts +0 -2
  161. package/lib/elements/edges/line.js +0 -2
  162. package/lib/elements/edges/line.js.map +1 -1
  163. package/lib/elements/edges/polyline.js.map +1 -1
  164. package/lib/elements/nodes/html.js +3 -0
  165. package/lib/elements/nodes/html.js.map +1 -1
  166. package/lib/elements/shapes/base-shape.d.ts +29 -14
  167. package/lib/elements/shapes/base-shape.js +29 -14
  168. package/lib/elements/shapes/base-shape.js.map +1 -1
  169. package/lib/exports.d.ts +4 -4
  170. package/lib/exports.js +4 -3
  171. package/lib/exports.js.map +1 -1
  172. package/lib/layouts/base-layout.d.ts +5 -0
  173. package/lib/layouts/base-layout.js +5 -0
  174. package/lib/layouts/base-layout.js.map +1 -1
  175. package/lib/plugins/background/index.d.ts +1 -0
  176. package/lib/plugins/background/index.js +1 -0
  177. package/lib/plugins/background/index.js.map +1 -1
  178. package/lib/plugins/base-plugin.d.ts +5 -0
  179. package/lib/plugins/base-plugin.js +5 -0
  180. package/lib/plugins/base-plugin.js.map +1 -1
  181. package/lib/plugins/bubble-sets.d.ts +1 -0
  182. package/lib/plugins/bubble-sets.js +1 -0
  183. package/lib/plugins/bubble-sets.js.map +1 -1
  184. package/lib/plugins/contextmenu/index.d.ts +1 -0
  185. package/lib/plugins/contextmenu/index.js +1 -0
  186. package/lib/plugins/contextmenu/index.js.map +1 -1
  187. package/lib/plugins/grid-line.d.ts +1 -0
  188. package/lib/plugins/grid-line.js +1 -0
  189. package/lib/plugins/grid-line.js.map +1 -1
  190. package/lib/plugins/history/index.d.ts +1 -0
  191. package/lib/plugins/history/index.js +1 -0
  192. package/lib/plugins/history/index.js.map +1 -1
  193. package/lib/plugins/hull/index.d.ts +1 -0
  194. package/lib/plugins/hull/index.js +1 -0
  195. package/lib/plugins/hull/index.js.map +1 -1
  196. package/lib/plugins/legend.d.ts +1 -0
  197. package/lib/plugins/legend.js +1 -0
  198. package/lib/plugins/legend.js.map +1 -1
  199. package/lib/plugins/minimap/index.d.ts +17 -2
  200. package/lib/plugins/minimap/index.js +24 -5
  201. package/lib/plugins/minimap/index.js.map +1 -1
  202. package/lib/plugins/snapline/index.d.ts +10 -0
  203. package/lib/plugins/snapline/index.js +5 -0
  204. package/lib/plugins/snapline/index.js.map +1 -1
  205. package/lib/plugins/timebar.d.ts +1 -0
  206. package/lib/plugins/timebar.js +1 -0
  207. package/lib/plugins/timebar.js.map +1 -1
  208. package/lib/plugins/toolbar/index.d.ts +1 -0
  209. package/lib/plugins/toolbar/index.js +1 -0
  210. package/lib/plugins/toolbar/index.js.map +1 -1
  211. package/lib/plugins/tooltip.d.ts +11 -0
  212. package/lib/plugins/tooltip.js +6 -0
  213. package/lib/plugins/tooltip.js.map +1 -1
  214. package/lib/plugins/watermark/index.d.ts +1 -0
  215. package/lib/plugins/watermark/index.js +1 -0
  216. package/lib/plugins/watermark/index.js.map +1 -1
  217. package/lib/registry/build-in.js +1 -1
  218. package/lib/registry/build-in.js.map +1 -1
  219. package/lib/runtime/data.js +13 -1
  220. package/lib/runtime/data.js.map +1 -1
  221. package/lib/transforms/base-transform.d.ts +5 -0
  222. package/lib/transforms/base-transform.js +5 -0
  223. package/lib/transforms/base-transform.js.map +1 -1
  224. package/lib/transforms/index.d.ts +2 -2
  225. package/lib/transforms/index.js +3 -3
  226. package/lib/transforms/index.js.map +1 -1
  227. package/lib/transforms/{position-radial-labels.d.ts → place-radial-labels.d.ts} +4 -4
  228. package/lib/transforms/{position-radial-labels.js → place-radial-labels.js} +5 -5
  229. package/lib/transforms/place-radial-labels.js.map +1 -0
  230. package/lib/transforms/process-parallel-edges.d.ts +7 -9
  231. package/lib/transforms/process-parallel-edges.js.map +1 -1
  232. package/lib/transforms/utils.d.ts +5 -5
  233. package/lib/transforms/utils.js +5 -5
  234. package/lib/utils/bbox.d.ts +12 -3
  235. package/lib/utils/bbox.js +19 -6
  236. package/lib/utils/bbox.js.map +1 -1
  237. package/lib/utils/edge.js +3 -3
  238. package/lib/utils/edge.js.map +1 -1
  239. package/lib/utils/padding.d.ts +4 -4
  240. package/lib/utils/padding.js +4 -4
  241. package/lib/utils/point.js +3 -0
  242. package/lib/utils/point.js.map +1 -1
  243. package/lib/utils/prefix.d.ts +1 -1
  244. package/lib/utils/prefix.js +1 -1
  245. package/lib/utils/router/orth.d.ts +1 -1
  246. package/lib/utils/router/orth.js +25 -9
  247. package/lib/utils/router/orth.js.map +1 -1
  248. package/lib/utils/size.d.ts +3 -1
  249. package/lib/utils/size.js +3 -1
  250. package/lib/utils/size.js.map +1 -1
  251. package/lib/utils/transform.d.ts +5 -5
  252. package/lib/utils/transform.js +5 -5
  253. package/lib/utils/visibility.js.map +1 -1
  254. package/lib/version.d.ts +1 -1
  255. package/lib/version.js +1 -1
  256. package/package.json +11 -11
  257. package/src/behaviors/base-behavior.ts +10 -0
  258. package/src/behaviors/collapse-expand.ts +4 -4
  259. package/src/behaviors/drag-canvas.ts +2 -2
  260. package/src/behaviors/drag-element.ts +1 -0
  261. package/src/behaviors/hover-activate.ts +33 -17
  262. package/src/elements/edges/line.ts +0 -2
  263. package/src/elements/edges/polyline.ts +2 -0
  264. package/src/elements/nodes/html.ts +4 -1
  265. package/src/elements/shapes/base-shape.ts +31 -16
  266. package/src/exports.ts +4 -2
  267. package/src/layouts/base-layout.ts +5 -0
  268. package/src/plugins/background/index.ts +1 -0
  269. package/src/plugins/base-plugin.ts +5 -0
  270. package/src/plugins/bubble-sets.ts +1 -0
  271. package/src/plugins/contextmenu/index.ts +1 -0
  272. package/src/plugins/grid-line.ts +1 -0
  273. package/src/plugins/history/index.ts +1 -0
  274. package/src/plugins/hull/index.ts +1 -0
  275. package/src/plugins/legend.ts +1 -0
  276. package/src/plugins/minimap/index.ts +39 -12
  277. package/src/plugins/snapline/index.ts +10 -0
  278. package/src/plugins/timebar.ts +1 -0
  279. package/src/plugins/toolbar/index.ts +1 -0
  280. package/src/plugins/tooltip.ts +11 -0
  281. package/src/plugins/watermark/index.ts +1 -0
  282. package/src/registry/build-in.ts +2 -2
  283. package/src/runtime/data.ts +15 -3
  284. package/src/transforms/base-transform.ts +5 -0
  285. package/src/transforms/index.ts +2 -2
  286. package/src/transforms/{position-radial-labels.ts → place-radial-labels.ts} +5 -5
  287. package/src/transforms/process-parallel-edges.ts +7 -9
  288. package/src/transforms/utils.ts +5 -5
  289. package/src/utils/bbox.ts +17 -4
  290. package/src/utils/edge.ts +4 -4
  291. package/src/utils/padding.ts +4 -4
  292. package/src/utils/point.ts +2 -0
  293. package/src/utils/prefix.ts +1 -1
  294. package/src/utils/router/orth.ts +29 -11
  295. package/src/utils/size.ts +3 -1
  296. package/src/utils/transform.ts +5 -5
  297. package/src/utils/visibility.ts +2 -2
  298. package/src/version.ts +1 -1
  299. package/esm/transforms/position-radial-labels.js.map +0 -1
  300. package/lib/transforms/position-radial-labels.js.map +0 -1
@@ -2,7 +2,7 @@ import { isFunction } from '@antv/util';
2
2
  import { CommonEvent } from '../constants';
3
3
  import { ELEMENT_TYPES } from '../constants/element';
4
4
  import type { RuntimeContext } from '../runtime/types';
5
- import type { EdgeDirection, Element, ElementType, ID, IDragEvent, IPointerEvent, State } from '../types';
5
+ import type { EdgeDirection, Element, ID, IDragEvent, IPointerEvent, State } from '../types';
6
6
  import { idsOf } from '../utils/id';
7
7
  import { getElementNthDegreeIds } from '../utils/relation';
8
8
  import type { BaseBehaviorOptions } from './base-behavior';
@@ -38,7 +38,7 @@ export interface HoverActivateOptions extends BaseBehaviorOptions {
38
38
  * - `1` means the current node and its directly adjacent nodes and edges are activated, etc
39
39
  * @defaultValue 0
40
40
  */
41
- degree?: number;
41
+ degree?: number | ((event: IPointerEvent) => number);
42
42
  /**
43
43
  * <zh/> 指定边的方向
44
44
  * - `'both'`: 表示激活当前节点的所有关系
@@ -114,8 +114,8 @@ export class HoverActivate extends BaseBehavior<HoverActivateOptions> {
114
114
  this.unbindEvents();
115
115
 
116
116
  ELEMENT_TYPES.forEach((type) => {
117
- graph.on(`${type}:${CommonEvent.POINTER_OVER}`, this.hoverElement);
118
- graph.on(`${type}:${CommonEvent.POINTER_OUT}`, this.hoverElement);
117
+ graph.on(`${type}:${CommonEvent.POINTER_ENTER}`, this.hoverElement);
118
+ graph.on(`${type}:${CommonEvent.POINTER_LEAVE}`, this.hoverElement);
119
119
  });
120
120
 
121
121
  const canvas = this.context.canvas.document;
@@ -125,25 +125,38 @@ export class HoverActivate extends BaseBehavior<HoverActivateOptions> {
125
125
 
126
126
  private hoverElement = (event: IPointerEvent<Element>) => {
127
127
  if (!this.validate(event)) return;
128
- const isOver = event.type === CommonEvent.POINTER_OVER;
129
- this.updateElementsState(event, isOver);
128
+ const isEnter = event.type === CommonEvent.POINTER_ENTER;
129
+ this.updateElementsState(event, isEnter);
130
130
 
131
131
  const { onHover, onHoverEnd } = this.options;
132
- if (isOver) onHover?.(event);
132
+ if (isEnter) onHover?.(event);
133
133
  else onHoverEnd?.(event);
134
134
  };
135
135
 
136
+ protected getActiveIds(event: IPointerEvent<Element>) {
137
+ const { graph } = this.context;
138
+ const { degree, direction } = this.options;
139
+ const elementId = event.target.id;
140
+ const elementType = graph.getElementType(elementId);
141
+
142
+ return degree
143
+ ? getElementNthDegreeIds(
144
+ graph,
145
+ elementType,
146
+ elementId,
147
+ typeof degree === 'function' ? degree(event) : degree,
148
+ direction,
149
+ )
150
+ : [elementId];
151
+ }
152
+
136
153
  private updateElementsState = (event: IPointerEvent<Element>, add: boolean) => {
137
154
  if (!this.options.state && !this.options.inactiveState) return;
138
155
 
139
156
  const { graph } = this.context;
140
- const { state, degree, direction, animation, inactiveState } = this.options;
141
- const { targetType, target } = event;
142
-
143
- const activeIds = degree
144
- ? getElementNthDegreeIds(graph, targetType as ElementType, target.id, degree, direction)
145
- : [target.id];
157
+ const { state, animation, inactiveState } = this.options;
146
158
 
159
+ const activeIds = this.getActiveIds(event);
147
160
  const states: Record<ID, State[]> = {};
148
161
 
149
162
  if (state) {
@@ -162,8 +175,11 @@ export class HoverActivate extends BaseBehavior<HoverActivateOptions> {
162
175
  const states: Record<ID, State[]> = {};
163
176
  ids.forEach((id) => {
164
177
  const currentState = graph.getElementState(id);
165
- const updatedState = add ? [...currentState, state] : currentState.filter((s) => s !== state);
166
- states[id] = updatedState;
178
+ if (add) {
179
+ states[id] = currentState.includes(state) ? currentState : [...currentState, state];
180
+ } else {
181
+ states[id] = currentState.filter((s) => s !== state);
182
+ }
167
183
  });
168
184
  return states;
169
185
  };
@@ -186,8 +202,8 @@ export class HoverActivate extends BaseBehavior<HoverActivateOptions> {
186
202
  const { graph } = this.context;
187
203
 
188
204
  ELEMENT_TYPES.forEach((type) => {
189
- graph.off(`${type}:${CommonEvent.POINTER_OVER}`, this.hoverElement);
190
- graph.off(`${type}:${CommonEvent.POINTER_OUT}`, this.hoverElement);
205
+ graph.off(`${type}:${CommonEvent.POINTER_ENTER}`, this.hoverElement);
206
+ graph.off(`${type}:${CommonEvent.POINTER_LEAVE}`, this.hoverElement);
191
207
  });
192
208
 
193
209
  const canvas = this.context.canvas.document;
@@ -17,8 +17,6 @@ type ParsedLineStyleProps = Required<LineStyleProps>;
17
17
  * <zh/> 直线
18
18
  *
19
19
  * <en/> Line
20
- * @remarks
21
- * <img width="300" src="https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*YbpvTa4liAEAAAAAAAAAAAAADmJ7AQ/original" />
22
20
  */
23
21
  export class Line extends BaseEdge {
24
22
  static defaultStyleProps: Partial<LineStyleProps> = {};
@@ -69,6 +69,7 @@ export class Polyline extends BaseEdge {
69
69
  if (router.type === 'shortest-path') {
70
70
  const nodes = this.context.element!.getNodes();
71
71
  controlPoints = aStarSearch(sourceNode, targetNode, nodes, router);
72
+
72
73
  if (!controlPoints.length) {
73
74
  controlPoints = orth(sourcePoint, targetPoint, sourceNode, targetNode, attributes.controlPoints, {
74
75
  padding: router.offset,
@@ -91,6 +92,7 @@ export class Polyline extends BaseEdge {
91
92
 
92
93
  protected getKeyPath(attributes: ParsedPolylineStyleProps): PathArray {
93
94
  const points = this.getPoints(attributes);
95
+
94
96
  return getPolylinePath(points, attributes.radius);
95
97
  }
96
98
 
@@ -10,7 +10,7 @@ import {
10
10
  Rect,
11
11
  } from '@antv/g';
12
12
  import { Renderer } from '@antv/g-canvas';
13
- import { isNil, isUndefined, pick } from '@antv/util';
13
+ import { isNil, isUndefined, pick, set } from '@antv/util';
14
14
  import { CommonEvent } from '../../constants';
15
15
  import type { BaseNodeStyleProps } from './base-node';
16
16
  import { BaseNode } from './base-node';
@@ -136,6 +136,9 @@ export class HTML extends BaseNode<HTMLStyleProps> {
136
136
 
137
137
  normalizedEvents.forEach((normalizedEvent) => {
138
138
  const event = this.bootstrapEvent(this.rootPointerEvent, normalizedEvent, iCanvas, nativeEvent);
139
+ // 当点击到 html 元素时,避免触发 pointerupoutside 事件
140
+ // When clicking on the html element, avoid triggering the pointerupoutside event
141
+ set(canvas.context.eventService, 'mappingTable.pointerupoutside', []);
139
142
  canvas.context.eventService.mapEvent(event);
140
143
  });
141
144
  };
@@ -14,6 +14,11 @@ import { getExtension } from './../../registry/get';
14
14
 
15
15
  export interface BaseShapeStyleProps extends BaseStyleProps {}
16
16
 
17
+ /**
18
+ * <zh/> 图形基类
19
+ *
20
+ * <en/> Base class for shapes
21
+ */
17
22
  export abstract class BaseShape<StyleProps extends BaseShapeStyleProps> extends CustomElement<StyleProps> {
18
23
  constructor(options: DisplayObjectConfig<StyleProps>) {
19
24
  super(options);
@@ -23,34 +28,43 @@ export abstract class BaseShape<StyleProps extends BaseShapeStyleProps> extends
23
28
  this.bindEvents();
24
29
  }
25
30
 
31
+ /**
32
+ * <zh/> 解析后的属性
33
+ *
34
+ * <en/> parsed attributes
35
+ * @returns <zh/> 解析后的属性 | <en/> parsed attributes
36
+ * @internal
37
+ */
26
38
  protected get parsedAttributes() {
27
39
  return this.attributes as Required<StyleProps>;
28
40
  }
29
41
 
30
42
  /**
31
- * <zh> 图形实例映射表
43
+ * <zh/> 图形实例映射表
32
44
  *
33
- * <en> shape instance map
45
+ * <en/> shape instance map
46
+ * @internal
34
47
  */
35
48
  protected shapeMap: Record<string, DisplayObject> = {};
36
49
 
37
50
  /**
38
- * <zh> 动画实例映射表
51
+ * <zh/> 动画实例映射表
39
52
  *
40
- * <en> animation instance map
53
+ * <en/> animation instance map
54
+ * @internal
41
55
  */
42
56
  protected animateMap: Record<string, IAnimation> = {};
43
57
 
44
58
  /**
45
- * <zh> 创建、更新或删除图形
59
+ * <zh/> 创建、更新或删除图形
46
60
  *
47
- * <en> create, update or remove shape
48
- * @param className - <zh> 图形名称 | <en> shape name
49
- * @param Ctor - <zh> 图形类型 | <en> shape type
50
- * @param style - <zh> 图形样式。若要删除图形,传入 false | <en> shape style. Pass false to remove the shape
51
- * @param container - <zh> 容器 | <en> container
52
- * @param hooks - <zh> 钩子函数 | <en> hooks
53
- * @returns <zh> 图形实例 | <en> shape instance
61
+ * <en/> create, update or remove shape
62
+ * @param className - <zh/> 图形名称 | <en/> shape name
63
+ * @param Ctor - <zh/> 图形类型 | <en/> shape type
64
+ * @param style - <zh/> 图形样式。若要删除图形,传入 false | <en/> shape style. Pass false to remove the shape
65
+ * @param container - <zh/> 容器 | <en/> container
66
+ * @param hooks - <zh/> 钩子函数 | <en/> hooks
67
+ * @returns <zh/> 图形实例 | <en/> shape instance
54
68
  */
55
69
  protected upsert<T extends DisplayObject>(
56
70
  className: string,
@@ -110,8 +124,8 @@ export abstract class BaseShape<StyleProps extends BaseShapeStyleProps> extends
110
124
  */
111
125
  protected transformPosition(attributes: Partial<StyleProps>) {
112
126
  // Use `transform: translate3d()` instead of `x/y/z`
113
- const { x = 0, y = 0, z = 0, transform } = attributes as any;
114
- if (x !== 0 || y !== 0 || z !== 0) {
127
+ if ('x' in attributes || 'y' in attributes || 'z' in attributes) {
128
+ const { x = 0, y = 0, z = 0, transform } = attributes as any;
115
129
  this.style.transform = replaceTranslateInTransform(+x, +y, +z, transform);
116
130
  }
117
131
  }
@@ -125,9 +139,9 @@ export abstract class BaseShape<StyleProps extends BaseShapeStyleProps> extends
125
139
  }
126
140
 
127
141
  /**
128
- * <zh> 在初始化时会被自动调用
142
+ * <zh/> 在初始化时会被自动调用
129
143
  *
130
- * <en> will be called automatically when initializing
144
+ * <en/> will be called automatically when initializing
131
145
  * @param attributes
132
146
  * @param container
133
147
  */
@@ -155,6 +169,7 @@ export abstract class BaseShape<StyleProps extends BaseShapeStyleProps> extends
155
169
  /**
156
170
  * Get the prefix pairs for composite shapes used to handle animation
157
171
  * @returns tuples array where each tuple contains a key corresponding to a method `get${key}Style` and its shape prefix
172
+ * @internal
158
173
  */
159
174
  protected get compositeShapes(): [string, string][] {
160
175
  return [
package/src/exports.ts CHANGED
@@ -73,6 +73,7 @@ export {
73
73
  RandomLayout,
74
74
  } from './layouts';
75
75
  export {
76
+ Background,
76
77
  BasePlugin,
77
78
  BubbleSets,
78
79
  CameraSetting,
@@ -94,7 +95,7 @@ export {
94
95
  export { getExtension, getExtensions } from './registry/get';
95
96
  export { register } from './registry/register';
96
97
  export { Graph } from './runtime/graph';
97
- export { BaseTransform, PositionRadialLabels, ProcessParallelEdges } from './transforms';
98
+ export { BaseTransform, PlaceRadialLabels, ProcessParallelEdges } from './transforms';
98
99
  export { isCollapsed } from './utils/collapsibility';
99
100
  export { idOf } from './utils/id';
100
101
  export { invokeLayoutMethod } from './utils/layout';
@@ -178,6 +179,7 @@ export type { ContourLabelStyleProps, ContourStyleProps } from './elements/shape
178
179
  export type { BaseLayoutOptions, WebWorkerLayoutOptions } from './layouts/types';
179
180
  export type { CategoricalPalette } from './palettes/types';
180
181
  export type {
182
+ BackgroundOptions,
181
183
  BasePluginOptions,
182
184
  BubbleSetsOptions,
183
185
  CameraSettingOptions,
@@ -217,7 +219,7 @@ export type { CustomBehaviorOption } from './spec/behavior';
217
219
  export type { AnimationStage } from './spec/element/animation';
218
220
  export type { LayoutOptions, STDLayoutOptions, SingleLayoutOptions } from './spec/layout';
219
221
  export type { CustomPluginOption } from './spec/plugin';
220
- export type { BaseTransformOptions, PositionRadialLabelsOptions, ProcessParallelEdgesOptions } from './transforms';
222
+ export type { BaseTransformOptions, PlaceRadialLabelsOptions, ProcessParallelEdgesOptions } from './transforms';
221
223
  export type { DrawData } from './transforms/types';
222
224
  export type {
223
225
  BaseElementStyleProps,
@@ -2,6 +2,11 @@ import type { RuntimeContext } from '../runtime/types';
2
2
  import type { GraphData } from '../spec';
3
3
  import type { BaseLayoutOptions } from './types';
4
4
 
5
+ /**
6
+ * <zh/> 布局的基类
7
+ *
8
+ * <en/> Base class for layout
9
+ */
5
10
  export abstract class BaseLayout<O extends BaseLayoutOptions = any> {
6
11
  public abstract id: string;
7
12
 
@@ -55,6 +55,7 @@ export class Background extends BasePlugin<BackgroundOptions> {
55
55
  * <zh/> 销毁背景图
56
56
  *
57
57
  * <en/> Destroy the background image
58
+ * @internal
58
59
  */
59
60
  public destroy(): void {
60
61
  super.destroy();
@@ -3,4 +3,9 @@ import type { CustomPluginOption } from '../spec/plugin';
3
3
 
4
4
  export interface BasePluginOptions extends CustomPluginOption {}
5
5
 
6
+ /**
7
+ * <zh/> 插件的基类
8
+ *
9
+ * <en/> Base class for plugins
10
+ */
6
11
  export abstract class BasePlugin<T extends BasePluginOptions> extends BaseExtension<T> {}
@@ -289,6 +289,7 @@ export class BubbleSets extends BasePlugin<BubbleSetsOptions> {
289
289
  * <zh/> 销毁
290
290
  *
291
291
  * <en/> Destroy
292
+ * @internal
292
293
  */
293
294
  public destroy(): void {
294
295
  this.context.graph.off(GraphEvent.AFTER_RENDER, this.drawBubbleSets);
@@ -171,6 +171,7 @@ export class Contextmenu extends BasePlugin<ContextmenuOptions> {
171
171
  * <zh/> 销毁上下文菜单
172
172
  *
173
173
  * <en/> Destroy the contextmenu
174
+ * @internal
174
175
  */
175
176
  public destroy(): void {
176
177
  this.unbindEvents();
@@ -156,6 +156,7 @@ export class GridLine extends BasePlugin<GridLineOptions> {
156
156
  * <zh/> 销毁网格线
157
157
  *
158
158
  * <en/> Destroy the grid line
159
+ * @internal
159
160
  */
160
161
  public destroy(): void {
161
162
  this.context.graph.off(GraphEvent.AFTER_TRANSFORM, this.onTransform);
@@ -239,6 +239,7 @@ export class History extends BasePlugin<HistoryOptions> {
239
239
  * <zh/> 销毁
240
240
  *
241
241
  * <en/> Destroy
242
+ * @internal
242
243
  */
243
244
  public destroy(): void {
244
245
  const { graph } = this.context;
@@ -204,6 +204,7 @@ export class Hull extends BasePlugin<HullOptions> {
204
204
  * <zh/> 销毁 Hull
205
205
  *
206
206
  * <en/> Destroy Hull
207
+ * @internal
207
208
  */
208
209
  public destroy(): void {
209
210
  this.context.graph.off(GraphEvent.AFTER_DRAW, this.drawHull);
@@ -396,6 +396,7 @@ export class Legend extends BasePlugin<LegendOptions> {
396
396
  * <zh/>销毁图例
397
397
  *
398
398
  * <en/> Destroy the legend
399
+ * @internal
399
400
  */
400
401
  public destroy(): void {
401
402
  this.clear();
@@ -1,6 +1,6 @@
1
1
  import { Canvas, DisplayObject, IRenderer, Landmark } from '@antv/g';
2
2
  import { Renderer } from '@antv/g-canvas';
3
- import { throttle } from '@antv/util';
3
+ import { debounce, throttle } from '@antv/util';
4
4
  import { GraphEvent } from '../../constants';
5
5
  import type { RuntimeContext } from '../../runtime/types';
6
6
  import { GraphData } from '../../spec';
@@ -13,15 +13,16 @@ import type { BasePluginOptions } from '../base-plugin';
13
13
  import { BasePlugin } from '../base-plugin';
14
14
 
15
15
  /**
16
- * <zh/> 缩略图插件的配置项
16
+ * <zh/> 缩略图插件配置项
17
17
  *
18
- * <en/> The configuration item of the Minimap plugin
18
+ * <en/> Minimap plugin options
19
19
  */
20
20
  export interface MinimapOptions extends BasePluginOptions {
21
21
  /**
22
22
  * <zh/> 宽度和高度
23
23
  *
24
24
  * <en/> Width and height
25
+ * @defaultValue [240, 160]
25
26
  */
26
27
  size?: [number, number];
27
28
  /**
@@ -92,8 +93,20 @@ export interface MinimapOptions extends BasePluginOptions {
92
93
  * <en/> Renderer, default to use Canvas renderer
93
94
  */
94
95
  renderer?: IRenderer;
96
+ /**
97
+ * <zh/> 延迟更新时间(毫秒),用于性能优化
98
+ *
99
+ * <en/> Delay update time(ms), used for performance optimization
100
+ * @defaultValue 128
101
+ */
102
+ delay?: number;
95
103
  }
96
104
 
105
+ /**
106
+ * <zh/> 缩略图插件
107
+ *
108
+ * <en/> Minimap plugin
109
+ */
97
110
  export class Minimap extends BasePlugin<MinimapOptions> {
98
111
  static defaultOptions: Partial<MinimapOptions> = {
99
112
  size: [240, 160],
@@ -108,15 +121,35 @@ export class Minimap extends BasePlugin<MinimapOptions> {
108
121
  border: '1px solid #ddd',
109
122
  background: '#fff',
110
123
  },
124
+ delay: 128,
111
125
  };
112
126
 
113
127
  private canvas!: Canvas;
114
128
 
115
129
  constructor(context: RuntimeContext, options: MinimapOptions) {
116
130
  super(context, Object.assign({}, Minimap.defaultOptions, options));
131
+ this.setOnRender();
117
132
  this.bindEvents();
118
133
  }
119
134
 
135
+ public update(options: Partial<MinimapOptions>): void {
136
+ this.unbindEvents();
137
+ super.update(options);
138
+ if ('delay' in options) this.setOnRender();
139
+ this.bindEvents();
140
+ }
141
+
142
+ private setOnRender() {
143
+ this.onRender = debounce(
144
+ () => {
145
+ this.renderMinimap();
146
+ this.renderMask();
147
+ },
148
+ this.options.delay,
149
+ true,
150
+ );
151
+ }
152
+
120
153
  private bindEvents() {
121
154
  const { graph } = this.context;
122
155
  graph.on(GraphEvent.AFTER_DRAW, this.onDraw);
@@ -136,14 +169,7 @@ export class Minimap extends BasePlugin<MinimapOptions> {
136
169
  this.onRender();
137
170
  };
138
171
 
139
- private onRender = throttle(
140
- () => {
141
- this.renderMinimap();
142
- this.renderMask();
143
- },
144
- 32,
145
- { leading: true },
146
- ) as () => void;
172
+ private onRender!: () => void;
147
173
 
148
174
  private shapes = new Map<ID, DisplayObject>();
149
175
 
@@ -290,7 +316,8 @@ export class Minimap extends BasePlugin<MinimapOptions> {
290
316
  } = this.options;
291
317
 
292
318
  if (this.canvas) {
293
- this.canvas.resize(width, height);
319
+ const { width: w, height: h } = this.canvas.getConfig();
320
+ if (width !== w || height !== h) this.canvas.resize(width, height);
294
321
  if (renderer) this.canvas.setRenderer(renderer);
295
322
  } else {
296
323
  const dom = document.createElement('div');
@@ -8,6 +8,11 @@ import { divide } from '../../utils/vector';
8
8
  import type { BasePluginOptions } from '../base-plugin';
9
9
  import { BasePlugin } from '../base-plugin';
10
10
 
11
+ /**
12
+ * <zh/> 对齐线插件配置项
13
+ *
14
+ * <en/> Snapline plugin options
15
+ */
11
16
  export interface SnaplineOptions extends BasePluginOptions {
12
17
  /**
13
18
  * <zh/> 对齐精度,即移动节点时与目标位置的距离小于 tolerance 时触发显示对齐线
@@ -79,6 +84,11 @@ type Metadata = {
79
84
  horizontalMaxX: number | null;
80
85
  };
81
86
 
87
+ /**
88
+ * <zh/> 对齐线插件
89
+ *
90
+ * <en/> Snapline plugin
91
+ */
82
92
  export class Snapline extends BasePlugin<SnaplineOptions> {
83
93
  static defaultOptions: Partial<SnaplineOptions> = {
84
94
  tolerance: 5,
@@ -430,6 +430,7 @@ export class Timebar extends BasePlugin<TimebarOptions> {
430
430
  * <zh/> 销毁时间条
431
431
  *
432
432
  * <en/> Destroy the timebar
433
+ * @internal
433
434
  */
434
435
  public destroy(): void {
435
436
  const { graph } = this.context;
@@ -97,6 +97,7 @@ export class Toolbar extends BasePlugin<ToolbarOptions> {
97
97
  * <zh/> 销毁工具栏
98
98
  *
99
99
  * <en/> Destroy the toolbar
100
+ * @internal
100
101
  */
101
102
  public destroy(): void {
102
103
  this.$element.removeEventListener('click', this.onToolbarItemClick);
@@ -7,6 +7,11 @@ import { isToBeDestroyed } from '../utils/element';
7
7
  import type { BasePluginOptions } from './base-plugin';
8
8
  import { BasePlugin } from './base-plugin';
9
9
 
10
+ /**
11
+ * <zh/> 提示框插件配置项
12
+ *
13
+ * <en/> Tooltip plugin options
14
+ */
10
15
  export interface TooltipOptions
11
16
  extends BasePluginOptions,
12
17
  Pick<TooltipStyleProps, 'position' | 'offset' | 'enterable' | 'style' | 'container' | 'title'> {
@@ -36,6 +41,11 @@ export interface TooltipOptions
36
41
  enable?: boolean | ((event: IElementEvent) => boolean);
37
42
  }
38
43
 
44
+ /**
45
+ * <zh/> 提示框插件
46
+ *
47
+ * <en/> Tooltip plugin
48
+ */
39
49
  export class Tooltip extends BasePlugin<TooltipOptions> {
40
50
  static defaultOptions: Partial<TooltipOptions> = {
41
51
  trigger: 'hover',
@@ -338,6 +348,7 @@ export class Tooltip extends BasePlugin<TooltipOptions> {
338
348
  * <zh/> 销毁tooltip
339
349
  *
340
350
  * <en/> Destroy tooltip
351
+ * @internal
341
352
  */
342
353
  public destroy(): void {
343
354
  this.unbindEvents();
@@ -230,6 +230,7 @@ export class Watermark extends BasePlugin<WatermarkOptions> {
230
230
  * <zh/> 销毁水印
231
231
  *
232
232
  * <en/> Destroy the watermark
233
+ * @internal
233
234
  */
234
235
  public destroy(): void {
235
236
  super.destroy();
@@ -93,7 +93,7 @@ import {
93
93
  CollapseExpandCombo,
94
94
  CollapseExpandNode,
95
95
  GetEdgeActualEnds,
96
- PositionRadialLabels,
96
+ PlaceRadialLabels,
97
97
  ProcessParallelEdges,
98
98
  UpdateRelatedEdge,
99
99
  } from '../transforms';
@@ -210,7 +210,7 @@ const BUILT_IN_EXTENSIONS: ExtensionRegistry = {
210
210
  'collapse-expand-node': CollapseExpandNode,
211
211
  'process-parallel-edges': ProcessParallelEdges,
212
212
  'get-edge-actual-ends': GetEdgeActualEnds,
213
- 'position-radial-labels': PositionRadialLabels,
213
+ 'place-radial-labels': PlaceRadialLabels,
214
214
  },
215
215
  shape: {
216
216
  circle: GCircle,
@@ -1,5 +1,5 @@
1
1
  import { Graph as GraphLib } from '@antv/graphlib';
2
- import { isUndefined, uniq } from '@antv/util';
2
+ import { get, isUndefined, set, uniq } from '@antv/util';
3
3
  import { COMBO_KEY, ChangeType, TREE_KEY } from '../constants';
4
4
  import type { ComboData, EdgeData, GraphData, NodeData } from '../spec';
5
5
  import type {
@@ -529,9 +529,18 @@ export class DataController {
529
529
  */
530
530
  public setParent(id: ID, parent: ID | undefined, hierarchyKey: HierarchyKey, update: boolean = true) {
531
531
  if (id === parent) return;
532
- const originalParentId = parentIdOf(this.getNodeLikeDatum(id));
533
-
532
+ const elementData = this.getNodeLikeDatum(id);
533
+ const originalParentId = parentIdOf(elementData);
534
+
535
+ if (parent) {
536
+ const parentData = this.getNodeLikeDatum(parent);
537
+ if (parentData.style?.zIndex !== undefined) {
538
+ const zIndex = get(parentData, ['style', 'zIndex'], 0) + (this.isCombo(parent) ? 1 : 0);
539
+ set(elementData, ['style', 'zIndex'], zIndex);
540
+ }
541
+ }
534
542
  // Sync data
543
+
535
544
  if (originalParentId !== parent && hierarchyKey === COMBO_KEY) {
536
545
  const modifiedDatum = { id, combo: parent };
537
546
  if (this.isCombo(id)) this.syncComboDatum(modifiedDatum);
@@ -617,10 +626,13 @@ export class DataController {
617
626
  if ([dx, dy, dz].some(isNaN) || [dx, dy, dz].every((o) => o === 0)) return;
618
627
  const combo = this.getComboData([id])[0];
619
628
  if (!combo) return;
629
+ const seenNodeLikeIds = new Set<ID>();
620
630
  dfs<NodeLikeData>(
621
631
  combo,
622
632
  (succeed) => {
623
633
  const succeedID = idOf(succeed);
634
+ if (seenNodeLikeIds.has(succeedID)) return;
635
+ seenNodeLikeIds.add(succeedID);
624
636
  const [x, y, z] = positionOf(succeed);
625
637
  const value = mergeElementsData(succeed, {
626
638
  style: { x: x + dx, y: y + dy, z: z + dz },
@@ -5,6 +5,11 @@ import type { DrawData } from './types';
5
5
 
6
6
  export type BaseTransformOptions = CustomBehaviorOption;
7
7
 
8
+ /**
9
+ * <zh/> 数据转换的基类
10
+ *
11
+ * <en/> Base class for data transforms
12
+ */
8
13
  export abstract class BaseTransform<T extends BaseTransformOptions = BaseTransformOptions> extends BaseExtension<T> {
9
14
  public beforeDraw(data: DrawData, context: DrawContext): DrawData {
10
15
  return data;
@@ -3,10 +3,10 @@ export { BaseTransform } from './base-transform';
3
3
  export { CollapseExpandCombo } from './collapse-expand-combo';
4
4
  export { CollapseExpandNode } from './collapse-expand-node';
5
5
  export { GetEdgeActualEnds } from './get-edge-actual-ends';
6
- export { PositionRadialLabels } from './position-radial-labels';
6
+ export { PlaceRadialLabels } from './place-radial-labels';
7
7
  export { ProcessParallelEdges } from './process-parallel-edges';
8
8
  export { UpdateRelatedEdge } from './update-related-edge';
9
9
 
10
10
  export type { BaseTransformOptions } from './base-transform';
11
- export type { PositionRadialLabelsOptions } from './position-radial-labels';
11
+ export type { PlaceRadialLabelsOptions } from './place-radial-labels';
12
12
  export type { ProcessParallelEdgesOptions } from './process-parallel-edges';