@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
@@ -16,9 +16,9 @@ const mangoFusionPaletteDark = ['#41698F', '#19D0CD', '#DE196B', '#FC5F5C', '#FF
16
16
  exports.mangoFusionPaletteDark = mangoFusionPaletteDark;
17
17
  const mangoFusionPalette = mode => mode === 'dark' ? mangoFusionPaletteDark : mangoFusionPaletteLight;
18
18
  exports.mangoFusionPalette = mangoFusionPalette;
19
- const cheerfulFiestaPaletteDark = ['#0072E6', '#66B2FF', '#FFB017', '#1F94AD', '#FF3143', '#FF6C63'];
19
+ const cheerfulFiestaPaletteDark = ['#0059B2', '#2E96FF', '#FFC24C', '#FF9F0E', '#F38200', '#2ABFDE', '#1F94AD', '#BD2C38', '#FF3143', '#FF8282'];
20
20
  exports.cheerfulFiestaPaletteDark = cheerfulFiestaPaletteDark;
21
- const cheerfulFiestaPaletteLight = ['#0059B2', '#2E96FF', '#EA8C00', '#1F94AD', '#C82634', '#FF3143'];
21
+ const cheerfulFiestaPaletteLight = ['#003A75', '#007FFF', '#FFC24C', '#FF9D09', '#CA6C00', '#127D94', '#1F94AD', '#C82634', '#FF3143', '#FF7E7E'];
22
22
  exports.cheerfulFiestaPaletteLight = cheerfulFiestaPaletteLight;
23
23
  const cheerfulFiestaPalette = mode => mode === 'dark' ? cheerfulFiestaPaletteDark : cheerfulFiestaPaletteLight;
24
24
  exports.cheerfulFiestaPalette = cheerfulFiestaPalette;
@@ -134,7 +134,8 @@ function CartesianContextProvider({
134
134
  const scaleType = axis.scaleType ?? 'linear';
135
135
  const extremums = [axis.min ?? minData, axis.max ?? maxData];
136
136
  const ticksNumber = (0, _useTicks.getTicksNumber)((0, _extends2.default)({}, axis, {
137
- range
137
+ range,
138
+ domain: extremums
138
139
  }));
139
140
  const niceScale = (0, _getScale.getScale)(scaleType, extremums, range).nice(ticksNumber);
140
141
  const niceDomain = niceScale.domain();
@@ -160,17 +161,17 @@ function CartesianContextProvider({
160
161
  const range = [drawingArea.top + drawingArea.height, drawingArea.top];
161
162
  if ((0, _axis.isBandScaleConfig)(axis)) {
162
163
  const categoryGapRatio = axis.categoryGapRatio ?? DEFAULT_CATEGORY_GAP_RATIO;
163
- completedXAxis[axis.id] = (0, _extends2.default)({
164
+ completedYAxis[axis.id] = (0, _extends2.default)({
164
165
  categoryGapRatio,
165
166
  barGapRatio: 0
166
167
  }, axis, {
167
- scale: (0, _d3Scale.scaleBand)(axis.data, range).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
168
+ scale: (0, _d3Scale.scaleBand)(axis.data, [range[1], range[0]]).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
168
169
  ticksNumber: axis.data.length
169
170
  });
170
171
  }
171
172
  if ((0, _axis.isPointScaleConfig)(axis)) {
172
- completedXAxis[axis.id] = (0, _extends2.default)({}, axis, {
173
- scale: (0, _d3Scale.scalePoint)(axis.data, range),
173
+ completedYAxis[axis.id] = (0, _extends2.default)({}, axis, {
174
+ scale: (0, _d3Scale.scalePoint)(axis.data, [range[1], range[0]]),
174
175
  ticksNumber: axis.data.length
175
176
  });
176
177
  }
@@ -181,7 +182,8 @@ function CartesianContextProvider({
181
182
  const scaleType = axis.scaleType ?? 'linear';
182
183
  const extremums = [axis.min ?? minData, axis.max ?? maxData];
183
184
  const ticksNumber = (0, _useTicks.getTicksNumber)((0, _extends2.default)({}, axis, {
184
- range
185
+ range,
186
+ domain: extremums
185
187
  }));
186
188
  const niceScale = (0, _getScale.getScale)(scaleType, extremums, range).nice(ticksNumber);
187
189
  const niceDomain = niceScale.domain();
@@ -230,15 +232,17 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
230
232
  label: _propTypes.default.string,
231
233
  labelFontSize: _propTypes.default.number,
232
234
  max: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
233
- maxTicks: _propTypes.default.number,
234
235
  min: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
235
- minTicks: _propTypes.default.number,
236
236
  position: _propTypes.default.oneOf(['bottom', 'left', 'right', 'top']),
237
237
  scaleType: _propTypes.default.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
238
+ slotProps: _propTypes.default.object,
239
+ slots: _propTypes.default.object,
238
240
  stroke: _propTypes.default.string,
239
241
  tickFontSize: _propTypes.default.number,
242
+ tickMaxStep: _propTypes.default.number,
243
+ tickMinStep: _propTypes.default.number,
244
+ tickNumber: _propTypes.default.number,
240
245
  tickSize: _propTypes.default.number,
241
- tickSpacing: _propTypes.default.number,
242
246
  valueFormatter: _propTypes.default.func
243
247
  })),
244
248
  yAxis: _propTypes.default.arrayOf(_propTypes.default.shape({
@@ -254,15 +258,17 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
254
258
  label: _propTypes.default.string,
255
259
  labelFontSize: _propTypes.default.number,
256
260
  max: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
257
- maxTicks: _propTypes.default.number,
258
261
  min: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
259
- minTicks: _propTypes.default.number,
260
262
  position: _propTypes.default.oneOf(['bottom', 'left', 'right', 'top']),
261
263
  scaleType: _propTypes.default.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
264
+ slotProps: _propTypes.default.object,
265
+ slots: _propTypes.default.object,
262
266
  stroke: _propTypes.default.string,
263
267
  tickFontSize: _propTypes.default.number,
268
+ tickMaxStep: _propTypes.default.number,
269
+ tickMinStep: _propTypes.default.number,
270
+ tickNumber: _propTypes.default.number,
264
271
  tickSize: _propTypes.default.number,
265
- tickSpacing: _propTypes.default.number,
266
272
  valueFormatter: _propTypes.default.func
267
273
  }))
268
274
  } : void 0;
@@ -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,44 +31,67 @@ 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 => {
45
+ var _ref, _s$data;
46
+ return ((_ref = (_s$data = s.data) != null ? _s$data : dataset) != null ? _ref : []).length;
47
+ }))
48
+ }, (_, index) => index)
49
+ };
50
+ const defaultizedAxisHighlight = _extends({}, hasHorizontalSeries ? {
51
+ y: 'band'
52
+ } : {
53
+ x: 'band'
54
+ }, axisHighlight);
37
55
  return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
38
56
  ref: ref,
39
57
  series: series.map(s => _extends({
40
58
  type: 'bar'
41
- }, s)),
59
+ }, s, {
60
+ layout: hasHorizontalSeries ? 'horizontal' : 'vertical'
61
+ })),
42
62
  width: width,
