@mui/x-charts 6.0.0-alpha.14 → 6.0.0-alpha.16

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 (199) hide show
  1. package/BarChart/BarChart.d.ts +16 -2
  2. package/BarChart/BarChart.js +49 -11
  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/CHANGELOG.md +169 -0
  8. package/ChartContainer/index.js +5 -2
  9. package/ChartsAxis/ChartsAxis.js +18 -2
  10. package/ChartsAxis/axisClasses.d.ts +1 -1
  11. package/ChartsAxisHighlight/ChartsAxisHighlight.js +2 -2
  12. package/ChartsClipPath/ChartsClipPath.js +2 -2
  13. package/ChartsLegend/ChartsLegend.d.ts +44 -24
  14. package/ChartsLegend/ChartsLegend.js +191 -145
  15. package/ChartsLegend/utils.d.ts +1 -6
  16. package/ChartsSurface.js +5 -13
  17. package/ChartsTooltip/ChartsAxisTooltipContent.js +2 -2
  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 +151 -40
  22. package/ChartsYAxis/ChartsYAxis.js +76 -33
  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 +13 -2
  27. package/LineChart/LineChart.d.ts +13 -0
  28. package/LineChart/LineChart.js +40 -10
  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 +12 -2
  35. package/LineChart/LinePlot.d.ts +10 -0
  36. package/LineChart/LinePlot.js +12 -2
  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 +12 -2
  41. package/PieChart/PieArc.js +2 -2
  42. package/PieChart/PieArcLabel.js +2 -2
  43. package/PieChart/PieChart.d.ts +13 -0
  44. package/PieChart/PieChart.js +41 -10
  45. package/PieChart/PiePlot.d.ts +10 -0
  46. package/PieChart/PiePlot.js +12 -2
  47. package/ResponsiveChartContainer/index.js +4 -4
  48. package/ScatterChart/Scatter.d.ts +10 -0
  49. package/ScatterChart/Scatter.js +12 -2
  50. package/ScatterChart/ScatterChart.d.ts +13 -0
  51. package/ScatterChart/ScatterChart.js +40 -10
  52. package/ScatterChart/ScatterPlot.d.ts +10 -0
  53. package/ScatterChart/ScatterPlot.js +12 -2
  54. package/SparkLineChart/SparkLineChart.d.ts +9 -0
  55. package/SparkLineChart/SparkLineChart.js +16 -2
  56. package/constants.js +1 -1
  57. package/context/CartesianContextProvider.js +20 -12
  58. package/context/DrawingProvider.d.ts +2 -0
  59. package/context/DrawingProvider.js +4 -2
  60. package/context/HighlightProvider.js +2 -2
  61. package/context/InteractionProvider.js +2 -2
  62. package/context/SeriesContextProvider.js +2 -2
  63. package/esm/BarChart/BarChart.js +47 -9
  64. package/esm/BarChart/BarElement.js +7 -4
  65. package/esm/BarChart/BarPlot.js +152 -67
  66. package/esm/ChartContainer/index.js +3 -0
  67. package/esm/ChartsAxis/ChartsAxis.js +16 -0
  68. package/esm/ChartsLegend/ChartsLegend.js +188 -142
  69. package/esm/ChartsSurface.js +3 -11
  70. package/esm/ChartsXAxis/ChartsXAxis.js +148 -37
  71. package/esm/ChartsYAxis/ChartsYAxis.js +73 -30
  72. package/esm/LineChart/AreaElement.js +10 -0
  73. package/esm/LineChart/AreaPlot.js +11 -0
  74. package/esm/LineChart/LineChart.js +38 -8
  75. package/esm/LineChart/LineElement.js +10 -0
  76. package/esm/LineChart/LineHighlightElement.js +10 -0
  77. package/esm/LineChart/LineHighlightPlot.js +10 -0
  78. package/esm/LineChart/LinePlot.js +10 -0
  79. package/esm/LineChart/MarkElement.js +10 -0
  80. package/esm/LineChart/MarkPlot.js +10 -0
  81. package/esm/PieChart/PieChart.js +39 -8
  82. package/esm/PieChart/PiePlot.js +10 -0
  83. package/esm/ResponsiveChartContainer/index.js +2 -2
  84. package/esm/ScatterChart/Scatter.js +10 -0
  85. package/esm/ScatterChart/ScatterChart.js +38 -8
  86. package/esm/ScatterChart/ScatterPlot.js +10 -0
  87. package/esm/SparkLineChart/SparkLineChart.js +14 -0
  88. package/esm/constants.js +1 -1
  89. package/esm/context/CartesianContextProvider.js +19 -11
  90. package/esm/context/DrawingProvider.js +2 -0
  91. package/esm/hooks/useChartDimensions.js +2 -0
  92. package/esm/hooks/useMounted.js +16 -0
  93. package/esm/hooks/useReducedMotion.js +27 -0
  94. package/esm/hooks/useTicks.js +15 -9
  95. package/esm/internals/components/AxisSharedComponents.js +15 -70
  96. package/esm/internals/components/ChartsText.js +75 -0
  97. package/esm/internals/domUtils.js +113 -0
  98. package/esm/internals/geometry.js +36 -0
  99. package/hooks/useAxisEvents.js +2 -2
  100. package/hooks/useChartDimensions.d.ts +2 -0
  101. package/hooks/useChartDimensions.js +4 -2
  102. package/hooks/useDrawingArea.js +2 -2
  103. package/hooks/useInteractionItemProps.js +2 -2
  104. package/hooks/useMounted.d.ts +1 -0
  105. package/hooks/useMounted.js +25 -0
  106. package/hooks/useReducedMotion.d.ts +8 -0
  107. package/hooks/useReducedMotion.js +33 -0
  108. package/hooks/useScale.d.ts +2 -2
  109. package/hooks/useScale.js +2 -2
  110. package/hooks/useTicks.d.ts +19 -11
  111. package/hooks/useTicks.js +18 -12
  112. package/index.js +1 -1
  113. package/internals/components/AxisSharedComponents.d.ts +0 -4
  114. package/internals/components/AxisSharedComponents.js +16 -71
  115. package/internals/components/ChartsText.d.ts +35 -0
  116. package/internals/components/ChartsText.js +85 -0
  117. package/internals/defaultizeColor.d.ts +1 -1
  118. package/internals/domUtils.d.ts +13 -0
  119. package/internals/domUtils.js +122 -0
  120. package/internals/geometry.d.ts +9 -0
  121. package/internals/geometry.js +42 -0
  122. package/legacy/BarChart/BarChart.js +47 -9
  123. package/legacy/BarChart/BarElement.js +6 -3
  124. package/legacy/BarChart/BarPlot.js +151 -63
  125. package/legacy/ChartContainer/index.js +3 -0
  126. package/legacy/ChartsAxis/ChartsAxis.js +16 -0
  127. package/legacy/ChartsLegend/ChartsLegend.js +203 -140
  128. package/legacy/ChartsSurface.js +2 -11
  129. package/legacy/ChartsXAxis/ChartsXAxis.js +152 -39
  130. package/legacy/ChartsYAxis/ChartsYAxis.js +73 -30
  131. package/legacy/LineChart/AreaElement.js +10 -0
  132. package/legacy/LineChart/AreaPlot.js +11 -0
  133. package/legacy/LineChart/LineChart.js +38 -8
  134. package/legacy/LineChart/LineElement.js +10 -0
  135. package/legacy/LineChart/LineHighlightElement.js +10 -0
  136. package/legacy/LineChart/LineHighlightPlot.js +10 -0
  137. package/legacy/LineChart/LinePlot.js +10 -0
  138. package/legacy/LineChart/MarkElement.js +10 -0
  139. package/legacy/LineChart/MarkPlot.js +10 -0
  140. package/legacy/PieChart/PieChart.js +39 -8
  141. package/legacy/PieChart/PiePlot.js +10 -0
  142. package/legacy/ResponsiveChartContainer/index.js +2 -2
  143. package/legacy/ScatterChart/Scatter.js +10 -0
  144. package/legacy/ScatterChart/ScatterChart.js +38 -8
  145. package/legacy/ScatterChart/ScatterPlot.js +10 -0
  146. package/legacy/SparkLineChart/SparkLineChart.js +14 -0
  147. package/legacy/constants.js +1 -1
  148. package/legacy/context/CartesianContextProvider.js +19 -11
  149. package/legacy/context/DrawingProvider.js +2 -0
  150. package/legacy/hooks/useChartDimensions.js +2 -0
  151. package/legacy/hooks/useMounted.js +21 -0
  152. package/legacy/hooks/useReducedMotion.js +27 -0
  153. package/legacy/hooks/useTicks.js +16 -9
  154. package/legacy/index.js +1 -1
  155. package/legacy/internals/components/AxisSharedComponents.js +9 -63
  156. package/legacy/internals/components/ChartsText.js +77 -0
  157. package/legacy/internals/domUtils.js +121 -0
  158. package/legacy/internals/geometry.js +37 -0
  159. package/models/axis.d.ts +25 -7
  160. package/models/layout.d.ts +7 -6
  161. package/models/seriesType/line.d.ts +2 -2
  162. package/modern/BarChart/BarChart.js +47 -9
  163. package/modern/BarChart/BarElement.js +7 -4
  164. package/modern/BarChart/BarPlot.js +149 -65
  165. package/modern/ChartContainer/index.js +3 -0
  166. package/modern/ChartsAxis/ChartsAxis.js +16 -0
  167. package/modern/ChartsLegend/ChartsLegend.js +188 -142
  168. package/modern/ChartsSurface.js +3 -11
  169. package/modern/ChartsXAxis/ChartsXAxis.js +148 -37
  170. package/modern/ChartsYAxis/ChartsYAxis.js +73 -30
  171. package/modern/LineChart/AreaElement.js +10 -0
  172. package/modern/LineChart/AreaPlot.js +11 -0
  173. package/modern/LineChart/LineChart.js +38 -8
  174. package/modern/LineChart/LineElement.js +10 -0
  175. package/modern/LineChart/LineHighlightElement.js +10 -0
  176. package/modern/LineChart/LineHighlightPlot.js +10 -0
  177. package/modern/LineChart/LinePlot.js +10 -0
  178. package/modern/LineChart/MarkElement.js +10 -0
  179. package/modern/LineChart/MarkPlot.js +10 -0
  180. package/modern/PieChart/PieChart.js +39 -8
  181. package/modern/PieChart/PiePlot.js +10 -0
  182. package/modern/ResponsiveChartContainer/index.js +2 -2
  183. package/modern/ScatterChart/Scatter.js +10 -0
  184. package/modern/ScatterChart/ScatterChart.js +38 -8
  185. package/modern/ScatterChart/ScatterPlot.js +10 -0
  186. package/modern/SparkLineChart/SparkLineChart.js +14 -0
  187. package/modern/constants.js +1 -1
  188. package/modern/context/CartesianContextProvider.js +19 -11
  189. package/modern/context/DrawingProvider.js +2 -0
  190. package/modern/hooks/useChartDimensions.js +2 -0
  191. package/modern/hooks/useMounted.js +16 -0
  192. package/modern/hooks/useReducedMotion.js +27 -0
  193. package/modern/hooks/useTicks.js +15 -9
  194. package/modern/index.js +1 -1
  195. package/modern/internals/components/AxisSharedComponents.js +15 -70
  196. package/modern/internals/components/ChartsText.js +75 -0
  197. package/modern/internals/domUtils.js +113 -0
  198. package/modern/internals/geometry.js +36 -0
  199. package/package.json +5 -3
