@antv/g6 5.0.10 → 5.0.12

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 (217) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/dist/lib/behaviors/drag-canvas.d.ts +1 -0
  3. package/dist/lib/behaviors/fix-element-size.d.ts +6 -0
  4. package/dist/lib/elements/nodes/base-node.d.ts +1 -0
  5. package/dist/lib/elements/nodes/image.d.ts +4 -2
  6. package/dist/lib/elements/shapes/icon.d.ts +2 -1
  7. package/dist/lib/elements/shapes/image.d.ts +38 -0
  8. package/dist/lib/elements/shapes/index.d.ts +2 -0
  9. package/dist/lib/exports.d.ts +4 -3
  10. package/dist/lib/plugins/index.d.ts +2 -0
  11. package/dist/lib/plugins/minimap/index.d.ts +131 -0
  12. package/dist/lib/registry/build-in.d.ts +4 -4
  13. package/dist/lib/registry/get.d.ts +22 -0
  14. package/dist/lib/registry/{index.d.ts → register.d.ts} +1 -26
  15. package/dist/lib/registry/store.d.ts +7 -0
  16. package/dist/lib/runtime/element.d.ts +3 -1
  17. package/dist/lib/runtime/graph.d.ts +5 -5
  18. package/dist/lib/utils/animation.d.ts +1 -1
  19. package/dist/lib/utils/event/events.d.ts +4 -4
  20. package/dist/lib/utils/shape.d.ts +9 -1
  21. package/dist/lib/version.d.ts +1 -1
  22. package/esm/behaviors/drag-canvas.d.ts +1 -0
  23. package/esm/behaviors/drag-canvas.js +18 -13
  24. package/esm/behaviors/drag-canvas.js.map +1 -1
  25. package/esm/behaviors/fix-element-size.d.ts +6 -0
  26. package/esm/behaviors/fix-element-size.js +10 -4
  27. package/esm/behaviors/fix-element-size.js.map +1 -1
  28. package/esm/behaviors/hover-activate.js +5 -1
  29. package/esm/behaviors/hover-activate.js.map +1 -1
  30. package/esm/behaviors/zoom-canvas.js +8 -11
  31. package/esm/behaviors/zoom-canvas.js.map +1 -1
  32. package/esm/elements/combos/base-combo.js +3 -0
  33. package/esm/elements/combos/base-combo.js.map +1 -1
  34. package/esm/elements/nodes/base-node.d.ts +1 -0
  35. package/esm/elements/nodes/base-node.js +34 -2
  36. package/esm/elements/nodes/base-node.js.map +1 -1
  37. package/esm/elements/nodes/image.d.ts +4 -2
  38. package/esm/elements/nodes/image.js +12 -2
  39. package/esm/elements/nodes/image.js.map +1 -1
  40. package/esm/elements/shapes/base-shape.js +0 -1
  41. package/esm/elements/shapes/base-shape.js.map +1 -1
  42. package/esm/elements/shapes/icon.d.ts +2 -1
  43. package/esm/elements/shapes/icon.js +2 -1
  44. package/esm/elements/shapes/icon.js.map +1 -1
  45. package/esm/elements/shapes/image.d.ts +38 -0
  46. package/esm/elements/shapes/image.js +75 -0
  47. package/esm/elements/shapes/image.js.map +1 -0
  48. package/esm/elements/shapes/index.d.ts +2 -0
  49. package/esm/elements/shapes/index.js +1 -0
  50. package/esm/elements/shapes/index.js.map +1 -1
  51. package/esm/exports.d.ts +4 -3
  52. package/esm/exports.js +3 -2
  53. package/esm/exports.js.map +1 -1
  54. package/esm/plugins/index.d.ts +2 -0
  55. package/esm/plugins/index.js +1 -0
  56. package/esm/plugins/index.js.map +1 -1
  57. package/esm/plugins/minimap/index.d.ts +131 -0
  58. package/esm/plugins/minimap/index.js +351 -0
  59. package/esm/plugins/minimap/index.js.map +1 -0
  60. package/esm/preset.js +1 -1
  61. package/esm/preset.js.map +1 -1
  62. package/esm/registry/build-in.d.ts +4 -4
  63. package/esm/registry/build-in.js +16 -2
  64. package/esm/registry/build-in.js.map +1 -1
  65. package/esm/registry/extension/index.js +1 -1
  66. package/esm/registry/extension/index.js.map +1 -1
  67. package/esm/registry/get.d.ts +22 -0
  68. package/esm/registry/get.js +29 -0
  69. package/esm/registry/get.js.map +1 -0
  70. package/esm/registry/{index.d.ts → register.d.ts} +1 -26
  71. package/esm/registry/{index.js → register.js} +2 -58
  72. package/esm/registry/register.js.map +1 -0
  73. package/esm/registry/store.d.ts +7 -0
  74. package/esm/registry/store.js +18 -0
  75. package/esm/registry/store.js.map +1 -0
  76. package/esm/runtime/canvas.js +8 -1
  77. package/esm/runtime/canvas.js.map +1 -1
  78. package/esm/runtime/element.d.ts +3 -1
  79. package/esm/runtime/element.js +5 -3
  80. package/esm/runtime/element.js.map +1 -1
  81. package/esm/runtime/graph.d.ts +5 -5
  82. package/esm/runtime/graph.js +6 -6
  83. package/esm/runtime/graph.js.map +1 -1
  84. package/esm/runtime/layout.js +1 -1
  85. package/esm/runtime/layout.js.map +1 -1
  86. package/esm/themes/base.js +2 -0
  87. package/esm/themes/base.js.map +1 -1
  88. package/esm/utils/animation.d.ts +1 -1
  89. package/esm/utils/animation.js +1 -1
  90. package/esm/utils/animation.js.map +1 -1
  91. package/esm/utils/event/events.d.ts +4 -4
  92. package/esm/utils/palette.js +1 -1
  93. package/esm/utils/palette.js.map +1 -1
  94. package/esm/utils/print.js +2 -0
  95. package/esm/utils/print.js.map +1 -1
  96. package/esm/utils/shape.d.ts +9 -1
  97. package/esm/utils/shape.js +17 -1
  98. package/esm/utils/shape.js.map +1 -1
  99. package/esm/utils/theme.js +1 -1
  100. package/esm/utils/theme.js.map +1 -1
  101. package/esm/version.d.ts +1 -1
  102. package/esm/version.js +1 -1
  103. package/lib/behaviors/drag-canvas.d.ts +1 -0
  104. package/lib/behaviors/drag-canvas.js +17 -12
  105. package/lib/behaviors/drag-canvas.js.map +1 -1
  106. package/lib/behaviors/fix-element-size.d.ts +6 -0
  107. package/lib/behaviors/fix-element-size.js +10 -4
  108. package/lib/behaviors/fix-element-size.js.map +1 -1
  109. package/lib/behaviors/hover-activate.js +5 -1
  110. package/lib/behaviors/hover-activate.js.map +1 -1
  111. package/lib/behaviors/zoom-canvas.js +7 -10
  112. package/lib/behaviors/zoom-canvas.js.map +1 -1
  113. package/lib/elements/combos/base-combo.js +3 -0
  114. package/lib/elements/combos/base-combo.js.map +1 -1
  115. package/lib/elements/nodes/base-node.d.ts +1 -0
  116. package/lib/elements/nodes/base-node.js +34 -2
  117. package/lib/elements/nodes/base-node.js.map +1 -1
  118. package/lib/elements/nodes/image.d.ts +4 -2
  119. package/lib/elements/nodes/image.js +11 -1
  120. package/lib/elements/nodes/image.js.map +1 -1
  121. package/lib/elements/shapes/base-shape.js +0 -1
  122. package/lib/elements/shapes/base-shape.js.map +1 -1
  123. package/lib/elements/shapes/icon.d.ts +2 -1
  124. package/lib/elements/shapes/icon.js +2 -1
  125. package/lib/elements/shapes/icon.js.map +1 -1
  126. package/lib/elements/shapes/image.d.ts +38 -0
  127. package/lib/elements/shapes/image.js +81 -0
  128. package/lib/elements/shapes/image.js.map +1 -0
  129. package/lib/elements/shapes/index.d.ts +2 -0
  130. package/lib/elements/shapes/index.js +3 -1
  131. package/lib/elements/shapes/index.js.map +1 -1
  132. package/lib/exports.d.ts +4 -3
  133. package/lib/exports.js +7 -5
  134. package/lib/exports.js.map +1 -1
  135. package/lib/plugins/index.d.ts +2 -0
  136. package/lib/plugins/index.js +3 -1
  137. package/lib/plugins/index.js.map +1 -1
  138. package/lib/plugins/minimap/index.d.ts +131 -0
  139. package/lib/plugins/minimap/index.js +355 -0
  140. package/lib/plugins/minimap/index.js.map +1 -0
  141. package/lib/preset.js +2 -2
  142. package/lib/preset.js.map +1 -1
  143. package/lib/registry/build-in.d.ts +4 -4
  144. package/lib/registry/build-in.js +16 -2
  145. package/lib/registry/build-in.js.map +1 -1
  146. package/lib/registry/extension/index.js +2 -2
  147. package/lib/registry/extension/index.js.map +1 -1
  148. package/lib/registry/get.d.ts +22 -0
  149. package/lib/registry/get.js +33 -0
  150. package/lib/registry/get.js.map +1 -0
  151. package/lib/registry/{index.d.ts → register.d.ts} +1 -26
  152. package/lib/registry/{index.js → register.js} +4 -63
  153. package/lib/registry/register.js.map +1 -0
  154. package/lib/registry/store.d.ts +7 -0
  155. package/lib/registry/store.js +21 -0
  156. package/lib/registry/store.js.map +1 -0
  157. package/lib/runtime/canvas.js +8 -1
  158. package/lib/runtime/canvas.js.map +1 -1
  159. package/lib/runtime/element.d.ts +3 -1
  160. package/lib/runtime/element.js +6 -4
  161. package/lib/runtime/element.js.map +1 -1
  162. package/lib/runtime/graph.d.ts +5 -5
  163. package/lib/runtime/graph.js +6 -6
  164. package/lib/runtime/graph.js.map +1 -1
  165. package/lib/runtime/layout.js +3 -3
  166. package/lib/runtime/layout.js.map +1 -1
  167. package/lib/themes/base.js +2 -0
  168. package/lib/themes/base.js.map +1 -1
  169. package/lib/utils/animation.d.ts +1 -1
  170. package/lib/utils/animation.js +2 -2
  171. package/lib/utils/animation.js.map +1 -1
  172. package/lib/utils/event/events.d.ts +4 -4
  173. package/lib/utils/palette.js +3 -3
  174. package/lib/utils/palette.js.map +1 -1
  175. package/lib/utils/print.js +2 -0
  176. package/lib/utils/print.js.map +1 -1
  177. package/lib/utils/shape.d.ts +9 -1
  178. package/lib/utils/shape.js +18 -1
  179. package/lib/utils/shape.js.map +1 -1
  180. package/lib/utils/theme.js +2 -2
  181. package/lib/utils/theme.js.map +1 -1
  182. package/lib/version.d.ts +1 -1
  183. package/lib/version.js +1 -1
  184. package/package.json +8 -8
  185. package/src/behaviors/drag-canvas.ts +18 -13
  186. package/src/behaviors/fix-element-size.ts +16 -4
  187. package/src/behaviors/hover-activate.ts +8 -1
  188. package/src/behaviors/zoom-canvas.ts +8 -10
  189. package/src/elements/combos/base-combo.ts +3 -0
  190. package/src/elements/nodes/base-node.ts +39 -2
  191. package/src/elements/nodes/image.ts +14 -3
  192. package/src/elements/shapes/base-shape.ts +0 -1
  193. package/src/elements/shapes/icon.ts +3 -1
  194. package/src/elements/shapes/image.ts +88 -0
  195. package/src/elements/shapes/index.ts +2 -0
  196. package/src/exports.ts +4 -1
  197. package/src/plugins/index.ts +2 -0
  198. package/src/plugins/minimap/index.ts +514 -0
  199. package/src/preset.ts +1 -1
  200. package/src/registry/build-in.ts +19 -1
  201. package/src/registry/extension/index.ts +1 -1
  202. package/src/registry/get.ts +37 -0
  203. package/src/registry/{index.ts → register.ts} +2 -66
  204. package/src/registry/store.ts +19 -0
  205. package/src/runtime/canvas.ts +10 -1
  206. package/src/runtime/element.ts +16 -4
  207. package/src/runtime/graph.ts +6 -6
  208. package/src/runtime/layout.ts +1 -1
  209. package/src/themes/base.ts +2 -0
  210. package/src/utils/animation.ts +1 -1
  211. package/src/utils/palette.ts +1 -1
  212. package/src/utils/print.ts +2 -0
  213. package/src/utils/shape.ts +18 -1
  214. package/src/utils/theme.ts +1 -1
  215. package/src/version.ts +1 -1
  216. package/esm/registry/index.js.map +0 -1
  217. package/lib/registry/index.js.map +0 -1