43
63
  height: height,
44
64
  margin: margin,
45
- xAxis: xAxis != null ? xAxis : [{
46
- id: DEFAULT_X_AXIS_KEY,
47
- scaleType: 'band',
48
- data: Array.from({
49
- length: Math.max(...series.map(s => {
50
- var _ref, _s$data;
51
- return ((_ref = (_s$data = s.data) != null ? _s$data : dataset) != null ? _ref : []).length;
52
- }))
53
- }, (_, index) => index)
54
- }],
55
- yAxis: yAxis,
65
+ xAxis: xAxis != null ? xAxis : hasHorizontalSeries ? undefined : [_extends({
66
+ id: DEFAULT_X_AXIS_KEY
67
+ }, defaultAxisConfig)],
68
+ yAxis: yAxis != null ? yAxis : hasHorizontalSeries ? [_extends({
69
+ id: DEFAULT_Y_AXIS_KEY
70
+ }, defaultAxisConfig)] : undefined,
56
71
  colors: colors,
57
72
  dataset: dataset,
58
73
  sx: sx,
59
74
  disableAxisListener: (tooltip == null ? void 0 : tooltip.trigger) !== 'axis' && (axisHighlight == null ? void 0 : axisHighlight.x) === 'none' && (axisHighlight == null ? void 0 : axisHighlight.y) === 'none',