@@ -1,15 +1,19 @@
1
1
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
- const _excluded = ["scale", "ticksNumber"];
3
+ const _excluded = ["scale", "tickNumber"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
+ import { useSlotProps } from '@mui/base/utils';
6
7
  import { unstable_composeClasses as composeClasses } from '@mui/utils';
7
8
  import { useThemeProps, useTheme } from '@mui/material/styles';
8
9
  import { CartesianContext } from '../context/CartesianContextProvider';
9
10
  import { DrawingContext } from '../context/DrawingProvider';
10
11
  import useTicks from '../hooks/useTicks';
11
12
  import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
12
- import { ChartsLine, ChartsTick, ChartsTickLabel, ChartsLabel, AxisRoot } from '../internals/components/AxisSharedComponents';
13
+ import { AxisRoot } from '../internals/components/AxisSharedComponents';
14
+ import { ChartsText, getWordsByLines } from '../internals/components/ChartsText';
15
+ import { getMinXTranslation } from '../internals/geometry';
16
+ import { useMounted } from '../hooks/useMounted';
13
17
  import { jsx as _jsx } from "react/jsx-runtime";
14
18
  import { jsxs as _jsxs } from "react/jsx-runtime";
15
19
  const useUtilityClasses = ownerState => {
@@ -27,12 +31,64 @@ const useUtilityClasses = ownerState => {
27
31
  };
28
32
  return composeClasses(slots, getAxisUtilityClass, classes);
29
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
+ }
30
88
  const defaultProps = {
31
89
  position: 'bottom',
32
90
  disableLine: false,
33
91
  disableTicks: false,
34
- tickFontSize: 12,
35
- labelFontSize: 14,
36
92
  tickSize: 6
37
93
  };
38
94
  function ChartsXAxis(inProps) {
@@ -47,23 +103,28 @@ function ChartsXAxis(inProps) {
47
103
  xAxis: {
48
104
  [_props$axisId]: {
49
105
  scale: xScale,
50
- ticksNumber
106
+ tickNumber
51
107
  }
52
108
  }
53
109
  } = _React$useContext,
54
110
  settings = _objectWithoutPropertiesLoose(_React$useContext.xAxis[_props$axisId], _excluded);
111
+ const isMounted = useMounted();
55
112
  const defaultizedProps = _extends({}, defaultProps, settings, props);
56
113
  const {
57
114
  position,
58
115
  disableLine,
59
116
  disableTicks,
60
- tickFontSize,
117
+ tickLabelStyle,
61
118
  label,
119
+ labelStyle,
120
+ tickFontSize,
62
121
  labelFontSize,
63
122
  tickSize: tickSizeProp,
64
123
  valueFormatter,
65
124
  slots,
66
- slotProps
125
+ slotProps,
126
+ tickInterval,
127
+ tickLabelInterval
67
128
  } = defaultizedProps;
68
129
  const theme = useTheme();
69
130
  const classes = useUtilityClasses(_extends({}, defaultizedProps, {
@@ -76,20 +137,52 @@ function ChartsXAxis(inProps) {
76
137
  height
77
138
  } = React.useContext(DrawingContext);
78
139
  const tickSize = disableTicks ? 4 : tickSizeProp;
140
+ const positionSign = position === 'bottom' ? 1 : -1;
141
+ const Line = (_slots$axisLine = slots == null ? void 0 : slots.axisLine) != null ? _slots$axisLine : 'line';
142
+ const Tick = (_slots$axisTick = slots == null ? void 0 : slots.axisTick) != null ? _slots$axisTick : 'line';
143
+ const TickLabel = (_slots$axisTickLabel = slots == null ? void 0 : slots.axisTickLabel) != null ? _slots$axisTickLabel : ChartsText;
144
+ const Label = (_slots$axisLabel = slots == null ? void 0 : slots.axisLabel) != null ? _slots$axisLabel : ChartsText;
145
+ const axisTickLabelProps = useSlotProps({
146
+ elementType: TickLabel,
147
+ externalSlotProps: slotProps == null ? void 0 : slotProps.axisTickLabel,
148
+ additionalProps: {
149
+ style: _extends({
150
+ textAnchor: 'middle',
151
+ dominantBaseline: position === 'bottom' ? 'hanging' : 'auto',
152
+ fontSize: tickFontSize != null ? tickFontSize : 12
153
+ }, tickLabelStyle),
154
+ className: classes.tickLabel
155
+ },
156
+ className: classes.tickLabel,
157
+ ownerState: {}
158
+ });
79
159
  const xTicks = useTicks({
80
160
  scale: xScale,
81
- ticksNumber,
82
- valueFormatter
161
+ tickNumber,
162
+ valueFormatter,
163
+ tickInterval
164
+ });
165
+ const xTicksWithDimension = addLabelDimension(xTicks, {
166
+ tickLabelStyle: axisTickLabelProps.style,
167
+ tickLabelInterval,
168
+ isMounted
83
169
  });
84
- const positionSigne = position === 'bottom' ? 1 : -1;
85
170
  const labelRefPoint = {
86
171
  x: left + width / 2,
87
- y: positionSigne * (tickFontSize + tickSize + 10)
172
+ y: positionSign * (tickSize + 22)
88
173
  };
89
- const Line = (_slots$axisLine = slots == null ? void 0 : slots.axisLine) != null ? _slots$axisLine : ChartsLine;
90
- const Tick = (_slots$axisTick = slots == null ? void 0 : slots.axisTick) != null ? _slots$axisTick : ChartsTick;
91
- const TickLabel = (_slots$axisTickLabel = slots == null ? void 0 : slots.axisTickLabel) != null ? _slots$axisTickLabel : ChartsTickLabel;
92
- const Label = (_slots$axisLabel = slots == null ? void 0 : slots.axisLabel) != null ? _slots$axisLabel : ChartsLabel;
174
+ const axisLabelProps = useSlotProps({
175
+ elementType: Label,
176
+ externalSlotProps: slotProps == null ? void 0 : slotProps.axisLabel,
177
+ additionalProps: {
178
+ style: _extends({
179
+ fontSize: labelFontSize != null ? labelFontSize : 14,
180
+ textAnchor: 'middle',
181
+ dominantBaseline: position === 'bottom' ? 'hanging' : 'auto'
182
+ }, labelStyle)
183
+ },
184
+ ownerState: {}
185
+ });
93
186
  return /*#__PURE__*/_jsxs(AxisRoot, {
94
187
  transform: `translate(0, ${position === 'bottom' ? top + height : top})`,
95
188
  className: classes.root,
@@ -97,40 +190,33 @@ function ChartsXAxis(inProps) {
97
190
  x1: xScale.range()[0],
98
191
  x2: xScale.range()[1],
99
192
  className: classes.line
100
- }, slotProps == null ? void 0 : slotProps.axisLine)), xTicks.map(({
193
+ }, slotProps == null ? void 0 : slotProps.axisLine)), xTicksWithDimension.map(({
101
194
  formattedValue,
102
195
  offset,
103
- labelOffset
196
+ labelOffset,
197
+ skipLabel
104
198
  }, index) => {
105
199
  const xTickLabel = labelOffset != null ? labelOffset : 0;
106
- const yTickLabel = positionSigne * (tickSize + 3);
200
+ const yTickLabel = positionSign * (tickSize + 3);
107
201
  return /*#__PURE__*/_jsxs("g", {
108
202
  transform: `translate(${offset}, 0)`,
109
203
  className: classes.tickContainer,
110
204
  children: [!disableTicks && /*#__PURE__*/_jsx(Tick, _extends({
111
- y2: positionSigne * tickSize,
205
+ y2: positionSign * tickSize,
112
206
  className: classes.tick
113
- }, 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({
114
208
  x: xTickLabel,
115
- y: yTickLabel,
116
- "transform-origin": `${xTickLabel}px ${yTickLabel}px`,
117
- sx: {
118
- fontSize: tickFontSize
119
- },
120
- className: classes.tickLabel
121
- }, slotProps == null ? void 0 : slotProps.axisTickLabel, {
122
- children: formattedValue
209
+ y: yTickLabel
210
+ }, axisTickLabelProps, {
211
+ text: formattedValue.toString()
123
212
  }))]
124
213
  }, index);
125
- }), label && /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, {
126
- sx: {
127
- fontSize: labelFontSize,
128
- transformOrigin: `${labelRefPoint.x}px ${labelRefPoint.y}px`
129
- },
130
- className: classes.label
131
- }, slotProps == null ? void 0 : slotProps.axisLabel, {
132
- children: label
133
- }))]
214
+ }), label && /*#__PURE__*/_jsx("g", {
215
+ className: classes.label,
216
+ children: /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, axisLabelProps, {
217
+ text: label
218
+ }))
219
+ })]
134
220
  });
