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