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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (329) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/esm/constant/shape.d.ts +1 -1
  3. package/esm/index.d.ts +3 -1
  4. package/esm/index.js +1 -1
  5. package/esm/item/combo.d.ts +6 -4
  6. package/esm/item/combo.js +10 -3
  7. package/esm/item/combo.js.map +1 -1
  8. package/esm/item/edge.d.ts +12 -4
  9. package/esm/item/edge.js +100 -17
  10. package/esm/item/edge.js.map +1 -1
  11. package/esm/item/item.d.ts +18 -8
  12. package/esm/item/item.js +121 -62
  13. package/esm/item/item.js.map +1 -1
  14. package/esm/item/node.d.ts +10 -4
  15. package/esm/item/node.js +92 -8
  16. package/esm/item/node.js.map +1 -1
  17. package/esm/runtime/controller/data.d.ts +5 -1
  18. package/esm/runtime/controller/data.js +38 -1
  19. package/esm/runtime/controller/data.js.map +1 -1
  20. package/esm/runtime/controller/index.d.ts +1 -1
  21. package/esm/runtime/controller/index.js +1 -1
  22. package/esm/runtime/controller/index.js.map +1 -1
  23. package/esm/runtime/controller/item.d.ts +22 -11
  24. package/esm/runtime/controller/item.js +241 -96
  25. package/esm/runtime/controller/item.js.map +1 -1
  26. package/esm/runtime/controller/layout.d.ts +3 -0
  27. package/esm/runtime/controller/layout.js +178 -98
  28. package/esm/runtime/controller/layout.js.map +1 -1
  29. package/esm/runtime/controller/plugin.d.ts +3 -0
  30. package/esm/runtime/controller/plugin.js +66 -24
  31. package/esm/runtime/controller/plugin.js.map +1 -1
  32. package/esm/runtime/controller/viewport.js +9 -2
  33. package/esm/runtime/controller/viewport.js.map +1 -1
  34. package/esm/runtime/graph.d.ts +57 -26
  35. package/esm/runtime/graph.js +263 -139
  36. package/esm/runtime/graph.js.map +1 -1
  37. package/esm/stdlib/behavior/click-select.js +9 -3
  38. package/esm/stdlib/behavior/click-select.js.map +1 -1
  39. package/esm/stdlib/behavior/drag-canvas.js +6 -3
  40. package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
  41. package/esm/stdlib/behavior/drag-combo.js +8 -8
  42. package/esm/stdlib/behavior/drag-combo.js.map +1 -1
  43. package/esm/stdlib/behavior/drag-node.d.ts +4 -0
  44. package/esm/stdlib/behavior/drag-node.js +121 -27
  45. package/esm/stdlib/behavior/drag-node.js.map +1 -1
  46. package/esm/stdlib/behavior/scroll-canvas.js +3 -3
  47. package/esm/stdlib/behavior/scroll-canvas.js.map +1 -1
  48. package/esm/stdlib/behavior/zoom-canvas.js +3 -3
  49. package/esm/stdlib/behavior/zoom-canvas.js.map +1 -1
  50. package/esm/stdlib/data/mapNodeSize.js +2 -2
  51. package/esm/stdlib/data/mapNodeSize.js.map +1 -1
  52. package/esm/stdlib/data/validateData.js +2 -2
  53. package/esm/stdlib/data/validateData.js.map +1 -1
  54. package/esm/stdlib/index.d.ts +2 -0
  55. package/esm/stdlib/index.js +3 -1
  56. package/esm/stdlib/index.js.map +1 -1
  57. package/esm/stdlib/item/edge/base.d.ts +2 -11
  58. package/esm/stdlib/item/edge/base.js +12 -105
  59. package/esm/stdlib/item/edge/base.js.map +1 -1
  60. package/esm/stdlib/item/node/base.d.ts +2 -20
  61. package/esm/stdlib/item/node/base.js +10 -150
  62. package/esm/stdlib/item/node/base.js.map +1 -1
  63. package/esm/stdlib/plugin/edgeFilterLens/index.js +2 -2
  64. package/esm/stdlib/plugin/edgeFilterLens/index.js.map +1 -1
  65. package/esm/stdlib/plugin/fisheye/index.js +3 -2
  66. package/esm/stdlib/plugin/fisheye/index.js.map +1 -1
  67. package/esm/stdlib/plugin/history/visibility-updated-command.js +2 -2
  68. package/esm/stdlib/plugin/history/visibility-updated-command.js.map +1 -1
  69. package/esm/stdlib/plugin/hull/index.d.ts +1 -1
  70. package/esm/stdlib/plugin/index.d.ts +1 -0
  71. package/esm/stdlib/plugin/index.js +1 -0
  72. package/esm/stdlib/plugin/index.js.map +1 -1
  73. package/esm/stdlib/plugin/lodController/index.d.ts +73 -0
  74. package/esm/stdlib/plugin/lodController/index.js +556 -0
  75. package/esm/stdlib/plugin/lodController/index.js.map +1 -0
  76. package/esm/stdlib/plugin/menu/index.js +2 -1
  77. package/esm/stdlib/plugin/menu/index.js.map +1 -1
  78. package/esm/stdlib/plugin/minimap/index.js +12 -14
  79. package/esm/stdlib/plugin/minimap/index.js.map +1 -1
  80. package/esm/stdlib/plugin/toolbar/index.d.ts +2 -2
  81. package/esm/stdlib/plugin/toolbar/index.js +27 -29
  82. package/esm/stdlib/plugin/toolbar/index.js.map +1 -1
  83. package/esm/stdlib/theme/dark.js +32 -35
  84. package/esm/stdlib/theme/dark.js.map +1 -1
  85. package/esm/stdlib/theme/light.js +27 -30
  86. package/esm/stdlib/theme/light.js.map +1 -1
  87. package/esm/stdlib/themeSolver/spec.js +2 -2
  88. package/esm/stdlib/themeSolver/spec.js.map +1 -1
  89. package/esm/types/animate.d.ts +1 -1
  90. package/esm/types/combo.d.ts +2 -2
  91. package/esm/types/edge.d.ts +2 -2
  92. package/esm/types/graph.d.ts +62 -43
  93. package/esm/types/hook.d.ts +5 -0
  94. package/esm/types/item.d.ts +9 -15
  95. package/esm/types/layout.d.ts +7 -2
  96. package/esm/types/layout.js.map +1 -1
  97. package/esm/types/node.d.ts +3 -2
  98. package/esm/types/plugin.d.ts +1 -0
  99. package/esm/types/plugin.js +1 -0
  100. package/esm/types/plugin.js.map +1 -1
  101. package/esm/types/spec.d.ts +1 -0
  102. package/esm/types/theme.d.ts +7 -7
  103. package/esm/util/animate.d.ts +7 -2
  104. package/esm/util/animate.js +40 -23
  105. package/esm/util/animate.js.map +1 -1
  106. package/esm/util/bbox.d.ts +7 -1
  107. package/esm/util/bbox.js +16 -0
  108. package/esm/util/bbox.js.map +1 -1
  109. package/esm/util/data.d.ts +7 -1
  110. package/esm/util/data.js +17 -5
  111. package/esm/util/data.js.map +1 -1
  112. package/esm/util/dom.js +5 -5
  113. package/esm/util/dom.js.map +1 -1
  114. package/esm/util/item.d.ts +1 -1
  115. package/esm/util/item.js +8 -8
  116. package/esm/util/item.js.map +1 -1
  117. package/esm/util/mapper.js +1 -1
  118. package/esm/util/mapper.js.map +1 -1
  119. package/esm/util/path.d.ts +6 -1
  120. package/esm/util/path.js +72 -1
  121. package/esm/util/path.js.map +1 -1
  122. package/esm/util/polyline.d.ts +10 -0
  123. package/esm/util/polyline.js +22 -17
  124. package/esm/util/polyline.js.map +1 -1
  125. package/esm/util/router.d.ts +1 -1
  126. package/esm/util/router.js +19 -18
  127. package/esm/util/router.js.map +1 -1
  128. package/esm/util/shape.d.ts +1 -1
  129. package/esm/util/shape.js +28 -13
  130. package/esm/util/shape.js.map +1 -1
  131. package/esm/util/zoom.d.ts +5 -8
  132. package/esm/util/zoom.js +15 -20
  133. package/esm/util/zoom.js.map +1 -1
  134. package/lib/constant/shape.d.ts +1 -1
  135. package/lib/index.d.ts +3 -1
  136. package/lib/index.js +1 -1
  137. package/lib/item/combo.d.ts +6 -4
  138. package/lib/item/combo.js +10 -3
  139. package/lib/item/combo.js.map +1 -1
  140. package/lib/item/edge.d.ts +12 -4
  141. package/lib/item/edge.js +99 -16
  142. package/lib/item/edge.js.map +1 -1
  143. package/lib/item/item.d.ts +18 -8
  144. package/lib/item/item.js +119 -60
  145. package/lib/item/item.js.map +1 -1
  146. package/lib/item/node.d.ts +10 -4
  147. package/lib/item/node.js +92 -8
  148. package/lib/item/node.js.map +1 -1
  149. package/lib/runtime/controller/data.d.ts +5 -1
  150. package/lib/runtime/controller/data.js +38 -1
  151. package/lib/runtime/controller/data.js.map +1 -1
  152. package/lib/runtime/controller/index.d.ts +1 -1
  153. package/lib/runtime/controller/index.js +1 -1
  154. package/lib/runtime/controller/index.js.map +1 -1
  155. package/lib/runtime/controller/item.d.ts +22 -11
  156. package/lib/runtime/controller/item.js +238 -93
  157. package/lib/runtime/controller/item.js.map +1 -1
  158. package/lib/runtime/controller/layout.d.ts +3 -0
  159. package/lib/runtime/controller/layout.js +178 -98
  160. package/lib/runtime/controller/layout.js.map +1 -1
  161. package/lib/runtime/controller/plugin.d.ts +3 -0
  162. package/lib/runtime/controller/plugin.js +66 -24
  163. package/lib/runtime/controller/plugin.js.map +1 -1
  164. package/lib/runtime/controller/viewport.js +9 -2
  165. package/lib/runtime/controller/viewport.js.map +1 -1
  166. package/lib/runtime/graph.d.ts +57 -26
  167. package/lib/runtime/graph.js +263 -139
  168. package/lib/runtime/graph.js.map +1 -1
  169. package/lib/stdlib/behavior/click-select.js +9 -3
  170. package/lib/stdlib/behavior/click-select.js.map +1 -1
  171. package/lib/stdlib/behavior/drag-canvas.js +6 -3
  172. package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
  173. package/lib/stdlib/behavior/drag-combo.js +8 -8
  174. package/lib/stdlib/behavior/drag-combo.js.map +1 -1
  175. package/lib/stdlib/behavior/drag-node.d.ts +4 -0
  176. package/lib/stdlib/behavior/drag-node.js +121 -27
  177. package/lib/stdlib/behavior/drag-node.js.map +1 -1
  178. package/lib/stdlib/behavior/scroll-canvas.js +3 -3
  179. package/lib/stdlib/behavior/scroll-canvas.js.map +1 -1
  180. package/lib/stdlib/behavior/zoom-canvas.js +3 -3
  181. package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
  182. package/lib/stdlib/data/mapNodeSize.js +2 -2
  183. package/lib/stdlib/data/mapNodeSize.js.map +1 -1
  184. package/lib/stdlib/data/validateData.js +2 -2
  185. package/lib/stdlib/data/validateData.js.map +1 -1
  186. package/lib/stdlib/index.d.ts +2 -0
  187. package/lib/stdlib/index.js +3 -1
  188. package/lib/stdlib/index.js.map +1 -1
  189. package/lib/stdlib/item/edge/base.d.ts +2 -11
  190. package/lib/stdlib/item/edge/base.js +12 -105
  191. package/lib/stdlib/item/edge/base.js.map +1 -1
  192. package/lib/stdlib/item/node/base.d.ts +2 -20
  193. package/lib/stdlib/item/node/base.js +10 -150
  194. package/lib/stdlib/item/node/base.js.map +1 -1
  195. package/lib/stdlib/plugin/edgeFilterLens/index.js +2 -2
  196. package/lib/stdlib/plugin/edgeFilterLens/index.js.map +1 -1
  197. package/lib/stdlib/plugin/fisheye/index.js +2 -1
  198. package/lib/stdlib/plugin/fisheye/index.js.map +1 -1
  199. package/lib/stdlib/plugin/history/visibility-updated-command.js +2 -2
  200. package/lib/stdlib/plugin/history/visibility-updated-command.js.map +1 -1
  201. package/lib/stdlib/plugin/hull/index.d.ts +1 -1
  202. package/lib/stdlib/plugin/index.d.ts +1 -0
  203. package/lib/stdlib/plugin/index.js +1 -0
  204. package/lib/stdlib/plugin/index.js.map +1 -1
  205. package/lib/stdlib/plugin/lodController/index.d.ts +73 -0
  206. package/lib/stdlib/plugin/lodController/index.js +560 -0
  207. package/lib/stdlib/plugin/lodController/index.js.map +1 -0
  208. package/lib/stdlib/plugin/menu/index.js +2 -1
  209. package/lib/stdlib/plugin/menu/index.js.map +1 -1
  210. package/lib/stdlib/plugin/minimap/index.js +12 -14
  211. package/lib/stdlib/plugin/minimap/index.js.map +1 -1
  212. package/lib/stdlib/plugin/toolbar/index.d.ts +2 -2
  213. package/lib/stdlib/plugin/toolbar/index.js +27 -29
  214. package/lib/stdlib/plugin/toolbar/index.js.map +1 -1
  215. package/lib/stdlib/theme/dark.js +32 -35
  216. package/lib/stdlib/theme/dark.js.map +1 -1
  217. package/lib/stdlib/theme/light.js +27 -30
  218. package/lib/stdlib/theme/light.js.map +1 -1
  219. package/lib/stdlib/themeSolver/spec.js +2 -2
  220. package/lib/stdlib/themeSolver/spec.js.map +1 -1
  221. package/lib/types/animate.d.ts +1 -1
  222. package/lib/types/combo.d.ts +2 -2
  223. package/lib/types/edge.d.ts +2 -2
  224. package/lib/types/graph.d.ts +62 -43
  225. package/lib/types/hook.d.ts +5 -0
  226. package/lib/types/item.d.ts +9 -15
  227. package/lib/types/layout.d.ts +7 -2
  228. package/lib/types/layout.js.map +1 -1
  229. package/lib/types/node.d.ts +3 -2
  230. package/lib/types/plugin.d.ts +1 -0
  231. package/lib/types/plugin.js +1 -0
  232. package/lib/types/plugin.js.map +1 -1
  233. package/lib/types/spec.d.ts +1 -0
  234. package/lib/types/theme.d.ts +7 -7
  235. package/lib/util/animate.d.ts +7 -2
  236. package/lib/util/animate.js +40 -23
  237. package/lib/util/animate.js.map +1 -1
  238. package/lib/util/bbox.d.ts +7 -1
  239. package/lib/util/bbox.js +18 -1
  240. package/lib/util/bbox.js.map +1 -1
  241. package/lib/util/data.d.ts +7 -1
  242. package/lib/util/data.js +19 -6
  243. package/lib/util/data.js.map +1 -1
  244. package/lib/util/dom.js +5 -5
  245. package/lib/util/dom.js.map +1 -1
  246. package/lib/util/item.d.ts +1 -1
  247. package/lib/util/item.js +8 -8
  248. package/lib/util/item.js.map +1 -1
  249. package/lib/util/mapper.js +1 -1
  250. package/lib/util/mapper.js.map +1 -1
  251. package/lib/util/path.d.ts +6 -1
  252. package/lib/util/path.js +72 -1
  253. package/lib/util/path.js.map +1 -1
  254. package/lib/util/polyline.d.ts +10 -0
  255. package/lib/util/polyline.js +25 -18
  256. package/lib/util/polyline.js.map +1 -1
  257. package/lib/util/router.d.ts +1 -1
  258. package/lib/util/router.js +19 -18
  259. package/lib/util/router.js.map +1 -1
  260. package/lib/util/shape.d.ts +1 -1
  261. package/lib/util/shape.js +27 -12
  262. package/lib/util/shape.js.map +1 -1
  263. package/lib/util/zoom.d.ts +5 -8
  264. package/lib/util/zoom.js +17 -22
  265. package/lib/util/zoom.js.map +1 -1
  266. package/package.json +1 -1
  267. package/src/index.ts +1 -1
  268. package/src/item/combo.ts +13 -5
  269. package/src/item/edge.ts +126 -17
  270. package/src/item/item.ts +140 -57
  271. package/src/item/node.ts +109 -12
  272. package/src/runtime/controller/data.ts +64 -3
  273. package/src/runtime/controller/index.ts +1 -1
  274. package/src/runtime/controller/item.ts +321 -135
  275. package/src/runtime/controller/layout.ts +254 -113
  276. package/src/runtime/controller/plugin.ts +86 -33
  277. package/src/runtime/controller/viewport.ts +8 -2
  278. package/src/runtime/graph.ts +383 -158
  279. package/src/stdlib/behavior/click-select.ts +8 -3
  280. package/src/stdlib/behavior/drag-canvas.ts +6 -3
  281. package/src/stdlib/behavior/drag-combo.ts +8 -8
  282. package/src/stdlib/behavior/drag-node.ts +165 -50
  283. package/src/stdlib/behavior/scroll-canvas.ts +3 -3
  284. package/src/stdlib/behavior/zoom-canvas.ts +3 -3
  285. package/src/stdlib/data/mapNodeSize.ts +2 -2
  286. package/src/stdlib/data/validateData.ts +2 -2
  287. package/src/stdlib/index.ts +3 -0
  288. package/src/stdlib/item/edge/base.ts +15 -139
  289. package/src/stdlib/item/node/base.ts +20 -215
  290. package/src/stdlib/plugin/edgeFilterLens/index.ts +2 -2
  291. package/src/stdlib/plugin/fisheye/index.ts +3 -2
  292. package/src/stdlib/plugin/history/visibility-updated-command.ts +2 -2
  293. package/src/stdlib/plugin/index.ts +1 -0
  294. package/src/stdlib/plugin/lodController/index.ts +602 -0
  295. package/src/stdlib/plugin/menu/index.ts +1 -1
  296. package/src/stdlib/plugin/minimap/index.ts +12 -14
  297. package/src/stdlib/plugin/toolbar/index.ts +29 -31
  298. package/src/stdlib/theme/dark.ts +32 -34
  299. package/src/stdlib/theme/light.ts +27 -29
  300. package/src/stdlib/themeSolver/spec.ts +2 -2
  301. package/src/types/animate.ts +1 -1
  302. package/src/types/combo.ts +2 -2
  303. package/src/types/edge.ts +2 -2
  304. package/src/types/graph.ts +65 -53
  305. package/src/types/hook.ts +5 -0
  306. package/src/types/item.ts +8 -14
  307. package/src/types/layout.ts +20 -15
  308. package/src/types/node.ts +3 -2
  309. package/src/types/plugin.ts +2 -0
  310. package/src/types/spec.ts +1 -0
  311. package/src/types/theme.ts +7 -7
  312. package/src/util/animate.ts +104 -75
  313. package/src/util/bbox.ts +26 -1
  314. package/src/util/data.ts +15 -6
  315. package/src/util/dom.ts +6 -6
  316. package/src/util/item.ts +15 -1
  317. package/src/util/mapper.ts +1 -1
  318. package/src/util/path.ts +72 -2
  319. package/src/util/polyline.ts +30 -23
  320. package/src/util/router.ts +21 -19
  321. package/src/util/shape.ts +27 -12
  322. package/src/util/zoom.ts +19 -25
  323. package/esm/runtime/controller/extension.d.ts +0 -9
  324. package/esm/runtime/controller/extension.js +0 -11
  325. package/esm/runtime/controller/extension.js.map +0 -1
  326. package/lib/runtime/controller/extension.d.ts +0 -9
  327. package/lib/runtime/controller/extension.js +0 -15
  328. package/lib/runtime/controller/extension.js.map +0 -1
  329. package/src/runtime/controller/extension.ts +0 -14