135
221
  }
136
222
  process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
@@ -168,8 +254,13 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
168
254
  /**
169
255
  * The font size of the axis label.
170
256
  * @default 14
257
+ * @deprecated Consider using `labelStyle.fontSize` instead.
171
258
  */
172
259
  labelFontSize: PropTypes.number,
260
+ /**
261
+ * The style applied to the axis label.
262
+ */
263
+ labelStyle: PropTypes.object,
173
264
  /**
174
265
  * Position of the axis.
175
266
  */
@@ -192,8 +283,28 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
192
283
  /**
193
284
  * The font size of the axis ticks text.
194
285
  * @default 12
286
+ * @deprecated Consider using `tickLabelStyle.fontSize` instead.
195
287
  */
196
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,
197
308
  /**
198
309
  * Maximal step between two ticks.
199
310
  * When using time data, the value is assumed to be in ms.
@@ -1,14 +1,16 @@
1
1
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
- const _excluded = ["scale", "ticksNumber"];
3
+ const _excluded = ["scale", "tickNumber"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
+ import { useSlotProps } from '@mui/base/utils';
6
7
  import { unstable_composeClasses as composeClasses } from '@mui/utils';
7
8
  import { useThemeProps, useTheme } from '@mui/material/styles';
8
9
  import { CartesianContext } from '../context/CartesianContextProvider';
9
10
  import { DrawingContext } from '../context/DrawingProvider';
10
11
  import useTicks from '../hooks/useTicks';
11
- import { ChartsLine, ChartsTick, ChartsTickLabel, ChartsLabel, AxisRoot } from '../internals/components/AxisSharedComponents';
12
+ import { AxisRoot } from '../internals/components/AxisSharedComponents';
13
+ import { ChartsText } from '../internals/components/ChartsText';
12
14
  import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
13
15
  import { jsx as _jsx } from "react/jsx-runtime";
14
16
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -47,7 +49,7 @@ function ChartsYAxis(inProps) {
47
49
  yAxis: {
48
50
  [_props$axisId]: {
49
51
  scale: yScale,
50
- ticksNumber
52
+ tickNumber
51
53
  }
52
54
  }
53
55
  } = _React$useContext,
@@ -78,18 +80,44 @@ function ChartsYAxis(inProps) {
78
80
  const tickSize = disableTicks ? 4 : tickSizeProp;
79
81
  const yTicks = useTicks({
80
82
  scale: yScale,
81
- ticksNumber,
83
+ tickNumber,
82
84
  valueFormatter
83
85
  });
84
- const positionSigne = position === 'right' ? 1 : -1;
86
+ const positionSign = position === 'right' ? 1 : -1;
85
87
  const labelRefPoint = {
86
- x: positionSigne * (tickFontSize + tickSize + 10),
88
+ x: positionSign * (tickFontSize + tickSize + 10),
87
89
  y: top + height / 2
88
90
  };
89
- const Line = (_slots$axisLine = slots == null ? void 0 : slots.axisLine) != null ? _slots$axisLine : ChartsLine;
90
- const Tick = (_slots$axisTick = slots == null ? void 0 : slots.axisTick) != null ? _slots$axisTick : ChartsTick;
91
- const TickLabel = (_slots$axisTickLabel = slots == null ? void 0 : slots.axisTickLabel) != null ? _slots$axisTickLabel : ChartsTickLabel;
92
- const Label = (_slots$axisLabel = slots == null ? void 0 : slots.axisLabel) != null ? _slots$axisLabel : ChartsLabel;
91
+ const Line = (_slots$axisLine = slots == null ? void 0 : slots.axisLine) != null ? _slots$axisLine : 'line';
92
+ const Tick = (_slots$axisTick = slots == null ? void 0 : slots.axisTick) != null ? _slots$axisTick : 'line';
93
+ const TickLabel = (_slots$axisTickLabel = slots == null ? void 0 : slots.axisTickLabel) != null ? _slots$axisTickLabel : ChartsText;
94
+ const Label = (_slots$axisLabel = slots == null ? void 0 : slots.axisLabel) != null ? _slots$axisLabel : ChartsText;
95
+ const axisTickLabelProps = useSlotProps({
96
+ elementType: TickLabel,
97
+ externalSlotProps: slotProps == null ? void 0 : slotProps.axisTickLabel,
98
+ additionalProps: {
99
+ style: {
100
+ fontSize: tickFontSize,
101
+ textAnchor: position === 'right' ? 'start' : 'end',
102
+ dominantBaseline: 'central'
103
+ },
104
+ className: classes.tickLabel
105
+ },
106
+ ownerState: {}
107
+ });
108
+ const axisLabelProps = useSlotProps({
109
+ elementType: Label,
110
+ externalSlotProps: slotProps == null ? void 0 : slotProps.axisLabel,
111
+ additionalProps: {
112
+ style: {
113
+ fontSize: labelFontSize,
114
+ angle: positionSign * 90,
115
+ textAnchor: 'middle',
116
+ dominantBaseline: 'auto'
117
+ }
118
+ },
119
+ ownerState: {}
120
+ });
93
121
  return /*#__PURE__*/_jsxs(AxisRoot, {
94
122
  transform: `translate(${position === 'right' ? left + width : left}, 0)`,
95
123
  className: classes.root,
@@ -102,36 +130,26 @@ function ChartsYAxis(inProps) {
102
130
  offset,
103
131
  labelOffset
104
132
  }, index) => {
105
- const xTickLabel = positionSigne * (tickSize + 2);
133
+ const xTickLabel = positionSign * (tickSize + 2);
106
134
  const yTickLabel = labelOffset;
107
135
  return /*#__PURE__*/_jsxs("g", {
108
136
  transform: `translate(0, ${offset})`,
109
137
  className: classes.tickContainer,
110
138
  children: [!disableTicks && /*#__PURE__*/_jsx(Tick, _extends({
111
- x2: positionSigne * tickSize,
139
+ x2: positionSign * tickSize,
112
140
  className: classes.tick
113
141
  }, slotProps == null ? void 0 : slotProps.axisTick)), formattedValue !== undefined && /*#__PURE__*/_jsx(TickLabel, _extends({
114
142
  x: xTickLabel,
115
143
  y: yTickLabel,
116
- "transform-origin": `${xTickLabel}px ${yTickLabel}px`,
117
- sx: {
118
- fontSize: tickFontSize
119
- },
120
- className: classes.tickLabel
121
- }, slotProps == null ? void 0 : slotProps.axisTickLabel, {
122
- children: formattedValue.toLocaleString()
123
- }))]
144
+ text: formattedValue.toString()
145
+ }, axisTickLabelProps))]
124
146
  }, index);
