@mui/x-charts 6.0.0-alpha.15 → 6.0.0-alpha.17

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 (184) hide show
  1. package/BarChart/BarChart.d.ts +13 -2
  2. package/BarChart/BarChart.js +45 -3
  3. package/BarChart/BarElement.d.ts +1318 -3
  4. package/BarChart/BarElement.js +10 -8
  5. package/BarChart/BarPlot.d.ts +17 -1
  6. package/BarChart/BarPlot.js +152 -66
  7. package/BarChart/formatter.js +1 -1
  8. package/CHANGELOG.md +131 -0
  9. package/ChartContainer/index.js +5 -2
  10. package/ChartsAxis/ChartsAxis.js +18 -2
  11. package/ChartsAxis/axisClasses.d.ts +1 -1
  12. package/ChartsAxisHighlight/ChartsAxisHighlight.js +2 -2
  13. package/ChartsClipPath/ChartsClipPath.js +2 -2
  14. package/ChartsLegend/ChartsLegend.d.ts +2 -1
  15. package/ChartsLegend/ChartsLegend.js +12 -8
  16. package/ChartsSurface.js +2 -2
  17. package/ChartsTooltip/ChartsAxisTooltipContent.js +29 -23
  18. package/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
  19. package/ChartsTooltip/ChartsTooltip.js +2 -2
  20. package/ChartsTooltip/utils.js +2 -2
  21. package/ChartsXAxis/ChartsXAxis.js +123 -35
  22. package/ChartsYAxis/ChartsYAxis.js +38 -16
  23. package/LineChart/AreaElement.d.ts +10 -0
  24. package/LineChart/AreaElement.js +12 -2
  25. package/LineChart/AreaPlot.d.ts +11 -0
  26. package/LineChart/AreaPlot.js +24 -7
  27. package/LineChart/LineChart.d.ts +10 -0
  28. package/LineChart/LineChart.js +36 -2
  29. package/LineChart/LineElement.d.ts +10 -0
  30. package/LineChart/LineElement.js +12 -2
  31. package/LineChart/LineHighlightElement.d.ts +10 -0
  32. package/LineChart/LineHighlightElement.js +12 -2
  33. package/LineChart/LineHighlightPlot.d.ts +10 -0
  34. package/LineChart/LineHighlightPlot.js +14 -3
  35. package/LineChart/LinePlot.d.ts +10 -0
  36. package/LineChart/LinePlot.js +22 -11
  37. package/LineChart/MarkElement.d.ts +10 -0
  38. package/LineChart/MarkElement.js +12 -2
  39. package/LineChart/MarkPlot.d.ts +10 -0
  40. package/LineChart/MarkPlot.js +40 -9
  41. package/LineChart/formatter.js +4 -3
  42. package/PieChart/PieArc.js +2 -2
  43. package/PieChart/PieArcLabel.js +2 -2
  44. package/PieChart/PieChart.d.ts +10 -0
  45. package/PieChart/PieChart.js +37 -2
  46. package/PieChart/PiePlot.d.ts +10 -0
  47. package/PieChart/PiePlot.js +12 -2
  48. package/ResponsiveChartContainer/index.js +4 -4
  49. package/ScatterChart/Scatter.d.ts +10 -0
  50. package/ScatterChart/Scatter.js +12 -2
  51. package/ScatterChart/ScatterChart.d.ts +10 -0
  52. package/ScatterChart/ScatterChart.js +36 -2
  53. package/ScatterChart/ScatterPlot.d.ts +10 -0
  54. package/ScatterChart/ScatterPlot.js +12 -2
  55. package/SparkLineChart/SparkLineChart.d.ts +9 -0
  56. package/SparkLineChart/SparkLineChart.js +16 -2
  57. package/context/CartesianContextProvider.js +10 -2
  58. package/context/DrawingProvider.js +2 -2
  59. package/context/HighlightProvider.js +2 -2
  60. package/context/InteractionProvider.js +2 -2
  61. package/context/SeriesContextProvider.js +2 -2
  62. package/esm/BarChart/BarChart.js +43 -1
  63. package/esm/BarChart/BarElement.js +7 -4
  64. package/esm/BarChart/BarPlot.js +152 -67
  65. package/esm/BarChart/formatter.js +1 -1
  66. package/esm/ChartContainer/index.js +3 -0
  67. package/esm/ChartsAxis/ChartsAxis.js +16 -0
  68. package/esm/ChartsLegend/ChartsLegend.js +10 -6
  69. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +27 -21
  70. package/esm/ChartsXAxis/ChartsXAxis.js +122 -34
  71. package/esm/ChartsYAxis/ChartsYAxis.js +36 -14
  72. package/esm/LineChart/AreaElement.js +10 -0
  73. package/esm/LineChart/AreaPlot.js +24 -6
  74. package/esm/LineChart/LineChart.js +34 -0
  75. package/esm/LineChart/LineElement.js +10 -0
  76. package/esm/LineChart/LineHighlightElement.js +10 -0
  77. package/esm/LineChart/LineHighlightPlot.js +12 -1
  78. package/esm/LineChart/LinePlot.js +23 -14
  79. package/esm/LineChart/MarkElement.js +10 -0
  80. package/esm/LineChart/MarkPlot.js +38 -7
  81. package/esm/LineChart/formatter.js +7 -3
  82. package/esm/PieChart/PieChart.js +35 -0
  83. package/esm/PieChart/PiePlot.js +10 -0
  84. package/esm/ResponsiveChartContainer/index.js +2 -2
  85. package/esm/ScatterChart/Scatter.js +10 -0
  86. package/esm/ScatterChart/ScatterChart.js +34 -0
  87. package/esm/ScatterChart/ScatterPlot.js +10 -0
  88. package/esm/SparkLineChart/SparkLineChart.js +14 -0
  89. package/esm/context/CartesianContextProvider.js +8 -0
  90. package/esm/hooks/useMounted.js +16 -0
  91. package/esm/hooks/useReducedMotion.js +27 -0
  92. package/esm/hooks/useTicks.js +12 -6
  93. package/esm/internals/components/ChartsText.js +19 -13
  94. package/esm/internals/geometry.js +36 -0
  95. package/hooks/useAxisEvents.js +2 -2
  96. package/hooks/useChartDimensions.js +2 -2
  97. package/hooks/useDrawingArea.js +2 -2
  98. package/hooks/useInteractionItemProps.js +2 -2
  99. package/hooks/useMounted.d.ts +1 -0
  100. package/hooks/useMounted.js +25 -0
  101. package/hooks/useReducedMotion.d.ts +8 -0
  102. package/hooks/useReducedMotion.js +33 -0
  103. package/hooks/useScale.d.ts +2 -2
  104. package/hooks/useScale.js +2 -2
  105. package/hooks/useTicks.d.ts +18 -9
  106. package/hooks/useTicks.js +14 -8
  107. package/index.js +1 -1
  108. package/internals/components/ChartsText.d.ts +11 -8
  109. package/internals/components/ChartsText.js +21 -15
  110. package/internals/defaultizeColor.d.ts +2 -2
  111. package/internals/domUtils.d.ts +0 -1
  112. package/internals/geometry.d.ts +9 -0
  113. package/internals/geometry.js +42 -0
  114. package/legacy/BarChart/BarChart.js +43 -1
  115. package/legacy/BarChart/BarElement.js +6 -3
  116. package/legacy/BarChart/BarPlot.js +151 -63
  117. package/legacy/BarChart/formatter.js +1 -1
  118. package/legacy/ChartContainer/index.js +3 -0
  119. package/legacy/ChartsAxis/ChartsAxis.js +16 -0
  120. package/legacy/ChartsLegend/ChartsLegend.js +14 -7
  121. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +5 -1
  122. package/legacy/ChartsXAxis/ChartsXAxis.js +126 -36
  123. package/legacy/ChartsYAxis/ChartsYAxis.js +36 -14
  124. package/legacy/LineChart/AreaElement.js +10 -0
  125. package/legacy/LineChart/AreaPlot.js +27 -7
  126. package/legacy/LineChart/LineChart.js +34 -0
  127. package/legacy/LineChart/LineElement.js +10 -0
  128. package/legacy/LineChart/LineHighlightElement.js +10 -0
  129. package/legacy/LineChart/LineHighlightPlot.js +12 -1
  130. package/legacy/LineChart/LinePlot.js +25 -12
  131. package/legacy/LineChart/MarkElement.js +10 -0
  132. package/legacy/LineChart/MarkPlot.js +37 -7
  133. package/legacy/LineChart/formatter.js +7 -3
  134. package/legacy/PieChart/PieChart.js +35 -0
  135. package/legacy/PieChart/PiePlot.js +10 -0
  136. package/legacy/ResponsiveChartContainer/index.js +2 -2
  137. package/legacy/ScatterChart/Scatter.js +10 -0
  138. package/legacy/ScatterChart/ScatterChart.js +34 -0
  139. package/legacy/ScatterChart/ScatterPlot.js +10 -0
  140. package/legacy/SparkLineChart/SparkLineChart.js +14 -0
  141. package/legacy/context/CartesianContextProvider.js +8 -0
  142. package/legacy/hooks/useMounted.js +21 -0
  143. package/legacy/hooks/useReducedMotion.js +27 -0
  144. package/legacy/hooks/useTicks.js +13 -6
  145. package/legacy/index.js +1 -1
  146. package/legacy/internals/components/ChartsText.js +17 -15
  147. package/legacy/internals/geometry.js +37 -0
  148. package/models/axis.d.ts +19 -2
  149. package/models/seriesType/line.d.ts +3 -3
  150. package/modern/BarChart/BarChart.js +43 -1
  151. package/modern/BarChart/BarElement.js +7 -4
  152. package/modern/BarChart/BarPlot.js +149 -65
  153. package/modern/BarChart/formatter.js +1 -1
  154. package/modern/ChartContainer/index.js +3 -0
  155. package/modern/ChartsAxis/ChartsAxis.js +16 -0
  156. package/modern/ChartsLegend/ChartsLegend.js +10 -6
  157. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +27 -21
  158. package/modern/ChartsXAxis/ChartsXAxis.js +122 -34
  159. package/modern/ChartsYAxis/ChartsYAxis.js +36 -14
  160. package/modern/LineChart/AreaElement.js +10 -0
  161. package/modern/LineChart/AreaPlot.js +22 -5
  162. package/modern/LineChart/LineChart.js +34 -0
  163. package/modern/LineChart/LineElement.js +10 -0
  164. package/modern/LineChart/LineHighlightElement.js +10 -0
  165. package/modern/LineChart/LineHighlightPlot.js +12 -1
  166. package/modern/LineChart/LinePlot.js +20 -9
  167. package/modern/LineChart/MarkElement.js +10 -0
  168. package/modern/LineChart/MarkPlot.js +38 -7
  169. package/modern/LineChart/formatter.js +4 -3
  170. package/modern/PieChart/PieChart.js +35 -0
  171. package/modern/PieChart/PiePlot.js +10 -0
  172. package/modern/ResponsiveChartContainer/index.js +2 -2
  173. package/modern/ScatterChart/Scatter.js +10 -0
  174. package/modern/ScatterChart/ScatterChart.js +34 -0
  175. package/modern/ScatterChart/ScatterPlot.js +10 -0
  176. package/modern/SparkLineChart/SparkLineChart.js +14 -0
  177. package/modern/context/CartesianContextProvider.js +8 -0
  178. package/modern/hooks/useMounted.js +16 -0
  179. package/modern/hooks/useReducedMotion.js +27 -0
  180. package/modern/hooks/useTicks.js +12 -6
  181. package/modern/index.js +1 -1
  182. package/modern/internals/components/ChartsText.js +19 -13
  183. package/modern/internals/geometry.js +36 -0
  184. package/package.json +5 -3
