@antv/g6 5.0.0-beta.26 → 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 (324) 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 +103 -59
  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/minimap/index.js +12 -14
  77. package/esm/stdlib/plugin/minimap/index.js.map +1 -1
  78. package/esm/stdlib/plugin/toolbar/index.d.ts +2 -2
  79. package/esm/stdlib/plugin/toolbar/index.js +27 -29
  80. package/esm/stdlib/plugin/toolbar/index.js.map +1 -1
  81. package/esm/stdlib/theme/dark.js +32 -35
  82. package/esm/stdlib/theme/dark.js.map +1 -1
  83. package/esm/stdlib/theme/light.js +27 -30
  84. package/esm/stdlib/theme/light.js.map +1 -1
  85. package/esm/stdlib/themeSolver/spec.js +2 -2
  86. package/esm/stdlib/themeSolver/spec.js.map +1 -1
  87. package/esm/types/animate.d.ts +1 -1
  88. package/esm/types/combo.d.ts +2 -2
  89. package/esm/types/edge.d.ts +2 -2
  90. package/esm/types/graph.d.ts +62 -43
  91. package/esm/types/hook.d.ts +5 -0
  92. package/esm/types/item.d.ts +9 -15
  93. package/esm/types/layout.d.ts +7 -2
  94. package/esm/types/layout.js.map +1 -1
  95. package/esm/types/node.d.ts +3 -2
  96. package/esm/types/plugin.d.ts +1 -0
  97. package/esm/types/plugin.js +1 -0
  98. package/esm/types/plugin.js.map +1 -1
  99. package/esm/types/spec.d.ts +1 -0
  100. package/esm/types/theme.d.ts +7 -7
  101. package/esm/util/animate.d.ts +7 -2
  102. package/esm/util/animate.js +37 -23
  103. package/esm/util/animate.js.map +1 -1
  104. package/esm/util/bbox.d.ts +7 -1
  105. package/esm/util/bbox.js +16 -0
  106. package/esm/util/bbox.js.map +1 -1
  107. package/esm/util/data.d.ts +7 -1
  108. package/esm/util/data.js +17 -5
  109. package/esm/util/data.js.map +1 -1
  110. package/esm/util/dom.js +5 -5
  111. package/esm/util/dom.js.map +1 -1
  112. package/esm/util/item.d.ts +1 -1
  113. package/esm/util/item.js +8 -8
  114. package/esm/util/item.js.map +1 -1
  115. package/esm/util/mapper.js +1 -1
  116. package/esm/util/mapper.js.map +1 -1
  117. package/esm/util/path.d.ts +6 -1
  118. package/esm/util/path.js +72 -1
  119. package/esm/util/path.js.map +1 -1
  120. package/esm/util/polyline.d.ts +10 -0
  121. package/esm/util/polyline.js +22 -17
  122. package/esm/util/polyline.js.map +1 -1
  123. package/esm/util/router.d.ts +1 -1
  124. package/esm/util/router.js +19 -18
  125. package/esm/util/router.js.map +1 -1
  126. package/esm/util/shape.d.ts +1 -1
  127. package/esm/util/shape.js +28 -13
  128. package/esm/util/shape.js.map +1 -1
  129. package/esm/util/zoom.d.ts +5 -8
  130. package/esm/util/zoom.js +15 -20
  131. package/esm/util/zoom.js.map +1 -1
  132. package/lib/constant/shape.d.ts +1 -1
  133. package/lib/index.d.ts +3 -1
  134. package/lib/index.js +1 -1
  135. package/lib/item/combo.d.ts +6 -4
  136. package/lib/item/combo.js +10 -3
  137. package/lib/item/combo.js.map +1 -1
  138. package/lib/item/edge.d.ts +12 -4
  139. package/lib/item/edge.js +99 -16
  140. package/lib/item/edge.js.map +1 -1
  141. package/lib/item/item.d.ts +18 -8
  142. package/lib/item/item.js +101 -57
  143. package/lib/item/item.js.map +1 -1
  144. package/lib/item/node.d.ts +10 -4
  145. package/lib/item/node.js +92 -8
  146. package/lib/item/node.js.map +1 -1
  147. package/lib/runtime/controller/data.d.ts +5 -1
  148. package/lib/runtime/controller/data.js +38 -1
  149. package/lib/runtime/controller/data.js.map +1 -1
  150. package/lib/runtime/controller/index.d.ts +1 -1
  151. package/lib/runtime/controller/index.js +1 -1
  152. package/lib/runtime/controller/index.js.map +1 -1
  153. package/lib/runtime/controller/item.d.ts +22 -11
  154. package/lib/runtime/controller/item.js +238 -93
  155. package/lib/runtime/controller/item.js.map +1 -1
  156. package/lib/runtime/controller/layout.d.ts +3 -0
  157. package/lib/runtime/controller/layout.js +178 -98
  158. package/lib/runtime/controller/layout.js.map +1 -1
  159. package/lib/runtime/controller/plugin.d.ts +3 -0
  160. package/lib/runtime/controller/plugin.js +66 -24
  161. package/lib/runtime/controller/plugin.js.map +1 -1
  162. package/lib/runtime/controller/viewport.js +9 -2
  163. package/lib/runtime/controller/viewport.js.map +1 -1
  164. package/lib/runtime/graph.d.ts +57 -26
  165. package/lib/runtime/graph.js +263 -139
  166. package/lib/runtime/graph.js.map +1 -1
  167. package/lib/stdlib/behavior/click-select.js +9 -3
  168. package/lib/stdlib/behavior/click-select.js.map +1 -1
  169. package/lib/stdlib/behavior/drag-canvas.js +6 -3
  170. package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
  171. package/lib/stdlib/behavior/drag-combo.js +8 -8
  172. package/lib/stdlib/behavior/drag-combo.js.map +1 -1
  173. package/lib/stdlib/behavior/drag-node.d.ts +4 -0
  174. package/lib/stdlib/behavior/drag-node.js +121 -27
  175. package/lib/stdlib/behavior/drag-node.js.map +1 -1
  176. package/lib/stdlib/behavior/scroll-canvas.js +3 -3
  177. package/lib/stdlib/behavior/scroll-canvas.js.map +1 -1
  178. package/lib/stdlib/behavior/zoom-canvas.js +3 -3
  179. package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
  180. package/lib/stdlib/data/mapNodeSize.js +2 -2
  181. package/lib/stdlib/data/mapNodeSize.js.map +1 -1
  182. package/lib/stdlib/data/validateData.js +2 -2
  183. package/lib/stdlib/data/validateData.js.map +1 -1
  184. package/lib/stdlib/index.d.ts +2 -0
  185. package/lib/stdlib/index.js +3 -1
  186. package/lib/stdlib/index.js.map +1 -1
  187. package/lib/stdlib/item/edge/base.d.ts +2 -11
  188. package/lib/stdlib/item/edge/base.js +12 -105
  189. package/lib/stdlib/item/edge/base.js.map +1 -1
  190. package/lib/stdlib/item/node/base.d.ts +2 -20
  191. package/lib/stdlib/item/node/base.js +10 -150
  192. package/lib/stdlib/item/node/base.js.map +1 -1
  193. package/lib/stdlib/plugin/edgeFilterLens/index.js +2 -2
  194. package/lib/stdlib/plugin/edgeFilterLens/index.js.map +1 -1
  195. package/lib/stdlib/plugin/fisheye/index.js +2 -1
  196. package/lib/stdlib/plugin/fisheye/index.js.map +1 -1
  197. package/lib/stdlib/plugin/history/visibility-updated-command.js +2 -2
  198. package/lib/stdlib/plugin/history/visibility-updated-command.js.map +1 -1
  199. package/lib/stdlib/plugin/hull/index.d.ts +1 -1
  200. package/lib/stdlib/plugin/index.d.ts +1 -0
  201. package/lib/stdlib/plugin/index.js +1 -0
  202. package/lib/stdlib/plugin/index.js.map +1 -1
  203. package/lib/stdlib/plugin/lodController/index.d.ts +73 -0
  204. package/lib/stdlib/plugin/lodController/index.js +560 -0
  205. package/lib/stdlib/plugin/lodController/index.js.map +1 -0
  206. package/lib/stdlib/plugin/minimap/index.js +12 -14
  207. package/lib/stdlib/plugin/minimap/index.js.map +1 -1
  208. package/lib/stdlib/plugin/toolbar/index.d.ts +2 -2
  209. package/lib/stdlib/plugin/toolbar/index.js +27 -29
  210. package/lib/stdlib/plugin/toolbar/index.js.map +1 -1
  211. package/lib/stdlib/theme/dark.js +32 -35
  212. package/lib/stdlib/theme/dark.js.map +1 -1
  213. package/lib/stdlib/theme/light.js +27 -30
  214. package/lib/stdlib/theme/light.js.map +1 -1
  215. package/lib/stdlib/themeSolver/spec.js +2 -2
  216. package/lib/stdlib/themeSolver/spec.js.map +1 -1
  217. package/lib/types/animate.d.ts +1 -1
  218. package/lib/types/combo.d.ts +2 -2
  219. package/lib/types/edge.d.ts +2 -2
  220. package/lib/types/graph.d.ts +62 -43
  221. package/lib/types/hook.d.ts +5 -0
  222. package/lib/types/item.d.ts +9 -15
  223. package/lib/types/layout.d.ts +7 -2
  224. package/lib/types/layout.js.map +1 -1
  225. package/lib/types/node.d.ts +3 -2
  226. package/lib/types/plugin.d.ts +1 -0
  227. package/lib/types/plugin.js +1 -0
  228. package/lib/types/plugin.js.map +1 -1
  229. package/lib/types/spec.d.ts +1 -0
  230. package/lib/types/theme.d.ts +7 -7
  231. package/lib/util/animate.d.ts +7 -2
  232. package/lib/util/animate.js +37 -23
  233. package/lib/util/animate.js.map +1 -1
  234. package/lib/util/bbox.d.ts +7 -1
  235. package/lib/util/bbox.js +18 -1
  236. package/lib/util/bbox.js.map +1 -1
  237. package/lib/util/data.d.ts +7 -1
  238. package/lib/util/data.js +19 -6
  239. package/lib/util/data.js.map +1 -1
  240. package/lib/util/dom.js +5 -5
  241. package/lib/util/dom.js.map +1 -1
  242. package/lib/util/item.d.ts +1 -1
  243. package/lib/util/item.js +8 -8
  244. package/lib/util/item.js.map +1 -1
  245. package/lib/util/mapper.js +1 -1
  246. package/lib/util/mapper.js.map +1 -1
  247. package/lib/util/path.d.ts +6 -1
  248. package/lib/util/path.js +72 -1
  249. package/lib/util/path.js.map +1 -1
  250. package/lib/util/polyline.d.ts +10 -0
  251. package/lib/util/polyline.js +25 -18
  252. package/lib/util/polyline.js.map +1 -1
  253. package/lib/util/router.d.ts +1 -1
  254. package/lib/util/router.js +19 -18
  255. package/lib/util/router.js.map +1 -1
  256. package/lib/util/shape.d.ts +1 -1
  257. package/lib/util/shape.js +27 -12
  258. package/lib/util/shape.js.map +1 -1
  259. package/lib/util/zoom.d.ts +5 -8
  260. package/lib/util/zoom.js +17 -22
  261. package/lib/util/zoom.js.map +1 -1
  262. package/package.json +1 -1
  263. package/src/index.ts +1 -1
  264. package/src/item/combo.ts +13 -5
  265. package/src/item/edge.ts +126 -17
  266. package/src/item/item.ts +119 -57
  267. package/src/item/node.ts +108 -11
  268. package/src/runtime/controller/data.ts +64 -3
  269. package/src/runtime/controller/index.ts +1 -1
  270. package/src/runtime/controller/item.ts +321 -135
  271. package/src/runtime/controller/layout.ts +254 -113
  272. package/src/runtime/controller/plugin.ts +86 -33
  273. package/src/runtime/controller/viewport.ts +8 -2
  274. package/src/runtime/graph.ts +383 -158
  275. package/src/stdlib/behavior/click-select.ts +8 -3
  276. package/src/stdlib/behavior/drag-canvas.ts +6 -3
  277. package/src/stdlib/behavior/drag-combo.ts +8 -8
  278. package/src/stdlib/behavior/drag-node.ts +165 -50
  279. package/src/stdlib/behavior/scroll-canvas.ts +3 -3
  280. package/src/stdlib/behavior/zoom-canvas.ts +3 -3
  281. package/src/stdlib/data/mapNodeSize.ts +2 -2
  282. package/src/stdlib/data/validateData.ts +2 -2
  283. package/src/stdlib/index.ts +3 -0
  284. package/src/stdlib/item/edge/base.ts +15 -139
  285. package/src/stdlib/item/node/base.ts +20 -215
  286. package/src/stdlib/plugin/edgeFilterLens/index.ts +2 -2
  287. package/src/stdlib/plugin/fisheye/index.ts +3 -2
  288. package/src/stdlib/plugin/history/visibility-updated-command.ts +2 -2
  289. package/src/stdlib/plugin/index.ts +1 -0
  290. package/src/stdlib/plugin/lodController/index.ts +602 -0
  291. package/src/stdlib/plugin/minimap/index.ts +12 -14
  292. package/src/stdlib/plugin/toolbar/index.ts +29 -31
  293. package/src/stdlib/theme/dark.ts +32 -34
  294. package/src/stdlib/theme/light.ts +27 -29
  295. package/src/stdlib/themeSolver/spec.ts +2 -2
  296. package/src/types/animate.ts +1 -1
  297. package/src/types/combo.ts +2 -2
  298. package/src/types/edge.ts +2 -2
  299. package/src/types/graph.ts +65 -53
  300. package/src/types/hook.ts +5 -0
  301. package/src/types/item.ts +8 -14
  302. package/src/types/layout.ts +20 -15
  303. package/src/types/node.ts +3 -2
  304. package/src/types/plugin.ts +2 -0
  305. package/src/types/spec.ts +1 -0
  306. package/src/types/theme.ts +7 -7
  307. package/src/util/animate.ts +104 -78
  308. package/src/util/bbox.ts +26 -1
  309. package/src/util/data.ts +15 -6
  310. package/src/util/dom.ts +6 -6
  311. package/src/util/item.ts +15 -1
  312. package/src/util/mapper.ts +1 -1
  313. package/src/util/path.ts +72 -2
  314. package/src/util/polyline.ts +30 -23
  315. package/src/util/router.ts +21 -19
  316. package/src/util/shape.ts +27 -12
  317. package/src/util/zoom.ts +19 -25
  318. package/esm/runtime/controller/extension.d.ts +0 -9
  319. package/esm/runtime/controller/extension.js +0 -11
  320. package/esm/runtime/controller/extension.js.map +0 -1
  321. package/lib/runtime/controller/extension.d.ts +0 -9
  322. package/lib/runtime/controller/extension.js +0 -15
  323. package/lib/runtime/controller/extension.js.map +0 -1
  324. 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,83 +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, iterations } = animateConfig;
