@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,16 +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
32
  declare const BarChart: React.ForwardRefExoticComponent<BarChartProps & React.RefAttributes<unknown>>;
16
33
  export { BarChart };
@@ -31,6 +31,7 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
31
31
  colors,
32
32
  dataset,
33
33
  sx,
34
+ layout,
34
35
  tooltip,
35
36
  axisHighlight,
36
37
  legend,
@@ -38,41 +39,64 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
38
39
  leftAxis,
39
40
  rightAxis,
40
41
  bottomAxis,
41
- children
42
+ children,
43
+ slots,
44
+ slotProps
42
45
  } = props;
43
46
  const id = (0, _useId.default)();
44
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);
45
60
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_ResponsiveChartContainer.ResponsiveChartContainer, {
46
61
  ref: ref,
47
62
  series: series.map(s => (0, _extends2.default)({
48
63
  type: 'bar'
49
- }, s)),
64
+ }, s, {
65
+ layout: hasHorizontalSeries ? 'horizontal' : 'vertical'
66
+ })),
50
67
  width: width,
51
68
  height: height,
52
69
  margin: margin,
53
- xAxis: xAxis ?? [{
54
- id: _constants.DEFAULT_X_AXIS_KEY,
55
- scaleType: 'band',
56
- data: Array.from({
57
- length: Math.max(...series.map(s => (s.data ?? dataset ?? []).length))
58
- }, (_, index) => index)
59
- }],
60
- 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),
61
76
  colors: colors,
62
77
  dataset: dataset,
63
78
  sx: sx,
64
79
  disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none',
65
80
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
66
81
  clipPath: `url(#${clipPathId})`,
67
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_BarPlot.BarPlot, {})
82
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_BarPlot.BarPlot, {
83
+ slots: slots,
84
+ slotProps: slotProps
85
+ })
68
86
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsAxis.ChartsAxis, {
69
87
  topAxis: topAxis,
70
88
  leftAxis: leftAxis,
71
89
  rightAxis: rightAxis,
72
- bottomAxis: bottomAxis
73
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsLegend.ChartsLegend, (0, _extends2.default)({}, legend)), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsAxisHighlight.ChartsAxisHighlight, (0, _extends2.default)({
74
- x: "band"
75
- }, 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, {
76
100
  id: clipPathId
77
101
  }), children]
78
102
  });
@@ -85,7 +109,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
85
109
  // ----------------------------------------------------------------------
86
110
  axisHighlight: _propTypes.default.shape({
87
111
  x: _propTypes.default.oneOf(['band', 'line', 'none']),
88
- y: _propTypes.default.oneOf(['line', 'none'])
112
+ y: _propTypes.default.oneOf(['band', 'line', 'none'])
89
113
  }),
