@antv/g6 5.0.0-beta.25 → 5.0.0-beta.27

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 (329) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/esm/constant/shape.d.ts +1 -1
  3. package/esm/index.d.ts +3 -1
  4. package/esm/index.js +1 -1
  5. package/esm/item/combo.d.ts +6 -4
  6. package/esm/item/combo.js +10 -3
  7. package/esm/item/combo.js.map +1 -1
  8. package/esm/item/edge.d.ts +12 -4
  9. package/esm/item/edge.js +100 -17
  10. package/esm/item/edge.js.map +1 -1
  11. package/esm/item/item.d.ts +18 -8
  12. package/esm/item/item.js +121 -62
  13. package/esm/item/item.js.map +1 -1
  14. package/esm/item/node.d.ts +10 -4
  15. package/esm/item/node.js +92 -8
  16. package/esm/item/node.js.map +1 -1
  17. package/esm/runtime/controller/data.d.ts +5 -1
  18. package/esm/runtime/controller/data.js +38 -1
  19. package/esm/runtime/controller/data.js.map +1 -1
  20. package/esm/runtime/controller/index.d.ts +1 -1
  21. package/esm/runtime/controller/index.js +1 -1
  22. package/esm/runtime/controller/index.js.map +1 -1
  23. package/esm/runtime/controller/item.d.ts +22 -11
  24. package/esm/runtime/controller/item.js +241 -96
  25. package/esm/runtime/controller/item.js.map +1 -1
  26. package/esm/runtime/controller/layout.d.ts +3 -0
  27. package/esm/runtime/controller/layout.js +178 -98
  28. package/esm/runtime/controller/layout.js.map +1 -1
  29. package/esm/runtime/controller/plugin.d.ts +3 -0
  30. package/esm/runtime/controller/plugin.js +66 -24
  31. package/esm/runtime/controller/plugin.js.map +1 -1
  32. package/esm/runtime/controller/viewport.js +9 -2
  33. package/esm/runtime/controller/viewport.js.map +1 -1
  34. package/esm/runtime/graph.d.ts +57 -26
  35. package/esm/runtime/graph.js +263 -139
  36. package/esm/runtime/graph.js.map +1 -1
  37. package/esm/stdlib/behavior/click-select.js +9 -3
  38. package/esm/stdlib/behavior/click-select.js.map +1 -1
  39. package/esm/stdlib/behavior/drag-canvas.js +6 -3
  40. package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
  41. package/esm/stdlib/behavior/drag-combo.js +8 -8
  42. package/esm/stdlib/behavior/drag-combo.js.map +1 -1
  43. package/esm/stdlib/behavior/drag-node.d.ts +4 -0
  44. package/esm/stdlib/behavior/drag-node.js +121 -27
  45. package/esm/stdlib/behavior/drag-node.js.map +1 -1
  46. package/esm/stdlib/behavior/scroll-canvas.js +3 -3
  47. package/esm/stdlib/behavior/scroll-canvas.js.map +1 -1
  48. package/esm/stdlib/behavior/zoom-canvas.js +3 -3
  49. package/esm/stdlib/behavior/zoom-canvas.js.map +1 -1
  50. package/esm/stdlib/data/mapNodeSize.js +2 -2
  51. package/esm/stdlib/data/mapNodeSize.js.map +1 -1
  52. package/esm/stdlib/data/validateData.js +2 -2
  53. package/esm/stdlib/data/validateData.js.map +1 -1
  54. package/esm/stdlib/index.d.ts +2 -0
  55. package/esm/stdlib/index.js +3 -1
  56. package/esm/stdlib/index.js.map +1 -1
  57. package/esm/stdlib/item/edge/base.d.ts +2 -11
  58. package/esm/stdlib/item/edge/base.js +12 -105
  59. package/esm/stdlib/item/edge/base.js.map +1 -1
  60. package/esm/stdlib/item/node/base.d.ts +2 -20
  61. package/esm/stdlib/item/node/base.js +10 -150
  62. package/esm/stdlib/item/node/base.js.map +1 -1
  63. package/esm/stdlib/plugin/edgeFilterLens/index.js +2 -2
  64. package/esm/stdlib/plugin/edgeFilterLens/index.js.map +1 -1
  65. package/esm/stdlib/plugin/fisheye/index.js +3 -2
  66. package/esm/stdlib/plugin/fisheye/index.js.map +1 -1
  67. package/esm/stdlib/plugin/history/visibility-updated-command.js +2 -2
  68. package/esm/stdlib/plugin/history/visibility-updated-command.js.map +1 -1
  69. package/esm/stdlib/plugin/hull/index.d.ts +1 -1
  70. package/esm/stdlib/plugin/index.d.ts +1 -0
  71. package/esm/stdlib/plugin/index.js +1 -0
  72. package/esm/stdlib/plugin/index.js.map +1 -1
  73. package/esm/stdlib/plugin/lodController/index.d.ts +73 -0
  74. package/esm/stdlib/plugin/lodController/index.js +556 -0
  75. package/esm/stdlib/plugin/lodController/index.js.map +1 -0
  76. package/esm/stdlib/plugin/menu/index.js +2 -1
  77. package/esm/stdlib/plugin/menu/index.js.map +1 -1
  78. package/esm/stdlib/plugin/minimap/index.js +12 -14
  79. package/esm/stdlib/plugin/minimap/index.js.map +1 -1
  80. package/esm/stdlib/plugin/toolbar/index.d.ts +2 -2
  81. package/esm/stdlib/plugin/toolbar/index.js +27 -29
  82. package/esm/stdlib/plugin/toolbar/index.js.map +1 -1
  83. package/esm/stdlib/theme/dark.js +32 -35
  84. package/esm/stdlib/theme/dark.js.map +1 -1
  85. package/esm/stdlib/theme/light.js +27 -30
  86. package/esm/stdlib/theme/light.js.map +1 -1
  87. package/esm/stdlib/themeSolver/spec.js +2 -2
  88. package/esm/stdlib/themeSolver/spec.js.map +1 -1
  89. package/esm/types/animate.d.ts +1 -1
  90. package/esm/types/combo.d.ts +2 -2
  91. package/esm/types/edge.d.ts +2 -2
  92. package/esm/types/graph.d.ts +62 -43
  93. package/esm/types/hook.d.ts +5 -0
  94. package/esm/types/item.d.ts +9 -15
  95. package/esm/types/layout.d.ts +7 -2
  96. package/esm/types/layout.js.map +1 -1
  97. package/esm/types/node.d.ts +3 -2
  98. package/esm/types/plugin.d.ts +1 -0
  99. package/esm/types/plugin.js +1 -0
  100. package/esm/types/plugin.js.map +1 -1
  101. package/esm/types/spec.d.ts +1 -0
  102. package/esm/types/theme.d.ts +7 -7
  103. package/esm/util/animate.d.ts +7 -2
  104. package/esm/util/animate.js +40 -23
  105. package/esm/util/animate.js.map +1 -1
  106. package/esm/util/bbox.d.ts +7 -1
  107. package/esm/util/bbox.js +16 -0
  108. package/esm/util/bbox.js.map +1 -1
  109. package/esm/util/data.d.ts +7 -1
  110. package/esm/util/data.js +17 -5
  111. package/esm/util/data.js.map +1 -1
  112. package/esm/util/dom.js +5 -5
  113. package/esm/util/dom.js.map +1 -1
  114. package/esm/util/item.d.ts +1 -1
  115. package/esm/util/item.js +8 -8
  116. package/esm/util/item.js.map +1 -1
  117. package/esm/util/mapper.js +1 -1
  118. package/esm/util/mapper.js.map +1 -1
  119. package/esm/util/path.d.ts +6 -1
  120. package/esm/util/path.js +72 -1
  121. package/esm/util/path.js.map +1 -1
  122. package/esm/util/polyline.d.ts +10 -0
  123. package/esm/util/polyline.js +22 -17
  124. package/esm/util/polyline.js.map +1 -1
  125. package/esm/util/router.d.ts +1 -1
  126. package/esm/util/router.js +19 -18
  127. package/esm/util/router.js.map +1 -1
  128. package/esm/util/shape.d.ts +1 -1
  129. package/esm/util/shape.js +28 -13
  130. package/esm/util/shape.js.map +1 -1
  131. package/esm/util/zoom.d.ts +5 -8
  132. package/esm/util/zoom.js +15 -20
  133. package/esm/util/zoom.js.map +1 -1
  134. package/lib/constant/shape.d.ts +1 -1
  135. package/lib/index.d.ts +3 -1
  136. package/lib/index.js +1 -1
  137. package/lib/item/combo.d.ts +6 -4
  138. package/lib/item/combo.js +10 -3
  139. package/lib/item/combo.js.map +1 -1
  140. package/lib/item/edge.d.ts +12 -4
  141. package/lib/item/edge.js +99 -16
  142. package/lib/item/edge.js.map +1 -1
  143. package/lib/item/item.d.ts +18 -8
  144. package/lib/item/item.js +119 -60
  145. package/lib/item/item.js.map +1 -1
  146. package/lib/item/node.d.ts +10 -4
  147. package/lib/item/node.js +92 -8
  148. package/lib/item/node.js.map +1 -1
  149. package/lib/runtime/controller/data.d.ts +5 -1
  150. package/lib/runtime/controller/data.js +38 -1
  151. package/lib/runtime/controller/data.js.map +1 -1
  152. package/lib/runtime/controller/index.d.ts +1 -1
  153. package/lib/runtime/controller/index.js +1 -1
  154. package/lib/runtime/controller/index.js.map +1 -1
  155. package/lib/runtime/controller/item.d.ts +22 -11
  156. package/lib/runtime/controller/item.js +238 -93
  157. package/lib/runtime/controller/item.js.map +1 -1
  158. package/lib/runtime/controller/layout.d.ts +3 -0
  159. package/lib/runtime/controller/layout.js +178 -98
  160. package/lib/runtime/controller/layout.js.map +1 -1
  161. package/lib/runtime/controller/plugin.d.ts +3 -0
  162. package/lib/runtime/controller/plugin.js +66 -24
  163. package/lib/runtime/controller/plugin.js.map +1 -1
  164. package/lib/runtime/controller/viewport.js +9 -2
  165. package/lib/runtime/controller/viewport.js.map +1 -1
  166. package/lib/runtime/graph.d.ts +57 -26
  167. package/lib/runtime/graph.js +263 -139
  168. package/lib/runtime/graph.js.map +1 -1
  169. package/lib/stdlib/behavior/click-select.js +9 -3
  170. package/lib/stdlib/behavior/click-select.js.map +1 -1
  171. package/lib/stdlib/behavior/drag-canvas.js +6 -3
  172. package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
  173. package/lib/stdlib/behavior/drag-combo.js +8 -8
  174. package/lib/stdlib/behavior/drag-combo.js.map +1 -1
  175. package/lib/stdlib/behavior/drag-node.d.ts +4 -0
  176. package/lib/stdlib/behavior/drag-node.js +121 -27
  177. package/lib/stdlib/behavior/drag-node.js.map +1 -1
  178. package/lib/stdlib/behavior/scroll-canvas.js +3 -3
  179. package/lib/stdlib/behavior/scroll-canvas.js.map +1 -1
  180. package/lib/stdlib/behavior/zoom-canvas.js +3 -3
  181. package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
  182. package/lib/stdlib/data/mapNodeSize.js +2 -2
  183. package/lib/stdlib/data/mapNodeSize.js.map +1 -1
  184. package/lib/stdlib/data/validateData.js +2 -2
  185. package/lib/stdlib/data/validateData.js.map +1 -1
  186. package/lib/stdlib/index.d.ts +2 -0
  187. package/lib/stdlib/index.js +3 -1
  188. package/lib/stdlib/index.js.map +1 -1
  189. package/lib/stdlib/item/edge/base.d.ts +2 -11
  190. package/lib/stdlib/item/edge/base.js +12 -105
  191. package/lib/stdlib/item/edge/base.js.map +1 -1
  192. package/lib/stdlib/item/node/base.d.ts +2 -20
  193. package/lib/stdlib/item/node/base.js +10 -150
  194. package/lib/stdlib/item/node/base.js.map +1 -1
  195. package/lib/stdlib/plugin/edgeFilterLens/index.js +2 -2
  196. package/lib/stdlib/plugin/edgeFilterLens/index.js.map +1 -1
  197. package/lib/stdlib/plugin/fisheye/index.js +2 -1
  198. package/lib/stdlib/plugin/fisheye/index.js.map +1 -1
  199. package/lib/stdlib/plugin/history/visibility-updated-command.js +2 -2
  200. package/lib/stdlib/plugin/history/visibility-updated-command.js.map +1 -1
  201. package/lib/stdlib/plugin/hull/index.d.ts +1 -1
  202. package/lib/stdlib/plugin/index.d.ts +1 -0
  203. package/lib/stdlib/plugin/index.js +1 -0
  204. package/lib/stdlib/plugin/index.js.map +1 -1
  205. package/lib/stdlib/plugin/lodController/index.d.ts +73 -0
  206. package/lib/stdlib/plugin/lodController/index.js +560 -0
  207. package/lib/stdlib/plugin/lodController/index.js.map +1 -0
  208. package/lib/stdlib/plugin/menu/index.js +2 -1
  209. package/lib/stdlib/plugin/menu/index.js.map +1 -1
  210. package/lib/stdlib/plugin/minimap/index.js +12 -14
  211. package/lib/stdlib/plugin/minimap/index.js.map +1 -1
  212. package/lib/stdlib/plugin/toolbar/index.d.ts +2 -2
  213. package/lib/stdlib/plugin/toolbar/index.js +27 -29
  214. package/lib/stdlib/plugin/toolbar/index.js.map +1 -1
  215. package/lib/stdlib/theme/dark.js +32 -35
  216. package/lib/stdlib/theme/dark.js.map +1 -1
  217. package/lib/stdlib/theme/light.js +27 -30
  218. package/lib/stdlib/theme/light.js.map +1 -1
  219. package/lib/stdlib/themeSolver/spec.js +2 -2
  220. package/lib/stdlib/themeSolver/spec.js.map +1 -1
  221. package/lib/types/animate.d.ts +1 -1
  222. package/lib/types/combo.d.ts +2 -2
  223. package/lib/types/edge.d.ts +2 -2
  224. package/lib/types/graph.d.ts +62 -43
  225. package/lib/types/hook.d.ts +5 -0
  226. package/lib/types/item.d.ts +9 -15
  227. package/lib/types/layout.d.ts +7 -2
  228. package/lib/types/layout.js.map +1 -1
  229. package/lib/types/node.d.ts +3 -2
  230. package/lib/types/plugin.d.ts +1 -0
  231. package/lib/types/plugin.js +1 -0
  232. package/lib/types/plugin.js.map +1 -1
  233. package/lib/types/spec.d.ts +1 -0
  234. package/lib/types/theme.d.ts +7 -7
  235. package/lib/util/animate.d.ts +7 -2
  236. package/lib/util/animate.js +40 -23
  237. package/lib/util/animate.js.map +1 -1
  238. package/lib/util/bbox.d.ts +7 -1
  239. package/lib/util/bbox.js +18 -1
  240. package/lib/util/bbox.js.map +1 -1
  241. package/lib/util/data.d.ts +7 -1
  242. package/lib/util/data.js +19 -6
  243. package/lib/util/data.js.map +1 -1
  244. package/lib/util/dom.js +5 -5
  245. package/lib/util/dom.js.map +1 -1
  246. package/lib/util/item.d.ts +1 -1
  247. package/lib/util/item.js +8 -8
  248. package/lib/util/item.js.map +1 -1
  249. package/lib/util/mapper.js +1 -1
  250. package/lib/util/mapper.js.map +1 -1
  251. package/lib/util/path.d.ts +6 -1
  252. package/lib/util/path.js +72 -1
  253. package/lib/util/path.js.map +1 -1
  254. package/lib/util/polyline.d.ts +10 -0
  255. package/lib/util/polyline.js +25 -18
  256. package/lib/util/polyline.js.map +1 -1
  257. package/lib/util/router.d.ts +1 -1
  258. package/lib/util/router.js +19 -18
  259. package/lib/util/router.js.map +1 -1
  260. package/lib/util/shape.d.ts +1 -1
  261. package/lib/util/shape.js +27 -12
  262. package/lib/util/shape.js.map +1 -1
  263. package/lib/util/zoom.d.ts +5 -8
  264. package/lib/util/zoom.js +17 -22
  265. package/lib/util/zoom.js.map +1 -1
  266. package/package.json +1 -1
  267. package/src/index.ts +1 -1
  268. package/src/item/combo.ts +13 -5
  269. package/src/item/edge.ts +126 -17
  270. package/src/item/item.ts +140 -57
  271. package/src/item/node.ts +109 -12
  272. package/src/runtime/controller/data.ts +64 -3
  273. package/src/runtime/controller/index.ts +1 -1
  274. package/src/runtime/controller/item.ts +321 -135
  275. package/src/runtime/controller/layout.ts +254 -113
  276. package/src/runtime/controller/plugin.ts +86 -33
  277. package/src/runtime/controller/viewport.ts +8 -2
  278. package/src/runtime/graph.ts +383 -158
  279. package/src/stdlib/behavior/click-select.ts +8 -3
  280. package/src/stdlib/behavior/drag-canvas.ts +6 -3
  281. package/src/stdlib/behavior/drag-combo.ts +8 -8
  282. package/src/stdlib/behavior/drag-node.ts +165 -50
  283. package/src/stdlib/behavior/scroll-canvas.ts +3 -3
  284. package/src/stdlib/behavior/zoom-canvas.ts +3 -3
  285. package/src/stdlib/data/mapNodeSize.ts +2 -2
  286. package/src/stdlib/data/validateData.ts +2 -2
  287. package/src/stdlib/index.ts +3 -0
  288. package/src/stdlib/item/edge/base.ts +15 -139
  289. package/src/stdlib/item/node/base.ts +20 -215
  290. package/src/stdlib/plugin/edgeFilterLens/index.ts +2 -2
  291. package/src/stdlib/plugin/fisheye/index.ts +3 -2
  292. package/src/stdlib/plugin/history/visibility-updated-command.ts +2 -2
  293. package/src/stdlib/plugin/index.ts +1 -0
  294. package/src/stdlib/plugin/lodController/index.ts +602 -0
  295. package/src/stdlib/plugin/menu/index.ts +1 -1
  296. package/src/stdlib/plugin/minimap/index.ts +12 -14
  297. package/src/stdlib/plugin/toolbar/index.ts +29 -31
  298. package/src/stdlib/theme/dark.ts +32 -34
  299. package/src/stdlib/theme/light.ts +27 -29
  300. package/src/stdlib/themeSolver/spec.ts +2 -2
  301. package/src/types/animate.ts +1 -1
  302. package/src/types/combo.ts +2 -2
  303. package/src/types/edge.ts +2 -2
  304. package/src/types/graph.ts +65 -53
  305. package/src/types/hook.ts +5 -0
  306. package/src/types/item.ts +8 -14
  307. package/src/types/layout.ts +20 -15
  308. package/src/types/node.ts +3 -2
  309. package/src/types/plugin.ts +2 -0
  310. package/src/types/spec.ts +1 -0
  311. package/src/types/theme.ts +7 -7
  312. package/src/util/animate.ts +104 -75
  313. package/src/util/bbox.ts +26 -1
  314. package/src/util/data.ts +15 -6
  315. package/src/util/dom.ts +6 -6
  316. package/src/util/item.ts +15 -1
  317. package/src/util/mapper.ts +1 -1
  318. package/src/util/path.ts +72 -2
  319. package/src/util/polyline.ts +30 -23
  320. package/src/util/router.ts +21 -19
  321. package/src/util/shape.ts +27 -12
  322. package/src/util/zoom.ts +19 -25
  323. package/esm/runtime/controller/extension.d.ts +0 -9
  324. package/esm/runtime/controller/extension.js +0 -11
  325. package/esm/runtime/controller/extension.js.map +0 -1
  326. package/lib/runtime/controller/extension.d.ts +0 -9
  327. package/lib/runtime/controller/extension.js +0 -15
  328. package/lib/runtime/controller/extension.js.map +0 -1
  329. package/src/runtime/controller/extension.ts +0 -14