@@ -6,10 +6,11 @@ import {
6
6
  Path,
7
7
  Polyline,
8
8
  } from '@antv/g';
9
+ import { isString, uniq } from '@antv/util';
9
10
  import { AnimateTiming, IAnimate, IAnimates } from '../types/animate';
10
11
  import { ItemShapeStyles, ShapeStyle } from '../types/item';
11
12
  import { isArrayOverlap, replaceElements } from './array';
12
- import { clone, isString, uniq } from '@antv/util';
13
+ import { cloneJSON } from './data';
13
14
 
14
15
  /**
15
16
  * Initial(timing = show) shape animation start from init shape styles, and end to the shape's style config.
@@ -45,6 +46,7 @@ export const getShapeAnimateBeginStyles = (shape) => {
45
46
  opacity: 0,
46
47
  strokeOpacity: 0,
47
48
  offsetDistance: 0,
49
+ fill: '#000',
48
50
  };
49
51
  }
50
52
  return {
@@ -75,7 +77,6 @@ export const DEFAULT_ANIMATE_CFG = {
75
77
  duration: 500,
76
78
  easing: 'cubic-bezier(0.250, 0.460, 0.450, 0.940)',
77
79
  iterations: 1,
78
- delay: 1000,
79
80
  fill: 'both',
80
81
  },
81
82
  show: {
@@ -151,7 +152,8 @@ const groupTimingAnimates = (
151
152
  */