@@ -53,7 +53,7 @@ const formatter = (params, dataset) => {
53
53
  return {
54
54
  seriesOrder,
55
55
  stackingGroups,
56
- series: defaultizeValueFormatter(completedSeries, v => v.toLocaleString())
56
+ series: defaultizeValueFormatter(completedSeries, v => v == null ? void 0 : v.toLocaleString())
57
57
  };
58
58
  };
59
59
  export default formatter;
@@ -3,6 +3,7 @@ import useForkRef from '@mui/utils/useForkRef';
3
3
  import { DrawingProvider } from '../context/DrawingProvider';
4
4
  import { SeriesContextProvider } from '../context/SeriesContextProvider';
5
5
  import { InteractionProvider } from '../context/InteractionProvider';
6
+ import { useReducedMotion } from '../hooks/useReducedMotion';
6
7
  import { ChartsSurface } from '../ChartsSurface';
7
8
  import { CartesianContextProvider } from '../context/CartesianContextProvider';
8
9
  import { HighlightProvider } from '../context/HighlightProvider';
@@ -25,6 +26,8 @@ export const ChartContainer = /*#__PURE__*/React.forwardRef(function ChartContai
25
26
  } = props;
26
27
  const svgRef = React.useRef(null);
27
28
  const handleRef = useForkRef(ref, svgRef);
