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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (282) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/dist/lib/behaviors/brush-select.d.ts +2 -3
  3. package/dist/lib/behaviors/collapse-expand.d.ts +1 -2
  4. package/dist/lib/behaviors/create-edge.d.ts +1 -2
  5. package/dist/lib/behaviors/drag-element-force.d.ts +1 -2
  6. package/dist/lib/behaviors/drag-element.d.ts +2 -3
  7. package/dist/lib/behaviors/lasso-select.d.ts +2 -3
  8. package/dist/lib/constants/events/animation.d.ts +1 -4
  9. package/dist/lib/elements/nodes/base-node.d.ts +2 -3
  10. package/dist/lib/elements/nodes/donut.d.ts +45 -0
  11. package/dist/lib/elements/nodes/html.d.ts +27 -0
  12. package/dist/lib/elements/nodes/index.d.ts +4 -0
  13. package/dist/lib/exports.d.ts +4 -3
  14. package/dist/lib/plugins/hull/index.d.ts +1 -2
  15. package/dist/lib/runtime/data.d.ts +4 -4
  16. package/dist/lib/runtime/element.d.ts +3 -3
  17. package/dist/lib/runtime/graph.d.ts +2 -3
  18. package/dist/lib/runtime/viewport.d.ts +1 -2
  19. package/dist/lib/spec/data.d.ts +74 -1
  20. package/dist/lib/spec/element/combo.d.ts +17 -6
  21. package/dist/lib/spec/element/edge.d.ts +14 -2
  22. package/dist/lib/spec/element/node.d.ts +19 -3
  23. package/dist/lib/themes/base.d.ts +1 -0
  24. package/dist/lib/transforms/process-parallel-edges.d.ts +1 -2
  25. package/dist/lib/transforms/types.d.ts +1 -1
  26. package/dist/lib/types/callable.d.ts +2 -2
  27. package/dist/lib/types/data.d.ts +1 -1
  28. package/dist/lib/types/id.d.ts +1 -0
  29. package/dist/lib/types/index.d.ts +1 -0
  30. package/dist/lib/types/style.d.ts +1 -3
  31. package/dist/lib/utils/animation.d.ts +1 -1
  32. package/dist/lib/utils/behaviors/brush.d.ts +1 -2
  33. package/dist/lib/utils/behaviors/lasso.d.ts +1 -2
  34. package/dist/lib/utils/behaviors/utils.d.ts +1 -1
  35. package/dist/lib/utils/edge.d.ts +1 -2
  36. package/dist/lib/utils/id.d.ts +2 -3
  37. package/dist/lib/utils/palette.d.ts +1 -2
  38. package/dist/lib/utils/relation.d.ts +1 -2
  39. package/esm/behaviors/brush-select.d.ts +2 -3
  40. package/esm/behaviors/brush-select.js.map +1 -1
  41. package/esm/behaviors/click-element.js.map +1 -1
  42. package/esm/behaviors/collapse-expand.d.ts +1 -2
  43. package/esm/behaviors/collapse-expand.js.map +1 -1
  44. package/esm/behaviors/create-edge.d.ts +1 -2
  45. package/esm/behaviors/create-edge.js.map +1 -1
  46. package/esm/behaviors/drag-element-force.d.ts +1 -2
  47. package/esm/behaviors/drag-element-force.js.map +1 -1
  48. package/esm/behaviors/drag-element.d.ts +2 -3
  49. package/esm/behaviors/drag-element.js.map +1 -1
  50. package/esm/behaviors/focus-element.js.map +1 -1
  51. package/esm/behaviors/hover-element.js.map +1 -1
  52. package/esm/behaviors/lasso-select.d.ts +2 -3
  53. package/esm/behaviors/lasso-select.js.map +1 -1
  54. package/esm/constants/events/animation.d.ts +1 -4
  55. package/esm/constants/events/animation.js +0 -4
  56. package/esm/constants/events/animation.js.map +1 -1
  57. package/esm/elements/nodes/base-node.d.ts +2 -3
  58. package/esm/elements/nodes/base-node.js.map +1 -1
  59. package/esm/elements/nodes/donut.d.ts +45 -0
  60. package/esm/elements/nodes/donut.js +81 -0
  61. package/esm/elements/nodes/donut.js.map +1 -0
  62. package/esm/elements/nodes/html.d.ts +27 -0
  63. package/esm/elements/nodes/html.js +209 -0
  64. package/esm/elements/nodes/html.js.map +1 -0
  65. package/esm/elements/nodes/index.d.ts +4 -0
  66. package/esm/elements/nodes/index.js +2 -0
  67. package/esm/elements/nodes/index.js.map +1 -1
  68. package/esm/exports.d.ts +4 -3
  69. package/esm/exports.js +2 -1
  70. package/esm/exports.js.map +1 -1
  71. package/esm/plugins/hull/index.d.ts +1 -2
  72. package/esm/plugins/hull/index.js.map +1 -1
  73. package/esm/plugins/legend.js +3 -2
  74. package/esm/plugins/legend.js.map +1 -1
  75. package/esm/registry/build-in.js +5 -3
  76. package/esm/registry/build-in.js.map +1 -1
  77. package/esm/runtime/canvas.js +5 -2
  78. package/esm/runtime/canvas.js.map +1 -1
  79. package/esm/runtime/data.d.ts +4 -4
  80. package/esm/runtime/data.js.map +1 -1
  81. package/esm/runtime/element.d.ts +3 -3
  82. package/esm/runtime/element.js +59 -42
  83. package/esm/runtime/element.js.map +1 -1
  84. package/esm/runtime/graph.d.ts +2 -3
  85. package/esm/runtime/graph.js +11 -9
  86. package/esm/runtime/graph.js.map +1 -1
  87. package/esm/runtime/layout.js +2 -2
  88. package/esm/runtime/layout.js.map +1 -1
  89. package/esm/runtime/viewport.d.ts +1 -2
  90. package/esm/runtime/viewport.js.map +1 -1
  91. package/esm/spec/data.d.ts +74 -1
  92. package/esm/spec/element/combo.d.ts +17 -6
  93. package/esm/spec/element/edge.d.ts +14 -2
  94. package/esm/spec/element/node.d.ts +19 -3
  95. package/esm/themes/base.d.ts +1 -0
  96. package/esm/themes/base.js +2 -0
  97. package/esm/themes/base.js.map +1 -1
  98. package/esm/transforms/process-parallel-edges.d.ts +1 -2
  99. package/esm/transforms/process-parallel-edges.js +2 -4
  100. package/esm/transforms/process-parallel-edges.js.map +1 -1
  101. package/esm/transforms/types.d.ts +1 -1
  102. package/esm/transforms/update-related-edge.js.map +1 -1
  103. package/esm/types/callable.d.ts +2 -2
  104. package/esm/types/data.d.ts +1 -1
  105. package/esm/types/id.d.ts +1 -0
  106. package/esm/types/id.js +2 -0
  107. package/esm/types/id.js.map +1 -0
  108. package/esm/types/index.d.ts +1 -0
  109. package/esm/types/style.d.ts +1 -3
  110. package/esm/utils/animation.d.ts +1 -1
  111. package/esm/utils/animation.js +1 -1
  112. package/esm/utils/animation.js.map +1 -1
  113. package/esm/utils/behaviors/brush.d.ts +1 -2
  114. package/esm/utils/behaviors/brush.js.map +1 -1
  115. package/esm/utils/behaviors/lasso.d.ts +1 -2
  116. package/esm/utils/behaviors/lasso.js.map +1 -1
  117. package/esm/utils/behaviors/utils.d.ts +1 -1
  118. package/esm/utils/change.js.map +1 -1
  119. package/esm/utils/edge.d.ts +1 -2
  120. package/esm/utils/edge.js.map +1 -1
  121. package/esm/utils/id.d.ts +2 -3
  122. package/esm/utils/id.js.map +1 -1
  123. package/esm/utils/palette.d.ts +1 -2
  124. package/esm/utils/palette.js.map +1 -1
  125. package/esm/utils/relation.d.ts +1 -2
  126. package/esm/utils/relation.js.map +1 -1
  127. package/esm/utils/style.js +3 -3
  128. package/esm/utils/style.js.map +1 -1
  129. package/lib/behaviors/brush-select.d.ts +2 -3
  130. package/lib/behaviors/brush-select.js.map +1 -1
  131. package/lib/behaviors/click-element.js.map +1 -1
  132. package/lib/behaviors/collapse-expand.d.ts +1 -2
  133. package/lib/behaviors/collapse-expand.js.map +1 -1
  134. package/lib/behaviors/create-edge.d.ts +1 -2
  135. package/lib/behaviors/create-edge.js.map +1 -1
  136. package/lib/behaviors/drag-element-force.d.ts +1 -2
  137. package/lib/behaviors/drag-element-force.js.map +1 -1
  138. package/lib/behaviors/drag-element.d.ts +2 -3
  139. package/lib/behaviors/drag-element.js.map +1 -1
  140. package/lib/behaviors/focus-element.js.map +1 -1
  141. package/lib/behaviors/hover-element.js.map +1 -1
  142. package/lib/behaviors/lasso-select.d.ts +2 -3
  143. package/lib/behaviors/lasso-select.js.map +1 -1
  144. package/lib/constants/events/animation.d.ts +1 -4
  145. package/lib/constants/events/animation.js +0 -4
  146. package/lib/constants/events/animation.js.map +1 -1
  147. package/lib/elements/nodes/base-node.d.ts +2 -3
  148. package/lib/elements/nodes/base-node.js.map +1 -1
  149. package/lib/elements/nodes/donut.d.ts +45 -0
  150. package/lib/elements/nodes/donut.js +85 -0
  151. package/lib/elements/nodes/donut.js.map +1 -0
  152. package/lib/elements/nodes/html.d.ts +27 -0
  153. package/lib/elements/nodes/html.js +213 -0
  154. package/lib/elements/nodes/html.js.map +1 -0
  155. package/lib/elements/nodes/index.d.ts +4 -0
  156. package/lib/elements/nodes/index.js +5 -1
  157. package/lib/elements/nodes/index.js.map +1 -1
  158. package/lib/exports.d.ts +4 -3
  159. package/lib/exports.js +5 -1
  160. package/lib/exports.js.map +1 -1
  161. package/lib/plugins/hull/index.d.ts +1 -2
  162. package/lib/plugins/hull/index.js.map +1 -1
  163. package/lib/plugins/legend.js +3 -2
  164. package/lib/plugins/legend.js.map +1 -1
  165. package/lib/registry/build-in.js +4 -2
  166. package/lib/registry/build-in.js.map +1 -1
  167. package/lib/runtime/canvas.js +5 -2
  168. package/lib/runtime/canvas.js.map +1 -1
  169. package/lib/runtime/data.d.ts +4 -4
  170. package/lib/runtime/data.js.map +1 -1
  171. package/lib/runtime/element.d.ts +3 -3
  172. package/lib/runtime/element.js +58 -41
  173. package/lib/runtime/element.js.map +1 -1
  174. package/lib/runtime/graph.d.ts +2 -3
  175. package/lib/runtime/graph.js +10 -8
  176. package/lib/runtime/graph.js.map +1 -1
  177. package/lib/runtime/layout.js +2 -2
  178. package/lib/runtime/layout.js.map +1 -1
  179. package/lib/runtime/viewport.d.ts +1 -2
  180. package/lib/runtime/viewport.js.map +1 -1
  181. package/lib/spec/data.d.ts +74 -1
  182. package/lib/spec/element/combo.d.ts +17 -6
  183. package/lib/spec/element/edge.d.ts +14 -2
  184. package/lib/spec/element/node.d.ts +19 -3
  185. package/lib/themes/base.d.ts +1 -0
  186. package/lib/themes/base.js +2 -0
  187. package/lib/themes/base.js.map +1 -1
  188. package/lib/transforms/process-parallel-edges.d.ts +1 -2
  189. package/lib/transforms/process-parallel-edges.js +2 -4
  190. package/lib/transforms/process-parallel-edges.js.map +1 -1
  191. package/lib/transforms/types.d.ts +1 -1
  192. package/lib/transforms/update-related-edge.js.map +1 -1
  193. package/lib/types/callable.d.ts +2 -2
  194. package/lib/types/data.d.ts +1 -1
  195. package/lib/types/id.d.ts +1 -0
  196. package/lib/{spec/element/base.js → types/id.js} +1 -1
  197. package/lib/types/id.js.map +1 -0
  198. package/lib/types/index.d.ts +1 -0
  199. package/lib/types/style.d.ts +1 -3
  200. package/lib/utils/animation.d.ts +1 -1
  201. package/lib/utils/animation.js +1 -1
  202. package/lib/utils/animation.js.map +1 -1
  203. package/lib/utils/behaviors/brush.d.ts +1 -2
  204. package/lib/utils/behaviors/brush.js.map +1 -1
  205. package/lib/utils/behaviors/lasso.d.ts +1 -2
  206. package/lib/utils/behaviors/lasso.js.map +1 -1
  207. package/lib/utils/behaviors/utils.d.ts +1 -1
  208. package/lib/utils/change.js.map +1 -1
  209. package/lib/utils/edge.d.ts +1 -2
  210. package/lib/utils/edge.js.map +1 -1
  211. package/lib/utils/id.d.ts +2 -3
  212. package/lib/utils/id.js.map +1 -1
  213. package/lib/utils/palette.d.ts +1 -2
  214. package/lib/utils/palette.js.map +1 -1
  215. package/lib/utils/relation.d.ts +1 -2
  216. package/lib/utils/relation.js.map +1 -1
  217. package/lib/utils/style.js +3 -3
  218. package/lib/utils/style.js.map +1 -1
  219. package/package.json +1 -1
  220. package/src/behaviors/brush-select.ts +1 -2
  221. package/src/behaviors/click-element.ts +1 -2
  222. package/src/behaviors/collapse-expand.ts +1 -2
  223. package/src/behaviors/create-edge.ts +1 -2
  224. package/src/behaviors/drag-element-force.ts +1 -2
  225. package/src/behaviors/drag-element.ts +1 -2
  226. package/src/behaviors/focus-element.ts +1 -2
  227. package/src/behaviors/hover-element.ts +1 -2
  228. package/src/behaviors/lasso-select.ts +1 -2
  229. package/src/constants/events/animation.ts +0 -4
  230. package/src/elements/nodes/base-node.ts +3 -3
  231. package/src/elements/nodes/donut.ts +137 -0
  232. package/src/elements/nodes/html.ts +230 -0
  233. package/src/elements/nodes/index.ts +4 -0
  234. package/src/exports.ts +20 -1
  235. package/src/plugins/hull/index.ts +1 -2
  236. package/src/plugins/legend.ts +4 -4
  237. package/src/registry/build-in.ts +6 -2
  238. package/src/runtime/canvas.ts +5 -2
  239. package/src/runtime/data.ts +2 -1
  240. package/src/runtime/element.ts +62 -36
  241. package/src/runtime/graph.ts +13 -10
  242. package/src/runtime/layout.ts +4 -4
  243. package/src/runtime/viewport.ts +1 -2
  244. package/src/spec/data.ts +74 -1
  245. package/src/spec/element/combo.ts +17 -6
  246. package/src/spec/element/edge.ts +14 -2
  247. package/src/spec/element/node.ts +19 -3
  248. package/src/themes/base.ts +3 -0
  249. package/src/transforms/arrange-draw-order.ts +1 -1
  250. package/src/transforms/process-parallel-edges.ts +4 -6
  251. package/src/transforms/types.ts +1 -1
  252. package/src/transforms/update-related-edge.ts +1 -2
  253. package/src/types/callable.ts +2 -2
  254. package/src/types/data.ts +1 -1
  255. package/src/types/id.ts +1 -0
  256. package/src/types/index.ts +1 -0
  257. package/src/types/style.ts +1 -3
  258. package/src/utils/animation.ts +2 -2
  259. package/src/utils/behaviors/brush.ts +1 -2
  260. package/src/utils/behaviors/lasso.ts +1 -2
  261. package/src/utils/behaviors/utils.ts +1 -1
  262. package/src/utils/change.ts +1 -2
  263. package/src/utils/edge.ts +1 -1
  264. package/src/utils/id.ts +1 -2
  265. package/src/utils/palette.ts +1 -1
  266. package/src/utils/relation.ts +1 -2
  267. package/src/utils/style.ts +3 -3
  268. package/dist/lib/runtime/index.d.ts +0 -6
  269. package/dist/lib/spec/element/base.d.ts +0 -6
  270. package/esm/runtime/index.d.ts +0 -6
  271. package/esm/runtime/index.js +0 -7
  272. package/esm/runtime/index.js.map +0 -1
  273. package/esm/spec/element/base.d.ts +0 -6
  274. package/esm/spec/element/base.js +0 -2
  275. package/esm/spec/element/base.js.map +0 -1
  276. package/lib/runtime/index.d.ts +0 -6
  277. package/lib/runtime/index.js +0 -8
  278. package/lib/runtime/index.js.map +0 -1
  279. package/lib/spec/element/base.d.ts +0 -6
  280. package/lib/spec/element/base.js.map +0 -1
  281. package/src/runtime/index.ts +0 -7
  282. package/src/spec/element/base.ts +0 -6
