@gravity-ui/charts 0.1.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 (521) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +15 -0
  3. package/dist/cjs/components/Axis/AxisX.d.ts +20 -0
  4. package/dist/cjs/components/Axis/AxisX.js +108 -0
  5. package/dist/cjs/components/Axis/AxisY.d.ts +12 -0
  6. package/dist/cjs/components/Axis/AxisY.js +199 -0
  7. package/dist/cjs/components/Axis/index.d.ts +2 -0
  8. package/dist/cjs/components/Axis/index.js +2 -0
  9. package/dist/cjs/components/Axis/styles.css +17 -0
  10. package/dist/cjs/components/ChartInner/index.d.ts +10 -0
  11. package/dist/cjs/components/ChartInner/index.js +143 -0
  12. package/dist/cjs/components/ChartInner/styles.css +10 -0
  13. package/dist/cjs/components/Legend/index.d.ts +13 -0
  14. package/dist/cjs/components/Legend/index.js +278 -0
  15. package/dist/cjs/components/Legend/styles.css +47 -0
  16. package/dist/cjs/components/PlotTitle/index.d.ts +8 -0
  17. package/dist/cjs/components/PlotTitle/index.js +13 -0
  18. package/dist/cjs/components/PlotTitle/styles.css +5 -0
  19. package/dist/cjs/components/Title/index.d.ts +8 -0
  20. package/dist/cjs/components/Title/index.js +9 -0
  21. package/dist/cjs/components/Title/styles.css +5 -0
  22. package/dist/cjs/components/Tooltip/DefaultContent.d.ts +10 -0
  23. package/dist/cjs/components/Tooltip/DefaultContent.js +101 -0
  24. package/dist/cjs/components/Tooltip/index.d.ts +13 -0
  25. package/dist/cjs/components/Tooltip/index.js +29 -0
  26. package/dist/cjs/components/Tooltip/styles.css +29 -0
  27. package/dist/cjs/components/index.d.ts +18 -0
  28. package/dist/cjs/components/index.js +66 -0
  29. package/dist/cjs/constants/defaults/axis.d.ts +14 -0
  30. package/dist/cjs/constants/defaults/axis.js +18 -0
  31. package/dist/cjs/constants/defaults/index.d.ts +3 -0
  32. package/dist/cjs/constants/defaults/index.js +3 -0
  33. package/dist/cjs/constants/defaults/legend.d.ts +13 -0
  34. package/dist/cjs/constants/defaults/legend.js +12 -0
  35. package/dist/cjs/constants/defaults/series-options.d.ts +24 -0
  36. package/dist/cjs/constants/defaults/series-options.js +106 -0
  37. package/dist/cjs/constants/index.d.ts +46 -0
  38. package/dist/cjs/constants/index.js +71 -0
  39. package/dist/cjs/hooks/index.d.ts +10 -0
  40. package/dist/cjs/hooks/index.js +10 -0
  41. package/dist/cjs/hooks/useAxisScales/index.d.ts +25 -0
  42. package/dist/cjs/hooks/useAxisScales/index.js +183 -0
  43. package/dist/cjs/hooks/useChartDimensions/index.d.ts +16 -0
  44. package/dist/cjs/hooks/useChartDimensions/index.js +34 -0
  45. package/dist/cjs/hooks/useChartDimensions/utils.d.ts +10 -0
  46. package/dist/cjs/hooks/useChartDimensions/utils.js +32 -0
  47. package/dist/cjs/hooks/useChartOptions/chart.d.ts +6 -0
  48. package/dist/cjs/hooks/useChartOptions/chart.js +28 -0
  49. package/dist/cjs/hooks/useChartOptions/index.d.ts +7 -0
  50. package/dist/cjs/hooks/useChartOptions/index.js +21 -0
  51. package/dist/cjs/hooks/useChartOptions/title.d.ts +5 -0
  52. package/dist/cjs/hooks/useChartOptions/title.js +18 -0
  53. package/dist/cjs/hooks/useChartOptions/tooltip.d.ts +5 -0
  54. package/dist/cjs/hooks/useChartOptions/tooltip.js +5 -0
  55. package/dist/cjs/hooks/useChartOptions/types.d.ts +47 -0
  56. package/dist/cjs/hooks/useChartOptions/types.js +1 -0
  57. package/dist/cjs/hooks/useChartOptions/x-axis.d.ts +7 -0
  58. package/dist/cjs/hooks/useChartOptions/x-axis.js +115 -0
  59. package/dist/cjs/hooks/useChartOptions/y-axis.d.ts +7 -0
  60. package/dist/cjs/hooks/useChartOptions/y-axis.js +117 -0
  61. package/dist/cjs/hooks/useSeries/constants.d.ts +8 -0
  62. package/dist/cjs/hooks/useSeries/constants.js +19 -0
  63. package/dist/cjs/hooks/useSeries/index.d.ts +29 -0
  64. package/dist/cjs/hooks/useSeries/index.js +82 -0
  65. package/dist/cjs/hooks/useSeries/prepare-area.d.ts +19 -0
  66. package/dist/cjs/hooks/useSeries/prepare-area.js +63 -0
  67. package/dist/cjs/hooks/useSeries/prepare-bar-x.d.ts +10 -0
  68. package/dist/cjs/hooks/useSeries/prepare-bar-x.js +38 -0
  69. package/dist/cjs/hooks/useSeries/prepare-bar-y.d.ts +10 -0
  70. package/dist/cjs/hooks/useSeries/prepare-bar-y.js +48 -0
  71. package/dist/cjs/hooks/useSeries/prepare-legend.d.ts +27 -0
  72. package/dist/cjs/hooks/useSeries/prepare-legend.js +144 -0
  73. package/dist/cjs/hooks/useSeries/prepare-line.d.ts +22 -0
  74. package/dist/cjs/hooks/useSeries/prepare-line.js +82 -0
  75. package/dist/cjs/hooks/useSeries/prepare-options.d.ts +3 -0
  76. package/dist/cjs/hooks/useSeries/prepare-options.js +5 -0
  77. package/dist/cjs/hooks/useSeries/prepare-pie.d.ts +9 -0
  78. package/dist/cjs/hooks/useSeries/prepare-pie.js +62 -0
  79. package/dist/cjs/hooks/useSeries/prepare-scatter.d.ts +11 -0
  80. package/dist/cjs/hooks/useSeries/prepare-scatter.js +46 -0
  81. package/dist/cjs/hooks/useSeries/prepare-treemap.d.ts +11 -0
  82. package/dist/cjs/hooks/useSeries/prepare-treemap.js +38 -0
  83. package/dist/cjs/hooks/useSeries/prepare-waterfall.d.ts +10 -0
  84. package/dist/cjs/hooks/useSeries/prepare-waterfall.js +37 -0
  85. package/dist/cjs/hooks/useSeries/prepareSeries.d.ts +10 -0
  86. package/dist/cjs/hooks/useSeries/prepareSeries.js +65 -0
  87. package/dist/cjs/hooks/useSeries/types.d.ts +253 -0
  88. package/dist/cjs/hooks/useSeries/types.js +1 -0
  89. package/dist/cjs/hooks/useSeries/utils.d.ts +7 -0
  90. package/dist/cjs/hooks/useSeries/utils.js +33 -0
  91. package/dist/cjs/hooks/useShapes/HtmlLayer.d.ts +8 -0
  92. package/dist/cjs/hooks/useShapes/HtmlLayer.js +22 -0
  93. package/dist/cjs/hooks/useShapes/area/index.d.ts +12 -0
  94. package/dist/cjs/hooks/useShapes/area/index.js +143 -0
  95. package/dist/cjs/hooks/useShapes/area/prepare-data.d.ts +12 -0
  96. package/dist/cjs/hooks/useShapes/area/prepare-data.js +158 -0
  97. package/dist/cjs/hooks/useShapes/area/types.d.ts +27 -0
  98. package/dist/cjs/hooks/useShapes/area/types.js +1 -0
  99. package/dist/cjs/hooks/useShapes/bar-x/index.d.ts +13 -0
  100. package/dist/cjs/hooks/useShapes/bar-x/index.js +95 -0
  101. package/dist/cjs/hooks/useShapes/bar-x/prepare-data.d.ts +13 -0
  102. package/dist/cjs/hooks/useShapes/bar-x/prepare-data.js +160 -0
  103. package/dist/cjs/hooks/useShapes/bar-x/types.d.ts +12 -0
  104. package/dist/cjs/hooks/useShapes/bar-x/types.js +1 -0
  105. package/dist/cjs/hooks/useShapes/bar-y/index.d.ts +12 -0
  106. package/dist/cjs/hooks/useShapes/bar-y/index.js +84 -0
  107. package/dist/cjs/hooks/useShapes/bar-y/prepare-data.d.ts +12 -0
  108. package/dist/cjs/hooks/useShapes/bar-y/prepare-data.js +169 -0
  109. package/dist/cjs/hooks/useShapes/bar-y/types.d.ts +13 -0
  110. package/dist/cjs/hooks/useShapes/bar-y/types.js +1 -0
  111. package/dist/cjs/hooks/useShapes/constants.d.ts +3 -0
  112. package/dist/cjs/hooks/useShapes/constants.js +3 -0
  113. package/dist/cjs/hooks/useShapes/index.d.ts +33 -0
  114. package/dist/cjs/hooks/useShapes/index.js +154 -0
  115. package/dist/cjs/hooks/useShapes/line/index.d.ts +12 -0
  116. package/dist/cjs/hooks/useShapes/line/index.js +130 -0
  117. package/dist/cjs/hooks/useShapes/line/prepare-data.d.ts +13 -0
  118. package/dist/cjs/hooks/useShapes/line/prepare-data.js +91 -0
  119. package/dist/cjs/hooks/useShapes/line/types.d.ts +29 -0
  120. package/dist/cjs/hooks/useShapes/line/types.js +1 -0
  121. package/dist/cjs/hooks/useShapes/marker.d.ts +14 -0
  122. package/dist/cjs/hooks/useShapes/marker.js +75 -0
  123. package/dist/cjs/hooks/useShapes/pie/index.d.ts +13 -0
  124. package/dist/cjs/hooks/useShapes/pie/index.js +171 -0
  125. package/dist/cjs/hooks/useShapes/pie/prepare-data.d.ts +9 -0
  126. package/dist/cjs/hooks/useShapes/pie/prepare-data.js +186 -0
  127. package/dist/cjs/hooks/useShapes/pie/types.d.ts +41 -0
  128. package/dist/cjs/hooks/useShapes/pie/types.js +1 -0
  129. package/dist/cjs/hooks/useShapes/pie/utils.d.ts +4 -0
  130. package/dist/cjs/hooks/useShapes/pie/utils.js +15 -0
  131. package/dist/cjs/hooks/useShapes/scatter/index.d.ts +12 -0
  132. package/dist/cjs/hooks/useShapes/scatter/index.js +69 -0
  133. package/dist/cjs/hooks/useShapes/scatter/prepare-data.d.ts +11 -0
  134. package/dist/cjs/hooks/useShapes/scatter/prepare-data.js +31 -0
  135. package/dist/cjs/hooks/useShapes/scatter/types.d.ts +17 -0
  136. package/dist/cjs/hooks/useShapes/scatter/types.js +1 -0
  137. package/dist/cjs/hooks/useShapes/styles.css +35 -0
  138. package/dist/cjs/hooks/useShapes/treemap/index.d.ts +12 -0
  139. package/dist/cjs/hooks/useShapes/treemap/index.js +98 -0
  140. package/dist/cjs/hooks/useShapes/treemap/prepare-data.d.ts +7 -0
  141. package/dist/cjs/hooks/useShapes/treemap/prepare-data.js +114 -0
  142. package/dist/cjs/hooks/useShapes/treemap/types.d.ts +16 -0
  143. package/dist/cjs/hooks/useShapes/treemap/types.js +1 -0
  144. package/dist/cjs/hooks/useShapes/utils.d.ts +29 -0
  145. package/dist/cjs/hooks/useShapes/utils.js +53 -0
  146. package/dist/cjs/hooks/useShapes/waterfall/index.d.ts +13 -0
  147. package/dist/cjs/hooks/useShapes/waterfall/index.js +127 -0
  148. package/dist/cjs/hooks/useShapes/waterfall/prepare-data.d.ts +12 -0
  149. package/dist/cjs/hooks/useShapes/waterfall/prepare-data.js +133 -0
  150. package/dist/cjs/hooks/useShapes/waterfall/types.d.ts +14 -0
  151. package/dist/cjs/hooks/useShapes/waterfall/types.js +1 -0
  152. package/dist/cjs/hooks/useSplit/index.d.ts +14 -0
  153. package/dist/cjs/hooks/useSplit/index.js +57 -0
  154. package/dist/cjs/hooks/useSplit/types.d.ts +17 -0
  155. package/dist/cjs/hooks/useSplit/types.js +1 -0
  156. package/dist/cjs/hooks/useTooltip/index.d.ts +13 -0
  157. package/dist/cjs/hooks/useTooltip/index.js +17 -0
  158. package/dist/cjs/hooks/useTooltip/types.d.ts +1 -0
  159. package/dist/cjs/hooks/useTooltip/types.js +1 -0
  160. package/dist/cjs/i18n/index.d.ts +8 -0
  161. package/dist/cjs/i18n/index.js +10 -0
  162. package/dist/cjs/index.d.ts +2 -0
  163. package/dist/cjs/index.js +1 -0
  164. package/dist/cjs/libs/chart-error/index.d.ts +16 -0
  165. package/dist/cjs/libs/chart-error/index.js +19 -0
  166. package/dist/cjs/libs/format-number/i18n/en.json +17 -0
  167. package/dist/cjs/libs/format-number/i18n/i18n.d.ts +5 -0
  168. package/dist/cjs/libs/format-number/i18n/i18n.js +8 -0
  169. package/dist/cjs/libs/format-number/i18n/ru.json +17 -0
  170. package/dist/cjs/libs/format-number/index.d.ts +5 -0
  171. package/dist/cjs/libs/format-number/index.js +87 -0
  172. package/dist/cjs/libs/format-number/types.d.ts +14 -0
  173. package/dist/cjs/libs/format-number/types.js +1 -0
  174. package/dist/cjs/libs/index.d.ts +2 -0
  175. package/dist/cjs/libs/index.js +2 -0
  176. package/dist/cjs/types/chart/area.d.ts +76 -0
  177. package/dist/cjs/types/chart/area.js +1 -0
  178. package/dist/cjs/types/chart/axis.d.ts +85 -0
  179. package/dist/cjs/types/chart/axis.js +1 -0
  180. package/dist/cjs/types/chart/bar-x.d.ts +67 -0
  181. package/dist/cjs/types/chart/bar-x.js +1 -0
  182. package/dist/cjs/types/chart/bar-y.d.ts +60 -0
  183. package/dist/cjs/types/chart/bar-y.js +1 -0
  184. package/dist/cjs/types/chart/base.d.ts +48 -0
  185. package/dist/cjs/types/chart/base.js +1 -0
  186. package/dist/cjs/types/chart/chart.d.ts +15 -0
  187. package/dist/cjs/types/chart/chart.js +1 -0
  188. package/dist/cjs/types/chart/halo.d.ts +9 -0
  189. package/dist/cjs/types/chart/halo.js +1 -0
  190. package/dist/cjs/types/chart/legend.d.ts +92 -0
  191. package/dist/cjs/types/chart/legend.js +1 -0
  192. package/dist/cjs/types/chart/line.d.ts +57 -0
  193. package/dist/cjs/types/chart/line.js +1 -0
  194. package/dist/cjs/types/chart/marker.d.ts +12 -0
  195. package/dist/cjs/types/chart/marker.js +1 -0
  196. package/dist/cjs/types/chart/pie.d.ts +88 -0
  197. package/dist/cjs/types/chart/pie.js +1 -0
  198. package/dist/cjs/types/chart/scatter.d.ts +46 -0
  199. package/dist/cjs/types/chart/scatter.js +1 -0
  200. package/dist/cjs/types/chart/series.d.ts +226 -0
  201. package/dist/cjs/types/chart/series.js +1 -0
  202. package/dist/cjs/types/chart/split.d.ts +13 -0
  203. package/dist/cjs/types/chart/split.js +1 -0
  204. package/dist/cjs/types/chart/title.d.ts +5 -0
  205. package/dist/cjs/types/chart/title.js +1 -0
  206. package/dist/cjs/types/chart/tooltip.d.ts +67 -0
  207. package/dist/cjs/types/chart/tooltip.js +1 -0
  208. package/dist/cjs/types/chart/treemap.d.ts +46 -0
  209. package/dist/cjs/types/chart/treemap.js +1 -0
  210. package/dist/cjs/types/chart/waterfall.d.ts +40 -0
  211. package/dist/cjs/types/chart/waterfall.js +1 -0
  212. package/dist/cjs/types/chart-ui.d.ts +24 -0
  213. package/dist/cjs/types/chart-ui.js +1 -0
  214. package/dist/cjs/types/formatter.d.ts +14 -0
  215. package/dist/cjs/types/formatter.js +1 -0
  216. package/dist/cjs/types/index.d.ts +42 -0
  217. package/dist/cjs/types/index.js +19 -0
  218. package/dist/cjs/types/misc.d.ts +4 -0
  219. package/dist/cjs/types/misc.js +1 -0
  220. package/dist/cjs/utils/chart/axis-generators/bottom.d.ts +24 -0
  221. package/dist/cjs/utils/chart/axis-generators/bottom.js +126 -0
  222. package/dist/cjs/utils/chart/axis-generators/index.d.ts +1 -0
  223. package/dist/cjs/utils/chart/axis-generators/index.js +1 -0
  224. package/dist/cjs/utils/chart/axis.d.ts +31 -0
  225. package/dist/cjs/utils/chart/axis.js +71 -0
  226. package/dist/cjs/utils/chart/color.d.ts +10 -0
  227. package/dist/cjs/utils/chart/color.js +43 -0
  228. package/dist/cjs/utils/chart/get-closest-data.d.ts +15 -0
  229. package/dist/cjs/utils/chart/get-closest-data.js +172 -0
  230. package/dist/cjs/utils/chart/index.d.ts +78 -0
  231. package/dist/cjs/utils/chart/index.js +210 -0
  232. package/dist/cjs/utils/chart/labels.d.ts +6 -0
  233. package/dist/cjs/utils/chart/labels.js +44 -0
  234. package/dist/cjs/utils/chart/legend.d.ts +8 -0
  235. package/dist/cjs/utils/chart/legend.js +23 -0
  236. package/dist/cjs/utils/chart/math.d.ts +25 -0
  237. package/dist/cjs/utils/chart/math.js +51 -0
  238. package/dist/cjs/utils/chart/series/index.d.ts +1 -0
  239. package/dist/cjs/utils/chart/series/index.js +1 -0
  240. package/dist/cjs/utils/chart/series/waterfall.d.ts +4 -0
  241. package/dist/cjs/utils/chart/series/waterfall.js +25 -0
  242. package/dist/cjs/utils/chart/symbol.d.ts +3 -0
  243. package/dist/cjs/utils/chart/symbol.js +36 -0
  244. package/dist/cjs/utils/chart/text.d.ts +29 -0
  245. package/dist/cjs/utils/chart/text.js +139 -0
  246. package/dist/cjs/utils/chart/time.d.ts +3 -0
  247. package/dist/cjs/utils/chart/time.js +34 -0
  248. package/dist/cjs/utils/chart-ui/index.d.ts +4 -0
  249. package/dist/cjs/utils/chart-ui/index.js +4 -0
  250. package/dist/cjs/utils/chart-ui/pie-center-text.d.ts +7 -0
  251. package/dist/cjs/utils/chart-ui/pie-center-text.js +23 -0
  252. package/dist/cjs/utils/cn.d.ts +3 -0
  253. package/dist/cjs/utils/cn.js +4 -0
  254. package/dist/cjs/utils/d3-dispatcher.d.ts +1 -0
  255. package/dist/cjs/utils/d3-dispatcher.js +4 -0
  256. package/dist/cjs/utils/index.d.ts +5 -0
  257. package/dist/cjs/utils/index.js +5 -0
  258. package/dist/cjs/utils/misc.d.ts +2 -0
  259. package/dist/cjs/utils/misc.js +8 -0
  260. package/dist/cjs/validation/index.d.ts +2 -0
  261. package/dist/cjs/validation/index.js +220 -0
  262. package/dist/esm/components/Axis/AxisX.d.ts +20 -0
  263. package/dist/esm/components/Axis/AxisX.js +108 -0
  264. package/dist/esm/components/Axis/AxisY.d.ts +12 -0
  265. package/dist/esm/components/Axis/AxisY.js +199 -0
  266. package/dist/esm/components/Axis/index.d.ts +2 -0
  267. package/dist/esm/components/Axis/index.js +2 -0
  268. package/dist/esm/components/Axis/styles.css +17 -0
  269. package/dist/esm/components/ChartInner/index.d.ts +10 -0
  270. package/dist/esm/components/ChartInner/index.js +143 -0
  271. package/dist/esm/components/ChartInner/styles.css +10 -0
  272. package/dist/esm/components/Legend/index.d.ts +13 -0
  273. package/dist/esm/components/Legend/index.js +278 -0
  274. package/dist/esm/components/Legend/styles.css +47 -0
  275. package/dist/esm/components/PlotTitle/index.d.ts +8 -0
  276. package/dist/esm/components/PlotTitle/index.js +13 -0
  277. package/dist/esm/components/PlotTitle/styles.css +5 -0
  278. package/dist/esm/components/Title/index.d.ts +8 -0
  279. package/dist/esm/components/Title/index.js +9 -0
  280. package/dist/esm/components/Title/styles.css +5 -0
  281. package/dist/esm/components/Tooltip/DefaultContent.d.ts +10 -0
  282. package/dist/esm/components/Tooltip/DefaultContent.js +101 -0
  283. package/dist/esm/components/Tooltip/index.d.ts +13 -0
  284. package/dist/esm/components/Tooltip/index.js +29 -0
  285. package/dist/esm/components/Tooltip/styles.css +29 -0
  286. package/dist/esm/components/index.d.ts +18 -0
  287. package/dist/esm/components/index.js +66 -0
  288. package/dist/esm/constants/defaults/axis.d.ts +14 -0
  289. package/dist/esm/constants/defaults/axis.js +18 -0
  290. package/dist/esm/constants/defaults/index.d.ts +3 -0
  291. package/dist/esm/constants/defaults/index.js +3 -0
  292. package/dist/esm/constants/defaults/legend.d.ts +13 -0
  293. package/dist/esm/constants/defaults/legend.js +12 -0
  294. package/dist/esm/constants/defaults/series-options.d.ts +24 -0
  295. package/dist/esm/constants/defaults/series-options.js +106 -0
  296. package/dist/esm/constants/index.d.ts +46 -0
  297. package/dist/esm/constants/index.js +71 -0
  298. package/dist/esm/hooks/index.d.ts +10 -0
  299. package/dist/esm/hooks/index.js +10 -0
  300. package/dist/esm/hooks/useAxisScales/index.d.ts +25 -0
  301. package/dist/esm/hooks/useAxisScales/index.js +183 -0
  302. package/dist/esm/hooks/useChartDimensions/index.d.ts +16 -0
  303. package/dist/esm/hooks/useChartDimensions/index.js +34 -0
  304. package/dist/esm/hooks/useChartDimensions/utils.d.ts +10 -0
  305. package/dist/esm/hooks/useChartDimensions/utils.js +32 -0
  306. package/dist/esm/hooks/useChartOptions/chart.d.ts +6 -0
  307. package/dist/esm/hooks/useChartOptions/chart.js +28 -0
  308. package/dist/esm/hooks/useChartOptions/index.d.ts +7 -0
  309. package/dist/esm/hooks/useChartOptions/index.js +21 -0
  310. package/dist/esm/hooks/useChartOptions/title.d.ts +5 -0
  311. package/dist/esm/hooks/useChartOptions/title.js +18 -0
  312. package/dist/esm/hooks/useChartOptions/tooltip.d.ts +5 -0
  313. package/dist/esm/hooks/useChartOptions/tooltip.js +5 -0
  314. package/dist/esm/hooks/useChartOptions/types.d.ts +47 -0
  315. package/dist/esm/hooks/useChartOptions/types.js +1 -0
  316. package/dist/esm/hooks/useChartOptions/x-axis.d.ts +7 -0
  317. package/dist/esm/hooks/useChartOptions/x-axis.js +115 -0
  318. package/dist/esm/hooks/useChartOptions/y-axis.d.ts +7 -0
  319. package/dist/esm/hooks/useChartOptions/y-axis.js +117 -0
  320. package/dist/esm/hooks/useSeries/constants.d.ts +8 -0
  321. package/dist/esm/hooks/useSeries/constants.js +19 -0
  322. package/dist/esm/hooks/useSeries/index.d.ts +29 -0
  323. package/dist/esm/hooks/useSeries/index.js +82 -0
  324. package/dist/esm/hooks/useSeries/prepare-area.d.ts +19 -0
  325. package/dist/esm/hooks/useSeries/prepare-area.js +63 -0
  326. package/dist/esm/hooks/useSeries/prepare-bar-x.d.ts +10 -0
  327. package/dist/esm/hooks/useSeries/prepare-bar-x.js +38 -0
  328. package/dist/esm/hooks/useSeries/prepare-bar-y.d.ts +10 -0
  329. package/dist/esm/hooks/useSeries/prepare-bar-y.js +48 -0
  330. package/dist/esm/hooks/useSeries/prepare-legend.d.ts +27 -0
  331. package/dist/esm/hooks/useSeries/prepare-legend.js +144 -0
  332. package/dist/esm/hooks/useSeries/prepare-line.d.ts +22 -0
  333. package/dist/esm/hooks/useSeries/prepare-line.js +82 -0
  334. package/dist/esm/hooks/useSeries/prepare-options.d.ts +3 -0
  335. package/dist/esm/hooks/useSeries/prepare-options.js +5 -0
  336. package/dist/esm/hooks/useSeries/prepare-pie.d.ts +9 -0
  337. package/dist/esm/hooks/useSeries/prepare-pie.js +62 -0
  338. package/dist/esm/hooks/useSeries/prepare-scatter.d.ts +11 -0
  339. package/dist/esm/hooks/useSeries/prepare-scatter.js +46 -0
  340. package/dist/esm/hooks/useSeries/prepare-treemap.d.ts +11 -0
  341. package/dist/esm/hooks/useSeries/prepare-treemap.js +38 -0
  342. package/dist/esm/hooks/useSeries/prepare-waterfall.d.ts +10 -0
  343. package/dist/esm/hooks/useSeries/prepare-waterfall.js +37 -0
  344. package/dist/esm/hooks/useSeries/prepareSeries.d.ts +10 -0
  345. package/dist/esm/hooks/useSeries/prepareSeries.js +65 -0
  346. package/dist/esm/hooks/useSeries/types.d.ts +253 -0
  347. package/dist/esm/hooks/useSeries/types.js +1 -0
  348. package/dist/esm/hooks/useSeries/utils.d.ts +7 -0
  349. package/dist/esm/hooks/useSeries/utils.js +33 -0
  350. package/dist/esm/hooks/useShapes/HtmlLayer.d.ts +8 -0
  351. package/dist/esm/hooks/useShapes/HtmlLayer.js +22 -0
  352. package/dist/esm/hooks/useShapes/area/index.d.ts +12 -0
  353. package/dist/esm/hooks/useShapes/area/index.js +143 -0
  354. package/dist/esm/hooks/useShapes/area/prepare-data.d.ts +12 -0
  355. package/dist/esm/hooks/useShapes/area/prepare-data.js +158 -0
  356. package/dist/esm/hooks/useShapes/area/types.d.ts +27 -0
  357. package/dist/esm/hooks/useShapes/area/types.js +1 -0
  358. package/dist/esm/hooks/useShapes/bar-x/index.d.ts +13 -0
  359. package/dist/esm/hooks/useShapes/bar-x/index.js +95 -0
  360. package/dist/esm/hooks/useShapes/bar-x/prepare-data.d.ts +13 -0
  361. package/dist/esm/hooks/useShapes/bar-x/prepare-data.js +160 -0
  362. package/dist/esm/hooks/useShapes/bar-x/types.d.ts +12 -0
  363. package/dist/esm/hooks/useShapes/bar-x/types.js +1 -0
  364. package/dist/esm/hooks/useShapes/bar-y/index.d.ts +12 -0
  365. package/dist/esm/hooks/useShapes/bar-y/index.js +84 -0
  366. package/dist/esm/hooks/useShapes/bar-y/prepare-data.d.ts +12 -0
  367. package/dist/esm/hooks/useShapes/bar-y/prepare-data.js +169 -0
  368. package/dist/esm/hooks/useShapes/bar-y/types.d.ts +13 -0
  369. package/dist/esm/hooks/useShapes/bar-y/types.js +1 -0
  370. package/dist/esm/hooks/useShapes/constants.d.ts +3 -0
  371. package/dist/esm/hooks/useShapes/constants.js +3 -0
  372. package/dist/esm/hooks/useShapes/index.d.ts +33 -0
  373. package/dist/esm/hooks/useShapes/index.js +154 -0
  374. package/dist/esm/hooks/useShapes/line/index.d.ts +12 -0
  375. package/dist/esm/hooks/useShapes/line/index.js +130 -0
  376. package/dist/esm/hooks/useShapes/line/prepare-data.d.ts +13 -0
  377. package/dist/esm/hooks/useShapes/line/prepare-data.js +91 -0
  378. package/dist/esm/hooks/useShapes/line/types.d.ts +29 -0
  379. package/dist/esm/hooks/useShapes/line/types.js +1 -0
  380. package/dist/esm/hooks/useShapes/marker.d.ts +14 -0
  381. package/dist/esm/hooks/useShapes/marker.js +75 -0
  382. package/dist/esm/hooks/useShapes/pie/index.d.ts +13 -0
  383. package/dist/esm/hooks/useShapes/pie/index.js +171 -0
  384. package/dist/esm/hooks/useShapes/pie/prepare-data.d.ts +9 -0
  385. package/dist/esm/hooks/useShapes/pie/prepare-data.js +186 -0
  386. package/dist/esm/hooks/useShapes/pie/types.d.ts +41 -0
  387. package/dist/esm/hooks/useShapes/pie/types.js +1 -0
  388. package/dist/esm/hooks/useShapes/pie/utils.d.ts +4 -0
  389. package/dist/esm/hooks/useShapes/pie/utils.js +15 -0
  390. package/dist/esm/hooks/useShapes/scatter/index.d.ts +12 -0
  391. package/dist/esm/hooks/useShapes/scatter/index.js +69 -0
  392. package/dist/esm/hooks/useShapes/scatter/prepare-data.d.ts +11 -0
  393. package/dist/esm/hooks/useShapes/scatter/prepare-data.js +31 -0
  394. package/dist/esm/hooks/useShapes/scatter/types.d.ts +17 -0
  395. package/dist/esm/hooks/useShapes/scatter/types.js +1 -0
  396. package/dist/esm/hooks/useShapes/styles.css +35 -0
  397. package/dist/esm/hooks/useShapes/treemap/index.d.ts +12 -0
  398. package/dist/esm/hooks/useShapes/treemap/index.js +98 -0
  399. package/dist/esm/hooks/useShapes/treemap/prepare-data.d.ts +7 -0
  400. package/dist/esm/hooks/useShapes/treemap/prepare-data.js +114 -0
  401. package/dist/esm/hooks/useShapes/treemap/types.d.ts +16 -0
  402. package/dist/esm/hooks/useShapes/treemap/types.js +1 -0
  403. package/dist/esm/hooks/useShapes/utils.d.ts +29 -0
  404. package/dist/esm/hooks/useShapes/utils.js +53 -0
  405. package/dist/esm/hooks/useShapes/waterfall/index.d.ts +13 -0
  406. package/dist/esm/hooks/useShapes/waterfall/index.js +127 -0
  407. package/dist/esm/hooks/useShapes/waterfall/prepare-data.d.ts +12 -0
  408. package/dist/esm/hooks/useShapes/waterfall/prepare-data.js +133 -0
  409. package/dist/esm/hooks/useShapes/waterfall/types.d.ts +14 -0
  410. package/dist/esm/hooks/useShapes/waterfall/types.js +1 -0
  411. package/dist/esm/hooks/useSplit/index.d.ts +14 -0
  412. package/dist/esm/hooks/useSplit/index.js +57 -0
  413. package/dist/esm/hooks/useSplit/types.d.ts +17 -0
  414. package/dist/esm/hooks/useSplit/types.js +1 -0
  415. package/dist/esm/hooks/useTooltip/index.d.ts +13 -0
  416. package/dist/esm/hooks/useTooltip/index.js +17 -0
  417. package/dist/esm/hooks/useTooltip/types.d.ts +1 -0
  418. package/dist/esm/hooks/useTooltip/types.js +1 -0
  419. package/dist/esm/i18n/index.d.ts +8 -0
  420. package/dist/esm/i18n/index.js +10 -0
  421. package/dist/esm/index.d.ts +2 -0
  422. package/dist/esm/index.js +1 -0
  423. package/dist/esm/libs/chart-error/index.d.ts +16 -0
  424. package/dist/esm/libs/chart-error/index.js +19 -0
  425. package/dist/esm/libs/format-number/i18n/en.json +17 -0
  426. package/dist/esm/libs/format-number/i18n/i18n.d.ts +5 -0
  427. package/dist/esm/libs/format-number/i18n/i18n.js +8 -0
  428. package/dist/esm/libs/format-number/i18n/ru.json +17 -0
  429. package/dist/esm/libs/format-number/index.d.ts +5 -0
  430. package/dist/esm/libs/format-number/index.js +87 -0
  431. package/dist/esm/libs/format-number/types.d.ts +14 -0
  432. package/dist/esm/libs/format-number/types.js +1 -0
  433. package/dist/esm/libs/index.d.ts +2 -0
  434. package/dist/esm/libs/index.js +2 -0
  435. package/dist/esm/types/chart/area.d.ts +76 -0
  436. package/dist/esm/types/chart/area.js +1 -0
  437. package/dist/esm/types/chart/axis.d.ts +85 -0
  438. package/dist/esm/types/chart/axis.js +1 -0
  439. package/dist/esm/types/chart/bar-x.d.ts +67 -0
  440. package/dist/esm/types/chart/bar-x.js +1 -0
  441. package/dist/esm/types/chart/bar-y.d.ts +60 -0
  442. package/dist/esm/types/chart/bar-y.js +1 -0
  443. package/dist/esm/types/chart/base.d.ts +48 -0
  444. package/dist/esm/types/chart/base.js +1 -0
  445. package/dist/esm/types/chart/chart.d.ts +15 -0
  446. package/dist/esm/types/chart/chart.js +1 -0
  447. package/dist/esm/types/chart/halo.d.ts +9 -0
  448. package/dist/esm/types/chart/halo.js +1 -0
  449. package/dist/esm/types/chart/legend.d.ts +92 -0
  450. package/dist/esm/types/chart/legend.js +1 -0
  451. package/dist/esm/types/chart/line.d.ts +57 -0
  452. package/dist/esm/types/chart/line.js +1 -0
  453. package/dist/esm/types/chart/marker.d.ts +12 -0
  454. package/dist/esm/types/chart/marker.js +1 -0
  455. package/dist/esm/types/chart/pie.d.ts +88 -0
  456. package/dist/esm/types/chart/pie.js +1 -0
  457. package/dist/esm/types/chart/scatter.d.ts +46 -0
  458. package/dist/esm/types/chart/scatter.js +1 -0
  459. package/dist/esm/types/chart/series.d.ts +226 -0
  460. package/dist/esm/types/chart/series.js +1 -0
  461. package/dist/esm/types/chart/split.d.ts +13 -0
  462. package/dist/esm/types/chart/split.js +1 -0
  463. package/dist/esm/types/chart/title.d.ts +5 -0
  464. package/dist/esm/types/chart/title.js +1 -0
  465. package/dist/esm/types/chart/tooltip.d.ts +67 -0
  466. package/dist/esm/types/chart/tooltip.js +1 -0
  467. package/dist/esm/types/chart/treemap.d.ts +46 -0
  468. package/dist/esm/types/chart/treemap.js +1 -0
  469. package/dist/esm/types/chart/waterfall.d.ts +40 -0
  470. package/dist/esm/types/chart/waterfall.js +1 -0
  471. package/dist/esm/types/chart-ui.d.ts +24 -0
  472. package/dist/esm/types/chart-ui.js +1 -0
  473. package/dist/esm/types/formatter.d.ts +14 -0
  474. package/dist/esm/types/formatter.js +1 -0
  475. package/dist/esm/types/index.d.ts +42 -0
  476. package/dist/esm/types/index.js +19 -0
  477. package/dist/esm/types/misc.d.ts +4 -0
  478. package/dist/esm/types/misc.js +1 -0
  479. package/dist/esm/utils/chart/axis-generators/bottom.d.ts +24 -0
  480. package/dist/esm/utils/chart/axis-generators/bottom.js +126 -0
  481. package/dist/esm/utils/chart/axis-generators/index.d.ts +1 -0
  482. package/dist/esm/utils/chart/axis-generators/index.js +1 -0
  483. package/dist/esm/utils/chart/axis.d.ts +31 -0
  484. package/dist/esm/utils/chart/axis.js +71 -0
  485. package/dist/esm/utils/chart/color.d.ts +10 -0
  486. package/dist/esm/utils/chart/color.js +43 -0
  487. package/dist/esm/utils/chart/get-closest-data.d.ts +15 -0
  488. package/dist/esm/utils/chart/get-closest-data.js +172 -0
  489. package/dist/esm/utils/chart/index.d.ts +78 -0
  490. package/dist/esm/utils/chart/index.js +210 -0
  491. package/dist/esm/utils/chart/labels.d.ts +6 -0
  492. package/dist/esm/utils/chart/labels.js +44 -0
  493. package/dist/esm/utils/chart/legend.d.ts +8 -0
  494. package/dist/esm/utils/chart/legend.js +23 -0
  495. package/dist/esm/utils/chart/math.d.ts +25 -0
  496. package/dist/esm/utils/chart/math.js +51 -0
  497. package/dist/esm/utils/chart/series/index.d.ts +1 -0
  498. package/dist/esm/utils/chart/series/index.js +1 -0
  499. package/dist/esm/utils/chart/series/waterfall.d.ts +4 -0
  500. package/dist/esm/utils/chart/series/waterfall.js +25 -0
  501. package/dist/esm/utils/chart/symbol.d.ts +3 -0
  502. package/dist/esm/utils/chart/symbol.js +36 -0
  503. package/dist/esm/utils/chart/text.d.ts +29 -0
  504. package/dist/esm/utils/chart/text.js +139 -0
  505. package/dist/esm/utils/chart/time.d.ts +3 -0
  506. package/dist/esm/utils/chart/time.js +34 -0
  507. package/dist/esm/utils/chart-ui/index.d.ts +4 -0
  508. package/dist/esm/utils/chart-ui/index.js +4 -0
  509. package/dist/esm/utils/chart-ui/pie-center-text.d.ts +7 -0
  510. package/dist/esm/utils/chart-ui/pie-center-text.js +23 -0
  511. package/dist/esm/utils/cn.d.ts +3 -0
  512. package/dist/esm/utils/cn.js +4 -0
  513. package/dist/esm/utils/d3-dispatcher.d.ts +1 -0
  514. package/dist/esm/utils/d3-dispatcher.js +4 -0
  515. package/dist/esm/utils/index.d.ts +5 -0
  516. package/dist/esm/utils/index.js +5 -0
  517. package/dist/esm/utils/misc.d.ts +2 -0
  518. package/dist/esm/utils/misc.js +8 -0
  519. package/dist/esm/validation/index.d.ts +2 -0
  520. package/dist/esm/validation/index.js +220 -0
  521. package/package.json +140 -0
