@antv/g6 5.0.0-beta.36 → 5.0.0-beta.38

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 (487) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/dist/lib/animations/executor.d.ts +4 -5
  3. package/dist/lib/animations/index.d.ts +22 -8
  4. package/dist/lib/animations/types.d.ts +78 -20
  5. package/dist/lib/behaviors/collapse-expand.d.ts +10 -1
  6. package/dist/lib/behaviors/drag-canvas.d.ts +1 -0
  7. package/dist/lib/behaviors/hover-element.d.ts +2 -0
  8. package/dist/lib/constants/animation.d.ts +3 -2
  9. package/dist/lib/constants/events/animation.d.ts +2 -0
  10. package/dist/lib/constants/events/graph.d.ts +0 -12
  11. package/dist/lib/elements/base-element.d.ts +35 -0
  12. package/dist/lib/elements/combos/base-combo.d.ts +8 -32
  13. package/dist/lib/elements/combos/circle.d.ts +1 -2
  14. package/dist/lib/elements/edges/base-edge.d.ts +21 -30
  15. package/dist/lib/elements/nodes/base-node.d.ts +7 -27
  16. package/dist/lib/elements/nodes/html.d.ts +3 -2
  17. package/dist/lib/elements/shapes/badge.d.ts +1 -1
  18. package/dist/lib/elements/shapes/base-shape.d.ts +6 -0
  19. package/dist/lib/exports.d.ts +3 -2
  20. package/dist/lib/layouts/types.d.ts +1 -1
  21. package/dist/lib/plugins/background/index.d.ts +38 -0
  22. package/dist/lib/plugins/{contextmenu.d.ts → contextmenu/index.d.ts} +5 -5
  23. package/dist/lib/plugins/index.d.ts +2 -0
  24. package/dist/lib/plugins/legend.d.ts +1 -1
  25. package/dist/lib/plugins/timebar.d.ts +1 -1
  26. package/dist/lib/plugins/toolbar/index.d.ts +2 -2
  27. package/{lib/plugins/watermark.d.ts → dist/lib/plugins/watermark/index.d.ts} +3 -3
  28. package/dist/lib/runtime/animation.d.ts +54 -0
  29. package/dist/lib/runtime/data.d.ts +4 -4
  30. package/dist/lib/runtime/element.d.ts +26 -40
  31. package/dist/lib/runtime/graph.d.ts +1 -0
  32. package/dist/lib/runtime/layout.d.ts +7 -0
  33. package/dist/lib/runtime/transform.d.ts +1 -0
  34. package/dist/lib/runtime/types.d.ts +7 -0
  35. package/dist/lib/spec/data.d.ts +14 -0
  36. package/dist/lib/spec/element/animation.d.ts +3 -9
  37. package/dist/lib/spec/element/combo.d.ts +4 -3
  38. package/dist/lib/spec/element/edge.d.ts +4 -3
  39. package/dist/lib/spec/element/node.d.ts +4 -3
  40. package/dist/lib/spec/graph.d.ts +1 -1
  41. package/dist/lib/transforms/base-transform.d.ts +2 -1
  42. package/dist/lib/transforms/collapse-expand-combo.d.ts +4 -3
  43. package/dist/lib/transforms/collapse-expand-node.d.ts +12 -0
  44. package/dist/lib/transforms/get-edge-actual-ends.d.ts +13 -0
  45. package/dist/lib/transforms/index.d.ts +2 -0
  46. package/dist/lib/transforms/process-parallel-edges.d.ts +6 -4
  47. package/dist/lib/transforms/types.d.ts +2 -2
  48. package/dist/lib/transforms/update-related-edge.d.ts +2 -1
  49. package/dist/lib/transforms/utils.d.ts +13 -0
  50. package/dist/lib/types/animation.d.ts +1 -2
  51. package/dist/lib/types/node.d.ts +12 -0
  52. package/dist/lib/utils/animation.d.ts +17 -29
  53. package/dist/lib/utils/collapsibility.d.ts +9 -0
  54. package/dist/lib/utils/element.d.ts +19 -2
  55. package/dist/lib/utils/theme.d.ts +9 -0
  56. package/dist/lib/utils/transform.d.ts +14 -0
  57. package/esm/animations/executor.d.ts +4 -5
  58. package/esm/animations/executor.js +31 -48
  59. package/esm/animations/executor.js.map +1 -1
  60. package/esm/animations/index.d.ts +22 -8
  61. package/esm/animations/index.js +10 -12
  62. package/esm/animations/index.js.map +1 -1
  63. package/esm/animations/types.d.ts +78 -20
  64. package/esm/behaviors/collapse-expand.d.ts +10 -1
  65. package/esm/behaviors/collapse-expand.js +15 -6
  66. package/esm/behaviors/collapse-expand.js.map +1 -1
  67. package/esm/behaviors/create-edge.js +2 -2
  68. package/esm/behaviors/create-edge.js.map +1 -1
  69. package/esm/behaviors/drag-canvas.d.ts +1 -0
  70. package/esm/behaviors/drag-canvas.js +5 -1
  71. package/esm/behaviors/drag-canvas.js.map +1 -1
  72. package/esm/behaviors/drag-element.js +2 -2
  73. package/esm/behaviors/drag-element.js.map +1 -1
  74. package/esm/behaviors/hover-element.d.ts +2 -0
  75. package/esm/behaviors/hover-element.js +12 -2
  76. package/esm/behaviors/hover-element.js.map +1 -1
  77. package/esm/constants/animation.d.ts +3 -2
  78. package/esm/constants/animation.js.map +1 -1
  79. package/esm/constants/events/animation.d.ts +2 -0
  80. package/esm/constants/events/animation.js +2 -0
  81. package/esm/constants/events/animation.js.map +1 -1
  82. package/esm/constants/events/graph.d.ts +0 -12
  83. package/esm/constants/events/graph.js +0 -12
  84. package/esm/constants/events/graph.js.map +1 -1
  85. package/esm/elements/base-element.d.ts +35 -0
  86. package/esm/elements/base-element.js +42 -0
  87. package/esm/elements/base-element.js.map +1 -0
  88. package/esm/elements/combos/base-combo.d.ts +8 -32
  89. package/esm/elements/combos/base-combo.js +53 -55
  90. package/esm/elements/combos/base-combo.js.map +1 -1
  91. package/esm/elements/combos/circle.d.ts +1 -2
  92. package/esm/elements/combos/circle.js +1 -12
  93. package/esm/elements/combos/circle.js.map +1 -1
  94. package/esm/elements/combos/rect.js +1 -2
  95. package/esm/elements/combos/rect.js.map +1 -1
  96. package/esm/elements/edges/base-edge.d.ts +21 -30
  97. package/esm/elements/edges/base-edge.js +38 -35
  98. package/esm/elements/edges/base-edge.js.map +1 -1
  99. package/esm/elements/edges/polyline.js +8 -4
  100. package/esm/elements/edges/polyline.js.map +1 -1
  101. package/esm/elements/nodes/base-node.d.ts +7 -27
  102. package/esm/elements/nodes/base-node.js +16 -38
  103. package/esm/elements/nodes/base-node.js.map +1 -1
  104. package/esm/elements/nodes/html.d.ts +3 -2
  105. package/esm/elements/nodes/html.js +13 -3
  106. package/esm/elements/nodes/html.js.map +1 -1
  107. package/esm/elements/shapes/badge.d.ts +1 -1
  108. package/esm/elements/shapes/base-shape.d.ts +6 -0
  109. package/esm/elements/shapes/base-shape.js +23 -6
  110. package/esm/elements/shapes/base-shape.js.map +1 -1
  111. package/esm/exports.d.ts +3 -2
  112. package/esm/layouts/types.d.ts +1 -1
  113. package/esm/plugins/background/index.d.ts +38 -0
  114. package/esm/plugins/background/index.js +49 -0
  115. package/esm/plugins/background/index.js.map +1 -0
  116. package/esm/plugins/{contextmenu.d.ts → contextmenu/index.d.ts} +5 -5
  117. package/esm/plugins/{contextmenu.js → contextmenu/index.js} +4 -4
  118. package/esm/plugins/contextmenu/index.js.map +1 -0
  119. package/esm/{utils/contextmenu.js → plugins/contextmenu/util.js} +1 -1
  120. package/esm/{utils/contextmenu.js.map → plugins/contextmenu/util.js.map} +1 -1
  121. package/esm/plugins/history/index.js +1 -1
  122. package/esm/plugins/history/index.js.map +1 -1
  123. package/esm/plugins/history/{utils.js → util.js} +1 -1
  124. package/esm/plugins/history/util.js.map +1 -0
  125. package/esm/plugins/index.d.ts +2 -0
  126. package/esm/plugins/index.js +1 -0
  127. package/esm/plugins/index.js.map +1 -1
  128. package/esm/plugins/legend.d.ts +1 -1
  129. package/esm/plugins/legend.js +1 -1
  130. package/esm/plugins/timebar.d.ts +1 -1
  131. package/esm/plugins/timebar.js +1 -1
  132. package/esm/plugins/timebar.js.map +1 -1
  133. package/esm/plugins/toolbar/index.d.ts +2 -2
  134. package/esm/plugins/toolbar/index.js +1 -1
  135. package/{dist/lib/plugins/watermark.d.ts → esm/plugins/watermark/index.d.ts} +3 -3
  136. package/esm/plugins/{watermark.js → watermark/index.js} +4 -4
  137. package/esm/plugins/watermark/index.js.map +1 -0
  138. package/esm/{utils/watermark.js → plugins/watermark/util.js} +1 -1
  139. package/esm/plugins/watermark/util.js.map +1 -0
  140. package/esm/registry/build-in.js +14 -6
  141. package/esm/registry/build-in.js.map +1 -1
  142. package/esm/registry/index.js +6 -4
  143. package/esm/registry/index.js.map +1 -1
  144. package/esm/runtime/animation.d.ts +54 -0
  145. package/esm/runtime/animation.js +139 -0
  146. package/esm/runtime/animation.js.map +1 -0
  147. package/esm/runtime/canvas.js +0 -5
  148. package/esm/runtime/canvas.js.map +1 -1
  149. package/esm/runtime/data.d.ts +4 -4
  150. package/esm/runtime/data.js +16 -17
  151. package/esm/runtime/data.js.map +1 -1
  152. package/esm/runtime/element.d.ts +26 -40
  153. package/esm/runtime/element.js +218 -179
  154. package/esm/runtime/element.js.map +1 -1
  155. package/esm/runtime/graph.d.ts +1 -0
  156. package/esm/runtime/graph.js +50 -21
  157. package/esm/runtime/graph.js.map +1 -1
  158. package/esm/runtime/layout.d.ts +7 -0
  159. package/esm/runtime/layout.js +44 -3
  160. package/esm/runtime/layout.js.map +1 -1
  161. package/esm/runtime/transform.d.ts +1 -0
  162. package/esm/runtime/transform.js +9 -2
  163. package/esm/runtime/transform.js.map +1 -1
  164. package/esm/runtime/types.d.ts +7 -0
  165. package/esm/runtime/viewport.js +2 -2
  166. package/esm/runtime/viewport.js.map +1 -1
  167. package/esm/spec/data.d.ts +14 -0
  168. package/esm/spec/element/animation.d.ts +3 -9
  169. package/esm/spec/element/combo.d.ts +4 -3
  170. package/esm/spec/element/edge.d.ts +4 -3
  171. package/esm/spec/element/node.d.ts +4 -3
  172. package/esm/spec/graph.d.ts +1 -1
  173. package/esm/themes/base.js +14 -10
  174. package/esm/themes/base.js.map +1 -1
  175. package/esm/transforms/base-transform.d.ts +2 -1
  176. package/esm/transforms/base-transform.js +1 -1
  177. package/esm/transforms/base-transform.js.map +1 -1
  178. package/esm/transforms/collapse-expand-combo.d.ts +4 -3
  179. package/esm/transforms/collapse-expand-combo.js +9 -25
  180. package/esm/transforms/collapse-expand-combo.js.map +1 -1
  181. package/esm/transforms/collapse-expand-node.d.ts +12 -0
  182. package/esm/transforms/collapse-expand-node.js +91 -0
  183. package/esm/transforms/collapse-expand-node.js.map +1 -0
  184. package/esm/transforms/get-edge-actual-ends.d.ts +13 -0
  185. package/esm/transforms/get-edge-actual-ends.js +36 -0
  186. package/esm/transforms/get-edge-actual-ends.js.map +1 -0
  187. package/esm/transforms/index.d.ts +2 -0
  188. package/esm/transforms/index.js +2 -0
  189. package/esm/transforms/index.js.map +1 -1
  190. package/esm/transforms/process-parallel-edges.d.ts +6 -4
  191. package/esm/transforms/process-parallel-edges.js +42 -27
  192. package/esm/transforms/process-parallel-edges.js.map +1 -1
  193. package/esm/transforms/types.d.ts +2 -2
  194. package/esm/transforms/types.js +1 -10
  195. package/esm/transforms/types.js.map +1 -1
  196. package/esm/transforms/update-related-edge.d.ts +2 -1
  197. package/esm/transforms/update-related-edge.js +4 -1
  198. package/esm/transforms/update-related-edge.js.map +1 -1
  199. package/esm/transforms/utils.d.ts +13 -0
  200. package/esm/transforms/utils.js +25 -0
  201. package/esm/transforms/utils.js.map +1 -0
  202. package/esm/types/animation.d.ts +1 -2
  203. package/esm/types/node.d.ts +12 -0
  204. package/esm/utils/animation.d.ts +17 -29
  205. package/esm/utils/animation.js +64 -54
  206. package/esm/utils/animation.js.map +1 -1
  207. package/esm/utils/cache.js +0 -1
  208. package/esm/utils/cache.js.map +1 -1
  209. package/esm/utils/collapsibility.d.ts +9 -0
  210. package/esm/utils/collapsibility.js +11 -0
  211. package/esm/utils/collapsibility.js.map +1 -0
  212. package/esm/utils/dom.js +1 -2
  213. package/esm/utils/dom.js.map +1 -1
  214. package/esm/utils/edge.js +2 -1
  215. package/esm/utils/edge.js.map +1 -1
  216. package/esm/utils/element.d.ts +19 -2
  217. package/esm/utils/element.js +24 -3
  218. package/esm/utils/element.js.map +1 -1
  219. package/esm/utils/theme.d.ts +9 -0
  220. package/esm/utils/theme.js +17 -0
  221. package/esm/utils/theme.js.map +1 -0
  222. package/esm/utils/transform.d.ts +14 -0
  223. package/esm/utils/transform.js +24 -0
  224. package/esm/utils/transform.js.map +1 -1
  225. package/lib/animations/executor.d.ts +4 -5
  226. package/lib/animations/executor.js +30 -47
  227. package/lib/animations/executor.js.map +1 -1
  228. package/lib/animations/index.d.ts +22 -8
  229. package/lib/animations/index.js +12 -14
  230. package/lib/animations/index.js.map +1 -1
  231. package/lib/animations/types.d.ts +78 -20
  232. package/lib/behaviors/collapse-expand.d.ts +10 -1
  233. package/lib/behaviors/collapse-expand.js +15 -6
  234. package/lib/behaviors/collapse-expand.js.map +1 -1
  235. package/lib/behaviors/create-edge.js +2 -2
  236. package/lib/behaviors/create-edge.js.map +1 -1
  237. package/lib/behaviors/drag-canvas.d.ts +1 -0
  238. package/lib/behaviors/drag-canvas.js +5 -1
  239. package/lib/behaviors/drag-canvas.js.map +1 -1
  240. package/lib/behaviors/drag-element.js +2 -2
  241. package/lib/behaviors/drag-element.js.map +1 -1
  242. package/lib/behaviors/hover-element.d.ts +2 -0
  243. package/lib/behaviors/hover-element.js +12 -2
  244. package/lib/behaviors/hover-element.js.map +1 -1
  245. package/lib/constants/animation.d.ts +3 -2
  246. package/lib/constants/animation.js.map +1 -1
  247. package/lib/constants/events/animation.d.ts +2 -0
  248. package/lib/constants/events/animation.js +2 -0
  249. package/lib/constants/events/animation.js.map +1 -1
  250. package/lib/constants/events/graph.d.ts +0 -12
  251. package/lib/constants/events/graph.js +0 -12
  252. package/lib/constants/events/graph.js.map +1 -1
  253. package/lib/elements/base-element.d.ts +35 -0
  254. package/lib/elements/base-element.js +46 -0
  255. package/lib/elements/base-element.js.map +1 -0
  256. package/lib/elements/combos/base-combo.d.ts +8 -32
  257. package/lib/elements/combos/base-combo.js +52 -54
  258. package/lib/elements/combos/base-combo.js.map +1 -1
  259. package/lib/elements/combos/circle.d.ts +1 -2
  260. package/lib/elements/combos/circle.js +1 -12
  261. package/lib/elements/combos/circle.js.map +1 -1
  262. package/lib/elements/combos/rect.js +1 -2
  263. package/lib/elements/combos/rect.js.map +1 -1
  264. package/lib/elements/edges/base-edge.d.ts +21 -30
  265. package/lib/elements/edges/base-edge.js +38 -35
  266. package/lib/elements/edges/base-edge.js.map +1 -1
  267. package/lib/elements/edges/polyline.js +8 -4
  268. package/lib/elements/edges/polyline.js.map +1 -1
  269. package/lib/elements/nodes/base-node.d.ts +7 -27
  270. package/lib/elements/nodes/base-node.js +15 -37
  271. package/lib/elements/nodes/base-node.js.map +1 -1
  272. package/lib/elements/nodes/html.d.ts +3 -2
  273. package/lib/elements/nodes/html.js +12 -2
  274. package/lib/elements/nodes/html.js.map +1 -1
  275. package/lib/elements/shapes/badge.d.ts +1 -1
  276. package/lib/elements/shapes/base-shape.d.ts +6 -0
  277. package/lib/elements/shapes/base-shape.js +23 -6
  278. package/lib/elements/shapes/base-shape.js.map +1 -1
  279. package/lib/exports.d.ts +3 -2
  280. package/lib/layouts/types.d.ts +1 -1
  281. package/lib/plugins/background/index.d.ts +38 -0
  282. package/lib/plugins/background/index.js +53 -0
  283. package/lib/plugins/background/index.js.map +1 -0
  284. package/lib/plugins/{contextmenu.d.ts → contextmenu/index.d.ts} +5 -5
  285. package/lib/plugins/{contextmenu.js → contextmenu/index.js} +6 -6
  286. package/lib/plugins/{contextmenu.js.map → contextmenu/index.js.map} +1 -1
  287. package/lib/{utils/contextmenu.js → plugins/contextmenu/util.js} +1 -1
  288. package/lib/{utils/contextmenu.js.map → plugins/contextmenu/util.js.map} +1 -1
  289. package/lib/plugins/history/index.js +2 -2
  290. package/lib/plugins/history/index.js.map +1 -1
  291. package/lib/plugins/history/{utils.js → util.js} +1 -1
  292. package/lib/plugins/history/util.js.map +1 -0
  293. package/lib/plugins/index.d.ts +2 -0
  294. package/lib/plugins/index.js +3 -1
  295. package/lib/plugins/index.js.map +1 -1
  296. package/lib/plugins/legend.d.ts +1 -1
  297. package/lib/plugins/legend.js +1 -1
  298. package/lib/plugins/timebar.d.ts +1 -1
  299. package/lib/plugins/timebar.js +1 -1
  300. package/lib/plugins/timebar.js.map +1 -1
  301. package/lib/plugins/toolbar/index.d.ts +2 -2
  302. package/lib/plugins/toolbar/index.js +1 -1
  303. package/{esm/plugins/watermark.d.ts → lib/plugins/watermark/index.d.ts} +3 -3
  304. package/lib/plugins/{watermark.js → watermark/index.js} +6 -6
  305. package/lib/plugins/watermark/index.js.map +1 -0
  306. package/lib/{utils/watermark.js → plugins/watermark/util.js} +1 -1
  307. package/lib/plugins/watermark/util.js.map +1 -0
  308. package/lib/registry/build-in.js +11 -3
  309. package/lib/registry/build-in.js.map +1 -1
  310. package/lib/registry/index.js +6 -4
  311. package/lib/registry/index.js.map +1 -1
  312. package/lib/runtime/animation.d.ts +54 -0
  313. package/lib/runtime/animation.js +143 -0
  314. package/lib/runtime/animation.js.map +1 -0
  315. package/lib/runtime/canvas.js +0 -5
  316. package/lib/runtime/canvas.js.map +1 -1
  317. package/lib/runtime/data.d.ts +4 -4
  318. package/lib/runtime/data.js +15 -16
  319. package/lib/runtime/data.js.map +1 -1
  320. package/lib/runtime/element.d.ts +26 -40
  321. package/lib/runtime/element.js +215 -176
  322. package/lib/runtime/element.js.map +1 -1
  323. package/lib/runtime/graph.d.ts +1 -0
  324. package/lib/runtime/graph.js +49 -20
  325. package/lib/runtime/graph.js.map +1 -1
  326. package/lib/runtime/layout.d.ts +7 -0
  327. package/lib/runtime/layout.js +43 -2
  328. package/lib/runtime/layout.js.map +1 -1
  329. package/lib/runtime/transform.d.ts +1 -0
  330. package/lib/runtime/transform.js +9 -2
  331. package/lib/runtime/transform.js.map +1 -1
  332. package/lib/runtime/types.d.ts +7 -0
  333. package/lib/runtime/viewport.js +1 -1
  334. package/lib/runtime/viewport.js.map +1 -1
  335. package/lib/spec/data.d.ts +14 -0
  336. package/lib/spec/element/animation.d.ts +3 -9
  337. package/lib/spec/element/combo.d.ts +4 -3
  338. package/lib/spec/element/edge.d.ts +4 -3
  339. package/lib/spec/element/node.d.ts +4 -3
  340. package/lib/spec/graph.d.ts +1 -1
  341. package/lib/themes/base.js +14 -10
  342. package/lib/themes/base.js.map +1 -1
  343. package/lib/transforms/base-transform.d.ts +2 -1
  344. package/lib/transforms/base-transform.js +1 -1
  345. package/lib/transforms/base-transform.js.map +1 -1
  346. package/lib/transforms/collapse-expand-combo.d.ts +4 -3
  347. package/lib/transforms/collapse-expand-combo.js +13 -29
  348. package/lib/transforms/collapse-expand-combo.js.map +1 -1
  349. package/lib/transforms/collapse-expand-node.d.ts +12 -0
  350. package/lib/transforms/collapse-expand-node.js +95 -0
  351. package/lib/transforms/collapse-expand-node.js.map +1 -0
  352. package/lib/transforms/get-edge-actual-ends.d.ts +13 -0
  353. package/lib/transforms/get-edge-actual-ends.js +41 -0
  354. package/lib/transforms/get-edge-actual-ends.js.map +1 -0
  355. package/lib/transforms/index.d.ts +2 -0
  356. package/lib/transforms/index.js +5 -1
  357. package/lib/transforms/index.js.map +1 -1
  358. package/lib/transforms/process-parallel-edges.d.ts +6 -4
  359. package/lib/transforms/process-parallel-edges.js +41 -26
  360. package/lib/transforms/process-parallel-edges.js.map +1 -1
  361. package/lib/transforms/types.d.ts +2 -2
  362. package/lib/transforms/types.js +0 -12
  363. package/lib/transforms/types.js.map +1 -1
  364. package/lib/transforms/update-related-edge.d.ts +2 -1
  365. package/lib/transforms/update-related-edge.js +4 -1
  366. package/lib/transforms/update-related-edge.js.map +1 -1
  367. package/lib/transforms/utils.d.ts +13 -0
  368. package/lib/transforms/utils.js +29 -0
  369. package/lib/transforms/utils.js.map +1 -0
  370. package/lib/types/animation.d.ts +1 -2
  371. package/lib/types/node.d.ts +12 -0
  372. package/lib/utils/animation.d.ts +17 -29
  373. package/lib/utils/animation.js +65 -56
  374. package/lib/utils/animation.js.map +1 -1
  375. package/lib/utils/cache.js +0 -1
  376. package/lib/utils/cache.js.map +1 -1
  377. package/lib/utils/collapsibility.d.ts +9 -0
  378. package/lib/utils/collapsibility.js +15 -0
  379. package/lib/utils/collapsibility.js.map +1 -0
  380. package/lib/utils/dom.js +1 -2
  381. package/lib/utils/dom.js.map +1 -1
  382. package/lib/utils/edge.js +2 -1
  383. package/lib/utils/edge.js.map +1 -1
  384. package/lib/utils/element.d.ts +19 -2
  385. package/lib/utils/element.js +26 -3
  386. package/lib/utils/element.js.map +1 -1
  387. package/lib/utils/theme.d.ts +9 -0
  388. package/lib/utils/theme.js +21 -0
  389. package/lib/utils/theme.js.map +1 -0
  390. package/lib/utils/transform.d.ts +14 -0
  391. package/lib/utils/transform.js +26 -1
  392. package/lib/utils/transform.js.map +1 -1
  393. package/package.json +6 -6
  394. package/src/animations/executor.ts +39 -61
  395. package/src/animations/index.ts +19 -15
  396. package/src/animations/types.ts +82 -27
  397. package/src/behaviors/collapse-expand.ts +25 -9
  398. package/src/behaviors/create-edge.ts +2 -2
  399. package/src/behaviors/drag-canvas.ts +6 -1
  400. package/src/behaviors/drag-element.ts +2 -2
  401. package/src/behaviors/hover-element.ts +17 -3
  402. package/src/constants/animation.ts +4 -2
  403. package/src/constants/events/animation.ts +2 -0
  404. package/src/constants/events/graph.ts +0 -12
  405. package/src/elements/base-element.ts +52 -0
  406. package/src/elements/combos/base-combo.ts +66 -74
  407. package/src/elements/combos/circle.ts +2 -20
  408. package/src/elements/combos/rect.ts +1 -2
  409. package/src/elements/edges/base-edge.ts +57 -45
  410. package/src/elements/edges/polyline.ts +8 -4
  411. package/src/elements/nodes/base-node.ts +20 -47
  412. package/src/elements/nodes/html.ts +17 -4
  413. package/src/elements/shapes/base-shape.ts +24 -9
  414. package/src/exports.ts +3 -2
  415. package/src/layouts/types.ts +1 -1
  416. package/src/plugins/background/index.ts +65 -0
  417. package/src/plugins/{contextmenu.ts → contextmenu/index.ts} +7 -7
  418. package/src/plugins/history/index.ts +1 -1
  419. package/src/plugins/index.ts +2 -0
  420. package/src/plugins/legend.ts +1 -1
  421. package/src/plugins/timebar.ts +2 -2
  422. package/src/plugins/toolbar/index.ts +2 -2
  423. package/src/plugins/{watermark.ts → watermark/index.ts} +5 -5
  424. package/src/registry/build-in.ts +21 -5
  425. package/src/registry/index.ts +4 -5
  426. package/src/runtime/animation.ts +186 -0
  427. package/src/runtime/canvas.ts +0 -5
  428. package/src/runtime/data.ts +16 -19
  429. package/src/runtime/element.ts +289 -255
  430. package/src/runtime/graph.ts +52 -37
  431. package/src/runtime/layout.ts +51 -4
  432. package/src/runtime/transform.ts +10 -2
  433. package/src/runtime/types.ts +7 -0
  434. package/src/runtime/viewport.ts +2 -2
  435. package/src/spec/data.ts +14 -1
  436. package/src/spec/element/animation.ts +3 -13
  437. package/src/spec/element/combo.ts +4 -3
  438. package/src/spec/element/edge.ts +4 -3
  439. package/src/spec/element/node.ts +4 -3
  440. package/src/spec/graph.ts +1 -1
  441. package/src/themes/base.ts +14 -10
  442. package/src/transforms/base-transform.ts +2 -1
  443. package/src/transforms/collapse-expand-combo.ts +11 -32
  444. package/src/transforms/collapse-expand-node.ts +107 -0
  445. package/src/transforms/get-edge-actual-ends.ts +45 -0
  446. package/src/transforms/index.ts +2 -0
  447. package/src/transforms/process-parallel-edges.ts +50 -36
  448. package/src/transforms/types.ts +5 -5
  449. package/src/transforms/update-related-edge.ts +5 -1
  450. package/src/transforms/utils.ts +31 -0
  451. package/src/types/animation.ts +1 -3
  452. package/src/types/node.ts +12 -0
  453. package/src/utils/animation.ts +73 -63
  454. package/src/utils/cache.ts +0 -1
  455. package/src/utils/collapsibility.ts +12 -0
  456. package/src/utils/dom.ts +1 -2
  457. package/src/utils/edge.ts +2 -1
  458. package/src/utils/element.ts +28 -3
  459. package/src/utils/theme.ts +18 -0
  460. package/src/utils/transform.ts +33 -0
  461. package/dist/lib/utils/combo.d.ts +0 -34
  462. package/esm/plugins/contextmenu.js.map +0 -1
  463. package/esm/plugins/history/utils.js.map +0 -1
  464. package/esm/plugins/watermark.js.map +0 -1
  465. package/esm/utils/combo.d.ts +0 -34
  466. package/esm/utils/combo.js +0 -111
  467. package/esm/utils/combo.js.map +0 -1
  468. package/esm/utils/watermark.js.map +0 -1
  469. package/lib/plugins/history/utils.js.map +0 -1
  470. package/lib/plugins/watermark.js.map +0 -1
  471. package/lib/utils/combo.d.ts +0 -34
  472. package/lib/utils/combo.js +0 -117
  473. package/lib/utils/combo.js.map +0 -1
  474. package/lib/utils/watermark.js.map +0 -1
  475. package/src/utils/combo.ts +0 -134
  476. /package/dist/lib/{utils/contextmenu.d.ts → plugins/contextmenu/util.d.ts} +0 -0
  477. /package/dist/lib/plugins/history/{utils.d.ts → util.d.ts} +0 -0
  478. /package/dist/lib/{utils/watermark.d.ts → plugins/watermark/util.d.ts} +0 -0
  479. /package/esm/{utils/contextmenu.d.ts → plugins/contextmenu/util.d.ts} +0 -0
  480. /package/esm/plugins/history/{utils.d.ts → util.d.ts} +0 -0
  481. /package/esm/{utils/watermark.d.ts → plugins/watermark/util.d.ts} +0 -0
  482. /package/lib/{utils/contextmenu.d.ts → plugins/contextmenu/util.d.ts} +0 -0
  483. /package/lib/plugins/history/{utils.d.ts → util.d.ts} +0 -0
  484. /package/lib/{utils/watermark.d.ts → plugins/watermark/util.d.ts} +0 -0
  485. /package/src/{utils/contextmenu.ts → plugins/contextmenu/util.ts} +0 -0
  486. /package/src/plugins/history/{utils.ts → util.ts} +0 -0
  487. /package/src/{utils/watermark.ts → plugins/watermark/util.ts} +0 -0
