@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,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) {
@@ -59,27 +61,37 @@ export function BarPlot() {
59
61
  const yAxisKey = series[seriesId].yAxisKey ?? defaultYAxisId;
60
62
  const xAxisConfig = xAxis[xAxisKey];
61
63
  const yAxisConfig = yAxis[yAxisKey];
62
- if (!isBandScaleConfig(xAxisConfig)) {
63
- throw new Error(`Axis with id "${xAxisKey}" shoud be of type "band" to display the bar series of id "${seriesId}"`);
64
- }
65
- if (xAxis[xAxisKey].data === undefined) {
66
- throw new Error(`Axis with id "${xAxisKey}" shoud have data property`);
64
+ const verticalLayout = series[seriesId].layout === 'vertical';
65
+ let baseScaleConfig;
66
+ if (verticalLayout) {
67
+ if (!isBandScaleConfig(xAxisConfig)) {
68
+ throw new Error(`Axis with id "${xAxisKey}" shoud be of type "band" to display the bar series of id "${seriesId}"`);
69
+ }
70
+ if (xAxis[xAxisKey].data === undefined) {
71
+ throw new Error(`Axis with id "${xAxisKey}" shoud have data property`);
72
+ }
73
+ baseScaleConfig = xAxisConfig;
74
+ } else {
75
+ if (!isBandScaleConfig(yAxisConfig)) {
76
+ throw new Error(`Axis with id "${yAxisKey}" shoud be of type "band" to display the bar series of id "${seriesId}"`);
77
+ }
78
+ if (yAxis[yAxisKey].data === undefined) {
79
+ throw new Error(`Axis with id "${xAxisKey}" shoud have data property`);
80
+ }
81
+ baseScaleConfig = yAxisConfig;
67
82
  }
68
83
  const xScale = xAxisConfig.scale;
69
84
  const yScale = yAxisConfig.scale;
70
-
71
- // Currently assuming all bars are vertical
72
- const bandWidth = xScale.bandwidth();
85
+ const bandWidth = baseScaleConfig.scale.bandwidth();
73
86
  const {
74
87
  barWidth,
75
88
  offset
76
89
  } = getBandSize({
77
90
  bandWidth,
78
91
  numberOfGroups: stackingGroups.length,
79
- gapRatio: xAxisConfig.barGapRatio
92
+ gapRatio: baseScaleConfig.barGapRatio
80
93
  });
81
-
82
- // @ts-ignore TODO: fix when adding a correct API for customisation
94
+ const barOffset = groupIndex * (barWidth + offset);
83
95
  const {
84
96
  stackedData,
85
97
  color
@@ -87,18 +99,35 @@ export function BarPlot() {
87
99
  return stackedData.map((values, dataIndex) => {
88
100
  const baseline = Math.min(...values);
89
101
  const value = Math.max(...values);
90
- return /*#__PURE__*/_jsx(BarElement, {
102
+ return /*#__PURE__*/_jsx(BarElement, _extends({
91
103
  id: seriesId,
92
104
  dataIndex: dataIndex,
93
- x: xScale(xAxis[xAxisKey].data?.[dataIndex]) + groupIndex * (barWidth + offset),
94
- y: yScale(value),
95
- height: yScale(baseline) - yScale(value),
96
- width: barWidth,
105
+ x: verticalLayout ? xScale(xAxis[xAxisKey].data?.[dataIndex]) + barOffset : xScale(baseline),
106
+ y: verticalLayout ? yScale(value) : yScale(yAxis[yAxisKey].data?.[dataIndex]) + barOffset,
107
+ height: verticalLayout ? Math.abs(yScale(baseline) - yScale(value)) : barWidth,
108
+ width: verticalLayout ? barWidth : Math.abs(xScale(baseline) - xScale(value)),
97
109
  color: color,
98
110
  highlightScope: series[seriesId].highlightScope
99
- }, `${seriesId}-${dataIndex}`);
111
+ }, props), `${seriesId}-${dataIndex}`);
100
112
  });
101
113
  });
102
114
  })
103
115
  });