@@ -69,6 +69,12 @@ export interface FixElementSizeOptions extends BaseBehaviorOptions {
69
69
  * <en/> Edge configuration for defining which edge attributes should remain fixed in size visually. By default, the lineWidth and labelFontSize attributes are fixed
70
70
  */
71
71
  edge?: FixShapeConfig | FixShapeConfig[];
72
+ /**
73
+ * <zh/> Combo 配置项,用于定义哪些属性在视觉上保持固定大小。默认整个 Combo 将被固定
74
+ *
75
+ * <en/> Combo configuration for defining which combo attributes should remain fixed in size visually. By default, the entire combo will be fixed
76
+ */
77
+ combo?: FixShapeConfig | FixShapeConfig[];
72
78
  }
73
79
 
74
80
  /**
@@ -88,7 +94,7 @@ export class FixElementSize extends BaseBehavior {
88
94
  {
89
95
  shape: (shapes: DisplayObject[]) =>
90
96
  shapes.find((shape) => shape.parentElement?.className === 'label' && shape.className === 'text')!,
91
- fields: ['fontSize'],
97
+ fields: ['fontSize', 'lineHeight'],
92
98
  },
93
99
  ],
94
100
  };
@@ -106,8 +112,14 @@ export class FixElementSize extends BaseBehavior {
106
112
  if (!this.isZoomEvent(event) || !this.validate(event)) return;
107
113
 
108
114
  const { graph, element } = this.context;
109
- const { node, edge, state } = this.options;
110
- const elementData = [...graph.getElementDataByState('node', state), ...graph.getElementDataByState('edge', state)];
115
+ const { state } = this.options;
116
+ const elementData = state
117
+ ? [
118
+ ...graph.getElementDataByState('node', state),
119
+ ...graph.getElementDataByState('edge', state),
120
+ ...graph.getElementDataByState('combo', state),
121
+ ]
122
+ : Object.values(graph.getData()).flat();
111
123
 
112
124
  if (!elementData.length) return;
113
125
 
@@ -117,7 +129,7 @@ export class FixElementSize extends BaseBehavior {
117
129
  const el = element?.getElement(id) as Element;
118
130
  const type = graph.getElementType(id);
119
131
 
120
- const config = type === 'edge' ? edge : node;
132
+ const config = this.options[type];
121
133
 
122
134
  if (!config) {
123
135
  this.elementCache.set(id, el);
@@ -155,7 +155,14 @@ export class HoverActivate extends BaseBehavior<HoverActivateOptions> {
155
155
  };
156
156
 
157
157
  private validate(event: IPointerEvent) {
158
- if (this.destroyed || this.isFrozen) return false;
158
+ if (
159
+ this.destroyed ||
160
+ this.isFrozen ||
161
+ // @ts-expect-error private property
162
+ // 避免动画冲突,在combo折叠展开过程中不触发悬停事件 | To prevent animation conflicts, hover events are disabled during combo expand/collapse actions
163
+ this.context.graph.isCollapsingExpanding
164
+ )
165
+ return false;
159
166
  const { enable } = this.options;
160
167
  if (isFunction(enable)) return enable(event);
161
168
  return !!enable;
@@ -1,4 +1,4 @@
1
- import { clamp, isArray, isFunction, isObject } from '@antv/util';
1
+ import { clamp, isFunction } from '@antv/util';
2
2
  import { CommonEvent } from '../constants';
3
3
  import type { RuntimeContext } from '../runtime/types';
4
4
  import type { IKeyboardEvent, IWheelEvent, Point, PointObject, ViewportAnimationEffectTiming } from '../types';
@@ -98,15 +98,15 @@ export class ZoomCanvas extends BaseBehavior<ZoomCanvasOptions> {
98
98
  const { trigger } = this.options;
99
99
  this.shortcut.unbindAll();
100
100
 
101
- if (isArray(trigger)) {
102
- this.preventDefault(CommonEvent.WHEEL);
101
+ if (Array.isArray(trigger)) {
102
+ this.context.canvas.getContainer()?.addEventListener(CommonEvent.WHEEL, this.preventDefault);
103
103
  this.shortcut.bind([...trigger, CommonEvent.WHEEL], (event) => {
104
104
  const { deltaX, deltaY } = event;
105
105
  this.zoom(-(deltaY ?? deltaX), event, false);
106
106
  });
107
107
  }
108
108
 
109
- if (isObject(trigger)) {
109
+ if (typeof trigger === 'object') {
110
110
  const {
111
111
  zoomIn = [],
112
112
  zoomOut = [],
@@ -170,12 +170,9 @@ export class ZoomCanvas extends BaseBehavior<ZoomCanvasOptions> {
170
170
  return !!enable;
171
171
  }
172
172
 
173
- private preventDefault(eventName: string) {
174
- const listener = (e: Event) => e.preventDefault();
175
- const container = this.context.canvas.getContainer();
176
- if (!container) return;
177
- container.addEventListener(eventName, listener);
178
- }
173
+ private preventDefault = (event: Event) => {
174
+ event.preventDefault();
175
+ };
179
176
 
180
177
  /**
181
178
  * <zh/> 销毁缩放画布
@@ -184,6 +181,7 @@ export class ZoomCanvas extends BaseBehavior<ZoomCanvasOptions> {
184
181
  */