60
75
  children: [/*#__PURE__*/_jsx("g", {
61
76
  clipPath: `url(#${clipPathId})`,
62
- children: /*#__PURE__*/_jsx(BarPlot, {})
77
+ children: /*#__PURE__*/_jsx(BarPlot, {
78
+ slots: slots,
79
+ slotProps: slotProps
80
+ })
63
81
  }), /*#__PURE__*/_jsx(ChartsAxis, {
64
82
  topAxis: topAxis,
65
83
  leftAxis: leftAxis,
66
84
  rightAxis: rightAxis,
67
- bottomAxis: bottomAxis
68
- }), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legend)), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({
69
- x: "band"
70
- }, axisHighlight)), /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip)), /*#__PURE__*/_jsx(ChartsClipPath, {
85
+ bottomAxis: bottomAxis,
86
+ slots: slots,
87
+ slotProps: slotProps
88
+ }), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legend, {
89
+ slots: slots,
90
+ slotProps: slotProps
91
+ })), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, defaultizedAxisHighlight)), /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip, {
92
+ slots: slots,
93
+ slotProps: slotProps
94
+ })), /*#__PURE__*/_jsx(ChartsClipPath, {
71
95
  id: clipPathId
72
96
  }), children]
73
97
  });
@@ -79,7 +103,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
79
103
  // ----------------------------------------------------------------------
80
104
  axisHighlight: PropTypes.shape({
81
105
  x: PropTypes.oneOf(['band', 'line', 'none']),
82
- y: PropTypes.oneOf(['line', 'none'])
106
+ y: PropTypes.oneOf(['band', 'line', 'none'])
83
107
  }),
84
108
  /**
85
109
  * Indicate which axis to display the bottom of the charts.
@@ -95,8 +119,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
95
119
  label: PropTypes.string,
96
120
  labelFontSize: PropTypes.number,
97
121
  position: PropTypes.oneOf(['bottom', 'top']),
122
+ slotProps: PropTypes.object,
123
+ slots: PropTypes.object,
98
124
  stroke: PropTypes.string,
99
125
  tickFontSize: PropTypes.number,
126
+ tickMaxStep: PropTypes.number,
127
+ tickMinStep: PropTypes.number,
128
+ tickNumber: PropTypes.number,
100
129
  tickSize: PropTypes.number
101
130
  }), PropTypes.string]),
102
131
  children: PropTypes.node,
@@ -109,6 +138,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
109
138
  desc: PropTypes.string,
110
139
  disableAxisListener: PropTypes.bool,
111
140
  height: PropTypes.number,
141
+ layout: PropTypes.oneOf(['horizontal', 'vertical']),
112
142
  /**
113
143
  * Indicate which axis to display the left of the charts.
114
144
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
@@ -123,8 +153,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
123
153
  label: PropTypes.string,
124
154
  labelFontSize: PropTypes.number,
125
155
  position: PropTypes.oneOf(['left', 'right']),
156
+ slotProps: PropTypes.object,
157
+ slots: PropTypes.object,
126
158
  stroke: PropTypes.string,
127
159
  tickFontSize: PropTypes.number,
160
+ tickMaxStep: PropTypes.number,
161
+ tickMinStep: PropTypes.number,
162
+ tickNumber: PropTypes.number,
128
163
  tickSize: PropTypes.number
129
164
  }), PropTypes.string]),
130
165
  legend: PropTypes.shape({
@@ -141,6 +176,8 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
141
176
  horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
142
177
  vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
143
178
  }),
179
+ slotProps: PropTypes.object,
180
+ slots: PropTypes.object,
144
181
  spacing: PropTypes.number
145
182
  }),
146
183
  margin: PropTypes.shape({
@@ -163,8 +200,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
163
200
  label: PropTypes.string,
164
201
  labelFontSize: PropTypes.number,
165
202
  position: PropTypes.oneOf(['left', 'right']),
203
+ slotProps: PropTypes.object,
204
+ slots: PropTypes.object,
166
205
  stroke: PropTypes.string,
167
206
  tickFontSize: PropTypes.number,
207
+ tickMaxStep: PropTypes.number,
208
+ tickMinStep: PropTypes.number,
209
+ tickNumber: PropTypes.number,
168
210
  tickSize: PropTypes.number
169
211
  }), PropTypes.string]),
170
212
  series: PropTypes.arrayOf(PropTypes.shape({
@@ -177,6 +219,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
177
219
  }),
178
220
  id: PropTypes.string,
179
221
  label: PropTypes.string,
222
+ layout: PropTypes.oneOf(['horizontal', 'vertical']),
180
223
  stack: PropTypes.string,
181
224
  stackOffset: PropTypes.oneOf(['diverging', 'expand', 'none', 'silhouette', 'wiggle']),
182
225
  stackOrder: PropTypes.oneOf(['appearance', 'ascending', 'descending', 'insideOut', 'none', 'reverse']),
@@ -185,6 +228,16 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
185
228
  xAxisKey: PropTypes.string,
186
229
  yAxisKey: PropTypes.string
187
230
  })).isRequired,
231
+ /**
232
+ * The props used for each component slot.
233
+ * @default {}
234
+ */
235
+ slotProps: PropTypes.object,
236
+ /**
237
+ * Overridable component slots.
238
+ * @default {}
239
+ */
240
+ slots: PropTypes.object,
188
241
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
189
242
  title: PropTypes.string,