152
153
  const runAnimateGroupOnShapes = (
153
154
  shapeMap: { [shapeId: string]: DisplayObject },
154
- group: Group,
155
+ shapeIds: string[] = undefined,
156
+ groups: Group[],
155
157
  timingAnimates: IAnimate[],
156
158
  targetStylesMap: ItemShapeStyles,
157
159
  timing: AnimateTiming,
@@ -163,80 +165,104 @@ const runAnimateGroupOnShapes = (
163
165
  let maxDurationIdx = -1;
164
166
  let hasCanceled = canceled;
165
167
  const isOut = timing === 'buildOut' || timing === 'hide';
166
- const animations = timingAnimates.map((animate: any, i) => {
167
- const { fields, shapeId, order, states, ...animateCfg } = animate;
168
- const animateConfig = {
169
- ...DEFAULT_ANIMATE_CFG[timing],
170
- ...animateCfg,
171
- };
172
- const { duration } = animateConfig;
168
+ const shapeIdsToAnimate = shapeIds ? shapeIds : Object.keys(shapeMap);
169
+ const animations = timingAnimates
170
+ .map((animateOptions: any) => {
171
+ const { fields, shapeId, order, states, ...animateCfg } = animateOptions;
172
+ const animateConfig = {
173
+ ...DEFAULT_ANIMATE_CFG[timing],
174
+ ...animateCfg,
175
+ };
176
+ const { iterations } = animateConfig;
177
+ if (iterations === Infinity && animateCfg.fill == undefined) {
178
+ animateConfig.fill = 'auto';
179
+ }
173
180
 
174
- let animation;
175
- if (!shapeId || shapeId === 'group') {
176
- // animate on group
177
- const usingFields = [];
178
- let hasOpacity = false;
179
- fields?.forEach((field) => {
180
- if (field === 'size') usingFields.push('transform');
181
- else if (field !== 'opacity') usingFields.push(field);
182
- else hasOpacity = true;
183
- });
184
- const targetStyle =
185
- targetStylesMap.group || GROUP_ANIMATE_STYLES[isOut ? 0 : 1];
186
- if (hasCanceled) {
187
- Object.keys(targetStyle).forEach((key) => {
188
- group.style[key] = targetStyle[key];
181
+ let animates = [];
182
+ if (!shapeId || shapeId === 'group') {
183
+ // animate on group
184
+ const usingFields = [];
185
+ let hasOpacity = false;
186
+ fields?.forEach((field) => {
187
+ if (field === 'size') usingFields.push('transform');
188
+ else if (field !== 'opacity') usingFields.push(field);
189
+ else hasOpacity = true;
189
190
  });
190
- } else {
191
- if (hasOpacity) {
192
- // opacity on group, animate on all shapes
193
- Object.keys(shapeMap).forEach((shapeId) => {
194
- const { opacity: targetOpaicty = 1 } =
195
- targetStylesMap[shapeId] ||
196
- targetStylesMap.otherShapes?.[shapeId] ||
197
- {};
198
- animation = runAnimateOnShape(
199
- shapeMap[shapeId],
200
- ['opacity'],
201
- { opacity: targetOpaicty },
202
- getShapeAnimateBeginStyles(shapeMap[shapeId]),
203
- animateConfig,
204
- );
205
- });
206
- }
207
- if (usingFields.length) {
208
- animation = runAnimateOnShape(
209
- group,
210
- usingFields,
211
- targetStyle,
212
- GROUP_ANIMATE_STYLES[isOut ? 1 : 0],
213
- animateConfig,
214
- );
215
- }
216
- }
217
- } else {
218
- const shape = shapeMap[shapeId];
219
- if (shape && shape.style.display !== 'none') {
220
191
  const targetStyle =
221
- targetStylesMap[shapeId] ||
222
- targetStylesMap.otherShapes?.[shapeId] ||
223
- {};
192
+ targetStylesMap.group || GROUP_ANIMATE_STYLES[isOut ? 0 : 1];
224
193
  if (hasCanceled) {
225
194
  Object.keys(targetStyle).forEach((key) => {
226
- shape.style[key] = targetStyle[key];
195
+ groups.forEach((group) => (group.style[key] = targetStyle[key]));
227
196
  });
228
197
  } else {
229
- animation = runAnimateOnShape(
230
- shape,
231
- fields,
232
- targetStyle,
233
- getShapeAnimateBeginStyles(shape),
234
- animateConfig,
235
- );
198
+ if (hasOpacity) {
199
+ // opacity on group, animate on all shapes
200
+ shapeIdsToAnimate.forEach((sid) => {
201
+ if (!shapeMap[sid]) return;
202
+ const { opacity: targetOpacity = isOut ? 0 : 1 } =
203
+ targetStylesMap[sid] ||
204
+ targetStylesMap.otherShapes?.[sid] ||
205
+ {};
206
+ animates.push(
207
+ runAnimateOnShape(
208
+ shapeMap[sid],
209
+ ['opacity'],
210
+ { opacity: targetOpacity },
211
+ getShapeAnimateBeginStyles(shapeMap[sid]),
212
+ animateConfig,
213
+ ),
214
+ );
215
+ });
216
+ }
217
+ if (usingFields.length) {
218
+ animates = animates.concat(
219
+ groups.map((group) =>
220
+ runAnimateOnShape(
221
+ group,
222
+ usingFields,
223
+ targetStyle,
224
+ GROUP_ANIMATE_STYLES[isOut ? 1 : 0],
225
+ animateConfig,
226
+ ),
227
+ ),
228
+ );
229
+ }
230
+ }
231
+ } else {
232
+ const shape = shapeMap[shapeId];
233
+ if (
234
+ shape &&
235
+ shape.style.display !== 'none' &&
236
+ shape.style.visibility !== 'hidden'
237
+ ) {
238
+ const targetStyle =
239
+ targetStylesMap[shapeId] ||
240
+ targetStylesMap.otherShapes?.[shapeId] ||
241
+ {};
242
+ if (hasCanceled) {
243
+ Object.keys(targetStyle).forEach((key) => {
244
+ shape.style[key] = targetStyle[key];
245
+ });
246
+ } else {
247
+ animates.push(
248
+ runAnimateOnShape(
249
+ shape,
250
+ fields,
251
+ targetStyle,
252
+ getShapeAnimateBeginStyles(shape),
253
+ animateConfig,
254
+ ),
255
+ );
256
+ }
236
257
  }
237
258
  }
238
- }
239
- if (maxDuration < duration && animation) {
259
+ return animates;
260
+ })
261
+ .flat()
262
+ .filter(Boolean);
263
+ animations.forEach((animation, i) => {
264
+ const { duration } = animation.effect.timing;
265
+ if (maxDuration < duration) {
240
266
  maxDuration = duration;
241
267
  maxDurationIdx = i;
242
268
  }
@@ -246,7 +272,6 @@ const runAnimateGroupOnShapes = (
246
272
  cancelAnimations();
247
273
  };
248
274
  }
249
- return animation;
250
275
  });
251
276
  if (maxDurationIdx > -1) {
252
277
  const selfOnfinish = animations[maxDurationIdx].onfinish;
@@ -283,10 +308,10 @@ const runAnimateOnShape = (
283
308
  fields.forEach((key) => {
284
309
  animateArr[0][key] =
285
310
  shape.style[key] === undefined
286
- ? clone(beginStyle[key])
287
- : clone(shape.style[key]);
311
+ ? cloneJSON(beginStyle[key])
312
+ : cloneJSON(shape.style[key]);
288
313
  if (targetStyle[key] === undefined) return;
289
- animateArr[1][key] = clone(targetStyle[key]);
314
+ animateArr[1][key] = cloneJSON(targetStyle[key]);
290
315
  if (key === 'lineDash') {
291
316
  const beginPercents = uniq(
292
317
  animateArr[0][key].filter(
@@ -299,7 +324,7 @@ const runAnimateOnShape = (
299
324
  ),
300
325
  );
301
326
  if (beginPercents.length || targetPercents.length) {
302
- percentLineDash = clone(animateArr[0].lineDash);
327
+ percentLineDash = cloneJSON(animateArr[0].lineDash);
303
328
  const totalLength = (
304
329
  shape as Line | Polyline | Path
305
330
  ).getTotalLength();
@@ -331,6 +356,8 @@ const runAnimateOnShape = (
331
356
  );
332
357
  return;
333
358
  }
359
+ if (animateConfig.iterations === -1 || animateConfig.iterations === null)
360
+ animateConfig.iterations = Infinity;
334
361
  const animation = shape.animate(animateArr, animateConfig);
335
362
  if (percentLineDash) {
336
363
  animation.onfinish = () => {
@@ -381,7 +408,8 @@ export const animateShapes = (
381
408
  animates: IAnimates,
382
409
  mergedStyles: ItemShapeStyles,
383
410
  shapeMap: { [shapeId: string]: DisplayObject },
384
- group: Group,
411
+ shapeIds: string[] = undefined,
412
+ groups: Group[],
385
413
  timing: AnimateTiming = 'buildIn',
386
414
  changedStates: string[] = [],
387
415
  onAnimatesFrame: Function = () => {},
@@ -410,7 +438,8 @@ export const animateShapes = (
410
438
  }
411
439
  const groupAnimations = runAnimateGroupOnShapes(
412
440
  shapeMap,
413
- group,
441
+ shapeIds,
442
+ groups,
414
443
  timingAnimateGroups[groupKeys[i]],
415
444
  mergedStyles,
416
445
  timing,
package/src/util/bbox.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AABB } from '@antv/g';
1
+ import { AABB, Canvas } from '@antv/g';
2
2
  import { Point, PolyPoint } from 'types/common';
3
3
 
4
4
  /**
@@ -332,3 +332,28 @@ export const isBBoxInBBox = (subBBox: AABB, bbox: AABB, scale?: number) => {
332
332
  subBBox.max[1] < bbox.max[1]
333
333
  );
334
334
  };
335
+
336
+ export const getCombinedCanvasesBounds = (canvases: Canvas[]) => {
337
+ const combinedBounds = {
338
+ min: [Infinity, Infinity, Infinity],
339
+ max: [-Infinity, -Infinity, -Infinity],
340
+ center: [0, 0, 0],
341
+ halfExtents: [0, 0, 0],
342
+ };
343
+ canvases.forEach((canvas) => {
344
+ const bounds = canvas.document.documentElement.getBounds();
345
+ combinedBounds.min = combinedBounds.min.map((val, i) =>
346
+ Math.min(val || Infinity, bounds.min[i]),
347
+ );
348
+ combinedBounds.max = combinedBounds.max.map((val, i) =>
349
+ Math.max(val || -Infinity, bounds.max[i]),
350
+ );
351
+ });
352
+ combinedBounds.center = combinedBounds.center.map(
353
+ (_, i) => (combinedBounds.max[i] + combinedBounds.min[i]) / 2,
354
+ );
355
+ combinedBounds.halfExtents = combinedBounds.halfExtents.map(
356
+ (_, i) => (combinedBounds.max[i] - combinedBounds.min[i]) / 2,
357
+ );
358
+ return combinedBounds;
359
+ };
package/src/util/data.ts CHANGED
@@ -334,18 +334,27 @@ export const dataLifecycleMap: Record<string, string> = {
334
334
  * @param excludeInvisibles whether exclude invisibles. true means the function should test without visible items.
335
335
  * @returns graph is empty or not.
336
336
  */
337
- export const isEmptyGraph = (graph, excludeInvisibles = false): Boolean => {
337
+ export const isEmptyGraph = (graph, excludeInvisibles = false): boolean => {
338
338
  const nodes = graph.getAllNodesData();
339
339
  const combos = graph.getAllCombosData();
340
340
  if (nodes.length === 0 && combos.length === 0) return true;
341
341
 
342
342
  if (excludeInvisibles) {
343
343
  const edges = graph.getAllEdgesData();
344
- const hasVisibleItems =
345
- nodes.filter((node) => graph.getItemVisible(node.id)).length +
346
- edges.filter((edge) => graph.getItemVisible(edge.id)).length +
347
- combos.filter((combo) => graph.getItemVisible(combo.id)).length;
348
- if (!hasVisibleItems) return true;
344
+ if (nodes.find((node) => graph.getItemVisible(node.id))) return false;
345
+ if (edges.find((edge) => graph.getItemVisible(edge.id))) return false;
346
+ if (combos.find((combo) => graph.getItemVisible(combo.id))) return false;
347
+ return true;
349
348
  }
350
349
  return false;
351
350
  };
351
+
352
+ /**
353
+ * Clone an object by JSON stringify and parse
354
+ * @param obj
355
+ * @returns
356
+ */
357
+ export const cloneJSON = (obj) => {
358
+ if (!obj) return obj;
359
+ return JSON.parse(JSON.stringify(obj));
360
+ };
package/src/util/dom.ts CHANGED
@@ -4,14 +4,14 @@
4
4
  * @returns
5
5
  */
6
6
  export function createDOM(str: string): HTMLElement {
7
- const container = document.createElement('div');
8
- container.innerHTML = str;
7
+ const containerDOM = document.createElement('div');
8
+ containerDOM.innerHTML = str;
9
9
 
10
- const dom = container.childNodes[0];
11
- if (dom && container.contains(dom)) {
12
- container.removeChild(dom);
10
+ let dom = containerDOM.childNodes[0] as HTMLElement;
11
+ if (dom && containerDOM.contains(dom)) {
12
+ dom = containerDOM.removeChild(dom);
13
13
  }
14
- return dom as HTMLElement;
14
+ return dom;
15
15
  }
16
16
 
17
17
  /**
package/src/util/item.ts CHANGED
@@ -32,6 +32,8 @@ export const upsertTransientItem = (
32
32
  nodeGroup: Group,
33
33
  edgeGroup: Group,
34
34
  comboGroup: Group,
35
+ nodeLabelGroup: Group,
36
+ edgeLabelGroup: Group,
35
37
  transientItemMap: Map<ID, Node | Edge | Combo | Group>,
36
38
  itemMap: Map<ID, Node | Edge | Combo>,
37
39
  graphCore?: GraphCore,
@@ -56,7 +58,7 @@ export const upsertTransientItem = (
56
58
  visible = true,
57
59
  } = drawOptions;
58
60
  if (item.type === 'node') {
59
- transientItem = item.clone(nodeGroup, shapeIds, true);
61
+ transientItem = item.clone(nodeGroup, nodeLabelGroup, shapeIds, true);
60
62
  } else if (item.type === 'edge') {
61
63
  let source;
62
64
  let target;
@@ -66,6 +68,8 @@ export const upsertTransientItem = (
66
68
  nodeGroup,
67
69
  edgeGroup,
68
70
  comboGroup,
71
+ nodeLabelGroup,
72
+ edgeLabelGroup,
69
73
  transientItemMap,
70
74
  itemMap,
71
75
  graphCore,
@@ -79,6 +83,8 @@ export const upsertTransientItem = (
79
83
  nodeGroup,
80
84
  edgeGroup,
81
85
  comboGroup,
86
+ nodeLabelGroup,
87
+ edgeLabelGroup,
82
88
  transientItemMap,
83
89
  itemMap,
84
90
  graphCore,
@@ -88,10 +94,13 @@ export const upsertTransientItem = (
88
94
  }
89
95
  transientItem = item.clone(
90
96
  edgeGroup,
97
+ edgeLabelGroup,
91
98
  source,
92
99
  target,
93
100
  shapeIds,
94
101
  true,
102
+ visible,
103
+ transientItemMap,
95
104
  ) as Edge;
96
105
  } else {
97
106
  // find the succeeds to upsert transients
@@ -106,6 +115,8 @@ export const upsertTransientItem = (
106
115
  nodeGroup,
107
116
  edgeGroup,
108
117
  comboGroup,
118
+ nodeLabelGroup,
119
+ edgeLabelGroup,
109
120
  transientItemMap,
110
121
  itemMap,
111
122
  graphCore,
@@ -117,6 +128,7 @@ export const upsertTransientItem = (
117
128
  });
118
129
  transientItem = (item as Combo).clone(
119
130
  comboGroup,
131
+ nodeLabelGroup,
120
132
  shapeIds,
121
133
  true,
122
134
  () => getCombinedBoundsByItem(childItems), // getCombinedBounds
@@ -143,6 +155,8 @@ export const upsertTransientItem = (
143
155
  nodeGroup,
144
156
  edgeGroup,
145
157
  comboGroup,
158
+ nodeLabelGroup,
159
+ edgeLabelGroup,
146
160
  transientItemMap,
147
161
  itemMap,
148
162
  graphCore,
@@ -32,7 +32,7 @@ export const DEFAULT_MAPPER = {
32
32
  },
33
33
  edge: (innerEdgeModel) => {
34
34
  const { id, source, target, data } = innerEdgeModel;
35
- const { color, label, icon, badge, keyShape } = data;
35
+ const { color, label, icon, badge, keyShape } = data || {};
36
36
  const resultData: NodeDisplayModelData = {
37
37
  ...data,
38
38
  keyShape: { ...keyShape },
package/src/util/path.ts CHANGED
@@ -35,9 +35,79 @@ export const getControlPoint = (
35
35
  return point;
36
36
  };
37
37
 
38
- export const pathToPoints = (path: any[]) => {
38
+ const PATH_COMMANDS = {
39
+ M: ['x', 'y'],
40
+ m: ['dx', 'dy'],
41
+ H: ['x'],
42
+ h: ['dx'],
43
+ V: ['y'],
44
+ v: ['dy'],
45
+ L: ['x', 'y'],
46
+ l: ['dx', 'dy'],
47
+ Z: [],
48
+ C: ['x1', 'y1', 'x2', 'y2', 'x', 'y'],
49
+ c: ['dx1', 'dy1', 'dx2', 'dy2', 'dx', 'dy'],
50
+ S: ['x2', 'y2', 'x', 'y'],
51
+ s: ['dx2', 'dy2', 'dx', 'dy'],
52
+ Q: ['x1', 'y1', 'x', 'y'],
53
+ q: ['dx1', 'dy1', 'dx', 'dy'],
54
+ T: ['x', 'y'],
55
+ t: ['dx', 'dy'],
56
+ A: ['rx', 'ry', 'rotation', 'large-arc', 'sweep', 'x', 'y'],
57
+ a: ['rx', 'ry', 'rotation', 'large-arc', 'sweep', 'dx', 'dy'],
58
+ };
59
+
60
+ /**
61
+ * Converts a path string to an array of path segments.
62
+ * @param {string} path - The path string to convert.
63
+ * @returns {Array} - An array of path segments.
64
+ **/
65
+ const fromPathToArray = (path: string) => {
66
+ const items = path
67
+ .replace(/[\n\r]/g, '')
68
+ .replace(/-/g, ' -')
69
+ .replace(/(\d*\.)(\d+)(?=\.)/g, '$1$2 ')
70
+ .trim()
71
+ .split(/\s*,|\s+/);
72
+ const segments = [];
73
+ let currentCommand = '';
74
+ let currentElement = {};
75
+ while (items.length > 0) {
76
+ let it = items.shift();
77
+ if (PATH_COMMANDS.hasOwnProperty(it)) {
78
+ currentCommand = it;
79
+ } else {
80
+ items.unshift(it);
81
+ }
82
+ currentElement = { type: currentCommand };
83
+ PATH_COMMANDS[currentCommand].forEach((prop) => {
84
+ it = items.shift(); // TODO sanity check
85
+ currentElement[prop] = it;
86
+ });
87
+ if (currentCommand === 'M') {
88
+ currentCommand = 'L';
89
+ } else if (currentCommand === 'm') {
90
+ currentCommand = 'l';
91
+ }
92
+ segments.push(currentElement);
93
+ }
94
+ return segments;
95
+ };
96
+
97
+ /**
98
+ * Converts a path to an array of points.
99
+ * @param {Array|string} path - The path to convert to points.
100
+ * @returns {Array} - An array of points.
101
+ */
102
+ export const pathToPoints = (path: any[] | string) => {
39
103
  const points = [];
40
- path.forEach((seg) => {
104
+ let segments = [];
105
+ if (typeof path === 'string') {
106
+ segments = fromPathToArray(path);
107
+ } else {
108
+ segments = path;
109
+ }
110
+ segments.forEach((seg) => {
41
111
  const command = seg[0];
42
112
  if (command !== 'A') {
43
113
  for (let i = 1; i < seg.length; i = i + 2) {
@@ -1,7 +1,10 @@
1
1
  import { AABB } from '@antv/g';
2
2
  import { each } from '@antv/util';
3
3
  import { ID } from '@antv/graphlib';
4
+ import { EdgeDisplayModel } from '../types/edge';
5
+ import { NodeDisplayModel } from '../types';
4
6
  import Node from '../item/node';
7
+ import Item from '../item/item';
5
8
  import { Point, PolyPoint } from '../types/common';
6
9
  import {
7
10
  getBBoxFromPoint,
@@ -18,24 +21,6 @@ import { manhattanDist } from './math';
18
21
  import { RouterCfg } from './router';
19
22
  import { isBending } from './point';
20
23
 
21
- // class PolylineHistory {
22
- // private pathMap: Map<ID, Point[]>;
23
-
24
- // constructor() {
25
- // this.pathMap = new Map<ID, Point[]>();
26
- // }
27
-
28
- // public addPath(edgeId: ID, points: Point[]): void {
29
- // this.pathMap.set(edgeId, points);
30
- // }
31
-
32
- // public getPointsById(edgeId: ID): Point[] | undefined {
33
- // return this.pathMap.get(edgeId);
34
- // }
35
- // }
36
-
37
- // const polylineHistory = new PolylineHistory();
38
-
39
24
  /**
40
25
  * Simplify points of polyline by removing duplicated points
41
26
  * @param points list of 2d points
@@ -341,9 +326,6 @@ export const getPolylinePath = (
341
326
 
342
327
  const newPoints = removeRedundantPoint(points);
343
328
 
344
- // Record polyline points
345
- // polylineHistory.addPath(id, newPoints);
346
-
347
329
  return pointsToPolyline(newPoints, radius, z);
348
330
  };
349
331
 
@@ -436,8 +418,6 @@ export const getPolylinePoints = (
436
418
  start,
437
419
  end,
438
420
  );
439
- pathPoints.unshift(start);
440
- pathPoints.push(end);
441
421
 
442
422
  return simplifyPolylinePoints(pathPoints);
443
423
  };
@@ -675,3 +655,30 @@ export class EdgeCollisionChecker {
675
655
  return potentialCollisions;
676
656
  }
677
657
  }
658
+
659
+ /**
660
+ * Check if the edge is a polyline and obstacle avoidance is enabled
661
+ */
662
+ export const isPolylineWithObstacleAvoidance = (
663
+ displayModel: EdgeDisplayModel,
664
+ polylineEdgeType = ['polyline-edge'],
665
+ ) => {
666
+ const { type, keyShape } = displayModel.data;
667
+ const isPolyline = polylineEdgeType.includes(type);
668
+ if (!isPolyline) return false;
669
+ // @ts-ignore
670
+ const isObstacleAvoidanceEnabled = (keyShape?.routeCfg as RouterCfg)
671
+ ?.enableObstacleAvoidance;
672
+ return isObstacleAvoidanceEnabled;
673
+ };
674
+
675
+ /**
676
+ * Check if the node prevents polyline edges from overlapping
677
+ */
678
+ export const isPointPreventPolylineOverlap = (
679
+ displayModel: NodeDisplayModel,
680
+ ) => {
681
+ if (!displayModel) return false;
682
+ const { preventPolylineEdgeOverlap } = displayModel.data;
683
+ return preventPolylineEdgeOverlap || false;
684
+ };