125
- }), label && /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, {
126
- sx: {
127
- fontSize: labelFontSize,
128
- transform: `rotate(${positionSigne * 90}deg)`,
129
- transformOrigin: `${labelRefPoint.x}px ${labelRefPoint.y}px`
130
- },
131
- className: classes.label
132
- }, slotProps == null ? void 0 : slotProps.axisLabel, {
133
- children: label
134
- }))]
147
+ }), label && /*#__PURE__*/_jsx("g", {
148
+ className: classes.label,
149
+ children: /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, axisLabelProps, {
150
+ text: label
151
+ }))
152
+ })]
135
153
  });
136
154
  }
137
155
  process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
@@ -169,8 +187,13 @@ process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
169
187
  /**
170
188
  * The font size of the axis label.
171
189
  * @default 14
190
+ * @deprecated Consider using `labelStyle.fontSize` instead.
172
191
  */
173
192
  labelFontSize: PropTypes.number,
193
+ /**
194
+ * The style applied to the axis label.
195
+ */
196
+ labelStyle: PropTypes.object,
174
197
  /**
175
198
  * Position of the axis.
176
199
  */
@@ -193,8 +216,28 @@ process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
193
216
  /**
194
217
  * The font size of the axis ticks text.
195
218
  * @default 12
219
+ * @deprecated Consider using `tickLabelStyle.fontSize` instead.
196
220
  */
