@mui/x-charts 6.0.0-alpha.1 → 6.0.0-alpha.10

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 (300) hide show
  1. package/BarChart/BarChart.d.ts +20 -6
  2. package/BarChart/BarChart.js +107 -34
  3. package/BarChart/BarElement.d.ts +22 -0
  4. package/BarChart/BarElement.js +21 -10
  5. package/BarChart/BarPlot.d.ts +14 -1
  6. package/BarChart/BarPlot.js +86 -23
  7. package/BarChart/extremums.js +19 -3
  8. package/BarChart/formatter.js +26 -13
  9. package/BarChart/legend.d.ts +3 -0
  10. package/BarChart/legend.js +20 -0
  11. package/CHANGELOG.md +835 -108
  12. package/ChartContainer/index.d.ts +3 -1
  13. package/ChartContainer/index.js +13 -6
  14. package/ChartsAxis/ChartsAxis.d.ts +15 -5
  15. package/ChartsAxis/ChartsAxis.js +55 -10
  16. package/ChartsAxisHighlight/ChartsAxisHighlight.d.ts +3 -2
  17. package/ChartsAxisHighlight/ChartsAxisHighlight.js +14 -5
  18. package/ChartsLegend/ChartsLegend.d.ts +28 -1
  19. package/ChartsLegend/ChartsLegend.js +53 -17
  20. package/ChartsLegend/utils.d.ts +1 -1
  21. package/ChartsLegend/utils.js +12 -1
  22. package/ChartsTooltip/ChartsAxisTooltipContent.js +15 -11
  23. package/ChartsTooltip/ChartsItemTooltipContent.js +11 -2
  24. package/ChartsTooltip/ChartsTooltipTable.d.ts +2 -9
  25. package/ChartsXAxis/ChartsXAxis.js +44 -9
  26. package/ChartsYAxis/ChartsYAxis.js +44 -9
  27. package/LineChart/AreaElement.d.ts +23 -1
  28. package/LineChart/AreaElement.js +31 -11
  29. package/LineChart/AreaPlot.d.ts +14 -1
  30. package/LineChart/AreaPlot.js +32 -5
  31. package/LineChart/LineChart.d.ts +26 -6
  32. package/LineChart/LineChart.js +99 -24
  33. package/LineChart/LineElement.d.ts +23 -1
  34. package/LineChart/LineElement.js +31 -10
  35. package/LineChart/LineHighlightElement.d.ts +21 -0
  36. package/LineChart/LineHighlightElement.js +79 -0
  37. package/LineChart/LineHighlightPlot.d.ts +25 -0
  38. package/LineChart/LineHighlightPlot.js +99 -0
  39. package/LineChart/LinePlot.d.ts +14 -1
  40. package/LineChart/LinePlot.js +38 -6
  41. package/LineChart/MarkElement.d.ts +1 -1
  42. package/LineChart/MarkElement.js +2 -5
  43. package/LineChart/MarkPlot.d.ts +24 -1
  44. package/LineChart/MarkPlot.js +58 -15
  45. package/LineChart/extremums.js +2 -2
  46. package/LineChart/formatter.js +23 -12
  47. package/LineChart/index.d.ts +2 -0
  48. package/LineChart/index.js +20 -0
  49. package/LineChart/legend.d.ts +3 -0
  50. package/LineChart/legend.js +20 -0
  51. package/PieChart/PieArc.d.ts +36 -0
  52. package/PieChart/PieArc.js +128 -0
  53. package/PieChart/PieArcLabel.d.ts +36 -0
  54. package/PieChart/PieArcLabel.js +112 -0
  55. package/PieChart/PieChart.d.ts +32 -0
  56. package/PieChart/PieChart.js +339 -0
  57. package/PieChart/PiePlot.d.ts +28 -0
  58. package/PieChart/PiePlot.js +121 -0
  59. package/PieChart/formatter.d.ts +3 -0
  60. package/PieChart/formatter.js +49 -0
  61. package/PieChart/index.d.ts +4 -0
  62. package/PieChart/index.js +47 -0
  63. package/PieChart/legend.d.ts +3 -0
  64. package/PieChart/legend.js +19 -0
  65. package/PieChart/package.json +6 -0
  66. package/README.md +7 -7
  67. package/ResponsiveChartContainer/index.d.ts +1 -1
  68. package/ResponsiveChartContainer/index.js +24 -11
  69. package/ScatterChart/Scatter.d.ts +1 -1
  70. package/ScatterChart/Scatter.js +40 -54
  71. package/ScatterChart/ScatterChart.d.ts +19 -6
  72. package/ScatterChart/ScatterChart.js +75 -21
  73. package/ScatterChart/ScatterPlot.d.ts +24 -1
  74. package/ScatterChart/ScatterPlot.js +28 -4
  75. package/ScatterChart/legend.d.ts +3 -0
  76. package/ScatterChart/legend.js +20 -0
  77. package/SparkLineChart/SparkLineChart.d.ts +74 -0
  78. package/SparkLineChart/SparkLineChart.js +213 -0
  79. package/SparkLineChart/index.d.ts +1 -0
  80. package/SparkLineChart/index.js +12 -0
  81. package/SparkLineChart/package.json +6 -0
  82. package/colorPalettes/colorPalettes.js +2 -2
  83. package/context/CartesianContextProvider.d.ts +3 -1
  84. package/context/CartesianContextProvider.js +81 -34
  85. package/context/DrawingProvider.d.ts +1 -1
  86. package/context/DrawingProvider.js +1 -1
  87. package/context/SeriesContextProvider.d.ts +3 -2
  88. package/context/SeriesContextProvider.js +16 -4
  89. package/esm/BarChart/BarChart.js +109 -34
  90. package/esm/BarChart/BarElement.js +21 -11
  91. package/esm/BarChart/BarPlot.js +89 -24
  92. package/esm/BarChart/extremums.js +18 -2
  93. package/esm/BarChart/formatter.js +26 -13
  94. package/esm/BarChart/legend.js +13 -0
  95. package/esm/ChartContainer/index.js +10 -5
  96. package/esm/ChartsAxis/ChartsAxis.js +55 -10
  97. package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +14 -5
  98. package/esm/ChartsLegend/ChartsLegend.js +51 -14
  99. package/esm/ChartsLegend/utils.js +11 -1
  100. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +15 -11
  101. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +11 -3
  102. package/esm/ChartsXAxis/ChartsXAxis.js +45 -9
  103. package/esm/ChartsYAxis/ChartsYAxis.js +45 -9
  104. package/esm/LineChart/AreaElement.js +31 -11
  105. package/esm/LineChart/AreaPlot.js +33 -5
  106. package/esm/LineChart/LineChart.js +100 -23
  107. package/esm/LineChart/LineElement.js +31 -11
  108. package/esm/LineChart/LineHighlightElement.js +68 -0
  109. package/esm/LineChart/LineHighlightPlot.js +92 -0
  110. package/esm/LineChart/LinePlot.js +45 -9
  111. package/esm/LineChart/MarkElement.js +2 -5
  112. package/esm/LineChart/MarkPlot.js +59 -15
  113. package/esm/LineChart/extremums.js +2 -2
  114. package/esm/LineChart/formatter.js +23 -13
  115. package/esm/LineChart/index.js +3 -1
  116. package/esm/LineChart/legend.js +13 -0
  117. package/esm/PieChart/PieArc.js +117 -0
  118. package/esm/PieChart/PieArcLabel.js +100 -0
  119. package/esm/PieChart/PieChart.js +332 -0
  120. package/esm/PieChart/PiePlot.js +117 -0
  121. package/esm/PieChart/formatter.js +48 -0
  122. package/esm/PieChart/index.js +4 -0
  123. package/esm/PieChart/legend.js +12 -0
  124. package/esm/ResponsiveChartContainer/index.js +22 -10
  125. package/esm/ScatterChart/Scatter.js +40 -54
  126. package/esm/ScatterChart/ScatterChart.js +73 -20
  127. package/esm/ScatterChart/ScatterPlot.js +29 -4
  128. package/esm/ScatterChart/legend.js +13 -0
  129. package/esm/SparkLineChart/SparkLineChart.js +205 -0
  130. package/esm/SparkLineChart/index.js +1 -0
  131. package/esm/colorPalettes/colorPalettes.js +2 -2
  132. package/esm/context/CartesianContextProvider.js +81 -32
  133. package/esm/context/DrawingProvider.js +1 -1
  134. package/esm/context/SeriesContextProvider.js +16 -4
  135. package/esm/hooks/index.js +2 -0
  136. package/esm/hooks/useAxisEvents.js +31 -43
  137. package/esm/hooks/useDrawingArea.js +16 -0
  138. package/esm/hooks/useScale.js +19 -21
  139. package/esm/hooks/useTicks.js +35 -19
  140. package/esm/index.js +3 -0
  141. package/esm/internals/components/AxisSharedComponents.js +10 -10
  142. package/esm/internals/defaultizeColor.js +7 -0
  143. package/esm/internals/getScale.js +17 -0
  144. package/esm/internals/isBandScale.js +3 -0
  145. package/esm/models/axis.js +6 -1
  146. package/esm/models/index.js +3 -1
  147. package/esm/models/seriesType/index.js +1 -8
  148. package/hooks/index.d.ts +2 -0
  149. package/hooks/index.js +27 -0
  150. package/hooks/package.json +6 -0
  151. package/hooks/useAxisEvents.js +31 -43
  152. package/hooks/useDrawingArea.d.ts +6 -0
  153. package/hooks/useDrawingArea.js +24 -0
  154. package/hooks/useScale.d.ts +3 -6
  155. package/hooks/useScale.js +24 -24
  156. package/hooks/useTicks.d.ts +21 -6
  157. package/hooks/useTicks.js +28 -15
  158. package/index.d.ts +3 -0
  159. package/index.js +34 -1
  160. package/internals/components/AxisSharedComponents.d.ts +4 -4
  161. package/internals/components/AxisSharedComponents.js +15 -15
  162. package/internals/defaultizeColor.d.ts +42 -2
  163. package/internals/defaultizeColor.js +7 -0
  164. package/internals/getScale.d.ts +2 -0
  165. package/internals/getScale.js +23 -0
  166. package/internals/isBandScale.d.ts +3 -0
  167. package/internals/isBandScale.js +9 -0
  168. package/legacy/BarChart/BarChart.js +114 -39
  169. package/legacy/BarChart/BarElement.js +20 -10
  170. package/legacy/BarChart/BarPlot.js +89 -26
  171. package/legacy/BarChart/extremums.js +22 -2
  172. package/legacy/BarChart/formatter.js +26 -11
  173. package/legacy/BarChart/legend.js +15 -0
  174. package/legacy/ChartContainer/index.js +10 -5
  175. package/legacy/ChartsAxis/ChartsAxis.js +55 -10
  176. package/legacy/ChartsAxisHighlight/ChartsAxisHighlight.js +14 -5
  177. package/legacy/ChartsLegend/ChartsLegend.js +50 -15
  178. package/legacy/ChartsLegend/utils.js +12 -6
  179. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +17 -11
  180. package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +10 -3
  181. package/legacy/ChartsXAxis/ChartsXAxis.js +45 -9
  182. package/legacy/ChartsYAxis/ChartsYAxis.js +45 -9
  183. package/legacy/LineChart/AreaElement.js +30 -10
  184. package/legacy/LineChart/AreaPlot.js +31 -5
  185. package/legacy/LineChart/LineChart.js +98 -23
  186. package/legacy/LineChart/LineElement.js +30 -10
  187. package/legacy/LineChart/LineHighlightElement.js +67 -0
  188. package/legacy/LineChart/LineHighlightPlot.js +85 -0
  189. package/legacy/LineChart/LinePlot.js +38 -6
  190. package/legacy/LineChart/MarkElement.js +2 -5
  191. package/legacy/LineChart/MarkPlot.js +49 -8
  192. package/legacy/LineChart/extremums.js +3 -3
  193. package/legacy/LineChart/formatter.js +23 -11
  194. package/legacy/LineChart/index.js +3 -1
  195. package/legacy/LineChart/legend.js +15 -0
  196. package/legacy/PieChart/PieArc.js +118 -0
  197. package/legacy/PieChart/PieArcLabel.js +100 -0
  198. package/legacy/PieChart/PieChart.js +344 -0
  199. package/legacy/PieChart/PiePlot.js +112 -0
  200. package/legacy/PieChart/formatter.js +55 -0
  201. package/legacy/PieChart/index.js +4 -0
  202. package/legacy/PieChart/legend.js +16 -0
  203. package/legacy/ResponsiveChartContainer/index.js +20 -10
  204. package/legacy/ScatterChart/Scatter.js +36 -47
  205. package/legacy/ScatterChart/ScatterChart.js +73 -20
  206. package/legacy/ScatterChart/ScatterPlot.js +27 -4
  207. package/legacy/ScatterChart/legend.js +15 -0
  208. package/legacy/SparkLineChart/SparkLineChart.js +211 -0
  209. package/legacy/SparkLineChart/index.js +1 -0
  210. package/legacy/colorPalettes/colorPalettes.js +2 -2
  211. package/legacy/context/CartesianContextProvider.js +90 -33
  212. package/legacy/context/DrawingProvider.js +1 -1
  213. package/legacy/context/SeriesContextProvider.js +17 -5
  214. package/legacy/hooks/index.js +2 -0
  215. package/legacy/hooks/useAxisEvents.js +31 -42
  216. package/legacy/hooks/useDrawingArea.js +17 -0
  217. package/legacy/hooks/useScale.js +17 -21
  218. package/legacy/hooks/useTicks.js +35 -22
  219. package/legacy/index.js +4 -1
  220. package/legacy/internals/components/AxisSharedComponents.js +10 -10
  221. package/legacy/internals/defaultizeColor.js +9 -0
  222. package/legacy/internals/getScale.js +17 -0
  223. package/legacy/internals/isBandScale.js +3 -0
  224. package/legacy/models/axis.js +6 -1
  225. package/legacy/models/index.js +3 -1
  226. package/legacy/models/seriesType/index.js +1 -8
  227. package/models/axis.d.ts +59 -15
  228. package/models/axis.js +9 -1
  229. package/models/index.d.ts +2 -0
  230. package/models/index.js +11 -0
  231. package/models/seriesType/bar.d.ts +14 -2
  232. package/models/seriesType/common.d.ts +2 -2
  233. package/models/seriesType/config.d.ts +33 -3
  234. package/models/seriesType/index.d.ts +7 -3
  235. package/models/seriesType/index.js +11 -0
  236. package/models/seriesType/line.d.ts +42 -2
  237. package/models/seriesType/pie.d.ts +103 -3
  238. package/models/seriesType/scatter.d.ts +1 -1
  239. package/modern/BarChart/BarChart.js +106 -34
  240. package/modern/BarChart/BarElement.js +20 -11
  241. package/modern/BarChart/BarPlot.js +88 -23
  242. package/modern/BarChart/extremums.js +18 -2
  243. package/modern/BarChart/formatter.js +26 -13
  244. package/modern/BarChart/legend.js +13 -0
  245. package/modern/ChartContainer/index.js +10 -5
  246. package/modern/ChartsAxis/ChartsAxis.js +55 -10
  247. package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +14 -5
  248. package/modern/ChartsLegend/ChartsLegend.js +50 -14
  249. package/modern/ChartsLegend/utils.js +11 -1
  250. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +15 -11
  251. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +11 -2
  252. package/modern/ChartsXAxis/ChartsXAxis.js +44 -9
  253. package/modern/ChartsYAxis/ChartsYAxis.js +44 -9
  254. package/modern/LineChart/AreaElement.js +30 -11
  255. package/modern/LineChart/AreaPlot.js +33 -5
  256. package/modern/LineChart/LineChart.js +97 -23
  257. package/modern/LineChart/LineElement.js +30 -11
  258. package/modern/LineChart/LineHighlightElement.js +68 -0
  259. package/modern/LineChart/LineHighlightPlot.js +91 -0
  260. package/modern/LineChart/LinePlot.js +39 -6
  261. package/modern/LineChart/MarkElement.js +2 -5
  262. package/modern/LineChart/MarkPlot.js +58 -15
  263. package/modern/LineChart/extremums.js +2 -2
  264. package/modern/LineChart/formatter.js +23 -13
  265. package/modern/LineChart/index.js +3 -1
  266. package/modern/LineChart/legend.js +13 -0
  267. package/modern/PieChart/PieArc.js +116 -0
  268. package/modern/PieChart/PieArcLabel.js +100 -0
  269. package/modern/PieChart/PieChart.js +332 -0
  270. package/modern/PieChart/PiePlot.js +115 -0
  271. package/modern/PieChart/formatter.js +41 -0
  272. package/modern/PieChart/index.js +4 -0
  273. package/modern/PieChart/legend.js +12 -0
  274. package/modern/ResponsiveChartContainer/index.js +22 -10
  275. package/modern/ScatterChart/Scatter.js +40 -54
  276. package/modern/ScatterChart/ScatterChart.js +73 -20
  277. package/modern/ScatterChart/ScatterPlot.js +28 -4
  278. package/modern/ScatterChart/legend.js +13 -0
  279. package/modern/SparkLineChart/SparkLineChart.js +205 -0
  280. package/modern/SparkLineChart/index.js +1 -0
  281. package/modern/colorPalettes/colorPalettes.js +2 -2
  282. package/modern/context/CartesianContextProvider.js +79 -32
  283. package/modern/context/DrawingProvider.js +1 -1
  284. package/modern/context/SeriesContextProvider.js +16 -4
  285. package/modern/hooks/index.js +2 -0
  286. package/modern/hooks/useAxisEvents.js +31 -43
  287. package/modern/hooks/useDrawingArea.js +16 -0
  288. package/modern/hooks/useScale.js +19 -21
  289. package/modern/hooks/useTicks.js +27 -14
  290. package/modern/index.js +4 -1
  291. package/modern/internals/components/AxisSharedComponents.js +10 -10
  292. package/modern/internals/defaultizeColor.js +7 -0
  293. package/modern/internals/getScale.js +17 -0
  294. package/modern/internals/isBandScale.js +3 -0
  295. package/modern/models/axis.js +6 -1
  296. package/modern/models/index.js +3 -1
  297. package/modern/models/seriesType/index.js +1 -8
  298. package/package.json +26 -6
  299. package/themeAugmentation/components.d.ts +0 -10
  300. package/themeAugmentation/overrides.d.ts +0 -2
