@antv/g2 5.0.0-beta.7 → 5.0.0-beta.9

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 (473) hide show
  1. package/dist/g2-lite.min.js +3 -3
  2. package/dist/g2.min.js +4 -4
  3. package/esm/animation/morphing.js +22 -2
  4. package/esm/animation/morphing.js.map +1 -1
  5. package/esm/api/chart.d.ts +8 -3
  6. package/esm/api/chart.js +35 -16
  7. package/esm/api/chart.js.map +1 -1
  8. package/esm/api/composition/base.d.ts +18 -1
  9. package/esm/api/composition/base.js +44 -1
  10. package/esm/api/composition/base.js.map +1 -1
  11. package/esm/api/mark/base.d.ts +22 -0
  12. package/esm/api/mark/base.js +54 -0
  13. package/esm/api/mark/base.js.map +1 -0
  14. package/esm/api/mark/mark.d.ts +1 -7
  15. package/esm/api/mark/mark.js +1 -13
  16. package/esm/api/mark/mark.js.map +1 -1
  17. package/esm/api/props.js +0 -20
  18. package/esm/api/props.js.map +1 -1
  19. package/esm/component/axis.d.ts +5 -7
  20. package/esm/component/axis.js +126 -94
  21. package/esm/component/axis.js.map +1 -1
  22. package/esm/component/axisArc.d.ts +7 -0
  23. package/esm/component/axisArc.js +9 -0
  24. package/esm/component/axisArc.js.map +1 -0
  25. package/esm/component/axisRadar.d.ts +9 -0
  26. package/esm/component/axisRadar.js +46 -0
  27. package/esm/component/axisRadar.js.map +1 -0
  28. package/esm/component/axisX.d.ts +2 -1
  29. package/esm/component/axisX.js +5 -4
  30. package/esm/component/axisX.js.map +1 -1
  31. package/esm/component/axisY.d.ts +1 -1
  32. package/esm/component/axisY.js +4 -4
  33. package/esm/component/axisY.js.map +1 -1
  34. package/esm/component/index.d.ts +8 -0
  35. package/esm/component/index.js +5 -0
  36. package/esm/component/index.js.map +1 -1
  37. package/esm/component/legendCategory.d.ts +5 -3
  38. package/esm/component/legendCategory.js +80 -36
  39. package/esm/component/legendCategory.js.map +1 -1
  40. package/esm/component/legendContinuous.d.ts +4 -2
  41. package/esm/component/legendContinuous.js +76 -24
  42. package/esm/component/legendContinuous.js.map +1 -1
  43. package/esm/component/legendContinuousBlock.d.ts +4 -0
  44. package/esm/component/legendContinuousBlock.js +6 -0
  45. package/esm/component/legendContinuousBlock.js.map +1 -0
  46. package/esm/component/legendContinuousBlockSize.d.ts +4 -0
  47. package/esm/component/legendContinuousBlockSize.js +6 -0
  48. package/esm/component/legendContinuousBlockSize.js.map +1 -0
  49. package/esm/component/legendContinuousSize.d.ts +4 -0
  50. package/esm/component/legendContinuousSize.js +10 -0
  51. package/esm/component/legendContinuousSize.js.map +1 -0
  52. package/esm/component/scrollbar.js +1 -1
  53. package/esm/component/scrollbar.js.map +1 -1
  54. package/esm/component/slider.js +1 -1
  55. package/esm/component/slider.js.map +1 -1
  56. package/esm/component/title.js +1 -1
  57. package/esm/component/title.js.map +1 -1
  58. package/esm/component/utils.d.ts +12 -0
  59. package/esm/component/utils.js +35 -0
  60. package/esm/component/utils.js.map +1 -1
  61. package/esm/composition/facetCircle.js +1 -1
  62. package/esm/composition/facetCircle.js.map +1 -1
  63. package/esm/coordinate/index.d.ts +3 -3
  64. package/esm/coordinate/index.js +3 -3
  65. package/esm/coordinate/index.js.map +1 -1
  66. package/esm/coordinate/polar.d.ts +6 -0
  67. package/esm/coordinate/polar.js +18 -6
  68. package/esm/coordinate/polar.js.map +1 -1
  69. package/esm/coordinate/radial.d.ts +6 -0
  70. package/esm/coordinate/radial.js +17 -5
  71. package/esm/coordinate/radial.js.map +1 -1
  72. package/esm/coordinate/theta.d.ts +7 -0
  73. package/esm/coordinate/theta.js +16 -4
  74. package/esm/coordinate/theta.js.map +1 -1
  75. package/esm/interaction/builtin/elementHighlight.d.ts +2 -0
  76. package/esm/interaction/builtin/elementHighlightByColor.d.ts +2 -0
  77. package/esm/interaction/builtin/elementHighlightByX.d.ts +2 -0
  78. package/esm/interaction/index.d.ts +2 -0
  79. package/esm/interaction/index.js +2 -0
  80. package/esm/interaction/index.js.map +1 -1
  81. package/esm/interaction/native/brushAxisHighlight.js +6 -1
  82. package/esm/interaction/native/brushAxisHighlight.js.map +1 -1
  83. package/esm/interaction/native/brushFilter.js +1 -1
  84. package/esm/interaction/native/brushFilter.js.map +1 -1
  85. package/esm/interaction/native/elementHighlight.d.ts +7 -2
  86. package/esm/interaction/native/elementHighlight.js +72 -19
  87. package/esm/interaction/native/elementHighlight.js.map +1 -1
  88. package/esm/interaction/native/elementHighlightByColor.d.ts +4 -1
  89. package/esm/interaction/native/elementHighlightByColor.js +19 -3
  90. package/esm/interaction/native/elementHighlightByColor.js.map +1 -1
  91. package/esm/interaction/native/elementHighlightByX.d.ts +3 -3
  92. package/esm/interaction/native/elementHighlightByX.js +19 -3
  93. package/esm/interaction/native/elementHighlightByX.js.map +1 -1
  94. package/esm/interaction/native/elementSelect.d.ts +1 -1
  95. package/esm/interaction/native/elementSelect.js +42 -21
  96. package/esm/interaction/native/elementSelect.js.map +1 -1
  97. package/esm/interaction/native/elementSelectByColor.js +3 -2
  98. package/esm/interaction/native/elementSelectByColor.js.map +1 -1
  99. package/esm/interaction/native/elementSelectByX.js +3 -2
  100. package/esm/interaction/native/elementSelectByX.js.map +1 -1
  101. package/esm/interaction/native/legendFilter.d.ts +6 -0
  102. package/esm/interaction/native/legendFilter.js +26 -7
  103. package/esm/interaction/native/legendFilter.js.map +1 -1
  104. package/esm/interaction/native/legendHighlight.d.ts +4 -0
  105. package/esm/interaction/native/legendHighlight.js +93 -0
  106. package/esm/interaction/native/legendHighlight.js.map +1 -0
  107. package/esm/interaction/native/poptip.d.ts +5 -0
  108. package/esm/interaction/native/poptip.js +91 -0
  109. package/esm/interaction/native/poptip.js.map +1 -0
  110. package/esm/interaction/native/utils.d.ts +13 -2
  111. package/esm/interaction/native/utils.js +151 -26
  112. package/esm/interaction/native/utils.js.map +1 -1
  113. package/esm/label-transform/overlapDodgeY.js +0 -8
  114. package/esm/label-transform/overlapDodgeY.js.map +1 -1
  115. package/esm/mark/area.js +1 -1
  116. package/esm/mark/area.js.map +1 -1
  117. package/esm/mark/pack.js +0 -1
  118. package/esm/mark/pack.js.map +1 -1
  119. package/esm/mark/treemap.js +0 -1
  120. package/esm/mark/treemap.js.map +1 -1
  121. package/esm/runtime/component.d.ts +3 -0
  122. package/esm/runtime/component.js +246 -103
  123. package/esm/runtime/component.js.map +1 -1
  124. package/esm/runtime/coordinate.d.ts +11 -0
  125. package/esm/runtime/coordinate.js +23 -16
  126. package/esm/runtime/coordinate.js.map +1 -1
  127. package/esm/runtime/layout.d.ts +1 -1
  128. package/esm/runtime/layout.js +145 -76
  129. package/esm/runtime/layout.js.map +1 -1
  130. package/esm/runtime/plot.js +5 -4
  131. package/esm/runtime/plot.js.map +1 -1
  132. package/esm/runtime/render.js +18 -13
  133. package/esm/runtime/render.js.map +1 -1
  134. package/esm/runtime/scale.d.ts +2 -1
  135. package/esm/runtime/scale.js +35 -0
  136. package/esm/runtime/scale.js.map +1 -1
  137. package/esm/runtime/transform.js +1 -1
  138. package/esm/runtime/transform.js.map +1 -1
  139. package/esm/runtime/types/common.d.ts +11 -2
  140. package/esm/runtime/types/component.d.ts +9 -7
  141. package/esm/runtime/types/options.d.ts +8 -6
  142. package/esm/runtime/types/scale.d.ts +18 -0
  143. package/esm/runtime/types/scale.js +19 -0
  144. package/esm/runtime/types/scale.js.map +1 -0
  145. package/esm/runtime/types/theme.d.ts +2 -1
  146. package/esm/shape/area/hv.d.ts +3 -0
  147. package/esm/shape/area/hv.js +9 -0
  148. package/esm/shape/area/hv.js.map +1 -0
  149. package/esm/shape/area/hvh.d.ts +3 -0
  150. package/esm/shape/area/{step.js → hvh.js} +3 -3
  151. package/esm/shape/area/hvh.js.map +1 -0
  152. package/esm/shape/area/vh.d.ts +3 -0
  153. package/esm/shape/area/vh.js +9 -0
  154. package/esm/shape/area/vh.js.map +1 -0
  155. package/esm/shape/connector/connector.js +1 -1
  156. package/esm/shape/index.d.ts +6 -2
  157. package/esm/shape/index.js +3 -1
  158. package/esm/shape/index.js.map +1 -1
  159. package/esm/shape/interval/color.d.ts +1 -0
  160. package/esm/shape/interval/color.js +65 -53
  161. package/esm/shape/interval/color.js.map +1 -1
  162. package/esm/shape/utils.js.map +1 -1
  163. package/esm/spec/composition.d.ts +0 -3
  164. package/esm/spec/geometry.d.ts +1 -1
  165. package/esm/spec/interaction.d.ts +33 -15
  166. package/esm/spec/transform.d.ts +13 -3
  167. package/esm/stdlib/index.js +4 -9
  168. package/esm/stdlib/index.js.map +1 -1
  169. package/esm/theme/academy.js +10 -4
  170. package/esm/theme/academy.js.map +1 -1
  171. package/esm/theme/dark.js +10 -4
  172. package/esm/theme/dark.js.map +1 -1
  173. package/esm/theme/light.js +12 -4
  174. package/esm/theme/light.js.map +1 -1
  175. package/esm/transform/sample.js +42 -26
  176. package/esm/transform/sample.js.map +1 -1
  177. package/esm/transform/utils/lttb.d.ts +5 -0
  178. package/esm/transform/utils/lttb.js +56 -0
  179. package/esm/transform/utils/lttb.js.map +1 -0
  180. package/esm/utils/angle.d.ts +2 -0
  181. package/esm/utils/angle.js +7 -0
  182. package/esm/utils/angle.js.map +1 -0
  183. package/esm/utils/array.d.ts +8 -0
  184. package/esm/utils/array.js +35 -0
  185. package/esm/utils/array.js.map +1 -1
  186. package/esm/utils/coordinate.d.ts +4 -0
  187. package/esm/utils/coordinate.js +19 -0
  188. package/esm/utils/coordinate.js.map +1 -1
  189. package/esm/utils/event.d.ts +0 -2
  190. package/esm/utils/event.js +0 -18
  191. package/esm/utils/event.js.map +1 -1
  192. package/esm/utils/scale.d.ts +1 -0
  193. package/esm/utils/scale.js +3 -3
  194. package/esm/utils/scale.js.map +1 -1
  195. package/esm/utils/vector.d.ts +1 -1
  196. package/esm/utils/vector.js +1 -1
  197. package/lib/animation/morphing.js +22 -2
  198. package/lib/animation/morphing.js.map +1 -1
  199. package/lib/api/chart.d.ts +8 -3
  200. package/lib/api/chart.js +37 -15
  201. package/lib/api/chart.js.map +1 -1
  202. package/lib/api/composition/base.d.ts +18 -1
  203. package/lib/api/composition/base.js +44 -1
  204. package/lib/api/composition/base.js.map +1 -1
  205. package/lib/api/mark/base.d.ts +22 -0
  206. package/lib/api/mark/base.js +58 -0
  207. package/lib/api/mark/base.js.map +1 -0
  208. package/lib/api/mark/mark.d.ts +1 -7
  209. package/lib/api/mark/mark.js +28 -41
  210. package/lib/api/mark/mark.js.map +1 -1
  211. package/lib/api/props.js +0 -20
  212. package/lib/api/props.js.map +1 -1
  213. package/lib/component/axis.d.ts +5 -7
  214. package/lib/component/axis.js +127 -96
  215. package/lib/component/axis.js.map +1 -1
  216. package/lib/component/axisArc.d.ts +7 -0
  217. package/lib/component/axisArc.js +13 -0
  218. package/lib/component/axisArc.js.map +1 -0
  219. package/lib/component/axisRadar.d.ts +9 -0
  220. package/lib/component/axisRadar.js +50 -0
  221. package/lib/component/axisRadar.js.map +1 -0
  222. package/lib/component/axisX.d.ts +2 -1
  223. package/lib/component/axisX.js +6 -4
  224. package/lib/component/axisX.js.map +1 -1
  225. package/lib/component/axisY.d.ts +1 -1
  226. package/lib/component/axisY.js +3 -3
  227. package/lib/component/axisY.js.map +1 -1
  228. package/lib/component/index.d.ts +8 -0
  229. package/lib/component/index.js +12 -1
  230. package/lib/component/index.js.map +1 -1
  231. package/lib/component/legendCategory.d.ts +5 -3
  232. package/lib/component/legendCategory.js +79 -35
  233. package/lib/component/legendCategory.js.map +1 -1
  234. package/lib/component/legendContinuous.d.ts +4 -2
  235. package/lib/component/legendContinuous.js +75 -23
  236. package/lib/component/legendContinuous.js.map +1 -1
  237. package/lib/component/legendContinuousBlock.d.ts +4 -0
  238. package/lib/component/legendContinuousBlock.js +10 -0
  239. package/lib/component/legendContinuousBlock.js.map +1 -0
  240. package/lib/component/legendContinuousBlockSize.d.ts +4 -0
  241. package/lib/component/legendContinuousBlockSize.js +10 -0
  242. package/lib/component/legendContinuousBlockSize.js.map +1 -0
  243. package/lib/component/legendContinuousSize.d.ts +4 -0
  244. package/lib/component/legendContinuousSize.js +14 -0
  245. package/lib/component/legendContinuousSize.js.map +1 -0
  246. package/lib/component/scrollbar.js +1 -1
  247. package/lib/component/scrollbar.js.map +1 -1
  248. package/lib/component/slider.js +1 -1
  249. package/lib/component/slider.js.map +1 -1
  250. package/lib/component/title.js +1 -1
  251. package/lib/component/title.js.map +1 -1
  252. package/lib/component/utils.d.ts +12 -0
  253. package/lib/component/utils.js +39 -1
  254. package/lib/component/utils.js.map +1 -1
  255. package/lib/composition/facetCircle.js +1 -1
  256. package/lib/composition/facetCircle.js.map +1 -1
  257. package/lib/coordinate/index.d.ts +3 -3
  258. package/lib/coordinate/index.js +4 -1
  259. package/lib/coordinate/index.js.map +1 -1
  260. package/lib/coordinate/polar.d.ts +6 -0
  261. package/lib/coordinate/polar.js +20 -7
  262. package/lib/coordinate/polar.js.map +1 -1
  263. package/lib/coordinate/radial.d.ts +6 -0
  264. package/lib/coordinate/radial.js +19 -6
  265. package/lib/coordinate/radial.js.map +1 -1
  266. package/lib/coordinate/theta.d.ts +7 -0
  267. package/lib/coordinate/theta.js +18 -5
  268. package/lib/coordinate/theta.js.map +1 -1
  269. package/lib/interaction/builtin/elementHighlight.d.ts +2 -0
  270. package/lib/interaction/builtin/elementHighlightByColor.d.ts +2 -0
  271. package/lib/interaction/builtin/elementHighlightByX.d.ts +2 -0
  272. package/lib/interaction/index.d.ts +2 -0
  273. package/lib/interaction/index.js +5 -1
  274. package/lib/interaction/index.js.map +1 -1
  275. package/lib/interaction/native/brushAxisHighlight.js +6 -1
  276. package/lib/interaction/native/brushAxisHighlight.js.map +1 -1
  277. package/lib/interaction/native/brushFilter.js +1 -1
  278. package/lib/interaction/native/brushFilter.js.map +1 -1
  279. package/lib/interaction/native/elementHighlight.d.ts +7 -2
  280. package/lib/interaction/native/elementHighlight.js +71 -18
  281. package/lib/interaction/native/elementHighlight.js.map +1 -1
  282. package/lib/interaction/native/elementHighlightByColor.d.ts +4 -1
  283. package/lib/interaction/native/elementHighlightByColor.js +18 -2
  284. package/lib/interaction/native/elementHighlightByColor.js.map +1 -1
  285. package/lib/interaction/native/elementHighlightByX.d.ts +3 -3
  286. package/lib/interaction/native/elementHighlightByX.js +18 -2
  287. package/lib/interaction/native/elementHighlightByX.js.map +1 -1
  288. package/lib/interaction/native/elementSelect.d.ts +1 -1
  289. package/lib/interaction/native/elementSelect.js +41 -20
  290. package/lib/interaction/native/elementSelect.js.map +1 -1
  291. package/lib/interaction/native/elementSelectByColor.js +2 -1
  292. package/lib/interaction/native/elementSelectByColor.js.map +1 -1
  293. package/lib/interaction/native/elementSelectByX.js +2 -1
  294. package/lib/interaction/native/elementSelectByX.js.map +1 -1
  295. package/lib/interaction/native/legendFilter.d.ts +6 -0
  296. package/lib/interaction/native/legendFilter.js +31 -6
  297. package/lib/interaction/native/legendFilter.js.map +1 -1
  298. package/lib/interaction/native/legendHighlight.d.ts +4 -0
  299. package/lib/interaction/native/legendHighlight.js +97 -0
  300. package/lib/interaction/native/legendHighlight.js.map +1 -0
  301. package/lib/interaction/native/poptip.d.ts +5 -0
  302. package/lib/interaction/native/poptip.js +95 -0
  303. package/lib/interaction/native/poptip.js.map +1 -0
  304. package/lib/interaction/native/utils.d.ts +13 -2
  305. package/lib/interaction/native/utils.js +154 -27
  306. package/lib/interaction/native/utils.js.map +1 -1
  307. package/lib/label-transform/overlapDodgeY.js +0 -8
  308. package/lib/label-transform/overlapDodgeY.js.map +1 -1
  309. package/lib/mark/area.js +1 -1
  310. package/lib/mark/area.js.map +1 -1
  311. package/lib/mark/pack.js +0 -1
  312. package/lib/mark/pack.js.map +1 -1
  313. package/lib/mark/treemap.js +0 -1
  314. package/lib/mark/treemap.js.map +1 -1
  315. package/lib/runtime/component.d.ts +3 -0
  316. package/lib/runtime/component.js +250 -107
  317. package/lib/runtime/component.js.map +1 -1
  318. package/lib/runtime/coordinate.d.ts +11 -0
  319. package/lib/runtime/coordinate.js +26 -17
  320. package/lib/runtime/coordinate.js.map +1 -1
  321. package/lib/runtime/layout.d.ts +1 -1
  322. package/lib/runtime/layout.js +146 -77
  323. package/lib/runtime/layout.js.map +1 -1
  324. package/lib/runtime/plot.js +4 -3
  325. package/lib/runtime/plot.js.map +1 -1
  326. package/lib/runtime/render.js +20 -12
  327. package/lib/runtime/render.js.map +1 -1
  328. package/lib/runtime/scale.d.ts +2 -1
  329. package/lib/runtime/scale.js +37 -1
  330. package/lib/runtime/scale.js.map +1 -1
  331. package/lib/runtime/transform.js +1 -1
  332. package/lib/runtime/transform.js.map +1 -1
  333. package/lib/runtime/types/common.d.ts +11 -2
  334. package/lib/runtime/types/component.d.ts +9 -7
  335. package/lib/runtime/types/options.d.ts +8 -6
  336. package/lib/runtime/types/scale.d.ts +18 -0
  337. package/lib/runtime/types/scale.js +22 -0
  338. package/lib/runtime/types/scale.js.map +1 -0
  339. package/lib/runtime/types/theme.d.ts +2 -1
  340. package/lib/shape/area/hv.d.ts +3 -0
  341. package/lib/shape/area/hv.js +13 -0
  342. package/lib/shape/area/hv.js.map +1 -0
  343. package/lib/shape/area/hvh.d.ts +3 -0
  344. package/lib/shape/area/{step.js → hvh.js} +5 -5
  345. package/lib/shape/area/hvh.js.map +1 -0
  346. package/lib/shape/area/vh.d.ts +3 -0
  347. package/lib/shape/area/vh.js +13 -0
  348. package/lib/shape/area/vh.js.map +1 -0
  349. package/lib/shape/connector/connector.js +1 -1
  350. package/lib/shape/index.d.ts +6 -2
  351. package/lib/shape/index.js +7 -3
  352. package/lib/shape/index.js.map +1 -1
  353. package/lib/shape/interval/color.d.ts +1 -0
  354. package/lib/shape/interval/color.js +67 -54
  355. package/lib/shape/interval/color.js.map +1 -1
  356. package/lib/shape/utils.js.map +1 -1
  357. package/lib/spec/composition.d.ts +0 -3
  358. package/lib/spec/geometry.d.ts +1 -1
  359. package/lib/spec/interaction.d.ts +33 -15
  360. package/lib/spec/transform.d.ts +13 -3
  361. package/lib/stdlib/index.js +1 -1
  362. package/lib/stdlib/index.js.map +1 -1
  363. package/lib/theme/academy.js +10 -4
  364. package/lib/theme/academy.js.map +1 -1
  365. package/lib/theme/dark.js +10 -4
  366. package/lib/theme/dark.js.map +1 -1
  367. package/lib/theme/light.js +12 -4
  368. package/lib/theme/light.js.map +1 -1
  369. package/lib/transform/sample.js +42 -26
  370. package/lib/transform/sample.js.map +1 -1
  371. package/lib/transform/utils/lttb.d.ts +5 -0
  372. package/lib/transform/utils/lttb.js +60 -0
  373. package/lib/transform/utils/lttb.js.map +1 -0
  374. package/lib/utils/angle.d.ts +2 -0
  375. package/lib/utils/angle.js +12 -0
  376. package/lib/utils/angle.js.map +1 -0
  377. package/lib/utils/array.d.ts +8 -0
  378. package/lib/utils/array.js +38 -1
  379. package/lib/utils/array.js.map +1 -1
  380. package/lib/utils/coordinate.d.ts +4 -0
  381. package/lib/utils/coordinate.js +24 -1
  382. package/lib/utils/coordinate.js.map +1 -1
  383. package/lib/utils/event.d.ts +0 -2
  384. package/lib/utils/event.js +1 -21
  385. package/lib/utils/event.js.map +1 -1
  386. package/lib/utils/scale.d.ts +1 -0
  387. package/lib/utils/scale.js +5 -4
  388. package/lib/utils/scale.js.map +1 -1
  389. package/lib/utils/vector.d.ts +1 -1
  390. package/lib/utils/vector.js +1 -1
  391. package/package.json +7 -7
  392. package/src/animation/morphing.ts +23 -2
  393. package/src/api/chart.ts +43 -20
  394. package/src/api/composition/base.ts +46 -1
  395. package/src/api/mark/base.ts +58 -0
  396. package/src/api/mark/mark.ts +1 -20
  397. package/src/api/props.ts +0 -23
  398. package/src/component/axis.ts +199 -118
  399. package/src/component/axisArc.ts +16 -0
  400. package/src/component/axisRadar.ts +73 -0
  401. package/src/component/axisX.ts +7 -4
  402. package/src/component/axisY.ts +4 -4
  403. package/src/component/index.ts +8 -0
  404. package/src/component/legendCategory.ts +156 -35
  405. package/src/component/legendContinuous.ts +133 -32
  406. package/src/component/legendContinuousBlock.ts +17 -0
  407. package/src/component/legendContinuousBlockSize.ts +22 -0
  408. package/src/component/legendContinuousSize.ts +27 -0
  409. package/src/component/scrollbar.ts +1 -1
  410. package/src/component/slider.ts +1 -1
  411. package/src/component/title.ts +1 -1
  412. package/src/component/utils.ts +46 -0
  413. package/src/composition/facetCircle.ts +1 -1
  414. package/src/coordinate/index.ts +3 -3
  415. package/src/coordinate/polar.ts +19 -11
  416. package/src/coordinate/radial.ts +19 -10
  417. package/src/coordinate/theta.ts +18 -9
  418. package/src/interaction/index.ts +2 -0
  419. package/src/interaction/native/brushAxisHighlight.ts +9 -1
  420. package/src/interaction/native/brushFilter.ts +1 -1
  421. package/src/interaction/native/elementHighlight.ts +78 -12
  422. package/src/interaction/native/elementHighlightByColor.ts +9 -4
  423. package/src/interaction/native/elementHighlightByX.ts +9 -5
  424. package/src/interaction/native/elementSelect.ts +58 -15
  425. package/src/interaction/native/elementSelectByColor.ts +4 -1
  426. package/src/interaction/native/elementSelectByX.ts +4 -1
  427. package/src/interaction/native/legendFilter.ts +29 -7
  428. package/src/interaction/native/legendHighlight.ts +86 -0
  429. package/src/interaction/native/poptip.ts +87 -0
  430. package/src/interaction/native/utils.ts +183 -26
  431. package/src/label-transform/overlapDodgeY.ts +0 -7
  432. package/src/mark/area.ts +1 -1
  433. package/src/mark/pack.ts +0 -1
  434. package/src/mark/treemap.ts +0 -1
  435. package/src/runtime/component.ts +335 -124
  436. package/src/runtime/coordinate.ts +29 -16
  437. package/src/runtime/layout.ts +206 -97
  438. package/src/runtime/plot.ts +5 -4
  439. package/src/runtime/render.ts +26 -13
  440. package/src/runtime/scale.ts +41 -0
  441. package/src/runtime/transform.ts +3 -0
  442. package/src/runtime/types/common.ts +23 -10
  443. package/src/runtime/types/component.ts +19 -10
  444. package/src/runtime/types/options.ts +24 -16
  445. package/src/runtime/types/scale.ts +20 -0
  446. package/src/runtime/types/theme.ts +2 -1
  447. package/src/shape/area/hv.ts +20 -0
  448. package/src/shape/area/{step.ts → hvh.ts} +3 -3
  449. package/src/shape/area/vh.ts +20 -0
  450. package/src/shape/connector/connector.ts +1 -1
  451. package/src/shape/index.ts +7 -2
  452. package/src/shape/interval/color.ts +86 -54
  453. package/src/shape/utils.ts +2 -0
  454. package/src/spec/composition.ts +0 -1
  455. package/src/spec/geometry.ts +3 -1
  456. package/src/spec/interaction.ts +51 -19
  457. package/src/spec/transform.ts +27 -2
  458. package/src/stdlib/index.ts +22 -6
  459. package/src/theme/academy.ts +10 -4
  460. package/src/theme/dark.ts +10 -4
  461. package/src/theme/light.ts +12 -4
  462. package/src/transform/sample.ts +54 -18
  463. package/src/transform/utils/lttb.ts +73 -0
  464. package/src/utils/angle.ts +7 -0
  465. package/src/utils/array.ts +39 -0
  466. package/src/utils/coordinate.ts +29 -0
  467. package/src/utils/event.ts +0 -26
  468. package/src/utils/scale.ts +4 -4
  469. package/src/utils/vector.ts +1 -1
  470. package/esm/shape/area/step.d.ts +0 -3
  471. package/esm/shape/area/step.js.map +0 -1
  472. package/lib/shape/area/step.d.ts +0 -3
  473. package/lib/shape/area/step.js.map +0 -1