104
- }
116
+ }
117
+ process.env.NODE_ENV !== "production" ? BarPlot.propTypes = {
118
+ // ----------------------------- Warning --------------------------------
119
+ // | These PropTypes are generated from the TypeScript type definitions |
120
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
121
+ // ----------------------------------------------------------------------
122
+ /**
123
+ * The props used for each component slot.
124
+ * @default {}
125
+ */
126
+ slotProps: PropTypes.object,
127
+ /**
128
+ * Overridable component slots.
129
+ * @default {}
130
+ */
131
+ slots: PropTypes.object
132
+ } : void 0;
133
+ export { BarPlot };
@@ -1,4 +1,4 @@
1
- export const getExtremumX = params => {
1
+ const getBaseExtremum = params => {
2
2
  const {
3
3
  axis
4
4
  } = params;
@@ -6,7 +6,7 @@ export const getExtremumX = params => {
6
6
  const maxX = Math.max(...(axis.data ?? []));
7
7
  return [minX, maxX];
8
8
  };
9
- export const getExtremumY = params => {
9
+ const getValueExtremum = params => {
10
10
  const {
11
11
  series,
12
12
  axis,
@@ -16,4 +16,20 @@ export const getExtremumY = params => {
16
16
  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]);
17
17
  return [acc[0] === null ? seriesMin : Math.min(seriesMin, acc[0]), acc[1] === null ? seriesMax : Math.max(seriesMax, acc[1])];
18
18
  }, [null, null]);
19
+ };
20
+ export const getExtremumX = params => {
21
+ // Notice that bar should be all horizontal or all vertical.
22
+ // Don't think it's a problem for now
23
+ const isHorizontal = Object.keys(params.series).some(seriesId => params.series[seriesId].layout === 'horizontal');
24
+ if (isHorizontal) {
25
+ return getValueExtremum(params);
26
+ }
27
+ return getBaseExtremum(params);
28
+ };
29
+ export const getExtremumY = params => {
30
+ const isHorizontal = Object.keys(params.series).some(seriesId => params.series[seriesId].layout === 'horizontal');
31
+ if (isHorizontal) {
32
+ return getBaseExtremum(params);
33
+ }
34
+ return getValueExtremum(params);
19
35
  };
@@ -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
  });
@@ -15,12 +15,23 @@ const getAxisId = propsValue => {
15
15
  }
16
16
  return propsValue;
17
17
  };
18
+ const mergeProps = (axisConfig, slots, slotProps) => {
19
+ return typeof axisConfig === 'object' ? _extends({}, axisConfig, {
20
+ slots: _extends({}, slots, axisConfig?.slots),
21
+ slotProps: _extends({}, slotProps, axisConfig?.slotProps)
22
+ }) : {
23
+ slots,
24
+ slotProps
25
+ };
26
+ };
18
27
  function ChartsAxis(props) {
19
28
  const {
20
29
  topAxis,
21
30
  leftAxis,
22
31
  rightAxis,
23
- bottomAxis
32
+ bottomAxis,
33
+ slots,
34
+ slotProps
24
35
  } = props;
25
36
  const {
26
37
  xAxis,
@@ -48,20 +59,24 @@ function ChartsAxis(props) {
48
59
  if (bottomId !== null && !xAxis[bottomId]) {
49
60
  throw Error(`MUI: id used for bottom axis "${bottomId}" is not defined`);
50
61
  }
62
+ const topAxisProps = mergeProps(topAxis, slots, slotProps);
63
+ const bottomAxisProps = mergeProps(bottomAxis, slots, slotProps);
64
+ const leftAxisProps = mergeProps(leftAxis, slots, slotProps);
65
+ const rightAxisProps = mergeProps(rightAxis, slots, slotProps);
51
66
  return /*#__PURE__*/_jsxs(React.Fragment, {
52
- children: [topId && /*#__PURE__*/_jsx(ChartsXAxis, _extends({
67
+ children: [topId && /*#__PURE__*/_jsx(ChartsXAxis, _extends({}, topAxisProps, {
53
68
  position: "top",
54
69
  axisId: topId
55
- }, typeof topAxis === 'object' ? topAxis : {})), bottomId && /*#__PURE__*/_jsx(ChartsXAxis, _extends({
70
+ })), bottomId && /*#__PURE__*/_jsx(ChartsXAxis, _extends({}, bottomAxisProps, {
56
71
  position: "bottom",
57
72
  axisId: bottomId
58
- }, typeof bottomAxis === 'object' ? bottomAxis : {})), leftId && /*#__PURE__*/_jsx(ChartsYAxis, _extends({
73
+ })), leftId && /*#__PURE__*/_jsx(ChartsYAxis, _extends({}, leftAxisProps, {
59
74
  position: "left",
60
75
  axisId: leftId
61
- }, typeof leftAxis === 'object' ? leftAxis : {})), rightId && /*#__PURE__*/_jsx(ChartsYAxis, _extends({
76
+ })), rightId && /*#__PURE__*/_jsx(ChartsYAxis, _extends({}, rightAxisProps, {
62
77
  position: "right",
63
78
  axisId: rightId
64
- }, typeof rightAxis === 'object' ? rightAxis : {}))]
79
+ }))]
65
80
  });
66
81
  }
67
82
  process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
@@ -83,8 +98,13 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
83
98
  label: PropTypes.string,
84
99
  labelFontSize: PropTypes.number,
85
100
  position: PropTypes.oneOf(['bottom', 'top']),
101
+ slotProps: PropTypes.object,
102
+ slots: PropTypes.object,
86
103
  stroke: PropTypes.string,
87
104
  tickFontSize: PropTypes.number,
105
+ tickMaxStep: PropTypes.number,
106
+ tickMinStep: PropTypes.number,
107
+ tickNumber: PropTypes.number,
88
108
  tickSize: PropTypes.number
89
109
  }), PropTypes.string]),
