@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
package/src/item/item.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Group, DisplayObject, AABB, IAnimation } from '@antv/g';
2
- import { clone, isFunction, isObject, throttle } from '@antv/util';
2
+ import { clone, isFunction, isObject, pick, throttle } from '@antv/util';
3
3
  import { OTHER_SHAPES_FIELD_NAME, RESERVED_SHAPE_IDS } from '../constant';
4
4
  import { EdgeShapeMap } from '../types/edge';
5
5
  import {
@@ -11,7 +11,7 @@ import {
11
11
  ItemShapeStyles,
12
12
  ITEM_TYPE,
13
13
  State,
14
- LodStrategyObj,
14
+ LodLevelRanges,
15
15
  } from '../types/item';
16
16
  import { NodeShapeMap } from '../types/node';
17
17
  import { EdgeStyleSet, NodeStyleSet } from '../types/theme';
@@ -24,16 +24,19 @@ import {
24
24
  } from '../util/shape';
25
25
  import { isEncode } from '../util/type';
26
26
  import { DEFAULT_MAPPER } from '../util/mapper';
27
+ import { cloneJSON } from '../util/data';
27
28
  import {
28
29
  getShapeAnimateBeginStyles,
29
30
  animateShapes,
30
31
  GROUP_ANIMATE_STYLES,
31
32
  stopAnimate,
32
33
  } from '../util/animate';
33
- import { AnimateTiming, IAnimates } from '../types/animate';
34
- import { formatLodStrategy } from '../util/zoom';
34
+ import { AnimateTiming, IAnimates, IStateAnimate } from '../types/animate';
35
+ import { formatLodLevels } from '../util/zoom';
36
+ import { IGraph } from '../types';
35
37
 
36
38
  export default abstract class Item implements IItem {
39
+ public graph: IGraph;
37
40
  public destroyed = false;
38
41
  /** Inner model. */
39
42
  public model: ItemModel;
@@ -47,6 +50,8 @@ export default abstract class Item implements IItem {
47
50
  };
48
51
  /** The graphic group for item drawing. */
49
52
  public group: Group;
53
+ /** The graphic group for item'label drawing. */
54
+ public labelGroup: Group;
50
55
  /** The keyShape of the item. */
51
56
  public keyShape: DisplayObject;
52
57
  /** render extension for this item. */
@@ -62,7 +67,9 @@ export default abstract class Item implements IItem {
62
67
  public shapeMap: NodeShapeMap | EdgeShapeMap = {
63
68
  keyShape: undefined,
64
69
  };
65
- public afterDrawShapeMap = {};
70
+ public afterDrawShapeMap: {
71
+ [otherShapeId: string]: DisplayObject;
72
+ } = {};
66
73
  /** Set to different value in implements. */
67
74
  public type: ITEM_TYPE;
68
75
  /** The flag of transient item. */
@@ -78,7 +85,7 @@ export default abstract class Item implements IItem {
78
85
  [stateName: string]: ItemShapeStyles;
79
86
  };
80
87
  /** The zoom strategy to show and hide shapes according to their lod. */
81
- public lodStrategy: LodStrategyObj;
88
+ public lodLevels: LodLevelRanges;
82
89
  /** Last zoom ratio. */
83
90
  public zoom: number;
84
91
  /** Cache the chaging states which are not consomed by draw */
@@ -102,8 +109,10 @@ export default abstract class Item implements IItem {
102
109
  /** Initiate the item. */
103
110
  public init(props) {
104
111
  const {
112
+ graph,
105
113
  model,
106
114
  containerGroup,
115
+ labelContainerGroup,
107
116
  mapper,
108
117
  stateMapper,
109
118
  renderExtensions,
@@ -112,10 +121,15 @@ export default abstract class Item implements IItem {
112
121
  type: itemType,
113
122
  } = props;
114
123
  this.type = itemType;
124
+ this.graph = graph;
115
125
  this.group = new Group({ style: { zIndex: 0 } });
126
+ this.labelGroup = new Group({ style: { zIndex: 0 } });
116
127
  this.group.setAttribute('data-item-type', this.type);
117
128
  this.group.setAttribute('data-item-id', props.model.id);
129
+ this.labelGroup.setAttribute('data-item-type', this.type);
130
+ this.labelGroup.setAttribute('data-item-id', props.model.id);
118
131
  containerGroup.appendChild(this.group);
132
+ labelContainerGroup.appendChild(this.labelGroup);
119
133
  this.model = model;
120
134
  this.mapper = mapper;
121
135
  this.zoom = zoom;
@@ -124,14 +138,14 @@ export default abstract class Item implements IItem {
124
138
  this.renderExtensions = renderExtensions;
125
139
  const {
126
140
  type = this.type === 'edge' ? 'line-edge' : `circle-${this.type}`,
127
- lodStrategy: modelLodStrategy,
141
+ lodLevels: modelLodLevels,
128
142
  enableBalanceShape,
129
143
  } = this.displayModel.data;
130
144
  const RenderExtension = renderExtensions.find((ext) => ext.type === type);
131
145
  this.themeStyles = theme.styles;
132
- const lodStrategy = modelLodStrategy
133
- ? formatLodStrategy(modelLodStrategy)
134
- : theme.lodStrategy;
146
+ this.lodLevels = modelLodLevels
147
+ ? formatLodLevels(modelLodLevels)
148
+ : theme.lodLevels;
135
149
  if (!RenderExtension) {
136
150
  if (this.type === 'node') {
137
151
  throw new Error(
@@ -149,7 +163,7 @@ export default abstract class Item implements IItem {
149
163
  }
150
164
  this.renderExt = new RenderExtension({
151
165
  themeStyles: this.themeStyles?.default,
152
- lodStrategy,
166
+ lodLevels: this.lodLevels,
153
167
  enableBalanceShape,
154
168
  device: this.device,
155
169
  zoom: this.zoom,
@@ -173,10 +187,18 @@ export default abstract class Item implements IItem {
173
187
  ...this.shapeMap,
174
188
  ...this.afterDrawShapeMap,
175
189
  }) || {};
190
+ if (this.afterDrawShapeMap.labelShape) {
191
+ this.afterDrawShapeMap.labelShape.attributes.dataIsLabel = true;
192
+ }
193
+ if (this.afterDrawShapeMap.labelBackgroundShape) {
194
+ this.afterDrawShapeMap.labelBackgroundShape.attributes.dataIsLabelBackground =
195
+ true;
196
+ }
176
197
  const shapeMap = updateShapes(
177
198
  this.afterDrawShapeMap,
178
199
  afterDrawShapeMap,
179
200
  this.group,
201
+ this.labelGroup,
180
202
  false,
181
203
  (id) => {
182
204
  if (RESERVED_SHAPE_IDS.includes(id)) {
@@ -192,6 +214,7 @@ export default abstract class Item implements IItem {
192
214
  ...this.shapeMap,
193
215
  ...shapeMap,
194
216
  };
217
+ this.changedStates = [];
195
218
  }
196
219
 
197
220
  /**
@@ -204,7 +227,7 @@ export default abstract class Item implements IItem {
204
227
  isReplace?: boolean,
205
228
  itemTheme?: {
206
229
  styles: NodeStyleSet | EdgeStyleSet;
207
- lodStrategy: LodStrategyObj;
230
+ lodLevels: LodLevelRanges;
208
231
  },
209
232
  onlyMove?: boolean,
210
233
  animate = true,
@@ -223,9 +246,9 @@ export default abstract class Item implements IItem {
223
246
  );
224
247
  this.displayModel = displayModel;
225
248
 
226
- this.lodStrategy = displayModel.data.lodStrategy
227
- ? formatLodStrategy(displayModel.data.lodStrategy)
228
- : itemTheme?.lodStrategy || this.lodStrategy;
249
+ this.lodLevels = displayModel.data.lodLevels
250
+ ? formatLodLevels(displayModel.data.lodLevels)
251
+ : itemTheme?.lodLevels || this.lodLevels;
229
252
 
230
253
  if (onlyMove) {
231
254
  this.updatePosition(displayModel, diffData, animate, onfinish);
@@ -242,13 +265,13 @@ export default abstract class Item implements IItem {
242
265
  );
243
266
  this.renderExt = new RenderExtension({
244
267
  themeStyles: this.themeStyles.default,
245
- lodStrategy: this.lodStrategy,
268
+ lodLevels: this.lodLevels,
246
269
  device: this.device,
247
270
  zoom: this.zoom,
248
271
  });
249
272
  } else {
250
273
  this.renderExt.themeStyles = this.themeStyles.default;
251
- this.renderExt.lodStrategy = this.lodStrategy;
274
+ this.renderExt.lodLevels = this.lodLevels;
252
275
  }
253
276
  // 3. call element update fn from useLib
254
277
  if (this.states?.length) {
@@ -324,7 +347,7 @@ export default abstract class Item implements IItem {
324
347
  // === fields' values in mapper are final value or Encode ===
325
348
  const dataChangedFields = isReplace
326
349
  ? undefined
327
- : Object.keys(current).concat(Object.keys(otherFields)); // only fields in current data for partial updating
350
+ : Object.keys(current || {}).concat(Object.keys(otherFields)); // only fields in current data for partial updating
328
351
 
329
352
  let typeChange = false;
330
353
  const { data, ...otherProps } = innerModel;
@@ -366,6 +389,7 @@ export default abstract class Item implements IItem {
366
389
  displayModelData[fieldName] || isObject(innerModel.data[fieldName])
367
390
  ? {
368
391
  ...(innerModel.data[fieldName] as object),
392
+ ...(this.displayModel?.data[fieldName] as object),
369
393
  }
370
394
  : {};
371
395
  updateShapeChange({
@@ -417,10 +441,23 @@ export default abstract class Item implements IItem {
417
441
  }
418
442
 
419
443
  /** Show the item. */
420
- public show(animate = true) {
421
- Promise.all(this.stopAnimations()).finally(() => {
444
+ public show(animate = true, shapeIds = undefined) {
445
+ const shapeIdsToStop = shapeIds?.filter((id) => {
446
+ const shape = this.shapeMap[id];
447
+ return shape && shape.style.visibility === 'hidden';
448
+ });
449
+ if (shapeIds?.length && !shapeIdsToStop?.length) return;
450
+ if (!shapeIdsToStop || shapeIdsToStop.includes('labelShape')) {
451
+ this.labelGroup.style.visibility = 'visible';
452
+ }
453
+ Promise.all(this.stopAnimations(shapeIdsToStop)).finally(() => {
422
454
  if (this.destroyed) return;
423
455
  const { animates = {} } = this.displayModel.data;
456
+ const shapeIdsToShow =
457
+ shapeIdsToStop ||
458
+ Object.keys(this.shapeMap).filter(
459
+ (shapeId) => this.cacheHiddenByItem[shapeId],
460
+ );
424
461
  if (animate && animates.show?.length) {
425
462
  const showAnimateFieldsMap: any = {};
426
463
  Object.values(animates.show).forEach((animate) => {
@@ -430,24 +467,26 @@ export default abstract class Item implements IItem {
430
467
  ).concat(animate.fields);
431
468
  });
432
469
  const targetStyleMap = {};
433
- Object.keys(this.shapeMap).forEach((id) => {
470
+ shapeIdsToShow.forEach((id) => {
434
471
  const shape = this.shapeMap[id];
435
- if (this.cacheHiddenByItem[id]) {
436
- // set the animate fields to initial value
437
- if (showAnimateFieldsMap[id]) {
438
- targetStyleMap[id] = targetStyleMap[id] || {};
439
- const beginStyle = getShapeAnimateBeginStyles(shape);
440
- showAnimateFieldsMap[id].forEach((field) => {
441
- if (beginStyle.hasOwnProperty(field)) {
442
- targetStyleMap[id][field] = shape.style[field];
443
- shape.style[field] = beginStyle[field];
444
- }
445
- });
446
- }
447
- shape.show();
472
+ // set the animate fields to initial value
473
+ if (showAnimateFieldsMap[id]) {
474
+ targetStyleMap[id] = targetStyleMap[id] || {};
475
+ const beginStyle = getShapeAnimateBeginStyles(shape);
476
+ showAnimateFieldsMap[id].forEach((field) => {
477
+ if (beginStyle.hasOwnProperty(field)) {
478
+ targetStyleMap[id][field] = shape.style[field];
479
+ shape.style[field] = beginStyle[field];
480
+ }
481
+ });
448
482
  }
483
+ shape.show();
484
+ delete this.cacheHiddenByItem[id];
449
485
  });
450
- if (showAnimateFieldsMap.group && !this.shapeMap.keyShape.isVisible()) {
486
+ if (
487
+ showAnimateFieldsMap.group &&
488
+ this.shapeMap.keyShape.attributes.visibility === 'hidden'
489
+ ) {
451
490
  showAnimateFieldsMap.group.forEach((field) => {
452
491
  const usingField = field === 'size' ? 'transform' : field;
453
492
  if (GROUP_ANIMATE_STYLES[0].hasOwnProperty(usingField)) {
@@ -456,42 +495,58 @@ export default abstract class Item implements IItem {
456
495
  }
457
496
  });
458
497
  }
459
-
460
498
  if (Object.keys(targetStyleMap).length) {
461
499
  this.animations = this.runWithAnimates(
462
500
  animates,
463
501
  'show',
464
502
  targetStyleMap,
503
+ shapeIdsToShow,
465
504
  );
466
505
  }
467
506
  } else {
468
- Object.keys(this.shapeMap).forEach((id) => {
507
+ shapeIdsToShow.forEach((id) => {
469
508
  const shape = this.shapeMap[id];
470
- if (this.cacheHiddenByItem[id]) shape.show();
509
+ shape.show();
510
+ delete this.cacheHiddenByItem[id];
471
511
  });
472
512
  }
473
513
 
474
514
  this.visible = true;
475
515
  this.cacheHiddenByItem = {};
516
+ // restore the states
517
+ if (this.states?.length) {
518
+ this.drawWithStates([]);
519
+ }
476
520
  });
477
521
  }
478
522
 
479
523
  /** Hides the item. */
480
- public hide(animate = true, keepKeyShape = false) {
524
+ public hide(animate = true, keepKeyShape = false, shapeIds = undefined) {
525
+ const shapeIdsToHide =
526
+ shapeIds?.filter((id) => {
527
+ const shape = this.shapeMap[id];
528
+ return (
529
+ shape &&
530
+ (shape.attributes.visibility !== 'hidden' ||
531
+ this.cacheNotHiddenByItem[id])
532
+ );
533
+ }) || Object.keys(this.shapeMap);
534
+ if (!shapeIdsToHide.length) return;
481
535
  this.cacheNotHiddenByItem = {};
482
536
  const func = () => {
483
- Object.keys(this.shapeMap).forEach((id) => {
537
+ shapeIdsToHide.forEach((id) => {
484
538
  if (keepKeyShape && id === 'keyShape') return;
485
539
  const shape = this.shapeMap[id];
486
- if (!shape.isVisible()) {
540
+ if (!shape || shape.attributes.visibility === 'hidden') {
487
541
  this.cacheNotHiddenByItem[id] = true;
488
542
  return;
489
543
  }
490
544
  shape.hide();
491
545
  this.cacheHiddenByItem[id] = true;
546
+ if (!shapeIds) this.visible = false;
492
547
  });
493
548
  };
494
- Promise.all(this.stopAnimations()).then(() => {
549
+ Promise.all(this.stopAnimations(shapeIdsToHide)).then(() => {
495
550
  if (this.destroyed) return;
496
551
  const { animates = {} } = this.displayModel.data;
497
552
  if (animate && animates.hide?.length) {
@@ -499,13 +554,13 @@ export default abstract class Item implements IItem {
499
554
  animates,
500
555
  'hide',
501
556
  undefined,
557
+ shapeIdsToHide,
502
558
  func,
503
559
  );
504
560
  } else {
505
561
  // 2. clear group and remove group
506
562
  func();
507
563
  }
508
- this.visible = false;
509
564
  });
510
565
  }
511
566
 
@@ -540,7 +595,7 @@ export default abstract class Item implements IItem {
540
595
  * @param value state value
541
596
  */
542
597
  public setState(state: string, value: string | boolean) {
543
- const previousStates = clone(this.states);
598
+ const previousStates = cloneJSON(this.states);
544
599
  const existState = this.states.find((item) => item.name === state);
545
600
  if (value) {
546
601
  if (existState) existState.value = value;
@@ -569,7 +624,7 @@ export default abstract class Item implements IItem {
569
624
  */
570
625
  public clearStates(states?: string[]) {
571
626
  // if states is not assigned, clear all the states on the item
572
- const previousStates = clone(this.states);
627
+ const previousStates = cloneJSON(this.states);
573
628
  const newStates = [];
574
629
  let changedStates = [];
575
630
  if (states) {
@@ -618,11 +673,12 @@ export default abstract class Item implements IItem {
618
673
  animates: IAnimates,
619
674
  timing: AnimateTiming,
620
675
  targetStyleMap: Object,
676
+ shapeIdsToShow: string[] | undefined,
621
677
  callback: Function = () => {},
622
678
  ) {
623
679
  let targetStyle = {};
624
680
  if (!targetStyleMap) {
625
- Object.keys(this.shapeMap).forEach((shapeId) => {
681
+ shapeIdsToShow?.forEach((shapeId) => {
626
682
  targetStyle[shapeId] = getShapeAnimateBeginStyles(
627
683
  this.shapeMap[shapeId],
628
684
  );
@@ -634,7 +690,8 @@ export default abstract class Item implements IItem {
634
690
  animates,
635
691
  targetStyle, // targetStylesMap
636
692
  this.shapeMap, // shapeMap
637
- this.group,
693
+ shapeIdsToShow,
694
+ [this.group, this.labelGroup],
638
695
  timing,
639
696
  [],
640
697
  () => {},
@@ -707,13 +764,29 @@ export default abstract class Item implements IItem {
707
764
  // merge the states' styles into drawing style
708
765
  styles = mergeStyles([styles, mergedStateStyles]);
709
766
  });
767
+ const mergedData = mergeStyles([displayModelData, styles]);
768
+ const { animates } = mergedData;
769
+ const displayUpdateAnimates = [];
770
+ const stateNames = this.states.map((state) => state.name);
771
+ animates?.update?.forEach((animateCfg) => {
772
+ const { states } = animateCfg as IStateAnimate;
773
+ if (states && isArrayOverlap(states, stateNames)) {
774
+ displayUpdateAnimates.push(animateCfg);
775
+ }
776
+ });
710
777
 
711
778
  // apply the merged styles
712
779
  this.draw(
713
780
  // displayModel
714
781
  {
715
782
  ...this.displayModel,
716
- data: mergeStyles([displayModelData, styles]),
783
+ data: {
784
+ ...mergedData,
785
+ animates: {
786
+ ...animates,
787
+ update: displayUpdateAnimates,
788
+ },
789
+ },
717
790
  } as ItemDisplayModel,
718
791
  // diffData
719
792
  undefined,
@@ -780,15 +853,18 @@ export default abstract class Item implements IItem {
780
853
  /**
781
854
  * Stop all the animations on the item.
782
855
  */
783
- public stopAnimations() {
856
+ public stopAnimations(shapeIds?: string[]) {
784
857
  const promises = [];
785
858
  if (this.animations?.length) {
786
- while (this.animations.length) {
787
- const animate = this.animations.pop();
788
- if (animate.playState !== 'running') break;
789
- promises.push(stopAnimate(animate));
790
- // @ts-ignore
791
- animate.onManualCancel?.();
859
+ for (let i = 0; i < this.animations.length; i++) {
860
+ const animate = this.animations[i];
861
+ if (!shapeIds?.length || shapeIds.includes(animate.effect.target.id)) {
862
+ this.animations.pop();
863
+ if (animate.playState !== 'running') break;
864
+ promises.push(stopAnimate(animate));
865
+ // @ts-ignore
866
+ animate.onManualCancel?.();
867
+ }
792
868
  }
793
869
  }
794
870
  if (this.groupAnimations?.length) {
@@ -827,10 +903,16 @@ export default abstract class Item implements IItem {
827
903
  this.renderExt.onZoom(this.shapeMap, zoom, this.cacheHiddenByItem);
828
904
  }
829
905
 
906
+ /**
907
+ * Update label positions on label canvas by getting viewport position from transformed canvas position.
908
+ */
909
+ public updateLabelPosition(ignoreVisibility: boolean = false) {}
910
+
830
911
  /** Destroy the item. */
831
912
  public destroy() {
832
913
  const func = () => {
833
914
  this.group.destroy();
915
+ this.labelGroup.destroy();
834
916
  this.model = null;
835
917
  this.displayModel = null;
836
918
  this.destroyed = true;
@@ -843,6 +925,7 @@ export default abstract class Item implements IItem {
843
925
  animates,
844
926
  'buildOut',
845
927
  undefined,
928
+ undefined,
846
929
  func,
847
930
  );
848
931
  } else {
@@ -917,12 +1000,12 @@ const updateShapeChange = ({
917
1000
  });
918
1001
  Object.keys(mapper).forEach((shapeAttrName) => {
919
1002
  if (innerModelValue?.hasOwnProperty(shapeAttrName)) return;
920
- const { value: mappedValue } = updateChange({
1003
+ const { value: mappedValue, changed } = updateChange({
921
1004
  innerModel,
922
1005
  mapper,
923
1006
  fieldName: shapeAttrName,
924
1007
  dataChangedFields,
925
1008
  });
926
- shapeConfig[shapeAttrName] = mappedValue;
1009
+ if (changed) shapeConfig[shapeAttrName] = mappedValue;
927
1010
  });
928
1011
  };