197
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,
198
241
  /**
199
242
  * Maximal step between two ticks.
200
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,
@@ -15,6 +15,16 @@ import { ChartsClipPath } from '../ChartsClipPath';
15
15
  import { LineHighlightPlot } from './LineHighlightPlot';
16
16
  import { jsx as _jsx } from "react/jsx-runtime";
17
17
  import { jsxs as _jsxs } from "react/jsx-runtime";
18
+ /**
19
+ * Demos:
20
+ *
21
+ * - [Lines](https://mui.com/x/react-charts/lines/)
22
+ * - [Line demonstration](https://mui.com/x/react-charts/line-demo/)
23
+ *
24
+ * API:
25
+ *
26
+ * - [LineChart API](https://mui.com/x/api/charts/line-chart/)
27
+ */
18
28
  const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
19
29
  const {
20
30
  xAxis,
@@ -121,11 +131,15 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
121
131
  fill: PropTypes.string,
122
132
  label: PropTypes.string,
123
133
  labelFontSize: PropTypes.number,
134
+ labelStyle: PropTypes.object,
124
135
  position: PropTypes.oneOf(['bottom', 'top']),
125
136
  slotProps: PropTypes.object,
126
137
  slots: PropTypes.object,
127
138
  stroke: PropTypes.string,
128
139
  tickFontSize: PropTypes.number,
140
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
141
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
142
+ tickLabelStyle: PropTypes.object,
129
143
  tickMaxStep: PropTypes.number,
130
144
  tickMinStep: PropTypes.number,
131
145
  tickNumber: PropTypes.number,
@@ -158,33 +172,33 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
158
172
  fill: PropTypes.string,
159
173
  label: PropTypes.string,
160
174
  labelFontSize: PropTypes.number,
175
+ labelStyle: PropTypes.object,
161
176
  position: PropTypes.oneOf(['left', 'right']),
162
177
  slotProps: PropTypes.object,
163
178
  slots: PropTypes.object,
164
179
  stroke: PropTypes.string,
165
180
  tickFontSize: PropTypes.number,
181
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
182
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
183
+ tickLabelStyle: PropTypes.object,
166
184
  tickMaxStep: PropTypes.number,
167
185
  tickMinStep: PropTypes.number,
168
186
  tickNumber: PropTypes.number,
169
187
  tickSize: PropTypes.number
170
188
  }), PropTypes.string]),
