@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
@@ -8,6 +8,16 @@ import { CartesianContext } from '../context/CartesianContextProvider';
8
8
  import { MarkElement } from './MarkElement';
9
9
  import { getValueToPositionMapper } from '../hooks/useScale';
10
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
+ /**
12
+ * Demos:
13
+ *
14
+ * - [Lines](https://mui.com/x/react-charts/lines/)
15
+ * - [Line demonstration](https://mui.com/x/react-charts/line-demo/)
16
+ *
17
+ * API:
18
+ *
19
+ * - [MarkPlot API](https://mui.com/x/api/charts/mark-plot/)
20
+ */
11
21
  function MarkPlot(props) {
12
22
  const {
13
23
  slots,
@@ -41,6 +51,7 @@ function MarkPlot(props) {
41
51
  xAxisKey = defaultXAxisId,
42
52
  yAxisKey = defaultYAxisId,
43
53
  stackedData,
54
+ data,
44
55
  showMark = true
45
56
  } = series[seriesId];
46
57
  if (showMark === false) {
@@ -67,28 +78,48 @@ function MarkPlot(props) {
67
78
  throw new Error(`Axis of id "${xAxisKey}" should have data property to be able to display a line plot`);
68
79
  }
69
80
  return xData?.map((x, index) => {
70
- const y = stackedData[index][1];
81
+ const value = data[index] == null ? null : stackedData[index][1];
71
82
  return {
72
83
  x: xScale(x),
73
- y: yScale(y),
84
+ y: value === null ? null : yScale(value),
74
85
  position: x,
75
- value: y,
86
+ value,
76
87
  index
77
88
  };
78
- }).filter(isInRange).map(({
89
+ }).filter(({
79
90
  x,
80
91
  y,
81
92
  index,
82
93
  position,
83
94
  value
84
95
  }) => {
85
- return showMark === true || showMark({
96
+ if (value === null || y === null) {
97
+ // Remove missing data point
98
+ return false;
99
+ }
100
+ if (!isInRange({
101
+ x,
102
+ y
103
+ })) {
104
+ // Remove out of range
105
+ return false;
106
+ }
107
+ if (showMark === true) {
108
+ return true;
109
+ }
110
+ return showMark({
86
111
  x,
87
112
  y,
88
113
  index,
89
114
  position,
90
115
  value
91
- }) ? /*#__PURE__*/_jsx(Mark, _extends({
116
+ });
117
+ }).map(({
118
+ x,
119
+ y,
120
+ index
121
+ }) => {
122
+ return /*#__PURE__*/_jsx(Mark, _extends({
92
123
  id: seriesId,
93
124
  dataIndex: index,
94
125
  shape: "circle",
@@ -96,7 +127,7 @@ function MarkPlot(props) {
96
127
  x: x,
97
128
  y: y,
98
129
  highlightScope: series[seriesId].highlightScope
99
- }, slotProps?.mark), `${seriesId}-${index}`) : null;
130
+ }, slotProps?.mark), `${seriesId}-${index}`);
100
131
  });
101
132
  });
102
133
  })
@@ -24,7 +24,7 @@ const formatter = (params, dataset) => {
24
24
  d3Dataset[index][id] = value;
25
25
  }
26
26
  });
27
- } else if (dataset === undefined) {
27
+ } else if (dataset === undefined && process.env.NODE_ENV !== 'production') {
28
28
  throw new Error([`MUI: line series with id='${id}' has no data.`, 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
29
29
  }
30
30
  });