190
243
  tooltip: PropTypes.shape({
@@ -207,8 +260,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
207
260
  label: PropTypes.string,
208
261
  labelFontSize: PropTypes.number,
209
262
  position: PropTypes.oneOf(['bottom', 'top']),
263
+ slotProps: PropTypes.object,
264
+ slots: PropTypes.object,
210
265
  stroke: PropTypes.string,
211
266
  tickFontSize: PropTypes.number,
267
+ tickMaxStep: PropTypes.number,
268
+ tickMinStep: PropTypes.number,
269
+ tickNumber: PropTypes.number,
212
270
  tickSize: PropTypes.number
213
271
  }), PropTypes.string]),
214
272
  viewBox: PropTypes.shape({
@@ -231,15 +289,17 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
231
289
  label: PropTypes.string,
232
290
  labelFontSize: PropTypes.number,
233
291
  max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
234
- maxTicks: PropTypes.number,
235
292
  min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
236
- minTicks: PropTypes.number,
237
293
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
238
294
  scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
295
+ slotProps: PropTypes.object,
296
+ slots: PropTypes.object,
239
297
  stroke: PropTypes.string,
240
298
  tickFontSize: PropTypes.number,
299
+ tickMaxStep: PropTypes.number,
300
+ tickMinStep: PropTypes.number,
301
+ tickNumber: PropTypes.number,
241
302
  tickSize: PropTypes.number,
242
- tickSpacing: PropTypes.number,
243
303
  valueFormatter: PropTypes.func
244
304
  })),
245
305
  yAxis: PropTypes.arrayOf(PropTypes.shape({
@@ -255,15 +315,17 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
255
315
  label: PropTypes.string,
256
316
  labelFontSize: PropTypes.number,
257
317
  max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
258
- maxTicks: PropTypes.number,
259
318
  min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
260
- minTicks: PropTypes.number,
261
319
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
262
320
  scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
321
+ slotProps: PropTypes.object,
322
+ slots: PropTypes.object,
263
323
  stroke: PropTypes.string,
264
324
  tickFontSize: PropTypes.number,
325
+ tickMaxStep: PropTypes.number,
326
+ tickMinStep: PropTypes.number,
327
+ tickNumber: PropTypes.number,
265
328
  tickSize: PropTypes.number,
266
- tickSpacing: PropTypes.number,
267
329
  valueFormatter: PropTypes.func
268
330
  }))
269
331
  } : 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
@@ -38,12 +39,15 @@ const BarElementPath = styled('rect', {
38
39
  opacity: ownerState.isFaded && 0.3 || 1
39
40
  }));
40
41
  export function BarElement(props) {
42
+ var _slots$bar;
41
43
  const {
42
44
  id,
43
45
  dataIndex,
44
46
  classes: innerClasses,
45
47
  color,
46
- highlightScope
48
+ highlightScope,
49
+ slots,
50
+ slotProps
47
51
  } = props,
48
52
  other = _objectWithoutPropertiesLoose(props, _excluded);
49
53
  const getInteractionItemProps = useInteractionItemProps(highlightScope);
@@ -69,12 +73,18 @@ export function BarElement(props) {
69
73
  isHighlighted
70
74
  };
71
75
  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
- })));
76
+ const Bar = (_slots$bar = slots == null ? void 0 : slots.bar) != null ? _slots$bar : BarElementPath;
77
+ const barProps = useSlotProps({
78
+ elementType: Bar,
79
+ externalSlotProps: slotProps == null ? void 0 : slotProps.bar,
80
+ additionalProps: _extends({}, other, getInteractionItemProps({
81
+ type: 'bar',
82
+ seriesId: id,
83
+ dataIndex
84
+ }), {
85
+ className: classes.root
86
+ }),
87
+ ownerState
88
+ });
89
+ return /*#__PURE__*/_jsx(Bar, _extends({}, barProps));
80
90
  }