189
+ /**
190
+ * @deprecated Consider using `slotProps.legend` instead.
191
+ */
171
192
  legend: PropTypes.shape({
172
193
  classes: PropTypes.object,
173
194
  direction: PropTypes.oneOf(['column', 'row']),
174
195
  hidden: PropTypes.bool,
175
- itemWidth: PropTypes.number,
176
- markSize: PropTypes.number,
177
- offset: PropTypes.shape({
178
- x: PropTypes.number,
179
- y: PropTypes.number
180
- }),
181
196
  position: PropTypes.shape({
182
197
  horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
183
198
  vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
184
199
  }),
185
200
  slotProps: PropTypes.object,
186
- slots: PropTypes.object,
187
- spacing: PropTypes.number
201
+ slots: PropTypes.object
188
202
  }),
189
203
  margin: PropTypes.shape({
190
204
  bottom: PropTypes.number,
@@ -205,11 +219,15 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
205
219
  fill: PropTypes.string,
206
220
  label: PropTypes.string,
207
221
  labelFontSize: PropTypes.number,
222
+ labelStyle: PropTypes.object,
208
223
  position: PropTypes.oneOf(['left', 'right']),
209
224
  slotProps: PropTypes.object,
210
225
  slots: PropTypes.object,
211
226
  stroke: PropTypes.string,
212
227
  tickFontSize: PropTypes.number,
228
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
229
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
230
+ tickLabelStyle: PropTypes.object,
213
231
  tickMaxStep: PropTypes.number,
214
232
  tickMinStep: PropTypes.number,
215
233
  tickNumber: PropTypes.number,
@@ -270,11 +288,15 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
270
288
  fill: PropTypes.string,
271
289
  label: PropTypes.string,
272
290
  labelFontSize: PropTypes.number,
291
+ labelStyle: PropTypes.object,
273
292
  position: PropTypes.oneOf(['bottom', 'top']),
274
293
  slotProps: PropTypes.object,
275
294
  slots: PropTypes.object,
276
295
  stroke: PropTypes.string,
277
296
  tickFontSize: PropTypes.number,
297
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
298
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
299
+ tickLabelStyle: PropTypes.object,
278
300
  tickMaxStep: PropTypes.number,
279
301
  tickMinStep: PropTypes.number,
280
302
  tickNumber: PropTypes.number,
@@ -299,6 +321,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
299
321
  id: PropTypes.string,
300
322
  label: PropTypes.string,
301
323
  labelFontSize: PropTypes.number,
324
+ labelStyle: PropTypes.object,
302
325
  max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
303
326
  min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
304
327
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
@@ -307,6 +330,9 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
307
330
  slots: PropTypes.object,
308
331
  stroke: PropTypes.string,
309
332
  tickFontSize: PropTypes.number,
333
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
334
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
335
+ tickLabelStyle: PropTypes.object,
310
336
  tickMaxStep: PropTypes.number,
311
337
  tickMinStep: PropTypes.number,
312
338
  tickNumber: PropTypes.number,
@@ -325,6 +351,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
325
351
  id: PropTypes.string,
326
352
  label: PropTypes.string,
327
353
  labelFontSize: PropTypes.number,
354
+ labelStyle: PropTypes.object,
328
355
  max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
329
356
  min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
330
357
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
@@ -333,6 +360,9 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
333
360
  slots: PropTypes.object,
334
361
  stroke: PropTypes.string,
335
362
  tickFontSize: PropTypes.number,
363
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
364
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
365
+ tickLabelStyle: PropTypes.object,
336
366
  tickMaxStep: PropTypes.number,
337
367
  tickMinStep: PropTypes.number,
338
368
  tickNumber: PropTypes.number,
@@ -57,6 +57,16 @@ LineElementPath.propTypes = {
57
57
  }).isRequired,
58
58
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
59
59
  };