@@ -0,0 +1,230 @@
1
+ import type {
2
+ DisplayObjectConfig,
3
+ FederatedMouseEvent,
4
+ HTMLStyleProps as GHTMLStyleProps,
5
+ Group,
6
+ ICanvas,
7
+ IEventTarget,
8
+ } from '@antv/g';
9
+ import { FederatedPointerEvent, HTML as GHTML } from '@antv/g';
10
+ import { isNil, isUndefined, pick } from '@antv/util';
11
+ import { NodeEvent } from '../../constants';
12
+ import type { BaseNodeStyleProps } from './base-node';
13
+ import { BaseNode } from './base-node';
14
+
15
+ export type HTMLStyleProps = BaseNodeStyleProps<{
16
+ innerHTML: string | HTMLElement;
17
+ }>;
18
+
19
+ /**
20
+ * @see https://github.com/antvis/G/blob/next/packages/g-lite/src/plugins/EventPlugin.ts
21
+ */
22
+ export class HTML extends BaseNode<HTMLStyleProps> {
23
+ static defaultStyleProps: Partial<HTMLStyleProps> = {
24
+ size: [160, 80],
25
+ halo: false,
26
+ icon: false,
27
+ label: false,
28
+ pointerEvents: 'auto',
29
+ };
30
+
31
+ constructor(options: DisplayObjectConfig<HTMLStyleProps>) {
32
+ super({ ...options, style: Object.assign({}, HTML.defaultStyleProps, options.style) });
33
+ }
34
+
35
+ private rootPointerEvent = new FederatedPointerEvent(null);
36
+
37
+ private get eventService() {
38
+ return this.attributes.context!.canvas.context.eventService;
39
+ }
40
+
41
+ private get events() {
42
+ return [
43
+ NodeEvent.CLICK,
44
+ NodeEvent.POINTER_DOWN,
45
+ NodeEvent.POINTER_MOVE,
46
+ NodeEvent.POINTER_UP,
47
+ NodeEvent.POINTER_OVER,
48
+ NodeEvent.POINTER_LEAVE,
49
+ ];
50
+ }
51
+
52
+ protected getDomElement() {
53
+ return this.getKey<GHTML>().getDomElement();
54
+ }
55
+
56
+ protected getKeyStyle(attributes: Required<HTMLStyleProps>): GHTMLStyleProps {
57
+ const style = pick(attributes, ['innerHTML', 'pointerEvents', 'cursor']) as unknown as HTMLStyleProps;
58
+ const [width, height] = this.getSize(attributes);
59
+ return { ...style, width, height };
60
+ }
61
+
62
+ protected drawKeyShape(attributes: Required<HTMLStyleProps>, container: Group) {
63
+ return this.upsert('key', GHTML, this.getKeyStyle(attributes), container);
64
+ }
65
+
66
+ public connectedCallback() {
67
+ const element = this.getDomElement();
68
+ this.events.forEach((eventName) => {
69
+ // @ts-expect-error assert event is PointerEvent
70
+ element.addEventListener(eventName, this.forwardEvents);
71
+ });
72
+ }
73
+
74
+ public attributeChangedCallback(name: any, oldValue: any, newValue: any) {
75
+ if (name === 'zIndex' && oldValue !== newValue) {
76
+ this.getDomElement().style.zIndex = newValue;
77
+ }
78
+ }
79
+
80
+ public onDestroy() {
81
+ const element = this.getDomElement();
82
+ this.events.forEach((eventName) => {
83
+ // @ts-expect-error assert event is PointerEvent
84
+ element.removeEventListener(eventName, this.forwardEvents);
85
+ });
86
+ }
87
+
88
+ private forwardEvents = (nativeEvent: PointerEvent) => {
89
+ const canvas = this.attributes.context!.canvas.main;
90
+ const iCanvas = canvas.context.renderingContext.root!.ownerDocument!.defaultView!;
91
+
92
+ const normalizedEvents = this.normalizeToPointerEvent(nativeEvent, iCanvas);
93
+
94
+ normalizedEvents.forEach((normalizedEvent) => {
95
+ const event = this.bootstrapEvent(this.rootPointerEvent, normalizedEvent, iCanvas, nativeEvent);
96
+ canvas.context.eventService.mapEvent(event);
97
+ });
98
+ };
99
+
100
+ private normalizeToPointerEvent(event: PointerEvent, canvas: ICanvas): PointerEvent[] {
101
+ const normalizedEvents = [];
102
+ if (canvas.isTouchEvent(event)) {
103
+ for (let i = 0; i < event.changedTouches.length; i++) {
104
+ const touch = event.changedTouches[i] as any;
105
+
106
+ // use changedTouches instead of touches since touchend has no touches
107
+ // @see https://stackoverflow.com/a/10079076
108
+ if (isUndefined(touch.button)) touch.button = 0;
109
+ if (isUndefined(touch.buttons)) touch.buttons = 1;
110
+ if (isUndefined(touch.isPrimary)) {
111
+ touch.isPrimary = event.touches.length === 1 && event.type === 'touchstart';
112
+ }
113
+ if (isUndefined(touch.width)) touch.width = touch.radiusX || 1;
114
+ if (isUndefined(touch.height)) touch.height = touch.radiusY || 1;
115
+ if (isUndefined(touch.tiltX)) touch.tiltX = 0;
116
+ if (isUndefined(touch.tiltY)) touch.tiltY = 0;
117
+ if (isUndefined(touch.pointerType)) touch.pointerType = 'touch';
118
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Touch/identifier
119
+ if (isUndefined(touch.pointerId)) touch.pointerId = touch.identifier || 0;
120
+ if (isUndefined(touch.pressure)) touch.pressure = touch.force || 0.5;
121
+ if (isUndefined(touch.twist)) touch.twist = 0;
122
+ if (isUndefined(touch.tangentialPressure)) touch.tangentialPressure = 0;
123
+ touch.isNormalized = true;
124
+ touch.type = event.type;
125
+
126
+ normalizedEvents.push(touch);
127
+ }
128
+ } else if (canvas.isMouseEvent(event)) {
129
+ const tempEvent = event as any;
130
+ if (isUndefined(tempEvent.isPrimary)) tempEvent.isPrimary = true;
131
+ if (isUndefined(tempEvent.width)) tempEvent.width = 1;
132
+ if (isUndefined(tempEvent.height)) tempEvent.height = 1;
133
+ if (isUndefined(tempEvent.tiltX)) tempEvent.tiltX = 0;
134
+ if (isUndefined(tempEvent.tiltY)) tempEvent.tiltY = 0;
135
+ if (isUndefined(tempEvent.pointerType)) tempEvent.pointerType = 'mouse';
136
+ if (isUndefined(tempEvent.pointerId)) tempEvent.pointerId = 1;
137
+ if (isUndefined(tempEvent.pressure)) tempEvent.pressure = 0.5;
138
+ if (isUndefined(tempEvent.twist)) tempEvent.twist = 0;
139
+ if (isUndefined(tempEvent.tangentialPressure)) tempEvent.tangentialPressure = 0;
140
+ tempEvent.isNormalized = true;
141
+
142
+ normalizedEvents.push(tempEvent);
143
+ } else {
144
+ normalizedEvents.push(event);
145
+ }
146
+
147
+ return normalizedEvents as PointerEvent[];
148
+ }
149
+
150
+ private transferMouseData(event: FederatedMouseEvent, nativeEvent: MouseEvent): void {
151
+ event.isTrusted = nativeEvent.isTrusted;
152
+ event.srcElement = nativeEvent.srcElement as IEventTarget;
153
+ event.timeStamp = performance.now();
154
+ event.type = nativeEvent.type;
155
+
156
+ event.altKey = nativeEvent.altKey;
157
+ event.metaKey = nativeEvent.metaKey;
158
+ event.shiftKey = nativeEvent.shiftKey;
159
+ event.ctrlKey = nativeEvent.ctrlKey;
160
+ event.button = nativeEvent.button;
161
+ event.buttons = nativeEvent.buttons;
162
+ event.client.x = nativeEvent.clientX;
163
+ event.client.y = nativeEvent.clientY;
164
+ event.movement.x = nativeEvent.movementX;
165
+ event.movement.y = nativeEvent.movementY;
166
+ event.page.x = nativeEvent.pageX;
167
+ event.page.y = nativeEvent.pageY;
168
+ event.screen.x = nativeEvent.screenX;
169
+ event.screen.y = nativeEvent.screenY;
170
+ event.relatedTarget = null;
171
+ }
172
+
173
+ private bootstrapEvent(
174
+ event: FederatedPointerEvent,
175
+ normalizedEvent: PointerEvent,
176
+ view: ICanvas,
177
+ nativeEvent: PointerEvent | MouseEvent | TouchEvent,
178
+ ): FederatedPointerEvent {
179
+ event.view = view;
180
+ // @ts-ignore
181
+ event.originalEvent = null;
182
+ event.nativeEvent = nativeEvent;
183
+
184
+ event.pointerId = normalizedEvent.pointerId;
185
+ event.width = normalizedEvent.width;
186
+ event.height = normalizedEvent.height;
187
+ event.isPrimary = normalizedEvent.isPrimary;
188
+ event.pointerType = normalizedEvent.pointerType;
189
+ event.pressure = normalizedEvent.pressure;
190
+ event.tangentialPressure = normalizedEvent.tangentialPressure;
191
+ event.tiltX = normalizedEvent.tiltX;
192
+ event.tiltY = normalizedEvent.tiltY;
193
+ event.twist = normalizedEvent.twist;
194
+ this.transferMouseData(event, normalizedEvent);
195
+
196
+ const { x, y } = this.getViewportXY(normalizedEvent);
197
+ event.viewport.x = x;
198
+ event.viewport.y = y;
199
+ const { x: canvasX, y: canvasY } = this.attributes.context!.canvas.viewport2Canvas(event.viewport);
200
+ event.canvas.x = canvasX;
201
+ event.canvas.y = canvasY;
202
+ event.global.copyFrom(event.canvas);
203
+ event.offset.copyFrom(event.canvas);
204
+
205
+ event.isTrusted = nativeEvent.isTrusted;
206
+ if (event.type === 'pointerleave') {
207
+ event.type = 'pointerout';
208
+ }
209
+ return event;
210
+ }
211
+
212
+ private getViewportXY(nativeEvent: PointerEvent | WheelEvent) {
213
+ let x: number;
214
+ let y: number;
215
+ const { offsetX, offsetY, clientX, clientY } = nativeEvent;
216
+ if (
217
+ this.attributes.context?.canvas.main.context.config.supportsCSSTransform &&
218
+ !isNil(offsetX) &&
219
+ !isNil(offsetY)
220
+ ) {
221
+ x = offsetX;
222
+ y = offsetY;
223
+ } else {
224
+ const point = this.eventService.client2Viewport({ x: clientX, y: clientY });
225
+ x = point.x;
226
+ y = point.y;
227
+ }
228
+ return { x, y };
229
+ }
230
+ }
@@ -1,8 +1,10 @@
1
1
  export { BaseNode } from './base-node';