173
- if (iterations === Infinity && animateCfg.fill == undefined) {
174
- animateConfig.fill = 'auto';
175
- }
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
+ }
176
180
 
177
- let animation;
178
- if (!shapeId || shapeId === 'group') {
179
- // animate on group
180
- const usingFields = [];
181
- let hasOpacity = false;
182
- fields?.forEach((field) => {
183
- if (field === 'size') usingFields.push('transform');
184
- else if (field !== 'opacity') usingFields.push(field);
185
- else hasOpacity = true;
186
- });
187
- const targetStyle =
188
- targetStylesMap.group || GROUP_ANIMATE_STYLES[isOut ? 0 : 1];
189
- if (hasCanceled) {
190
- Object.keys(targetStyle).forEach((key) => {
191
- 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;
192
190
  });
193
- } else {
194
- if (hasOpacity) {
195
- // opacity on group, animate on all shapes
196
- Object.keys(shapeMap).forEach((shapeId) => {
197
- const { opacity: targetOpaicty = 1 } =
198
- targetStylesMap[shapeId] ||
199
- targetStylesMap.otherShapes?.[shapeId] ||
200
- {};
201
- animation = runAnimateOnShape(
202
- shapeMap[shapeId],
203
- ['opacity'],
204
- { opacity: targetOpaicty },
205
- getShapeAnimateBeginStyles(shapeMap[shapeId]),
206
- animateConfig,
207
- );
208
- });
209
- }
210
- if (usingFields.length) {
211
- animation = runAnimateOnShape(
212
- group,
213
- usingFields,
214
- targetStyle,
215
- GROUP_ANIMATE_STYLES[isOut ? 1 : 0],
216
- animateConfig,
217
- );
218
- }
219
- }
220
- } else {
221
- const shape = shapeMap[shapeId];
222
- if (shape && shape.style.display !== 'none') {
223
191
  const targetStyle =
224
- targetStylesMap[shapeId] ||
225
- targetStylesMap.otherShapes?.[shapeId] ||
226
- {};
192
+ targetStylesMap.group || GROUP_ANIMATE_STYLES[isOut ? 0 : 1];
227
193
  if (hasCanceled) {
228
194
  Object.keys(targetStyle).forEach((key) => {
229
- shape.style[key] = targetStyle[key];
195
+ groups.forEach((group) => (group.style[key] = targetStyle[key]));
230
196
  });
231
197
  } else {
232
- animation = runAnimateOnShape(
233
- shape,
234
- fields,
235
- targetStyle,
236
- getShapeAnimateBeginStyles(shape),
237
- animateConfig,
238
- );
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
+ }
239
257
  }
240
258
  }