29
+ useReducedMotion(); // a11y reduce motion (see: https://react-spring.dev/docs/utilities/use-reduced-motion)
30
+
28
31
  return /*#__PURE__*/_jsx(DrawingProvider, {
29
32
  width: width,
30
33
  height: height,
@@ -97,11 +97,15 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
97
97
  fill: PropTypes.string,
98
98
  label: PropTypes.string,
99
99
  labelFontSize: PropTypes.number,
100
+ labelStyle: PropTypes.object,
100
101
  position: PropTypes.oneOf(['bottom', 'top']),
101
102
  slotProps: PropTypes.object,
102
103
  slots: PropTypes.object,
103
104
  stroke: PropTypes.string,
104
105
  tickFontSize: PropTypes.number,
106
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
107
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
108
+ tickLabelStyle: PropTypes.object,
105
109
  tickMaxStep: PropTypes.number,
106
110
  tickMinStep: PropTypes.number,
107
111
  tickNumber: PropTypes.number,
@@ -120,11 +124,15 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
120
124
  fill: PropTypes.string,
121
125
  label: PropTypes.string,
122
126
  labelFontSize: PropTypes.number,
127
+ labelStyle: PropTypes.object,
123
128
  position: PropTypes.oneOf(['left', 'right']),
124
129
  slotProps: PropTypes.object,
125
130
  slots: PropTypes.object,
126
131
  stroke: PropTypes.string,
127
132
  tickFontSize: PropTypes.number,
133
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
134
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
135
+ tickLabelStyle: PropTypes.object,
128
136
  tickMaxStep: PropTypes.number,
129
137
  tickMinStep: PropTypes.number,
130
138
  tickNumber: PropTypes.number,
@@ -143,11 +151,15 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
143
151
  fill: PropTypes.string,
144
152
  label: PropTypes.string,
145
153
  labelFontSize: PropTypes.number,
154
+ labelStyle: PropTypes.object,
146
155
  position: PropTypes.oneOf(['left', 'right']),
147
156
  slotProps: PropTypes.object,
148
157
  slots: PropTypes.object,
149
158
  stroke: PropTypes.string,
150
159
  tickFontSize: PropTypes.number,
160
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
161
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
162
+ tickLabelStyle: PropTypes.object,
151
163
  tickMaxStep: PropTypes.number,
152
164
  tickMinStep: PropTypes.number,
153
165
  tickNumber: PropTypes.number,
@@ -176,11 +188,15 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
176
188
  fill: PropTypes.string,
177
189
  label: PropTypes.string,
178
190
  labelFontSize: PropTypes.number,
191
+ labelStyle: PropTypes.object,
179
192
  position: PropTypes.oneOf(['bottom', 'top']),
180
193
  slotProps: PropTypes.object,
181
194
  slots: PropTypes.object,
182
195
  stroke: PropTypes.string,
183
196
  tickFontSize: PropTypes.number,
197
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
198
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
199
+ tickLabelStyle: PropTypes.object,
184
200
  tickMaxStep: PropTypes.number,
185
201
  tickMinStep: PropTypes.number,
186
202
  tickNumber: PropTypes.number,
@@ -1,6 +1,7 @@
1
1
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
- const _excluded = ["label"];
3
+ const _excluded = ["rotate", "dominantBaseline"],
4
+ _excluded2 = ["label"];
4
5
  import * as React from 'react';
5
6
  import { useSlotProps } from '@mui/base/utils';
6
7
  import { NoSsr } from '@mui/base/NoSsr';
@@ -75,11 +76,16 @@ function DefaultChartsLegend(props) {
75
76
  const theme = useTheme();
76
77
  const labelStyle = React.useMemo(() => _extends({}, theme.typography.subtitle1, {
77
78
  color: 'inherit',
79
+ dominantBaseline: 'central',
80
+ textAnchor: 'start',
78
81
  fill: (theme.vars || theme).palette.text.primary,
79
82
  lineHeight: 1
80
- }, inLabelStyle), [inLabelStyle, theme]);
83
+ }, inLabelStyle),
84
+ // To say to TS that the dominantBaseline and textAnchor are correct
85
+ [inLabelStyle, theme]);
81
86
  const padding = React.useMemo(() => getStandardizedPadding(paddingProps), [paddingProps]);