@@ -1,19 +1,33 @@
1
1
  import * as React from 'react';
2
+ import { BarPlotSlotComponentProps, BarPlotSlotsComponent } from './BarPlot';
2
3
  import { ResponsiveChartContainerProps } from '../ResponsiveChartContainer';
3
4
  import { ChartsAxisProps } from '../ChartsAxis';
4
5
  import { BarSeriesType } from '../models/seriesType/bar';
5
6
  import { MakeOptional } from '../models/helpers';
6
7
  import { ChartsTooltipProps } from '../ChartsTooltip';
7
- import { ChartsLegendProps } from '../ChartsLegend';
8
+ import { ChartsLegendProps, ChartsLegendSlotsComponent, ChartsLegendSlotComponentProps } from '../ChartsLegend';
8
9
  import { ChartsAxisHighlightProps } from '../ChartsAxisHighlight';
9
- export interface BarChartProps extends Omit<ResponsiveChartContainerProps, 'series'>, ChartsAxisProps {
10
+ import { ChartsAxisSlotsComponent, ChartsAxisSlotComponentProps } from '../models/axis';
11
+ export interface BarChartSlotsComponent extends ChartsAxisSlotsComponent, BarPlotSlotsComponent, ChartsLegendSlotsComponent {
12
+ }
13
+ export interface BarChartSlotComponentProps extends ChartsAxisSlotComponentProps, BarPlotSlotComponentProps, ChartsLegendSlotComponentProps {
14
+ }
15
+ export interface BarChartProps extends Omit<ResponsiveChartContainerProps, 'series'>, Omit<ChartsAxisProps, 'slots' | 'slotProps'> {
10
16
  series: MakeOptional<BarSeriesType, 'type'>[];
11
17
  tooltip?: ChartsTooltipProps;
12
18
  axisHighlight?: ChartsAxisHighlightProps;
13
19
  legend?: ChartsLegendProps;
20
+ /**
21
+ * Overridable component slots.
22
+ * @default {}
23
+ */
24
+ slots?: BarChartSlotsComponent;
25
+ /**
26
+ * The props used for each component slot.
27
+ * @default {}
28
+ */
29
+ slotProps?: BarChartSlotComponentProps;
30
+ layout?: BarSeriesType['layout'];
14
31
  }
15
- declare function BarChart(props: BarChartProps): React.JSX.Element;
16
- declare namespace BarChart {
17
- var propTypes: any;
18
- }
32
+ declare const BarChart: React.ForwardRefExoticComponent<BarChartProps & React.RefAttributes<unknown>>;
19
33
  export { BarChart };
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.BarChart = BarChart;
7
+ exports.BarChart = void 0;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
9
  var React = _interopRequireWildcard(require("react"));
10
10
  var _useId = _interopRequireDefault(require("@mui/utils/useId"));
@@ -20,7 +20,7 @@ var _ChartsClipPath = require("../ChartsClipPath");
20
20
  var _jsxRuntime = require("react/jsx-runtime");
21
21
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
22
22
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
- function BarChart(props) {
23
+ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
24
24
  const {
25
25
  xAxis,
26
26
  yAxis,
@@ -29,7 +29,9 @@ function BarChart(props) {
29
29
  height,
30
30
  margin,
31
31
  colors,
32
+ dataset,
32
33
  sx,
34
+ layout,
33
35
  tooltip,
34
36
  axisHighlight,
35
37
  legend,
@@ -37,43 +39,69 @@ function BarChart(props) {
37
39
  leftAxis,
38
40
  rightAxis,
39
41
  bottomAxis,
40
- children
42
+ children,
43
+ slots,
44
+ slotProps
41
45
  } = props;
42
46
  const id = (0, _useId.default)();
43
47
  const clipPathId = `${id}-clip-path`;
48
+ const hasHorizontalSeries = layout === 'horizontal' || layout === undefined && series.some(item => item.layout === 'horizontal');
49
+ const defaultAxisConfig = {
50
+ scaleType: 'band',
51
+ data: Array.from({
52
+ length: Math.max(...series.map(s => (s.data ?? dataset ?? []).length))
53
+ }, (_, index) => index)
54
+ };
55
+ const defaultizedAxisHighlight = (0, _extends2.default)({}, hasHorizontalSeries ? {
56
+ y: 'band'
57
+ } : {
58
+ x: 'band'
59
+ }, axisHighlight);
44
60
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_ResponsiveChartContainer.ResponsiveChartContainer, {
61
+ ref: ref,
45
62
  series: series.map(s => (0, _extends2.default)({
46
63
  type: 'bar'
47
- }, s)),
64
+ }, s, {
65
+ layout: hasHorizontalSeries ? 'horizontal' : 'vertical'
66
+ })),
48
67
  width: width,
49
68
  height: height,
50
69
  margin: margin,
51
- xAxis: xAxis ?? [{
52
- id: _constants.DEFAULT_X_AXIS_KEY,
53
- scaleType: 'band',
54
- data: Array.from({
55
- length: Math.max(...series.map(s => s.data.length))
56
- }, (_, index) => index)
57
- }],
58
- yAxis: yAxis,
70
+ xAxis: xAxis ?? (hasHorizontalSeries ? undefined : [(0, _extends2.default)({
71
+ id: _constants.DEFAULT_X_AXIS_KEY
72
+ }, defaultAxisConfig)]),
73
+ yAxis: yAxis ?? (hasHorizontalSeries ? [(0, _extends2.default)({
74
+ id: _constants.DEFAULT_Y_AXIS_KEY
75
+ }, defaultAxisConfig)] : undefined),
59
76
  colors: colors,
77
+ dataset: dataset,
60
78
  sx: sx,
61
79
  disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none',
62
80
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
63
81
  clipPath: `url(#${clipPathId})`,
64
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_BarPlot.BarPlot, {})
82
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_BarPlot.BarPlot, {
83
+ slots: slots,
84
+ slotProps: slotProps
85
+ })
65
86
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsAxis.ChartsAxis, {
66
87
  topAxis: topAxis,
67
88
  leftAxis: leftAxis,
68
89
  rightAxis: rightAxis,
69
- bottomAxis: bottomAxis
70
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsLegend.ChartsLegend, (0, _extends2.default)({}, legend)), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsAxisHighlight.ChartsAxisHighlight, (0, _extends2.default)({
71
- x: "band"
72
- }, axisHighlight)), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsTooltip.ChartsTooltip, (0, _extends2.default)({}, tooltip)), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsClipPath.ChartsClipPath, {
90
+ bottomAxis: bottomAxis,
91
+ slots: slots,
92
+ slotProps: slotProps
93
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsLegend.ChartsLegend, (0, _extends2.default)({}, legend, {
94
+ slots: slots,
95
+ slotProps: slotProps
96
+ })), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsAxisHighlight.ChartsAxisHighlight, (0, _extends2.default)({}, defaultizedAxisHighlight)), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsTooltip.ChartsTooltip, (0, _extends2.default)({}, tooltip, {
97
+ slots: slots,
98
+ slotProps: slotProps
99
+ })), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsClipPath.ChartsClipPath, {
73
100
  id: clipPathId
74
101
  }), children]
