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