@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
@@ -0,0 +1,602 @@
1
+ import { debounce, uniqueId, throttle, isArray } from '@antv/util';
2
+ import { AABB } from '@antv/g';
3
+ import {
4
+ ComboDisplayModel,
5
+ ComboModel,
6
+ EdgeDisplayModel,
7
+ EdgeModel,
8
+ ID,
9
+ IGraph,
10
+ NodeDisplayModel,
11
+ NodeModel,
12
+ } from '../../../types';
13
+ import { Plugin as Base, IPluginBaseConfig } from '../../../types/plugin';
14
+ import { intersectBBox } from '../../../util/shape';
15
+ import { getZoomLevel } from '../../../util/zoom';
16
+ import { GraphTransformOptions } from '../../../types/view';
17
+
18
+ /**
19
+ * This is an interface named `LodControllerConfig`, which extends the `IPluginBaseConfig` interface. It contains the following properties:
20
+ * cellSize
21
+ * numberPerCell
22
+ */
23
+ export interface LodControllerConfig extends IPluginBaseConfig {
24
+ cellSize?: number;
25
+ numberPerCell?: number;
26
+ disableLod?: boolean;
27
+ debounce?: number | 'auto';
28
+ }
29
+
30
+ export class LodController extends Base {
31
+ static required: boolean = true;
32
+ private shownIds = new Map();
33
+ private cacheViewModels: {
34
+ inView: (NodeModel | EdgeModel | ComboModel)[];
35
+ outView: (NodeModel | EdgeModel | ComboModel)[];
36
+ newlyOutView: (NodeModel | EdgeModel | ComboModel)[];
37
+ newlyInView: (NodeModel | EdgeModel | ComboModel)[];
38
+ };
39
+ private displayModelCache: Map<
40
+ ID,
41
+ NodeDisplayModel | EdgeDisplayModel | ComboDisplayModel
42
+ > = new Map();
43
+ private renderBoundsCache: Map<ID, AABB | false> = new Map();
44
+ private canvasCellDirty: boolean = true;
45
+ private canvasCellSize = 100;
46
+ private modelCanvasIdxMap: Map<ID, { rowIdx: number; colIdx: number }>;
47
+ private labelPositionDirty: Map<ID, boolean> = new Map();
48
+ private debounce = 16;
49
+ private animationUpdateTimer: number = 0;
50
+
51
+ constructor(options?: LodControllerConfig) {
52
+ super(options);
53
+ }
54
+
55
+ public getDefaultCfgs(): LodControllerConfig {
56
+ return {
57
+ key: `lodController-${uniqueId()}`,
58
+ cellSize: 200,
59
+ numberPerCell: 1,
60
+ disableLod: false,
61
+ disableAnimate: true,
62
+ debounce: 'auto',
63
+ };
64
+ }
65
+
66
+ public init(graph: IGraph) {
67
+ super.init(graph);
68
+ }
69
+
70
+ public getEvents() {
71
+ if (this.graph.rendererType === 'webgl-3d') return {};
72
+ return {
73
+ afterrender: this.onAfterRender,
74
+ afterlayout: this.onAfterLayout,
75
+ aftersetsize: this.updateCells,
76
+ viewportchange: this.updateCells,
77
+ afteritemchange: this.updateCacheModels,
78
+ beforeviewportanimation: this.beforeViewportAnimation,
79
+ afterviewportanimation: this.afterViewportAnimation,
80
+ cancelviewportanimation: this.afterViewportAnimation,
81
+ };
82
+ }
83
+
84
+ protected onAfterRender = () => {
85
+ // show the shapes with lod when diableLod is true
86
+ const { graph, options } = this;
87
+
88
+ this.clearCache();
89
+
90
+ this.debounce = 80;
91
+ if (options.debounce === undefined || options.debounce === 'auto') {
92
+ const nodes = graph.getAllNodesData();
93
+ this.debounce = Math.min(Math.floor(nodes.length / 100), 80);
94
+ }
95
+ this.debounceUpdateVisible = this.getDebounceFn(
96
+ this.updateVisible.bind(this),
97
+ );
98
+ };
99
+
100
+ protected onAfterLayout = () => {
101
+ this.canvasCellDirty = true;
102
+ this.updateLabelPositions(1);
103
+ this.updateCells();
104
+ };
105
+ /**
106
+ * Update grid.
107
+ * @param param
108
+ */
109
+ protected updateCells = (params?: GraphTransformOptions) => {
110
+ if (!this.graph.canvasReady) return;
111
+ const { zoom } = params || {};
112
+ if (params) {
113
+ this.updateLabelPositions(zoom?.ratio);
114
+ }
115
+ // @ts-ignore
116
+ if (!this.options.disableLod) this.debounceUpdateVisible(zoom?.ratio);
117
+ };
118
+
119
+ private getDebounceFn = (fn) => {
120
+ return debounce(fn, this.debounce, false);
121
+ };
122
+
123
+ private updateVisible = (zoomRatio = 1) => {
124
+ const { graph, cacheViewModels, options } = this;
125
+ const { cellSize, numberPerCell, disableAnimate, disableLod } = options;
126
+ const graphZoom = graph.getZoom();
127
+ const { inView } = cacheViewModels || this.groupItemsByView(1);
128
+
129
+ const cells = new Map<string, ID[]>();
130
+ const candidateShapeMap = new Map<
131
+ ID,
132
+ {
133
+ lodVisibleShapeIds: string[];
134
+ autoVisibleShapeIds: string[];
135
+ invisibleShapeIds: string[];
136
+ }
137
+ >();
138
+ const lodVisibleIds = [];
139
+ const lodInvisibleIds = new Map<ID, string[]>();
140
+ inView.forEach((model) => {
141
+ const displayModel = this.getDisplayModel(model.id);
142
+ const { lodLevels, x, y, z, ...others } = displayModel.data;
143
+ const lodLevelsEmpty = isEmptyObj(lodLevels);
144
+ const currentZoomLevel = lodLevelsEmpty
145
+ ? 0
146
+ : getZoomLevel(lodLevels as any, graphZoom);
147
+ const autoVisibleShapeIds = [];
148
+ const lodVisibleShapeIds = [];
149
+ const invisibleShapeIds = [];
150
+ Object.keys(others).forEach((shapeId) => {
151
+ if (shapeId === 'keyShape') return;
152
+ const val = others[shapeId] as any;
153
+ if (
154
+ !val ||
155
+ typeof val !== 'object' ||
156
+ !Object.keys(val).length ||
157
+ isArray(val)
158
+ ) {
159
+ return;
160
+ }
161
+ const { lod, visible } = val;
162
+ if (visible === false) return;
163
+ if (lodLevelsEmpty || lod === 'auto') {
164
+ autoVisibleShapeIds.push(shapeId);
165
+ } else if (lod <= currentZoomLevel) {
166
+ lodVisibleShapeIds.push(shapeId);
167
+ } else {
168
+ invisibleShapeIds.push(shapeId);
169
+ }
170
+ });
171
+
172
+ if (!lodVisibleShapeIds.length && !autoVisibleShapeIds.length) {
173
+ lodInvisibleIds.set(model.id, invisibleShapeIds);
174
+ return;
175
+ }
176
+
177
+ const bounds = this.getRenderBBox(model.id);
178
+ if (!bounds || !graph.getItemVisible(model.id)) {
179
+ lodInvisibleIds.set(model.id, invisibleShapeIds);
180
+ return;
181
+ }
182
+
183
+ if (!autoVisibleShapeIds.length) {
184
+ lodVisibleIds.push(model.id);
185
+ }
186
+
187
+ const { center } = bounds;
188
+ const param = graphZoom / cellSize;
189
+ // rowIdx = (center[i] * graphZoom + offset[i]) - offset[i] / cellSize = center[i] * param
190
+ const rowIdx = Math.floor((center[0] || x) * param);
191
+ const colIdx = Math.floor((center[1] || y) * param);
192
+ const cellIdx = `${rowIdx}-${colIdx}`;
193
+ const cellNodeIds = cells.get(cellIdx) || [];
194
+ cellNodeIds.push(model.id);
195
+ cells.set(cellIdx, cellNodeIds);
196
+ candidateShapeMap.set(model.id, {
197
+ lodVisibleShapeIds,
198
+ autoVisibleShapeIds,
199
+ invisibleShapeIds,
200
+ });
201
+ });
202
+ const shownIds = new Map();
203
+ cells.forEach((cell) => {
204
+ // priority: lod Visible > shown last time > rest auto
205
+ cell.sort((a, b) => {
206
+ const { lodVisibleShapeIds: aLodVisibleShapeIds } =
207
+ candidateShapeMap.get(a);
208
+ const { lodVisibleShapeIds: bLodVisibleShapeIds } =
209
+ candidateShapeMap.get(b);
210
+ if (lodVisibleIds.includes(b) && bLodVisibleShapeIds.length) return 1;
211
+ if (lodVisibleIds.includes(a) && aLodVisibleShapeIds.length) return -1;
212
+ const bShownLastTime = this.shownIds.has(b) && !lodInvisibleIds.has(b);
213
+ if (bShownLastTime) return 1;
214
+ const aShownLastTime = this.shownIds.has(a) && !lodInvisibleIds.has(a);
215
+ if (aShownLastTime) return -1;
216
+ return 0;
217
+ });
218
+ let rest = numberPerCell;
219
+ cell.forEach((id) => {
220
+ const { lodVisibleShapeIds, autoVisibleShapeIds, invisibleShapeIds } =
221
+ candidateShapeMap.get(id);
222
+
223
+ if (!disableLod && invisibleShapeIds.length) {
224
+ graph.hideItem(id, { shapeIds: invisibleShapeIds, disableAnimate });
225
+ }
226
+ const item = graph.itemController.itemMap.get(id);
227
+ if (
228
+ disableLod ||
229
+ (item.labelGroup.children.length &&
230
+ (rest > 0 || (zoomRatio >= 1 && this.shownIds.has(id))))
231
+ ) {
232
+ const shapeIdsToShow = lodVisibleShapeIds.concat(autoVisibleShapeIds);
233
+ if (shapeIdsToShow.length) {
234
+ graph.showItem(id, {
235
+ shapeIds: lodVisibleShapeIds.concat(autoVisibleShapeIds),
236
+ disableAnimate,
237
+ });
238
+ }
239
+ if (this.labelPositionDirty.has(id)) {
240
+ item.updateLabelPosition(disableLod);
241
+ this.labelPositionDirty.delete(id);
242
+ }
243
+ shownIds.set(id, 1);
244
+ rest--;
245
+ } else {
246
+ if (
247
+ lodVisibleShapeIds.includes('labelShape') &&
248
+ this.labelPositionDirty.has(id)
249
+ ) {
250
+ item.updateLabelPosition(disableLod);
251
+ this.labelPositionDirty.delete(id);
252
+ }
253
+ lodVisibleShapeIds.length &&
254
+ graph.showItem(id, {
255
+ shapeIds: lodVisibleShapeIds,
256
+ disableAnimate,
257
+ });
258
+ if (!disableLod && autoVisibleShapeIds.length) {
259
+ graph.hideItem(id, {
260
+ shapeIds: autoVisibleShapeIds,
261
+ disableAnimate,
262
+ });
263
+ }
264
+ }
265
+ });
266
+ });
267
+ if (!disableLod) {
268
+ lodInvisibleIds.forEach((shapeIds, id) => {
269
+ shapeIds.length && graph.hideItem(id, { shapeIds, disableAnimate });
270
+ });
271
+ }
272
+ this.shownIds = shownIds;
273
+ };
274
+
275
+ private debounceUpdateVisible = this.getDebounceFn(
276
+ this.updateVisible.bind(this),
277
+ );
278
+
279
+ private updateLabelPositions = throttle(
280
+ (zoomRatio) => {
281
+ const { graph, options } = this;
282
+ const { inView, newlyOutView, newlyInView } =
283
+ this.groupItemsByView(zoomRatio);
284
+ const graphZoom = graph.getZoom();
285
+ const levelCache = {};
286
+ this.labelPositionDirty.clear();
287
+
288
+ // 1. inside current view &&
289
+ // 2. lod is number and matches the current zoom ratio
290
+ // 3. lod is 'auto' and filtered by cells)
291
+ // 1 && (2 || 3)
292
+ inView.forEach((model) => {
293
+ this.labelPositionDirty.set(model.id, true);
294
+ const item = graph.itemController.itemMap.get(model.id);
295
+ if (
296
+ !item ||
297
+ !item.labelGroup.children.length ||
298
+ !item.shapeMap.labelShape ||
299
+ (!options.disableLod &&
300
+ (item.labelGroup.style.visibility === 'hidden' ||
301
+ item.shapeMap.labelShape.style.visibility === 'hidden'))
302
+ ) {
303
+ return;
304
+ }
305
+ const displayModel = this.getDisplayModel(model.id);
306
+ const { labelShape, lodLevels } = displayModel.data;
307
+ if (!labelShape) return;
308
+ const updatePosition = () => {
309
+ // adjust labels'positions for visible items
310
+ item.updateLabelPosition(options.disableLod);
311
+ this.labelPositionDirty.delete(model.id);
312
+ };
313
+ const { visible, lod } = labelShape;
314
+ if (visible === false) return;
315
+ if (lod === undefined) {
316
+ updatePosition();
317
+ return;
318
+ }
319
+ if (lod === 'auto') {
320
+ updatePosition();
321
+ return;
322
+ }
323
+ if (typeof lod !== 'number' || item.animations?.length) {
324
+ // lod is 'auto' / lod is not defined / during animating
325
+ updatePosition();
326
+ return;
327
+ }
328
+ const lodLevelsEmpty = isEmptyObj(lodLevels);
329
+ if (lodLevelsEmpty) {
330
+ updatePosition();
331
+ return;
332
+ }
333
+ const levelsKey = JSON.stringify(lodLevels);
334
+ const currentZoomLevel =
335
+ levelCache[levelsKey] || lodLevelsEmpty
336
+ ? 0
337
+ : getZoomLevel(lodLevels as any, graphZoom);
338
+ levelCache[levelsKey] = currentZoomLevel;
339
+ if (lod <= currentZoomLevel) {
340
+ // lod visible
341
+ updatePosition();
342
+ }
343
+ });
344
+ newlyOutView.forEach((model) => {
345
+ graph.hideItem(model.id, {
346
+ shapeIds: ['labelShape', 'labelBackgroundShape'],
347
+ disableAnimate: true,
348
+ });
349
+ });
350
+ if (options.disableLod) {
351
+ newlyInView.forEach((model) => {
352
+ graph.showItem(model.id, {
353
+ shapeIds: ['labelShape', 'labelBackgroundShape'],
354
+ disableAnimate: true,
355
+ });
356
+ });
357
+ }
358
+ },
359
+ 16,
360
+ {
361
+ leading: true,
362
+ trailing: true,
363
+ },
364
+ );
365
+
366
+ /**
367
+ * get the items inside viewport
368
+ * @returns
369
+ */
370
+ private groupItemsByView = (ratio: number = 1) => {
371
+ const { graph } = this;
372
+ const range = graph.getCanvasRange();
373
+ const models = graph.getAllNodesData().concat(graph.getAllEdgesData());
374
+ let { inView, outView } = this.cacheViewModels || {};
375
+ if (this.canvasCellDirty) this.updateCanvasCells();
376
+ const canvasCellRowRange = [
377
+ Math.floor(range.min[0] / this.canvasCellSize),
378
+ Math.ceil(range.max[0] / this.canvasCellSize),
379
+ ];
380
+ const canvasCellColRange = [
381
+ Math.floor(range.min[1] / this.canvasCellSize),
382
+ Math.ceil(range.max[1] / this.canvasCellSize),
383
+ ];
384
+ const atBoundary = (rowIdx, colIdx) => {
385
+ if (
386
+ rowIdx > canvasCellRowRange[0] &&
387
+ rowIdx < canvasCellRowRange[1] &&
388
+ (Math.abs(colIdx - canvasCellColRange[0]) < 2 ||
389
+ Math.abs(colIdx - canvasCellColRange[1]) < 2)
390
+ ) {
391
+ return true;
392
+ } else if (
393
+ colIdx > canvasCellColRange[0] &&
394
+ colIdx < canvasCellColRange[1] &&
395
+ (Math.abs(rowIdx - canvasCellRowRange[0]) < 2 ||
396
+ Math.abs(rowIdx - canvasCellRowRange[1]) < 2)
397
+ ) {
398
+ return true;
399
+ }
400
+ return false;
401
+ };
402
+ const outBoundary = (rowIdx, colIdx) => {
403
+ return (
404
+ rowIdx <= canvasCellRowRange[0] ||
405
+ rowIdx >= canvasCellRowRange[1] ||
406
+ colIdx <= canvasCellColRange[0] ||
407
+ colIdx >= canvasCellColRange[1]
408
+ );
409
+ };
410
+ const newlyOutView = [];
411
+ const newlyInView = [];
412
+ const cacheIsEmpty =
413
+ !this.cacheViewModels || (!inView.length && !outView.length);
414
+ if (!ratio || ratio === 1 || cacheIsEmpty) {
415
+ const previousOutView = new Map();
416
+ const previousInView = new Map();
417
+ outView?.forEach((model) => previousOutView.set(model.id, true));
418
+ inView?.forEach((model) => previousInView.set(model.id, true));
419
+ inView = [];
420
+ outView = [];
421
+ models.forEach((model) => {
422
+ if (!this.modelCanvasIdxMap.get(model.id)) {
423
+ outView.push(model);
424
+ if (!previousOutView.has(model.id)) newlyOutView.push(model);
425
+ return;
426
+ }
427
+ const { rowIdx, colIdx } = this.modelCanvasIdxMap.get(model.id);
428
+ if (atBoundary(rowIdx, colIdx)) {
429
+ const renderBounds = this.getRenderBBox(model.id);
430
+ if (!renderBounds) return;
431
+ if (intersectBBox(renderBounds, range)) {
432
+ inView.push(model);
433
+ if (!previousInView.has(model.id)) newlyInView.push(model);
434
+ } else {
435
+ outView.push(model);
436
+ if (!previousOutView.has(model.id)) newlyOutView.push(model);
437
+ }
438
+ } else if (outBoundary(rowIdx, colIdx)) {
439
+ outView.push(model);
440
+ if (!previousOutView.has(model.id)) newlyOutView.push(model);
441
+ } else {
442
+ inView.push(model);
443
+ if (!previousInView.has(model.id)) newlyInView.push(model);
444
+ }
445
+ });
446
+ } else if (ratio < 1) {
447
+ // zoom-out
448
+ const outViewNew = [];
449
+ outView.forEach((model) => {
450
+ if (!this.modelCanvasIdxMap.get(model.id)) {
451
+ outViewNew.push(model);
452
+ return;
453
+ }
454
+ const { rowIdx, colIdx } = this.modelCanvasIdxMap.get(model.id);
455
+ if (atBoundary(rowIdx, colIdx)) {
456
+ const renderBounds = this.getRenderBBox(model.id);
457
+ if (!renderBounds) return;
458
+ if (intersectBBox(renderBounds, range)) {
459
+ inView.push(model);
460
+ newlyInView.push(model);
461
+ } else {
462
+ outViewNew.push(model);
463
+ }
464
+ } else if (outBoundary(rowIdx, colIdx)) {
465
+ outViewNew.push(model);
466
+ } else {
467
+ inView.push(model);
468
+ newlyInView.push(model);
469
+ }
470
+ });
471
+ outView = outViewNew;
472
+ } else if (ratio > 1) {
473
+ // zoom-in
474
+ const inViewNew = [];
475
+ inView.forEach((model) => {
476
+ if (!this.modelCanvasIdxMap.get(model.id)) {
477
+ outView.push(model);
478
+ newlyOutView.push(model);
479
+ return;
480
+ }
481
+ const { rowIdx, colIdx } = this.modelCanvasIdxMap.get(model.id);
482
+ if (atBoundary(rowIdx, colIdx)) {
483
+ const renderBounds = this.getRenderBBox(model.id);
484
+ if (!renderBounds) return;
485
+ if (!intersectBBox(renderBounds, range)) {
486
+ outView.push(model);
487
+ newlyOutView.push(model);
488
+ } else {
489
+ inViewNew.push(model);
490
+ }
491
+ } else if (outBoundary(rowIdx, colIdx)) {
492
+ outView.push(model);
493
+ newlyOutView.push(model);
494
+ } else {
495
+ inViewNew.push(model);
496
+ }
497
+ });
498
+ inView = inViewNew;
499
+ }
500
+ this.cacheViewModels = { inView, outView, newlyOutView, newlyInView };
501
+ return this.cacheViewModels;
502
+ };
503
+
504
+ private updateCanvasCells = () => {
505
+ const canvasCells = new Map();
506
+ const idxMap = new Map();
507
+ const { graph, canvasCellSize } = this;
508
+ graph.getAllNodesData().forEach((model) => {
509
+ const { x, y } = model.data;
510
+ const rowIdx = Math.floor(x / canvasCellSize);
511
+ const colIdx = Math.floor(y / canvasCellSize);
512
+ const cellIdx = `${rowIdx}-${colIdx}`;
513
+ const cell = canvasCells.get(cellIdx) || [];
514
+ cell.push(model.id);
515
+ canvasCells.set(cellIdx, cell);
516
+ idxMap.set(model.id, { rowIdx, colIdx });
517
+ });
518
+ graph.getAllEdgesData().forEach((model) => {
519
+ const { source, target } = model;
520
+ const { rowIdx: sourceRowIdx, colIdx: sourceColIdx } = idxMap.get(source);
521
+ const { rowIdx: targetRowIdx, colIdx: targetColIdx } = idxMap.get(target);
522
+ const centerRowIdx = Math.round((sourceRowIdx + targetRowIdx) / 2);
523
+ const centerColIdx = Math.round((sourceColIdx + targetColIdx) / 2);
524
+ const cellIdx = `${centerRowIdx}-${centerColIdx}`;
525
+ const cell = canvasCells.get(cellIdx) || [];
526
+ cell.push(model.id);
527
+ canvasCells.set(cellIdx, cell);
528
+ idxMap.set(model.id, { rowIdx: centerRowIdx, colIdx: centerColIdx });
529
+ });
530
+ this.modelCanvasIdxMap = idxMap;
531
+ this.canvasCellDirty = false;
532
+ };
533
+
534
+ protected updateCacheModels = (params) => {
535
+ const { models, action } = params;
536
+ this.canvasCellDirty = true;
537
+ models?.forEach((model) => {
538
+ this.renderBoundsCache.delete(model.id);
539
+ if (action !== 'updatePosition') {
540
+ this.displayModelCache.delete(model.id);
541
+ }
542
+ if (this.options.disableLod) {
543
+ this.graph.showItem(model.id, {
544
+ shapeIds: ['labelShape', 'labelBackgroundShape'],
545
+ disableAnimate: true,
546
+ });
547
+ }
548
+ });
549
+ };
550
+
551
+ protected beforeViewportAnimation = () => {
552
+ if (this.animationUpdateTimer) return;
553
+ this.animationUpdateTimer = setInterval(() => {
554
+ this.updateLabelPositions();
555
+ }, 16);
556
+ };
557
+
558
+ protected afterViewportAnimation = () => {
559
+ if (this.animationUpdateTimer) {
560
+ clearInterval(this.animationUpdateTimer);
561
+ this.animationUpdateTimer = 0;
562
+ }
563
+ };
564
+
565
+ protected clearCache = () => {
566
+ this.displayModelCache.clear();
567
+ this.renderBoundsCache.clear();
568
+ this.cacheViewModels = {
569
+ inView: [],
570
+ outView: [],
571
+ newlyOutView: [],
572
+ newlyInView: [],
573
+ };
574
+ };
575
+ private getDisplayModel = (id) => {
576
+ let displayModel = this.displayModelCache.get(id);
577
+ if (!displayModel) {
578
+ displayModel = this.graph.getDisplayModel(id);
579
+ this.displayModelCache.set(id, displayModel);
580
+ }
581
+ return displayModel;
582
+ };
583
+ private getRenderBBox = (id) => {
584
+ let renderBounds;
585
+ if (!this.renderBoundsCache.has(id)) {
586
+ renderBounds = this.graph.getRenderBBox(id, true);
587
+ this.renderBoundsCache.set(id, renderBounds);
588
+ } else {
589
+ renderBounds = this.renderBoundsCache.get(id);
590
+ }
591
+ return renderBounds;
592
+ };
593
+
594
+ public destroy() {
595
+ super.destroy();
596
+ }
597
+ }
598
+
599
+ const isEmptyObj = (obj) => {
600
+ if (!obj) return true;
601
+ return !Object.keys(obj).length;
602
+ };
@@ -143,7 +143,7 @@ export class Menu extends Base {
143
143
 
144
144
  protected async onMenuShow(e: IG6GraphEvent) {
145
145
  const self = this;
146
- e.preventDefault();
146
+ e.preventDefault?.();
147
147
  self.onMenuHide();
148
148
  const itemTypes = this.options.itemTypes;
149
149
  if (!e.itemId) {
@@ -12,7 +12,6 @@ import { createDOM, modifyCSS } from '../../../util/dom';
12
12
  const DEFAULT_MODE = 'default';
13
13
  const KEYSHAPE_MODE = 'keyShape';
14
14
  const DELEGATE_MODE = 'delegate';
15
- const SVG = 'svg';
16
15
 
17
16
  export interface MiniMapConfig extends IPluginBaseConfig {
18
17
  /** Class name of viewport */
@@ -111,18 +110,17 @@ export class Minimap extends Base {
111
110
  const containerDOM = canvas.context.config.container as HTMLElement;
112
111
  const isFireFox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
113
112
  const isSafari = navigator.userAgent.toLowerCase().indexOf('safari') > -1;
114
- const viewport = createDOM(`
115
- <div
116
- class=${viewportClassName}
117
- style='position:absolute;
118
- left:0;
119
- top:0;
120
- border: 2px solid #1980ff;
121
- box-sizing:border-box;
122
- background: rgba(0, 0, 255, 0.1);
123
- cursor:move'
124
- draggable=${isSafari || isFireFox ? false : true}
125
- />`);
113
+ const viewport = createDOM(`<div
114
+ class=${viewportClassName}
115
+ style='position:absolute;
116
+ left:0;
117
+ top:0;
118
+ border: 2px solid #1980ff;
119
+ box-sizing:border-box;
120
+ background: rgba(0, 0, 255, 0.1);
121
+ cursor:move'
122
+ draggable=${isSafari || isFireFox ? false : true}
123
+ />`);
126
124
 
127
125
  // Last mouse x position
128
126
  let x = 0;
@@ -653,7 +651,7 @@ export class Minimap extends Base {
653
651
  }
654
652
  this.container = container;
655
653
 
656
- const containerDOM = createDom(
654
+ const containerDOM = createDOM(
657
655
  '<div class="g6-minimap-container" style="position: relative;"></div>',
658
656
  );
659
657
  container.appendChild(containerDOM);