@antv/g6 5.0.1 → 5.0.3

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 (302) 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/behaviors/hover-activate.d.ts +0 -1
  4. package/dist/lib/elements/base-element.d.ts +1 -22
  5. package/dist/lib/elements/combos/base-combo.d.ts +4 -4
  6. package/dist/lib/elements/edges/base-edge.d.ts +4 -2
  7. package/dist/lib/elements/effect.d.ts +17 -0
  8. package/dist/lib/elements/nodes/base-node.d.ts +5 -4
  9. package/dist/lib/elements/nodes/diamond.d.ts +0 -1
  10. package/dist/lib/elements/shapes/badge.d.ts +17 -6
  11. package/dist/lib/elements/shapes/base-shape.d.ts +9 -3
  12. package/dist/lib/elements/shapes/icon.d.ts +15 -3
  13. package/dist/lib/elements/shapes/label.d.ts +18 -7
  14. package/dist/lib/exports.d.ts +3 -2
  15. package/dist/lib/index.d.ts +5 -1
  16. package/dist/lib/layouts/base-layout.d.ts +3 -1
  17. package/dist/lib/plugins/bubble-sets.d.ts +2 -2
  18. package/dist/lib/plugins/contextmenu/index.d.ts +4 -3
  19. package/dist/lib/plugins/hull/index.d.ts +2 -2
  20. package/dist/lib/runtime/canvas.d.ts +15 -2
  21. package/dist/lib/runtime/data.d.ts +9 -16
  22. package/dist/lib/runtime/element.d.ts +18 -2
  23. package/dist/lib/runtime/graph.d.ts +374 -109
  24. package/dist/lib/spec/element/edge.d.ts +1 -1
  25. package/dist/lib/spec/element/node.d.ts +1 -1
  26. package/dist/lib/transforms/process-parallel-edges.d.ts +2 -2
  27. package/dist/lib/types/callable.d.ts +0 -11
  28. package/dist/lib/types/data.d.ts +12 -0
  29. package/dist/lib/types/edge.d.ts +11 -0
  30. package/dist/lib/types/element.d.ts +100 -9
  31. package/dist/lib/types/index.d.ts +0 -1
  32. package/dist/lib/types/point.d.ts +0 -1
  33. package/dist/lib/utils/element.d.ts +2 -2
  34. package/dist/lib/utils/layout.d.ts +2 -2
  35. package/dist/lib/utils/path.d.ts +3 -3
  36. package/dist/lib/utils/position.d.ts +8 -8
  37. package/dist/lib/utils/style.d.ts +13 -8
  38. package/esm/behaviors/click-select.d.ts +4 -5
  39. package/esm/behaviors/click-select.js +62 -50
  40. package/esm/behaviors/click-select.js.map +1 -1
  41. package/esm/behaviors/drag-element.js +2 -9
  42. package/esm/behaviors/drag-element.js.map +1 -1
  43. package/esm/behaviors/hover-activate.d.ts +0 -1
  44. package/esm/behaviors/hover-activate.js +18 -16
  45. package/esm/behaviors/hover-activate.js.map +1 -1
  46. package/esm/behaviors/lasso-select.js.map +1 -1
  47. package/esm/elements/base-element.d.ts +1 -22
  48. package/esm/elements/base-element.js +0 -21
  49. package/esm/elements/base-element.js.map +1 -1
  50. package/esm/elements/combos/base-combo.d.ts +4 -4
  51. package/esm/elements/combos/base-combo.js +27 -4
  52. package/esm/elements/combos/base-combo.js.map +1 -1
  53. package/esm/elements/edges/base-edge.d.ts +4 -2
  54. package/esm/elements/edges/base-edge.js +41 -7
  55. package/esm/elements/edges/base-edge.js.map +1 -1
  56. package/esm/elements/effect.d.ts +17 -0
  57. package/esm/elements/effect.js +70 -0
  58. package/esm/elements/effect.js.map +1 -0
  59. package/esm/elements/nodes/base-node.d.ts +5 -4
  60. package/esm/elements/nodes/base-node.js +33 -14
  61. package/esm/elements/nodes/base-node.js.map +1 -1
  62. package/esm/elements/nodes/circle.js +1 -1
  63. package/esm/elements/nodes/circle.js.map +1 -1
  64. package/esm/elements/nodes/diamond.d.ts +0 -1
  65. package/esm/elements/nodes/diamond.js +0 -6
  66. package/esm/elements/nodes/diamond.js.map +1 -1
  67. package/esm/elements/nodes/ellipse.js +1 -1
  68. package/esm/elements/nodes/ellipse.js.map +1 -1
  69. package/esm/elements/nodes/image.js +2 -2
  70. package/esm/elements/nodes/image.js.map +1 -1
  71. package/esm/elements/nodes/rect.js +1 -1
  72. package/esm/elements/nodes/rect.js.map +1 -1
  73. package/esm/elements/shapes/badge.d.ts +17 -6
  74. package/esm/elements/shapes/badge.js +9 -0
  75. package/esm/elements/shapes/badge.js.map +1 -1
  76. package/esm/elements/shapes/base-shape.d.ts +9 -3
  77. package/esm/elements/shapes/base-shape.js +33 -15
  78. package/esm/elements/shapes/base-shape.js.map +1 -1
  79. package/esm/elements/shapes/icon.d.ts +15 -3
  80. package/esm/elements/shapes/icon.js +12 -4
  81. package/esm/elements/shapes/icon.js.map +1 -1
  82. package/esm/elements/shapes/label.d.ts +18 -7
  83. package/esm/elements/shapes/label.js +10 -0
  84. package/esm/elements/shapes/label.js.map +1 -1
  85. package/esm/elements/shapes/polygon.js +1 -1
  86. package/esm/elements/shapes/polygon.js.map +1 -1
  87. package/esm/exports.d.ts +3 -2
  88. package/esm/exports.js +1 -1
  89. package/esm/exports.js.map +1 -1
  90. package/esm/index.d.ts +5 -1
  91. package/esm/index.js +5 -1
  92. package/esm/index.js.map +1 -1
  93. package/esm/layouts/base-layout.d.ts +3 -1
  94. package/esm/layouts/base-layout.js +3 -1
  95. package/esm/layouts/base-layout.js.map +1 -1
  96. package/esm/plugins/bubble-sets.d.ts +2 -2
  97. package/esm/plugins/bubble-sets.js.map +1 -1
  98. package/esm/plugins/contextmenu/index.d.ts +4 -3
  99. package/esm/plugins/contextmenu/index.js +12 -10
  100. package/esm/plugins/contextmenu/index.js.map +1 -1
  101. package/esm/plugins/hull/index.d.ts +2 -2
  102. package/esm/plugins/hull/index.js.map +1 -1
  103. package/esm/runtime/canvas.d.ts +15 -2
  104. package/esm/runtime/canvas.js.map +1 -1
  105. package/esm/runtime/data.d.ts +9 -16
  106. package/esm/runtime/data.js +26 -34
  107. package/esm/runtime/data.js.map +1 -1
  108. package/esm/runtime/element.d.ts +18 -2
  109. package/esm/runtime/element.js +75 -24
  110. package/esm/runtime/element.js.map +1 -1
  111. package/esm/runtime/graph.d.ts +374 -109
  112. package/esm/runtime/graph.js +278 -82
  113. package/esm/runtime/graph.js.map +1 -1
  114. package/esm/runtime/layout.js +1 -1
  115. package/esm/runtime/layout.js.map +1 -1
  116. package/esm/spec/element/edge.d.ts +1 -1
  117. package/esm/spec/element/node.d.ts +1 -1
  118. package/esm/themes/base.js +5 -0
  119. package/esm/themes/base.js.map +1 -1
  120. package/esm/transforms/collapse-expand-node.js +14 -4
  121. package/esm/transforms/collapse-expand-node.js.map +1 -1
  122. package/esm/transforms/process-parallel-edges.d.ts +2 -2
  123. package/esm/types/callable.d.ts +0 -11
  124. package/esm/types/data.d.ts +12 -0
  125. package/esm/types/edge.d.ts +11 -0
  126. package/esm/types/element.d.ts +100 -9
  127. package/esm/types/index.d.ts +0 -1
  128. package/esm/types/point.d.ts +0 -1
  129. package/esm/utils/element.d.ts +2 -2
  130. package/esm/utils/element.js.map +1 -1
  131. package/esm/utils/layout.d.ts +2 -2
  132. package/esm/utils/layout.js +4 -4
  133. package/esm/utils/layout.js.map +1 -1
  134. package/esm/utils/path.d.ts +3 -3
  135. package/esm/utils/path.js +1 -1
  136. package/esm/utils/path.js.map +1 -1
  137. package/esm/utils/position.d.ts +8 -8
  138. package/esm/utils/position.js +2 -2
  139. package/esm/utils/position.js.map +1 -1
  140. package/esm/utils/style.d.ts +13 -8
  141. package/esm/utils/style.js +16 -11
  142. package/esm/utils/style.js.map +1 -1
  143. package/lib/behaviors/click-select.d.ts +4 -5
  144. package/lib/behaviors/click-select.js +62 -50
  145. package/lib/behaviors/click-select.js.map +1 -1
  146. package/lib/behaviors/drag-element.js +2 -9
  147. package/lib/behaviors/drag-element.js.map +1 -1
  148. package/lib/behaviors/hover-activate.d.ts +0 -1
  149. package/lib/behaviors/hover-activate.js +18 -16
  150. package/lib/behaviors/hover-activate.js.map +1 -1
  151. package/lib/behaviors/lasso-select.js.map +1 -1
  152. package/lib/elements/base-element.d.ts +1 -22
  153. package/lib/elements/base-element.js +0 -21
  154. package/lib/elements/base-element.js.map +1 -1
  155. package/lib/elements/combos/base-combo.d.ts +4 -4
  156. package/lib/elements/combos/base-combo.js +27 -4
  157. package/lib/elements/combos/base-combo.js.map +1 -1
  158. package/lib/elements/edges/base-edge.d.ts +4 -2
  159. package/lib/elements/edges/base-edge.js +41 -7
  160. package/lib/elements/edges/base-edge.js.map +1 -1
  161. package/lib/elements/effect.d.ts +17 -0
  162. package/lib/elements/effect.js +74 -0
  163. package/lib/elements/effect.js.map +1 -0
  164. package/lib/elements/nodes/base-node.d.ts +5 -4
  165. package/lib/elements/nodes/base-node.js +33 -14
  166. package/lib/elements/nodes/base-node.js.map +1 -1
  167. package/lib/elements/nodes/circle.js +1 -1
  168. package/lib/elements/nodes/circle.js.map +1 -1
  169. package/lib/elements/nodes/diamond.d.ts +0 -1
  170. package/lib/elements/nodes/diamond.js +0 -6
  171. package/lib/elements/nodes/diamond.js.map +1 -1
  172. package/lib/elements/nodes/ellipse.js +1 -1
  173. package/lib/elements/nodes/ellipse.js.map +1 -1
  174. package/lib/elements/nodes/image.js +2 -2
  175. package/lib/elements/nodes/image.js.map +1 -1
  176. package/lib/elements/nodes/rect.js +1 -1
  177. package/lib/elements/nodes/rect.js.map +1 -1
  178. package/lib/elements/shapes/badge.d.ts +17 -6
  179. package/lib/elements/shapes/badge.js +9 -0
  180. package/lib/elements/shapes/badge.js.map +1 -1
  181. package/lib/elements/shapes/base-shape.d.ts +9 -3
  182. package/lib/elements/shapes/base-shape.js +33 -15
  183. package/lib/elements/shapes/base-shape.js.map +1 -1
  184. package/lib/elements/shapes/icon.d.ts +15 -3
  185. package/lib/elements/shapes/icon.js +12 -4
  186. package/lib/elements/shapes/icon.js.map +1 -1
  187. package/lib/elements/shapes/label.d.ts +18 -7
  188. package/lib/elements/shapes/label.js +10 -0
  189. package/lib/elements/shapes/label.js.map +1 -1
  190. package/lib/elements/shapes/polygon.js +1 -1
  191. package/lib/elements/shapes/polygon.js.map +1 -1
  192. package/lib/exports.d.ts +3 -2
  193. package/lib/exports.js +5 -2
  194. package/lib/exports.js.map +1 -1
  195. package/lib/index.d.ts +5 -1
  196. package/lib/index.js +6 -2
  197. package/lib/index.js.map +1 -1
  198. package/lib/layouts/base-layout.d.ts +3 -1
  199. package/lib/layouts/base-layout.js +3 -1
  200. package/lib/layouts/base-layout.js.map +1 -1
  201. package/lib/plugins/bubble-sets.d.ts +2 -2
  202. package/lib/plugins/bubble-sets.js.map +1 -1
  203. package/lib/plugins/contextmenu/index.d.ts +4 -3
  204. package/lib/plugins/contextmenu/index.js +12 -10
  205. package/lib/plugins/contextmenu/index.js.map +1 -1
  206. package/lib/plugins/hull/index.d.ts +2 -2
  207. package/lib/plugins/hull/index.js.map +1 -1
  208. package/lib/runtime/canvas.d.ts +15 -2
  209. package/lib/runtime/canvas.js.map +1 -1
  210. package/lib/runtime/data.d.ts +9 -16
  211. package/lib/runtime/data.js +26 -34
  212. package/lib/runtime/data.js.map +1 -1
  213. package/lib/runtime/element.d.ts +18 -2
  214. package/lib/runtime/element.js +75 -24
  215. package/lib/runtime/element.js.map +1 -1
  216. package/lib/runtime/graph.d.ts +374 -109
  217. package/lib/runtime/graph.js +278 -82
  218. package/lib/runtime/graph.js.map +1 -1
  219. package/lib/runtime/layout.js +1 -1
  220. package/lib/runtime/layout.js.map +1 -1
  221. package/lib/spec/element/edge.d.ts +1 -1
  222. package/lib/spec/element/node.d.ts +1 -1
  223. package/lib/themes/base.js +5 -0
  224. package/lib/themes/base.js.map +1 -1
  225. package/lib/transforms/collapse-expand-node.js +14 -4
  226. package/lib/transforms/collapse-expand-node.js.map +1 -1
  227. package/lib/transforms/process-parallel-edges.d.ts +2 -2
  228. package/lib/types/callable.d.ts +0 -11
  229. package/lib/types/data.d.ts +12 -0
  230. package/lib/types/edge.d.ts +11 -0
  231. package/lib/types/element.d.ts +100 -9
  232. package/lib/types/index.d.ts +0 -1
  233. package/lib/types/point.d.ts +0 -1
  234. package/lib/utils/element.d.ts +2 -2
  235. package/lib/utils/element.js.map +1 -1
  236. package/lib/utils/layout.d.ts +2 -2
  237. package/lib/utils/layout.js +4 -4
  238. package/lib/utils/layout.js.map +1 -1
  239. package/lib/utils/path.d.ts +3 -3
  240. package/lib/utils/path.js +1 -1
  241. package/lib/utils/path.js.map +1 -1
  242. package/lib/utils/position.d.ts +8 -8
  243. package/lib/utils/position.js +2 -2
  244. package/lib/utils/position.js.map +1 -1
  245. package/lib/utils/style.d.ts +13 -8
  246. package/lib/utils/style.js +18 -13
  247. package/lib/utils/style.js.map +1 -1
  248. package/package.json +10 -10
  249. package/src/behaviors/click-select.ts +61 -60
  250. package/src/behaviors/drag-element.ts +2 -7
  251. package/src/behaviors/hover-activate.ts +18 -22
  252. package/src/behaviors/lasso-select.ts +2 -2
  253. package/src/elements/base-element.ts +1 -25
  254. package/src/elements/combos/base-combo.ts +27 -11
  255. package/src/elements/edges/base-edge.ts +28 -8
  256. package/src/elements/effect.ts +74 -0
  257. package/src/elements/nodes/base-node.ts +23 -18
  258. package/src/elements/nodes/circle.ts +1 -1
  259. package/src/elements/nodes/diamond.ts +0 -7
  260. package/src/elements/nodes/ellipse.ts +1 -1
  261. package/src/elements/nodes/image.ts +2 -2
  262. package/src/elements/nodes/rect.ts +1 -1
  263. package/src/elements/shapes/badge.ts +17 -5
  264. package/src/elements/shapes/base-shape.ts +35 -15
  265. package/src/elements/shapes/icon.ts +18 -7
  266. package/src/elements/shapes/label.ts +19 -6
  267. package/src/elements/shapes/polygon.ts +1 -1
  268. package/src/exports.ts +6 -2
  269. package/src/index.ts +6 -2
  270. package/src/layouts/base-layout.ts +5 -1
  271. package/src/plugins/bubble-sets.ts +2 -2
  272. package/src/plugins/contextmenu/index.ts +16 -16
  273. package/src/plugins/hull/index.ts +2 -2
  274. package/src/runtime/canvas.ts +15 -10
  275. package/src/runtime/data.ts +32 -44
  276. package/src/runtime/element.ts +87 -30
  277. package/src/runtime/graph.ts +405 -132
  278. package/src/runtime/layout.ts +2 -2
  279. package/src/spec/element/edge.ts +1 -1
  280. package/src/spec/element/node.ts +1 -1
  281. package/src/themes/base.ts +5 -0
  282. package/src/transforms/collapse-expand-node.ts +13 -4
  283. package/src/transforms/process-parallel-edges.ts +2 -2
  284. package/src/types/callable.ts +0 -12
  285. package/src/types/data.ts +13 -0
  286. package/src/types/edge.ts +11 -0
  287. package/src/types/element.ts +106 -10
  288. package/src/types/index.ts +0 -1
  289. package/src/types/point.ts +0 -1
  290. package/src/utils/element.ts +3 -13
  291. package/src/utils/layout.ts +6 -6
  292. package/src/utils/path.ts +3 -3
  293. package/src/utils/position.ts +8 -8
  294. package/src/utils/style.ts +19 -12
  295. package/dist/lib/types/position.d.ts +0 -2
  296. package/esm/types/position.d.ts +0 -2
  297. package/esm/types/position.js +0 -2
  298. package/esm/types/position.js.map +0 -1
  299. package/lib/types/position.d.ts +0 -2
  300. package/lib/types/position.js +0 -3
  301. package/lib/types/position.js.map +0 -1
  302. package/src/types/position.ts +0 -3