@@ -5,18 +5,27 @@ import { Reflect } from './reflect';
5
5
 
6
6
  export type RadialOptions = Omit<RadialCoordinate, 'type'>;
7
7
 
8
+ export const getRadialOptions = (options: RadialOptions = {}) => {
9
+ const defaultOptions = {
10
+ startAngle: -Math.PI / 2,
11
+ endAngle: (Math.PI * 3) / 2,
12
+ innerRadius: 0,
13
+ outerRadius: 1,
14
+ };
15
+ return { ...defaultOptions, ...options };
16
+ };
17
+
8
18
  /**
9
19
  * Radial
10
20
  */
11
- export const Radial: CC<RadialOptions> = ({
12
- startAngle = -Math.PI / 2,
13
- endAngle = (Math.PI * 3) / 2,
14
- innerRadius = 0,
15
- outerRadius = 1,
16
- }) => [
17
- ['transpose'],
18
- ...Reflect(),
19
- ...Polar({ startAngle, endAngle, innerRadius, outerRadius }),
20
- ];
21
+ export const Radial: CC<RadialOptions> = (options) => {
22
+ const { startAngle, endAngle, innerRadius, outerRadius } =
23
+ getRadialOptions(options);
24
+ return [
25
+ ['transpose'],
26
+ ...Reflect(),
27
+ ...Polar({ startAngle, endAngle, innerRadius, outerRadius }),
28
+ ];
29
+ };
21
30
 