75
102
  });
76
- }
103
+ });
104
+ exports.BarChart = BarChart;
77
105
  process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
78
106
  // ----------------------------- Warning --------------------------------
79
107
  // | These PropTypes are generated from the TypeScript type definitions |
@@ -81,11 +109,11 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
81
109
  // ----------------------------------------------------------------------
82
110
  axisHighlight: _propTypes.default.shape({
83
111
  x: _propTypes.default.oneOf(['band', 'line', 'none']),
84
- y: _propTypes.default.oneOf(['line', 'none'])
112
+ y: _propTypes.default.oneOf(['band', 'line', 'none'])
85
113
  }),
86
114
  /**
87
115
  * Indicate which axis to display the bottom of the charts.
88
- * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
116
+ * Can be a string (the id of the axis) or an object `ChartsXAxisProps`.
89
117
  * @default xAxisIds[0] The id of the first provided axis
90
118
  */
91
119
  bottomAxis: _propTypes.default.oneOfType([_propTypes.default.shape({
@@ -97,8 +125,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
97
125
  label: _propTypes.default.string,
98
126
  labelFontSize: _propTypes.default.number,
99
127
  position: _propTypes.default.oneOf(['bottom', 'top']),
128
+ slotProps: _propTypes.default.object,
129
+ slots: _propTypes.default.object,
100
130
  stroke: _propTypes.default.string,
101
131
  tickFontSize: _propTypes.default.number,
132
+ tickMaxStep: _propTypes.default.number,
133
+ tickMinStep: _propTypes.default.number,
134
+ tickNumber: _propTypes.default.number,
102
135
  tickSize: _propTypes.default.number
103
136
  }), _propTypes.default.string]),