2
2
  export { Circle } from './circle';
3
3
  export { Diamond } from './diamond';
4
+ export { Donut } from './donut';
4
5
  export { Ellipse } from './ellipse';
5
6
  export { Hexagon } from './hexagon';
7
+ export { HTML } from './html';
6
8
  export { Image } from './image';
7
9
  export { Rect } from './rect';
8
10
  export { Star } from './star';
@@ -11,8 +13,10 @@ export { Triangle } from './triangle';
11
13
  export type { BaseNodeStyleProps } from './base-node';
12
14
  export type { CircleStyleProps } from './circle';
13
15
  export type { DiamondStyleProps } from './diamond';
16
+ export type { DonutStyleProps } from './donut';
14
17
  export type { EllipseStyleProps } from './ellipse';
15
18
  export type { HexagonStyleProps } from './hexagon';
19
+ export type { HTMLStyleProps } from './html';
16
20
  export type { ImageStyleProps } from './image';
17
21
  export type { RectStyleProps } from './rect';
18
22
  export type { StarStyleProps } from './star';
package/src/exports.ts CHANGED
@@ -16,13 +16,26 @@ export {
16
16
  } from './constants';
17
17
  export { BaseCombo, CircleCombo, RectCombo } from './elements/combos';
18
18
  export { BaseEdge, Cubic, CubicHorizontal, CubicVertical, Line, Polyline, Quadratic } from './elements/edges';
