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

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 (615) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/dist/lib/behaviors/brush-select.d.ts +104 -0
  3. package/dist/lib/behaviors/click-element.d.ts +77 -0
  4. package/dist/lib/behaviors/drag-element-force.d.ts +14 -0
  5. package/dist/lib/behaviors/drag-element.d.ts +13 -12
  6. package/dist/lib/behaviors/index.d.ts +8 -0
  7. package/dist/lib/behaviors/lasso-select.d.ts +20 -0
  8. package/dist/lib/behaviors/types.d.ts +1 -0
  9. package/dist/lib/constants/change.d.ts +1 -1
  10. package/dist/lib/constants/events/graph.d.ts +9 -7
  11. package/dist/lib/constants/registry.d.ts +3 -1
  12. package/dist/lib/elements/combos/base-combo.d.ts +43 -6
  13. package/dist/lib/elements/combos/circle.d.ts +8 -12
  14. package/dist/lib/elements/combos/rect.d.ts +5 -9
  15. package/dist/lib/elements/edges/base-edge.d.ts +64 -10
  16. package/dist/lib/elements/edges/cubic-horizontal.d.ts +2 -2
  17. package/dist/lib/elements/edges/cubic-vertical.d.ts +2 -2
  18. package/dist/lib/elements/edges/cubic.d.ts +2 -2
  19. package/dist/lib/elements/edges/polyline.d.ts +2 -2
  20. package/dist/lib/elements/edges/quadratic.d.ts +2 -2
  21. package/dist/lib/elements/nodes/base-node.d.ts +104 -13
  22. package/dist/lib/elements/nodes/circle.d.ts +5 -8
  23. package/dist/lib/elements/nodes/diamond.d.ts +2 -4
  24. package/dist/lib/elements/nodes/ellipse.d.ts +5 -8
  25. package/dist/lib/elements/nodes/hexagon.d.ts +6 -9
  26. package/dist/lib/elements/nodes/image.d.ts +9 -11
  27. package/dist/lib/elements/nodes/polygon.d.ts +9 -8
  28. package/dist/lib/elements/nodes/rect.d.ts +2 -3
  29. package/dist/lib/elements/nodes/star.d.ts +7 -10
  30. package/dist/lib/elements/nodes/triangle.d.ts +7 -10
  31. package/dist/lib/exports.d.ts +4 -2
  32. package/dist/lib/layouts/index.d.ts +1 -1
  33. package/dist/lib/layouts/types.d.ts +6 -6
  34. package/dist/lib/palettes/index.d.ts +1 -0
  35. package/dist/lib/plugins/history/events.d.ts +21 -0
  36. package/dist/lib/plugins/history/index.d.ts +82 -0
  37. package/dist/lib/plugins/history/utils.d.ts +31 -0
  38. package/dist/lib/plugins/hull/index.d.ts +59 -0
  39. package/dist/lib/plugins/hull/shape.d.ts +49 -0
  40. package/dist/lib/plugins/hull/util.d.ts +12 -0
  41. package/dist/lib/plugins/index.d.ts +4 -0
  42. package/dist/lib/registry/extension/index.d.ts +1 -1
  43. package/dist/lib/registry/types.d.ts +4 -0
  44. package/dist/lib/runtime/batch.d.ts +11 -0
  45. package/dist/lib/runtime/behavior.d.ts +1 -1
  46. package/dist/lib/runtime/canvas.d.ts +13 -3
  47. package/dist/lib/runtime/data.d.ts +4 -4
  48. package/dist/lib/runtime/element.d.ts +3 -19
  49. package/dist/lib/runtime/graph.d.ts +40 -2
  50. package/dist/lib/runtime/layout.d.ts +5 -11
  51. package/dist/lib/runtime/plugin.d.ts +1 -1
  52. package/dist/lib/runtime/transform.d.ts +11 -0
  53. package/dist/lib/runtime/types.d.ts +14 -0
  54. package/dist/lib/spec/index.d.ts +1 -0
  55. package/dist/lib/spec/spec.d.ts +7 -0
  56. package/dist/lib/spec/transform.d.ts +12 -0
  57. package/dist/lib/transforms/arrange-draw-order.d.ts +10 -0
  58. package/dist/lib/transforms/base-transform.d.ts +7 -0
  59. package/dist/lib/transforms/collapse-expand-combo.d.ts +10 -0
  60. package/dist/lib/transforms/index.d.ts +6 -0
  61. package/dist/lib/transforms/process-parallel-edges.d.ts +84 -0
  62. package/dist/lib/transforms/types.d.ts +20 -0
  63. package/dist/lib/transforms/update-related-edge.d.ts +9 -0
  64. package/dist/lib/types/canvas.d.ts +1 -1
  65. package/dist/lib/types/change.d.ts +27 -10
  66. package/dist/lib/types/element.d.ts +6 -140
  67. package/dist/lib/types/node.d.ts +3 -3
  68. package/dist/lib/types/point.d.ts +1 -0
  69. package/dist/lib/utils/animation.d.ts +1 -1
  70. package/dist/lib/utils/behaviors/brush.d.ts +19 -0
  71. package/dist/lib/utils/behaviors/lasso.d.ts +13 -0
  72. package/dist/lib/utils/behaviors/utils.d.ts +21 -0
  73. package/dist/lib/utils/change.d.ts +9 -1
  74. package/dist/lib/utils/combo.d.ts +5 -4
  75. package/dist/lib/utils/edge.d.ts +11 -0
  76. package/dist/lib/utils/event/events.d.ts +1 -1
  77. package/dist/lib/utils/extension.d.ts +1 -1
  78. package/dist/lib/utils/id.d.ts +3 -8
  79. package/dist/lib/utils/line.d.ts +21 -0
  80. package/dist/lib/utils/path.d.ts +35 -0
  81. package/dist/lib/utils/point.d.ts +74 -20
  82. package/dist/lib/utils/polygon.d.ts +17 -0
  83. package/dist/lib/utils/position.d.ts +14 -1
  84. package/dist/lib/utils/prefix.d.ts +1 -1
  85. package/dist/lib/utils/shortcut.d.ts +1 -0
  86. package/dist/lib/utils/vector.d.ts +3 -2
  87. package/esm/behaviors/brush-select.d.ts +104 -0
  88. package/esm/behaviors/brush-select.js +199 -0
  89. package/esm/behaviors/brush-select.js.map +1 -0
  90. package/esm/behaviors/click-element.d.ts +77 -0
  91. package/esm/behaviors/click-element.js +108 -0
  92. package/esm/behaviors/click-element.js.map +1 -0
  93. package/esm/behaviors/drag-element-force.d.ts +14 -0
  94. package/esm/behaviors/drag-element-force.js +55 -0
  95. package/esm/behaviors/drag-element-force.js.map +1 -0
  96. package/esm/behaviors/drag-element.d.ts +13 -12
  97. package/esm/behaviors/drag-element.js +17 -9
  98. package/esm/behaviors/drag-element.js.map +1 -1
  99. package/esm/behaviors/hover-element.js +2 -2
  100. package/esm/behaviors/hover-element.js.map +1 -1
  101. package/esm/behaviors/index.d.ts +8 -0
  102. package/esm/behaviors/index.js +4 -0
  103. package/esm/behaviors/index.js.map +1 -1
  104. package/esm/behaviors/lasso-select.d.ts +20 -0
  105. package/esm/behaviors/lasso-select.js +79 -0
  106. package/esm/behaviors/lasso-select.js.map +1 -0
  107. package/esm/behaviors/types.d.ts +1 -0
  108. package/esm/constants/change.d.ts +1 -1
  109. package/esm/constants/change.js +12 -12
  110. package/esm/constants/change.js.map +1 -1
  111. package/esm/constants/events/graph.d.ts +9 -7
  112. package/esm/constants/events/graph.js +8 -8
  113. package/esm/constants/events/graph.js.map +1 -1
  114. package/esm/constants/registry.d.ts +3 -1
  115. package/esm/constants/registry.js +2 -0
  116. package/esm/constants/registry.js.map +1 -1
  117. package/esm/elements/combos/base-combo.d.ts +43 -6
  118. package/esm/elements/combos/base-combo.js.map +1 -1
  119. package/esm/elements/combos/circle.d.ts +8 -12
  120. package/esm/elements/combos/circle.js.map +1 -1
  121. package/esm/elements/combos/rect.d.ts +5 -9
  122. package/esm/elements/combos/rect.js.map +1 -1
  123. package/esm/elements/edges/base-edge.d.ts +64 -10
  124. package/esm/elements/edges/base-edge.js.map +1 -1
  125. package/esm/elements/edges/cubic-horizontal.d.ts +2 -2
  126. package/esm/elements/edges/cubic-vertical.d.ts +2 -2
  127. package/esm/elements/edges/cubic.d.ts +2 -2
  128. package/esm/elements/edges/polyline.d.ts +2 -2
  129. package/esm/elements/edges/quadratic.d.ts +2 -2
  130. package/esm/elements/nodes/base-node.d.ts +104 -13
  131. package/esm/elements/nodes/base-node.js +4 -1
  132. package/esm/elements/nodes/base-node.js.map +1 -1
  133. package/esm/elements/nodes/circle.d.ts +5 -8
  134. package/esm/elements/nodes/circle.js.map +1 -1
  135. package/esm/elements/nodes/diamond.d.ts +2 -4
  136. package/esm/elements/nodes/diamond.js +2 -2
  137. package/esm/elements/nodes/diamond.js.map +1 -1
  138. package/esm/elements/nodes/ellipse.d.ts +5 -8
  139. package/esm/elements/nodes/ellipse.js +1 -1
  140. package/esm/elements/nodes/ellipse.js.map +1 -1
  141. package/esm/elements/nodes/hexagon.d.ts +6 -9
  142. package/esm/elements/nodes/hexagon.js.map +1 -1
  143. package/esm/elements/nodes/image.d.ts +9 -11
  144. package/esm/elements/nodes/image.js.map +1 -1
  145. package/esm/elements/nodes/polygon.d.ts +9 -8
  146. package/esm/elements/nodes/polygon.js +4 -1
  147. package/esm/elements/nodes/polygon.js.map +1 -1
  148. package/esm/elements/nodes/rect.d.ts +2 -3
  149. package/esm/elements/nodes/rect.js.map +1 -1
  150. package/esm/elements/nodes/star.d.ts +7 -10
  151. package/esm/elements/nodes/star.js.map +1 -1
  152. package/esm/elements/nodes/triangle.d.ts +7 -10
  153. package/esm/elements/nodes/triangle.js.map +1 -1
  154. package/esm/exports.d.ts +4 -2
  155. package/esm/exports.js +2 -1
  156. package/esm/exports.js.map +1 -1
  157. package/esm/layouts/index.d.ts +1 -1
  158. package/esm/layouts/index.js +1 -1
  159. package/esm/layouts/index.js.map +1 -1
  160. package/esm/layouts/types.d.ts +6 -6
  161. package/esm/palettes/index.d.ts +1 -0
  162. package/esm/palettes/index.js +12 -0
  163. package/esm/palettes/index.js.map +1 -1
  164. package/esm/plugins/history/events.d.ts +21 -0
  165. package/esm/plugins/history/events.js +16 -0
  166. package/esm/plugins/history/events.js.map +1 -0
  167. package/esm/plugins/history/index.d.ts +82 -0
  168. package/esm/plugins/history/index.js +168 -0
  169. package/esm/plugins/history/index.js.map +1 -0
  170. package/esm/plugins/history/utils.d.ts +31 -0
  171. package/esm/plugins/history/utils.js +79 -0
  172. package/esm/plugins/history/utils.js.map +1 -0
  173. package/esm/plugins/hull/index.d.ts +59 -0
  174. package/esm/plugins/hull/index.js +107 -0
  175. package/esm/plugins/hull/index.js.map +1 -0
  176. package/esm/plugins/hull/shape.d.ts +49 -0
  177. package/esm/plugins/hull/shape.js +35 -0
  178. package/esm/plugins/hull/shape.js.map +1 -0
  179. package/esm/plugins/hull/util.d.ts +12 -0
  180. package/esm/plugins/hull/util.js +203 -0
  181. package/esm/plugins/hull/util.js.map +1 -0
  182. package/esm/plugins/index.d.ts +4 -0
  183. package/esm/plugins/index.js +2 -0
  184. package/esm/plugins/index.js.map +1 -1
  185. package/esm/plugins/legend.js.map +1 -1
  186. package/esm/registry/build-in.js +19 -4
  187. package/esm/registry/build-in.js.map +1 -1
  188. package/esm/registry/extension/index.d.ts +1 -1
  189. package/esm/registry/index.js +1 -0
  190. package/esm/registry/index.js.map +1 -1
  191. package/esm/registry/types.d.ts +4 -0
  192. package/esm/runtime/batch.d.ts +11 -0
  193. package/esm/runtime/batch.js +31 -0
  194. package/esm/runtime/batch.js.map +1 -0
  195. package/esm/runtime/behavior.d.ts +1 -1
  196. package/esm/runtime/behavior.js.map +1 -1
  197. package/esm/runtime/canvas.d.ts +13 -3
  198. package/esm/runtime/canvas.js +36 -12
  199. package/esm/runtime/canvas.js.map +1 -1
  200. package/esm/runtime/data.d.ts +4 -4
  201. package/esm/runtime/data.js +23 -25
  202. package/esm/runtime/data.js.map +1 -1
  203. package/esm/runtime/element.d.ts +3 -19
  204. package/esm/runtime/element.js +16 -137
  205. package/esm/runtime/element.js.map +1 -1
  206. package/esm/runtime/graph.d.ts +40 -2
  207. package/esm/runtime/graph.js +57 -1
  208. package/esm/runtime/graph.js.map +1 -1
  209. package/esm/runtime/layout.d.ts +5 -11
  210. package/esm/runtime/layout.js +29 -75
  211. package/esm/runtime/layout.js.map +1 -1
  212. package/esm/runtime/plugin.d.ts +1 -1
  213. package/esm/runtime/plugin.js.map +1 -1
  214. package/esm/runtime/transform.d.ts +11 -0
  215. package/esm/runtime/transform.js +20 -0
  216. package/esm/runtime/transform.js.map +1 -0
  217. package/esm/runtime/types.d.ts +14 -0
  218. package/esm/spec/index.d.ts +1 -0
  219. package/esm/spec/spec.d.ts +7 -0
  220. package/esm/spec/transform.d.ts +12 -0
  221. package/esm/spec/transform.js +2 -0
  222. package/esm/spec/transform.js.map +1 -0
  223. package/esm/themes/base.js +9 -1
  224. package/esm/themes/base.js.map +1 -1
  225. package/esm/transforms/arrange-draw-order.d.ts +10 -0
  226. package/esm/transforms/arrange-draw-order.js +27 -0
  227. package/esm/transforms/arrange-draw-order.js.map +1 -0
  228. package/esm/transforms/base-transform.d.ts +7 -0
  229. package/esm/transforms/base-transform.js +7 -0
  230. package/esm/transforms/base-transform.js.map +1 -0
  231. package/esm/transforms/collapse-expand-combo.d.ts +10 -0
  232. package/esm/transforms/collapse-expand-combo.js +82 -0
  233. package/esm/transforms/collapse-expand-combo.js.map +1 -0
  234. package/esm/transforms/index.d.ts +6 -0
  235. package/esm/transforms/index.js +6 -0
  236. package/esm/transforms/index.js.map +1 -0
  237. package/esm/transforms/process-parallel-edges.d.ts +84 -0
  238. package/esm/transforms/process-parallel-edges.js +215 -0
  239. package/esm/transforms/process-parallel-edges.js.map +1 -0
  240. package/esm/transforms/types.d.ts +20 -0
  241. package/esm/transforms/types.js +11 -0
  242. package/esm/transforms/types.js.map +1 -0
  243. package/esm/transforms/update-related-edge.d.ts +9 -0
  244. package/esm/transforms/update-related-edge.js +20 -0
  245. package/esm/transforms/update-related-edge.js.map +1 -0
  246. package/esm/types/canvas.d.ts +1 -1
  247. package/esm/types/change.d.ts +27 -10
  248. package/esm/types/element.d.ts +6 -140
  249. package/esm/types/node.d.ts +3 -3
  250. package/esm/types/point.d.ts +1 -0
  251. package/esm/utils/animation.d.ts +1 -1
  252. package/esm/utils/animation.js +6 -0
  253. package/esm/utils/animation.js.map +1 -1
  254. package/esm/utils/behaviors/brush.d.ts +19 -0
  255. package/esm/utils/behaviors/brush.js +25 -0
  256. package/esm/utils/behaviors/brush.js.map +1 -0
  257. package/esm/utils/behaviors/lasso.d.ts +13 -0
  258. package/esm/utils/behaviors/lasso.js +112 -0
  259. package/esm/utils/behaviors/lasso.js.map +1 -0
  260. package/esm/utils/behaviors/utils.d.ts +21 -0
  261. package/esm/utils/behaviors/utils.js +42 -0
  262. package/esm/utils/behaviors/utils.js.map +1 -0
  263. package/esm/utils/change.d.ts +9 -1
  264. package/esm/utils/change.js +28 -0
  265. package/esm/utils/change.js.map +1 -1
  266. package/esm/utils/combo.d.ts +5 -4
  267. package/esm/utils/combo.js.map +1 -1
  268. package/esm/utils/edge.d.ts +11 -0
  269. package/esm/utils/edge.js +1 -1
  270. package/esm/utils/edge.js.map +1 -1
  271. package/esm/utils/event/events.d.ts +1 -1
  272. package/esm/utils/event/events.js.map +1 -1
  273. package/esm/utils/extension.d.ts +1 -1
  274. package/esm/utils/extension.js.map +1 -1
  275. package/esm/utils/id.d.ts +3 -8
  276. package/esm/utils/id.js +8 -2
  277. package/esm/utils/id.js.map +1 -1
  278. package/esm/utils/line.d.ts +21 -0
  279. package/esm/utils/line.js +41 -0
  280. package/esm/utils/line.js.map +1 -0
  281. package/esm/utils/path.d.ts +35 -0
  282. package/esm/utils/path.js +143 -0
  283. package/esm/utils/path.js.map +1 -0
  284. package/esm/utils/point.d.ts +74 -20
  285. package/esm/utils/point.js +168 -44
  286. package/esm/utils/point.js.map +1 -1
  287. package/esm/utils/polygon.d.ts +17 -0
  288. package/esm/utils/polygon.js +62 -0
  289. package/esm/utils/polygon.js.map +1 -0
  290. package/esm/utils/position.d.ts +14 -1
  291. package/esm/utils/position.js +16 -0
  292. package/esm/utils/position.js.map +1 -1
  293. package/esm/utils/prefix.d.ts +1 -1
  294. package/esm/utils/prefix.js.map +1 -1
  295. package/esm/utils/shortcut.d.ts +1 -0
  296. package/esm/utils/shortcut.js +13 -2
  297. package/esm/utils/shortcut.js.map +1 -1
  298. package/esm/utils/style.js.map +1 -1
  299. package/esm/utils/vector.d.ts +3 -2
  300. package/esm/utils/vector.js +10 -3
  301. package/esm/utils/vector.js.map +1 -1
  302. package/lib/behaviors/brush-select.d.ts +104 -0
  303. package/lib/behaviors/brush-select.js +203 -0
  304. package/lib/behaviors/brush-select.js.map +1 -0
  305. package/lib/behaviors/click-element.d.ts +77 -0
  306. package/lib/behaviors/click-element.js +112 -0
  307. package/lib/behaviors/click-element.js.map +1 -0
  308. package/lib/behaviors/drag-element-force.d.ts +14 -0
  309. package/lib/behaviors/drag-element-force.js +59 -0
  310. package/lib/behaviors/drag-element-force.js.map +1 -0
  311. package/lib/behaviors/drag-element.d.ts +13 -12
  312. package/lib/behaviors/drag-element.js +17 -9
  313. package/lib/behaviors/drag-element.js.map +1 -1
  314. package/lib/behaviors/hover-element.js +1 -1
  315. package/lib/behaviors/hover-element.js.map +1 -1
  316. package/lib/behaviors/index.d.ts +8 -0
  317. package/lib/behaviors/index.js +9 -1
  318. package/lib/behaviors/index.js.map +1 -1
  319. package/lib/behaviors/lasso-select.d.ts +20 -0
  320. package/lib/behaviors/lasso-select.js +83 -0
  321. package/lib/behaviors/lasso-select.js.map +1 -0
  322. package/lib/behaviors/types.d.ts +1 -0
  323. package/lib/constants/change.d.ts +1 -1
  324. package/lib/constants/change.js +13 -13
  325. package/lib/constants/change.js.map +1 -1
  326. package/lib/constants/events/graph.d.ts +9 -7
  327. package/lib/constants/events/graph.js +9 -9
  328. package/lib/constants/events/graph.js.map +1 -1
  329. package/lib/constants/registry.d.ts +3 -1
  330. package/lib/constants/registry.js +2 -0
  331. package/lib/constants/registry.js.map +1 -1
  332. package/lib/elements/combos/base-combo.d.ts +43 -6
  333. package/lib/elements/combos/base-combo.js.map +1 -1
  334. package/lib/elements/combos/circle.d.ts +8 -12
  335. package/lib/elements/combos/circle.js.map +1 -1
  336. package/lib/elements/combos/rect.d.ts +5 -9
  337. package/lib/elements/combos/rect.js.map +1 -1
  338. package/lib/elements/edges/base-edge.d.ts +64 -10
  339. package/lib/elements/edges/base-edge.js.map +1 -1
  340. package/lib/elements/edges/cubic-horizontal.d.ts +2 -2
  341. package/lib/elements/edges/cubic-vertical.d.ts +2 -2
  342. package/lib/elements/edges/cubic.d.ts +2 -2
  343. package/lib/elements/edges/polyline.d.ts +2 -2
  344. package/lib/elements/edges/quadratic.d.ts +2 -2
  345. package/lib/elements/nodes/base-node.d.ts +104 -13
  346. package/lib/elements/nodes/base-node.js +4 -1
  347. package/lib/elements/nodes/base-node.js.map +1 -1
  348. package/lib/elements/nodes/circle.d.ts +5 -8
  349. package/lib/elements/nodes/circle.js.map +1 -1
  350. package/lib/elements/nodes/diamond.d.ts +2 -4
  351. package/lib/elements/nodes/diamond.js +2 -2
  352. package/lib/elements/nodes/diamond.js.map +1 -1
  353. package/lib/elements/nodes/ellipse.d.ts +5 -8
  354. package/lib/elements/nodes/ellipse.js +1 -1
  355. package/lib/elements/nodes/ellipse.js.map +1 -1
  356. package/lib/elements/nodes/hexagon.d.ts +6 -9
  357. package/lib/elements/nodes/hexagon.js.map +1 -1
  358. package/lib/elements/nodes/image.d.ts +9 -11
  359. package/lib/elements/nodes/image.js.map +1 -1
  360. package/lib/elements/nodes/polygon.d.ts +9 -8
  361. package/lib/elements/nodes/polygon.js +4 -1
  362. package/lib/elements/nodes/polygon.js.map +1 -1
  363. package/lib/elements/nodes/rect.d.ts +2 -3
  364. package/lib/elements/nodes/rect.js.map +1 -1
  365. package/lib/elements/nodes/star.d.ts +7 -10
  366. package/lib/elements/nodes/star.js.map +1 -1
  367. package/lib/elements/nodes/triangle.d.ts +7 -10
  368. package/lib/elements/nodes/triangle.js.map +1 -1
  369. package/lib/exports.d.ts +4 -2
  370. package/lib/exports.js +4 -1
  371. package/lib/exports.js.map +1 -1
  372. package/lib/layouts/index.d.ts +1 -1
  373. package/lib/layouts/index.js +2 -1
  374. package/lib/layouts/index.js.map +1 -1
  375. package/lib/layouts/types.d.ts +6 -6
  376. package/lib/palettes/index.d.ts +1 -0
  377. package/lib/palettes/index.js +13 -1
  378. package/lib/palettes/index.js.map +1 -1
  379. package/lib/plugins/history/events.d.ts +21 -0
  380. package/lib/plugins/history/events.js +19 -0
  381. package/lib/plugins/history/events.js.map +1 -0
  382. package/lib/plugins/history/index.d.ts +82 -0
  383. package/lib/plugins/history/index.js +175 -0
  384. package/lib/plugins/history/index.js.map +1 -0
  385. package/lib/plugins/history/utils.d.ts +31 -0
  386. package/lib/plugins/history/utils.js +84 -0
  387. package/lib/plugins/history/utils.js.map +1 -0
  388. package/lib/plugins/hull/index.d.ts +59 -0
  389. package/lib/plugins/hull/index.js +114 -0
  390. package/lib/plugins/hull/index.js.map +1 -0
  391. package/lib/plugins/hull/shape.d.ts +49 -0
  392. package/lib/plugins/hull/shape.js +39 -0
  393. package/lib/plugins/hull/shape.js.map +1 -0
  394. package/lib/plugins/hull/util.d.ts +12 -0
  395. package/lib/plugins/hull/util.js +207 -0
  396. package/lib/plugins/hull/util.js.map +1 -0
  397. package/lib/plugins/index.d.ts +4 -0
  398. package/lib/plugins/index.js +5 -1
  399. package/lib/plugins/index.js.map +1 -1
  400. package/lib/plugins/legend.js.map +1 -1
  401. package/lib/registry/build-in.js +15 -0
  402. package/lib/registry/build-in.js.map +1 -1
  403. package/lib/registry/extension/index.d.ts +1 -1
  404. package/lib/registry/index.js +1 -0
  405. package/lib/registry/index.js.map +1 -1
  406. package/lib/registry/types.d.ts +4 -0
  407. package/lib/runtime/batch.d.ts +11 -0
  408. package/lib/runtime/batch.js +35 -0
  409. package/lib/runtime/batch.js.map +1 -0
  410. package/lib/runtime/behavior.d.ts +1 -1
  411. package/lib/runtime/behavior.js.map +1 -1
  412. package/lib/runtime/canvas.d.ts +13 -3
  413. package/lib/runtime/canvas.js +34 -10
  414. package/lib/runtime/canvas.js.map +1 -1
  415. package/lib/runtime/data.d.ts +4 -4
  416. package/lib/runtime/data.js +22 -24
  417. package/lib/runtime/data.js.map +1 -1
  418. package/lib/runtime/element.d.ts +3 -19
  419. package/lib/runtime/element.js +16 -137
  420. package/lib/runtime/element.js.map +1 -1
  421. package/lib/runtime/graph.d.ts +40 -2
  422. package/lib/runtime/graph.js +57 -1
  423. package/lib/runtime/graph.js.map +1 -1
  424. package/lib/runtime/layout.d.ts +5 -11
  425. package/lib/runtime/layout.js +27 -73
  426. package/lib/runtime/layout.js.map +1 -1
  427. package/lib/runtime/plugin.d.ts +1 -1
  428. package/lib/runtime/plugin.js.map +1 -1
  429. package/lib/runtime/transform.d.ts +11 -0
  430. package/lib/runtime/transform.js +24 -0
  431. package/lib/runtime/transform.js.map +1 -0
  432. package/lib/runtime/types.d.ts +14 -0
  433. package/lib/spec/index.d.ts +1 -0
  434. package/lib/spec/spec.d.ts +7 -0
  435. package/lib/spec/transform.d.ts +12 -0
  436. package/lib/spec/transform.js +3 -0
  437. package/lib/spec/transform.js.map +1 -0
  438. package/lib/themes/base.js +9 -1
  439. package/lib/themes/base.js.map +1 -1
  440. package/lib/transforms/arrange-draw-order.d.ts +10 -0
  441. package/lib/transforms/arrange-draw-order.js +31 -0
  442. package/lib/transforms/arrange-draw-order.js.map +1 -0
  443. package/lib/transforms/base-transform.d.ts +7 -0
  444. package/lib/transforms/base-transform.js +11 -0
  445. package/lib/transforms/base-transform.js.map +1 -0
  446. package/lib/transforms/collapse-expand-combo.d.ts +10 -0
  447. package/lib/transforms/collapse-expand-combo.js +86 -0
  448. package/lib/transforms/collapse-expand-combo.js.map +1 -0
  449. package/lib/transforms/index.d.ts +6 -0
  450. package/lib/transforms/index.js +14 -0
  451. package/lib/transforms/index.js.map +1 -0
  452. package/lib/transforms/process-parallel-edges.d.ts +84 -0
  453. package/lib/transforms/process-parallel-edges.js +222 -0
  454. package/lib/transforms/process-parallel-edges.js.map +1 -0
  455. package/lib/transforms/types.d.ts +20 -0
  456. package/lib/transforms/types.js +15 -0
  457. package/lib/transforms/types.js.map +1 -0
  458. package/lib/transforms/update-related-edge.d.ts +9 -0
  459. package/lib/transforms/update-related-edge.js +24 -0
  460. package/lib/transforms/update-related-edge.js.map +1 -0
  461. package/lib/types/canvas.d.ts +1 -1
  462. package/lib/types/change.d.ts +27 -10
  463. package/lib/types/element.d.ts +6 -140
  464. package/lib/types/node.d.ts +3 -3
  465. package/lib/types/point.d.ts +1 -0
  466. package/lib/utils/animation.d.ts +1 -1
  467. package/lib/utils/animation.js +6 -0
  468. package/lib/utils/animation.js.map +1 -1
  469. package/lib/utils/behaviors/brush.d.ts +19 -0
  470. package/lib/utils/behaviors/brush.js +30 -0
  471. package/lib/utils/behaviors/brush.js.map +1 -0
  472. package/lib/utils/behaviors/lasso.d.ts +13 -0
  473. package/lib/utils/behaviors/lasso.js +116 -0
  474. package/lib/utils/behaviors/lasso.js.map +1 -0
  475. package/lib/utils/behaviors/utils.d.ts +21 -0
  476. package/lib/utils/behaviors/utils.js +47 -0
  477. package/lib/utils/behaviors/utils.js.map +1 -0
  478. package/lib/utils/change.d.ts +9 -1
  479. package/lib/utils/change.js +30 -1
  480. package/lib/utils/change.js.map +1 -1
  481. package/lib/utils/combo.d.ts +5 -4
  482. package/lib/utils/combo.js.map +1 -1
  483. package/lib/utils/edge.d.ts +11 -0
  484. package/lib/utils/edge.js +2 -1
  485. package/lib/utils/edge.js.map +1 -1
  486. package/lib/utils/event/events.d.ts +1 -1
  487. package/lib/utils/event/events.js.map +1 -1
  488. package/lib/utils/extension.d.ts +1 -1
  489. package/lib/utils/extension.js.map +1 -1
  490. package/lib/utils/id.d.ts +3 -8
  491. package/lib/utils/id.js +10 -4
  492. package/lib/utils/id.js.map +1 -1
  493. package/lib/utils/line.d.ts +21 -0
  494. package/lib/utils/line.js +46 -0
  495. package/lib/utils/line.js.map +1 -0
  496. package/lib/utils/path.d.ts +35 -0
  497. package/lib/utils/path.js +150 -0
  498. package/lib/utils/path.js.map +1 -0
  499. package/lib/utils/point.d.ts +74 -20
  500. package/lib/utils/point.js +178 -48
  501. package/lib/utils/point.js.map +1 -1
  502. package/lib/utils/polygon.d.ts +17 -0
  503. package/lib/utils/polygon.js +66 -0
  504. package/lib/utils/polygon.js.map +1 -0
  505. package/lib/utils/position.d.ts +14 -1
  506. package/lib/utils/position.js +18 -1
  507. package/lib/utils/position.js.map +1 -1
  508. package/lib/utils/prefix.d.ts +1 -1
  509. package/lib/utils/prefix.js.map +1 -1
  510. package/lib/utils/shortcut.d.ts +1 -0
  511. package/lib/utils/shortcut.js +12 -1
  512. package/lib/utils/shortcut.js.map +1 -1
  513. package/lib/utils/style.js.map +1 -1
  514. package/lib/utils/vector.d.ts +3 -2
  515. package/lib/utils/vector.js +10 -3
  516. package/lib/utils/vector.js.map +1 -1
  517. package/package.json +5 -6
  518. package/src/behaviors/brush-select.ts +306 -0
  519. package/src/behaviors/click-element.ts +182 -0
  520. package/src/behaviors/drag-element-force.ts +70 -0
  521. package/src/behaviors/drag-element.ts +27 -17
  522. package/src/behaviors/hover-element.ts +2 -3
  523. package/src/behaviors/index.ts +8 -0
  524. package/src/behaviors/lasso-select.ts +103 -0
  525. package/src/behaviors/types.ts +2 -0
  526. package/src/constants/change.ts +1 -1
  527. package/src/constants/events/graph.ts +8 -8
  528. package/src/constants/registry.ts +2 -0
  529. package/src/elements/combos/base-combo.ts +59 -10
  530. package/src/elements/combos/circle.ts +8 -11
  531. package/src/elements/combos/rect.ts +5 -8
  532. package/src/elements/edges/base-edge.ts +70 -13
  533. package/src/elements/edges/cubic-horizontal.ts +2 -2
  534. package/src/elements/edges/cubic-vertical.ts +2 -2
  535. package/src/elements/edges/cubic.ts +2 -2
  536. package/src/elements/edges/polyline.ts +2 -2
  537. package/src/elements/edges/quadratic.ts +2 -2
  538. package/src/elements/nodes/base-node.ts +115 -19
  539. package/src/elements/nodes/circle.ts +5 -7
  540. package/src/elements/nodes/diamond.ts +4 -6
  541. package/src/elements/nodes/ellipse.ts +6 -8
  542. package/src/elements/nodes/hexagon.ts +7 -9
  543. package/src/elements/nodes/image.ts +12 -13
  544. package/src/elements/nodes/polygon.ts +17 -11
  545. package/src/elements/nodes/rect.ts +3 -4
  546. package/src/elements/nodes/star.ts +9 -11
  547. package/src/elements/nodes/triangle.ts +7 -9
  548. package/src/exports.ts +4 -2
  549. package/src/layouts/index.ts +1 -0
  550. package/src/layouts/types.ts +7 -5
  551. package/src/palettes/index.ts +13 -0
  552. package/src/plugins/history/events.ts +25 -0
  553. package/src/plugins/history/index.ts +222 -0
  554. package/src/plugins/history/utils.ts +98 -0
  555. package/src/plugins/hull/index.ts +149 -0
  556. package/src/plugins/hull/shape.ts +96 -0
  557. package/src/plugins/hull/util.ts +222 -0
  558. package/src/plugins/index.ts +4 -0
  559. package/src/plugins/legend.ts +1 -1
  560. package/src/registry/build-in.ts +22 -2
  561. package/src/registry/extension/index.ts +1 -1
  562. package/src/registry/index.ts +1 -0
  563. package/src/registry/types.ts +2 -0
  564. package/src/runtime/batch.ts +38 -0
  565. package/src/runtime/behavior.ts +1 -1
  566. package/src/runtime/canvas.ts +51 -13
  567. package/src/runtime/data.ts +31 -36
  568. package/src/runtime/element.ts +28 -167
  569. package/src/runtime/graph.ts +65 -3
  570. package/src/runtime/layout.ts +48 -79
  571. package/src/runtime/plugin.ts +1 -1
  572. package/src/runtime/transform.ts +27 -0
  573. package/src/runtime/types.ts +14 -0
  574. package/src/spec/index.ts +1 -0
  575. package/src/spec/spec.ts +7 -0
  576. package/src/spec/transform.ts +15 -0
  577. package/src/themes/base.ts +9 -1
  578. package/src/transforms/arrange-draw-order.ts +36 -0
  579. package/src/transforms/base-transform.ts +11 -0
  580. package/src/transforms/collapse-expand-combo.ts +87 -0
  581. package/src/transforms/index.ts +7 -0
  582. package/src/transforms/process-parallel-edges.ts +286 -0
  583. package/src/transforms/types.ts +23 -0
  584. package/src/transforms/update-related-edge.ts +28 -0
  585. package/src/types/canvas.ts +1 -1
  586. package/src/types/change.ts +28 -10
  587. package/src/types/element.ts +6 -147
  588. package/src/types/node.ts +3 -3
  589. package/src/types/point.ts +1 -0
  590. package/src/utils/animation.ts +6 -0
  591. package/src/utils/behaviors/brush.ts +29 -0
  592. package/src/utils/behaviors/lasso.ts +127 -0
  593. package/src/utils/behaviors/utils.ts +47 -0
  594. package/src/utils/change.ts +42 -1
  595. package/src/utils/combo.ts +6 -5
  596. package/src/utils/edge.ts +6 -1
  597. package/src/utils/event/events.ts +3 -1
  598. package/src/utils/extension.ts +1 -1
  599. package/src/utils/id.ts +11 -2
  600. package/src/utils/line.ts +50 -0
  601. package/src/utils/path.ts +153 -0
  602. package/src/utils/point.ts +190 -51
  603. package/src/utils/polygon.ts +72 -0
  604. package/src/utils/position.ts +18 -1
  605. package/src/utils/prefix.ts +1 -1
  606. package/src/utils/shortcut.ts +13 -2
  607. package/src/utils/style.ts +1 -1
  608. package/src/utils/vector.ts +10 -3
  609. package/esm/elements/types.d.ts +0 -0
  610. package/esm/elements/types.js +0 -15
  611. package/esm/elements/types.js.map +0 -1
  612. package/lib/elements/types.d.ts +0 -0
  613. package/lib/elements/types.js +0 -15
  614. package/lib/elements/types.js.map +0 -1
  615. package/src/elements/types.ts +0 -21