package/src/item/node.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { Group } from '@antv/g';
2
- import { clone } from '@antv/util';
2
+ import { clone, debounce, throttle } from '@antv/util';
3
3
  import { Point } from '../types/common';
4
- import { ComboDisplayModel, ComboModel, NodeModel } from '../types';
5
- import { DisplayMapper, State, LodStrategyObj } from '../types/item';
4
+ import { ComboDisplayModel, ComboModel, IGraph, NodeModel } from '../types';
5
+ import { DisplayMapper, State, LodLevelRanges } from '../types/item';
6
6
  import { NodeDisplayModel, NodeModelData } from '../types/node';
7
7
  import { ComboStyleSet, NodeStyleSet } from '../types/theme';
8
8
  import { updateShapes } from '../util/shape';
@@ -17,9 +17,11 @@ import { ComboModelData } from '../types/combo';
17
17
  import Item from './item';
18
18
 
19
19
  interface IProps {
20
+ graph: IGraph;
20
21
  model: NodeModel | ComboModel;
21
22
  renderExtensions: any;
22
23
  containerGroup: Group;
24
+ labelContainerGroup?: Group; // TODO: optional?
23
25
  mapper?: DisplayMapper;
24
26
  stateMapper?: {
25
27
  [stateName: string]: DisplayMapper;
@@ -27,7 +29,7 @@ interface IProps {
27
29
  zoom?: number;
28
30
  theme: {
29
31
  styles: NodeStyleSet | ComboStyleSet;
30
- lodStrategy: LodStrategyObj;
32
+ lodLevels: LodLevelRanges;
31
33
  };
32
34
  device?: any; // for 3d shapes
33
35
  onframe?: Function;
@@ -61,7 +63,14 @@ export default class Node extends Item {
61
63
  animate = true,
62
64
  onfinish: Function = () => {},
63
65
  ) {
64
- const { group, renderExt, shapeMap: prevShapeMap, model } = this;
66
+ const {
67
+ group,
68
+ labelGroup,
69
+ renderExt,
70
+ shapeMap: prevShapeMap,
71
+ model,
72
+ graph,
73
+ } = this;
65
74
  renderExt.mergeStyles(displayModel);
66
75
 
67
76
  const firstRendering = !this.shapeMap?.keyShape;
@@ -71,9 +80,16 @@ export default class Node extends Item {
71
80
  diffData,
72
81
  diffState,
73
82
  );
83
+ if (this.shapeMap.labelShape) {
84
+ this.shapeMap.labelShape.attributes.dataIsLabel = true;
85
+ }
86
+ if (this.shapeMap.labelBackgroundShape) {
87
+ this.shapeMap.labelBackgroundShape.attributes.dataIsLabelBackground =
88
+ true;
89
+ }
74
90
 
75
91
  // add shapes to group, and update shapeMap
76
- this.shapeMap = updateShapes(prevShapeMap, shapeMap, group);
92
+ this.shapeMap = updateShapes(prevShapeMap, shapeMap, group, labelGroup);
77
93
 
78
94
  const { animates, disableAnimate, x = 0, y = 0, z = 0 } = displayModel.data;
79
95
  if (firstRendering) {
@@ -81,6 +97,10 @@ export default class Node extends Item {
81
97
  group.style.x = x;
82
98
  group.style.y = y;
83
99
  group.style.z = z;
100
+ const viewportPosition = graph.getViewportByCanvas({ x, y, z });
101
+ labelGroup.style.x = viewportPosition.x;
102
+ labelGroup.style.y = viewportPosition.y;
103
+ labelGroup.style.z = viewportPosition.z;
84
104
  } else {
85
105
  // terminate previous animations
86
106
  this.stopAnimations();
@@ -105,13 +125,18 @@ export default class Node extends Item {
105
125
  animatesExcludePosition, // animates
106
126
  renderExt.mergedStyles, // targetStylesMap
107
127
  this.shapeMap, // shapeMap
108
- group,
128
+ undefined,
129
+ [group, labelGroup],
109
130
  firstRendering ? 'buildIn' : 'update',
110
- this.changedStates,
131
+ diffState?.current.map((state) => state.name) || this.changedStates,
111
132
  this.animateFrameListener,
112
133
  (canceled) => onfinish(model.id, canceled),
113
134
  );
114
135
  }
136
+ this.labelGroup.children
137
+ .filter((element) => element.attributes.dataIsLabel)
138
+ .forEach((shape) => (shape.attributes.dataOriginPosition = ''));
139
+ this.updateLabelPosition(true);
115
140
  }
116
141
 
117
142
  /**
@@ -127,7 +152,7 @@ export default class Node extends Item {
127
152
  animate?: boolean,
128
153
  onfinish: Function = () => {},
129
154
  ) {
130
- const { group } = this;
155
+ const { group, labelGroup, graph } = this;
131
156
  const {
132
157
  fx,
133
158
  fy,
@@ -149,6 +174,10 @@ export default class Node extends Item {
149
174
  isNaN(position.z as number)
150
175
  )
151
176
  return;
177
+ const viewportPosition = graph.getViewportByCanvas(position);
178
+ labelGroup.style.x = viewportPosition.x;
179
+ labelGroup.style.y = viewportPosition.y;
180
+ labelGroup.style.z = viewportPosition.z || 0;
152
181
  if (animate && !disableAnimate && animates?.update) {
153
182
  const groupAnimates = animates.update.filter(
154
183
  ({ shapeId, fields = [] }) =>
@@ -160,7 +189,8 @@ export default class Node extends Item {
160
189
  { update: groupAnimates },
161
190
  { group: position } as any, // targetStylesMap
162
191
  this.shapeMap, // shapeMap
163
- group,
192
+ undefined,
193
+ [group],
164
194
  'update',
165
195
  [],
166
196
  this.animateFrameListener,
@@ -175,12 +205,74 @@ export default class Node extends Item {
175
205
  group.style.z = position.z;
176
206
  onfinish(displayModel.id, !animate);
177
207
  }
208
+ /**
209
+ * Update label positions on label canvas by getting viewport position from transformed canvas position.
210
+ */
211
+ public updateLabelPosition(ignoreVisibility?: boolean) {
212
+ if (!ignoreVisibility && this.labelGroup.style.visibility === 'hidden') {
213
+ return;
214
+ }
215
+ const { graph, group, labelGroup, displayModel, shapeMap, renderExt } =
216
+ this;
217
+
218
+ let [x, y, z] = group.getPosition();
219
+ if (group.getAnimations().length) {
220
+ const { x: dataX, y: dataY, z: dataZ } = displayModel.data;
221
+ x = dataX as number;
222
+ y = dataY as number;
223
+ z = dataZ as number;
224
+ }
225
+ const zoom = graph.getZoom();
226
+ const { x: vx, y: vy, z: vz } = graph.getViewportByCanvas({ x, y, z });
227
+ if (labelGroup.style.x !== vx) {
228
+ labelGroup.style.x = vx;
229
+ }
230
+ if (labelGroup.style.y !== vy) {
231
+ labelGroup.style.y = vy;
232
+ }
233
+ if (labelGroup.style.z !== vz) {
234
+ labelGroup.style.z = vz;
235
+ }
236
+
237
+ labelGroup.children.forEach((shape) => {
238
+ if (shape.attributes.dataIsLabelBackground) {
239
+ renderExt.drawLabelBackgroundShape(displayModel, shapeMap);
240
+ return;
241
+ }
242
+ if (shape.attributes.dataIsLabel) {
243
+ // this.throttleUpdateWordWidth(zoom, shape);
244
+ const { wordWrapWidth } = shape.style;
245
+ if (wordWrapWidth) {
246
+ if (!shape.attributes.dataOriginWordWrapWidth) {
247
+ shape.style.dataOriginWordWrapWidth = wordWrapWidth;
248
+ }
249
+ const originWordWrapWidth = shape.attributes.dataOriginWordWrapWidth;
250
+ shape.style.wordWrapWidth = originWordWrapWidth * zoom;
251
+ }
252
+ }
253
+ if (!shape.attributes.dataOriginPosition) {
254
+ shape.attributes.dataOriginPosition = {
255
+ x: shape.style.x,
256
+ y: shape.style.y,
257
+ z: shape.style.z,
258
+ };
259
+ }
260
+ const originPosition = shape.attributes.dataOriginPosition;
261
+ Object.keys(originPosition).forEach((field) => {
262
+ if (!isNaN(shape.style[field])) {
263
+ shape.style[field] = originPosition[field] * zoom;
264
+ }
265
+ });
266
+ });
267
+ }
178
268
 
179
269
  public clone(
180
270
  containerGroup: Group,
271
+ labelContainerGroup: Group,
181
272
  shapeIds?: string[],
182
273
  disableAnimate?: boolean,
183
274
  ) {
275
+ // clone specific shapes but not the whole item
184
276
  if (shapeIds?.length) {
185
277
  const group = new Group();
186
278
  shapeIds.forEach((shapeId) => {
@@ -199,19 +291,24 @@ export default class Node extends Item {
199
291
  clonedModel.data.disableAnimate = disableAnimate;
200
292
  const clonedNode = new Node({
201
293
  model: clonedModel,
294
+ graph: this.graph,
202
295
  renderExtensions: this.renderExtensions,
203
296
  containerGroup,
297
+ labelContainerGroup,
204
298
  mapper: this.mapper,
205
299
  stateMapper: this.stateMapper,
206
300
  zoom: this.zoom,
207
301
  theme: {
208
302
  styles: this.themeStyles,
209
- lodStrategy: this.lodStrategy,
303
+ lodLevels: this.lodLevels,
210
304
  },
211
305
  });
212
306
  Object.keys(this.shapeMap).forEach((shapeId) => {
213
- if (!this.shapeMap[shapeId].isVisible())
307
+ if (!this.shapeMap[shapeId].isVisible()) {
214
308
  clonedNode.shapeMap[shapeId].hide();
309
+ } else {
310
+ clonedNode.shapeMap[shapeId]?.show();
311
+ }
215
312
  });
216
313
  return clonedNode;
217
314
  }
@@ -1,5 +1,6 @@
1
1
  import { Graph as GraphLib, ID } from '@antv/graphlib';
2
2
  import { clone, isArray, isEmpty, isObject } from '@antv/util';
3
+ import { AABB } from '@antv/g';
3
4
  import { registery as registry } from '../../stdlib';
4
5
  import {
5
6
  ComboModel,
@@ -19,6 +20,7 @@ import {
19
20
  InlineTreeDataConfig,
20
21
  } from '../../types/data';
21
22
  import {
23
+ EdgeDisplayModel,
22
24
  EdgeModel,
23
25
  EdgeModelData,
24
26
  EdgeUserModel,
@@ -43,9 +45,12 @@ import {
43
45
  validateComboStrucutre,
44
46
  } from '../../util/data';
45
47
  import { getExtension } from '../../util/extension';
46
- import { convertToNumber } from '../../util/type';
47
48
  import { isTreeLayout } from '../../util/layout';
48
49
  import { hasTreeBehaviors } from '../../util/behavior';
50
+ import { EdgeCollisionChecker, QuadTree } from '../../util/polyline';
51
+ import Node from '../../item/node';
52
+ import Edge from '../../item/edge';
53
+ import Combo from '../../item/combo';
49
54
 
50
55
  /**
51
56
  * Manages the data transform extensions;
@@ -140,6 +145,60 @@ export class DataController {
140
145
  ) {
141
146
  return this.graphCore.getRelatedEdges(nodeId, direction);
142
147
  }
148
+
149
+ public findNearEdges(
150
+ nodeId: ID,
151
+ itemMap: Map<ID, Node | Edge | Combo>,
152
+ transientItem?: Node,
153
+ shouldBegin?: (edge: EdgeDisplayModel) => boolean,
154
+ ): EdgeModel[] {
155
+ const edges = this.graphCore.getAllEdges();
156
+
157
+ const canvasBBox = this.graph.getRenderBBox(undefined) as AABB;
158
+ const quadTree = new QuadTree(canvasBBox, 4);
159
+
160
+ edges.forEach((edge) => {
161
+ // @ts-ignore
162
+ const edgeDisplayModel = itemMap.get(edge.id)
163
+ .displayModel as EdgeDisplayModel;
164
+ if (!shouldBegin(edgeDisplayModel)) return;
165
+
166
+ const {
167
+ data: { x: sourceX, y: sourceY },
168
+ } = this.graphCore.getNode(edge.source);
169
+ const {
170
+ data: { x: targetX, y: targetY },
171
+ } = this.graphCore.getNode(edge.target);
172
+
173
+ quadTree.insert({
174
+ id: edge.id,
175
+ p1: { x: sourceX, y: sourceY },
176
+ p2: { x: targetX, y: targetY },
177
+ bbox: this.graph.getRenderBBox(edge.id) as AABB,
178
+ });
179
+ });
180
+ const nodeBBox = this.graph.getRenderBBox(nodeId) as AABB;
181
+
182
+ if (transientItem) {
183
+ // @ts-ignore
184
+ const nodeData = transientItem.displayModel.data;
185
+ if (nodeData) {
186
+ nodeBBox.update(
187
+ [nodeData.x as number, nodeData.y as number, 0],
188
+ nodeBBox.halfExtents,
189
+ );
190
+ }
191
+ }
192
+
193
+ const checker = new EdgeCollisionChecker(quadTree);
194
+ const collisions = checker.getCollidingEdges(nodeBBox);
195
+ const collidingEdges = collisions.map((collision) =>
196
+ this.graphCore.getEdge(collision.id),
197
+ );
198
+
199
+ return collidingEdges;
200
+ }
201
+
143
202
  public findNeighborNodes(
144
203
  nodeId: ID,
145
204
  direction: 'in' | 'out' | 'both' = 'both',
@@ -177,7 +236,9 @@ export class DataController {
177
236
  */
178
237
  private getExtensions() {
179
238
  const { transforms = [] } = this.graph.getSpecification();
180
- const requiredTransformers = ['validate-data'];
239
+ const requiredTransformers = [
240
+ { type: 'validate-data', activeLifecycle: 'all' },
241
+ ];
181
242
  return [...transforms, ...requiredTransformers]
182
243
  .map((config) => ({
183
244
  config,
@@ -403,6 +464,7 @@ export class DataController {
403
464
 
404
465
  // update edge
405
466
  edges.forEach((newModel) => {
467
+ if (!graphCore.hasEdge(newModel.id)) return;
406
468
  const oldModel = graphCore.getEdge(newModel.id);
407
469
  if (!oldModel) return;
408
470
  const { id, source, target, data } = newModel;
@@ -720,7 +782,6 @@ export class DataController {
720
782
  : activeLifecycle === 'all'
721
783
  ? AVAILABLE_DATA_LIFECYCLE
722
784
  : [activeLifecycle];
723
-
724
785
  return (activeLifecycle as string[]).includes(dataLifecycleMap[changeType]);
725
786
  };
726
787
 
@@ -4,4 +4,4 @@ export * from './item';
4
4
  export * from './layout';
5
5
  export * from './viewport';
6
6
  export * from './theme';
7
- export * from './extension';
7
+ export * from './plugin';