@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,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
+ constructor(options) {
8
+ super(options);
9
+ //#region state: historyPoints
10
+ this.historyPoints = [
11
+ undefined,
12
+ undefined,
13
+ ];
14
+ /**
15
+ * when start drag, offset of cursor and node center (event.canvas - draggingnode.BBox)
16
+ */
17
+ this.initialOffset = [undefined, undefined];
18
+ /**
19
+ * Cache the nodes' positions to be throttly updated.
20
+ */
21
+ this.updateCache = new Map();
22
+ /**
23
+ * Gets the current cursor node and center offset and then with initialOffset difference
24
+ */
25
+ this.getCurOffsetCompareToInitialOffset = (e) => {
26
+ if (this.initialOffset[0] === undefined ||
27
+ this.initialOffset[1] === undefined) {
28
+ return [undefined, undefined];
29
+ }
30
+ const curOffset = [
31
+ e.canvas.x - this.draggingBBox.center[0],
32
+ e.canvas.y - this.draggingBBox.center[1],
33
+ ];
34
+ return [
35
+ curOffset[0] - this.initialOffset[0],
36
+ curOffset[1] - this.initialOffset[1],
37
+ ];
38
+ };
39
+ this.dragging = false;
40
+ this.draggingBBox = undefined;
41
+ // Gets the offset between the cursor and draggingItem
42
+ this.getPointerOffsetWithItem = (pointer) => {
43
+ return {
44
+ x: Math.abs(pointer.x - this.draggingBBox.center[0]),
45
+ y: Math.abs(pointer.x - this.draggingBBox.center[1]),
46
+ };
47
+ };
48
+ //#region state: tolerance
49
+ this.tolerance = 4;
50
+ this.toleranceFactor = 2;
51
+ //#endregion
52
+ // All the lines in the vertical direction
53
+ this.vContrastPoints = [];
54
+ this.hContrastPoints = [];
55
+ /**
56
+ * alignLinesForChoose container
57
+ */
58
+ this.alignLinesForChoose = { v: [], h: [] };
59
+ /**
60
+ * v and h direction adsorption state
61
+ */
62
+ this.isAdsorbed = [false, false]; // whether the adsorption state
63
+ this.dragEvent = undefined; // drag event
64
+ // use dragItemId and dragItemType to avoid object changing when dragging
65
+ this.dragItemId = undefined;
66
+ this.dragItemType = undefined;
67
+ /**
68
+ * Historical adsorption region: v and h directions
69
+ * x0 ~ x1: Represents the starting and ending line in the v direction
70
+ * y0 ~ y1: Represents the starting and ending line in the h direction
71
+ *
72
+ * When the cursor moves out of this region && non-adsorbed state => set to undefined
73
+ */
74
+ this.historyAbsorbArea = [undefined, undefined];
75
+ /**
76
+ * Unable to adsorb: countdown
77
+ */
78
+ this.canAdsorbCount = 0;
79
+ /**
80
+ * Countdown method: Countdown
81
+ */
82
+ this.canAdsorbCountDown = () => {
83
+ if (this.canAdsorbCount > 0) {
84
+ const intervalID = setInterval(() => {
85
+ this.canAdsorbCount--;
86
+ if (this.canAdsorbCount <= 0) {
87
+ clearTimeout(intervalID);
88
+ }
89
+ }, 100);
90
+ }
91
+ };
92
+ this.onDrag = (0, util_1.throttle)(((event) => {
93
+ var _a, _b, _c, _d, _e, _f, _g, _h;
94
+ this.dragEvent = event;
95
+ this.initAlignLinesForChoose();
96
+ // control layer: Check to delete existing line & drawed line & adsorption
97
+ // set historyPoints
98
+ this.historyPoints[0] = this.historyPoints[1];
99
+ this.historyPoints[1] = { x: event.canvas.x, y: event.canvas.y };
100
+ let vlp = undefined;
101
+ let vline = undefined;
102
+ let hlp = undefined;
103
+ let hline = undefined;
104
+ // v direction: whether keep adsorption
105
+ const checkVShouldHoldAbsorb = (vlp, vline) => {
106
+ // v direction: continue to adsorb
107
+ const vShouldAbsorb = Math.abs(this.getCurOffsetCompareToInitialOffset(event)[0]) <=
108
+ this.tolerance * this.toleranceFactor;
109
+ if (vShouldAbsorb) {
110
+ if (vlp === 'left') {
111
+ this.doUpdatePosition({
112
+ x: vline[0].x + this.draggingBBox.halfExtents[0],
113
+ });
114
+ }
115
+ else if (vlp === 'vcenter') {
116
+ this.doUpdatePosition({
117
+ x: vline[0].x,
118
+ });
119
+ }
120
+ else if (vlp === 'right') {
121
+ this.doUpdatePosition({
122
+ fx: vline[0].x - this.draggingBBox.halfExtents[0],
123
+ });
124
+ }
125
+ // updarte align line when absorb
126
+ this.updateAlignLineWhenAbsorb([true, false]);
127
+ }
128
+ else {
129
+ // cancel absorb
130
+ // 1.update positon
131
+ this.doUpdatePosition({ fx: undefined });
132
+ // 2.remove align line && update state
133
+ this.removeAlignLine([true, undefined]);
134
+ // count down to be adsorbable
135
+ this.canAdsorbCount = 10; // 1s
136
+ this.canAdsorbCountDown();
137
+ }
138
+ };
139
+ // h direction: whether keep adsorption
140
+ const checkHShouldHoldAbsorb = (hlp, hline) => {
141
+ // h direction: continue to adsorb
142
+ const hShouldAbsorb = Math.abs(this.getCurOffsetCompareToInitialOffset(event)[1]) <=
143
+ this.tolerance * this.toleranceFactor;
144
+ if (hShouldAbsorb) {
145
+ if (hlp === 'top') {
146
+ this.doUpdatePosition({
147
+ fy: hline[0].y + this.draggingBBox.halfExtents[1],
148
+ });
149
+ }
150
+ else if (hlp === 'hcenter') {
151
+ this.doUpdatePosition({
152
+ fy: hline[0].y,
153
+ });
154
+ }
155
+ else if (hlp === 'bottom') {
156
+ this.doUpdatePosition({
157
+ fy: hline[0].y - this.draggingBBox.halfExtents[1],
158
+ });
159
+ }
160
+ // update align line
161
+ this.updateAlignLineWhenAbsorb([false, true]);
162
+ }
163
+ else {
164
+ // 1.update position
165
+ this.doUpdatePosition({ fy: undefined });
166
+ // 2.remove align line && update state
167
+ this.removeAlignLine([undefined, true]);
168
+ // count down to be adsorbable
169
+ this.canAdsorbCount = 10; // 1s
170
+ this.canAdsorbCountDown();
171
+ }
172
+ };
173
+ // v direction: whether adsorbed
174
+ const checkVShouldAbsorb = () => {
175
+ const ret = this.canDrawLine();
176
+ // If in recent from adsorption area, can't immediately draw lines (must be removed from the area to reline this area)
177
+ if (ret) {
178
+ // draw align lines
179
+ this.drawAlignLines({ vdl: ret.vdl, hdl: undefined });
180
+ // absorb dragging box
181
+ this.absorb({ vdl: ret.vdl, hdl: undefined });
182
+ }
183
+ };
184
+ // h direction: whether adsorbed
185
+ const checkHShouldAbsorb = () => {
186
+ const ret = this.canDrawLine();
187
+ // If in recent from adsorption area, can't immediately draw lines (must be removed from the area to reline this area)
188
+ if (ret) {
189
+ // draw align lines
190
+ this.drawAlignLines({ vdl: undefined, hdl: ret.hdl });
191
+ // absorb dragging box
192
+ this.absorb({ vdl: undefined, hdl: ret.hdl });
193
+ }
194
+ };
195
+ // 1、the current state of the two directions are adsorption
196
+ if (this.isAdsorbed[0] && this.isAdsorbed[1]) {
197
+ vlp = (_a = this.drawedLines[0].dl) === null || _a === void 0 ? void 0 : _a.lp;
198
+ vline = (_b = this.drawedLines[0].dl) === null || _b === void 0 ? void 0 : _b.line;
199
+ hlp = (_c = this.drawedLines[1].dl) === null || _c === void 0 ? void 0 : _c.lp;
200
+ hline = (_d = this.drawedLines[1].dl) === null || _d === void 0 ? void 0 : _d.line;
201
+ checkVShouldHoldAbsorb(vlp, vline);
202
+ checkHShouldHoldAbsorb(hlp, hline);
203
+ }
204
+ else if (this.isAdsorbed[0] && !this.isAdsorbed[1]) {
205
+ // 2、currently, only the v direction is adsorbed
206
+ vlp = (_e = this.drawedLines[0].dl) === null || _e === void 0 ? void 0 : _e.lp;
207
+ vline = (_f = this.drawedLines[0].dl) === null || _f === void 0 ? void 0 : _f.line;
208
+ checkVShouldHoldAbsorb(vlp, vline);
209
+ checkHShouldAbsorb();
210
+ }
211
+ else if (!this.isAdsorbed[0] && this.isAdsorbed[1]) {
212
+ // 3、currently, only the h direction is adsorbed
213
+ hlp = (_g = this.drawedLines[1].dl) === null || _g === void 0 ? void 0 : _g.lp;
214
+ hline = (_h = this.drawedLines[1].dl) === null || _h === void 0 ? void 0 : _h.line;
215
+ checkHShouldHoldAbsorb(vlp, vline);
216
+ checkVShouldAbsorb();
217
+ }
218
+ else if (!this.isAdsorbed[0] && !this.isAdsorbed[1]) {
219
+ // 4、currently, v and h directions are not adsorbed
220
+ const ret = this.canDrawLine();
221
+ // 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)
222
+ if (ret) {
223
+ // draw align lines
224
+ this.drawAlignLines(ret);
225
+ // absorb dragging box
226
+ this.absorb(ret);
227
+ }
228
+ }
229
+ }).bind(this), 16, {
230
+ leading: false,
231
+ trailing: true,
232
+ });
233
+ //#region draw/remove lines
234
+ // first:v direction; second:h direction;
235
+ // ddo: drawed DisplayObject, dl: DrawLine
236
+ this.drawedLines = [undefined, undefined];
237
+ this.throttleUpdate = (0, util_1.throttle)(() => {
238
+ this.graph.updateNodePosition(Array.from(this.updateCache.values()), false, true);
239
+ this.updateCache.clear();
240
+ }, 16, {
241
+ leading: true,
242
+ trailing: true,
243
+ });
244
+ this.init(options.graph);
245
+ }
246
+ setTolerance(tolerance) {
247
+ this.tolerance = tolerance;
248
+ }
249
+ getTolerance() {
250
+ return this.tolerance;
251
+ }
252
+ /**
253
+ * getDrawLineId via DrawLine
254
+ * Principle: the lines on the drawing board is the only load-point
255
+ * @param dl drawLine
256
+ */
257
+ getDrawLineIdByDrawLine(dl) {
258
+ if (!dl)
259
+ return;
260
+ return `${dl.line[0].x}-${dl.line[0].y}-${dl.line[1].x}-${dl.line[1].y}`;
261
+ }
262
+ /**
263
+ *
264
+ * @param cp based on constractBBox's point
265
+ * @param dp based on draggingBBox point
266
+ * @returns
267
+ */
268
+ getDrawLineIdByPoints([cp, dp]) {
269
+ return `${cp.x}-${cp.y}-${dp.x}-${dp.y}`;
270
+ }
271
+ /**
272
+ * all AlignLines satisfy conditions: in the tolerance range
273
+ */
274
+ addAlignLinesForChoose() {
275
+ function isInToleranceRange(xOrY, contrast, tolerance) {
276
+ return xOrY >= contrast - tolerance && xOrY <= contrast + tolerance;
277
+ }
278
+ this.vContrastPoints.forEach((vpoint) => {
279
+ if (isInToleranceRange(this.draggingBBox.min[0], vpoint.x, this.tolerance))
280
+ this.alignLinesForChoose.v.push({
281
+ dl: {
282
+ line: [vpoint, { x: vpoint.x, y: this.draggingBBox.center[1] }],
283
+ lp: 'left',
284
+ },
285
+ offset: { x: vpoint.x - this.draggingBBox.min[0], y: 0 },
286
+ });
287
+ if (isInToleranceRange(this.draggingBBox.center[0], vpoint.x, this.tolerance))
288
+ this.alignLinesForChoose.v.push({
289
+ dl: {
290
+ line: [vpoint, { x: vpoint.x, y: this.draggingBBox.center[1] }],
291
+ lp: 'vcenter',
292
+ },
293
+ offset: { x: vpoint.x - this.draggingBBox.center[0], y: 0 },
294
+ });
295
+ if (isInToleranceRange(this.draggingBBox.max[0], vpoint.x, this.tolerance))
296
+ this.alignLinesForChoose.v.push({
297
+ dl: {
298
+ line: [vpoint, { x: vpoint.x, y: this.draggingBBox.center[1] }],
299
+ lp: 'right',
300
+ },
301
+ offset: { x: vpoint.x - this.draggingBBox.max[0], y: 0 },
302
+ });
303
+ });
304
+ this.hContrastPoints.forEach((hpoint) => {
305
+ if (isInToleranceRange(this.draggingBBox.min[1], hpoint.y, this.tolerance))
306
+ this.alignLinesForChoose.v.push({
307
+ dl: {
308
+ line: [hpoint, { x: this.draggingBBox.min[0], y: hpoint.y }],
309
+ lp: 'top',
310
+ },
311
+ offset: { x: 0, y: hpoint.y - this.draggingBBox.min[1] },
312
+ });
313
+ if (isInToleranceRange(this.draggingBBox.center[1], hpoint.y, this.tolerance))
314
+ this.alignLinesForChoose.v.push({
315
+ dl: {
316
+ line: [hpoint, { x: this.draggingBBox.center[0], y: hpoint.y }],
317
+ lp: 'hcenter',
318
+ },
319
+ offset: { x: 0, y: hpoint.y - this.draggingBBox.center[1] },
320
+ });
321
+ if (isInToleranceRange(this.draggingBBox.max[1], hpoint.y, this.tolerance))
322
+ this.alignLinesForChoose.v.push({
323
+ dl: {
324
+ line: [hpoint, { x: this.draggingBBox.max[0], y: hpoint.y }],
325
+ lp: 'bottom',
326
+ },
327
+ offset: { x: 0, y: hpoint.y - this.draggingBBox.max[1] },
328
+ });
329
+ });
330
+ }
331
+ initAlignLinesForChoose() {
332
+ this.alignLinesForChoose.v = [];
333
+ this.alignLinesForChoose.h = [];
334
+ let allIds = [];
335
+ this.graph.getAllCombosData().forEach((item) => {
336
+ allIds.push(item.id);
337
+ });
338
+ this.graph.getAllNodesData().forEach((item) => {
339
+ allIds.push(item.id);
340
+ });
341
+ allIds = allIds.filter((item) => item !== this.dragItemId); // 排除drag item
342
+ allIds.forEach((id) => {
343
+ const cb = this.graph.getRenderBBox(id, true); // contrast bbox
344
+ // 判断2个方向,6条线的对比
345
+ /* draggingBBox left */
346
+ if (Math.abs(this.draggingBBox.min[0] - cb.min[0]) <= this.tolerance) {
347
+ this.alignLinesForChoose.v.push({
348
+ dl: {
349
+ line: [
350
+ { x: cb.min[0], y: cb.center[1] },
351
+ { x: cb.min[0], y: this.draggingBBox.center[1] },
352
+ ],
353
+ lp: 'left',
354
+ },
355
+ offset: {
356
+ x: this.draggingBBox.min[0] - cb.min[0],
357
+ y: this.draggingBBox.center[1] - cb.center[1],
358
+ },
359
+ });
360
+ }
361
+ if (Math.abs(this.draggingBBox.min[0] - cb.center[0]) <= this.tolerance) {
362
+ this.alignLinesForChoose.v.push({
363
+ dl: {
364
+ line: [
365
+ { x: cb.center[0], y: cb.center[1] },
366
+ { x: cb.center[0], y: this.draggingBBox.center[1] },
367
+ ],
368
+ lp: 'left',
369
+ },
370
+ offset: {
371
+ x: this.draggingBBox.min[0] - cb.center[0],
372
+ y: this.draggingBBox.center[1] - cb.center[1],
373
+ },
374
+ });
375
+ }
376
+ if (Math.abs(this.draggingBBox.min[0] - cb.max[0]) <= this.tolerance) {
377
+ this.alignLinesForChoose.v.push({
378
+ dl: {
379
+ line: [
380
+ { x: cb.max[0], y: cb.center[1] },
381
+ { x: cb.max[0], y: this.draggingBBox.center[1] },
382
+ ],
383
+ lp: 'left',
384
+ },
385
+ offset: {
386
+ x: this.draggingBBox.min[0] - cb.max[0],
387
+ y: this.draggingBBox.center[1] - cb.center[1],
388
+ },
389
+ });
390
+ }
391
+ /* draggingBBox vcenter */
392
+ if (Math.abs(this.draggingBBox.center[0] - cb.min[0]) <= this.tolerance) {
393
+ this.alignLinesForChoose.v.push({
394
+ dl: {
395
+ line: [
396
+ { x: cb.min[0], y: cb.center[1] },
397
+ { x: cb.min[0], y: this.draggingBBox.center[1] },
398
+ ],
399
+ lp: 'vcenter',
400
+ },
401
+ offset: {
402
+ x: this.draggingBBox.center[0] - cb.min[0],
403
+ y: this.draggingBBox.center[1] - cb.center[1],
404
+ },
405
+ });
406
+ }
407
+ if (Math.abs(this.draggingBBox.center[0] - cb.center[0]) <= this.tolerance) {
408
+ this.alignLinesForChoose.v.push({
409
+ dl: {
410
+ line: [
411
+ { x: cb.center[0], y: cb.center[1] },
412
+ { x: cb.center[0], y: this.draggingBBox.center[1] },
413
+ ],
414
+ lp: 'vcenter',
415
+ },
416
+ offset: {
417
+ x: this.draggingBBox.center[0] - cb.center[0],
418
+ y: this.draggingBBox.center[1] - cb.center[1],
419
+ },
420
+ });
421
+ }
422
+ if (Math.abs(this.draggingBBox.center[0] - cb.max[0]) <= this.tolerance) {
423
+ this.alignLinesForChoose.v.push({
424
+ dl: {
425
+ line: [
426
+ { x: cb.max[0], y: cb.center[1] },
427
+ { x: cb.max[0], y: this.draggingBBox.center[1] },
428
+ ],
429
+ lp: 'vcenter',
430
+ },
431
+ offset: {
432
+ x: this.draggingBBox.center[0] - cb.max[0],
433
+ y: this.draggingBBox.center[1] - cb.center[1],
434
+ },
435
+ });
436
+ }
437
+ /* draggingBBox right */
438
+ if (Math.abs(this.draggingBBox.max[0] - cb.min[0]) <= this.tolerance) {
439
+ this.alignLinesForChoose.v.push({
440
+ dl: {
441
+ line: [
442
+ { x: cb.min[0], y: cb.center[1] },
443
+ { x: cb.min[0], y: this.draggingBBox.center[1] },
444
+ ],
445
+ lp: 'right',
446
+ },
447
+ offset: {
448
+ x: this.draggingBBox.max[0] - cb.min[0],
449
+ y: this.draggingBBox.center[1] - cb.center[1],
450
+ },
451
+ });
452
+ }
453
+ if (Math.abs(this.draggingBBox.max[0] - cb.center[0]) <= this.tolerance) {
454
+ this.alignLinesForChoose.v.push({
455
+ dl: {
456
+ line: [
457
+ { x: cb.center[0], y: cb.center[1] },
458
+ { x: cb.center[0], y: this.draggingBBox.center[1] },
459
+ ],
460
+ lp: 'right',
461
+ },
462
+ offset: {
463
+ x: this.draggingBBox.max[0] - cb.center[0],
464
+ y: this.draggingBBox.center[1] - cb.center[1],
465
+ },
466
+ });
467
+ }
468
+ if (Math.abs(this.draggingBBox.max[0] - cb.max[0]) <= this.tolerance) {
469
+ this.alignLinesForChoose.v.push({
470
+ dl: {
471
+ line: [
472
+ { x: cb.max[0], y: cb.center[1] },
473
+ { x: cb.max[0], y: this.draggingBBox.center[1] },
474
+ ],
475
+ lp: 'right',
476
+ },
477
+ offset: {
478
+ x: this.draggingBBox.max[0] - cb.max[0],
479
+ y: this.draggingBBox.center[1] - cb.center[1],
480
+ },
481
+ });
482
+ }
483
+ /* draggingBBox top */
484
+ if (Math.abs(this.draggingBBox.min[1] - cb.max[1]) <= this.tolerance) {
485
+ this.alignLinesForChoose.h.push({
486
+ dl: {
487
+ line: [
488
+ { x: cb.center[0], y: cb.max[1] },
489
+ { x: this.draggingBBox.center[0], y: cb.max[1] },
490
+ ],
491
+ lp: 'top',
492
+ },
493
+ offset: {
494
+ x: this.draggingBBox.center[0] - cb.center[0],
495
+ y: this.draggingBBox.min[1] - cb.max[1],
496
+ },
497
+ });
498
+ }
499
+ if (Math.abs(this.draggingBBox.min[1] - cb.center[1]) <= this.tolerance) {
500
+ this.alignLinesForChoose.h.push({
501
+ dl: {
502
+ line: [
503
+ { x: cb.center[0], y: cb.center[1] },
504
+ { x: this.draggingBBox.center[0], y: cb.center[1] },
505
+ ],
506
+ lp: 'top',
507
+ },
508
+ offset: {
509
+ x: this.draggingBBox.center[0] - cb.center[0],
510
+ y: this.draggingBBox.min[1] - cb.center[1],
511
+ },
512
+ });
513
+ }
514
+ if (Math.abs(this.draggingBBox.min[1] - cb.min[1]) <= this.tolerance) {
515
+ this.alignLinesForChoose.h.push({
516
+ dl: {
517
+ line: [
518
+ { x: cb.center[0], y: cb.max[1] },
519
+ { x: this.draggingBBox.center[0], y: cb.max[1] },
520
+ ],
521
+ lp: 'top',
522
+ },
523
+ offset: {
524
+ x: this.draggingBBox.center[0] - cb.center[0],
525
+ y: this.draggingBBox.min[1] - cb.min[1],
526
+ },
527
+ });
528
+ }
529
+ /* draggingBBox hcenter */
530
+ if (Math.abs(this.draggingBBox.center[1] - cb.max[1]) <= this.tolerance) {
531
+ this.alignLinesForChoose.h.push({
532
+ dl: {
533
+ line: [
534
+ { x: cb.center[0], y: cb.max[1] },
535
+ { x: this.draggingBBox.center[0], y: cb.max[1] },
536
+ ],
537
+ lp: 'hcenter',
538
+ },
539
+ offset: {
540
+ x: this.draggingBBox.center[0] - cb.center[0],
541
+ y: this.draggingBBox.center[1] - cb.max[1],
542
+ },
543
+ });
544
+ }
545
+ if (Math.abs(this.draggingBBox.center[1] - cb.center[1]) <= this.tolerance) {
546
+ this.alignLinesForChoose.h.push({
547
+ dl: {
548
+ line: [
549
+ { x: cb.center[0], y: cb.center[1] },
550
+ { x: this.draggingBBox.center[0], y: cb.center[1] },
551
+ ],
552
+ lp: 'hcenter',
553
+ },
554
+ offset: {
555
+ x: this.draggingBBox.center[0] - cb.center[0],
556
+ y: this.draggingBBox.center[1] - cb.center[1],
557
+ },
558
+ });
559
+ }
560
+ if (Math.abs(this.draggingBBox.center[1] - cb.min[1]) <= this.tolerance) {
561
+ this.alignLinesForChoose.h.push({
562
+ dl: {
563
+ line: [
564
+ { x: cb.center[0], y: cb.min[1] },
565
+ { x: this.draggingBBox.center[0], y: cb.min[1] },
566
+ ],
567
+ lp: 'hcenter',
568
+ },
569
+ offset: {
570
+ x: this.draggingBBox.center[0] - cb.center[0],
571
+ y: this.draggingBBox.center[1] - cb.min[1],
572
+ },
573
+ });
574
+ }
575
+ /* draggingBBox bottom */
576
+ if (Math.abs(this.draggingBBox.max[1] - cb.max[1]) <= this.tolerance) {
577
+ this.alignLinesForChoose.h.push({
578
+ dl: {
579
+ line: [
580
+ { x: cb.center[0], y: cb.max[1] },
581
+ { x: this.draggingBBox.center[0], y: cb.max[1] },
582
+ ],
583
+ lp: 'bottom',
584
+ },
585
+ offset: {
586
+ x: this.draggingBBox.center[0] - cb.center[0],
587
+ y: this.draggingBBox.max[1] - cb.max[1],
588
+ },
589
+ });
590
+ }
591
+ if (Math.abs(this.draggingBBox.max[1] - cb.center[1]) <= this.tolerance) {
592
+ this.alignLinesForChoose.h.push({
593
+ dl: {
594
+ line: [
595
+ { x: cb.center[0], y: cb.center[1] },
596
+ { x: this.draggingBBox.center[0], y: cb.center[1] },
597
+ ],
598
+ lp: 'bottom',
599
+ },
600
+ offset: {
601
+ x: this.draggingBBox.center[0] - cb.center[0],
602
+ y: this.draggingBBox.max[1] - cb.center[1],
603
+ },
604
+ });
605
+ }
606
+ if (Math.abs(this.draggingBBox.max[1] - cb.min[1]) <= this.tolerance) {
607
+ this.alignLinesForChoose.h.push({
608
+ dl: {
609
+ line: [
610
+ { x: cb.center[0], y: cb.min[1] },
611
+ { x: this.draggingBBox.center[0], y: cb.min[1] },
612
+ ],
613
+ lp: 'bottom',
614
+ },
615
+ offset: {
616
+ x: this.draggingBBox.center[0] - cb.center[0],
617
+ y: this.draggingBBox.max[1] - cb.min[1],
618
+ },
619
+ });
620
+ }
621
+ });
622
+ }
623
+ chooseAlignLine() {
624
+ // Principles:
625
+ // 1. Smaller difference from tolerance is more important
626
+ // 2. Same tolerance, (if multiple lines in the same direction are within the tolerance range) Importance: hcenter > top > bottom; vcenter > left > right
627
+ // 3. At most: vertical one count; horizon one count
628
+ // 4. Repeat line, will be subject to the longest (note: can't go to heavy, for performance, in the array of selected again)
629
+ // v direction line selection rule: draggingBBox's left/vcenter/right compares to vContrastPoints
630
+ // h direction line selection rule: draggingBBox's top/hcenter/bottom compares to hContrastPoints
631
+ if (this.alignLinesForChoose.v.length + this.alignLinesForChoose.h.length ===
632
+ 0) {
633
+ return { v: undefined, h: undefined };
634
+ }
635
+ let vTmpLines = [];
636
+ let hTmpLines = [];
637
+ // 1.v,h direction: select the line with minimum offset
638
+ const vMinOffset = Math.min(...this.alignLinesForChoose.v.map((dlFc) => dlFc.offset.x));
639
+ const hMinOffset = Math.min(...this.alignLinesForChoose.h.map((dlFc) => dlFc.offset.y));
640
+ vTmpLines = this.alignLinesForChoose.v.filter((dlFc) => dlFc.offset.x === vMinOffset);
641
+ hTmpLines = this.alignLinesForChoose.h.filter((dlFc) => dlFc.offset.y === hMinOffset);
642
+ // 2.same tolerance,hcenter > top > bottom; vcenter > left > right. (The principle of selecting only one direction)
643
+ {
644
+ const vcenter_hasdata = vTmpLines.some((dlFc) => dlFc.dl.lp === 'vcenter');
645
+ const left_hasdata = vTmpLines.some((dlFc) => dlFc.dl.lp === 'left');
646
+ vTmpLines = vTmpLines.filter((dlFc) => {
647
+ if (dlFc.dl.lp === 'vcenter') {
648
+ return true;
649
+ }
650
+ if (dlFc.dl.lp === 'left') {
651
+ if (!vcenter_hasdata && left_hasdata) {
652
+ return true;
653
+ }
654
+ return false;
655
+ }
656
+ if (dlFc.dl.lp === 'right') {
657
+ if (!vcenter_hasdata && !left_hasdata) {
658
+ return true;
659
+ }
660
+ return false;
661
+ }
662
+ return false;
663
+ });
664
+ const hcenter_hasdata = hTmpLines.some((dlFc) => dlFc.dl.lp === 'hcenter');
665
+ const top_hasdata = hTmpLines.some((dlFc) => dlFc.dl.lp === 'top');
666
+ hTmpLines = hTmpLines.filter((dlFc) => {
667
+ if (dlFc.dl.lp === 'hcenter') {
668
+ return true;
669
+ }
670
+ if (dlFc.dl.lp === 'top') {
671
+ if (!hcenter_hasdata && top_hasdata) {
672
+ return true;
673
+ }
674
+ return false;
675
+ }
676
+ if (dlFc.dl.lp === 'bottom') {
677
+ if (!hcenter_hasdata && !top_hasdata) {
678
+ return true;
679
+ }
680
+ return false;
681
+ }
682
+ return false;
683
+ });
684
+ }
685
+ // 3.remove duplicates
686
+ const uniVTmpLines = Array.from(vTmpLines
687
+ .reduce((map, item) => {
688
+ var _a;
689
+ if (!map.has(item.dl.lp) ||
690
+ Math.abs(item.offset.x) < Math.abs((_a = map.get(item.dl.lp)) === null || _a === void 0 ? void 0 : _a.offset.x)) {
691
+ map.set(item.dl.lp, item);
692
+ }
693
+ return map;
694
+ }, new Map())
695
+ .values());
696
+ const uniHTmpLines = Array.from(hTmpLines
697
+ .reduce((map, item) => {
698
+ var _a;
699
+ if (!map.has(item.dl.lp) ||
700
+ Math.abs(item.offset.y) < Math.abs((_a = map.get(item.dl.lp)) === null || _a === void 0 ? void 0 : _a.offset.y)) {
701
+ map.set(item.dl.lp, item);
702
+ }
703
+ return map;
704
+ }, new Map())
705
+ .values());
706
+ // 4.choose a maximum offset one of DrawLineForChoose
707
+ const vMaxDL = uniVTmpLines.length
708
+ ? uniVTmpLines.reduce((maxItem, curItem) => {
709
+ if (curItem.offset.x > maxItem.offset.x) {
710
+ return curItem;
711
+ }
712
+ else {
713
+ return maxItem;
714
+ }
715
+ })
716
+ : undefined;
717
+ const hMaxDL = uniHTmpLines.length
718
+ ? uniHTmpLines.reduce((maxItem, curItem) => {
719
+ if (curItem.offset.y > maxItem.offset.y) {
720
+ return curItem;
721
+ }
722
+ else {
723
+ return maxItem;
724
+ }
725
+ })
726
+ : undefined;
727
+ return {
728
+ v: vMaxDL ? vMaxDL.dl : undefined,
729
+ h: hMaxDL ? hMaxDL.dl : undefined,
730
+ };
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