@@ -2,6 +2,7 @@ import type {
2
2
  AntVDagreLayoutOptions,
3
3
  CircularLayoutOptions,
4
4
  ConcentricLayoutOptions,
5
+ D3Force3DLayoutOptions,
5
6
  D3ForceLayoutOptions,
6
7
  DagreLayoutOptions,
7
8
  ForceAtlas2LayoutOptions,
@@ -19,6 +20,7 @@ export type BuiltInLayoutOptions =
19
20
  | CircularLayout
20
21
  | ConcentricLayout
21
22
  | D3ForceLayout
23
+ | D3Force3DLayout
22
24
  | DagreLayout
23
25
  | ForceAtlas2
24
26
  | ForceLayout
@@ -28,7 +30,7 @@ export type BuiltInLayoutOptions =
28
30
  | RadialLayout
29
31
  | RandomLayout;
30
32
 
31
- export interface BaseLayoutOptions extends AnimationOptions, WebWorkerLayoutOptions, PresetLayoutOptions {
33
+ export interface BaseLayoutOptions extends AnimationOptions, WebWorkerLayoutOptions {
32
34
  type: string;
33
35
  /**
34
36
  * <zh/> 参与该布局的节点
@@ -73,6 +75,10 @@ interface D3ForceLayout extends BaseLayoutOptions, D3ForceLayoutOptions {
73
75
  type: 'd3force';
74
76
  }
75
77
 
78
+ interface D3Force3DLayout extends BaseLayoutOptions, D3Force3DLayoutOptions {
79
+ type: 'd3force3d';
80
+ }
81
+
76
82
  interface ForceLayout extends BaseLayoutOptions, ForceLayoutOptions {
77
83
  type: 'force' | 'gforce';
78
84
  }
@@ -89,10 +95,6 @@ interface DagreLayout extends BaseLayoutOptions, DagreLayoutOptions {
89
95
  type: 'dagre';
90
96
  }
91
97
 
92
- export interface PresetLayoutOptions {
93
- presetLayout?: BaseLayoutOptions;
94
- }
95
-
96
98
  export interface AnimationOptions {
97
99
  /**
98
100
  * <zh/> 启用布局动画,对于迭代布局,会在两次迭代之间进行动画过渡
@@ -17,6 +17,19 @@ export const spectral = [
17
17
  'rgb(94, 79, 162)',
18
18
  ];
19
19
 
20
+ export const tableau = [
21
+ 'rgb(78, 121, 167)',
22
+ 'rgb(242, 142, 44)',
23
+ 'rgb(225, 87, 89)',
24
+ 'rgb(118, 183, 178)',
25
+ 'rgb(89, 161, 79)',
26
+ 'rgb(237, 201, 73)',
27
+ 'rgb(175, 122, 161)',
28
+ 'rgb(255, 157, 167)',
29
+ 'rgb(156, 117, 95)',
30
+ 'rgb(186, 176, 171)',
31
+ ];
32
+
20
33
  export const oranges = [
21
34
  'rgb(255, 245, 235)',
22
35
  'rgb(254, 230, 206)',
@@ -0,0 +1,25 @@
1
+ import type { Loosen } from '../../types';
2
+ import type { Command } from './utils';
3
+
4
+ export interface IHistoryEvent {
5
+ cmd?: Command | null;
6
+ }
7
+
8
+ export type HistoryEventHandler = (e: IHistoryEvent) => void;
9
+
10
+ export enum HistoryEvent {
11
+ /** <zh/> 当命令被撤销时 | <en/> When the command is undone */
12
+ UNDO = 'undo',
13
+ /** <zh/> 当命令被重做时 | <en/> When the command is redone */
14
+ REDO = 'redo',
15
+ /** <zh/> 当命令被取消时 | <en/> When the command is canceled */
16
+ CANCEL = 'cancel',
17
+ /** <zh/> 当命令被添加到队列时 | <en/> When the command is added */
18
+ ADD = 'add',
19
+ /** <zh/> 当历史队列被清空时 | <en/> When the command queue is cleared */
20
+ CLEAR = 'clear',
21
+ /** <zh/> 当历史队列发生变化时 | <en/> When the command queue changes */
22
+ CHANGE = 'change',
23
+ }
24
+
25
+ export type HistoryEventName = Loosen<HistoryEvent>;
@@ -0,0 +1,222 @@
1
+ import EventEmitter from '@antv/event-emitter';
2
+ import { GraphEvent } from '../../constants';
3
+ import type { RuntimeContext } from '../../runtime/types';
4
+ import { DataChange } from '../../types';
5
+ import type { GraphLifeCycleEvent } from '../../utils/event';
6
+ import { idsOf } from '../../utils/id';
7
+ import type { BasePluginOptions } from '../base-plugin';
8
+ import { BasePlugin } from '../base-plugin';
9
+ import type { HistoryEventHandler, HistoryEventName } from './events';
10
+ import { HistoryEvent } from './events';
11
+ import type { Command } from './utils';
12
+ import { parseCommand } from './utils';
13
+
14
+ export interface HistoryOptions extends BasePluginOptions {
15
+ /**
16
+ * <zh/> 最多记录该数据长度的历史记录,默认为 0 表示不做限制
17
+ */
18
+ stackSize?: number;
19
+ /**
20
+ * <zh/> 当一个命令被添加到 Undo/Redo 队列前被调用,如果该方法返回 false,那么这个命令将不会被添加到队列中。revert 为 true 时表示撤销操作,为 false 时表示重做操作
21
+ *
22
+ * <en/> Called before a command is added to the Undo/Redo queue. If this method returns false, the command will not be added to the queue. revert is true for undo operations and false for redo operations
23
+ */
24
+ beforeAddCommand?: (cmd: Command, revert?: boolean) => boolean | void;
25
+ /**
26
+ * <zh/> 当一个命令被添加到 Undo/Redo 队列后被调用。revert 为 true 时表示撤销操作,为 false 时表示重做操作
27
+ *
28
+ * <en/> Called after a command is added to the Undo/Redo queue. revert is true for undo operations and false for redo operations
29
+ */
30
+ afterAddCommand?: (cmd: Command, revert?: boolean) => void;
31
+ /**
32
+ * <zh/> 执行命令时的回调函数
33
+ *
34
+ * <en/> Callback function when executing a command
35
+ */
36
+ executeCommand?: (cmd: Command) => void;
37
+ }
38
+
39
+ export class History extends BasePlugin<HistoryOptions> {
40
+ static defaultOptions: Partial<HistoryOptions> = {
41
+ stackSize: 0,
42
+ };
43
+ private emitter: EventEmitter;
44
+ private batchChanges: DataChange[][] | null = null;
45
+ private batchAnimation = false;
46
+ public undoStack: Command[] = [];
47
+ public redoStack: Command[] = [];
48
+ private isFirstDraw = true;
49
+ private freezed = false;
50
+
51
+ constructor(context: RuntimeContext, options: HistoryOptions) {
52
+ super(context, Object.assign({}, History.defaultOptions, options));
53
+
54
+ this.emitter = new EventEmitter();
55
+
56
+ const { graph } = this.context;
57
+ graph.on(GraphEvent.AFTER_DRAW, this.addCommand);
58
+ graph.on(GraphEvent.BATCH_START, this.initBatchCommand);
59
+ graph.on(GraphEvent.BATCH_END, this.addCommand);
60
+ }
61
+
62
+ /**
63
+ * <zh/> 是否可以执行撤销操作
64
+ * <en/> Whether undo can be done
65
+ * @returns <zh/> 是否可以执行撤销操作 | <en/> Whether undo can be done
66
+ */
67
+ public canUndo = () => {
68
+ return this.undoStack.length > 0;
69
+ };
70
+
71
+ /**
72
+ * <zh/> 是否可以执行重做操作
73
+ * <en/> Whether redo can be done
74
+ * @returns <zh/> 是否可以执行重做操作 | <en/> Whether redo can be done
75
+ */
76
+ public canRedo = () => {
77
+ return this.redoStack.length > 0;
78
+ };
79
+
80
+ /**
81
+ * <zh/> 执行撤销
82
+ * <en/> Execute undo
83
+ * @returns <zh/> 返回当前实例 | <en/> Return the current instance
84
+ */
85
+ public undo = () => {
86
+ const cmd = this.undoStack.pop();
87
+ if (cmd) {
88
+ this.executeCommand(cmd);
89
+ this.options.beforeAddCommand?.(cmd, false);
90
+ this.redoStack.push(cmd);
91
+ this.options.afterAddCommand?.(cmd, false);
92
+ this.notify(HistoryEvent.UNDO, cmd);
93
+ }
94
+ return this;
95
+ };
96
+
97
+ /**
98
+ * <zh/> 执行重做
99
+ * <en/> Execute redo
100
+ * @returns <zh/> 返回当前实例 | <en/> Return the current instance
101
+ */
102
+ public redo = () => {
103
+ const cmd = this.redoStack.pop();
104
+ if (cmd) {
105
+ this.executeCommand(cmd, false);
106
+ this.undoStackPush(cmd);
107
+ this.notify(HistoryEvent.REDO, cmd);
108
+ }
109
+ return this;
110
+ };
111
+
112
+ /**
113
+ * <zh/> 执行撤销且不计入历史记录
114
+ * <en/> Execute undo and do not record in history
115
+ * @returns <zh/> 返回当前实例 | <en/> Return the current instance
116
+ */
117
+ public undoAndCancel = () => {
118
+ const cmd = this.undoStack.pop();
119
+ if (cmd) {
120
+ this.executeCommand(cmd, false);
121
+ this.redoStack = [];
122
+ this.notify(HistoryEvent.CANCEL, cmd);
123
+ }
124
+ return this;
125
+ };
126
+
127
+ private executeCommand = (cmd: Command, revert = true) => {
128
+ this.freezed = true;
129
+
130
+ this.options.executeCommand?.(cmd);
131
+
132
+ const values = revert ? cmd.original : cmd.current;
133
+ this.context.graph.addData(values.add);
134
+ this.context.graph.updateData(values.update);
135
+ this.context.graph.removeData(idsOf(values.remove, false));
136
+ this.context.element?.draw({ silence: true, animation: cmd.animation });
137
+
138
+ this.freezed = false;
139
+ };
140
+
141
+ private addCommand = (event: GraphLifeCycleEvent) => {
142
+ if (this.isFirstDraw) {
143
+ this.isFirstDraw = false;
144
+ return;
145
+ }
146
+
147
+ if (this.freezed) return;
148
+
149
+ if (event.type === GraphEvent.AFTER_DRAW) {
150
+ const { dataChanges = [], animation = true } = (event as GraphLifeCycleEvent).data;
151
+
152
+ if (this.context.batch?.isBatching) {
153
+ if (!this.batchChanges) return;
154
+ this.batchChanges.push(dataChanges);
155
+ this.batchAnimation &&= animation;
156
+ return;
157
+ }
158
+ this.batchChanges = [dataChanges];
159
+ this.batchAnimation = animation;
160
+ }
161
+
162
+ this.undoStackPush(parseCommand(this.batchChanges!.flat(), this.batchAnimation, this.context));
163
+ this.notify(HistoryEvent.ADD, this.undoStack[this.undoStack.length - 1]);
164
+ };
165
+
166
+ private initBatchCommand = (event: GraphLifeCycleEvent) => {
167
+ const { initiate } = event.data;
168
+ this.batchAnimation = false;
169
+ if (initiate) {
170
+ this.batchChanges = [];
171
+ } else {
172
+ const cmd = this.undoStack.pop();
173
+ if (!cmd) this.batchChanges = null;
174
+ }
175
+ };
176
+
177
+ private undoStackPush(cmd: Command): void {
178
+ const { stackSize } = this.options;
179
+
180
+ if (stackSize !== 0 && this.undoStack.length >= stackSize) {
181
+ this.undoStack.shift();
182
+ }
183
+
184
+ this.options.beforeAddCommand?.(cmd, true);
185
+ this.undoStack.push(cmd);
186
+ this.options.afterAddCommand?.(cmd, true);
187
+ }
188
+
189
+ /**
190
+ * <zh/> 清空历史记录
191
+ * <en/> Clear history
192
+ */
193
+ public clear(): void {
194
+ this.undoStack = [];
195
+ this.redoStack = [];
196
+ this.batchChanges = null;
197
+ this.batchAnimation = false;
198
+ this.notify(HistoryEvent.CLEAR, null);
199
+ }
200
+
201
+ protected notify(event: HistoryEventName, cmd: Command | null) {
202
+ this.emitter.emit(event, { cmd });
203
+ this.emitter.emit(HistoryEvent.CHANGE, { cmd });
204
+ }
205
+
206
+ public on(event: HistoryEventName, handler: HistoryEventHandler): void {
207
+ this.emitter.on(event, handler);
208
+ }
209
+
210
+ public destroy(): void {
211
+ const { graph } = this.context;
212
+ graph.off(GraphEvent.AFTER_DRAW, this.addCommand);
213
+ graph.off(GraphEvent.BATCH_START, this.initBatchCommand);
214
+ graph.off(GraphEvent.BATCH_END, this.addCommand);
215
+
216
+ this.emitter.off();
217
+
218
+ super.destroy();
219
+ this.undoStack = [];
220
+ this.redoStack = [];
221
+ }
222
+ }
@@ -0,0 +1,98 @@
1
+ import { isObject } from '@antv/util';
2
+ import type { RuntimeContext } from '../../runtime/types';
3
+ import type { GraphData } from '../../spec';
4
+ import type { DataChange, DataChanges, ElementDatum } from '../../types';
5
+ import { inferDefaultValue } from '../../utils/animation';
6
+ import { groupByChangeType, reduceDataChanges } from '../../utils/change';
7
+ import { idOf } from '../../utils/id';
8
+
9
+ export type Command = {
10
+ current: CommandData;
11
+ original: CommandData;
12
+ animation: boolean;
13
+ };
14
+
15
+ export type CommandData = {
16
+ add: GraphData;
17
+ update: GraphData;
18
+ remove: GraphData;
19
+ };
20
+
21
+ /**
22
+ * <zh/> 对齐两个对象的字段。若目标对象缺少字段,则会添加默认值。
23
+ *
24
+ * <en/> Align the fields of two objects. If the target object lacks fields, default values will be added.
25
+ * @param refObject - <zh/> 参考对象 | <en/> Reference object
26
+ * @param targetObject - <zh/> 目标对象 | <en/> Target object
27
+ */
28
+ export function alignFields(refObject: Record<string, any>, targetObject: Record<string, any>) {
29
+ for (const key in refObject) {
30
+ if (isObject(refObject[key]) && !Array.isArray(refObject[key]) && refObject[key] !== null) {
31
+ if (!targetObject[key]) targetObject[key] = {};
32
+ alignFields(refObject[key], targetObject[key]);
33
+ } else if (!targetObject[key]) {
34
+ targetObject[key] = inferDefaultValue(key);
35
+ }
36
+ }
37
+ }
38
+
39
+ /**
40
+ * <zh/> 解析数据变更为历史记录命令
41
+ *
42
+ * <en/> Parse data changes into history commands
43
+ * @param changes - <zh/> 数据变更 | <en/> Data changes
44
+ * @param animation - <zh/> 是否开启动画 | <en/> Whether to enable animation
45
+ * @param context - <zh/> 运行时上下文 | <en/> Runtime context
46
+ * @returns <zh/> 历史记录命令 | <en/> History command
47
+ */
48
+ export function parseCommand(changes: DataChange[], animation = false, context?: RuntimeContext): Command {
49
+ const cmd = {
50
+ animation,
51
+ current: { add: {}, update: {}, remove: {} },
52
+ original: { add: {}, update: {}, remove: {} },
53
+ } as Command;
54
+
55
+ const { add, update, remove } = groupByChangeType(reduceDataChanges(changes));
56
+
57
+ (['nodes', 'edges', 'combos'] as const).forEach((category) => {
58
+ if (update[category]) {
59
+ update[category].forEach((item: DataChanges['update'][typeof category][number]) => {
60
+ const newValue = { ...item.value };
61
+ let newOriginal = { ...item.original };
62
+ if (context) {
63
+ // 特殊处理:获取元素原始 color
64
+ const itemType = context.graph.getElementType(idOf(item.original));
65
+ const { color } = context.element!.getElementComputedStyle(itemType, item.original);
66
+ newOriginal = { ...item.original, style: { color, ...item.original.style } } as ElementDatum;
67
+ }
68
+ alignFields(newValue, newOriginal);
69
+ cmd.current.update[category] ||= [];
70
+ (cmd.current.update[category] as ElementDatum[]).push(newValue);
71
+ cmd.original.update[category] ||= [];
72
+ (cmd.original.update[category] as ElementDatum[]).push(newOriginal);
73
+ });
74
+ }
75
+
76
+ if (add[category]) {
77
+ add[category].forEach((item: DataChanges['add'][typeof category][number]) => {
78
+ const newValue = { ...item.value };
79
+ cmd.current.add[category] ||= [];
80
+ (cmd.current.add[category] as ElementDatum[]).push(newValue);
81
+ cmd.original.remove[category] ||= [];
82
+ (cmd.original.remove[category] as ElementDatum[]).push(newValue);
83
+ });
84
+ }
85
+
86
+ if (remove[category]) {
87
+ remove[category].forEach((item: DataChanges['remove'][typeof category][number]) => {
88
+ const newValue = { ...item.value };
89
+ cmd.current.remove[category] ||= [];
90
+ (cmd.current.remove[category] as ElementDatum[]).push(newValue);
91
+ cmd.original.add[category] ||= [];
92
+ (cmd.original.add[category] as ElementDatum[]).push(newValue);
93
+ });
94
+ }
95
+ });
96
+
97
+ return cmd;
98
+ }
@@ -0,0 +1,149 @@
1
+ import type { ID } from '@antv/graphlib';
2
+ import { PathArray, isEqual, isFunction } from '@antv/util';
3
+ import hull from 'hull.js';
4
+ import { GraphEvent } from '../../constants';
5
+ import type { RuntimeContext } from '../../runtime/types';
6
+ import type { CallableValue, Point } from '../../types';
7
+ import type { ElementLifeCycleEvent } from '../../utils/event';
8
+ import { idOf } from '../../utils/id';
9
+ import { positionOf } from '../../utils/position';
10
+ import type { BasePluginOptions } from '../base-plugin';
11
+ import { BasePlugin } from '../base-plugin';
12
+ import type { HullStyleProps } from './shape';
13
+ import { Hull as HullShape } from './shape';
14
+ import { computeHullPath } from './util';
15
+
16
+ export interface HullOptions extends BasePluginOptions, HullStyleProps {
17
+ /**
18
+ * <zh/> Hull 内的元素
19
+ * <en/> Elements in Hull
20
+ */
21
+ members?: ID[];
22
+ /**
23
+ * <zh/> 凹度,数值越大凹度越小;默认为 Infinity 代表为 Convex Hull
24
+ * <en/> Concavity. Default is Infinity, which means Convex Hull
25
+ */
26
+ concavity?: number;
27
+ /**
28
+ * <zh/> 内边距,默认为 10
29
+ * <en/> Padding, default is 10
30
+ */
31
+ padding?: number;
32
+ /**
33
+ * <zh/> 拐角类型,目前支持 'rounded'、'smooth' 和 'sharp'
34
+ * <en/> Corner type, currently supports 'rounded', 'smooth' and 'sharp'
35
+ */
36
+ corner?: 'rounded' | 'smooth' | 'sharp';
37
+ }
38
+
39
+ export class Hull extends BasePlugin<HullOptions> {
40
+ private shape!: HullShape;
41
+ /**
42
+ * <zh/> 在 Hull 上的元素
43
+ * <en/> Element Ids on Hull
44
+ */
45
+ private hullMemberIds: ID[] = [];
46
+ /**
47
+ * <zh/> Hull 绘制路径
48
+ * <en/> Hull path
49
+ */
50
+ private path!: PathArray;
51
+ /**
52
+ * <zh> 是否初次渲染完成
53
+ * <en> Whether the first rendering is completed
54
+ */
55
+ private firstRender = false;
56
+
57
+ static defaultOptions: Partial<HullOptions> = {
58
+ members: [],
59
+ padding: 10,
60
+ corner: 'rounded',
61
+ concavity: Infinity,
62
+ /** hull style */
63
+ fill: 'lightblue',
64
+ stroke: 'blue',
65
+ opacity: 0.2,
66
+ };
67
+
68
+ constructor(context: RuntimeContext, options: HullOptions) {
69
+ super(context, Object.assign({}, Hull.defaultOptions, options));
70
+
71
+ this.bindEvents();
72
+ }
73
+
74
+ private bindEvents() {
75
+ this.context.graph.on(GraphEvent.AFTER_RENDER, this.drawHull);
76
+ this.context.graph.on(GraphEvent.AFTER_ELEMENT_UPDATE, this.updateHullPath);
77
+ }
78
+
79
+ private getHullStyle(forceUpdate?: boolean): HullStyleProps {
80
+ const { members, padding, corner, ...style } = this.options;
81
+ return { ...style, path: this.getHullPath(forceUpdate) };
82
+ }
83
+
84
+ private drawHull = () => {
85
+ this.shape = new HullShape({ style: this.getHullStyle() });
86
+ this.context.canvas.appendChild(this.shape);
87
+ this.firstRender = true;
88
+ };
89
+
90
+ private updateHullPath = (event: ElementLifeCycleEvent) => {
91
+ if (!this.firstRender) return;
92
+ if (!this.options.members.includes(idOf(event.data))) return;
93
+ this.shape.update({ path: this.getHullPath(true) });
94
+ };
95
+
96
+ private getHullPath = (forceUpdate = false): PathArray => {
97
+ const { graph } = this.context;
98
+ const data = this.options.members.map((id) => graph.getNodeData(id));
99
+ const vertices = hull(data.map(positionOf), this.options.concavity).slice(1).reverse() as Point[];
100
+ const hullMemberIds = vertices.flatMap((point) => data.filter((m) => isEqual(positionOf(m), point)).map(idOf));
101
+ if (isEqual(hullMemberIds, this.hullMemberIds) && !forceUpdate) return this.path;
102
+ this.hullMemberIds = hullMemberIds;
103
+ this.path = computeHullPath(vertices, this.getPadding(), this.options.corner);
104
+ return this.path;
105
+ };
106
+
107
+ private getPadding() {
108
+ const { graph } = this.context;
109
+
110
+ const memberPadding = this.hullMemberIds.reduce((acc: number, id: ID) => {
111
+ const { halfExtents } = graph.getElementRenderBounds(id);
112
+ const size = Math.max(halfExtents[0], halfExtents[1]);
113
+ return Math.max(acc, size);
114
+ }, 0);
115
+
116
+ return memberPadding + this.options.padding;
117
+ }
118
+
119
+ public addMembers(members: ID | ID[]) {
120
+ const membersToAdd = Array.isArray(members) ? members : [members];
121
+ this.options.members = [...new Set([...this.options.members, ...membersToAdd])];
122
+ this.shape.update({ path: this.getHullPath() });
123
+ }
124
+
125
+ public removeMembers(members: ID | ID[]) {
126
+ const membersToRemove = Array.isArray(members) ? members : [members];
127
+ this.options.members = this.options.members.filter((id) => !membersToRemove.includes(id));
128
+ if (membersToRemove.some((id) => this.hullMemberIds.includes(id))) {
129
+ this.shape.update({ path: this.getHullPath() });
130
+ }
131
+ }
132
+
133
+ public updateMembers(members: CallableValue<ID[]>) {
134
+ this.options.members = isFunction(members) ? members(this.options.members) : members;
135
+ this.shape.update(this.getHullStyle(true));
136
+ }
137
+
138
+ public updateOptions(options: CallableValue<HullOptions>) {
139
+ this.options = (isFunction(options) ? options(this.options) : options) as Required<HullOptions>;
140
+ this.shape.update({ ...this.options, path: this.getHullPath(true) });
141
+ }
142
+
143
+ public destroy(): void {
144
+ this.context.graph.off(GraphEvent.AFTER_DRAW, this.drawHull);
145
+ this.shape.destroy();
146
+ this.hullMemberIds = [];
147
+ super.destroy();
148
+ }
149
+ }
@@ -0,0 +1,96 @@
1
+ import type { DisplayObjectConfig, Group, PathStyleProps } from '@antv/g';
2
+ import { Path } from '@antv/g';
3
+ import { deepMix } from '@antv/util';
4
+ import type { LabelStyleProps } from '../../elements/shapes';
5
+ import { BaseShape, Label } from '../../elements/shapes';
6
+ import type { CardinalPlacement, PrefixObject } from '../../types';
7
+ import { getPolygonTextStyleByPlacement } from '../../utils/polygon';
8
+ import { subStyleProps } from '../../utils/prefix';
9
+ import { getWordWrapWidthByBox } from '../../utils/text';
10
+
11
+ type HullLabelStyleProps = LabelStyleProps & {
12
+ /**
13
+ * <zh/> 标签位置,可选值为 'top'、'right'、'bottom'、'left'、'center';默认为 'bottom'
14
+ * <en/> Label position, optional values are 'top', 'right', 'bottom', 'left', 'center'; default is 'bottom'
15
+ */
16
+ placement?: CardinalPlacement | 'center';
17
+ /**
18
+ * <zh/> 标签是否贴合轮廓,默认为 true
19
+ * <en/> Whether the label is close to the contour, default is true
20
+ */
21
+ closeToHull?: boolean;
22
+ /**
23
+ * <zh/> 标签是否跟随轮廓旋转,默认为 true,仅在 closeToHull 为 true 时生效
24
+ * <en/> Whether the label rotates with the contour, default is true. Only effective when closeToHull is true
25
+ */
26
+ autoRotate?: boolean;
27
+ /**
28
+ * <zh/> x 轴偏移量
29
+ * <en/> Label x-axis offset
30
+ */
31
+ offsetX?: number;
32
+ /**
33
+ * <zh/> y 轴偏移量
34
+ * <en/> Label y-axis offset
35
+ */
36
+ offsetY?: number;
37
+ /**
38
+ * <zh/> 文本的最大宽度,超出会自动省略
39
+ * <en/> The maximum width of the text, which will be automatically ellipsis if exceeded
40
+ */
41
+ maxWidth?: number;
42
+ };
43
+
44
+ export type HullStyleProps = PathStyleProps & {
45
+ label?: boolean;
46
+ } & PrefixObject<HullLabelStyleProps, 'label'>;
47
+ type ParsedHullStyleProps = Required<HullStyleProps>;
48
+ type HullOptions = DisplayObjectConfig<HullStyleProps>;
49
+
50
+ export class Hull extends BaseShape<HullStyleProps> {
51
+ static defaultStyleProps: Partial<HullStyleProps> = {
52
+ label: true,
53
+ labelPlacement: 'bottom',
54
+ labelCloseToHull: true,
55
+ labelAutoRotate: true,
56
+ labelOffsetX: 0,
57
+ labelOffsetY: 0,
58
+ };
59
+
60
+ constructor(options: HullOptions) {
61
+ super(deepMix({}, { style: Hull.defaultStyleProps }, options));
62
+ }
63
+
64
+ protected getLabelStyle(attributes: ParsedHullStyleProps): LabelStyleProps | false {
65
+ if (!attributes.label || !attributes.path || attributes.path.length === 0) return false;
66
+ const { maxWidth, offsetX, offsetY, autoRotate, placement, closeToHull, ...labelStyle } = subStyleProps<
67
+ Required<HullLabelStyleProps>
68
+ >(this.getGraphicStyle(attributes), 'label');
69
+
70
+ const contour = this.shapeMap.contour;
71
+ const contourBounds = contour?.getRenderBounds();
72
+
73
+ return Object.assign(
74
+ getPolygonTextStyleByPlacement(
75
+ contourBounds,
76
+ placement,
77
+ offsetX,
78
+ offsetY,
79
+ closeToHull,
80
+ attributes.path,
81
+ autoRotate,
82
+ ),
83
+ { wordWrapWidth: getWordWrapWidthByBox(contourBounds, maxWidth) },
84
+ labelStyle,
85
+ );
86
+ }
87
+
88
+ protected getContourStyle(attributes: ParsedHullStyleProps) {
89
+ return this.getGraphicStyle(attributes);
90
+ }
91
+
92
+ public render(attributes: ParsedHullStyleProps, container: Group): void {
93
+ this.upsert('contour', Path, this.getContourStyle(attributes), container);
94
+ this.upsert('label', Label, this.getLabelStyle(attributes), container);
95
+ }
96
+ }