82
- const getItemSpace = React.useCallback((label, style) => {
87
+ const getItemSpace = React.useCallback((label, inStyle = {}) => {
88
+ const style = _objectWithoutPropertiesLoose(inStyle, _excluded);
83
89
  const linesSize = getWordsByLines({
84
90
  style,
85
91
  needsComputation: true,
@@ -112,7 +118,7 @@ function DefaultChartsLegend(props) {
112
118
  let {
113
119
  label
114
120
  } = _ref,
115
- other = _objectWithoutPropertiesLoose(_ref, _excluded);
121
+ other = _objectWithoutPropertiesLoose(_ref, _excluded2);
116
122
  const itemSpace = getItemSpace(label, labelStyle);
117
123
  const rep = _extends({}, other, {
118
124
  label,
@@ -219,8 +225,6 @@ function DefaultChartsLegend(props) {
219
225
  fill: color
220
226
  }), /*#__PURE__*/_jsx(ChartsText, {
221
227
  style: labelStyle,
222
- dominantBaseline: "central",
223
- textAnchor: "start",
224
228
  text: label,
225
229
  x: itemMarkWidth + markGap,
226
230
  y: 0
@@ -41,27 +41,33 @@ export function DefaultChartsAxisContent(props) {
41
41
  label,
42
42
  valueFormatter,
43
43
  data
44
- }) => /*#__PURE__*/_jsxs(ChartsTooltipRow, {
45
- children: [/*#__PURE__*/_jsx(ChartsTooltipCell, {
46
- className: classes.markCell,
47
- children: /*#__PURE__*/_jsx(ChartsTooltipMark, {
48
- ownerState: {
49
- color
50
- },
51
- boxShadow: 1
52
- })
53
- }), /*#__PURE__*/_jsx(ChartsTooltipCell, {
54
- className: classes.labelCell,
55
- children: label ? /*#__PURE__*/_jsx(Typography, {
56
- children: label
57
- }) : null
58
- }), /*#__PURE__*/_jsx(ChartsTooltipCell, {
59
- className: classes.valueCell,
60
- children: /*#__PURE__*/_jsx(Typography, {
61
- children: valueFormatter(data[dataIndex])
62
- })
63
- })]
64
- }, id))
44
+ }) => {
45
+ const formattedValue = valueFormatter(data[dataIndex]);
46
+ if (formattedValue == null) {
47
+ return null;
48
+ }
49
+ return /*#__PURE__*/_jsxs(ChartsTooltipRow, {
50
+ children: [/*#__PURE__*/_jsx(ChartsTooltipCell, {
51
+ className: classes.markCell,
52
+ children: /*#__PURE__*/_jsx(ChartsTooltipMark, {
53
+ ownerState: {
54
+ color
55
+ },
56
+ boxShadow: 1
57
+ })
58
+ }), /*#__PURE__*/_jsx(ChartsTooltipCell, {
59
+ className: classes.labelCell,
60
+ children: label ? /*#__PURE__*/_jsx(Typography, {
61
+ children: label
62
+ }) : null
63
+ }), /*#__PURE__*/_jsx(ChartsTooltipCell, {
64
+ className: classes.valueCell,
65
+ children: /*#__PURE__*/_jsx(Typography, {
66
+ children: formattedValue
67
+ })
68
+ })]
69
+ }, id);
70
+ })
65
71
  })]
66
72
  })