@@ -1,4 +1,6 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
1
2
  import * as React from 'react';
3
+ import PropTypes from 'prop-types';
2
4
  import { SeriesContext } from '../context/SeriesContextProvider';
3
5
  import { CartesianContext } from '../context/CartesianContextProvider';
4
6
  import { BarElement } from './BarElement';
@@ -32,7 +34,7 @@ function getBandSize({
32
34
  offset
33
35
  };
34
36
  }
35
- export function BarPlot() {
37
+ function BarPlot(props) {
36
38
  const seriesData = React.useContext(SeriesContext).bar;
37
39
  const axisData = React.useContext(CartesianContext);
38
40
  if (seriesData === undefined) {
@@ -60,47 +62,74 @@ export function BarPlot() {
60
62
  const yAxisKey = (_series$seriesId$yAxi = series[seriesId].yAxisKey) != null ? _series$seriesId$yAxi : defaultYAxisId;
61
63
  const xAxisConfig = xAxis[xAxisKey];
62
64
  const yAxisConfig = yAxis[yAxisKey];
63
- if (!isBandScaleConfig(xAxisConfig)) {
64
- throw new Error(`Axis with id "${xAxisKey}" shoud be of type "band" to display the bar series of id "${seriesId}"`);
65
- }
66
- if (xAxis[xAxisKey].data === undefined) {
67
- throw new Error(`Axis with id "${xAxisKey}" shoud have data property`);
65
+ const verticalLayout = series[seriesId].layout === 'vertical';
66
+ let baseScaleConfig;
67
+ if (verticalLayout) {
68
+ if (!isBandScaleConfig(xAxisConfig)) {
69
+ throw new Error(`Axis with id "${xAxisKey}" shoud be of type "band" to display the bar series of id "${seriesId}"`);
70
+ }
71
+ if (xAxis[xAxisKey].data === undefined) {
72
+ throw new Error(`Axis with id "${xAxisKey}" shoud have data property`);
73
+ }
74
+ baseScaleConfig = xAxisConfig;
75
+ } else {
76
+ if (!isBandScaleConfig(yAxisConfig)) {
77
+ throw new Error(`Axis with id "${yAxisKey}" shoud be of type "band" to display the bar series of id "${seriesId}"`);
78
+ }
79
+ if (yAxis[yAxisKey].data === undefined) {
80
+ throw new Error(`Axis with id "${xAxisKey}" shoud have data property`);
81
+ }
82
+ baseScaleConfig = yAxisConfig;
68
83
  }
69
84
  const xScale = xAxisConfig.scale;
70
85
  const yScale = yAxisConfig.scale;
71
-
72
- // Currently assuming all bars are vertical
73
- const bandWidth = xScale.bandwidth();
86
+ const bandWidth = baseScaleConfig.scale.bandwidth();
74
87
  const {
75
88
  barWidth,
76
89
  offset
77
90
  } = getBandSize({
78
91
  bandWidth,
79
92
  numberOfGroups: stackingGroups.length,
80
- gapRatio: xAxisConfig.barGapRatio
93
+ gapRatio: baseScaleConfig.barGapRatio
81
94
  });
82
-
83
- // @ts-ignore TODO: fix when adding a correct API for customisation
95
+ const barOffset = groupIndex * (barWidth + offset);
84
96
  const {
85
97
  stackedData,
86
98
  color
87
99
  } = series[seriesId];
88
100
  return stackedData.map((values, dataIndex) => {
89
- var _xAxis$xAxisKey$data;
101
+ var _xAxis$xAxisKey$data, _yAxis$yAxisKey$data;
90
102
  const baseline = Math.min(...values);
91
103
  const value = Math.max(...values);
92
- return /*#__PURE__*/_jsx(BarElement, {
104
+ return /*#__PURE__*/_jsx(BarElement, _extends({
93
105
  id: seriesId,
94
106
  dataIndex: dataIndex,
95
- x: xScale((_xAxis$xAxisKey$data = xAxis[xAxisKey].data) == null ? void 0 : _xAxis$xAxisKey$data[dataIndex]) + groupIndex * (barWidth + offset),
96
- y: yScale(value),
97
- height: yScale(baseline) - yScale(value),
98
- width: barWidth,
107
+ x: verticalLayout ? xScale((_xAxis$xAxisKey$data = xAxis[xAxisKey].data) == null ? void 0 : _xAxis$xAxisKey$data[dataIndex]) + barOffset : xScale(baseline),
108
+ y: verticalLayout ? yScale(value) : yScale((_yAxis$yAxisKey$data = yAxis[yAxisKey].data) == null ? void 0 : _yAxis$yAxisKey$data[dataIndex]) + barOffset,
109
+ height: verticalLayout ? Math.abs(yScale(baseline) - yScale(value)) : barWidth,
110
+ width: verticalLayout ? barWidth : Math.abs(xScale(baseline) - xScale(value)),
99
111
  color: color,
100
112
  highlightScope: series[seriesId].highlightScope
101
- }, `${seriesId}-${dataIndex}`);
113
+ }, props), `${seriesId}-${dataIndex}`);
102
114
  });
103
115
  });
104
116
  })
105
117
  });
