@antv/g6 5.0.1-beta.2 → 5.0.2

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/click-select.d.ts +4 -5
  3. package/dist/lib/elements/base-element.d.ts +1 -22
  4. package/dist/lib/elements/combos/base-combo.d.ts +4 -4
  5. package/dist/lib/elements/edges/base-edge.d.ts +4 -2
  6. package/dist/lib/elements/effect.d.ts +17 -0
  7. package/dist/lib/elements/nodes/base-node.d.ts +5 -4
  8. package/dist/lib/elements/nodes/diamond.d.ts +0 -1
  9. package/dist/lib/elements/shapes/badge.d.ts +17 -6
  10. package/dist/lib/elements/shapes/base-shape.d.ts +9 -3
  11. package/dist/lib/elements/shapes/icon.d.ts +15 -3
  12. package/dist/lib/elements/shapes/label.d.ts +18 -7
  13. package/dist/lib/exports.d.ts +3 -2
  14. package/dist/lib/index.d.ts +5 -1
  15. package/dist/lib/layouts/base-layout.d.ts +3 -1
  16. package/dist/lib/plugins/bubble-sets.d.ts +2 -2
  17. package/dist/lib/plugins/hull/index.d.ts +2 -2
  18. package/dist/lib/runtime/canvas.d.ts +15 -2
  19. package/dist/lib/runtime/data.d.ts +7 -16
  20. package/dist/lib/runtime/element.d.ts +18 -2
  21. package/dist/lib/runtime/graph.d.ts +372 -108
  22. package/dist/lib/spec/element/edge.d.ts +1 -1
  23. package/dist/lib/spec/element/node.d.ts +1 -1
  24. package/dist/lib/transforms/process-parallel-edges.d.ts +2 -2
  25. package/dist/lib/types/callable.d.ts +0 -11
  26. package/dist/lib/types/data.d.ts +12 -0
  27. package/dist/lib/types/edge.d.ts +11 -0
  28. package/dist/lib/types/element.d.ts +100 -9
  29. package/dist/lib/types/index.d.ts +0 -1
  30. package/dist/lib/types/point.d.ts +0 -1
  31. package/dist/lib/utils/element.d.ts +2 -2
  32. package/dist/lib/utils/layout.d.ts +2 -2
  33. package/dist/lib/utils/path.d.ts +3 -3
  34. package/dist/lib/utils/position.d.ts +8 -8
  35. package/dist/lib/utils/style.d.ts +13 -8
  36. package/esm/behaviors/click-select.d.ts +4 -5
  37. package/esm/behaviors/click-select.js +59 -50
  38. package/esm/behaviors/click-select.js.map +1 -1
  39. package/esm/behaviors/lasso-select.js.map +1 -1
  40. package/esm/elements/base-element.d.ts +1 -22
  41. package/esm/elements/base-element.js +0 -21
  42. package/esm/elements/base-element.js.map +1 -1
  43. package/esm/elements/combos/base-combo.d.ts +4 -4
  44. package/esm/elements/combos/base-combo.js +27 -4
  45. package/esm/elements/combos/base-combo.js.map +1 -1
  46. package/esm/elements/edges/base-edge.d.ts +4 -2
  47. package/esm/elements/edges/base-edge.js +41 -7
  48. package/esm/elements/edges/base-edge.js.map +1 -1
  49. package/esm/elements/effect.d.ts +17 -0
  50. package/esm/elements/effect.js +70 -0
  51. package/esm/elements/effect.js.map +1 -0
  52. package/esm/elements/nodes/base-node.d.ts +5 -4
  53. package/esm/elements/nodes/base-node.js +33 -14
  54. package/esm/elements/nodes/base-node.js.map +1 -1
  55. package/esm/elements/nodes/circle.js +1 -1
  56. package/esm/elements/nodes/circle.js.map +1 -1
  57. package/esm/elements/nodes/diamond.d.ts +0 -1
  58. package/esm/elements/nodes/diamond.js +0 -6
  59. package/esm/elements/nodes/diamond.js.map +1 -1
  60. package/esm/elements/nodes/ellipse.js +1 -1
  61. package/esm/elements/nodes/ellipse.js.map +1 -1
  62. package/esm/elements/nodes/image.js +2 -2
  63. package/esm/elements/nodes/image.js.map +1 -1
  64. package/esm/elements/nodes/rect.js +1 -1
  65. package/esm/elements/nodes/rect.js.map +1 -1
  66. package/esm/elements/shapes/badge.d.ts +17 -6
  67. package/esm/elements/shapes/badge.js +9 -0
  68. package/esm/elements/shapes/badge.js.map +1 -1
  69. package/esm/elements/shapes/base-shape.d.ts +9 -3
  70. package/esm/elements/shapes/base-shape.js +33 -15
  71. package/esm/elements/shapes/base-shape.js.map +1 -1
  72. package/esm/elements/shapes/icon.d.ts +15 -3
  73. package/esm/elements/shapes/icon.js +12 -4
  74. package/esm/elements/shapes/icon.js.map +1 -1
  75. package/esm/elements/shapes/label.d.ts +18 -7
  76. package/esm/elements/shapes/label.js +10 -0
  77. package/esm/elements/shapes/label.js.map +1 -1
  78. package/esm/elements/shapes/polygon.js +1 -1
  79. package/esm/elements/shapes/polygon.js.map +1 -1
  80. package/esm/exports.d.ts +3 -2
  81. package/esm/exports.js +1 -1
  82. package/esm/exports.js.map +1 -1
  83. package/esm/index.d.ts +5 -1
  84. package/esm/index.js +5 -1
  85. package/esm/index.js.map +1 -1
  86. package/esm/layouts/base-layout.d.ts +3 -1
  87. package/esm/layouts/base-layout.js +3 -1
  88. package/esm/layouts/base-layout.js.map +1 -1
  89. package/esm/plugins/bubble-sets.d.ts +2 -2
  90. package/esm/plugins/bubble-sets.js.map +1 -1
  91. package/esm/plugins/hull/index.d.ts +2 -2
  92. package/esm/plugins/hull/index.js.map +1 -1
  93. package/esm/runtime/canvas.d.ts +15 -2
  94. package/esm/runtime/canvas.js.map +1 -1
  95. package/esm/runtime/data.d.ts +7 -16
  96. package/esm/runtime/data.js +14 -34
  97. package/esm/runtime/data.js.map +1 -1
  98. package/esm/runtime/element.d.ts +18 -2
  99. package/esm/runtime/element.js +68 -20
  100. package/esm/runtime/element.js.map +1 -1
  101. package/esm/runtime/graph.d.ts +372 -108
  102. package/esm/runtime/graph.js +271 -76
  103. package/esm/runtime/graph.js.map +1 -1
  104. package/esm/runtime/layout.js +1 -1
  105. package/esm/runtime/layout.js.map +1 -1
  106. package/esm/spec/element/edge.d.ts +1 -1
  107. package/esm/spec/element/node.d.ts +1 -1
  108. package/esm/themes/base.js +2 -0
  109. package/esm/themes/base.js.map +1 -1
  110. package/esm/transforms/collapse-expand-node.js +14 -4
  111. package/esm/transforms/collapse-expand-node.js.map +1 -1
  112. package/esm/transforms/process-parallel-edges.d.ts +2 -2
  113. package/esm/types/callable.d.ts +0 -11
  114. package/esm/types/data.d.ts +12 -0
  115. package/esm/types/edge.d.ts +11 -0
  116. package/esm/types/element.d.ts +100 -9
  117. package/esm/types/index.d.ts +0 -1
  118. package/esm/types/point.d.ts +0 -1
  119. package/esm/utils/element.d.ts +2 -2
  120. package/esm/utils/element.js.map +1 -1
  121. package/esm/utils/layout.d.ts +2 -2
  122. package/esm/utils/layout.js +4 -4
  123. package/esm/utils/layout.js.map +1 -1
  124. package/esm/utils/path.d.ts +3 -3
  125. package/esm/utils/path.js +1 -1
  126. package/esm/utils/path.js.map +1 -1
  127. package/esm/utils/position.d.ts +8 -8
  128. package/esm/utils/position.js +2 -2
  129. package/esm/utils/position.js.map +1 -1
  130. package/esm/utils/style.d.ts +13 -8
  131. package/esm/utils/style.js +16 -11
  132. package/esm/utils/style.js.map +1 -1
  133. package/lib/behaviors/click-select.d.ts +4 -5
  134. package/lib/behaviors/click-select.js +59 -50
  135. package/lib/behaviors/click-select.js.map +1 -1
  136. package/lib/behaviors/lasso-select.js.map +1 -1
  137. package/lib/elements/base-element.d.ts +1 -22
  138. package/lib/elements/base-element.js +0 -21
  139. package/lib/elements/base-element.js.map +1 -1
  140. package/lib/elements/combos/base-combo.d.ts +4 -4
  141. package/lib/elements/combos/base-combo.js +27 -4
  142. package/lib/elements/combos/base-combo.js.map +1 -1
  143. package/lib/elements/edges/base-edge.d.ts +4 -2
  144. package/lib/elements/edges/base-edge.js +41 -7
  145. package/lib/elements/edges/base-edge.js.map +1 -1
  146. package/lib/elements/effect.d.ts +17 -0
  147. package/lib/elements/effect.js +74 -0
  148. package/lib/elements/effect.js.map +1 -0
  149. package/lib/elements/nodes/base-node.d.ts +5 -4
  150. package/lib/elements/nodes/base-node.js +33 -14
  151. package/lib/elements/nodes/base-node.js.map +1 -1
  152. package/lib/elements/nodes/circle.js +1 -1
  153. package/lib/elements/nodes/circle.js.map +1 -1
  154. package/lib/elements/nodes/diamond.d.ts +0 -1
  155. package/lib/elements/nodes/diamond.js +0 -6
  156. package/lib/elements/nodes/diamond.js.map +1 -1
  157. package/lib/elements/nodes/ellipse.js +1 -1
  158. package/lib/elements/nodes/ellipse.js.map +1 -1
  159. package/lib/elements/nodes/image.js +2 -2
  160. package/lib/elements/nodes/image.js.map +1 -1
  161. package/lib/elements/nodes/rect.js +1 -1
  162. package/lib/elements/nodes/rect.js.map +1 -1
  163. package/lib/elements/shapes/badge.d.ts +17 -6
  164. package/lib/elements/shapes/badge.js +9 -0
  165. package/lib/elements/shapes/badge.js.map +1 -1
  166. package/lib/elements/shapes/base-shape.d.ts +9 -3
  167. package/lib/elements/shapes/base-shape.js +33 -15
  168. package/lib/elements/shapes/base-shape.js.map +1 -1
  169. package/lib/elements/shapes/icon.d.ts +15 -3
  170. package/lib/elements/shapes/icon.js +12 -4
  171. package/lib/elements/shapes/icon.js.map +1 -1
  172. package/lib/elements/shapes/label.d.ts +18 -7
  173. package/lib/elements/shapes/label.js +10 -0
  174. package/lib/elements/shapes/label.js.map +1 -1
  175. package/lib/elements/shapes/polygon.js +1 -1
  176. package/lib/elements/shapes/polygon.js.map +1 -1
  177. package/lib/exports.d.ts +3 -2
  178. package/lib/exports.js +5 -2
  179. package/lib/exports.js.map +1 -1
  180. package/lib/index.d.ts +5 -1
  181. package/lib/index.js +6 -2
  182. package/lib/index.js.map +1 -1
  183. package/lib/layouts/base-layout.d.ts +3 -1
  184. package/lib/layouts/base-layout.js +3 -1
  185. package/lib/layouts/base-layout.js.map +1 -1
  186. package/lib/plugins/bubble-sets.d.ts +2 -2
  187. package/lib/plugins/bubble-sets.js.map +1 -1
  188. package/lib/plugins/hull/index.d.ts +2 -2
  189. package/lib/plugins/hull/index.js.map +1 -1
  190. package/lib/runtime/canvas.d.ts +15 -2
  191. package/lib/runtime/canvas.js.map +1 -1
  192. package/lib/runtime/data.d.ts +7 -16
  193. package/lib/runtime/data.js +14 -34
  194. package/lib/runtime/data.js.map +1 -1
  195. package/lib/runtime/element.d.ts +18 -2
  196. package/lib/runtime/element.js +68 -20
  197. package/lib/runtime/element.js.map +1 -1
  198. package/lib/runtime/graph.d.ts +372 -108
  199. package/lib/runtime/graph.js +271 -76
  200. package/lib/runtime/graph.js.map +1 -1
  201. package/lib/runtime/layout.js +1 -1
  202. package/lib/runtime/layout.js.map +1 -1
  203. package/lib/spec/element/edge.d.ts +1 -1
  204. package/lib/spec/element/node.d.ts +1 -1
  205. package/lib/themes/base.js +2 -0
  206. package/lib/themes/base.js.map +1 -1
  207. package/lib/transforms/collapse-expand-node.js +14 -4
  208. package/lib/transforms/collapse-expand-node.js.map +1 -1
  209. package/lib/transforms/process-parallel-edges.d.ts +2 -2
  210. package/lib/types/callable.d.ts +0 -11
  211. package/lib/types/data.d.ts +12 -0
  212. package/lib/types/edge.d.ts +11 -0
  213. package/lib/types/element.d.ts +100 -9
  214. package/lib/types/index.d.ts +0 -1
  215. package/lib/types/point.d.ts +0 -1
  216. package/lib/utils/element.d.ts +2 -2
  217. package/lib/utils/element.js.map +1 -1
  218. package/lib/utils/layout.d.ts +2 -2
  219. package/lib/utils/layout.js +4 -4
  220. package/lib/utils/layout.js.map +1 -1
  221. package/lib/utils/path.d.ts +3 -3
  222. package/lib/utils/path.js +1 -1
  223. package/lib/utils/path.js.map +1 -1
  224. package/lib/utils/position.d.ts +8 -8
  225. package/lib/utils/position.js +2 -2
  226. package/lib/utils/position.js.map +1 -1
  227. package/lib/utils/style.d.ts +13 -8
  228. package/lib/utils/style.js +18 -13
  229. package/lib/utils/style.js.map +1 -1
  230. package/package.json +10 -12
  231. package/src/behaviors/click-select.ts +59 -60
  232. package/src/behaviors/lasso-select.ts +2 -2
  233. package/src/elements/base-element.ts +1 -25
  234. package/src/elements/combos/base-combo.ts +27 -11
  235. package/src/elements/edges/base-edge.ts +28 -8
  236. package/src/elements/effect.ts +74 -0
  237. package/src/elements/nodes/base-node.ts +23 -18
  238. package/src/elements/nodes/circle.ts +1 -1
  239. package/src/elements/nodes/diamond.ts +0 -7
  240. package/src/elements/nodes/ellipse.ts +1 -1
  241. package/src/elements/nodes/image.ts +2 -2
  242. package/src/elements/nodes/rect.ts +1 -1
  243. package/src/elements/shapes/badge.ts +17 -5
  244. package/src/elements/shapes/base-shape.ts +35 -15
  245. package/src/elements/shapes/icon.ts +18 -7
  246. package/src/elements/shapes/label.ts +19 -6
  247. package/src/elements/shapes/polygon.ts +1 -1
  248. package/src/exports.ts +6 -2
  249. package/src/index.ts +6 -2
  250. package/src/layouts/base-layout.ts +5 -1
  251. package/src/plugins/bubble-sets.ts +2 -2
  252. package/src/plugins/hull/index.ts +2 -2
  253. package/src/runtime/canvas.ts +15 -10
  254. package/src/runtime/data.ts +22 -44
  255. package/src/runtime/element.ts +80 -26
  256. package/src/runtime/graph.ts +398 -126
  257. package/src/runtime/layout.ts +2 -2
  258. package/src/spec/element/edge.ts +1 -1
  259. package/src/spec/element/node.ts +1 -1
  260. package/src/themes/base.ts +2 -0
  261. package/src/transforms/collapse-expand-node.ts +13 -4
  262. package/src/transforms/process-parallel-edges.ts +2 -2
  263. package/src/types/callable.ts +0 -12
  264. package/src/types/data.ts +13 -0
  265. package/src/types/edge.ts +11 -0
  266. package/src/types/element.ts +106 -10
  267. package/src/types/index.ts +0 -1
  268. package/src/types/point.ts +0 -1
  269. package/src/utils/element.ts +3 -13
  270. package/src/utils/layout.ts +6 -6
  271. package/src/utils/path.ts +3 -3
  272. package/src/utils/position.ts +8 -8
  273. package/src/utils/style.ts +19 -12
  274. package/dist/lib/types/position.d.ts +0 -2
  275. package/esm/types/position.d.ts +0 -2
  276. package/esm/types/position.js +0 -2
  277. package/esm/types/position.js.map +0 -1
  278. package/lib/types/position.d.ts +0 -2
  279. package/lib/types/position.js +0 -3
  280. package/lib/types/position.js.map +0 -1
  281. package/scripts/tips.js +0 -6
  282. package/src/types/position.ts +0 -3