@@ -1,22 +1,54 @@
1
- import type { IAnimation, IAnimationEffectTiming } from '@antv/g';
2
- import type { Element, State } from '../types';
1
+ import type { IAnimation } from '@antv/g';
2
+ import type { AnimationStage } from '../spec/element/animation';
3
+ import type { Element, ElementType, State } from '../types';
4
+
5
+ export type STDAnimation = AnimationOptions[];
3
6
 
4
7
  /**
5
- * <zh/> 为 string 时,会从注册的动画中获取
8
+ * <zh/> 元素动画选项
6
9
  *
7
- * <en/> When it is a string, it will be obtained from the registered animation
10
+ * <en/> Element animation options
8
11
  */
9
- export type Animation = false | string | STDAnimation;
10
-
11
- export type STDAnimation = ConfigurableAnimationOptions[];
12
-
13
- interface ConfigurableAnimationOptions extends AnimationEffectTiming {
12
+ export interface AnimationOptions extends AnimationEffectTiming {
13
+ /**
14
+ * <zh/> 执行动画的字段(样式)名
15
+ *
16
+ * <en/> Field (style) name of the animation
17
+ */
14
18
  fields: string[];
19
+ /**
20
+ * <zh/> 执行动画的图形,默认为当前元素
21
+ *
22
+ * <en/> Shape of the animation, default is the current element
23
+ */
15
24
  shape?: string;
25
+ /**
26
+ * <zh/> 参与动画的状态
27
+ *
28
+ * <en/> States involved in the animation
29
+ */
16
30
  states?: State[];
17
31
  }
18
32
 
19
33
  export interface AnimationContext {
34
+ /**
35
+ * <zh/> 执行动画的元素
36
+ *
37
+ * <en/> Element to execute animation
38
+ */
39
+ element: Element;
40
+ /**
41
+ * <zh/> 元素类型
42
+ *
43
+ * <en/> Element type
44
+ */
45
+ elementType: ElementType;
46
+ /**
47
+ * <zh/> 动画阶段
48
+ *
49
+ * <en/> Animation stage
50
+ */
51
+ stage: AnimationStage;
20
52
  /**
21
53
  * <zh/> 动画的源样式
22
54
  *
@@ -36,32 +68,55 @@ export interface AnimationContext {
36
68
  *
37
69
  * <en/> For example, before the element is destroyed, the final state opacity of the element needs to be set to 0
38
70
  */
39
- modifiedStyle?: Record<string, unknown>;
71
+ modifiedStyle: Record<string, unknown>;
72
+ }
73
+
74
+ /**
75
+ * <zh/> 动画效果时序
76
+ *
77
+ * <en/> Animation effect timing
78
+ */
79
+ export interface AnimationEffectTiming {
40
80
  /**
41
- * <zh/> 动画配置过滤
81
+ * <zh/> 动画延迟时间
42
82
  *
43
- * <en/> Animation configuration filter
44
- * @remarks
45
- * <zh/> 某些情况下,需要过滤掉一些动画配置,例如位移动画只会作用于元素根节点图形,不会作用于子图形。这项配置通常用于优化动画性能,避免不必要的动画执行
83
+ * <en/> Animation delay time
84
+ */
85
+ delay?: number;
86
+ /**
87
+ * <zh/> 动画方向
46
88
  *
47
- * <en/> In some cases, it is necessary to filter out some animation configurations. For example, the displacement animation will only affect the root node shape of the element, not the child shape. This configuration is usually used to optimize animation performance and avoid unnecessary animation execution
89
+ * <en/> Animation direction
48
90
  */
49
- animationsFilter?: (animation: ConfigurableAnimationOptions) => boolean;
91
+ direction?: PlaybackDirection;
50
92
  /**
51
- * <zh/> 元素状态
93
+ * <zh/> 动画持续时间
52
94
  *
53
- * <en/> Element states
95
+ * <en/> Animation duration
54
96
  */
55
- states: State[];
97
+ duration?: number;
98
+ /**
99
+ * <zh/> 动画缓动函数
100
+ *
101
+ * <en/> Animation easing function
102
+ */
103
+ easing?: string;
104
+ /**
105
+ * <zh/> 动画结束后的填充模式
106
+ *
107
+ * <en/> Fill mode after the animation ends
108
+ */
109
+ fill?: FillMode;
110
+ /**
111
+ * <zh/> 动画迭代次数
112
+ *
113
+ * <en/> Number of iterations of the animation
114
+ */
115
+ iterations?: number;
56
116
  }
57
117
 
58
- export type AnimationEffectTiming = Partial<
59
- Pick<IAnimationEffectTiming, 'duration' | 'delay' | 'easing' | 'iterations' | 'direction' | 'fill'>
60
- >;
61
-
62
118
  export type AnimationExecutor = (
63
- shape: Element,
64
- animation: Animation | false,
65
- baseEffectTiming: AnimationEffectTiming,
66
- context: AnimationContext,
119
+ element: Element,
120
+ keyframes: [Record<string, unknown>, Record<string, unknown>],
121
+ options: STDAnimation,
67
122
  ) => IAnimation | null;
@@ -1,13 +1,14 @@
1
1
  import { isFunction } from '@antv/util';
2
2
  import { CommonEvent } from '../constants';
3
3
  import type { RuntimeContext } from '../runtime/types';
4
- import type { ID, IPointerEvent } from '../types';
4
+ import type { ID, IPointerEvent, NodeLikeData } from '../types';
5
+ import { isCollapsed } from '../utils/collapsibility';
5
6
  import { isElement } from '../utils/element';
6
7
  import type { BaseBehaviorOptions } from './base-behavior';
7
8
  import { BaseBehavior } from './base-behavior';
8
9
 
9
10
  /**
10
- * <zh/> 展开/收起组合元素交互配置项
11
+ * <zh/> 展开/收起元素交互配置项
11
12
  *
12
13
  * <en/> Collapse/Expand combo behavior options
13
14
  */
@@ -26,6 +27,13 @@ export interface CollapseExpandOptions extends BaseBehaviorOptions {
26
27
  * @defaultValue true
27
28
  */
28
29
  enable?: boolean | ((event: IPointerEvent) => boolean);
30
+ /**
31
+ * <zh/> 触发方式
32
+ *
33
+ * <en/> Trigger method
34
+ * @defaultValue 'dblclick'
35
+ */
36
+ trigger?: CommonEvent.CLICK | CommonEvent.DBLCLICK;
29
37
  /**
30
38
  * <zh/> 完成收起时的回调
31
39
  *
@@ -53,6 +61,7 @@ export class CollapseExpand extends BaseBehavior<CollapseExpandOptions> {
53
61
  static defaultOptions: Partial<CollapseExpandOptions> = {
54
62
  enable: true,
55
63
  animation: true,
64
+ trigger: CommonEvent.DBLCLICK,
56
65
  };
57
66
 
58
67
  constructor(context: RuntimeContext, options: CollapseExpandOptions) {
@@ -61,16 +70,24 @@ export class CollapseExpand extends BaseBehavior<CollapseExpandOptions> {
61
70
  this.bindEvents();
62
71
  }
63
72
 
64
- private bindEvents() {
65
- const { graph } = this.context;
73
+ public update(options: Partial<CollapseExpandOptions>) {
66
74
  this.unbindEvents();
75
+ super.update(options);
76
+ this.bindEvents();
77
+ }
67
78
 
68
- graph.on(`combo:${CommonEvent.DBLCLICK}`, this.onCollapseExpand);
79
+ private bindEvents() {
80
+ const { graph } = this.context;
81
+ const { trigger } = this.options;
82
+ graph.on(`node:${trigger}`, this.onCollapseExpand);
83
+ graph.on(`combo:${trigger}`, this.onCollapseExpand);
69
84
  }
70
85
 
71
86
  private unbindEvents() {
72
87
  const { graph } = this.context;
73
- graph.off(`combo:${CommonEvent.DBLCLICK}`, this.onCollapseExpand);
88
+ const { trigger } = this.options;
89
+ graph.off(`node:${trigger}`, this.onCollapseExpand);
90
+ graph.off(`combo:${trigger}`, this.onCollapseExpand);
74
91
  }
75
92
 
76
93
  private onCollapseExpand = async (event: IPointerEvent) => {
@@ -80,12 +97,11 @@ export class CollapseExpand extends BaseBehavior<CollapseExpandOptions> {
80
97
 
81
98
  const id = target.id;
82
99
  const { model, graph } = this.context;
83
- const data = model.getComboData([id])[0];
100
+ const data = model.getElementDataById(id) as NodeLikeData;
84
101
  if (!data) return false;
85
102
 
86
103
  const { onCollapse, onExpand, animation } = this.options;
87
- const isCollapse = data.style?.collapsed;
88
- if (isCollapse) {
104
+ if (isCollapsed(data)) {
89
105
  await graph.expandElement(id, animation);
90
106
  onExpand?.(id);
91
107
  } else {
@@ -157,7 +157,7 @@ export class CreateEdge extends BaseBehavior<CreateEdgeOptions> {
157
157
 
158
158
  model.translateNodeTo(ASSIST_NODE_ID, [event.canvas.x, event.canvas.y]);
159
159
 
160
- await element!.draw({ animation: false, silence: true });
160
+ await element!.draw({ animation: false, silence: true })?.finished;
161
161
  };
162
162
 
163
163
  private createEdge = (event: IElementEvent) => {
@@ -183,7 +183,7 @@ export class CreateEdge extends BaseBehavior<CreateEdgeOptions> {
183
183
 
184
184
  this.source = undefined;
185
185
 
186
- await element!.draw({ animation: false, silence: true });
186
+ await element!.draw({ animation: false, silence: true })?.finished;
187
187
  };
188
188
 
189
189
  private getSelectedNodeIDs(currTarget: ID[]) {
@@ -87,13 +87,13 @@ export class DragCanvas extends BaseBehavior<DragCanvasOptions> {
87
87
  * @internal
88
88
  */
89
89
  public update(options: Partial<DragCanvasOptions>): void {
90
+ this.unbindEvents();
90
91
  super.update(options);
91
92
  this.bindEvents();
92
93
  }
93
94
 
94
95
  private bindEvents() {
95
96
  const { trigger } = this.options;
96
- this.shortcut.unbindAll();
97
97
  const { graph } = this.context;
98
98
 
99
99
  if (isObject(trigger)) {
@@ -144,6 +144,11 @@ export class DragCanvas extends BaseBehavior<DragCanvasOptions> {
144
144
  return !!enable;
145
145
  }
146
146
 
147
+ private unbindEvents() {
148
+ this.shortcut.unbindAll();
149
+ this.context.graph.off(CanvasEvent.DRAG, this.onDrag);
150
+ }
151
+
147
152
  public destroy(): void {
148
153
  this.shortcut.destroy();
149
154
  this.context.canvas.setCursor(this.defaultCursor);
@@ -268,7 +268,7 @@ export class DragElement extends BaseBehavior<DragElementOptions> {
268
268
  }
269
269
  model.setParent(id, modifiedParentId, COMBO_KEY);
270
270
  });
271
- await element?.draw({ animation: true });
271
+ await element?.draw({ animation: true })?.finished;
272
272
  };
273
273
 
274
274
  /**
@@ -304,7 +304,7 @@ export class DragElement extends BaseBehavior<DragElementOptions> {
304
304
  });
305
305
 
306
306
  if (dropEffect === 'move') ids.forEach((id) => model.refreshComboData(id));
307
- await element!.draw({ animation: this.animation });
307
+ await element!.draw({ animation: this.animation })?.finished;
308
308
  }
309
309
 
310
310
  private moveShadow(offset: Point) {
@@ -2,7 +2,7 @@ import { isFunction } from '@antv/util';
2
2
  import { CommonEvent } from '../constants';
3
3
  import { ELEMENT_TYPES } from '../constants/element';
4
4
  import type { RuntimeContext } from '../runtime/types';
5
- import type { Element, ElementType, ID, IPointerEvent, State } from '../types';
5
+ import type { Element, ElementType, ID, IDragEvent, IPointerEvent, State } from '../types';
6
6
  import { idsOf } from '../utils/id';
7
7
  import { getElementNthDegreeIds } from '../utils/relation';
8
8
  import type { BaseBehaviorOptions } from './base-behavior';
@@ -77,18 +77,24 @@ export interface HoverElementOptions extends BaseBehaviorOptions {
77
77
  */
78
78
  export class HoverElement extends BaseBehavior<HoverElementOptions> {
79
79
  static defaultOptions: Partial<HoverElementOptions> = {
80
- animation: true,
80
+ animation: false,
81
81
  enable: true,
82
82
  degree: 0,
83
83
  activeState: 'active',
84
84
  inactiveState: undefined,
85
85
  };
86
86
 
87
+ private isFrozen = false;
88
+
87
89
  constructor(context: RuntimeContext, options: HoverElementOptions) {
88
90
  super(context, Object.assign({}, HoverElement.defaultOptions, options));
89
91
  this.bindEvents();
90
92
  }
91
93
 
94
+ private toggleFrozen = (e: IDragEvent) => {
95
+ this.isFrozen = e.type === 'dragstart';
96
+ };
97
+
92
98
  private bindEvents() {
93
99
  const { graph } = this.context;
94
100
  this.unbindEvents();
@@ -97,6 +103,10 @@ export class HoverElement extends BaseBehavior<HoverElementOptions> {
97
103
  graph.on(`${type}:${CommonEvent.POINTER_OVER}`, this.hoverElement);
98
104
  graph.on(`${type}:${CommonEvent.POINTER_OUT}`, this.hoverEndElement);
99
105
  });
106
+
107
+ const canvas = this.context.canvas.document;
108
+ canvas.addEventListener(`${CommonEvent.DRAG_START}`, this.toggleFrozen);
109
+ canvas.addEventListener(`${CommonEvent.DRAG_END}`, this.toggleFrozen);
100
110
  }
101
111
 
102
112
  private hoverElement = (event: IPointerEvent) => {
@@ -149,7 +159,7 @@ export class HoverElement extends BaseBehavior<HoverElementOptions> {
149
159
  };
150
160
 
151
161
  private validate(event: IPointerEvent) {
152
- if (this.destroyed) return false;
162
+ if (this.destroyed || this.isFrozen) return false;
153
163
  const { enable } = this.options;
154
164
  if (isFunction(enable)) return enable(event);
155
165
  return !!enable;
@@ -162,6 +172,10 @@ export class HoverElement extends BaseBehavior<HoverElementOptions> {
162
172
  graph.off(`${type}:${CommonEvent.POINTER_OVER}`, this.hoverElement);
163
173
  graph.off(`${type}:${CommonEvent.POINTER_OUT}`, this.hoverEndElement);
164
174
  });
175
+
176
+ const canvas = this.context.canvas.document;
177
+ canvas.removeEventListener(`${CommonEvent.DRAG_START}`, this.toggleFrozen);
178
+ canvas.removeEventListener(`${CommonEvent.DRAG_END}`, this.toggleFrozen);
165
179
  }
166
180
 
167
181
  public destroy() {
@@ -1,8 +1,10 @@
1
- export const DEFAULT_ANIMATION_OPTIONS: KeyframeAnimationOptions = {
1
+ import type { AnimationEffectTiming } from '../animations/types';
2
+
3
+ export const DEFAULT_ANIMATION_OPTIONS: AnimationEffectTiming = {
2
4
  duration: 500,
3
5
  };
4
6
 
5
- export const DEFAULT_ELEMENTS_ANIMATION_OPTIONS: KeyframeAnimationOptions = {
7
+ export const DEFAULT_ELEMENTS_ANIMATION_OPTIONS: AnimationEffectTiming = {
6
8
  duration: 1000,
7
9
  easing: 'cubic-bezier(0.250, 0.460, 0.450, 0.940)',
8
10
  iterations: 1,
@@ -1,4 +1,6 @@
1
1
  export enum AnimationType {
2
2
  DRAW = 'draw',
3
+ COLLAPSE = 'collapse',
4
+ EXPAND = 'expand',
3
5
  TRANSFORM = 'transform',
4
6
  }
@@ -131,18 +131,6 @@ export enum GraphEvent {
131
131
  * <en/> After the visible area changes
132
132
  */
133
133
  AFTER_TRANSFORM = 'aftertransform',
134
- /**
135
- * <zh/> 状态变化之前
136
- *
137
- * <en/> Before the state changes
138
- */
139
- BEFORE_ELEMENT_STATE_CHANGE = 'beforeelementstatechange',
140
- /**
141
- * <zh/> 状态变化之后
142
- *
143
- * <en/> After the state changes
144
- */
145
- AFTER_ELEMENT_STATE_CHANGE = 'afterelementstatechange',
146
134
  /**
147
135
  * <zh/> 批处理开始
148
136
  *
@@ -0,0 +1,52 @@
1
+ import { IAnimation } from '@antv/g';
2
+ import { Keyframe } from '../types';
3
+ import type { BaseShapeStyleProps } from './shapes';
4
+ import { BaseShape } from './shapes';
5
+
6
+ export abstract class BaseElement<T extends BaseShapeStyleProps> extends BaseShape<T> {
7
+ public get parsedAttributes() {
8
+ return this.attributes as Required<T>;
9
+ }
10
+
11
+ /**
12
+ * <zh/> 动画帧执行函数
13
+ *
14
+ * <en/> Animation frame execution function
15
+ */
16
+ protected onframe() {}
17
+
18
+ public animate(keyframes: Keyframe[], options?: number | KeyframeAnimationOptions | undefined): IAnimation | null {
19
+ const animation = super.animate(keyframes, options);
20
+
21
+ if (animation) {
22
+ animation.onframe = () => this.onframe();
23
+ animation.finished.then(() => this.onframe());
24
+ }
25
+
26
+ return animation;
27
+ }
28
+
29
+ /**
30
+ * <zh/> 在元素完成创建并执行完入场动画后调用
31
+ *
32
+ * <en/> Called after the element is created and the entrance animation is completed
33
+ * @override
34
+ */
35
+ public onCreate() {}
36
+
37
+ /**
38
+ * <zh/> 在元素更新并执行完过渡动画后调用
39
+ *
40
+ * <en/> Called after the element is updated and the transition animation is completed
41
+ * @override
42
+ */
43
+ public onUpdate() {}
44
+
45
+ /**
46
+ * <zh/> 在元素完成退场动画并销毁后调用
47
+ *
48
+ * <en/> Called after the element completes the exit animation and is destroyed
49
+ * @override
50
+ */
51
+ public onDestroy() {}
52
+ }
@@ -1,20 +1,17 @@
1
- import type { AABB, BaseStyleProps, DisplayObject, DisplayObjectConfig, Group } from '@antv/g';
2
- import { deepMix, isEmpty, isFunction } from '@antv/util';
1
+ import { AABB, BaseStyleProps, DisplayObject, DisplayObjectConfig, Group } from '@antv/g';
2
+ import { deepMix, isFunction } from '@antv/util';
3
3
  import { COMBO_KEY } from '../../constants';
4
4
  import type {
5
5
  CollapsedMarkerStyleProps,
6
- Combo,
7
- Node,
6
+ ID,
8
7
  NodeLikeData,
9
8
  Padding,
10
- Placement,
11
9
  Position,
12
10
  Prefix,
13
11
  STDSize,
14
12
  Size,
15
13
  } from '../../types';
16
14
  import { getBBoxHeight, getBBoxWidth, getCombinedBBox, getExpandedBBox } from '../../utils/bbox';
17
- import { getXYByCollapsedOrigin } from '../../utils/combo';
18
15
  import { idOf } from '../../utils/id';
19
16
  import { parsePadding } from '../../utils/padding';
20
17
  import { getXYByPlacement, positionOf } from '../../utils/position';
@@ -46,18 +43,12 @@ export interface BaseComboStyleProps
46
43
  * <en/> The default size of combo when collapsed
47
44
  */
48
45
  collapsedSize?: Size;
49
- /**
50
- * <zh/> 组合收起时的原点
51
- *
52
- * <en/> The origin of combo when collapsed
53
- */
54
- collapsedOrigin?: Placement;
55
46
  /**
56
47
  * <zh/> 组合的子元素,可以是节点或者组合
57
48
  *
58
49
  * <en/> The children of combo, which can be nodes or combos
59
50
  */
60
- childrenNode?: (Node | Combo)[];
51
+ childrenNode?: ID[];
61
52
  /**
62
53
  * <zh/> 组合的子元素数据
63
54
  *
@@ -100,7 +91,6 @@ export abstract class BaseCombo<S extends BaseComboStyleProps = BaseComboStylePr
100
91
  draggable: true,
101
92
  collapsed: false,
102
93
  collapsedSize: 32,
103
- collapsedOrigin: [0.5, 0.5],
104
94
  collapsedMarker: true,
105
95
  collapsedMarkerZIndex: 1,
106
96
  collapsedMarkerFontSize: 12,
@@ -117,34 +107,6 @@ export abstract class BaseCombo<S extends BaseComboStyleProps = BaseComboStylePr
117
107
  */
118
108
  protected abstract drawKeyShape(attributes: Required<S>, container: Group): DisplayObject | undefined;
119
109
 
120
- protected calculatePosition(attributes: Required<S>): Position {
121
- const { x = 0, y = 0, collapsed, childrenNode = [], childrenData = [] } = attributes;
122
-
123
- if (childrenNode.length < childrenData.length) {
124
- if (childrenData.length > 0) {
125
- // combo 被收起,返回平均中心位置 / combo is collapsed, return the average center position
126
- if (collapsed) {
127
- const totalPosition = childrenData.reduce((acc, datum) => add(acc, positionOf(datum)), [0, 0, 0] as Position);
128
- return divide(totalPosition, childrenData.length);
129
- }
130
- }
131
- return [+x, +y, 0];
132
- }
133
-
134
- // empty combo
135
- if (!childrenData.length) return [+x, +y, 0];
136
- return !collapsed ? this.getContentBBox(attributes).center : this.getCollapsedOriginPosition(attributes);
137
- }
138
-
139
- protected getCollapsedOriginPosition(attributes: Required<S>): Position {
140
- return getXYByCollapsedOrigin(
141
- attributes.collapsedOrigin,
142
- this.getContentBBox(attributes).center,
143
- this.getCollapsedKeySize(attributes),
144
- this.getExpandedKeySize(attributes),
145
- );
146
- }
147
-
148
110
  protected getKeySize(attributes: Required<S>): STDSize {
149
111
  const { collapsed, childrenNode = [] } = attributes;
150
112
  if (childrenNode.length === 0) return this.getEmptyKeySize(attributes);
@@ -162,15 +124,15 @@ export abstract class BaseCombo<S extends BaseComboStyleProps = BaseComboStylePr
162
124
  }
163
125
 
164
126
  protected getExpandedKeySize(attributes: Required<S>): STDSize {
165
- if (!isEmpty(attributes.size)) return parseSize(attributes.size);
166
-
167
127
  const contentBBox = this.getContentBBox(attributes);
168
128
  return [getBBoxWidth(contentBBox), getBBoxHeight(contentBBox), 0];
169
129
  }
170
130
 
171
131
  protected getContentBBox(attributes: Required<S>): AABB {
172
- const { childrenNode: children = [], padding } = attributes;
173
- const childrenBBox = getCombinedBBox(children.map((child) => child.getBounds()));
132
+ const { context, childrenNode = [], padding } = attributes;
133
+ const childrenBBox = getCombinedBBox(
134
+ childrenNode.map((id) => context!.element!.getElement(id)).map((child) => child!.getBounds()),
135
+ );
174
136
 
175
137
  if (!padding) return childrenBBox;
176
138
 
@@ -203,8 +165,7 @@ export abstract class BaseCombo<S extends BaseComboStyleProps = BaseComboStylePr
203
165
 
204
166
  protected getCollapsedMarkerText(type: CollapsedMarkerStyleProps['type'], attributes: Required<S>): string {
205
167
  const { context, childrenData = [] } = attributes;
206
- if (!context) return '';
207
- const { model } = context;
168
+ const { model } = context!;
208
169
 
209
170
  if (type === 'descendant-count') return model.getDescendantsData(this.id).length.toString();
210
171
  if (type === 'child-count') return childrenData.length.toString();
@@ -218,50 +179,81 @@ export abstract class BaseCombo<S extends BaseComboStyleProps = BaseComboStylePr
218
179
  }
219
180
 
220
181
  protected getComboZIndex(attributes: Required<S>): number {
221
- const ancestors = attributes.context?.model.getAncestorsData(this.id, COMBO_KEY) || [];
182
+ const ancestors = attributes.context!.model.getAncestorsData(this.id, COMBO_KEY) || [];
222
183
  return ancestors.length;
223
184
  }
224
185
 
186
+ public getComboPosition(attributes: Required<S>): Position {
187
+ const { x = 0, y = 0, collapsed, context, childrenData = [] } = attributes;
188
+
189
+ if (childrenData.length === 0) return [+x, +y, 0];
190
+
191
+ if (collapsed) {
192
+ const { model } = context!;
193
+ const descendants = model.getDescendantsData(this.id).filter((datum) => !model.isCombo(idOf(datum)));
194
+
195
+ if (descendants.length > 0) {
196
+ // combo 被收起,返回平均中心位置 / combo is collapsed, return the average center position
197
+ const totalPosition = descendants.reduce((acc, datum) => add(acc, positionOf(datum)), [0, 0, 0] as Position);
198
+ return divide(totalPosition, descendants.length);
199
+ }
200
+ // empty combo
201
+ return [+x, +y, 0];
202
+ }
203
+
204
+ return this.getContentBBox(attributes).center;
205
+ }
206
+
225
207
  protected getComboStyle(attributes: Required<S>) {
226
208
  const { zIndex = this.getComboZIndex(attributes) } = attributes;
227
- const [x, y] = this.calculatePosition(attributes);
209
+ const [x, y] = this.getComboPosition(attributes);
228
210
  // x/y will be used to calculate position later.
229
211
  return { x, y, transform: `translate(${x}, ${y})`, zIndex };
230
212
  }
231
213
 
232
- public render(attributes: Required<S>, container: Group = this) {
233
- super.render(attributes, container);
214
+ protected updateComboPosition(attributes: Required<S>) {
234
215
  const comboStyle = this.getComboStyle(attributes);
235
216
  Object.assign(this.style, comboStyle);
236
217
 
237
218
  // Sync combo position to model
238
- attributes.context?.model.syncComboDatum({ id: this.id, style: comboStyle });
219
+ attributes.context!.model.syncComboDatum({ id: this.id, style: comboStyle });
220
+ }
221
+
222
+ public render(attributes: Required<S>, container: Group = this) {
223
+ super.render(attributes, container);
224
+ this.updateComboPosition(attributes);
239
225
 
240
226
  // collapsed marker
241
227
  this.drawCollapsedMarkerShape(attributes, container);
242
228
  }
243
229
 
244
- /**
245
- * <zh/> 在元素完成创建并执行完入场动画后调用
246
- *
247
- * <en/> Called after the element is created and the entrance animation is completed
248
- * @override
249
- */
250
- public onCreate() {}
230
+ protected hostingAnimation = false;
251
231
 
252
- /**
253
- * <zh/> 在元素更新并执行完过渡动画后调用
254
- *
255
- * <en/> Called after the element is updated and the transition animation is completed
256
- * @override
257
- */
258
- public onUpdate() {}
232
+ protected onframe() {
233
+ super.onframe();
234
+ // 收起状态下,通过动画来更新位置
235
+ // Update position through animation in collapsed state
236
+ if (!this.attributes.collapsed) this.updateComboPosition(this.parsedAttributes);
237
+ this.drawKeyShape(this.parsedAttributes, this);
238
+ }
259
239
 
260
- /**
261
- * <zh/> 在元素完成退场动画并销毁后调用
262
- *
263
- * <en/> Called after the element completes the exit animation and is destroyed
264
- * @override
265
- */
266
- public onDestroy() {}
240
+ public animate(keyframes: Keyframe[], options?: number | KeyframeAnimationOptions) {
241
+ const animation = super.animate(
242
+ this.attributes.collapsed
243
+ ? keyframes
244
+ : // 如果当前 combo 是展开状态,则动画不受 x, y, z, transform 影响,仅由子元素决定位置
245
+ // If the current combo is in the expanded state, the animation is not affected by x, y, z, transform, and the position is determined only by the child elements
246
+ keyframes.map(({ x, y, z, transform, ...keyframe }: any) => keyframe),
247
+ options,
248
+ );
249
+
250
+ if (!animation) return animation;
251
+
252
+ return new Proxy(animation, {
253
+ set: (target, propKey, value) => {
254
+ if (propKey === 'currentTime') Promise.resolve().then(() => this.onframe());
255
+ return Reflect.set(target, propKey, value);
256
+ },
257
+ });
258
+ }
267
259
  }