67
73
  });
@@ -11,7 +11,9 @@ import { DrawingContext } from '../context/DrawingProvider';
11
11
  import useTicks from '../hooks/useTicks';
12
12
  import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
13
13
  import { AxisRoot } from '../internals/components/AxisSharedComponents';
14
- import { ChartsText } from '../internals/components/ChartsText';
14
+ import { ChartsText, getWordsByLines } from '../internals/components/ChartsText';
15
+ import { getMinXTranslation } from '../internals/geometry';
16
+ import { useMounted } from '../hooks/useMounted';
15
17
  import { jsx as _jsx } from "react/jsx-runtime";
16
18
  import { jsxs as _jsxs } from "react/jsx-runtime";
17
19
  const useUtilityClasses = ownerState => {
@@ -29,12 +31,64 @@ const useUtilityClasses = ownerState => {
29
31
  };
30
32
  return composeClasses(slots, getAxisUtilityClass, classes);
31
33
  };
34
+ function addLabelDimension(xTicks, {
35
+ tickLabelStyle: style,
36
+ tickLabelInterval,
37
+ isMounted
38
+ }) {
39
+ const withDimension = xTicks.map(tick => {
40
+ if (!isMounted || tick.formattedValue === undefined) {
41
+ return _extends({}, tick, {
42
+ width: 0,
43
+ height: 0
44
+ });
45
+ }
46
+ const tickSizes = getWordsByLines({
47
+ style,
48
+ needsComputation: true,
49
+ text: tick.formattedValue
50
+ });
51
+ return _extends({}, tick, {
52
+ width: Math.max(...tickSizes.map(size => size.width)),
53
+ height: Math.max(tickSizes.length * tickSizes[0].height)
54
+ });
55
+ });
56
+ if (typeof tickLabelInterval === 'function') {
57
+ return withDimension.map((item, index) => _extends({}, item, {
58
+ skipLabel: !tickLabelInterval(item.value, index)
59
+ }));
60
+ }
61
+
62
+ // Filter label to avoid overlap
63
+ let textStart = 0;
64
+ let textEnd = 0;
65
+ return withDimension.map((item, labelIndex) => {
66
+ const {
67
+ width,
68
+ offset,
69
+ labelOffset,
70
+ height
71
+ } = item;
72
+ const distance = getMinXTranslation(width, height, style == null ? void 0 : style.angle);
73
+ const textPosition = offset + labelOffset;
74
+ const gapRatio = 1.2; // Ratio applied to the minimal distance to add some margin.
75
+
76
+ textStart = textPosition - gapRatio * distance / 2;
77
+ if (labelIndex > 0 && textStart < textEnd) {
78
+ // Except for the first label, we skip all label that overlap with the last accepted.
79
+ // Notice that the early return prevents `textEnd` from being updated.
80
+ return _extends({}, item, {
81
+ skipLabel: true
82
+ });
83
+ }
84
+ textEnd = textPosition + gapRatio * distance / 2;
85
+ return item;
86
+ });
87
+ }
32
88
  const defaultProps = {
33
89
  position: 'bottom',
34
90
  disableLine: false,
35
91
  disableTicks: false,
36
- tickFontSize: 12,
37
- labelFontSize: 14,
38
92
  tickSize: 6
39
93
  };
40
94
  function ChartsXAxis(inProps) {
@@ -54,18 +108,23 @@ function ChartsXAxis(inProps) {
54
108
  }
55
109
  } = _React$useContext,
56
110
  settings = _objectWithoutPropertiesLoose(_React$useContext.xAxis[_props$axisId], _excluded);
111
+ const isMounted = useMounted();
57
112
  const defaultizedProps = _extends({}, defaultProps, settings, props);
58
113
  const {
59
114
  position,
60
115
  disableLine,
61
116
  disableTicks,
62
- tickFontSize,
117
+ tickLabelStyle,
63
118
  label,
119
+ labelStyle,
120
+ tickFontSize,
64
121
  labelFontSize,
65
122
  tickSize: tickSizeProp,
66
123
  valueFormatter,
67
124
  slots,
68
- slotProps
125
+ slotProps,
126
+ tickInterval,
127
+ tickLabelInterval
69
128
  } = defaultizedProps;
70
129
  const theme = useTheme();
