@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
@@ -12,6 +12,7 @@ import {
12
12
  } from './bbox';
13
13
  import { getLineIntersect } from './shape';
14
14
  import { eulerDist, manhattanDist } from './math';
15
+ import { getNearestPoint } from './point';
15
16
 
16
17
  export interface RouterCfg {
17
18
  name: 'orth' | 'er';
@@ -43,13 +44,13 @@ export interface RouterCfg {
43
44
  * Whether to automatically avoid other nodes (obstacles) on the path
44
45
  * Defaults to false.
45
46
  */
46
- obstacleAvoidance?: boolean;
47
+ enableObstacleAvoidance?: boolean;
47
48
  }
48
49
 
49
50
  const defaultCfg: RouterCfg = {
50
51
  name: 'orth',
51
- obstacleAvoidance: false,
52
- offset: 20,
52
+ enableObstacleAvoidance: false,
53
+ offset: 2,
53
54
  maxAllowedDirectionChange: Math.PI / 2,
54
55
  maximumLoops: 2000,
55
56
  gridSize: 10,
@@ -307,11 +308,11 @@ const getControlPoints = (
307
308
  cameFrom,
308
309
  scaleStartPoint,
309
310
  endPoint,
310
- startPoint,
311
+ startPoints,
311
312
  scaleEndPoint,
312
313
  gridSize,
313
314
  ) => {
314
- const controlPoints = [endPoint];
315
+ const controlPoints = [];
315
316
  let pointZero = endPoint;
316
317
  let currentId = current.id;
317
318
  let currentX = current.x;
@@ -321,13 +322,13 @@ const getControlPoints = (
321
322
  y: currentY,
322
323
  id: currentId,
323
324
  };
324
- if (getDirectionChange(lastPoint, scaleEndPoint, cameFrom, scaleStartPoint)) {
325
- pointZero = {
326
- x: scaleEndPoint.x === endPoint.x ? endPoint.x : lastPoint.x * gridSize,
327
- y: scaleEndPoint.y === endPoint.y ? endPoint.y : lastPoint.y * gridSize,
328
- };
329
- controlPoints.unshift(pointZero);
330
- }
325
+ // append endPoint
326
+ pointZero = {
327
+ x: scaleEndPoint.x === endPoint.x ? endPoint.x : lastPoint.x * gridSize,
328
+ y: scaleEndPoint.y === endPoint.y ? endPoint.y : lastPoint.y * gridSize,
329
+ };
330
+ controlPoints.unshift(pointZero);
331
+
331
332
  let currentCameFrom = cameFrom[currentId];
332
333
  while (currentCameFrom && currentCameFrom.id !== currentId) {
333
334
  const point = {
@@ -360,11 +361,12 @@ const getControlPoints = (
360
361
  currentCameFrom = cameFrom[currentId];
361
362
  }
362
363
 
363
- // Align with startNode
364
- controlPoints[0].x =
365
- currentX === scaleStartPoint.x ? startPoint.x : pointZero.x;
366
- controlPoints[0].y =
367
- currentY === scaleStartPoint.y ? startPoint.y : pointZero.y;
364
+ // append startPoint
365
+ const realStartPoints = startPoints.map((point) => ({
366
+ x: point.x * gridSize,
367
+ y: point.y * gridSize,
368
+ }));
369
+ const startPoint = getNearestPoint(realStartPoints, pointZero).nearestPoint;
368
370
  controlPoints.unshift(startPoint);
369
371
  return controlPoints;
370
372
  };
@@ -391,7 +393,7 @@ export const pathFinder = (
391
393
 
392
394
  const cfg: RouterCfg = deepMix(defaultCfgs, routerCfg);
393
395
 
394
- if (!cfg.obstacleAvoidance) {
396
+ if (!cfg.enableObstacleAvoidance) {
395
397
  return cfg.fallbackRoute(startPoint, endPoint, startNode, endNode, cfg);
396
398
  }
397
399
 
@@ -497,7 +499,7 @@ export const pathFinder = (
497
499
  cameFrom,
498
500
  scaleStartPoint,
499
501
  endPoint,
500
- startPoint,
502
+ startPoints,
501
503
  scaleEndPoint,
502
504
  gridSize,
503
505
  );
package/src/util/shape.ts CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  AABB,
15
15
  Tuple3Number,
16
16
  } from '@antv/g';
17
- import { clone, isArray, isNumber } from '@antv/util';
17
+ import { isArray, isNumber } from '@antv/util';
18
18
  import { DEFAULT_LABEL_BG_PADDING } from '../constant';
19
19
  import { Padding, Point, StandardPadding } from '../types/common';
20
20
  import { EdgeDisplayModel, EdgeShapeMap } from '../types/edge';
@@ -33,6 +33,7 @@ import Combo from '../item/combo';
33
33
  import { getShapeAnimateBeginStyles } from './animate';
34
34
  import { isArrayOverlap } from './array';
35
35
  import { isBetween } from './math';
36
+ import { cloneJSON } from './data';
36
37
 
37
38
  export const ShapeTagMap = {
38
39
  circle: Circle,
@@ -116,9 +117,6 @@ export const upsertShape = (
116
117
  const firstRendering = !shapeMap.keyShape;
117
118
  const { animates, disableAnimate } = model?.data || {};
118
119
  if (!shape) {
119
- // create
120
- shape = createShape(type, style, id);
121
- if (style.interactive === false) shape.interactive = false;
122
120
  // find the animate styles, set them to be INIT_SHAPE_STYLES
123
121
  if (!disableAnimate && animates) {
124
122
  const animateFields = findAnimateFields(
@@ -126,11 +124,15 @@ export const upsertShape = (
126
124
  firstRendering ? 'buildIn' : 'update',
127
125
  id,
128
126
  );
127
+ shape = createShape(type, style, id);
129
128
  const initShapeStyles = getShapeAnimateBeginStyles(shape);
130
129
  animateFields.forEach((key) => {
131
130
  shape.style[key] = initShapeStyles[key];
132
131
  });
132
+ } else {
133
+ shape = createShape(type, style, id);
133
134
  }
135
+ if (style.interactive === false) shape.interactive = false;
134
136
  } else if (shape.nodeName !== type) {
135
137
  // remove and create for the shape changed type
136
138
  shape.remove();
@@ -191,6 +193,7 @@ export const updateShapes = (
191
193
  prevShapeMap: { [id: string]: DisplayObject },
192
194
  newShapeMap: { [id: string]: DisplayObject },
193
195
  group: Group,
196
+ labelGroup: Group,
194
197
  removeDiff = true,
195
198
  shouldUpdate: (id: string) => boolean = () => true,
196
199
  ): NodeShapeMap | EdgeShapeMap => {
@@ -212,16 +215,27 @@ export const updateShapes = (
212
215
  prevShape.remove();
213
216
  }
214
217
  finalShapeMap[id] = newShape;
218
+ const parentGroup =
219
+ newShape.attributes.dataIsLabel ||
220
+ newShape.attributes.dataIsLabelBackground
221
+ ? labelGroup
222
+ : group;
215
223
  if (
216
224
  // NewShape is already in the group, no need to reappend.
217
225
  // Note: If the given child is a reference to an existing node in the document,
218
226
  // appendChild() moves it from its current position to the new position.
219
227
  // @see https://developer.mozilla.org/en-US/docs/Web/API/Node/appendChild
220
- newShape.parentElement !== group &&
228
+ newShape.parentElement !== parentGroup &&
221
229
  !newShape.destroyed &&
222
230
  newShape.style.display !== 'none'
223
231
  ) {
224
- group.appendChild(newShape);
232
+ parentGroup.appendChild(newShape);
233
+ if (newShape.style.lod === 'auto') {
234
+ newShape.style.visibility = 'hidden';
235
+ if (newShape.id === 'labelShape' && parentGroup === labelGroup) {
236
+ labelGroup.attributes.visibility = 'hidden';
237
+ }
238
+ }
225
239
  }
226
240
  }
227
241
 
@@ -268,7 +282,7 @@ export const formatPadding = (
268
282
  * @returns
269
283
  */
270
284
  export const mergeStyles = (styleMaps: ItemShapeStyles[]) => {
271
- let currentResult = clone(styleMaps[0]);
285
+ let currentResult = cloneJSON(styleMaps[0]);
272
286
  styleMaps.forEach((styleMap, i) => {
273
287
  if (i > 0) currentResult = merge2Styles(currentResult, styleMap);
274
288
  });
@@ -397,11 +411,12 @@ export const isPolygonsIntersect = (
397
411
  };
398
412
 
399
413
  export const intersectBBox = (box1: Partial<AABB>, box2: Partial<AABB>) => {
400
- return !(
401
- box2.min[0] > box1.max[0] ||
402
- box2.max[0] < box1.min[0] ||
403
- box2.min[1] > box1.max[1] ||
404
- box2.max[1] < box1.min[1]
414
+ if (!box2?.min || !box1?.min) return false;
415
+ return (
416
+ box2.min[0] <= box1.max[0] &&
417
+ box2.max[0] >= box1.min[0] &&
418
+ box2.min[1] <= box1.max[1] &&
419
+ box2.max[1] >= box1.min[1]
405
420
  );
406
421
  };
407
422
 
package/src/util/zoom.ts CHANGED
@@ -1,27 +1,22 @@
1
- import { LodStrategy, LodStrategyObj } from '../types/item';
1
+ import { LodLevel, LodLevelRanges } from '../types/item';
2
2
 
3
3
  /**
4
- * Format lodStrategy to the pattern that ratio 1 (primary level) at level 0, and higher the ratio, higher the level.
5
- * @param lodStrategy
4
+ * Format lodLevels to the pattern that ratio 1 (primary level) at level 0, and higher the ratio, higher the level.
5
+ * @param lodLevels
6
6
  * @returns
7
7
  */
8
- export const formatLodStrategy = (
9
- lodStrategy?: LodStrategy,
10
- ): LodStrategyObj | undefined => {
11
- if (!lodStrategy) return;
12
- const { levels, animateCfg } = lodStrategy;
13
- if (!levels) return;
14
- const primaryLevel = levels.find((level) => level.primary);
8
+ export const formatLodLevels = (
9
+ lodLevels?: LodLevel[],
10
+ ): LodLevelRanges | undefined => {
11
+ if (!lodLevels?.length) return;
12
+ const primaryLevel = lodLevels.find((level) => level.primary);
15
13
  if (!primaryLevel) return;
16
- const primaryIndex = levels.indexOf(primaryLevel);
14
+ const primaryIndex = lodLevels.indexOf(primaryLevel);
17
15
  const formattedLevels = {};
18
- levels.forEach((level, i) => {
16
+ lodLevels.forEach((level, i) => {
19
17
  formattedLevels[i - primaryIndex] = level.zoomRange;
20
18
  });
21
- return {
22
- animateCfg,
23
- levels: formattedLevels,
24
- };
19
+ return formattedLevels;
25
20
  };
26
21
 
27
22
  /**
@@ -30,14 +25,13 @@ export const formatLodStrategy = (
30
25
  * @param zoom
31
26
  * @returns
32
27
  */
33
- export const getZoomLevel = (
34
- levels: { [idx: number | string]: [number, number] },
35
- zoom: number,
36
- ) => {
37
- let level = 0;
38
- Object.keys(levels).forEach((idx) => {
28
+ export const getZoomLevel = (levels: LodLevelRanges, zoom: number) => {
29
+ const keys = Object.keys(levels);
30
+ for (let i = 0; i < keys.length; i++) {
31
+ const idx = keys[i];
39
32
  const zoomRange = levels[idx];
40
- if (zoom >= zoomRange[0] && zoom < zoomRange[1]) level = Number(idx);
41
- });
42
- return level;
33
+ if (zoom >= zoomRange[0] && zoom < zoomRange[1]) {
34
+ return Number(idx);
35
+ }
36
+ }
43
37
  };
@@ -1,9 +0,0 @@
1
- import { IGraph } from '../../types';
2
- /**
3
- * Free extensions(plugins) controller
4
- */
5
- export declare class ExtensionController {
6
- extensions: {};
7
- graph: IGraph;
8
- constructor(graph: IGraph<any, any>);
9
- }
@@ -1,11 +0,0 @@
1
- /**
2
- * Free extensions(plugins) controller
3
- */
4
- export class ExtensionController {
5
- constructor(graph) {
6
- this.extensions = {};
7
- this.graph = graph;
8
- // this.tap();
9
- }
10
- }
11
- //# sourceMappingURL=extension.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extension.js","sourceRoot":"src/","sources":["runtime/controller/extension.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,mBAAmB;IAI9B,YAAY,KAAuB;QAH5B,eAAU,GAAG,EAAE,CAAC;QAIrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,cAAc;IAChB,CAAC;CACF"}
@@ -1,9 +0,0 @@
1
- import { IGraph } from '../../types';
2
- /**
3
- * Free extensions(plugins) controller
4
- */
5
- export declare class ExtensionController {
6
- extensions: {};
7
- graph: IGraph;
8
- constructor(graph: IGraph<any, any>);
9
- }
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExtensionController = void 0;
4
- /**
5
- * Free extensions(plugins) controller
6
- */
7
- class ExtensionController {
8
- constructor(graph) {
9
- this.extensions = {};
10
- this.graph = graph;
11
- // this.tap();
12
- }
13
- }
14
- exports.ExtensionController = ExtensionController;
15
- //# sourceMappingURL=extension.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extension.js","sourceRoot":"src/","sources":["runtime/controller/extension.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,MAAa,mBAAmB;IAI9B,YAAY,KAAuB;QAH5B,eAAU,GAAG,EAAE,CAAC;QAIrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,cAAc;IAChB,CAAC;CACF;AARD,kDAQC"}
@@ -1,14 +0,0 @@
1
- import { IGraph } from '../../types';
2
-
3
- /**
4
- * Free extensions(plugins) controller
5
- */
6
- export class ExtensionController {
7
- public extensions = {};
8
- public graph: IGraph;
9
-
10
- constructor(graph: IGraph<any, any>) {
11
- this.graph = graph;
12
- // this.tap();
13
- }
14
- }