@antv/g6 4.8.14-beta.0 → 5.0.0-alpha.1

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 (595) hide show
  1. package/dist/g6.min.js +19 -3
  2. package/esm/constant/index.d.ts +1 -0
  3. package/esm/constant/index.js +2 -0
  4. package/esm/constant/index.js.map +1 -0
  5. package/esm/constant/shape.d.ts +27 -0
  6. package/esm/constant/shape.js +26 -0
  7. package/esm/constant/shape.js.map +1 -0
  8. package/esm/index.d.ts +124 -0
  9. package/esm/index.js +11 -0
  10. package/esm/index.js.map +1 -0
  11. package/esm/item/combo.d.ts +4 -0
  12. package/esm/item/combo.js +4 -0
  13. package/esm/item/combo.js.map +1 -0
  14. package/esm/item/edge.d.ts +54 -0
  15. package/esm/item/edge.js +113 -0
  16. package/esm/item/edge.js.map +1 -0
  17. package/esm/item/item.d.ts +189 -0
  18. package/esm/item/item.js +636 -0
  19. package/esm/item/item.js.map +1 -0
  20. package/esm/item/node.d.ts +54 -0
  21. package/esm/item/node.js +170 -0
  22. package/esm/item/node.js.map +1 -0
  23. package/esm/runtime/controller/data.d.ts +65 -0
  24. package/esm/runtime/controller/data.js +489 -0
  25. package/esm/runtime/controller/data.js.map +1 -0
  26. package/esm/runtime/controller/extension.d.ts +9 -0
  27. package/esm/runtime/controller/extension.js +11 -0
  28. package/esm/runtime/controller/extension.js.map +1 -0
  29. package/esm/runtime/controller/index.d.ts +7 -0
  30. package/esm/runtime/controller/index.js +8 -0
  31. package/esm/runtime/controller/index.js.map +1 -0
  32. package/esm/runtime/controller/interaction.d.ts +51 -0
  33. package/esm/runtime/controller/interaction.js +259 -0
  34. package/esm/runtime/controller/interaction.js.map +1 -0
  35. package/esm/runtime/controller/item.d.ts +101 -0
  36. package/esm/runtime/controller/item.js +537 -0
  37. package/esm/runtime/controller/item.js.map +1 -0
  38. package/esm/runtime/controller/layout.d.ts +30 -0
  39. package/esm/runtime/controller/layout.js +204 -0
  40. package/esm/runtime/controller/layout.js.map +1 -0
  41. package/esm/runtime/controller/plugin.d.ts +34 -0
  42. package/esm/runtime/controller/plugin.js +140 -0
  43. package/esm/runtime/controller/plugin.js.map +1 -0
  44. package/esm/runtime/controller/theme.d.ts +29 -0
  45. package/esm/runtime/controller/theme.js +54 -0
  46. package/esm/runtime/controller/theme.js.map +1 -0
  47. package/esm/runtime/controller/viewport.d.ts +11 -0
  48. package/esm/runtime/controller/viewport.js +102 -0
  49. package/esm/runtime/controller/viewport.js.map +1 -0
  50. package/esm/runtime/graph.d.ts +462 -0
  51. package/esm/runtime/graph.js +1077 -0
  52. package/esm/runtime/graph.js.map +1 -0
  53. package/esm/runtime/hooks.d.ts +33 -0
  54. package/esm/runtime/hooks.js +74 -0
  55. package/esm/runtime/hooks.js.map +1 -0
  56. package/esm/stdlib/behavior/activate-relations.d.ts +62 -0
  57. package/esm/stdlib/behavior/activate-relations.js +81 -0
  58. package/esm/stdlib/behavior/activate-relations.js.map +1 -0
  59. package/esm/stdlib/behavior/brush-select.d.ts +110 -0
  60. package/esm/stdlib/behavior/brush-select.js +268 -0
  61. package/esm/stdlib/behavior/brush-select.js.map +1 -0
  62. package/esm/stdlib/behavior/click-select.d.ts +71 -0
  63. package/esm/stdlib/behavior/click-select.js +143 -0
  64. package/esm/stdlib/behavior/click-select.js.map +1 -0
  65. package/esm/stdlib/behavior/drag-canvas.d.ts +82 -0
  66. package/esm/stdlib/behavior/drag-canvas.js +246 -0
  67. package/esm/stdlib/behavior/drag-canvas.js.map +1 -0
  68. package/esm/stdlib/behavior/drag-node.d.ts +80 -0
  69. package/esm/stdlib/behavior/drag-node.js +250 -0
  70. package/esm/stdlib/behavior/drag-node.js.map +1 -0
  71. package/esm/stdlib/behavior/hover-activate.d.ts +41 -0
  72. package/esm/stdlib/behavior/hover-activate.js +63 -0
  73. package/esm/stdlib/behavior/hover-activate.js.map +1 -0
  74. package/esm/stdlib/behavior/lasso-select.d.ts +27 -0
  75. package/esm/stdlib/behavior/lasso-select.js +79 -0
  76. package/esm/stdlib/behavior/lasso-select.js.map +1 -0
  77. package/esm/stdlib/behavior/orbit-canvas-3d.d.ts +37 -0
  78. package/esm/stdlib/behavior/orbit-canvas-3d.js +62 -0
  79. package/esm/stdlib/behavior/orbit-canvas-3d.js.map +1 -0
  80. package/esm/stdlib/behavior/rotate-canvas-3d.d.ts +61 -0
  81. package/esm/stdlib/behavior/rotate-canvas-3d.js +123 -0
  82. package/esm/stdlib/behavior/rotate-canvas-3d.js.map +1 -0
  83. package/esm/stdlib/behavior/track-canvas-3d.d.ts +37 -0
  84. package/esm/stdlib/behavior/track-canvas-3d.js +62 -0
  85. package/esm/stdlib/behavior/track-canvas-3d.js.map +1 -0
  86. package/esm/stdlib/behavior/zoom-canvas-3d.d.ts +51 -0
  87. package/esm/stdlib/behavior/zoom-canvas-3d.js +74 -0
  88. package/esm/stdlib/behavior/zoom-canvas-3d.js.map +1 -0
  89. package/esm/stdlib/behavior/zoom-canvas.d.ts +61 -0
  90. package/esm/stdlib/behavior/zoom-canvas.js +160 -0
  91. package/esm/stdlib/behavior/zoom-canvas.js.map +1 -0
  92. package/esm/stdlib/data/comboFromNode.d.ts +9 -0
  93. package/esm/stdlib/data/comboFromNode.js +28 -0
  94. package/esm/stdlib/data/comboFromNode.js.map +1 -0
  95. package/esm/stdlib/index.d.ts +80 -0
  96. package/esm/stdlib/index.js +82 -0
  97. package/esm/stdlib/index.js.map +1 -0
  98. package/esm/stdlib/item/edge/base.d.ts +111 -0
  99. package/esm/stdlib/item/edge/base.js +341 -0
  100. package/esm/stdlib/item/edge/base.js.map +1 -0
  101. package/esm/stdlib/item/edge/index.d.ts +1 -0
  102. package/esm/stdlib/item/edge/index.js +2 -0
  103. package/esm/stdlib/item/edge/index.js.map +1 -0
  104. package/esm/stdlib/item/edge/line.d.ts +33 -0
  105. package/esm/stdlib/item/edge/line.js +45 -0
  106. package/esm/stdlib/item/edge/line.js.map +1 -0
  107. package/esm/stdlib/item/node/base.d.ts +137 -0
  108. package/esm/stdlib/item/node/base.js +414 -0
  109. package/esm/stdlib/item/node/base.js.map +1 -0
  110. package/esm/stdlib/item/node/base3d.d.ts +72 -0
  111. package/esm/stdlib/item/node/base3d.js +113 -0
  112. package/esm/stdlib/item/node/base3d.js.map +1 -0
  113. package/esm/stdlib/item/node/circle.d.ts +30 -0
  114. package/esm/stdlib/item/node/circle.js +56 -0
  115. package/esm/stdlib/item/node/circle.js.map +1 -0
  116. package/esm/stdlib/item/node/index.d.ts +2 -0
  117. package/esm/stdlib/item/node/index.js +3 -0
  118. package/esm/stdlib/item/node/index.js.map +1 -0
  119. package/esm/stdlib/item/node/sphere.d.ts +33 -0
  120. package/esm/stdlib/item/node/sphere.js +52 -0
  121. package/esm/stdlib/item/node/sphere.js.map +1 -0
  122. package/esm/stdlib/plugin/legend/index.d.ts +121 -0
  123. package/esm/stdlib/plugin/legend/index.js +587 -0
  124. package/esm/stdlib/plugin/legend/index.js.map +1 -0
  125. package/esm/stdlib/plugin/minimap/index.d.ts +106 -0
  126. package/esm/stdlib/plugin/minimap/index.js +578 -0
  127. package/esm/stdlib/plugin/minimap/index.js.map +1 -0
  128. package/esm/stdlib/selector/lasso.d.ts +15 -0
  129. package/esm/stdlib/selector/lasso.js +61 -0
  130. package/esm/stdlib/selector/lasso.js.map +1 -0
  131. package/esm/stdlib/selector/rect.d.ts +16 -0
  132. package/esm/stdlib/selector/rect.js +54 -0
  133. package/esm/stdlib/selector/rect.js.map +1 -0
  134. package/esm/stdlib/theme/dark.d.ts +3 -0
  135. package/esm/stdlib/theme/dark.js +279 -0
  136. package/esm/stdlib/theme/dark.js.map +1 -0
  137. package/esm/stdlib/theme/light.d.ts +3 -0
  138. package/esm/stdlib/theme/light.js +274 -0
  139. package/esm/stdlib/theme/light.js.map +1 -0
  140. package/esm/stdlib/themeSolver/base.d.ts +15 -0
  141. package/esm/stdlib/themeSolver/base.js +11 -0
  142. package/esm/stdlib/themeSolver/base.js.map +1 -0
  143. package/esm/stdlib/themeSolver/spec.d.ts +37 -0
  144. package/esm/stdlib/themeSolver/spec.js +66 -0
  145. package/esm/stdlib/themeSolver/spec.js.map +1 -0
  146. package/esm/stdlib/themeSolver/subject.d.ts +43 -0
  147. package/esm/stdlib/themeSolver/subject.js +396 -0
  148. package/esm/stdlib/themeSolver/subject.js.map +1 -0
  149. package/esm/types/animate.d.ts +59 -0
  150. package/esm/types/animate.js +2 -0
  151. package/esm/types/animate.js.map +1 -0
  152. package/esm/types/behavior.d.ts +45 -0
  153. package/esm/types/behavior.js +14 -0
  154. package/esm/types/behavior.js.map +1 -0
  155. package/esm/types/combo.d.ts +87 -0
  156. package/esm/types/combo.js +2 -0
  157. package/esm/types/combo.js.map +1 -0
  158. package/esm/types/common.d.ts +6 -0
  159. package/esm/types/common.js +2 -0
  160. package/esm/types/common.js.map +1 -0
  161. package/esm/types/data.d.ts +21 -0
  162. package/esm/types/data.js +2 -0
  163. package/esm/types/data.js.map +1 -0
  164. package/esm/types/edge.d.ts +100 -0
  165. package/esm/types/edge.js +2 -0
  166. package/esm/types/edge.js.map +1 -0
  167. package/esm/types/event.d.ts +30 -0
  168. package/esm/types/event.js +31 -0
  169. package/esm/types/event.js.map +1 -0
  170. package/esm/types/graph.d.ts +445 -0
  171. package/esm/types/graph.js +2 -0
  172. package/esm/types/graph.js.map +1 -0
  173. package/esm/types/hook.d.ts +97 -0
  174. package/esm/types/hook.js +2 -0
  175. package/esm/types/hook.js.map +1 -0
  176. package/esm/types/index.d.ts +10 -0
  177. package/esm/types/index.js +2 -0
  178. package/esm/types/index.js.map +1 -0
  179. package/esm/types/item.d.ts +229 -0
  180. package/esm/types/item.js +16 -0
  181. package/esm/types/item.js.map +1 -0
  182. package/esm/types/layout.d.ts +69 -0
  183. package/esm/types/layout.js +20 -0
  184. package/esm/types/layout.js.map +1 -0
  185. package/esm/types/node.d.ts +134 -0
  186. package/esm/types/node.js +2 -0
  187. package/esm/types/node.js.map +1 -0
  188. package/esm/types/plugin.d.ts +40 -0
  189. package/esm/types/plugin.js +53 -0
  190. package/esm/types/plugin.js.map +1 -0
  191. package/esm/types/render.d.ts +1 -0
  192. package/esm/types/render.js +2 -0
  193. package/esm/types/render.js.map +1 -0
  194. package/esm/types/spec.d.ts +65 -0
  195. package/esm/types/spec.js +2 -0
  196. package/esm/types/spec.js.map +1 -0
  197. package/esm/types/stdlib.d.ts +13 -0
  198. package/esm/types/stdlib.js +2 -0
  199. package/esm/types/stdlib.js.map +1 -0
  200. package/esm/types/theme.d.ts +102 -0
  201. package/esm/types/theme.js +15 -0
  202. package/esm/types/theme.js.map +1 -0
  203. package/esm/types/view.d.ts +23 -0
  204. package/esm/types/view.js +2 -0
  205. package/esm/types/view.js.map +1 -0
  206. package/esm/util/animate.d.ts +101 -0
  207. package/esm/util/animate.js +350 -0
  208. package/esm/util/animate.js.map +1 -0
  209. package/esm/util/array.d.ts +20 -0
  210. package/esm/util/array.js +60 -0
  211. package/esm/util/array.js.map +1 -0
  212. package/esm/util/canvas.d.ts +20 -0
  213. package/esm/util/canvas.js +81 -0
  214. package/esm/util/canvas.js.map +1 -0
  215. package/esm/util/event.d.ts +12 -0
  216. package/esm/util/event.js +26 -0
  217. package/esm/util/event.js.map +1 -0
  218. package/esm/util/extend.d.ts +21 -0
  219. package/esm/util/extend.js +22 -0
  220. package/esm/util/extend.js.map +1 -0
  221. package/esm/util/extension.d.ts +10 -0
  222. package/esm/util/extension.js +24 -0
  223. package/esm/util/extension.js.map +1 -0
  224. package/esm/util/index.d.ts +14 -0
  225. package/esm/util/index.js +5 -0
  226. package/esm/util/index.js.map +1 -0
  227. package/esm/util/item.d.ts +14 -0
  228. package/esm/util/item.js +42 -0
  229. package/esm/util/item.js.map +1 -0
  230. package/esm/util/mapper.d.ts +17 -0
  231. package/esm/util/mapper.js +60 -0
  232. package/esm/util/mapper.js.map +1 -0
  233. package/esm/util/math.d.ts +8 -0
  234. package/esm/util/math.js +9 -0
  235. package/esm/util/math.js.map +1 -0
  236. package/esm/util/point.d.ts +61 -0
  237. package/esm/util/point.js +160 -0
  238. package/esm/util/point.js.map +1 -0
  239. package/esm/util/shape.d.ts +105 -0
  240. package/esm/util/shape.js +504 -0
  241. package/esm/util/shape.js.map +1 -0
  242. package/esm/util/shape3d.d.ts +23 -0
  243. package/esm/util/shape3d.js +147 -0
  244. package/esm/util/shape3d.js.map +1 -0
  245. package/esm/util/text.d.ts +18 -0
  246. package/esm/util/text.js +36 -0
  247. package/esm/util/text.js.map +1 -0
  248. package/esm/util/type.d.ts +2 -0
  249. package/esm/util/type.js +2 -0
  250. package/esm/util/type.js.map +1 -0
  251. package/esm/util/zoom.d.ts +17 -0
  252. package/esm/util/zoom.js +36 -0
  253. package/esm/util/zoom.js.map +1 -0
  254. package/lib/constant/index.d.ts +1 -0
  255. package/lib/constant/index.js +18 -0
  256. package/lib/constant/index.js.map +1 -0
  257. package/lib/constant/shape.d.ts +27 -0
  258. package/lib/constant/shape.js +29 -0
  259. package/lib/constant/shape.js.map +1 -0
  260. package/lib/index.d.ts +124 -4
  261. package/lib/index.js +30 -27
  262. package/lib/index.js.map +1 -0
  263. package/lib/item/combo.d.ts +4 -0
  264. package/lib/item/combo.js +10 -0
  265. package/lib/item/combo.js.map +1 -0
  266. package/lib/item/edge.d.ts +54 -0
  267. package/lib/item/edge.js +119 -0
  268. package/lib/item/edge.js.map +1 -0
  269. package/lib/item/item.d.ts +189 -0
  270. package/lib/item/item.js +639 -0
  271. package/lib/item/item.js.map +1 -0
  272. package/lib/item/node.d.ts +54 -0
  273. package/lib/item/node.js +176 -0
  274. package/lib/item/node.js.map +1 -0
  275. package/lib/runtime/controller/data.d.ts +65 -0
  276. package/lib/runtime/controller/data.js +493 -0
  277. package/lib/runtime/controller/data.js.map +1 -0
  278. package/lib/runtime/controller/extension.d.ts +9 -0
  279. package/lib/runtime/controller/extension.js +15 -0
  280. package/lib/runtime/controller/extension.js.map +1 -0
  281. package/lib/runtime/controller/index.d.ts +7 -0
  282. package/lib/runtime/controller/index.js +24 -0
  283. package/lib/runtime/controller/index.js.map +1 -0
  284. package/lib/runtime/controller/interaction.d.ts +51 -0
  285. package/lib/runtime/controller/interaction.js +263 -0
  286. package/lib/runtime/controller/interaction.js.map +1 -0
  287. package/lib/runtime/controller/item.d.ts +101 -0
  288. package/lib/runtime/controller/item.js +544 -0
  289. package/lib/runtime/controller/item.js.map +1 -0
  290. package/lib/runtime/controller/layout.d.ts +30 -0
  291. package/lib/runtime/controller/layout.js +208 -0
  292. package/lib/runtime/controller/layout.js.map +1 -0
  293. package/lib/runtime/controller/plugin.d.ts +34 -0
  294. package/lib/runtime/controller/plugin.js +147 -0
  295. package/lib/runtime/controller/plugin.js.map +1 -0
  296. package/lib/runtime/controller/theme.d.ts +29 -0
  297. package/lib/runtime/controller/theme.js +61 -0
  298. package/lib/runtime/controller/theme.js.map +1 -0
  299. package/lib/runtime/controller/viewport.d.ts +11 -0
  300. package/lib/runtime/controller/viewport.js +106 -0
  301. package/lib/runtime/controller/viewport.js.map +1 -0
  302. package/lib/runtime/graph.d.ts +462 -0
  303. package/lib/runtime/graph.js +1083 -0
  304. package/lib/runtime/graph.js.map +1 -0
  305. package/lib/runtime/hooks.d.ts +33 -0
  306. package/lib/runtime/hooks.js +77 -0
  307. package/lib/runtime/hooks.js.map +1 -0
  308. package/lib/stdlib/behavior/activate-relations.d.ts +62 -0
  309. package/lib/stdlib/behavior/activate-relations.js +84 -0
  310. package/lib/stdlib/behavior/activate-relations.js.map +1 -0
  311. package/lib/stdlib/behavior/brush-select.d.ts +110 -0
  312. package/lib/stdlib/behavior/brush-select.js +271 -0
  313. package/lib/stdlib/behavior/brush-select.js.map +1 -0
  314. package/lib/stdlib/behavior/click-select.d.ts +71 -0
  315. package/lib/stdlib/behavior/click-select.js +146 -0
  316. package/lib/stdlib/behavior/click-select.js.map +1 -0
  317. package/lib/stdlib/behavior/drag-canvas.d.ts +82 -0
  318. package/lib/stdlib/behavior/drag-canvas.js +249 -0
  319. package/lib/stdlib/behavior/drag-canvas.js.map +1 -0
  320. package/lib/stdlib/behavior/drag-node.d.ts +80 -0
  321. package/lib/stdlib/behavior/drag-node.js +253 -0
  322. package/lib/stdlib/behavior/drag-node.js.map +1 -0
  323. package/lib/stdlib/behavior/hover-activate.d.ts +41 -0
  324. package/lib/stdlib/behavior/hover-activate.js +67 -0
  325. package/lib/stdlib/behavior/hover-activate.js.map +1 -0
  326. package/lib/stdlib/behavior/lasso-select.d.ts +27 -0
  327. package/lib/stdlib/behavior/lasso-select.js +85 -0
  328. package/lib/stdlib/behavior/lasso-select.js.map +1 -0
  329. package/lib/stdlib/behavior/orbit-canvas-3d.d.ts +37 -0
  330. package/lib/stdlib/behavior/orbit-canvas-3d.js +68 -0
  331. package/lib/stdlib/behavior/orbit-canvas-3d.js.map +1 -0
  332. package/lib/stdlib/behavior/rotate-canvas-3d.d.ts +61 -0
  333. package/lib/stdlib/behavior/rotate-canvas-3d.js +126 -0
  334. package/lib/stdlib/behavior/rotate-canvas-3d.js.map +1 -0
  335. package/lib/stdlib/behavior/track-canvas-3d.d.ts +37 -0
  336. package/lib/stdlib/behavior/track-canvas-3d.js +68 -0
  337. package/lib/stdlib/behavior/track-canvas-3d.js.map +1 -0
  338. package/lib/stdlib/behavior/zoom-canvas-3d.d.ts +51 -0
  339. package/lib/stdlib/behavior/zoom-canvas-3d.js +77 -0
  340. package/lib/stdlib/behavior/zoom-canvas-3d.js.map +1 -0
  341. package/lib/stdlib/behavior/zoom-canvas.d.ts +61 -0
  342. package/lib/stdlib/behavior/zoom-canvas.js +163 -0
  343. package/lib/stdlib/behavior/zoom-canvas.js.map +1 -0
  344. package/lib/stdlib/data/comboFromNode.d.ts +9 -0
  345. package/lib/stdlib/data/comboFromNode.js +32 -0
  346. package/lib/stdlib/data/comboFromNode.js.map +1 -0
  347. package/lib/stdlib/index.d.ts +80 -0
  348. package/lib/stdlib/index.js +90 -0
  349. package/lib/stdlib/index.js.map +1 -0
  350. package/lib/stdlib/item/edge/base.d.ts +111 -0
  351. package/lib/stdlib/item/edge/base.js +345 -0
  352. package/lib/stdlib/item/edge/base.js.map +1 -0
  353. package/lib/stdlib/item/edge/index.d.ts +1 -0
  354. package/lib/stdlib/item/edge/index.js +18 -0
  355. package/lib/stdlib/item/edge/index.js.map +1 -0
  356. package/lib/stdlib/item/edge/line.d.ts +33 -0
  357. package/lib/stdlib/item/edge/line.js +49 -0
  358. package/lib/stdlib/item/edge/line.js.map +1 -0
  359. package/lib/stdlib/item/node/base.d.ts +137 -0
  360. package/lib/stdlib/item/node/base.js +418 -0
  361. package/lib/stdlib/item/node/base.js.map +1 -0
  362. package/lib/stdlib/item/node/base3d.d.ts +72 -0
  363. package/lib/stdlib/item/node/base3d.js +117 -0
  364. package/lib/stdlib/item/node/base3d.js.map +1 -0
  365. package/lib/stdlib/item/node/circle.d.ts +30 -0
  366. package/lib/stdlib/item/node/circle.js +60 -0
  367. package/lib/stdlib/item/node/circle.js.map +1 -0
  368. package/lib/stdlib/item/node/index.d.ts +2 -0
  369. package/lib/stdlib/item/node/index.js +19 -0
  370. package/lib/stdlib/item/node/index.js.map +1 -0
  371. package/lib/stdlib/item/node/sphere.d.ts +33 -0
  372. package/lib/stdlib/item/node/sphere.js +56 -0
  373. package/lib/stdlib/item/node/sphere.js.map +1 -0
  374. package/lib/stdlib/plugin/legend/index.d.ts +121 -0
  375. package/lib/stdlib/plugin/legend/index.js +590 -0
  376. package/lib/stdlib/plugin/legend/index.js.map +1 -0
  377. package/lib/stdlib/plugin/minimap/index.d.ts +106 -0
  378. package/lib/stdlib/plugin/minimap/index.js +581 -0
  379. package/lib/stdlib/plugin/minimap/index.js.map +1 -0
  380. package/lib/stdlib/selector/lasso.d.ts +15 -0
  381. package/lib/stdlib/selector/lasso.js +63 -0
  382. package/lib/stdlib/selector/lasso.js.map +1 -0
  383. package/lib/stdlib/selector/rect.d.ts +16 -0
  384. package/lib/stdlib/selector/rect.js +56 -0
  385. package/lib/stdlib/selector/rect.js.map +1 -0
  386. package/lib/stdlib/theme/dark.d.ts +3 -0
  387. package/lib/stdlib/theme/dark.js +281 -0
  388. package/lib/stdlib/theme/dark.js.map +1 -0
  389. package/lib/stdlib/theme/light.d.ts +3 -0
  390. package/lib/stdlib/theme/light.js +276 -0
  391. package/lib/stdlib/theme/light.js.map +1 -0
  392. package/lib/stdlib/themeSolver/base.d.ts +15 -0
  393. package/lib/stdlib/themeSolver/base.js +14 -0
  394. package/lib/stdlib/themeSolver/base.js.map +1 -0
  395. package/lib/stdlib/themeSolver/spec.d.ts +37 -0
  396. package/lib/stdlib/themeSolver/spec.js +72 -0
  397. package/lib/stdlib/themeSolver/spec.js.map +1 -0
  398. package/lib/stdlib/themeSolver/subject.d.ts +43 -0
  399. package/lib/stdlib/themeSolver/subject.js +404 -0
  400. package/lib/stdlib/themeSolver/subject.js.map +1 -0
  401. package/lib/types/animate.d.ts +59 -0
  402. package/lib/types/animate.js +3 -0
  403. package/lib/types/animate.js.map +1 -0
  404. package/lib/types/behavior.d.ts +45 -0
  405. package/lib/types/behavior.js +18 -0
  406. package/lib/types/behavior.js.map +1 -0
  407. package/lib/types/combo.d.ts +87 -0
  408. package/lib/types/combo.js +3 -0
  409. package/lib/types/combo.js.map +1 -0
  410. package/lib/types/common.d.ts +6 -0
  411. package/lib/types/common.js +3 -0
  412. package/lib/types/common.js.map +1 -0
  413. package/lib/types/data.d.ts +21 -0
  414. package/lib/types/data.js +3 -0
  415. package/lib/types/data.js.map +1 -0
  416. package/lib/types/edge.d.ts +100 -0
  417. package/lib/types/edge.js +3 -0
  418. package/lib/types/edge.js.map +1 -0
  419. package/lib/types/event.d.ts +30 -0
  420. package/lib/types/event.js +34 -0
  421. package/lib/types/event.js.map +1 -0
  422. package/lib/types/graph.d.ts +445 -0
  423. package/lib/types/graph.js +3 -0
  424. package/lib/types/graph.js.map +1 -0
  425. package/lib/types/hook.d.ts +97 -0
  426. package/lib/types/hook.js +3 -0
  427. package/lib/types/hook.js.map +1 -0
  428. package/lib/types/index.d.ts +10 -0
  429. package/lib/types/index.js +7 -0
  430. package/lib/types/index.js.map +1 -0
  431. package/lib/types/item.d.ts +229 -0
  432. package/lib/types/item.js +19 -0
  433. package/lib/types/item.js.map +1 -0
  434. package/lib/types/layout.d.ts +69 -0
  435. package/lib/types/layout.js +25 -0
  436. package/lib/types/layout.js.map +1 -0
  437. package/lib/types/node.d.ts +134 -0
  438. package/lib/types/node.js +3 -0
  439. package/lib/types/node.js.map +1 -0
  440. package/lib/types/plugin.d.ts +40 -0
  441. package/lib/types/plugin.js +57 -0
  442. package/lib/types/plugin.js.map +1 -0
  443. package/lib/types/render.d.ts +1 -0
  444. package/lib/types/render.js +3 -0
  445. package/lib/types/render.js.map +1 -0
  446. package/lib/types/spec.d.ts +65 -0
  447. package/lib/types/spec.js +3 -0
  448. package/lib/types/spec.js.map +1 -0
  449. package/lib/types/stdlib.d.ts +13 -0
  450. package/lib/types/stdlib.js +3 -0
  451. package/lib/types/stdlib.js.map +1 -0
  452. package/lib/types/theme.d.ts +102 -0
  453. package/lib/types/theme.js +19 -0
  454. package/lib/types/theme.js.map +1 -0
  455. package/lib/types/view.d.ts +23 -0
  456. package/lib/types/view.js +3 -0
  457. package/lib/types/view.js.map +1 -0
  458. package/lib/util/animate.d.ts +101 -0
  459. package/lib/util/animate.js +358 -0
  460. package/lib/util/animate.js.map +1 -0
  461. package/lib/util/array.d.ts +20 -0
  462. package/lib/util/array.js +68 -0
  463. package/lib/util/array.js.map +1 -0
  464. package/lib/util/canvas.d.ts +20 -0
  465. package/lib/util/canvas.js +86 -0
  466. package/lib/util/canvas.js.map +1 -0
  467. package/lib/util/event.d.ts +12 -0
  468. package/lib/util/event.js +30 -0
  469. package/lib/util/event.js.map +1 -0
  470. package/lib/util/extend.d.ts +21 -0
  471. package/lib/util/extend.js +29 -0
  472. package/lib/util/extend.js.map +1 -0
  473. package/lib/util/extension.d.ts +10 -0
  474. package/lib/util/extension.js +29 -0
  475. package/lib/util/extension.js.map +1 -0
  476. package/lib/util/index.d.ts +14 -0
  477. package/lib/util/index.js +7 -0
  478. package/lib/util/index.js.map +1 -0
  479. package/lib/util/item.d.ts +14 -0
  480. package/lib/util/item.js +47 -0
  481. package/lib/util/item.js.map +1 -0
  482. package/lib/util/mapper.d.ts +17 -0
  483. package/lib/util/mapper.js +63 -0
  484. package/lib/util/mapper.js.map +1 -0
  485. package/lib/util/math.d.ts +8 -0
  486. package/lib/util/math.js +13 -0
  487. package/lib/util/math.js.map +1 -0
  488. package/lib/util/point.d.ts +61 -0
  489. package/lib/util/point.js +169 -0
  490. package/lib/util/point.js.map +1 -0
  491. package/lib/util/shape.d.ts +105 -0
  492. package/lib/util/shape.js +519 -0
  493. package/lib/util/shape.js.map +1 -0
  494. package/lib/util/shape3d.d.ts +23 -0
  495. package/lib/util/shape3d.js +153 -0
  496. package/lib/util/shape3d.js.map +1 -0
  497. package/lib/util/text.d.ts +18 -0
  498. package/lib/util/text.js +41 -0
  499. package/lib/util/text.js.map +1 -0
  500. package/lib/util/type.d.ts +2 -0
  501. package/lib/util/type.js +6 -0
  502. package/lib/util/type.js.map +1 -0
  503. package/lib/util/zoom.d.ts +17 -0
  504. package/lib/util/zoom.js +41 -0
  505. package/lib/util/zoom.js.map +1 -0
  506. package/package.json +82 -50
  507. package/src/constant/index.ts +1 -0
  508. package/src/constant/shape.ts +33 -0
  509. package/src/index.ts +13 -0
  510. package/src/item/combo.ts +5 -0
  511. package/src/item/edge.ts +177 -0
  512. package/src/item/item.ts +812 -0
  513. package/src/item/node.ts +275 -0
  514. package/src/runtime/controller/data.ts +575 -0
  515. package/src/runtime/controller/extension.ts +14 -0
  516. package/src/runtime/controller/index.ts +7 -0
  517. package/src/runtime/controller/interaction.ts +343 -0
  518. package/src/runtime/controller/item.ts +780 -0
  519. package/src/runtime/controller/layout.ts +251 -0
  520. package/src/runtime/controller/plugin.ts +171 -0
  521. package/src/runtime/controller/theme.ts +69 -0
  522. package/src/runtime/controller/viewport.ts +131 -0
  523. package/src/runtime/graph.ts +1439 -0
  524. package/src/runtime/hooks.ts +64 -0
  525. package/src/stdlib/behavior/activate-relations.ts +139 -0
  526. package/src/stdlib/behavior/brush-select.ts +386 -0
  527. package/src/stdlib/behavior/click-select.ts +201 -0
  528. package/src/stdlib/behavior/drag-canvas.ts +333 -0
  529. package/src/stdlib/behavior/drag-node.ts +402 -0
  530. package/src/stdlib/behavior/hover-activate.ts +106 -0
  531. package/src/stdlib/behavior/lasso-select.ts +94 -0
  532. package/src/stdlib/behavior/orbit-canvas-3d.ts +104 -0
  533. package/src/stdlib/behavior/rotate-canvas-3d.ts +172 -0
  534. package/src/stdlib/behavior/track-canvas-3d.ts +104 -0
  535. package/src/stdlib/behavior/zoom-canvas-3d.ts +127 -0
  536. package/src/stdlib/behavior/zoom-canvas.ts +244 -0
  537. package/src/stdlib/data/comboFromNode.ts +28 -0
  538. package/src/stdlib/index.ts +87 -0
  539. package/src/stdlib/item/edge/base.ts +571 -0
  540. package/src/stdlib/item/edge/index.ts +1 -0
  541. package/src/stdlib/item/edge/line.ts +98 -0
  542. package/src/stdlib/item/node/base.ts +726 -0
  543. package/src/stdlib/item/node/base3d.ts +192 -0
  544. package/src/stdlib/item/node/circle.ts +113 -0
  545. package/src/stdlib/item/node/index.ts +2 -0
  546. package/src/stdlib/item/node/sphere.ts +99 -0
  547. package/src/stdlib/plugin/legend/index.ts +733 -0
  548. package/src/stdlib/plugin/minimap/index.ts +689 -0
  549. package/src/stdlib/selector/lasso.ts +75 -0
  550. package/src/stdlib/selector/rect.ts +78 -0
  551. package/src/stdlib/theme/dark.ts +340 -0
  552. package/src/stdlib/theme/light.ts +333 -0
  553. package/src/stdlib/themeSolver/base.ts +22 -0
  554. package/src/stdlib/themeSolver/spec.ts +110 -0
  555. package/src/stdlib/themeSolver/subject.ts +502 -0
  556. package/src/types/animate.ts +71 -0
  557. package/src/types/behavior.ts +49 -0
  558. package/src/types/combo.ts +120 -0
  559. package/src/types/common.ts +7 -0
  560. package/src/types/data.ts +35 -0
  561. package/src/types/edge.ts +119 -0
  562. package/src/types/event.ts +47 -0
  563. package/src/types/graph.ts +573 -0
  564. package/src/types/hook.ts +98 -0
  565. package/src/types/index.ts +29 -0
  566. package/src/types/item.ts +324 -0
  567. package/src/types/layout.ts +138 -0
  568. package/src/types/node.ts +162 -0
  569. package/src/types/plugin.ts +77 -0
  570. package/src/types/render.ts +1 -0
  571. package/src/types/spec.ts +116 -0
  572. package/src/types/stdlib.ts +25 -0
  573. package/src/types/theme.ts +101 -0
  574. package/src/types/view.ts +31 -0
  575. package/src/util/animate.ts +430 -0
  576. package/src/util/array.ts +57 -0
  577. package/src/util/canvas.ts +95 -0
  578. package/src/util/event.ts +34 -0
  579. package/src/util/extend.ts +42 -0
  580. package/src/util/extension.ts +29 -0
  581. package/src/util/index.ts +4 -0
  582. package/src/util/item.ts +70 -0
  583. package/src/util/mapper.ts +61 -0
  584. package/src/util/math.ts +9 -0
  585. package/src/util/point.ts +195 -0
  586. package/src/util/shape.ts +609 -0
  587. package/src/util/shape3d.ts +198 -0
  588. package/src/util/text.ts +49 -0
  589. package/src/util/type.ts +4 -0
  590. package/src/util/zoom.ts +39 -0
  591. package/README.en-US.md +0 -170
  592. package/README.md +0 -177
  593. package/dist/g6.min.js.map +0 -1
  594. package/es/index.d.ts +0 -4
  595. package/es/index.js +0 -5