185
182
  public destroy() {
186
183
  this.shortcut.destroy();
184
+ this.context.canvas.getContainer()?.removeEventListener(CommonEvent.WHEEL, this.preventDefault);
187
185
  super.destroy();
188
186
  }
189
187
  }
@@ -24,6 +24,7 @@ import { effect } from '../effect';
24
24
  import type { BaseNodeStyleProps } from '../nodes';
25
25
  import { BaseNode } from '../nodes';
26
26
  import { Icon, IconStyleProps } from '../shapes';
27
+ import { connectImage, dispatchPositionChange } from '../shapes/image';
27
28
 
28
29
  /**
29
30
  * <zh/> 组合通用样式配置项
@@ -156,6 +157,7 @@ export abstract class BaseCombo<S extends BaseComboStyleProps = BaseComboStylePr
156
157
  @effect((self, attributes) => self.getCollapsedMarkerStyle(attributes))
157
158
  protected drawCollapsedMarkerShape(attributes: Required<S>, container: Group): void {
158
159
  this.upsert('collapsed-marker', Icon, this.getCollapsedMarkerStyle(attributes), container);
160
+ connectImage(this);
159
161
  }
160
162
 
161
163
  protected getCollapsedMarkerStyle(attributes: Required<S>): IconStyleProps | false {
@@ -232,6 +234,7 @@ export abstract class BaseCombo<S extends BaseComboStyleProps = BaseComboStylePr
232
234
  // Sync combo position to model
233
235
  const { x, y } = comboStyle;
234
236
  this.context.model.syncComboDatum({ id: this.id, style: { x, y } });
237
+ dispatchPositionChange(this);
235
238
  }
236
239
 
237
240
  public render(attributes: Required<S>, container: Group = this) {
@@ -1,6 +1,7 @@
1
1
  import type { BaseStyleProps, CircleStyleProps, DisplayObject, DisplayObjectConfig, Group } from '@antv/g';
2
2
  import { Circle as GCircle } from '@antv/g';
3
3
  import type { CategoricalPalette } from '../../palettes/types';
4
+ import type { RuntimeContext } from '../../runtime/types';
4
5
  import type { NodeData } from '../../spec';
5
6
  import type {
6
7
  BaseElementStyleProps,
@@ -24,10 +25,12 @@ import { omitStyleProps, subObject, subStyleProps } from '../../utils/prefix';
24
25
  import { parseSize } from '../../utils/size';
25
26
  import { mergeOptions } from '../../utils/style';
26
27
  import { getWordWrapWidthByBox } from '../../utils/text';
28
+ import { setVisibility } from '../../utils/visibility';
27
29
  import { BaseElement } from '../base-element';
28
30
  import { effect } from '../effect';
29
31
  import type { BadgeStyleProps, IconStyleProps, LabelStyleProps } from '../shapes';
30
32
  import { Badge, Icon, Label } from '../shapes';
33
+ import { connectImage, dispatchPositionChange } from '../shapes/image';
31
34
 
32
35
  /**
33
36
  * <zh/> 节点通用样式配置项
@@ -328,8 +331,8 @@ export abstract class BaseNode<S extends BaseNodeStyleProps = BaseNodeStyleProps
328
331
 
329
332
  protected getPortXY(attributes: Required<S>, style: NodePortStyleProps): Point {
330
333
  const { placement = 'left' } = style;
331
- const bounds = this.getShape('key').getLocalBounds();
332
- return getPortXYByPlacement(bounds, placement as PortPlacement);
334
+ const keyShape = this.getShape('key');
335
+ return getPortXYByPlacement(getBoundsInOffscreen(this.context, keyShape), placement as PortPlacement);
333
336
  }
334
337
 
335
338
  /**
@@ -372,6 +375,7 @@ export abstract class BaseNode<S extends BaseNodeStyleProps = BaseNodeStyleProps
372
375
  @effect((self, attributes) => self.getIconStyle(attributes))
373
376
  protected drawIconShape(attributes: Required<S>, container: Group): void {
374
377
  this.upsert('icon', Icon, this.getIconStyle(attributes), container);
378
+ connectImage(this);
375
379
  }
376
380
 
377
381
  @effect((self, attributes) => self.getBadgesStyle(attributes))
@@ -385,6 +389,7 @@ export abstract class BaseNode<S extends BaseNodeStyleProps = BaseNodeStyleProps
385
389
  @effect((self, attributes) => self.getPortsStyle(attributes))
386
390
  protected drawPortShapes(attributes: Required<S>, container: Group): void {
387
391
  const portsStyle = this.getPortsStyle(attributes);
392
+
388
393
  Object.keys(portsStyle).forEach((key) => {
389
394
  this.upsert(`port-${key}`, GCircle, portsStyle[key] as CircleStyleProps, container);
390
395
  });
@@ -424,8 +429,40 @@ export abstract class BaseNode<S extends BaseNodeStyleProps = BaseNodeStyleProps
424
429
  this.drawPortShapes(attributes, container);
425
430
  }
426
431
 
432
+ public update(attr?: Partial<S>): void {
433
+ super.update(attr);
434
+ if (attr && ('x' in attr || 'y' in attr || 'z' in attr)) {
435
+ dispatchPositionChange(this);
436
+ }
437
+ }
438
+
427
439
  protected onframe() {
428
440
  this.drawBadgeShapes(this.parsedAttributes, this);
429
441
  this.drawLabelShape(this.parsedAttributes, this);
430
442
  }
431
443
  }
444
+
445
+ /**
446
+ * <zh/> 在离屏画布中获取图形包围盒
447
+ *
448
+ * <en/> Get the bounding box of the graphic in the off-screen canvas
449
+ * @param context - <zh/> 运行时上下文 <en/> Runtime context
450
+ * @param shape - <zh/> 图形实例 <en/> Graphic instance
451
+ * @returns <zh/> 图形包围盒 <en/> Graphic bounding box
452
+ */
453
+ function getBoundsInOffscreen(context: RuntimeContext, shape: DisplayObject) {
454
+ if (!context) return shape.getLocalBounds();
455
+
456
+ // 将主图形靠背至全局空间,避免受到父级 transform 的影响
457
+ // 合理的操作应该是靠背至离屏画布,但目前 G 有点问题
458
+ // Move the main graphic to the global space to avoid being affected by the parent transform
459
+ // The reasonable operation should be moved to the off-screen canvas, but there is a problem with G at present
460
+ const canvas = context.canvas.getLayer();
461
+ const substitute = shape.cloneNode();
462
+ setVisibility(substitute, 'hidden');
463
+ canvas.appendChild(substitute);
464
+ const bounds = substitute.getLocalBounds();
465
+ canvas.removeChild(substitute);
466
+
467
+ return bounds;
468
+ }
@@ -1,10 +1,12 @@
1
1
  import type { DisplayObjectConfig, RectStyleProps as GRectStyleProps, Group } from '@antv/g';