22
31
  Radial.props = {};
@@ -5,17 +5,26 @@ import { Transpose } from './transpose';
5
5
 
6
6
  export type ThetaOptions = ThetaCoordinate;
7
7
 
8
+ export const getThetaOptions = (options: ThetaOptions = {}) => {
9
+ const defaultOptions = {
10
+ startAngle: -Math.PI / 2,
11
+ endAngle: (Math.PI * 3) / 2,
12
+ innerRadius: 0,
13
+ outerRadius: 1,
14
+ };
15
+ return { ...defaultOptions, ...options };
16
+ };
17
+
8
18
  /**
9
19
  * Theta = Transpose + Polar.
10
20
  */
11
- export const Theta: CC<ThetaOptions> = ({
12
- startAngle = -Math.PI / 2,
13
- endAngle = (Math.PI * 3) / 2,
14
- innerRadius = 0,
15
- outerRadius = 1,
16
- }) => [
17
- ...Transpose(),
18
- ...Polar({ startAngle, endAngle, innerRadius, outerRadius }),
19
- ];
21
+ export const Theta: CC<ThetaOptions> = (options) => {
22
+ const { startAngle, endAngle, innerRadius, outerRadius } =
23
+ getThetaOptions(options);
24
+ return [
25
+ ...Transpose(),
26
+ ...Polar({ startAngle, endAngle, innerRadius, outerRadius }),
27
+ ];
28
+ };
20
29
 