@@ -0,0 +1,609 @@
1
+ import {
2
+ Circle,
3
+ DisplayObject,
4
+ Ellipse,
5
+ Group,
6
+ IElement,
7
+ Line,
8
+ Polygon,
9
+ Polyline,
10
+ Rect,
11
+ Text,
12
+ Image,
13
+ Path,
14
+ AABB,
15
+ } from '@antv/g';
16
+ import { clone, isArray, isNumber } from '@antv/util';
17
+ import { DEFAULT_LABEL_BG_PADDING, RESERVED_SHAPE_IDS } from '../constant';
18
+ import { Point } from '../types/common';
19
+ import { EdgeDisplayModel, EdgeShapeMap } from '../types/edge';
20
+ import {
21
+ GShapeStyle,
22
+ SHAPE_TYPE,
23
+ ItemShapeStyles,
24
+ ShapeStyle,
25
+ SHAPE_TYPE_3D,
26
+ } from '../types/item';
27
+ import { NodeDisplayModel, NodeShapeMap } from '../types/node';
28
+ import { ComboDisplayModel } from '../types';
29
+ import { getShapeAnimateBeginStyles } from './animate';
30
+ import { isArrayOverlap } from './array';
31
+ import { isBetween } from './math';
32
+ import { getZoomLevel } from './zoom';
33
+
34
+ export const ShapeTagMap = {
35
+ circle: Circle,
36
+ rect: Rect,
37
+ ellipse: Ellipse,
38
+ polygon: Polygon,
39
+ line: Line,
40
+ polyline: Polyline,
41
+ text: Text,
42
+ image: Image,
43
+ path: Path,
44
+ };
45
+
46
+ const LINE_TYPES = ['line', 'polyline', 'path'];
47
+
48
+ export const LOCAL_BOUNDS_DIRTY_FLAG_KEY = 'data-item-local-bounds-dirty';
49
+
50
+ export const createShape = (
51
+ type: SHAPE_TYPE,
52
+ style: GShapeStyle,
53
+ id: string,
54
+ ) => {
55
+ const ShapeClass = ShapeTagMap[type];
56
+ const shape = new ShapeClass({ id, style });
57
+ if (LINE_TYPES.includes(type)) {
58
+ shape.style.increasedLineWidthForHitTesting = Math.max(
59
+ shape.style.lineWidth as number,
60
+ 6,
61
+ );
62
+ }
63
+ return shape;
64
+ };
65
+
66
+ /**
67
+ * Collect the fields to be animated at the timing on shape with shapeId.
68
+ * @param animates animate configs
69
+ * @param timing
70
+ * @param shapeId
71
+ * @returns
72
+ */
73
+ const findAnimateFields = (animates, timing, shapeId) => {
74
+ if (!animates?.[timing]) return [];
75
+ let animateFields = [];
76
+ animates[timing].forEach(({ fields, shapeId: animateShapeId }) => {
77
+ if (animateShapeId === shapeId) {
78
+ animateFields = animateFields.concat(fields);
79
+ } else if (
80
+ (!animateShapeId || animateShapeId === 'group') &&
81
+ fields.includes('opacity')
82
+ ) {
83
+ // group opacity, all shapes animates with opacity
84
+ animateFields.push('opacity');
85
+ }
86
+ });
87
+ if (animateFields.includes(undefined)) {
88
+ // there is an animate on all styles
89
+ return [];
90
+ }
91
+ return animateFields;
92
+ };
93
+
94
+ /**
95
+ * Create (if does not exit in shapeMap) or update the shape according to the configurations.
96
+ * @param type shape's type
97
+ * @param id unique string to indicates the shape
98
+ * @param style style to be updated
99
+ * @param shapeMap the shape map of a node / edge / combo
100
+ * @param model data model of the node / edge / combo
101
+ * @returns
102
+ */
103
+ export const upsertShape = (
104
+ type: SHAPE_TYPE,
105
+ id: string,
106
+ style: GShapeStyle,
107
+ shapeMap: { [shapeId: string]: DisplayObject },
108
+ model?: NodeDisplayModel | EdgeDisplayModel | ComboDisplayModel,
109
+ ): DisplayObject => {
110
+ let shape = shapeMap[id];
111
+ const { animates, disableAnimate } = model?.data || {};
112
+ if (!shape) {
113
+ // create
114
+ shape = createShape(type, style, id);
115
+ // find the animate styles, set them to be INIT_SHAPE_STYLES
116
+ if (!disableAnimate && animates) {
117
+ const animateFields = findAnimateFields(animates, 'buildIn', id);
118
+ const initShapeStyles = getShapeAnimateBeginStyles(shape);
119
+ animateFields.forEach((key) => {
120
+ shape.style[key] = initShapeStyles[key];
121
+ });
122
+ }
123
+ shape.setAttribute(LOCAL_BOUNDS_DIRTY_FLAG_KEY, true);
124
+ } else if (shape.nodeName !== type) {
125
+ // remove and create for the shape changed type
126
+ shape.remove();
127
+ shape = createShape(type, style, id);
128
+ shape.setAttribute(LOCAL_BOUNDS_DIRTY_FLAG_KEY, true);
129
+ } else {
130
+ const updateStyles = {};
131
+ const oldStyles = shape.attributes;
132
+ // update
133
+ // update the styles excludes the ones in the animate fields
134
+ const animateFields = findAnimateFields(animates, 'update', id);
135
+ if (disableAnimate || !animates?.update || !animateFields.length) {
136
+ // update all the style directly when there are no animates for update timing
137
+ Object.keys(style).forEach((key) => {
138
+ if (oldStyles[key] !== style[key]) {
139
+ updateStyles[key] = style[key];
140
+ shape.style[key] = style[key];
141
+ }
142
+ });
143
+ } else {
144
+ Object.keys(style).forEach((key) => {
145
+ if (oldStyles[key] !== style[key]) {
146
+ updateStyles[key] = style[key];
147
+ if (!animateFields.includes(key)) {
148
+ shape.style[key] = style[key];
149
+ }
150
+ }
151
+ });
152
+ }
153
+ if (isStyleAffectBBox(type, updateStyles)) {
154
+ shape.setAttribute(LOCAL_BOUNDS_DIRTY_FLAG_KEY, true);
155
+ }
156
+ }
157
+ shapeMap[id] = shape;
158
+ return shape;
159
+ };
160
+
161
+ export const getGroupSucceedMap = (
162
+ group: IElement,
163
+ map?: { [id: string]: IElement },
164
+ ) => {
165
+ const useMap = map || {};
166
+ group.children.forEach((child) => {
167
+ if (child.tagName === 'group') getGroupSucceedMap(child, useMap);
168
+ useMap[child.id] = child;
169
+ });
170
+ return useMap;
171
+ };
172
+
173
+ /**
174
+ * Update shapes in the intersaction of prevShapeMap and newShapeMap;
175
+ * Remove shapes in the prevShapeMap - newShapeMap (if removeDiff is true);
176
+ * Add shapes in the newShapeMap - prevShapeMap;
177
+ * @param prevShapeMap previous shape map
178
+ * @param newShapeMap new shape map
179
+ * @param group container group
180
+ * @returns merged shape map
181
+ */
182
+ export const updateShapes = (
183
+ prevShapeMap: { [id: string]: DisplayObject },
184
+ newShapeMap: { [id: string]: DisplayObject },
185
+ group: Group,
186
+ removeDiff = true,
187
+ shouldUpdate: (id: string) => boolean = () => true,
188
+ ): NodeShapeMap | EdgeShapeMap => {
189
+ const tolalMap = {
190
+ ...prevShapeMap,
191
+ ...newShapeMap,
192
+ };
193
+ const finalShapeMap = {
194
+ ...prevShapeMap,
195
+ };
196
+ Object.keys(tolalMap).forEach((id) => {
197
+ const prevShape = prevShapeMap[id];
198
+ const newShape = newShapeMap[id];
199
+ if (newShape && !shouldUpdate(id)) return;
200
+ if (prevShape && newShape) {
201
+ // update intersaction
202
+ finalShapeMap[id] = newShape;
203
+ if (prevShape !== newShape) {
204
+ prevShape.remove();
205
+ }
206
+ if (newShape.style.display !== 'none') {
207
+ group.appendChild(newShape);
208
+ }
209
+ } else if (!prevShape && newShape) {
210
+ // add newShapeMap - prevShapeMap
211
+ finalShapeMap[id] = newShape;
212
+ if (newShape.style.display !== 'none') {
213
+ group.appendChild(newShape);
214
+ }
215
+ } else if (prevShape && !newShape && removeDiff) {
216
+ // remove prevShapeMap - newShapeMap
217
+ delete finalShapeMap[id];
218
+ prevShape.remove();
219
+ }
220
+ });
221
+ return finalShapeMap as NodeShapeMap;
222
+ };
223
+
224
+ /**
225
+ * Format the number or array padding to an array with length 4, [padding-top, padding-right, padding-bottom, padding-left].
226
+ * @param value value to be formatted
227
+ * @param defaultArr default value
228
+ * @returns [padding-top, padding-right, padding-bottom, padding-left]
229
+ */
230
+ export const formatPadding = (value, defaultArr = DEFAULT_LABEL_BG_PADDING) => {
231
+ if (isArray(value)) {
232
+ switch (value.length) {
233
+ case 0:
234
+ return defaultArr;
235
+ case 1:
236
+ return [value[0], value[0], value[0], value[0]];
237
+ case 2:
238
+ return value.concat(value);
239
+ case 3:
240
+ return value.concat([value[0]]);
241
+ default:
242
+ return value;
243
+ }
244
+ }
245
+ if (isNumber(value)) return [value, value, value, value];
246
+ return defaultArr;
247
+ };
248
+
249
+ /**
250
+ * Merge multiple shape style map including undefined value in incoming map.
251
+ * @param styleMaps shapes' styles map array, the latter item in the array will be merged into the former
252
+ * @returns
253
+ */
254
+ export const mergeStyles = (styleMaps: ItemShapeStyles[]) => {
255
+ let currentResult = styleMaps[0];
256
+ styleMaps.forEach((styleMap, i) => {
257
+ if (i > 0) currentResult = merge2Styles(currentResult, styleMap);
258
+ });
259
+ return currentResult;
260
+ };
261
+
262
+ /**
263
+ * Merge two shape style map including undefined value in incoming map.
264
+ * @param styleMap1 shapes' styles map as current map
265
+ * @param styleMap2 shapes' styles map as incoming map
266
+ * @returns
267
+ */
268
+ const merge2Styles = (
269
+ styleMap1: ItemShapeStyles,
270
+ styleMap2: ItemShapeStyles,
271
+ ) => {
272
+ if (!styleMap1) return { ...styleMap2 };
273
+ else if (!styleMap2) return { ...styleMap1 };
274
+ const mergedStyle = clone(styleMap1);
275
+ Object.keys(styleMap2).forEach((shapeId) => {
276
+ const style = styleMap2[shapeId];
277
+ mergedStyle[shapeId] = mergedStyle[shapeId] || {};
278
+ if (!style) return;
279
+ Object.keys(style).forEach((styleName) => {
280
+ const value = style[styleName];
281
+ mergedStyle[shapeId][styleName] = value;
282
+ });
283
+ });
284
+ return mergedStyle;
285
+ };
286
+
287
+ /**
288
+ * Whether two polygons are intersected.
289
+ * @param points1 vertex array of polygon1
290
+ * @param points2 vertex array of polygon2
291
+ */
292
+ export const isPolygonsIntersect = (
293
+ points1: number[][],
294
+ points2: number[][],
295
+ ): Boolean => {
296
+ const getBBox = (points): Partial<AABB> => {
297
+ const xArr = points.map((p) => p[0]);
298
+ const yArr = points.map((p) => p[1]);
299
+ return {
300
+ min: [Math.min.apply(null, xArr), Math.min.apply(null, yArr), 0],
301
+ max: [Math.max.apply(null, xArr), Math.max.apply(null, yArr), 0],
302
+ };
303
+ };
304
+
305
+ const parseToLines = (points: number[][]) => {
306
+ const lines = [];
307
+ const count = points.length;
308
+ for (let i = 0; i < count - 1; i++) {
309
+ const point = points[i];
310
+ const next = points[i + 1];
311
+ lines.push({
312
+ from: {
313
+ x: point[0],
314
+ y: point[1],
315
+ },
316
+ to: {
317
+ x: next[0],
318
+ y: next[1],
319
+ },
320
+ });
321
+ }
322
+ if (lines.length > 1) {
323
+ const first = points[0];
324
+ const last = points[count - 1];
325
+ lines.push({
326
+ from: {
327
+ x: last[0],
328
+ y: last[1],
329
+ },
330
+ to: {
331
+ x: first[0],
332
+ y: first[1],
333
+ },
334
+ });
335
+ }
336
+ return lines;
337
+ };
338
+
339
+ // 空数组,或者一个点返回 false
340
+ if (points1.length < 2 || points2.length < 2) {
341
+ return false;
342
+ }
343
+
344
+ const bbox1 = getBBox(points1);
345
+ const bbox2 = getBBox(points2);
346
+ // 判定包围盒是否相交,比判定点是否在多边形内要快的多,可以筛选掉大多数情况
347
+ if (!intersectBBox(bbox1, bbox2)) {
348
+ return false;
349
+ }
350
+
351
+ let isIn = false;
352
+ // 判定点是否在多边形内部,一旦有一个点在另一个多边形内,则返回
353
+ points2.forEach((point) => {
354
+ if (isPointInPolygon(points1, point[0], point[1])) {
355
+ isIn = true;
356
+ return false;
357
+ }
358
+ });
359
+ if (isIn) {
360
+ return true;
361
+ }
362
+ points1.forEach((point) => {
363
+ if (isPointInPolygon(points2, point[0], point[1])) {
364
+ isIn = true;
365
+ return false;
366
+ }
367
+ });
368
+ if (isIn) {
369
+ return true;
370
+ }
371
+
372
+ const lines1 = parseToLines(points1);
373
+ const lines2 = parseToLines(points2);
374
+ let isIntersect = false;
375
+ lines2.forEach((line) => {
376
+ if (lineIntersectPolygon(lines1, line)) {
377
+ isIntersect = true;
378
+ return false;
379
+ }
380
+ });
381
+ return isIntersect;
382
+ };
383
+
384
+ export const intersectBBox = (box1: Partial<AABB>, box2: Partial<AABB>) => {
385
+ return !(
386
+ box2.min[0] > box1.max[0] ||
387
+ box2.max[0] < box1.min[0] ||
388
+ box2.min[1] > box1.max[1] ||
389
+ box2.max[1] < box1.min[1]
390
+ );
391
+ };
392
+
393
+ /**
394
+ * Whether point is inside the polygon (ray algo)
395
+ * @param points
396
+ * @param x
397
+ * @param y
398
+ */
399
+ export const isPointInPolygon = (points: number[][], x: number, y: number) => {
400
+ let isHit = false;
401
+ const n = points.length;
402
+ // 判断两个double在eps精度下的大小关系
403
+ const tolerance = 1e-6;
404
+ function dcmp(xValue) {
405
+ if (Math.abs(xValue) < tolerance) {
406
+ return 0;
407
+ }
408
+ return xValue < 0 ? -1 : 1;
409
+ }
410
+ if (n <= 2) {
411
+ // svg 中点小于 3 个时,不显示,也无法被拾取
412
+ return false;
413
+ }
414
+ for (let i = 0; i < n; i++) {
415
+ const p1 = points[i];
416
+ const p2 = points[(i + 1) % n];
417
+ if (onSegment(p1, p2, [x, y])) {
418
+ // 点在多边形一条边上
419
+ return true;
420
+ }
421
+ // 前一个判断min(p1[1],p2[1])<P.y<=max(p1[1],p2[1])
422
+ // 后一个判断被测点 在 射线与边交点 的左边
423
+ if (
424
+ dcmp(p1[1] - y) > 0 !== dcmp(p2[1] - y) > 0 &&
425
+ dcmp(x - ((y - p1[1]) * (p1[0] - p2[0])) / (p1[1] - p2[1]) - p1[0]) < 0
426
+ ) {
427
+ isHit = !isHit;
428
+ }
429
+ }
430
+ return isHit;
431
+ };
432
+
433
+ /**
434
+ * Whether q is on the segment line between p1 and p2.
435
+ * @param p1 begin of segment line
436
+ * @param p2 end of segment line
437
+ * @param q the point to be judged
438
+ * @returns
439
+ */
440
+ const onSegment = (p1, p2, q) => {
441
+ if (
442
+ (q[0] - p1[0]) * (p2[1] - p1[1]) === (p2[0] - p1[0]) * (q[1] - p1[1]) &&
443
+ Math.min(p1[0], p2[0]) <= q[0] &&
444
+ q[0] <= Math.max(p1[0], p2[0]) &&
445
+ Math.min(p1[1], p2[1]) <= q[1] &&
446
+ q[1] <= Math.max(p1[1], p2[1])
447
+ ) {
448
+ return true;
449
+ }
450
+ return false;
451
+ };
452
+
453
+ const lineIntersectPolygon = (lines, line) => {
454
+ let isIntersect = false;
455
+ lines.forEach((l) => {
456
+ if (getLineIntersect(l.from, l.to, line.from, line.to)) {
457
+ isIntersect = true;
458
+ return false;
459
+ }
460
+ });
461
+ return isIntersect;
462
+ };
463
+
464
+ /**
465
+ * Get the intersect point of two line.
466
+ * @param {Point} p0 start of the first line
467
+ * @param {Point} p1 end of the first line
468
+ * @param {Point} p2 start of the second line
469
+ * @param {Point} p3 end of the second line
470
+ * @return {Point} the intersect point
471
+ */
472
+ export const getLineIntersect = (
473
+ p0: Point,
474
+ p1: Point,
475
+ p2: Point,
476
+ p3: Point,
477
+ ): Point | null => {
478
+ const tolerance = 0.0001;
479
+
480
+ const E: Point = {
481
+ x: p2.x - p0.x,
482
+ y: p2.y - p0.y,
483
+ };
484
+ const D0: Point = {
485
+ x: p1.x - p0.x,
486
+ y: p1.y - p0.y,
487
+ };
488
+ const D1: Point = {
489
+ x: p3.x - p2.x,
490
+ y: p3.y - p2.y,
491
+ };
492
+ const kross: number = D0.x * D1.y - D0.y * D1.x;
493
+ const sqrKross: number = kross * kross;
494
+ const invertKross: number = 1 / kross;
495
+ const sqrLen0: number = D0.x * D0.x + D0.y * D0.y;
496
+ const sqrLen1: number = D1.x * D1.x + D1.y * D1.y;
497
+ if (sqrKross > tolerance * sqrLen0 * sqrLen1) {
498
+ const s = (E.x * D1.y - E.y * D1.x) * invertKross;
499
+ const t = (E.x * D0.y - E.y * D0.x) * invertKross;
500
+ if (!isBetween(s, 0, 1) || !isBetween(t, 0, 1)) return null;
501
+ return {
502
+ x: p0.x + s * D0.x,
503
+ y: p0.y + s * D0.y,
504
+ };
505
+ }
506
+ return null;
507
+ };
508
+
509
+ const FEILDS_AFFECT_BBOX = {
510
+ circle: ['r', 'lineWidth'],
511
+ rect: ['width', 'height', 'lineWidth'],
512
+ image: ['width', 'height', 'lineWidth'],
513
+ ellipse: ['rx', 'ry', 'lineWidth'],
514
+ text: ['fontSize', 'fontWeight', 'text', 'wordWrapWidth'],
515
+ polygon: ['points', 'lineWidth'],
516
+ line: ['x1', 'x2', 'y1', 'y2', 'lineWidth'],
517
+ polyline: ['points', 'lineWidth'],
518
+ path: ['points', 'lineWidth'],
519
+ sphere: ['radius'],
520
+ cube: ['width', 'height', 'depth'],
521
+ plane: ['width', 'depth'],
522
+ };
523
+ /**
524
+ * Will the fields in style affect the bbox.
525
+ * @param type shape type
526
+ * @param style style object
527
+ * @returns
528
+ */
529
+ export const isStyleAffectBBox = (
530
+ type: SHAPE_TYPE | SHAPE_TYPE_3D,
531
+ style: ShapeStyle,
532
+ ) => {
533
+ return isArrayOverlap(Object.keys(style), FEILDS_AFFECT_BBOX[type]);
534
+ };
535
+
536
+ /**
537
+ * Estimate the width of the shape according to the given style.
538
+ * @param shape target shape
539
+ * @param style computed merged style
540
+ * @param bounds shape's local bounds
541
+ * @returns
542
+ */
543
+ export const getShapeLocalBoundsByStyle = (
544
+ shape: DisplayObject,
545
+ style: ShapeStyle,
546
+ bbox?: AABB,
547
+ ): {
548
+ min: number[];
549
+ max: number[];
550
+ center: number[];
551
+ } => {
552
+ const {
553
+ r,
554
+ rx,
555
+ ry,
556
+ width,
557
+ height,
558
+ depth = 0,
559
+ x1,
560
+ x2,
561
+ y1,
562
+ y2,
563
+ z1 = 0,
564
+ z2 = 0,
565
+ } = style;
566
+ const radius = Number(r);
567
+ const radiusX = Number(rx);
568
+ const radiusY = Number(ry);
569
+ switch (shape.nodeName) {
570
+ case 'circle':
571
+ return {
572
+ min: [-radius, -radius, 0],
573
+ max: [radius, radius, 0],
574
+ center: [0, 0, 0],
575
+ };
576
+ case 'sphere':
577
+ return {
578
+ min: [-radius, -radius, -radius],
579
+ max: [radius, radius, radius],
580
+ center: [0, 0, 0],
581
+ };
582
+ case 'image':
583
+ case 'rect':
584
+ case 'cube':
585
+ case 'plane':
586
+ return {
587
+ min: [-width / 2, -height / 2, -depth / 2],
588
+ max: [width / 2, height / 2, depth / 2],
589
+ center: [0, 0, 0],
590
+ };
591
+ case 'ellipse':
592
+ return {
593
+ min: [-radiusX, -radiusY, 0],
594
+ max: [radiusX, radiusY, 0],
595
+ center: [0, 0, 0],
596
+ };
597
+ case 'line':
598
+ return {
599
+ min: [x1, y1, z1],
600
+ max: [x2, y2, z2],
601
+ center: [(x1 + x2) / 2, (y1 + y2) / 2, (z1 + z2) / 2],
602
+ };
603
+ case 'text':
604
+ case 'polyline':
605
+ case 'path':
606
+ case 'polygon':
607
+ return bbox || shape.getLocalBounds();
608
+ }
609
+ };