@antv/g6 4.8.14 → 5.0.0-alpha.2

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,733 @@
1
+ import { Category } from '@antv/gui';
2
+ import { Canvas, DisplayObject, Circle, Line } from '@antv/g';
3
+ import { isFunction, upperFirst } from '@antv/util';
4
+ import { createDom } from '@antv/dom-util';
5
+ import { ID } from '@antv/graphlib';
6
+ import { IGraph } from '../../../types';
7
+ import { Plugin as Base, IPluginBaseConfig } from '../../../types/plugin';
8
+ import { createCanvas } from '../../../util/canvas';
9
+ import { formatPadding, ShapeTagMap } from '../../../util/shape';
10
+
11
+ type ItemLegendConfig = {
12
+ // whether show the item legend
13
+ enable: boolean;
14
+ // the field name of the item type
15
+ typeField?: string;
16
+ // title of the item legend
17
+ title?: string;
18
+ // number of rows
19
+ rows?: number;
20
+ // number of cols
21
+ cols?: number;
22
+ // padding between cols
23
+ colPadding?: number;
24
+ // padding between rows
25
+ rowPadding?: number;
26
+ // padding of the item legend
27
+ padding?: number | number[];
28
+ // formatter for the label
29
+ labelFormatter?: (type: string) => string;
30
+ // style for the label
31
+ labelStyle?: {
32
+ [shapeAttr: string]: unknown;
33
+ };
34
+ // style config or mapper for the marker, could be value/map/function
35
+ markerStyle?: {
36
+ shape?: string | { [nodeType: string]: string };
37
+ size?: number | number[] | { [nodeType: string]: number | number[] };
38
+ color?: string | { [nodeType: string]: string };
39
+ [styleName: string]: unknown | { [nodeType: string]: unknown };
40
+ };
41
+ };
42
+
43
+ interface LegendConfig extends IPluginBaseConfig {
44
+ // container for the legend, using graph's container by default
45
+ container?: HTMLDivElement | null;
46
+ // className for the DOM wrapper, "g6-category-legend" by default
47
+ className?: string;
48
+ // size for the legend canvas, 'fit-content', or an array of number(px) and string(percentage with %)
49
+ size?: 'fit-content' | [number | string, number | string];
50
+ // orientation for the legend layout
51
+ orientation?: 'horizontal' | 'vertical';
52
+ // Selected state name, triggered while clicking a legend item. Click will not take effect if selectedState is not assigned
53
+ selectedState?: string;
54
+ // Active state name, triggered while mouseenter a legend item. Mouseenter will not take effect if activeState is not assigned
55
+ activeState?: string;
56
+ // Inactive state name, triggered on other items while mouseenter a legend item. Mouseleave will not take effect if inactiveState is not assigned
57
+ inactiveState?: string;
58
+ // config for the node legend
59
+ node?: ItemLegendConfig;
60
+ // config for the edge legend
61
+ edge?: ItemLegendConfig;
62
+ }
63
+
64
+ export default class Legend extends Base {
65
+ private nodeLegend: Category;
66
+ private edgeLegend: Category;
67
+ private wrapper: HTMLDivElement;
68
+ private canvas: Canvas;
69
+ private size: ('fit-content' | number)[];
70
+ private selectedTypes: {
71
+ node: Set<string>;
72
+ edge: Set<string>;
73
+ };
74
+ private activeType: {
75
+ node: string | undefined;
76
+ edge: string | undefined;
77
+ };
78
+ private selectedIds: {
79
+ node: Set<ID>;
80
+ edge: Set<ID>;
81
+ };
82
+ private activeIds: {
83
+ node: Set<ID>;
84
+ edge: Set<ID>;
85
+ };
86
+ private styleCache: {
87
+ node: {
88
+ [type: string]: any;
89
+ };
90
+ edge: {
91
+ [type: string]: any;
92
+ };
93
+ };
94
+
95
+ constructor(options?: LegendConfig) {
96
+ super(options);
97
+ }
98
+
99
+ public getDefaultCfgs(): LegendConfig {
100
+ return {
101
+ container: null,
102
+ className: 'g6-category-legend',
103
+ orientation: 'horizontal',
104
+ selectedState: 'selected',
105
+ activeState: 'active',
106
+ };
107
+ }
108
+
109
+ public getEvents() {
110
+ return {
111
+ afterrender: this.updateLegend,
112
+ };
113
+ }
114
+
115
+ public init(graph: IGraph) {
116
+ super.init(graph);
117
+ const { size = 'fit-content', orientation } = this.options;
118
+ const graphSize = graph.getSize();
119
+ this.size = size;
120
+ this.selectedTypes = {
121
+ node: new Set<string>(),
122
+ edge: new Set<string>(),
123
+ };
124
+ this.activeType = {
125
+ node: undefined,
126
+ edge: undefined,
127
+ };
128
+ this.selectedIds = {
129
+ node: new Set<string>(),
130
+ edge: new Set<string>(),
131
+ };
132
+ this.activeIds = {
133
+ node: new Set<string>(),
134
+ edge: new Set<string>(),
135
+ };
136
+ this.styleCache = {
137
+ node: {},
138
+ edge: {},
139
+ };
140
+ // If size is set to "fit-content", sets the size of the legend canvas to fit the content.
141
+ if (size === 'fit-content') {
142
+ this.size = [
143
+ orientation === 'horizontal' ? graphSize[0] : 'fit-content',
144
+ orientation === 'horizontal' ? 'fit-content' : graphSize[1],
145
+ ];
146
+ }
147
+ // If size is set to "100%", sets the size of the legend canvas to match the size of the graph.
148
+ if (size[0].includes('%')) {
149
+ const ratio = Number(size[0].replace('%')) / 100 || 1;
150
+ this.size[0] = graphSize[0] * ratio;
151
+ } else if (typeof size[0] === 'number') {
152
+ // Otherwise, sets the size of the legend canvas to the specified size.
153
+ this.size[0] = size[0];
154
+ }
155
+ // If size is set to "100%", sets the size of the legend canvas to match the size of the graph.
156
+ if (size[1] === '100%') {
157
+ const ratio = Number(size[0].replace('%')) / 100 || 1;
158
+ this.size[1] = graphSize[1] * ratio;
159
+ } else if (typeof size[1] === 'number') {
160
+ // Otherwise, sets the size of the legend canvas to the specified size.
161
+ this.size[1] = size[1];
162
+ }
163
+ }
164
+
165
+ /**
166
+ * Update or create the legend including node and edge legend.
167
+ */
168
+ private updateLegend() {
169
+ const { size } = this;
170
+
171
+ // If wrapper does not exist, create it
172
+ if (!this.wrapper) {
173
+ this.wrapper = this.createWrapper();
174
+ }
175
+ // If canvas does not exist, create it
176
+ if (!this.canvas) {
177
+ const canvasSize = [
178
+ size[0] === 'fit-content' ? 0 : size[0],
179
+ size[1] === 'fit-content' ? 0 : size[1],
180
+ ];
181
+ this.canvas = createCanvas(
182
+ 'canvas',
183
+ this.wrapper,
184
+ canvasSize[0],
185
+ canvasSize[1],
186
+ );
187
+ // Set canvas background color
188
+ // TODO: update type define.
189
+ // @ts-ignore
190
+ this.canvas.context.config.canvas.style.backgroundColor =
191
+ 'rgba(255, 255, 255, 0.8)';
192
+
193
+ // Add click event listener to canvas
194
+ this.canvas.addEventListener('click', (evt) => {
195
+ // If the click target is not canvas, return
196
+ if (evt.target?.nodeName !== 'document') return;
197
+
198
+ // Clear relevant states on the graph
199
+ const { graph, options } = this;
200
+ const { activeState, selectedState } = options;
201
+ if (this.activeIds.node.size)
202
+ graph.clearItemState(Array.from(this.activeIds.node), activeState);
203
+ if (this.activeIds.edge.size)
204
+ graph.clearItemState(Array.from(this.activeIds.edge), activeState);
205
+ this.activeIds = {
206
+ node: new Set<ID>(),
207
+ edge: new Set<ID>(),
208
+ };
209
+ if (selectedState) {
210
+ const { node: selectedNodes, edge: selectedEdges } = this.selectedIds;
211
+ graph.clearItemState(Array.from(selectedNodes), selectedState);
212
+ graph.clearItemState(Array.from(selectedEdges), selectedState);
213
+ this.selectedIds = {
214
+ node: new Set<ID>(),
215
+ edge: new Set<ID>(),
216
+ };
217
+ }
218
+
219
+ // Clear legend states
220
+ this.selectedTypes.node.forEach((nodeType) => {
221
+ const marker = this.canvas
222
+ .getRoot()
223
+ .querySelector(`#marker-node-${nodeType}`);
224
+ if (!marker) return;
225
+ const lineWidth = this.styleCache.node[nodeType].lineWidth;
226
+ marker.style.lineWidth = lineWidth;
227
+ });
228
+ this.selectedTypes.edge.forEach((edgeType) => {
229
+ const marker = this.canvas
230
+ .getRoot()
231
+ .querySelector(`#marker-edge-${edgeType}`);
232
+ if (!marker) return;
233
+ const lineWidth = this.styleCache.edge[edgeType].lineWidth;
234
+ marker.style.lineWidth = lineWidth;
235
+ });
236
+ this.selectedTypes = {
237
+ node: new Set<string>(),
238
+ edge: new Set<string>(),
239
+ };
240
+ this.activeType = {
241
+ node: undefined,
242
+ edge: undefined,
243
+ };
244
+ });
245
+ }
246
+
247
+ const promise = this.canvas.ready;
248
+ promise.then(() => {
249
+ this.nodeLegend = this.upsertLegend('node');
250
+ this.edgeLegend = this.upsertLegend('edge');
251
+ this.updateLayout();
252
+ });
253
+ }
254
+
255
+ /**
256
+ * Creates a wrapper div element for the graph and appends it to the container.
257
+ * @returns {HTMLDivElement} - The created wrapper div element.
258
+ */
259
+ private createWrapper() {
260
+ const { options, graph, size } = this;
261
+ const { container: propContainer, className } = options;
262
+ let container: any = propContainer;
263
+ // If the container is a string, it will find the corresponding element in the document.
264
+ if (typeof propContainer === 'string') {
265
+ container = document.getElementById(propContainer);
266
+ }
267
+ // If the container is not found, it will use the graph's container.
268
+ if (!container) {
269
+ container = graph.container;
270
+ }
271
+
272
+ const wrapperSize = [
273
+ size[0] === 'fit-content' ? 0 : size[0],
274
+ size[1] === 'fit-content' ? 0 : size[1],
275
+ ];
276
+ const wrapper = (HTMLDivElement = createDom(
277
+ `<div class='${className}' style='width: ${wrapperSize[0]}px; height: ${wrapperSize[1]}px; overflow: hidden;'></div>`,
278
+ ));
279
+ container.appendChild(wrapper);
280
+ return wrapper;
281
+ }
282
+
283
+ /**
284
+ * Creates a legend for the graph based on the given item type (node or edge).
285
+ * @param {string} itemType - The type of item for which the legend is being created (node or edge).
286
+ * @returns {Category} - The created legend.
287
+ */
288
+ private upsertLegend(itemType: 'node' | 'edge' = 'node') {
289
+ const { graph, options, canvas } = this;
290
+ const { node, edge, orientation } = options;
291
+
292
+ // Checks if the legend is enabled for the given item type. If not, it returns.
293
+ const itemLegendConfig = itemType === 'node' ? node : edge;
294
+ if (!itemLegendConfig?.enable) return;
295
+
296
+ // Extracts the necessary configuration options from the options object.
297
+ const {
298
+ title,
299
+ typeField,
300
+ labelFormatter,
301
+ rows = 1,
302
+ cols = 4,
303
+ colPadding = 5,
304
+ rowPadding = 8,
305
+ padding: propsPadding = [0, 0, 0, 0],
306
+ labelStyle = {},
307
+ markerStyle: propsMarkerStyle,
308
+ } = itemLegendConfig;
309
+ const defaultStyle = {
310
+ shape: itemType === 'node' ? 'circle' : 'line',
311
+ size: 10,
312
+ color: '#ccc',
313
+ fillOpacity: 0.3,
314
+ };
315
+
316
+ // Calculates the necessary padding, spacing, and size for the legend.
317
+ const padding = formatPadding(propsPadding);
318
+ const labelRelatedStyle: any = {};
319
+ Object.keys(labelStyle).forEach((key) => {
320
+ labelRelatedStyle[`itemLabel${upperFirst(key)}`] = labelStyle[key];
321
+ });
322
+ const itemSpacing = labelRelatedStyle.itemLabelSpacing;
323
+ const { size: legendSize, grid } = this.getLegendSize(rows, cols, padding);
324
+
325
+ // Gets all the data for the given item type and extracts the unique types based on the typeField.
326
+ const datas =
327
+ itemType === 'node' ? graph.getAllNodesData() : graph.getAllEdgesData();
328
+ const typeSet = new Set<string>();
329
+ const typeModelMap = {};
330
+ datas.map((model) => {
331
+ if (model.data[typeField]) {
332
+ const type = model.data[typeField];
333
+ typeSet.add(type);
334
+ if (!typeModelMap[type]) typeModelMap[type] = model;
335
+ }
336
+ });
337
+ const types = Array.from(typeSet);
338
+
339
+ // Creates the legend data based on the unique types and labelFormatter function.
340
+ const legendData = types.map((type) => ({
341
+ typeValue: type,
342
+ label: labelFormatter ? labelFormatter(type) : type,
343
+ }));
344
+
345
+ const markerStyleKeys = [
346
+ 'fill',
347
+ 'stroke',
348
+ 'fillOpacity',
349
+ 'opacity',
350
+ 'lineWidth',
351
+ 'shadow',
352
+ 'shadowBlur',
353
+ 'size',
354
+ ];
355
+
356
+ // Creates the marker style for the legend based on the propsMarkerStyle or the style of the corresponding element on the graph.
357
+ const markerRelatedStyle: any = {};
358
+ let getShape;
359
+ if (!propsMarkerStyle) {
360
+ // 使用图上对应元素的样式
361
+ const graphGroup = graph.canvas.getRoot();
362
+ const itemTypeGroup =
363
+ graphGroup.getElementById(`${itemType}-group`) || graphGroup;
364
+ const typeStyleMap = {};
365
+ const formatStyles = {
366
+ x1: -10,
367
+ y1: 0,
368
+ x2: 10,
369
+ y2: 0,
370
+ };
371
+ types.forEach((type) => {
372
+ const itemGroup = itemTypeGroup.find(
373
+ (ele) => ele.getAttribute('data-item-id') === typeModelMap[type].id,
374
+ );
375
+ const keyShape = itemGroup.querySelector('#keyShape');
376
+ typeStyleMap[type] = {
377
+ shape: keyShape.nodeName,
378
+ style: {
379
+ ...keyShape.attributes,
380
+ ...formatStyles,
381
+ },
382
+ };
383
+ });
384
+
385
+ markerStyleKeys.forEach((key) => {
386
+ markerRelatedStyle[`itemMarker${upperFirstLetter(key)}`] = (item) => {
387
+ const { typeValue } = item;
388
+ let markerStyleKey = key;
389
+ if (key === 'size') {
390
+ if (typeStyleMap[typeValue].style.r) markerStyleKey = 'r';
391
+ markerStyleKey = 'width';
392
+ }
393
+ return (
394
+ typeStyleMap[typeValue].style[markerStyleKey] || defaultStyle[key]
395
+ );
396
+ };
397
+ });
398
+ getShape = (item) => {
399
+ const { typeValue } = item;
400
+ const shape = typeStyleMap[typeValue].shape || defaultStyle.shape;
401
+ return {
402
+ Shape: ShapeTagMap[shape],
403
+ style: typeStyleMap[typeValue].style,
404
+ };
405
+ };
406
+ } else {
407
+ // 使用 markerStyle 中的样式映射
408
+ const { shape: markerShape, ...markerStyle } = Object.assign(
409
+ {},
410
+ defaultStyle,
411
+ propsMarkerStyle || {},
412
+ );
413
+ getShape = this.getShapeConfig(itemType, markerShape);
414
+ Object.keys(markerStyle).forEach((key) => {
415
+ const styleValue = markerStyle[key];
416
+ let value = styleValue;
417
+ if (typeof styleValue === 'object') {
418
+ value = (item) => {
419
+ return (
420
+ styleValue[item.typeValue] ||
421
+ styleValue[item.typeValue].size ||
422
+ 10
423
+ );
424
+ };
425
+ } else if (isFunction(styleValue)) {
426
+ value = (item) => styleValue(item.typeValue);
427
+ }
428
+ if (key === 'color') {
429
+ markerRelatedStyle['itemMarkerFill'] =
430
+ markerRelatedStyle['itemMarkerFill'] || value;
431
+ markerRelatedStyle['itemMarkerStroke'] =
432
+ markerRelatedStyle['itemMarkerStroke'] || value;
433
+ } else {
434
+ markerRelatedStyle[`itemMarker${upperFirstLetter(key)}`] = value;
435
+ }
436
+ });
437
+ }
438
+
439
+ // Creates the legend using the Category component and appends it to the canvas.
440
+ const legend = new Category({
441
+ style: {
442
+ x: padding[3],
443
+ y: padding[0],
444
+ data: legendData,
445
+ layout: 'flex',
446
+ orientation,
447
+ gridRow: grid[0],
448
+ gridCol: grid[1],
449
+ colPadding,
450
+ rowPadding,
451
+ width: legendSize[0],
452
+ height: legendSize[1],
453
+ titleText: title,
454
+ itemSpacing,
455
+ ...labelRelatedStyle,
456
+ ...markerRelatedStyle,
457
+ // itemMarkerFillOpacity: 0.5,
458
+ itemMarker: (item) => {
459
+ const { Shape, style } = getShape(item as any);
460
+ const { typeValue } = item;
461
+ this.styleCache[itemType][typeValue] = style;
462
+ return () =>
463
+ new Shape({ style, id: `marker-${itemType}-${typeValue}` });
464
+ },
465
+ mouseenter: (ele) =>
466
+ this.handleMouseEnter(ele, types, typeField, itemType, datas),
467
+ mouseleave: (ele) =>
468
+ this.handleMouseLeave(ele, types, typeField, itemType),
469
+ click: (ele) =>
470
+ this.handleClick(ele, types, typeField, itemType, datas),
471
+ },
472
+ });
473
+
474
+ // TODO: update type define.
475
+ // @ts-ignore
476
+ canvas.appendChild(legend);
477
+ return legend;
478
+ }
479
+
480
+ /**
481
+ * Updates the layout by positioning the node and edge legends.
482
+ */
483
+ private updateLayout() {
484
+ const { nodeLegend, edgeLegend, options, size } = this;
485
+ // If both node and edge legends exist, it determines the order of the legends based on their respective orders in the options object.
486
+ if (nodeLegend && edgeLegend) {
487
+ const { node, edge, orientation } = options;
488
+ const { order: nodeOrder = 1, padding: nodePadding } = node;
489
+ const { order: edgeOrder = 2, padding: edgePadding } = edge;
490
+ let firstItem;
491
+ let secondItem;
492
+ if (nodeOrder < edgeOrder) {
493
+ firstItem = {
494
+ padding: formatPadding(nodePadding),
495
+ legend: nodeLegend,
496
+ };
497
+ secondItem = {
498
+ padding: formatPadding(edgePadding),
499
+ legend: edgeLegend,
500
+ };
501
+ } else {
502
+ secondItem = {
503
+ padding: formatPadding(nodePadding),
504
+ legend: nodeLegend,
505
+ };
506
+ firstItem = {
507
+ padding: formatPadding(edgePadding),
508
+ legend: edgeLegend,
509
+ };
510
+ }
511
+ const bbox = firstItem.legend.getRenderBounds();
512
+
513
+ // Positions the legends based on their orientation and padding values.
514
+ if (orientation === 'horizontal') {
515
+ firstItem.legend.translateLocal([
516
+ 0,
517
+ -bbox.min[1] + firstItem.padding[0],
518
+ ]);
519
+
520
+ const firstItemBounds =
521
+ firstItem.legend.childNodes[1].childNodes[0].childNodes[0].getRenderBounds();
522
+ const firstBottom = firstItemBounds.max[1] + firstItem.padding[2];
523
+
524
+ secondItem.legend.translateLocal([0, firstBottom]);
525
+ } else {
526
+ firstItem.legend.translateLocal([
527
+ -bbox.min[0] + firstItem.padding[3],
528
+ 0,
529
+ ]);
530
+ const firstRight =
531
+ firstItem.legend.childNodes[1].childNodes[0].childNodes[0].childNodes[1].getRenderBounds()
532
+ .max[0] + firstItem.padding[1];
533
+ secondItem.legend.translateLocal([firstRight, 0]);
534
+ }
535
+ }
536
+
537
+ // If the size of the canvas is set to "fit-content", it resizes the canvas to fit the total bounding box of the legend.
538
+ if (size[0] === 'fit-content' || size[1] === 'fit-content') {
539
+ const totalBBox = this.canvas.getRoot().getRenderBounds();
540
+ const canvasSize = [
541
+ size[0] === 'fit-content'
542
+ ? totalBBox.max[0] - totalBBox.min[0]
543
+ : size[0],
544
+ size[1] === 'fit-content'
545
+ ? totalBBox.max[1] - totalBBox.min[1]
546
+ : size[1],
547
+ ];
548
+ this.canvas.resize(canvasSize[0], canvasSize[1]);
549
+ this.wrapper.style.width = `${canvasSize[1]}px`;
550
+ this.wrapper.style.height = `${canvasSize[0]}px`;
551
+ }
552
+ }
553
+
554
+ /**
555
+ * generate a function that takes an legend's item object and returns an object with Shape and style properties for the item marker rendering.
556
+ * @param itemType specifies whether the item is a node or an edge.
557
+ * @param markerShape
558
+ * @returns
559
+ */
560
+ private getShapeConfig(
561
+ itemType: 'node' | 'edge',
562
+ markerShape,
563
+ ): (item: { typeValue: string }) => { Shape: DisplayObject; style: any } {
564
+ const DefaultShape: typeof Circle | typeof Line =
565
+ itemType === 'node' ? Circle : Line;
566
+ const defaultStyle =
567
+ itemType === 'node'
568
+ ? { r: 10, width: 20, height: 20, lineWidth: 1 }
569
+ : { lineWidth: 4, x1: -10, y1: 0, x2: 10, y2: 0 };
570
+
571
+ if (typeof markerShape === 'string') {
572
+ // If markerShape is a string, it is used as a key to look up a shape in the ShapeTagMap object. If the key is not found, the DefaultShape is used.
573
+ const Shape = ShapeTagMap[markerShape] || DefaultShape;
574
+ return () => ({
575
+ Shape: Shape,
576
+ style: defaultStyle,
577
+ });
578
+ } else {
579
+ // If markerShape is an object, it is used to look up a shape configuration based on the item's typeValue property.
580
+ return (item) => {
581
+ const shapeConfig = markerShape[item.typeValue];
582
+ if (typeof shapeConfig === 'string') {
583
+ // If the configuration is a string, it is used as a key to look up a shape in the ShapeTagMap object. If the key is not found, the DefaultShape is used.
584
+ const Shape = ShapeTagMap[shapeConfig];
585
+ return {
586
+ Shape,
587
+ style: defaultStyle,
588
+ };
589
+ } else {
590
+ // If the configuration is an object, it is used to determine the shape type and style. The shape type is looked up in the ShapeTagMap object. If the key is not found, the DefaultShape is used. The style is a combination of the defaultStyle and the style property of the configuration object.
591
+ const { type: shapeType, style } = shapeConfig;
592
+ const Shape = ShapeTagMap[shapeType] || DefaultShape;
593
+ return {
594
+ Shape,
595
+ style: { ...defaultStyle, ...style },
596
+ };
597
+ }
598
+ };
599
+ }
600
+ }
601
+
602
+ /**
603
+ * Calculates the size of the legend based on the number of rows and columns, padding, and the orientation of the legend.
604
+ * @param rows
605
+ * @param cols
606
+ * @param padding
607
+ * @returns
608
+ */
609
+ private getLegendSize(rows, cols, padding) {
610
+ const { graph, options, size } = this;
611
+ const { orientation } = options;
612
+ let [width, height] = size;
613
+ let grid = [rows, cols];
614
+ const [graphWidth, graphHeight] = graph.getSize();
615
+
616
+ if (orientation === 'horizontal') {
617
+ // If the orientation is horizontal, it checks if the first value in the size array is "fit-content" and sets the width to the graphWidth if it is.
618
+ if (size[0] === 'fit-content') width = graphWidth;
619
+ if (size[1] === 'fit-content') height = 50;
620
+ } else {
621
+ // If the orientation is not horizontal, it checks if the first value in the size array is "fit-content" and sets the width to 50 if it is.
622
+ if (size[0] === 'fit-content') width = 50;
623
+ if (size[1] === 'fit-content') height = graphHeight;
624
+ // Swaps the values of rows and cols in the grid array.
625
+ grid = [cols, rows];
626
+ }
627
+ // Adds the padding to the width and height.
628
+ width += padding[1] + padding[3];
629
+ height += padding[0] + padding[2];
630
+ return {
631
+ size: [width, height],
632
+ grid,
633
+ };
634
+ }
635
+
636
+ /**
637
+ * Handles the mouse enter event for a given element.
638
+ * @param {Object} ele - The element (legend item marker) that triggered the event.
639
+ * @param {Array} types - An array of all the types on the legend.
640
+ * @param {string} typeField - The field that contains the type information.
641
+ * @param {string} itemType - The type of item, node or edge.
642
+ * @param {Array} datas - An array of data models.
643
+ */
644
+ private handleMouseEnter(ele, types, typeField, itemType, datas) {
645
+ const { graph, options } = this;
646
+ const { activeState } = options;
647
+ if (!activeState) return;
648
+ const { index } = ele.__data__;
649
+ const type = types[index];
650
+ this.activeType[typeField] = type;
651
+ const activeIds = datas
652
+ .filter((model) => model.data[typeField] === type)
653
+ .map((model) => model.id);
654
+ graph.setItemState(activeIds, activeState, true);
655
+ activeIds.forEach((id) => this.activeIds[itemType].add(id));
656
+
657
+ // Update legend style.
658
+ ele.querySelector('.legend-category-item-marker').style.lineWidth =
659
+ this.styleCache[itemType][type].lineWidth + 2 || 4;
660
+ }
661
+
662
+ /**
663
+ * Handles mouse leave event for a given element.
664
+ * @param {HTMLElement} ele - The element (legend item marker) that triggered the event.
665
+ * @param {Array} types - An array of all the types on the legend.
666
+ * @param {string} typeField - The field that contains the type information.
667
+ * @param {string} itemType - The type of the item, node or edge.
668
+ */
669
+ private handleMouseLeave(ele, types, typeField, itemType) {
670
+ const { graph, options } = this;
671
+ const { activeState } = options;
672
+ if (!activeState) return;
673
+ this.activeType[typeField] = undefined;
674
+ const currentActiveIds = graph.findIdByState(itemType, activeState, true);
675
+ const { index } = ele.__data__;
676
+ const type = types[index];
677
+ if (this.selectedTypes[itemType].has(type)) {
678
+ ele.querySelector('.legend-category-item-marker').style.lineWidth =
679
+ this.styleCache[itemType][type].lineWidth + 4 || 6;
680
+ } else {
681
+ ele.querySelector('.legend-category-item-marker').style.lineWidth =
682
+ this.styleCache[itemType][type].lineWidth || 1;
683
+ }
684
+ graph.setItemState(currentActiveIds, activeState, false);
685
+ currentActiveIds.forEach((id) => this.activeIds[itemType].delete(id));
686
+ }
687
+
688
+ /**
689
+ * Handles the click event on a legend category item.
690
+ * @param {HTMLElement} ele - The legend category item element that was clicked.
691
+ * @param {Array} types - An array of all the types on the legend.
692
+ * @param {string} typeField - The field in the data model that contains the type of the data.
693
+ * @param {string} itemType - The type of the item, node or edge.
694
+ * @param {Array} datas - An array of data models.
695
+ */
696
+ private handleClick(ele, types, typeField, itemType, datas) {
697
+ const { graph, options } = this;
698
+ const { selectedState } = options;
699
+ if (!selectedState) return;
700
+ const { index } = ele.__data__;
701
+ const type = types[index];
702
+ const ids = datas
703
+ .filter((model) => model.data[typeField] === type)
704
+ .map((model) => model.id);
705
+ if (this.selectedTypes[itemType].has(type)) {
706
+ this.selectedTypes[itemType].delete(type);
707
+ ids.forEach((id) => this.selectedIds[itemType].delete(id));
708
+ graph.setItemState(ids, selectedState, false);
709
+ ele.querySelector('.legend-category-item-marker').style.lineWidth = 4;
710
+ } else {
711
+ this.selectedTypes[itemType].add(type);
712
+ ids.forEach((id) => this.selectedIds[itemType].add(id));
713
+ graph.setItemState(ids, selectedState, true);
714
+ ele.querySelector('.legend-category-item-marker').style.lineWidth =
715
+ this.styleCache[itemType][type].lineWidth + 4 || 6;
716
+ }
717
+ }
718
+
719
+ public destroy() {
720
+ super.destroy();
721
+ this.canvas.destroy();
722
+ }
723
+ }
724
+
725
+ /**
726
+ * Takes a string as input and returns the same string with the first letter capitalized.
727
+ * @param str
728
+ * @returns
729
+ */
730
+ const upperFirstLetter = (str: string) => {
731
+ if (!str) return '';
732
+ return `${str.substring(0, 1).toUpperCase()}${str.substring(1)}`;
733
+ };