106
- }
118
+ }
119
+ process.env.NODE_ENV !== "production" ? BarPlot.propTypes = {
120
+ // ----------------------------- Warning --------------------------------
121
+ // | These PropTypes are generated from the TypeScript type definitions |
122
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
123
+ // ----------------------------------------------------------------------
124
+ /**
125
+ * The props used for each component slot.
126
+ * @default {}
127
+ */
128
+ slotProps: PropTypes.object,
129
+ /**
130
+ * Overridable component slots.
131
+ * @default {}
132
+ */
133
+ slots: PropTypes.object
134
+ } : void 0;
135
+ export { BarPlot };
@@ -1,4 +1,4 @@
1
- export const getExtremumX = params => {
1
+ const getBaseExtremum = params => {
2
2
  var _axis$data, _axis$data2;
3
3
  const {
4
4
  axis
@@ -7,7 +7,7 @@ export const getExtremumX = params => {
7
7
  const maxX = Math.max(...((_axis$data2 = axis.data) != null ? _axis$data2 : []));
8
8
  return [minX, maxX];
9
9
  };
10
- export const getExtremumY = params => {
10
+ const getValueExtremum = params => {
11
11
  const {
12
12
  series,
13
13
  axis,
@@ -17,4 +17,20 @@ export const getExtremumY = params => {
17
17
  const [seriesMin, seriesMax] = series[seriesId].stackedData.reduce((seriesAcc, values) => [Math.min(...values, ...(seriesAcc[0] === null ? [] : [seriesAcc[0]])), Math.max(...values, ...(seriesAcc[1] === null ? [] : [seriesAcc[1]]))], series[seriesId].stackedData[0]);
18
18
  return [acc[0] === null ? seriesMin : Math.min(seriesMin, acc[0]), acc[1] === null ? seriesMax : Math.max(seriesMax, acc[1])];
19
19
  }, [null, null]);
20
+ };
21
+ export const getExtremumX = params => {
22
+ // Notice that bar should be all horizontal or all vertical.
23
+ // Don't think it's a problem for now
24
+ const isHorizontal = Object.keys(params.series).some(seriesId => params.series[seriesId].layout === 'horizontal');
25
+ if (isHorizontal) {
26
+ return getValueExtremum(params);
27
+ }
28
+ return getBaseExtremum(params);
29
+ };
30
+ export const getExtremumY = params => {
31
+ const isHorizontal = Object.keys(params.series).some(seriesId => params.series[seriesId].layout === 'horizontal');
32
+ if (isHorizontal) {
33
+ return getBaseExtremum(params);
34
+ }
35
+ return getValueExtremum(params);
20
36
  };
@@ -42,7 +42,9 @@ const formatter = (params, dataset) => {
42
42
  })).order(stackingOrder).offset(stackingOffset)(d3Dataset);
43
43
  ids.forEach((id, index) => {
44
44
  const dataKey = series[id].dataKey;
45
- completedSeries[id] = _extends({}, series[id], {
45
+ completedSeries[id] = _extends({
46
+ layout: 'vertical'
47
+ }, series[id], {
46
48
  data: dataKey ? dataset.map(d => d[dataKey]) : series[id].data,
47
49
  stackedData: stackedSeries[index].map(([a, b]) => [a, b])
48
50
  });