@mui/x-charts 6.0.0-alpha.6 → 6.0.0-alpha.8

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 (142) hide show
  1. package/BarChart/BarChart.d.ts +19 -2
  2. package/BarChart/BarChart.js +84 -22
  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 +48 -19
  7. package/BarChart/extremums.js +19 -3
  8. package/BarChart/formatter.js +3 -1
  9. package/CHANGELOG.md +213 -28
  10. package/ChartsAxis/ChartsAxis.d.ts +11 -1
  11. package/ChartsAxis/ChartsAxis.js +51 -6
  12. package/ChartsAxisHighlight/ChartsAxisHighlight.d.ts +3 -2
  13. package/ChartsAxisHighlight/ChartsAxisHighlight.js +11 -3
  14. package/ChartsLegend/ChartsLegend.d.ts +25 -2
  15. package/ChartsLegend/ChartsLegend.js +49 -17
  16. package/ChartsTooltip/ChartsAxisTooltipContent.js +13 -9
  17. package/ChartsTooltip/ChartsTooltipTable.d.ts +2 -9
  18. package/ChartsXAxis/ChartsXAxis.js +44 -9
  19. package/ChartsYAxis/ChartsYAxis.js +44 -9
  20. package/LineChart/AreaElement.d.ts +22 -0
  21. package/LineChart/AreaElement.js +31 -11
  22. package/LineChart/AreaPlot.d.ts +14 -1
  23. package/LineChart/AreaPlot.js +29 -3
  24. package/LineChart/LineChart.d.ts +20 -2
  25. package/LineChart/LineChart.js +63 -11
  26. package/LineChart/LineElement.d.ts +22 -0
  27. package/LineChart/LineElement.js +31 -10
  28. package/LineChart/LinePlot.d.ts +14 -1
  29. package/LineChart/LinePlot.js +35 -4
  30. package/LineChart/MarkPlot.d.ts +24 -1
  31. package/LineChart/MarkPlot.js +29 -4
  32. package/PieChart/PieArcLabel.js +0 -1
  33. package/PieChart/PieChart.d.ts +14 -2
  34. package/PieChart/PieChart.js +52 -10
  35. package/PieChart/PiePlot.d.ts +27 -1
  36. package/PieChart/PiePlot.js +29 -6
  37. package/ScatterChart/ScatterChart.d.ts +18 -2
  38. package/ScatterChart/ScatterChart.js +56 -10
  39. package/ScatterChart/ScatterPlot.d.ts +24 -1
  40. package/ScatterChart/ScatterPlot.js +28 -4
  41. package/SparkLineChart/SparkLineChart.d.ts +18 -0
  42. package/SparkLineChart/SparkLineChart.js +29 -6
  43. package/colorPalettes/colorPalettes.js +2 -2
  44. package/context/CartesianContextProvider.js +18 -12
  45. package/esm/BarChart/BarChart.js +88 -26
  46. package/esm/BarChart/BarElement.js +21 -11
  47. package/esm/BarChart/BarPlot.js +49 -20
  48. package/esm/BarChart/extremums.js +18 -2
  49. package/esm/BarChart/formatter.js +3 -1
  50. package/esm/ChartsAxis/ChartsAxis.js +51 -6
  51. package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +11 -3
  52. package/esm/ChartsLegend/ChartsLegend.js +47 -14
  53. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +13 -9
  54. package/esm/ChartsXAxis/ChartsXAxis.js +45 -9
  55. package/esm/ChartsYAxis/ChartsYAxis.js +45 -9
  56. package/esm/LineChart/AreaElement.js +31 -11
  57. package/esm/LineChart/AreaPlot.js +31 -4
  58. package/esm/LineChart/LineChart.js +63 -11
  59. package/esm/LineChart/LineElement.js +31 -11
  60. package/esm/LineChart/LinePlot.js +43 -8
  61. package/esm/LineChart/MarkPlot.js +32 -5
  62. package/esm/PieChart/PieArcLabel.js +0 -1
  63. package/esm/PieChart/PieChart.js +52 -10
  64. package/esm/PieChart/PiePlot.js +31 -6
  65. package/esm/ScatterChart/ScatterChart.js +56 -10
  66. package/esm/ScatterChart/ScatterPlot.js +29 -4
  67. package/esm/SparkLineChart/SparkLineChart.js +29 -6
  68. package/esm/colorPalettes/colorPalettes.js +2 -2
  69. package/esm/context/CartesianContextProvider.js +18 -12
  70. package/esm/hooks/useAxisEvents.js +21 -38
  71. package/esm/hooks/useTicks.js +11 -8
  72. package/esm/internals/components/AxisSharedComponents.js +10 -10
  73. package/hooks/useAxisEvents.js +21 -38
  74. package/hooks/useTicks.d.ts +20 -5
  75. package/hooks/useTicks.js +11 -8
  76. package/index.js +1 -1
  77. package/internals/components/AxisSharedComponents.d.ts +4 -4
  78. package/internals/components/AxisSharedComponents.js +15 -15
  79. package/internals/defaultizeColor.d.ts +1 -0
  80. package/legacy/BarChart/BarChart.js +93 -29
  81. package/legacy/BarChart/BarElement.js +20 -10
  82. package/legacy/BarChart/BarPlot.js +49 -20
  83. package/legacy/BarChart/extremums.js +22 -2
  84. package/legacy/BarChart/formatter.js +3 -1
  85. package/legacy/ChartsAxis/ChartsAxis.js +51 -6
  86. package/legacy/ChartsAxisHighlight/ChartsAxisHighlight.js +11 -3
  87. package/legacy/ChartsLegend/ChartsLegend.js +46 -15
  88. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +13 -9
  89. package/legacy/ChartsXAxis/ChartsXAxis.js +45 -9
  90. package/legacy/ChartsYAxis/ChartsYAxis.js +45 -9
  91. package/legacy/LineChart/AreaElement.js +30 -10
  92. package/legacy/LineChart/AreaPlot.js +29 -4
  93. package/legacy/LineChart/LineChart.js +63 -11
  94. package/legacy/LineChart/LineElement.js +30 -10
  95. package/legacy/LineChart/LinePlot.js +36 -5
  96. package/legacy/LineChart/MarkPlot.js +30 -5
  97. package/legacy/PieChart/PieArcLabel.js +0 -1
  98. package/legacy/PieChart/PieChart.js +52 -10
  99. package/legacy/PieChart/PiePlot.js +29 -6
  100. package/legacy/ScatterChart/ScatterChart.js +56 -10
  101. package/legacy/ScatterChart/ScatterPlot.js +27 -4
  102. package/legacy/SparkLineChart/SparkLineChart.js +29 -6
  103. package/legacy/colorPalettes/colorPalettes.js +2 -2
  104. package/legacy/context/CartesianContextProvider.js +18 -12
  105. package/legacy/hooks/useAxisEvents.js +21 -37
  106. package/legacy/hooks/useTicks.js +11 -11
  107. package/legacy/index.js +1 -1
  108. package/legacy/internals/components/AxisSharedComponents.js +10 -10
  109. package/models/axis.d.ts +24 -1
  110. package/models/seriesType/bar.d.ts +6 -1
  111. package/modern/BarChart/BarChart.js +85 -23
  112. package/modern/BarChart/BarElement.js +20 -11
  113. package/modern/BarChart/BarPlot.js +48 -19
  114. package/modern/BarChart/extremums.js +18 -2
  115. package/modern/BarChart/formatter.js +3 -1
  116. package/modern/ChartsAxis/ChartsAxis.js +51 -6
  117. package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +11 -3
  118. package/modern/ChartsLegend/ChartsLegend.js +46 -14
  119. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +13 -9
  120. package/modern/ChartsXAxis/ChartsXAxis.js +44 -9
  121. package/modern/ChartsYAxis/ChartsYAxis.js +44 -9
  122. package/modern/LineChart/AreaElement.js +30 -11
  123. package/modern/LineChart/AreaPlot.js +31 -4
  124. package/modern/LineChart/LineChart.js +63 -11
  125. package/modern/LineChart/LineElement.js +30 -11
  126. package/modern/LineChart/LinePlot.js +37 -5
  127. package/modern/LineChart/MarkPlot.js +31 -5
  128. package/modern/PieChart/PieArcLabel.js +0 -1
  129. package/modern/PieChart/PieChart.js +52 -10
  130. package/modern/PieChart/PiePlot.js +30 -6
  131. package/modern/ScatterChart/ScatterChart.js +56 -10
  132. package/modern/ScatterChart/ScatterPlot.js +28 -4
  133. package/modern/SparkLineChart/SparkLineChart.js +29 -6
  134. package/modern/colorPalettes/colorPalettes.js +2 -2
  135. package/modern/context/CartesianContextProvider.js +18 -12
  136. package/modern/hooks/useAxisEvents.js +21 -38
  137. package/modern/hooks/useTicks.js +11 -8
  138. package/modern/index.js +1 -1
  139. package/modern/internals/components/AxisSharedComponents.js +10 -10
  140. package/package.json +5 -5
  141. package/themeAugmentation/components.d.ts +0 -10
  142. package/themeAugmentation/overrides.d.ts +0 -2