71
130
  const classes = useUtilityClasses(_extends({}, defaultizedProps, {
@@ -78,16 +137,7 @@ function ChartsXAxis(inProps) {
78
137
  height
79
138
  } = React.useContext(DrawingContext);
80
139
  const tickSize = disableTicks ? 4 : tickSizeProp;
81
- const xTicks = useTicks({
82
- scale: xScale,
83
- tickNumber,
84
- valueFormatter
85
- });
86
- const positionSigne = position === 'bottom' ? 1 : -1;
87
- const labelRefPoint = {
88
- x: left + width / 2,
89
- y: positionSigne * (tickFontSize + tickSize + 10)
90
- };
140
+ const positionSign = position === 'bottom' ? 1 : -1;
91
141
  const Line = (_slots$axisLine = slots == null ? void 0 : slots.axisLine) != null ? _slots$axisLine : 'line';
92
142
  const Tick = (_slots$axisTick = slots == null ? void 0 : slots.axisTick) != null ? _slots$axisTick : 'line';
93
143
  const TickLabel = (_slots$axisTickLabel = slots == null ? void 0 : slots.axisTickLabel) != null ? _slots$axisTickLabel : ChartsText;
@@ -96,27 +146,40 @@ function ChartsXAxis(inProps) {
96
146
  elementType: TickLabel,
97
147
  externalSlotProps: slotProps == null ? void 0 : slotProps.axisTickLabel,
98
148
  additionalProps: {
99
- textAnchor: 'middle',
100
- dominantBaseline: position === 'bottom' ? 'hanging' : 'auto',
101
- style: {
102
- fontSize: tickFontSize
103
- },
149
+ style: _extends({
150
+ textAnchor: 'middle',
151
+ dominantBaseline: position === 'bottom' ? 'hanging' : 'auto',
152
+ fontSize: tickFontSize != null ? tickFontSize : 12
153
+ }, tickLabelStyle),
104
154
  className: classes.tickLabel
105
155
  },
106
156
  className: classes.tickLabel,
107
157
  ownerState: {}
108
158
  });
159
+ const xTicks = useTicks({
160
+ scale: xScale,
161
+ tickNumber,
162
+ valueFormatter,
163
+ tickInterval
164
+ });
165
+ const xTicksWithDimension = addLabelDimension(xTicks, {
166
+ tickLabelStyle: axisTickLabelProps.style,
167
+ tickLabelInterval,
168
+ isMounted
169
+ });
170
+ const labelRefPoint = {
171
+ x: left + width / 2,
172
+ y: positionSign * (tickSize + 22)
173
+ };
109
174
  const axisLabelProps = useSlotProps({
110
175
  elementType: Label,
111
176
  externalSlotProps: slotProps == null ? void 0 : slotProps.axisLabel,
112
177
  additionalProps: {
113
- textAnchor: 'middle',
114
- dominantBaseline: position === 'bottom' ? 'hanging' : 'auto',
115
- style: {
116
- fontSize: labelFontSize,
117
- transformOrigin: `${labelRefPoint.x}px ${labelRefPoint.y}px`
118
- },
119
- className: classes.label
178
+ style: _extends({
179
+ fontSize: labelFontSize != null ? labelFontSize : 14,
180
+ textAnchor: 'middle',
181
+ dominantBaseline: position === 'bottom' ? 'hanging' : 'auto'
182
+ }, labelStyle)
120
183
  },
121
184
  ownerState: {}
122
185
  });
@@ -127,23 +190,23 @@ function ChartsXAxis(inProps) {
127
190
  x1: xScale.range()[0],
128
191
  x2: xScale.range()[1],
129
192
  className: classes.line
130
- }, slotProps == null ? void 0 : slotProps.axisLine)), xTicks.map(({
193
+ }, slotProps == null ? void 0 : slotProps.axisLine)), xTicksWithDimension.map(({
131
194
  formattedValue,
132
195
  offset,
133
- labelOffset
196
+ labelOffset,
197
+ skipLabel
134
198
  }, index) => {
135
199
  const xTickLabel = labelOffset != null ? labelOffset : 0;
136
- const yTickLabel = positionSigne * (tickSize + 3);
200
+ const yTickLabel = positionSign * (tickSize + 3);
137
201
  return /*#__PURE__*/_jsxs("g", {
138
202
  transform: `translate(${offset}, 0)`,
139
203
  className: classes.tickContainer,
140
204
  children: [!disableTicks && /*#__PURE__*/_jsx(Tick, _extends({
141
- y2: positionSigne * tickSize,
205
+ y2: positionSign * tickSize,
142
206
  className: classes.tick
143
- }, slotProps == null ? void 0 : slotProps.axisTick)), formattedValue !== undefined && /*#__PURE__*/_jsx(TickLabel, _extends({
207
+ }, slotProps == null ? void 0 : slotProps.axisTick)), formattedValue !== undefined && !skipLabel && /*#__PURE__*/_jsx(TickLabel, _extends({
144
208
  x: xTickLabel,
145
- y: yTickLabel,
146
- "transform-origin": `${xTickLabel}px ${yTickLabel}px`
209
+ y: yTickLabel
147
210
  }, axisTickLabelProps, {
148
211
  text: formattedValue.toString()
149
212
  }))]
@@ -191,8 +254,13 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
191
254
  /**
192
255
  * The font size of the axis label.
193
256
  * @default 14
257
+ * @deprecated Consider using `labelStyle.fontSize` instead.
194
258
  */
195
259
  labelFontSize: PropTypes.number,
260
+ /**
261
+ * The style applied to the axis label.
262
+ */
263
+ labelStyle: PropTypes.object,
196
264
  /**
197
265
  * Position of the axis.
198
266
  */
@@ -215,8 +283,28 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
215
283
  /**
216
284
  * The font size of the axis ticks text.
217
285
  * @default 12
286
+ * @deprecated Consider using `tickLabelStyle.fontSize` instead.
218
287
  */
219
288
  tickFontSize: PropTypes.number,
289
+ /**
290
+ * Defines which ticks are displayed. Its value can be:
291
+ * - 'auto' In such case the ticks are computed based on axis scale and other parameters.
292
+ * - a filtering function of the form `(value, index) => boolean` which is available only if the axis has a data property.
293
+ * - an array containing the values where ticks should be displayed.
294
+ * @default 'auto'
295
+ */
296
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
297
+ /**
298
+ * Defines which ticks get its label displayed. Its value can be:
299
+ * - 'auto' In such case, labels are displayed if they do not overlap with the previous one.
300
+ * - a filtering function of the form (value, index) => boolean. Warning: the index is tick index, not data ones.
301
+ * @default 'auto'
302
+ */
303
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
304
+ /**
305
+ * The style applied to ticks text.
306
+ */
307
+ tickLabelStyle: PropTypes.object,
220
308
  /**
221
309
  * Maximal step between two ticks.
222
310
  * When using time data, the value is assumed to be in ms.
@@ -83,9 +83,9 @@ function ChartsYAxis(inProps) {
83
83
  tickNumber,
84
84
  valueFormatter
85
85
  });
86
- const positionSigne = position === 'right' ? 1 : -1;
86
+ const positionSign = position === 'right' ? 1 : -1;
87
87
  const labelRefPoint = {
88
- x: positionSigne * (tickFontSize + tickSize + 10),
88
+ x: positionSign * (tickFontSize + tickSize + 10),
89
89
  y: top + height / 2
90
90
  };
91
91
  const Line = (_slots$axisLine = slots == null ? void 0 : slots.axisLine) != null ? _slots$axisLine : 'line';
@@ -96,10 +96,10 @@ function ChartsYAxis(inProps) {
96
96
  elementType: TickLabel,
97
97
  externalSlotProps: slotProps == null ? void 0 : slotProps.axisTickLabel,
98
98
  additionalProps: {
99
- textAnchor: position === 'right' ? 'start' : 'end',
100
- dominantBaseline: 'central',
101
99
  style: {
102
- fontSize: tickFontSize
100
+ fontSize: tickFontSize,
101
+ textAnchor: position === 'right' ? 'start' : 'end',
102
+ dominantBaseline: 'central'
103
103
  },
104
104
  className: classes.tickLabel
105
105
  },
@@ -109,14 +109,12 @@ function ChartsYAxis(inProps) {
109
109
  elementType: Label,
110
110
  externalSlotProps: slotProps == null ? void 0 : slotProps.axisLabel,
111
111
  additionalProps: {
112
- textAnchor: 'middle',
113
- dominantBaseline: 'auto',
114
112
  style: {
115
113
  fontSize: labelFontSize,
116
- transform: `rotate(${positionSigne * 90}deg)`,
117
- transformOrigin: `${labelRefPoint.x}px ${labelRefPoint.y}px`
118
- },
119
- className: classes.label
114
+ angle: positionSign * 90,
115
+ textAnchor: 'middle',
116
+ dominantBaseline: 'auto'
117
+ }
120
118
  },
121
119
  ownerState: {}
122
120
  });
@@ -132,18 +130,17 @@ function ChartsYAxis(inProps) {
132
130
  offset,
133
131
  labelOffset
134
132
  }, index) => {
135
- const xTickLabel = positionSigne * (tickSize + 2);
133
+ const xTickLabel = positionSign * (tickSize + 2);
136
134
  const yTickLabel = labelOffset;
137
135
  return /*#__PURE__*/_jsxs("g", {
138
136
  transform: `translate(0, ${offset})`,
139
137
  className: classes.tickContainer,
140
138
  children: [!disableTicks && /*#__PURE__*/_jsx(Tick, _extends({
141
- x2: positionSigne * tickSize,
139
+ x2: positionSign * tickSize,
142
140
  className: classes.tick
143
141
  }, slotProps == null ? void 0 : slotProps.axisTick)), formattedValue !== undefined && /*#__PURE__*/_jsx(TickLabel, _extends({
144
142
  x: xTickLabel,
145
143
  y: yTickLabel,
146
- "transform-origin": `${xTickLabel}px ${yTickLabel}px`,
147
144
  text: formattedValue.toString()
148
145
  }, axisTickLabelProps))]
149
146
  }, index);
@@ -190,8 +187,13 @@ process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
190
187
  /**
191
188
  * The font size of the axis label.
192
189
  * @default 14
190
+ * @deprecated Consider using `labelStyle.fontSize` instead.
193
191
  */
194
192
  labelFontSize: PropTypes.number,
193
+ /**
194
+ * The style applied to the axis label.
195
+ */
196
+ labelStyle: PropTypes.object,
195
197
  /**
196
198
  * Position of the axis.
197
199
  */
@@ -214,8 +216,28 @@ process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
214
216
  /**
215
217
  * The font size of the axis ticks text.
216
218
  * @default 12
219
+ * @deprecated Consider using `tickLabelStyle.fontSize` instead.
217
220
  */
218
221
  tickFontSize: PropTypes.number,
222
+ /**
223
+ * Defines which ticks are displayed. Its value can be:
224
+ * - 'auto' In such case the ticks are computed based on axis scale and other parameters.
225
+ * - a filtering function of the form `(value, index) => boolean` which is available only if the axis has a data property.
226
+ * - an array containing the values where ticks should be displayed.
227
+ * @default 'auto'
228
+ */
229
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
230
+ /**
231
+ * Defines which ticks get its label displayed. Its value can be:
232
+ * - 'auto' In such case, labels are displayed if they do not overlap with the previous one.
233
+ * - a filtering function of the form (value, index) => boolean. Warning: the index is tick index, not data ones.
234
+ * @default 'auto'
235
+ */
236
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
237
+ /**
238
+ * The style applied to ticks text.
239
+ */
240
+ tickLabelStyle: PropTypes.object,
219
241
  /**
220
242
  * Maximal step between two ticks.
221
243
  * When using time data, the value is assumed to be in ms.
@@ -55,6 +55,16 @@ AreaElementPath.propTypes = {
55
55
  }).isRequired,
56
56
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
57
57
  };
58
+ /**
59
+ * Demos:
60
+ *
61
+ * - [Lines](https://mui.com/x/react-charts/lines/)
62
+ * - [Areas demonstration](https://mui.com/x/react-charts/areas-demo/)
63
+ *
64
+ * API:
65
+ *
66
+ * - [AreaElement API](https://mui.com/x/api/charts/area-element/)
67
+ */
58
68
  function AreaElement(props) {
59
69
  var _slots$area;
60
70
  const {
@@ -10,6 +10,17 @@ import { AreaElement } from './AreaElement';
10
10
  import { getValueToPositionMapper } from '../hooks/useScale';
11
11
  import getCurveFactory from '../internals/getCurve';
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
+ /**
14
+ * Demos:
15
+ *
16
+ * - [Lines](https://mui.com/x/react-charts/lines/)
17
+ * - [Areas demonstration](https://mui.com/x/react-charts/areas-demo/)
18
+ * - [Stacking](https://mui.com/x/react-charts/stacking/)
19
+ *
20
+ * API:
21
+ *
22
+ * - [AreaPlot API](https://mui.com/x/api/charts/area-plot/)
23
+ */
13
24
  function AreaPlot(props) {
14
25
  const {
15
26
  slots,
@@ -38,23 +49,30 @@ function AreaPlot(props) {
38
49
  ids: groupIds
39
50
  }) => {
40
51
  return groupIds.flatMap(seriesId => {
52
+ var _xData$map;
41
53
  const {
42
54
  xAxisKey = defaultXAxisId,
43
55
  yAxisKey = defaultYAxisId,
44
- stackedData
56
+ stackedData,
57
+ data
45
58
  } = series[seriesId];
46
59
  const xScale = getValueToPositionMapper(xAxis[xAxisKey].scale);
47
60
  const yScale = yAxis[yAxisKey].scale;
48
61
  const xData = xAxis[xAxisKey].data;
49
- if (xData === undefined) {
50
- throw new Error(`Axis of id "${xAxisKey}" should have data property to be able to display a line plot.`);
62
+ if (process.env.NODE_ENV !== 'production') {
63
+ if (xData === undefined) {
64
+ throw new Error(`Axis of id "${xAxisKey}" should have data property to be able to display a line plot.`);
65
+ }
66
+ if (xData.length < stackedData.length) {
67
+ throw new Error(`MUI: data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items)`);
68
+ }
51
69
  }
52
- const areaPath = d3Area().x(d => xScale(d.x)).y0(d => yScale(d.y[0])).y1(d => yScale(d.y[1]));
70
+ const areaPath = d3Area().x(d => xScale(d.x)).defined((_, i) => data[i] != null).y0(d => d.y && yScale(d.y[0])).y1(d => d.y && yScale(d.y[1]));
53
71
  const curve = getCurveFactory(series[seriesId].curve);
54
- const d3Data = xData == null ? void 0 : xData.map((x, index) => ({
72
+ const d3Data = (_xData$map = xData == null ? void 0 : xData.map((x, index) => ({
55
73
  x,
56
74
  y: stackedData[index]
57
- }));
75
+ }))) != null ? _xData$map : [];
58
76
  return !!series[seriesId].area && /*#__PURE__*/_jsx(AreaElement, {
59
77
  id: seriesId,
60
78
  d: areaPath.curve(curve)(d3Data) || undefined,