@antv/g6 5.0.0-beta.33 → 5.0.0-beta.34

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 (282) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/dist/lib/behaviors/brush-select.d.ts +2 -3
  3. package/dist/lib/behaviors/collapse-expand.d.ts +1 -2
  4. package/dist/lib/behaviors/create-edge.d.ts +1 -2
  5. package/dist/lib/behaviors/drag-element-force.d.ts +1 -2
  6. package/dist/lib/behaviors/drag-element.d.ts +2 -3
  7. package/dist/lib/behaviors/lasso-select.d.ts +2 -3
  8. package/dist/lib/constants/events/animation.d.ts +1 -4
  9. package/dist/lib/elements/nodes/base-node.d.ts +2 -3
  10. package/dist/lib/elements/nodes/donut.d.ts +45 -0
  11. package/dist/lib/elements/nodes/html.d.ts +27 -0
  12. package/dist/lib/elements/nodes/index.d.ts +4 -0
  13. package/dist/lib/exports.d.ts +4 -3
  14. package/dist/lib/plugins/hull/index.d.ts +1 -2
  15. package/dist/lib/runtime/data.d.ts +4 -4
  16. package/dist/lib/runtime/element.d.ts +3 -3
  17. package/dist/lib/runtime/graph.d.ts +2 -3
  18. package/dist/lib/runtime/viewport.d.ts +1 -2
  19. package/dist/lib/spec/data.d.ts +74 -1
  20. package/dist/lib/spec/element/combo.d.ts +17 -6
  21. package/dist/lib/spec/element/edge.d.ts +14 -2
  22. package/dist/lib/spec/element/node.d.ts +19 -3
  23. package/dist/lib/themes/base.d.ts +1 -0
  24. package/dist/lib/transforms/process-parallel-edges.d.ts +1 -2
  25. package/dist/lib/transforms/types.d.ts +1 -1
  26. package/dist/lib/types/callable.d.ts +2 -2
  27. package/dist/lib/types/data.d.ts +1 -1
  28. package/dist/lib/types/id.d.ts +1 -0
  29. package/dist/lib/types/index.d.ts +1 -0
  30. package/dist/lib/types/style.d.ts +1 -3
  31. package/dist/lib/utils/animation.d.ts +1 -1
  32. package/dist/lib/utils/behaviors/brush.d.ts +1 -2
  33. package/dist/lib/utils/behaviors/lasso.d.ts +1 -2
  34. package/dist/lib/utils/behaviors/utils.d.ts +1 -1
  35. package/dist/lib/utils/edge.d.ts +1 -2
  36. package/dist/lib/utils/id.d.ts +2 -3
  37. package/dist/lib/utils/palette.d.ts +1 -2
  38. package/dist/lib/utils/relation.d.ts +1 -2
  39. package/esm/behaviors/brush-select.d.ts +2 -3
  40. package/esm/behaviors/brush-select.js.map +1 -1
  41. package/esm/behaviors/click-element.js.map +1 -1
  42. package/esm/behaviors/collapse-expand.d.ts +1 -2
  43. package/esm/behaviors/collapse-expand.js.map +1 -1
  44. package/esm/behaviors/create-edge.d.ts +1 -2
  45. package/esm/behaviors/create-edge.js.map +1 -1
  46. package/esm/behaviors/drag-element-force.d.ts +1 -2
  47. package/esm/behaviors/drag-element-force.js.map +1 -1
  48. package/esm/behaviors/drag-element.d.ts +2 -3
  49. package/esm/behaviors/drag-element.js.map +1 -1
  50. package/esm/behaviors/focus-element.js.map +1 -1
  51. package/esm/behaviors/hover-element.js.map +1 -1
  52. package/esm/behaviors/lasso-select.d.ts +2 -3
  53. package/esm/behaviors/lasso-select.js.map +1 -1
  54. package/esm/constants/events/animation.d.ts +1 -4
  55. package/esm/constants/events/animation.js +0 -4
  56. package/esm/constants/events/animation.js.map +1 -1
  57. package/esm/elements/nodes/base-node.d.ts +2 -3
  58. package/esm/elements/nodes/base-node.js.map +1 -1
  59. package/esm/elements/nodes/donut.d.ts +45 -0
  60. package/esm/elements/nodes/donut.js +81 -0
  61. package/esm/elements/nodes/donut.js.map +1 -0
  62. package/esm/elements/nodes/html.d.ts +27 -0
  63. package/esm/elements/nodes/html.js +209 -0
  64. package/esm/elements/nodes/html.js.map +1 -0
  65. package/esm/elements/nodes/index.d.ts +4 -0
  66. package/esm/elements/nodes/index.js +2 -0
  67. package/esm/elements/nodes/index.js.map +1 -1
  68. package/esm/exports.d.ts +4 -3
  69. package/esm/exports.js +2 -1
  70. package/esm/exports.js.map +1 -1
  71. package/esm/plugins/hull/index.d.ts +1 -2
  72. package/esm/plugins/hull/index.js.map +1 -1
  73. package/esm/plugins/legend.js +3 -2
  74. package/esm/plugins/legend.js.map +1 -1
  75. package/esm/registry/build-in.js +5 -3
  76. package/esm/registry/build-in.js.map +1 -1
  77. package/esm/runtime/canvas.js +5 -2
  78. package/esm/runtime/canvas.js.map +1 -1
  79. package/esm/runtime/data.d.ts +4 -4
  80. package/esm/runtime/data.js.map +1 -1
  81. package/esm/runtime/element.d.ts +3 -3
  82. package/esm/runtime/element.js +59 -42
  83. package/esm/runtime/element.js.map +1 -1
  84. package/esm/runtime/graph.d.ts +2 -3
  85. package/esm/runtime/graph.js +11 -9
  86. package/esm/runtime/graph.js.map +1 -1
  87. package/esm/runtime/layout.js +2 -2
  88. package/esm/runtime/layout.js.map +1 -1
  89. package/esm/runtime/viewport.d.ts +1 -2
  90. package/esm/runtime/viewport.js.map +1 -1
  91. package/esm/spec/data.d.ts +74 -1
  92. package/esm/spec/element/combo.d.ts +17 -6
  93. package/esm/spec/element/edge.d.ts +14 -2
  94. package/esm/spec/element/node.d.ts +19 -3
  95. package/esm/themes/base.d.ts +1 -0
  96. package/esm/themes/base.js +2 -0
  97. package/esm/themes/base.js.map +1 -1
  98. package/esm/transforms/process-parallel-edges.d.ts +1 -2
  99. package/esm/transforms/process-parallel-edges.js +2 -4
  100. package/esm/transforms/process-parallel-edges.js.map +1 -1
  101. package/esm/transforms/types.d.ts +1 -1
  102. package/esm/transforms/update-related-edge.js.map +1 -1
  103. package/esm/types/callable.d.ts +2 -2
  104. package/esm/types/data.d.ts +1 -1
  105. package/esm/types/id.d.ts +1 -0
  106. package/esm/types/id.js +2 -0
  107. package/esm/types/id.js.map +1 -0
  108. package/esm/types/index.d.ts +1 -0
  109. package/esm/types/style.d.ts +1 -3
  110. package/esm/utils/animation.d.ts +1 -1
  111. package/esm/utils/animation.js +1 -1
  112. package/esm/utils/animation.js.map +1 -1
  113. package/esm/utils/behaviors/brush.d.ts +1 -2
  114. package/esm/utils/behaviors/brush.js.map +1 -1
  115. package/esm/utils/behaviors/lasso.d.ts +1 -2
  116. package/esm/utils/behaviors/lasso.js.map +1 -1
  117. package/esm/utils/behaviors/utils.d.ts +1 -1
  118. package/esm/utils/change.js.map +1 -1
  119. package/esm/utils/edge.d.ts +1 -2
  120. package/esm/utils/edge.js.map +1 -1
  121. package/esm/utils/id.d.ts +2 -3
  122. package/esm/utils/id.js.map +1 -1
  123. package/esm/utils/palette.d.ts +1 -2
  124. package/esm/utils/palette.js.map +1 -1
  125. package/esm/utils/relation.d.ts +1 -2
  126. package/esm/utils/relation.js.map +1 -1
  127. package/esm/utils/style.js +3 -3
  128. package/esm/utils/style.js.map +1 -1
  129. package/lib/behaviors/brush-select.d.ts +2 -3
  130. package/lib/behaviors/brush-select.js.map +1 -1
  131. package/lib/behaviors/click-element.js.map +1 -1
  132. package/lib/behaviors/collapse-expand.d.ts +1 -2
  133. package/lib/behaviors/collapse-expand.js.map +1 -1
  134. package/lib/behaviors/create-edge.d.ts +1 -2
  135. package/lib/behaviors/create-edge.js.map +1 -1
  136. package/lib/behaviors/drag-element-force.d.ts +1 -2
  137. package/lib/behaviors/drag-element-force.js.map +1 -1
  138. package/lib/behaviors/drag-element.d.ts +2 -3
  139. package/lib/behaviors/drag-element.js.map +1 -1
  140. package/lib/behaviors/focus-element.js.map +1 -1
  141. package/lib/behaviors/hover-element.js.map +1 -1
  142. package/lib/behaviors/lasso-select.d.ts +2 -3
  143. package/lib/behaviors/lasso-select.js.map +1 -1
  144. package/lib/constants/events/animation.d.ts +1 -4
  145. package/lib/constants/events/animation.js +0 -4
  146. package/lib/constants/events/animation.js.map +1 -1
  147. package/lib/elements/nodes/base-node.d.ts +2 -3
  148. package/lib/elements/nodes/base-node.js.map +1 -1
  149. package/lib/elements/nodes/donut.d.ts +45 -0
  150. package/lib/elements/nodes/donut.js +85 -0
  151. package/lib/elements/nodes/donut.js.map +1 -0
  152. package/lib/elements/nodes/html.d.ts +27 -0
  153. package/lib/elements/nodes/html.js +213 -0
  154. package/lib/elements/nodes/html.js.map +1 -0
  155. package/lib/elements/nodes/index.d.ts +4 -0
  156. package/lib/elements/nodes/index.js +5 -1
  157. package/lib/elements/nodes/index.js.map +1 -1
  158. package/lib/exports.d.ts +4 -3
  159. package/lib/exports.js +5 -1
  160. package/lib/exports.js.map +1 -1
  161. package/lib/plugins/hull/index.d.ts +1 -2
  162. package/lib/plugins/hull/index.js.map +1 -1
  163. package/lib/plugins/legend.js +3 -2
  164. package/lib/plugins/legend.js.map +1 -1
  165. package/lib/registry/build-in.js +4 -2
  166. package/lib/registry/build-in.js.map +1 -1
  167. package/lib/runtime/canvas.js +5 -2
  168. package/lib/runtime/canvas.js.map +1 -1
  169. package/lib/runtime/data.d.ts +4 -4
  170. package/lib/runtime/data.js.map +1 -1
  171. package/lib/runtime/element.d.ts +3 -3
  172. package/lib/runtime/element.js +58 -41
  173. package/lib/runtime/element.js.map +1 -1
  174. package/lib/runtime/graph.d.ts +2 -3
  175. package/lib/runtime/graph.js +10 -8
  176. package/lib/runtime/graph.js.map +1 -1
  177. package/lib/runtime/layout.js +2 -2
  178. package/lib/runtime/layout.js.map +1 -1
  179. package/lib/runtime/viewport.d.ts +1 -2
  180. package/lib/runtime/viewport.js.map +1 -1
  181. package/lib/spec/data.d.ts +74 -1
  182. package/lib/spec/element/combo.d.ts +17 -6
  183. package/lib/spec/element/edge.d.ts +14 -2
  184. package/lib/spec/element/node.d.ts +19 -3
  185. package/lib/themes/base.d.ts +1 -0
  186. package/lib/themes/base.js +2 -0
  187. package/lib/themes/base.js.map +1 -1
  188. package/lib/transforms/process-parallel-edges.d.ts +1 -2
  189. package/lib/transforms/process-parallel-edges.js +2 -4
  190. package/lib/transforms/process-parallel-edges.js.map +1 -1
  191. package/lib/transforms/types.d.ts +1 -1
  192. package/lib/transforms/update-related-edge.js.map +1 -1
  193. package/lib/types/callable.d.ts +2 -2
  194. package/lib/types/data.d.ts +1 -1
  195. package/lib/types/id.d.ts +1 -0
  196. package/lib/{spec/element/base.js → types/id.js} +1 -1
  197. package/lib/types/id.js.map +1 -0
  198. package/lib/types/index.d.ts +1 -0
  199. package/lib/types/style.d.ts +1 -3
  200. package/lib/utils/animation.d.ts +1 -1
  201. package/lib/utils/animation.js +1 -1
  202. package/lib/utils/animation.js.map +1 -1
  203. package/lib/utils/behaviors/brush.d.ts +1 -2
  204. package/lib/utils/behaviors/brush.js.map +1 -1
  205. package/lib/utils/behaviors/lasso.d.ts +1 -2
  206. package/lib/utils/behaviors/lasso.js.map +1 -1
  207. package/lib/utils/behaviors/utils.d.ts +1 -1
  208. package/lib/utils/change.js.map +1 -1
  209. package/lib/utils/edge.d.ts +1 -2
  210. package/lib/utils/edge.js.map +1 -1
  211. package/lib/utils/id.d.ts +2 -3
  212. package/lib/utils/id.js.map +1 -1
  213. package/lib/utils/palette.d.ts +1 -2
  214. package/lib/utils/palette.js.map +1 -1
  215. package/lib/utils/relation.d.ts +1 -2
  216. package/lib/utils/relation.js.map +1 -1
  217. package/lib/utils/style.js +3 -3
  218. package/lib/utils/style.js.map +1 -1
  219. package/package.json +1 -1
  220. package/src/behaviors/brush-select.ts +1 -2
  221. package/src/behaviors/click-element.ts +1 -2
  222. package/src/behaviors/collapse-expand.ts +1 -2
  223. package/src/behaviors/create-edge.ts +1 -2
  224. package/src/behaviors/drag-element-force.ts +1 -2
  225. package/src/behaviors/drag-element.ts +1 -2
  226. package/src/behaviors/focus-element.ts +1 -2
  227. package/src/behaviors/hover-element.ts +1 -2
  228. package/src/behaviors/lasso-select.ts +1 -2
  229. package/src/constants/events/animation.ts +0 -4
  230. package/src/elements/nodes/base-node.ts +3 -3
  231. package/src/elements/nodes/donut.ts +137 -0
  232. package/src/elements/nodes/html.ts +230 -0
  233. package/src/elements/nodes/index.ts +4 -0
  234. package/src/exports.ts +20 -1
  235. package/src/plugins/hull/index.ts +1 -2
  236. package/src/plugins/legend.ts +4 -4
  237. package/src/registry/build-in.ts +6 -2
  238. package/src/runtime/canvas.ts +5 -2
  239. package/src/runtime/data.ts +2 -1
  240. package/src/runtime/element.ts +62 -36
  241. package/src/runtime/graph.ts +13 -10
  242. package/src/runtime/layout.ts +4 -4
  243. package/src/runtime/viewport.ts +1 -2
  244. package/src/spec/data.ts +74 -1
  245. package/src/spec/element/combo.ts +17 -6
  246. package/src/spec/element/edge.ts +14 -2
  247. package/src/spec/element/node.ts +19 -3
  248. package/src/themes/base.ts +3 -0
  249. package/src/transforms/arrange-draw-order.ts +1 -1
  250. package/src/transforms/process-parallel-edges.ts +4 -6
  251. package/src/transforms/types.ts +1 -1
  252. package/src/transforms/update-related-edge.ts +1 -2
  253. package/src/types/callable.ts +2 -2
  254. package/src/types/data.ts +1 -1
  255. package/src/types/id.ts +1 -0
  256. package/src/types/index.ts +1 -0
  257. package/src/types/style.ts +1 -3
  258. package/src/utils/animation.ts +2 -2
  259. package/src/utils/behaviors/brush.ts +1 -2
  260. package/src/utils/behaviors/lasso.ts +1 -2
  261. package/src/utils/behaviors/utils.ts +1 -1
  262. package/src/utils/change.ts +1 -2
  263. package/src/utils/edge.ts +1 -1
  264. package/src/utils/id.ts +1 -2
  265. package/src/utils/palette.ts +1 -1
  266. package/src/utils/relation.ts +1 -2
  267. package/src/utils/style.ts +3 -3
  268. package/dist/lib/runtime/index.d.ts +0 -6
  269. package/dist/lib/spec/element/base.d.ts +0 -6
  270. package/esm/runtime/index.d.ts +0 -6
  271. package/esm/runtime/index.js +0 -7
  272. package/esm/runtime/index.js.map +0 -1
  273. package/esm/spec/element/base.d.ts +0 -6
  274. package/esm/spec/element/base.js +0 -2
  275. package/esm/spec/element/base.js.map +0 -1
  276. package/lib/runtime/index.d.ts +0 -6
  277. package/lib/runtime/index.js +0 -8
  278. package/lib/runtime/index.js.map +0 -1
  279. package/lib/spec/element/base.d.ts +0 -6
  280. package/lib/spec/element/base.js.map +0 -1
  281. package/src/runtime/index.ts +0 -7
  282. package/src/spec/element/base.ts +0 -6