104
137
  children: _propTypes.default.node,
@@ -107,12 +140,14 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
107
140
  * Color palette used to colorize multiple series.
108
141
  */
109
142
  colors: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.string), _propTypes.default.func]),
143
+ dataset: _propTypes.default.arrayOf(_propTypes.default.object),
110
144
  desc: _propTypes.default.string,
111
145
  disableAxisListener: _propTypes.default.bool,
112
146
  height: _propTypes.default.number,
147
+ layout: _propTypes.default.oneOf(['horizontal', 'vertical']),
113
148
  /**
114
149
  * Indicate which axis to display the left of the charts.
115
- * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
150
+ * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
116
151
  * @default yAxisIds[0] The id of the first provided axis
117
152
  */
118
153
  leftAxis: _propTypes.default.oneOfType([_propTypes.default.shape({
@@ -124,13 +159,19 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
124
159
  label: _propTypes.default.string,
125
160
  labelFontSize: _propTypes.default.number,
126
161
  position: _propTypes.default.oneOf(['left', 'right']),
162
+ slotProps: _propTypes.default.object,
163
+ slots: _propTypes.default.object,
127
164
  stroke: _propTypes.default.string,
128
165
  tickFontSize: _propTypes.default.number,
166
+ tickMaxStep: _propTypes.default.number,
167
+ tickMinStep: _propTypes.default.number,
168
+ tickNumber: _propTypes.default.number,
129
169
  tickSize: _propTypes.default.number
130
170
  }), _propTypes.default.string]),