@@ -6,6 +6,11 @@ import { omitStyleProps, startsWith, subStyleProps } from '../../utils/prefix';
6
6
  import { mergeOptions } from '../../utils/style';
7
7
  import { BaseShape } from './base-shape';
8
8
 
9
+ /**
10
+ * <zh/> 标签样式
11
+ *
12
+ * <en/> Label style
13
+ */
9
14
  export interface LabelStyleProps extends TextStyleProps, Prefix<'background', RectStyleProps> {
10
15
  /**
11
16
  * <zh/> 是否显示背景
@@ -21,13 +26,21 @@ export interface LabelStyleProps extends TextStyleProps, Prefix<'background', Re
21
26
  */
22
27
  padding?: Padding;
23
28
  }
24
- type ParsedLabelStyleProps = Required<LabelStyleProps>;
25
- type LabelOptions = DisplayObjectConfig<LabelStyleProps>;
26
29
 
30
+ /**
31
+ * <zh/> 标签
32
+ *
33
+ * <en/> Label
34
+ * @remarks
35
+ * <zh/> 标签是一种具有背景的文本图形。
36
+ *
37
+ * <en/> Label is a text shape with background.
38
+ */
27
39
  export class Label extends BaseShape<LabelStyleProps> {
28
40
  static defaultStyleProps: Partial<LabelStyleProps> = {
29
41
  padding: 0,
30
42
  fontSize: 12,
43
+ fontFamily: 'system-ui, sans-serif',
31
44
  wordWrap: true,
32
45
  maxLines: 1,
33
46
  wordWrapWidth: 128,
@@ -38,7 +51,7 @@ export class Label extends BaseShape<LabelStyleProps> {
38
51
  backgroundLineWidth: 0,
39
52
  };
40
53
 
41
- constructor(options: LabelOptions) {
54
+ constructor(options: DisplayObjectConfig<LabelStyleProps>) {
42
55
  super(mergeOptions({ style: Label.defaultStyleProps }, options));
43
56
  }
44
57
 
@@ -50,12 +63,12 @@ export class Label extends BaseShape<LabelStyleProps> {
50
63
  return startsWith(key, 'background');
51
64
  }
52
65
 
53
- protected getTextStyle(attributes: ParsedLabelStyleProps) {
66
+ protected getTextStyle(attributes: Required<LabelStyleProps>) {
54
67
  const { padding, ...style } = this.getGraphicStyle(attributes);
55
68
  return omitStyleProps<TextStyleProps>(style, 'background');
56
69
  }
57
70
 
58
- protected getBackgroundStyle(attributes: ParsedLabelStyleProps) {
71
+ protected getBackgroundStyle(attributes: Required<LabelStyleProps>) {
59
72
  if (attributes.background === false) return false;
60
73
 
61
74
  const style = this.getGraphicStyle(attributes);
@@ -94,7 +107,7 @@ export class Label extends BaseShape<LabelStyleProps> {
94
107
  return backgroundStyle;
95
108
  }
96
109
 
97
- public render(attributes: ParsedLabelStyleProps = this.parsedAttributes, container: Group = this): void {
110
+ public render(attributes: Required<LabelStyleProps> = this.parsedAttributes, container: Group = this): void {
98
111
  this.upsert('text', Text, this.getTextStyle(attributes), container);
99
112
  this.upsert('background', Rect, this.getBackgroundStyle(attributes), container);
100
113
  }
@@ -44,7 +44,7 @@ export abstract class Polygon<T extends PolygonStyleProps = PolygonStyleProps> e
44
44
  protected abstract getPoints(attributes: Required<T>): Point[];
45
45
 
46
46
  public getIntersectPoint(point: Point): Point {
47
- const { points } = this.getKeyStyle(this.parsedAttributes as Required<T>);
47
+ const { points } = this.getShape<GPolygon>('key').attributes;
48
48
  const center: Point = [+(this.attributes?.x || 0), +(this.attributes?.y || 0)];
49
49
  return getPolygonIntersectPoint(point, center, points!).point;
50
50
  }
package/src/exports.ts CHANGED
@@ -39,7 +39,7 @@ export {
39
39
  Star,
40
40
  Triangle,
41
41
  } from './elements/nodes';
42
- export { BaseShape } from './elements/shapes';
42
+ export { Badge, BaseShape, Icon, Label } from './elements/shapes';
43
43
  export {
44
44
  AntVDagreLayout,
45
45
  BaseLayout,
@@ -167,6 +167,7 @@ export type {
167
167
  TooltipOptions,
168
168
  WatermarkOptions,
169
169
  } from './plugins';
170
+ export type { DataURLOptions } from './runtime/canvas';
170
171
  export type { RuntimeContext } from './runtime/types';
171
172
  export type {
172
173
  BehaviorOptions,
@@ -190,7 +191,6 @@ export type { CustomPluginOption } from './spec/plugin';
190
191
  export type { BaseTransformOptions } from './transforms';
191
192
  export type {
192
193
  BaseElementStyleProps,
193
- CallableValue,
194
194
  CardinalPlacement,
195
195
  CollapsedMarkerStyleProps,
196
196
  Combo,
@@ -198,11 +198,15 @@ export type {
198
198
  DirectionalPlacement,
199
199
  Edge,
200
200
  EdgeArrowStyleProps,
201
+ EdgeDirection,
201
202
  EdgeLabelStyleProps,
202
203
  Element,
203
204
  ElementDatum,
205
+ ElementHooks,
206
+ ElementMethods,
204
207
  ElementType,
205
208
  FitViewOptions,
209
+ HierarchyKey,
206
210
  IAnimateEvent,
207
211
  ID,
208
212
  IDragEvent,
package/src/index.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  import './preset';
2
2
 
3
- export const version = '5.0.0';
4
-
5
3
  export * from './exports';
4
+
5
+ export const version = '5.0.2';
6
+ export const iconfont = {
7
+ css: '//at.alicdn.com/t/a/font_470089_8hnbbf8n4u8.css',
8
+ js: '//at.alicdn.com/t/a/font_470089_8hnbbf8n4u8.js',
9
+ };
@@ -1,3 +1,4 @@
1
+ import type { RuntimeContext } from '../runtime/types';
1
2
  import type { GraphData } from '../spec';
2
3
  import type { BaseLayoutOptions } from './types';
3
4
 
@@ -6,7 +7,10 @@ export abstract class BaseLayout<O extends BaseLayoutOptions = any> {
6
7
 
7
8
  public options: O;
8
9
 
9
- constructor(options?: O) {
10
+ protected context: RuntimeContext;
11
+
12
+ constructor(context: RuntimeContext, options?: O) {
13
+ this.context = context;
10
14
  this.options = options || ({} as O);
11
15
  }
12
16
 
@@ -7,7 +7,7 @@ import type { ContourStyleProps } from '../elements/shapes';
7
7
  import { Contour } from '../elements/shapes';
8
8
  import type { Graph } from '../runtime/graph';
9
9
  import type { RuntimeContext } from '../runtime/types';
10
- import type { CallableValue, ID } from '../types';
10
+ import type { ID } from '../types';
11
11
  import { getBBoxHeight, getBBoxWidth } from '../utils/bbox';
12
12
  import { arrayDiff } from '../utils/diff';
13
13
  import type { ElementLifeCycleEvent } from '../utils/event';
@@ -225,7 +225,7 @@ export class BubbleSets extends BasePlugin<BubbleSetsOptions> {
225
225
  * <en/> Update member elements
226
226
  * @param members - <zh/> 值或者回调函数 | <en/> value or callback function
227
227
  */
228
- public updateMember(members: CallableValue<ID[]>) {
228
+ public updateMember(members: ID[] | ((prev: ID[]) => ID[])) {
229
229
  this.options.members = isFunction(members) ? members(this.options.members) : members;
230
230
  this.drawBubbleSets();
231
231
  }
@@ -4,7 +4,7 @@ import { GraphEvent } from '../../constants';
4
4
  import type { ContourStyleProps } from '../../elements/shapes';
5
5
  import { Contour } from '../../elements/shapes';
6
6
  import type { RuntimeContext } from '../../runtime/types';
7
- import type { CallableValue, ID, Point } from '../../types';
7
+ import type { ID, Point } from '../../types';
8
8
  import type { ElementLifeCycleEvent } from '../../utils/event';
9
9
  import { idOf } from '../../utils/id';
10
10
  import { positionOf } from '../../utils/position';
@@ -185,7 +185,7 @@ export class Hull extends BasePlugin<HullOptions> {
185
185
  * <en/> Update Hull member
186
186
  * @param members - <zh/> 元素 Ids | <en/> Element Ids
187
187
  */
188
- public updateMember(members: CallableValue<ID[]>) {
188
+ public updateMember(members: ID[] | ((prev: ID[]) => ID[])) {
189
189
  this.options.members = isFunction(members) ? members(this.options.members) : members;
190
190
  this.shape.update(this.getHullStyle(true));
191
191
  }
@@ -1,12 +1,4 @@
1
- import type {
2
- Cursor,
3
- DisplayObject,
4
- CanvasConfig as GCanvasConfig,
5
- DataURLOptions as GDataURLOptions,
6
- IAnimation,
7
- IRenderer,
8
- PointLike,
9
- } from '@antv/g';
1
+ import type { Cursor, DisplayObject, CanvasConfig as GCanvasConfig, IAnimation, IRenderer, PointLike } from '@antv/g';
10
2
  import { CanvasEvent, Canvas as GCanvas } from '@antv/g';
11
3
  import { Renderer as CanvasRenderer } from '@antv/g-canvas';
12
4
  import { Plugin as DragNDropPlugin } from '@antv/g-plugin-dragndrop';
@@ -21,7 +13,7 @@ export interface CanvasConfig
21
13
  background?: string;
22
14
  }
23
15
 
24
- export interface DataURLOptions extends GDataURLOptions {
16
+ export interface DataURLOptions {
25
17
  /**
26
18
  * <zh/> 导出模式
27
19
  * - viewport: 导出视口内容
@@ -32,6 +24,19 @@ export interface DataURLOptions extends GDataURLOptions {
32
24
  * - overall: export the entire canvas
33
25
  */
34
26
  mode?: 'viewport' | 'overall';
27
+ /**
28
+ * <zh/> 图片类型
29
+ *
30
+ * <en/> image type
31
+ * @defaultValue 'image/png'
32
+ */
33
+ type: 'image/png' | 'image/jpeg' | 'image/webp' | 'image/bmp';
34
+ /**
35
+ * <zh/> 图片质量, 仅对 image/jpeg 和 image/webp 有效,取值范围 0 ~ 1
36
+ *
37
+ * <en/> image quality, only valid for image/jpeg and image/webp, range 0 ~ 1
38
+ */
39
+ encoderOptions: number;
35
40
  }
36
41
 
37
42
  /**
@@ -9,24 +9,22 @@ import type {
9
9
  DataRemoved,
10
10
  DataUpdated,
11
11
  ElementDatum,
12
+ HierarchyKey,
12
13
  ID,
13
14
  NodeLikeData,
14
15
  PartialEdgeData,
15
16
  PartialGraphData,
16
17
  PartialNodeLikeData,
17
- Position,
18
+ Point,
18
19
  State,
19
20
  } from '../types';
20
21
  import type { EdgeDirection } from '../types/edge';
21
22
  import type { ElementType } from '../types/element';
22
- import type { Point } from '../types/point';
23
- import { isCollapsed } from '../utils/collapsibility';
24
23
  import { cloneElementData, mergeElementsData } from '../utils/data';
25
24
  import { arrayDiff } from '../utils/diff';
26
25
  import { toG6Data, toGraphlibData } from '../utils/graphlib';
27
26
  import { idOf, parentIdOf } from '../utils/id';
28
27
  import { positionOf } from '../utils/position';
29
- import { zIndexOf } from '../utils/style';
30
28
  import { dfs } from '../utils/traverse';
31
29
  import { add } from '../utils/vector';
32
30
 
@@ -368,6 +366,14 @@ export class DataController {
368
366
  this.updateNodeLikeHierarchy(combos);
369
367
  }
370
368
 
369
+ public addChildrenData(parentId: ID, childrenData: NodeData[]) {
370
+ const parentData = this.getNodeLikeDatum(parentId) as NodeData;
371
+ const childrenId = childrenData.map(idOf);
372
+ this.addNodeData(childrenData);
373
+ this.updateNodeData([{ id: parentId, children: [...(parentData.children || []), ...childrenId] }]);
374
+ this.addEdgeData(childrenId.map((childId) => ({ source: parentId, target: childId })));
375
+ }
376
+
371
377
  protected updateNodeLikeHierarchy(data: NodeLikeData[]) {
372
378
  if (!this.enableUpdateNodeLikeHierarchy) return;
373
379
  const { model } = this;
@@ -381,9 +387,13 @@ export class DataController {
381
387
  const children = (datum as NodeData).children;
382
388
  if (children !== undefined) {
383
389
  model.attachTreeStructure(TREE_KEY);
384
- children.forEach((child) => {
385
- this.setParent(child, id, TREE_KEY);
386
- });
390
+ const _children = children.filter((child) => model.hasNode(child));
391
+ _children.forEach((child) => this.setParent(child, id, TREE_KEY));
392
+ if (_children.length !== children.length) {
393
+ // 从数据中移除不存在的子节点
394
+ // Remove non-existent child nodes from the data
395
+ this.updateNodeData([{ id, children: _children }]);
396
+ }
387
397
  }
388
398
  });
389
399
  }
@@ -565,25 +575,25 @@ export class DataController {
565
575
  model.mergeNodeData(id, value);
566
576
  }
567
577
 
568
- public getElementPosition(id: ID): Position {
578
+ public getElementPosition(id: ID): Point {
569
579
  const datum = this.getElementDataById(id) as NodeLikeData;
570
580
  return positionOf(datum);
571
581
  }
572
582
 
573
- public translateNodeBy(id: ID, offset: Position) {
583
+ public translateNodeBy(id: ID, offset: Point) {
574
584
  const curr = this.getElementPosition(id);
575
585
  const position = add(curr, [...offset, 0].slice(0, 3) as Point);
576
586
  this.translateNodeTo(id, position);
577
587
  }
578
588
 
579
- public translateNodeTo(id: ID, position: Position) {
589
+ public translateNodeTo(id: ID, position: Point) {
580
590
  const [x = 0, y = 0, z = 0] = position;
581
591
  this.preventUpdateNodeLikeHierarchy(() => {
582
592
  this.updateNodeData([{ id, style: { x, y, z } }]);
583
593
  });
584
594
  }
585
595
 
586
- public translateComboBy(id: ID, offset: Position) {
596
+ public translateComboBy(id: ID, offset: Point) {
587
597
  const [dx = 0, dy = 0, dz = 0] = offset;
588
598
  if ([dx, dy, dz].some(isNaN) || [dx, dy, dz].every((o) => o === 0)) return;
589
599
  const combo = this.getComboData([id])[0];
@@ -610,7 +620,7 @@ export class DataController {
610
620
  );
611
621
  }
612
622
 
613
- public translateComboTo(id: ID, position: Position) {
623
+ public translateComboTo(id: ID, position: Point) {
614
624
  if (position.some(isNaN)) return;
615
625
  const [tx = 0, ty = 0, tz = 0] = position;
616
626
  const combo = this.getComboData([id])?.[0];
@@ -743,36 +753,6 @@ export class DataController {
743
753
  throw new Error(`Unknown element type of id: ${id}`);
744
754
  }
745
755
 
746
- /**
747
- * <zh/> 计算元素置顶后的 zIndex
748
- *
749
- * <en/> Calculate the zIndex after the element is placed on top
750
- * @param id - <zh/> 元素 ID | <en/> ID of the element
751
- * @returns <zh/> zIndex | <en/> zIndex
752
- */
753
- public getFrontZIndex(id: ID) {
754
- const elementType = this.getElementType(id);
755
- let elementsToCompare: NodeLikeData[] = [];
756
-
757
- if (elementType === 'combo') {
758
- const ancestors = [id, ...this.getAncestorsData(id, COMBO_KEY).map(idOf)];
759
- // 过滤掉以下 combo 不参与 zIndex 计算
760
- // - 未展开的 combo
761
- // - 当前 combo 及其祖先和后代
762
- // The following combos do not participate in zIndex calculation
763
- // - collapsed combo
764
- // - current combo and its ancestors and descendants
765
- elementsToCompare = this.getComboData().filter((combo) => {
766
- const comboId = idOf(combo);
767
- const comboAncestors = this.getAncestorsData(comboId, COMBO_KEY);
768
- const comboAncestorIds = comboAncestors.map(idOf);
769
- return !comboAncestors.some(isCollapsed) && !ancestors.includes(comboId) && !comboAncestorIds.includes(comboId);
770
- });
771
- } else elementsToCompare = this.getNodeData().filter((node) => idOf(node) !== id);
772
-
773
- return Math.max(0, ...elementsToCompare.map(zIndexOf)) + 1;
774
- }
775
-
776
756
  public destroy() {
777
757
  const { model } = this;
778
758
  const nodes = model.getAllNodes();
@@ -785,5 +765,3 @@ export class DataController {
785
765
  this.context = {};
786
766
  }
787
767
  }
788
-
789
- export type HierarchyKey = typeof TREE_KEY | typeof COMBO_KEY;
@@ -38,11 +38,7 @@ import type { RuntimeContext } from './types';
38
38
  export class ElementController {
39
39
  private context: RuntimeContext;
40
40
 
41
- private container!: {
42
- node: Group;
43
- edge: Group;
44
- combo: Group;
45
- };
41
+ private container!: Group;
46
42
 
47
43
  private elementMap: Record<ID, Element> = {};
48
44
 
@@ -55,11 +51,7 @@ export class ElementController {
55
51
  public init() {
56
52
  if (!this.container) {
57
53
  const { canvas } = this.context;
58
- this.container = {
59
- node: canvas.appendChild(new Group({ style: { zIndex: 2 } })),
60
- edge: canvas.appendChild(new Group({ style: { zIndex: 1 } })),
61
- combo: canvas.appendChild(new Group({ style: { zIndex: 0 } })),
62
- };
54
+ this.container = canvas.appendChild(new Group());
63
55
  }
64
56
  }
65
57
 
@@ -224,16 +216,22 @@ export class ElementController {
224
216
  return this.elementMap[id] as T;
225
217
  }
226
218
 
219
+ public getElementZIndex(id: ID) {
220
+ const element = this.getElement(id);
221
+ if (!element) return 0;
222
+ return element.style.zIndex ?? 0;
223
+ }
224
+
227
225
  public getNodes() {
228
- return this.container.node.children as Node[];
226
+ return this.context.model.getNodeData().map(({ id }) => this.elementMap[id]) as Node[];
229
227
  }
230
228
 
231
229
  public getEdges() {
232
- return this.container.edge.children as Edge[];
230
+ return this.context.model.getEdgeData().map((edge) => this.elementMap[idOf(edge)]) as Edge[];
233
231
  }
234
232
 
235
233
  public getCombos() {
236
- return this.container.combo.children as Combo[];
234
+ return this.context.model.getComboData().map(({ id }) => this.elementMap[id]) as Combo[];
237
235
  }
238
236
 
239
237
  public getElementComputedStyle(elementType: ElementType, datum: ElementDatum) {
@@ -269,6 +267,7 @@ export class ElementController {
269
267
  if (!data) return null;
270
268
 
271
269
  const { dataChanges, drawData } = data;
270
+ this.markDestroyElement(drawData);
272
271
  // 计算样式 / Calculate style
273
272
  this.computeStyle();
274
273
  // 创建渲染任务 / Create render task
@@ -365,7 +364,7 @@ export class ElementController {
365
364
 
366
365
  this.emit(new ElementLifeCycleEvent(GraphEvent.BEFORE_ELEMENT_CREATE, elementType, datum), context);
367
366
 
368
- const element = this.container[elementType].appendChild(
367
+ const element = this.container.appendChild(
369
368
  new Ctor({
370
369
  id,
371
370
  style: {
@@ -391,7 +390,7 @@ export class ElementController {
391
390
  {
392
391
  after: () => {
393
392
  this.emit(new ElementLifeCycleEvent(GraphEvent.AFTER_ELEMENT_CREATE, elementType, datum), context);
394
- element.onCreate();
393
+ element.onCreate?.();
395
394
  },
396
395
  },
397
396
  );
@@ -459,7 +458,7 @@ export class ElementController {
459
458
  if (stage === 'collapse') updateStyle(element, style);
460
459
  if (exactStage === 'hide') updateStyle(element, { visibility: getCachedStyle(element, 'visibility') });
461
460
  this.emit(new ElementLifeCycleEvent(GraphEvent.AFTER_ELEMENT_UPDATE, elementType, datum), context);
462
- element.onUpdate();
461
+ element.onUpdate?.();
463
462
  },
464
463
  },
465
464
  );
@@ -478,6 +477,22 @@ export class ElementController {
478
477
  });
479
478
  }
480
479
 
480
+ /**
481
+ * <zh/> 标记销毁元素
482
+ *
483
+ * <en/> mark destroy element
484
+ * @param data - <zh/> 绘制数据 | <en/> draw data
485
+ */
486
+ private markDestroyElement(data: DrawData) {
487
+ Object.values(data.remove).forEach((elementData) => {
488
+ elementData.forEach((datum) => {
489
+ const id = idOf(datum);
490
+ const element = this.getElement(id);
491
+ if (element) markToBeDestroyed(element);
492
+ });
493
+ });
494
+ }
495
+
481
496
  private destroyElement(elementType: ElementType, datum: ElementDatum, context: DrawContext) {
482
497
  const { stage = 'exit' } = context;
483
498
  const id = idOf(datum);
@@ -498,7 +513,7 @@ export class ElementController {
498
513
  after: () => {
499
514
  this.clearElement(id);
500
515
  element.destroy();
501
- element.onDestroy();
516
+ element.onDestroy?.();
502
517
  this.emit(new ElementLifeCycleEvent(GraphEvent.AFTER_ELEMENT_DESTROY, elementType, datum), context);
503
518
  },
504
519
  },
@@ -540,11 +555,7 @@ export class ElementController {
540
555
 
541
556
  const preprocess = this.computeChangesAndDrawData({ stage: 'collapse', animation })!;
542
557
 
543
- preprocess.drawData.remove.nodes.forEach((datum) => {
544
- const id = idOf(datum);
545
- const element = this.getElement(id);
546
- if (element) markToBeDestroyed(element);
547
- });
558
+ this.markDestroyElement(preprocess.drawData);
548
559
 
549
560
  // 进行预布局,计算出所有元素的位置
550
561
  // Perform pre-layout to calculate the position of all elements
@@ -554,7 +565,7 @@ export class ElementController {
554
565
  // 重新计算数据 / Recalculate data
555
566
  const { drawData } = this.computeChangesAndDrawData({ stage: 'collapse', animation })!;
556
567
  const { add, remove, update } = drawData;
557
-
568
+ this.markDestroyElement(drawData);
558
569
  const context = { animation, stage: 'collapse', data: drawData } as const;
559
570
 
560
571
  this.destroyElements(remove, context);
@@ -649,7 +660,7 @@ export class ElementController {
649
660
  });
650
661
 
651
662
  const { dataChanges, drawData } = this.computeChangesAndDrawData({ stage: 'collapse', animation })!;
652
-
663
+ this.markDestroyElement(drawData);
653
664
  const { update, remove } = drawData;
654
665
  const context = { animation, stage: 'collapse', data: drawData } as const;
655
666
 
@@ -713,9 +724,52 @@ export class ElementController {
713
724
  )?.finished;
714
725
  }
715
726
 
727
+ /**
728
+ * <zh/> 计算元素置顶后的 zIndex
729
+ *
730
+ * <en/> Calculate the zIndex after the element is placed on top
731
+ * @param id - <zh/> 元素 ID | <en/> ID of the element
732
+ * @returns <zh/> zIndex | <en/> zIndex
733
+ */
734
+ public getFrontZIndex(id: ID) {
735
+ const { model } = this.context;
736
+
737
+ const elementType = model.getElementType(id);
738
+ const elementData = model.getElementDataById(id);
739
+ const data = model.getData();
740
+
741
+ // 排除当前元素 / Exclude the current element
742
+ Object.assign(data, {
743
+ [`${elementType}s`]: data[`${elementType}s`].filter((element) => idOf(element) !== id),
744
+ });
745
+
746
+ if (elementType === 'combo') {
747
+ // 如果 combo 展开,则排除 combo 的子节点/combo 及内部边
748
+ // If the combo is expanded, exclude the child nodes/combos of the combo and the internal edges
749
+ if (!isCollapsed(elementData as ComboData)) {
750
+ const ancestors = model.getAncestorsData(id, COMBO_KEY).map(idOf);
751
+ data.nodes = data.nodes.filter((element) => !ancestors.includes(idOf(element)));
752
+ data.combos = data.combos.filter((element) => !ancestors.includes(idOf(element)));
753
+ data.edges = data.edges.filter(
754
+ ({ source, target }) => ancestors.includes(source) && ancestors.includes(target),
755
+ );
756
+ }
757
+ }
758
+ return (
759
+ Math.max(
760
+ 0,
761
+ ...Object.values(data)
762
+ .flat()
763
+ .map((datum) => {
764
+ const id = idOf(datum);
765
+ return this.getElementZIndex(id);
766
+ }),
767
+ ) + 1
768
+ );
769
+ }
770
+
716
771
  public destroy() {
717
- // @ts-expect-error force delete
718
- this.container = {};
772
+ this.container.destroy();
719
773
  this.elementMap = {};
720
774
  this.shapeTypeMap = {};
721
775
  this.defaultStyle = {};