@@ -40,7 +40,8 @@ const formatter = (params, dataset) => {
40
40
  // Use dataKey if needed and available
41
41
  const dataKey = series[id].dataKey;
42
42
  return series[id].data === undefined && dataKey !== undefined ? dataKey : id;
43
- })).order(stackingOrder).offset(stackingOffset)(d3Dataset);
43
+ })).value((d, key) => d[key] ?? 0) // defaultize null value to 0
44
+ .order(stackingOrder).offset(stackingOffset)(d3Dataset);
44
45
  ids.forEach((id, index) => {
45
46
  const dataKey = series[id].dataKey;
46
47
  completedSeries[id] = _extends({}, series[id], {
@@ -52,7 +53,7 @@ const formatter = (params, dataset) => {
52
53
  return {
53
54
  seriesOrder,
54
55
  stackingGroups,
55
- series: defaultizeValueFormatter(completedSeries, v => v.toLocaleString())
56
+ series: defaultizeValueFormatter(completedSeries, v => v?.toLocaleString())
56
57
  };
57
58
  };
58
59
  export default formatter;
@@ -16,6 +16,17 @@ const defaultMargin = {
16
16
  left: 5,
17
17
  right: 100
18
18
  };
19
+
20
+ /**
21
+ * Demos:
22
+ *
23
+ * - [Pie](https://mui.com/x/react-charts/pie/)
24
+ * - [Pie demonstration](https://mui.com/x/react-charts/pie-demo/)
25
+ *
26
+ * API:
27
+ *
28
+ * - [PieChart API](https://mui.com/x/api/charts/pie-chart/)
29
+ */
19
30
  function PieChart(props) {
20
31
  const {
21
32
  xAxis,
@@ -105,11 +116,15 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
105
116
  fill: PropTypes.string,
106
117
  label: PropTypes.string,
107
118
  labelFontSize: PropTypes.number,
119
+ labelStyle: PropTypes.object,
108
120
  position: PropTypes.oneOf(['bottom', 'top']),
109
121
  slotProps: PropTypes.object,
110
122
  slots: PropTypes.object,
111
123
  stroke: PropTypes.string,
112
124
  tickFontSize: PropTypes.number,
125
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
126
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
127
+ tickLabelStyle: PropTypes.object,
113
128
  tickMaxStep: PropTypes.number,
114
129
  tickMinStep: PropTypes.number,
115
130
  tickNumber: PropTypes.number,
@@ -138,11 +153,15 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
138
153
  fill: PropTypes.string,
139
154
  label: PropTypes.string,
140
155
  labelFontSize: PropTypes.number,
156
+ labelStyle: PropTypes.object,
141
157
  position: PropTypes.oneOf(['left', 'right']),
142
158
  slotProps: PropTypes.object,
143
159
  slots: PropTypes.object,
144
160
  stroke: PropTypes.string,
145
161
  tickFontSize: PropTypes.number,
162
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
163
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
164
+ tickLabelStyle: PropTypes.object,
146
165
  tickMaxStep: PropTypes.number,
147
166
  tickMinStep: PropTypes.number,
148
167
  tickNumber: PropTypes.number,
@@ -182,11 +201,15 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
182
201
  fill: PropTypes.string,
183
202
  label: PropTypes.string,
184
203
  labelFontSize: PropTypes.number,
204
+ labelStyle: PropTypes.object,
185
205
  position: PropTypes.oneOf(['left', 'right']),
186
206
  slotProps: PropTypes.object,
187
207
  slots: PropTypes.object,
188
208
  stroke: PropTypes.string,
189
209
  tickFontSize: PropTypes.number,
210
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
211
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
212
+ tickLabelStyle: PropTypes.object,
190
213
  tickMaxStep: PropTypes.number,
191
214
  tickMinStep: PropTypes.number,
192
215
  tickNumber: PropTypes.number,
@@ -260,11 +283,15 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
260
283
  fill: PropTypes.string,
261
284
  label: PropTypes.string,
262
285
  labelFontSize: PropTypes.number,
286
+ labelStyle: PropTypes.object,
263
287
  position: PropTypes.oneOf(['bottom', 'top']),
264
288
  slotProps: PropTypes.object,
265
289
  slots: PropTypes.object,
266
290
  stroke: PropTypes.string,
267
291
  tickFontSize: PropTypes.number,
292
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
293
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
294
+ tickLabelStyle: PropTypes.object,
268
295
  tickMaxStep: PropTypes.number,
269
296
  tickMinStep: PropTypes.number,
270
297
  tickNumber: PropTypes.number,
@@ -289,6 +316,7 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
289
316
  id: PropTypes.string,
290
317
  label: PropTypes.string,
291
318
  labelFontSize: PropTypes.number,
319
+ labelStyle: PropTypes.object,
292
320
  max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
293
321
  min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
294
322
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
@@ -297,6 +325,9 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
297
325
  slots: PropTypes.object,
298
326
  stroke: PropTypes.string,
299
327
  tickFontSize: PropTypes.number,
328
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
329
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
330
+ tickLabelStyle: PropTypes.object,
300
331
  tickMaxStep: PropTypes.number,
301
332
  tickMinStep: PropTypes.number,
302
333
  tickNumber: PropTypes.number,
@@ -315,6 +346,7 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
315
346
  id: PropTypes.string,
316
347
  label: PropTypes.string,
317
348
  labelFontSize: PropTypes.number,
349
+ labelStyle: PropTypes.object,
318
350
  max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
319
351
  min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
320
352
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
@@ -323,6 +355,9 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
323
355
  slots: PropTypes.object,
324
356
  stroke: PropTypes.string,
325
357
  tickFontSize: PropTypes.number,
358
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
359
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
360
+ tickLabelStyle: PropTypes.object,
326
361
  tickMaxStep: PropTypes.number,
327
362
  tickMinStep: PropTypes.number,
328
363
  tickNumber: PropTypes.number,
@@ -22,6 +22,16 @@ function getItemLabel(arcLabel, arcLabelMinAngle, item) {
22
22
  }
23
23
  return arcLabel(item);
24
24
  }
25
+ /**
26
+ * Demos:
27
+ *
28
+ * - [Pie](https://mui.com/x/react-charts/pie/)
29
+ * - [Pie demonstration](https://mui.com/x/react-charts/pie-demo/)
30
+ *
31
+ * API:
32
+ *
33
+ * - [PiePlot API](https://mui.com/x/api/charts/pie-plot/)
34
+ */
25
35
  function PiePlot(props) {
26
36
  const {
27
37
  slots,
@@ -103,10 +103,10 @@ export const ResponsiveChartContainer = /*#__PURE__*/React.forwardRef(function R
103
103
  width: inWidth,
104
104
  height: inHeight
105
105
  },
106
- children: /*#__PURE__*/_jsx(ChartContainer, _extends({}, other, {
106
+ children: width && height ? /*#__PURE__*/_jsx(ChartContainer, _extends({}, other, {
107
107
  width: width,
108
108
  height: height,
109
109
  ref: ref
110
- }))
110
+ })) : null
111
111
  });
112
112
  });
@@ -5,6 +5,16 @@ import { getValueToPositionMapper } from '../hooks/useScale';
5
5
  import { getIsFaded, getIsHighlighted, useInteractionItemProps } from '../hooks/useInteractionItemProps';
6
6
  import { InteractionContext } from '../context/InteractionProvider';
7
7
  import { jsx as _jsx } from "react/jsx-runtime";
8
+ /**
9
+ * Demos:
10
+ *
11
+ * - [Scatter](https://mui.com/x/react-charts/scatter/)
12
+ * - [Scatter demonstration](https://mui.com/x/react-charts/scatter-demo/)
13
+ *
14
+ * API:
15
+ *
16
+ * - [Scatter API](https://mui.com/x/api/charts/scatter/)
17
+ */
8
18
  function Scatter(props) {
9
19
  const {
10
20
  series,
@@ -9,6 +9,16 @@ import { ChartsLegend } from '../ChartsLegend';
9
9
  import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
10
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
11
  import { jsxs as _jsxs } from "react/jsx-runtime";
12
+ /**
13
+ * Demos:
14
+ *
15
+ * - [Scatter](https://mui.com/x/react-charts/scatter/)
16
+ * - [Scatter demonstration](https://mui.com/x/react-charts/scatter-demo/)
17
+ *
18
+ * API:
19
+ *
20
+ * - [ScatterChart API](https://mui.com/x/api/charts/scatter-chart/)
21
+ */
12
22
  const ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props, ref) {
13
23
  const {
14
24
  xAxis,
@@ -85,11 +95,15 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
85
95
  fill: PropTypes.string,
86
96
  label: PropTypes.string,
87
97
  labelFontSize: PropTypes.number,
98
+ labelStyle: PropTypes.object,
88
99
  position: PropTypes.oneOf(['bottom', 'top']),
89
100
  slotProps: PropTypes.object,
90
101
  slots: PropTypes.object,
91
102
  stroke: PropTypes.string,
92
103
  tickFontSize: PropTypes.number,
104
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
105
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
106
+ tickLabelStyle: PropTypes.object,
93
107
  tickMaxStep: PropTypes.number,
94
108
  tickMinStep: PropTypes.number,
95
109
  tickNumber: PropTypes.number,
@@ -118,11 +132,15 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
118
132
  fill: PropTypes.string,
119
133
  label: PropTypes.string,
120
134
  labelFontSize: PropTypes.number,
135
+ labelStyle: PropTypes.object,
121
136
  position: PropTypes.oneOf(['left', 'right']),
122
137
  slotProps: PropTypes.object,
123
138
  slots: PropTypes.object,
124
139
  stroke: PropTypes.string,
125
140
  tickFontSize: PropTypes.number,
141
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
142
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
143
+ tickLabelStyle: PropTypes.object,
126
144
  tickMaxStep: PropTypes.number,
127
145
  tickMinStep: PropTypes.number,
128
146
  tickNumber: PropTypes.number,
@@ -161,11 +179,15 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
161
179
  fill: PropTypes.string,
162
180
  label: PropTypes.string,
163
181
  labelFontSize: PropTypes.number,
182
+ labelStyle: PropTypes.object,
164
183
  position: PropTypes.oneOf(['left', 'right']),
165
184
  slotProps: PropTypes.object,
166
185
  slots: PropTypes.object,
167
186
  stroke: PropTypes.string,
168
187
  tickFontSize: PropTypes.number,
188
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
189
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
190
+ tickLabelStyle: PropTypes.object,
169
191
  tickMaxStep: PropTypes.number,
170
192
  tickMinStep: PropTypes.number,
171
193
  tickNumber: PropTypes.number,
@@ -223,11 +245,15 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
223
245
  fill: PropTypes.string,
224
246
  label: PropTypes.string,
225
247
  labelFontSize: PropTypes.number,
248
+ labelStyle: PropTypes.object,
226
249
  position: PropTypes.oneOf(['bottom', 'top']),
227
250
  slotProps: PropTypes.object,
228
251
  slots: PropTypes.object,
229
252
  stroke: PropTypes.string,
230
253
  tickFontSize: PropTypes.number,
254
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
255
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
256
+ tickLabelStyle: PropTypes.object,
231
257
  tickMaxStep: PropTypes.number,
232
258
  tickMinStep: PropTypes.number,
233
259
  tickNumber: PropTypes.number,
@@ -252,6 +278,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
252
278
  id: PropTypes.string,
253
279
  label: PropTypes.string,
254
280
  labelFontSize: PropTypes.number,
281
+ labelStyle: PropTypes.object,
255
282
  max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
256
283
  min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
257
284
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
@@ -260,6 +287,9 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
260
287
  slots: PropTypes.object,
261
288
  stroke: PropTypes.string,
262
289
  tickFontSize: PropTypes.number,
290
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
291
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
292
+ tickLabelStyle: PropTypes.object,
263
293
  tickMaxStep: PropTypes.number,
264
294
  tickMinStep: PropTypes.number,
265
295
  tickNumber: PropTypes.number,
@@ -278,6 +308,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
278
308
  id: PropTypes.string,
279
309
  label: PropTypes.string,
280
310
  labelFontSize: PropTypes.number,
311
+ labelStyle: PropTypes.object,
281
312
  max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
282
313
  min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
283
314
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
@@ -286,6 +317,9 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
286
317
  slots: PropTypes.object,
287
318
  stroke: PropTypes.string,
288
319
  tickFontSize: PropTypes.number,
320
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
321
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
322
+ tickLabelStyle: PropTypes.object,
289
323
  tickMaxStep: PropTypes.number,
290
324
  tickMinStep: PropTypes.number,
291
325
  tickNumber: PropTypes.number,
@@ -5,6 +5,16 @@ import { Scatter } from './Scatter';
5
5
  import { SeriesContext } from '../context/SeriesContextProvider';
6
6
  import { CartesianContext } from '../context/CartesianContextProvider';
7
7
  import { jsx as _jsx } from "react/jsx-runtime";
8
+ /**
9
+ * Demos:
10
+ *
11
+ * - [Scatter](https://mui.com/x/react-charts/scatter/)
12
+ * - [Scatter demonstration](https://mui.com/x/react-charts/scatter-demo/)
13
+ *
14
+ * API:
15
+ *
16
+ * - [ScatterPlot API](https://mui.com/x/api/charts/scatter-plot/)
17
+ */
8
18
  function ScatterPlot(props) {
9
19
  const {
10
20
  slots,
@@ -15,6 +15,16 @@ const SPARKLINE_DEFAULT_MARGIN = {
15
15
  left: 5,
16
16
  right: 5
17
17
  };
18
+
19
+ /**
20
+ * Demos:
21
+ *
22
+ * - [SparkLine](https://mui.com/x/react-charts/sparkline/)
23
+ *
24
+ * API:
25
+ *
26
+ * - [SparkLineChart API](https://mui.com/x/api/charts/spark-line-chart/)
27
+ */
18
28
  const SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(props, ref) {
19
29
  const {
20
30
  xAxis,
@@ -195,6 +205,7 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
195
205
  id: PropTypes.string,
196
206
  label: PropTypes.string,
197
207
  labelFontSize: PropTypes.number,
208
+ labelStyle: PropTypes.object,
198
209
  max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
199
210
  min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
200
211
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
@@ -203,6 +214,9 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
203
214
  slots: PropTypes.object,
204
215
  stroke: PropTypes.string,
205
216
  tickFontSize: PropTypes.number,
217
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
218
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
219
+ tickLabelStyle: PropTypes.object,
206
220
  tickMaxStep: PropTypes.number,
207
221
  tickMinStep: PropTypes.number,
208
222
  tickNumber: PropTypes.number,
@@ -222,6 +222,7 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
222
222
  id: PropTypes.string,
223
223
  label: PropTypes.string,
224
224
  labelFontSize: PropTypes.number,
225
+ labelStyle: PropTypes.object,
225
226
  max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
226
227
  min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
227
228
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
@@ -230,6 +231,9 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
230
231
  slots: PropTypes.object,
231
232
  stroke: PropTypes.string,
232
233
  tickFontSize: PropTypes.number,
234
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
235
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
236
+ tickLabelStyle: PropTypes.object,
233
237
  tickMaxStep: PropTypes.number,
234
238
  tickMinStep: PropTypes.number,
235
239
  tickNumber: PropTypes.number,
@@ -248,6 +252,7 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
248
252
  id: PropTypes.string,
249
253
  label: PropTypes.string,
250
254
  labelFontSize: PropTypes.number,
255
+ labelStyle: PropTypes.object,
251
256
  max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
252
257
  min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
253
258
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
@@ -256,6 +261,9 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
256
261
  slots: PropTypes.object,
257
262
  stroke: PropTypes.string,
258
263
  tickFontSize: PropTypes.number,
264
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
265
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
266
+ tickLabelStyle: PropTypes.object,
259
267
  tickMaxStep: PropTypes.number,
260
268
  tickMinStep: PropTypes.number,
261
269
  tickNumber: PropTypes.number,
@@ -0,0 +1,16 @@
1
+ import * as React from 'react';
2
+ import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
3
+ export function useMounted(defer = false) {
4
+ const [mountedState, setMountedState] = React.useState(false);
5
+ useEnhancedEffect(() => {
6
+ if (!defer) {
7
+ setMountedState(true);
8
+ }
9
+ }, [defer]);
10
+ React.useEffect(() => {
11
+ if (defer) {
12
+ setMountedState(true);
13
+ }
14
+ }, [defer]);
15
+ return mountedState;
16
+ }
@@ -0,0 +1,27 @@
1
+ import { useIsomorphicLayoutEffect, Globals } from '@react-spring/web';
2
+
3
+ /**
4
+ * Returns `boolean` or `null`, used to automatically
5
+ * set skipAnimations to the value of the user's
6
+ * `prefers-reduced-motion` query.
7
+ *
8
+ * The return value, post-effect, is the value of their prefered setting
9
+ */
10
+ export const useReducedMotion = () => {
11
+ // Taken from: https://github.com/pmndrs/react-spring/blob/02ec877bbfab0df46da0e4a47d5f68d3e731206a/packages/shared/src/hooks/useReducedMotion.ts#L13
12
+
13
+ useIsomorphicLayoutEffect(() => {
14
+ const mql = window.matchMedia('(prefers-reduced-motion)');
15
+ const handleMediaChange = e => {
16
+ Globals.assign({
17
+ // Modification such the react-spring implementation such that this hook can remove animation but never activate animation.
18
+ skipAnimation: e.matches || undefined
19
+ });
20
+ };
21
+ handleMediaChange(mql);
22
+ mql.addEventListener('change', handleMediaChange);
23
+ return () => {
24
+ mql.removeEventListener('change', handleMediaChange);
25
+ };
26
+ }, []);
27
+ };
@@ -17,7 +17,8 @@ function useTicks(options) {
17
17
  const {
18
18
  scale,
19
19
  tickNumber,
20
- valueFormatter
20
+ valueFormatter,
21
+ tickInterval
21
22
  } = options;
22
23
  return React.useMemo(() => {
23
24
  // band scale
@@ -26,7 +27,8 @@ function useTicks(options) {
26
27
  if (scale.bandwidth() > 0) {
27
28
  // scale type = 'band'
28
29
  return [...domain.map(value => ({
29
- formattedValue: valueFormatter?.(value) ?? value,
30
+ value,
31
+ formattedValue: valueFormatter?.(value) ?? `${value}`,
30
32
  offset: scale(value) - (scale.step() - scale.bandwidth()) / 2,
31
33
  labelOffset: scale.step() / 2
32
34
  })), {
@@ -37,17 +39,21 @@ function useTicks(options) {
37
39
  }
38
40
 
39
41
  // scale type = 'point'
40
- return domain.map(value => ({
41
- formattedValue: valueFormatter?.(value) ?? value,
42
+ const filteredDomain = typeof tickInterval === 'function' && domain.filter(tickInterval) || typeof tickInterval === 'object' && tickInterval || domain;
43
+ return filteredDomain.map(value => ({
44
+ value,
45
+ formattedValue: valueFormatter?.(value) ?? `${value}`,
42
46
  offset: scale(value),
43
47
  labelOffset: 0
44
48
  }));
45
49
  }
46
- return scale.ticks(tickNumber).map(value => ({
50
+ const ticks = typeof tickInterval === 'object' ? tickInterval : scale.ticks(tickNumber);
51
+ return ticks.map(value => ({
52
+ value,
47
53
  formattedValue: valueFormatter?.(value) ?? scale.tickFormat(tickNumber)(value),
48
54
  offset: scale(value),
49
55
  labelOffset: 0
50
56
  }));
51
- }, [tickNumber, scale, valueFormatter]);
57
+ }, [tickNumber, scale, valueFormatter, tickInterval]);
52
58
  }
53
59
  export default useTicks;
package/modern/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v6.0.0-alpha.15
2
+ * @mui/x-charts v6.0.0-alpha.17
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -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 = ["x", "y", "textAnchor", "dominantBaseline", "style", "text", "ownerState"];
3
+ const _excluded = ["x", "y", "style", "text", "ownerState"],
4
+ _excluded2 = ["angle", "textAnchor", "dominantBaseline"];
4
5
  import * as React from 'react';
5
6
  import { getStringSize } from '../domUtils';
6
7
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -20,12 +21,17 @@ export function ChartsText(props) {
20
21
  const {
21
22
  x,
22
23
  y,
23
- textAnchor = 'start',
24
- dominantBaseline = 'central',
25
- style,
24
+ style: styleProps,
26
25
  text
27
26
  } = props,
28
27
  textProps = _objectWithoutPropertiesLoose(props, _excluded);
28
+ const _ref = styleProps ?? {},
29
+ {
30
+ angle,
31
+ textAnchor,
32
+ dominantBaseline
33
+ } = _ref,
34
+ style = _objectWithoutPropertiesLoose(_ref, _excluded2);
29
35
  const wordsByLines = React.useMemo(() => getWordsByLines({
30
36
  style,
31
37
  needsComputation: text.includes('\n'),
@@ -43,19 +49,17 @@ export function ChartsText(props) {
43
49
  startDy = (wordsByLines.length - 1) * -wordsByLines[0].height;
44
50
  break;
45
51
  }
46
-
47
- // const transforms = [];
52
+ const transforms = [];
48
53
  // if (scaleToFit) {
49
54
  // const lineWidth = wordsByLines[0].width;
50
55
  // transforms.push(`scale(${(isNumber(width as number) ? (width as number) / lineWidth : 1) / lineWidth})`);
51
56
  // }
52
- // if (angle) {
53
- // transforms.push(`rotate(${angle}, ${x}, ${y})`);
54
- // }
55
- // if (transforms.length) {
56
- // textProps.transform = transforms.join(' ');
57
- // }
58
-
57
+ if (angle) {
58
+ transforms.push(`rotate(${angle}, ${x}, ${y})`);
59
+ }
60
+ if (transforms.length) {
61
+ textProps.transform = transforms.join(' ');
62
+ }
59
63
  return /*#__PURE__*/_jsx("text", _extends({}, textProps, {
60
64
  x: x,
61
65
  y: y,
@@ -65,6 +69,8 @@ export function ChartsText(props) {
65
69
  children: wordsByLines.map((line, index) => /*#__PURE__*/_jsx("tspan", {
66
70
  x: x,
67
71
  dy: `${index === 0 ? startDy : wordsByLines[0].height}px`,
72
+ dominantBaseline: dominantBaseline // Propagated to fix Safari issue: https://github.com/mui/mui-x/issues/10808
73
+ ,
68
74
  children: line.text
69
75
  }, index))
70
76
  }));