21
30
  Theta.props = {};
@@ -10,6 +10,7 @@ export { ChartIndex } from './native/chartIndex';
10
10
  export { Fisheye } from './native/fisheye';
11
11
  export { Tooltip } from './native/tooltip';
12
12
  export { LegendFilter } from './native/legendFilter';
13
+ export { LegendHighlight } from './native/legendHighlight';
13
14
  export { BrushHighlight } from './native/brushHighlight';
14
15
  export { BrushXHighlight } from './native/brushXHighlight';
15
16
  export { BrushYHighlight } from './native/brushYHighlight';
@@ -18,6 +19,7 @@ export { BrushFilter } from './native/brushFilter';
18
19
  export { BrushXFilter } from './native/brushXFilter';
19
20
  export { BrushYFilter } from './native/brushYFilter';
20
21
  export { SliderFilter } from './native/sliderFilter';
22
+ export { Poptip } from './native/poptip';
21
23
 
22
24
  export { LEGEND_ITEMS_CLASS_NAME } from './native/legendFilter';
23
25
 
@@ -185,7 +185,15 @@ export function BrushAxisHighlight(options) {
185
185
  offsetY: y0,
186
186
  offsetX: x0,
187
187
  points: (element) => element.__data__.points,
188
- horizontal: (axis) => axis.attributes.horizontal,
188
+ horizontal: (axis) => {
189
+ const {
190
+ startPos: [sx, sy],
191
+ endPos: [ex, ey],
192
+ } = axis.attributes;
193
+ // attention, non-horizontal does not mean vertical
194
+ // it may has a specific degree angle
195
+ return sx !== ex && sy === ey;
196
+ },
189
197
  datum: createDatumof(view),
190
198
  unhighlightedOpacity: 0.5,
191
199
  ...options,
@@ -60,7 +60,7 @@ export function brushFilter(
60
60
 
61
61
  return () => {
62
62
  brush.destroy();
63
- root.removeEventListener('dblclick', click);
63
+ root.removeEventListener('click', click);
64
64
  };
65
65
  }
66
66
 
@@ -1,5 +1,6 @@
1
1
  import { DisplayObject } from '@antv/g';
2
2
  import { group } from 'd3-array';
3
+ import { isPolar, isTranspose } from '../../utils/coordinate';
3
4
  import { subObject } from '../../utils/helper';
4
5
  import {
5
6
  createValueof,
@@ -8,6 +9,9 @@ import {
8
9
  useState,
9
10
  renderLink,
10
11
  applyDefaultsHighlightedStyle,
12
+ renderBackground,
13
+ selectPlotArea,
14
+ offsetTransform,
11
15
  } from './utils';
12
16
 
13
17
  /**
@@ -20,6 +24,11 @@ export function elementHighlight(
20
24
  datum, // given each element returns the datum of it
21
25
  groupKey = (d) => d, // group elements by specified key
22
26
  link = false, // draw link or not
27
+ background = false, // draw background or not
28
+ delay = 60, // delay to unhighlighted element
29
+ scale,
30
+ coordinate,
31
+ offset = 0,
23
32
  ...rest
24
33
  }: Record<string, any>,
25
34
  ) {
@@ -27,50 +36,107 @@ export function elementHighlight(
27
36
  const elementSet = new Set(elements);
28
37
  const keyGroup = group(elements, groupKey);
29
38
  const valueof = createValueof(elements, datum);
30
- const [appendLink, removeLink] = renderLink(root, {
39
+ const [appendLink, removeLink] = renderLink({
31
40
  elements,
32
41
  valueof,
42
+ link,
43
+ coordinate,
33
44
  ...subObject(rest, 'link'),
34
45
  });
35
- const { setState, removeState } = useState(rest, valueof);
46
+ const [appendBackground, removeBackground, isBackground] = renderBackground({
47
+ scale,
48
+ coordinate,
49
+ background,
50
+ valueof,
51
+ ...subObject(rest, 'background'),
52
+ });
53
+ const elementStyle = {
54
+ ...(offset !== 0 && {
55
+ // Apply translate to mock slice out.
56
+ highlightedTransform: (_, i) => {
57
+ return offsetTransform(elements[i], offset, coordinate);
58
+ },
59
+ }),
60
+ ...rest,
61
+ };
62
+ const { setState, removeState, hasState } = useState(elementStyle, valueof);
36
63
 
64
+ let out; // Timer for delaying unhighlighted.
37
65
  const pointerover = (event) => {
38
66
  const { target: element } = event;
39
67
  if (!elementSet.has(element)) return;
68
+ if (out) clearTimeout(out);
40
69
  const k = groupKey(element);
41
70
  const group = keyGroup.get(k);
42
71
  const groupSet = new Set(group);
43
72
  for (const e of elements) {
44
- if (groupSet.has(e)) setState(e, 'highlighted');
45
- else setState(e, 'unhighlighted');
73
+ if (groupSet.has(e)) {
74
+ if (!hasState(e, 'highlighted')) setState(e, 'highlighted');
75
+ } else {
76
+ setState(e, 'unhighlighted');
77
+ removeLink(e);
78
+ }
79
+ if (e !== element) removeBackground(e);
80
+ }
81
+ appendBackground(element);
82
+ appendLink(group);
83
+ };
84
+
85
+ const delayUnhighlighted = () => {
86
+ if (out) clearTimeout(out);
87
+ out = setTimeout(() => {
88
+ unhighlighted();
89
+ out = null;
90
+ }, delay);
91
+ };
92
+
93
+ const unhighlighted = () => {
94
+ for (const e of elements) {
95
+ removeState(e, 'unhighlighted', 'highlighted');
96
+ removeBackground(e);
97
+ removeLink(e);
46
98
  }
47
- if (link) appendLink(group);
48
99
  };
49
100
 
50
101
  const pointerout = (event) => {
51
102
  const { target: element } = event;
52
- if (!elementSet.has(element)) return;
53
- for (const e of elements) removeState(e, 'unhighlighted', 'highlighted');
54
- if (link) removeLink();
103
+ if (background && !isBackground(element)) return;
104
+ if (!background && !elementSet.has(element)) return;
105
+ if (delay > 0) delayUnhighlighted();
106
+ else unhighlighted();
107
+ };
108
+
109
+ const pointerleave = () => {
110
+ unhighlighted();
55
111
  };
56
112
 
57
113
  root.addEventListener('pointerover', pointerover);
58
114
  root.addEventListener('pointerout', pointerout);
115
+ root.addEventListener('pointerleave', pointerleave);
59
116
 
60
117
  return () => {
61
118
  root.removeEventListener('pointerover', pointerover);
62
119
  root.removeEventListener('pointerout', pointerout);
63
- removeLink();
120
+ root.removeEventListener('pointerleave', pointerleave);
121
+ for (const e of elements) {
122
+ removeBackground(e);
123
+ removeLink(e);
124
+ }
64
125
  };
65
126
  }
66
127
 
67
- export function ElementHighlight(options) {
128
+ export function ElementHighlight({ delay, ...rest }) {
68
129
  return (context) => {
69
130
  const { container, view } = context;
70
- return elementHighlight(container, {
71
- ...applyDefaultsHighlightedStyle(options),
131
+ const { scale, coordinate } = view;
132
+ const plotArea = selectPlotArea(container);
133
+ return elementHighlight(plotArea, {
134
+ ...applyDefaultsHighlightedStyle(rest),
72
135
  elements: selectG2Elements,
73
136
  datum: createDatumof(view),
137
+ scale,
138
+ coordinate,
139
+ delay,
74
140
  });
75
141
  };
76
142
  }
@@ -3,21 +3,26 @@ import {
3
3
  createDatumof,
4
4
  selectG2Elements,
5
5
  createColorKey,
6
+ selectPlotArea,
6
7
  } from './utils';
7
8
  import { elementHighlight } from './elementHighlight';
8
9
 
9
10
  /**
10
11
  * @todo Bind abstract data or data index.
11
12
  */
12
- export function ElementHighlightByColor(options) {
13
+ export function ElementHighlightByColor({ delay, ...rest }) {
13
14
  return (context) => {
14
15
  const { container, view } = context;
15
- return elementHighlight(container, {
16
- ...options,
17
- ...applyDefaultsHighlightedStyle(options),
16
+ const { scale, coordinate } = view;
17
+ const plotArea = selectPlotArea(container);
18
+ return elementHighlight(plotArea, {
19
+ ...applyDefaultsHighlightedStyle(rest),
18
20
  elements: selectG2Elements,
19
21
  datum: createDatumof(view),
20
22
  groupKey: createColorKey(view),
23
+ scale,
24
+ coordinate,
25
+ delay,
21
26
  });
22
27
  };
23
28
  }
@@ -3,6 +3,7 @@ import {
3
3
  createDatumof,
4
4
  selectG2Elements,
5
5
  createXKey,
6
+ selectPlotArea,
6
7
  } from './utils';
7
8
  import { elementHighlight } from './elementHighlight';
8
9
 
@@ -10,16 +11,19 @@ import { elementHighlight } from './elementHighlight';
10
11
  *
11
12
  * @todo Bind abstract data or data index.
12
13
  */
13
- export function ElementHighlightByX(
14
- options = { selectedLineWidth: 1, selectedColor: 'black' },
15
- ) {
14
+ export function ElementHighlightByX({ delay, ...rest }) {
16
15
  return (context) => {
17
16
  const { container, view } = context;
18
- return elementHighlight(container, {
19
- ...applyDefaultsHighlightedStyle(options),
17
+ const { scale, coordinate } = view;
18
+ const plotArea = selectPlotArea(container);
19
+ return elementHighlight(plotArea, {
20
+ ...applyDefaultsHighlightedStyle(rest),
20
21
  elements: selectG2Elements,
21
22
  datum: createDatumof(view),
22
23
  groupKey: createXKey(view),
24
+ scale,
25
+ coordinate,
26
+ delay,
23
27
  });
24
28
  };
25
29
  }
@@ -8,6 +8,9 @@ import {
8
8
  useState,
9
9
  renderLink,
10
10
  applyDefaultsHighlightedStyle,
11
+ renderBackground,
12
+ selectPlotArea,
13
+ offsetTransform,
11
14
  } from './utils';
12
15
 
13
16
  /**
@@ -21,6 +24,10 @@ export function elementSelect(
21
24
  groupKey = (d) => d, // group elements by specified key
22
25
  link = false, // draw link or not
23
26
  single = false, // single select or not
27
+ coordinate,
28
+ background = false,
29
+ offset = 0,
30
+ scale,
24
31
  ...rest
25
32
  }: Record<string, any>,
26
33
  ) {
@@ -28,15 +35,39 @@ export function elementSelect(
28
35
  const elementSet = new Set(elements);
29
36
  const keyGroup = group(elements, groupKey);
30
37
  const valueof = createValueof(elements, datum);
31
- const [appendLink, removeLink] = renderLink(root, {
38
+ const [appendLink, removeLink] = renderLink({
39
+ link,
32
40
  elements,
33
41
  valueof,
42
+ coordinate,
34
43
  ...subObject(rest, 'link'),
35
44
  });
36
- const { setState, removeState, hasState } = useState(rest, valueof);
45
+
46
+ const [appendBackground, removeBackground] = renderBackground({
47
+ background,
48
+ coordinate,
49
+ scale,
50
+ valueof,
51
+ ...subObject(rest, 'background'),
52
+ });
53
+
54
+ const elementStyle = {
55
+ ...(offset !== 0 && {
56
+ // Apply translate to mock slice out.
57
+ selectedTransform: (_, i) => {
58
+ return offsetTransform(elements[i], offset, coordinate);
59
+ },
60
+ }),
61
+ ...rest,
62
+ };
63
+ const { setState, removeState, hasState } = useState(elementStyle, valueof);
64
+
37
65
  const clear = () => {
38
- for (const e of elements) removeState(e, 'selected', 'unselected');
39
- if (link) removeLink();
66
+ for (const e of elements) {
67
+ removeState(e, 'selected', 'unselected');
68
+ removeLink(e);
69
+ removeBackground(e);
70
+ }
40
71
  return;
41
72
  };
42
73
 
@@ -49,13 +80,14 @@ export function elementSelect(
49
80
  const groupSet = new Set(group);
50
81
  for (const e of elements) {
51
82
  if (groupSet.has(e)) setState(e, 'selected');
52
- else setState(e, 'unselected');
53
- }
54
- // Remove all links and append link for this group.
55
- if (link) {
56
- removeLink();
57
- appendLink(group);
83
+ else {
84
+ setState(e, 'unselected');
85
+ removeLink(e);
86
+ }
87
+ if (e !== element) removeBackground(e);
58
88
  }
89
+ appendLink(group);
90
+ appendBackground(element);
59
91
  }
60
92
  };
61
93
 
@@ -70,7 +102,8 @@ export function elementSelect(
70
102
  else if (!hasState(e, 'selected')) setState(e, 'unselected');
71
103
  }
72
104
  // Append link for each group only once.
73
- if (!hasSelectedGroup && link) appendLink(group, k);
105
+ if (!hasSelectedGroup && link) appendLink(group);
106
+ appendBackground(element);
74
107
  } else {
75
108
  // If there is no selected elements after resetting this group,
76
109
  // clear the states.
@@ -80,8 +113,11 @@ export function elementSelect(
80
113
  if (!hasSelected) return clear();
81
114
  // If there are still some selected elements after resetting this group,
82
115
  // only remove the link.
83
- for (const e of group) setState(e, 'unselected');
84
- if (link) removeLink(k);
116
+ for (const e of group) {
117
+ setState(e, 'unselected');
118
+ removeLink(e);
119
+ removeBackground(e);
120
+ }
85
121
  }
86
122
  };
87
123
 
@@ -98,17 +134,24 @@ export function elementSelect(
98
134
 
99
135
  return () => {
100
136
  root.removeEventListener('click', click);
101
- removeLink();
137
+ for (const e of elements) {
138
+ removeLink(e);
139
+ }
102
140
  };
103
141
  }
104
142
 
105
143
  export function ElementSelect(options) {
106
144
  return (context) => {
107
145
  const { container, view } = context;
108
- return elementSelect(container, {
146
+ const { coordinate, scale } = view;
147
+ const plotArea = selectPlotArea(container);
148
+ return elementSelect(plotArea, {
149
+ ...options,
109
150
  ...applyDefaultsHighlightedStyle(options),
110
151
  elements: selectG2Elements,
111
152
  datum: createDatumof(view),
153
+ coordinate,
154
+ scale,
112
155
  });
113
156
  };
114
157
  }
@@ -3,13 +3,16 @@ import {
3
3
  selectG2Elements,
4
4
  applyDefaultsHighlightedStyle,
5
5
  createColorKey,
6
+ selectPlotArea,
6
7
  } from './utils';
7
8
  import { elementSelect } from './elementSelect';
8
9
 
9
10
  export function ElementSelectByColor(options) {
10
11
  return (context) => {
11
12
  const { container, view } = context;
12
- return elementSelect(container, {
13
+ const plot = selectPlotArea(container);
14
+ return elementSelect(plot, {
15
+ ...options,
13
16
  ...applyDefaultsHighlightedStyle(options),
14
17
  elements: selectG2Elements,
15
18
  datum: createDatumof(view),
@@ -3,13 +3,16 @@ import {
3
3
  selectG2Elements,
4
4
  applyDefaultsHighlightedStyle,
5
5
  createXKey,
6
+ selectPlotArea,
6
7
  } from './utils';
7
8
  import { elementSelect } from './elementSelect';
8
9
 
9
10
  export function ElementSelectByX(options) {
10
11
  return (context) => {
11
12
  const { container, view } = context;
12
- return elementSelect(container, {
13
+ const plot = selectPlotArea(container);
14
+ return elementSelect(plot, {
15
+ ...options,
13
16
  ...applyDefaultsHighlightedStyle(options),
14
17
  elements: selectG2Elements,
15
18
  datum: createDatumof(view),
@@ -11,27 +11,48 @@ export const LEGEND_MAKER_CLASS_NAME = 'legend-category-item-marker';
11
11
 
12
12
  export const LEGEND_LABEL_CLASS_NAME = 'legend-category-item-label';
13
13
 
14
- function markerOf(item) {
14
+ export function markerOf(item) {
15
15
  return item.getElementsByClassName(LEGEND_MAKER_CLASS_NAME)[0];
16
16
  }
17
17
 
18
- function labelOf(item) {
18
+ export function labelOf(item) {
19
19
  return item.getElementsByClassName(LEGEND_LABEL_CLASS_NAME)[0];
20
20
  }
21
21
 
22
- function legendsOf(root) {
22
+ export function itemsOf(root) {
23
23
  return root.getElementsByClassName(LEGEND_ITEMS_CLASS_NAME);
24
24
  }
25
25
 
26
+ export function legendsOf(root) {
27
+ return root.getElementsByClassName(CATEGORY_LEGEND_CLASS_NAME);
28
+ }
29
+
30
+ export function dataOf(root) {
31
+ // legend -> layout -> container
32
+ let parent = root.parentNode;
33
+ while (parent && !parent.__data__) {
34
+ parent = parent.parentNode;
35
+ }
36
+ return parent.__data__;
37
+ }
38
+
39
+ export function attributesOf(root) {
40
+ let child = root;
41
+ while (child && !child.attr('class').startsWith('legend')) {
42
+ child = child.children[0];
43
+ }
44
+ return child.attributes;
45
+ }
46
+
26
47
  function builtInAccessors(selectedLegend) {
27
48
  // Get the value and scale type from legend.
28
- const { data } = selectedLegend.attributes;
29
- const { __data__ } = selectedLegend.parentNode;
30
- const { name: channel } = __data__.scale;
49
+ const { data } = attributesOf(selectedLegend);
50
+ // In theory, scales' channels are the same
51
+ const { name: channel } = dataOf(selectedLegend).scales[0];
31
52
  return [
32
53
  channel,
33
54
  {
34
- legends: legendsOf,
55
+ legends: itemsOf,
35
56
  marker: markerOf,
36
57
  label: labelOf,
37
58
  datum: (d) => {
@@ -66,6 +87,7 @@ function legendFilter(
66
87
  ? {
67
88
  labelUnselectedFill: '#aaa',
68
89
  markerUnselectedFill: '#aaa',
90
+ markerUnselectedStroke: '#aaa',
69
91
  }
70
92
  : options;
71
93
  const markerStyle = subObject(style, 'marker');
@@ -0,0 +1,86 @@
1
+ import { group } from 'd3-array';
2
+ import { subObject } from '../../utils/helper';
3
+ import { selectG2Elements, useState } from './utils';
4
+ import { markerOf, labelOf, itemsOf, legendsOf, dataOf } from './legendFilter';
5
+
6
+ export function LegendHighlight({ channel, ...rest }) {
7
+ return (context) => {
8
+ const { container, view } = context;
9
+ const legends = legendsOf(container);
10
+ const elements = selectG2Elements(container);
11
+ const channelOf = (legend) => {
12
+ return dataOf(legend).scales[0].name;
13
+ };
14
+ const scaleOf = (channel) => {
15
+ const {
16
+ scale: { [channel]: scale },
17
+ } = view;
18
+ return scale;
19
+ };
20
+ for (const legend of legends) {
21
+ const datumOf = (item) => {
22
+ const { data } = legend.attributes;
23
+ const { __data__: datum } = item;
24
+ const { index } = datum;
25
+ return data[index].label;
26
+ };
27
+ const channel = channelOf(legend);
28
+ const items = itemsOf(legend);
29
+ const scale = scaleOf(channel);
30
+ const elementGroup = group<any, any>(elements, (d) =>
31
+ scale.invert(d.__data__[channel]),
32
+ );
33
+ const { setState, removeState } = useState(rest);
34
+ const markerStyle = subObject(rest, 'marker');
35
+ const labelStyle = subObject(rest, 'label');
36
+ const { setState: setM, removeState: removeM } = useState(markerStyle);
37
+ const { setState: setL, removeState: removeL } = useState(labelStyle);
38
+ const updateLegendState = (highlight) => {
39
+ for (const item of items) {
40
+ const marker = markerOf(item);
41
+ const label = labelOf(item);
42
+ if (item === highlight || highlight === null) {
43
+ removeM(marker, 'unhighlighted');
44
+ removeL(label, 'unhighlighted');
45
+ } else {
46
+ setM(marker, 'unhighlighted');
47
+ setL(label, 'unhighlighted');
48
+ }
49
+ }
50
+ };
51
+
52
+ const itemPointerover = new Map();
53
+
54
+ // Add listener for the legend items.
55
+ for (const item of items) {
56
+ const pointerover = () => {
57
+ const value = datumOf(item);
58
+ const elementSet = new Set(elementGroup.get(value));
59
+ for (const e of elements) {
60
+ if (elementSet.has(e)) setState(e, 'highlighted');
61
+ else setState(e, 'unhighlighted');
62
+ }
63
+ updateLegendState(item);
64
+ };
65
+ item.addEventListener('pointerover', pointerover);
66
+ itemPointerover.set(item, pointerover);
67
+ }
68
+
69
+ // Add listener for the legend group.
70
+ const pointerleave = () => {
71
+ for (const e of elements) {
72
+ removeState(e, 'unhighlighted', 'highlighted');
73
+ }
74
+ updateLegendState(null);
75
+ };
76
+ legend.addEventListener('pointerleave', pointerleave);
77
+
78
+ return () => {
79
+ legend.removeEventListener(pointerleave);
80
+ for (const [item, pointerover] of itemPointerover) {
81
+ item.removeEventListener(pointerover);
82
+ }
83
+ };
84
+ }
85
+ };
86
+ }