@mui/x-charts 7.12.0 → 7.13.0

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 (196) hide show
  1. package/BarChart/BarChart.js +2 -0
  2. package/BarChart/BarPlot.js +2 -2
  3. package/BarChart/extremums.d.ts +1 -1
  4. package/BarChart/extremums.js +5 -3
  5. package/BarChart/formatter.d.ts +2 -2
  6. package/BarChart/getColor.d.ts +3 -3
  7. package/BarChart/getColor.js +4 -3
  8. package/BarChart/legend.d.ts +1 -1
  9. package/BarChart/plugin.d.ts +2 -2
  10. package/CHANGELOG.md +151 -2
  11. package/ChartContainer/ChartContainer.d.ts +4 -15
  12. package/ChartContainer/ChartContainer.js +8 -6
  13. package/ChartContainer/useChartContainerProps.d.ts +10 -7
  14. package/ChartContainer/useChartContainerProps.js +16 -19
  15. package/ChartContainer/useDefaultizeAxis.d.ts +2 -1
  16. package/ChartsTooltip/ChartsAxisTooltipContent.js +2 -2
  17. package/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
  18. package/ChartsTooltip/utils.js +4 -2
  19. package/ChartsXAxis/ChartsXAxis.js +11 -5
  20. package/ChartsYAxis/ChartsYAxis.js +11 -5
  21. package/LineChart/AreaPlot.js +11 -1
  22. package/LineChart/LineChart.js +2 -0
  23. package/LineChart/extremums.d.ts +1 -1
  24. package/LineChart/extremums.js +4 -15
  25. package/LineChart/formatter.d.ts +2 -2
  26. package/LineChart/getColor.d.ts +3 -3
  27. package/LineChart/getColor.js +4 -3
  28. package/LineChart/legend.d.ts +1 -1
  29. package/LineChart/plugin.d.ts +2 -2
  30. package/PieChart/PieChart.js +2 -0
  31. package/PieChart/formatter.d.ts +2 -2
  32. package/PieChart/getColor.d.ts +3 -2
  33. package/PieChart/getColor.js +4 -3
  34. package/PieChart/legend.d.ts +1 -1
  35. package/PieChart/plugin.d.ts +2 -2
  36. package/ResponsiveChartContainer/ResponsiveChartContainer.js +2 -0
  37. package/ResponsiveChartContainer/useResponsiveChartContainerProps.d.ts +1 -2
  38. package/ScatterChart/ScatterChart.js +2 -0
  39. package/ScatterChart/extremums.d.ts +1 -1
  40. package/ScatterChart/extremums.js +6 -14
  41. package/ScatterChart/formatter.d.ts +2 -2
  42. package/ScatterChart/getColor.d.ts +3 -4
  43. package/ScatterChart/getColor.js +4 -3
  44. package/ScatterChart/legend.d.ts +1 -1
  45. package/ScatterChart/plugin.d.ts +2 -2
  46. package/SparkLineChart/SparkLineChart.js +2 -0
  47. package/context/CartesianProvider/CartesianProvider.d.ts +3 -12
  48. package/context/CartesianProvider/CartesianProvider.js +6 -4
  49. package/context/CartesianProvider/computeValue.d.ts +2 -1
  50. package/context/CartesianProvider/defaultizeAxis.d.ts +2 -1
  51. package/context/CartesianProvider/getAxisExtremum.d.ts +2 -2
  52. package/context/CartesianProvider/getAxisExtremum.js +3 -10
  53. package/context/PluginProvider/ColorProcessor.types.d.ts +8 -0
  54. package/context/PluginProvider/ExtremumGetter.types.d.ts +14 -0
  55. package/context/PluginProvider/ExtremumGetter.types.js +5 -0
  56. package/context/PluginProvider/Plugin.types.d.ts +25 -0
  57. package/context/PluginProvider/Plugin.types.js +5 -0
  58. package/context/PluginProvider/PluginContext.d.ts +4 -0
  59. package/{hooks/useColor.js → context/PluginProvider/PluginContext.js} +11 -7
  60. package/context/PluginProvider/PluginProvider.d.ts +4 -0
  61. package/context/{ColorProvider.js → PluginProvider/PluginProvider.js} +12 -11
  62. package/context/PluginProvider/SeriesFormatter.types.d.ts +21 -0
  63. package/context/PluginProvider/SeriesFormatter.types.js +5 -0
  64. package/context/PluginProvider/index.d.ts +10 -0
  65. package/context/PluginProvider/index.js +115 -0
  66. package/context/PluginProvider/mergePlugins.d.ts +36 -0
  67. package/context/PluginProvider/mergePlugins.js +37 -0
  68. package/context/PluginProvider/useColorProcessor.d.ts +4 -0
  69. package/context/PluginProvider/useColorProcessor.js +23 -0
  70. package/context/PluginProvider/useSeriesFormatter.d.ts +4 -0
  71. package/context/PluginProvider/useSeriesFormatter.js +23 -0
  72. package/context/PluginProvider/useXExtremumGetter.d.ts +4 -0
  73. package/context/PluginProvider/useXExtremumGetter.js +23 -0
  74. package/context/PluginProvider/useYExtremumGetter.d.ts +4 -0
  75. package/context/PluginProvider/useYExtremumGetter.js +23 -0
  76. package/context/SeriesProvider/Series.types.d.ts +4 -10
  77. package/context/SeriesProvider/SeriesProvider.js +2 -1
  78. package/context/SeriesProvider/index.d.ts +1 -1
  79. package/context/SeriesProvider/processSeries.d.ts +2 -1
  80. package/esm/BarChart/BarChart.js +2 -0
  81. package/esm/BarChart/BarPlot.js +1 -2
  82. package/esm/BarChart/extremums.js +5 -3
  83. package/esm/BarChart/getColor.js +3 -2
  84. package/esm/ChartContainer/ChartContainer.js +9 -7
  85. package/esm/ChartContainer/useChartContainerProps.js +14 -19
  86. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  87. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +1 -1
  88. package/esm/ChartsTooltip/utils.js +4 -2
  89. package/esm/ChartsXAxis/ChartsXAxis.js +11 -5
  90. package/esm/ChartsYAxis/ChartsYAxis.js +11 -5
  91. package/esm/LineChart/AreaPlot.js +11 -1
  92. package/esm/LineChart/LineChart.js +2 -0
  93. package/esm/LineChart/extremums.js +4 -15
  94. package/esm/LineChart/getColor.js +3 -2
  95. package/esm/PieChart/PieChart.js +2 -0
  96. package/esm/PieChart/getColor.js +3 -2
  97. package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +2 -0
  98. package/esm/ScatterChart/ScatterChart.js +2 -0
  99. package/esm/ScatterChart/extremums.js +6 -14
  100. package/esm/ScatterChart/getColor.js +3 -2
  101. package/esm/SparkLineChart/SparkLineChart.js +2 -0
  102. package/esm/context/CartesianProvider/CartesianProvider.js +6 -4
  103. package/esm/context/CartesianProvider/getAxisExtremum.js +3 -10
  104. package/esm/context/PluginProvider/Plugin.types.js +1 -0
  105. package/esm/context/PluginProvider/PluginContext.js +13 -0
  106. package/esm/context/PluginProvider/PluginProvider.js +19 -0
  107. package/esm/context/PluginProvider/SeriesFormatter.types.js +1 -0
  108. package/esm/context/PluginProvider/index.js +10 -0
  109. package/esm/context/PluginProvider/mergePlugins.js +30 -0
  110. package/esm/context/PluginProvider/useColorProcessor.js +15 -0
  111. package/esm/context/PluginProvider/useSeriesFormatter.js +15 -0
  112. package/esm/context/PluginProvider/useXExtremumGetter.js +15 -0
  113. package/esm/context/PluginProvider/useYExtremumGetter.js +15 -0
  114. package/esm/context/SeriesProvider/SeriesProvider.js +2 -1
  115. package/esm/hooks/useTicks.js +5 -2
  116. package/esm/internals/index.js +1 -1
  117. package/esm/internals/isInfinity.js +3 -0
  118. package/esm/models/index.js +0 -1
  119. package/hooks/useTicks.js +5 -2
  120. package/index.js +1 -1
  121. package/internals/colorScale.d.ts +1 -1
  122. package/internals/defaultizeColor.d.ts +1 -0
  123. package/internals/index.d.ts +1 -1
  124. package/internals/index.js +12 -12
  125. package/internals/isInfinity.d.ts +1 -0
  126. package/internals/isInfinity.js +9 -0
  127. package/models/axis.d.ts +2 -0
  128. package/models/index.d.ts +0 -1
  129. package/models/index.js +0 -11
  130. package/models/seriesType/config.d.ts +0 -26
  131. package/models/seriesType/line.d.ts +10 -0
  132. package/modern/BarChart/BarChart.js +2 -0
  133. package/modern/BarChart/BarPlot.js +1 -2
  134. package/modern/BarChart/extremums.js +5 -3
  135. package/modern/BarChart/getColor.js +3 -2
  136. package/modern/ChartContainer/ChartContainer.js +9 -7
  137. package/modern/ChartContainer/useChartContainerProps.js +14 -19
  138. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  139. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +1 -1
  140. package/modern/ChartsTooltip/utils.js +4 -2
  141. package/modern/ChartsXAxis/ChartsXAxis.js +11 -5
  142. package/modern/ChartsYAxis/ChartsYAxis.js +11 -5
  143. package/modern/LineChart/AreaPlot.js +11 -1
  144. package/modern/LineChart/LineChart.js +2 -0
  145. package/modern/LineChart/extremums.js +4 -15
  146. package/modern/LineChart/getColor.js +3 -2
  147. package/modern/PieChart/PieChart.js +2 -0
  148. package/modern/PieChart/getColor.js +3 -2
  149. package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +2 -0
  150. package/modern/ScatterChart/ScatterChart.js +2 -0
  151. package/modern/ScatterChart/extremums.js +6 -14
  152. package/modern/ScatterChart/getColor.js +3 -2
  153. package/modern/SparkLineChart/SparkLineChart.js +2 -0
  154. package/modern/context/CartesianProvider/CartesianProvider.js +6 -4
  155. package/modern/context/CartesianProvider/getAxisExtremum.js +3 -10
  156. package/modern/context/PluginProvider/ColorProcessor.types.js +1 -0
  157. package/modern/context/PluginProvider/ExtremumGetter.types.js +1 -0
  158. package/modern/context/PluginProvider/Plugin.types.js +1 -0
  159. package/modern/context/PluginProvider/PluginContext.js +13 -0
  160. package/modern/context/PluginProvider/PluginProvider.js +19 -0
  161. package/modern/context/PluginProvider/SeriesFormatter.types.js +1 -0
  162. package/modern/context/PluginProvider/index.js +10 -0
  163. package/modern/context/PluginProvider/mergePlugins.js +30 -0
  164. package/modern/context/PluginProvider/useColorProcessor.js +15 -0
  165. package/modern/context/PluginProvider/useSeriesFormatter.js +15 -0
  166. package/modern/context/PluginProvider/useXExtremumGetter.js +15 -0
  167. package/modern/context/PluginProvider/useYExtremumGetter.js +15 -0
  168. package/modern/context/SeriesProvider/SeriesProvider.js +2 -1
  169. package/modern/hooks/useTicks.js +5 -2
  170. package/modern/index.js +1 -1
  171. package/modern/internals/index.js +1 -1
  172. package/modern/internals/isInfinity.js +3 -0
  173. package/modern/models/index.js +0 -1
  174. package/package.json +2 -2
  175. package/ChartContainer/defaultPlugins.d.ts +0 -2
  176. package/ChartContainer/defaultPlugins.js +0 -11
  177. package/ChartContainer/useChartContainerHooks.d.ts +0 -11
  178. package/ChartContainer/useChartContainerHooks.js +0 -34
  179. package/ChartContainer/usePluginsMerge.d.ts +0 -9
  180. package/ChartContainer/usePluginsMerge.js +0 -39
  181. package/context/ColorProvider.d.ts +0 -12
  182. package/esm/ChartContainer/defaultPlugins.js +0 -5
  183. package/esm/ChartContainer/useChartContainerHooks.js +0 -24
  184. package/esm/ChartContainer/usePluginsMerge.js +0 -31
  185. package/esm/context/ColorProvider.js +0 -16
  186. package/esm/hooks/useColor.js +0 -9
  187. package/hooks/useColor.d.ts +0 -4
  188. package/models/plugin.d.ts +0 -19
  189. package/modern/ChartContainer/defaultPlugins.js +0 -5
  190. package/modern/ChartContainer/useChartContainerHooks.js +0 -24
  191. package/modern/ChartContainer/usePluginsMerge.js +0 -31
  192. package/modern/context/ColorProvider.js +0 -16
  193. package/modern/hooks/useColor.js +0 -9
  194. /package/{models/plugin.js → context/PluginProvider/ColorProcessor.types.js} +0 -0
  195. /package/esm/{models/plugin.js → context/PluginProvider/ColorProcessor.types.js} +0 -0
  196. /package/{modern/models/plugin.js → esm/context/PluginProvider/ExtremumGetter.types.js} +0 -0