@@ -0,0 +1,36 @@
1
+ import { symbolCircle, symbolDiamond2, symbolSquare, symbolTriangle2 } from 'd3';
2
+ import { SymbolType } from '../../constants';
3
+ export const getSymbolType = (index) => {
4
+ const scatterStyles = Object.values(SymbolType);
5
+ return scatterStyles[index % scatterStyles.length];
6
+ };
7
+ // This is an inverted triangle
8
+ // Based on https://github.com/d3/d3-shape/blob/main/src/symbol/triangle2.js
9
+ const sqrt3 = Math.sqrt(3);
10
+ const triangleDown = {
11
+ draw: (context, size) => {
12
+ const s = Math.sqrt(size) * 0.6824;
13
+ const t = s / 2;
14
+ const u = (s * sqrt3) / 2;
15
+ context.moveTo(0, s);
16
+ context.lineTo(u, -t);
17
+ context.lineTo(-u, -t);
18
+ context.closePath();
19
+ },
20
+ };
21
+ export const getSymbol = (symbolType) => {
22
+ switch (symbolType) {
23
+ case SymbolType.Diamond:
24
+ return symbolDiamond2;
25
+ case SymbolType.Circle:
26
+ return symbolCircle;
27
+ case SymbolType.Square:
28
+ return symbolSquare;
29
+ case SymbolType.Triangle:
30
+ return symbolTriangle2;
31
+ case SymbolType.TriangleDown:
32
+ return triangleDown;
33
+ default:
34
+ return symbolCircle;
35
+ }
36
+ };
@@ -0,0 +1,29 @@
1
+ import type { Selection } from 'd3';
2
+ import type { BaseTextStyle, MeaningfulAny } from '../../types';
3
+ export declare function handleOverflowingText(tSpan: SVGTSpanElement | null, maxWidth: number): void;
4
+ export declare function setEllipsisForOverflowText<T>(selection: Selection<SVGTextElement, T, null, unknown>, maxWidth: number): void;
5
+ export declare function setEllipsisForOverflowTexts<T>(selection: Selection<SVGTextElement, T, MeaningfulAny, unknown>, maxWidth: ((datum: T) => number) | number): void;
6
+ export declare function hasOverlappingLabels({ width, labels, padding, style, }: {
7
+ width: number;
8
+ labels: string[];
9
+ style?: BaseTextStyle;
10
+ padding?: number;
11
+ }): boolean;
12
+ export declare function getLabelsSize({ labels, style, rotation, html, }: {
13
+ labels: string[];
14
+ style?: BaseTextStyle;
15
+ rotation?: number;
16
+ html?: boolean;
17
+ }): {
18
+ maxHeight: number;
19
+ maxWidth: number;
20
+ };
21
+ export type TextRow = {
22
+ text: string;
23
+ y: number;
24
+ };
25
+ export declare function wrapText(args: {
26
+ text: string;
27
+ style?: BaseTextStyle;
28
+ width: number;
29
+ }): TextRow[];
@@ -0,0 +1,139 @@
1
+ import { select } from 'd3-selection';
2
+ export function handleOverflowingText(tSpan, maxWidth) {
3
+ var _a, _b, _c;
4
+ if (!tSpan) {
5
+ return;
6
+ }
7
+ const svg = tSpan.closest('svg');
8
+ if (!svg) {
9
+ return;
10
+ }
11
+ const textNode = tSpan.closest('text');
12
+ const angle = ((_a = Array.from((textNode === null || textNode === void 0 ? void 0 : textNode.transform.baseVal) || []).find((item) => item.angle)) === null || _a === void 0 ? void 0 : _a.angle) || 0;
13
+ const revertRotation = svg.createSVGTransform();
14
+ revertRotation.setRotate(-angle, 0, 0);
15
+ textNode === null || textNode === void 0 ? void 0 : textNode.transform.baseVal.appendItem(revertRotation);
16
+ let text = tSpan.textContent || '';
17
+ let textLength = ((_b = tSpan.getBoundingClientRect()) === null || _b === void 0 ? void 0 : _b.width) || 0;
18
+ while (textLength > maxWidth && text.length > 1) {
19
+ text = text.slice(0, -1);
20
+ tSpan.textContent = text + '…';
21
+ textLength = ((_c = tSpan.getBoundingClientRect()) === null || _c === void 0 ? void 0 : _c.width) || 0;
22
+ }
23
+ textNode === null || textNode === void 0 ? void 0 : textNode.transform.baseVal.removeItem((textNode === null || textNode === void 0 ? void 0 : textNode.transform.baseVal.length) - 1);
24
+ }
25
+ export function setEllipsisForOverflowText(selection, maxWidth) {
26
+ const text = selection.text();
27
+ selection.text(null).append('title').text(text);
28
+ const tSpan = selection.append('tspan').text(text).style('alignment-baseline', 'inherit');
29
+ handleOverflowingText(tSpan.node(), maxWidth);
30
+ }
31
+ export function setEllipsisForOverflowTexts(selection, maxWidth) {
32
+ selection.each(function (datum) {
33
+ const textMaxWidth = typeof maxWidth === 'function' ? maxWidth(datum) : maxWidth;
34
+ setEllipsisForOverflowText(select(this), textMaxWidth);
35
+ });
36
+ }
37
+ export function hasOverlappingLabels({ width, labels, padding = 0, style, }) {
38
+ const maxWidth = (width - padding * (labels.length - 1)) / labels.length;
39
+ const textElement = select(document.body)
40
+ .append('text')
41
+ .style('font-size', (style === null || style === void 0 ? void 0 : style.fontSize) || '');
42
+ const result = labels.some((label) => {
43
+ var _a, _b;
44
+ const textWidth = ((_b = (_a = textElement.text(label).node()) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect()) === null || _b === void 0 ? void 0 : _b.width) || 0;
45
+ return textWidth > maxWidth;
46
+ });
47
+ textElement.remove();
48
+ return result;
49
+ }
50
+ function renderLabels(selection, { labels, style = {}, attrs = {}, }) {
51
+ const text = selection.append('g').append('text');
52
+ text.style('font-size', style.fontSize || '');
53
+ text.style('font-weight', style.fontWeight || '');
54
+ Object.entries(attrs).forEach(([name, value]) => {
55
+ text.attr(name, value);
56
+ });
57
+ text.selectAll('tspan')
58
+ .data(labels)
59
+ .enter()
60
+ .append('tspan')
61
+ .attr('x', 0)
62
+ .attr('dy', 0)
63
+ .text((d) => d);
64
+ return text;
65
+ }
66
+ export function getLabelsSize({ labels, style, rotation, html, }) {
67
+ var _a, _b, _c;
68
+ if (!labels.filter(Boolean).length) {
69
+ return { maxHeight: 0, maxWidth: 0 };
70
+ }
71
+ const container = select(document.body).append('div');
72
+ // TODO: Why do we need this styles?
73
+ // .attr('class', 'chartkit chartkit-theme_common');
74
+ const result = { maxHeight: 0, maxWidth: 0 };
75
+ let labelWrapper;
76
+ if (html) {
77
+ labelWrapper = container.append('div').style('position', 'absolute').node();
78
+ const { height, width } = labels.reduce((acc, l) => {
79
+ var _a, _b;
80
+ if (labelWrapper) {
81
+ labelWrapper.innerHTML = l;
82
+ }
83
+ const rect = labelWrapper === null || labelWrapper === void 0 ? void 0 : labelWrapper.getBoundingClientRect();
84
+ return {
85
+ width: Math.max(acc.width, (_a = rect === null || rect === void 0 ? void 0 : rect.width) !== null && _a !== void 0 ? _a : 0),
86
+ height: Math.max(acc.height, (_b = rect === null || rect === void 0 ? void 0 : rect.height) !== null && _b !== void 0 ? _b : 0),
87
+ };
88
+ }, { height: 0, width: 0 });
89
+ result.maxWidth = width;
90
+ result.maxHeight = height;
91
+ }
92
+ else {
93
+ const svg = container.append('svg');
94
+ const textSelection = renderLabels(svg, { labels, style });
95
+ if (rotation) {
96
+ textSelection
97
+ .attr('text-anchor', rotation > 0 ? 'start' : 'end')
98
+ .style('transform', `rotate(${rotation}deg)`);
99
+ }
100
+ const rect = (_a = svg.select('g').node()) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
101
+ result.maxWidth = (_b = rect === null || rect === void 0 ? void 0 : rect.width) !== null && _b !== void 0 ? _b : 0;
102
+ result.maxHeight = (_c = rect === null || rect === void 0 ? void 0 : rect.height) !== null && _c !== void 0 ? _c : 0;
103
+ }
104
+ container.remove();
105
+ return result;
106
+ }
107
+ export function wrapText(args) {
108
+ const { text, style, width } = args;
109
+ const height = getLabelsSize({
110
+ labels: [text],
111
+ style: style,
112
+ }).maxHeight;
113
+ // @ts-ignore
114
+ const segmenter = new Intl.Segmenter([], { granularity: 'word' });
115
+ const segments = Array.from(segmenter.segment(text));
116
+ return segments.reduce((acc, s) => {
117
+ const item = s;
118
+ if (!acc.length) {
119
+ acc.push({
120
+ text: '',
121
+ y: acc.length * height,
122
+ });
123
+ }
124
+ let lastRow = acc[acc.length - 1];
125
+ if (item.isWordLike &&
126
+ getLabelsSize({
127
+ labels: [lastRow.text + item.segment],
128
+ style,
129
+ }).maxWidth > width) {
130
+ lastRow = {
131
+ text: '',
132
+ y: acc.length * height,
133
+ };
134
+ acc.push(lastRow);
135
+ }
136
+ lastRow.text += item.segment;
137
+ return acc;
138
+ }, []);
139
+ }
@@ -0,0 +1,3 @@
1
+ export declare const TIME_UNITS: Record<string, number>;
2
+ export declare const DATETIME_LABEL_FORMATS: Record<keyof typeof TIME_UNITS, string>;
3
+ export declare function getDefaultDateFormat(range?: number): string;
@@ -0,0 +1,34 @@
1
+ export const TIME_UNITS = {
2
+ millisecond: 1,
3
+ second: 1000,
4
+ minute: 60000,
5
+ hour: 3600000,
6
+ day: 24 * 3600000,
7
+ week: 7 * 24 * 3600000,
8
+ month: 28 * 24 * 3600000,
9
+ year: 364 * 24 * 3600000,
10
+ };
11
+ export const DATETIME_LABEL_FORMATS = {
12
+ millisecond: 'DD.MM.YY HH:mm:ss.SSS',
13
+ second: 'DD.MM.YY HH:mm:ss',
14
+ minute: 'DD.MM.YY HH:mm',
15
+ hour: 'DD.MM.YY HH:mm',
16
+ day: 'DD.MM.YY',
17
+ week: 'DD.MM.YY',
18
+ month: "MMM 'YY",
19
+ year: 'YYYY',
20
+ };
21
+ function getTimeUnit(range) {
22
+ const units = Object.keys(TIME_UNITS);
23
+ const index = units.findIndex((unit) => range < TIME_UNITS[unit]);
24
+ return index === -1 ? 'year' : units[index - 1];
25
+ }
26
+ export function getDefaultDateFormat(range) {
27
+ if (range) {
28
+ const unit = getTimeUnit(range);
29
+ if (unit in DATETIME_LABEL_FORMATS) {
30
+ return DATETIME_LABEL_FORMATS[unit];
31
+ }
32
+ }
33
+ return DATETIME_LABEL_FORMATS.day;
34
+ }
@@ -0,0 +1,4 @@
1
+ import { pieCenterText } from './pie-center-text';
2
+ export declare const CustomShapeRenderer: {
3
+ pieCenterText: typeof pieCenterText;
4
+ };
@@ -0,0 +1,4 @@
1
+ import { pieCenterText } from './pie-center-text';
2
+ export const CustomShapeRenderer = {
3
+ pieCenterText,
4
+ };
@@ -0,0 +1,7 @@
1
+ export declare function pieCenterText(text: string, options?: {
2
+ padding?: number;
3
+ }): ((args: {
4
+ series: {
5
+ innerRadius: number;
6
+ };
7
+ }) => Element | null) | undefined;
@@ -0,0 +1,23 @@
1
+ import { create } from 'd3-selection';
2
+ import get from 'lodash/get';
3
+ import { getLabelsSize } from '../chart/text';
4
+ const MAX_FONT_SIZE = 64;
5
+ export function pieCenterText(text, options) {
6
+ if (!text) {
7
+ return undefined;
8
+ }
9
+ const padding = get(options, 'padding', 12);
10
+ return function (args) {
11
+ let fontSize = MAX_FONT_SIZE;
12
+ const textSize = getLabelsSize({ labels: [text], style: { fontSize: `${fontSize}px` } });
13
+ fontSize = (fontSize * (args.series.innerRadius - padding) * 2) / textSize.maxWidth;
14
+ const container = create('svg:g');
15
+ container
16
+ .append('text')
17
+ .text(text)
18
+ .attr('text-anchor', 'middle')
19
+ .attr('alignment-baseline', 'middle')
20
+ .style('font-size', `${fontSize}px`);
21
+ return container.node();
22
+ };
23
+ }
@@ -0,0 +1,3 @@
1
+ export declare const CN_NAMESPACE = "gcharts-";
2
+ export declare const cn: import("@bem-react/classname").ClassNameInitilizer;
3
+ export declare const block: import("@bem-react/classname").ClassNameInitilizer;
@@ -0,0 +1,4 @@
1
+ import { withNaming } from '@bem-react/classname';
2
+ export const CN_NAMESPACE = 'gcharts-';
3
+ export const cn = withNaming({ e: '__', m: '_' });
4
+ export const block = withNaming({ n: CN_NAMESPACE, e: '__', m: '_' });
@@ -0,0 +1 @@
1
+ export declare const getD3Dispatcher: () => import("d3-dispatch").Dispatch<object>;
@@ -0,0 +1,4 @@
1
+ import { dispatch } from 'd3';
2
+ export const getD3Dispatcher = () => {
3
+ return dispatch('hover-shape', 'click-chart');
4
+ };
@@ -0,0 +1,5 @@
1
+ export * from './chart';
2
+ export * from './chart-ui';
3
+ export * from './cn';
4
+ export * from './d3-dispatcher';
5
+ export * from './misc';
@@ -0,0 +1,5 @@
1
+ export * from './chart';
2
+ export * from './chart-ui';
3
+ export * from './cn';
4
+ export * from './d3-dispatcher';
5
+ export * from './misc';
@@ -0,0 +1,2 @@
1
+ export declare const randomString: (length: number, chars: string) => string;
2
+ export declare const getUniqId: () => string;
@@ -0,0 +1,8 @@
1
+ export const randomString = (length, chars) => {
2
+ let result = '';
3
+ for (let i = length; i > 0; --i) {
4
+ result += chars[Math.floor(Math.random() * chars.length)];
5
+ }
6
+ return result;
7
+ };
8
+ export const getUniqId = () => `gravity-chart.${randomString(5, '0123456789abcdefghijklmnopqrstuvwxyz')}`;
@@ -0,0 +1,2 @@
1
+ import type { ChartData } from '../types';
2
+ export declare const validateData: (data?: ChartData) => void;
@@ -0,0 +1,220 @@
1
+ import get from 'lodash/get';
2
+ import isEmpty from 'lodash/isEmpty';
3
+ import { DEFAULT_AXIS_TYPE, SeriesType } from '../constants';
4
+ import { i18n } from '../i18n';
5
+ import { CHART_ERROR_CODE, ChartError } from '../libs';
6
+ const AVAILABLE_SERIES_TYPES = Object.values(SeriesType);
7
+ const validateXYSeries = (args) => {
8
+ const { series, xAxis, yAxis = [] } = args;
9
+ const yAxisIndex = get(series, 'yAxis', 0);
10
+ const seriesYAxis = yAxis[yAxisIndex];
11
+ if (yAxisIndex !== 0 && typeof seriesYAxis === 'undefined') {
12
+ throw new ChartError({
13
+ code: CHART_ERROR_CODE.INVALID_DATA,
14
+ message: i18n('error', 'label_invalid-y-axis-index', {
15
+ index: yAxisIndex,
16
+ }),
17
+ });
18
+ }
19
+ const xType = get(xAxis, 'type', DEFAULT_AXIS_TYPE);
20
+ const yType = get(seriesYAxis, 'type', DEFAULT_AXIS_TYPE);
21
+ series.data.forEach(({ x, y }) => {
22
+ switch (xType) {
23
+ case 'category': {
24
+ if (typeof x !== 'string' && typeof x !== 'number') {
25
+ throw new ChartError({
26
+ code: CHART_ERROR_CODE.INVALID_DATA,
27
+ message: i18n('error', 'label_invalid-axis-category-data-point', {
28
+ key: 'x',
29
+ seriesName: series.name,
30
+ }),
31
+ });
32
+ }
33
+ break;
34
+ }
35
+ case 'datetime': {
36
+ if (typeof x !== 'number') {
37
+ throw new ChartError({
38
+ code: CHART_ERROR_CODE.INVALID_DATA,
39
+ message: i18n('error', 'label_invalid-axis-datetime-data-point', {
40
+ key: 'x',
41
+ seriesName: series.name,
42
+ }),
43
+ });
44
+ }
45
+ break;
46
+ }
47
+ case 'linear': {
48
+ if (typeof x !== 'number' && x !== null) {
49
+ throw new ChartError({
50
+ code: CHART_ERROR_CODE.INVALID_DATA,
51
+ message: i18n('error', 'label_invalid-axis-linear-data-point', {
52
+ key: 'x',
53
+ seriesName: series.name,
54
+ }),
55
+ });
56
+ }
57
+ }
58
+ }
59
+ switch (yType) {
60
+ case 'category': {
61
+ if (typeof y !== 'string' && typeof y !== 'number') {
62
+ throw new ChartError({
63
+ code: CHART_ERROR_CODE.INVALID_DATA,
64
+ message: i18n('error', 'label_invalid-axis-category-data-point', {
65
+ key: 'y',
66
+ seriesName: series.name,
67
+ }),
68
+ });
69
+ }
70
+ break;
71
+ }
72
+ case 'datetime': {
73
+ if (typeof y !== 'number') {
74
+ throw new ChartError({
75
+ code: CHART_ERROR_CODE.INVALID_DATA,
76
+ message: i18n('error', 'label_invalid-axis-datetime-data-point', {
77
+ key: 'y',
78
+ seriesName: series.name,
79
+ }),
80
+ });
81
+ }
82
+ break;
83
+ }
84
+ case 'linear': {
85
+ if (typeof y !== 'number' && y !== null) {
86
+ throw new ChartError({
87
+ code: CHART_ERROR_CODE.INVALID_DATA,
88
+ message: i18n('error', 'label_invalid-axis-linear-data-point', {
89
+ key: 'y',
90
+ seriesName: series.name,
91
+ }),
92
+ });
93
+ }
94
+ }
95
+ }
96
+ });
97
+ };
98
+ const validatePieSeries = ({ series }) => {
99
+ series.data.forEach(({ value }) => {
100
+ if (typeof value !== 'number') {
101
+ throw new ChartError({
102
+ code: CHART_ERROR_CODE.INVALID_DATA,
103
+ message: i18n('error', 'label_invalid-pie-data-value'),
104
+ });
105
+ }
106
+ });
107
+ };
108
+ const validateStacking = ({ series }) => {
109
+ const availableStackingValues = ['normal', 'percent'];
110
+ if (series.stacking && !availableStackingValues.includes(series.stacking)) {
111
+ throw new ChartError({
112
+ code: CHART_ERROR_CODE.INVALID_DATA,
113
+ message: i18n('error', 'label_invalid-series-property', {
114
+ key: 'stacking',
115
+ values: availableStackingValues,
116
+ }),
117
+ });
118
+ }
119
+ };
120
+ const validateTreemapSeries = ({ series }) => {
121
+ const parentIds = {};
122
+ series.data.forEach((d) => {
123
+ if (d.parentId && !parentIds[d.parentId]) {
124
+ parentIds[d.parentId] = true;
125
+ }
126
+ });
127
+ series.data.forEach((d) => {
128
+ let idOrName = d.id;
129
+ if (!idOrName) {
130
+ idOrName = Array.isArray(d.name) ? d.name.join() : d.name;
131
+ }
132
+ if (parentIds[idOrName] && typeof d.value === 'number') {
133
+ throw new ChartError({
134
+ code: CHART_ERROR_CODE.INVALID_DATA,
135
+ message: i18n('error', 'label_invalid-treemap-redundant-value', {
136
+ id: d.id,
137
+ name: d.name,
138
+ }),
139
+ });
140
+ }
141
+ if (!parentIds[idOrName] && typeof d.value !== 'number') {
142
+ throw new ChartError({
143
+ code: CHART_ERROR_CODE.INVALID_DATA,
144
+ message: i18n('error', 'label_invalid-treemap-missing-value', {
145
+ id: d.id,
146
+ name: d.name,
147
+ }),
148
+ });
149
+ }
150
+ });
151
+ };
152
+ const validateSeries = (args) => {
153
+ const { series, xAxis, yAxis } = args;
154
+ if (!AVAILABLE_SERIES_TYPES.includes(series.type)) {
155
+ throw new ChartError({
156
+ code: CHART_ERROR_CODE.INVALID_DATA,
157
+ message: i18n('error', 'label_invalid-series-type', {
158
+ types: AVAILABLE_SERIES_TYPES.join(', '),
159
+ }),
160
+ });
161
+ }
162
+ switch (series.type) {
163
+ case 'area':
164
+ case 'bar-y':
165
+ case 'bar-x': {
166
+ validateXYSeries({ series, xAxis, yAxis });
167
+ validateStacking({ series });
168
+ break;
169
+ }
170
+ case 'line':
171
+ case 'scatter': {
172
+ validateXYSeries({ series, xAxis, yAxis });
173
+ break;
174
+ }
175
+ case 'pie': {
176
+ validatePieSeries({ series });
177
+ break;
178
+ }
179
+ case 'treemap': {
180
+ validateTreemapSeries({ series });
181
+ }
182
+ }
183
+ };
184
+ const countSeriesByType = (args) => {
185
+ const { series, type } = args;
186
+ let count = 0;
187
+ series.forEach((s) => {
188
+ if (s.type === type) {
189
+ count += 1;
190
+ }
191
+ });
192
+ return count;
193
+ };
194
+ export const validateData = (data) => {
195
+ if (isEmpty(data) || isEmpty(data.series) || isEmpty(data.series.data)) {
196
+ throw new ChartError({
197
+ code: CHART_ERROR_CODE.NO_DATA,
198
+ message: i18n('error', 'label_no-data'),
199
+ });
200
+ }
201
+ if (data.series.data.some((s) => isEmpty(s.data))) {
202
+ throw new ChartError({
203
+ code: CHART_ERROR_CODE.INVALID_DATA,
204
+ message: 'You should specify data for all series',
205
+ });
206
+ }
207
+ const treemapSeriesCount = countSeriesByType({
208
+ series: data.series.data,
209
+ type: SeriesType.Treemap,
210
+ });
211
+ if (treemapSeriesCount > 1) {
212
+ throw new ChartError({
213
+ code: CHART_ERROR_CODE.INVALID_DATA,
214
+ message: 'It looks like you are trying to define more than one "treemap" series.',
215
+ });
216
+ }
217
+ data.series.data.forEach((series) => {
218
+ validateSeries({ series, yAxis: data.yAxis, xAxis: data.xAxis });
219
+ });
220
+ };
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+ import type { ChartScale, PreparedAxis, PreparedSplit } from '../../hooks';
3
+ import './styles.css';
4
+ type Props = {
5
+ axis: PreparedAxis;
6
+ width: number;
7
+ height: number;
8
+ scale: ChartScale;
9
+ split: PreparedSplit;
10
+ };
11
+ export declare function getTitlePosition(args: {
12
+ axis: PreparedAxis;
13
+ width: number;
14
+ rowCount: number;
15
+ }): {
16
+ x: number;
17
+ y: number;
18
+ };
19
+ export declare const AxisX: React.NamedExoticComponent<Props>;
20
+ export {};