131
171
  legend: _propTypes.default.shape({
132
172
  classes: _propTypes.default.object,
133
173
  direction: _propTypes.default.oneOf(['column', 'row']),
174
+ hidden: _propTypes.default.bool,
134
175
  itemWidth: _propTypes.default.number,
135
176
  markSize: _propTypes.default.number,
136
177
  offset: _propTypes.default.shape({
@@ -141,6 +182,8 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
141
182
  horizontal: _propTypes.default.oneOf(['left', 'middle', 'right']).isRequired,
142
183
  vertical: _propTypes.default.oneOf(['bottom', 'middle', 'top']).isRequired
143
184
  }),
185
+ slotProps: _propTypes.default.object,
186
+ slots: _propTypes.default.object,
144
187
  spacing: _propTypes.default.number
145
188
  }),
146
189
  margin: _propTypes.default.shape({
@@ -151,7 +194,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
151
194
  }),
152
195
  /**
153
196
  * Indicate which axis to display the right of the charts.
154
- * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
197
+ * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
155
198
  * @default null
156
199
  */
157
200
  rightAxis: _propTypes.default.oneOfType([_propTypes.default.shape({
@@ -163,19 +206,26 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
163
206
  label: _propTypes.default.string,
164
207
  labelFontSize: _propTypes.default.number,
165
208
  position: _propTypes.default.oneOf(['left', 'right']),
209
+ slotProps: _propTypes.default.object,
210
+ slots: _propTypes.default.object,
166
211
  stroke: _propTypes.default.string,
167
212
  tickFontSize: _propTypes.default.number,
213
+ tickMaxStep: _propTypes.default.number,
214
+ tickMinStep: _propTypes.default.number,
215
+ tickNumber: _propTypes.default.number,
168
216
  tickSize: _propTypes.default.number
169
217
  }), _propTypes.default.string]),
