@antv/g6 5.0.0-beta.1 → 5.0.0-beta.10

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 (409) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/esm/constant/shape.d.ts +4 -1
  3. package/esm/constant/shape.js.map +1 -1
  4. package/esm/index.d.ts +22 -7
  5. package/esm/index.js +3 -2
  6. package/esm/index.js.map +1 -1
  7. package/esm/item/combo.d.ts +1 -1
  8. package/esm/item/combo.js +16 -9
  9. package/esm/item/combo.js.map +1 -1
  10. package/esm/item/edge.d.ts +20 -3
  11. package/esm/item/edge.js +99 -43
  12. package/esm/item/edge.js.map +1 -1
  13. package/esm/item/item.d.ts +3 -2
  14. package/esm/item/item.js +21 -11
  15. package/esm/item/item.js.map +1 -1
  16. package/esm/item/node.d.ts +2 -1
  17. package/esm/item/node.js +33 -16
  18. package/esm/item/node.js.map +1 -1
  19. package/esm/runtime/controller/data.d.ts +7 -10
  20. package/esm/runtime/controller/data.js +125 -281
  21. package/esm/runtime/controller/data.js.map +1 -1
  22. package/esm/runtime/controller/item.d.ts +1 -0
  23. package/esm/runtime/controller/item.js +267 -151
  24. package/esm/runtime/controller/item.js.map +1 -1
  25. package/esm/runtime/graph.d.ts +103 -23
  26. package/esm/runtime/graph.js +460 -88
  27. package/esm/runtime/graph.js.map +1 -1
  28. package/esm/stdlib/behavior/activate-relations.d.ts +9 -9
  29. package/esm/stdlib/behavior/activate-relations.js +8 -8
  30. package/esm/stdlib/behavior/activate-relations.js.map +1 -1
  31. package/esm/stdlib/behavior/brush-select.js +1 -2
  32. package/esm/stdlib/behavior/brush-select.js.map +1 -1
  33. package/esm/stdlib/behavior/click-select.js +1 -1
  34. package/esm/stdlib/behavior/click-select.js.map +1 -1
  35. package/esm/stdlib/behavior/create-edge.d.ts +57 -0
  36. package/esm/stdlib/behavior/create-edge.js +207 -0
  37. package/esm/stdlib/behavior/create-edge.js.map +1 -0
  38. package/esm/stdlib/behavior/drag-canvas.d.ts +2 -1
  39. package/esm/stdlib/behavior/drag-canvas.js +59 -28
  40. package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
  41. package/esm/stdlib/behavior/drag-combo.d.ts +2 -2
  42. package/esm/stdlib/behavior/drag-combo.js +43 -32
  43. package/esm/stdlib/behavior/drag-combo.js.map +1 -1
  44. package/esm/stdlib/behavior/drag-node.d.ts +3 -3
  45. package/esm/stdlib/behavior/drag-node.js +76 -63
  46. package/esm/stdlib/behavior/drag-node.js.map +1 -1
  47. package/esm/stdlib/behavior/index.d.ts +3 -0
  48. package/esm/stdlib/behavior/index.js +3 -0
  49. package/esm/stdlib/behavior/index.js.map +1 -1
  50. package/esm/stdlib/behavior/lasso-select.d.ts +1 -1
  51. package/esm/stdlib/behavior/lasso-select.js +1 -2
  52. package/esm/stdlib/behavior/lasso-select.js.map +1 -1
  53. package/esm/stdlib/behavior/scroll-canvas.d.ts +67 -0
  54. package/esm/stdlib/behavior/scroll-canvas.js +266 -0
  55. package/esm/stdlib/behavior/scroll-canvas.js.map +1 -0
  56. package/esm/stdlib/behavior/shortcuts-call.d.ts +38 -0
  57. package/esm/stdlib/behavior/shortcuts-call.js +80 -0
  58. package/esm/stdlib/behavior/shortcuts-call.js.map +1 -0
  59. package/esm/stdlib/behavior/zoom-canvas.d.ts +2 -1
  60. package/esm/stdlib/behavior/zoom-canvas.js +55 -24
  61. package/esm/stdlib/behavior/zoom-canvas.js.map +1 -1
  62. package/esm/stdlib/data/mapNodeSize.d.ts +2 -2
  63. package/esm/stdlib/data/mapNodeSize.js +2 -2
  64. package/esm/stdlib/data/mapNodeSize.js.map +1 -1
  65. package/esm/stdlib/data/transformV4Data.d.ts +2 -2
  66. package/esm/stdlib/data/transformV4Data.js +2 -2
  67. package/esm/stdlib/data/transformV4Data.js.map +1 -1
  68. package/esm/stdlib/data/validateData.d.ts +2 -2
  69. package/esm/stdlib/data/validateData.js +9 -9
  70. package/esm/stdlib/data/validateData.js.map +1 -1
  71. package/esm/stdlib/index.d.ts +16 -6
  72. package/esm/stdlib/index.js +20 -10
  73. package/esm/stdlib/index.js.map +1 -1
  74. package/esm/stdlib/item/edge/base.d.ts +10 -1
  75. package/esm/stdlib/item/edge/base.js +20 -13
  76. package/esm/stdlib/item/edge/base.js.map +1 -1
  77. package/esm/stdlib/item/edge/line.js +5 -2
  78. package/esm/stdlib/item/edge/line.js.map +1 -1
  79. package/esm/stdlib/item/edge/polyline.d.ts +3 -2
  80. package/esm/stdlib/item/edge/polyline.js +3 -3
  81. package/esm/stdlib/item/edge/polyline.js.map +1 -1
  82. package/esm/stdlib/item/node/base.d.ts +1 -1
  83. package/esm/stdlib/item/node/base.js +18 -26
  84. package/esm/stdlib/item/node/base.js.map +1 -1
  85. package/esm/stdlib/item/node/base3d.d.ts +1 -0
  86. package/esm/stdlib/item/node/base3d.js +1 -0
  87. package/esm/stdlib/item/node/base3d.js.map +1 -1
  88. package/esm/stdlib/item/node/diamond.js +1 -1
  89. package/esm/stdlib/item/node/ellipse.js +2 -2
  90. package/esm/stdlib/item/node/hexagon.js +12 -5
  91. package/esm/stdlib/item/node/hexagon.js.map +1 -1
  92. package/esm/stdlib/item/node/image.d.ts +40 -0
  93. package/esm/stdlib/item/node/image.js +110 -0
  94. package/esm/stdlib/item/node/image.js.map +1 -0
  95. package/esm/stdlib/item/node/index.d.ts +1 -0
  96. package/esm/stdlib/item/node/index.js +1 -0
  97. package/esm/stdlib/item/node/index.js.map +1 -1
  98. package/esm/stdlib/plugin/history/combo-command.js +2 -2
  99. package/esm/stdlib/plugin/history/combo-command.js.map +1 -1
  100. package/esm/stdlib/plugin/history/index.d.ts +10 -10
  101. package/esm/stdlib/plugin/history/index.js +14 -14
  102. package/esm/stdlib/plugin/history/index.js.map +1 -1
  103. package/esm/stdlib/plugin/history/item-data-command.js +25 -16
  104. package/esm/stdlib/plugin/history/item-data-command.js.map +1 -1
  105. package/esm/stdlib/plugin/history/layer-updated-command.js +2 -2
  106. package/esm/stdlib/plugin/history/layer-updated-command.js.map +1 -1
  107. package/esm/stdlib/plugin/history/state-updated-command.js +1 -1
  108. package/esm/stdlib/plugin/history/state-updated-command.js.map +1 -1
  109. package/esm/stdlib/plugin/history/visibility-updated-command.js +2 -2
  110. package/esm/stdlib/plugin/history/visibility-updated-command.js.map +1 -1
  111. package/esm/stdlib/plugin/hull/hullComponent.d.ts +1 -1
  112. package/esm/stdlib/plugin/hull/hullComponent.js +3 -6
  113. package/esm/stdlib/plugin/hull/hullComponent.js.map +1 -1
  114. package/esm/stdlib/plugin/index.d.ts +2 -0
  115. package/esm/stdlib/plugin/index.js +2 -0
  116. package/esm/stdlib/plugin/index.js.map +1 -1
  117. package/esm/stdlib/plugin/legend/index.js +1 -1
  118. package/esm/stdlib/plugin/legend/index.js.map +1 -1
  119. package/esm/stdlib/plugin/map/index.d.ts +118 -0
  120. package/esm/stdlib/plugin/map/index.js +683 -0
  121. package/esm/stdlib/plugin/map/index.js.map +1 -0
  122. package/esm/stdlib/plugin/minimap/index.d.ts +5 -1
  123. package/esm/stdlib/plugin/minimap/index.js +116 -9
  124. package/esm/stdlib/plugin/minimap/index.js.map +1 -1
  125. package/esm/stdlib/plugin/snapline/index.d.ts +167 -0
  126. package/esm/stdlib/plugin/snapline/index.js +1063 -0
  127. package/esm/stdlib/plugin/snapline/index.js.map +1 -0
  128. package/esm/stdlib/plugin/timebar/index.d.ts +98 -0
  129. package/esm/stdlib/plugin/timebar/index.js +303 -0
  130. package/esm/stdlib/plugin/timebar/index.js.map +1 -0
  131. package/esm/stdlib/plugin/toolbar/index.js +1 -1
  132. package/esm/stdlib/plugin/toolbar/index.js.map +1 -1
  133. package/esm/stdlib/plugin/types.d.ts +2 -0
  134. package/esm/stdlib/theme/dark.js +42 -2
  135. package/esm/stdlib/theme/dark.js.map +1 -1
  136. package/esm/stdlib/theme/light.js +4 -4
  137. package/esm/types/common.d.ts +1 -0
  138. package/esm/types/event.d.ts +1 -0
  139. package/esm/types/graph.d.ts +48 -22
  140. package/esm/types/hook.d.ts +22 -2
  141. package/esm/types/item.d.ts +6 -0
  142. package/esm/types/item.js.map +1 -1
  143. package/esm/types/spec.d.ts +19 -3
  144. package/esm/types/view.d.ts +5 -0
  145. package/esm/util/bbox.d.ts +16 -1
  146. package/esm/util/bbox.js +29 -0
  147. package/esm/util/bbox.js.map +1 -1
  148. package/esm/util/canvas.d.ts +2 -2
  149. package/esm/util/canvas.js +5 -11
  150. package/esm/util/canvas.js.map +1 -1
  151. package/esm/util/event.d.ts +3 -1
  152. package/esm/util/event.js +8 -1
  153. package/esm/util/event.js.map +1 -1
  154. package/esm/util/item.d.ts +16 -1
  155. package/esm/util/item.js +31 -8
  156. package/esm/util/item.js.map +1 -1
  157. package/esm/util/layout.d.ts +11 -0
  158. package/esm/util/layout.js +45 -0
  159. package/esm/util/layout.js.map +1 -1
  160. package/esm/util/point.js +9 -2
  161. package/esm/util/point.js.map +1 -1
  162. package/esm/util/router.d.ts +4 -3
  163. package/esm/util/router.js +8 -5
  164. package/esm/util/router.js.map +1 -1
  165. package/esm/util/shape.d.ts +3 -3
  166. package/esm/util/shape.js +8 -12
  167. package/esm/util/shape.js.map +1 -1
  168. package/esm/util/warn.d.ts +14 -0
  169. package/esm/util/warn.js +4 -0
  170. package/esm/util/warn.js.map +1 -0
  171. package/lib/constant/shape.d.ts +4 -1
  172. package/lib/constant/shape.js.map +1 -1
  173. package/lib/index.d.ts +22 -7
  174. package/lib/index.js +4 -2
  175. package/lib/index.js.map +1 -1
  176. package/lib/item/combo.d.ts +1 -1
  177. package/lib/item/combo.js +16 -9
  178. package/lib/item/combo.js.map +1 -1
  179. package/lib/item/edge.d.ts +20 -3
  180. package/lib/item/edge.js +98 -42
  181. package/lib/item/edge.js.map +1 -1
  182. package/lib/item/item.d.ts +3 -2
  183. package/lib/item/item.js +21 -11
  184. package/lib/item/item.js.map +1 -1
  185. package/lib/item/node.d.ts +2 -1
  186. package/lib/item/node.js +33 -16
  187. package/lib/item/node.js.map +1 -1
  188. package/lib/runtime/controller/data.d.ts +7 -10
  189. package/lib/runtime/controller/data.js +125 -281
  190. package/lib/runtime/controller/data.js.map +1 -1
  191. package/lib/runtime/controller/item.d.ts +1 -0
  192. package/lib/runtime/controller/item.js +266 -150
  193. package/lib/runtime/controller/item.js.map +1 -1
  194. package/lib/runtime/graph.d.ts +103 -23
  195. package/lib/runtime/graph.js +460 -88
  196. package/lib/runtime/graph.js.map +1 -1
  197. package/lib/stdlib/behavior/activate-relations.d.ts +9 -9
  198. package/lib/stdlib/behavior/activate-relations.js +8 -8
  199. package/lib/stdlib/behavior/activate-relations.js.map +1 -1
  200. package/lib/stdlib/behavior/brush-select.js +1 -2
  201. package/lib/stdlib/behavior/brush-select.js.map +1 -1
  202. package/lib/stdlib/behavior/click-select.js +1 -1
  203. package/lib/stdlib/behavior/click-select.js.map +1 -1
  204. package/lib/stdlib/behavior/create-edge.d.ts +57 -0
  205. package/lib/stdlib/behavior/create-edge.js +211 -0
  206. package/lib/stdlib/behavior/create-edge.js.map +1 -0
  207. package/lib/stdlib/behavior/drag-canvas.d.ts +2 -1
  208. package/lib/stdlib/behavior/drag-canvas.js +59 -28
  209. package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
  210. package/lib/stdlib/behavior/drag-combo.d.ts +2 -2
  211. package/lib/stdlib/behavior/drag-combo.js +43 -32
  212. package/lib/stdlib/behavior/drag-combo.js.map +1 -1
  213. package/lib/stdlib/behavior/drag-node.d.ts +3 -3
  214. package/lib/stdlib/behavior/drag-node.js +76 -63
  215. package/lib/stdlib/behavior/drag-node.js.map +1 -1
  216. package/lib/stdlib/behavior/index.d.ts +3 -0
  217. package/lib/stdlib/behavior/index.js +3 -0
  218. package/lib/stdlib/behavior/index.js.map +1 -1
  219. package/lib/stdlib/behavior/lasso-select.d.ts +1 -1
  220. package/lib/stdlib/behavior/lasso-select.js +1 -2
  221. package/lib/stdlib/behavior/lasso-select.js.map +1 -1
  222. package/lib/stdlib/behavior/scroll-canvas.d.ts +67 -0
  223. package/lib/stdlib/behavior/scroll-canvas.js +270 -0
  224. package/lib/stdlib/behavior/scroll-canvas.js.map +1 -0
  225. package/lib/stdlib/behavior/shortcuts-call.d.ts +38 -0
  226. package/lib/stdlib/behavior/shortcuts-call.js +84 -0
  227. package/lib/stdlib/behavior/shortcuts-call.js.map +1 -0
  228. package/lib/stdlib/behavior/zoom-canvas.d.ts +2 -1
  229. package/lib/stdlib/behavior/zoom-canvas.js +55 -24
  230. package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
  231. package/lib/stdlib/data/mapNodeSize.d.ts +2 -2
  232. package/lib/stdlib/data/mapNodeSize.js +2 -2
  233. package/lib/stdlib/data/mapNodeSize.js.map +1 -1
  234. package/lib/stdlib/data/transformV4Data.d.ts +2 -2
  235. package/lib/stdlib/data/transformV4Data.js +2 -2
  236. package/lib/stdlib/data/transformV4Data.js.map +1 -1
  237. package/lib/stdlib/data/validateData.d.ts +2 -2
  238. package/lib/stdlib/data/validateData.js +9 -9
  239. package/lib/stdlib/data/validateData.js.map +1 -1
  240. package/lib/stdlib/index.d.ts +16 -6
  241. package/lib/stdlib/index.js +20 -10
  242. package/lib/stdlib/index.js.map +1 -1
  243. package/lib/stdlib/item/edge/base.d.ts +10 -1
  244. package/lib/stdlib/item/edge/base.js +20 -13
  245. package/lib/stdlib/item/edge/base.js.map +1 -1
  246. package/lib/stdlib/item/edge/line.js +5 -2
  247. package/lib/stdlib/item/edge/line.js.map +1 -1
  248. package/lib/stdlib/item/edge/polyline.d.ts +3 -2
  249. package/lib/stdlib/item/edge/polyline.js +3 -3
  250. package/lib/stdlib/item/edge/polyline.js.map +1 -1
  251. package/lib/stdlib/item/node/base.d.ts +1 -1
  252. package/lib/stdlib/item/node/base.js +18 -26
  253. package/lib/stdlib/item/node/base.js.map +1 -1
  254. package/lib/stdlib/item/node/base3d.d.ts +1 -0
  255. package/lib/stdlib/item/node/base3d.js +1 -0
  256. package/lib/stdlib/item/node/base3d.js.map +1 -1
  257. package/lib/stdlib/item/node/diamond.js +1 -1
  258. package/lib/stdlib/item/node/ellipse.js +2 -2
  259. package/lib/stdlib/item/node/hexagon.js +12 -5
  260. package/lib/stdlib/item/node/hexagon.js.map +1 -1
  261. package/lib/stdlib/item/node/image.d.ts +40 -0
  262. package/lib/stdlib/item/node/image.js +114 -0
  263. package/lib/stdlib/item/node/image.js.map +1 -0
  264. package/lib/stdlib/item/node/index.d.ts +1 -0
  265. package/lib/stdlib/item/node/index.js +1 -0
  266. package/lib/stdlib/item/node/index.js.map +1 -1
  267. package/lib/stdlib/plugin/history/combo-command.js +2 -2
  268. package/lib/stdlib/plugin/history/combo-command.js.map +1 -1
  269. package/lib/stdlib/plugin/history/index.d.ts +10 -10
  270. package/lib/stdlib/plugin/history/index.js +14 -14
  271. package/lib/stdlib/plugin/history/index.js.map +1 -1
  272. package/lib/stdlib/plugin/history/item-data-command.js +25 -16
  273. package/lib/stdlib/plugin/history/item-data-command.js.map +1 -1
  274. package/lib/stdlib/plugin/history/layer-updated-command.js +2 -2
  275. package/lib/stdlib/plugin/history/layer-updated-command.js.map +1 -1
  276. package/lib/stdlib/plugin/history/state-updated-command.js +1 -1
  277. package/lib/stdlib/plugin/history/state-updated-command.js.map +1 -1
  278. package/lib/stdlib/plugin/history/visibility-updated-command.js +2 -2
  279. package/lib/stdlib/plugin/history/visibility-updated-command.js.map +1 -1
  280. package/lib/stdlib/plugin/hull/hullComponent.d.ts +1 -1
  281. package/lib/stdlib/plugin/hull/hullComponent.js +3 -6
  282. package/lib/stdlib/plugin/hull/hullComponent.js.map +1 -1
  283. package/lib/stdlib/plugin/index.d.ts +2 -0
  284. package/lib/stdlib/plugin/index.js +2 -0
  285. package/lib/stdlib/plugin/index.js.map +1 -1
  286. package/lib/stdlib/plugin/legend/index.js +1 -1
  287. package/lib/stdlib/plugin/legend/index.js.map +1 -1
  288. package/lib/stdlib/plugin/map/index.d.ts +118 -0
  289. package/lib/stdlib/plugin/map/index.js +687 -0
  290. package/lib/stdlib/plugin/map/index.js.map +1 -0
  291. package/lib/stdlib/plugin/minimap/index.d.ts +5 -1
  292. package/lib/stdlib/plugin/minimap/index.js +116 -9
  293. package/lib/stdlib/plugin/minimap/index.js.map +1 -1
  294. package/lib/stdlib/plugin/snapline/index.d.ts +167 -0
  295. package/lib/stdlib/plugin/snapline/index.js +1067 -0
  296. package/lib/stdlib/plugin/snapline/index.js.map +1 -0
  297. package/lib/stdlib/plugin/timebar/index.d.ts +98 -0
  298. package/lib/stdlib/plugin/timebar/index.js +307 -0
  299. package/lib/stdlib/plugin/timebar/index.js.map +1 -0
  300. package/lib/stdlib/plugin/toolbar/index.js +1 -1
  301. package/lib/stdlib/plugin/toolbar/index.js.map +1 -1
  302. package/lib/stdlib/plugin/types.d.ts +2 -0
  303. package/lib/stdlib/theme/dark.js +42 -2
  304. package/lib/stdlib/theme/dark.js.map +1 -1
  305. package/lib/stdlib/theme/light.js +4 -4
  306. package/lib/types/common.d.ts +1 -0
  307. package/lib/types/event.d.ts +1 -0
  308. package/lib/types/graph.d.ts +48 -22
  309. package/lib/types/hook.d.ts +22 -2
  310. package/lib/types/item.d.ts +6 -0
  311. package/lib/types/item.js.map +1 -1
  312. package/lib/types/spec.d.ts +19 -3
  313. package/lib/types/view.d.ts +5 -0
  314. package/lib/util/bbox.d.ts +16 -1
  315. package/lib/util/bbox.js +32 -1
  316. package/lib/util/bbox.js.map +1 -1
  317. package/lib/util/canvas.d.ts +2 -2
  318. package/lib/util/canvas.js +5 -11
  319. package/lib/util/canvas.js.map +1 -1
  320. package/lib/util/event.d.ts +3 -1
  321. package/lib/util/event.js +8 -1
  322. package/lib/util/event.js.map +1 -1
  323. package/lib/util/item.d.ts +16 -1
  324. package/lib/util/item.js +33 -9
  325. package/lib/util/item.js.map +1 -1
  326. package/lib/util/layout.d.ts +11 -0
  327. package/lib/util/layout.js +47 -1
  328. package/lib/util/layout.js.map +1 -1
  329. package/lib/util/point.js +9 -2
  330. package/lib/util/point.js.map +1 -1
  331. package/lib/util/router.d.ts +4 -3
  332. package/lib/util/router.js +8 -5
  333. package/lib/util/router.js.map +1 -1
  334. package/lib/util/shape.d.ts +3 -3
  335. package/lib/util/shape.js +8 -12
  336. package/lib/util/shape.js.map +1 -1
  337. package/lib/util/warn.d.ts +14 -0
  338. package/lib/util/warn.js +8 -0
  339. package/lib/util/warn.js.map +1 -0
  340. package/package.json +10 -10
  341. package/src/constant/shape.ts +2 -1
  342. package/src/index.ts +4 -2
  343. package/src/item/combo.ts +14 -9
  344. package/src/item/edge.ts +131 -57
  345. package/src/item/item.ts +24 -15
  346. package/src/item/node.ts +38 -24
  347. package/src/runtime/controller/data.ts +140 -339
  348. package/src/runtime/controller/item.ts +236 -72
  349. package/src/runtime/graph.ts +592 -96
  350. package/src/stdlib/behavior/activate-relations.ts +8 -8
  351. package/src/stdlib/behavior/brush-select.ts +4 -2
  352. package/src/stdlib/behavior/click-select.ts +1 -1
  353. package/src/stdlib/behavior/create-edge.ts +296 -0
  354. package/src/stdlib/behavior/drag-canvas.ts +78 -29
  355. package/src/stdlib/behavior/drag-combo.ts +10 -10
  356. package/src/stdlib/behavior/drag-node.ts +18 -18
  357. package/src/stdlib/behavior/index.ts +3 -0
  358. package/src/stdlib/behavior/lasso-select.ts +5 -3
  359. package/src/stdlib/behavior/scroll-canvas.ts +348 -0
  360. package/src/stdlib/behavior/shortcuts-call.ts +120 -0
  361. package/src/stdlib/behavior/zoom-canvas.ts +72 -25
  362. package/src/stdlib/data/mapNodeSize.ts +2 -2
  363. package/src/stdlib/data/transformV4Data.ts +2 -2
  364. package/src/stdlib/data/validateData.ts +9 -9
  365. package/src/stdlib/index.ts +33 -9
  366. package/src/stdlib/item/edge/base.ts +26 -13
  367. package/src/stdlib/item/edge/line.ts +8 -2
  368. package/src/stdlib/item/edge/polyline.ts +7 -5
  369. package/src/stdlib/item/node/base.ts +24 -29
  370. package/src/stdlib/item/node/base3d.ts +1 -0
  371. package/src/stdlib/item/node/diamond.ts +1 -1
  372. package/src/stdlib/item/node/ellipse.ts +2 -2
  373. package/src/stdlib/item/node/hexagon.ts +14 -6
  374. package/src/stdlib/item/node/image.ts +190 -0
  375. package/src/stdlib/item/node/index.ts +1 -0
  376. package/src/stdlib/plugin/history/combo-command.ts +2 -2
  377. package/src/stdlib/plugin/history/index.ts +14 -14
  378. package/src/stdlib/plugin/history/item-data-command.ts +35 -17
  379. package/src/stdlib/plugin/history/layer-updated-command.ts +2 -2
  380. package/src/stdlib/plugin/history/state-updated-command.ts +1 -1
  381. package/src/stdlib/plugin/history/visibility-updated-command.ts +2 -2
  382. package/src/stdlib/plugin/hull/hullComponent.ts +8 -5
  383. package/src/stdlib/plugin/index.ts +2 -0
  384. package/src/stdlib/plugin/legend/index.ts +1 -1
  385. package/src/stdlib/plugin/map/index.ts +808 -0
  386. package/src/stdlib/plugin/minimap/index.ts +120 -10
  387. package/src/stdlib/plugin/snapline/index.ts +1297 -0
  388. package/src/stdlib/plugin/timebar/index.ts +473 -0
  389. package/src/stdlib/plugin/toolbar/index.ts +1 -1
  390. package/src/stdlib/plugin/types.ts +2 -0
  391. package/src/stdlib/theme/dark.ts +66 -2
  392. package/src/stdlib/theme/light.ts +4 -4
  393. package/src/types/common.ts +1 -0
  394. package/src/types/event.ts +1 -0
  395. package/src/types/graph.ts +59 -25
  396. package/src/types/hook.ts +22 -2
  397. package/src/types/item.ts +10 -0
  398. package/src/types/spec.ts +22 -3
  399. package/src/types/view.ts +8 -3
  400. package/src/util/bbox.ts +38 -1
  401. package/src/util/canvas.ts +5 -5
  402. package/src/util/event.ts +14 -1
  403. package/src/util/item.ts +65 -28
  404. package/src/util/layout.ts +45 -0
  405. package/src/util/point.ts +8 -3
  406. package/src/util/router.ts +15 -6
  407. package/src/util/shape.ts +16 -14
  408. package/src/util/warn.ts +20 -0
  409. package/src/api-doc/readme.md +0 -59