@@ -2,12 +2,24 @@ import { DisplayObjectConfig, Image as GImage, Text as GText, Group, ImageStyleP
2
2
  import type { BaseShapeStyleProps } from './base-shape';
3
3
  import { BaseShape } from './base-shape';
4
4
 
5
+ /**
6
+ * <zh/> 图标样式
7
+ *
8
+ * <en/> Icon style
9
+ */
5
10
  export interface IconStyleProps extends BaseShapeStyleProps, Partial<TextStyleProps>, Omit<ImageStyleProps, 'z'> {}
6
11
 
7
- type IconOptions = DisplayObjectConfig<IconStyleProps>;
8
-
12
+ /**
13
+ * <zh/> 图标
14
+ *
15
+ * <en/> Icon
16
+ * @remarks
17
+ * <zh/> 图标是一种特殊的图形,可以是图片或者文字。传入 src 属性时,会渲染图片;传入 text 属性时,会渲染文字。
18
+ *
19
+ * <en/> Icon is a special shape, which can be an image or text. When the src attribute is passed in, an image will be rendered; when the text attribute is passed in, text will be rendered.
20
+ */
9
21
  export class Icon extends BaseShape<IconStyleProps> {
10
- constructor(options: IconOptions) {
22
+ constructor(options: DisplayObjectConfig<IconStyleProps>) {
11
23
  super(options);
12
24
  }
13
25
 
@@ -16,13 +28,12 @@ export class Icon extends BaseShape<IconStyleProps> {
16
28
  }
17
29
 
18
30
  protected getIconStyle(attributes: IconStyleProps = this.attributes): IconStyleProps {
19
- const { x = 0, y = 0 } = attributes;
31
+ const { width = 0, height = 0 } = attributes;
20
32
  const style = this.getGraphicStyle(attributes);
21
- const { width, height } = style;
22
33
  if (this.isGImage()) {
23
34
  return {
24
- x: (x as number) - (width as number) / 2,
25
- y: (y as number) - (height as number) / 2,
35
+ x: -width / 2,
36
+ y: -height / 2,
26
37
  ...style,
27
38
  };
28
39
  }
@@ -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.3';
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
  }
@@ -13,9 +13,9 @@ import { CONTEXTMENU_CSS, getContentFromItems } from './util';
13
13
  */
14
14
  export interface ContextmenuOptions extends BasePluginOptions {
15
15
  /**
16
- * <zh/> 给菜单的 DOM 追加的 classname,便于自定义样式。默认是包含 `g6-contextmenu`
16
+ * <zh/> 给菜单的 DOM 追加的类名
17
17
  *
18
- * <en/> The classname appended to the menu DOM for custom styles. The default is `g6-contextmenu`
18
+ * <en/> The class name appended to the menu DOM for custom styles
19
19
  * @defaultValue 'g6-contextmenu'
20
20
  */
21
21
  className?: string;
@@ -42,7 +42,7 @@ export interface ContextmenuOptions extends BasePluginOptions {
42
42
  *
43
43
  * <en/> The callback method triggered when the menu is clicked
44
44
  */
45
- onClick?: (v: string, target: HTMLElement) => void;
45
+ onClick?: (value: string, target: HTMLElement) => void;
46
46
  /**
47
47
  * <zh/> 返回菜单的项目列表,支持 `Promise` 类型的返回值。是 `getContent` 的快捷配置
48
48
  *
@@ -88,18 +88,24 @@ export class Contextmenu extends BasePlugin<ContextmenuOptions> {
88
88
  enable: () => true,
89
89
  };
90
90
 
91
- private $element: HTMLElement = createPluginContainer('contextmenu', false);
91
+ private $element!: HTMLElement;
92
92
 
93
93
  constructor(context: RuntimeContext, options: ContextmenuOptions) {
94
94
  super(context, Object.assign({}, Contextmenu.defaultOptions, options));
95
95
 
96
+ this.initElement();
97
+ this.update(options);
98
+ }
99
+
100
+ private initElement() {
101
+ this.$element = createPluginContainer('contextmenu', false);
102
+ const { className } = this.options;
103
+ if (className) this.$element.classList.add(className);
104
+
96
105
  const $container = this.context.canvas.getContainer();
97
106
  $container!.appendChild(this.$element);
98
107
 
99
- // 设置样式
100
108
  insertDOM('g6-contextmenu-css', 'style', {}, CONTEXTMENU_CSS, document.head);
101
-
102
- this.update(options);
103
109
  }
104
110
 
105
111
  /**
@@ -210,16 +216,10 @@ export class Contextmenu extends BasePlugin<ContextmenuOptions> {
210
216
  const { onClick } = this.options;
211
217
  if (event.target instanceof HTMLElement) {
212
218
  if (event.target.className.includes('g6-contextmenu-li')) {
213
- const v = event.target.getAttribute('value') as string;
214
- onClick && onClick(v, event.target);
215
-
216
- this.hide();
217
- }
218
-
219
- // 点击其他地方,隐藏菜单
220
- if (!this.context.graph.getCanvas().getContainer()!.contains(event.target)) {
221
- this.hide();
219
+ const value = event.target.getAttribute('value') as string;
220
+ onClick?.(value, event.target);
222
221
  }
223
222
  }
223
+ this.hide();
224
224
  };
225
225
  }
@@ -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,35 @@ 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 translateNodeLikeBy(id: ID, offset: Point) {
584
+ if (this.isCombo(id)) this.translateComboBy(id, offset);
585
+ else this.translateNodeBy(id, offset);
586
+ }
587
+
588
+ public translateNodeLikeTo(id: ID, position: Point) {
589
+ if (this.isCombo(id)) this.translateComboTo(id, position);
590
+ else this.translateNodeTo(id, position);
591
+ }
592
+
593
+ public translateNodeBy(id: ID, offset: Point) {
574
594
  const curr = this.getElementPosition(id);
575
595
  const position = add(curr, [...offset, 0].slice(0, 3) as Point);
576
596
  this.translateNodeTo(id, position);
577
597
  }
578
598
 
579
- public translateNodeTo(id: ID, position: Position) {
599
+ public translateNodeTo(id: ID, position: Point) {
580
600
  const [x = 0, y = 0, z = 0] = position;
581
601
  this.preventUpdateNodeLikeHierarchy(() => {
582
602
  this.updateNodeData([{ id, style: { x, y, z } }]);
583
603
  });
584
604
  }
585
605
 
586
- public translateComboBy(id: ID, offset: Position) {
606
+ public translateComboBy(id: ID, offset: Point) {
587
607
  const [dx = 0, dy = 0, dz = 0] = offset;
588
608
  if ([dx, dy, dz].some(isNaN) || [dx, dy, dz].every((o) => o === 0)) return;
589
609
  const combo = this.getComboData([id])[0];
@@ -610,7 +630,7 @@ export class DataController {
610
630
  );
611
631
  }
612
632
 
613
- public translateComboTo(id: ID, position: Position) {
633
+ public translateComboTo(id: ID, position: Point) {
614
634
  if (position.some(isNaN)) return;
615
635
  const [tx = 0, ty = 0, tz = 0] = position;
616
636
  const combo = this.getComboData([id])?.[0];
@@ -743,36 +763,6 @@ export class DataController {
743
763
  throw new Error(`Unknown element type of id: ${id}`);
744
764
  }
745
765
 
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
766
  public destroy() {
777
767
  const { model } = this;
778
768
  const nodes = model.getAllNodes();
@@ -785,5 +775,3 @@ export class DataController {
785
775
  this.context = {};
786
776
  }
787
777
  }
788
-
789
- export type HierarchyKey = typeof TREE_KEY | typeof COMBO_KEY;