90
114
  /**
91
115
  * Indicate which axis to display the bottom of the charts.
@@ -101,8 +125,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
101
125
  label: _propTypes.default.string,
102
126
  labelFontSize: _propTypes.default.number,
103
127
  position: _propTypes.default.oneOf(['bottom', 'top']),
128
+ slotProps: _propTypes.default.object,
129
+ slots: _propTypes.default.object,
104
130
  stroke: _propTypes.default.string,
105
131
  tickFontSize: _propTypes.default.number,
132
+ tickMaxStep: _propTypes.default.number,
133
+ tickMinStep: _propTypes.default.number,
134
+ tickNumber: _propTypes.default.number,
106
135
  tickSize: _propTypes.default.number
107
136
  }), _propTypes.default.string]),
108
137
  children: _propTypes.default.node,
@@ -115,6 +144,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
115
144
  desc: _propTypes.default.string,
116
145
  disableAxisListener: _propTypes.default.bool,
117
146
  height: _propTypes.default.number,
147
+ layout: _propTypes.default.oneOf(['horizontal', 'vertical']),
118
148
  /**
119
149
  * Indicate which axis to display the left of the charts.
120
150
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
@@ -129,8 +159,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
129
159
  label: _propTypes.default.string,
130
160
  labelFontSize: _propTypes.default.number,
131
161
  position: _propTypes.default.oneOf(['left', 'right']),
162
+ slotProps: _propTypes.default.object,
163
+ slots: _propTypes.default.object,
132
164
  stroke: _propTypes.default.string,
133
165
  tickFontSize: _propTypes.default.number,
166
+ tickMaxStep: _propTypes.default.number,
167
+ tickMinStep: _propTypes.default.number,
168
+ tickNumber: _propTypes.default.number,
134
169
  tickSize: _propTypes.default.number
135
170
  }), _propTypes.default.string]),
136
171
  legend: _propTypes.default.shape({
@@ -147,6 +182,8 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
147
182
  horizontal: _propTypes.default.oneOf(['left', 'middle', 'right']).isRequired,
148
183
  vertical: _propTypes.default.oneOf(['bottom', 'middle', 'top']).isRequired
149
184
  }),
185
+ slotProps: _propTypes.default.object,
186
+ slots: _propTypes.default.object,
150
187
  spacing: _propTypes.default.number
151
188
  }),
152
189
  margin: _propTypes.default.shape({
@@ -169,8 +206,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
169
206
  label: _propTypes.default.string,
170
207
  labelFontSize: _propTypes.default.number,
171
208
  position: _propTypes.default.oneOf(['left', 'right']),
209
+ slotProps: _propTypes.default.object,
210
+ slots: _propTypes.default.object,
172
211
  stroke: _propTypes.default.string,
173
212
  tickFontSize: _propTypes.default.number,
213
+ tickMaxStep: _propTypes.default.number,
214
+ tickMinStep: _propTypes.default.number,
215
+ tickNumber: _propTypes.default.number,
174
216
  tickSize: _propTypes.default.number
175
217
  }), _propTypes.default.string]),
176
218
  series: _propTypes.default.arrayOf(_propTypes.default.shape({
@@ -183,6 +225,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
183
225
  }),
184
226
  id: _propTypes.default.string,
185
227
  label: _propTypes.default.string,
228
+ layout: _propTypes.default.oneOf(['horizontal', 'vertical']),
186
229
  stack: _propTypes.default.string,
187
230
  stackOffset: _propTypes.default.oneOf(['diverging', 'expand', 'none', 'silhouette', 'wiggle']),
188
231
  stackOrder: _propTypes.default.oneOf(['appearance', 'ascending', 'descending', 'insideOut', 'none', 'reverse']),
@@ -191,6 +234,16 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
191
234
  xAxisKey: _propTypes.default.string,
192
235
  yAxisKey: _propTypes.default.string
193
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,
194
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]),
195
248
  title: _propTypes.default.string,
196
249
  tooltip: _propTypes.default.shape({
@@ -213,8 +266,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
213
266
  label: _propTypes.default.string,
214
267
  labelFontSize: _propTypes.default.number,
215
268
  position: _propTypes.default.oneOf(['bottom', 'top']),
269
+ slotProps: _propTypes.default.object,
270
+ slots: _propTypes.default.object,
216
271
  stroke: _propTypes.default.string,
217
272
  tickFontSize: _propTypes.default.number,
273
+ tickMaxStep: _propTypes.default.number,
274
+ tickMinStep: _propTypes.default.number,
275
+ tickNumber: _propTypes.default.number,
218
276
  tickSize: _propTypes.default.number
219
277
  }), _propTypes.default.string]),
220
278
  viewBox: _propTypes.default.shape({
@@ -237,15 +295,17 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
237
295
  label: _propTypes.default.string,
238
296
  labelFontSize: _propTypes.default.number,
239
297
  max: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
240
- maxTicks: _propTypes.default.number,
241
298
  min: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
242
- minTicks: _propTypes.default.number,
243
299
  position: _propTypes.default.oneOf(['bottom', 'left', 'right', 'top']),
244
300
  scaleType: _propTypes.default.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
301
+ slotProps: _propTypes.default.object,
302
+ slots: _propTypes.default.object,
245
303
  stroke: _propTypes.default.string,
246
304
  tickFontSize: _propTypes.default.number,
305
+ tickMaxStep: _propTypes.default.number,
306
+ tickMinStep: _propTypes.default.number,
307
+ tickNumber: _propTypes.default.number,
247
308
  tickSize: _propTypes.default.number,
248
- tickSpacing: _propTypes.default.number,
249
309
  valueFormatter: _propTypes.default.func
250
310
  })),
251
311
  yAxis: _propTypes.default.arrayOf(_propTypes.default.shape({
@@ -261,15 +321,17 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
261
321
  label: _propTypes.default.string,
262
322
  labelFontSize: _propTypes.default.number,
263
323
  max: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
264
- maxTicks: _propTypes.default.number,
265
324
  min: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
266
- minTicks: _propTypes.default.number,
267
325
  position: _propTypes.default.oneOf(['bottom', 'left', 'right', 'top']),
268
326
  scaleType: _propTypes.default.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
327
+ slotProps: _propTypes.default.object,
328
+ slots: _propTypes.default.object,
269
329
  stroke: _propTypes.default.string,
270
330
  tickFontSize: _propTypes.default.number,
331
+ tickMaxStep: _propTypes.default.number,
332
+ tickMinStep: _propTypes.default.number,
333
+ tickNumber: _propTypes.default.number,
271
334
  tickSize: _propTypes.default.number,
272
- tickSpacing: _propTypes.default.number,
273
335
  valueFormatter: _propTypes.default.func
274
336
  }))
275
337
  } : void 0;
@@ -1,4 +1,5 @@
1
1
  import * as React from 'react';
2
+ import { 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,10 +1,13 @@
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
13
  var _BarElement = require("./BarElement");
@@ -38,7 +41,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
38
41
  offset
39
42
  };
40
43
  }
41
- function BarPlot() {
44
+ function BarPlot(props) {
42
45
  const seriesData = React.useContext(_SeriesContextProvider.SeriesContext).bar;
43
46
  const axisData = React.useContext(_CartesianContextProvider.CartesianContext);
44
47
  if (seriesData === undefined) {
@@ -65,27 +68,37 @@ function BarPlot() {
65
68
  const yAxisKey = series[seriesId].yAxisKey ?? defaultYAxisId;
66
69
  const xAxisConfig = xAxis[xAxisKey];
67
70
  const yAxisConfig = yAxis[yAxisKey];
68
- if (!(0, _axis.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`);
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;
73
89
  }
74
90
  const xScale = xAxisConfig.scale;
75
91
  const yScale = yAxisConfig.scale;
76
-
77
- // Currently assuming all bars are vertical
78
- const bandWidth = xScale.bandwidth();
92
+ const bandWidth = baseScaleConfig.scale.bandwidth();
79
93
  const {
80
94
  barWidth,
81
95
  offset
82
96
  } = getBandSize({
83
97
  bandWidth,
84
98
  numberOfGroups: stackingGroups.length,
85
- gapRatio: xAxisConfig.barGapRatio
99
+ gapRatio: baseScaleConfig.barGapRatio
86
100
  });
87
-
88
- // @ts-ignore TODO: fix when adding a correct API for customisation
101
+ const barOffset = groupIndex * (barWidth + offset);
89
102
  const {
90
103
  stackedData,
91
104
  color
@@ -93,18 +106,34 @@ function BarPlot() {
93
106
  return stackedData.map((values, dataIndex) => {
94
107
  const baseline = Math.min(...values);
95
108
  const value = Math.max(...values);
96
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_BarElement.BarElement, {
109
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_BarElement.BarElement, (0, _extends2.default)({
97
110
  id: seriesId,
98
111
  dataIndex: dataIndex,
99
- x: xScale(xAxis[xAxisKey].data?.[dataIndex]) + groupIndex * (barWidth + offset),
100
- y: yScale(value),
101
- height: yScale(baseline) - yScale(value),
102
- 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)),
103
116
  color: color,
104
117
  highlightScope: series[seriesId].highlightScope
105
- }, `${seriesId}-${dataIndex}`);
118
+ }, props), `${seriesId}-${dataIndex}`);
106
119
  });
107
120
  });
108
121
  })
109
122
  });
110
- }
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;
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getExtremumY = exports.getExtremumX = void 0;
7
- const getExtremumX = params => {
7
+ const getBaseExtremum = params => {
8
8
  const {
9
9
  axis
10
10
  } = params;
@@ -12,8 +12,7 @@ const getExtremumX = params => {
12
12
  const maxX = Math.max(...(axis.data ?? []));
13
13
  return [minX, maxX];
14
14
  };
15
- exports.getExtremumX = getExtremumX;
16
- const getExtremumY = params => {
15
+ const getValueExtremum = params => {
17
16
  const {
18
17
  series,
19
18
  axis,
@@ -24,4 +23,21 @@ const getExtremumY = params => {
24
23
  return [acc[0] === null ? seriesMin : Math.min(seriesMin, acc[0]), acc[1] === null ? seriesMax : Math.max(seriesMax, acc[1])];
25
24
  }, [null, null]);
26
25
  };
26
+ const getExtremumX = params => {
27
+ // Notice that bar should be all horizontal or all vertical.
28
+ // Don't think it's a problem for now
29
+ const isHorizontal = Object.keys(params.series).some(seriesId => params.series[seriesId].layout === 'horizontal');
30
+ if (isHorizontal) {
31
+ return getValueExtremum(params);
32
+ }
33
+ return getBaseExtremum(params);
34
+ };
35
+ exports.getExtremumX = getExtremumX;
36
+ const getExtremumY = params => {
37
+ const isHorizontal = Object.keys(params.series).some(seriesId => params.series[seriesId].layout === 'horizontal');
38
+ if (isHorizontal) {
39
+ return getBaseExtremum(params);
40
+ }
41
+ return getValueExtremum(params);
42
+ };
27
43
  exports.getExtremumY = getExtremumY;
@@ -49,7 +49,9 @@ const formatter = (params, dataset) => {
49
49
  })).order(stackingOrder).offset(stackingOffset)(d3Dataset);
50
50
  ids.forEach((id, index) => {
51
51
  const dataKey = series[id].dataKey;
52
- completedSeries[id] = (0, _extends2.default)({}, series[id], {
52
+ completedSeries[id] = (0, _extends2.default)({
53
+ layout: 'vertical'
54
+ }, series[id], {
53
55
  data: dataKey ? dataset.map(d => d[dataKey]) : series[id].data,
54
56
  stackedData: stackedSeries[index].map(([a, b]) => [a, b])
55
57
  });