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