@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,1067 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Snapline = void 0;
4
+ const util_1 = require("@antv/util");
5
+ const plugin_1 = require("../../../types/plugin");
6
+ class Snapline extends plugin_1.Plugin {
7
+ setTolerance(tolerance) {
8
+ this.tolerance = tolerance;
9
+ }
10
+ getTolerance() {
11
+ return this.tolerance;
12
+ }
13
+ /**
14
+ * getDrawLineId via DrawLine
15
+ * Principle: the lines on the drawing board is the only load-point
16
+ * @param dl drawLine
17
+ */
18
+ getDrawLineIdByDrawLine(dl) {
19
+ if (!dl)
20
+ return;
21
+ return `${dl.line[0].x}-${dl.line[0].y}-${dl.line[1].x}-${dl.line[1].y}`;
22
+ }
23
+ /**
24
+ *
25
+ * @param cp based on constractBBox's point
26
+ * @param dp based on draggingBBox point
27
+ * @returns
28
+ */
29
+ getDrawLineIdByPoints([cp, dp]) {
30
+ return `${cp.x}-${cp.y}-${dp.x}-${dp.y}`;
31
+ }
32
+ /**
33
+ * all AlignLines satisfy conditions: in the tolerance range
34
+ */
35
+ addAlignLinesForChoose() {
36
+ function isInToleranceRange(xOrY, contrast, tolerance) {
37
+ return xOrY >= contrast - tolerance && xOrY <= contrast + tolerance;
38
+ }
39
+ this.vContrastPoints.forEach((vpoint) => {
40
+ if (isInToleranceRange(this.draggingBBox.min[0], vpoint.x, this.tolerance))
41
+ this.alignLinesForChoose.v.push({
42
+ dl: {
43
+ line: [vpoint, { x: vpoint.x, y: this.draggingBBox.center[1] }],
44
+ lp: 'left',
45
+ },
46
+ offset: { x: vpoint.x - this.draggingBBox.min[0], y: 0 },
47
+ });
48
+ if (isInToleranceRange(this.draggingBBox.center[0], vpoint.x, this.tolerance))
49
+ this.alignLinesForChoose.v.push({
50
+ dl: {
51
+ line: [vpoint, { x: vpoint.x, y: this.draggingBBox.center[1] }],
52
+ lp: 'vcenter',
53
+ },
54
+ offset: { x: vpoint.x - this.draggingBBox.center[0], y: 0 },
55
+ });
56
+ if (isInToleranceRange(this.draggingBBox.max[0], vpoint.x, this.tolerance))
57
+ this.alignLinesForChoose.v.push({
58
+ dl: {
59
+ line: [vpoint, { x: vpoint.x, y: this.draggingBBox.center[1] }],
60
+ lp: 'right',
61
+ },
62
+ offset: { x: vpoint.x - this.draggingBBox.max[0], y: 0 },
63
+ });
64
+ });
65
+ this.hContrastPoints.forEach((hpoint) => {
66
+ if (isInToleranceRange(this.draggingBBox.min[1], hpoint.y, this.tolerance))
67
+ this.alignLinesForChoose.v.push({
68
+ dl: {
69
+ line: [hpoint, { x: this.draggingBBox.min[0], y: hpoint.y }],
70
+ lp: 'top',
71
+ },
72
+ offset: { x: 0, y: hpoint.y - this.draggingBBox.min[1] },
73
+ });
74
+ if (isInToleranceRange(this.draggingBBox.center[1], hpoint.y, this.tolerance))
75
+ this.alignLinesForChoose.v.push({
76
+ dl: {
77
+ line: [hpoint, { x: this.draggingBBox.center[0], y: hpoint.y }],
78
+ lp: 'hcenter',
79
+ },
80
+ offset: { x: 0, y: hpoint.y - this.draggingBBox.center[1] },
81
+ });
82
+ if (isInToleranceRange(this.draggingBBox.max[1], hpoint.y, this.tolerance))
83
+ this.alignLinesForChoose.v.push({
84
+ dl: {
85
+ line: [hpoint, { x: this.draggingBBox.max[0], y: hpoint.y }],
86
+ lp: 'bottom',
87
+ },
88
+ offset: { x: 0, y: hpoint.y - this.draggingBBox.max[1] },
89
+ });
90
+ });
91
+ }
92
+ initAlignLinesForChoose() {
93
+ this.alignLinesForChoose.v = [];
94
+ this.alignLinesForChoose.h = [];
95
+ let allIds = [];
96
+ this.graph.getAllCombosData().forEach((item) => {
97
+ allIds.push(item.id);
98
+ });
99
+ this.graph.getAllNodesData().forEach((item) => {
100
+ allIds.push(item.id);
101
+ });
102
+ allIds = allIds.filter((item) => item !== this.dragItemId); // 排除drag item
103
+ allIds.forEach((id) => {
104
+ const cb = this.graph.getRenderBBox(id, true); // contrast bbox
105
+ // 判断2个方向,6条线的对比
106
+ /* draggingBBox left */
107
+ if (Math.abs(this.draggingBBox.min[0] - cb.min[0]) <= this.tolerance) {
108
+ this.alignLinesForChoose.v.push({
109
+ dl: {
110
+ line: [
111
+ { x: cb.min[0], y: cb.center[1] },
112
+ { x: cb.min[0], y: this.draggingBBox.center[1] },
113
+ ],
114
+ lp: 'left',
115
+ },
116
+ offset: {
117
+ x: this.draggingBBox.min[0] - cb.min[0],
118
+ y: this.draggingBBox.center[1] - cb.center[1],
119
+ },
120
+ });
121
+ }
122
+ if (Math.abs(this.draggingBBox.min[0] - cb.center[0]) <= this.tolerance) {
123
+ this.alignLinesForChoose.v.push({
124
+ dl: {
125
+ line: [
126
+ { x: cb.center[0], y: cb.center[1] },
127
+ { x: cb.center[0], y: this.draggingBBox.center[1] },
128
+ ],
129
+ lp: 'left',
130
+ },
131
+ offset: {
132
+ x: this.draggingBBox.min[0] - cb.center[0],
133
+ y: this.draggingBBox.center[1] - cb.center[1],
134
+ },
135
+ });
136
+ }
137
+ if (Math.abs(this.draggingBBox.min[0] - cb.max[0]) <= this.tolerance) {
138
+ this.alignLinesForChoose.v.push({
139
+ dl: {
140
+ line: [
141
+ { x: cb.max[0], y: cb.center[1] },
142
+ { x: cb.max[0], y: this.draggingBBox.center[1] },
143
+ ],
144
+ lp: 'left',
145
+ },
146
+ offset: {
147
+ x: this.draggingBBox.min[0] - cb.max[0],
148
+ y: this.draggingBBox.center[1] - cb.center[1],
149
+ },
150
+ });
151
+ }
152
+ /* draggingBBox vcenter */
153
+ if (Math.abs(this.draggingBBox.center[0] - cb.min[0]) <= this.tolerance) {
154
+ this.alignLinesForChoose.v.push({
155
+ dl: {
156
+ line: [
157
+ { x: cb.min[0], y: cb.center[1] },
158
+ { x: cb.min[0], y: this.draggingBBox.center[1] },
159
+ ],
160
+ lp: 'vcenter',
161
+ },
162
+ offset: {
163
+ x: this.draggingBBox.center[0] - cb.min[0],
164
+ y: this.draggingBBox.center[1] - cb.center[1],
165
+ },
166
+ });
167
+ }
168
+ if (Math.abs(this.draggingBBox.center[0] - cb.center[0]) <= this.tolerance) {
169
+ this.alignLinesForChoose.v.push({
170
+ dl: {
171
+ line: [
172
+ { x: cb.center[0], y: cb.center[1] },
173
+ { x: cb.center[0], y: this.draggingBBox.center[1] },
174
+ ],
175
+ lp: 'vcenter',
176
+ },
177
+ offset: {
178
+ x: this.draggingBBox.center[0] - cb.center[0],
179
+ y: this.draggingBBox.center[1] - cb.center[1],
180
+ },
181
+ });
182
+ }
183
+ if (Math.abs(this.draggingBBox.center[0] - cb.max[0]) <= this.tolerance) {
184
+ this.alignLinesForChoose.v.push({
185
+ dl: {
186
+ line: [
187
+ { x: cb.max[0], y: cb.center[1] },
188
+ { x: cb.max[0], y: this.draggingBBox.center[1] },
189
+ ],
190
+ lp: 'vcenter',
191
+ },
192
+ offset: {
193
+ x: this.draggingBBox.center[0] - cb.max[0],
194
+ y: this.draggingBBox.center[1] - cb.center[1],
195
+ },
196
+ });
197
+ }
198
+ /* draggingBBox right */
199
+ if (Math.abs(this.draggingBBox.max[0] - cb.min[0]) <= this.tolerance) {
200
+ this.alignLinesForChoose.v.push({
201
+ dl: {
202
+ line: [
203
+ { x: cb.min[0], y: cb.center[1] },
204
+ { x: cb.min[0], y: this.draggingBBox.center[1] },
205
+ ],
206
+ lp: 'right',
207
+ },
208
+ offset: {
209
+ x: this.draggingBBox.max[0] - cb.min[0],
210
+ y: this.draggingBBox.center[1] - cb.center[1],
211
+ },
212
+ });
213
+ }
214
+ if (Math.abs(this.draggingBBox.max[0] - cb.center[0]) <= this.tolerance) {
215
+ this.alignLinesForChoose.v.push({
216
+ dl: {
217
+ line: [
218
+ { x: cb.center[0], y: cb.center[1] },
219
+ { x: cb.center[0], y: this.draggingBBox.center[1] },
220
+ ],
221
+ lp: 'right',
222
+ },
223
+ offset: {
224
+ x: this.draggingBBox.max[0] - cb.center[0],
225
+ y: this.draggingBBox.center[1] - cb.center[1],
226
+ },
227
+ });
228
+ }
229
+ if (Math.abs(this.draggingBBox.max[0] - cb.max[0]) <= this.tolerance) {
230
+ this.alignLinesForChoose.v.push({
231
+ dl: {
232
+ line: [
233
+ { x: cb.max[0], y: cb.center[1] },
234
+ { x: cb.max[0], y: this.draggingBBox.center[1] },
235
+ ],
236
+ lp: 'right',
237
+ },
238
+ offset: {
239
+ x: this.draggingBBox.max[0] - cb.max[0],
240
+ y: this.draggingBBox.center[1] - cb.center[1],
241
+ },
242
+ });
243
+ }
244
+ /* draggingBBox top */
245
+ if (Math.abs(this.draggingBBox.min[1] - cb.max[1]) <= this.tolerance) {
246
+ this.alignLinesForChoose.h.push({
247
+ dl: {
248
+ line: [
249
+ { x: cb.center[0], y: cb.max[1] },
250
+ { x: this.draggingBBox.center[0], y: cb.max[1] },
251
+ ],
252
+ lp: 'top',
253
+ },
254
+ offset: {
255
+ x: this.draggingBBox.center[0] - cb.center[0],
256
+ y: this.draggingBBox.min[1] - cb.max[1],
257
+ },
258
+ });
259
+ }
260
+ if (Math.abs(this.draggingBBox.min[1] - cb.center[1]) <= this.tolerance) {
261
+ this.alignLinesForChoose.h.push({
262
+ dl: {
263
+ line: [
264
+ { x: cb.center[0], y: cb.center[1] },
265
+ { x: this.draggingBBox.center[0], y: cb.center[1] },
266
+ ],
267
+ lp: 'top',
268
+ },
269
+ offset: {
270
+ x: this.draggingBBox.center[0] - cb.center[0],
271
+ y: this.draggingBBox.min[1] - cb.center[1],
272
+ },
273
+ });
274
+ }
275
+ if (Math.abs(this.draggingBBox.min[1] - cb.min[1]) <= this.tolerance) {
276
+ this.alignLinesForChoose.h.push({
277
+ dl: {
278
+ line: [
279
+ { x: cb.center[0], y: cb.max[1] },
280
+ { x: this.draggingBBox.center[0], y: cb.max[1] },
281
+ ],
282
+ lp: 'top',
283
+ },
284
+ offset: {
285
+ x: this.draggingBBox.center[0] - cb.center[0],
286
+ y: this.draggingBBox.min[1] - cb.min[1],
287
+ },
288
+ });
289
+ }
290
+ /* draggingBBox hcenter */
291
+ if (Math.abs(this.draggingBBox.center[1] - cb.max[1]) <= this.tolerance) {
292
+ this.alignLinesForChoose.h.push({
293
+ dl: {
294
+ line: [
295
+ { x: cb.center[0], y: cb.max[1] },
296
+ { x: this.draggingBBox.center[0], y: cb.max[1] },
297
+ ],
298
+ lp: 'hcenter',
299
+ },
300
+ offset: {
301
+ x: this.draggingBBox.center[0] - cb.center[0],
302
+ y: this.draggingBBox.center[1] - cb.max[1],
303
+ },
304
+ });
305
+ }
306
+ if (Math.abs(this.draggingBBox.center[1] - cb.center[1]) <= this.tolerance) {
307
+ this.alignLinesForChoose.h.push({
308
+ dl: {
309
+ line: [
310
+ { x: cb.center[0], y: cb.center[1] },
311
+ { x: this.draggingBBox.center[0], y: cb.center[1] },
312
+ ],
313
+ lp: 'hcenter',
314
+ },
315
+ offset: {
316
+ x: this.draggingBBox.center[0] - cb.center[0],
317
+ y: this.draggingBBox.center[1] - cb.center[1],
318
+ },
319
+ });
320
+ }
321
+ if (Math.abs(this.draggingBBox.center[1] - cb.min[1]) <= this.tolerance) {
322
+ this.alignLinesForChoose.h.push({
323
+ dl: {
324
+ line: [
325
+ { x: cb.center[0], y: cb.min[1] },
326
+ { x: this.draggingBBox.center[0], y: cb.min[1] },
327
+ ],
328
+ lp: 'hcenter',
329
+ },
330
+ offset: {
331
+ x: this.draggingBBox.center[0] - cb.center[0],
332
+ y: this.draggingBBox.center[1] - cb.min[1],
333
+ },
334
+ });
335
+ }
336
+ /* draggingBBox bottom */
337
+ if (Math.abs(this.draggingBBox.max[1] - cb.max[1]) <= this.tolerance) {
338
+ this.alignLinesForChoose.h.push({
339
+ dl: {
340
+ line: [
341
+ { x: cb.center[0], y: cb.max[1] },
342
+ { x: this.draggingBBox.center[0], y: cb.max[1] },
343
+ ],
344
+ lp: 'bottom',
345
+ },
346
+ offset: {
347
+ x: this.draggingBBox.center[0] - cb.center[0],
348
+ y: this.draggingBBox.max[1] - cb.max[1],
349
+ },
350
+ });
351
+ }
352
+ if (Math.abs(this.draggingBBox.max[1] - cb.center[1]) <= this.tolerance) {
353
+ this.alignLinesForChoose.h.push({
354
+ dl: {
355
+ line: [
356
+ { x: cb.center[0], y: cb.center[1] },
357
+ { x: this.draggingBBox.center[0], y: cb.center[1] },
358
+ ],
359
+ lp: 'bottom',
360
+ },
361
+ offset: {
362
+ x: this.draggingBBox.center[0] - cb.center[0],
363
+ y: this.draggingBBox.max[1] - cb.center[1],
364
+ },
365
+ });
366
+ }
367
+ if (Math.abs(this.draggingBBox.max[1] - cb.min[1]) <= this.tolerance) {
368
+ this.alignLinesForChoose.h.push({
369
+ dl: {
370
+ line: [
371
+ { x: cb.center[0], y: cb.min[1] },
372
+ { x: this.draggingBBox.center[0], y: cb.min[1] },
373
+ ],
374
+ lp: 'bottom',
375
+ },
376
+ offset: {
377
+ x: this.draggingBBox.center[0] - cb.center[0],
378
+ y: this.draggingBBox.max[1] - cb.min[1],
379
+ },
380
+ });
381
+ }
382
+ });
383
+ }
384
+ chooseAlignLine() {
385
+ // Principles:
386
+ // 1. Smaller difference from tolerance is more important
387
+ // 2. Same tolerance, (if multiple lines in the same direction are within the tolerance range) Importance: hcenter > top > bottom; vcenter > left > right
388
+ // 3. At most: vertical one count; horizon one count
389
+ // 4. Repeat line, will be subject to the longest (note: can't go to heavy, for performance, in the array of selected again)
390
+ // v direction line selection rule: draggingBBox's left/vcenter/right compares to vContrastPoints
391
+ // h direction line selection rule: draggingBBox's top/hcenter/bottom compares to hContrastPoints
392
+ if (this.alignLinesForChoose.v.length + this.alignLinesForChoose.h.length ===
393
+ 0) {
394
+ return { v: undefined, h: undefined };
395
+ }
396
+ let vTmpLines = [];
397
+ let hTmpLines = [];
398
+ // 1.v,h direction: select the line with minimum offset
399
+ const vMinOffset = Math.min(...this.alignLinesForChoose.v.map((dlFc) => dlFc.offset.x));
400
+ const hMinOffset = Math.min(...this.alignLinesForChoose.h.map((dlFc) => dlFc.offset.y));
401
+ vTmpLines = this.alignLinesForChoose.v.filter((dlFc) => dlFc.offset.x === vMinOffset);
402
+ hTmpLines = this.alignLinesForChoose.h.filter((dlFc) => dlFc.offset.y === hMinOffset);
403
+ // 2.same tolerance,hcenter > top > bottom; vcenter > left > right. (The principle of selecting only one direction)
404
+ {
405
+ const vcenter_hasdata = vTmpLines.some((dlFc) => dlFc.dl.lp === 'vcenter');
406
+ const left_hasdata = vTmpLines.some((dlFc) => dlFc.dl.lp === 'left');
407
+ vTmpLines = vTmpLines.filter((dlFc) => {
408
+ if (dlFc.dl.lp === 'vcenter') {
409
+ return true;
410
+ }
411
+ if (dlFc.dl.lp === 'left') {
412
+ if (!vcenter_hasdata && left_hasdata) {
413
+ return true;
414
+ }
415
+ return false;
416
+ }
417
+ if (dlFc.dl.lp === 'right') {
418
+ if (!vcenter_hasdata && !left_hasdata) {
419
+ return true;
420
+ }
421
+ return false;
422
+ }
423
+ return false;
424
+ });
425
+ const hcenter_hasdata = hTmpLines.some((dlFc) => dlFc.dl.lp === 'hcenter');
426
+ const top_hasdata = hTmpLines.some((dlFc) => dlFc.dl.lp === 'top');
427
+ hTmpLines = hTmpLines.filter((dlFc) => {
428
+ if (dlFc.dl.lp === 'hcenter') {
429
+ return true;
430
+ }
431
+ if (dlFc.dl.lp === 'top') {
432
+ if (!hcenter_hasdata && top_hasdata) {
433
+ return true;
434
+ }
435
+ return false;
436
+ }
437
+ if (dlFc.dl.lp === 'bottom') {
438
+ if (!hcenter_hasdata && !top_hasdata) {
439
+ return true;
440
+ }
441
+ return false;
442
+ }
443
+ return false;
444
+ });
445
+ }
446
+ // 3.remove duplicates
447
+ const uniVTmpLines = Array.from(vTmpLines
448
+ .reduce((map, item) => {
449
+ var _a;
450
+ if (!map.has(item.dl.lp) ||
451
+ Math.abs(item.offset.x) < Math.abs((_a = map.get(item.dl.lp)) === null || _a === void 0 ? void 0 : _a.offset.x)) {
452
+ map.set(item.dl.lp, item);
453
+ }
454
+ return map;
455
+ }, new Map())
456
+ .values());
457
+ const uniHTmpLines = Array.from(hTmpLines
458
+ .reduce((map, item) => {
459
+ var _a;
460
+ if (!map.has(item.dl.lp) ||
461
+ Math.abs(item.offset.y) < Math.abs((_a = map.get(item.dl.lp)) === null || _a === void 0 ? void 0 : _a.offset.y)) {
462
+ map.set(item.dl.lp, item);
463
+ }
464
+ return map;
465
+ }, new Map())
466
+ .values());
467
+ // 4.choose a maximum offset one of DrawLineForChoose
468
+ const vMaxDL = uniVTmpLines.length
469
+ ? uniVTmpLines.reduce((maxItem, curItem) => {
470
+ if (curItem.offset.x > maxItem.offset.x) {
471
+ return curItem;
472
+ }
473
+ else {
474
+ return maxItem;
475
+ }
476
+ })
477
+ : undefined;
478
+ const hMaxDL = uniHTmpLines.length
479
+ ? uniHTmpLines.reduce((maxItem, curItem) => {
480
+ if (curItem.offset.y > maxItem.offset.y) {
481
+ return curItem;
482
+ }
483
+ else {
484
+ return maxItem;
485
+ }
486
+ })
487
+ : undefined;
488
+ return {
489
+ v: vMaxDL ? vMaxDL.dl : undefined,
490
+ h: hMaxDL ? hMaxDL.dl : undefined,
491
+ };
492
+ }
493
+ constructor(options) {
494
+ super(options);
495
+ //#region state: historyPoints
496
+ this.historyPoints = [
497
+ undefined,
498
+ undefined,
499
+ ];
500
+ /**
501
+ * when start drag, offset of cursor and node center (event.canvas - draggingnode.BBox)
502
+ */
503
+ this.initialOffset = [undefined, undefined];
504
+ /**
505
+ * Cache the nodes' positions to be throttly updated.
506
+ */
507
+ this.updateCache = new Map();
508
+ /**
509
+ * Gets the current cursor node and center offset and then with initialOffset difference
510
+ */
511
+ this.getCurOffsetCompareToInitialOffset = (e) => {
512
+ if (this.initialOffset[0] === undefined ||
513
+ this.initialOffset[1] === undefined) {
514
+ return [undefined, undefined];
515
+ }
516
+ const curOffset = [
517
+ e.canvas.x - this.draggingBBox.center[0],
518
+ e.canvas.y - this.draggingBBox.center[1],
519
+ ];
520
+ return [
521
+ curOffset[0] - this.initialOffset[0],
522
+ curOffset[1] - this.initialOffset[1],
523
+ ];
524
+ };
525
+ this.dragging = false;
526
+ this.draggingBBox = undefined;
527
+ // Gets the offset between the cursor and draggingItem
528
+ this.getPointerOffsetWithItem = (pointer) => {
529
+ return {
530
+ x: Math.abs(pointer.x - this.draggingBBox.center[0]),
531
+ y: Math.abs(pointer.x - this.draggingBBox.center[1]),
532
+ };
533
+ };
534
+ //#region state: tolerance
535
+ this.tolerance = 4;
536
+ this.toleranceFactor = 2;
537
+ //#endregion
538
+ // All the lines in the vertical direction
539
+ this.vContrastPoints = [];
540
+ this.hContrastPoints = [];
541
+ /**
542
+ * alignLinesForChoose container
543
+ */
544
+ this.alignLinesForChoose = { v: [], h: [] };
545
+ /**
546
+ * v and h direction adsorption state
547
+ */
548
+ this.isAdsorbed = [false, false]; // whether the adsorption state
549
+ this.dragEvent = undefined; // drag event
550
+ // use dragItemId and dragItemType to avoid object changing when dragging
551
+ this.dragItemId = undefined;
552
+ this.dragItemType = undefined;
553
+ /**
554
+ * Historical adsorption region: v and h directions
555
+ * x0 ~ x1: Represents the starting and ending line in the v direction
556
+ * y0 ~ y1: Represents the starting and ending line in the h direction
557
+ *
558
+ * When the cursor moves out of this region && non-adsorbed state => set to undefined
559
+ */
560
+ this.historyAbsorbArea = [undefined, undefined];
561
+ /**
562
+ * Unable to adsorb: countdown
563
+ */
564
+ this.canAdsorbCount = 0;
565
+ /**
566
+ * Countdown method: Countdown
567
+ */
568
+ this.canAdsorbCountDown = () => {
569
+ if (this.canAdsorbCount > 0) {
570
+ const intervalID = setInterval(() => {
571
+ this.canAdsorbCount--;
572
+ if (this.canAdsorbCount <= 0) {
573
+ clearTimeout(intervalID);
574
+ }
575
+ }, 100);
576
+ }
577
+ };
578
+ this.onDrag = (0, util_1.throttle)(((event) => {
579
+ var _a, _b, _c, _d, _e, _f, _g, _h;
580
+ this.dragEvent = event;
581
+ this.initAlignLinesForChoose();
582
+ // control layer: Check to delete existing line & drawed line & adsorption
583
+ // set historyPoints
584
+ this.historyPoints[0] = this.historyPoints[1];
585
+ this.historyPoints[1] = { x: event.canvas.x, y: event.canvas.y };
586
+ let vlp = undefined;
587
+ let vline = undefined;
588
+ let hlp = undefined;
589
+ let hline = undefined;
590
+ // v direction: whether keep adsorption
591
+ const checkVShouldHoldAbsorb = (vlp, vline) => {
592
+ // v direction: continue to adsorb
593
+ const vShouldAbsorb = Math.abs(this.getCurOffsetCompareToInitialOffset(event)[0]) <=
594
+ this.tolerance * this.toleranceFactor;
595
+ if (vShouldAbsorb) {
596
+ if (vlp === 'left') {
597
+ this.doUpdatePosition({
598
+ x: vline[0].x + this.draggingBBox.halfExtents[0],
599
+ });
600
+ }
601
+ else if (vlp === 'vcenter') {
602
+ this.doUpdatePosition({
603
+ x: vline[0].x,
604
+ });
605
+ }
606
+ else if (vlp === 'right') {
607
+ this.doUpdatePosition({
608
+ fx: vline[0].x - this.draggingBBox.halfExtents[0],
609
+ });
610
+ }
611
+ // updarte align line when absorb
612
+ this.updateAlignLineWhenAbsorb([true, false]);
613
+ }
614
+ else {
615
+ // cancel absorb
616
+ // 1.update positon
617
+ this.doUpdatePosition({ fx: undefined });
618
+ // 2.remove align line && update state
619
+ this.removeAlignLine([true, undefined]);
620
+ // count down to be adsorbable
621
+ this.canAdsorbCount = 10; // 1s
622
+ this.canAdsorbCountDown();
623
+ }
624
+ };
625
+ // h direction: whether keep adsorption
626
+ const checkHShouldHoldAbsorb = (hlp, hline) => {
627
+ // h direction: continue to adsorb
628
+ const hShouldAbsorb = Math.abs(this.getCurOffsetCompareToInitialOffset(event)[1]) <=
629
+ this.tolerance * this.toleranceFactor;
630
+ if (hShouldAbsorb) {
631
+ if (hlp === 'top') {
632
+ this.doUpdatePosition({
633
+ fy: hline[0].y + this.draggingBBox.halfExtents[1],
634
+ });
635
+ }
636
+ else if (hlp === 'hcenter') {
637
+ this.doUpdatePosition({
638
+ fy: hline[0].y,
639
+ });
640
+ }
641
+ else if (hlp === 'bottom') {
642
+ this.doUpdatePosition({
643
+ fy: hline[0].y - this.draggingBBox.halfExtents[1],
644
+ });
645
+ }
646
+ // update align line
647
+ this.updateAlignLineWhenAbsorb([false, true]);
648
+ }
649
+ else {
650
+ // 1.update position
651
+ this.doUpdatePosition({ fy: undefined });
652
+ // 2.remove align line && update state
653
+ this.removeAlignLine([undefined, true]);
654
+ // count down to be adsorbable
655
+ this.canAdsorbCount = 10; // 1s
656
+ this.canAdsorbCountDown();
657
+ }
658
+ };
659
+ // v direction: whether adsorbed
660
+ const checkVShouldAbsorb = () => {
661
+ const ret = this.canDrawLine();
662
+ // If in recent from adsorption area, can't immediately draw lines (must be removed from the area to reline this area)
663
+ if (ret) {
664
+ // draw align lines
665
+ this.drawAlignLines({ vdl: ret.vdl, hdl: undefined });
666
+ // absorb dragging box
667
+ this.absorb({ vdl: ret.vdl, hdl: undefined });
668
+ }
669
+ };
670
+ // h direction: whether adsorbed
671
+ const checkHShouldAbsorb = () => {
672
+ const ret = this.canDrawLine();
673
+ // If in recent from adsorption area, can't immediately draw lines (must be removed from the area to reline this area)
674
+ if (ret) {
675
+ // draw align lines
676
+ this.drawAlignLines({ vdl: undefined, hdl: ret.hdl });
677
+ // absorb dragging box
678
+ this.absorb({ vdl: undefined, hdl: ret.hdl });
679
+ }
680
+ };
681
+ // 1、the current state of the two directions are adsorption
682
+ if (this.isAdsorbed[0] && this.isAdsorbed[1]) {
683
+ vlp = (_a = this.drawedLines[0].dl) === null || _a === void 0 ? void 0 : _a.lp;
684
+ vline = (_b = this.drawedLines[0].dl) === null || _b === void 0 ? void 0 : _b.line;
685
+ hlp = (_c = this.drawedLines[1].dl) === null || _c === void 0 ? void 0 : _c.lp;
686
+ hline = (_d = this.drawedLines[1].dl) === null || _d === void 0 ? void 0 : _d.line;
687
+ checkVShouldHoldAbsorb(vlp, vline);
688
+ checkHShouldHoldAbsorb(hlp, hline);
689
+ }
690
+ else if (this.isAdsorbed[0] && !this.isAdsorbed[1]) {
691
+ // 2、currently, only the v direction is adsorbed
692
+ vlp = (_e = this.drawedLines[0].dl) === null || _e === void 0 ? void 0 : _e.lp;
693
+ vline = (_f = this.drawedLines[0].dl) === null || _f === void 0 ? void 0 : _f.line;
694
+ checkVShouldHoldAbsorb(vlp, vline);
695
+ checkHShouldAbsorb();
696
+ }
697
+ else if (!this.isAdsorbed[0] && this.isAdsorbed[1]) {
698
+ // 3、currently, only the h direction is adsorbed
699
+ hlp = (_g = this.drawedLines[1].dl) === null || _g === void 0 ? void 0 : _g.lp;
700
+ hline = (_h = this.drawedLines[1].dl) === null || _h === void 0 ? void 0 : _h.line;
701
+ checkHShouldHoldAbsorb(vlp, vline);
702
+ checkVShouldAbsorb();
703
+ }
704
+ else if (!this.isAdsorbed[0] && !this.isAdsorbed[1]) {
705
+ // 4、currently, v and h directions are not adsorbed
706
+ const ret = this.canDrawLine();
707
+ // If you have recently detached from the attachment area, you cannot draw the line immediately (you need to remove the detached area to redraw the area)
708
+ if (ret) {
709
+ // draw align lines
710
+ this.drawAlignLines(ret);
711
+ // absorb dragging box
712
+ this.absorb(ret);
713
+ }
714
+ }
715
+ }).bind(this), 16, {
716
+ leading: false,
717
+ trailing: true,
718
+ });
719
+ //#region draw/remove lines
720
+ // first:v direction; second:h direction;
721
+ // ddo: drawed DisplayObject, dl: DrawLine
722
+ this.drawedLines = [undefined, undefined];
723
+ this.throttleUpdate = (0, util_1.throttle)(() => {
724
+ this.graph.updateNodePosition(Array.from(this.updateCache.values()), false, true);
725
+ this.updateCache.clear();
726
+ }, 16, {
727
+ leading: true,
728
+ trailing: true,
729
+ });
730
+ this.init(options.graph);
731
+ }
732
+ getEvents() {
733
+ return {
734
+ pointerdown: this.onPointerDown,
735
+ pointermove: this.onPointerMove,
736
+ pointerup: this.onPointerUp,
737
+ };
738
+ }
739
+ onPointerDown(event) {
740
+ this.historyPoints[1] = { x: event.canvas.x, y: event.canvas.y };
741
+ this.dragItemId = event.itemId;
742
+ this.dragItemType = event.itemType;
743
+ }
744
+ onPointerMove(event) {
745
+ if (!this.historyPoints[1])
746
+ return;
747
+ if (this.dragItemType !== 'node') {
748
+ return;
749
+ }
750
+ // pointerDown + first move = start drag
751
+ if (!this.dragging) {
752
+ this.onDragStart(event);
753
+ this.dragging = true;
754
+ }
755
+ else {
756
+ this.onDrag(event);
757
+ }
758
+ }
759
+ onPointerUp(event) {
760
+ // pointerUp + dragging = onDragEnd
761
+ if (this.dragging) {
762
+ this.onDragEnd();
763
+ }
764
+ else {
765
+ this.historyPoints = [undefined, undefined];
766
+ this.dragging = false;
767
+ this.dragItemId = undefined;
768
+ this.dragItemType = undefined;
769
+ }
770
+ }
771
+ getGraph(event) {
772
+ return event.currentTarget;
773
+ }
774
+ //#region event handler
775
+ onDragStart(event) {
776
+ this.draggingBBox = this.graph.getRenderBBox(event.itemId, true);
777
+ this.initialOffset = [
778
+ event.canvas.x - this.draggingBBox.center[0],
779
+ event.canvas.y - this.draggingBBox.center[1],
780
+ ];
781
+ }
782
+ onDragEnd() {
783
+ this.dragEvent = undefined;
784
+ this.historyPoints = [undefined, undefined];
785
+ this.dragging = false;
786
+ this.dragItemId = undefined;
787
+ this.dragItemType = undefined;
788
+ }
789
+ drawAlignLines({ vdl, hdl, }) {
790
+ // 1.draw align line
791
+ const vLineID = vdl ? this.getDrawLineIdByDrawLine(vdl) : undefined;
792
+ const hLineID = hdl ? this.getDrawLineIdByDrawLine(hdl) : undefined;
793
+ let vLine = undefined;
794
+ if (vdl) {
795
+ vLine = this.graph.drawTransient('line', vLineID, {
796
+ style: {
797
+ stroke: 'red',
798
+ lineWidth: 1,
799
+ x1: vdl.line[0].x,
800
+ y1: vdl.line[0].y,
801
+ x2: vdl.line[1].x,
802
+ y2: vdl.line[1].y,
803
+ },
804
+ });
805
+ // add to alignLines
806
+ this.drawedLines[0] = { do: vLine, dl: vdl };
807
+ }
808
+ let hLine = undefined;
809
+ if (hdl) {
810
+ hLine = this.graph.drawTransient('line', hLineID, {
811
+ style: {
812
+ stroke: 'red',
813
+ lineWidth: 1,
814
+ x1: hdl.line[0].x,
815
+ y1: hdl.line[0].y,
816
+ x2: hdl.line[1].x,
817
+ y2: hdl.line[1].y,
818
+ },
819
+ });
820
+ // add to alignLines
821
+ this.drawedLines[1] = { do: hLine, dl: hdl };
822
+ }
823
+ }
824
+ /**
825
+ * remove align line
826
+ * @param rvdl: remove vertical drawed line
827
+ * @param rhdl: remove horizon drawed line
828
+ */
829
+ removeAlignLine([rvdl, rhdl]) {
830
+ if (rvdl) {
831
+ const vlid = this.getDrawLineIdByDrawLine(this.drawedLines[0].dl);
832
+ this.graph.drawTransient('line', vlid, { action: 'remove' });
833
+ this.drawedLines[0] = undefined;
834
+ this.isAdsorbed[0] = false;
835
+ }
836
+ if (rhdl) {
837
+ const hlid = this.getDrawLineIdByDrawLine(this.drawedLines[1].dl);
838
+ this.graph.drawTransient('line', hlid, { action: 'remove' });
839
+ this.drawedLines[1] = undefined;
840
+ this.isAdsorbed[1] = false;
841
+ }
842
+ }
843
+ /**
844
+ * via ID: remove align line
845
+ * @param rmLineID
846
+ */
847
+ removeAlignLineByID(rmLineID) {
848
+ // remove from DisplayObject
849
+ const [vTmpDrawedLine, hTmpDrawedLine] = this.drawedLines;
850
+ this.drawedLines.forEach((line, index) => {
851
+ if (line && line.do) {
852
+ const lineID = this.getDrawLineIdByPoints(line.dl.line);
853
+ if (lineID === rmLineID) {
854
+ if (index === 0 && vTmpDrawedLine) {
855
+ vTmpDrawedLine.dl = undefined;
856
+ vTmpDrawedLine.do = undefined;
857
+ }
858
+ else if (index === 1 && hTmpDrawedLine) {
859
+ hTmpDrawedLine.dl = undefined;
860
+ hTmpDrawedLine.do = undefined;
861
+ }
862
+ this.isAdsorbed[index] = false;
863
+ }
864
+ }
865
+ });
866
+ this.drawedLines[0] = vTmpDrawedLine;
867
+ this.drawedLines[1] = hTmpDrawedLine;
868
+ // remove drawed line
869
+ this.graph.drawTransient('line', rmLineID, { action: 'remove' });
870
+ }
871
+ /**
872
+ * get draggingBBox Point based on LinePosition
873
+ */
874
+ getDraggingBBoxPointByLinePosition(lp) {
875
+ if (!this.draggingBBox) {
876
+ return undefined;
877
+ }
878
+ if (lp === 'left') {
879
+ return { x: this.draggingBBox.min[0], y: this.draggingBBox.center[1] };
880
+ }
881
+ if (lp === 'vcenter' || lp === 'hcenter') {
882
+ return { x: this.draggingBBox.center[0], y: this.draggingBBox.center[1] };
883
+ }
884
+ if (lp === 'right') {
885
+ return { x: this.draggingBBox.max[0], y: this.draggingBBox.center[1] };
886
+ }
887
+ if (lp === 'top') {
888
+ return { x: this.draggingBBox.center[0], y: this.draggingBBox.min[1] };
889
+ }
890
+ if (lp === 'bottom') {
891
+ return { x: this.draggingBBox.center[0], y: this.draggingBBox.max[1] };
892
+ }
893
+ return undefined;
894
+ }
895
+ /**
896
+ * update align line under condition of absorbed
897
+ */
898
+ updateAlignLineWhenAbsorb([v, h]) {
899
+ if (v) {
900
+ if (this.drawedLines[0] && this.drawedLines[0].do) {
901
+ const draggingBBoxDrawEndPoint = this.getDraggingBBoxPointByLinePosition(this.drawedLines[0].dl.lp);
902
+ const vdl = {
903
+ line: [
904
+ this.drawedLines[0].dl.line[0],
905
+ {
906
+ x: this.drawedLines[0].dl.line[0].x,
907
+ y: draggingBBoxDrawEndPoint.y,
908
+ },
909
+ ],
910
+ lp: this.drawedLines[0].dl.lp,
911
+ };
912
+ this.removeAlignLineByID(this.drawedLines[0].do.id);
913
+ this.drawAlignLines({ vdl: vdl, hdl: undefined });
914
+ this.isAdsorbed[0] = true;
915
+ }
916
+ }
917
+ if (h) {
918
+ if (this.drawedLines[1] && this.drawedLines[1].do) {
919
+ const draggingBBoxDrawEndPoint = this.getDraggingBBoxPointByLinePosition(this.drawedLines[1].dl.lp);
920
+ const hdl = {
921
+ line: [
922
+ this.drawedLines[1].dl.line[0],
923
+ {
924
+ x: draggingBBoxDrawEndPoint.x,
925
+ y: this.drawedLines[1].dl.line[0].y,
926
+ },
927
+ ],
928
+ lp: this.drawedLines[1].dl.lp,
929
+ };
930
+ this.removeAlignLineByID(this.drawedLines[1].do.id);
931
+ this.drawAlignLines({ vdl: undefined, hdl: hdl });
932
+ this.isAdsorbed[1] = true;
933
+ }
934
+ }
935
+ }
936
+ /**
937
+ * check whether can draw lines
938
+ */
939
+ canDrawLine() {
940
+ const { v, h } = this.chooseAlignLine();
941
+ if (!v && !h) {
942
+ return false;
943
+ }
944
+ return { vdl: v, hdl: h };
945
+ }
946
+ /**
947
+ * detect whether adsorption can be cancelled
948
+ * two directions:v h
949
+ * @return first: v direction ; second:h direction; undefine means no-adsorb
950
+ */
951
+ canCancelAbsorb() {
952
+ // eslint-disable-next-line prefer-const
953
+ let ret = [
954
+ undefined,
955
+ undefined,
956
+ ];
957
+ const vdl = this.drawedLines[0].dl;
958
+ const hdl = this.drawedLines[1].dl;
959
+ const offset = this.getPointerOffsetWithItem({
960
+ x: this.dragEvent.canvas.x,
961
+ y: this.dragEvent.canvas.y,
962
+ });
963
+ if (vdl) {
964
+ if (Math.abs(offset.x) > this.tolerance * this.toleranceFactor) {
965
+ ret[0] = true;
966
+ }
967
+ }
968
+ if (hdl) {
969
+ if (Math.abs(offset.y) > this.tolerance * this.toleranceFactor) {
970
+ ret[1] = true;
971
+ }
972
+ }
973
+ return ret;
974
+ }
975
+ //#endregion
976
+ /**
977
+ * absorb the dragging box
978
+ */
979
+ absorb(dls) {
980
+ if (dls.vdl) {
981
+ this.isAdsorbed[0] = true;
982
+ this.historyAbsorbArea[0] = [
983
+ dls.vdl.line[0].x - this.tolerance * this.toleranceFactor,
984
+ dls.vdl.line[0].x + this.tolerance * this.toleranceFactor,
985
+ ];
986
+ this.updateDraggingItemPosition(this.drawedLines[0].dl);
987
+ }
988
+ if (dls.hdl) {
989
+ this.isAdsorbed[1] = true;
990
+ this.historyAbsorbArea[1] = [
991
+ dls.hdl.line[0].y - this.tolerance * this.toleranceFactor,
992
+ dls.hdl.line[0].y + this.tolerance * this.toleranceFactor,
993
+ ];
994
+ this.updateDraggingItemPosition(this.drawedLines[1].dl);
995
+ }
996
+ }
997
+ /**
998
+ * If there is dl(draw line), then absorb to dl;
999
+ * don't pass dl, means cancel absorb
1000
+ * @param dl drawline [point, point]
1001
+ */
1002
+ updateDraggingItemPosition(dl, shouldChange) {
1003
+ // Determine if historyPoints do not exist do not continue
1004
+ if (!this.historyPoints[0] && !this.historyPoints[1]) {
1005
+ return;
1006
+ }
1007
+ // absorb effect
1008
+ if (dl) {
1009
+ // calculate the diff and absorb
1010
+ if (dl.lp === 'left') {
1011
+ const tmpX = dl.line[0].x + this.draggingBBox.halfExtents[0];
1012
+ this.doUpdatePosition({ fx: tmpX });
1013
+ }
1014
+ if (dl.lp === 'vcenter') {
1015
+ this.doUpdatePosition({
1016
+ fx: dl.line[0].x,
1017
+ });
1018
+ }
1019
+ if (dl.lp === 'right') {
1020
+ this.doUpdatePosition({
1021
+ fx: dl.line[0].x - this.draggingBBox.halfExtents[0],
1022
+ });
1023
+ }
1024
+ if (dl.lp === 'top') {
1025
+ this.doUpdatePosition({
1026
+ fy: dl.line[0].y + this.draggingBBox.halfExtents[1],
1027
+ });
1028
+ }
1029
+ if (dl.lp === 'hcenter') {
1030
+ this.doUpdatePosition({
1031
+ fy: dl.line[0].y,
1032
+ });
1033
+ }
1034
+ if (dl.lp === 'bottom') {
1035
+ this.doUpdatePosition({
1036
+ fy: dl.line[0].y - this.draggingBBox.halfExtents[1],
1037
+ });
1038
+ }
1039
+ }
1040
+ if (shouldChange) {
1041
+ if (shouldChange.x) {
1042
+ const changeX = this.draggingBBox.center[0] + shouldChange.x;
1043
+ this.doUpdatePosition({
1044
+ x: changeX,
1045
+ fx: undefined,
1046
+ });
1047
+ }
1048
+ if (shouldChange.y) {
1049
+ const changeY = this.draggingBBox.center[1] + shouldChange.y;
1050
+ this.doUpdatePosition({
1051
+ y: changeY,
1052
+ fy: undefined,
1053
+ });
1054
+ }
1055
+ }
1056
+ }
1057
+ doUpdatePosition(data) {
1058
+ const cache = this.updateCache.get(this.dragItemId);
1059
+ this.updateCache.set(this.dragItemId, {
1060
+ id: this.dragItemId,
1061
+ data: Object.assign(Object.assign({}, cache === null || cache === void 0 ? void 0 : cache.data), data),
1062
+ });
1063
+ this.throttleUpdate();
1064
+ }
1065
+ }
1066
+ exports.Snapline = Snapline;
1067
+ //# sourceMappingURL=index.js.map