@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,112 +1,17 @@
1
1
  import React from 'react';
2
- import { color } from 'd3-color';
3
- import { select } from 'd3-selection';
4
- import get from 'lodash/get';
5
- import { getLineDashArray } from '../../../core/utils';
2
+ import { renderXRange } from '../../../core/shapes/x-range/renderer';
6
3
  import { block } from '../../../utils';
7
4
  import { HtmlLayer } from '../HtmlLayer';
8
- import { getRectPath } from '../utils';
9
- export { prepareXRangeData } from './prepare-data';
5
+ export { prepareXRangeData } from '../../../core/shapes/x-range/prepare-data';
10
6
  const b = block('x-range');
11
7
  export function XRangeSeriesShapes(args) {
12
8
  const { dispatcher, preparedData, seriesOptions, htmlLayout, clipPathId } = args;
13
- const hoveredDataRef = React.useRef(null);
14
9
  const ref = React.useRef(null);
15
10
  React.useEffect(() => {
16
- var _a;
17
11
  if (!ref.current) {
18
12
  return () => { };
19
13
  }
20
- const svgElement = select(ref.current);
21
- svgElement.selectAll('*').remove();
22
- const segmentSelection = svgElement
23
- .selectAll(`path.${b('segment')}`)
24
- .data(preparedData)
25
- .join('path')
26
- .attr('d', (d) => {
27
- const borderRadius = Math.min(d.height / 2, d.width / 2, d.series.borderRadius);
28
- return getRectPath({
29
- x: d.x,
30
- y: d.y,
31
- width: d.width,
32
- height: d.height,
33
- borderRadius,
34
- }).toString();
35
- })
36
- .attr('class', b('segment'))
37
- .attr('fill', (d) => d.color)
38
- .attr('opacity', (d) => { var _a; return (_a = d.data.opacity) !== null && _a !== void 0 ? _a : d.series.opacity; })
39
- .attr('cursor', (d) => d.series.cursor);
40
- svgElement
41
- .selectAll(`path.${b('segment-border')}`)
42
- .data(preparedData.filter((d) => d.series.borderWidth > 0))
43
- .join('path')
44
- .attr('d', (d) => {
45
- const borderRadius = Math.min(d.height / 2, d.width / 2, d.series.borderRadius);
46
- return getRectPath({
47
- x: d.x,
48
- y: d.y,
49
- width: d.width,
50
- height: d.height,
51
- borderRadius,
52
- }).toString();
53
- })
54
- .attr('class', b('segment-border'))
55
- .attr('fill', 'none')
56
- .attr('stroke', (d) => d.series.borderColor)
57
- .attr('stroke-width', (d) => d.series.borderWidth)
58
- .attr('stroke-dasharray', (d) => getLineDashArray(d.series.borderDashStyle, d.series.borderWidth))
59
- .attr('opacity', (d) => { var _a; return (_a = d.data.opacity) !== null && _a !== void 0 ? _a : d.series.opacity; })
60
- .attr('pointer-events', 'none');
61
- const svgLabels = preparedData.flatMap((d) => d.svgLabels);
62
- svgElement
63
- .selectAll(`text.${b('label')}`)
64
- .data(svgLabels)
65
- .join('text')
66
- .attr('class', b('label'))
67
- .attr('x', (d) => d.x)
68
- .attr('y', (d) => d.y)
69
- .attr('text-anchor', (d) => d.textAnchor)
70
- .attr('dominant-baseline', 'central')
71
- .attr('pointer-events', 'none')
72
- .style('font-size', (d) => d.style.fontSize)
73
- .style('font-weight', (d) => d.style.fontWeight || null)
74
- .style('fill', (d) => d.style.fontColor || null)
75
- .html((d) => d.text);
76
- const hoverOptions = get(seriesOptions, 'x-range.states.hover');
77
- const inactiveOptions = get(seriesOptions, 'x-range.states.inactive');
78
- function handleShapeHover(data) {
79
- hoveredDataRef.current = data;
80
- if (hoverOptions === null || hoverOptions === void 0 ? void 0 : hoverOptions.enabled) {
81
- const hoveredSet = new Set(data === null || data === void 0 ? void 0 : data.map((d) => d.data));
82
- segmentSelection.attr('fill', (d) => {
83
- var _a;
84
- const fillColor = d.color;
85
- if (hoveredSet.has(d.data)) {
86
- return (((_a = color(fillColor)) === null || _a === void 0 ? void 0 : _a.brighter(hoverOptions.brightness).toString()) ||
87
- fillColor);
88
- }
89
- return fillColor;
90
- });
91
- }
92
- if (inactiveOptions === null || inactiveOptions === void 0 ? void 0 : inactiveOptions.enabled) {
93
- const hoveredSeries = data === null || data === void 0 ? void 0 : data.map((d) => d.series.id);
94
- segmentSelection.attr('opacity', (d) => {
95
- var _a, _b;
96
- if ((hoveredSeries === null || hoveredSeries === void 0 ? void 0 : hoveredSeries.length) && !hoveredSeries.includes(d.series.id)) {
97
- return inactiveOptions.opacity || null;
98
- }
99
- return (_b = (_a = d.data.opacity) !== null && _a !== void 0 ? _a : d.series.opacity) !== null && _b !== void 0 ? _b : null;
100
- });
101
- }
102
- }
103
- if (hoveredDataRef.current !== null) {
104
- handleShapeHover((_a = hoveredDataRef.current) !== null && _a !== void 0 ? _a : undefined);
105
- }
106
- dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher.on('hover-shape.x-range', handleShapeHover);
107
- return () => {
108
- dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher.on('hover-shape.x-range', null);
109
- };
14
+ return renderXRange({ plot: ref.current }, preparedData, seriesOptions, dispatcher);
110
15
  }, [dispatcher, preparedData, seriesOptions]);
111
16
  const htmlLayerData = React.useMemo(() => ({ htmlElements: preparedData.flatMap((d) => d.htmlLabels) }), [preparedData]);
112
17
  return (React.createElement(React.Fragment, null,
@@ -1,8 +1,8 @@
1
1
  import type { PreparedSplit } from '../../core/layout/split-types';
2
2
  import type { ChartScale } from '../../core/scales/types';
3
+ import type { ZoomState } from '../../core/zoom/types';
3
4
  import type { PreparedZoom } from '../types';
4
5
  import type { PreparedXAxis, PreparedYAxis } from '../useAxis/types';
5
- import type { ZoomState } from './types';
6
6
  interface UseZoomProps {
7
7
  node: SVGGElement | null;
8
8
  onUpdate: (zoomState: Partial<ZoomState>) => void;
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { select } from 'd3-selection';
3
+ import { selectionToZoomBounds } from '../../core/zoom/utils';
3
4
  import { useBrush } from '../useBrush';
4
- import { selectionToZoomBounds } from './utils';
5
5
  export function useZoom(props) {
6
6
  const { node, onUpdate, plotContainerHeight, plotContainerWidth, preparedSplit, preparedZoom, rangeSliderDomain, xAxis, xScale, yAxis, yScale, } = props;
7
7
  const isBrushDisabled = Boolean(!xAxis || !yAxis || !xScale || !yScale);
@@ -1,5 +1,6 @@
1
1
  export { CustomShapeRenderer } from './utils';
2
2
  export { getFormattedValue } from './core/utils';
3
3
  export { getDefaultTooltipHeaderFormat } from './core/utils/tooltip';
4
+ export { FORMAT_UNITS_BITS, FORMAT_UNITS_BYTES, FORMAT_UNITS_NUMBERS, } from './libs/format-number/presets';
4
5
  export * from './components';
5
6
  export * from './types';
package/dist/esm/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export { CustomShapeRenderer } from './utils';
2
2
  export { getFormattedValue } from './core/utils';
3
3
  export { getDefaultTooltipHeaderFormat } from './core/utils/tooltip';
4
+ export { FORMAT_UNITS_BITS, FORMAT_UNITS_BYTES, FORMAT_UNITS_NUMBERS, } from './libs/format-number/presets';
4
5
  export * from './components';
5
6
  export * from './types';
@@ -11,26 +11,30 @@ function getUnitRate(value, exponent, unitsI18nKeys) {
11
11
  }
12
12
  return resultUnitRate - 1;
13
13
  }
14
+ const formatScaledNumber = (value, options) => {
15
+ const { precision, showRankDelimiter = true, lang } = options;
16
+ let result = value;
17
+ if (typeof precision === 'number') {
18
+ result = Number(result.toFixed(precision));
19
+ }
20
+ else if (precision === 'auto' && result % 1 !== 0) {
21
+ result = Number(result.toFixed(Math.abs(result) > 1 ? 2 : 4));
22
+ }
23
+ return new Intl.NumberFormat(lang !== null && lang !== void 0 ? lang : i18nInstance.lang, {
24
+ minimumFractionDigits: typeof precision === 'number' ? precision : 0,
25
+ maximumFractionDigits: 20,
26
+ useGrouping: showRankDelimiter,
27
+ }).format(result);
28
+ };
14
29
  const unitFormatter = ({ exponent, unitsI18nKeys, unitDelimiterI18nKey, }) => {
15
30
  return function formatUnit(value, options = {}) {
16
- const { precision, unitRate, showRankDelimiter = true, lang } = options;
31
+ const { unitRate, lang } = options;
17
32
  const i18nLang = i18nInstance.lang;
18
33
  if (lang) {
19
34
  i18nInstance.setLang(lang);
20
35
  }
21
36
  const resultUnitRate = typeof unitRate === 'number' ? unitRate : getUnitRate(value, exponent, unitsI18nKeys);
22
- let result = value / Math.pow(exponent, resultUnitRate);
23
- if (typeof precision === 'number') {
24
- result = Number(result.toFixed(precision));
25
- }
26
- else if (precision === 'auto' && result % 1 !== 0) {
27
- result = Number(result.toFixed(Math.abs(result) > 1 ? 2 : 4));
28
- }
29
- result = new Intl.NumberFormat(lang !== null && lang !== void 0 ? lang : i18nLang, {
30
- minimumFractionDigits: typeof precision === 'number' ? precision : 0,
31
- maximumFractionDigits: 20,
32
- useGrouping: showRankDelimiter,
33
- }).format(result);
37
+ const result = formatScaledNumber(value / Math.pow(exponent, resultUnitRate), options);
34
38
  const unit = i18n(unitsI18nKeys[resultUnitRate]);
35
39
  const delimiter = i18n(unitDelimiterI18nKey);
36
40
  i18nInstance.setLang(i18nLang);
@@ -59,6 +63,65 @@ const baseFormatNumber = unitFormatter({
59
63
  unitDelimiterI18nKey: 'value_number-delimiter',
60
64
  unitsI18nKeys: BASE_NUMBER_FORMAT_UNIT_KEYS,
61
65
  });
66
+ const resolvePostfix = (postfix, lang) => {
67
+ var _a, _b;
68
+ if (typeof postfix === 'string') {
69
+ return postfix;
70
+ }
71
+ return (_b = (_a = postfix[lang]) !== null && _a !== void 0 ? _a : postfix.en) !== null && _b !== void 0 ? _b : '';
72
+ };
73
+ const FALLBACK_UNIT_ENTRY = { factor: 1, postfix: '' };
74
+ const normalizedUnitsCache = new WeakMap();
75
+ const normalizeUnits = (units) => {
76
+ const cached = normalizedUnitsCache.get(units);
77
+ if (cached) {
78
+ return cached;
79
+ }
80
+ const { scale } = units;
81
+ const rawEntries = Array.isArray(scale)
82
+ ? scale.map((e) => ({ factor: e.factor, postfix: e.postfix }))
83
+ : scale.postfixes.map((postfix, i) => ({ factor: Math.pow(scale.base, i), postfix }));
84
+ const valid = rawEntries.filter((e) => Number.isFinite(e.factor) && e.factor > 0);
85
+ valid.sort((a, b) => a.factor - b.factor);
86
+ const deduped = [];
87
+ for (const e of valid) {
88
+ if (deduped.length === 0 || deduped[deduped.length - 1].factor !== e.factor) {
89
+ deduped.push(e);
90
+ }
91
+ }
92
+ const result = deduped.length > 0 ? deduped : [FALLBACK_UNIT_ENTRY];
93
+ normalizedUnitsCache.set(units, result);
94
+ return result;
95
+ };
96
+ const pickUnitEntry = (value, scale) => {
97
+ const av = Math.abs(value);
98
+ let chosen = scale[0];
99
+ for (const e of scale) {
100
+ if (av / e.factor >= 1) {
101
+ chosen = e;
102
+ }
103
+ else {
104
+ break;
105
+ }
106
+ }
107
+ return chosen;
108
+ };
109
+ const customUnitFormatter = (value, units, options) => {
110
+ const { lang } = options;
111
+ const i18nLang = i18nInstance.lang;
112
+ if (lang) {
113
+ i18nInstance.setLang(lang);
114
+ }
115
+ const normalizedScale = normalizeUnits(units);
116
+ const entry = pickUnitEntry(value, normalizedScale);
117
+ const result = formatScaledNumber(value / entry.factor, options);
118
+ const effectiveLang = lang !== null && lang !== void 0 ? lang : i18nLang;
119
+ const resolvedPostfix = resolvePostfix(entry.postfix, effectiveLang);
120
+ const resolvedDelimiter = typeof units.delimiter === 'string' ? units.delimiter : ' ';
121
+ const delimiter = resolvedPostfix ? resolvedDelimiter : '';
122
+ i18nInstance.setLang(i18nLang);
123
+ return `${result}${delimiter}${resolvedPostfix}`;
124
+ };
62
125
  const NUMBER_UNIT_RATE_BY_UNIT = {
63
126
  default: 0,
64
127
  auto: undefined,
@@ -77,7 +140,7 @@ export const formatNumber = (value, options = {}) => {
77
140
  if (Number.isNaN(value) || Number.isNaN(Number(value))) {
78
141
  return new Intl.NumberFormat('en').format(Number(value));
79
142
  }
80
- const { format = 'number', multiplier = 1, prefix = '', postfix = '', unit, labelMode } = options;
143
+ const { format = 'number', multiplier = 1, prefix = '', postfix = '', unit, units, labelMode, } = options;
81
144
  let changedMultiplier = multiplier;
82
145
  let prePostfix = '';
83
146
  if (format === 'percent') {
@@ -87,6 +150,11 @@ export const formatNumber = (value, options = {}) => {
87
150
  if (labelMode === 'percent') {
88
151
  prePostfix = '%';
89
152
  }
153
+ if (units) {
154
+ const unitScale = 'scale' in units ? units : { scale: [units] };
155
+ const formattedValue = customUnitFormatter(Number(value) * changedMultiplier, unitScale, options);
156
+ return `${prefix}${formattedValue}${prePostfix}${postfix}`;
157
+ }
90
158
  const formattedValue = baseFormatNumber(Number(value) * changedMultiplier, Object.assign(Object.assign({}, options), { unitRate: NUMBER_UNIT_RATE_BY_UNIT[unit !== null && unit !== void 0 ? unit : 'default'] }));
91
159
  return `${prefix}${formattedValue}${prePostfix}${postfix}`;
92
160
  };
@@ -0,0 +1,40 @@
1
+ import type { FormatUnitScale } from './types';
2
+ /**
3
+ * Byte scale with binary base (`1024`) and localized postfixes.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * tooltip: {
8
+ * valueFormat: {type: 'number', units: FORMAT_UNITS_BYTES, precision: 1},
9
+ * }
10
+ * ```
11
+ */
12
+ export declare const FORMAT_UNITS_BYTES: FormatUnitScale;
13
+ /**
14
+ * Short number scale with decimal base (`1000`). Renders large numbers
15
+ * compactly as `K/M/B/T`. Postfixes are plain Latin letters and stay the
16
+ * same regardless of language. The first entry has an empty postfix, so
17
+ * values below `1000` render as plain numbers without a delimiter.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * tooltip: {
22
+ * valueFormat: {type: 'number', units: FORMAT_UNITS_NUMBERS, precision: 1},
23
+ * }
24
+ * // 300 → "300"
25
+ * // 1_500 → "1.5 K"
26
+ * // 1_500_000 → "1.5 M"
27
+ * ```
28
+ */
29
+ export declare const FORMAT_UNITS_NUMBERS: FormatUnitScale;
30
+ /**
31
+ * Bit scale with decimal base (`1000`) and localized postfixes.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * tooltip: {
36
+ * valueFormat: {type: 'number', units: FORMAT_UNITS_BITS, precision: 1},
37
+ * }
38
+ * ```
39
+ */
40
+ export declare const FORMAT_UNITS_BITS: FormatUnitScale;
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Byte scale with binary base (`1024`) and localized postfixes.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * tooltip: {
7
+ * valueFormat: {type: 'number', units: FORMAT_UNITS_BYTES, precision: 1},
8
+ * }
9
+ * ```
10
+ */
11
+ export const FORMAT_UNITS_BYTES = {
12
+ scale: {
13
+ base: 1024,
14
+ postfixes: [
15
+ { en: 'B', ru: 'Б' },
16
+ { en: 'KB', ru: 'КБ' },
17
+ { en: 'MB', ru: 'МБ' },
18
+ { en: 'GB', ru: 'ГБ' },
19
+ { en: 'TB', ru: 'ТБ' },
20
+ ],
21
+ },
22
+ };
23
+ /**
24
+ * Short number scale with decimal base (`1000`). Renders large numbers
25
+ * compactly as `K/M/B/T`. Postfixes are plain Latin letters and stay the
26
+ * same regardless of language. The first entry has an empty postfix, so
27
+ * values below `1000` render as plain numbers without a delimiter.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * tooltip: {
32
+ * valueFormat: {type: 'number', units: FORMAT_UNITS_NUMBERS, precision: 1},
33
+ * }
34
+ * // 300 → "300"
35
+ * // 1_500 → "1.5 K"
36
+ * // 1_500_000 → "1.5 M"
37
+ * ```
38
+ */
39
+ export const FORMAT_UNITS_NUMBERS = {
40
+ scale: {
41
+ base: 1000,
42
+ postfixes: ['', 'K', 'M', 'B', 'T'],
43
+ },
44
+ };
45
+ /**
46
+ * Bit scale with decimal base (`1000`) and localized postfixes.
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * tooltip: {
51
+ * valueFormat: {type: 'number', units: FORMAT_UNITS_BITS, precision: 1},
52
+ * }
53
+ * ```
54
+ */
55
+ export const FORMAT_UNITS_BITS = {
56
+ scale: {
57
+ base: 1000,
58
+ postfixes: [
59
+ { en: 'bit', ru: 'бит' },
60
+ { en: 'Kbit', ru: 'Кбит' },
61
+ { en: 'Mbit', ru: 'Мбит' },
62
+ { en: 'Gbit', ru: 'Гбит' },
63
+ { en: 'Tbit', ru: 'Тбит' },
64
+ ],
65
+ },
66
+ };
@@ -1,13 +1,92 @@
1
- export type FormatOptions = {
1
+ export interface FormatOptions {
2
+ /**
3
+ * Number of decimal places to display.
4
+ * Use `'auto'` to determine precision automatically based on the value magnitude.
5
+ */
2
6
  precision?: number | 'auto';
7
+ /** When `true`, inserts a thousands separator (e.g. `1 500 000`). */
3
8
  showRankDelimiter?: boolean;
9
+ /**
10
+ * BCP 47 language tag used for locale-aware formatting (e.g. `'en'`, `'ru'`).
11
+ * Defaults to the application locale when omitted.
12
+ */
4
13
  lang?: string;
14
+ /** Internal rendering hint for axis label layout. Not intended for public use. */
5
15
  labelMode?: string;
16
+ }
17
+ /**
18
+ * Plain string or a per-language dictionary of strings.
19
+ * When a dictionary is used, the lookup chain is:
20
+ * current `lang` → `en` → empty string.
21
+ */
22
+ export type FormatI18nString = string | Partial<Record<string, string>>;
23
+ /** Single entry of a custom unit scale. */
24
+ export type FormatUnitScaleEntry = {
25
+ /** Positive multiplier applied to the value. The entry wins when `|value| / factor >= 1`. */
26
+ factor: number;
27
+ /**
28
+ * String appended after the scaled value (e.g. `'KB'`).
29
+ * Use an empty string to suppress the suffix and the delimiter.
30
+ * Pass a `{lang: string}` dictionary to localize the postfix — resolution falls back to `en`, then to empty.
31
+ */
32
+ postfix: FormatI18nString;
6
33
  };
7
- export type FormatNumberOptions = FormatOptions & {
34
+ /**
35
+ * Custom unit scale for numeric formatting.
36
+ *
37
+ * `scale` describes the unit table in one of two forms:
38
+ * - `{base, postfixes}` — geometric progression: `postfixes[i]` is bound to `factor = base^i` (e.g. `{base: 1024, postfixes: ['B','KB','MB']}`).
39
+ * - `FormatUnitScaleEntry[]` — arbitrary factors; required for non-linear scales (e.g. `[{factor:1,postfix:'s'},{factor:60,postfix:'min'},{factor:3600,postfix:'h'}]`).
40
+ *
41
+ * `delimiter` is the shared string placed between the scaled value and the
42
+ * postfix. Defaults to a locale-aware space; pass `''` to suppress it.
43
+ *
44
+ * The normalized scale is cached by object identity, so for best performance
45
+ * reuse the same `units` object across `formatNumber` calls instead of
46
+ * creating a new inline literal on every render.
47
+ */
48
+ export type FormatUnitScale = {
49
+ scale: {
50
+ base: number;
51
+ postfixes: FormatI18nString[];
52
+ } | FormatUnitScaleEntry[];
53
+ delimiter?: string;
54
+ };
55
+ export interface FormatNumberOptions extends FormatOptions {
56
+ /**
57
+ * Display mode for the numeric value.
58
+ * - `'number'` — plain number (default).
59
+ * - `'percent'` — value is multiplied by 100 and rendered with a `%` suffix.
60
+ *
61
+ * Combining `'percent'` with `units` is not meaningful and should be avoided.
62
+ */
8
63
  format?: 'number' | 'percent';
64
+ /** Factor applied to the value before formatting. For example, `multiplier: 1000` converts seconds to milliseconds. */
9
65
  multiplier?: number;
66
+ /** String prepended to the formatted value (e.g. `'$'`). */
10
67
  prefix?: string;
68
+ /** String appended to the formatted value (e.g. `' USD'`). */
11
69
  postfix?: string;
70
+ /**
71
+ * Compact unit suffix applied to large numbers.
72
+ * - `'auto'` — picks the most appropriate unit automatically (`k`, `m`, `b`, `t`).
73
+ * - `'k'` — thousands (÷ 1 000).
74
+ * - `'m'` — millions (÷ 1 000 000).
75
+ * - `'b'` — billions (÷ 1 000 000 000).
76
+ * - `'t'` — trillions (÷ 1 000 000 000 000).
77
+ * - `null` — no unit suffix.
78
+ *
79
+ * @deprecated Use `units` for custom scales. This option is fully ignored when `units` is set.
80
+ */
12
81
  unit?: 'auto' | 'k' | 'm' | 'b' | 't' | null;
13
- };
82
+ /**
83
+ * Custom unit scale, or a single `FormatUnitScaleEntry` as sugar for
84
+ * locking every value to one unit (equivalent to the legacy `unit: 'k'`).
85
+ * When set, fully overrides `unit`.
86
+ *
87
+ * Unit selection is always automatic: the entry with the largest `factor`
88
+ * such that `|value| / factor >= 1`, clamped to the smallest entry for
89
+ * very small values.
90
+ */
91
+ units?: FormatUnitScale | FormatUnitScaleEntry;
92
+ }
@@ -10,6 +10,13 @@ if (typeof document !== 'undefined') {
10
10
  });
11
11
  }
12
12
  }
13
+ if (typeof ResizeObserver === 'undefined') {
14
+ global.ResizeObserver = class ResizeObserver {
15
+ observe() { }
16
+ unobserve() { }
17
+ disconnect() { }
18
+ };
19
+ }
13
20
  if (typeof HTMLCanvasElement !== 'undefined') {
14
21
  // jsdom does not implement HTMLCanvasElement.prototype.getContext (used for text measurement)
15
22
  HTMLCanvasElement.prototype.getContext = (() => ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/charts",
3
- "version": "1.46.0",
3
+ "version": "1.47.0",
4
4
  "description": "A flexible JavaScript library for data visualization and chart rendering using React",
5
5
  "license": "MIT",
6
6
  "main": "dist/cjs/index.js",
@@ -54,7 +54,8 @@
54
54
  "prepublishOnly": "npm run build",
55
55
  "docs:deps": "cd ./docs && npm ci",
56
56
  "docs:dev": "cd ./docs && npm run docs:dev",
57
- "docs:build": "cd ./docs && npm run docs:build",
57
+ "docs:build-examples": "vite build --config docs/examples/vite.config.ts",
58
+ "docs:build": "npm run docs:build-examples && cd ./docs && npm run docs:build",
58
59
  "playwright:install": "playwright install chromium webkit --with-deps",
59
60
  "playwright": "playwright test --config=playwright/playwright.config.ts",
60
61
  "playwright:visual": "playwright test --project=chromium --project=webkit --config=playwright/playwright.config.ts",
@@ -113,6 +114,7 @@
113
114
  "@types/lodash": "^4.17.12",
114
115
  "@types/react": "^18.3.2",
115
116
  "@types/react-dom": "^18.3.0",
117
+ "@vitejs/plugin-react": "^4.7.0",
116
118
  "eslint": "^9.39.4",
117
119
  "eslint-plugin-jsx-a11y": "^6.10.2",
118
120
  "eslint-plugin-storybook": "^10.2.16",
@@ -127,6 +129,7 @@
127
129
  "jest": "^29.7.0",
128
130
  "jest-environment-jsdom": "^29.7.0",
129
131
  "jest-transform-css": "^6.0.1",
132
+ "monaco-editor": "^0.55.1",
130
133
  "nano-staged": "^0.8.0",
131
134
  "npm-run-all": "^4.1.5",
132
135
  "prettier": "^3.8.1",
@@ -1,12 +0,0 @@
1
- import type { PreparedLegend, PreparedSeries } from '../../core/series/types';
2
- import type { ChartData } from '../../types';
3
- export declare const getVisibleSeries: ({ preparedSeries, activeLegendItems, }: {
4
- preparedSeries: PreparedSeries[];
5
- activeLegendItems: string[];
6
- }) => PreparedSeries[];
7
- export declare const getPreparedSeries: ({ seriesData, seriesOptions, colors, preparedLegend, }: {
8
- seriesData: ChartData["series"]["data"];
9
- seriesOptions: ChartData["series"]["options"];
10
- colors: string[];
11
- preparedLegend?: PreparedLegend | null;
12
- }) => Promise<PreparedSeries[]>;
@@ -1,40 +0,0 @@
1
- import { group } from 'd3-array';
2
- import { scaleOrdinal } from 'd3-scale';
3
- import { prepareSeries } from '../../core/series/prepareSeries';
4
- import { getSeriesNames } from '../../core/utils';
5
- export const getVisibleSeries = ({ preparedSeries, activeLegendItems, }) => {
6
- return preparedSeries.map((singleSeries) => {
7
- if (singleSeries.legend.enabled) {
8
- return Object.assign(Object.assign({}, singleSeries), { visible: activeLegendItems.includes(singleSeries.legend.groupId) });
9
- }
10
- return singleSeries;
11
- });
12
- };
13
- export const getPreparedSeries = async ({ seriesData, seriesOptions, colors, preparedLegend, }) => {
14
- const seriesNames = getSeriesNames(seriesData);
15
- const colorScale = scaleOrdinal(seriesNames, colors);
16
- const groupedSeries = group(seriesData, (item, index) => {
17
- if (item.type === 'line') {
18
- return `${item.type}_${index}`;
19
- }
20
- return item.type;
21
- });
22
- const acc = [];
23
- if (!preparedLegend) {
24
- return acc;
25
- }
26
- const list = Array.from(groupedSeries);
27
- for (let i = 0; i < list.length; i++) {
28
- const [_groupId, seriesList] = list[i];
29
- const seriesType = seriesList[0].type;
30
- acc.push(...(await prepareSeries({
31
- type: seriesType,
32
- series: seriesList,
33
- seriesOptions,
34
- legend: preparedLegend,
35
- colorScale,
36
- colors,
37
- })));
38
- }
39
- return acc;
40
- };
@@ -1 +0,0 @@
1
- export * from '../../core/series/types';
@@ -1 +0,0 @@
1
- export * from '../../core/series/types';
@@ -1 +0,0 @@
1
- export * from '../../core/series/utils';
@@ -1 +0,0 @@
1
- export * from '../../core/series/utils';
@@ -1,15 +0,0 @@
1
- import type { BaseType, Selection } from 'd3-selection';
2
- import { SymbolType } from '../../core/constants';
3
- import type { MarkerData as AreaMarkerData } from './area/types';
4
- import type { MarkerData as LineMarkerData } from './line/types';
5
- import type { RadarMarkerData } from './radar/types';
6
- import type { MarkerData as ScatterMarkerData } from './scatter/types';
7
- type MarkerData = LineMarkerData | AreaMarkerData | ScatterMarkerData | RadarMarkerData;
8
- export declare function renderMarker<T extends MarkerData>(selection: Selection<BaseType, T, BaseType, unknown>): Selection<BaseType, T, BaseType, unknown>;
9
- export declare function getMarkerVisibility(d: MarkerData): "" | "hidden";
10
- export declare function getMarkerHaloVisibility(d: MarkerData): "" | "hidden";
11
- export declare function setMarker<T extends BaseType, D extends MarkerData>(selection: Selection<T, D, BaseType | null, unknown>, state: 'normal' | 'hover'): void;
12
- export declare function getMarkerSymbol(type: `${SymbolType}` | undefined, radius: number): string | null;
13
- export declare function selectMarkerHalo<T>(parentSelection: Selection<BaseType, T, null, undefined>): Selection<BaseType, T, null, undefined>;
14
- export declare function selectMarkerSymbol<T>(parentSelection: Selection<BaseType, T, null, undefined>): Selection<BaseType, T, null, undefined>;
15
- export {};
@@ -1 +0,0 @@
1
- export * from './bar-y';
@@ -1 +0,0 @@
1
- export * from './bar-y';
@@ -1,12 +0,0 @@
1
- import type { PreparedLegend, PreparedSeries } from '../../core/series/types';
2
- import type { ChartData } from '../../types';
3
- export declare const getVisibleSeries: ({ preparedSeries, activeLegendItems, }: {
4
- preparedSeries: PreparedSeries[];
5
- activeLegendItems: string[];
6
- }) => PreparedSeries[];
7
- export declare const getPreparedSeries: ({ seriesData, seriesOptions, colors, preparedLegend, }: {
8
- seriesData: ChartData["series"]["data"];
9
- seriesOptions: ChartData["series"]["options"];
10
- colors: string[];
11
- preparedLegend?: PreparedLegend | null;
12
- }) => Promise<PreparedSeries[]>;