2
- import { Image as GImage, ImageStyleProps as GImageStyleProps, Rect as GRect } from '@antv/g';
2
+ import { ImageStyleProps as GImageStyleProps, Rect as GRect } from '@antv/g';
3
3
  import { ICON_SIZE_RATIO } from '../../constants/element';
4
4
  import { subStyleProps } from '../../utils/prefix';
5
5
  import { mergeOptions } from '../../utils/style';
6
6
  import { add } from '../../utils/vector';
7
7
  import type { IconStyleProps } from '../shapes';
8
+ import { Image as ImageShape } from '../shapes';
9
+ import { connectImage, dispatchPositionChange } from '../shapes/image';
8
10
  import type { BaseNodeStyleProps } from './base-node';
9
11
  import { BaseNode } from './base-node';
10
12
 
@@ -79,11 +81,20 @@ export class Image extends BaseNode<ImageStyleProps> {
79
81
  : false;
80
82
  }
81
83
 
82
- protected drawKeyShape(attributes: Required<ImageStyleProps>, container: Group): GImage | undefined {
83
- return this.upsert('key', GImage, this.getKeyStyle(attributes), container);
84
+ protected drawKeyShape(attributes: Required<ImageStyleProps>, container: Group): ImageShape | undefined {
85
+ const image = this.upsert('key', ImageShape, this.getKeyStyle(attributes), container);
86
+ connectImage(this);
87
+ return image;
84
88
  }
85
89
 
86
90
  protected drawHaloShape(attributes: Required<ImageStyleProps>, container: Group): void {
87
91
  this.upsert('halo', GRect, this.getHaloStyle(attributes), container);
88
92
  }
93
+
94
+ public update(attr?: Partial<ImageStyleProps>): void {
95
+ super.update(attr);
96
+ if (attr && ('x' in attr || 'y' in attr || 'z' in attr)) {
97
+ dispatchPositionChange(this);
98
+ }
99
+ }
89
100
  }
