@gravity-ui/charts 1.46.0 → 1.47.0

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 (445) hide show
  1. package/dist/cjs/components/ChartInner/index.js +1 -0
  2. package/dist/cjs/components/ChartInner/useChartInnerProps.d.ts +1 -0
  3. package/dist/cjs/components/ChartInner/useChartInnerProps.js +13 -6
  4. package/dist/cjs/components/Legend/index.js +13 -14
  5. package/dist/cjs/components/Tooltip/index.js +22 -1
  6. package/dist/cjs/core/axes/x-axis.js +1 -1
  7. package/dist/cjs/core/axes/y-axis.js +1 -1
  8. package/dist/cjs/core/brush/index.d.ts +2 -0
  9. package/dist/cjs/core/brush/index.js +2 -0
  10. package/dist/cjs/{hooks/useBrush → core/brush}/types.d.ts +2 -2
  11. package/dist/cjs/{hooks/useBrush → core/brush}/utils.d.ts +1 -1
  12. package/dist/cjs/core/chart/index.d.ts +1 -0
  13. package/dist/cjs/core/chart/index.js +1 -0
  14. package/dist/cjs/core/chart/types.d.ts +8 -0
  15. package/dist/cjs/core/index.d.ts +3 -0
  16. package/dist/cjs/core/index.js +3 -0
  17. package/dist/cjs/core/layout/chart-dimensions.d.ts +1 -1
  18. package/dist/cjs/core/range-slider/index.d.ts +2 -0
  19. package/dist/cjs/core/range-slider/index.js +2 -0
  20. package/dist/cjs/core/range-slider/types.d.ts +4 -0
  21. package/dist/{esm/hooks/useRangeSlider → cjs/core/range-slider}/utils.d.ts +5 -5
  22. package/dist/{esm/hooks/useRangeSlider → cjs/core/range-slider}/utils.js +1 -1
  23. package/dist/cjs/core/scales/utils.d.ts +1 -1
  24. package/dist/cjs/core/scales/utils.js +1 -1
  25. package/dist/cjs/core/scales/x-scale.d.ts +2 -2
  26. package/dist/cjs/core/scales/x-scale.js +2 -2
  27. package/dist/cjs/core/scales/y-scale.js +69 -4
  28. package/dist/cjs/core/series/prepare-area.js +1 -1
  29. package/dist/cjs/core/series/prepare-bar-x.js +1 -1
  30. package/dist/cjs/core/series/prepare-bar-y.js +1 -1
  31. package/dist/cjs/core/series/prepare-funnel.js +1 -1
  32. package/dist/cjs/core/series/prepare-heatmap.js +1 -1
  33. package/dist/cjs/core/series/prepare-legend.d.ts +1 -1
  34. package/dist/cjs/core/series/prepare-legend.js +2 -2
  35. package/dist/cjs/core/series/prepare-line.js +1 -1
  36. package/dist/cjs/core/series/prepare-pie.js +1 -1
  37. package/dist/cjs/core/series/prepare-radar.js +1 -1
  38. package/dist/cjs/core/series/prepare-sankey.js +1 -1
  39. package/dist/cjs/core/series/prepare-scatter.js +1 -1
  40. package/dist/cjs/core/series/prepare-treemap.js +1 -1
  41. package/dist/cjs/core/series/prepare-waterfall.js +1 -1
  42. package/dist/cjs/core/series/prepare-x-range.js +1 -1
  43. package/dist/cjs/core/series/prepareSeries.d.ts +7 -1
  44. package/dist/cjs/core/series/prepareSeries.js +31 -0
  45. package/dist/cjs/core/series/types.d.ts +5 -0
  46. package/dist/cjs/core/series/utils.d.ts +4 -0
  47. package/dist/cjs/core/series/utils.js +9 -1
  48. package/dist/cjs/{hooks/useShapes/annotation/index.d.ts → core/shapes/annotation.d.ts} +1 -7
  49. package/dist/cjs/{hooks/useShapes/annotation/index.js → core/shapes/annotation.js} +2 -2
  50. package/dist/cjs/{hooks/useShapes → core/shapes}/area/prepare-data.d.ts +4 -4
  51. package/dist/cjs/{hooks/useShapes → core/shapes}/area/prepare-data.js +9 -4
  52. package/dist/cjs/core/shapes/area/renderer.d.ts +11 -0
  53. package/dist/cjs/core/shapes/area/renderer.js +175 -0
  54. package/dist/cjs/{hooks/useShapes → core/shapes}/area/types.d.ts +7 -8
  55. package/dist/{esm/hooks/useShapes → cjs/core/shapes}/bar-x/prepare-data.d.ts +4 -4
  56. package/dist/{esm/hooks/useShapes → cjs/core/shapes}/bar-x/prepare-data.js +6 -6
  57. package/dist/cjs/core/shapes/bar-x/renderer.d.ts +9 -0
  58. package/dist/cjs/core/shapes/bar-x/renderer.js +104 -0
  59. package/dist/cjs/{hooks/useShapes → core/shapes}/bar-x/types.d.ts +1 -2
  60. package/dist/{esm/hooks/useShapes → cjs/core/shapes}/bar-y/prepare-data.d.ts +3 -3
  61. package/dist/{esm/hooks/useShapes → cjs/core/shapes}/bar-y/prepare-data.js +3 -3
  62. package/dist/cjs/core/shapes/bar-y/renderer.d.ts +6 -0
  63. package/dist/cjs/core/shapes/bar-y/renderer.js +74 -0
  64. package/dist/cjs/{hooks/useShapes → core/shapes}/bar-y/types.d.ts +1 -1
  65. package/dist/cjs/{hooks/useShapes → core/shapes}/bar-y/utils.js +1 -1
  66. package/dist/cjs/core/shapes/data-labels.d.ts +15 -0
  67. package/dist/cjs/core/shapes/data-labels.js +15 -0
  68. package/dist/cjs/{hooks/useShapes → core/shapes}/funnel/prepare-data.d.ts +1 -1
  69. package/dist/{esm/hooks/useShapes → cjs/core/shapes}/funnel/prepare-data.js +1 -1
  70. package/dist/cjs/core/shapes/funnel/renderer.d.ts +6 -0
  71. package/dist/cjs/core/shapes/funnel/renderer.js +74 -0
  72. package/dist/cjs/{hooks/useShapes → core/shapes}/funnel/types.d.ts +2 -2
  73. package/dist/cjs/{hooks/useShapes → core/shapes}/heatmap/prepare-data.d.ts +3 -3
  74. package/dist/cjs/{hooks/useShapes → core/shapes}/heatmap/prepare-data.js +3 -2
  75. package/dist/cjs/core/shapes/heatmap/renderer.d.ts +6 -0
  76. package/dist/cjs/core/shapes/heatmap/renderer.js +50 -0
  77. package/dist/{esm/hooks/useShapes → cjs/core/shapes}/heatmap/types.d.ts +2 -1
  78. package/dist/{esm/hooks/useShapes → cjs/core/shapes}/line/prepare-data.d.ts +4 -4
  79. package/dist/cjs/{hooks/useShapes → core/shapes}/line/prepare-data.js +12 -4
  80. package/dist/cjs/core/shapes/line/renderer.d.ts +11 -0
  81. package/dist/cjs/core/shapes/line/renderer.js +161 -0
  82. package/dist/{esm/hooks/useShapes → cjs/core/shapes}/line/types.d.ts +7 -8
  83. package/dist/cjs/core/shapes/marker.d.ts +45 -0
  84. package/dist/{esm/hooks/useShapes → cjs/core/shapes}/marker.js +2 -2
  85. package/dist/cjs/{hooks/useShapes → core/shapes}/pie/prepare-data.d.ts +1 -1
  86. package/dist/cjs/{hooks/useShapes → core/shapes}/pie/prepare-data.js +3 -3
  87. package/dist/cjs/core/shapes/pie/renderer.d.ts +8 -0
  88. package/dist/cjs/core/shapes/pie/renderer.js +160 -0
  89. package/dist/cjs/{hooks/useShapes → core/shapes}/pie/types.d.ts +1 -1
  90. package/dist/cjs/{hooks/useShapes → core/shapes}/radar/prepare-data.d.ts +1 -1
  91. package/dist/{esm/hooks/useShapes → cjs/core/shapes}/radar/prepare-data.js +2 -2
  92. package/dist/cjs/core/shapes/radar/renderer.d.ts +6 -0
  93. package/dist/cjs/core/shapes/radar/renderer.js +122 -0
  94. package/dist/cjs/{hooks/useShapes → core/shapes}/radar/types.d.ts +1 -1
  95. package/dist/cjs/{hooks/useShapes → core/shapes}/sankey/prepare-data.d.ts +1 -1
  96. package/dist/cjs/{hooks/useShapes → core/shapes}/sankey/prepare-data.js +1 -1
  97. package/dist/cjs/core/shapes/sankey/renderer.d.ts +6 -0
  98. package/dist/cjs/core/shapes/sankey/renderer.js +44 -0
  99. package/dist/{esm/hooks/useShapes → cjs/core/shapes}/sankey/types.d.ts +1 -1
  100. package/dist/{esm/hooks/useShapes → cjs/core/shapes}/scatter/prepare-data.d.ts +3 -3
  101. package/dist/cjs/{hooks/useShapes → core/shapes}/scatter/prepare-data.js +2 -2
  102. package/dist/cjs/core/shapes/scatter/renderer.d.ts +6 -0
  103. package/dist/cjs/core/shapes/scatter/renderer.js +52 -0
  104. package/dist/cjs/{hooks/useShapes → core/shapes}/scatter/types.d.ts +1 -1
  105. package/dist/cjs/{hooks/useShapes → core/shapes}/treemap/prepare-data.d.ts +1 -1
  106. package/dist/{esm/hooks/useShapes → cjs/core/shapes}/treemap/prepare-data.js +3 -3
  107. package/dist/cjs/core/shapes/treemap/renderer.d.ts +6 -0
  108. package/dist/cjs/core/shapes/treemap/renderer.js +88 -0
  109. package/dist/cjs/{hooks/useShapes → core/shapes}/treemap/types.d.ts +1 -1
  110. package/dist/cjs/core/shapes/utils.d.ts +76 -0
  111. package/dist/cjs/core/shapes/utils.js +186 -0
  112. package/dist/cjs/{hooks/useShapes → core/shapes}/waterfall/prepare-data.d.ts +3 -3
  113. package/dist/{esm/hooks/useShapes → cjs/core/shapes}/waterfall/prepare-data.js +4 -4
  114. package/dist/cjs/core/shapes/waterfall/renderer.d.ts +6 -0
  115. package/dist/cjs/core/shapes/waterfall/renderer.js +109 -0
  116. package/dist/cjs/{hooks/useShapes → core/shapes}/waterfall/types.d.ts +1 -1
  117. package/dist/cjs/{hooks/useShapes → core/shapes}/x-range/prepare-data.d.ts +3 -3
  118. package/dist/cjs/{hooks/useShapes → core/shapes}/x-range/prepare-data.js +4 -4
  119. package/dist/cjs/core/shapes/x-range/renderer.d.ts +6 -0
  120. package/dist/cjs/core/shapes/x-range/renderer.js +88 -0
  121. package/dist/cjs/{hooks/useShapes → core/shapes}/x-range/types.d.ts +1 -1
  122. package/dist/cjs/core/types/chart/area.d.ts +0 -1
  123. package/dist/cjs/core/types/chart/axis.d.ts +0 -1
  124. package/dist/cjs/core/types/chart/base.d.ts +18 -7
  125. package/dist/cjs/core/types/chart/tooltip.d.ts +3 -3
  126. package/dist/cjs/core/types/formatter.d.ts +1 -40
  127. package/dist/{esm/hooks/utils/get-band-size.js → cjs/core/utils/band-size.js} +1 -1
  128. package/dist/cjs/{hooks → core}/utils/bar-y.d.ts +3 -3
  129. package/dist/{esm/hooks → cjs/core}/utils/bar-y.js +4 -4
  130. package/dist/cjs/core/utils/format.d.ts +2 -2
  131. package/dist/cjs/core/utils/get-closest-data.d.ts +1 -1
  132. package/dist/cjs/core/utils/get-closest-data.js +13 -8
  133. package/dist/cjs/core/utils/series/sorting.js +1 -1
  134. package/dist/cjs/core/utils/text.d.ts +0 -1
  135. package/dist/cjs/core/utils/text.js +0 -1
  136. package/dist/cjs/core/zoom/index.d.ts +2 -0
  137. package/dist/cjs/core/zoom/index.js +2 -0
  138. package/dist/{esm/hooks/useZoom → cjs/core/zoom}/utils.d.ts +3 -3
  139. package/dist/{esm/hooks/useZoom → cjs/core/zoom}/utils.js +1 -1
  140. package/dist/cjs/core/zoom/zoom.d.ts +3 -3
  141. package/dist/cjs/hooks/index.d.ts +3 -3
  142. package/dist/cjs/hooks/index.js +3 -3
  143. package/dist/cjs/hooks/types.d.ts +2 -8
  144. package/dist/cjs/hooks/useBrush/index.d.ts +1 -1
  145. package/dist/cjs/hooks/useBrush/index.js +1 -1
  146. package/dist/cjs/hooks/useRangeSlider/index.js +3 -3
  147. package/dist/cjs/hooks/useRangeSlider/types.d.ts +6 -8
  148. package/dist/cjs/hooks/useShapes/area/index.d.ts +2 -2
  149. package/dist/cjs/hooks/useShapes/area/index.js +13 -185
  150. package/dist/cjs/hooks/useShapes/bar-x/index.d.ts +4 -4
  151. package/dist/cjs/hooks/useShapes/bar-x/index.js +10 -119
  152. package/dist/cjs/hooks/useShapes/bar-y/index.d.ts +3 -3
  153. package/dist/cjs/hooks/useShapes/bar-y/index.js +5 -84
  154. package/dist/cjs/hooks/useShapes/funnel/index.d.ts +4 -4
  155. package/dist/cjs/hooks/useShapes/funnel/index.js +4 -83
  156. package/dist/cjs/hooks/useShapes/heatmap/index.d.ts +4 -4
  157. package/dist/cjs/hooks/useShapes/heatmap/index.js +4 -59
  158. package/dist/cjs/hooks/useShapes/index.d.ts +15 -16
  159. package/dist/cjs/hooks/useShapes/index.js +13 -13
  160. package/dist/cjs/hooks/useShapes/line/index.d.ts +2 -2
  161. package/dist/cjs/hooks/useShapes/line/index.js +14 -172
  162. package/dist/cjs/hooks/useShapes/pie/index.d.ts +3 -5
  163. package/dist/cjs/hooks/useShapes/pie/index.js +3 -158
  164. package/dist/cjs/hooks/useShapes/radar/index.d.ts +2 -2
  165. package/dist/cjs/hooks/useShapes/radar/index.js +2 -121
  166. package/dist/cjs/hooks/useShapes/sankey/index.d.ts +2 -2
  167. package/dist/cjs/hooks/useShapes/sankey/index.js +2 -51
  168. package/dist/cjs/hooks/useShapes/scatter/index.d.ts +3 -3
  169. package/dist/cjs/hooks/useShapes/scatter/index.js +3 -58
  170. package/dist/cjs/hooks/useShapes/treemap/index.d.ts +2 -2
  171. package/dist/cjs/hooks/useShapes/treemap/index.js +2 -88
  172. package/dist/cjs/hooks/useShapes/utils.d.ts +3 -53
  173. package/dist/cjs/hooks/useShapes/utils.js +3 -140
  174. package/dist/cjs/hooks/useShapes/waterfall/index.d.ts +4 -4
  175. package/dist/cjs/hooks/useShapes/waterfall/index.js +6 -119
  176. package/dist/cjs/hooks/useShapes/x-range/index.d.ts +4 -4
  177. package/dist/cjs/hooks/useShapes/x-range/index.js +3 -98
  178. package/dist/cjs/hooks/useZoom/index.d.ts +1 -1
  179. package/dist/cjs/hooks/useZoom/index.js +1 -1
  180. package/dist/cjs/index.d.ts +1 -0
  181. package/dist/cjs/index.js +1 -0
  182. package/dist/cjs/libs/format-number/index.js +82 -14
  183. package/dist/cjs/libs/format-number/presets.d.ts +40 -0
  184. package/dist/cjs/libs/format-number/presets.js +66 -0
  185. package/dist/cjs/libs/format-number/types.d.ts +82 -3
  186. package/dist/cjs/setup-jsdom.js +7 -0
  187. package/dist/esm/components/ChartInner/index.js +1 -0
  188. package/dist/esm/components/ChartInner/useChartInnerProps.d.ts +1 -0
  189. package/dist/esm/components/ChartInner/useChartInnerProps.js +13 -6
  190. package/dist/esm/components/Legend/index.js +13 -14
  191. package/dist/esm/components/Tooltip/index.js +22 -1
  192. package/dist/esm/core/axes/x-axis.js +1 -1
  193. package/dist/esm/core/axes/y-axis.js +1 -1
  194. package/dist/esm/core/brush/index.d.ts +2 -0
  195. package/dist/esm/core/brush/index.js +2 -0
  196. package/dist/esm/{hooks/useBrush → core/brush}/types.d.ts +2 -2
  197. package/dist/esm/{hooks/useBrush → core/brush}/utils.d.ts +1 -1
  198. package/dist/esm/core/chart/index.d.ts +1 -0
  199. package/dist/esm/core/chart/index.js +1 -0
  200. package/dist/esm/core/chart/types.d.ts +8 -0
  201. package/dist/esm/core/index.d.ts +3 -0
  202. package/dist/esm/core/index.js +3 -0
  203. package/dist/esm/core/layout/chart-dimensions.d.ts +1 -1
  204. package/dist/esm/core/range-slider/index.d.ts +2 -0
  205. package/dist/esm/core/range-slider/index.js +2 -0
  206. package/dist/esm/core/range-slider/types.d.ts +4 -0
  207. package/dist/{cjs/hooks/useRangeSlider → esm/core/range-slider}/utils.d.ts +5 -5
  208. package/dist/{cjs/hooks/useRangeSlider → esm/core/range-slider}/utils.js +1 -1
  209. package/dist/esm/core/scales/utils.d.ts +1 -1
  210. package/dist/esm/core/scales/utils.js +1 -1
  211. package/dist/esm/core/scales/x-scale.d.ts +2 -2
  212. package/dist/esm/core/scales/x-scale.js +2 -2
  213. package/dist/esm/core/scales/y-scale.js +69 -4
  214. package/dist/esm/core/series/prepare-area.js +1 -1
  215. package/dist/esm/core/series/prepare-bar-x.js +1 -1
  216. package/dist/esm/core/series/prepare-bar-y.js +1 -1
  217. package/dist/esm/core/series/prepare-funnel.js +1 -1
  218. package/dist/esm/core/series/prepare-heatmap.js +1 -1
  219. package/dist/esm/core/series/prepare-legend.d.ts +1 -1
  220. package/dist/esm/core/series/prepare-legend.js +2 -2
  221. package/dist/esm/core/series/prepare-line.js +1 -1
  222. package/dist/esm/core/series/prepare-pie.js +1 -1
  223. package/dist/esm/core/series/prepare-radar.js +1 -1
  224. package/dist/esm/core/series/prepare-sankey.js +1 -1
  225. package/dist/esm/core/series/prepare-scatter.js +1 -1
  226. package/dist/esm/core/series/prepare-treemap.js +1 -1
  227. package/dist/esm/core/series/prepare-waterfall.js +1 -1
  228. package/dist/esm/core/series/prepare-x-range.js +1 -1
  229. package/dist/esm/core/series/prepareSeries.d.ts +7 -1
  230. package/dist/esm/core/series/prepareSeries.js +31 -0
  231. package/dist/esm/core/series/types.d.ts +5 -0
  232. package/dist/esm/core/series/utils.d.ts +4 -0
  233. package/dist/esm/core/series/utils.js +9 -1
  234. package/dist/esm/{hooks/useShapes/annotation/index.d.ts → core/shapes/annotation.d.ts} +1 -7
  235. package/dist/esm/{hooks/useShapes/annotation/index.js → core/shapes/annotation.js} +2 -2
  236. package/dist/esm/{hooks/useShapes → core/shapes}/area/prepare-data.d.ts +4 -4
  237. package/dist/esm/{hooks/useShapes → core/shapes}/area/prepare-data.js +9 -4
  238. package/dist/esm/core/shapes/area/renderer.d.ts +11 -0
  239. package/dist/esm/core/shapes/area/renderer.js +175 -0
  240. package/dist/esm/{hooks/useShapes → core/shapes}/area/types.d.ts +7 -8
  241. package/dist/{cjs/hooks/useShapes → esm/core/shapes}/bar-x/prepare-data.d.ts +4 -4
  242. package/dist/{cjs/hooks/useShapes → esm/core/shapes}/bar-x/prepare-data.js +6 -6
  243. package/dist/esm/core/shapes/bar-x/renderer.d.ts +9 -0
  244. package/dist/esm/core/shapes/bar-x/renderer.js +104 -0
  245. package/dist/esm/{hooks/useShapes → core/shapes}/bar-x/types.d.ts +1 -2
  246. package/dist/{cjs/hooks/useShapes → esm/core/shapes}/bar-y/prepare-data.d.ts +3 -3
  247. package/dist/{cjs/hooks/useShapes → esm/core/shapes}/bar-y/prepare-data.js +3 -3
  248. package/dist/esm/core/shapes/bar-y/renderer.d.ts +6 -0
  249. package/dist/esm/core/shapes/bar-y/renderer.js +74 -0
  250. package/dist/esm/{hooks/useShapes → core/shapes}/bar-y/types.d.ts +1 -1
  251. package/dist/esm/{hooks/useShapes → core/shapes}/bar-y/utils.js +1 -1
  252. package/dist/esm/core/shapes/data-labels.d.ts +15 -0
  253. package/dist/esm/core/shapes/data-labels.js +15 -0
  254. package/dist/esm/{hooks/useShapes → core/shapes}/funnel/prepare-data.d.ts +1 -1
  255. package/dist/{cjs/hooks/useShapes → esm/core/shapes}/funnel/prepare-data.js +1 -1
  256. package/dist/esm/core/shapes/funnel/renderer.d.ts +6 -0
  257. package/dist/esm/core/shapes/funnel/renderer.js +74 -0
  258. package/dist/esm/{hooks/useShapes → core/shapes}/funnel/types.d.ts +2 -2
  259. package/dist/esm/{hooks/useShapes → core/shapes}/heatmap/prepare-data.d.ts +3 -3
  260. package/dist/esm/{hooks/useShapes → core/shapes}/heatmap/prepare-data.js +3 -2
  261. package/dist/esm/core/shapes/heatmap/renderer.d.ts +6 -0
  262. package/dist/esm/core/shapes/heatmap/renderer.js +50 -0
  263. package/dist/{cjs/hooks/useShapes → esm/core/shapes}/heatmap/types.d.ts +2 -1
  264. package/dist/{cjs/hooks/useShapes → esm/core/shapes}/line/prepare-data.d.ts +4 -4
  265. package/dist/esm/{hooks/useShapes → core/shapes}/line/prepare-data.js +12 -4
  266. package/dist/esm/core/shapes/line/renderer.d.ts +11 -0
  267. package/dist/esm/core/shapes/line/renderer.js +161 -0
  268. package/dist/{cjs/hooks/useShapes → esm/core/shapes}/line/types.d.ts +7 -8
  269. package/dist/esm/core/shapes/marker.d.ts +45 -0
  270. package/dist/{cjs/hooks/useShapes → esm/core/shapes}/marker.js +2 -2
  271. package/dist/esm/{hooks/useShapes → core/shapes}/pie/prepare-data.d.ts +1 -1
  272. package/dist/esm/{hooks/useShapes → core/shapes}/pie/prepare-data.js +3 -3
  273. package/dist/esm/core/shapes/pie/renderer.d.ts +8 -0
  274. package/dist/esm/core/shapes/pie/renderer.js +160 -0
  275. package/dist/esm/{hooks/useShapes → core/shapes}/pie/types.d.ts +1 -1
  276. package/dist/esm/{hooks/useShapes → core/shapes}/radar/prepare-data.d.ts +1 -1
  277. package/dist/{cjs/hooks/useShapes → esm/core/shapes}/radar/prepare-data.js +2 -2
  278. package/dist/esm/core/shapes/radar/renderer.d.ts +6 -0
  279. package/dist/esm/core/shapes/radar/renderer.js +122 -0
  280. package/dist/esm/{hooks/useShapes → core/shapes}/radar/types.d.ts +1 -1
  281. package/dist/esm/{hooks/useShapes → core/shapes}/sankey/prepare-data.d.ts +1 -1
  282. package/dist/esm/{hooks/useShapes → core/shapes}/sankey/prepare-data.js +1 -1
  283. package/dist/esm/core/shapes/sankey/renderer.d.ts +6 -0
  284. package/dist/esm/core/shapes/sankey/renderer.js +44 -0
  285. package/dist/{cjs/hooks/useShapes → esm/core/shapes}/sankey/types.d.ts +1 -1
  286. package/dist/{cjs/hooks/useShapes → esm/core/shapes}/scatter/prepare-data.d.ts +3 -3
  287. package/dist/esm/{hooks/useShapes → core/shapes}/scatter/prepare-data.js +2 -2
  288. package/dist/esm/core/shapes/scatter/renderer.d.ts +6 -0
  289. package/dist/esm/core/shapes/scatter/renderer.js +52 -0
  290. package/dist/esm/{hooks/useShapes → core/shapes}/scatter/types.d.ts +1 -1
  291. package/dist/esm/{hooks/useShapes → core/shapes}/treemap/prepare-data.d.ts +1 -1
  292. package/dist/{cjs/hooks/useShapes → esm/core/shapes}/treemap/prepare-data.js +3 -3
  293. package/dist/esm/core/shapes/treemap/renderer.d.ts +6 -0
  294. package/dist/esm/core/shapes/treemap/renderer.js +88 -0
  295. package/dist/esm/{hooks/useShapes → core/shapes}/treemap/types.d.ts +1 -1
  296. package/dist/esm/core/shapes/treemap/types.js +1 -0
  297. package/dist/esm/core/shapes/utils.d.ts +76 -0
  298. package/dist/esm/core/shapes/utils.js +186 -0
  299. package/dist/esm/{hooks/useShapes → core/shapes}/waterfall/prepare-data.d.ts +3 -3
  300. package/dist/{cjs/hooks/useShapes → esm/core/shapes}/waterfall/prepare-data.js +4 -4
  301. package/dist/esm/core/shapes/waterfall/renderer.d.ts +6 -0
  302. package/dist/esm/core/shapes/waterfall/renderer.js +109 -0
  303. package/dist/esm/{hooks/useShapes → core/shapes}/waterfall/types.d.ts +1 -1
  304. package/dist/esm/core/shapes/waterfall/types.js +1 -0
  305. package/dist/esm/{hooks/useShapes → core/shapes}/x-range/prepare-data.d.ts +3 -3
  306. package/dist/esm/{hooks/useShapes → core/shapes}/x-range/prepare-data.js +4 -4
  307. package/dist/esm/core/shapes/x-range/renderer.d.ts +6 -0
  308. package/dist/esm/core/shapes/x-range/renderer.js +88 -0
  309. package/dist/esm/{hooks/useShapes → core/shapes}/x-range/types.d.ts +1 -1
  310. package/dist/esm/core/shapes/x-range/types.js +1 -0
  311. package/dist/esm/core/types/chart/area.d.ts +0 -1
  312. package/dist/esm/core/types/chart/axis.d.ts +0 -1
  313. package/dist/esm/core/types/chart/base.d.ts +18 -7
  314. package/dist/esm/core/types/chart/tooltip.d.ts +3 -3
  315. package/dist/esm/core/types/formatter.d.ts +1 -40
  316. package/dist/{cjs/hooks/utils/get-band-size.js → esm/core/utils/band-size.js} +1 -1
  317. package/dist/esm/{hooks → core}/utils/bar-y.d.ts +3 -3
  318. package/dist/{cjs/hooks → esm/core}/utils/bar-y.js +4 -4
  319. package/dist/esm/core/utils/format.d.ts +2 -2
  320. package/dist/esm/core/utils/get-closest-data.d.ts +1 -1
  321. package/dist/esm/core/utils/get-closest-data.js +13 -8
  322. package/dist/esm/core/utils/series/sorting.js +1 -1
  323. package/dist/esm/core/utils/text.d.ts +0 -1
  324. package/dist/esm/core/utils/text.js +0 -1
  325. package/dist/esm/core/zoom/index.d.ts +2 -0
  326. package/dist/esm/core/zoom/index.js +2 -0
  327. package/dist/esm/core/zoom/types.js +1 -0
  328. package/dist/{cjs/hooks/useZoom → esm/core/zoom}/utils.d.ts +3 -3
  329. package/dist/{cjs/hooks/useZoom → esm/core/zoom}/utils.js +1 -1
  330. package/dist/esm/core/zoom/zoom.d.ts +3 -3
  331. package/dist/esm/hooks/index.d.ts +3 -3
  332. package/dist/esm/hooks/index.js +3 -3
  333. package/dist/esm/hooks/types.d.ts +2 -8
  334. package/dist/esm/hooks/useBrush/index.d.ts +1 -1
  335. package/dist/esm/hooks/useBrush/index.js +1 -1
  336. package/dist/esm/hooks/useRangeSlider/index.js +3 -3
  337. package/dist/esm/hooks/useRangeSlider/types.d.ts +6 -8
  338. package/dist/esm/hooks/useShapes/area/index.d.ts +2 -2
  339. package/dist/esm/hooks/useShapes/area/index.js +13 -185
  340. package/dist/esm/hooks/useShapes/bar-x/index.d.ts +4 -4
  341. package/dist/esm/hooks/useShapes/bar-x/index.js +10 -119
  342. package/dist/esm/hooks/useShapes/bar-y/index.d.ts +3 -3
  343. package/dist/esm/hooks/useShapes/bar-y/index.js +5 -84
  344. package/dist/esm/hooks/useShapes/funnel/index.d.ts +4 -4
  345. package/dist/esm/hooks/useShapes/funnel/index.js +4 -83
  346. package/dist/esm/hooks/useShapes/heatmap/index.d.ts +4 -4
  347. package/dist/esm/hooks/useShapes/heatmap/index.js +4 -59
  348. package/dist/esm/hooks/useShapes/index.d.ts +15 -16
  349. package/dist/esm/hooks/useShapes/index.js +13 -13
  350. package/dist/esm/hooks/useShapes/line/index.d.ts +2 -2
  351. package/dist/esm/hooks/useShapes/line/index.js +14 -172
  352. package/dist/esm/hooks/useShapes/pie/index.d.ts +3 -5
  353. package/dist/esm/hooks/useShapes/pie/index.js +3 -158
  354. package/dist/esm/hooks/useShapes/radar/index.d.ts +2 -2
  355. package/dist/esm/hooks/useShapes/radar/index.js +2 -121
  356. package/dist/esm/hooks/useShapes/sankey/index.d.ts +2 -2
  357. package/dist/esm/hooks/useShapes/sankey/index.js +2 -51
  358. package/dist/esm/hooks/useShapes/scatter/index.d.ts +3 -3
  359. package/dist/esm/hooks/useShapes/scatter/index.js +3 -58
  360. package/dist/esm/hooks/useShapes/treemap/index.d.ts +2 -2
  361. package/dist/esm/hooks/useShapes/treemap/index.js +2 -88
  362. package/dist/esm/hooks/useShapes/utils.d.ts +3 -53
  363. package/dist/esm/hooks/useShapes/utils.js +3 -140
  364. package/dist/esm/hooks/useShapes/waterfall/index.d.ts +4 -4
  365. package/dist/esm/hooks/useShapes/waterfall/index.js +6 -119
  366. package/dist/esm/hooks/useShapes/x-range/index.d.ts +4 -4
  367. package/dist/esm/hooks/useShapes/x-range/index.js +3 -98
  368. package/dist/esm/hooks/useZoom/index.d.ts +1 -1
  369. package/dist/esm/hooks/useZoom/index.js +1 -1
  370. package/dist/esm/index.d.ts +1 -0
  371. package/dist/esm/index.js +1 -0
  372. package/dist/esm/libs/format-number/index.js +82 -14
  373. package/dist/esm/libs/format-number/presets.d.ts +40 -0
  374. package/dist/esm/libs/format-number/presets.js +66 -0
  375. package/dist/esm/libs/format-number/types.d.ts +82 -3
  376. package/dist/esm/setup-jsdom.js +7 -0
  377. package/package.json +5 -2
  378. package/dist/cjs/hooks/useSeries/index.d.ts +0 -12
  379. package/dist/cjs/hooks/useSeries/index.js +0 -40
  380. package/dist/cjs/hooks/useSeries/types.d.ts +0 -1
  381. package/dist/cjs/hooks/useSeries/types.js +0 -1
  382. package/dist/cjs/hooks/useSeries/utils.d.ts +0 -1
  383. package/dist/cjs/hooks/useSeries/utils.js +0 -1
  384. package/dist/cjs/hooks/useShapes/marker.d.ts +0 -15
  385. package/dist/cjs/hooks/utils/index.d.ts +0 -1
  386. package/dist/cjs/hooks/utils/index.js +0 -1
  387. package/dist/esm/hooks/useSeries/index.d.ts +0 -12
  388. package/dist/esm/hooks/useSeries/index.js +0 -40
  389. package/dist/esm/hooks/useSeries/types.d.ts +0 -1
  390. package/dist/esm/hooks/useSeries/types.js +0 -1
  391. package/dist/esm/hooks/useSeries/utils.d.ts +0 -1
  392. package/dist/esm/hooks/useSeries/utils.js +0 -1
  393. package/dist/esm/hooks/useShapes/marker.d.ts +0 -15
  394. package/dist/esm/hooks/utils/index.d.ts +0 -1
  395. package/dist/esm/hooks/utils/index.js +0 -1
  396. /package/dist/cjs/{hooks/useBrush → core/brush}/types.js +0 -0
  397. /package/dist/cjs/{hooks/useBrush → core/brush}/utils.js +0 -0
  398. /package/dist/cjs/{hooks/useShapes/area → core/chart}/types.js +0 -0
  399. /package/dist/cjs/{hooks/useShapes/bar-x → core/range-slider}/types.js +0 -0
  400. /package/dist/cjs/{hooks/useShapes/bar-y → core/shapes/area}/types.js +0 -0
  401. /package/dist/cjs/{hooks/constants.d.ts → core/shapes/bar-constants.d.ts} +0 -0
  402. /package/dist/cjs/{hooks/constants.js → core/shapes/bar-constants.js} +0 -0
  403. /package/dist/cjs/{hooks/useShapes/funnel → core/shapes/bar-x}/types.js +0 -0
  404. /package/dist/cjs/{hooks/useShapes/heatmap → core/shapes/bar-y}/types.js +0 -0
  405. /package/dist/cjs/{hooks/useShapes → core/shapes}/bar-y/utils.d.ts +0 -0
  406. /package/dist/cjs/{hooks/useShapes/line → core/shapes/funnel}/types.js +0 -0
  407. /package/dist/cjs/{hooks/useShapes/pie → core/shapes/heatmap}/types.js +0 -0
  408. /package/dist/cjs/{hooks/useShapes/radar → core/shapes/line}/types.js +0 -0
  409. /package/dist/cjs/{hooks/useShapes/sankey → core/shapes/pie}/types.js +0 -0
  410. /package/dist/cjs/{hooks/useShapes → core/shapes}/pie/utils.d.ts +0 -0
  411. /package/dist/cjs/{hooks/useShapes → core/shapes}/pie/utils.js +0 -0
  412. /package/dist/cjs/{hooks/useShapes/scatter → core/shapes/radar}/types.js +0 -0
  413. /package/dist/cjs/{hooks/useShapes → core/shapes}/sankey/sankey-layout.d.ts +0 -0
  414. /package/dist/cjs/{hooks/useShapes → core/shapes}/sankey/sankey-layout.js +0 -0
  415. /package/dist/cjs/{hooks/useShapes/treemap → core/shapes/sankey}/types.js +0 -0
  416. /package/dist/cjs/{hooks/useShapes/waterfall → core/shapes/scatter}/types.js +0 -0
  417. /package/dist/cjs/{hooks/useShapes/x-range → core/shapes/treemap}/types.js +0 -0
  418. /package/dist/cjs/{hooks/useZoom → core/shapes/waterfall}/types.js +0 -0
  419. /package/dist/{esm/hooks/useBrush → cjs/core/shapes/x-range}/types.js +0 -0
  420. /package/dist/cjs/{hooks/utils/get-band-size.d.ts → core/utils/band-size.d.ts} +0 -0
  421. /package/dist/cjs/{hooks/useZoom → core/zoom}/types.d.ts +0 -0
  422. /package/dist/{esm/hooks/useShapes/area → cjs/core/zoom}/types.js +0 -0
  423. /package/dist/esm/{hooks/useShapes/bar-x → core/brush}/types.js +0 -0
  424. /package/dist/esm/{hooks/useBrush → core/brush}/utils.js +0 -0
  425. /package/dist/esm/{hooks/useShapes/bar-y → core/chart}/types.js +0 -0
  426. /package/dist/esm/{hooks/useShapes/funnel → core/range-slider}/types.js +0 -0
  427. /package/dist/esm/{hooks/useShapes/heatmap → core/shapes/area}/types.js +0 -0
  428. /package/dist/esm/{hooks/constants.d.ts → core/shapes/bar-constants.d.ts} +0 -0
  429. /package/dist/esm/{hooks/constants.js → core/shapes/bar-constants.js} +0 -0
  430. /package/dist/esm/{hooks/useShapes/line → core/shapes/bar-x}/types.js +0 -0
  431. /package/dist/esm/{hooks/useShapes/pie → core/shapes/bar-y}/types.js +0 -0
  432. /package/dist/esm/{hooks/useShapes → core/shapes}/bar-y/utils.d.ts +0 -0
  433. /package/dist/esm/{hooks/useShapes/radar → core/shapes/funnel}/types.js +0 -0
  434. /package/dist/esm/{hooks/useShapes/sankey → core/shapes/heatmap}/types.js +0 -0
  435. /package/dist/esm/{hooks/useShapes/scatter → core/shapes/line}/types.js +0 -0
  436. /package/dist/esm/{hooks/useShapes/treemap → core/shapes/pie}/types.js +0 -0
  437. /package/dist/esm/{hooks/useShapes → core/shapes}/pie/utils.d.ts +0 -0
  438. /package/dist/esm/{hooks/useShapes → core/shapes}/pie/utils.js +0 -0
  439. /package/dist/esm/{hooks/useShapes/waterfall → core/shapes/radar}/types.js +0 -0
  440. /package/dist/esm/{hooks/useShapes → core/shapes}/sankey/sankey-layout.d.ts +0 -0
  441. /package/dist/esm/{hooks/useShapes → core/shapes}/sankey/sankey-layout.js +0 -0
  442. /package/dist/esm/{hooks/useShapes/x-range → core/shapes/sankey}/types.js +0 -0
  443. /package/dist/esm/{hooks/useZoom → core/shapes/scatter}/types.js +0 -0
  444. /package/dist/esm/{hooks/utils/get-band-size.d.ts → core/utils/band-size.d.ts} +0 -0
  445. /package/dist/esm/{hooks/useZoom → core/zoom}/types.d.ts +0 -0