@@ -0,0 +1,808 @@
1
+ // TODO: update type define.
2
+ // @ts-nocheck
3
+ import { createDom, modifyCSS } from '@antv/dom-util';
4
+ import { Canvas, DisplayObject, Group, Rect } from '@antv/g';
5
+ import { debounce, each, isNil, isString, uniqueId } from '@antv/util';
6
+ import { IGraph } from '../../../types';
7
+ import { IG6GraphEvent } from '../../../types/event';
8
+ import { ShapeStyle } from '../../../types/item';
9
+ import { Plugin as Base, IPluginBaseConfig } from '../../../types/plugin';
10
+ import { createCanvas } from '../../../util/canvas';
11
+
12
+ const DEFAULT_MODE = 'default';
13
+ const KEYSHAPE_MODE = 'keyShape';
14
+ const DELEGATE_MODE = 'delegate';
15
+ const SVG = 'svg';
16
+
17
+ export interface MiniMapConfig extends IPluginBaseConfig {
18
+ /** Class name of viewport */
19
+ viewportClassName?: string;
20
+ /** Class name of minimap */
21
+ className?: string;
22
+ /** Mode of minimap */
23
+ mode?: 'default' | 'keyShape' | 'delegate';
24
+ /** Size of minimap */
25
+ size?: number[];
26
+ /** Style of delegate shape */
27
+ delegateStyle?: ShapeStyle;
28
+ /** Whether to refresh minimap */
29
+ refresh?: boolean;
30
+ /** Padding of minimap */
31
+ padding?: number;
32
+ /** Whether to hide edges on minimap to enhance performance */
33
+ hideEdge?: boolean;
34
+ /** Container for minimap */
35
+ container?: HTMLDivElement | null;
36
+ }
37
+
38
+ export class Minimap extends Base {
39
+ private canvas: Canvas;
40
+ /** The viewport DOM on the minimap. */
41
+ private viewport: HTMLElement | undefined;
42
+ /** Cache the mapping of graphics of nodes/edges/combos on main graph and minimap graph. */
43
+ private itemMap: Map<
44
+ ID,
45
+ {
46
+ minimapItem: DisplayObject;
47
+ graphItem: DisplayObject;
48
+ }
49
+ > = new Map();
50
+ private container: HTMLDivElement;
51
+ /** Ratio of (minimap graph size / main graph size). */
52
+ private ratio: number;
53
+ /** Distance from top of minimap graph to the top of minimap container. */
54
+ private dx: number;
55
+ /** Distance from left of minimap graph to the left of minimap container. */
56
+ private dy: number;
57
+ /** Cache the visibility while items' visibility changed. And apply them onto the minimap with debounce. */
58
+ private visibleCache: { [id: string]: boolean } = {};
59
+
60
+ constructor(options?: MiniMapConfig) {
61
+ super(options);
62
+ }
63
+
64
+ public getDefaultCfgs(): MiniMapConfig {
65
+ return {
66
+ key: `minimap-${uniqueId()}`,
67
+ container: null,
68
+ className: 'g6-minimap',
69
+ viewportClassName: 'g6-minimap-viewport',
70
+ // Minimap 中默认展示和主图一样的内容,KeyShape 只展示节点和边的 key shape 部分,delegate表示展示自定义的rect,用户可自定义样式
71
+ mode: 'default',
72
+ padding: 8,
73
+ size: [200, 120],
74
+ delegateStyle: {
75
+ fill: '#40a9ff',
76
+ stroke: '#096dd9',
77
+ },
78
+ refresh: true,
79
+ hideEdge: false,
80
+ };
81
+ }
82
+
83
+ public getEvents() {
84
+ return {
85
+ afteritemstatechange: this.handleUpdateCanvas,
86
+ afterlayout: this.handleUpdateCanvas,
87
+ viewportchange: this.handleUpdateCanvas,
88
+ afteritemchange: this.handleUpdateCanvas,
89
+ afteritemvisibilitychange: this.handleVisibilityChange,
90
+ };
91
+ }
92
+
93
+ /**
94
+ * If it is animating, disable refresh.
95
+ */
96
+ protected disableRefresh() {
97
+ this.options.refresh = false;
98
+ }
99
+
100
+ protected enableRefresh() {
101
+ this.options.refresh = true;
102
+ this.updateCanvas();
103
+ }
104
+
105
+ private initViewport() {
106
+ const { canvas, options, destroyed, graph } = this;
107
+ const { size, viewportClassName } = options;
108
+
109
+ if (destroyed) return;
110
+
111
+ const containerDOM = canvas.context.config.container as HTMLElement;
112
+ const isFireFox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
113
+ 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
+ />`);
126
+
127
+ // Last mouse x position
128
+ let x = 0;
129
+ // Last mouse y position
130
+ let y = 0;
131
+ // Whether in dragging status
132
+ let dragging = false;
133
+ let resizing = false;
134
+
135
+ const dragstartevent = isSafari || isFireFox ? 'mousedown' : 'dragstart';
136
+ this.container.addEventListener('mousemove', (e) => {
137
+ const moveAtBorder = getMoveAtBorder(viewport, e);
138
+ if (moveAtBorder) {
139
+ this.container.style.cursor = cursorMap[moveAtBorder];
140
+ viewport.style.cursor = cursorMap[moveAtBorder];
141
+ } else {
142
+ this.container.style.cursor = 'unset';
143
+ viewport.style.cursor = 'move';
144
+ }
145
+ });
146
+ viewport.addEventListener(
147
+ dragstartevent,
148
+ ((e: IG6GraphEvent) => {
149
+ resizing = getMoveAtBorder(viewport, e);
150
+ if (resizing) return;
151
+
152
+ if ((e as any).dataTransfer) {
153
+ const img = new Image();
154
+ img.src =
155
+ "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' %3E%3Cpath /%3E%3C/svg%3E";
156
+ (e as any).dataTransfer.setDragImage?.(img, 0, 0);
157
+ try {
158
+ (e as any).dataTransfer.setData('text/html', 'view-port-minimap');
159
+ } catch {
160
+ // support IE
161
+ (e as any).dataTransfer.setData('text', 'view-port-minimap');
162
+ }
163
+ }
164
+
165
+ this.options.refresh = false;
166
+ if (e.target !== viewport) {
167
+ return;
168
+ }
169
+
170
+ dragging = true;
171
+ x = e.clientX;
172
+ y = e.clientY;
173
+ }).bind(this),
174
+ false,
175
+ );
176
+
177
+ const dragListener = (e: IG6GraphEvent) => {
178
+ const { style } = viewport;
179
+ const left = parseInt(style.left, 10);
180
+ const top = parseInt(style.top, 10);
181
+ const width = parseInt(style.width, 10);
182
+ const height = parseInt(style.height, 10);
183
+
184
+ if (resizing) {
185
+ const { clientX, clientY } = e;
186
+ const afterResize = { left, top, width, height };
187
+ if (resizing.includes('left')) {
188
+ afterResize.left = `${clientX}px`;
189
+ afterResize.width = `${left + width - clientX}px`;
190
+ } else if (resizing.includes('right')) {
191
+ afterResize.width = `${clientX - left}px`;
192
+ }
193
+ if (resizing.includes('top')) {
194
+ afterResize.top = `${clientY}`;
195
+ afterResize.height = `${top + height - clientY}`;
196
+ } else if (resizing.includes('bottom')) {
197
+ afterResize.height = `${clientY - top}`;
198
+ }
199
+ modifyCSS(viewport, afterResize);
200
+ return;
201
+ }
202
+ if (!dragging || isNil(e.clientX) || isNil(e.clientY)) {
203
+ return;
204
+ }
205
+ const { ratio } = this;
206
+ const zoom = graph!.getZoom();
207
+
208
+ let dx = x - e.clientX;
209
+ let dy = y - e.clientY;
210
+
211
+ // If the viewport is already on the left or right, stop moving x.
212
+ if (left - dx < 0 || left - dx + width >= size[0]) {
213
+ dx = 0;
214
+ }
215
+ // If the viewport is already on the top or bottom, stop moving y.
216
+ if (top - dy < 0 || top - dy + height >= size[1]) {
217
+ dy = 0;
218
+ }
219
+
220
+ // Translate tht graph and update minimap viewport.
221
+ graph!
222
+ .translate({
223
+ dx: (dx * zoom) / ratio,
224
+ dy: (dy * zoom) / ratio,
225
+ })
226
+ .then(() => {
227
+ this.updateViewport();
228
+ });
229
+ x = e.clientX;
230
+ y = e.clientY;
231
+ };
232
+ if (!isSafari && !isFireFox) {
233
+ viewport.addEventListener('drag', dragListener.bind(this), false);
234
+ }
235
+
236
+ const dragendListener = () => {
237
+ dragging = false;
238
+ resizing = false;
239
+ this.options.refresh = true;
240
+ };
241
+ const dragendevent = isSafari || isFireFox ? 'mouseup' : 'dragend';
242
+ viewport.addEventListener(dragendevent, dragendListener.bind(this), false);
243
+
244
+ const zoomListener = (evt) => {
245
+ // TODO: zoom the graph and update viewport
246
+ };
247
+ viewport.addEventListener('wheel', zoomListener, false);
248
+
249
+ containerDOM.addEventListener('mouseleave', dragendListener.bind(this));
250
+ containerDOM.addEventListener('mouseup', dragendListener.bind(this));
251
+
252
+ if (isSafari || isFireFox) {
253
+ containerDOM.addEventListener(
254
+ 'mousemove',
255
+ dragListener.bind(this),
256
+ false,
257
+ );
258
+ }
259
+
260
+ this.viewport = viewport;
261
+ containerDOM.appendChild(viewport);
262
+ }
263
+
264
+ /**
265
+ * Update the viewport DOM.
266
+ */
267
+ private updateViewport() {
268
+ if (this.destroyed) return;
269
+ if (!this.viewport) {
270
+ this.initViewport();
271
+ }
272
+ const { options, graph, dx, dy, ratio, viewport } = this;
273
+
274
+ const { size } = options;
275
+ const graphCanvasEl = graph.canvas.context.config.canvas;
276
+ const [
277
+ graphWidth = graphCanvasEl?.scrollWidth || 500,
278
+ graphHeight = graphCanvasEl?.scrollHeight || 500,
279
+ ] = graph.getSize();
280
+
281
+ const graphZoom = graph.getZoom();
282
+ const graphBBox = graph.canvas.getRoot().getRenderBounds();
283
+
284
+ const graphTopLeftViewport = graph.getViewportByCanvas({
285
+ x: graphBBox.min[0],
286
+ y: graphBBox.min[1],
287
+ });
288
+ const graphBottomRightViewport = graph.getViewportByCanvas({
289
+ x: graphBBox.max[0],
290
+ y: graphBBox.max[1],
291
+ });
292
+
293
+ // Width and height of the viewport DOM
294
+ let width = (graphWidth * ratio) / graphZoom;
295
+ let height = (graphHeight * ratio) / graphZoom;
296
+
297
+ let left = 0;
298
+ let top = 0;
299
+ if (graphTopLeftViewport.x < 0) {
300
+ left = (-graphTopLeftViewport.x / graphWidth) * width + dx;
301
+ if (graphBottomRightViewport.x < graphWidth) {
302
+ width = size[0] - left;
303
+ }
304
+ } else {
305
+ width -= (graphTopLeftViewport.x / graphWidth) * width - dx;
306
+ }
307
+ if (graphTopLeftViewport.y < 0) {
308
+ top = (-graphTopLeftViewport.y / graphHeight) * height + dy;
309
+ if (graphBottomRightViewport.y < graphHeight) {
310
+ height = size[1] - top;
311
+ }
312
+ } else {
313
+ height -= (graphTopLeftViewport.y / graphHeight) * height - dy;
314
+ }
315
+
316
+ const right = width + left;
317
+ if (right > size[0]) {
318
+ width -= right - size[0];
319
+ }
320
+ const bottom = height + top;
321
+ if (bottom > size[1]) {
322
+ height -= bottom - size[1];
323
+ }
324
+
325
+ modifyCSS(viewport, {
326
+ left: `${left}px`,
327
+ top: `${top}px`,
328
+ width: `${width}px`,
329
+ height: `${height}px`,
330
+ });
331
+ }
332
+
333
+ /**
334
+ * Clone all the graphic from main graph to the minimap graph.
335
+ */
336
+ private updateGraphShapes() {
337
+ const { graph, options, canvas } = this;
338
+ const graphGroup = graph.canvas.getRoot();
339
+ if (graphGroup.destroyed) return;
340
+ canvas.removeChildren();
341
+ let clonedGroup;
342
+ const { hideEdge } = options;
343
+ if (hideEdge) {
344
+ clonedGroup = new Group();
345
+ canvas.appendChild(clonedGroup);
346
+ graphGroup.children.forEach((group) => {
347
+ if (group.id === 'edge-group') return;
348
+ clonedGroup.appendChild(group.cloneNode(true));
349
+ });
350
+ } else {
351
+ clonedGroup = graphGroup.cloneNode(true);
352
+ canvas.appendChild(clonedGroup);
353
+ }
354
+ }
355
+
356
+ /**
357
+ * Only draw keyShapes on the minimap.
358
+ */
359
+ private updateKeyShapes() {
360
+ const { graph, options, canvas } = this;
361
+ const { hideEdge } = options;
362
+
363
+ const group = canvas.getRoot();
364
+
365
+ if (!hideEdge) {
366
+ each(graph!.getAllEdgesData(), (edge) => {
367
+ this.updateOneEdgeKeyShape(edge, group);
368
+ });
369
+ }
370
+ each(graph!.getAllNodesData(), (node) => {
371
+ this.updateOneNodeKeyShape(node, group);
372
+ });
373
+ const combos = graph!.getAllCombosData();
374
+ if (combos && combos.length) {
375
+ let comboGroup = group.find((e) => e.id === 'combo-group');
376
+ if (!comboGroup) {
377
+ comboGroup = new Group({ id: 'combo-group' });
378
+ group.appendChild(comboGroup);
379
+ }
380
+ setTimeout(() => {
381
+ if (this.destroyed) return;
382
+ each(combos, (combo) => {
383
+ // this.updateOneComboKeyShape(combo, comboGroup);
384
+ this.updateOneNodeKeyShape(combo, comboGroup);
385
+ });
386
+ comboGroup?.sort();
387
+ comboGroup?.toBack();
388
+ this.updateCanvas();
389
+ }, 250);
390
+ }
391
+ this.clearDestroyedShapes();
392
+ }
393
+
394
+ /**
395
+ * Add or update keyShape of one node.
396
+ * @param nodeModel node data model
397
+ * @param group container graphics group on minimap
398
+ */
399
+ private updateOneNodeKeyShape(nodeModel, group) {
400
+ const { itemMap = new Map(), graph } = this;
401
+ const graphNodeGroup = graph.canvas
402
+ .getRoot()
403
+ .find((ele) => ele.id === 'node-group');
404
+ if (!graphNodeGroup) return;
405
+
406
+ let { minimapItem, graphItem } = itemMap.get(nodeModel.id) || {};
407
+ if (!minimapItem || minimapItem.destroyed) {
408
+ graphItem = graphNodeGroup
409
+ .find((ele) => ele.getAttribute('data-item-id') === nodeModel.id)
410
+ ?.find((ele) => ele.id === 'keyShape');
411
+ minimapItem = graphItem.cloneNode();
412
+ minimapItem.id = `minimap-keyShape-${nodeModel.id}`;
413
+ group.appendChild(minimapItem);
414
+ itemMap.set(nodeModel.id, { graphItem, minimapItem });
415
+ }
416
+ const bbox = graphItem.getRenderBounds();
417
+ if (!bbox) return;
418
+ const keyShapeStyle = graphItem.attributes;
419
+ const attrs: any = {
420
+ ...keyShapeStyle,
421
+ cx: bbox.center[0],
422
+ cy: bbox.center[1],
423
+ };
424
+ minimapItem.toFront();
425
+
426
+ const shapeType = minimapItem.get('type');
427
+ if (shapeType === 'rect' || shapeType === 'image' || shapeType === 'text') {
428
+ attrs.x = bbox.min[0];
429
+ attrs.y = bbox.min[1];
430
+ }
431
+ Object.keys(attrs).forEach((key) => {
432
+ minimapItem.style[key] = attrs[key];
433
+ });
434
+
435
+ if (!graph.getItemVisible(nodeModel.id)) minimapItem.hide();
436
+ else minimapItem.show();
437
+ const zIndex = nodeModel.data.depth;
438
+ if (!isNaN(zIndex)) minimapItem.set('zIndex', zIndex);
439
+ this.itemMap = itemMap;
440
+ }
441
+
442
+ /**
443
+ * Draw the delegate rects for nodes and line edges on minimap.
444
+ */
445
+ private updateDelegateShapes() {
446
+ const { graph, options, canvas } = this;
447
+ const { hideEdge } = options;
448
+
449
+ const group = canvas.getRoot();
450
+
451
+ // If hideEdge is true, do not render the edges on minimap to enhance the performance
452
+ if (!hideEdge) {
453
+ each(graph!.getAllEdgesData(), (edge) => {
454
+ this.updateOneEdgeKeyShape(edge, group);
455
+ });
456
+ }
457
+ each(graph!.getAllNodesData(), (node) => {
458
+ this.updateOneNodeDelegateShape(node, group);
459
+ });
460
+ const combos = graph!.getAllCombosData();
461
+ if (combos && combos.length) {
462
+ const comboGroup =
463
+ group.find((e) => e.get('name') === 'comboGroup') ||
464
+ group.addGroup({
465
+ name: 'comboGroup',
466
+ });
467
+ setTimeout(() => {
468
+ if (this.destroyed) return;
469
+ each(combos, (combo) => {
470
+ // this.updateOneComboKeyShape(combo, comboGroup);
471
+ this.updateOneNodeKeyShape(combo, comboGroup);
472
+ });
473
+ comboGroup?.sort();
474
+ comboGroup?.toBack();
475
+ this.updateCanvas();
476
+ }, 250);
477
+ }
478
+ this.clearDestroyedShapes();
479
+ }
480
+
481
+ private clearDestroyedShapes() {
482
+ const { itemMap = new Map() } = this;
483
+ itemMap.forEach((val, key) => {
484
+ const { minimapItem, graphItem } = val || {};
485
+ if (graphItem.destroyed && minimapItem) {
486
+ minimapItem.remove();
487
+ itemMap.delete(key);
488
+ }
489
+ });
490
+ }
491
+
492
+ /**
493
+ * Add or update keyShape of one edge.
494
+ * @param edgeModel edge data model
495
+ * @param group container graphics group on minimap
496
+ */
497
+ private updateOneEdgeKeyShape(edgeModel, group) {
498
+ const { itemMap = new Map(), graph } = this;
499
+ const graphEdgeGroup = graph.canvas
500
+ .getRoot()
501
+ .find((ele) => ele.id === 'edge-group');
502
+ if (!graphEdgeGroup) return;
503
+ let { minimapItem, graphItem } = itemMap.get(edgeModel.id) || {};
504
+ if (minimapItem && !minimapItem.destroyed) {
505
+ const { path, x1, x2, y1, y2 } = graphItem.style;
506
+ minimapItem.style.path = path;
507
+ minimapItem.style.x1 = x1;
508
+ minimapItem.style.x2 = x2;
509
+ minimapItem.style.y1 = y1;
510
+ minimapItem.style.y2 = y2;
511
+ } else {
512
+ graphItem = graphEdgeGroup
513
+ .find((ele) => ele.getAttribute('data-item-id') === edgeModel.id)
514
+ ?.find((ele) => ele.id === 'keyShape');
515
+ minimapItem = graphItem.cloneNode();
516
+ minimapItem.id = `minimap-keyShape-${edgeModel.id}`;
517
+ group.appendChild(minimapItem);
518
+ }
519
+ if (!graph.getItemVisible(edgeModel.id)) minimapItem.hide();
520
+ else minimapItem.show();
521
+ itemMap.set(edgeModel.id, { graphItem, minimapItem });
522
+ this.itemMap = itemMap;
523
+ }
524
+
525
+ /**
526
+ * Add or update delegate rect of one node.
527
+ * @param nodeModel node data model
528
+ * @param group container graphics group on minimap
529
+ */
530
+ private updateOneNodeDelegateShape(nodeModel, group) {
531
+ const { itemMap = new Map(), options, graph } = this;
532
+ const { delegateStyle } = options;
533
+
534
+ const graphNodeGroup = graph.canvas
535
+ .getRoot()
536
+ .find((ele) => ele.id === 'node-group');
537
+ if (!graphNodeGroup) return;
538
+
539
+ // 差量更新 minimap 上的一个节点,对应主图的 item
540
+ let { minimapItem, graphItem } = itemMap.get(nodeModel.id) || {};
541
+ if (!graphItem) {
542
+ graphItem = graphNodeGroup
543
+ .find((ele) => ele.getAttribute('data-item-id') === nodeModel.id)
544
+ ?.find((ele) => ele.id === 'keyShape');
545
+ }
546
+
547
+ const bbox = graphItem.getRenderBounds();
548
+ const attrs = {
549
+ x: bbox.min[0],
550
+ y: bbox.min[1],
551
+ width: bbox.max[0] - bbox.min[0],
552
+ height: bbox.max[1] - bbox.min[1],
553
+ ...delegateStyle,
554
+ };
555
+ if (!minimapItem || minimapItem.destroyed) {
556
+ minimapItem = new Rect({
557
+ style: {
558
+ ...graphItem.attributes,
559
+ ...attrs,
560
+ ...delegateStyle,
561
+ },
562
+ id: `minimap-delegate-${nodeModel.id}`,
563
+ });
564
+ group.appendChild(minimapItem);
565
+ } else {
566
+ Object.keys(attrs).forEach(
567
+ (key) => (minimapItem.style[key] = attrs[key]),
568
+ );
569
+ }
570
+ minimapItem.toFront();
571
+
572
+ if (!graph.getItemVisible(nodeModel.id)) minimapItem.hide();
573
+ else minimapItem.show();
574
+ itemMap.set(nodeModel.id, { graphItem, minimapItem });
575
+ this.itemMap = itemMap;
576
+ }
577
+
578
+ /**
579
+ * Listener for main graph updating, update the viewport DOM.
580
+ */
581
+ private handleUpdateCanvas = debounce(
582
+ (event) => {
583
+ const self = this;
584
+ if (self.destroyed) return;
585
+ self.updateCanvas();
586
+ },
587
+ 100,
588
+ false,
589
+ );
590
+
591
+ private handleVisibilityChange = (params) => {
592
+ const { ids, value } = params;
593
+ ids.forEach((id) => {
594
+ this.visibleCache[id] = value;
595
+ });
596
+ this.debounceCloneVisibility();
597
+ };
598
+
599
+ private debounceCloneVisibility = debounce(
600
+ () => {
601
+ const nodeGroup = this.canvas.getRoot().getElementById('node-group');
602
+ const edgeGroup = this.canvas.getRoot().getElementById('edge-group');
603
+ (nodeGroup?.childNodes || [])
604
+ .concat(edgeGroup?.childNodes || [])
605
+ .forEach((child) => {
606
+ const id = child.getAttribute?.('data-item-id');
607
+ if (this.visibleCache.hasOwnProperty(id)) {
608
+ if (this.visibleCache[id]) {
609
+ child.childNodes.forEach((shape) => shape.show());
610
+ } else if (this.visibleCache[id] === false) {
611
+ child.childNodes.forEach((shape) => shape.hide());
612
+ }
613
+ }
614
+ });
615
+ this.visibleCache = {};
616
+ },
617
+ 50,
618
+ false,
619
+ );
620
+
621
+ public init(graph: IGraph) {
622
+ super.init(graph);
623
+ const promise = this.initContainer();
624
+ promise.then(() => this.updateCanvas());
625
+ }
626
+
627
+ /**
628
+ * Init the DOM container for minimap.
629
+ */
630
+ public initContainer() {
631
+ const { graph, options } = this;
632
+ const { size, className } = options;
633
+ let parentNode = options.container;
634
+ const container: HTMLDivElement = createDom(
635
+ `<div class='${className}' style='width: ${size[0]}px; height: ${size[1]}px; overflow: hidden;'></div>`,
636
+ );
637
+
638
+ if (isString(parentNode)) {
639
+ parentNode = document.getElementById(parentNode) as HTMLDivElement;
640
+ }
641
+
642
+ if (parentNode) {
643
+ parentNode.appendChild(container);
644
+ } else {
645
+ graph.container.appendChild(container);
646
+ }
647
+
648
+ if (this.container) {
649
+ this.container.remove();
650
+ this.viewport?.remove();
651
+ this.viewport = undefined;
652
+ this.canvas?.destroy();
653
+ }
654
+ this.container = container;
655
+
656
+ const containerDOM = createDom(
657
+ '<div class="g6-minimap-container" style="position: relative;"></div>',
658
+ );
659
+ container.appendChild(containerDOM);
660
+ containerDOM.addEventListener('dragenter', (e) => {
661
+ e.preventDefault();
662
+ });
663
+ containerDOM.addEventListener('dragover', (e) => {
664
+ e.preventDefault();
665
+ });
666
+
667
+ // TODO: graph.rendererType
668
+ const graphCanvas = graph.canvas;
669
+ this.canvas = createCanvas(
670
+ 'canvas',
671
+ containerDOM,
672
+ size[0],
673
+ size[1],
674
+ graphCanvas.devicePixelRatio,
675
+ );
676
+
677
+ return this.canvas.ready;
678
+ }
679
+
680
+ public updateCanvas() {
681
+ if (this.destroyed) return;
682
+ const { graph, canvas, options } = this;
683
+ const { refresh, size, padding, mode } = options;
684
+ // Controlled by the animation of graph. Animating, and then disable refreshing
685
+ if (!refresh || graph.destroyed || canvas.destroyed) return;
686
+
687
+ switch (mode) {
688
+ case DEFAULT_MODE:
689
+ this.updateGraphShapes();
690
+ break;
691
+ case KEYSHAPE_MODE:
692
+ this.updateKeyShapes();
693
+ break;
694
+ case DELEGATE_MODE:
695
+ this.updateDelegateShapes();
696
+ break;
697
+ default:
698
+ break;
699
+ }
700
+
701
+ const group = canvas.getRoot();
702
+ if (!group) return;
703
+
704
+ const minimapBBox = group.getRenderBounds();
705
+ const graphBBox = graph.canvas.getRoot().getRenderBounds();
706
+ const width = graphBBox.max[0] - graphBBox.min[0];
707
+ const height = graphBBox.max[1] - graphBBox.min[1];
708
+
709
+ // Scale the graph to fit the size - padding of the minimap container
710
+ const zoomRatio = Math.min(
711
+ (size[0] - 2 * padding) / width,
712
+ (size[1] - 2 * padding) / height,
713
+ );
714
+ const zoomCenter = canvas.viewport2Canvas({ x: 0, y: 0 });
715
+ canvas.getCamera().setFocalPoint(zoomCenter.x, zoomCenter.y);
716
+ canvas.getCamera().setPosition(zoomCenter.x, zoomCenter.y);
717
+ canvas.getCamera().setZoom(zoomRatio);
718
+ canvas
719
+ .getCamera()
720
+ .setPosition(minimapBBox.center[0], minimapBBox.center[1]);
721
+ canvas
722
+ .getCamera()
723
+ .setFocalPoint(minimapBBox.center[0], minimapBBox.center[1]);
724
+
725
+ const { x: dx, y: dy } = canvas.canvas2Viewport({
726
+ x: minimapBBox.min[0],
727
+ y: minimapBBox.min[1],
728
+ });
729
+
730
+ // Update the viewport DOM
731
+ this.ratio = zoomRatio;
732
+ this.dx = dx;
733
+ this.dy = dy;
734
+ this.updateViewport();
735
+ }
736
+
737
+ /**
738
+ * Get the canvas of the minimap.
739
+ * @return {Canvas} G Canvas
740
+ */
741
+ public getCanvas(): Canvas {
742
+ return this.canvas;
743
+ }
744
+
745
+ /**
746
+ * Get the viewport DOM of the minimap.
747
+ * @return {HTMLElement} viewport DOM
748
+ */
749
+ public getViewport(): HTMLElement {
750
+ return this.viewport;
751
+ }
752
+
753
+ /**
754
+ * Get the container DOM of the minimap.
755
+ * @return {HTMLElement} container DOM
756
+ */
757
+ public getContainer(): HTMLElement {
758
+ return this.container;
759
+ }
760
+
761
+ public destroy() {
762
+ super.destroy();
763
+ this.canvas?.destroy();
764
+ const container = this.container;
765
+ if (container?.parentNode) container.parentNode.removeChild(container);
766
+ }
767
+ }
768
+
769
+ const getMoveAtBorder = (dom, evt) => {
770
+ const bounds = dom.getBoundingClientRect();
771
+ const { clientX, clientY } = evt;
772
+ if (Math.abs(clientX - bounds.x) < 4 && Math.abs(clientY - bounds.y) < 4) {
773
+ return 'left-top';
774
+ } else if (
775
+ Math.abs(clientX - bounds.x) < 4 &&
776
+ Math.abs(clientY - bounds.y - bounds.height) < 4
777
+ ) {
778
+ return 'left-bottom';
779
+ } else if (
780
+ Math.abs(clientX - bounds.x - bounds.width) < 4 &&
781
+ Math.abs(clientY - bounds.y) < 4
782
+ ) {
783
+ return 'right-top';
784
+ } else if (
785
+ Math.abs(clientX - bounds.x - bounds.width) < 4 &&
786
+ Math.abs(clientY - bounds.y - bounds.height) < 4
787
+ ) {
788
+ return 'right-bottom';
789
+ } else if (Math.abs(clientX - bounds.x) < 4) {
790
+ return 'left';
791
+ } else if (Math.abs(clientY - bounds.y) < 4) {
792
+ return 'top';
793
+ } else if (Math.abs(clientY - bounds.y - bounds.height) < 4) {
794
+ return 'bottom';
795
+ }
796
+ return false;
797
+ };
798
+
799
+ const cursorMap = {
800
+ 'left-top': 'nwse-resize',
801
+ 'right-bottom': 'nwse-resize',
802
+ 'right-top': 'nesw-resize',
803
+ 'left-bottom': 'nesw-resize',
804
+ left: 'ew-resize',
805
+ right: 'ew-resize',
806
+ top: 'ns-resize',
807
+ bottom: 'ns-resize',
808
+ };