@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,108 @@
1
+ import React from 'react';
2
+ import { select } from 'd3';
3
+ import { block, formatAxisTickLabel, getAxisTitleRows, getClosestPointsRange, getMaxTickCount, getScaleTicks, getTicksCount, handleOverflowingText, } from '../../utils';
4
+ import { axisBottom } from '../../utils/chart/axis-generators';
5
+ import './styles.css';
6
+ const b = block('d3-axis');
7
+ function getLabelFormatter({ axis, scale }) {
8
+ const ticks = getScaleTicks(scale);
9
+ const tickStep = getClosestPointsRange(axis, ticks);
10
+ return (value) => {
11
+ if (!axis.labels.enabled) {
12
+ return '';
13
+ }
14
+ return formatAxisTickLabel({
15
+ axis,
16
+ value,
17
+ step: tickStep,
18
+ });
19
+ };
20
+ }
21
+ export function getTitlePosition(args) {
22
+ const { axis, width, rowCount } = args;
23
+ if (rowCount < 1) {
24
+ return { x: 0, y: 0 };
25
+ }
26
+ let x;
27
+ const y = axis.title.height / rowCount + axis.title.margin + axis.labels.height + axis.labels.margin;
28
+ switch (axis.title.align) {
29
+ case 'left': {
30
+ x = axis.title.width / 2;
31
+ break;
32
+ }
33
+ case 'right': {
34
+ x = width - axis.title.width / 2;
35
+ break;
36
+ }
37
+ case 'center': {
38
+ x = width / 2;
39
+ break;
40
+ }
41
+ }
42
+ return { x, y };
43
+ }
44
+ export const AxisX = React.memo(function AxisX(props) {
45
+ const { axis, width, height: totalHeight, scale, split } = props;
46
+ const ref = React.useRef(null);
47
+ React.useEffect(() => {
48
+ if (!ref.current) {
49
+ return;
50
+ }
51
+ let tickItems = [];
52
+ if (axis.grid.enabled) {
53
+ tickItems = new Array(split.plots.length || 1).fill(null).map((_, index) => {
54
+ var _a, _b;
55
+ const top = ((_a = split.plots[index]) === null || _a === void 0 ? void 0 : _a.top) || 0;
56
+ const height = ((_b = split.plots[index]) === null || _b === void 0 ? void 0 : _b.height) || totalHeight;
57
+ return [-top, -(top + height)];
58
+ });
59
+ }
60
+ const xAxisGenerator = axisBottom({
61
+ scale: scale,
62
+ ticks: {
63
+ items: tickItems,
64
+ labelFormat: getLabelFormatter({ axis, scale }),
65
+ labelsPaddings: axis.labels.padding,
66
+ labelsMargin: axis.labels.margin,
67
+ labelsStyle: axis.labels.style,
68
+ labelsMaxWidth: axis.labels.maxWidth,
69
+ labelsLineHeight: axis.labels.lineHeight,
70
+ count: getTicksCount({ axis, range: width }),
71
+ maxTickCount: getMaxTickCount({ axis, width }),
72
+ rotation: axis.labels.rotation,
73
+ },
74
+ domain: {
75
+ size: width,
76
+ color: axis.lineColor,
77
+ },
78
+ });
79
+ const svgElement = select(ref.current);
80
+ svgElement.selectAll('*').remove();
81
+ svgElement.call(xAxisGenerator).attr('class', b());
82
+ // add an axis header if necessary
83
+ if (axis.title.text) {
84
+ const titleRows = getAxisTitleRows({ axis, textMaxWidth: width });
85
+ svgElement
86
+ .append('text')
87
+ .attr('class', b('title'))
88
+ .attr('transform', () => {
89
+ const { x, y } = getTitlePosition({ axis, width, rowCount: titleRows.length });
90
+ return `translate(${x}, ${y})`;
91
+ })
92
+ .attr('font-size', axis.title.style.fontSize)
93
+ .attr('text-anchor', 'middle')
94
+ .selectAll('tspan')
95
+ .data(titleRows)
96
+ .join('tspan')
97
+ .attr('x', 0)
98
+ .attr('y', (d) => d.y)
99
+ .text((d) => d.text)
100
+ .each((_d, index, nodes) => {
101
+ if (index === axis.title.maxRowCount - 1) {
102
+ handleOverflowingText(nodes[index], width);
103
+ }
104
+ });
105
+ }
106
+ }, [axis, width, totalHeight, scale, split]);
107
+ return React.createElement("g", { ref: ref });
108
+ });
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import type { ChartScale, PreparedAxis, PreparedSplit } from '../../hooks';
3
+ import './styles.css';
4
+ type Props = {
5
+ axes: PreparedAxis[];
6
+ scale: ChartScale[];
7
+ width: number;
8
+ height: number;
9
+ split: PreparedSplit;
10
+ };
11
+ export declare const AxisY: (props: Props) => React.JSX.Element;
12
+ export {};
@@ -0,0 +1,199 @@
1
+ import React from 'react';
2
+ import { axisLeft, axisRight, line, select } from 'd3';
3
+ import { block, calculateCos, calculateSin, formatAxisTickLabel, getAxisHeight, getAxisTitleRows, getClosestPointsRange, getScaleTicks, getTicksCount, handleOverflowingText, parseTransformStyle, setEllipsisForOverflowTexts, wrapText, } from '../../utils';
4
+ import './styles.css';
5
+ const b = block('d3-axis');
6
+ function transformLabel(args) {
7
+ const { node, axis } = args;
8
+ let topOffset = axis.labels.lineHeight / 2;
9
+ let leftOffset = axis.labels.margin;
10
+ if (axis.position === 'left') {
11
+ leftOffset = leftOffset * -1;
12
+ }
13
+ if (axis.labels.rotation) {
14
+ if (axis.labels.rotation > 0) {
15
+ leftOffset -= axis.labels.lineHeight * calculateSin(axis.labels.rotation);
16
+ topOffset = axis.labels.lineHeight * calculateCos(axis.labels.rotation);
17
+ if (axis.labels.rotation % 360 === 90) {
18
+ topOffset = ((node === null || node === void 0 ? void 0 : node.getBoundingClientRect().width) || 0) / 2;
19
+ }
20
+ }
21
+ else {
22
+ topOffset = 0;
23
+ if (axis.labels.rotation % 360 === -90) {
24
+ topOffset = -((node === null || node === void 0 ? void 0 : node.getBoundingClientRect().width) || 0) / 2;
25
+ }
26
+ }
27
+ return `translate(${leftOffset}px, ${topOffset}px) rotate(${axis.labels.rotation}deg)`;
28
+ }
29
+ return `translate(${leftOffset}px, ${topOffset}px)`;
30
+ }
31
+ function getAxisGenerator(args) {
32
+ const { preparedAxis, axisGenerator: generator, width, height, scale } = args;
33
+ const tickSize = preparedAxis.grid.enabled ? width * -1 : 0;
34
+ const step = getClosestPointsRange(preparedAxis, getScaleTicks(scale));
35
+ let axisGenerator = generator
36
+ .tickSize(tickSize)
37
+ .tickPadding(preparedAxis.labels.margin)
38
+ .tickFormat((value) => {
39
+ if (!preparedAxis.labels.enabled) {
40
+ return '';
41
+ }
42
+ return formatAxisTickLabel({
43
+ axis: preparedAxis,
44
+ value,
45
+ step,
46
+ });
47
+ });
48
+ const ticksCount = getTicksCount({ axis: preparedAxis, range: height });
49
+ if (ticksCount) {
50
+ axisGenerator = axisGenerator.ticks(ticksCount);
51
+ }
52
+ return axisGenerator;
53
+ }
54
+ function getTitlePosition(args) {
55
+ const { axis, axisHeight, rowCount } = args;
56
+ if (rowCount < 1) {
57
+ return { x: 0, y: 0 };
58
+ }
59
+ const x = -(axis.title.height -
60
+ axis.title.height / rowCount +
61
+ axis.title.margin +
62
+ axis.labels.margin +
63
+ axis.labels.width);
64
+ let y;
65
+ switch (axis.title.align) {
66
+ case 'left': {
67
+ y = axisHeight - axis.title.width / 2;
68
+ break;
69
+ }
70
+ case 'right': {
71
+ y = axis.title.width / 2;
72
+ break;
73
+ }
74
+ case 'center': {
75
+ y = axisHeight / 2;
76
+ break;
77
+ }
78
+ }
79
+ return { x, y };
80
+ }
81
+ export const AxisY = (props) => {
82
+ const { axes, width, height: totalHeight, scale, split } = props;
83
+ const height = getAxisHeight({ split, boundsHeight: totalHeight });
84
+ const ref = React.useRef(null);
85
+ React.useEffect(() => {
86
+ if (!ref.current) {
87
+ return;
88
+ }
89
+ const svgElement = select(ref.current);
90
+ svgElement.selectAll('*').remove();
91
+ const axisSelection = svgElement
92
+ .selectAll('axis')
93
+ .data(axes)
94
+ .join('g')
95
+ .attr('class', b())
96
+ .style('transform', (d) => {
97
+ var _a;
98
+ const top = ((_a = split.plots[d.plotIndex]) === null || _a === void 0 ? void 0 : _a.top) || 0;
99
+ if (d.position === 'left') {
100
+ return `translate(0, ${top}px)`;
101
+ }
102
+ return `translate(${width}px, 0)`;
103
+ });
104
+ axisSelection.each((d, index, node) => {
105
+ const seriesScale = scale[index];
106
+ const axisItem = select(node[index]);
107
+ const yAxisGenerator = getAxisGenerator({
108
+ axisGenerator: d.position === 'left'
109
+ ? axisLeft(seriesScale)
110
+ : axisRight(seriesScale),
111
+ preparedAxis: d,
112
+ height,
113
+ width,
114
+ scale: seriesScale,
115
+ });
116
+ yAxisGenerator(axisItem);
117
+ if (d.labels.enabled) {
118
+ const tickTexts = axisItem
119
+ .selectAll('.tick text')
120
+ // The offset must be applied before the labels are rotated.
121
+ // Therefore, we reset the values and make an offset in transform attribute.
122
+ // FIXME: give up axisLeft(d3) and switch to our own generation method
123
+ .attr('x', null)
124
+ .attr('dy', null)
125
+ .style('font-size', d.labels.style.fontSize)
126
+ .style('transform', function () {
127
+ return transformLabel({ node: this, axis: d });
128
+ });
129
+ const textMaxWidth = !d.labels.rotation || Math.abs(d.labels.rotation) % 360 !== 90
130
+ ? d.labels.maxWidth
131
+ : (height - d.labels.padding * (tickTexts.size() - 1)) / tickTexts.size();
132
+ tickTexts.call(setEllipsisForOverflowTexts, textMaxWidth);
133
+ }
134
+ // remove overlapping ticks
135
+ // Note: this method do not prepared for rotated labels
136
+ if (!d.labels.rotation) {
137
+ let elementY = 0;
138
+ axisItem
139
+ .selectAll('.tick')
140
+ .filter(function (_d, tickIndex) {
141
+ const tickNode = this;
142
+ const r = tickNode.getBoundingClientRect();
143
+ if (r.bottom > elementY && tickIndex !== 0) {
144
+ return true;
145
+ }
146
+ elementY = r.top - d.labels.padding;
147
+ return false;
148
+ })
149
+ .remove();
150
+ }
151
+ return axisItem;
152
+ });
153
+ axisSelection
154
+ .select('.domain')
155
+ .attr('d', () => {
156
+ const points = [
157
+ [0, 0],
158
+ [0, height],
159
+ ];
160
+ return line()(points);
161
+ })
162
+ .style('stroke', (d) => d.lineColor || '');
163
+ svgElement.selectAll('.tick').each((_d, index, nodes) => {
164
+ const tickNode = select(nodes[index]);
165
+ if (parseTransformStyle(tickNode.attr('transform')).y === height) {
166
+ // Remove stroke from tick that has the same y coordinate like domain
167
+ tickNode.select('line').style('stroke', 'none');
168
+ }
169
+ });
170
+ axisSelection
171
+ .append('text')
172
+ .attr('class', b('title'))
173
+ .attr('text-anchor', 'middle')
174
+ .attr('font-size', (d) => d.title.style.fontSize)
175
+ .attr('transform', (d) => {
176
+ const titleRows = wrapText({
177
+ text: d.title.text,
178
+ style: d.title.style,
179
+ width: height,
180
+ });
181
+ const rowCount = Math.min(titleRows.length, d.title.maxRowCount);
182
+ const { x, y } = getTitlePosition({ axis: d, axisHeight: height, rowCount });
183
+ const angle = d.position === 'left' ? -90 : 90;
184
+ return `translate(${x}, ${y}) rotate(${angle})`;
185
+ })
186
+ .selectAll('tspan')
187
+ .data((d) => getAxisTitleRows({ axis: d, textMaxWidth: height }))
188
+ .join('tspan')
189
+ .attr('x', 0)
190
+ .attr('y', (d) => d.y)
191
+ .text((d) => d.text)
192
+ .each((_d, index, nodes) => {
193
+ if (index === nodes.length - 1) {
194
+ handleOverflowingText(nodes[index], height);
195
+ }
196
+ });
197
+ }, [axes, width, height, scale, split]);
198
+ return React.createElement("g", { ref: ref, className: b('container') });
199
+ };
@@ -0,0 +1,2 @@
1
+ export * from './AxisX';
2
+ export * from './AxisY';
@@ -0,0 +1,2 @@
1
+ export * from './AxisX';
2
+ export * from './AxisY';
@@ -0,0 +1,17 @@
1
+ .gcharts-d3-axis .domain {
2
+ stroke: var(--g-color-line-generic-active);
3
+ }
4
+ .gcharts-d3-axis .tick text {
5
+ color: var(--g-color-text-secondary);
6
+ alignment-baseline: after-edge;
7
+ }
8
+ .gcharts-d3-axis .tick line, .gcharts-d3-axis .tick path {
9
+ stroke: var(--g-color-line-generic);
10
+ }
11
+ .gcharts-d3-axis__title {
12
+ alignment-baseline: after-edge;
13
+ fill: var(--g-color-text-secondary);
14
+ }
15
+ .gcharts-d3-axis__title tspan {
16
+ alignment-baseline: after-edge;
17
+ }
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import type { ChartData } from '../../types';
3
+ import './styles.css';
4
+ type Props = {
5
+ width: number;
6
+ height: number;
7
+ data: ChartData;
8
+ };
9
+ export declare const ChartInner: (props: Props) => React.JSX.Element;
10
+ export {};
@@ -0,0 +1,143 @@
1
+ import React from 'react';
2
+ import { pointer } from 'd3';
3
+ import throttle from 'lodash/throttle';
4
+ import { useAxisScales, useChartDimensions, useChartOptions, useSeries, useShapes, } from '../../hooks';
5
+ import { getYAxisWidth } from '../../hooks/useChartDimensions/utils';
6
+ import { getPreparedXAxis } from '../../hooks/useChartOptions/x-axis';
7
+ import { getPreparedYAxis } from '../../hooks/useChartOptions/y-axis';
8
+ import { useSplit } from '../../hooks/useSplit';
9
+ import { block, getD3Dispatcher } from '../../utils';
10
+ import { getClosestPoints } from '../../utils/chart/get-closest-data';
11
+ import { AxisX, AxisY } from '../Axis';
12
+ import { Legend } from '../Legend';
13
+ import { PlotTitle } from '../PlotTitle';
14
+ import { Title } from '../Title';
15
+ import { Tooltip } from '../Tooltip';
16
+ import './styles.css';
17
+ const b = block('d3');
18
+ const THROTTLE_DELAY = 50;
19
+ export const ChartInner = (props) => {
20
+ var _a, _b;
21
+ const { width, height, data } = props;
22
+ const svgRef = React.useRef(null);
23
+ const htmlLayerRef = React.useRef(null);
24
+ const dispatcher = React.useMemo(() => {
25
+ return getD3Dispatcher();
26
+ }, []);
27
+ const { chart, title, tooltip } = useChartOptions({
28
+ data,
29
+ });
30
+ const xAxis = React.useMemo(() => getPreparedXAxis({ xAxis: data.xAxis, width, series: data.series.data }), [data, width]);
31
+ const yAxis = React.useMemo(() => getPreparedYAxis({
32
+ series: data.series.data,
33
+ yAxis: data.yAxis,
34
+ height,
35
+ }), [data, height]);
36
+ const { legendItems, legendConfig, preparedSeries, preparedSeriesOptions, preparedLegend, handleLegendItemClick, } = useSeries({
37
+ chartWidth: width,
38
+ chartHeight: height,
39
+ chartMargin: chart.margin,
40
+ series: data.series,
41
+ legend: data.legend,
42
+ preparedYAxis: yAxis,
43
+ });
44
+ const { boundsWidth, boundsHeight } = useChartDimensions({
45
+ width,
46
+ height,
47
+ margin: chart.margin,
48
+ preparedLegend,
49
+ preparedXAxis: xAxis,
50
+ preparedYAxis: yAxis,
51
+ preparedSeries: preparedSeries,
52
+ });
53
+ const preparedSplit = useSplit({ split: data.split, boundsHeight, chartWidth: width });
54
+ const { xScale, yScale } = useAxisScales({
55
+ boundsWidth,
56
+ boundsHeight,
57
+ series: preparedSeries,
58
+ xAxis,
59
+ yAxis,
60
+ split: preparedSplit,
61
+ });
62
+ const { shapes, shapesData } = useShapes({
63
+ boundsWidth,
64
+ boundsHeight,
65
+ dispatcher,
66
+ series: preparedSeries,
67
+ seriesOptions: preparedSeriesOptions,
68
+ xAxis,
69
+ xScale,
70
+ yAxis,
71
+ yScale,
72
+ split: preparedSplit,
73
+ htmlLayout: htmlLayerRef.current,
74
+ });
75
+ const clickHandler = (_b = (_a = data.chart) === null || _a === void 0 ? void 0 : _a.events) === null || _b === void 0 ? void 0 : _b.click;
76
+ React.useEffect(() => {
77
+ if (clickHandler) {
78
+ dispatcher.on('click-chart', clickHandler);
79
+ }
80
+ return () => {
81
+ dispatcher.on('click-chart', null);
82
+ };
83
+ }, [dispatcher, clickHandler]);
84
+ const boundsOffsetTop = chart.margin.top;
85
+ // We only need to consider the width of the first left axis
86
+ const boundsOffsetLeft = chart.margin.left + getYAxisWidth(yAxis[0]);
87
+ const isOutsideBounds = React.useCallback((x, y) => {
88
+ return x < 0 || x > boundsWidth || y < 0 || y > boundsHeight;
89
+ }, [boundsHeight, boundsWidth]);
90
+ const handleMouseMove = (event) => {
91
+ const [pointerX, pointerY] = pointer(event, svgRef.current);
92
+ const x = pointerX - boundsOffsetLeft;
93
+ const y = pointerY - boundsOffsetTop;
94
+ if (isOutsideBounds(x, y)) {
95
+ dispatcher.call('hover-shape', {}, undefined);
96
+ return;
97
+ }
98
+ const closest = getClosestPoints({
99
+ position: [x, y],
100
+ shapesData,
101
+ });
102
+ dispatcher.call('hover-shape', event.target, closest, [pointerX, pointerY]);
103
+ };
104
+ const throttledHandleMouseMove = throttle(handleMouseMove, THROTTLE_DELAY);
105
+ const handleMouseLeave = () => {
106
+ throttledHandleMouseMove.cancel();
107
+ dispatcher.call('hover-shape', {}, undefined);
108
+ };
109
+ const handleChartClick = React.useCallback((event) => {
110
+ const [pointerX, pointerY] = pointer(event, svgRef.current);
111
+ const x = pointerX - boundsOffsetLeft;
112
+ const y = pointerY - boundsOffsetTop;
113
+ if (isOutsideBounds(x, y)) {
114
+ return;
115
+ }
116
+ const items = getClosestPoints({
117
+ position: [x, y],
118
+ shapesData,
119
+ });
120
+ const selected = items === null || items === void 0 ? void 0 : items.find((item) => item.closest);
121
+ if (!selected) {
122
+ return;
123
+ }
124
+ dispatcher.call('click-chart', undefined, { point: selected.data, series: selected.series }, event);
125
+ }, [boundsOffsetLeft, boundsOffsetTop, dispatcher, isOutsideBounds, shapesData]);
126
+ return (React.createElement(React.Fragment, null,
127
+ React.createElement("svg", { ref: svgRef, className: b(), width: width, height: height, onMouseMove: throttledHandleMouseMove, onMouseLeave: handleMouseLeave, onClick: handleChartClick },
128
+ title && React.createElement(Title, Object.assign({}, title, { chartWidth: width })),
129
+ React.createElement("g", { transform: `translate(0, ${boundsOffsetTop})` }, preparedSplit.plots.map((plot, index) => {
130
+ return React.createElement(PlotTitle, { key: `plot-${index}`, title: plot.title });
131
+ })),
132
+ React.createElement("g", { width: boundsWidth, height: boundsHeight, transform: `translate(${[boundsOffsetLeft, boundsOffsetTop].join(',')})` },
133
+ xScale && (yScale === null || yScale === void 0 ? void 0 : yScale.length) && (React.createElement(React.Fragment, null,
134
+ React.createElement(AxisY, { axes: yAxis, width: boundsWidth, height: boundsHeight, scale: yScale, split: preparedSplit }),
135
+ React.createElement("g", { transform: `translate(0, ${boundsHeight})` },
136
+ React.createElement(AxisX, { axis: xAxis, width: boundsWidth, height: boundsHeight, scale: xScale, split: preparedSplit })))),
137
+ shapes),
138
+ preparedLegend.enabled && (React.createElement(Legend, { chartSeries: preparedSeries, boundsWidth: boundsWidth, legend: preparedLegend, items: legendItems, config: legendConfig, onItemClick: handleLegendItemClick }))),
139
+ React.createElement("div", { className: b('html-layer'), ref: htmlLayerRef, style: {
140
+ transform: `translate(${boundsOffsetLeft}px, ${boundsOffsetTop}px)`,
141
+ } }),
142
+ React.createElement(Tooltip, { dispatcher: dispatcher, tooltip: tooltip, svgContainer: svgRef.current, xAxis: xAxis, yAxis: yAxis[0] })));
143
+ };
@@ -0,0 +1,10 @@
1
+ .gcharts-d3 {
2
+ --d3-data-labels: var(--g-color-text-secondary);
3
+ position: absolute;
4
+ }
5
+ .gcharts-d3__html-layer {
6
+ display: contents;
7
+ }
8
+ .gcharts-d3__html-layer > * {
9
+ transform: inherit;
10
+ }
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import type { LegendConfig, LegendItem, OnLegendItemClick, PreparedLegend, PreparedSeries } from '../../hooks';
3
+ import './styles.css';
4
+ type Props = {
5
+ boundsWidth: number;
6
+ chartSeries: PreparedSeries[];
7
+ legend: PreparedLegend;
8
+ items: LegendItem[][];
9
+ config: LegendConfig;
10
+ onItemClick: OnLegendItemClick;
11
+ };
12
+ export declare const Legend: (props: Props) => React.JSX.Element;
13
+ export {};