@antv/g6 5.0.19 → 5.0.21

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 (440) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/dist/lib/behaviors/base-behavior.d.ts +10 -0
  3. package/dist/lib/behaviors/drag-canvas.d.ts +9 -0
  4. package/dist/lib/behaviors/hover-activate.d.ts +16 -2
  5. package/dist/lib/behaviors/scroll-canvas.d.ts +9 -0
  6. package/dist/lib/elements/combos/circle.d.ts +1 -1
  7. package/dist/lib/elements/edges/cubic-radial.d.ts +24 -0
  8. package/dist/lib/elements/edges/index.d.ts +2 -0
  9. package/dist/lib/elements/edges/line.d.ts +0 -2
  10. package/dist/lib/elements/nodes/base-node.d.ts +2 -1
  11. package/dist/lib/elements/nodes/circle.d.ts +1 -1
  12. package/dist/lib/elements/nodes/ellipse.d.ts +1 -1
  13. package/dist/lib/elements/shapes/base-shape.d.ts +29 -14
  14. package/dist/lib/elements/shapes/polygon.d.ts +1 -1
  15. package/dist/lib/exports.d.ts +9 -7
  16. package/dist/lib/layouts/base-layout.d.ts +5 -0
  17. package/dist/lib/plugins/background/index.d.ts +1 -0
  18. package/dist/lib/plugins/base-plugin.d.ts +5 -0
  19. package/dist/lib/plugins/bubble-sets.d.ts +1 -0
  20. package/dist/lib/plugins/contextmenu/index.d.ts +1 -0
  21. package/dist/lib/plugins/grid-line.d.ts +1 -0
  22. package/dist/lib/plugins/history/index.d.ts +1 -0
  23. package/dist/lib/plugins/hull/index.d.ts +1 -0
  24. package/dist/lib/plugins/legend.d.ts +1 -0
  25. package/dist/lib/plugins/minimap/index.d.ts +8 -2
  26. package/dist/lib/plugins/snapline/index.d.ts +10 -0
  27. package/dist/lib/plugins/timebar.d.ts +1 -0
  28. package/dist/lib/plugins/toolbar/index.d.ts +1 -0
  29. package/dist/lib/plugins/tooltip.d.ts +11 -0
  30. package/dist/lib/plugins/watermark/index.d.ts +1 -0
  31. package/dist/lib/runtime/data.d.ts +1 -0
  32. package/dist/lib/runtime/element.d.ts +1 -0
  33. package/dist/lib/runtime/graph.d.ts +2 -0
  34. package/dist/lib/runtime/layout.d.ts +1 -0
  35. package/dist/lib/transforms/base-transform.d.ts +6 -0
  36. package/dist/lib/transforms/index.d.ts +3 -0
  37. package/dist/lib/transforms/position-radial-labels.d.ts +27 -0
  38. package/dist/lib/transforms/process-parallel-edges.d.ts +7 -9
  39. package/dist/lib/transforms/utils.d.ts +5 -5
  40. package/dist/lib/types/element.d.ts +2 -1
  41. package/dist/lib/utils/bbox.d.ts +12 -3
  42. package/dist/lib/utils/data.d.ts +14 -0
  43. package/dist/lib/utils/diff.d.ts +2 -1
  44. package/dist/lib/utils/padding.d.ts +4 -4
  45. package/dist/lib/utils/point.d.ts +17 -5
  46. package/dist/lib/utils/position.d.ts +8 -0
  47. package/dist/lib/utils/prefix.d.ts +1 -1
  48. package/dist/lib/utils/relation.d.ts +6 -4
  49. package/dist/lib/utils/router/orth.d.ts +1 -1
  50. package/dist/lib/utils/size.d.ts +3 -1
  51. package/dist/lib/utils/transform.d.ts +5 -5
  52. package/dist/lib/utils/vector.d.ts +8 -0
  53. package/dist/lib/version.d.ts +1 -1
  54. package/esm/behaviors/base-behavior.d.ts +10 -0
  55. package/esm/behaviors/base-behavior.js +5 -0
  56. package/esm/behaviors/base-behavior.js.map +1 -1
  57. package/esm/behaviors/drag-canvas.d.ts +9 -0
  58. package/esm/behaviors/drag-canvas.js +28 -3
  59. package/esm/behaviors/drag-canvas.js.map +1 -1
  60. package/esm/behaviors/hover-activate.d.ts +16 -2
  61. package/esm/behaviors/hover-activate.js +17 -7
  62. package/esm/behaviors/hover-activate.js.map +1 -1
  63. package/esm/behaviors/scroll-canvas.d.ts +9 -0
  64. package/esm/behaviors/scroll-canvas.js +31 -4
  65. package/esm/behaviors/scroll-canvas.js.map +1 -1
  66. package/esm/elements/combos/base-combo.js +2 -2
  67. package/esm/elements/combos/base-combo.js.map +1 -1
  68. package/esm/elements/combos/circle.d.ts +1 -1
  69. package/esm/elements/combos/circle.js +2 -2
  70. package/esm/elements/combos/circle.js.map +1 -1
  71. package/esm/elements/edges/cubic-radial.d.ts +24 -0
  72. package/esm/elements/edges/cubic-radial.js +52 -0
  73. package/esm/elements/edges/cubic-radial.js.map +1 -0
  74. package/esm/elements/edges/index.d.ts +2 -0
  75. package/esm/elements/edges/index.js +1 -0
  76. package/esm/elements/edges/index.js.map +1 -1
  77. package/esm/elements/edges/line.d.ts +0 -2
  78. package/esm/elements/edges/line.js +0 -2
  79. package/esm/elements/edges/line.js.map +1 -1
  80. package/esm/elements/edges/polyline.js.map +1 -1
  81. package/esm/elements/nodes/base-node.d.ts +2 -1
  82. package/esm/elements/nodes/base-node.js +3 -2
  83. package/esm/elements/nodes/base-node.js.map +1 -1
  84. package/esm/elements/nodes/circle.d.ts +1 -1
  85. package/esm/elements/nodes/circle.js +2 -2
  86. package/esm/elements/nodes/circle.js.map +1 -1
  87. package/esm/elements/nodes/ellipse.d.ts +1 -1
  88. package/esm/elements/nodes/ellipse.js +2 -2
  89. package/esm/elements/nodes/ellipse.js.map +1 -1
  90. package/esm/elements/nodes/html.js +4 -1
  91. package/esm/elements/nodes/html.js.map +1 -1
  92. package/esm/elements/shapes/base-shape.d.ts +29 -14
  93. package/esm/elements/shapes/base-shape.js +27 -12
  94. package/esm/elements/shapes/base-shape.js.map +1 -1
  95. package/esm/elements/shapes/polygon.d.ts +1 -1
  96. package/esm/elements/shapes/polygon.js +2 -2
  97. package/esm/elements/shapes/polygon.js.map +1 -1
  98. package/esm/exports.d.ts +9 -7
  99. package/esm/exports.js +6 -4
  100. package/esm/exports.js.map +1 -1
  101. package/esm/layouts/base-layout.d.ts +5 -0
  102. package/esm/layouts/base-layout.js +5 -0
  103. package/esm/layouts/base-layout.js.map +1 -1
  104. package/esm/plugins/background/index.d.ts +1 -0
  105. package/esm/plugins/background/index.js +1 -0
  106. package/esm/plugins/background/index.js.map +1 -1
  107. package/esm/plugins/base-plugin.d.ts +5 -0
  108. package/esm/plugins/base-plugin.js +5 -0
  109. package/esm/plugins/base-plugin.js.map +1 -1
  110. package/esm/plugins/bubble-sets.d.ts +1 -0
  111. package/esm/plugins/bubble-sets.js +1 -0
  112. package/esm/plugins/bubble-sets.js.map +1 -1
  113. package/esm/plugins/contextmenu/index.d.ts +1 -0
  114. package/esm/plugins/contextmenu/index.js +1 -0
  115. package/esm/plugins/contextmenu/index.js.map +1 -1
  116. package/esm/plugins/grid-line.d.ts +1 -0
  117. package/esm/plugins/grid-line.js +1 -0
  118. package/esm/plugins/grid-line.js.map +1 -1
  119. package/esm/plugins/history/index.d.ts +1 -0
  120. package/esm/plugins/history/index.js +1 -0
  121. package/esm/plugins/history/index.js.map +1 -1
  122. package/esm/plugins/hull/index.d.ts +1 -0
  123. package/esm/plugins/hull/index.js +1 -0
  124. package/esm/plugins/hull/index.js.map +1 -1
  125. package/esm/plugins/legend.d.ts +1 -0
  126. package/esm/plugins/legend.js +1 -0
  127. package/esm/plugins/legend.js.map +1 -1
  128. package/esm/plugins/minimap/index.d.ts +8 -2
  129. package/esm/plugins/minimap/index.js +5 -0
  130. package/esm/plugins/minimap/index.js.map +1 -1
  131. package/esm/plugins/snapline/index.d.ts +10 -0
  132. package/esm/plugins/snapline/index.js +5 -0
  133. package/esm/plugins/snapline/index.js.map +1 -1
  134. package/esm/plugins/timebar.d.ts +1 -0
  135. package/esm/plugins/timebar.js +1 -0
  136. package/esm/plugins/timebar.js.map +1 -1
  137. package/esm/plugins/toolbar/index.d.ts +1 -0
  138. package/esm/plugins/toolbar/index.js +1 -0
  139. package/esm/plugins/toolbar/index.js.map +1 -1
  140. package/esm/plugins/tooltip.d.ts +11 -0
  141. package/esm/plugins/tooltip.js +11 -2
  142. package/esm/plugins/tooltip.js.map +1 -1
  143. package/esm/plugins/watermark/index.d.ts +1 -0
  144. package/esm/plugins/watermark/index.js +1 -0
  145. package/esm/plugins/watermark/index.js.map +1 -1
  146. package/esm/registry/build-in.js +4 -2
  147. package/esm/registry/build-in.js.map +1 -1
  148. package/esm/runtime/animation.js +12 -10
  149. package/esm/runtime/animation.js.map +1 -1
  150. package/esm/runtime/data.d.ts +1 -0
  151. package/esm/runtime/data.js +21 -13
  152. package/esm/runtime/data.js.map +1 -1
  153. package/esm/runtime/element.d.ts +1 -0
  154. package/esm/runtime/element.js +21 -11
  155. package/esm/runtime/element.js.map +1 -1
  156. package/esm/runtime/graph.d.ts +2 -0
  157. package/esm/runtime/graph.js +42 -22
  158. package/esm/runtime/graph.js.map +1 -1
  159. package/esm/runtime/layout.d.ts +1 -0
  160. package/esm/runtime/layout.js +5 -0
  161. package/esm/runtime/layout.js.map +1 -1
  162. package/esm/transforms/base-transform.d.ts +6 -0
  163. package/esm/transforms/base-transform.js +6 -0
  164. package/esm/transforms/base-transform.js.map +1 -1
  165. package/esm/transforms/collapse-expand-combo.js +3 -0
  166. package/esm/transforms/collapse-expand-combo.js.map +1 -1
  167. package/esm/transforms/collapse-expand-node.js +2 -0
  168. package/esm/transforms/collapse-expand-node.js.map +1 -1
  169. package/esm/transforms/index.d.ts +3 -0
  170. package/esm/transforms/index.js +1 -0
  171. package/esm/transforms/index.js.map +1 -1
  172. package/esm/transforms/position-radial-labels.d.ts +27 -0
  173. package/esm/transforms/position-radial-labels.js +50 -0
  174. package/esm/transforms/position-radial-labels.js.map +1 -0
  175. package/esm/transforms/process-parallel-edges.d.ts +7 -9
  176. package/esm/transforms/process-parallel-edges.js.map +1 -1
  177. package/esm/transforms/utils.d.ts +5 -5
  178. package/esm/transforms/utils.js +5 -5
  179. package/esm/types/element.d.ts +2 -1
  180. package/esm/utils/bbox.d.ts +12 -3
  181. package/esm/utils/bbox.js +16 -4
  182. package/esm/utils/bbox.js.map +1 -1
  183. package/esm/utils/data.d.ts +14 -0
  184. package/esm/utils/data.js +39 -0
  185. package/esm/utils/data.js.map +1 -1
  186. package/esm/utils/diff.d.ts +2 -1
  187. package/esm/utils/diff.js +3 -2
  188. package/esm/utils/diff.js.map +1 -1
  189. package/esm/utils/edge.js +4 -4
  190. package/esm/utils/edge.js.map +1 -1
  191. package/esm/utils/padding.d.ts +4 -4
  192. package/esm/utils/padding.js +4 -4
  193. package/esm/utils/point.d.ts +17 -5
  194. package/esm/utils/point.js +27 -8
  195. package/esm/utils/point.js.map +1 -1
  196. package/esm/utils/position.d.ts +8 -0
  197. package/esm/utils/position.js +11 -0
  198. package/esm/utils/position.js.map +1 -1
  199. package/esm/utils/prefix.d.ts +1 -1
  200. package/esm/utils/prefix.js +1 -1
  201. package/esm/utils/relation.d.ts +6 -4
  202. package/esm/utils/relation.js +10 -8
  203. package/esm/utils/relation.js.map +1 -1
  204. package/esm/utils/router/orth.d.ts +1 -1
  205. package/esm/utils/router/orth.js +27 -11
  206. package/esm/utils/router/orth.js.map +1 -1
  207. package/esm/utils/size.d.ts +3 -1
  208. package/esm/utils/size.js +3 -1
  209. package/esm/utils/size.js.map +1 -1
  210. package/esm/utils/transform.d.ts +5 -5
  211. package/esm/utils/transform.js +5 -5
  212. package/esm/utils/vector.d.ts +8 -0
  213. package/esm/utils/vector.js +13 -0
  214. package/esm/utils/vector.js.map +1 -1
  215. package/esm/version.d.ts +1 -1
  216. package/esm/version.js +1 -1
  217. package/lib/behaviors/base-behavior.d.ts +10 -0
  218. package/lib/behaviors/base-behavior.js +5 -0
  219. package/lib/behaviors/base-behavior.js.map +1 -1
  220. package/lib/behaviors/drag-canvas.d.ts +9 -0
  221. package/lib/behaviors/drag-canvas.js +27 -2
  222. package/lib/behaviors/drag-canvas.js.map +1 -1
  223. package/lib/behaviors/hover-activate.d.ts +16 -2
  224. package/lib/behaviors/hover-activate.js +17 -7
  225. package/lib/behaviors/hover-activate.js.map +1 -1
  226. package/lib/behaviors/scroll-canvas.d.ts +9 -0
  227. package/lib/behaviors/scroll-canvas.js +31 -4
  228. package/lib/behaviors/scroll-canvas.js.map +1 -1
  229. package/lib/elements/combos/base-combo.js +1 -1
  230. package/lib/elements/combos/base-combo.js.map +1 -1
  231. package/lib/elements/combos/circle.d.ts +1 -1
  232. package/lib/elements/combos/circle.js +2 -2
  233. package/lib/elements/combos/circle.js.map +1 -1
  234. package/lib/elements/edges/cubic-radial.d.ts +24 -0
  235. package/lib/elements/edges/cubic-radial.js +56 -0
  236. package/lib/elements/edges/cubic-radial.js.map +1 -0
  237. package/lib/elements/edges/index.d.ts +2 -0
  238. package/lib/elements/edges/index.js +3 -1
  239. package/lib/elements/edges/index.js.map +1 -1
  240. package/lib/elements/edges/line.d.ts +0 -2
  241. package/lib/elements/edges/line.js +0 -2
  242. package/lib/elements/edges/line.js.map +1 -1
  243. package/lib/elements/edges/polyline.js.map +1 -1
  244. package/lib/elements/nodes/base-node.d.ts +2 -1
  245. package/lib/elements/nodes/base-node.js +3 -2
  246. package/lib/elements/nodes/base-node.js.map +1 -1
  247. package/lib/elements/nodes/circle.d.ts +1 -1
  248. package/lib/elements/nodes/circle.js +2 -2
  249. package/lib/elements/nodes/circle.js.map +1 -1
  250. package/lib/elements/nodes/ellipse.d.ts +1 -1
  251. package/lib/elements/nodes/ellipse.js +2 -2
  252. package/lib/elements/nodes/ellipse.js.map +1 -1
  253. package/lib/elements/nodes/html.js +3 -0
  254. package/lib/elements/nodes/html.js.map +1 -1
  255. package/lib/elements/shapes/base-shape.d.ts +29 -14
  256. package/lib/elements/shapes/base-shape.js +27 -12
  257. package/lib/elements/shapes/base-shape.js.map +1 -1
  258. package/lib/elements/shapes/polygon.d.ts +1 -1
  259. package/lib/elements/shapes/polygon.js +2 -2
  260. package/lib/elements/shapes/polygon.js.map +1 -1
  261. package/lib/exports.d.ts +9 -7
  262. package/lib/exports.js +15 -6
  263. package/lib/exports.js.map +1 -1
  264. package/lib/layouts/base-layout.d.ts +5 -0
  265. package/lib/layouts/base-layout.js +5 -0
  266. package/lib/layouts/base-layout.js.map +1 -1
  267. package/lib/plugins/background/index.d.ts +1 -0
  268. package/lib/plugins/background/index.js +1 -0
  269. package/lib/plugins/background/index.js.map +1 -1
  270. package/lib/plugins/base-plugin.d.ts +5 -0
  271. package/lib/plugins/base-plugin.js +5 -0
  272. package/lib/plugins/base-plugin.js.map +1 -1
  273. package/lib/plugins/bubble-sets.d.ts +1 -0
  274. package/lib/plugins/bubble-sets.js +1 -0
  275. package/lib/plugins/bubble-sets.js.map +1 -1
  276. package/lib/plugins/contextmenu/index.d.ts +1 -0
  277. package/lib/plugins/contextmenu/index.js +1 -0
  278. package/lib/plugins/contextmenu/index.js.map +1 -1
  279. package/lib/plugins/grid-line.d.ts +1 -0
  280. package/lib/plugins/grid-line.js +1 -0
  281. package/lib/plugins/grid-line.js.map +1 -1
  282. package/lib/plugins/history/index.d.ts +1 -0
  283. package/lib/plugins/history/index.js +1 -0
  284. package/lib/plugins/history/index.js.map +1 -1
  285. package/lib/plugins/hull/index.d.ts +1 -0
  286. package/lib/plugins/hull/index.js +1 -0
  287. package/lib/plugins/hull/index.js.map +1 -1
  288. package/lib/plugins/legend.d.ts +1 -0
  289. package/lib/plugins/legend.js +1 -0
  290. package/lib/plugins/legend.js.map +1 -1
  291. package/lib/plugins/minimap/index.d.ts +8 -2
  292. package/lib/plugins/minimap/index.js +5 -0
  293. package/lib/plugins/minimap/index.js.map +1 -1
  294. package/lib/plugins/snapline/index.d.ts +10 -0
  295. package/lib/plugins/snapline/index.js +5 -0
  296. package/lib/plugins/snapline/index.js.map +1 -1
  297. package/lib/plugins/timebar.d.ts +1 -0
  298. package/lib/plugins/timebar.js +1 -0
  299. package/lib/plugins/timebar.js.map +1 -1
  300. package/lib/plugins/toolbar/index.d.ts +1 -0
  301. package/lib/plugins/toolbar/index.js +1 -0
  302. package/lib/plugins/toolbar/index.js.map +1 -1
  303. package/lib/plugins/tooltip.d.ts +11 -0
  304. package/lib/plugins/tooltip.js +11 -2
  305. package/lib/plugins/tooltip.js.map +1 -1
  306. package/lib/plugins/watermark/index.d.ts +1 -0
  307. package/lib/plugins/watermark/index.js +1 -0
  308. package/lib/plugins/watermark/index.js.map +1 -1
  309. package/lib/registry/build-in.js +2 -0
  310. package/lib/registry/build-in.js.map +1 -1
  311. package/lib/runtime/animation.js +12 -10
  312. package/lib/runtime/animation.js.map +1 -1
  313. package/lib/runtime/data.d.ts +1 -0
  314. package/lib/runtime/data.js +19 -11
  315. package/lib/runtime/data.js.map +1 -1
  316. package/lib/runtime/element.d.ts +1 -0
  317. package/lib/runtime/element.js +21 -11
  318. package/lib/runtime/element.js.map +1 -1
  319. package/lib/runtime/graph.d.ts +2 -0
  320. package/lib/runtime/graph.js +42 -22
  321. package/lib/runtime/graph.js.map +1 -1
  322. package/lib/runtime/layout.d.ts +1 -0
  323. package/lib/runtime/layout.js +5 -0
  324. package/lib/runtime/layout.js.map +1 -1
  325. package/lib/transforms/base-transform.d.ts +6 -0
  326. package/lib/transforms/base-transform.js +6 -0
  327. package/lib/transforms/base-transform.js.map +1 -1
  328. package/lib/transforms/collapse-expand-combo.js +3 -0
  329. package/lib/transforms/collapse-expand-combo.js.map +1 -1
  330. package/lib/transforms/collapse-expand-node.js +2 -0
  331. package/lib/transforms/collapse-expand-node.js.map +1 -1
  332. package/lib/transforms/index.d.ts +3 -0
  333. package/lib/transforms/index.js +3 -1
  334. package/lib/transforms/index.js.map +1 -1
  335. package/lib/transforms/position-radial-labels.d.ts +27 -0
  336. package/lib/transforms/position-radial-labels.js +54 -0
  337. package/lib/transforms/position-radial-labels.js.map +1 -0
  338. package/lib/transforms/process-parallel-edges.d.ts +7 -9
  339. package/lib/transforms/process-parallel-edges.js.map +1 -1
  340. package/lib/transforms/utils.d.ts +5 -5
  341. package/lib/transforms/utils.js +5 -5
  342. package/lib/types/element.d.ts +2 -1
  343. package/lib/utils/bbox.d.ts +12 -3
  344. package/lib/utils/bbox.js +19 -6
  345. package/lib/utils/bbox.js.map +1 -1
  346. package/lib/utils/data.d.ts +14 -0
  347. package/lib/utils/data.js +40 -0
  348. package/lib/utils/data.js.map +1 -1
  349. package/lib/utils/diff.d.ts +2 -1
  350. package/lib/utils/diff.js +3 -2
  351. package/lib/utils/diff.js.map +1 -1
  352. package/lib/utils/edge.js +3 -3
  353. package/lib/utils/edge.js.map +1 -1
  354. package/lib/utils/padding.d.ts +4 -4
  355. package/lib/utils/padding.js +4 -4
  356. package/lib/utils/point.d.ts +17 -5
  357. package/lib/utils/point.js +28 -8
  358. package/lib/utils/point.js.map +1 -1
  359. package/lib/utils/position.d.ts +8 -0
  360. package/lib/utils/position.js +12 -0
  361. package/lib/utils/position.js.map +1 -1
  362. package/lib/utils/prefix.d.ts +1 -1
  363. package/lib/utils/prefix.js +1 -1
  364. package/lib/utils/relation.d.ts +6 -4
  365. package/lib/utils/relation.js +10 -8
  366. package/lib/utils/relation.js.map +1 -1
  367. package/lib/utils/router/orth.d.ts +1 -1
  368. package/lib/utils/router/orth.js +25 -9
  369. package/lib/utils/router/orth.js.map +1 -1
  370. package/lib/utils/size.d.ts +3 -1
  371. package/lib/utils/size.js +3 -1
  372. package/lib/utils/size.js.map +1 -1
  373. package/lib/utils/transform.d.ts +5 -5
  374. package/lib/utils/transform.js +5 -5
  375. package/lib/utils/vector.d.ts +8 -0
  376. package/lib/utils/vector.js +14 -0
  377. package/lib/utils/vector.js.map +1 -1
  378. package/lib/version.d.ts +1 -1
  379. package/lib/version.js +1 -1
  380. package/package.json +10 -10
  381. package/src/behaviors/base-behavior.ts +10 -0
  382. package/src/behaviors/drag-canvas.ts +42 -3
  383. package/src/behaviors/hover-activate.ts +39 -9
  384. package/src/behaviors/scroll-canvas.ts +45 -4
  385. package/src/elements/combos/base-combo.ts +2 -2
  386. package/src/elements/combos/circle.ts +2 -2
  387. package/src/elements/edges/cubic-radial.ts +77 -0
  388. package/src/elements/edges/index.ts +2 -0
  389. package/src/elements/edges/line.ts +0 -2
  390. package/src/elements/edges/polyline.ts +2 -0
  391. package/src/elements/nodes/base-node.ts +3 -2
  392. package/src/elements/nodes/circle.ts +2 -2
  393. package/src/elements/nodes/ellipse.ts +2 -2
  394. package/src/elements/nodes/html.ts +4 -1
  395. package/src/elements/shapes/base-shape.ts +29 -14
  396. package/src/elements/shapes/polygon.ts +2 -2
  397. package/src/exports.ts +21 -7
  398. package/src/layouts/base-layout.ts +5 -0
  399. package/src/plugins/background/index.ts +1 -0
  400. package/src/plugins/base-plugin.ts +5 -0
  401. package/src/plugins/bubble-sets.ts +1 -0
  402. package/src/plugins/contextmenu/index.ts +1 -0
  403. package/src/plugins/grid-line.ts +1 -0
  404. package/src/plugins/history/index.ts +1 -0
  405. package/src/plugins/hull/index.ts +1 -0
  406. package/src/plugins/legend.ts +1 -0
  407. package/src/plugins/minimap/index.ts +8 -2
  408. package/src/plugins/snapline/index.ts +10 -0
  409. package/src/plugins/timebar.ts +1 -0
  410. package/src/plugins/toolbar/index.ts +1 -0
  411. package/src/plugins/tooltip.ts +15 -2
  412. package/src/plugins/watermark/index.ts +1 -0
  413. package/src/registry/build-in.ts +4 -0
  414. package/src/runtime/animation.ts +16 -11
  415. package/src/runtime/data.ts +20 -13
  416. package/src/runtime/element.ts +23 -11
  417. package/src/runtime/graph.ts +51 -22
  418. package/src/runtime/layout.ts +7 -0
  419. package/src/transforms/base-transform.ts +7 -0
  420. package/src/transforms/collapse-expand-combo.ts +2 -0
  421. package/src/transforms/collapse-expand-node.ts +3 -0
  422. package/src/transforms/index.ts +3 -0
  423. package/src/transforms/position-radial-labels.ts +76 -0
  424. package/src/transforms/process-parallel-edges.ts +7 -9
  425. package/src/transforms/utils.ts +5 -5
  426. package/src/types/element.ts +2 -1
  427. package/src/utils/bbox.ts +17 -4
  428. package/src/utils/data.ts +49 -0
  429. package/src/utils/diff.ts +8 -2
  430. package/src/utils/edge.ts +4 -4
  431. package/src/utils/padding.ts +4 -4
  432. package/src/utils/point.ts +27 -7
  433. package/src/utils/position.ts +12 -0
  434. package/src/utils/prefix.ts +1 -1
  435. package/src/utils/relation.ts +22 -9
  436. package/src/utils/router/orth.ts +29 -11
  437. package/src/utils/size.ts +3 -1
  438. package/src/utils/transform.ts +5 -5
  439. package/src/utils/vector.ts +13 -0
  440. package/src/version.ts +1 -1