@@ -1,72 +1,17 @@
1
1
  import React from 'react';
2
- import { select } from 'd3-selection';
3
- import get from 'lodash/get';
2
+ import { renderScatter } from '../../../core/shapes/scatter/renderer';
4
3
  import { block } from '../../../utils';
5
4
  import { HtmlLayer } from '../HtmlLayer';
6
- import { getMarkerHaloVisibility, renderMarker, selectMarkerHalo, selectMarkerSymbol, setMarker, } from '../marker';
7
- import { setActiveState, shapeKey } from '../utils';
8
- export { prepareScatterData } from './prepare-data';
5
+ export { prepareScatterData } from '../../../core/shapes/scatter/prepare-data';
9
6
  const b = block('scatter');
10
7
  export function ScatterSeriesShape(props) {
11
8
  const { clipPathId, dispatcher, preparedData, seriesOptions, htmlLayout } = props;
12
- const hoveredDataRef = React.useRef(null);
13
9
  const ref = React.useRef(null);
14
10
  React.useEffect(() => {
15
11
  if (!ref.current) {
16
12
  return () => { };
17
13
  }
18
- const svgElement = select(ref.current);
19
- const hoverOptions = get(seriesOptions, 'scatter.states.hover');
20
- const inactiveOptions = get(seriesOptions, 'scatter.states.inactive');
21
- svgElement.selectAll('*').remove();
22
- const selection = svgElement
23
- .selectAll('path')
24
- .data(preparedData, shapeKey)
25
- .join('g')
26
- .call(renderMarker)
27
- .attr('opacity', (d) => d.point.opacity)
28
- .attr('cursor', (d) => d.point.series.cursor);
29
- const hoverEnabled = hoverOptions === null || hoverOptions === void 0 ? void 0 : hoverOptions.enabled;
30
- const inactiveEnabled = inactiveOptions === null || inactiveOptions === void 0 ? void 0 : inactiveOptions.enabled;
31
- function handleShapeHover(data) {
32
- var _a;
33
- hoveredDataRef.current = data;
34
- const selected = data === null || data === void 0 ? void 0 : data.find((d) => d.series.type === 'scatter');
35
- const selectedDataItem = selected === null || selected === void 0 ? void 0 : selected.data;
36
- const selectedSeriesId = (_a = selected === null || selected === void 0 ? void 0 : selected.series) === null || _a === void 0 ? void 0 : _a.id;
37
- selection.datum((d, index, list) => {
38
- const elementSelection = select(list[index]);
39
- const hovered = Boolean(hoverEnabled && d.point.data === selectedDataItem);
40
- if (d.hovered !== hovered) {
41
- d.hovered = hovered;
42
- elementSelection.attr('z-index', hovered ? 999 : null);
43
- selectMarkerHalo(elementSelection).attr('visibility', getMarkerHaloVisibility);
44
- selectMarkerSymbol(elementSelection).call(setMarker, hovered ? 'hover' : 'normal');
45
- }
46
- if (hovered) {
47
- elementSelection.raise();
48
- }
49
- if (d.point.series.marker.states.normal.enabled) {
50
- const isActive = Boolean(!inactiveEnabled ||
51
- !selectedSeriesId ||
52
- selectedSeriesId === d.point.series.id);
53
- setActiveState({
54
- element: list[index],
55
- state: inactiveOptions,
56
- active: isActive,
57
- datum: d,
58
- });
59
- }
60
- return d;
61
- });
62
- }
63
- if (hoveredDataRef.current !== null) {
64
- handleShapeHover(hoveredDataRef.current);
65
- }
66
- dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher.on('hover-shape.scatter', handleShapeHover);
67
- return () => {
68
- dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher.on('hover-shape.scatter', null);
69
- };
14
+ return renderScatter({ plot: ref.current }, preparedData, seriesOptions, dispatcher);
70
15
  }, [dispatcher, preparedData, seriesOptions]);
71
16
  return (React.createElement(React.Fragment, null,
72
17
  React.createElement("g", { ref: ref, className: b(), clipPath: clipPathId ? `url(#${clipPathId})` : undefined }),
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import type { Dispatch } from 'd3-dispatch';
3
- import type { PreparedSeriesOptions } from '../../useSeries/types';
4
- import type { PreparedTreemapData } from './types';
3
+ import type { PreparedSeriesOptions } from '../../../core/series/types';
4
+ import type { PreparedTreemapData } from '../../../core/shapes/treemap/types';
5
5
  type ShapeProps = {
6
6
  htmlLayout: HTMLElement | null;
7
7
  preparedData: PreparedTreemapData;
@@ -1,102 +1,16 @@
1
1
  import React from 'react';
2
- import { color } from 'd3-color';
3
- import { select } from 'd3-selection';
4
- import get from 'lodash/get';
2
+ import { renderTreemap } from '../../../core/shapes/treemap/renderer';
5
3
  import { block } from '../../../utils';
6
4
  import { HtmlLayer } from '../HtmlLayer';
7
5
  const b = block('treemap');
8
6
  export const TreemapSeriesShape = (props) => {
9
7
  const { dispatcher, preparedData, seriesOptions, htmlLayout } = props;
10
- const hoveredDataRef = React.useRef(null);
11
8
  const ref = React.useRef(null);
12
9
  React.useEffect(() => {
13
10
  if (!ref.current) {
14
11
  return () => { };
15
12
  }
16
- const svgElement = select(ref.current);
17
- svgElement.selectAll('*').remove();
18
- const { labelData, leaves, series } = preparedData;
19
- const leaf = svgElement
20
- .selectAll('g')
21
- .data(leaves)
22
- .join('g')
23
- .attr('transform', (d) => `translate(${d.x0},${d.y0})`)
24
- .attr('cursor', series.cursor);
25
- const rectSelection = leaf
26
- .append('rect')
27
- .attr('id', (d) => d.id || d.name)
28
- .attr('fill', (d) => {
29
- var _a;
30
- if (d.data.color) {
31
- return d.data.color;
32
- }
33
- const levelOptions = (_a = series.levels) === null || _a === void 0 ? void 0 : _a.find((l) => l.index === d.depth);
34
- return (levelOptions === null || levelOptions === void 0 ? void 0 : levelOptions.color) || series.color;
35
- })
36
- .attr('width', (d) => d.x1 - d.x0)
37
- .attr('height', (d) => d.y1 - d.y0);
38
- const labelSelection = svgElement
39
- .selectAll('tspan')
40
- .data(labelData)
41
- .join('text')
42
- .html((d) => d.text)
43
- .attr('class', b('label'))
44
- .attr('x', (d) => d.x)
45
- .attr('y', (d) => d.y)
46
- .style('font-size', () => series.dataLabels.style.fontSize)
47
- .style('font-weight', () => { var _a; return ((_a = series.dataLabels.style) === null || _a === void 0 ? void 0 : _a.fontWeight) || null; })
48
- .style('fill', () => { var _a; return ((_a = series.dataLabels.style) === null || _a === void 0 ? void 0 : _a.fontColor) || null; });
49
- const eventName = `hover-shape.treemap`;
50
- const hoverOptions = get(seriesOptions, 'treemap.states.hover');
51
- const inactiveOptions = get(seriesOptions, 'treemap.states.inactive');
52
- function handleShapeHover(data) {
53
- var _a;
54
- hoveredDataRef.current = data;
55
- const hoverEnabled = hoverOptions === null || hoverOptions === void 0 ? void 0 : hoverOptions.enabled;
56
- const inactiveEnabled = inactiveOptions === null || inactiveOptions === void 0 ? void 0 : inactiveOptions.enabled;
57
- const hoveredData = (_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.data;
58
- rectSelection.datum((d, index, list) => {
59
- const currentRect = select(list[index]);
60
- const hovered = Boolean(hoverEnabled && hoveredData === d.data);
61
- const inactive = Boolean(inactiveEnabled && hoveredData && !hovered);
62
- currentRect
63
- .attr('fill', (currentD) => {
64
- var _a, _b;
65
- const levelOptions = (_a = series.levels) === null || _a === void 0 ? void 0 : _a.find((l) => l.index === currentD.depth);
66
- const initialColor = (levelOptions === null || levelOptions === void 0 ? void 0 : levelOptions.color) || d.data.color || series.color;
67
- if (hovered) {
68
- return (((_b = color(initialColor)) === null || _b === void 0 ? void 0 : _b.brighter(hoverOptions === null || hoverOptions === void 0 ? void 0 : hoverOptions.brightness).toString()) || initialColor);
69
- }
70
- return initialColor;
71
- })
72
- .attr('opacity', () => {
73
- if (inactive) {
74
- return (inactiveOptions === null || inactiveOptions === void 0 ? void 0 : inactiveOptions.opacity) || null;
75
- }
76
- return null;
77
- });
78
- return d;
79
- });
80
- labelSelection.datum((d, index, list) => {
81
- const currentLabel = select(list[index]);
82
- const hovered = Boolean(hoverEnabled && hoveredData === d.nodeData);
83
- const inactive = Boolean(inactiveEnabled && hoveredData && !hovered);
84
- currentLabel.attr('opacity', () => {
85
- if (inactive) {
86
- return (inactiveOptions === null || inactiveOptions === void 0 ? void 0 : inactiveOptions.opacity) || null;
87
- }
88
- return null;
89
- });
90
- return d;
91
- });
92
- }
93
- if (hoveredDataRef.current !== null) {
94
- handleShapeHover(hoveredDataRef.current);
95
- }
96
- dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher.on(eventName, handleShapeHover);
97
- return () => {
98
- dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher.on(eventName, null);
99
- };
13
+ return renderTreemap({ plot: ref.current }, preparedData, seriesOptions, dispatcher);
100
14
  }, [dispatcher, preparedData, seriesOptions]);
101
15
  return (React.createElement(React.Fragment, null,
102
16
  React.createElement("g", { ref: ref, className: b() }),
@@ -1,56 +1,6 @@
1
- import type { BaseType } from 'd3-selection';
2
- import type { ChartScale } from '../../core/scales/types';
3
- import type { BasicInactiveState } from '../../types';
4
- import type { PreparedXAxis, PreparedYAxis } from '../useAxis/types';
5
- import type { ZoomState } from '../useZoom/types';
6
- export declare function getXValue(args: {
7
- point: {
8
- x?: number | string | null;
9
- };
10
- points?: {
11
- x?: number | string | null;
12
- }[];
13
- xAxis: PreparedXAxis;
14
- xScale: ChartScale;
15
- }): number | null;
16
- export declare function getYValue(args: {
17
- point: {
18
- y?: number | string | null;
19
- };
20
- points?: {
21
- y?: number | string | null;
22
- }[];
23
- yAxis: PreparedYAxis;
24
- yScale: ChartScale;
25
- }): number | null;
26
- export declare function shapeKey(d: unknown): string | -1;
27
- export declare function setActiveState<T extends {
28
- active?: boolean;
29
- }>(args: {
30
- element: BaseType;
31
- datum: T;
32
- state: BasicInactiveState | undefined;
33
- active: boolean;
34
- }): T;
35
- export declare function getRectPath(args: {
36
- x: number;
37
- y: number;
38
- width: number;
39
- height: number;
40
- borderRadius?: number | number[];
41
- }): import("d3-path").Path;
42
- export declare function getRectBorderPath(args: {
43
- x: number;
44
- y: number;
45
- width: number;
46
- height: number;
47
- borderWidth: number;
48
- borderRadius?: number | number[];
49
- }): string;
50
- export declare function getClipPathIdByBounds(args: {
51
- clipPathId: string;
52
- bounds?: 'horizontal';
53
- }): string;
1
+ import type { ZoomState } from '../../core/zoom/types';
2
+ import type { PreparedYAxis } from '../useAxis/types';
3
+ export * from '../../core/shapes/utils';
54
4
  export declare function getSeriesClipPathId(args: {
55
5
  clipPathId: string;
56
6
  yAxis: PreparedYAxis[];
@@ -1,141 +1,4 @@
1
- import { path } from 'd3-path';
2
- import { select } from 'd3-selection';
3
- import get from 'lodash/get';
4
- import { getDataCategoryValue } from '../../core/utils';
5
- const ONE_POINT_DOMAIN_DATA_CAPACITY = 3;
6
- export function getXValue(args) {
7
- const { point, points, xAxis, xScale } = args;
8
- if (xAxis.type === 'category') {
9
- const xBandScale = xScale;
10
- const categories = get(xAxis, 'categories', []);
11
- const dataCategory = getDataCategoryValue({ axisDirection: 'x', categories, data: point });
12
- return (xBandScale(dataCategory) || 0) + xBandScale.step() / 2;
13
- }
14
- let xLinearScale = xScale;
15
- const [xMinDomain, xMaxDomain] = xLinearScale.domain();
16
- if (Number(xMinDomain) === Number(xMaxDomain) &&
17
- (points === null || points === void 0 ? void 0 : points.length) === ONE_POINT_DOMAIN_DATA_CAPACITY) {
18
- const x1 = Number(points[0].x);
19
- const xTarget = Number(points[1].x);
20
- const x3 = Number(points[2].x);
21
- if (!Number.isNaN(x1) && !Number.isNaN(xTarget) && !Number.isNaN(x3)) {
22
- const xMin = Math.min(x1, xTarget, x3);
23
- const xMax = Math.max(x1, xTarget, x3);
24
- xLinearScale = xLinearScale
25
- .copy()
26
- .domain([xMin + (xTarget - xMin) / 2, xMax - (xMax - xTarget) / 2]);
27
- }
28
- }
29
- return point.x === null ? null : xLinearScale(point.x);
30
- }
31
- export function getYValue(args) {
32
- const { point, points, yAxis, yScale } = args;
33
- if (yAxis.type === 'category') {
34
- const yBandScale = yScale;
35
- const categories = get(yAxis, 'categories', []);
36
- const dataCategory = getDataCategoryValue({ axisDirection: 'y', categories, data: point });
37
- return (yBandScale(dataCategory) || 0) + yBandScale.step() / 2;
38
- }
39
- let yLinearScale = yScale;
40
- const [yMinDomain, yMaxDomain] = yLinearScale.domain();
41
- if (Number(yMinDomain) === Number(yMaxDomain) &&
42
- (points === null || points === void 0 ? void 0 : points.length) === ONE_POINT_DOMAIN_DATA_CAPACITY) {
43
- const y1 = Number(points[0].y);
44
- const yTarget = Number(points[1].y);
45
- const y2 = Number(points[2].y);
46
- if (!Number.isNaN(y1) && !Number.isNaN(yTarget) && !Number.isNaN(y2)) {
47
- const yMin = Math.min(y1, yTarget, y2);
48
- const yMax = Math.max(y1, yTarget, y2);
49
- yLinearScale = yLinearScale
50
- .copy()
51
- .domain([yMin + (yTarget - yMin) / 2, yMax - (yMax - yTarget) / 2]);
52
- }
53
- }
54
- return point.y === null ? null : yLinearScale(point.y);
55
- }
56
- export function shapeKey(d) {
57
- return d.id || -1;
58
- }
59
- export function setActiveState(args) {
60
- const { element, datum, state, active } = args;
61
- const elementSelection = select(element);
62
- if (datum.active !== active) {
63
- datum.active = active;
64
- const opacity = datum.active ? null : state === null || state === void 0 ? void 0 : state.opacity;
65
- elementSelection.attr('opacity', opacity || null);
66
- }
67
- return datum;
68
- }
69
- export function getRectPath(args) {
70
- const { x, y, width, height, borderRadius = 0 } = args;
71
- const borderRadiuses = typeof borderRadius === 'number' ? new Array(4).fill(borderRadius) : borderRadius;
72
- const [borderRadiusTopLeft = 0, borderRadiusTopRight = 0, borderRadiusBottomRight = 0, borderRadiusBottomLeft = 0,] = borderRadiuses !== null && borderRadiuses !== void 0 ? borderRadiuses : [];
73
- const p = path();
74
- let startAngle = -Math.PI / 2;
75
- const angle = Math.PI / 2;
76
- p.moveTo(x + borderRadiusTopLeft, y);
77
- p.lineTo(x + width - borderRadiusTopRight, y);
78
- p.arc(x + width - borderRadiusTopRight, y + borderRadiusTopRight, borderRadiusTopRight, startAngle, startAngle + angle);
79
- startAngle += angle;
80
- p.lineTo(x + width, y + height - borderRadiusBottomRight);
81
- p.arc(x + width - borderRadiusBottomRight, y + height - borderRadiusBottomRight, borderRadiusBottomRight, startAngle, startAngle + angle);
82
- startAngle += angle;
83
- p.lineTo(x + borderRadiusBottomLeft, y + height);
84
- p.arc(x + borderRadiusBottomLeft, y + height - borderRadiusBottomLeft, borderRadiusBottomLeft, startAngle, startAngle + angle);
85
- startAngle += angle;
86
- p.lineTo(x, y + borderRadiusTopLeft);
87
- p.arc(x + borderRadiusTopLeft, y + borderRadiusTopLeft, borderRadiusTopLeft, startAngle, startAngle + angle);
88
- p.closePath();
89
- return p;
90
- }
91
- export function getRectBorderPath(args) {
92
- const { x, y, width, height, borderWidth, borderRadius = 0 } = args;
93
- if (!borderWidth) {
94
- return '';
95
- }
96
- const halfWidth = borderWidth / 2;
97
- const expandedWidth = width + borderWidth;
98
- const expandedHeight = height + borderWidth;
99
- const innerWidth = width - borderWidth;
100
- const innerHeight = height - borderWidth;
101
- const borderRadiuses = typeof borderRadius === 'number' ? new Array(4).fill(borderRadius) : borderRadius;
102
- const [borderRadiusTopLeft = 0, borderRadiusTopRight = 0, borderRadiusBottomRight = 0, borderRadiusBottomLeft = 0,] = borderRadiuses !== null && borderRadiuses !== void 0 ? borderRadiuses : [];
103
- const adjustOuterRadius = (radius) => (radius ? radius + halfWidth : 0);
104
- const outerBorderRadius = [
105
- adjustOuterRadius(borderRadiusTopLeft),
106
- adjustOuterRadius(borderRadiusTopRight),
107
- adjustOuterRadius(borderRadiusBottomRight),
108
- adjustOuterRadius(borderRadiusBottomLeft),
109
- ];
110
- const outerPath = getRectPath({
111
- x: x - halfWidth,
112
- y: y - halfWidth,
113
- width: expandedWidth,
114
- height: expandedHeight,
115
- borderRadius: outerBorderRadius,
116
- }).toString();
117
- if (innerWidth <= 0 || innerHeight <= 0) {
118
- return outerPath;
119
- }
120
- const innerBorderRadius = [
121
- Math.max(borderRadiusTopLeft - halfWidth, 0),
122
- Math.max(borderRadiusTopRight - halfWidth, 0),
123
- Math.max(borderRadiusBottomRight - halfWidth, 0),
124
- Math.max(borderRadiusBottomLeft - halfWidth, 0),
125
- ];
126
- const innerPath = getRectPath({
127
- x: x + halfWidth,
128
- y: y + halfWidth,
129
- width: innerWidth,
130
- height: innerHeight,
131
- borderRadius: innerBorderRadius,
132
- }).toString();
133
- return `${outerPath} ${innerPath}`;
134
- }
135
- export function getClipPathIdByBounds(args) {
136
- const { bounds, clipPathId } = args;
137
- return bounds ? `${clipPathId}-${bounds}` : clipPathId;
138
- }
1
+ export * from '../../core/shapes/utils';
139
2
  export function getSeriesClipPathId(args) {
140
3
  const { clipPathId, yAxis, zoomState } = args;
141
4
  const hasMinOrMax = yAxis.some((axis) => {
@@ -143,7 +6,7 @@ export function getSeriesClipPathId(args) {
143
6
  });
144
7
  const hasZoom = zoomState && Object.keys(zoomState).length > 0;
145
8
  if (!hasZoom && !hasMinOrMax) {
146
- return getClipPathIdByBounds({ clipPathId, bounds: 'horizontal' });
9
+ return `${clipPathId}-horizontal`;
147
10
  }
148
- return getClipPathIdByBounds({ clipPathId });
11
+ return clipPathId;
149
12
  }
@@ -1,9 +1,9 @@
1
1
  import React from 'react';
2
2
  import type { Dispatch } from 'd3-dispatch';
3
- import type { PreparedSeriesOptions } from '../../useSeries/types';
4
- import type { PreparedWaterfallData } from './types';
5
- export { prepareWaterfallData } from './prepare-data';
6
- export * from './types';
3
+ import type { PreparedSeriesOptions } from '../../../core/series/types';
4
+ import type { PreparedWaterfallData } from '../../../core/shapes/waterfall/types';
5
+ export { prepareWaterfallData } from '../../../core/shapes/waterfall/prepare-data';
6
+ export * from '../../../core/shapes/waterfall/types';
7
7
  type Args = {
8
8
  clipPathId: string;
9
9
  htmlLayout: HTMLElement | null;
@@ -1,20 +1,14 @@
1
1
  import React from 'react';
2
- import { color } from 'd3-color';
3
- import { select } from 'd3-selection';
4
- import { line as lineGenerator } from 'd3-shape';
5
- import get from 'lodash/get';
6
- import { DASH_STYLE } from '../../../core/constants';
7
- import { filterOverlappingLabels, getLineDashArray, getWaterfallPointColor } from '../../../core/utils';
2
+ import { renderWaterfall } from '../../../core/shapes/waterfall/renderer';
3
+ import { filterOverlappingLabels } from '../../../core/utils';
8
4
  import { block } from '../../../utils';
9
5
  import { HtmlLayer } from '../HtmlLayer';
10
- export { prepareWaterfallData } from './prepare-data';
11
- export * from './types';
6
+ export { prepareWaterfallData } from '../../../core/shapes/waterfall/prepare-data';
7
+ export * from '../../../core/shapes/waterfall/types';
12
8
  const b = block('waterfall');
13
9
  export const WaterfallSeriesShapes = (args) => {
14
10
  const { dispatcher, preparedData, seriesOptions, htmlLayout, clipPathId } = args;
15
- const hoveredDataRef = React.useRef(null);
16
11
  const ref = React.useRef(null);
17
- const connectorSelector = `.${b('connector')}`;
18
12
  const allowOverlapDataLabels = React.useMemo(() => {
19
13
  return preparedData.some((d) => d === null || d === void 0 ? void 0 : d.series.dataLabels.allowOverlap);
20
14
  }, [preparedData]);
@@ -22,115 +16,8 @@ export const WaterfallSeriesShapes = (args) => {
22
16
  if (!ref.current) {
23
17
  return () => { };
24
18
  }
25
- const svgElement = select(ref.current);
26
- const hoverOptions = get(seriesOptions, 'waterfall.states.hover');
27
- const inactiveOptions = get(seriesOptions, 'waterfall.states.inactive');
28
- svgElement.selectAll('*').remove();
29
- const rectSelection = svgElement
30
- .selectAll('allRects')
31
- .data(preparedData)
32
- .join('rect')
33
- .attr('class', b('segment'))
34
- .attr('x', (d) => d.x)
35
- .attr('y', (d) => d.y)
36
- .attr('height', (d) => d.height)
37
- .attr('width', (d) => d.width)
38
- .attr('fill', (d) => getWaterfallPointColor(d.data, d.series))
39
- .attr('opacity', (d) => d.opacity)
40
- .attr('cursor', (d) => d.series.cursor);
41
- let dataLabels = preparedData.map((d) => d.label).filter(Boolean);
42
- if (!allowOverlapDataLabels) {
43
- dataLabels = filterOverlappingLabels(dataLabels);
44
- }
45
- const labelSelection = svgElement
46
- .selectAll('text')
47
- .data(dataLabels)
48
- .join('text')
49
- .html((d) => d.text)
50
- .attr('class', b('label'))
51
- .attr('x', (d) => d.x)
52
- .attr('y', (d) => d.y)
53
- .attr('text-anchor', (d) => d.textAnchor)
54
- .style('font-size', (d) => d.style.fontSize)
55
- .style('font-weight', (d) => d.style.fontWeight || null)
56
- .style('fill', (d) => d.style.fontColor || null);
57
- // Add the connector line between bars
58
- svgElement
59
- .selectAll(connectorSelector)
60
- .data(preparedData)
61
- .join('path')
62
- .attr('class', b('connector'))
63
- .attr('d', (d, index) => {
64
- const line = lineGenerator();
65
- const prev = preparedData[index - 1];
66
- if (!prev) {
67
- return null;
68
- }
69
- const points = [];
70
- if (Number(prev.data.y) > 0) {
71
- points.push([prev.x, prev.y]);
72
- }
73
- else {
74
- points.push([prev.x, prev.y + prev.height]);
75
- }
76
- if (Number(d.data.y) > 0 && !d.data.total) {
77
- points.push([d.x + d.width, d.y + d.height]);
78
- }
79
- else {
80
- points.push([d.x + d.width, d.y]);
81
- }
82
- return line(points);
83
- })
84
- .attr('stroke-width', 1)
85
- .attr('stroke-dasharray', () => getLineDashArray(DASH_STYLE.Dash, 1));
86
- function handleShapeHover(data) {
87
- hoveredDataRef.current = data;
88
- const hoverEnabled = hoverOptions === null || hoverOptions === void 0 ? void 0 : hoverOptions.enabled;
89
- const inactiveEnabled = inactiveOptions === null || inactiveOptions === void 0 ? void 0 : inactiveOptions.enabled;
90
- if (!data) {
91
- if (hoverEnabled) {
92
- rectSelection.attr('fill', (d) => getWaterfallPointColor(d.data, d.series));
93
- }
94
- if (inactiveEnabled) {
95
- rectSelection.attr('opacity', null);
96
- labelSelection.attr('opacity', null);
97
- }
98
- return;
99
- }
100
- if (hoverEnabled) {
101
- const hoveredValues = data.map((d) => d.data.x);
102
- rectSelection.attr('fill', (d) => {
103
- var _a;
104
- const fillColor = getWaterfallPointColor(d.data, d.series);
105
- if (hoveredValues.includes(d.data.x)) {
106
- const brightness = hoverOptions === null || hoverOptions === void 0 ? void 0 : hoverOptions.brightness;
107
- return ((_a = color(fillColor)) === null || _a === void 0 ? void 0 : _a.brighter(brightness).toString()) || fillColor;
108
- }
109
- return fillColor;
110
- });
111
- }
112
- if (inactiveEnabled) {
113
- const hoveredSeries = data.map((d) => d.series.id);
114
- rectSelection.attr('opacity', (d) => {
115
- return hoveredSeries.includes(d.series.id)
116
- ? null
117
- : (inactiveOptions === null || inactiveOptions === void 0 ? void 0 : inactiveOptions.opacity) || null;
118
- });
119
- labelSelection.attr('opacity', (d) => {
120
- return hoveredSeries.includes(d.series.id)
121
- ? null
122
- : (inactiveOptions === null || inactiveOptions === void 0 ? void 0 : inactiveOptions.opacity) || null;
123
- });
124
- }
125
- }
126
- if (hoveredDataRef.current !== null) {
127
- handleShapeHover(hoveredDataRef.current);
128
- }
129
- dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher.on('hover-shape.waterfall', handleShapeHover);
130
- return () => {
131
- dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher.on('hover-shape.waterfall', null);
132
- };
133
- }, [allowOverlapDataLabels, connectorSelector, dispatcher, preparedData, seriesOptions]);
19
+ return renderWaterfall({ plot: ref.current }, preparedData, seriesOptions, allowOverlapDataLabels, dispatcher);
20
+ }, [allowOverlapDataLabels, dispatcher, preparedData, seriesOptions]);
134
21
  const htmlLayerData = React.useMemo(() => {
135
22
  const items = preparedData.map((d) => d === null || d === void 0 ? void 0 : d.htmlElements).flat();
136
23
  if (allowOverlapDataLabels) {
@@ -1,9 +1,9 @@
1
1
  import React from 'react';
2
2
  import type { Dispatch } from 'd3-dispatch';
3
- import type { PreparedSeriesOptions } from '../../useSeries/types';
4
- export { prepareXRangeData } from './prepare-data';
5
- export type { PreparedXRangeData } from './types';
6
- import type { PreparedXRangeData } from './types';
3
+ import type { PreparedSeriesOptions } from '../../../core/series/types';
4
+ import type { PreparedXRangeData } from '../../../core/shapes/x-range/types';
5
+ export { prepareXRangeData } from '../../../core/shapes/x-range/prepare-data';
6
+ export type { PreparedXRangeData } from '../../../core/shapes/x-range/types';
7
7
  type Args = {
8
8
  clipPathId: string;
9
9
  htmlLayout: HTMLElement | null;