@antv/g6 5.0.0-beta.38 → 5.0.0-beta.39

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 (211) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/dist/lib/behaviors/{click-element.d.ts → click-select.d.ts} +27 -11
  3. package/{lib/behaviors/hover-element.d.ts → dist/lib/behaviors/hover-activate.d.ts} +5 -5
  4. package/dist/lib/behaviors/index.d.ts +4 -4
  5. package/dist/lib/exports.d.ts +3 -3
  6. package/dist/lib/layouts/index.d.ts +1 -1
  7. package/dist/lib/layouts/types.d.ts +2 -2
  8. package/dist/lib/runtime/data.d.ts +9 -0
  9. package/dist/lib/runtime/element.d.ts +1 -1
  10. package/dist/lib/types/node.d.ts +12 -0
  11. package/dist/lib/utils/prefix.d.ts +1 -1
  12. package/dist/lib/utils/style.d.ts +10 -0
  13. package/{lib/behaviors/click-element.d.ts → esm/behaviors/click-select.d.ts} +27 -11
  14. package/esm/behaviors/{click-element.js → click-select.js} +40 -24
  15. package/esm/behaviors/click-select.js.map +1 -0
  16. package/{dist/lib/behaviors/hover-element.d.ts → esm/behaviors/hover-activate.d.ts} +5 -5
  17. package/esm/behaviors/{hover-element.js → hover-activate.js} +7 -7
  18. package/esm/behaviors/hover-activate.js.map +1 -0
  19. package/esm/behaviors/index.d.ts +4 -4
  20. package/esm/behaviors/index.js +2 -2
  21. package/esm/behaviors/index.js.map +1 -1
  22. package/esm/elements/combos/base-combo.js +3 -2
  23. package/esm/elements/combos/base-combo.js.map +1 -1
  24. package/esm/elements/edges/base-edge.js +5 -4
  25. package/esm/elements/edges/base-edge.js.map +1 -1
  26. package/esm/elements/edges/cubic-horizontal.js +2 -2
  27. package/esm/elements/edges/cubic-horizontal.js.map +1 -1
  28. package/esm/elements/edges/cubic-vertical.js +2 -2
  29. package/esm/elements/edges/cubic-vertical.js.map +1 -1
  30. package/esm/elements/edges/cubic.js +2 -2
  31. package/esm/elements/edges/cubic.js.map +1 -1
  32. package/esm/elements/edges/line.js +2 -2
  33. package/esm/elements/edges/line.js.map +1 -1
  34. package/esm/elements/edges/polyline.js +2 -2
  35. package/esm/elements/edges/polyline.js.map +1 -1
  36. package/esm/elements/edges/quadratic.js +2 -2
  37. package/esm/elements/edges/quadratic.js.map +1 -1
  38. package/esm/elements/nodes/base-node.js +8 -8
  39. package/esm/elements/nodes/base-node.js.map +1 -1
  40. package/esm/elements/nodes/circle.js +2 -2
  41. package/esm/elements/nodes/circle.js.map +1 -1
  42. package/esm/elements/nodes/donut.js +3 -2
  43. package/esm/elements/nodes/donut.js.map +1 -1
  44. package/esm/elements/nodes/ellipse.js +2 -2
  45. package/esm/elements/nodes/ellipse.js.map +1 -1
  46. package/esm/elements/nodes/image.js +2 -2
  47. package/esm/elements/nodes/image.js.map +1 -1
  48. package/esm/elements/nodes/rect.js +2 -2
  49. package/esm/elements/nodes/rect.js.map +1 -1
  50. package/esm/elements/nodes/triangle.js +3 -2
  51. package/esm/elements/nodes/triangle.js.map +1 -1
  52. package/esm/elements/shapes/badge.js +2 -2
  53. package/esm/elements/shapes/badge.js.map +1 -1
  54. package/esm/elements/shapes/contour.js +2 -2
  55. package/esm/elements/shapes/contour.js.map +1 -1
  56. package/esm/elements/shapes/label.js +2 -2
  57. package/esm/elements/shapes/label.js.map +1 -1
  58. package/esm/exports.d.ts +3 -3
  59. package/esm/exports.js +2 -2
  60. package/esm/exports.js.map +1 -1
  61. package/esm/layouts/index.d.ts +1 -1
  62. package/esm/layouts/index.js +1 -1
  63. package/esm/layouts/index.js.map +1 -1
  64. package/esm/layouts/types.d.ts +2 -2
  65. package/esm/plugins/background/index.js +1 -2
  66. package/esm/plugins/background/index.js.map +1 -1
  67. package/esm/registry/build-in.js +5 -6
  68. package/esm/registry/build-in.js.map +1 -1
  69. package/esm/runtime/data.d.ts +9 -0
  70. package/esm/runtime/data.js +19 -7
  71. package/esm/runtime/data.js.map +1 -1
  72. package/esm/runtime/element.d.ts +1 -1
  73. package/esm/runtime/element.js +23 -16
  74. package/esm/runtime/element.js.map +1 -1
  75. package/esm/runtime/graph.js +1 -0
  76. package/esm/runtime/graph.js.map +1 -1
  77. package/esm/types/node.d.ts +12 -0
  78. package/esm/utils/id.js +2 -4
  79. package/esm/utils/id.js.map +1 -1
  80. package/esm/utils/palette.js +17 -9
  81. package/esm/utils/palette.js.map +1 -1
  82. package/esm/utils/prefix.d.ts +1 -1
  83. package/esm/utils/prefix.js +7 -6
  84. package/esm/utils/prefix.js.map +1 -1
  85. package/esm/utils/shape.js +1 -1
  86. package/esm/utils/shape.js.map +1 -1
  87. package/esm/utils/size.js +2 -3
  88. package/esm/utils/size.js.map +1 -1
  89. package/esm/utils/style.d.ts +10 -0
  90. package/esm/utils/style.js +15 -0
  91. package/esm/utils/style.js.map +1 -1
  92. package/{esm/behaviors/click-element.d.ts → lib/behaviors/click-select.d.ts} +27 -11
  93. package/lib/behaviors/{click-element.js → click-select.js} +42 -26
  94. package/lib/behaviors/click-select.js.map +1 -0
  95. package/{esm/behaviors/hover-element.d.ts → lib/behaviors/hover-activate.d.ts} +5 -5
  96. package/lib/behaviors/{hover-element.js → hover-activate.js} +9 -9
  97. package/lib/behaviors/hover-activate.js.map +1 -0
  98. package/lib/behaviors/index.d.ts +4 -4
  99. package/lib/behaviors/index.js +5 -5
  100. package/lib/behaviors/index.js.map +1 -1
  101. package/lib/elements/combos/base-combo.js +2 -1
  102. package/lib/elements/combos/base-combo.js.map +1 -1
  103. package/lib/elements/edges/base-edge.js +4 -3
  104. package/lib/elements/edges/base-edge.js.map +1 -1
  105. package/lib/elements/edges/cubic-horizontal.js +2 -2
  106. package/lib/elements/edges/cubic-horizontal.js.map +1 -1
  107. package/lib/elements/edges/cubic-vertical.js +2 -2
  108. package/lib/elements/edges/cubic-vertical.js.map +1 -1
  109. package/lib/elements/edges/cubic.js +2 -2
  110. package/lib/elements/edges/cubic.js.map +1 -1
  111. package/lib/elements/edges/line.js +2 -2
  112. package/lib/elements/edges/line.js.map +1 -1
  113. package/lib/elements/edges/polyline.js +2 -2
  114. package/lib/elements/edges/polyline.js.map +1 -1
  115. package/lib/elements/edges/quadratic.js +2 -2
  116. package/lib/elements/edges/quadratic.js.map +1 -1
  117. package/lib/elements/nodes/base-node.js +8 -8
  118. package/lib/elements/nodes/base-node.js.map +1 -1
  119. package/lib/elements/nodes/circle.js +2 -2
  120. package/lib/elements/nodes/circle.js.map +1 -1
  121. package/lib/elements/nodes/donut.js +2 -1
  122. package/lib/elements/nodes/donut.js.map +1 -1
  123. package/lib/elements/nodes/ellipse.js +2 -2
  124. package/lib/elements/nodes/ellipse.js.map +1 -1
  125. package/lib/elements/nodes/image.js +2 -2
  126. package/lib/elements/nodes/image.js.map +1 -1
  127. package/lib/elements/nodes/rect.js +2 -2
  128. package/lib/elements/nodes/rect.js.map +1 -1
  129. package/lib/elements/nodes/triangle.js +2 -1
  130. package/lib/elements/nodes/triangle.js.map +1 -1
  131. package/lib/elements/shapes/badge.js +2 -2
  132. package/lib/elements/shapes/badge.js.map +1 -1
  133. package/lib/elements/shapes/contour.js +2 -2
  134. package/lib/elements/shapes/contour.js.map +1 -1
  135. package/lib/elements/shapes/label.js +2 -2
  136. package/lib/elements/shapes/label.js.map +1 -1
  137. package/lib/exports.d.ts +3 -3
  138. package/lib/exports.js +4 -5
  139. package/lib/exports.js.map +1 -1
  140. package/lib/layouts/index.d.ts +1 -1
  141. package/lib/layouts/index.js +1 -2
  142. package/lib/layouts/index.js.map +1 -1
  143. package/lib/layouts/types.d.ts +2 -2
  144. package/lib/plugins/background/index.js +1 -2
  145. package/lib/plugins/background/index.js.map +1 -1
  146. package/lib/registry/build-in.js +3 -4
  147. package/lib/registry/build-in.js.map +1 -1
  148. package/lib/runtime/data.d.ts +9 -0
  149. package/lib/runtime/data.js +19 -7
  150. package/lib/runtime/data.js.map +1 -1
  151. package/lib/runtime/element.d.ts +1 -1
  152. package/lib/runtime/element.js +22 -15
  153. package/lib/runtime/element.js.map +1 -1
  154. package/lib/runtime/graph.js +1 -0
  155. package/lib/runtime/graph.js.map +1 -1
  156. package/lib/types/node.d.ts +12 -0
  157. package/lib/utils/id.js +2 -4
  158. package/lib/utils/id.js.map +1 -1
  159. package/lib/utils/palette.js +16 -8
  160. package/lib/utils/palette.js.map +1 -1
  161. package/lib/utils/prefix.d.ts +1 -1
  162. package/lib/utils/prefix.js +6 -5
  163. package/lib/utils/prefix.js.map +1 -1
  164. package/lib/utils/shape.js +1 -1
  165. package/lib/utils/shape.js.map +1 -1
  166. package/lib/utils/size.js +2 -3
  167. package/lib/utils/size.js.map +1 -1
  168. package/lib/utils/style.d.ts +10 -0
  169. package/lib/utils/style.js +17 -1
  170. package/lib/utils/style.js.map +1 -1
  171. package/package.json +1 -1
  172. package/src/behaviors/{click-element.ts → click-select.ts} +72 -31
  173. package/src/behaviors/{hover-element.ts → hover-activate.ts} +10 -10
  174. package/src/behaviors/index.ts +4 -4
  175. package/src/elements/combos/base-combo.ts +3 -2
  176. package/src/elements/edges/base-edge.ts +5 -4
  177. package/src/elements/edges/cubic-horizontal.ts +2 -2
  178. package/src/elements/edges/cubic-vertical.ts +2 -2
  179. package/src/elements/edges/cubic.ts +2 -2
  180. package/src/elements/edges/line.ts +2 -2
  181. package/src/elements/edges/polyline.ts +2 -2
  182. package/src/elements/edges/quadratic.ts +2 -2
  183. package/src/elements/nodes/base-node.ts +8 -8
  184. package/src/elements/nodes/circle.ts +2 -2
  185. package/src/elements/nodes/donut.ts +3 -2
  186. package/src/elements/nodes/ellipse.ts +2 -2
  187. package/src/elements/nodes/image.ts +2 -2
  188. package/src/elements/nodes/rect.ts +2 -2
  189. package/src/elements/nodes/triangle.ts +3 -2
  190. package/src/elements/shapes/badge.ts +2 -2
  191. package/src/elements/shapes/contour.ts +2 -2
  192. package/src/elements/shapes/label.ts +2 -2
  193. package/src/exports.ts +4 -5
  194. package/src/layouts/index.ts +0 -1
  195. package/src/layouts/types.ts +2 -2
  196. package/src/plugins/background/index.ts +1 -2
  197. package/src/registry/build-in.ts +5 -7
  198. package/src/runtime/data.ts +20 -5
  199. package/src/runtime/element.ts +18 -13
  200. package/src/runtime/graph.ts +1 -0
  201. package/src/types/node.ts +12 -0
  202. package/src/utils/id.ts +2 -4
  203. package/src/utils/palette.ts +17 -9
  204. package/src/utils/prefix.ts +8 -7
  205. package/src/utils/shape.ts +1 -1
  206. package/src/utils/size.ts +1 -2
  207. package/src/utils/style.ts +17 -0
  208. package/esm/behaviors/click-element.js.map +0 -1
  209. package/esm/behaviors/hover-element.js.map +0 -1
  210. package/lib/behaviors/click-element.js.map +0 -1
  211. package/lib/behaviors/hover-element.js.map +0 -1
