@antv/g6 5.0.0-beta.2 → 5.0.0-beta.20

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 (608) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/esm/api-doc/graph.d.ts +3 -3
  3. package/esm/api-doc/graph.js +3 -3
  4. package/esm/api-doc/graph.js.map +1 -1
  5. package/esm/api-doc/types.d.ts +1 -0
  6. package/esm/api-doc/types.js +1 -2
  7. package/esm/api-doc/types.js.map +1 -1
  8. package/esm/constant/shape.d.ts +3 -1
  9. package/esm/index.d.ts +24 -63
  10. package/esm/index.js +4 -5
  11. package/esm/index.js.map +1 -1
  12. package/esm/item/combo.d.ts +1 -1
  13. package/esm/item/combo.js +18 -14
  14. package/esm/item/combo.js.map +1 -1
  15. package/esm/item/edge.d.ts +19 -2
  16. package/esm/item/edge.js +100 -44
  17. package/esm/item/edge.js.map +1 -1
  18. package/esm/item/item.d.ts +3 -2
  19. package/esm/item/item.js +27 -13
  20. package/esm/item/item.js.map +1 -1
  21. package/esm/item/node.d.ts +2 -8
  22. package/esm/item/node.js +31 -19
  23. package/esm/item/node.js.map +1 -1
  24. package/esm/runtime/controller/data.d.ts +7 -10
  25. package/esm/runtime/controller/data.js +125 -281
  26. package/esm/runtime/controller/data.js.map +1 -1
  27. package/esm/runtime/controller/interaction.js +9 -4
  28. package/esm/runtime/controller/interaction.js.map +1 -1
  29. package/esm/runtime/controller/item.d.ts +1 -0
  30. package/esm/runtime/controller/item.js +285 -150
  31. package/esm/runtime/controller/item.js.map +1 -1
  32. package/esm/runtime/controller/layout.js +1 -3
  33. package/esm/runtime/controller/layout.js.map +1 -1
  34. package/esm/runtime/controller/plugin.js +9 -5
  35. package/esm/runtime/controller/plugin.js.map +1 -1
  36. package/esm/runtime/graph.d.ts +104 -24
  37. package/esm/runtime/graph.js +472 -94
  38. package/esm/runtime/graph.js.map +1 -1
  39. package/esm/stdlib/behavior/activate-relations.d.ts +1 -1
  40. package/esm/stdlib/behavior/activate-relations.js +2 -2
  41. package/esm/stdlib/behavior/activate-relations.js.map +1 -1
  42. package/esm/stdlib/behavior/brush-select.d.ts +9 -3
  43. package/esm/stdlib/behavior/brush-select.js +10 -12
  44. package/esm/stdlib/behavior/brush-select.js.map +1 -1
  45. package/esm/stdlib/behavior/click-select.d.ts +1 -1
  46. package/esm/stdlib/behavior/click-select.js +1 -1
  47. package/esm/stdlib/behavior/click-select.js.map +1 -1
  48. package/esm/stdlib/behavior/collapse-expand-combo.d.ts +1 -1
  49. package/esm/stdlib/behavior/collapse-expand-tree.d.ts +1 -1
  50. package/esm/stdlib/behavior/create-edge.d.ts +57 -0
  51. package/esm/stdlib/behavior/create-edge.js +215 -0
  52. package/esm/stdlib/behavior/create-edge.js.map +1 -0
  53. package/esm/stdlib/behavior/drag-canvas.d.ts +3 -1
  54. package/esm/stdlib/behavior/drag-canvas.js +78 -33
  55. package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
  56. package/esm/stdlib/behavior/drag-combo.d.ts +3 -3
  57. package/esm/stdlib/behavior/drag-combo.js +43 -32
  58. package/esm/stdlib/behavior/drag-combo.js.map +1 -1
  59. package/esm/stdlib/behavior/drag-node.d.ts +4 -4
  60. package/esm/stdlib/behavior/drag-node.js +80 -63
  61. package/esm/stdlib/behavior/drag-node.js.map +1 -1
  62. package/esm/stdlib/behavior/index.d.ts +3 -0
  63. package/esm/stdlib/behavior/index.js +3 -0
  64. package/esm/stdlib/behavior/index.js.map +1 -1
  65. package/esm/stdlib/behavior/lasso-select.d.ts +1 -1
  66. package/esm/stdlib/behavior/lasso-select.js +3 -4
  67. package/esm/stdlib/behavior/lasso-select.js.map +1 -1
  68. package/esm/stdlib/behavior/scroll-canvas.d.ts +67 -0
  69. package/esm/stdlib/behavior/scroll-canvas.js +266 -0
  70. package/esm/stdlib/behavior/scroll-canvas.js.map +1 -0
  71. package/esm/stdlib/behavior/shortcuts-call.d.ts +38 -0
  72. package/esm/stdlib/behavior/shortcuts-call.js +87 -0
  73. package/esm/stdlib/behavior/shortcuts-call.js.map +1 -0
  74. package/esm/stdlib/behavior/zoom-canvas-3d.js +4 -1
  75. package/esm/stdlib/behavior/zoom-canvas-3d.js.map +1 -1
  76. package/esm/stdlib/behavior/zoom-canvas.d.ts +3 -1
  77. package/esm/stdlib/behavior/zoom-canvas.js +70 -26
  78. package/esm/stdlib/behavior/zoom-canvas.js.map +1 -1
  79. package/esm/stdlib/data/mapNodeSize.d.ts +2 -2
  80. package/esm/stdlib/data/mapNodeSize.js +2 -2
  81. package/esm/stdlib/data/mapNodeSize.js.map +1 -1
  82. package/esm/stdlib/data/transformV4Data.d.ts +2 -2
  83. package/esm/stdlib/data/transformV4Data.js +2 -2
  84. package/esm/stdlib/data/transformV4Data.js.map +1 -1
  85. package/esm/stdlib/data/validateData.d.ts +2 -2
  86. package/esm/stdlib/data/validateData.js +13 -12
  87. package/esm/stdlib/data/validateData.js.map +1 -1
  88. package/esm/stdlib/index.d.ts +18 -6
  89. package/esm/stdlib/index.js +22 -10
  90. package/esm/stdlib/index.js.map +1 -1
  91. package/esm/stdlib/item/edge/base.d.ts +3 -5
  92. package/esm/stdlib/item/edge/base.js +32 -31
  93. package/esm/stdlib/item/edge/base.js.map +1 -1
  94. package/esm/stdlib/item/edge/cubic-horizontal.js.map +1 -1
  95. package/esm/stdlib/item/edge/cubic-vertical.js.map +1 -1
  96. package/esm/stdlib/item/edge/cubic.js +1 -1
  97. package/esm/stdlib/item/edge/cubic.js.map +1 -1
  98. package/esm/stdlib/item/edge/loop.js +1 -1
  99. package/esm/stdlib/item/edge/loop.js.map +1 -1
  100. package/esm/stdlib/item/node/base.d.ts +3 -6
  101. package/esm/stdlib/item/node/base.js +30 -60
  102. package/esm/stdlib/item/node/base.js.map +1 -1
  103. package/esm/stdlib/item/node/base3d.d.ts +1 -0
  104. package/esm/stdlib/item/node/base3d.js +1 -0
  105. package/esm/stdlib/item/node/base3d.js.map +1 -1
  106. package/esm/stdlib/item/node/cube.d.ts +35 -0
  107. package/esm/stdlib/item/node/cube.js +54 -0
  108. package/esm/stdlib/item/node/cube.js.map +1 -0
  109. package/esm/stdlib/item/node/diamond.js +1 -1
  110. package/esm/stdlib/item/node/donut.d.ts +3 -3
  111. package/esm/stdlib/item/node/ellipse.js +2 -2
  112. package/esm/stdlib/item/node/hexagon.js +6 -2
  113. package/esm/stdlib/item/node/hexagon.js.map +1 -1
  114. package/esm/stdlib/item/node/image.d.ts +40 -0
  115. package/esm/stdlib/item/node/image.js +110 -0
  116. package/esm/stdlib/item/node/image.js.map +1 -0
  117. package/esm/stdlib/item/node/index.d.ts +4 -0
  118. package/esm/stdlib/item/node/index.js +4 -0
  119. package/esm/stdlib/item/node/index.js.map +1 -1
  120. package/esm/stdlib/plugin/edgeFilterLens/index.d.ts +66 -0
  121. package/esm/stdlib/plugin/edgeFilterLens/index.js +309 -0
  122. package/esm/stdlib/plugin/edgeFilterLens/index.js.map +1 -0
  123. package/esm/stdlib/plugin/grid/index.d.ts +1 -1
  124. package/esm/stdlib/plugin/grid/index.js +3 -4
  125. package/esm/stdlib/plugin/grid/index.js.map +1 -1
  126. package/esm/stdlib/plugin/history/combo-command.js +2 -2
  127. package/esm/stdlib/plugin/history/combo-command.js.map +1 -1
  128. package/esm/stdlib/plugin/history/index.d.ts +10 -10
  129. package/esm/stdlib/plugin/history/index.js +14 -14
  130. package/esm/stdlib/plugin/history/index.js.map +1 -1
  131. package/esm/stdlib/plugin/history/item-data-command.js +25 -16
  132. package/esm/stdlib/plugin/history/item-data-command.js.map +1 -1
  133. package/esm/stdlib/plugin/history/layer-updated-command.js +2 -2
  134. package/esm/stdlib/plugin/history/layer-updated-command.js.map +1 -1
  135. package/esm/stdlib/plugin/history/state-updated-command.js +1 -1
  136. package/esm/stdlib/plugin/history/state-updated-command.js.map +1 -1
  137. package/esm/stdlib/plugin/history/visibility-updated-command.js +2 -2
  138. package/esm/stdlib/plugin/history/visibility-updated-command.js.map +1 -1
  139. package/esm/stdlib/plugin/hull/convexHull.d.ts +1 -1
  140. package/esm/stdlib/plugin/hull/hullComponent.d.ts +2 -2
  141. package/esm/stdlib/plugin/hull/hullComponent.js +5 -9
  142. package/esm/stdlib/plugin/hull/hullComponent.js.map +1 -1
  143. package/esm/stdlib/plugin/hull/util.d.ts +2 -2
  144. package/esm/stdlib/plugin/hull/util.js +6 -2
  145. package/esm/stdlib/plugin/hull/util.js.map +1 -1
  146. package/esm/stdlib/plugin/index.d.ts +2 -0
  147. package/esm/stdlib/plugin/index.js +2 -0
  148. package/esm/stdlib/plugin/index.js.map +1 -1
  149. package/esm/stdlib/plugin/legend/index.d.ts +3 -3
  150. package/esm/stdlib/plugin/legend/index.js +3 -3
  151. package/esm/stdlib/plugin/legend/index.js.map +1 -1
  152. package/esm/stdlib/plugin/menu/index.d.ts +4 -4
  153. package/esm/stdlib/plugin/menu/index.js +3 -3
  154. package/esm/stdlib/plugin/menu/index.js.map +1 -1
  155. package/esm/stdlib/plugin/minimap/index.d.ts +6 -2
  156. package/esm/stdlib/plugin/minimap/index.js +119 -12
  157. package/esm/stdlib/plugin/minimap/index.js.map +1 -1
  158. package/esm/stdlib/plugin/snapline/index.d.ts +167 -0
  159. package/esm/stdlib/plugin/snapline/index.js +1063 -0
  160. package/esm/stdlib/plugin/snapline/index.js.map +1 -0
  161. package/esm/stdlib/plugin/timebar/index.d.ts +4 -4
  162. package/esm/stdlib/plugin/timebar/index.js +6 -6
  163. package/esm/stdlib/plugin/timebar/index.js.map +1 -1
  164. package/esm/stdlib/plugin/toolbar/index.d.ts +3 -3
  165. package/esm/stdlib/plugin/toolbar/index.js +4 -4
  166. package/esm/stdlib/plugin/toolbar/index.js.map +1 -1
  167. package/esm/stdlib/plugin/tooltip/index.d.ts +5 -5
  168. package/esm/stdlib/plugin/tooltip/index.js +3 -4
  169. package/esm/stdlib/plugin/tooltip/index.js.map +1 -1
  170. package/esm/stdlib/plugin/types.d.ts +2 -0
  171. package/esm/stdlib/plugin/watermaker/index.d.ts +78 -0
  172. package/esm/stdlib/plugin/watermaker/index.js +243 -0
  173. package/esm/stdlib/plugin/watermaker/index.js.map +1 -0
  174. package/esm/stdlib/theme/dark.js +42 -2
  175. package/esm/stdlib/theme/dark.js.map +1 -1
  176. package/esm/stdlib/theme/light.js +4 -4
  177. package/esm/types/animate.d.ts +2 -2
  178. package/esm/types/behavior.d.ts +1 -1
  179. package/esm/types/combo.d.ts +7 -7
  180. package/esm/types/common.d.ts +5 -5
  181. package/esm/types/data.d.ts +6 -6
  182. package/esm/types/edge.d.ts +9 -9
  183. package/esm/types/event.d.ts +2 -1
  184. package/esm/types/graph.d.ts +48 -22
  185. package/esm/types/history.d.ts +2 -2
  186. package/esm/types/hook.d.ts +23 -3
  187. package/esm/types/index.d.ts +2 -1
  188. package/esm/types/index.js +1 -0
  189. package/esm/types/index.js.map +1 -1
  190. package/esm/types/item.d.ts +18 -12
  191. package/esm/types/item.js.map +1 -1
  192. package/esm/types/layout.d.ts +6 -6
  193. package/esm/types/loop.d.ts +2 -2
  194. package/esm/types/node.d.ts +7 -7
  195. package/esm/types/plugin.d.ts +1 -1
  196. package/esm/types/render.d.ts +1 -1
  197. package/esm/types/spec.d.ts +19 -3
  198. package/esm/types/stdlib.d.ts +1 -1
  199. package/esm/types/theme.d.ts +8 -8
  200. package/esm/types/view.d.ts +7 -2
  201. package/esm/util/bbox.d.ts +16 -1
  202. package/esm/util/bbox.js +33 -5
  203. package/esm/util/bbox.js.map +1 -1
  204. package/esm/util/behavior.d.ts +2 -2
  205. package/esm/util/behavior.js +2 -2
  206. package/esm/util/behavior.js.map +1 -1
  207. package/esm/util/data.d.ts +2 -2
  208. package/esm/util/data.js.map +1 -1
  209. package/esm/util/dom.d.ts +15 -0
  210. package/esm/util/dom.js +29 -0
  211. package/esm/util/dom.js.map +1 -0
  212. package/esm/util/event.d.ts +5 -3
  213. package/esm/util/event.js +8 -1
  214. package/esm/util/event.js.map +1 -1
  215. package/esm/util/extend.d.ts +1 -1
  216. package/esm/util/extend.js +0 -1
  217. package/esm/util/extend.js.map +1 -1
  218. package/esm/util/index.d.ts +7 -52
  219. package/esm/util/index.js +7 -23
  220. package/esm/util/index.js.map +1 -1
  221. package/esm/util/item.d.ts +16 -1
  222. package/esm/util/item.js +31 -8
  223. package/esm/util/item.js.map +1 -1
  224. package/esm/util/layout.d.ts +13 -2
  225. package/esm/util/layout.js +45 -0
  226. package/esm/util/layout.js.map +1 -1
  227. package/esm/util/loop.d.ts +1 -1
  228. package/esm/util/loop.js +4 -0
  229. package/esm/util/loop.js.map +1 -1
  230. package/esm/util/math.d.ts +1 -1
  231. package/esm/util/matrix.d.ts +6 -0
  232. package/esm/util/matrix.js +48 -0
  233. package/esm/util/matrix.js.map +1 -0
  234. package/esm/util/path.js +1 -1
  235. package/esm/util/path.js.map +1 -1
  236. package/esm/util/point.d.ts +1 -1
  237. package/esm/util/point.js +9 -2
  238. package/esm/util/point.js.map +1 -1
  239. package/esm/util/polyline.d.ts +2 -1
  240. package/esm/util/polyline.js +2 -1
  241. package/esm/util/polyline.js.map +1 -1
  242. package/esm/util/router.d.ts +1 -1
  243. package/esm/util/shape.d.ts +1 -2
  244. package/esm/util/shape.js +15 -25
  245. package/esm/util/shape.js.map +1 -1
  246. package/esm/util/shape3d.js +16 -17
  247. package/esm/util/shape3d.js.map +1 -1
  248. package/esm/util/text.d.ts +1 -1
  249. package/esm/util/text.js +3 -2
  250. package/esm/util/text.js.map +1 -1
  251. package/esm/util/warn.d.ts +14 -0
  252. package/esm/util/warn.js +4 -0
  253. package/esm/util/warn.js.map +1 -0
  254. package/lib/api-doc/graph.d.ts +3 -3
  255. package/lib/api-doc/graph.js +27 -7
  256. package/lib/api-doc/graph.js.map +1 -1
  257. package/lib/api-doc/types.d.ts +1 -0
  258. package/lib/api-doc/types.js +2 -2
  259. package/lib/api-doc/types.js.map +1 -1
  260. package/lib/constant/shape.d.ts +3 -1
  261. package/lib/index.d.ts +24 -63
  262. package/lib/index.js +18 -10
  263. package/lib/index.js.map +1 -1
  264. package/lib/item/combo.d.ts +1 -1
  265. package/lib/item/combo.js +18 -14
  266. package/lib/item/combo.js.map +1 -1
  267. package/lib/item/edge.d.ts +19 -2
  268. package/lib/item/edge.js +99 -43
  269. package/lib/item/edge.js.map +1 -1
  270. package/lib/item/item.d.ts +3 -2
  271. package/lib/item/item.js +27 -13
  272. package/lib/item/item.js.map +1 -1
  273. package/lib/item/node.d.ts +2 -8
  274. package/lib/item/node.js +31 -19
  275. package/lib/item/node.js.map +1 -1
  276. package/lib/runtime/controller/data.d.ts +7 -10
  277. package/lib/runtime/controller/data.js +125 -281
  278. package/lib/runtime/controller/data.js.map +1 -1
  279. package/lib/runtime/controller/interaction.js +9 -4
  280. package/lib/runtime/controller/interaction.js.map +1 -1
  281. package/lib/runtime/controller/item.d.ts +1 -0
  282. package/lib/runtime/controller/item.js +284 -149
  283. package/lib/runtime/controller/item.js.map +1 -1
  284. package/lib/runtime/controller/layout.js +1 -3
  285. package/lib/runtime/controller/layout.js.map +1 -1
  286. package/lib/runtime/controller/plugin.js +9 -5
  287. package/lib/runtime/controller/plugin.js.map +1 -1
  288. package/lib/runtime/graph.d.ts +104 -24
  289. package/lib/runtime/graph.js +473 -94
  290. package/lib/runtime/graph.js.map +1 -1
  291. package/lib/stdlib/behavior/activate-relations.d.ts +1 -1
  292. package/lib/stdlib/behavior/activate-relations.js +2 -2
  293. package/lib/stdlib/behavior/activate-relations.js.map +1 -1
  294. package/lib/stdlib/behavior/brush-select.d.ts +9 -3
  295. package/lib/stdlib/behavior/brush-select.js +13 -12
  296. package/lib/stdlib/behavior/brush-select.js.map +1 -1
  297. package/lib/stdlib/behavior/click-select.d.ts +1 -1
  298. package/lib/stdlib/behavior/click-select.js +1 -1
  299. package/lib/stdlib/behavior/click-select.js.map +1 -1
  300. package/lib/stdlib/behavior/collapse-expand-combo.d.ts +1 -1
  301. package/lib/stdlib/behavior/collapse-expand-tree.d.ts +1 -1
  302. package/lib/stdlib/behavior/create-edge.d.ts +57 -0
  303. package/lib/stdlib/behavior/create-edge.js +219 -0
  304. package/lib/stdlib/behavior/create-edge.js.map +1 -0
  305. package/lib/stdlib/behavior/drag-canvas.d.ts +3 -1
  306. package/lib/stdlib/behavior/drag-canvas.js +78 -33
  307. package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
  308. package/lib/stdlib/behavior/drag-combo.d.ts +3 -3
  309. package/lib/stdlib/behavior/drag-combo.js +43 -32
  310. package/lib/stdlib/behavior/drag-combo.js.map +1 -1
  311. package/lib/stdlib/behavior/drag-node.d.ts +4 -4
  312. package/lib/stdlib/behavior/drag-node.js +80 -63
  313. package/lib/stdlib/behavior/drag-node.js.map +1 -1
  314. package/lib/stdlib/behavior/index.d.ts +3 -0
  315. package/lib/stdlib/behavior/index.js +3 -0
  316. package/lib/stdlib/behavior/index.js.map +1 -1
  317. package/lib/stdlib/behavior/lasso-select.d.ts +1 -1
  318. package/lib/stdlib/behavior/lasso-select.js +6 -4
  319. package/lib/stdlib/behavior/lasso-select.js.map +1 -1
  320. package/lib/stdlib/behavior/scroll-canvas.d.ts +67 -0
  321. package/lib/stdlib/behavior/scroll-canvas.js +270 -0
  322. package/lib/stdlib/behavior/scroll-canvas.js.map +1 -0
  323. package/lib/stdlib/behavior/shortcuts-call.d.ts +38 -0
  324. package/lib/stdlib/behavior/shortcuts-call.js +91 -0
  325. package/lib/stdlib/behavior/shortcuts-call.js.map +1 -0
  326. package/lib/stdlib/behavior/zoom-canvas-3d.js +4 -1
  327. package/lib/stdlib/behavior/zoom-canvas-3d.js.map +1 -1
  328. package/lib/stdlib/behavior/zoom-canvas.d.ts +3 -1
  329. package/lib/stdlib/behavior/zoom-canvas.js +70 -26
  330. package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
  331. package/lib/stdlib/data/mapNodeSize.d.ts +2 -2
  332. package/lib/stdlib/data/mapNodeSize.js +2 -2
  333. package/lib/stdlib/data/mapNodeSize.js.map +1 -1
  334. package/lib/stdlib/data/transformV4Data.d.ts +2 -2
  335. package/lib/stdlib/data/transformV4Data.js +2 -2
  336. package/lib/stdlib/data/transformV4Data.js.map +1 -1
  337. package/lib/stdlib/data/validateData.d.ts +2 -2
  338. package/lib/stdlib/data/validateData.js +13 -12
  339. package/lib/stdlib/data/validateData.js.map +1 -1
  340. package/lib/stdlib/index.d.ts +18 -6
  341. package/lib/stdlib/index.js +22 -10
  342. package/lib/stdlib/index.js.map +1 -1
  343. package/lib/stdlib/item/edge/base.d.ts +3 -5
  344. package/lib/stdlib/item/edge/base.js +30 -29
  345. package/lib/stdlib/item/edge/base.js.map +1 -1
  346. package/lib/stdlib/item/edge/cubic-horizontal.js.map +1 -1
  347. package/lib/stdlib/item/edge/cubic-vertical.js.map +1 -1
  348. package/lib/stdlib/item/edge/cubic.js +2 -2
  349. package/lib/stdlib/item/edge/cubic.js.map +1 -1
  350. package/lib/stdlib/item/edge/loop.js +3 -3
  351. package/lib/stdlib/item/edge/loop.js.map +1 -1
  352. package/lib/stdlib/item/node/base.d.ts +3 -6
  353. package/lib/stdlib/item/node/base.js +29 -59
  354. package/lib/stdlib/item/node/base.js.map +1 -1
  355. package/lib/stdlib/item/node/base3d.d.ts +1 -0
  356. package/lib/stdlib/item/node/base3d.js +1 -0
  357. package/lib/stdlib/item/node/base3d.js.map +1 -1
  358. package/lib/stdlib/item/node/cube.d.ts +35 -0
  359. package/lib/stdlib/item/node/cube.js +58 -0
  360. package/lib/stdlib/item/node/cube.js.map +1 -0
  361. package/lib/stdlib/item/node/diamond.js +1 -1
  362. package/lib/stdlib/item/node/donut.d.ts +3 -3
  363. package/lib/stdlib/item/node/ellipse.js +2 -2
  364. package/lib/stdlib/item/node/hexagon.js +6 -2
  365. package/lib/stdlib/item/node/hexagon.js.map +1 -1
  366. package/lib/stdlib/item/node/image.d.ts +40 -0
  367. package/lib/stdlib/item/node/image.js +114 -0
  368. package/lib/stdlib/item/node/image.js.map +1 -0
  369. package/lib/stdlib/item/node/index.d.ts +4 -0
  370. package/lib/stdlib/item/node/index.js +4 -0
  371. package/lib/stdlib/item/node/index.js.map +1 -1
  372. package/lib/stdlib/plugin/edgeFilterLens/index.d.ts +66 -0
  373. package/lib/stdlib/plugin/edgeFilterLens/index.js +313 -0
  374. package/lib/stdlib/plugin/edgeFilterLens/index.js.map +1 -0
  375. package/lib/stdlib/plugin/grid/index.d.ts +1 -1
  376. package/lib/stdlib/plugin/grid/index.js +6 -7
  377. package/lib/stdlib/plugin/grid/index.js.map +1 -1
  378. package/lib/stdlib/plugin/history/combo-command.js +2 -2
  379. package/lib/stdlib/plugin/history/combo-command.js.map +1 -1
  380. package/lib/stdlib/plugin/history/index.d.ts +10 -10
  381. package/lib/stdlib/plugin/history/index.js +14 -14
  382. package/lib/stdlib/plugin/history/index.js.map +1 -1
  383. package/lib/stdlib/plugin/history/item-data-command.js +25 -16
  384. package/lib/stdlib/plugin/history/item-data-command.js.map +1 -1
  385. package/lib/stdlib/plugin/history/layer-updated-command.js +2 -2
  386. package/lib/stdlib/plugin/history/layer-updated-command.js.map +1 -1
  387. package/lib/stdlib/plugin/history/state-updated-command.js +1 -1
  388. package/lib/stdlib/plugin/history/state-updated-command.js.map +1 -1
  389. package/lib/stdlib/plugin/history/visibility-updated-command.js +2 -2
  390. package/lib/stdlib/plugin/history/visibility-updated-command.js.map +1 -1
  391. package/lib/stdlib/plugin/hull/convexHull.d.ts +1 -1
  392. package/lib/stdlib/plugin/hull/hullComponent.d.ts +2 -2
  393. package/lib/stdlib/plugin/hull/hullComponent.js +5 -9
  394. package/lib/stdlib/plugin/hull/hullComponent.js.map +1 -1
  395. package/lib/stdlib/plugin/hull/util.d.ts +2 -2
  396. package/lib/stdlib/plugin/hull/util.js +26 -22
  397. package/lib/stdlib/plugin/hull/util.js.map +1 -1
  398. package/lib/stdlib/plugin/index.d.ts +2 -0
  399. package/lib/stdlib/plugin/index.js +2 -0
  400. package/lib/stdlib/plugin/index.js.map +1 -1
  401. package/lib/stdlib/plugin/legend/index.d.ts +3 -3
  402. package/lib/stdlib/plugin/legend/index.js +3 -3
  403. package/lib/stdlib/plugin/legend/index.js.map +1 -1
  404. package/lib/stdlib/plugin/menu/index.d.ts +4 -4
  405. package/lib/stdlib/plugin/menu/index.js +6 -6
  406. package/lib/stdlib/plugin/menu/index.js.map +1 -1
  407. package/lib/stdlib/plugin/minimap/index.d.ts +6 -2
  408. package/lib/stdlib/plugin/minimap/index.js +121 -14
  409. package/lib/stdlib/plugin/minimap/index.js.map +1 -1
  410. package/lib/stdlib/plugin/snapline/index.d.ts +167 -0
  411. package/lib/stdlib/plugin/snapline/index.js +1067 -0
  412. package/lib/stdlib/plugin/snapline/index.js.map +1 -0
  413. package/lib/stdlib/plugin/timebar/index.d.ts +4 -4
  414. package/lib/stdlib/plugin/timebar/index.js +6 -6
  415. package/lib/stdlib/plugin/timebar/index.js.map +1 -1
  416. package/lib/stdlib/plugin/toolbar/index.d.ts +3 -3
  417. package/lib/stdlib/plugin/toolbar/index.js +5 -5
  418. package/lib/stdlib/plugin/toolbar/index.js.map +1 -1
  419. package/lib/stdlib/plugin/tooltip/index.d.ts +5 -5
  420. package/lib/stdlib/plugin/tooltip/index.js +10 -11
  421. package/lib/stdlib/plugin/tooltip/index.js.map +1 -1
  422. package/lib/stdlib/plugin/types.d.ts +2 -0
  423. package/lib/stdlib/plugin/watermaker/index.d.ts +78 -0
  424. package/lib/stdlib/plugin/watermaker/index.js +247 -0
  425. package/lib/stdlib/plugin/watermaker/index.js.map +1 -0
  426. package/lib/stdlib/theme/dark.js +42 -2
  427. package/lib/stdlib/theme/dark.js.map +1 -1
  428. package/lib/stdlib/theme/light.js +4 -4
  429. package/lib/types/animate.d.ts +2 -2
  430. package/lib/types/behavior.d.ts +1 -1
  431. package/lib/types/combo.d.ts +7 -7
  432. package/lib/types/common.d.ts +5 -5
  433. package/lib/types/data.d.ts +6 -6
  434. package/lib/types/edge.d.ts +9 -9
  435. package/lib/types/event.d.ts +2 -1
  436. package/lib/types/event.js +2 -2
  437. package/lib/types/event.js.map +1 -1
  438. package/lib/types/graph.d.ts +48 -22
  439. package/lib/types/history.d.ts +2 -2
  440. package/lib/types/history.js +1 -1
  441. package/lib/types/history.js.map +1 -1
  442. package/lib/types/hook.d.ts +23 -3
  443. package/lib/types/index.d.ts +2 -1
  444. package/lib/types/index.js +3 -1
  445. package/lib/types/index.js.map +1 -1
  446. package/lib/types/item.d.ts +18 -12
  447. package/lib/types/item.js +1 -1
  448. package/lib/types/item.js.map +1 -1
  449. package/lib/types/layout.d.ts +6 -6
  450. package/lib/types/loop.d.ts +2 -2
  451. package/lib/types/loop.js +1 -1
  452. package/lib/types/loop.js.map +1 -1
  453. package/lib/types/node.d.ts +7 -7
  454. package/lib/types/plugin.d.ts +1 -1
  455. package/lib/types/render.d.ts +1 -1
  456. package/lib/types/spec.d.ts +19 -3
  457. package/lib/types/stdlib.d.ts +1 -1
  458. package/lib/types/theme.d.ts +8 -8
  459. package/lib/types/view.d.ts +7 -2
  460. package/lib/util/bbox.d.ts +16 -1
  461. package/lib/util/bbox.js +36 -6
  462. package/lib/util/bbox.js.map +1 -1
  463. package/lib/util/behavior.d.ts +2 -2
  464. package/lib/util/behavior.js +2 -2
  465. package/lib/util/behavior.js.map +1 -1
  466. package/lib/util/data.d.ts +2 -2
  467. package/lib/util/data.js.map +1 -1
  468. package/lib/util/dom.d.ts +15 -0
  469. package/lib/util/dom.js +34 -0
  470. package/lib/util/dom.js.map +1 -0
  471. package/lib/util/event.d.ts +5 -3
  472. package/lib/util/event.js +8 -1
  473. package/lib/util/event.js.map +1 -1
  474. package/lib/util/extend.d.ts +1 -1
  475. package/lib/util/extend.js +0 -1
  476. package/lib/util/extend.js.map +1 -1
  477. package/lib/util/index.d.ts +7 -52
  478. package/lib/util/index.js +23 -23
  479. package/lib/util/index.js.map +1 -1
  480. package/lib/util/item.d.ts +16 -1
  481. package/lib/util/item.js +33 -9
  482. package/lib/util/item.js.map +1 -1
  483. package/lib/util/layout.d.ts +13 -2
  484. package/lib/util/layout.js +47 -1
  485. package/lib/util/layout.js.map +1 -1
  486. package/lib/util/loop.d.ts +1 -1
  487. package/lib/util/loop.js +4 -0
  488. package/lib/util/loop.js.map +1 -1
  489. package/lib/util/math.d.ts +1 -1
  490. package/lib/util/matrix.d.ts +6 -0
  491. package/lib/util/matrix.js +52 -0
  492. package/lib/util/matrix.js.map +1 -0
  493. package/lib/util/path.js +2 -2
  494. package/lib/util/path.js.map +1 -1
  495. package/lib/util/point.d.ts +1 -1
  496. package/lib/util/point.js +9 -2
  497. package/lib/util/point.js.map +1 -1
  498. package/lib/util/polyline.d.ts +2 -1
  499. package/lib/util/polyline.js +2 -1
  500. package/lib/util/polyline.js.map +1 -1
  501. package/lib/util/router.d.ts +1 -1
  502. package/lib/util/shape.d.ts +1 -2
  503. package/lib/util/shape.js +16 -26
  504. package/lib/util/shape.js.map +1 -1
  505. package/lib/util/shape3d.js +15 -16
  506. package/lib/util/shape3d.js.map +1 -1
  507. package/lib/util/text.d.ts +1 -1
  508. package/lib/util/text.js +3 -2
  509. package/lib/util/text.js.map +1 -1
  510. package/lib/util/warn.d.ts +14 -0
  511. package/lib/util/warn.js +8 -0
  512. package/lib/util/warn.js.map +1 -0
  513. package/package.json +41 -50
  514. package/src/api-doc/graph.ts +4 -3
  515. package/src/api-doc/types.ts +1 -0
  516. package/src/constant/shape.ts +1 -1
  517. package/src/index.ts +5 -6
  518. package/src/item/combo.ts +16 -15
  519. package/src/item/edge.ts +135 -57
  520. package/src/item/item.ts +32 -19
  521. package/src/item/node.ts +36 -50
  522. package/src/runtime/controller/data.ts +140 -339
  523. package/src/runtime/controller/interaction.ts +10 -4
  524. package/src/runtime/controller/item.ts +261 -78
  525. package/src/runtime/controller/layout.ts +1 -5
  526. package/src/runtime/controller/plugin.ts +15 -4
  527. package/src/runtime/graph.ts +605 -103
  528. package/src/stdlib/behavior/activate-relations.ts +2 -2
  529. package/src/stdlib/behavior/brush-select.ts +14 -13
  530. package/src/stdlib/behavior/click-select.ts +1 -1
  531. package/src/stdlib/behavior/create-edge.ts +305 -0
  532. package/src/stdlib/behavior/drag-canvas.ts +107 -35
  533. package/src/stdlib/behavior/drag-combo.ts +10 -10
  534. package/src/stdlib/behavior/drag-node.ts +27 -18
  535. package/src/stdlib/behavior/index.ts +3 -0
  536. package/src/stdlib/behavior/lasso-select.ts +7 -5
  537. package/src/stdlib/behavior/scroll-canvas.ts +348 -0
  538. package/src/stdlib/behavior/shortcuts-call.ts +129 -0
  539. package/src/stdlib/behavior/zoom-canvas-3d.ts +4 -1
  540. package/src/stdlib/behavior/zoom-canvas.ts +98 -27
  541. package/src/stdlib/data/mapNodeSize.ts +2 -2
  542. package/src/stdlib/data/transformV4Data.ts +2 -2
  543. package/src/stdlib/data/validateData.ts +16 -16
  544. package/src/stdlib/index.ts +28 -7
  545. package/src/stdlib/item/edge/base.ts +32 -41
  546. package/src/stdlib/item/edge/cubic-horizontal.ts +0 -1
  547. package/src/stdlib/item/edge/cubic-vertical.ts +0 -1
  548. package/src/stdlib/item/edge/cubic.ts +1 -1
  549. package/src/stdlib/item/edge/loop.ts +1 -1
  550. package/src/stdlib/item/node/base.ts +38 -65
  551. package/src/stdlib/item/node/base3d.ts +1 -0
  552. package/src/stdlib/item/node/cube.ts +102 -0
  553. package/src/stdlib/item/node/diamond.ts +1 -1
  554. package/src/stdlib/item/node/ellipse.ts +2 -2
  555. package/src/stdlib/item/node/hexagon.ts +6 -2
  556. package/src/stdlib/item/node/image.ts +190 -0
  557. package/src/stdlib/item/node/index.ts +4 -0
  558. package/src/stdlib/plugin/edgeFilterLens/index.ts +387 -0
  559. package/src/stdlib/plugin/grid/index.ts +6 -6
  560. package/src/stdlib/plugin/history/combo-command.ts +2 -2
  561. package/src/stdlib/plugin/history/index.ts +14 -14
  562. package/src/stdlib/plugin/history/item-data-command.ts +35 -17
  563. package/src/stdlib/plugin/history/layer-updated-command.ts +2 -2
  564. package/src/stdlib/plugin/history/state-updated-command.ts +1 -1
  565. package/src/stdlib/plugin/history/visibility-updated-command.ts +2 -2
  566. package/src/stdlib/plugin/hull/convexHull.ts +1 -1
  567. package/src/stdlib/plugin/hull/hullComponent.ts +10 -8
  568. package/src/stdlib/plugin/hull/util.ts +6 -2
  569. package/src/stdlib/plugin/index.ts +2 -0
  570. package/src/stdlib/plugin/legend/index.ts +6 -6
  571. package/src/stdlib/plugin/menu/index.ts +13 -13
  572. package/src/stdlib/plugin/minimap/index.ts +126 -16
  573. package/src/stdlib/plugin/snapline/index.ts +1297 -0
  574. package/src/stdlib/plugin/timebar/index.ts +4 -4
  575. package/src/stdlib/plugin/toolbar/index.ts +8 -8
  576. package/src/stdlib/plugin/tooltip/index.ts +10 -10
  577. package/src/stdlib/plugin/types.ts +2 -0
  578. package/src/stdlib/plugin/watermaker/index.ts +302 -0
  579. package/src/stdlib/theme/dark.ts +66 -2
  580. package/src/stdlib/theme/light.ts +4 -4
  581. package/src/types/event.ts +1 -0
  582. package/src/types/graph.ts +62 -25
  583. package/src/types/hook.ts +22 -2
  584. package/src/types/index.ts +2 -1
  585. package/src/types/item.ts +10 -0
  586. package/src/types/plugin.ts +1 -1
  587. package/src/types/spec.ts +22 -3
  588. package/src/types/view.ts +8 -3
  589. package/src/util/bbox.ts +42 -6
  590. package/src/util/behavior.ts +4 -4
  591. package/src/util/data.ts +2 -3
  592. package/src/util/dom.ts +33 -0
  593. package/src/util/event.ts +14 -1
  594. package/src/util/extend.ts +2 -3
  595. package/src/util/index.ts +7 -24
  596. package/src/util/item.ts +65 -28
  597. package/src/util/layout.ts +48 -2
  598. package/src/util/loop.ts +5 -1
  599. package/src/util/math.ts +1 -1
  600. package/src/util/matrix.ts +66 -0
  601. package/src/util/path.ts +1 -1
  602. package/src/util/point.ts +9 -4
  603. package/src/util/polyline.ts +2 -1
  604. package/src/util/router.ts +1 -1
  605. package/src/util/shape.ts +22 -26
  606. package/src/util/shape3d.ts +20 -20
  607. package/src/util/text.ts +3 -1
  608. package/src/util/warn.ts +20 -0