@@ -236,7 +236,6 @@ export abstract class BaseShape<StyleProps extends BaseShapeStyleProps> extends
236
236
  * @description see: https://github.com/antvis/G/issues/1731
237
237
  */
238
238
  function releaseAnimation(target: DisplayObject, animation: IAnimation) {
239
- animation.oncancel = () => console.log('cancel');
240
239
  animation?.finished.then(() => {
241
240
  // @ts-expect-error private property
242
241
  const index = target.activeAnimations.findIndex((_) => _ === animation);
@@ -1,6 +1,8 @@
1
- import { DisplayObjectConfig, Image as GImage, Text as GText, Group, ImageStyleProps, TextStyleProps } from '@antv/g';
1
+ import { DisplayObjectConfig, Text as GText, Group, TextStyleProps } from '@antv/g';
2
2
  import type { BaseShapeStyleProps } from './base-shape';
3
3
  import { BaseShape } from './base-shape';
4
+ import type { ImageStyleProps } from './image';
5
+ import { Image as GImage } from './image';
4
6
 
5
7
  /**
6
8
  * <zh/> 图标样式
@@ -0,0 +1,88 @@
1
+ import type { DisplayObject, DisplayObjectConfig, ImageStyleProps as GImageStyleProps } from '@antv/g';
2
+ import { ElementEvent, Image as GImage, Rect as GRect } from '@antv/g';
3
+ import { getAncestorShapes } from '../../utils/shape';
4
+
5
+ export interface ImageStyleProps extends GImageStyleProps {
6
+ /**
7
+ * <zh/> 圆角半径
8
+ *
9
+ * <en/> Radius of the rounded corner
10
+ */
11
+ radius?: number | number[];
12
+ }
13
+
14
+ export class Image extends GImage {
15
+ constructor(options: DisplayObjectConfig<ImageStyleProps>) {
16
+ super(options);
17
+ current = this;
18
+ this.isMutationObserved = true;
19
+ this.addEventListener(ElementEvent.MOUNTED, this.onMounted);
20
+ this.addEventListener(ElementEvent.ATTR_MODIFIED, this.onAttrModified);
21
+ }
22
+
23
+ private onMounted = () => {
24
+ this.handleRadius();
25
+ };
26
+
27
+ private onAttrModified = () => {
28
+ this.handleRadius();
29
+ };
30
+
31
+ public handleRadius() {
32
+ const { radius, clipPath, width = 0, height = 0 } = this.attributes as ImageStyleProps;
33
+
34
+ if (radius && width && height) {
35
+ const [x, y] = this.getBounds().min;
36
+ const clipPathStyle = { x, y, radius, width, height };
37
+
38
+ if (clipPath) {
39
+ Object.assign(this.parsedStyle.clipPath!.style, clipPathStyle);
40
+ } else {
41
+ const rect = new GRect({ style: clipPathStyle });
42
+ this.style.clipPath = rect;
43
+ }
44
+ } else {
45
+ if (clipPath) this.style.clipPath = null;
46
+ }
47
+ }
48
+ }
49
+
50
+ const ImagesWeakMap = new WeakMap<DisplayObject, Image[]>();
51
+
52
+ let current: Image | null = null;
53
+
54
+ /**
55
+ * <zh/> 由于 g clipPath 不支持相对位置,因此当作用的元素发生位置变化时,需要通知 Image 更新 clipPath。
56
+ *
57
+ * 通过 connectImage 创建图形与图片的关联,并结合 dispatchPositionChange 方法触发更新
58
+ *
59
+ * ⚠️ 这是一种临时的、黑盒的解决方案,如果后续 g 支持相对位置,会移除该方法。
60
+ *
61
+ * <en/> Since g clipPath does not support relative positions, when the position of the affected element changes, the Image needs to be notified to update the clipPath.
62
+ *
63
+ * Use connectImage to create an association between the shape and the image, and combine it with the dispatchPositionChange method to trigger the update.
64
+ *
65
+ * ⚠️ This is a temporary, black-box solution, and if g supports relative positions in the future, this method will be removed.
66
+ * @param target - <zh/> 目标元素 <en/> Target element
67
+ */
68
+ export const connectImage = (target: DisplayObject) => {
69
+ if (current && getAncestorShapes(current).includes(target)) {
70
+ const images = ImagesWeakMap.get(target);
71
+ if (images) {
72
+ if (!images.includes(current)) images.push(current);
73
+ } else ImagesWeakMap.set(target, [current]);
74
+ }
75
+ };
76
+
77
+ /**
78
+ * <zh/> 触发关联的图片更新位置
79
+ *
80
+ * <en/> Trigger the associated image to update its position
81
+ * @param target - <zh/> 目标元素 <en/> Target element
82
+ */
83
+ export const dispatchPositionChange = (target: DisplayObject) => {
84
+ const image = ImagesWeakMap.get(target);
85
+ if (image) {
86
+ image.forEach((i) => i.handleRadius());
87
+ }
88
+ };
@@ -8,11 +8,13 @@ export { Badge } from './badge';
8
8
  export { BaseShape } from './base-shape';
9
9
  export { Contour } from './contour';
10
10
  export { Icon } from './icon';
11
+ export { Image } from './image';
11
12
  export { Label } from './label';
12
13
 
13
14
  export type { BadgeStyleProps } from './badge';
14
15
  export type { BaseShapeStyleProps } from './base-shape';
15
16
  export type { ContourStyleProps } from './contour';
16
17
  export type { IconStyleProps } from './icon';
18
+ export type { ImageStyleProps } from './image';
17
19
  export type { LabelStyleProps } from './label';
18
20
  export type { PolygonStyleProps } from './polygon';
package/src/exports.ts CHANGED
@@ -72,12 +72,14 @@ export {
72
72
  History,
73
73
  Hull,
74
74
  Legend,
75
+ Minimap,
75
76
  Timebar,
76
77
  Toolbar,
77
78
  Tooltip,
78
79
  Watermark,
79
80
  } from './plugins';
80
- export { getExtension, getExtensions, register } from './registry';
81
+ export { getExtension, getExtensions } from './registry/get';
82
+ export { register } from './registry/register';
81
83
  export { Graph } from './runtime/graph';
82
84
  export { BaseTransform } from './transforms';
83
85
  export { isCollapsed } from './utils/collapsibility';
@@ -168,6 +170,7 @@ export type {
168
170
  HistoryOptions,
169
171
  HullOptions,
170
172
  LegendOptions,
173
+ MinimapOptions,
171
174
  TimebarOptions,
172
175
  ToolbarOptions,
173
176
  TooltipOptions,
@@ -8,6 +8,7 @@ export { GridLine } from './grid-line';
8
8
  export { History } from './history';
9
9
  export { Hull } from './hull';
10
10
  export { Legend } from './legend';
11
+ export { Minimap } from './minimap';
11
12
  export { Timebar } from './timebar';
12
13
  export { Toolbar } from './toolbar';
13
14
  export { Tooltip } from './tooltip';
@@ -23,6 +24,7 @@ export type { GridLineOptions } from './grid-line';
23
24
  export type { HistoryOptions } from './history';
24
25
  export type { HullOptions } from './hull';
25
26
  export type { LegendOptions } from './legend';
27
+ export type { MinimapOptions } from './minimap';
26
28
  export type { TimebarOptions } from './timebar';
27
29
  export type { ToolbarOptions } from './toolbar';
28
30
  export type { TooltipOptions } from './tooltip';