@@ -1,8 +1,8 @@
1
1
  import type { DisplayObjectConfig } from '@antv/g';
2
2
  import type { PathArray } from '@antv/util';
3
- import { deepMix } from '@antv/util';
4
3
  import type { Point } from '../../types';
5
4
  import { getCubicPath, getCurveControlPoint, parseCurveOffset, parseCurvePosition } from '../../utils/edge';
5
+ import { mergeOptions } from '../../utils/style';
6
6
  import type { BaseEdgeStyleProps } from './base-edge';
7
7
  import { BaseEdge } from './base-edge';
8
8
 
@@ -48,7 +48,7 @@ export class Cubic extends BaseEdge {
48
48
  };
49
49
 
50
50
  constructor(options: DisplayObjectConfig<CubicStyleProps>) {
51
- super(deepMix({}, { style: Cubic.defaultStyleProps }, options));
51
+ super(mergeOptions({ style: Cubic.defaultStyleProps }, options));
52
52
  }
53
53
 
54
54
  /**
@@ -1,6 +1,6 @@
1
1
  import type { DisplayObjectConfig } from '@antv/g';
2
2
  import type { PathArray } from '@antv/util';
3
- import { deepMix } from '@antv/util';
3
+ import { mergeOptions } from '../../utils/style';
4
4
  import type { BaseEdgeStyleProps } from './base-edge';
5
5
  import { BaseEdge } from './base-edge';
6
6
 
@@ -24,7 +24,7 @@ export class Line extends BaseEdge {
24
24
  static defaultStyleProps: Partial<LineStyleProps> = {};
25
25
 
26
26
  constructor(options: DisplayObjectConfig<LineStyleProps>) {
27
- super(deepMix({}, { style: Line.defaultStyleProps }, options));
27
+ super(mergeOptions({ style: Line.defaultStyleProps }, options));
28
28
  }
29
29
 
30
30
  protected getKeyPath(attributes: ParsedLineStyleProps): PathArray {
@@ -1,12 +1,12 @@
1
1
  import type { DisplayObjectConfig } from '@antv/g';
2
2
  import type { PathArray } from '@antv/util';
3
- import { deepMix } from '@antv/util';
4
3
  import type { LoopStyleProps, Padding, Point, Port } from '../../types';
5
4
  import { getBBoxHeight, getBBoxWidth, getNodeBBox } from '../../utils/bbox';
6
5
  import { getPolylineLoopPath, getPolylinePath } from '../../utils/edge';
7
6
  import { findPorts, getConnectionPoint, getPortPosition } from '../../utils/element';
8
7
  import { subStyleProps } from '../../utils/prefix';
9
8
  import { orth } from '../../utils/router/orth';
9
+ import { mergeOptions } from '../../utils/style';
10
10
  import type { BaseEdgeStyleProps } from './base-edge';
11
11
  import { BaseEdge } from './base-edge';
12
12
 
@@ -70,7 +70,7 @@ export class Polyline extends BaseEdge {
70
70
  };
71
71
 
72
72
  constructor(options: DisplayObjectConfig<PolylineStyleProps>) {
73
- super(deepMix({}, { style: Polyline.defaultStyleProps }, options));
73
+ super(mergeOptions({ style: Polyline.defaultStyleProps }, options));
74
74
  }
75
75
 
76
76
  protected getKeyPath(attributes: ParsedPolylineStyleProps): PathArray {
@@ -1,8 +1,8 @@
1
1
  import type { DisplayObjectConfig } from '@antv/g';
2
2
  import type { PathArray } from '@antv/util';
3
- import { deepMix } from '@antv/util';
4
3
  import type { Point } from '../../types';
5
4
  import { getCurveControlPoint, getQuadraticPath } from '../../utils/edge';
5
+ import { mergeOptions } from '../../utils/style';
6
6
  import type { BaseEdgeStyleProps } from './base-edge';
7
7
  import { BaseEdge } from './base-edge';
8
8
 
@@ -48,7 +48,7 @@ export class Quadratic extends BaseEdge {
48
48
  };
49
49
 
50
50
  constructor(options: DisplayObjectConfig<QuadraticStyleProps>) {
51
- super(deepMix({}, { style: Quadratic.defaultStyleProps }, options));
51
+ super(mergeOptions({ style: Quadratic.defaultStyleProps }, options));
52
52
  }
53
53
 
54
54
  protected getKeyPath(attributes: ParsedQuadraticStyleProps): PathArray {
@@ -1,6 +1,5 @@
1
1
  import type { BaseStyleProps, DisplayObject, DisplayObjectConfig, Group } from '@antv/g';
2
2
  import { Circle as GCircle } from '@antv/g';
3
- import { deepMix, isEmpty } from '@antv/util';
4
3
  import type { CategoricalPalette } from '../../palettes/types';
5
4
  import type { NodeData } from '../../spec';
6
5
  import type {
@@ -22,6 +21,7 @@ import { getRectIntersectPoint } from '../../utils/point';
22
21
  import { getXYByPlacement } from '../../utils/position';
23
22
  import { omitStyleProps, subObject, subStyleProps } from '../../utils/prefix';
24
23
  import { parseSize } from '../../utils/size';
24
+ import { mergeOptions } from '../../utils/style';
25
25
  import { getWordWrapWidthByBox } from '../../utils/text';
26
26
  import { replaceTranslateInTransform } from '../../utils/transform';
27
27
  import { BaseElement } from '../base-element';
@@ -218,7 +218,7 @@ export abstract class BaseNode<S extends BaseNodeStyleProps = BaseNodeStyleProps
218
218
  };
219
219
 
220
220
  constructor(options: DisplayObjectConfig<S>) {
221
- super(deepMix({}, { style: BaseNode.defaultStyleProps }, options));
221
+ super(mergeOptions({ style: BaseNode.defaultStyleProps }, options));
222
222
  }
223
223
 
224
224
  protected getSize(attributes = this.attributes) {
@@ -233,9 +233,9 @@ export abstract class BaseNode<S extends BaseNodeStyleProps = BaseNodeStyleProps
233
233
  }
234
234
 
235
235
  protected getLabelStyle(attributes: Required<S>): false | LabelStyleProps {
236
- if (attributes.label === false || isEmpty(attributes.labelText)) return false;
236
+ if (attributes.label === false || !attributes.labelText) return false;
237
237
 
238
- const { placement, maxWidth, ...labelStyle } = subStyleProps<Required<NodeLabelStyleProps>>(
238
+ const { placement, maxWidth, offsetX, offsetY, ...labelStyle } = subStyleProps<Required<NodeLabelStyleProps>>(
239
239
  this.getGraphicStyle(attributes),
240
240
  'label',
241
241
  );
@@ -243,7 +243,7 @@ export abstract class BaseNode<S extends BaseNodeStyleProps = BaseNodeStyleProps
243
243
  const keyBounds = keyShape.getLocalBounds();
244
244
 
245
245
  return Object.assign(
246
- getTextStyleByPlacement(keyBounds, placement),
246
+ getTextStyleByPlacement(keyBounds, placement, offsetX, offsetY),
247
247
  { wordWrapWidth: getWordWrapWidthByBox(keyBounds, maxWidth) },
248
248
  labelStyle,
249
249
  );
@@ -259,7 +259,7 @@ export abstract class BaseNode<S extends BaseNodeStyleProps = BaseNodeStyleProps
259
259
  }
260
260
 
261
261
  protected getIconStyle(attributes: Required<S>): false | IconStyleProps {
262
- if (attributes.icon === false || isEmpty(attributes.iconText || attributes.iconSrc)) return false;
262
+ if (attributes.icon === false || (!attributes.iconText && !attributes.iconSrc)) return false;
263
263
 
264
264
  const iconStyle = subStyleProps(this.getGraphicStyle(attributes), 'icon');
265
265
  const keyShape = this.getKey();
@@ -275,7 +275,7 @@ export abstract class BaseNode<S extends BaseNodeStyleProps = BaseNodeStyleProps
275
275
  Object.keys(badges).forEach((key) => {
276
276
  badgesShapeStyle[key] = false;
277
277
  });
278
- if (attributes.badge === false || isEmpty(attributes.badges)) return badgesShapeStyle;
278
+ if (attributes.badge === false || !attributes.badges?.length) return badgesShapeStyle;
279
279
 
280
280
  const { badges: badgeOptions = [], badgePalette, opacity = 1, ...restAttributes } = attributes;
281
281
  const colors = getPaletteColors(badgePalette);
@@ -308,7 +308,7 @@ export abstract class BaseNode<S extends BaseNodeStyleProps = BaseNodeStyleProps
308
308
  portsShapeStyle[key] = false;
309
309
  });
310
310
 
311
- if (attributes.port === false || isEmpty(attributes.ports)) return portsShapeStyle;
311
+ if (attributes.port === false || !attributes.ports?.length) return portsShapeStyle;
312
312
 
313
313
  const portStyle = subStyleProps<PortStyleProps>(this.getGraphicStyle(attributes), 'port');
314
314
  const { ports: portOptions = [] } = attributes;
@@ -1,9 +1,9 @@
1
1
  import type { DisplayObjectConfig, CircleStyleProps as GCircleStyleProps, Group } from '@antv/g';
2
2
  import { Circle as GCircle } from '@antv/g';
3
- import { deepMix } from '@antv/util';
4
3
  import { ICON_SIZE_RATIO } from '../../constants/element';
5
4
  import type { Point } from '../../types';
6
5
  import { getEllipseIntersectPoint } from '../../utils/point';
6
+ import { mergeOptions } from '../../utils/style';
7
7
  import type { IconStyleProps } from '../shapes';
8
8
  import type { BaseNodeStyleProps } from './base-node';
9
9
  import { BaseNode } from './base-node';
@@ -26,7 +26,7 @@ export class Circle extends BaseNode {
26
26
  };
27
27
 
28
28
  constructor(options: DisplayObjectConfig<CircleStyleProps>) {
29
- super(deepMix({}, { style: Circle.defaultStyleProps }, options));
29
+ super(mergeOptions({ style: Circle.defaultStyleProps }, options));
30
30
  }
31
31
 
32
32
  protected drawKeyShape(attributes: Required<CircleStyleProps>, container: Group) {
@@ -1,5 +1,5 @@
1
1
  import { Path } from '@antv/g';
2
- import { deepMix, isNumber, isString } from '@antv/util';
2
+ import { isNumber, isString } from '@antv/util';
3
3
  import { getPaletteColors } from '../../utils/palette';
4
4
  import { subStyleProps } from '../../utils/prefix';
5
5
  import { parseSize } from '../../utils/size';
@@ -8,6 +8,7 @@ import { Circle } from './circle';
8
8
  import type { BaseStyleProps, DisplayObjectConfig, Group } from '@antv/g';
9
9
  import type { CategoricalPalette } from '../../palettes/types';
10
10
  import type { DonutRound, Prefix } from '../../types';
11
+ import { mergeOptions } from '../../utils/style';
11
12
  import type { CircleStyleProps } from './circle';
12
13
 
13
14
  /**
@@ -51,7 +52,7 @@ export class Donut extends Circle {
51
52
  };
52
53
 
53
54
  constructor(options: DisplayObjectConfig<DonutStyleProps>) {
54
- super(deepMix({}, { style: Donut.defaultStyleProps }, options));
55
+ super(mergeOptions({ style: Donut.defaultStyleProps }, options));
55
56
  }
56
57
 
57
58
  private parseOuterR() {
@@ -1,9 +1,9 @@
1
1
  import type { DisplayObjectConfig, EllipseStyleProps as GEllipseStyleProps, Group } from '@antv/g';
2
2
  import { Ellipse as GEllipse } from '@antv/g';
3
- import { deepMix } from '@antv/util';
4
3
  import { ICON_SIZE_RATIO } from '../../constants/element';
5
4
  import type { Point } from '../../types';
6
5
  import { getEllipseIntersectPoint } from '../../utils/point';
6
+ import { mergeOptions } from '../../utils/style';
7
7
  import type { IconStyleProps } from '../shapes';
8
8
  import type { BaseNodeStyleProps } from './base-node';
9
9
  import { BaseNode } from './base-node';
@@ -26,7 +26,7 @@ export class Ellipse extends BaseNode {
26
26
  };
27
27
 
28
28
  constructor(options: DisplayObjectConfig<EllipseStyleProps>) {
29
- super(deepMix({}, { style: Ellipse.defaultStyleProps }, options));
29
+ super(mergeOptions({ style: Ellipse.defaultStyleProps }, options));
30
30
  }
31
31
 
32
32
  protected drawKeyShape(attributes: Required<EllipseStyleProps>, container: Group) {
@@ -1,8 +1,8 @@
1
1
  import type { DisplayObjectConfig, RectStyleProps as GRectStyleProps, Group } from '@antv/g';
2
2
  import { Image as GImage, ImageStyleProps as GImageStyleProps, Rect as GRect } from '@antv/g';
3
- import { deepMix } from '@antv/util';
4
3
  import { ICON_SIZE_RATIO } from '../../constants/element';
5
4
  import { subStyleProps } from '../../utils/prefix';
5
+ import { mergeOptions } from '../../utils/style';
6
6
  import { add } from '../../utils/vector';
7
7
  import type { IconStyleProps } from '../shapes';
8
8
  import type { BaseNodeStyleProps } from './base-node';
@@ -39,7 +39,7 @@ export class Image extends BaseNode<ImageStyleProps> {
39
39
  };
40
40
 
41
41
  constructor(options: DisplayObjectConfig<ImageStyleProps>) {
42
- super(deepMix({}, { style: Image.defaultStyleProps }, options));
42
+ super(mergeOptions({ style: Image.defaultStyleProps }, options));
43
43
  }
44
44
 
45
45
  protected getKeyStyle(attributes: Required<ImageStyleProps>): GImageStyleProps {
@@ -1,7 +1,7 @@
1
1
  import type { DisplayObjectConfig, RectStyleProps as GRectStyleProps, Group } from '@antv/g';
2
2
  import { Rect as GRect } from '@antv/g';
3
- import { deepMix } from '@antv/util';
4
3
  import { ICON_SIZE_RATIO } from '../../constants/element';
4
+ import { mergeOptions } from '../../utils/style';
5
5
  import type { IconStyleProps } from '../shapes';
6
6
  import type { BaseNodeStyleProps } from './base-node';
7
7
  import { BaseNode } from './base-node';
@@ -25,7 +25,7 @@ export class Rect extends BaseNode<RectStyleProps> {
25
25
  };
26
26
 
27
27
  constructor(options: DisplayObjectConfig<RectStyleProps>) {
28
- super(deepMix({}, { style: Rect.defaultStyleProps }, options));
28
+ super(mergeOptions({ style: Rect.defaultStyleProps }, options));
29
29
  }
30
30
 
31
31
  protected getKeyStyle(attributes: ParsedRectStyleProps): GRectStyleProps {
@@ -1,10 +1,11 @@
1
1
  import type { DisplayObjectConfig } from '@antv/g';
2
- import { deepMix, isEmpty } from '@antv/util';
2
+ import { isEmpty } from '@antv/util';
3
3
  import { ICON_SIZE_RATIO } from '../../constants/element';
4
4
  import type { NodePortStyleProps, Point, TriangleDirection, TrianglePortPlacement } from '../../types';
5
5
  import { getIncircleRadius, getTriangleCenter } from '../../utils/bbox';
6
6
  import { getPortXYByPlacement, getTrianglePoints, getTrianglePorts } from '../../utils/element';
7
7
  import { subStyleProps } from '../../utils/prefix';
8
+ import { mergeOptions } from '../../utils/style';
8
9
  import type { PolygonStyleProps } from '../shapes';
9
10
  import { IconStyleProps } from '../shapes';
10
11
  import { Polygon } from '../shapes/polygon';
@@ -36,7 +37,7 @@ export class Triangle extends Polygon<TriangleStyleProps> {
36
37
  };
37
38
 
38
39
  constructor(options: DisplayObjectConfig<TriangleStyleProps>) {
39
- super(deepMix({}, { style: Triangle.defaultStyleProps }, options));
40
+ super(mergeOptions({ style: Triangle.defaultStyleProps }, options));
40
41
  }
41
42
 
42
43
  protected getPoints(attributes: Required<TriangleStyleProps>): Point[] {
@@ -1,5 +1,5 @@
1
1
  import type { DisplayObjectConfig, Group } from '@antv/g';
2
- import { deepMix } from '@antv/util';
2
+ import { mergeOptions } from '../../utils/style';
3
3
  import { BaseShape } from './base-shape';
4
4
  import type { LabelStyleProps } from './label';
5
5
  import { Label } from './label';
@@ -18,7 +18,7 @@ export class Badge extends BaseShape<BadgeStyleProps> {
18
18
  };
19
19
 
20
20
  constructor(options: BadgeOptions) {
21
- super(deepMix({}, { style: Badge.defaultStyleProps }, options));
21
+ super(mergeOptions({ style: Badge.defaultStyleProps }, options));
22
22
  }
23
23
 
24
24
  protected getBadgeStyle(attributes: ParsedBadgeStyleProps) {
@@ -1,9 +1,9 @@
1
1
  import type { DisplayObjectConfig, Group, PathStyleProps } from '@antv/g';
2
2
  import { Path } from '@antv/g';
3
- import { deepMix } from '@antv/util';
4
3
  import type { CardinalPlacement, Prefix } from '../../types';
5
4
  import { getPolygonTextStyleByPlacement } from '../../utils/polygon';
6
5
  import { subStyleProps } from '../../utils/prefix';
6
+ import { mergeOptions } from '../../utils/style';
7
7
  import { getWordWrapWidthByBox } from '../../utils/text';
8
8
  import type { LabelStyleProps } from '../shapes';
9
9
  import { BaseShape } from './base-shape';
@@ -76,7 +76,7 @@ export class Contour extends BaseShape<ContourStyleProps> {
76
76
  };
77
77
 
78
78
  constructor(options: ContourOptions) {
79
- super(deepMix({}, { style: Contour.defaultStyleProps }, options));
79
+ super(mergeOptions({ style: Contour.defaultStyleProps }, options));
80
80
  }
81
81
 
82
82
  protected getLabelStyle(attributes: ParsedContourStyleProps): LabelStyleProps | false {
@@ -1,9 +1,9 @@
1
1
  import { DisplayObjectConfig, Group, Rect, RectStyleProps, Text, TextStyleProps } from '@antv/g';
2
- import { deepMix } from '@antv/util';
3
2
  import type { Padding } from '../../types/padding';
4
3
  import type { Prefix } from '../../types/prefix';
5
4
  import { parsePadding } from '../../utils/padding';
6
5
  import { omitStyleProps, startsWith, subStyleProps } from '../../utils/prefix';
6
+ import { mergeOptions } from '../../utils/style';
7
7
  import { BaseShape } from './base-shape';
8
8
 
9
9
  export interface LabelStyleProps extends TextStyleProps, Prefix<'background', RectStyleProps> {
@@ -39,7 +39,7 @@ export class Label extends BaseShape<LabelStyleProps> {
39
39
  };
40
40
 
41
41
  constructor(options: LabelOptions) {
42
- super(deepMix({}, { style: Label.defaultStyleProps }, options));
42
+ super(mergeOptions({ style: Label.defaultStyleProps }, options));
43
43
  }
44
44
 
45
45
  protected isTextStyle(key: string) {
package/src/exports.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  export {
2
2
  BaseBehavior,
3
3
  BrushSelect,
4
- ClickElement,
4
+ ClickSelect,
5
5
  CollapseExpand,
6
6
  CreateEdge,
7
7
  DragCanvas,
8
8
  DragElement,
9
9
  DragElementForce,
10
10
  FocusElement,
11
- HoverElement,
11
+ HoverActivate,
12
12
  LassoSelect,
13
13
  ScrollCanvas,
14
14
  ZoomCanvas,
@@ -46,7 +46,6 @@ export {
46
46
  CircularLayout,
47
47
  ComboCombinedLayout,
48
48
  ConcentricLayout,
49
- D3Force3DLayout,
50
49
  D3ForceLayout,
51
50
  DagreLayout,
52
51
  ForceAtlas2Layout,
@@ -107,14 +106,14 @@ export type { AnimationContext, AnimationEffectTiming, AnimationExecutor, Animat
107
106
  export type {
108
107
  BaseBehaviorOptions,
109
108
  BrushSelectOptions,
110
- ClickElementOptions,
109
+ ClickSelectOptions,
111
110
  CollapseExpandOptions,
112
111
  CreateEdgeOptions,
113
112
  DragCanvasOptions,
114
113
  DragElementForceOptions,
115
114
  DragElementOptions,
116
115
  FocusElementOptions,
117
- HoverElementOptions,
116
+ HoverActivateOptions,
118
117
  LassoSelectOptions,
119
118
  ScrollCanvasOptions,
120
119
  ZoomCanvasOptions,
@@ -4,7 +4,6 @@ export {
4
4
  CircularLayout,
5
5
  ComboCombinedLayout,
6
6
  ConcentricLayout,
7
- D3Force3DLayout,
8
7
  D3ForceLayout,
9
8
  DagreLayout,
10
9
  ForceAtlas2Layout,
@@ -79,11 +79,11 @@ interface FruchtermanLayout extends BaseLayoutOptions, FruchtermanLayoutOptions
79
79
  }
80
80
 
81
81
  interface D3ForceLayout extends BaseLayoutOptions, D3ForceLayoutOptions {
82
- type: 'd3force';
82
+ type: 'd3-force';
83
83
  }
84
84
 
85
85
  interface D3Force3DLayout extends BaseLayoutOptions, D3Force3DLayoutOptions {
86
- type: 'd3force3d';
86
+ type: 'd3-force3d';
87
87
  }
88
88
 
89
89
  interface ForceLayout extends BaseLayoutOptions, ForceLayoutOptions {
@@ -24,7 +24,6 @@ export class Background extends BasePlugin<BackgroundOptions> {
24
24
  static defaultOptions: Partial<BackgroundOptions> = {
25
25
  transition: 'background 0.5s',
26
26
  backgroundSize: 'cover',
27
- opacity: '0.35',
28
27
  };
29
28
 
30
29
  private $element: HTMLElement = createPluginContainer('background');
@@ -33,7 +32,7 @@ export class Background extends BasePlugin<BackgroundOptions> {
33
32
  super(context, Object.assign({}, Background.defaultOptions, options));
34
33
 
35
34
  const $container = this.context.canvas.getContainer();
36
- $container!.appendChild(this.$element);
35
+ $container!.prepend(this.$element);
37
36
 
38
37
  this.update(options);
39
38
  }
@@ -1,14 +1,14 @@
1
1
  import { ComboCollapse, ComboExpand, Fade, NodeCollapse, NodeExpand, PathIn, PathOut, Translate } from '../animations';
2
2
  import {
3
3
  BrushSelect,
4
- ClickElement,
4
+ ClickSelect,
5
5
  CollapseExpand,
6
6
  CreateEdge,
7
7
  DragCanvas,
8
8
  DragElement,
9
9
  DragElementForce,
10
10
  FocusElement,
11
- HoverElement,
11
+ HoverActivate,
12
12
  LassoSelect,
13
13
  ScrollCanvas,
14
14
  ZoomCanvas,
@@ -38,7 +38,6 @@ import {
38
38
  CircularLayout,
39
39
  ComboCombinedLayout,
40
40
  ConcentricLayout,
41
- D3Force3DLayout,
42
41
  D3ForceLayout,
43
42
  DagreLayout,
44
43
  ForceAtlas2Layout,
@@ -100,8 +99,8 @@ export const BUILT_IN_EXTENSIONS: ExtensionRegistry = {
100
99
  'drag-element-force': DragElementForce,
101
100
  'scroll-canvas': ScrollCanvas,
102
101
  'collapse-expand': CollapseExpand,
103
- 'click-element': ClickElement,
104
- 'hover-element': HoverElement,
102
+ 'click-select': ClickSelect,
103
+ 'hover-activate': HoverActivate,
105
104
  'focus-element': FocusElement,
106
105
  'create-edge': CreateEdge,
107
106
  'brush-select': BrushSelect,
@@ -126,8 +125,7 @@ export const BUILT_IN_EXTENSIONS: ExtensionRegistry = {
126
125
  'force-atlas2': ForceAtlas2Layout,
127
126
  circular: CircularLayout,
128
127
  concentric: ConcentricLayout,
129
- d3force: D3ForceLayout,
130
- 'd3-force-3d': D3Force3DLayout,
128
+ 'd3-force': D3ForceLayout,
131
129
  dagre: DagreLayout,
132
130
  dendrogram,
133
131
  force: ForceLayout,
@@ -143,6 +143,10 @@ export class DataController {
143
143
  }, [] as NodeData[]);
144
144
  }
145
145
 
146
+ public getEdgeDatum(id: ID) {
147
+ return toG6Data(this.model.getEdge(id));
148
+ }
149
+
146
150
  public getEdgeData(ids?: ID[]) {
147
151
  return this.model.getAllEdges().reduce((acc, edge) => {
148
152
  const data = toG6Data(edge);
@@ -224,9 +228,20 @@ export class DataController {
224
228
  */