90
110
  /**
@@ -101,8 +121,13 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
101
121
  label: PropTypes.string,
102
122
  labelFontSize: PropTypes.number,
103
123
  position: PropTypes.oneOf(['left', 'right']),
124
+ slotProps: PropTypes.object,
125
+ slots: PropTypes.object,
104
126
  stroke: PropTypes.string,
105
127
  tickFontSize: PropTypes.number,
128
+ tickMaxStep: PropTypes.number,
129
+ tickMinStep: PropTypes.number,
130
+ tickNumber: PropTypes.number,
106
131
  tickSize: PropTypes.number
107
132
  }), PropTypes.string]),
108
133
  /**
@@ -119,10 +144,25 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
119
144
  label: PropTypes.string,
120
145
  labelFontSize: PropTypes.number,
121
146
  position: PropTypes.oneOf(['left', 'right']),
147
+ slotProps: PropTypes.object,
148
+ slots: PropTypes.object,
122
149
  stroke: PropTypes.string,
123
150
  tickFontSize: PropTypes.number,
151
+ tickMaxStep: PropTypes.number,
152
+ tickMinStep: PropTypes.number,
153
+ tickNumber: PropTypes.number,
124
154
  tickSize: PropTypes.number
125
155
  }), PropTypes.string]),
156
+ /**
157
+ * The props used for each component slot.
158
+ * @default {}
159
+ */
160
+ slotProps: PropTypes.object,
161
+ /**
162
+ * Overridable component slots.
163
+ * @default {}
164
+ */
165
+ slots: PropTypes.object,
126
166
  /**
127
167
  * Indicate which axis to display the top of the charts.
128
168
  * Can be a string (the id of the axis) or an object `ChartsXAxisProps`.
@@ -137,8 +177,13 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
137
177
  label: PropTypes.string,
138
178
  labelFontSize: PropTypes.number,
139
179
  position: PropTypes.oneOf(['bottom', 'top']),
180
+ slotProps: PropTypes.object,
181
+ slots: PropTypes.object,
140
182
  stroke: PropTypes.string,
141
183
  tickFontSize: PropTypes.number,
184
+ tickMaxStep: PropTypes.number,
185
+ tickMinStep: PropTypes.number,
186
+ tickNumber: PropTypes.number,
142
187
  tickSize: PropTypes.number
143
188
  }), PropTypes.string])
144
189
  } : void 0;
@@ -25,6 +25,7 @@ function ChartsAxisHighlight(props) {
25
25
  axis
26
26
  } = React.useContext(InteractionContext);
27
27
  const getXPosition = getValueToPositionMapper(xScale);
28
+ const getYPosition = getValueToPositionMapper(yScale);
28
29
  return /*#__PURE__*/_jsxs(React.Fragment, {
29
30
  children: [xAxisHighlight === 'band' && axis.x !== null && isBandScale(xScale) && /*#__PURE__*/_jsx("path", {
30
31
  d: `M ${xScale(axis.x.value) - (xScale.step() - xScale.bandwidth()) / 2} ${yScale.range()[0]} l ${xScale.step()} 0 l 0 ${yScale.range()[1] - yScale.range()[0]} l ${-xScale.step()} 0 Z`,
@@ -33,15 +34,22 @@ function ChartsAxisHighlight(props) {
33
34
  style: {
34
35
  pointerEvents: 'none'
35
36
  }
37
+ }), yAxisHighlight === 'band' && axis.y !== null && isBandScale(yScale) && /*#__PURE__*/_jsx("path", {
38
+ d: `M ${xScale.range()[0]} ${yScale(axis.y.value) - (yScale.step() - yScale.bandwidth()) / 2} l 0 ${yScale.step()} l ${xScale.range()[1] - xScale.range()[0]} 0 l 0 ${-yScale.step()} Z`,
39
+ fill: "gray",
40
+ fillOpacity: 0.1,
41
+ style: {
42
+ pointerEvents: 'none'
43
+ }
36
44
  }), xAxisHighlight === 'line' && axis.x !== null && /*#__PURE__*/_jsx("path", {
37
- d: `M ${getXPosition(axis.x.value)} ${yScale(yScale.domain()[0])} L ${getXPosition(axis.x.value)} ${yScale(yScale.domain().at(-1))}`,
45
+ d: `M ${getXPosition(axis.x.value)} ${yScale.range()[0]} L ${getXPosition(axis.x.value)} ${yScale.range()[1]}`,
38
46
  stroke: "black",
39
47
  strokeDasharray: "5 2",
40
48
  style: {
41
49
  pointerEvents: 'none'
42
50
  }
43
51
  }), yAxisHighlight === 'line' && axis.y !== null && /*#__PURE__*/_jsx("path", {
44
- d: `M ${xScale.range()[0]} ${yScale(axis.y.value)} L ${xScale.range()[1]} ${yScale(axis.y.value)}`,
52
+ d: `M ${xScale.range()[0]} ${getYPosition(axis.y.value)} L ${xScale.range()[1]} ${getYPosition(axis.y.value)}`,
45
53
  stroke: "black",
46
54
  strokeDasharray: "5 2",
47
55
  style: {
@@ -56,6 +64,6 @@ process.env.NODE_ENV !== "production" ? ChartsAxisHighlight.propTypes = {
56
64
  // | To update them edit the TypeScript types and run "yarn proptypes" |
57
65
  // ----------------------------------------------------------------------
58
66
  x: PropTypes.oneOf(['band', 'line', 'none']),
59
- y: PropTypes.oneOf(['line', 'none'])
67
+ y: PropTypes.oneOf(['band', 'line', 'none'])
60
68
  } : void 0;
61
69
  export { ChartsAxisHighlight };
@@ -1,5 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
+ import { useSlotProps } from '@mui/base/utils';
3
4
  import { unstable_composeClasses as composeClasses } from '@mui/utils';
4
5
  import { useThemeProps, useTheme, styled } from '@mui/material/styles';
5
6
  import { DrawingContext } from '../context/DrawingProvider';
@@ -126,7 +127,7 @@ export const ChartsLegendLabel = styled('text', {
126
127
  calc(0.5 * var(--ChartsLegend-itemMarkSize))
127
128
  )`,
128
129
  fill: theme.palette.text.primary,
129
- alignmentBaseline: 'central'
130
+ dominantBaseline: 'central'
130
131
  }));
131
132
  const defaultProps = {
132
133
  position: {
@@ -138,27 +139,20 @@ const defaultProps = {
138
139
  itemWidth: 100,
139
140
  spacing: 2
140
141
  };
141
- export function ChartsLegend(inProps) {
142
- const props = useThemeProps({
143
- props: _extends({}, defaultProps, inProps),
144
- name: 'MuiChartsLegend'
145
- });
142
+ function DefaultChartsLegend(props) {
146
143
  const {
144
+ hidden,
147
145
  position,
148
146
  direction,
149
147
  offset,
150
- hidden
148
+ series,
149
+ seriesToDisplay,
150
+ drawingArea,
151
+ classes
151
152
  } = props;
152
- const theme = useTheme();
153
- const classes = useUtilityClasses(_extends({}, props, {
154
- theme
155
- }));
156
- const drawingArea = React.useContext(DrawingContext);
157
- const series = React.useContext(SeriesContext);
158
153
  if (hidden) {
159
154
  return null;
160
155
  }
161
- const seriesToDisplay = getSeriesToDisplay(series);
162
156
  return /*#__PURE__*/_jsx(ChartsLegendRoot, {
163
157
  ownerState: {
164
158
  direction,
@@ -190,4 +184,42 @@ export function ChartsLegend(inProps) {
190
184
  })]
191
185
  }, id))
192
186
  });
187
+ }
188
+ export function ChartsLegend(inProps) {
189
+ const props = useThemeProps({
190
+ props: _extends({}, defaultProps, inProps),
191
+ name: 'MuiChartsLegend'
192
+ });
193
+ const {
194
+ position,
195
+ direction,
196
+ offset,
197
+ hidden,
198
+ slots,
199
+ slotProps
200
+ } = props;
201
+ const theme = useTheme();
202
+ const classes = useUtilityClasses(_extends({}, props, {
203
+ theme
204
+ }));
205
+ const drawingArea = React.useContext(DrawingContext);
206
+ const series = React.useContext(SeriesContext);
207
+ const seriesToDisplay = getSeriesToDisplay(series);
208
+ const ChartLegendRender = slots?.legend ?? DefaultChartsLegend;
209
+ const chartLegendRenderProps = useSlotProps({
210
+ elementType: ChartLegendRender,
211
+ externalSlotProps: slotProps?.legend,
212
+ additionalProps: {
213
+ position,
214
+ direction,
215
+ offset,
216
+ classes,
217
+ drawingArea,
218
+ series,
219
+ hidden,
220
+ seriesToDisplay
221
+ },
222
+ ownerState: {}
223
+ });
224
+ return /*#__PURE__*/_jsx(ChartLegendRender, _extends({}, chartLegendRenderProps));
193
225
  }
@@ -71,29 +71,33 @@ export function ChartsAxisTooltipContent(props) {
71
71
  sx,
72
72
  classes
73
73
  } = props;
74
- const dataIndex = axisData.x && axisData.x.index;
75
- const axisValue = axisData.x && axisData.x.value;
74
+ const isXaxis = (axisData.x && axisData.x.index) !== undefined;
75
+ const dataIndex = isXaxis ? axisData.x && axisData.x.index : axisData.y && axisData.y.index;
76
+ const axisValue = isXaxis ? axisData.x && axisData.x.value : axisData.y && axisData.y.value;
76
77
  const {
77
78
  xAxisIds,
78
- xAxis
79
+ xAxis,
80
+ yAxisIds,
81
+ yAxis
79
82
  } = React.useContext(CartesianContext);
80
83
  const series = React.useContext(SeriesContext);
81
- const USED_X_AXIS_ID = xAxisIds[0];
84
+ const USED_AXIS_ID = isXaxis ? xAxisIds[0] : yAxisIds[0];
82
85
  const relevantSeries = React.useMemo(() => {
83
86
  const rep = [];
84
87
  Object.keys(series).filter(seriesType => ['bar', 'line', 'scatter'].includes(seriesType)).forEach(seriesType => {
85
88
  series[seriesType].seriesOrder.forEach(seriesId => {
86
- const axisKey = series[seriesType].series[seriesId].xAxisKey;
87
- if (axisKey === undefined || axisKey === USED_X_AXIS_ID) {
89
+ const item = series[seriesType].series[seriesId];
90
+ const axisKey = isXaxis ? item.xAxisKey : item.yAxisKey;
91
+ if (axisKey === undefined || axisKey === USED_AXIS_ID) {
88
92
  rep.push(series[seriesType].series[seriesId]);
89
93
  }
90
94
  });
91
95
  });
92
96
  return rep;
93
- }, [USED_X_AXIS_ID, series]);
97
+ }, [USED_AXIS_ID, isXaxis, series]);
94
98
  const relevantAxis = React.useMemo(() => {
95
- return xAxis[USED_X_AXIS_ID];
96
- }, [USED_X_AXIS_ID, xAxis]);
99
+ return isXaxis ? xAxis[USED_AXIS_ID] : yAxis[USED_AXIS_ID];
100
+ }, [USED_AXIS_ID, isXaxis, xAxis, yAxis]);
97
101
  const Content = content ?? DefaultChartsAxisContent;
98
102
  return /*#__PURE__*/_jsx(Content, {
99
103
  axisData: axisData,
@@ -9,7 +9,7 @@ import { CartesianContext } from '../context/CartesianContextProvider';
9
9
  import { DrawingContext } from '../context/DrawingProvider';
10
10
  import useTicks from '../hooks/useTicks';
11
11
  import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
12
- import { Line, Tick, TickLabel, Label, AxisRoot } from '../internals/components/AxisSharedComponents';
12
+ import { ChartsLine, ChartsTick, ChartsTickLabel, ChartsLabel, AxisRoot } from '../internals/components/AxisSharedComponents';
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
14
  import { jsxs as _jsxs } from "react/jsx-runtime";
15
15
  const useUtilityClasses = ownerState => {
@@ -60,7 +60,9 @@ function ChartsXAxis(inProps) {
60
60
  label,
61
61
  labelFontSize,
62
62
  tickSize: tickSizeProp,
63
- valueFormatter
63
+ valueFormatter,
64
+ slots,
65
+ slotProps
64
66
  } = defaultizedProps;
65
67
  const theme = useTheme();
66
68
  const classes = useUtilityClasses(_extends({}, defaultizedProps, {
@@ -83,14 +85,18 @@ function ChartsXAxis(inProps) {
83
85
  x: left + width / 2,
84
86
  y: positionSigne * (tickFontSize + tickSize + 10)
85
87
  };
88
+ const Line = slots?.axisLine ?? ChartsLine;
89
+ const Tick = slots?.axisTick ?? ChartsTick;
90
+ const TickLabel = slots?.axisTickLabel ?? ChartsTickLabel;
91
+ const Label = slots?.axisLabel ?? ChartsLabel;
86
92
  return /*#__PURE__*/_jsxs(AxisRoot, {
87
93
  transform: `translate(0, ${position === 'bottom' ? top + height : top})`,
88
94
  className: classes.root,
89
- children: [!disableLine && /*#__PURE__*/_jsx(Line, {
95
+ children: [!disableLine && /*#__PURE__*/_jsx(Line, _extends({
90
96
  x1: xScale.range()[0],
91
97
  x2: xScale.range()[1],
92
98
  className: classes.line
93
- }), xTicks.map(({
99
+ }, slotProps?.axisLine)), xTicks.map(({
94
100
  formattedValue,
95
101
  offset,
96
102
  labelOffset
@@ -100,26 +106,28 @@ function ChartsXAxis(inProps) {
100
106
  return /*#__PURE__*/_jsxs("g", {
101
107
  transform: `translate(${offset}, 0)`,
102
108
  className: classes.tickContainer,
103
- children: [!disableTicks && /*#__PURE__*/_jsx(Tick, {
109
+ children: [!disableTicks && /*#__PURE__*/_jsx(Tick, _extends({
104
110
  y2: positionSigne * tickSize,
105
111
  className: classes.tick
106
- }), formattedValue !== undefined && /*#__PURE__*/_jsx(TickLabel, {
112
+ }, slotProps?.axisTick)), formattedValue !== undefined && /*#__PURE__*/_jsx(TickLabel, _extends({
107
113
  x: xTickLabel,
108
114
  y: yTickLabel,
109
115
  "transform-origin": `${xTickLabel}px ${yTickLabel}px`,
110
116
  sx: {
111
117
  fontSize: tickFontSize
112
118
  },
113
- className: classes.tickLabel,
119
+ className: classes.tickLabel
120
+ }, slotProps?.axisTickLabel, {
114
121
  children: formattedValue
115
- })]
122
+ }))]
116
123
  }, index);
117
124
  }), label && /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, {
118
125
  sx: {
119
126
  fontSize: labelFontSize,
120
127
  transformOrigin: `${labelRefPoint.x}px ${labelRefPoint.y}px`
121
128
  },
122
- className: classes.label,
129
+ className: classes.label
130
+ }, slotProps?.axisLabel, {
123
131
  children: label
124
132
  }))]
125
133
  });
@@ -165,6 +173,16 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
165
173
  * Position of the axis.
166
174
  */
167
175
  position: PropTypes.oneOf(['bottom', 'top']),
176
+ /**
177
+ * The props used for each component slot.
178
+ * @default {}
179
+ */
180
+ slotProps: PropTypes.object,
181
+ /**
182
+ * Overridable component slots.
183
+ * @default {}
184
+ */
185
+ slots: PropTypes.object,
168
186
  /**
169
187
  * The stroke color of the axis line.
170
188
  * @default 'currentColor'
@@ -175,6 +193,23 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
175
193
  * @default 12
176
194
  */
177
195
  tickFontSize: PropTypes.number,
196
+ /**
197
+ * Maximal step between two ticks.
198
+ * When using time data, the value is assumed to be in ms.
199
+ * Not supported by categorical axis (band, points).
200
+ */
201
+ tickMaxStep: PropTypes.number,
202
+ /**
203
+ * Maximal step between two ticks.
204
+ * When using time data, the value is assumed to be in ms.
205
+ * Not supported by categorical axis (band, points).
206
+ */
207
+ tickMinStep: PropTypes.number,
208
+ /**
209
+ * The number of ticks. This number is not guaranted.
210
+ * Not supported by categorical axis (band, points).
211
+ */
212
+ tickNumber: PropTypes.number,
178
213
  /**
179
214
  * The size of the ticks.
180
215
  * @default 6