@@ -1,7 +1,6 @@
1
1
  import EventEmitter from '@antv/event-emitter';
2
2
  import type { AABB, BaseStyleProps } from '@antv/g';
3
- import type { ID } from '@antv/graphlib';
4
- import { debounce, isEqual, isFunction, isNumber, isObject, isString, omit } from '@antv/util';
3
+ import { debounce, isArray, isEqual, isFunction, isNumber, isObject, isString, omit } from '@antv/util';
5
4
  import { COMBO_KEY, GraphEvent } from '../constants';
6
5
  import type { Plugin } from '../plugins/types';
7
6
  import { getExtension } from '../registry';
@@ -30,6 +29,7 @@ import type {
30
29
  ElementDatum,
31
30
  ElementType,
32
31
  FitViewOptions,
32
+ ID,
33
33
  IEvent,
34
34
  NodeLikeData,
35
35
  PartialEdgeData,
@@ -65,8 +65,6 @@ export class Graph extends EventEmitter {
65
65
 
66
66
  static defaultOptions: G6Spec = {
67
67
  autoResize: false,
68
- width: 800,
69
- height: 600,
70
68
  theme: 'light',
71
69
  rotation: 0,
72
70
  zoom: 1,
@@ -146,7 +144,7 @@ export class Graph extends EventEmitter {
146
144
 
147
145
  if (zoomRange) this.options.zoomRange = zoomRange;
148
146
  if (isNumber(zoom)) this.options.zoom = zoom;
149
- if (isNumber(padding)) this.options.padding = padding;
147
+ if (isNumber(padding) || isArray(padding)) this.options.padding = padding;
150
148
  }
151
149
 
152
150
  public setBackground(background: G6Spec['background']): void {
@@ -486,13 +484,14 @@ export class Graph extends EventEmitter {
486
484
  await container.init();
487
485
  } else {
488
486
  const $container = isString(container) ? document.getElementById(container!) : container;
487
+ const containerSize = sizeOf($container!);
489
488
 
490
489
  this.emit(GraphEvent.BEFORE_CANVAS_INIT, { container: $container, width, height });
491
490
 
492
491
  const canvas = new Canvas({
493
492
  container: $container!,
494
- width,
495
- height,
493
+ width: width ?? containerSize[0],
494
+ height: height ?? containerSize[1],
496
495
  renderer,
497
496
  });
498
497
 
@@ -502,7 +501,7 @@ export class Graph extends EventEmitter {
502
501
  }
503
502
  }
504
503
 
505
- private createRuntime() {
504
+ private initRuntime() {
506
505
  this.context.options = this.options;
507
506
  if (!this.context.batch) this.context.batch = new BatchController(this.context);
508
507
  if (!this.context.plugin) this.context.plugin = new PluginController(this.context);
@@ -514,10 +513,14 @@ export class Graph extends EventEmitter {
514
513
  }
515
514
 
516
515
  private async prepare(): Promise<void> {
516
+ // 等待同步任务执行完成,避免 render 后立即调用 destroy 导致的问题
517
+ // Wait for synchronous tasks to complete, to avoid problems caused by calling destroy immediately after render
518
+ await Promise.resolve();
519
+
517
520
  if (this.destroyed) throw new Error('Graph has been destroyed');
518
521
 
519
522
  await this.initCanvas();
520
- this.createRuntime();
523
+ this.initRuntime();
521
524
  }
522
525
 
523
526
  /**
@@ -530,8 +533,8 @@ export class Graph extends EventEmitter {
530
533
  * <en/> This process will execute data update, element rendering, and layout execution
531
534
  */
532
535
  public async render(): Promise<void> {
533
- emit(this, new GraphLifeCycleEvent(GraphEvent.BEFORE_RENDER));
534
536
  await this.prepare();
537
+ emit(this, new GraphLifeCycleEvent(GraphEvent.BEFORE_RENDER));
535
538
  await Promise.all([this.context.element?.draw(), this.context.layout?.layout()]);
536
539
  await this.autoFit();
537
540
  emit(this, new GraphLifeCycleEvent(GraphEvent.AFTER_RENDER));
@@ -8,7 +8,7 @@ import { COMBO_KEY, GraphEvent, TREE_KEY } from '../constants';
8
8
  import { getExtension } from '../registry';
9
9
  import type { EdgeData, NodeData } from '../spec';
10
10
  import type { STDLayoutOptions } from '../spec/layout';
11
- import type { Combo, Node, PartialGraphData, TreeData } from '../types';
11
+ import type { Combo, ID, Node, PartialGraphData, TreeData } from '../types';
12
12
  import { getAnimation } from '../utils/animation';
13
13
  import { isVisible } from '../utils/element';
14
14
  import { GraphLifeCycleEvent, emit } from '../utils/event';
@@ -292,7 +292,7 @@ export class LayoutController {
292
292
  const nodeSize: number | ((node: LayoutGraphlibNode) => number) =
293
293
  (options?.nodeSize as number) ??
294
294
  ((node) => {
295
- const nodeElement = element?.getElement<Node | Combo>(node.id);
295
+ const nodeElement = element?.getElement<Node | Combo>(node.id as string);
296
296
  const { size } = nodeElement?.attributes || {};
297
297
  return Math.max(...parseSize(size));
298
298
  });
@@ -327,7 +327,7 @@ export class LayoutController {
327
327
  const { nodes, edges } = layoutData;
328
328
  const dataToUpdate: Required<PartialGraphData> = { nodes: [], edges: [], combos: [] };
329
329
  nodes.forEach(({ id, data: { x, y, z = 0 } }) => {
330
- dataToUpdate.nodes.push({ id, style: { x, y, z } });
330
+ dataToUpdate.nodes.push({ id: id as ID, style: { x, y, z } });
331
331
  });
332
332
 
333
333
  edges.forEach(({ id, data: { points = [], controlPoints = points.slice(1, points.length - 1) } }) => {
@@ -338,7 +338,7 @@ export class LayoutController {
338
338
  if (controlPoints?.length) {
339
339
  // points 的第一个点是起点,最后一个点是终点,中间的点是控制点
340
340
  // The first point of points is the starting point, and the last point is the end point, and the middle point is the control point
341
- dataToUpdate.edges.push({ id, style: { controlPoints: controlPoints.map(parsePoint) } });
341
+ dataToUpdate.edges.push({ id: id as ID, style: { controlPoints: controlPoints.map(parsePoint) } });
342
342
  }
343
343
  });
344
344
 
@@ -1,8 +1,7 @@
1
1
  import { AABB } from '@antv/g';
2
- import type { ID } from '@antv/graphlib';
3
2
  import { clamp, isNumber, pick } from '@antv/util';
4
3
  import { AnimationType, GraphEvent } from '../constants';
5
- import type { FitViewOptions, Point, TransformOptions, Vector2, ViewportAnimationEffectTiming } from '../types';
4
+ import type { FitViewOptions, ID, Point, TransformOptions, Vector2, ViewportAnimationEffectTiming } from '../types';
6
5
  import { getAnimation } from '../utils/animation';
7
6
  import { getBBoxSize, getCombinedBBox } from '../utils/bbox';
8
7
  import { AnimateEvent, ViewportEvent, emit } from '../utils/event';
package/src/spec/data.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ID } from '@antv/graphlib';
1
+ import type { ID } from '../types';
2
2
  import type { ComboStyle } from './element/combo';
3
3
  import type { EdgeStyle } from './element/edge';
4
4
  import type { NodeStyle } from './element/node';
@@ -25,24 +25,97 @@ export interface GraphData {
25
25
  }
26
26
 
27
27
  export interface NodeData {
28
+ /**
29
+ * <zh/> 节点 ID
30
+ *
31
+ * <en/> Node ID
32
+ */
28
33
  id: ID;
34
+ /**
35
+ * <zh/> 节点类型
36
+ *
37
+ * <en/> Node type
38
+ */
39
+ type?: string;
40
+ /**
41
+ * <zh/> 节点数据
42
+ *
43
+ * <en/> Node data
44
+ */
29
45
  data?: Record<string, unknown>;
46
+ /**
47
+ * <zh/> 节点样式
48
+ *
49
+ * <en/> Node style
50
+ */
30
51
  style?: NodeStyle;
31
52
  [key: string]: unknown;
32
53
  }
33
54
 
34
55
  export interface ComboData {
56
+ /**
57
+ * <zh/> Combo ID
58
+ *
59
+ * <en/> Combo ID
60
+ */
35
61
  id: ID;
62
+ /**
63
+ * <zh/> Combo 类型
64
+ *
65
+ * <en/> Combo type
66
+ */
67
+ type?: string;
68
+ /**
69
+ * <zh/> Combo 数据
70
+ *
71
+ * <en/> Combo data
72
+ */
36
73
  data?: Record<string, unknown>;
74
+ /**
75
+ * <zh/> Combo 样式
76
+ *
77
+ * <en/> Combo style
78
+ */
37
79
  style?: ComboStyle;
38
80
  [key: string]: unknown;
39
81
  }
40
82
 
41
83
  export interface EdgeData {
84
+ /**
85
+ * <zh/> 边 ID
86
+ *
87
+ * <en/> Edge ID
88
+ */
42
89
  id?: ID;
90
+ /**
91
+ * <zh/> 边源节点 ID
92
+ *
93
+ * <en/> Source node ID
94
+ */
43
95
  source: ID;
96
+ /**
97
+ * <zh/> 边目标节点 ID
98
+ *
99
+ * <en/> Target node ID
100
+ */
44
101
  target: ID;
102
+ /**
103
+ * <zh/> 边类型
104
+ *
105
+ * <en/> Edge type
106
+ */
107
+ type?: string;
108
+ /**
109
+ * <zh/> 边数据
110
+ *
111
+ * <en/> Edge data
112
+ */
45
113
  data?: Record<string, unknown>;
114
+ /**
115
+ * <zh/> 边样式
116
+ *
117
+ * <en/> Edge style
118
+ */
46
119
  style?: EdgeStyle;
47
120
  [key: string]: unknown;
48
121
  }
@@ -1,9 +1,8 @@
1
- import type { ID } from '@antv/graphlib';
2
1
  import type { BaseComboStyleProps } from '../../elements/combos';
2
+ import type { ID, State } from '../../types';
3
3
  import type { CallableObject } from '../../types/callable';
4
- import type { NodeData } from '../data';
4
+ import type { ComboData } from '../data';
5
5
  import type { AnimationOptions } from './animation';
6
- import type { BaseElementStyle } from './base';
7
6
  import type { PaletteOptions } from './palette';
8
7
 
9
8
  /**
@@ -12,18 +11,24 @@ import type { PaletteOptions } from './palette';
12
11
  * <en/> Combo spec
13
12
  */
14
13
  export interface ComboOptions {
14
+ /**
15
+ * <zh/> Combo 类型
16
+ *
17
+ * <en/> Combo type
18
+ */
19
+ type?: string | ((datum: ComboData) => string);
15
20
  /**
16
21
  * <zh/> Combo 样式
17
22
  *
18
23
  * <en/> Combo style
19
24
  */
20
- style?: CallableObject<ComboStyle, NodeData>;
25
+ style?: CallableObject<ComboStyle, ComboData>;
21
26
  /**
22
27
  * <zh/> Combo 状态样式
23
28
  *
24
29
  * <en/> Combo state style
25
30
  */
26
- state?: Record<string, CallableObject<ComboStyle, NodeData>>;
31
+ state?: Record<string, CallableObject<ComboStyle, ComboData>>;
27
32
  /**
28
33
  * <zh/> Combo 动画
29
34
  *
@@ -45,7 +50,13 @@ export interface StaticComboOptions {
45
50
  palette?: PaletteOptions;
46
51
  }
47
52
 
48
- export interface ComboStyle extends BaseElementStyle, Partial<BaseComboStyleProps> {
53
+ export interface ComboStyle extends Partial<BaseComboStyleProps> {
54
+ /**
55
+ * <zh/> 初始状态
56
+ *
57
+ * <en/> Initial state
58
+ */
59
+ states?: State[];
49
60
  children?: ID[];
50
61
  [key: string]: any;
51
62
  }
@@ -1,8 +1,8 @@
1
1
  import type { BaseEdgeStyleProps } from '../../elements/edges';
2
+ import { State } from '../../types';
2
3
  import type { CallableObject } from '../../types/callable';
3
4
  import type { EdgeData } from '../data';
4
5
  import type { AnimationOptions } from './animation';
5
- import type { BaseElementStyle } from './base';
6
6
  import type { PaletteOptions } from './palette';
7
7
 
8
8
  /**
@@ -11,6 +11,12 @@ import type { PaletteOptions } from './palette';
11
11
  * <en/> Edge spec
12
12
  */
13
13
  export interface EdgeOptions {
14
+ /**
15
+ * <zh/> 边类型
16
+ *
17
+ * <en/> Edge type
18
+ */
19
+ type?: string | ((datum: EdgeData) => string);
14
20
  /**
15
21
  * <zh/> 边样式
16
22
  *
@@ -44,6 +50,12 @@ export interface StaticEdgeOptions {
44
50
  palette?: PaletteOptions;
45
51
  }
46
52
 
47
- export interface EdgeStyle extends BaseElementStyle, Partial<BaseEdgeStyleProps> {
53
+ export interface EdgeStyle extends Partial<BaseEdgeStyleProps> {
54
+ /**
55
+ * <zh/> 初始状态
56
+ *
57
+ * <en/> Initial state
58
+ */
59
+ states?: State[];
48
60
  [key: string]: any;
49
61
  }
@@ -1,9 +1,8 @@
1
- import type { ID } from '@antv/graphlib';
2
1
  import type { BaseNodeStyleProps } from '../../elements/nodes';
2
+ import type { ID, State } from '../../types';
3
3
  import type { CallableObject } from '../../types/callable';
4
4
  import type { NodeData } from '../data';
5
5
  import type { AnimationOptions } from './animation';
6
- import type { BaseElementStyle } from './base';
7
6
  import type { PaletteOptions } from './palette';
8
7
 
9
8
  /**
@@ -12,6 +11,12 @@ import type { PaletteOptions } from './palette';
12
11
  * <en/> Node spec
13
12
  */
14
13
  export interface NodeOptions {
14
+ /**
15
+ * <zh/> 节点类型
16
+ *
17
+ * <en/> Node type
18
+ */
19
+ type?: string | ((datum: NodeData) => string);
15
20
  /**
16
21
  * <zh/> 节点样式
17
22
  *
@@ -45,7 +50,18 @@ export interface StaticNodeOptions {
45
50
  palette?: PaletteOptions;
46
51
  }
47
52
 
48
- export interface NodeStyle extends BaseElementStyle, Partial<BaseNodeStyleProps> {
53
+ export interface NodeStyle extends Partial<BaseNodeStyleProps> {
54
+ /**
55
+ * <zh/> 初始状态
56
+ *
57
+ * <en/> Initial state
58
+ */
59
+ states?: State[];
60
+ /**
61
+ * <zh/> 子节点 ID (树图专用)
62
+ *
63
+ * <en/> Child node ID (for tree graph)
64
+ */
49
65
  children?: ID[];
50
66
  [key: string]: any;
51
67
  }
@@ -34,6 +34,7 @@ type ThemeTokens = {
34
34
  nodeStroke: string;
35
35
  nodeBadgePalette?: string[];
36
36
  nodePaletteOptions?: PaletteOptions;
37
+ donutPaletteOptions?: PaletteOptions;
37
38
  edgeColor: string;
38
39
  edgeColorDisabled: string;
39
40
  edgePaletteOptions?: PaletteOptions;
@@ -120,6 +121,7 @@ export function create(tokens: ThemeTokens): Theme {
120
121
  strokeOpacity: 0.85,
121
122
  },
122
123
  inactive: {
124
+ donutOpacity: 0.25,
123
125
  iconOpacity: 0.25,
124
126
  labelOpacity: 0.25,
125
127
  opacity: 0.25,
@@ -127,6 +129,7 @@ export function create(tokens: ThemeTokens): Theme {
127
129
  disabled: {
128
130
  color: nodeColorDisabled,
129
131
  labelOpacity: 0.25,
132
+ donutOpacity: 0.25,
130
133
  },
131
134
  },
132
135
  animation: {
@@ -1,5 +1,5 @@
1
- import type { ID } from '@antv/graphlib';
2
1
  import type { ComboData } from '../spec';
2
+ import type { ID } from '../types';
3
3
  import { idOf } from '../utils/id';
4
4
  import { BaseTransform } from './base-transform';
5
5
  import type { DrawData } from './types';
@@ -1,9 +1,8 @@
1
1
  import type { PathStyleProps } from '@antv/g';
2
- import type { ID } from '@antv/graphlib';
3
2
  import { deepMix, isBoolean, isEmpty } from '@antv/util';
4
3
  import type { RuntimeContext } from '../runtime/types';
5
4
  import type { EdgeData } from '../spec';
6
- import type { ElementDatum, ElementType, LoopPlacement, NodeLikeData } from '../types';
5
+ import type { ElementDatum, ElementType, ID, LoopPlacement, NodeLikeData } from '../types';
7
6
  import { groupByChangeType, reduceDataChanges } from '../utils/change';
8
7
  import { idOf } from '../utils/id';
9
8
  import type { BaseTransformOptions } from './base-transform';
@@ -153,9 +152,7 @@ export class ProcessParallelEdges extends BaseTransform<ProcessParallelEdgesOpti
153
152
  arcEdges.forEach((edge, i, edgeArr) => {
154
153
  const computeStyle = () => {
155
154
  const length = edgeArr.length;
156
- const style: EdgeData['style'] = {
157
- type: CUBIC_EDGE_TYPE,
158
- };
155
+ const style: EdgeData['style'] = {};
159
156
  if (edge.source === edge.target) {
160
157
  const len = CUBIC_LOOP_PLACEMENTS.length;
161
158
  style.loopPlacement = CUBIC_LOOP_PLACEMENTS[i % len];
@@ -172,7 +169,8 @@ export class ProcessParallelEdges extends BaseTransform<ProcessParallelEdgesOpti
172
169
  return style;
173
170
  };
174
171
 
175
- const mergedEdgeData = deepMix(edge, { style: computeStyle() });
172
+ const mergedEdgeData = deepMix(edge, { type: CUBIC_EDGE_TYPE, style: computeStyle() });
173
+
176
174
  const element = this.context.element?.getElement(idOf(edge));
177
175
  if (element) reassignTo('update', 'edge', mergedEdgeData);
178
176
  else reassignTo('add', 'edge', mergedEdgeData);
@@ -1,5 +1,5 @@
1
- import { ID } from '@antv/graphlib';
2
1
  import type { ComboData, EdgeData, NodeData } from '../spec';
2
+ import type { ID } from '../types';
3
3
  import type { BaseTransform, BaseTransformOptions } from './base-transform';
4
4
 
5
5
  export type BuiltInTransformOptions = BaseTransformOptions;
@@ -1,5 +1,4 @@
1
- import type { ID } from '@antv/graphlib';
2
- import type { NodeLikeData } from '../types';
1
+ import type { ID, NodeLikeData } from '../types';
3
2
  import { idOf } from '../utils/id';
4
3
  import { BaseTransform } from './base-transform';
5
4
  import type { DrawData } from './types';
@@ -27,7 +27,7 @@ export type CallableValue<Returns, Param = Returns> = Returns | ((args: Param) =
27
27
  * }
28
28
  */
29
29
  export type CallableObject<Obj extends Record<string, unknown>, T> =
30
- | ((datum: T, index: number, data: T[]) => Obj)
30
+ | ((datum: T) => Obj)
31
31
  | {
32
- [K in keyof Obj]: Obj[K] | ((datum: T, index: number, data: T[]) => NonNullable<Obj[K]>);
32
+ [K in keyof Obj]: Obj[K] | ((datum: T) => NonNullable<Obj[K]>);
33
33
  };
package/src/types/data.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { ID } from '@antv/graphlib';
2
1
  import type { ComboData, EdgeData, NodeData } from '../spec/data';
2
+ import type { ID } from '../types';
3
3
 
4
4
  export type DataID = {
5
5
  nodes?: ID[];
@@ -0,0 +1 @@
1
+ export type ID = string;
@@ -9,6 +9,7 @@ export type * from './element';
9
9
  export type * from './enum';
10
10
  export type * from './event';
11
11
  export type * from './graphlib';
12
+ export type * from './id';
12
13
  export type * from './node';
13
14
  export type * from './padding';
14
15
  export type * from './placement';
@@ -1,4 +1,4 @@
1
- import type { ElementData, ElementDatum } from './data';
1
+ import type { ElementDatum } from './data';
2
2
 
3
3
  /**
4
4
  * <zh/> 样式计算迭代上下文
@@ -7,6 +7,4 @@ import type { ElementData, ElementDatum } from './data';
7
7
  */
8
8
  export type StyleIterationContext = {
9
9
  datum: ElementDatum;
10
- index: number;
11
- elementData: ElementData;
12
10
  };
@@ -182,7 +182,7 @@ type Callbacks = {
182
182
  * @param callbacks - <zh/> 回调函数 | <en/> callback function
183
183
  * @returns <zh/> 动画对象 | <en/> animation object
184
184
  */
185
- export function withAnimationCallbacks(animation: IAnimation | null, callbacks: Callbacks) {
185
+ export function withAnimationCallbacks(animation: IAnimation | null | undefined, callbacks: Callbacks) {
186
186
  callbacks.before?.();
187
187
  if (animation) {
188
188
  callbacks.beforeAnimate?.(animation);
@@ -193,7 +193,7 @@ export function withAnimationCallbacks(animation: IAnimation | null, callbacks:
193
193
  } else {
194
194
  callbacks.after?.();
195
195
  }
196
- return animation;
196
+ return animation || null;
197
197
  }
198
198
 
199
199
  /**
@@ -1,8 +1,7 @@
1
1
  import { isPointInPolygon } from '../point';
2
2
 
3
- import type { ID } from '@antv/graphlib';
4
3
  import type { Graph } from '../../runtime/graph';
5
- import type { Point, Points } from '../../types';
4
+ import type { ID, Point, Points } from '../../types';
6
5
 
7
6
  /**
8
7
  * <zh/> 元素中心是否在 rect 中
@@ -2,9 +2,8 @@ import { AABB } from '@antv/g';
2
2
  import { getLinesIntersection } from '../line';
3
3
  import { isPointInPolygon } from '../point';
4
4
 
5
- import type { ID } from '@antv/graphlib';
6
5
  import type { Graph } from '../../runtime/graph';
7
- import type { Points } from '../../types';
6
+ import type { ID, Points } from '../../types';
8
7
  import type { LineSegment } from '../line';
9
8
 
10
9
  /**
@@ -1,8 +1,8 @@
1
1
  import { isFunction } from '@antv/util';
2
2
 
3
- import type { ID } from '@antv/graphlib';
4
3
  import type { States } from '../../behaviors/types';
5
4
  import type { Graph } from '../../runtime/graph';
5
+ import type { ID } from '../../types';
6
6
 
7
7
  /**
8
8
  * <zh/> 获取所有元素状态.
@@ -1,7 +1,6 @@
1
- import type { ID } from '@antv/graphlib';
2
1
  import { groupBy } from '@antv/util';
3
2
  import { ChangeType } from '../constants';
4
- import type { DataAdded, DataChange, DataChanges, DataRemoved, DataUpdated } from '../types';
3
+ import type { DataAdded, DataChange, DataChanges, DataRemoved, DataUpdated, ID } from '../types';
5
4
  import { idOf } from './id';
6
5
 
7
6
  /**
package/src/utils/edge.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import type { AABB } from '@antv/g';
2
- import type { ID } from '@antv/graphlib';
3
2
  import type { PathArray } from '@antv/util';
4
3
  import { isEqual, isNumber } from '@antv/util';
5
4
  import type { EdgeData } from '../spec';
@@ -7,6 +6,7 @@ import type {
7
6
  EdgeKey,
8
7
  EdgeLabelPlacement,
9
8
  EdgeLabelStyleProps,
9
+ ID,
10
10
  LoopPlacement,
11
11
  Node,
12
12
  Point,
package/src/utils/id.ts CHANGED
@@ -1,7 +1,6 @@
1
- import type { ID } from '@antv/graphlib';
2
1
  import { isNumber, isString } from '@antv/util';
3
2
  import type { ComboData, EdgeData, GraphData, NodeData } from '../spec';
4
- import type { DataID } from '../types';
3
+ import type { DataID, ID } from '../types';
5
4
  import { isEdgeData } from './is';
6
5
 
7
6
  /**
@@ -1,8 +1,8 @@
1
- import type { ID } from '@antv/graphlib';
2
1
  import { groupBy, isFunction, isNumber, isString } from '@antv/util';
3
2
  import type { CategoricalPalette } from '../palettes/types';
4
3
  import { getExtension } from '../registry';
5
4
  import type { PaletteOptions, STDPaletteOptions } from '../spec/element/palette';
5
+ import type { ID } from '../types';
6
6
  import type { ElementData, ElementDatum } from '../types/data';
7
7
  import { idOf } from './id';
8
8
 
@@ -1,6 +1,5 @@
1
- import type { ID } from '@antv/graphlib';
2
1
  import type { Graph } from '../runtime/graph';
3
- import type { ElementType } from '../types';
2
+ import type { ElementType, ID } from '../types';
4
3
  import { idOf } from './id';
5
4
  import { bfs } from './traverse';
6
5
 
@@ -14,13 +14,13 @@ export function computeElementCallbackStyle(
14
14
  callableStyle: CallableObject<Record<string, unknown>, ElementDatum>,
15
15
  context: StyleIterationContext,
16
16
  ) {
17
- const { datum, index, elementData } = context;
17
+ const { datum } = context;
18
18
 
19
- if (isFunction(callableStyle)) return callableStyle(datum, index, elementData);
19
+ if (isFunction(callableStyle)) return callableStyle(datum);
20
20
 
21
21
  return Object.fromEntries(
22
22
  Object.entries(callableStyle).map(([key, style]) => {
23
- if (isFunction(style)) return [key, style(datum, index, elementData)];
23
+ if (isFunction(style)) return [key, style(datum)];
24
24
  return [key, style];
25
25
  }),
26
26
  );
@@ -1,6 +0,0 @@
1
- /**
2
- * <zh/> 运行时,包括数据处理、布局、渲染等
3
- *
4
- * <en/> Runtime, including data processing, layout, rendering, etc.
5
- */
6
- export {};
@@ -1,6 +0,0 @@
1
- export interface BaseElementStyle {
2
- /** <zh/> 元素类型 | <en/> Element type */
3
- type?: string;
4
- /** <zh/> 初始状态 | <en/> Initial state */
5
- states?: string[];
6
- }
@@ -1,6 +0,0 @@
1
- /**
2
- * <zh/> 运行时,包括数据处理、布局、渲染等
3
- *
4
- * <en/> Runtime, including data processing, layout, rendering, etc.
5
- */
6
- export {};
@@ -1,7 +0,0 @@
1
- /**
2
- * <zh/> 运行时,包括数据处理、布局、渲染等
3
- *
4
- * <en/> Runtime, including data processing, layout, rendering, etc.
5
- */
6
- export {};
7
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"src/","sources":["runtime/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -1,6 +0,0 @@
1
- export interface BaseElementStyle {
2
- /** <zh/> 元素类型 | <en/> Element type */
3
- type?: string;
4
- /** <zh/> 初始状态 | <en/> Initial state */
5
- states?: string[];
6
- }