19
- export { BaseNode, Circle, Diamond, Ellipse, Hexagon, Image, Rect, Star, Triangle } from './elements/nodes';
19
+ export {
20
+ BaseNode,
21
+ Circle,
22
+ Diamond,
23
+ Donut,
24
+ Ellipse,
25
+ HTML,
26
+ Hexagon,
27
+ Image,
28
+ Rect,
29
+ Star,
30
+ Triangle,
31
+ } from './elements/nodes';
20
32
  export { BaseShape } from './elements/shapes';
21
33
  export { BasePlugin, CameraSetting, History } from './plugins';
22
34
  export { getExtension, getExtensions, register } from './registry';
23
35
  export { Graph } from './runtime/graph';
24
36
  export { BaseTransform } from './transforms';
25
37
  export { Shortcut } from './utils/shortcut';
38
+ export { parseSize } from './utils/size';
26
39
 
27
40
  export type { BaseBehaviorOptions, DragCanvasOptions, ZoomCanvasOptions } from './behaviors';
28
41
  export type { BaseComboStyleProps, CircleComboStyleProps, RectComboStyleProps } from './elements/combos';
@@ -40,6 +53,7 @@ export type {
40
53
  CircleStyleProps,
41
54
  DiamondStyleProps,
42
55
  EllipseStyleProps,
56
+ HTMLStyleProps,
43
57
  HexagonStyleProps,
44
58
  ImageStyleProps,
45
59
  RectStyleProps,
@@ -67,7 +81,11 @@ export type {
67
81
  } from './spec';
68
82
  export type { BaseTransformOptions } from './transforms';
69
83
  export type {
84
+ Combo,
85
+ Edge,
86
+ Element,
70
87
  IAnimateEvent,
88
+ ID,
71
89
  IDragEvent,
72
90
  IElementLifeCycleEvent,
73
91
  IEvent,
@@ -76,6 +94,7 @@ export type {
76
94
  IPointerEvent,
77
95
  IViewportEvent,
78
96
  IWheelEvent,
97
+ Node,
79
98
  Point,
80
99
  Vector2,
81
100
  Vector3,
@@ -1,9 +1,8 @@
1
- import type { ID } from '@antv/graphlib';
2
1
  import { PathArray, isEqual, isFunction } from '@antv/util';
3
2
  import hull from 'hull.js';
4
3
  import { GraphEvent } from '../../constants';
5
4
  import type { RuntimeContext } from '../../runtime/types';
6
- import type { CallableValue, Point } from '../../types';
5
+ import type { CallableValue, ID, Point } from '../../types';
7
6
  import type { ElementLifeCycleEvent } from '../../utils/event';
8
7
  import { idOf } from '../../utils/id';
9
8
  import { positionOf } from '../../utils/position';
@@ -1,10 +1,9 @@
1
1
  import type { CategoryOptions } from '@antv/component';
2
2
  import { Category, Layout, Selection } from '@antv/component';
3
- import type { ID } from '@antv/graphlib';
4
3
  import { get, isFunction } from '@antv/util';
5
4
  import { GraphEvent } from '../constants';
6
5
  import type { RuntimeContext } from '../runtime/types';
7
- import type { ElementDatum, ElementType, State } from '../types';
6
+ import type { ElementDatum, ElementType, ID, State } from '../types';
8
7
  import type { CardinalPlacement } from '../types/placement';
9
8
  import type { BasePluginOptions } from './base-plugin';
10
9
  import { BasePlugin } from './base-plugin';
@@ -198,8 +197,9 @@ export class Legend extends BasePlugin<LegendOptions> {
198
197
  data.forEach((item) => {
199
198
  const { id } = item;
200
199
  const value = get(item, ['data', getField(item)]);
201
- const { color = '#1783ff', type: marker = 'circle' } = getElementStyle(type, item);
202
- if ((id || id === 0) && value && value.replace(/\s+/g, '')) {
200
+ const marker = element?.getElementType(type, item) || 'circle';
201
+ const { color = '#1783ff' } = getElementStyle(type, item);
202
+ if (id && value && value.replace(/\s+/g, '')) {
203
203
  this.setFieldMap(value, id, type);
204
204
  if (!items[value]) {
205
205
  items[value] = {
@@ -19,7 +19,9 @@ import {
19
19
  CubicHorizontal,
20
20
  CubicVertical,
21
21
  Diamond,
22
+ Donut,
22
23
  Ellipse,
24
+ HTML,
23
25
  Hexagon,
24
26
  Image,
25
27
  Line,
@@ -113,13 +115,15 @@ export const BUILT_IN_EXTENSIONS: ExtensionRegistry = {
113
115
  },
114
116
  node: {
115
117
  circle: Circle,
118
+ diamond: Diamond,
116
119
  ellipse: Ellipse,
120
+ hexagon: Hexagon,
121
+ html: HTML,
117
122
  image: Image,
118
123
  rect: Rect,
119
124
  star: Star,
125
+ donut: Donut,
120
126
  triangle: Triangle,
121
- diamond: Diamond,
122
- hexagon: Hexagon,
123
127
  },
124
128
  palette: {
125
129
  spectral,
@@ -153,6 +153,7 @@ export class Canvas {
153
153
 
154
154
  public setBackground(background = this.config.background) {
155
155
  const container = this.getContainer();
156
+ this.config.background = background;
156
157
  if (container && background) {
157
158
  container.style.background = background;
158
159
  container.style.transition = 'background 0.5s';
@@ -248,7 +249,7 @@ export class Canvas {
248
249
  renderer: new CanvasRenderer(),
249
250
  devicePixelRatio,
250
251
  container,
251
- background: this.background.getConfig().background,
252
+ background: this.config.background,
252
253
  });
253
254
 
254
255
  await offscreenCanvas.ready;
@@ -286,7 +287,9 @@ export class Canvas {
286
287
  const contextService = offscreenCanvas.getContextService();
287
288
 
288
289
  return new Promise<string>((resolve) => {
289
- offscreenCanvas.on(CanvasEvent.AFTER_RENDER, async () => {
290
+ offscreenCanvas.on(CanvasEvent.RERENDER, async () => {
291
+ // 等待图片渲染完成 / Wait for the image to render
292
+ await new Promise((r) => setTimeout(r, 300));
290
293
  const url = await contextService.toDataURL(restOptions);
291
294
  resolve(url);
292
295
  });
@@ -1,4 +1,4 @@
1
- import { Graph as GraphLib, ID } from '@antv/graphlib';
1
+ import { Graph as GraphLib } from '@antv/graphlib';
2
2
  import { isEqual, isUndefined } from '@antv/util';
3
3
  import { COMBO_KEY, ChangeType, TREE_KEY } from '../constants';
4
4
  import type { ComboData, EdgeData, GraphData, NodeData } from '../spec';
@@ -9,6 +9,7 @@ import type {
9
9
  DataRemoved,
10
10
  DataUpdated,
11
11
  ElementDatum,
12
+ ID,
12
13
  NodeLikeData,
13
14
  PartialEdgeData,
14
15
  PartialGraphData,
@@ -2,8 +2,7 @@
2
2
  /* eslint-disable jsdoc/require-param */
3
3
  import type { BaseStyleProps, DisplayObject, IAnimation } from '@antv/g';
4
4
  import { Group } from '@antv/g';
5
- import type { ID } from '@antv/graphlib';
6
- import { groupBy, isEmpty } from '@antv/util';
5
+ import { groupBy, isEmpty, isString } from '@antv/util';
7
6
  import { executor as animationExecutor } from '../animations';
8
7
  import type { AnimationContext } from '../animations/types';
9
8
  import { AnimationType, ChangeType, GraphEvent } from '../constants';
@@ -21,6 +20,7 @@ import type {
21
20
  ElementData,
22
21
  ElementDatum,
23
22
  ElementType,
23
+ ID,
24
24
  Node,
25
25
  State,
26
26
  StyleIterationContext,
@@ -64,7 +64,8 @@ export class ElementController {
64
64
  }
65
65
  }
66
66
 
67
- private emit(event: BaseEvent) {
67
+ private emit(event: BaseEvent, context: DrawContext) {
68
+ if (context.silence) return;
68
69
  emit(this.context.graph, event);
69
70
  }
70
71
 
@@ -75,6 +76,17 @@ export class ElementController {
75
76
  });
76
77
  }
77
78
 
79
+ public getElementType(elementType: ElementType, datum: ElementDatum) {
80
+ const { options } = this.context;
81
+ const userDefinedType = options[elementType]?.type || datum.type;
82
+
83
+ if (!userDefinedType) {
84
+ return { node: 'circle', edge: 'line', combo: 'circle' }[elementType];
85
+ }
86
+ if (isString(userDefinedType)) return userDefinedType;
87
+ return userDefinedType(datum as any);
88
+ }
89
+
78
90
  private getTheme(elementType: ElementType) {
79
91
  const { theme } = this.context.options;
80
92
  if (!theme) return {};
@@ -125,7 +137,7 @@ export class ElementController {
125
137
  *
126
138
  * <en/> compute default style of single element
127
139
  */
128
- private computedElementDefaultStyle(elementType: ElementType, context: StyleIterationContext) {
140
+ private computeElementDefaultStyle(elementType: ElementType, context: StyleIterationContext) {
129
141
  const { options } = this.context;
130
142
  const defaultStyle = options[elementType]?.style || {};
131
143
  this.defaultStyle[idOf(context.datum)] = computeElementCallbackStyle(defaultStyle as any, context);
@@ -135,8 +147,8 @@ export class ElementController {
135
147
  this.forEachElementData((elementType, elementData) => {
136
148
  elementData
137
149
  .filter((datum) => ids === undefined || ids.includes(idOf(datum)))
138
- .forEach((datum, index) => {
139
- this.computedElementDefaultStyle(elementType, { datum, index, elementData });
150
+ .forEach((datum) => {
151
+ this.computeElementDefaultStyle(elementType, { datum });
140
152
  });
141
153
  });
142
154
  }
@@ -189,9 +201,9 @@ export class ElementController {
189
201
  this.forEachElementData((elementType, elementData) => {
190
202
  elementData
191
203
  .filter((datum) => ids === undefined || ids.includes(idOf(datum)))
192
- .forEach((datum, index) => {
204
+ .forEach((datum) => {
193
205
  const states = this.getElementState(idOf(datum));
194
- this.computeElementStatesStyle(elementType, states, { datum, index, elementData });
206
+ this.computeElementStatesStyle(elementType, states, { datum });
195
207
  });
196
208
  });
197
209
  }
@@ -309,10 +321,6 @@ export class ElementController {
309
321
  Object.assign(style, { childrenNode, childrenData });
310
322
  }
311
323
 
312
- if (!style.type) {
313
- style.type = { node: 'circle', edge: 'line', combo: 'circle' }[elementType];
314
- }
315
-
316
324
  return style;
317
325
  }
318
326
 
@@ -344,14 +352,22 @@ export class ElementController {
344
352
  before: () =>
345
353
  this.emit(
346
354
  new GraphLifeCycleEvent(GraphEvent.BEFORE_DRAW, { dataChanges, animation: drawContext.animation }),
355
+ drawContext,
347
356
  ),
348
357
  beforeAnimate: (animation) =>
349
- this.emit(new AnimateEvent(GraphEvent.BEFORE_ANIMATE, AnimationType.DRAW, animation, drawData)),
358
+ this.emit(
359
+ new AnimateEvent(GraphEvent.BEFORE_ANIMATE, AnimationType.DRAW, animation, drawData),
360
+ drawContext,
361
+ ),
350
362
  afterAnimate: (animation) =>
351
- this.emit(new AnimateEvent(GraphEvent.AFTER_ANIMATE, AnimationType.DRAW, animation, drawData)),
363
+ this.emit(
364
+ new AnimateEvent(GraphEvent.AFTER_ANIMATE, AnimationType.DRAW, animation, drawData),
365
+ drawContext,
366
+ ),
352
367
  after: () =>
353
368
  this.emit(
354
369
  new GraphLifeCycleEvent(GraphEvent.AFTER_DRAW, { dataChanges, animation: drawContext.animation }),
370
+ drawContext,
355
371
  ),
356
372
  },
357
373
  )?.finished;
@@ -415,17 +431,17 @@ export class ElementController {
415
431
  }
416
432
 
417
433
  private createElement(elementType: ElementType, datum: ElementDatum, context: DrawContext) {
418
- const { animator } = context;
419
434
  const id = idOf(datum);
420
435
  const currentShape = this.getElement(id);
421
436
  if (currentShape) return () => null;
422
- const { type, ...style } = this.getElementComputedStyle(elementType, datum);
437
+ const type = this.getElementType(elementType, datum);
438
+ const style = this.getElementComputedStyle(elementType, datum);
423
439
 
424
440
  // get shape constructor
425
441
  const Ctor = getExtension(elementType, type);
426
442
  if (!Ctor) return () => null;
427
443
 
428
- this.emit(new ElementLifeCycleEvent(GraphEvent.BEFORE_ELEMENT_CREATE, elementType, datum));
444
+ this.emit(new ElementLifeCycleEvent(GraphEvent.BEFORE_ELEMENT_CREATE, elementType, datum), context);
429
445
 
430
446
  const shape = this.container[elementType].appendChild(
431
447
  new Ctor({
@@ -440,10 +456,11 @@ export class ElementController {
440
456
  this.shapeTypeMap[id] = type;
441
457
  this.elementMap[id] = shape;
442
458
 
459
+ const { animation, animator } = context;
443
460
  return () =>
444
- withAnimationCallbacks(animator?.(id, shape, { ...shape.attributes, opacity: 0 }) || null, {
461
+ withAnimationCallbacks(animation ? animator?.(id, shape, { ...shape.attributes, opacity: 0 }) : null, {
445
462
  after: () => {
446
- this.emit(new ElementLifeCycleEvent(GraphEvent.AFTER_ELEMENT_CREATE, elementType, datum));
463
+ this.emit(new ElementLifeCycleEvent(GraphEvent.AFTER_ELEMENT_CREATE, elementType, datum), context);
447
464
  shape.onCreate();
448
465
  },
449
466
  });
@@ -495,20 +512,21 @@ export class ElementController {
495
512
  const shape = this.getElement(id);
496
513
  if (!shape) return () => null;
497
514
 
498
- this.emit(new ElementLifeCycleEvent(GraphEvent.BEFORE_ELEMENT_UPDATE, elementType, datum));
515
+ this.emit(new ElementLifeCycleEvent(GraphEvent.BEFORE_ELEMENT_UPDATE, elementType, datum), context);
499
516
  const afterUpdate = () => {
500
- this.emit(new ElementLifeCycleEvent(GraphEvent.AFTER_ELEMENT_UPDATE, elementType, datum));
517
+ this.emit(new ElementLifeCycleEvent(GraphEvent.AFTER_ELEMENT_UPDATE, elementType, datum), context);
501
518
  shape.onUpdate();
502
519
  };
503
520
 
504
- const { type, ...style } = this.getElementComputedStyle(elementType, datum);
521
+ const type = this.getElementType(elementType, datum);
522
+ const style = this.getElementComputedStyle(elementType, datum);
505
523
 
506
524
  // 如果类型不同,需要先销毁原有元素,再创建新元素
507
525
  // If the type is different, you need to destroy the original element first, and then create a new element
508
526
  if (this.shapeTypeMap[id] !== type) {
527
+ this.destroyElement(elementType, datum, { animation: false, silence: true })();
528
+ this.createElement(elementType, datum, { animation: false, silence: true })();
509
529
  return () => {
510
- this.destroyElement(elementType, datum, { ...context, animation: false })();
511
- this.createElement(elementType, datum, { ...context, animation: false })();
512
530
  afterUpdate();
513
531
  return null;
514
532
  };
@@ -527,7 +545,7 @@ export class ElementController {
527
545
  updateStyle(shape, { visibility: 'visible' });
528
546
  return () =>
529
547
  withAnimationCallbacks(
530
- animator?.(id, shape, { ...shape.attributes, opacity: 0 }, { opacity: originalOpacity }) || null,
548
+ animator?.(id, shape, { ...shape.attributes, opacity: 0 }, { opacity: originalOpacity }),
531
549
  { after: afterUpdate },
532
550
  );
533
551
  }
@@ -535,7 +553,7 @@ export class ElementController {
535
553
  else if (style.visibility === 'hidden') {
536
554
  return () =>
537
555
  withAnimationCallbacks(
538
- animator?.(id, shape, { ...shape.attributes, opacity: originalOpacity }, { opacity: 0 }) || null,
556
+ animator?.(id, shape, { ...shape.attributes, opacity: originalOpacity }, { opacity: 0 }),
539
557
  {
540
558
  after: () => {
541
559
  updateStyle(shape, { visibility: this.latestElementVisibilityMap.get(shape) });
@@ -549,8 +567,19 @@ export class ElementController {
549
567
  const originalStyle = { ...shape.attributes };
550
568
  updateStyle(shape, style);
551
569
 
570
+ // 如果边的端点节点已经销毁,则更新端点节点
571
+ // If the endpoint node of the edge has been destroyed, update the endpoint node
572
+ if (elementType === 'edge') {
573
+ if (originalStyle.sourceNode.destroyed) {
574
+ originalStyle.sourceNode = style.sourceNode;
575
+ }
576
+ if (originalStyle.targetNode.destroyed) {
577
+ originalStyle.targetNode = style.targetNode;
578
+ }
579
+ }
580
+
552
581
  return () =>
553
- withAnimationCallbacks(animator?.(id, shape, originalStyle) || null, {
582
+ withAnimationCallbacks(animator?.(id, shape, originalStyle), {
554
583
  after: afterUpdate,
555
584
  });
556
585
  }
@@ -582,20 +611,17 @@ export class ElementController {
582
611
  const element = this.elementMap[id];
583
612
  if (!element) return () => null;
584
613
 
585
- this.emit(new ElementLifeCycleEvent(GraphEvent.BEFORE_ELEMENT_DESTROY, elementType, datum));
614
+ this.emit(new ElementLifeCycleEvent(GraphEvent.BEFORE_ELEMENT_DESTROY, elementType, datum), context);
586
615
 
587
- return () => {
588
- const result = animator?.(id, element, { ...element.attributes }, { opacity: 0 }) || null;
589
- withAnimationCallbacks(result, {
616
+ return () =>
617
+ withAnimationCallbacks(animator?.(id, element, { ...element.attributes }, { opacity: 0 }), {
590
618
  after: () => {
591
619
  this.clearElement(id);
592
620
  element.destroy();
593
621
  element.onDestroy();
594
- this.emit(new ElementLifeCycleEvent(GraphEvent.AFTER_ELEMENT_DESTROY, elementType, datum));
622
+ this.emit(new ElementLifeCycleEvent(GraphEvent.AFTER_ELEMENT_DESTROY, elementType, datum), context);
595
623
  },
596
624
  });
597
- return result;
598
- };
599
625
  }
600
626
 
601
627
  private getDestroyTasks(data: ProcedureData, context: Omit<DrawContext, 'animator'>): AnimatableTask[] {
@@ -606,11 +632,11 @@ export class ElementController {
606
632
  ['node', nodes],
607
633
  ];
608
634
 
609
- const { animation, stage } = context;
635
+ const { animation, stage = 'exit' } = context;
610
636
  const tasks: AnimatableTask[] = [];
611
637
  iteration.forEach(([elementType, elementData]) => {
612
638
  if (elementData.size === 0) return [];
613
- const animator = this.getAnimationExecutor(elementType, stage || 'exit', animation);
639
+ const animator = this.getAnimationExecutor(elementType, stage, animation);
614
640
  elementData.forEach((datum) =>
615
641
  tasks.push(() => this.destroyElement(elementType, datum, { ...context, animator })),
616
642
  );