@@ -12,6 +12,8 @@ import { useDrawingArea } from '../hooks/useDrawingArea';
12
12
  import { AxisRoot } from '../internals/components/AxisSharedComponents';
13
13
  import { ChartsText } from '../ChartsText';
14
14
  import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
15
+ import { isInfinity } from '../internals/isInfinity';
16
+ import { isBandScale } from '../internals/isBandScale';
15
17
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
16
18
  const useUtilityClasses = ownerState => {
17
19
  const {
@@ -78,7 +80,8 @@ function ChartsYAxis(inProps) {
78
80
  tickPlacement,
79
81
  tickLabelPlacement,
80
82
  tickInterval,
81
- tickLabelInterval
83
+ tickLabelInterval,
84
+ sx
82
85
  } = defaultizedProps;
83
86
  const theme = useTheme();
84
87
  const isRTL = theme.direction === 'rtl';
@@ -145,15 +148,17 @@ function ChartsYAxis(inProps) {
145
148
  ownerState: {}
146
149
  });
147
150
  const domain = yScale.domain();
148
- if (domain.length === 0 || domain[0] === domain[1]) {
149
- // Skip axis rendering if
150
- // - the data is empty (for band and point axis)
151
- // - No data is associated to the axis (other scale types)
151
+ const ordinalAxis = isBandScale(yScale);
152
+ // Skip axis rendering if no data is available
153
+ // - The domain is an empty array for band/point scales.
154
+ // - The domains contains Infinity for continuous scales.
155
+ if (ordinalAxis && domain.length === 0 || !ordinalAxis && domain.some(isInfinity)) {
152
156
  return null;
153
157
  }
154
158
  return /*#__PURE__*/_jsxs(AxisRoot, {
155
159
  transform: `translate(${position === 'right' ? left + width : left}, 0)`,
156
160
  className: classes.root,
161
+ sx: sx,
157
162
  children: [!disableLine && /*#__PURE__*/_jsx(Line, _extends({
158
163
  y1: top,
159
164
  y2: top + height,
@@ -253,6 +258,7 @@ process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
253
258
  * @default 'currentColor'
254
259
  */
255
260
  stroke: PropTypes.string,
261
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
256
262
  /**
257
263
  * The font size of the axis ticks text.
258
264
  * @default 12
@@ -42,7 +42,8 @@ const useAggregatedData = () => {
42
42
  yAxisKey = defaultYAxisId,
43
43
  stackedData,
44
44
  data,
45
- connectNulls
45
+ connectNulls,
46
+ baseline
46
47
  } = series[seriesId];
47
48
  const xAxisId = xAxisIdProp ?? xAxisKey;
48
49
  const yAxisId = yAxisIdProp ?? yAxisKey;
@@ -59,6 +60,15 @@ const useAggregatedData = () => {
59
60
  }
60
61
  }
61
62
  const areaPath = d3Area().x(d => xScale(d.x)).defined((_, i) => connectNulls || data[i] != null).y0(d => {
63
+ if (typeof baseline === 'number') {
64
+ return yScale(baseline);
65
+ }
66
+ if (baseline === 'max') {
67
+ return yScale.range()[1];
68
+ }
69
+ if (baseline === 'min') {
70
+ return yScale.range()[0];
71
+ }
62
72
  const value = d.y && yScale(d.y[0]);
63
73
  if (Number.isNaN(value)) {
64
74
  return yScale.range()[0];
@@ -274,6 +274,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
274
274
  slotProps: PropTypes.object,
275
275
  slots: PropTypes.object,
276
276
  stroke: PropTypes.string,
277
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
277
278
  tickFontSize: PropTypes.number,
278
279
  tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
279
280
  tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
@@ -326,6 +327,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
326
327
  slotProps: PropTypes.object,
327
328
  slots: PropTypes.object,
328
329
  stroke: PropTypes.string,
330
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
329
331
  tickFontSize: PropTypes.number,
330
332
  tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
331
333
  tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
@@ -7,16 +7,10 @@ export const getExtremumX = params => {
7
7
  return [minX, maxX];
8
8
  };
9
9
  function getSeriesExtremums(getValues, stackedData) {
10
- if (stackedData.length === 0) {
11
- return [null, null];
12
- }
13
10
  return stackedData.reduce((seriesAcc, stackedValue) => {
14
11
  const [base, value] = getValues(stackedValue);
15
- if (seriesAcc[0] === null) {
16
- return [Math.min(base, value), Math.max(base, value)];
17
- }
18
12
  return [Math.min(base, value, seriesAcc[0]), Math.max(base, value, seriesAcc[1])];
19
- }, getValues(stackedData[0]));
13
+ }, [Infinity, -Infinity]);
20
14
  }
21
15
  export const getExtremumY = params => {
22
16
  const {
@@ -33,16 +27,11 @@ export const getExtremumY = params => {
33
27
  stackedData
34
28
  } = series[seriesId];
35
29
  const isArea = area !== undefined;
36
- const getValues = isArea && axis.scaleType !== 'log' ? d => d : d => [d[1], d[1]]; // Since this series is not used to display an area, we do not consider the base (the d[0]).
37
30
 
31
+ // Since this series is not used to display an area, we do not consider the base (the d[0]).
32
+ const getValues = isArea && axis.scaleType !== 'log' && typeof series[seriesId].baseline !== 'string' ? d => d : d => [d[1], d[1]];
38
33
  const seriesExtremums = getSeriesExtremums(getValues, stackedData);
39
- if (acc[0] === null) {
40
- return seriesExtremums;
41
- }
42
- if (seriesExtremums[0] === null) {
43
- return acc;
44
- }
45
34
  const [seriesMin, seriesMax] = seriesExtremums;
46
35
  return [Math.min(seriesMin, acc[0]), Math.max(seriesMax, acc[1])];
47
- }, [null, null]);
36
+ }, [Infinity, -Infinity]);
48
37
  };
@@ -1,4 +1,4 @@
1
- export default function getColor(series, xAxis, yAxis) {
1
+ const getColor = (series, xAxis, yAxis) => {
2
2
  const yColorScale = yAxis?.colorScale;
3
3
  const xColorScale = xAxis?.colorScale;
4
4
  if (yColorScale) {
@@ -22,4 +22,5 @@ export default function getColor(series, xAxis, yAxis) {
22
22
  };
23
23
  }
24
24
  return () => series.color;
25
- }
25
+ };
26
+ export default getColor;
@@ -318,6 +318,7 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
318
318
  slotProps: PropTypes.object,
319
319
  slots: PropTypes.object,
320
320
  stroke: PropTypes.string,
321
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
321
322
  tickFontSize: PropTypes.number,
322
323
  tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
323
324
  tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
@@ -370,6 +371,7 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
370
371
  slotProps: PropTypes.object,
371
372
  slots: PropTypes.object,
372
373
  stroke: PropTypes.string,
374
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
373
375
  tickFontSize: PropTypes.number,
374
376
  tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
375
377
  tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
@@ -1,5 +1,6 @@
1
- export default function getColor(series) {
1
+ const getColor = series => {
2
2
  return dataIndex => {
3
3
  return series.data[dataIndex].color;
4
4
  };
5
- }
5
+ };
6
+ export default getColor;
@@ -130,6 +130,7 @@ process.env.NODE_ENV !== "production" ? ResponsiveChartContainer.propTypes = {
130
130
  slotProps: PropTypes.object,
131
131
  slots: PropTypes.object,
132
132
  stroke: PropTypes.string,
133
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
133
134
  tickFontSize: PropTypes.number,
134
135
  tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
135
136
  tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
@@ -182,6 +183,7 @@ process.env.NODE_ENV !== "production" ? ResponsiveChartContainer.propTypes = {
182
183
  slotProps: PropTypes.object,
183
184
  slots: PropTypes.object,
184
185
  stroke: PropTypes.string,
186
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
185
187
  tickFontSize: PropTypes.number,
186
188
  tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
187
189
  tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
@@ -255,6 +255,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
255
255
  slotProps: PropTypes.object,
256
256
  slots: PropTypes.object,
257
257
  stroke: PropTypes.string,
258
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
258
259
  tickFontSize: PropTypes.number,
259
260
  tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
260
261
  tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
@@ -307,6 +308,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
307
308
  slotProps: PropTypes.object,
308
309
  slots: PropTypes.object,
309
310
  stroke: PropTypes.string,
311
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
310
312
  tickFontSize: PropTypes.number,
311
313
  tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
312
314
  tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
@@ -1,10 +1,4 @@
1
1
  const mergeMinMax = (acc, val) => {
2
- if (acc[0] === null || acc[1] === null) {
3
- return val;
4
- }
5
- if (val[0] === null || val[1] === null) {
6
- return acc;
7
- }
8
2
  return [Math.min(acc[0], val[0]), Math.max(acc[1], val[1])];
9
3
  };
10
4
  export const getExtremumX = params => {
@@ -20,11 +14,10 @@ export const getExtremumX = params => {
20
14
  const seriesMinMax = series[seriesId].data.reduce((accSeries, {
21
15
  x
22
16
  }) => {
23
- const val = [x, x];
24
- return mergeMinMax(accSeries, val);
25
- }, [null, null]);
17
+ return mergeMinMax(accSeries, [x, x]);
18
+ }, [Infinity, -Infinity]);
26
19
  return mergeMinMax(acc, seriesMinMax);
27
- }, [null, null]);
20
+ }, [Infinity, -Infinity]);
28
21
  };
29
22
  export const getExtremumY = params => {
30
23
  const {
@@ -39,9 +32,8 @@ export const getExtremumY = params => {
39
32
  const seriesMinMax = series[seriesId].data.reduce((accSeries, {
40
33
  y
41
34
  }) => {
42
- const val = [y, y];
43
- return mergeMinMax(accSeries, val);
44
- }, [null, null]);
35
+ return mergeMinMax(accSeries, [y, y]);
36
+ }, [Infinity, -Infinity]);
45
37
  return mergeMinMax(acc, seriesMinMax);
46
- }, [null, null]);
38
+ }, [Infinity, -Infinity]);
47
39
  };
@@ -1,4 +1,4 @@
1
- export default function getColor(series, xAxis, yAxis, zAxis) {
1
+ const getColor = (series, xAxis, yAxis, zAxis) => {
2
2
  const zColorScale = zAxis?.colorScale;
3
3
  const yColorScale = yAxis?.colorScale;
4
4
  const xColorScale = xAxis?.colorScale;
@@ -39,4 +39,5 @@ export default function getColor(series, xAxis, yAxis, zAxis) {
39
39
  };
40
40
  }
41
41
  return () => series.color;
42
- }
42
+ };
43
+ export default getColor;
@@ -279,6 +279,7 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
279
279
  slotProps: PropTypes.object,
280
280
  slots: PropTypes.object,
281
281
  stroke: PropTypes.string,
282
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
282
283
  tickFontSize: PropTypes.number,
283
284
  tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
284
285
  tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
@@ -330,6 +331,7 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
330
331
  slotProps: PropTypes.object,
331
332
  slots: PropTypes.object,
332
333
  stroke: PropTypes.string,
334
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
333
335
  tickFontSize: PropTypes.number,
334
336
  tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
335
337
  tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
@@ -3,18 +3,20 @@ import { useDrawingArea } from '../../hooks/useDrawingArea';
3
3
  import { useSeries } from '../../hooks/useSeries';
4
4
  import { CartesianContext } from './CartesianContext';
5
5
  import { computeValue } from './computeValue';
6
+ import { useXExtremumGetter } from '../PluginProvider/useXExtremumGetter';
7
+ import { useYExtremumGetter } from '../PluginProvider';
6
8
  import { jsx as _jsx } from "react/jsx-runtime";
7
- function CartesianContextProvider(props) {
9
+ function CartesianProvider(props) {
8
10
  const {
9
11
  xAxis,
10
12
  yAxis,
11
13
  dataset,
12
- xExtremumGetters,
13
- yExtremumGetters,
14
14
  children
15
15
  } = props;
16
16
  const formattedSeries = useSeries();
17
17
  const drawingArea = useDrawingArea();
18
+ const xExtremumGetters = useXExtremumGetter();
19
+ const yExtremumGetters = useYExtremumGetter();
18
20
  const xValues = React.useMemo(() => computeValue({
19
21
  drawingArea,
20
22
  formattedSeries,
@@ -45,4 +47,4 @@ function CartesianContextProvider(props) {
45
47
  children: children
46
48
  });
47
49
  }
48
- export { CartesianContextProvider };
50
+ export { CartesianProvider };
@@ -5,17 +5,10 @@ const axisExtremumCallback = (acc, chartType, axis, getters, isDefaultAxis, form
5
5
  series,
6
6
  axis,
7
7
  isDefaultAxis
8
- }) ?? [null, null];
9
- const [minData, maxData] = acc;
10
- if (minData === null || maxData === null) {
11
- return [minChartTypeData, maxChartTypeData];
12
- }
13
- if (minChartTypeData === null || maxChartTypeData === null) {
14
- return [minData, maxData];
15
- }
16
- return [Math.min(minChartTypeData, minData), Math.max(maxChartTypeData, maxData)];
8
+ }) ?? [Infinity, -Infinity];
9
+ return [Math.min(minChartTypeData, acc[0]), Math.max(maxChartTypeData, acc[1])];
17
10
  };
18
11
  export const getAxisExtremum = (axis, getters, isDefaultAxis, formattedSeries) => {
19
12
  const charTypes = Object.keys(getters);
20
- return charTypes.reduce((acc, charType) => axisExtremumCallback(acc, charType, axis, getters, isDefaultAxis, formattedSeries), [null, null]);
13
+ return charTypes.reduce((acc, charType) => axisExtremumCallback(acc, charType, axis, getters, isDefaultAxis, formattedSeries), [Infinity, -Infinity]);
21
14
  };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ import * as React from 'react';
2
+ export const PluginContext = /*#__PURE__*/React.createContext({
3
+ isInitialized: false,
4
+ data: {
5
+ colorProcessors: {},
6
+ seriesFormatters: {},
7
+ xExtremumGetters: {},
8
+ yExtremumGetters: {}
9
+ }
10
+ });
11
+ if (process.env.NODE_ENV !== 'production') {
12
+ PluginContext.displayName = 'PluginContext';
13
+ }
@@ -0,0 +1,19 @@
1
+ import * as React from 'react';
2
+ import { PluginContext } from './PluginContext';
3
+ import { mergePlugins } from './mergePlugins';
4
+ import { jsx as _jsx } from "react/jsx-runtime";
5
+ function PluginProvider(props) {
6
+ const {
7
+ children,
8
+ plugins
9
+ } = props;
10
+ const formattedSeries = React.useMemo(() => ({
11
+ isInitialized: true,
12
+ data: mergePlugins(plugins)
13
+ }), [plugins]);
14
+ return /*#__PURE__*/_jsx(PluginContext.Provider, {
15
+ value: formattedSeries,
16
+ children: children
17
+ });
18
+ }
19
+ export { PluginProvider };
@@ -0,0 +1,10 @@
1
+ export * from './PluginProvider';
2
+ export * from './Plugin.types';
3
+ export * from './PluginContext';
4
+ export * from './ColorProcessor.types';
5
+ export * from './SeriesFormatter.types';
6
+ export * from './ExtremumGetter.types';
7
+ export * from './useColorProcessor';
8
+ export * from './useSeriesFormatter';
9
+ export * from './useXExtremumGetter';
10
+ export * from './useYExtremumGetter';
@@ -0,0 +1,30 @@
1
+ import { plugin as barPlugin } from '../../BarChart/plugin';
2
+ import { plugin as scatterPlugin } from '../../ScatterChart/plugin';
3
+ import { plugin as linePlugin } from '../../LineChart/plugin';
4
+ import { plugin as piePlugin } from '../../PieChart/plugin';
5
+ export const defaultPlugins = [barPlugin, scatterPlugin, linePlugin, piePlugin];
6
+ export function mergePlugins(plugins) {
7
+ const defaultizedPlugins = plugins ?? defaultPlugins;
8
+ const seriesFormatters = {};
9
+ const colorProcessors = {};
10
+ const xExtremumGetters = {};
11
+ const yExtremumGetters = {};
12
+ for (let i = 0; i < defaultizedPlugins.length; i += 1) {
13
+ const plugin = defaultizedPlugins[i];
14
+ const seriesType = plugin.seriesType;
15
+ seriesFormatters[seriesType] = plugin.seriesFormatter;
16
+ colorProcessors[seriesType] = plugin.colorProcessor;
17
+ if (plugin.xExtremumGetter) {
18
+ xExtremumGetters[seriesType] = plugin.xExtremumGetter;
19
+ }
20
+ if (plugin.yExtremumGetter) {
21
+ yExtremumGetters[seriesType] = plugin.yExtremumGetter;
22
+ }
23
+ }
24
+ return {
25
+ seriesFormatters,
26
+ colorProcessors,
27
+ xExtremumGetters,
28
+ yExtremumGetters
29
+ };
30
+ }
@@ -0,0 +1,15 @@
1
+ import * as React from 'react';
2
+ import { PluginContext } from './PluginContext';
3
+ export function useColorProcessor(seriesType) {
4
+ const {
5
+ isInitialized,
6
+ data
7
+ } = React.useContext(PluginContext);
8
+ if (!isInitialized) {
9
+ throw new Error(['MUI X: Could not find the plugin context.', 'It looks like you rendered your component outside of a ChartsContainer parent component.'].join('\n'));
10
+ }
11
+ if (!seriesType) {
12
+ return data.colorProcessors;
13
+ }
14
+ return data.colorProcessors[seriesType];
15
+ }
@@ -0,0 +1,15 @@
1
+ import * as React from 'react';
2
+ import { PluginContext } from './PluginContext';
3
+ export function useSeriesFormatter(seriesType) {
4
+ const {
5
+ isInitialized,
6
+ data
7
+ } = React.useContext(PluginContext);
8
+ if (!isInitialized) {
9
+ throw new Error(['MUI X: Could not find the plugin context.', 'It looks like you rendered your component outside of a ChartsContainer parent component.'].join('\n'));
10
+ }
11
+ if (!seriesType) {
12
+ return data.seriesFormatters;
13
+ }
14
+ return data.seriesFormatters[seriesType];
15
+ }
@@ -0,0 +1,15 @@
1
+ import * as React from 'react';
2
+ import { PluginContext } from './PluginContext';
3
+ export function useXExtremumGetter(seriesType) {
4
+ const {
5
+ isInitialized,
6
+ data
7
+ } = React.useContext(PluginContext);
8
+ if (!isInitialized) {
9
+ throw new Error(['MUI X: Could not find the plugin context.', 'It looks like you rendered your component outside of a ChartsContainer parent component.'].join('\n'));
10
+ }
11
+ if (!seriesType) {
12
+ return data.xExtremumGetters;
13
+ }
14
+ return data.xExtremumGetters[seriesType];
15
+ }
@@ -0,0 +1,15 @@
1
+ import * as React from 'react';
2
+ import { PluginContext } from './PluginContext';
3
+ export function useYExtremumGetter(seriesType) {
4
+ const {
5
+ isInitialized,
6
+ data
7
+ } = React.useContext(PluginContext);
8
+ if (!isInitialized) {
9
+ throw new Error(['MUI X: Could not find the plugin context.', 'It looks like you rendered your component outside of a ChartsContainer parent component.'].join('\n'));
10
+ }
11
+ if (!seriesType) {
12
+ return data.yExtremumGetters;
13
+ }
14
+ return data.yExtremumGetters[seriesType];
15
+ }
@@ -3,15 +3,16 @@ import { useTheme } from '@mui/material/styles';
3
3
  import { blueberryTwilightPalette } from '../../colorPalettes';
4
4
  import { SeriesContext } from './SeriesContext';
5
5
  import { preprocessSeries } from './processSeries';
6
+ import { useSeriesFormatter } from '../PluginProvider';
6
7
  import { jsx as _jsx } from "react/jsx-runtime";
7
8
  function SeriesProvider(props) {
8
9
  const {
9
10
  series,
10
11
  dataset,
11
12
  colors = blueberryTwilightPalette,
12
- seriesFormatters,
13
13
  children
14
14
  } = props;
15
+ const seriesFormatters = useSeriesFormatter();
15
16
  const theme = useTheme();
16
17
  const formattedSeries = React.useMemo(() => ({
17
18
  isInitialized: true,
@@ -1,5 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { isBandScale } from '../internals/isBandScale';
3
+ import { isInfinity } from '../internals/isInfinity';
3
4
  export function getTickNumber(params) {
4
5
  const {
5
6
  tickMaxStep,
@@ -60,8 +61,10 @@ export function useTicks(options) {
60
61
  labelOffset: 0
61
62
  }));
62
63
  }
63
- if (scale.domain().length === 0 || scale.domain()[0] === scale.domain()[1]) {
64
- // The axis should not be visible, so ticks should also be hidden.
64
+ const domain = scale.domain();
65
+ // Skip axis rendering if no data is available
66
+ // - The domains contains Infinity for continuous scales.
67
+ if (domain.some(isInfinity)) {
65
68
  return [];
66
69
  }
67
70
  const ticks = typeof tickInterval === 'object' ? tickInterval : scale.ticks(tickNumber);
package/modern/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v7.12.0
2
+ * @mui/x-charts v7.13.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -25,10 +25,10 @@ export * from './isDefined';
25
25
 
26
26
  export * from '../context/CartesianProvider';
27
27
  export * from '../context/DrawingProvider';
28
- export * from '../context/ColorProvider';
29
28
  export * from '../context/InteractionProvider';
30
29
  export * from '../context/SeriesProvider';
31
30
  export * from '../context/ZAxisContextProvider';
31
+ export * from '../context/PluginProvider';
32
32
  // series configuration
33
33
  export * from '../models/seriesType/config';
34
34
  export * from '../models/seriesType/common';
@@ -0,0 +1,3 @@
1
+ export function isInfinity(v) {
2
+ return typeof v === 'number' && !Number.isFinite(v);
3
+ }
@@ -1,5 +1,4 @@
1
1
  export * from './seriesType';
2
2
  export * from './layout';
3
3
  export * from './stacking';
4
- export * from './plugin';
5
4
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-charts",
3
- "version": "7.12.0",
3
+ "version": "7.13.0",
4
4
  "description": "The community edition of the Charts components (MUI X).",
5
5
  "author": "MUI Team",
6
6
  "main": "./index.js",
@@ -36,7 +36,7 @@
36
36
  "@react-spring/web": "^9.7.4",
37
37
  "clsx": "^2.1.1",
38
38
  "prop-types": "^15.8.1",
39
- "@mui/x-charts-vendor": "7.12.0"
39
+ "@mui/x-charts-vendor": "7.13.0"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "@emotion/react": "^11.9.0",
@@ -1,2 +0,0 @@
1
- import { ChartsPluginType } from '../models';
2
- export declare const defaultPlugins: ChartsPluginType<'bar' | 'scatter' | 'line' | 'pie'>[];
@@ -1,11 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.defaultPlugins = void 0;
7
- var _plugin = require("../BarChart/plugin");
8
- var _plugin2 = require("../ScatterChart/plugin");
9
- var _plugin3 = require("../LineChart/plugin");
10
- var _plugin4 = require("../PieChart/plugin");
11
- const defaultPlugins = exports.defaultPlugins = [_plugin.plugin, _plugin2.plugin, _plugin3.plugin, _plugin4.plugin];
@@ -1,11 +0,0 @@
1
- import * as React from 'react';
2
- import { ChartsPluginType } from '../models';
3
- import { ChartSeriesType } from '../models/seriesType/config';
4
- export declare const useChartContainerHooks: (ref: React.ForwardedRef<unknown> | null, plugins?: ChartsPluginType<ChartSeriesType>[]) => {
5
- svgRef: React.RefObject<SVGSVGElement>;
6
- chartSurfaceRef: ((instance: unknown) => void | React.DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES[keyof React.DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES]) | null;
7
- xExtremumGetters: import("../models").ExtremumGettersConfig<keyof import("../models/seriesType/config").ChartsSeriesConfig>;
8
- yExtremumGetters: import("../models").ExtremumGettersConfig<keyof import("../models/seriesType/config").ChartsSeriesConfig>;
9
- seriesFormatters: import("../internals").SeriesFormatterConfig<keyof import("../models/seriesType/config").ChartsSeriesConfig>;
10
- colorProcessors: import("../models").ColorProcessorsConfig<keyof import("../models/seriesType/config").ChartsSeriesConfig>;
11
- };
@@ -1,34 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.useChartContainerHooks = void 0;
8
- var _useForkRef = _interopRequireDefault(require("@mui/utils/useForkRef"));
9
- var React = _interopRequireWildcard(require("react"));
10
- var _usePluginsMerge = require("./usePluginsMerge");
11
- var _useReducedMotion = require("../hooks/useReducedMotion");
12
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
13
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14
- const useChartContainerHooks = (ref, plugins) => {
15
- const svgRef = React.useRef(null);
16
- const chartSurfaceRef = (0, _useForkRef.default)(ref, svgRef);
17
- const {
18
- xExtremumGetters,
19
- yExtremumGetters,
20
- seriesFormatters,
21
- colorProcessors
22
- } = (0, _usePluginsMerge.usePluginsMerge)(plugins);
23
- (0, _useReducedMotion.useReducedMotion)(); // a11y reduce motion (see: https://react-spring.dev/docs/utilities/use-reduced-motion)
24
-
25
- return {
26
- svgRef,
27
- chartSurfaceRef,
28
- xExtremumGetters,
29
- yExtremumGetters,
30
- seriesFormatters,
31
- colorProcessors
32
- };
33
- };
34
- exports.useChartContainerHooks = useChartContainerHooks;