170
218
  series: _propTypes.default.arrayOf(_propTypes.default.shape({
171
219
  color: _propTypes.default.string,
172
- data: _propTypes.default.arrayOf(_propTypes.default.number).isRequired,
220
+ data: _propTypes.default.arrayOf(_propTypes.default.number),
221
+ dataKey: _propTypes.default.string,
173
222
  highlightScope: _propTypes.default.shape({
174
223
  faded: _propTypes.default.oneOf(['global', 'none', 'series']),
175
224
  highlighted: _propTypes.default.oneOf(['item', 'none', 'series'])
176
225
  }),
177
226
  id: _propTypes.default.string,
178
227
  label: _propTypes.default.string,
228
+ layout: _propTypes.default.oneOf(['horizontal', 'vertical']),
179
229
  stack: _propTypes.default.string,
180
230
  stackOffset: _propTypes.default.oneOf(['diverging', 'expand', 'none', 'silhouette', 'wiggle']),
181
231
  stackOrder: _propTypes.default.oneOf(['appearance', 'ascending', 'descending', 'insideOut', 'none', 'reverse']),
@@ -184,6 +234,16 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
184
234
  xAxisKey: _propTypes.default.string,
185
235
  yAxisKey: _propTypes.default.string
186
236
  })).isRequired,
237
+ /**
238
+ * The props used for each component slot.
239
+ * @default {}
240
+ */
241
+ slotProps: _propTypes.default.object,
242
+ /**
243
+ * Overridable component slots.
244
+ * @default {}
245
+ */
246
+ slots: _propTypes.default.object,
187
247
  sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object]),
188
248
  title: _propTypes.default.string,
189
249
  tooltip: _propTypes.default.shape({
@@ -194,7 +254,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
194
254
  }),
195
255
  /**
196
256
  * Indicate which axis to display the top of the charts.
197
- * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
257
+ * Can be a string (the id of the axis) or an object `ChartsXAxisProps`.
198
258
  * @default null
199
259
  */
200
260
  topAxis: _propTypes.default.oneOfType([_propTypes.default.shape({
@@ -206,8 +266,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
206
266
  label: _propTypes.default.string,
207
267
  labelFontSize: _propTypes.default.number,
208
268
  position: _propTypes.default.oneOf(['bottom', 'top']),
269
+ slotProps: _propTypes.default.object,
270
+ slots: _propTypes.default.object,
209
271
  stroke: _propTypes.default.string,
210
272
  tickFontSize: _propTypes.default.number,
273
+ tickMaxStep: _propTypes.default.number,
274
+ tickMinStep: _propTypes.default.number,
275
+ tickNumber: _propTypes.default.number,
211
276
  tickSize: _propTypes.default.number
212
277
  }), _propTypes.default.string]),
213
278
  viewBox: _propTypes.default.shape({
@@ -221,44 +286,52 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
221
286
  axisId: _propTypes.default.string,
222
287
  classes: _propTypes.default.object,
223
288
  data: _propTypes.default.array,
289
+ dataKey: _propTypes.default.string,
224
290
  disableLine: _propTypes.default.bool,
225
291
  disableTicks: _propTypes.default.bool,
226
292
  fill: _propTypes.default.string,
293
+ hideTooltip: _propTypes.default.bool,
227
294
  id: _propTypes.default.string,
228
295
  label: _propTypes.default.string,
229
296
  labelFontSize: _propTypes.default.number,
230
- max: _propTypes.default.number,
231
- maxTicks: _propTypes.default.number,
232
- min: _propTypes.default.number,
233
- minTicks: _propTypes.default.number,
297
+ max: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
298
+ min: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
234
299
  position: _propTypes.default.oneOf(['bottom', 'left', 'right', 'top']),
235
300
  scaleType: _propTypes.default.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
301
+ slotProps: _propTypes.default.object,
302
+ slots: _propTypes.default.object,
236
303
  stroke: _propTypes.default.string,
237
304
  tickFontSize: _propTypes.default.number,
305
+ tickMaxStep: _propTypes.default.number,
306
+ tickMinStep: _propTypes.default.number,
307
+ tickNumber: _propTypes.default.number,
238
308
  tickSize: _propTypes.default.number,
239
- tickSpacing: _propTypes.default.number,
240
309
  valueFormatter: _propTypes.default.func
241
310
  })),
242
311
  yAxis: _propTypes.default.arrayOf(_propTypes.default.shape({
243
312
  axisId: _propTypes.default.string,
244
313
  classes: _propTypes.default.object,
245
314
  data: _propTypes.default.array,
315
+ dataKey: _propTypes.default.string,
246
316
  disableLine: _propTypes.default.bool,
247
317
  disableTicks: _propTypes.default.bool,
248
318
  fill: _propTypes.default.string,
319
+ hideTooltip: _propTypes.default.bool,
249
320
  id: _propTypes.default.string,
250
321
  label: _propTypes.default.string,
251
322
  labelFontSize: _propTypes.default.number,
252
- max: _propTypes.default.number,
253
- maxTicks: _propTypes.default.number,
254
- min: _propTypes.default.number,
255
- minTicks: _propTypes.default.number,
323
+ max: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
324
+ min: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
256
325
  position: _propTypes.default.oneOf(['bottom', 'left', 'right', 'top']),
257
326
  scaleType: _propTypes.default.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
327
+ slotProps: _propTypes.default.object,
328
+ slots: _propTypes.default.object,
258
329
  stroke: _propTypes.default.string,
259
330
  tickFontSize: _propTypes.default.number,
331
+ tickMaxStep: _propTypes.default.number,
332
+ tickMinStep: _propTypes.default.number,
333
+ tickNumber: _propTypes.default.number,
260
334
  tickSize: _propTypes.default.number,
261
- tickSpacing: _propTypes.default.number,
262
335
  valueFormatter: _propTypes.default.func
263
336
  }))