60
+ /**
61
+ * Demos:
62
+ *
63
+ * - [Lines](https://mui.com/x/react-charts/lines/)
64
+ * - [Line demonstration](https://mui.com/x/react-charts/line-demo/)
65
+ *
66
+ * API:
67
+ *
68
+ * - [LineElement API](https://mui.com/x/api/charts/line-element/)
69
+ */
60
70
  function LineElement(props) {
61
71
  var _slots$line;
62
72
  const {
@@ -33,6 +33,16 @@ const HighlightElement = styled('circle', {
33
33
  transformOrigin: `${ownerState.x}px ${ownerState.y}px`,
34
34
  fill: ownerState.color
35
35
  }));
36
+ /**
37
+ * Demos:
38
+ *
39
+ * - [Lines](https://mui.com/x/react-charts/lines/)
40
+ * - [Line demonstration](https://mui.com/x/react-charts/line-demo/)
41
+ *
42
+ * API:
43
+ *
44
+ * - [LineHighlightElement API](https://mui.com/x/api/charts/line-highlight-element/)
45
+ */
36
46
  function LineHighlightElement(props) {
37
47
  const {
38
48
  x,
@@ -9,6 +9,16 @@ import { LineHighlightElement } from './LineHighlightElement';
9
9
  import { getValueToPositionMapper } from '../hooks/useScale';
10
10
  import { InteractionContext } from '../context/InteractionProvider';
11
11
  import { jsx as _jsx } from "react/jsx-runtime";
12
+ /**
13
+ * Demos:
14
+ *
15
+ * - [Lines](https://mui.com/x/react-charts/lines/)
16
+ * - [Line demonstration](https://mui.com/x/react-charts/line-demo/)
17
+ *
18
+ * API:
19
+ *
20
+ * - [LineHighlightPlot API](https://mui.com/x/api/charts/line-highlight-plot/)
21
+ */
12
22
  function LineHighlightPlot(props) {
13
23
  var _axis$x, _slots$lineHighlight;
14
24
  const {