@@ -0,0 +1,1297 @@
1
+ import { ID } from '@antv/graphlib';
2
+ import { AABB, DisplayObject } from '@antv/g';
3
+ import { throttle } from '@antv/util';
4
+ import { ITEM_TYPE, ShapeStyle } from '../../../types/item';
5
+ import { IG6GraphEvent, IGraph, NodeModel } from '../../../types';
6
+ import { Plugin as Base, IPluginBaseConfig } from '../../../types/plugin';
7
+ import { Point } from '../../../types/common';
8
+
9
+ export interface SnapLineConfig extends IPluginBaseConfig {
10
+ // snapline type
11
+ line?: ShapeStyle;
12
+ // snapline align type. true means 'horizontal' and 'vertical'
13
+ itemAlignType?: boolean | 'horizontal' | 'vertical' | 'center';
14
+ }
15
+
16
+ /**
17
+ * draw line position
18
+ */
19
+ type LinePosition = 'top' | 'hcenter' | 'bottom' | 'left' | 'vcenter' | 'right';
20
+
21
+ /**
22
+ * Line for draw
23
+ * first point: point on constractItem
24
+ * second point: point on draggingItem
25
+ */
26
+ type DrawLine = { line: [Point, Point]; lp: LinePosition };
27
+
28
+ /**
29
+ * dl: draw line for choose
30
+ * offset: offset that selects the drawline with the smallest gap
31
+ */
32
+ type DrawLineForChoose = { dl: DrawLine; offset: Point };
33
+
34
+ export class Snapline extends Base {
35
+ //#region state: historyPoints
36
+ private historyPoints: [Point | undefined, Point | undefined] = [
37
+ undefined,
38
+ undefined,
39
+ ];
40
+
41
+ /**
42
+ * when start drag, offset of cursor and node center (event.canvas - draggingnode.BBox)
43
+ */
44
+ private initialOffset: [
45
+ offsetX: number | undefined,
46
+ offsetY: number | undefined,
47
+ ] = [undefined, undefined];
48
+
49
+ /**
50
+ * Cache the nodes' positions to be throttly updated.
51
+ */
52
+ private updateCache: Map<ID, NodeModel> = new Map();
53
+
54
+ /**
55
+ * Gets the current cursor node and center offset and then with initialOffset difference
56
+ */
57
+ private getCurOffsetCompareToInitialOffset = (
58
+ e: IG6GraphEvent,
59
+ ): [number | undefined, number | undefined] => {
60
+ if (
61
+ this.initialOffset[0] === undefined ||
62
+ this.initialOffset[1] === undefined
63
+ ) {
64
+ return [undefined, undefined];
65
+ }
66
+
67
+ const curOffset: [curOffsetX: number, curOffsetY: number] = [
68
+ e.canvas.x - this.draggingBBox.center[0],
69
+ e.canvas.y - this.draggingBBox.center[1],
70
+ ];
71
+
72
+ return [
73
+ curOffset[0] - this.initialOffset[0],
74
+ curOffset[1] - this.initialOffset[1],
75
+ ];
76
+ };
77
+
78
+ private dragging = false;
79
+ private draggingBBox: AABB = undefined;
80
+
81
+ // Gets the offset between the cursor and draggingItem
82
+ private getPointerOffsetWithItem = (pointer: {
83
+ x: number;
84
+ y: number;
85
+ }): { x: number; y: number } => {
86
+ return {
87
+ x: Math.abs(pointer.x - this.draggingBBox.center[0]),
88
+ y: Math.abs(pointer.x - this.draggingBBox.center[1]),
89
+ };
90
+ };
91
+
92
+ //#region state: tolerance
93
+ public tolerance = 4;
94
+ public toleranceFactor = 2;
95
+ public setTolerance(tolerance: number) {
96
+ this.tolerance = tolerance;
97
+ }
98
+ public getTolerance(): number {
99
+ return this.tolerance;
100
+ }
101
+ //#endregion
102
+
103
+ // All the lines in the vertical direction
104
+ private vContrastPoints: Point[] = [];
105
+ private hContrastPoints: Point[] = [];
106
+
107
+ /**
108
+ * alignLinesForChoose container
109
+ */
110
+ private alignLinesForChoose: {
111
+ v: DrawLineForChoose[];
112
+ h: DrawLineForChoose[];
113
+ } = { v: [], h: [] };
114
+
115
+ /**
116
+ * getDrawLineId via DrawLine
117
+ * Principle: the lines on the drawing board is the only load-point
118
+ * @param dl drawLine
119
+ */
120
+ getDrawLineIdByDrawLine(dl: DrawLine): ID {
121
+ if (!dl) return;
122
+ return `${dl.line[0].x}-${dl.line[0].y}-${dl.line[1].x}-${dl.line[1].y}`;
123
+ }
124
+ /**
125
+ *
126
+ * @param cp based on constractBBox's point
127
+ * @param dp based on draggingBBox point
128
+ * @returns
129
+ */
130
+ getDrawLineIdByPoints([cp, dp]: [Point, Point]): ID {
131
+ return `${cp.x}-${cp.y}-${dp.x}-${dp.y}`;
132
+ }
133
+
134
+ /**
135
+ * all AlignLines satisfy conditions: in the tolerance range
136
+ */
137
+ addAlignLinesForChoose() {
138
+ function isInToleranceRange(
139
+ xOrY: number,
140
+ contrast: number,
141
+ tolerance: number,
142
+ ): boolean {
143
+ return xOrY >= contrast - tolerance && xOrY <= contrast + tolerance;
144
+ }
145
+
146
+ this.vContrastPoints.forEach((vpoint) => {
147
+ if (
148
+ isInToleranceRange(this.draggingBBox.min[0], vpoint.x, this.tolerance)
149
+ )
150
+ this.alignLinesForChoose.v.push({
151
+ dl: {
152
+ line: [vpoint, { x: vpoint.x, y: this.draggingBBox.center[1] }],
153
+ lp: 'left',
154
+ },
155
+ offset: { x: vpoint.x - this.draggingBBox.min[0], y: 0 },
156
+ });
157
+ if (
158
+ isInToleranceRange(
159
+ this.draggingBBox.center[0],
160
+ vpoint.x,
161
+ this.tolerance,
162
+ )
163
+ )
164
+ this.alignLinesForChoose.v.push({
165
+ dl: {
166
+ line: [vpoint, { x: vpoint.x, y: this.draggingBBox.center[1] }],
167
+ lp: 'vcenter',
168
+ },
169
+ offset: { x: vpoint.x - this.draggingBBox.center[0], y: 0 },
170
+ });
171
+ if (
172
+ isInToleranceRange(this.draggingBBox.max[0], vpoint.x, this.tolerance)
173
+ )
174
+ this.alignLinesForChoose.v.push({
175
+ dl: {
176
+ line: [vpoint, { x: vpoint.x, y: this.draggingBBox.center[1] }],
177
+ lp: 'right',
178
+ },
179
+ offset: { x: vpoint.x - this.draggingBBox.max[0], y: 0 },
180
+ });
181
+ });
182
+
183
+ this.hContrastPoints.forEach((hpoint) => {
184
+ if (
185
+ isInToleranceRange(this.draggingBBox.min[1], hpoint.y, this.tolerance)
186
+ )
187
+ this.alignLinesForChoose.v.push({
188
+ dl: {
189
+ line: [hpoint, { x: this.draggingBBox.min[0], y: hpoint.y }],
190
+ lp: 'top',
191
+ },
192
+ offset: { x: 0, y: hpoint.y - this.draggingBBox.min[1] },
193
+ });
194
+ if (
195
+ isInToleranceRange(
196
+ this.draggingBBox.center[1],
197
+ hpoint.y,
198
+ this.tolerance,
199
+ )
200
+ )
201
+ this.alignLinesForChoose.v.push({
202
+ dl: {
203
+ line: [hpoint, { x: this.draggingBBox.center[0], y: hpoint.y }],
204
+ lp: 'hcenter',
205
+ },
206
+ offset: { x: 0, y: hpoint.y - this.draggingBBox.center[1] },
207
+ });
208
+ if (
209
+ isInToleranceRange(this.draggingBBox.max[1], hpoint.y, this.tolerance)
210
+ )
211
+ this.alignLinesForChoose.v.push({
212
+ dl: {
213
+ line: [hpoint, { x: this.draggingBBox.max[0], y: hpoint.y }],
214
+ lp: 'bottom',
215
+ },
216
+ offset: { x: 0, y: hpoint.y - this.draggingBBox.max[1] },
217
+ });
218
+ });
219
+ }
220
+
221
+ initAlignLinesForChoose() {
222
+ this.alignLinesForChoose.v = [];
223
+ this.alignLinesForChoose.h = [];
224
+
225
+ let allIds: ID[] = [];
226
+
227
+ this.graph.getAllCombosData().forEach((item) => {
228
+ allIds.push(item.id);
229
+ });
230
+ this.graph.getAllNodesData().forEach((item) => {
231
+ allIds.push(item.id);
232
+ });
233
+ allIds = allIds.filter((item) => item !== this.dragItemId); // 排除drag item
234
+
235
+ allIds.forEach((id) => {
236
+ const cb = this.graph.getRenderBBox(id, true) as AABB; // contrast bbox
237
+ // 判断2个方向,6条线的对比
238
+
239
+ /* draggingBBox left */
240
+ if (Math.abs(this.draggingBBox.min[0] - cb.min[0]) <= this.tolerance) {
241
+ this.alignLinesForChoose.v.push({
242
+ dl: {
243
+ line: [
244
+ { x: cb.min[0], y: cb.center[1] },
245
+ { x: cb.min[0], y: this.draggingBBox.center[1] },
246
+ ],
247
+ lp: 'left',
248
+ },
249
+ offset: {
250
+ x: this.draggingBBox.min[0] - cb.min[0],
251
+ y: this.draggingBBox.center[1] - cb.center[1],
252
+ },
253
+ });
254
+ }
255
+ if (Math.abs(this.draggingBBox.min[0] - cb.center[0]) <= this.tolerance) {
256
+ this.alignLinesForChoose.v.push({
257
+ dl: {
258
+ line: [
259
+ { x: cb.center[0], y: cb.center[1] },
260
+ { x: cb.center[0], y: this.draggingBBox.center[1] },
261
+ ],
262
+ lp: 'left',
263
+ },
264
+ offset: {
265
+ x: this.draggingBBox.min[0] - cb.center[0],
266
+ y: this.draggingBBox.center[1] - cb.center[1],
267
+ },
268
+ });
269
+ }
270
+ if (Math.abs(this.draggingBBox.min[0] - cb.max[0]) <= this.tolerance) {
271
+ this.alignLinesForChoose.v.push({
272
+ dl: {
273
+ line: [
274
+ { x: cb.max[0], y: cb.center[1] },
275
+ { x: cb.max[0], y: this.draggingBBox.center[1] },
276
+ ],
277
+ lp: 'left',
278
+ },
279
+ offset: {
280
+ x: this.draggingBBox.min[0] - cb.max[0],
281
+ y: this.draggingBBox.center[1] - cb.center[1],
282
+ },
283
+ });
284
+ }
285
+
286
+ /* draggingBBox vcenter */
287
+ if (Math.abs(this.draggingBBox.center[0] - cb.min[0]) <= this.tolerance) {
288
+ this.alignLinesForChoose.v.push({
289
+ dl: {
290
+ line: [
291
+ { x: cb.min[0], y: cb.center[1] },
292
+ { x: cb.min[0], y: this.draggingBBox.center[1] },
293
+ ],
294
+ lp: 'vcenter',
295
+ },
296
+ offset: {
297
+ x: this.draggingBBox.center[0] - cb.min[0],
298
+ y: this.draggingBBox.center[1] - cb.center[1],
299
+ },
300
+ });
301
+ }
302
+ if (
303
+ Math.abs(this.draggingBBox.center[0] - cb.center[0]) <= this.tolerance
304
+ ) {
305
+ this.alignLinesForChoose.v.push({
306
+ dl: {
307
+ line: [
308
+ { x: cb.center[0], y: cb.center[1] },
309
+ { x: cb.center[0], y: this.draggingBBox.center[1] },
310
+ ],
311
+ lp: 'vcenter',
312
+ },
313
+ offset: {
314
+ x: this.draggingBBox.center[0] - cb.center[0],
315
+ y: this.draggingBBox.center[1] - cb.center[1],
316
+ },
317
+ });
318
+ }
319
+ if (Math.abs(this.draggingBBox.center[0] - cb.max[0]) <= this.tolerance) {
320
+ this.alignLinesForChoose.v.push({
321
+ dl: {
322
+ line: [
323
+ { x: cb.max[0], y: cb.center[1] },
324
+ { x: cb.max[0], y: this.draggingBBox.center[1] },
325
+ ],
326
+ lp: 'vcenter',
327
+ },
328
+ offset: {
329
+ x: this.draggingBBox.center[0] - cb.max[0],
330
+ y: this.draggingBBox.center[1] - cb.center[1],
331
+ },
332
+ });
333
+ }
334
+
335
+ /* draggingBBox right */
336
+ if (Math.abs(this.draggingBBox.max[0] - cb.min[0]) <= this.tolerance) {
337
+ this.alignLinesForChoose.v.push({
338
+ dl: {
339
+ line: [
340
+ { x: cb.min[0], y: cb.center[1] },
341
+ { x: cb.min[0], y: this.draggingBBox.center[1] },
342
+ ],
343
+ lp: 'right',
344
+ },
345
+ offset: {
346
+ x: this.draggingBBox.max[0] - cb.min[0],
347
+ y: this.draggingBBox.center[1] - cb.center[1],
348
+ },
349
+ });
350
+ }
351
+ if (Math.abs(this.draggingBBox.max[0] - cb.center[0]) <= this.tolerance) {
352
+ this.alignLinesForChoose.v.push({
353
+ dl: {
354
+ line: [
355
+ { x: cb.center[0], y: cb.center[1] },
356
+ { x: cb.center[0], y: this.draggingBBox.center[1] },
357
+ ],
358
+ lp: 'right',
359
+ },
360
+ offset: {
361
+ x: this.draggingBBox.max[0] - cb.center[0],
362
+ y: this.draggingBBox.center[1] - cb.center[1],
363
+ },
364
+ });
365
+ }
366
+ if (Math.abs(this.draggingBBox.max[0] - cb.max[0]) <= this.tolerance) {
367
+ this.alignLinesForChoose.v.push({
368
+ dl: {
369
+ line: [
370
+ { x: cb.max[0], y: cb.center[1] },
371
+ { x: cb.max[0], y: this.draggingBBox.center[1] },
372
+ ],
373
+ lp: 'right',
374
+ },
375
+ offset: {
376
+ x: this.draggingBBox.max[0] - cb.max[0],
377
+ y: this.draggingBBox.center[1] - cb.center[1],
378
+ },
379
+ });
380
+ }
381
+
382
+ /* draggingBBox top */
383
+ if (Math.abs(this.draggingBBox.min[1] - cb.max[1]) <= this.tolerance) {
384
+ this.alignLinesForChoose.h.push({
385
+ dl: {
386
+ line: [
387
+ { x: cb.center[0], y: cb.max[1] },
388
+ { x: this.draggingBBox.center[0], y: cb.max[1] },
389
+ ],
390
+ lp: 'top',
391
+ },
392
+ offset: {
393
+ x: this.draggingBBox.center[0] - cb.center[0],
394
+ y: this.draggingBBox.min[1] - cb.max[1],
395
+ },
396
+ });
397
+ }
398
+ if (Math.abs(this.draggingBBox.min[1] - cb.center[1]) <= this.tolerance) {
399
+ this.alignLinesForChoose.h.push({
400
+ dl: {
401
+ line: [
402
+ { x: cb.center[0], y: cb.center[1] },
403
+ { x: this.draggingBBox.center[0], y: cb.center[1] },
404
+ ],
405
+ lp: 'top',
406
+ },
407
+ offset: {
408
+ x: this.draggingBBox.center[0] - cb.center[0],
409
+ y: this.draggingBBox.min[1] - cb.center[1],
410
+ },
411
+ });
412
+ }
413
+ if (Math.abs(this.draggingBBox.min[1] - cb.min[1]) <= this.tolerance) {
414
+ this.alignLinesForChoose.h.push({
415
+ dl: {
416
+ line: [
417
+ { x: cb.center[0], y: cb.max[1] },
418
+ { x: this.draggingBBox.center[0], y: cb.max[1] },
419
+ ],
420
+ lp: 'top',
421
+ },
422
+ offset: {
423
+ x: this.draggingBBox.center[0] - cb.center[0],
424
+ y: this.draggingBBox.min[1] - cb.min[1],
425
+ },
426
+ });
427
+ }
428
+
429
+ /* draggingBBox hcenter */
430
+ if (Math.abs(this.draggingBBox.center[1] - cb.max[1]) <= this.tolerance) {
431
+ this.alignLinesForChoose.h.push({
432
+ dl: {
433
+ line: [
434
+ { x: cb.center[0], y: cb.max[1] },
435
+ { x: this.draggingBBox.center[0], y: cb.max[1] },
436
+ ],
437
+ lp: 'hcenter',
438
+ },
439
+ offset: {
440
+ x: this.draggingBBox.center[0] - cb.center[0],
441
+ y: this.draggingBBox.center[1] - cb.max[1],
442
+ },
443
+ });
444
+ }
445
+ if (
446
+ Math.abs(this.draggingBBox.center[1] - cb.center[1]) <= this.tolerance
447
+ ) {
448
+ this.alignLinesForChoose.h.push({
449
+ dl: {
450
+ line: [
451
+ { x: cb.center[0], y: cb.center[1] },
452
+ { x: this.draggingBBox.center[0], y: cb.center[1] },
453
+ ],
454
+ lp: 'hcenter',
455
+ },
456
+ offset: {
457
+ x: this.draggingBBox.center[0] - cb.center[0],
458
+ y: this.draggingBBox.center[1] - cb.center[1],
459
+ },
460
+ });
461
+ }
462
+ if (Math.abs(this.draggingBBox.center[1] - cb.min[1]) <= this.tolerance) {
463
+ this.alignLinesForChoose.h.push({
464
+ dl: {
465
+ line: [
466
+ { x: cb.center[0], y: cb.min[1] },
467
+ { x: this.draggingBBox.center[0], y: cb.min[1] },
468
+ ],
469
+ lp: 'hcenter',
470
+ },
471
+ offset: {
472
+ x: this.draggingBBox.center[0] - cb.center[0],
473
+ y: this.draggingBBox.center[1] - cb.min[1],
474
+ },
475
+ });
476
+ }
477
+
478
+ /* draggingBBox bottom */
479
+ if (Math.abs(this.draggingBBox.max[1] - cb.max[1]) <= this.tolerance) {
480
+ this.alignLinesForChoose.h.push({
481
+ dl: {
482
+ line: [
483
+ { x: cb.center[0], y: cb.max[1] },
484
+ { x: this.draggingBBox.center[0], y: cb.max[1] },
485
+ ],
486
+ lp: 'bottom',
487
+ },
488
+ offset: {
489
+ x: this.draggingBBox.center[0] - cb.center[0],
490
+ y: this.draggingBBox.max[1] - cb.max[1],
491
+ },
492
+ });
493
+ }
494
+ if (Math.abs(this.draggingBBox.max[1] - cb.center[1]) <= this.tolerance) {
495
+ this.alignLinesForChoose.h.push({
496
+ dl: {
497
+ line: [
498
+ { x: cb.center[0], y: cb.center[1] },
499
+ { x: this.draggingBBox.center[0], y: cb.center[1] },
500
+ ],
501
+ lp: 'bottom',
502
+ },
503
+ offset: {
504
+ x: this.draggingBBox.center[0] - cb.center[0],
505
+ y: this.draggingBBox.max[1] - cb.center[1],
506
+ },
507
+ });
508
+ }
509
+ if (Math.abs(this.draggingBBox.max[1] - cb.min[1]) <= this.tolerance) {
510
+ this.alignLinesForChoose.h.push({
511
+ dl: {
512
+ line: [
513
+ { x: cb.center[0], y: cb.min[1] },
514
+ { x: this.draggingBBox.center[0], y: cb.min[1] },
515
+ ],
516
+ lp: 'bottom',
517
+ },
518
+ offset: {
519
+ x: this.draggingBBox.center[0] - cb.center[0],
520
+ y: this.draggingBBox.max[1] - cb.min[1],
521
+ },
522
+ });
523
+ }
524
+ });
525
+ }
526
+
527
+ chooseAlignLine(): { v: DrawLine | undefined; h: DrawLine | undefined } {
528
+ // Principles:
529
+ // 1. Smaller difference from tolerance is more important
530
+ // 2. Same tolerance, (if multiple lines in the same direction are within the tolerance range) Importance: hcenter > top > bottom; vcenter > left > right
531
+ // 3. At most: vertical one count; horizon one count
532
+ // 4. Repeat line, will be subject to the longest (note: can't go to heavy, for performance, in the array of selected again)
533
+
534
+ // v direction line selection rule: draggingBBox's left/vcenter/right compares to vContrastPoints
535
+ // h direction line selection rule: draggingBBox's top/hcenter/bottom compares to hContrastPoints
536
+
537
+ if (
538
+ this.alignLinesForChoose.v.length + this.alignLinesForChoose.h.length ===
539
+ 0
540
+ ) {
541
+ return { v: undefined, h: undefined };
542
+ }
543
+
544
+ let vTmpLines: DrawLineForChoose[] = [];
545
+ let hTmpLines: DrawLineForChoose[] = [];
546
+
547
+ // 1.v,h direction: select the line with minimum offset
548
+ const vMinOffset = Math.min(
549
+ ...this.alignLinesForChoose.v.map((dlFc) => dlFc.offset.x),
550
+ );
551
+ const hMinOffset = Math.min(
552
+ ...this.alignLinesForChoose.h.map((dlFc) => dlFc.offset.y),
553
+ );
554
+
555
+ vTmpLines = this.alignLinesForChoose.v.filter(
556
+ (dlFc) => dlFc.offset.x === vMinOffset,
557
+ );
558
+ hTmpLines = this.alignLinesForChoose.h.filter(
559
+ (dlFc) => dlFc.offset.y === hMinOffset,
560
+ );
561
+
562
+ // 2.same tolerance,hcenter > top > bottom; vcenter > left > right. (The principle of selecting only one direction)
563
+ {
564
+ const vcenter_hasdata = vTmpLines.some(
565
+ (dlFc) => dlFc.dl.lp === 'vcenter',
566
+ );
567
+ const left_hasdata = vTmpLines.some((dlFc) => dlFc.dl.lp === 'left');
568
+
569
+ vTmpLines = vTmpLines.filter((dlFc) => {
570
+ if (dlFc.dl.lp === 'vcenter') {
571
+ return true;
572
+ }
573
+
574
+ if (dlFc.dl.lp === 'left') {
575
+ if (!vcenter_hasdata && left_hasdata) {
576
+ return true;
577
+ }
578
+ return false;
579
+ }
580
+
581
+ if (dlFc.dl.lp === 'right') {
582
+ if (!vcenter_hasdata && !left_hasdata) {
583
+ return true;
584
+ }
585
+ return false;
586
+ }
587
+
588
+ return false;
589
+ });
590
+
591
+ const hcenter_hasdata = hTmpLines.some(
592
+ (dlFc) => dlFc.dl.lp === 'hcenter',
593
+ );
594
+ const top_hasdata = hTmpLines.some((dlFc) => dlFc.dl.lp === 'top');
595
+
596
+ hTmpLines = hTmpLines.filter((dlFc) => {
597
+ if (dlFc.dl.lp === 'hcenter') {
598
+ return true;
599
+ }
600
+
601
+ if (dlFc.dl.lp === 'top') {
602
+ if (!hcenter_hasdata && top_hasdata) {
603
+ return true;
604
+ }
605
+ return false;
606
+ }
607
+
608
+ if (dlFc.dl.lp === 'bottom') {
609
+ if (!hcenter_hasdata && !top_hasdata) {
610
+ return true;
611
+ }
612
+ return false;
613
+ }
614
+
615
+ return false;
616
+ });
617
+ }
618
+
619
+ // 3.remove duplicates
620
+ const uniVTmpLines = Array.from(
621
+ vTmpLines
622
+ .reduce((map, item) => {
623
+ if (
624
+ !map.has(item.dl.lp) ||
625
+ Math.abs(item.offset.x) < Math.abs(map.get(item.dl.lp)?.offset.x)
626
+ ) {
627
+ map.set(item.dl.lp, item);
628
+ }
629
+ return map;
630
+ }, new Map<string, (typeof vTmpLines)[0]>())
631
+ .values(),
632
+ );
633
+
634
+ const uniHTmpLines = Array.from(
635
+ hTmpLines
636
+ .reduce((map, item) => {
637
+ if (
638
+ !map.has(item.dl.lp) ||
639
+ Math.abs(item.offset.y) < Math.abs(map.get(item.dl.lp)?.offset.y)
640
+ ) {
641
+ map.set(item.dl.lp, item);
642
+ }
643
+ return map;
644
+ }, new Map<string, (typeof vTmpLines)[0]>())
645
+ .values(),
646
+ );
647
+
648
+ // 4.choose a maximum offset one of DrawLineForChoose
649
+ const vMaxDL = uniVTmpLines.length
650
+ ? uniVTmpLines.reduce(
651
+ (maxItem: DrawLineForChoose, curItem: DrawLineForChoose) => {
652
+ if (curItem.offset.x > maxItem.offset.x) {
653
+ return curItem;
654
+ } else {
655
+ return maxItem;
656
+ }
657
+ },
658
+ )
659
+ : undefined;
660
+
661
+ const hMaxDL = uniHTmpLines.length
662
+ ? uniHTmpLines.reduce(
663
+ (maxItem: DrawLineForChoose, curItem: DrawLineForChoose) => {
664
+ if (curItem.offset.y > maxItem.offset.y) {
665
+ return curItem;
666
+ } else {
667
+ return maxItem;
668
+ }
669
+ },
670
+ )
671
+ : undefined;
672
+
673
+ return {
674
+ v: vMaxDL ? vMaxDL.dl : undefined,
675
+ h: hMaxDL ? hMaxDL.dl : undefined,
676
+ };
677
+ }
678
+
679
+ /**
680
+ * v and h direction adsorption state
681
+ */
682
+ private isAdsorbed: [boolean, boolean] = [false, false]; // whether the adsorption state
683
+
684
+ private dragEvent: IG6GraphEvent = undefined; // drag event
685
+
686
+ // use dragItemId and dragItemType to avoid object changing when dragging
687
+ private dragItemId: ID = undefined;
688
+ private dragItemType: ITEM_TYPE | 'canvas' = undefined;
689
+
690
+ /**
691
+ * Historical adsorption region: v and h directions
692
+ * x0 ~ x1: Represents the starting and ending line in the v direction
693
+ * y0 ~ y1: Represents the starting and ending line in the h direction
694
+ *
695
+ * When the cursor moves out of this region && non-adsorbed state => set to undefined
696
+ */
697
+ private historyAbsorbArea: [
698
+ [x0: number, x1: number] | undefined,
699
+ [y0: number, y1: number] | undefined,
700
+ ] = [undefined, undefined];
701
+
702
+ /**
703
+ * Unable to adsorb: countdown
704
+ */
705
+ private canAdsorbCount = 0;
706
+
707
+ /**
708
+ * Countdown method: Countdown
709
+ */
710
+ private canAdsorbCountDown = () => {
711
+ if (this.canAdsorbCount > 0) {
712
+ const intervalID = setInterval(() => {
713
+ this.canAdsorbCount--;
714
+
715
+ if (this.canAdsorbCount <= 0) {
716
+ clearTimeout(intervalID);
717
+ }
718
+ }, 100);
719
+ }
720
+ };
721
+
722
+ constructor(options?: SnapLineConfig) {
723
+ super(options);
724
+
725
+ this.init(options.graph);
726
+ }
727
+
728
+ public getEvents() {
729
+ return {
730
+ pointerdown: this.onPointerDown,
731
+ pointermove: this.onPointerMove,
732
+ pointerup: this.onPointerUp,
733
+ };
734
+ }
735
+
736
+ public onPointerDown(event: IG6GraphEvent) {
737
+ this.historyPoints[1] = { x: event.canvas.x, y: event.canvas.y };
738
+
739
+ this.dragItemId = event.itemId;
740
+ this.dragItemType = event.itemType;
741
+ }
742
+
743
+ public onPointerMove(event: IG6GraphEvent) {
744
+ if (!this.historyPoints[1]) return;
745
+ if (this.dragItemType !== 'node') {
746
+ return;
747
+ }
748
+
749
+ // pointerDown + first move = start drag
750
+ if (!this.dragging) {
751
+ this.onDragStart(event);
752
+ this.dragging = true;
753
+ } else {
754
+ this.onDrag(event);
755
+ }
756
+ }
757
+
758
+ public onPointerUp(event: IG6GraphEvent) {
759
+ // pointerUp + dragging = onDragEnd
760
+ if (this.dragging) {
761
+ this.onDragEnd();
762
+ } else {
763
+ this.historyPoints = [undefined, undefined];
764
+ this.dragging = false;
765
+ this.dragItemId = undefined;
766
+ this.dragItemType = undefined;
767
+ }
768
+ }
769
+
770
+ getGraph(event: IG6GraphEvent): IGraph {
771
+ return event.currentTarget;
772
+ }
773
+
774
+ //#region event handler
775
+ onDragStart(event: IG6GraphEvent) {
776
+ this.draggingBBox = this.graph.getRenderBBox(event.itemId, true) as AABB;
777
+ this.initialOffset = [
778
+ event.canvas.x - this.draggingBBox.center[0],
779
+ event.canvas.y - this.draggingBBox.center[1],
780
+ ];
781
+ }
782
+
783
+ onDrag = throttle(
784
+ ((event: IG6GraphEvent) => {
785
+ this.dragEvent = event;
786
+
787
+ this.initAlignLinesForChoose();
788
+
789
+ // control layer: Check to delete existing line & drawed line & adsorption
790
+ // set historyPoints
791
+
792
+ this.historyPoints[0] = this.historyPoints[1];
793
+ this.historyPoints[1] = { x: event.canvas.x, y: event.canvas.y };
794
+
795
+ let vlp: LinePosition = undefined;
796
+ let vline: [Point, Point] = undefined;
797
+ let hlp: LinePosition = undefined;
798
+ let hline: [Point, Point] = undefined;
799
+
800
+ // v direction: whether keep adsorption
801
+ const checkVShouldHoldAbsorb = (vlp, vline) => {
802
+ // v direction: continue to adsorb
803
+ const vShouldAbsorb =
804
+ Math.abs(this.getCurOffsetCompareToInitialOffset(event)[0]) <=
805
+ this.tolerance * this.toleranceFactor;
806
+
807
+ if (vShouldAbsorb) {
808
+ if (vlp === 'left') {
809
+ this.doUpdatePosition({
810
+ x: vline[0].x + this.draggingBBox.halfExtents[0],
811
+ });
812
+ } else if (vlp === 'vcenter') {
813
+ this.doUpdatePosition({
814
+ x: vline[0].x,
815
+ });
816
+ } else if (vlp === 'right') {
817
+ this.doUpdatePosition({
818
+ fx: vline[0].x - this.draggingBBox.halfExtents[0],
819
+ });
820
+ }
821
+
822
+ // updarte align line when absorb
823
+ this.updateAlignLineWhenAbsorb([true, false]);
824
+ } else {
825
+ // cancel absorb
826
+ // 1.update positon
827
+ this.doUpdatePosition({ fx: undefined });
828
+ // 2.remove align line && update state
829
+ this.removeAlignLine([true, undefined]);
830
+
831
+ // count down to be adsorbable
832
+ this.canAdsorbCount = 10; // 1s
833
+ this.canAdsorbCountDown();
834
+ }
835
+ };
836
+ // h direction: whether keep adsorption
837
+ const checkHShouldHoldAbsorb = (hlp, hline) => {
838
+ // h direction: continue to adsorb
839
+ const hShouldAbsorb =
840
+ Math.abs(this.getCurOffsetCompareToInitialOffset(event)[1]) <=
841
+ this.tolerance * this.toleranceFactor;
842
+
843
+ if (hShouldAbsorb) {
844
+ if (hlp === 'top') {
845
+ this.doUpdatePosition({
846
+ fy: hline[0].y + this.draggingBBox.halfExtents[1],
847
+ });
848
+ } else if (hlp === 'hcenter') {
849
+ this.doUpdatePosition({
850
+ fy: hline[0].y,
851
+ });
852
+ } else if (hlp === 'bottom') {
853
+ this.doUpdatePosition({
854
+ fy: hline[0].y - this.draggingBBox.halfExtents[1],
855
+ });
856
+ }
857
+
858
+ // update align line
859
+ this.updateAlignLineWhenAbsorb([false, true]);
860
+ } else {
861
+ // 1.update position
862
+ this.doUpdatePosition({ fy: undefined });
863
+ // 2.remove align line && update state
864
+ this.removeAlignLine([undefined, true]);
865
+
866
+ // count down to be adsorbable
867
+ this.canAdsorbCount = 10; // 1s
868
+ this.canAdsorbCountDown();
869
+ }
870
+ };
871
+ // v direction: whether adsorbed
872
+ const checkVShouldAbsorb = () => {
873
+ const ret: { vdl: DrawLine; hdl: DrawLine } | false =
874
+ this.canDrawLine();
875
+
876
+ // If in recent from adsorption area, can't immediately draw lines (must be removed from the area to reline this area)
877
+ if (ret) {
878
+ // draw align lines
879
+ this.drawAlignLines({ vdl: ret.vdl, hdl: undefined });
880
+ // absorb dragging box
881
+ this.absorb({ vdl: ret.vdl, hdl: undefined });
882
+ }
883
+ };
884
+ // h direction: whether adsorbed
885
+ const checkHShouldAbsorb = () => {
886
+ const ret: { vdl: DrawLine; hdl: DrawLine } | false =
887
+ this.canDrawLine();
888
+
889
+ // If in recent from adsorption area, can't immediately draw lines (must be removed from the area to reline this area)
890
+ if (ret) {
891
+ // draw align lines
892
+ this.drawAlignLines({ vdl: undefined, hdl: ret.hdl });
893
+ // absorb dragging box
894
+ this.absorb({ vdl: undefined, hdl: ret.hdl });
895
+ }
896
+ };
897
+
898
+ // 1、the current state of the two directions are adsorption
899
+ if (this.isAdsorbed[0] && this.isAdsorbed[1]) {
900
+ vlp = this.drawedLines[0].dl?.lp;
901
+ vline = this.drawedLines[0].dl?.line;
902
+ hlp = this.drawedLines[1].dl?.lp;
903
+ hline = this.drawedLines[1].dl?.line;
904
+
905
+ checkVShouldHoldAbsorb(vlp, vline);
906
+ checkHShouldHoldAbsorb(hlp, hline);
907
+ } else if (this.isAdsorbed[0] && !this.isAdsorbed[1]) {
908
+ // 2、currently, only the v direction is adsorbed
909
+ vlp = this.drawedLines[0].dl?.lp;
910
+ vline = this.drawedLines[0].dl?.line;
911
+
912
+ checkVShouldHoldAbsorb(vlp, vline);
913
+ checkHShouldAbsorb();
914
+ } else if (!this.isAdsorbed[0] && this.isAdsorbed[1]) {
915
+ // 3、currently, only the h direction is adsorbed
916
+ hlp = this.drawedLines[1].dl?.lp;
917
+ hline = this.drawedLines[1].dl?.line;
918
+
919
+ checkHShouldHoldAbsorb(vlp, vline);
920
+ checkVShouldAbsorb();
921
+ } else if (!this.isAdsorbed[0] && !this.isAdsorbed[1]) {
922
+ // 4、currently, v and h directions are not adsorbed
923
+ const ret: { vdl: DrawLine; hdl: DrawLine } | false =
924
+ this.canDrawLine();
925
+
926
+ // 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)
927
+ if (ret) {
928
+ // draw align lines
929
+ this.drawAlignLines(ret);
930
+ // absorb dragging box
931
+ this.absorb(ret);
932
+ }
933
+ }
934
+ }).bind(this),
935
+ 16,
936
+ {
937
+ leading: false,
938
+ trailing: true,
939
+ },
940
+ );
941
+
942
+ onDragEnd() {
943
+ this.dragEvent = undefined;
944
+ this.historyPoints = [undefined, undefined];
945
+ this.dragging = false;
946
+ this.dragItemId = undefined;
947
+ this.dragItemType = undefined;
948
+ }
949
+
950
+ //#region draw/remove lines
951
+ // first:v direction; second:h direction;
952
+ // ddo: drawed DisplayObject, dl: DrawLine
953
+ private drawedLines: [
954
+ { do: DisplayObject | undefined; dl: DrawLine | undefined } | undefined,
955
+ { do: DisplayObject | undefined; dl: DrawLine | undefined } | undefined,
956
+ ] = [undefined, undefined];
957
+
958
+ drawAlignLines({
959
+ vdl,
960
+ hdl,
961
+ }: {
962
+ vdl: DrawLine | undefined;
963
+ hdl: DrawLine | undefined;
964
+ }) {
965
+ // 1.draw align line
966
+ const vLineID: ID = vdl ? this.getDrawLineIdByDrawLine(vdl) : undefined;
967
+ const hLineID: ID = hdl ? this.getDrawLineIdByDrawLine(hdl) : undefined;
968
+
969
+ let vLine: DisplayObject = undefined;
970
+ if (vdl) {
971
+ vLine = this.graph.drawTransient('line', vLineID, {
972
+ style: {
973
+ stroke: 'red',
974
+ lineWidth: 1,
975
+ x1: vdl.line[0].x,
976
+ y1: vdl.line[0].y,
977
+ x2: vdl.line[1].x,
978
+ y2: vdl.line[1].y,
979
+ },
980
+ });
981
+ // add to alignLines
982
+ this.drawedLines[0] = { do: vLine, dl: vdl };
983
+ }
984
+
985
+ let hLine: DisplayObject = undefined;
986
+ if (hdl) {
987
+ hLine = this.graph.drawTransient('line', hLineID, {
988
+ style: {
989
+ stroke: 'red',
990
+ lineWidth: 1,
991
+ x1: hdl.line[0].x,
992
+ y1: hdl.line[0].y,
993
+ x2: hdl.line[1].x,
994
+ y2: hdl.line[1].y,
995
+ },
996
+ });
997
+ // add to alignLines
998
+ this.drawedLines[1] = { do: hLine, dl: hdl };
999
+ }
1000
+ }
1001
+
1002
+ /**
1003
+ * remove align line
1004
+ * @param rvdl: remove vertical drawed line
1005
+ * @param rhdl: remove horizon drawed line
1006
+ */
1007
+ removeAlignLine([rvdl, rhdl]: [
1008
+ rvdl: boolean | undefined,
1009
+ rhdl: boolean | undefined,
1010
+ ]) {
1011
+ if (rvdl) {
1012
+ const vlid = this.getDrawLineIdByDrawLine(this.drawedLines[0].dl);
1013
+ this.graph.drawTransient('line', vlid, { action: 'remove' });
1014
+ this.drawedLines[0] = undefined;
1015
+
1016
+ this.isAdsorbed[0] = false;
1017
+ }
1018
+
1019
+ if (rhdl) {
1020
+ const hlid = this.getDrawLineIdByDrawLine(this.drawedLines[1].dl);
1021
+
1022
+ this.graph.drawTransient('line', hlid, { action: 'remove' });
1023
+ this.drawedLines[1] = undefined;
1024
+
1025
+ this.isAdsorbed[1] = false;
1026
+ }
1027
+ }
1028
+
1029
+ /**
1030
+ * via ID: remove align line
1031
+ * @param rmLineID
1032
+ */
1033
+ removeAlignLineByID(rmLineID: ID) {
1034
+ // remove from DisplayObject
1035
+
1036
+ const [vTmpDrawedLine, hTmpDrawedLine] = this.drawedLines;
1037
+ this.drawedLines.forEach((line, index) => {
1038
+ if (line && line.do) {
1039
+ const lineID = this.getDrawLineIdByPoints(line.dl.line);
1040
+ if (lineID === rmLineID) {
1041
+ if (index === 0 && vTmpDrawedLine) {
1042
+ vTmpDrawedLine.dl = undefined;
1043
+ vTmpDrawedLine.do = undefined;
1044
+ } else if (index === 1 && hTmpDrawedLine) {
1045
+ hTmpDrawedLine.dl = undefined;
1046
+ hTmpDrawedLine.do = undefined;
1047
+ }
1048
+
1049
+ this.isAdsorbed[index] = false;
1050
+ }
1051
+ }
1052
+ });
1053
+
1054
+ this.drawedLines[0] = vTmpDrawedLine;
1055
+ this.drawedLines[1] = hTmpDrawedLine;
1056
+
1057
+ // remove drawed line
1058
+ this.graph.drawTransient('line', rmLineID, { action: 'remove' });
1059
+ }
1060
+
1061
+ /**
1062
+ * get draggingBBox Point based on LinePosition
1063
+ */
1064
+ getDraggingBBoxPointByLinePosition(lp: LinePosition): Point | undefined {
1065
+ if (!this.draggingBBox) {
1066
+ return undefined;
1067
+ }
1068
+
1069
+ if (lp === 'left') {
1070
+ return { x: this.draggingBBox.min[0], y: this.draggingBBox.center[1] };
1071
+ }
1072
+ if (lp === 'vcenter' || lp === 'hcenter') {
1073
+ return { x: this.draggingBBox.center[0], y: this.draggingBBox.center[1] };
1074
+ }
1075
+ if (lp === 'right') {
1076
+ return { x: this.draggingBBox.max[0], y: this.draggingBBox.center[1] };
1077
+ }
1078
+ if (lp === 'top') {
1079
+ return { x: this.draggingBBox.center[0], y: this.draggingBBox.min[1] };
1080
+ }
1081
+ if (lp === 'bottom') {
1082
+ return { x: this.draggingBBox.center[0], y: this.draggingBBox.max[1] };
1083
+ }
1084
+
1085
+ return undefined;
1086
+ }
1087
+
1088
+ /**
1089
+ * update align line under condition of absorbed
1090
+ */
1091
+ updateAlignLineWhenAbsorb([v, h]: [boolean, boolean]) {
1092
+ if (v) {
1093
+ if (this.drawedLines[0] && this.drawedLines[0].do) {
1094
+ const draggingBBoxDrawEndPoint: Point =
1095
+ this.getDraggingBBoxPointByLinePosition(this.drawedLines[0].dl.lp);
1096
+ const vdl: DrawLine = {
1097
+ line: [
1098
+ this.drawedLines[0].dl.line[0],
1099
+ {
1100
+ x: this.drawedLines[0].dl.line[0].x,
1101
+ y: draggingBBoxDrawEndPoint.y,
1102
+ },
1103
+ ],
1104
+ lp: this.drawedLines[0].dl.lp,
1105
+ };
1106
+ this.removeAlignLineByID(this.drawedLines[0].do.id);
1107
+ this.drawAlignLines({ vdl: vdl, hdl: undefined });
1108
+ this.isAdsorbed[0] = true;
1109
+ }
1110
+ }
1111
+
1112
+ if (h) {
1113
+ if (this.drawedLines[1] && this.drawedLines[1].do) {
1114
+ const draggingBBoxDrawEndPoint: Point =
1115
+ this.getDraggingBBoxPointByLinePosition(this.drawedLines[1].dl.lp);
1116
+ const hdl: DrawLine = {
1117
+ line: [
1118
+ this.drawedLines[1].dl.line[0],
1119
+ {
1120
+ x: draggingBBoxDrawEndPoint.x,
1121
+ y: this.drawedLines[1].dl.line[0].y,
1122
+ },
1123
+ ],
1124
+ lp: this.drawedLines[1].dl.lp,
1125
+ };
1126
+ this.removeAlignLineByID(this.drawedLines[1].do.id);
1127
+ this.drawAlignLines({ vdl: undefined, hdl: hdl });
1128
+ this.isAdsorbed[1] = true;
1129
+ }
1130
+ }
1131
+ }
1132
+
1133
+ /**
1134
+ * check whether can draw lines
1135
+ */
1136
+ canDrawLine(): { vdl: DrawLine; hdl: DrawLine } | false {
1137
+ const { v, h }: { v: DrawLine | undefined; h: DrawLine | undefined } =
1138
+ this.chooseAlignLine();
1139
+ if (!v && !h) {
1140
+ return false;
1141
+ }
1142
+
1143
+ return { vdl: v, hdl: h };
1144
+ }
1145
+
1146
+ /**
1147
+ * detect whether adsorption can be cancelled
1148
+ * two directions:v h
1149
+ * @return first: v direction ; second:h direction; undefine means no-adsorb
1150
+ */
1151
+ canCancelAbsorb(): [boolean | undefined, boolean | undefined] {
1152
+ // eslint-disable-next-line prefer-const
1153
+ let ret: [boolean | undefined, boolean | undefined] = [
1154
+ undefined,
1155
+ undefined,
1156
+ ];
1157
+
1158
+ const vdl = this.drawedLines[0].dl;
1159
+ const hdl = this.drawedLines[1].dl;
1160
+
1161
+ const offset = this.getPointerOffsetWithItem({
1162
+ x: this.dragEvent.canvas.x,
1163
+ y: this.dragEvent.canvas.y,
1164
+ });
1165
+
1166
+ if (vdl) {
1167
+ if (Math.abs(offset.x) > this.tolerance * this.toleranceFactor) {
1168
+ ret[0] = true;
1169
+ }
1170
+ }
1171
+ if (hdl) {
1172
+ if (Math.abs(offset.y) > this.tolerance * this.toleranceFactor) {
1173
+ ret[1] = true;
1174
+ }
1175
+ }
1176
+
1177
+ return ret;
1178
+ }
1179
+
1180
+ //#endregion
1181
+
1182
+ /**
1183
+ * absorb the dragging box
1184
+ */
1185
+ absorb(dls: { vdl: DrawLine; hdl: DrawLine }) {
1186
+ if (dls.vdl) {
1187
+ this.isAdsorbed[0] = true;
1188
+ this.historyAbsorbArea[0] = [
1189
+ dls.vdl.line[0].x - this.tolerance * this.toleranceFactor,
1190
+ dls.vdl.line[0].x + this.tolerance * this.toleranceFactor,
1191
+ ];
1192
+ this.updateDraggingItemPosition(this.drawedLines[0].dl);
1193
+ }
1194
+ if (dls.hdl) {
1195
+ this.isAdsorbed[1] = true;
1196
+ this.historyAbsorbArea[1] = [
1197
+ dls.hdl.line[0].y - this.tolerance * this.toleranceFactor,
1198
+ dls.hdl.line[0].y + this.tolerance * this.toleranceFactor,
1199
+ ];
1200
+ this.updateDraggingItemPosition(this.drawedLines[1].dl);
1201
+ }
1202
+ }
1203
+
1204
+ /**
1205
+ * If there is dl(draw line), then absorb to dl;
1206
+ * don't pass dl, means cancel absorb
1207
+ * @param dl drawline [point, point]
1208
+ */
1209
+ updateDraggingItemPosition(
1210
+ dl?: DrawLine,
1211
+ shouldChange?: { x?: number; y?: number },
1212
+ ) {
1213
+ // Determine if historyPoints do not exist do not continue
1214
+ if (!this.historyPoints[0] && !this.historyPoints[1]) {
1215
+ return;
1216
+ }
1217
+
1218
+ // absorb effect
1219
+ if (dl) {
1220
+ // calculate the diff and absorb
1221
+ if (dl.lp === 'left') {
1222
+ const tmpX = dl.line[0].x + this.draggingBBox.halfExtents[0];
1223
+ this.doUpdatePosition({ fx: tmpX });
1224
+ }
1225
+ if (dl.lp === 'vcenter') {
1226
+ this.doUpdatePosition({
1227
+ fx: dl.line[0].x,
1228
+ });
1229
+ }
1230
+ if (dl.lp === 'right') {
1231
+ this.doUpdatePosition({
1232
+ fx: dl.line[0].x - this.draggingBBox.halfExtents[0],
1233
+ });
1234
+ }
1235
+ if (dl.lp === 'top') {
1236
+ this.doUpdatePosition({
1237
+ fy: dl.line[0].y + this.draggingBBox.halfExtents[1],
1238
+ });
1239
+ }
1240
+ if (dl.lp === 'hcenter') {
1241
+ this.doUpdatePosition({
1242
+ fy: dl.line[0].y,
1243
+ });
1244
+ }
1245
+ if (dl.lp === 'bottom') {
1246
+ this.doUpdatePosition({
1247
+ fy: dl.line[0].y - this.draggingBBox.halfExtents[1],
1248
+ });
1249
+ }
1250
+ }
1251
+
1252
+ if (shouldChange) {
1253
+ if (shouldChange.x) {
1254
+ const changeX = this.draggingBBox.center[0] + shouldChange.x;
1255
+ this.doUpdatePosition({
1256
+ x: changeX,
1257
+ fx: undefined,
1258
+ });
1259
+ }
1260
+ if (shouldChange.y) {
1261
+ const changeY = this.draggingBBox.center[1] + shouldChange.y;
1262
+ this.doUpdatePosition({
1263
+ y: changeY,
1264
+ fy: undefined,
1265
+ });
1266
+ }
1267
+ }
1268
+ }
1269
+
1270
+ doUpdatePosition(data) {
1271
+ const cache = this.updateCache.get(this.dragItemId);
1272
+ this.updateCache.set(this.dragItemId, {
1273
+ id: this.dragItemId,
1274
+ data: {
1275
+ ...cache?.data,
1276
+ ...data,
1277
+ },
1278
+ });
1279
+ this.throttleUpdate();
1280
+ }
1281
+
1282
+ throttleUpdate = throttle(
1283
+ () => {
1284
+ this.graph.updateNodePosition(
1285
+ Array.from(this.updateCache.values()),
1286
+ false,
1287
+ true,
1288
+ );
1289
+ this.updateCache.clear();
1290
+ },
1291
+ 16,
1292
+ {
1293
+ leading: true,
1294
+ trailing: true,
1295
+ },
1296
+ );
1297
+ }