@@ -19,6 +19,7 @@ import type {
19
19
  ElementType,
20
20
  ID,
21
21
  Node,
22
+ NodeLikeData,
22
23
  State,
23
24
  StyleIterationContext,
24
25
  } from '../types';
@@ -287,7 +288,6 @@ export class ElementController {
287
288
  const { animation, silence } = context;
288
289
 
289
290
  const { type = 'draw' } = context;
290
- const willRender = type === 'render';
291
291
 
292
292
  return this.context.animation!.animate(
293
293
  animation,
@@ -296,7 +296,7 @@ export class ElementController {
296
296
  : {
297
297
  before: () =>
298
298
  this.emit(
299
- new GraphLifeCycleEvent(GraphEvent.BEFORE_DRAW, { dataChanges, animation, render: willRender }),
299
+ new GraphLifeCycleEvent(GraphEvent.BEFORE_DRAW, { dataChanges, animation, render: type === 'render' }),
300
300
  context,
301
301
  ),
302
302
  beforeAnimate: (animation) =>
@@ -305,7 +305,7 @@ export class ElementController {
305
305
  this.emit(new AnimateEvent(GraphEvent.AFTER_ANIMATE, AnimationType.DRAW, animation, drawData), context),
306
306
  after: () =>
307
307
  this.emit(
308
- new GraphLifeCycleEvent(GraphEvent.AFTER_DRAW, { dataChanges, animation, render: willRender }),
308
+ new GraphLifeCycleEvent(GraphEvent.AFTER_DRAW, { dataChanges, animation, render: type === 'render' }),
309
309
  context,
310
310
  ),
311
311
  },
@@ -433,8 +433,24 @@ export class ElementController {
433
433
  });
434
434
  }
435
435
 
436
+ private getUpdateStageStyle(elementType: ElementType, datum: ElementDatum, context: DrawContext) {
437
+ const { stage = 'update' } = context;
438
+
439
+ // 优化 translate 阶段,直接返回 x, y, z,避免计算样式
440
+ // Optimize the translate stage, return x, y, z directly to avoid calculating style
441
+ if (stage === 'translate') {
442
+ if (elementType === 'node' || elementType === 'combo') {
443
+ const { style: { x = 0, y = 0, z = 0 } = {} } = datum as NodeLikeData;
444
+ return { x, y, z };
445
+ } else return {};
446
+ }
447
+
448
+ return this.getElementComputedStyle(elementType, datum);
449
+ }
450
+
436
451
  private updateElement(elementType: ElementType, datum: ElementDatum, context: DrawContext) {
437
452
  const id = idOf(datum);
453
+ const { stage = 'update' } = context;
438
454
 
439
455
  const element = this.getElement(id);
440
456
  if (!element) return () => null;
@@ -442,7 +458,7 @@ export class ElementController {
442
458
  this.emit(new ElementLifeCycleEvent(GraphEvent.BEFORE_ELEMENT_UPDATE, elementType, datum), context);
443
459
 
444
460
  const type = this.getElementType(elementType, datum);
445
- const style = this.getElementComputedStyle(elementType, datum);
461
+ const style = this.getUpdateStageStyle(elementType, datum, context);
446
462
 
447
463
  // 如果类型不同,需要先销毁原有元素,再创建新元素
448
464
  // If the type is different, you need to destroy the original element first, and then create a new element
@@ -454,8 +470,6 @@ export class ElementController {
454
470
  this.createElement(elementType, datum, { animation: false, silence: true });
455
471
  }
456
472
 
457
- const { stage = 'update' } = context;
458
-
459
473
  const exactStage = stage !== 'visibility' ? stage : style.visibility === 'hidden' ? 'hide' : 'show';
460
474
 
461
475
  // 避免立即将 visibility 设置为 hidden,导致元素不可见,而是在 after 阶段再设置
@@ -664,11 +678,9 @@ export class ElementController {
664
678
 
665
679
  const context = { animation, stage: 'expand', data: drawData } as const;
666
680
 
667
- // 将新增边添加到更新列表 / Add new edges to the update list
668
- add.edges.forEach((edge) => {
669
- const id = idOf(edge);
670
- if (!update.edges.has(id)) update.edges.set(id, edge);
671
- });
681
+ // 将新增节点/边添加到更新列表 / Add new nodes/edges to the update list
682
+ add.edges.forEach((edge) => update.edges.set(idOf(edge), edge));
683
+ add.nodes.forEach((node) => update.nodes.set(idOf(node), node));
672
684
 
673
685
  this.updateElements(update, context);
674
686
 
@@ -41,6 +41,7 @@ import type {
41
41
  } from '../types';
42
42
  import { isCollapsed } from '../utils/collapsibility';
43
43
  import { sizeOf } from '../utils/dom';
44
+ import { getSubgraphRelatedEdges } from '../utils/edge';
44
45
  import { GraphLifeCycleEvent, emit } from '../utils/event';
45
46
  import { idOf } from '../utils/id';
46
47
  import { format } from '../utils/print';
@@ -87,7 +88,7 @@ export class Graph extends EventEmitter {
87
88
  constructor(options: GraphOptions) {
88
89
  super();
89
90
  this.options = Object.assign({}, Graph.defaultOptions, options);
90
- this.setOptions(this.options);
91
+ this._setOptions(this.options, true);
91
92
  this.context.graph = this;
92
93
 
93
94
  // Listening window.resize to autoResize.
@@ -117,32 +118,28 @@ export class Graph extends EventEmitter {
117
118
  * @apiCategory option
118
119
  */
119
120
  public setOptions(options: GraphOptions): void {
120
- const { behaviors, combo, data, edge, height, layout, node, plugins, theme, transforms, width, cursor, renderer } =
121
- options;
121
+ this._setOptions(options, false);
122
+ }
122
123
 
123
- if (renderer) {
124
- const canvas = this.context.canvas;
125
- if (canvas) {
126
- this.emit(GraphEvent.BEFORE_RENDERER_CHANGE, { renderer: this.options.renderer });
127
- canvas.setRenderer(renderer);
128
- this.emit(GraphEvent.AFTER_RENDERER_CHANGE, { renderer });
129
- }
130
- }
124
+ private _setOptions(options: GraphOptions, isInit: boolean) {
125
+ this.updateCanvas(options);
131
126
 
127
+ if (isInit) {
128
+ const { data } = options;
129
+ if (data) this.addData(data);
130
+ return;
131
+ }
132
132
  Object.assign(this.options, options);
133
-
134
- if (cursor) this.context.canvas?.setCursor(cursor);
133
+ const { behaviors, combo, data, edge, layout, node, plugins, theme, transforms } = options;
135
134
  if (behaviors) this.setBehaviors(behaviors);
136
- if (combo) this.setCombo(combo);
137
135
  if (data) this.setData(data);
136
+ if (node) this.setNode(node);
138
137
  if (edge) this.setEdge(edge);
138
+ if (combo) this.setCombo(combo);
139
139
  if (layout) this.setLayout(layout);
140
- if (node) this.setNode(node);
141
140
  if (theme) this.setTheme(theme);
142
141
  if (plugins) this.setPlugins(plugins);
143
142
  if (transforms) this.setTransforms(transforms);
144
- if (isNumber(width) || isNumber(height))
145
- this.setSize(width ?? this.options.width ?? 0, height ?? this.options.height ?? 0);
146
143
  }
147
144
 
148
145
  /**
@@ -1015,7 +1012,15 @@ export class Graph extends EventEmitter {
1015
1012
  private async initCanvas() {
1016
1013
  if (this.context.canvas) return await this.context.canvas.ready;
1017
1014
 
1018
- const { container = 'container', width, height, renderer, cursor, background } = this.options;
1015
+ const {
1016
+ container = 'container',
1017
+ width,
1018
+ height,
1019
+ renderer,
1020
+ cursor,
1021
+ background,
1022
+ devicePixelRatio = window.devicePixelRatio ?? 1,
1023
+ } = this.options;
1019
1024
  if (container instanceof Canvas) {
1020
1025
  this.context.canvas = container;
1021
1026
  if (cursor) container.setCursor(cursor);
@@ -1034,6 +1039,7 @@ export class Graph extends EventEmitter {
1034
1039
  background,
1035
1040
  renderer,
1036
1041
  cursor,
1042
+ devicePixelRatio,
1037
1043
  });
1038
1044
 
1039
1045
  this.context.canvas = canvas;
@@ -1042,6 +1048,23 @@ export class Graph extends EventEmitter {
1042
1048
  }
1043
1049
  }
1044
1050
 
1051
+ private updateCanvas(options: GraphOptions) {
1052
+ const { renderer, cursor, height, width } = options;
1053
+ const canvas = this.context.canvas;
1054
+ if (!canvas) return;
1055
+
1056
+ if (renderer) {
1057
+ this.emit(GraphEvent.BEFORE_RENDERER_CHANGE, { renderer: this.options.renderer });
1058
+ canvas.setRenderer(renderer);
1059
+ this.emit(GraphEvent.AFTER_RENDERER_CHANGE, { renderer });
1060
+ }
1061
+
1062
+ if (cursor) canvas.setCursor(cursor);
1063
+
1064
+ if (isNumber(width) || isNumber(height))
1065
+ this.setSize(width ?? this.options.width ?? 0, height ?? this.options.height ?? 0);
1066
+ }
1067
+
1045
1068
  private initRuntime() {
1046
1069
  this.context.options = this.options;
1047
1070
  if (!this.context.batch) this.context.batch = new BatchController(this.context);
@@ -1621,7 +1644,7 @@ export class Graph extends EventEmitter {
1621
1644
  public async frontElement(id: ID | ID[]): Promise<void> {
1622
1645
  const ids = Array.isArray(id) ? id : [id];
1623
1646
  const { model, element } = this.context;
1624
- const config: Record<ID, number> = {};
1647
+ const zIndexes: Record<ID, number> = {};
1625
1648
 
1626
1649
  ids.map((_id) => {
1627
1650
  const zIndex = element!.getFrontZIndex(_id);
@@ -1631,12 +1654,18 @@ export class Graph extends EventEmitter {
1631
1654
  const combos = [ancestor, ...model.getDescendantsData(idOf(ancestor))];
1632
1655
  const delta = zIndex - element!.getElementZIndex(_id);
1633
1656
  combos.forEach((combo) => {
1634
- config[idOf(combo)] = this.getElementZIndex(idOf(combo)) + delta;
1657
+ zIndexes[idOf(combo)] = this.getElementZIndex(idOf(combo)) + delta;
1658
+ });
1659
+
1660
+ const { internal } = getSubgraphRelatedEdges(combos.map(idOf), (id) => model.getRelatedEdgesData(id));
1661
+ internal.forEach((edge) => {
1662
+ const edgeId = idOf(edge);
1663
+ zIndexes[edgeId] = this.getElementZIndex(edgeId) + delta;
1635
1664
  });
1636
- } else config[_id] = zIndex;
1665
+ } else zIndexes[_id] = zIndex;
1637
1666
  });
1638
1667
 
1639
- await this.setElementZIndex(config);
1668
+ await this.setElementZIndex(zIndexes);
1640
1669
  }
1641
1670
 
1642
1671
  /**
@@ -69,6 +69,13 @@ export class LayoutController {
69
69
  }
70
70
  }
71
71
  emit(graph, new GraphLifeCycleEvent(GraphEvent.AFTER_LAYOUT));
72
+ this.transformDataAfterLayout();
73
+ }
74
+
75
+ private transformDataAfterLayout() {
76
+ const transforms = this.context.transform.getTransformInstance();
77
+
78
+ Object.values(transforms).forEach((transform) => transform.afterLayout());
72
79
  }
73
80
 
74
81
  /**
@@ -5,8 +5,15 @@ import type { DrawData } from './types';
5
5
 
6
6
  export type BaseTransformOptions = CustomBehaviorOption;
7
7
 
8
+ /**
9
+ * <zh/> 数据转换的基类
10
+ *
11
+ * <en/> Base class for data transforms
12
+ */
8
13
  export abstract class BaseTransform<T extends BaseTransformOptions = BaseTransformOptions> extends BaseExtension<T> {
9
14
  public beforeDraw(data: DrawData, context: DrawContext): DrawData {
10
15
  return data;
11
16
  }
17
+
18
+ public afterLayout() {}
12
19
  }
@@ -1,3 +1,4 @@
1
+ import { COMBO_KEY } from '../constants';
1
2
  import type { DrawContext } from '../runtime/element';
2
3
  import type { ComboData } from '../spec';
3
4
  import { isCollapsed } from '../utils/collapsibility';
@@ -16,6 +17,7 @@ import { reassignTo } from './utils';
16
17
  export class CollapseExpandCombo extends BaseTransform {
17
18
  public beforeDraw(input: DrawData, context: DrawContext): DrawData {
18
19
  if (context.stage === 'visibility') return input;
20
+ if (!this.context.model.model.hasTreeStructure(COMBO_KEY)) return input;
19
21
 
20
22
  const { model } = this.context;
21
23
  const { add, update } = input;
@@ -47,6 +47,9 @@ export class CollapseExpandNode extends BaseTransform {
47
47
 
48
48
  public beforeDraw(input: DrawData): DrawData {
49
49
  const { graph, model } = this.context;
50
+
51
+ if (!model.model.hasTreeStructure(TREE_KEY)) return input;
52
+
50
53
  const {
51
54
  add: { nodes: nodesToAdd, edges: edgesToAdd },
52
55
  update: { nodes: nodesToUpdate },
@@ -3,7 +3,10 @@ export { BaseTransform } from './base-transform';
3
3
  export { CollapseExpandCombo } from './collapse-expand-combo';
4
4
  export { CollapseExpandNode } from './collapse-expand-node';
5
5
  export { GetEdgeActualEnds } from './get-edge-actual-ends';
6
+ export { PositionRadialLabels } from './position-radial-labels';
6
7
  export { ProcessParallelEdges } from './process-parallel-edges';
7
8
  export { UpdateRelatedEdge } from './update-related-edge';
8
9
 
9
10
  export type { BaseTransformOptions } from './base-transform';
11
+ export type { PositionRadialLabelsOptions } from './position-radial-labels';
12
+ export type { ProcessParallelEdgesOptions } from './process-parallel-edges';
@@ -0,0 +1,76 @@
1
+ import { rad2deg } from '@antv/g';
2
+ import type { RuntimeContext } from '../runtime/types';
3
+ import type { NodeData } from '../spec';
4
+ import { idOf } from '../utils/id';
5
+ import { positionOf } from '../utils/position';
6
+ import { parseSize } from '../utils/size';
7
+ import { rad, subtract } from '../utils/vector';
8
+ import type { BaseTransformOptions } from './base-transform';
9
+ import { BaseTransform } from './base-transform';
10
+
11
+ /**
12
+ * <zh/> 根据径向布局自动调整节点标签样式的配置项
13
+ *
14
+ * <en/> Options for automatically adjusting the style of node labels according to the radial layout
15
+ */
16
+ export interface PositionRadialLabelsOptions extends BaseTransformOptions {
17
+ /**
18
+ * <zh/> 偏移量
19
+ *
20
+ * <en/> Offset
21
+ */
22
+ offset?: number;
23
+ }
24
+
25
+ /**
26
+ * <zh/> 根据径向布局自动调整节点标签样式,包括位置和旋转角度
27
+ *
28
+ * <en/> Automatically adjust the style of node labels according to the radial layout, including position and rotation angle
29
+ */
30
+ export class PositionRadialLabels extends BaseTransform<PositionRadialLabelsOptions> {
31
+ static defaultOptions: Partial<PositionRadialLabelsOptions> = {
32
+ offset: 5,
33
+ };
34
+
35
+ constructor(context: RuntimeContext, options: PositionRadialLabelsOptions) {
36
+ super(context, Object.assign({}, PositionRadialLabels.defaultOptions, options));
37
+ }
38
+
39
+ private get ref(): NodeData {
40
+ return this.context.model.getRootsData()[0];
41
+ }
42
+
43
+ public afterLayout() {
44
+ const refPoint = positionOf(this.ref);
45
+
46
+ const { graph, model } = this.context;
47
+ const data = model.getData();
48
+
49
+ data.nodes?.forEach((datum) => {
50
+ if (idOf(datum) === idOf(this.ref)) return;
51
+
52
+ const radian = rad(subtract(positionOf(datum), refPoint));
53
+ const isLeft = Math.abs(radian) > Math.PI / 2;
54
+
55
+ const isLeaf = !datum.children || datum.children.length === 0;
56
+ const nodeHalfWidth = parseSize(graph.getElementRenderStyle(idOf(datum)).size)[0] / 2;
57
+ const offset = (isLeaf ? 1 : -1) * (nodeHalfWidth + this.options.offset);
58
+
59
+ const translate = `translate(${offset * Math.cos(radian)},${offset * Math.sin(radian)})`;
60
+ const rotate = `rotate(${isLeft ? rad2deg(radian) + 180 : rad2deg(radian)}deg)`;
61
+
62
+ model.updateNodeData([
63
+ {
64
+ id: idOf(datum),
65
+ style: {
66
+ labelTextAlign: isLeft === isLeaf ? 'right' : 'left',
67
+ labelTextBaseline: 'middle',
68
+ labelTransform: `${translate} ${rotate}`,
69
+ },
70
+ },
71
+ ]);
72
+ });
73
+
74
+ graph.draw();
75
+ }
76
+ }
@@ -26,16 +26,14 @@ const CUBIC_LOOP_PLACEMENTS: LoopPlacement[] = [
26
26
 
27
27
  export interface ProcessParallelEdgesOptions extends BaseTransformOptions {
28
28
  /**
29
- * <zh/> 处理模式,默认为捆绑
29
+ * <zh/> 处理模式
30
+ * - `'merge'`: 将平行边合并为一条边,适用于不需要区分平行边的情况
31
+ * - '`bundle`': 每条边都会与其他所有平行边捆绑在一起,并通过改变曲率与其他边分开。如果一组平行边的数量是奇数,那么中心的边将被绘制为直线,其他的边将被绘制为曲线
30
32
  *
31
- * <en/> Processing mode, default is bundle
32
- * @remarks
33
- * <zh/>
34
- * - merge: 将平行边合并为一条边,适用于不需要区分平行边的情况
35
- * - bundle: 每条边都会与其他所有平行边捆绑在一起,并通过改变曲率与其他边分开。如果一组平行边的数量是奇数,那么中心的边将被绘制为直线,其他的边将被绘制为曲线
36
- * <en/>
37
- * - merge: Merge parallel edges into one edge which is suitable for cases where parallel edges do not need to be distinguished
38
- * - bundle: Each edge will be bundled with all other parallel edges and separated from them by varying the curvature. If the number of parallel edges in a group is odd, the central edge will be drawn as a straight line, and the others will be drawn as curves
33
+ * <en/> Processing mode
34
+ * - '`merge`': Merge parallel edges into one edge which is suitable for cases where parallel edges do not need to be distinguished
35
+ * - '`bundle`': Each edge will be bundled with all other parallel edges and separated from them by varying the curvature. If the number of parallel edges in a group is odd, the central edge will be drawn as a straight line, and the others will be drawn as curves
36
+ * @defaultValue 'bundle'
39
37
  */
40
38
  mode: 'bundle' | 'merge';
41
39
  /**
@@ -6,11 +6,11 @@ import type { DrawData, ProcedureData } from './types';
6
6
  * <zh/> 重新分配绘制任务
7
7
  *
8
8
  * <en/> Reassign drawing tasks
9
- * @param input - <zh>绘制数据 | <en>DrawData
10
- * @param type - <zh>类型 | <en>type
11
- * @param elementType - <zh>元素类型 | <en>element type
12
- * @param datum - <zh>数据 | <en>data
13
- * @param overwrite - <zh>是否覆盖现有数据 | <en>whether to overwrite existing data
9
+ * @param input - <zh/>绘制数据 | <en/>DrawData
10
+ * @param type - <zh/>类型 | <en/>type
11
+ * @param elementType - <zh/>元素类型 | <en/>element type
12
+ * @param datum - <zh/>数据 | <en/>data
13
+ * @param overwrite - <zh/>是否覆盖现有数据 | <en/>whether to overwrite existing data
14
14
  */
15
15
  export function reassignTo(
16
16
  input: DrawData,
@@ -29,13 +29,14 @@ export interface Node extends DisplayObject, ElementHooks, ElementMethods {
29
29
  *
30
30
  * <en/> Get the intersection point
31
31
  * @param point - <zh/> 外部位置 | <en/> external position
32
+ * @param useExtendedLine - <zh/> 是否使用延长线 | <en/> whether to use the extended line
32
33
  * @returns <zh/> 交点位置 | <en/> intersection point
33
34
  * @remarks
34
35
  * <zh/> 给定一个外部位置,返回当前节点与该位置的连边与节点的交点位置
35
36
  *
36
37
  * <en/> Given an external position, return the intersection point of the edge between the current node and the position and the node
37
38
  */
38
- getIntersectPoint(point: Point): Point;
39
+ getIntersectPoint(point: Point, useExtendedLine?: boolean): Point;
39
40
  }
40
41
 
41
42
  /**
package/src/utils/bbox.ts CHANGED
@@ -150,6 +150,19 @@ export function isPointOutsideBBox(point: Point, bbox: AABB) {
150
150
  return !isPointInBBox(point, bbox);
151
151
  }
152
152
 
153
+ /**
154
+ * <zh/> 判断点是否位于包围盒中心
155
+ *
156
+ * <en/> When the point is at the center of the bounding box
157
+ * @param point - <zh/> 点 | <en/> Point
158
+ * @param bbox - <zh/> 包围盒 | <en/> Bounding box
159
+ * @returns <zh/> 如果点在包围盒中心返回 true,否则返回 false | <en/> Returns true if the point is at the center of the bounding box, false otherwise
160
+ */
161
+ export function isPointBBoxCenter(point: Point, bbox: AABB) {
162
+ const { center } = bbox;
163
+ return point[0] === center[0] && point[1] === center[1];
164
+ }
165
+
153
166
  /**
154
167
  * <zh/> 获取包围盒上离点 `p` 最近的边
155
168
  *
@@ -158,7 +171,7 @@ export function isPointOutsideBBox(point: Point, bbox: AABB) {
158
171
  * @param p - <zh/> 点 | <en/> Point
159
172
  * @returns <zh/> 离点 `p` 最近的边 | <en/> The side nearest to the point `p`
160
173
  */
161
- export function getNearestSideToPoint(bbox: AABB, p: Point): 'left' | 'right' | 'top' | 'bottom' {
174
+ export function getNearestBoundarySide(p: Point, bbox: AABB): 'left' | 'right' | 'top' | 'bottom' {
162
175
  const [x, y] = p;
163
176
  const [minX, minY] = bbox.min;
164
177
  const [maxX, maxY] = bbox.max;
@@ -171,17 +184,17 @@ export function getNearestSideToPoint(bbox: AABB, p: Point): 'left' | 'right' |
171
184
  }
172
185
 
173
186
  /**
174
- * <zh/> 获取包围盒上离点 `p` 最近的点
187
+ * <zh/> 获取包围盒上离点 `p` 最近的边界点
175
188
  *
176
189
  * <en/> Get a point on the boundary nearest to the point `p`
177
190
  * @param bbox - <zh/> 包围盒 | <en/> Bounding box
178
191
  * @param p - <zh/> 点 | <en/> Point
179
192
  * @returns <zh/> 离点 `p` 最近的点 | <en/> The point nearest to the point `p`
180
193
  */
181
- export function getNearestPointToPoint(bbox: AABB, p: Point): Point {
194
+ export function getNearestBoundaryPoint(p: Point, bbox: AABB): Point {
182
195
  const ref = clone(p);
183
196
  if (isPointInBBox(p, bbox)) {
184
- const side = getNearestSideToPoint(bbox, p);
197
+ const side = getNearestBoundarySide(p, bbox);
185
198
  switch (side) {
186
199
  case 'left':
187
200
  ref[0] = bbox.min[0];
package/src/utils/data.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { get } from '@antv/util';
2
2
  import type { ComboData, EdgeData, GraphData, NodeData } from '../spec';
3
+ import type { ElementDatum, ID } from '../types';
3
4
 
4
5
  /**
5
6
  * <zh/> 合并两个 节点/边/Combo 的数据
@@ -62,3 +63,51 @@ export function cloneElementData<T extends NodeData | EdgeData | ComboData>(data
62
63
  export function isEmptyData(data: GraphData) {
63
64
  return !get(data, ['nodes', 'length']) && !get(data, ['edges', 'length']) && !get(data, ['combos', 'length']);
64
65
  }
66
+
67
+ /**
68
+ * <zh/> 判断两个元素数据是否相等
69
+ *
70
+ * <en/> Determine if two element data are equal
71
+ * @param original - <zh/> 原始数据 | <en/> original data
72
+ * @param modified - <zh/> 修改后的数据 | <en/> modified data
73
+ * @returns <zh/> 是否相等 | <en/> is equal
74
+ * @remarks
75
+ * <zh/> 相比于 isEqual,这个方法不会比较更下层的数据
76
+ *
77
+ * <en/> Compared to isEqual, this method does not compare data at a lower level
78
+ */
79
+ export function isElementDataEqual(original: Partial<ElementDatum> = {}, modified: Partial<ElementDatum> = {}) {
80
+ const {
81
+ states: originalStates = [],
82
+ data: originalData = {},
83
+ style: originalStyle = {},
84
+ children: originalChildren = [],
85
+ ...originalAttrs
86
+ } = original;
87
+ const {
88
+ states: modifiedStates = [],
89
+ data: modifiedData = {},
90
+ style: modifiedStyle = {},
91
+ children: modifiedChildren = [],
92
+ ...modifiedAttrs
93
+ } = modified;
94
+
95
+ const isArrayEqual = (arr1: unknown[], arr2: unknown[]) => {
96
+ if (arr1.length !== arr2.length) return false;
97
+ return arr1.every((item, index) => item === arr2[index]);
98
+ };
99
+ const isObjectEqual = (obj1: Record<string, unknown>, obj2: Record<string, unknown>) => {
100
+ const keys1 = Object.keys(obj1);
101
+ const keys2 = Object.keys(obj2);
102
+ if (keys1.length !== keys2.length) return false;
103
+ return keys1.every((key) => obj1[key] === obj2[key]);
104
+ };
105
+
106
+ if (!isObjectEqual(originalAttrs, modifiedAttrs)) return false;
107
+ if (!isArrayEqual(originalChildren as ID[], modifiedChildren as ID[])) return false;
108
+ if (!isArrayEqual(originalStates, modifiedStates)) return false;
109
+ if (!isObjectEqual(originalData, modifiedData)) return false;
110
+ if (!isObjectEqual(originalStyle, modifiedStyle)) return false;
111
+
112
+ return true;
113
+ }
package/src/utils/diff.ts CHANGED
@@ -7,9 +7,15 @@ import { isEqual } from '@antv/util';
7
7
  * @param original - <zh/> 原始数组 | <en/> original array
8
8
  * @param modified - <zh/> 修改后的数组 | <en/> modified array
9
9
  * @param key - <zh/> 比较的 key | <en/> key to compare
10
+ * @param comparator - <zh/> 比较函数 | <en/> compare function
10
11
  * @returns <zh/> 数组差异 | <en/> array diff
11
12
  */
12
- export function arrayDiff<T>(original: T[], modified: T[], key: (d: T) => string | number) {
13
+ export function arrayDiff<T>(
14
+ original: T[],
15
+ modified: T[],
16
+ key: (d: T) => string | number,
17
+ comparator: (a?: T, b?: T) => boolean = isEqual,
18
+ ) {
13
19
  const originalMap = new Map(original.map((d) => [key(d), d]));
14
20
  const modifiedMap = new Map(modified.map((d) => [key(d), d]));
15
21
 
@@ -23,7 +29,7 @@ export function arrayDiff<T>(original: T[], modified: T[], key: (d: T) => string
23
29
 
24
30
  modifiedSet.forEach((key) => {
25
31
  if (originalSet.has(key)) {
26
- if (!isEqual(originalMap.get(key), modifiedMap.get(key))) {
32
+ if (!comparator(originalMap.get(key), modifiedMap.get(key))) {
27
33
  update.push(modifiedMap.get(key)!);
28
34
  } else {
29
35
  keep.push(modifiedMap.get(key)!);
package/src/utils/edge.ts CHANGED
@@ -15,7 +15,7 @@ import type {
15
15
  Size,
16
16
  Vector2,
17
17
  } from '../types';
18
- import { getBBoxHeight, getBBoxSize, getBBoxWidth, getNearestSideToPoint, getNodeBBox } from './bbox';
18
+ import { getBBoxHeight, getBBoxSize, getBBoxWidth, getNearestBoundarySide, getNodeBBox } from './bbox';
19
19
  import { isCollapsed } from './collapsibility';
20
20
  import { getAllPorts, getNodeConnectionPoint, getPortConnectionPoint, getPortPosition } from './element';
21
21
  import { idOf } from './id';
@@ -481,7 +481,7 @@ export function getPolylineLoopControlPoints(node: Node, sourcePoint: Point, tar
481
481
 
482
482
  // 1. 起点和终点相同 | The start and end points are the same
483
483
  if (isEqual(sourcePoint, targetPoint)) {
484
- const side = getNearestSideToPoint(bbox, sourcePoint);
484
+ const side = getNearestBoundarySide(sourcePoint, bbox);
485
485
  switch (side) {
486
486
  case 'left':
487
487
  controlPoints.push([sourcePoint[0] - dist, sourcePoint[1]]);
@@ -505,8 +505,8 @@ export function getPolylineLoopControlPoints(node: Node, sourcePoint: Point, tar
505
505
  break;
506
506
  }
507
507
  } else {
508
- const sourceSide = getNearestSideToPoint(bbox, sourcePoint);
509
- const targetSide = getNearestSideToPoint(bbox, targetPoint);
508
+ const sourceSide = getNearestBoundarySide(sourcePoint, bbox);
509
+ const targetSide = getNearestBoundarySide(targetPoint, bbox);
510
510
  // 2. 起点与终点同边 | The start and end points are on the same side
511
511
  if (sourceSide === targetSide) {
512
512
  const side = sourceSide;
@@ -1,11 +1,11 @@
1
1
  import type { Padding, STDPadding } from '../types/padding';
2
2
 
3
3
  /**
4
- * <zh> 解析 padding
4
+ * <zh/> 解析 padding
5
5
  *
6
- * <en> parse padding
7
- * @param padding - <zh> padding | <en> padding
8
- * @returns <zh> 标准 padding | <en> standard padding
6
+ * <en/> parse padding
7
+ * @param padding - <zh/> padding | <en/> padding
8
+ * @returns <zh/> 标准 padding | <en/> standard padding
9
9
  */
10
10
  export function parsePadding(padding: Padding = 0): STDPadding {
11
11
  if (Array.isArray(padding)) {