@@ -1,3 +1,4 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
1
2
  import * as React from 'react';
2
3
  import { InteractionContext } from '../context/InteractionProvider';
3
4
  import { CartesianContext } from '../context/CartesianContextProvider';
@@ -30,64 +31,47 @@ export var useAxisEvents = function useAxisEvents(disableAxisListener) {
30
31
  if (element === null || disableAxisListener) {
31
32
  return function () {};
32
33
  }
33
- var getUpdateY = function getUpdateY(y) {
34
- if (usedYAxis === null) {
35
- return null;
36
- }
37
- var _yAxis$usedYAxis = yAxis[usedYAxis],
38
- yScale = _yAxis$usedYAxis.scale,
39
- yAxisData = _yAxis$usedYAxis.data;
40
- if (!isBandScale(yScale)) {
41
- return {
42
- value: yScale.invert(y)
43
- };
44
- }
45
- var dataIndex = Math.floor((y - yScale.range()[0]) / yScale.step());
46
- if (dataIndex < 0 || dataIndex >= yAxisData.length) {
47
- return null;
48
- }
49
- return {
50
- index: dataIndex,
51
- value: yAxisData[dataIndex]
52
- };
53
- };
54
- var getUpdateX = function getUpdateX(x) {
34
+ var getUpdate = function getUpdate(axisConfig, mouseValue) {
55
35
  if (usedXAxis === null) {
56
36
  return null;
57
37
  }
58
- var _xAxis$usedXAxis = xAxis[usedXAxis],
59
- xScale = _xAxis$usedXAxis.scale,
60
- xAxisData = _xAxis$usedXAxis.data;
61
- if (!isBandScale(xScale)) {
62
- var value = xScale.invert(x);
63
- var closestIndex = xAxisData == null ? void 0 : xAxisData.findIndex(function (v, index) {
38
+ var scale = axisConfig.scale,
39
+ axisData = axisConfig.data;
40
+ if (!isBandScale(scale)) {
41
+ var value = scale.invert(mouseValue);
42
+ if (axisData === undefined) {
43
+ return {
44
+ value: value
45
+ };
46
+ }
47
+ var closestIndex = axisData == null ? void 0 : axisData.findIndex(function (v, index) {
64
48
  if (v > value) {
65
49
  // @ts-ignore
66
- if (index === 0 || Math.abs(value - v) <= Math.abs(value - xAxisData[index - 1])) {
50
+ if (index === 0 || Math.abs(value - v) <= Math.abs(value - axisData[index - 1])) {
67
51
  return true;
68
52
  }
69
53
  }
70
54
  if (v <= value) {
71
- if (index === xAxisData.length - 1 ||
55
+ if (index === axisData.length - 1 ||
72
56
  // @ts-ignore
73
- Math.abs(value - v) < Math.abs(value - xAxisData[index + 1])) {
57
+ Math.abs(value - v) < Math.abs(value - axisData[index + 1])) {
74
58
  return true;
75
59
  }
76
60
  }
77
61
  return false;
78
62
  });
79
63
  return {
80
- value: closestIndex !== undefined && closestIndex >= 0 ? xAxisData[closestIndex] : value,
64
+ value: closestIndex !== undefined && closestIndex >= 0 ? axisData[closestIndex] : value,
81
65
  index: closestIndex
82
66
  };
83
67
  }
84
- var dataIndex = xScale.bandwidth() === 0 ? Math.floor((x - xScale.range()[0] + xScale.step() / 2) / xScale.step()) : Math.floor((x - xScale.range()[0]) / xScale.step());
85
- if (dataIndex < 0 || dataIndex >= xAxisData.length) {
68
+ var dataIndex = scale.bandwidth() === 0 ? Math.floor((mouseValue - Math.min.apply(Math, _toConsumableArray(scale.range())) + scale.step() / 2) / scale.step()) : Math.floor((mouseValue - Math.min.apply(Math, _toConsumableArray(scale.range()))) / scale.step());
69
+ if (dataIndex < 0 || dataIndex >= axisData.length) {
86
70
  return null;
87
71
  }
88
72
  return {
89
73
  index: dataIndex,
90
- value: xAxisData[dataIndex]
74
+ value: axisData[dataIndex]
91
75
  };
92
76
  };
93
77
  var handleMouseOut = function handleMouseOut() {
@@ -125,8 +109,8 @@ export var useAxisEvents = function useAxisEvents(disableAxisListener) {
125
109
  });
126
110
  return;
127
111
  }
128
- var newStateX = getUpdateX(svgPt.x);
129
- var newStateY = getUpdateY(svgPt.y);
112
+ var newStateX = getUpdate(xAxis[usedXAxis], svgPt.x);
113
+ var newStateY = getUpdate(yAxis[usedYAxis], svgPt.y);
130
114
  dispatch({
131
115
  type: 'updateAxis',
132
116
  data: {
@@ -2,15 +2,15 @@ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
2
  import * as React from 'react';
3
3
  import { isBandScale } from '../internals/isBandScale';
4
4
  export function getTicksNumber(params) {
5
- var _params$maxTicks = params.maxTicks,
6
- maxTicks = _params$maxTicks === void 0 ? 999 : _params$maxTicks,
7
- _params$minTicks = params.minTicks,
8
- minTicks = _params$minTicks === void 0 ? 2 : _params$minTicks,
9
- _params$tickSpacing = params.tickSpacing,
10
- tickSpacing = _params$tickSpacing === void 0 ? 50 : _params$tickSpacing,
11
- range = params.range;
12
- var estimatedTickNumber = Math.floor(Math.abs(range[1] - range[0]) / tickSpacing);
13
- return Math.min(maxTicks, Math.max(minTicks, estimatedTickNumber));
5
+ var tickMaxStep = params.tickMaxStep,
6
+ tickMinStep = params.tickMinStep,
7
+ tickNumber = params.tickNumber,
8
+ range = params.range,
9
+ domain = params.domain;
10
+ var maxTicks = tickMinStep === undefined ? 999 : Math.floor(Math.abs(domain[1] - domain[0]) / tickMinStep);
11
+ var minTicks = tickMaxStep === undefined ? 2 : Math.ceil(Math.abs(domain[1] - domain[0]) / tickMaxStep);
12
+ var defaultizedTickNumber = tickNumber != null ? tickNumber : Math.floor(Math.abs(range[1] - range[0]) / 50);
13
+ return Math.min(maxTicks, Math.max(minTicks, defaultizedTickNumber));
14
14
  }
15
15
  function useTicks(options) {
16
16
  var scale = options.scale,
@@ -22,11 +22,11 @@ function useTicks(options) {
22
22
  var domain = scale.domain();
23
23
  if (scale.bandwidth() > 0) {
24
24
  // scale type = 'band'
25
- return [].concat(_toConsumableArray(domain.map(function (value, index) {
25
+ return [].concat(_toConsumableArray(domain.map(function (value) {
26
26
  var _valueFormatter;
27
27
  return {
28
28
  formattedValue: (_valueFormatter = valueFormatter == null ? void 0 : valueFormatter(value)) != null ? _valueFormatter : value,
29
- offset: index === 0 ? scale.range()[0] : scale(value) - (scale.step() - scale.bandwidth()) / 2,
29
+ offset: scale(value) - (scale.step() - scale.bandwidth()) / 2,
30
30
  labelOffset: scale.step() / 2
31
31
  };
32
32
  })), [{
package/legacy/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v6.0.0-alpha.6
2
+ * @mui/x-charts v6.0.0-alpha.8
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -10,24 +10,24 @@ export var AxisRoot = styled('g', {
10
10
  return styles.root;
11
11
  }
12
12
  })((_styled = {}, _defineProperty(_styled, "&.".concat(axisClasses.directionY), (_$concat = {}, _defineProperty(_$concat, ".".concat(axisClasses.tickLabel), {
13
- alignmentBaseline: 'middle'
13
+ dominantBaseline: 'middle'
14
14
  }), _defineProperty(_$concat, ".".concat(axisClasses.label), {
15
- alignmentBaseline: 'baseline',
15
+ dominantBaseline: 'auto',
16
16
  textAnchor: 'middle'
17
17
  }), _$concat)), _defineProperty(_styled, "&.".concat(axisClasses.left), _defineProperty({}, ".".concat(axisClasses.tickLabel), {
18
- alignmentBaseline: 'central',
18
+ dominantBaseline: 'central',
19
19
  textAnchor: 'end'
20
20
  })), _defineProperty(_styled, "&.".concat(axisClasses.right), _defineProperty({}, ".".concat(axisClasses.tickLabel), {
21
- alignmentBaseline: 'central',
21
+ dominantBaseline: 'central',
22
22
  textAnchor: 'start'
23
23
  })), _defineProperty(_styled, "&.".concat(axisClasses.bottom), _defineProperty({}, ".".concat(axisClasses.tickLabel, ", .").concat(axisClasses.label), {
24
- alignmentBaseline: 'hanging',
24
+ dominantBaseline: 'hanging',
25
25
  textAnchor: 'middle'
26
26
  })), _defineProperty(_styled, "&.".concat(axisClasses.top), _defineProperty({}, ".".concat(axisClasses.tickLabel, ", .").concat(axisClasses.label), {
27
- alignmentBaseline: 'baseline',
27
+ dominantBaseline: 'baseline',
28
28
  textAnchor: 'middle'
29
29
  })), _styled));
30
- export var Line = styled('line', {
30
+ export var ChartsLine = styled('line', {
31
31
  name: 'MuiChartsAxis',
32
32
  slot: 'Line',
33
33
  overridesResolver: function overridesResolver(props, styles) {
@@ -41,7 +41,7 @@ export var Line = styled('line', {
41
41
  strokeWidth: 1
42
42
  };
43
43
  });
44
- export var Tick = styled('line', {
44
+ export var ChartsTick = styled('line', {
45
45
  name: 'MuiChartsAxis',
46
46
  slot: 'Tick',
47
47
  overridesResolver: function overridesResolver(props, styles) {
@@ -54,7 +54,7 @@ export var Tick = styled('line', {
54
54
  shapeRendering: 'crispEdges'
55
55
  };
56
56
  });
57
- export var TickLabel = styled('text', {
57
+ export var ChartsTickLabel = styled('text', {
58
58
  name: 'MuiChartsAxis',
59
59
  slot: 'TickLabel',
60
60
  overridesResolver: function overridesResolver(props, styles) {
@@ -66,7 +66,7 @@ export var TickLabel = styled('text', {
66
66
  fill: theme.palette.text.primary
67
67
  });
68
68
  });
69
- export var Label = styled('text', {
69
+ export var ChartsLabel = styled('text', {
70
70
  name: 'MuiChartsAxis',
71
71
  slot: 'Label',
72
72
  overridesResolver: function overridesResolver(props, styles) {
package/models/axis.d.ts CHANGED
@@ -1,9 +1,22 @@
1
+ /// <reference types="react" />
1
2
  import type { ScaleBand, ScaleLogarithmic, ScalePower, ScaleTime, ScaleLinear, ScalePoint } from 'd3-scale';
2
3
  import { ChartsAxisClasses } from '../ChartsAxis/axisClasses';
3
4
  import type { TickParams } from '../hooks/useTicks';
4
5
  export type D3Scale = ScaleBand<any> | ScaleLogarithmic<any, any> | ScalePoint<any> | ScalePower<any, any> | ScaleTime<any, any> | ScaleLinear<any, any>;
5
6
  export type D3ContinuouseScale = ScaleLogarithmic<any, any> | ScalePower<any, any> | ScaleTime<any, any> | ScaleLinear<any, any>;
6
- export interface ChartsAxisProps {
7
+ export interface ChartsAxisSlotsComponent {
8
+ axisLine?: React.JSXElementConstructor<React.SVGAttributes<SVGPathElement>>;
9
+ axisTick?: React.JSXElementConstructor<React.SVGAttributes<SVGPathElement>>;
10
+ axisTickLabel?: React.JSXElementConstructor<React.SVGAttributes<SVGTextElement>>;
11
+ axisLabel?: React.JSXElementConstructor<React.SVGAttributes<SVGTextElement>>;
12
+ }
13
+ export interface ChartsAxisSlotComponentProps {
14
+ axisLine?: Partial<React.SVGAttributes<SVGPathElement>>;
15
+ axisTick?: Partial<React.SVGAttributes<SVGPathElement>>;
16
+ axisTickLabel?: Partial<React.SVGAttributes<SVGTextElement>>;
17
+ axisLabel?: Partial<React.SVGAttributes<SVGTextElement>>;
18
+ }
19
+ export interface ChartsAxisProps extends TickParams {
7
20
  /**
8
21
  * Id of the axis to render.
9
22
  */
@@ -51,6 +64,16 @@ export interface ChartsAxisProps {
51
64
  * Override or extend the styles applied to the component.
52
65
  */
53
66
  classes?: Partial<ChartsAxisClasses>;
67
+ /**
68
+ * Overridable component slots.
69
+ * @default {}
70
+ */
71
+ slots?: Partial<ChartsAxisSlotsComponent>;
72
+ /**
73
+ * The props used for each component slot.
74
+ * @default {}
75
+ */
76
+ slotProps?: Partial<ChartsAxisSlotComponentProps>;
54
77
  }
55
78
  export interface ChartsYAxisProps extends ChartsAxisProps {
56
79
  /**
@@ -11,6 +11,11 @@ export interface BarSeriesType extends CommonSeriesType<number>, CartesianSeries
11
11
  */
12
12
  dataKey?: string;
13
13
  label?: string;
14
+ /**
15
+ * Layout of the bars. All bar should have the same layout.
16
+ * @default 'vertical'
17
+ */
18
+ layout?: 'horizontal' | 'vertical';
14
19
  }
15
20
  /**
16
21
  * An object that allows to identify a single bar.
@@ -21,5 +26,5 @@ export type BarItemIdentifier = {
21
26
  seriesId: DefaultizedBarSeriesType['id'];
22
27
  dataIndex: number;
23
28
  };
24
- export interface DefaultizedBarSeriesType extends DefaultizedProps<BarSeriesType, CommonDefaultizedProps | 'color'> {
29
+ export interface DefaultizedBarSeriesType extends DefaultizedProps<BarSeriesType, CommonDefaultizedProps | 'color' | 'layout'> {
25
30
  }
@@ -5,7 +5,7 @@ import PropTypes from 'prop-types';
5
5
  import { BarPlot } from './BarPlot';
6
6
  import { ResponsiveChartContainer } from '../ResponsiveChartContainer';
7
7
  import { ChartsAxis } from '../ChartsAxis';
8
- import { DEFAULT_X_AXIS_KEY } from '../constants';
8
+ import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
9
9
  import { ChartsTooltip } from '../ChartsTooltip';
10
10
  import { ChartsLegend } from '../ChartsLegend';
11
11
  import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
@@ -23,6 +23,7 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
23
23
  colors,
24
24
  dataset,
25
25
  sx,
26
+ layout,
26
27
  tooltip,
27
28
  axisHighlight,
28
29
  legend,
@@ -30,41 +31,64 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
30
31
  leftAxis,
31
32
  rightAxis,
32
33
  bottomAxis,
33
- children
34
+ children,
35
+ slots,
36
+ slotProps
34
37
  } = props;
35
38
  const id = useId();
36
39
  const clipPathId = `${id}-clip-path`;
40
+ const hasHorizontalSeries = layout === 'horizontal' || layout === undefined && series.some(item => item.layout === 'horizontal');
41
+ const defaultAxisConfig = {
42
+ scaleType: 'band',
43
+ data: Array.from({
44
+ length: Math.max(...series.map(s => (s.data ?? dataset ?? []).length))
45
+ }, (_, index) => index)
46
+ };
47
+ const defaultizedAxisHighlight = _extends({}, hasHorizontalSeries ? {
48
+ y: 'band'
49
+ } : {
50
+ x: 'band'
51
+ }, axisHighlight);
37
52
  return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
38
53
  ref: ref,
39
54
  series: series.map(s => _extends({
40
55
  type: 'bar'
41
- }, s)),
56
+ }, s, {
57
+ layout: hasHorizontalSeries ? 'horizontal' : 'vertical'
58
+ })),
42
59
  width: width,
43
60
  height: height,
44
61
  margin: margin,
45
- xAxis: xAxis ?? [{
46
- id: DEFAULT_X_AXIS_KEY,
47
- scaleType: 'band',
48
- data: Array.from({
49
- length: Math.max(...series.map(s => (s.data ?? dataset ?? []).length))
50
- }, (_, index) => index)
51
- }],
52
- yAxis: yAxis,
62
+ xAxis: xAxis ?? (hasHorizontalSeries ? undefined : [_extends({
63
+ id: DEFAULT_X_AXIS_KEY
64
+ }, defaultAxisConfig)]),
65
+ yAxis: yAxis ?? (hasHorizontalSeries ? [_extends({
66
+ id: DEFAULT_Y_AXIS_KEY
67
+ }, defaultAxisConfig)] : undefined),
53
68
  colors: colors,
54
69
  dataset: dataset,
55
70
  sx: sx,
56
71
  disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none',
57
72
  children: [/*#__PURE__*/_jsx("g", {
58
73
  clipPath: `url(#${clipPathId})`,
59
- children: /*#__PURE__*/_jsx(BarPlot, {})
74
+ children: /*#__PURE__*/_jsx(BarPlot, {
75
+ slots: slots,
76
+ slotProps: slotProps
77
+ })
60
78
  }), /*#__PURE__*/_jsx(ChartsAxis, {
61
79
  topAxis: topAxis,
62
80
  leftAxis: leftAxis,
63
81
  rightAxis: rightAxis,
64
- bottomAxis: bottomAxis
65
- }), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legend)), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({
66
- x: "band"
67
- }, axisHighlight)), /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip)), /*#__PURE__*/_jsx(ChartsClipPath, {
82
+ bottomAxis: bottomAxis,
83
+ slots: slots,
84
+ slotProps: slotProps
85
+ }), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legend, {
86
+ slots: slots,
87
+ slotProps: slotProps
88
+ })), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, defaultizedAxisHighlight)), /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip, {
89
+ slots: slots,
90
+ slotProps: slotProps
91
+ })), /*#__PURE__*/_jsx(ChartsClipPath, {
68
92
  id: clipPathId
69
93
  }), children]
70
94
  });
@@ -76,7 +100,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
76
100
  // ----------------------------------------------------------------------
77
101
  axisHighlight: PropTypes.shape({
78
102
  x: PropTypes.oneOf(['band', 'line', 'none']),
79
- y: PropTypes.oneOf(['line', 'none'])
103
+ y: PropTypes.oneOf(['band', 'line', 'none'])
80
104
  }),
81
105
  /**
82
106
  * Indicate which axis to display the bottom of the charts.
@@ -92,8 +116,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
92
116
  label: PropTypes.string,
93
117
  labelFontSize: PropTypes.number,
94
118
  position: PropTypes.oneOf(['bottom', 'top']),
119
+ slotProps: PropTypes.object,
120
+ slots: PropTypes.object,
95
121
  stroke: PropTypes.string,
96
122
  tickFontSize: PropTypes.number,
123
+ tickMaxStep: PropTypes.number,
124
+ tickMinStep: PropTypes.number,
125
+ tickNumber: PropTypes.number,
97
126
  tickSize: PropTypes.number
98
127
  }), PropTypes.string]),
99
128
  children: PropTypes.node,
@@ -106,6 +135,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
106
135
  desc: PropTypes.string,
107
136
  disableAxisListener: PropTypes.bool,
108
137
  height: PropTypes.number,
138
+ layout: PropTypes.oneOf(['horizontal', 'vertical']),
109
139
  /**
110
140
  * Indicate which axis to display the left of the charts.
111
141
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
@@ -120,8 +150,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
120
150
  label: PropTypes.string,
121
151
  labelFontSize: PropTypes.number,
122
152
  position: PropTypes.oneOf(['left', 'right']),
153
+ slotProps: PropTypes.object,
154
+ slots: PropTypes.object,
123
155
  stroke: PropTypes.string,
124
156
  tickFontSize: PropTypes.number,
157
+ tickMaxStep: PropTypes.number,
158
+ tickMinStep: PropTypes.number,
159
+ tickNumber: PropTypes.number,
125
160
  tickSize: PropTypes.number
126
161
  }), PropTypes.string]),
127
162
  legend: PropTypes.shape({
@@ -138,6 +173,8 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
138
173
  horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
139
174
  vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
140
175
  }),
176
+ slotProps: PropTypes.object,
177
+ slots: PropTypes.object,
141
178
  spacing: PropTypes.number
142
179
  }),
143
180
  margin: PropTypes.shape({
@@ -160,8 +197,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
160
197
  label: PropTypes.string,
161
198
  labelFontSize: PropTypes.number,
162
199
  position: PropTypes.oneOf(['left', 'right']),
200
+ slotProps: PropTypes.object,
201
+ slots: PropTypes.object,
163
202
  stroke: PropTypes.string,
164
203
  tickFontSize: PropTypes.number,
204
+ tickMaxStep: PropTypes.number,
205
+ tickMinStep: PropTypes.number,
206
+ tickNumber: PropTypes.number,
165
207
  tickSize: PropTypes.number
166
208
  }), PropTypes.string]),
167
209
  series: PropTypes.arrayOf(PropTypes.shape({
@@ -174,6 +216,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
174
216
  }),
175
217
  id: PropTypes.string,
176
218
  label: PropTypes.string,
219
+ layout: PropTypes.oneOf(['horizontal', 'vertical']),
177
220
  stack: PropTypes.string,
178
221
  stackOffset: PropTypes.oneOf(['diverging', 'expand', 'none', 'silhouette', 'wiggle']),
179
222
  stackOrder: PropTypes.oneOf(['appearance', 'ascending', 'descending', 'insideOut', 'none', 'reverse']),
@@ -182,6 +225,16 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
182
225
  xAxisKey: PropTypes.string,
183
226
  yAxisKey: PropTypes.string
184
227
  })).isRequired,
228
+ /**
229
+ * The props used for each component slot.
230
+ * @default {}
231
+ */
232
+ slotProps: PropTypes.object,
233
+ /**
234
+ * Overridable component slots.
235
+ * @default {}
236
+ */
237
+ slots: PropTypes.object,
185
238
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
186
239
  title: PropTypes.string,
187
240
  tooltip: PropTypes.shape({
@@ -204,8 +257,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
204
257
  label: PropTypes.string,
205
258
  labelFontSize: PropTypes.number,
206
259
  position: PropTypes.oneOf(['bottom', 'top']),
260
+ slotProps: PropTypes.object,
261
+ slots: PropTypes.object,
207
262
  stroke: PropTypes.string,
208
263
  tickFontSize: PropTypes.number,
264
+ tickMaxStep: PropTypes.number,
265
+ tickMinStep: PropTypes.number,
266
+ tickNumber: PropTypes.number,
209
267
  tickSize: PropTypes.number
210
268
  }), PropTypes.string]),
211
269
  viewBox: PropTypes.shape({
@@ -228,15 +286,17 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
228
286
  label: PropTypes.string,
229
287
  labelFontSize: PropTypes.number,
230
288
  max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
231
- maxTicks: PropTypes.number,
232
289
  min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
233
- minTicks: PropTypes.number,
234
290
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
235
291
  scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
292
+ slotProps: PropTypes.object,
293
+ slots: PropTypes.object,
236
294
  stroke: PropTypes.string,
237
295
  tickFontSize: PropTypes.number,
296
+ tickMaxStep: PropTypes.number,
297
+ tickMinStep: PropTypes.number,
298
+ tickNumber: PropTypes.number,
238
299
  tickSize: PropTypes.number,
239
- tickSpacing: PropTypes.number,
240
300
  valueFormatter: PropTypes.func
241
301
  })),
242
302
  yAxis: PropTypes.arrayOf(PropTypes.shape({
@@ -252,15 +312,17 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
252
312
  label: PropTypes.string,
253
313
  labelFontSize: PropTypes.number,
254
314
  max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
255
- maxTicks: PropTypes.number,
256
315
  min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
257
- minTicks: PropTypes.number,
258
316
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
259
317
  scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
318
+ slotProps: PropTypes.object,
319
+ slots: PropTypes.object,
260
320
  stroke: PropTypes.string,
261
321
  tickFontSize: PropTypes.number,
322
+ tickMaxStep: PropTypes.number,
323
+ tickMinStep: PropTypes.number,
324
+ tickNumber: PropTypes.number,
262
325
  tickSize: PropTypes.number,
263
- tickSpacing: PropTypes.number,
264
326
  valueFormatter: PropTypes.func
265
327
  }))
266
328
  } : void 0;
@@ -1,8 +1,9 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["id", "dataIndex", "classes", "color", "highlightScope"];
3
+ const _excluded = ["id", "dataIndex", "classes", "color", "highlightScope", "slots", "slotProps"];
4
4
  import * as React from 'react';
5
5
  import composeClasses from '@mui/utils/composeClasses';
6
+ import { useSlotProps } from '@mui/base/utils';
6
7
  import generateUtilityClass from '@mui/utils/generateUtilityClass';
7
8
  import { styled } from '@mui/material/styles';
8
9
  import { color as d3Color } from 'd3-color';
@@ -24,7 +25,7 @@ const useUtilityClasses = ownerState => {
24
25
  };
25
26
  return composeClasses(slots, getBarElementUtilityClass, classes);
26
27
  };
27
- const BarElementPath = styled('rect', {
28
+ export const BarElementPath = styled('rect', {
28
29
  name: 'MuiBarElement',
29
30
  slot: 'Root',
30
31
  overridesResolver: (_, styles) => styles.root
@@ -43,7 +44,9 @@ export function BarElement(props) {
43
44
  dataIndex,
44
45
  classes: innerClasses,
45
46
  color,
46
- highlightScope
47
+ highlightScope,
48
+ slots,
49
+ slotProps
47
50
  } = props,
48
51
  other = _objectWithoutPropertiesLoose(props, _excluded);
49
52
  const getInteractionItemProps = useInteractionItemProps(highlightScope);
@@ -69,12 +72,18 @@ export function BarElement(props) {
69
72
  isHighlighted
70
73
  };
71
74
  const classes = useUtilityClasses(ownerState);
72
- return /*#__PURE__*/_jsx(BarElementPath, _extends({}, other, {
73
- ownerState: ownerState,
74
- className: classes.root
75
- }, getInteractionItemProps({
76
- type: 'bar',
77
- seriesId: id,
78
- dataIndex
79
- })));
75
+ const Bar = slots?.bar ?? BarElementPath;
76
+ const barProps = useSlotProps({
77
+ elementType: Bar,
78
+ externalSlotProps: slotProps?.bar,
79
+ additionalProps: _extends({}, other, getInteractionItemProps({
80
+ type: 'bar',
81
+ seriesId: id,
82
+ dataIndex
83
+ }), {
84
+ className: classes.root
85
+ }),
86
+ ownerState
87
+ });
88
+ return /*#__PURE__*/_jsx(Bar, _extends({}, barProps));
80
89
  }