225
229
  public getElementDataById(id: ID): ElementDatum {
226
230
  const type = this.getElementType(id);
227
- if (type === 'node') return this.getNodeData([id])[0];
228
- else if (type === 'edge') return this.getEdgeData([id])[0];
229
- return this.getComboData([id])[0];
231
+ if (type === 'edge') return this.getEdgeDatum(id);
232
+ return this.getNodeLikeDatum(id);
233
+ }
234
+
235
+ /**
236
+ * <zh/> 获取节点的数据
237
+ *
238
+ * <en/> Get node data
239
+ * @param id - <zh/> 节点 ID | <en/> node ID
240
+ * @returns <zh/> 节点数据 | <en/> node data
241
+ */
242
+ public getNodeLikeDatum(id: ID) {
243
+ const data = this.model.getNode(id);
244
+ return toG6Data(data);
230
245
  }
231
246
 
232
247
  /**
@@ -496,7 +511,7 @@ export class DataController {
496
511
  */
497
512
  public setParent(id: ID, parent: ID | undefined, hierarchyKey: HierarchyKey, update: boolean = true) {
498
513
  if (id === parent) return;
499
- const originalParentId = parentIdOf(this.getNodeLikeData([id])[0]);
514
+ const originalParentId = parentIdOf(this.getNodeLikeDatum(id));
500
515
 
501
516
  // Sync data
502
517
  if (originalParentId !== parent && hierarchyKey === COMBO_KEY) {
@@ -681,7 +696,7 @@ export class DataController {
681
696
  */
682
697
  protected removeNodeLikeHierarchy(id: ID) {
683
698
  if (this.model.hasTreeStructure(COMBO_KEY)) {
684
- const grandParent = parentIdOf(this.getNodeLikeData([id])[0]);
699
+ const grandParent = parentIdOf(this.getNodeLikeDatum(id));
685
700
 
686
701
  // 从父节点的 children 列表中移除
687
702
  // remove from its parent's children list
@@ -2,7 +2,7 @@
2
2
  /* eslint-disable jsdoc/require-param */
3
3
  import type { BaseStyleProps } from '@antv/g';
4
4
  import { Group } from '@antv/g';
5
- import { groupBy, isEmpty, isString } from '@antv/util';
5
+ import { groupBy } from '@antv/util';
6
6
  import { AnimationType, COMBO_KEY, ChangeType, GraphEvent } from '../constants';
7
7
  import { ELEMENT_TYPES } from '../constants/element';
8
8
  import { getExtension } from '../registry';
@@ -80,9 +80,11 @@ export class ElementController {
80
80
  const userDefinedType = options[elementType]?.type || datum.type;
81
81
 
82
82
  if (!userDefinedType) {
83
- return { node: 'circle', edge: 'line', combo: 'circle' }[elementType];
83
+ if (elementType === 'edge') return 'line';
84
+ // node / combo
85
+ else return 'circle';
84
86
  }
85
- if (isString(userDefinedType)) return userDefinedType;
87
+ if (typeof userDefinedType === 'string') return userDefinedType;
86
88
  return userDefinedType(datum as any);
87
89
  }
88
90
 
@@ -112,7 +114,7 @@ export class ElementController {
112
114
  parsePalette(this.getTheme(elementType)?.palette),
113
115
  parsePalette(options[elementType]?.palette),
114
116
  );
115
- if (!isEmpty(palette) && palette?.field) {
117
+ if (palette?.field) {
116
118
  Object.assign(this.paletteStyle, assignColorByPalette(elementData, palette));
117
119
  }
118
120
  });
@@ -141,11 +143,13 @@ export class ElementController {
141
143
 
142
144
  private computeElementsDefaultStyle(ids?: ID[]) {
143
145
  this.forEachElementData((elementType, elementData) => {
144
- elementData
145
- .filter((datum) => ids === undefined || ids.includes(idOf(datum)))
146
- .forEach((datum) => {
146
+ const length = elementData.length;
147
+ for (let i = 0; i < length; i++) {
148
+ const datum = elementData[i];
149
+ if (ids === undefined || ids.includes(idOf(datum))) {
147
150
  this.computeElementDefaultStyle(elementType, { datum });
148
- });
151
+ }
152
+ }
149
153
  });
150
154
  }
151
155
 
@@ -195,12 +199,14 @@ export class ElementController {
195
199
  */
196
200
  private computeElementsStatesStyle(ids?: ID[]) {
197
201
  this.forEachElementData((elementType, elementData) => {
198
- elementData
199
- .filter((datum) => ids === undefined || ids.includes(idOf(datum)))
200
- .forEach((datum) => {
202
+ const length = elementData.length;
203
+ for (let i = 0; i < length; i++) {
204
+ const datum = elementData[i];
205
+ if (ids === undefined || ids.includes(idOf(datum))) {
201
206
  const states = this.getElementState(idOf(datum));
202
207
  this.computeElementStatesStyle(elementType, states, { datum });
203
- });
208
+ }
209
+ }
204
210
  });
205
211
  }
206
212
 
@@ -449,7 +455,6 @@ export class ElementController {
449
455
  if (exactStage === 'show') updateStyle(element, { visibility: 'visible' });
450
456
  }
451
457
  },
452
- afterAnimate: () => {},
453
458
  after: () => {
454
459
  if (stage === 'collapse') updateStyle(element, style);
455
460
  if (exactStage === 'hide') updateStyle(element, { visibility: getCachedStyle(element, 'visibility') });
@@ -872,6 +872,7 @@ export class Graph extends EventEmitter {
872
872
  public async draw(): Promise<void> {
873
873
  await this.prepare();
874
874
  await this.context.element!.draw()?.finished;
875
+ await this.autoFit();
875
876
  }
876
877
 
877
878
  /**
package/src/types/node.ts CHANGED
@@ -44,6 +44,18 @@ export interface NodeLabelStyleProps extends LabelStyleProps {
44
44
  * @defaultValue '200%'
45
45
  */
46
46
  maxWidth?: string | number;
47
+ /**
48
+ * <zh/> 标签在 x 轴方向上的偏移量
49
+ *
50
+ * <en/> The offset of the label in the x-axis direction
51
+ */
52
+ offsetX?: number;
53
+ /**
54
+ * <zh/> 标签在 y 轴方向上的偏移量
55
+ *
56
+ * <en/> The offset of the label in the y-axis direction
57
+ */
58
+ offsetY?: number;
47
59
  }
48
60
 
49
61
  /**
package/src/utils/id.ts CHANGED
@@ -1,7 +1,5 @@
1
- import { isNumber, isString } from '@antv/util';
2
1
  import type { ComboData, EdgeData, GraphData, NodeData } from '../spec';
3
2
  import type { DataID, ID } from '../types';
4
- import { isEdgeData } from './is';
5
3
 
6
4
  /**
7
5
  * <zh/> 获取节点/边/Combo 的 ID
@@ -11,8 +9,8 @@ import { isEdgeData } from './is';
11
9
  * @returns <zh/> 节点/边/Combo 的 ID | <en/> ID of node/edge/combo
12
10
  */
13
11
  export function idOf(data: Partial<NodeData | EdgeData | ComboData>): ID {
14
- if (isString(data.id) || isNumber(data.id)) return data.id;
15
- if (isEdgeData(data)) return `${data.source}-${data.target}`;
12
+ if (data.id !== undefined) return data.id;
13
+ if (data.source !== undefined && data.target !== undefined) return `${data.source}-${data.target}`;
16
14
 
17
15
  throw new Error('The data does not have available id.');
18
16
  }