264
337
  } : void 0;
@@ -1,4 +1,5 @@
1
1
  import * as React from 'react';
2
+ import type { SlotComponentProps } from '@mui/base';
2
3
  import { HighlightScope } from '../context/HighlightProvider';
3
4
  export interface BarElementClasses {
4
5
  /** Styles applied to the root element. */
@@ -15,7 +16,28 @@ export interface BarElementOwnerState {
15
16
  }
16
17
  export declare function getBarElementUtilityClass(slot: string): string;
17
18
  export declare const lineElementClasses: BarElementClasses;
19
+ export declare const BarElementPath: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme> & {
20
+ ownerState: BarElementOwnerState;
21
+ }, Pick<React.SVGProps<SVGRectElement>, keyof React.SVGProps<SVGRectElement>>, {}>;
18
22
  export type BarElementProps = Omit<BarElementOwnerState, 'isFaded' | 'isHighlighted'> & React.ComponentPropsWithoutRef<'path'> & {
19
23
  highlightScope?: Partial<HighlightScope>;
24
+ /**
25
+ * The props used for each component slot.
26
+ * @default {}
27
+ */
28
+ slotProps?: {
29
+ bar?: SlotComponentProps<'path', {}, BarElementOwnerState>;
30
+ };
31
+ /**
32
+ * Overridable component slots.
33
+ * @default {}
34
+ */
35
+ slots?: {
36
+ /**
37
+ * The component that renders the root.
38
+ * @default BarElementPath
39
+ */
40
+ bar?: React.ElementType;
41
+ };
20
42
  };
21
43
  export declare function BarElement(props: BarElementProps): React.JSX.Element;
@@ -5,12 +5,14 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.BarElement = BarElement;
8
+ exports.BarElementPath = void 0;
8
9
  exports.getBarElementUtilityClass = getBarElementUtilityClass;
9
10
  exports.lineElementClasses = void 0;
10
11
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
12
  var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
12
13
  var React = _interopRequireWildcard(require("react"));
13
14
  var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
15
+ var _utils = require("@mui/base/utils");
14
16
  var _generateUtilityClass = _interopRequireDefault(require("@mui/utils/generateUtilityClass"));
15
17
  var _styles = require("@mui/material/styles");
16
18
  var _d3Color = require("d3-color");
@@ -18,7 +20,7 @@ var _generateUtilityClasses = _interopRequireDefault(require("@mui/utils/generat
18
20
  var _useInteractionItemProps = require("../hooks/useInteractionItemProps");
19
21
  var _InteractionProvider = require("../context/InteractionProvider");
20
22
  var _jsxRuntime = require("react/jsx-runtime");
21
- const _excluded = ["id", "dataIndex", "classes", "color", "highlightScope"];
23
+ const _excluded = ["id", "dataIndex", "classes", "color", "highlightScope", "slots", "slotProps"];
22
24
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
23
25
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
24
26
  function getBarElementUtilityClass(slot) {
@@ -49,13 +51,16 @@ const BarElementPath = (0, _styles.styled)('rect', {
49
51
  transition: 'opacity 0.2s ease-in, fill 0.2s ease-in',
50
52
  opacity: ownerState.isFaded && 0.3 || 1
51
53
  }));
54
+ exports.BarElementPath = BarElementPath;
52
55
  function BarElement(props) {
53
56
  const {
54
57
  id,
55
58
  dataIndex,
56
59
  classes: innerClasses,
57
60
  color,
58
- highlightScope
61
+ highlightScope,
62
+ slots,
63
+ slotProps
59
64
  } = props,
60
65
  other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
61
66
  const getInteractionItemProps = (0, _useInteractionItemProps.useInteractionItemProps)(highlightScope);
@@ -81,12 +86,18 @@ function BarElement(props) {
81
86
  isHighlighted
82
87
  };
83
88
  const classes = useUtilityClasses(ownerState);
84
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(BarElementPath, (0, _extends2.default)({}, other, {
85
- ownerState: ownerState,
86
- className: classes.root
87
- }, getInteractionItemProps({
88
- type: 'bar',
89
- seriesId: id,
90
- dataIndex
91
- })));
89
+ const Bar = slots?.bar ?? BarElementPath;
90
+ const barProps = (0, _utils.useSlotProps)({
91
+ elementType: Bar,
92
+ externalSlotProps: slotProps?.bar,
93
+ additionalProps: (0, _extends2.default)({}, other, getInteractionItemProps({
94
+ type: 'bar',
95
+ seriesId: id,
96
+ dataIndex
97
+ }), {
98
+ className: classes.root
99
+ }),
100
+ ownerState
101
+ });
102
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(Bar, (0, _extends2.default)({}, barProps));
92
103
  }
@@ -1,2 +1,15 @@
1
1
  import * as React from 'react';
2
- export declare function BarPlot(): React.JSX.Element | null;
2
+ import { BarElementProps } from './BarElement';
3
+ export interface BarPlotSlotsComponent {
4
+ bar?: React.JSXElementConstructor<BarElementProps>;
5
+ }
6
+ export interface BarPlotSlotComponentProps {
7
+ bar?: Partial<BarElementProps>;
8
+ }
9
+ export interface BarPlotProps extends Pick<BarElementProps, 'slots' | 'slotProps'> {
10
+ }
11
+ declare function BarPlot(props: BarPlotProps): React.JSX.Element | null;
12
+ declare namespace BarPlot {
13
+ var propTypes: any;
14
+ }
15
+ export { BarPlot };
@@ -1,18 +1,47 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.BarPlot = BarPlot;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
7
9
  var React = _interopRequireWildcard(require("react"));
10
+ var _propTypes = _interopRequireDefault(require("prop-types"));
8
11
  var _SeriesContextProvider = require("../context/SeriesContextProvider");
9
12
  var _CartesianContextProvider = require("../context/CartesianContextProvider");
10
- var _useScale = require("../hooks/useScale");
11
13
  var _BarElement = require("./BarElement");
14
+ var _axis = require("../models/axis");
12
15
  var _jsxRuntime = require("react/jsx-runtime");
13
16
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
14
17
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
- function BarPlot() {
18
+ /**
19
+ * Solution of the equations
20
+ * W = barWidth * N + offset * (N-1)
21
+ * offset / (offset + barWidth) = r
22
+ * @param bandWidth The width available to place bars.
23
+ * @param numberOfGroups The number of bars to place in that space.
24
+ * @param gapRatio The ratio of the gap between bars over the bar width.
25
+ * @returns The bar width and the offset between bars.
26
+ */function getBandSize({
27
+ bandWidth: W,
28
+ numberOfGroups: N,
29
+ gapRatio: r
30
+ }) {
31
+ if (r === 0) {
32
+ return {
33
+ barWidth: W / N,
34
+ offset: 0
35
+ };
36
+ }
37
+ const barWidth = W / (N + (N - 1) * r);
38
+ const offset = r * barWidth;
39
+ return {
40
+ barWidth,
41
+ offset
42
+ };
43
+ }
44
+ function BarPlot(props) {
16
45
  const seriesData = React.useContext(_SeriesContextProvider.SeriesContext).bar;
17
46
  const axisData = React.useContext(_CartesianContextProvider.CartesianContext);
18
47
  if (seriesData === undefined) {
@@ -37,21 +66,39 @@ function BarPlot() {
37
66
  return groupIds.flatMap(seriesId => {
38
67
  const xAxisKey = series[seriesId].xAxisKey ?? defaultXAxisId;
39
68
  const yAxisKey = series[seriesId].yAxisKey ?? defaultYAxisId;
40
- const xScale = xAxis[xAxisKey].scale;
41
- const yScale = yAxis[yAxisKey].scale;
42
- if (!(0, _useScale.isBandScale)(xScale)) {
43
- throw new Error(`Axis with id "${xAxisKey}" shoud be of type "band" to display the bar series ${stackingGroups}`);
44
- }
45
- if (xAxis[xAxisKey].data === undefined) {
46
- throw new Error(`Axis with id "${xAxisKey}" shoud have data property`);
69
+ const xAxisConfig = xAxis[xAxisKey];
70
+ const yAxisConfig = yAxis[yAxisKey];
71
+ const verticalLayout = series[seriesId].layout === 'vertical';
72
+ let baseScaleConfig;
73
+ if (verticalLayout) {
74
+ if (!(0, _axis.isBandScaleConfig)(xAxisConfig)) {
75
+ throw new Error(`Axis with id "${xAxisKey}" shoud be of type "band" to display the bar series of id "${seriesId}"`);
76
+ }
77
+ if (xAxis[xAxisKey].data === undefined) {
78
+ throw new Error(`Axis with id "${xAxisKey}" shoud have data property`);
79
+ }
80
+ baseScaleConfig = xAxisConfig;
81
+ } else {
82
+ if (!(0, _axis.isBandScaleConfig)(yAxisConfig)) {
83
+ throw new Error(`Axis with id "${yAxisKey}" shoud be of type "band" to display the bar series of id "${seriesId}"`);
84
+ }
85
+ if (yAxis[yAxisKey].data === undefined) {
86
+ throw new Error(`Axis with id "${xAxisKey}" shoud have data property`);
87
+ }
88
+ baseScaleConfig = yAxisConfig;
47
89
  }
48
-
49
- // Currently assuming all bars are vertical
50
- const bandWidth = xScale.bandwidth();
51
- const barWidth = 0.9 * bandWidth / stackingGroups.length;
52
- const offset = 0.05 * bandWidth;
53
-
54
- // @ts-ignore TODO: fix when adding a correct API for customisation
90
+ const xScale = xAxisConfig.scale;
91
+ const yScale = yAxisConfig.scale;
92
+ const bandWidth = baseScaleConfig.scale.bandwidth();
93
+ const {
94
+ barWidth,
95
+ offset
96
+ } = getBandSize({
97
+ bandWidth,
98
+ numberOfGroups: stackingGroups.length,
99
+ gapRatio: baseScaleConfig.barGapRatio
100
+ });
101
+ const barOffset = groupIndex * (barWidth + offset);
55
102
  const {
56
103
  stackedData,
57
104
  color
@@ -59,18 +106,34 @@ function BarPlot() {
59
106
  return stackedData.map((values, dataIndex) => {
60
107
  const baseline = Math.min(...values);
61
108
  const value = Math.max(...values);
62
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_BarElement.BarElement, {
109
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_BarElement.BarElement, (0, _extends2.default)({
63
110
  id: seriesId,
64
111
  dataIndex: dataIndex,
65
- x: xScale(xAxis[xAxisKey].data?.[dataIndex]) + groupIndex * barWidth + offset,
66
- y: yScale(value),
67
- height: yScale(baseline) - yScale(value),
68
- width: barWidth,
112
+ x: verticalLayout ? xScale(xAxis[xAxisKey].data?.[dataIndex]) + barOffset : xScale(baseline),
113
+ y: verticalLayout ? yScale(value) : yScale(yAxis[yAxisKey].data?.[dataIndex]) + barOffset,
114
+ height: verticalLayout ? Math.abs(yScale(baseline) - yScale(value)) : barWidth,
115
+ width: verticalLayout ? barWidth : Math.abs(xScale(baseline) - xScale(value)),
69
116
  color: color,
70
117
  highlightScope: series[seriesId].highlightScope
71
- }, `${seriesId}-${dataIndex}`);
118
+ }, props), `${seriesId}-${dataIndex}`);
72
119
  });
73
120
  });
74
121
  })
75
122
  });
76
- }
123
+ }
124
+ process.env.NODE_ENV !== "production" ? BarPlot.propTypes = {
125
+ // ----------------------------- Warning --------------------------------
126
+ // | These PropTypes are generated from the TypeScript type definitions |
127
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
128
+ // ----------------------------------------------------------------------
129
+ /**
130
+ * The props used for each component slot.
131
+ * @default {}
132
+ */
133
+ slotProps: _propTypes.default.object,
134
+ /**
135
+ * Overridable component slots.
136
+ * @default {}
137
+ */
138
+ slots: _propTypes.default.object
139
+ } : void 0;