241
- }
242
- 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) {
243
266
  maxDuration = duration;
244
267
  maxDurationIdx = i;
245
268
  }
@@ -249,7 +272,6 @@ const runAnimateGroupOnShapes = (
249
272
  cancelAnimations();
250
273
  };
251
274
  }
252
- return animation;
253
275
  });
254
276
  if (maxDurationIdx > -1) {
255
277
  const selfOnfinish = animations[maxDurationIdx].onfinish;
@@ -286,10 +308,10 @@ const runAnimateOnShape = (
286
308
  fields.forEach((key) => {
287
309
  animateArr[0][key] =
288
310
  shape.style[key] === undefined
289
- ? clone(beginStyle[key])
290
- : clone(shape.style[key]);
311
+ ? cloneJSON(beginStyle[key])
312
+ : cloneJSON(shape.style[key]);
291
313
  if (targetStyle[key] === undefined) return;
292
- animateArr[1][key] = clone(targetStyle[key]);
314
+ animateArr[1][key] = cloneJSON(targetStyle[key]);
293
315
  if (key === 'lineDash') {
294
316
  const beginPercents = uniq(
295
317
  animateArr[0][key].filter(
@@ -302,7 +324,7 @@ const runAnimateOnShape = (
302
324
  ),
303
325
  );
304
326
  if (beginPercents.length || targetPercents.length) {
305
- percentLineDash = clone(animateArr[0].lineDash);
327
+ percentLineDash = cloneJSON(animateArr[0].lineDash);
306
328
  const totalLength = (
307
329
  shape as Line | Polyline | Path
308
330
  ).getTotalLength();
@@ -334,6 +356,8 @@ const runAnimateOnShape = (
334
356
  );
335
357
  return;
336
358
  }
359
+ if (animateConfig.iterations === -1 || animateConfig.iterations === null)
360
+ animateConfig.iterations = Infinity;
337
361
  const animation = shape.animate(animateArr, animateConfig);
338
362
  if (percentLineDash) {
339
363
  animation.onfinish = () => {
@@ -384,7 +408,8 @@ export const animateShapes = (
384
408
  animates: IAnimates,
385
409
  mergedStyles: ItemShapeStyles,
386
410
  shapeMap: { [shapeId: string]: DisplayObject },
387
- group: Group,
411
+ shapeIds: string[] = undefined,
412
+ groups: Group[],
388
413
  timing: AnimateTiming = 'buildIn',
389
414
  changedStates: string[] = [],
390
415
  onAnimatesFrame: Function = () => {},
@@ -413,7 +438,8 @@ export const animateShapes = (
413
438
  }
414
439
  const groupAnimations = runAnimateGroupOnShapes(
415
440
  shapeMap,
416
- group,
441
+ shapeIds,
442
+ groups,
417
443
  timingAnimateGroups[groupKeys[i]],
418
444
  mergedStyles,
419
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
+ };