@mui/x-charts 7.1.1 → 7.3.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 (192) hide show
  1. package/BarChart/BarChart.js +32 -2
  2. package/BarChart/BarPlot.js +12 -5
  3. package/BarChart/extremums.js +1 -1
  4. package/BarChart/getColor.d.ts +3 -0
  5. package/BarChart/getColor.js +33 -0
  6. package/CHANGELOG.md +211 -0
  7. package/ChartContainer/ChartContainer.js +35 -4
  8. package/ChartsAxis/ChartsAxis.js +4 -4
  9. package/ChartsClipPath/ChartsClipPath.js +2 -2
  10. package/ChartsLegend/ChartsLegend.js +2 -2
  11. package/ChartsTooltip/ChartsAxisTooltipContent.d.ts +4 -1
  12. package/ChartsTooltip/ChartsAxisTooltipContent.js +7 -2
  13. package/ChartsTooltip/ChartsItemTooltipContent.d.ts +6 -0
  14. package/ChartsTooltip/ChartsItemTooltipContent.js +15 -1
  15. package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +6 -3
  16. package/ChartsTooltip/DefaultChartsItemTooltipContent.js +13 -4
  17. package/ChartsTooltip/utils.d.ts +5 -1
  18. package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +6 -6
  19. package/ChartsXAxis/ChartsXAxis.js +7 -7
  20. package/ChartsYAxis/ChartsYAxis.js +9 -6
  21. package/Gauge/GaugeProvider.js +5 -5
  22. package/LineChart/AnimatedArea.js +6 -5
  23. package/LineChart/AnimatedLine.js +7 -5
  24. package/LineChart/AreaElement.d.ts +1 -0
  25. package/LineChart/AreaElement.js +4 -1
  26. package/LineChart/AreaPlot.js +7 -1
  27. package/LineChart/LineChart.js +32 -2
  28. package/LineChart/LineElement.d.ts +1 -0
  29. package/LineChart/LineElement.js +4 -1
  30. package/LineChart/LineHighlightPlot.js +4 -1
  31. package/LineChart/LinePlot.js +7 -1
  32. package/LineChart/MarkPlot.js +5 -5
  33. package/LineChart/getColor.d.ts +3 -0
  34. package/LineChart/getColor.js +31 -0
  35. package/PieChart/PieChart.js +32 -2
  36. package/PieChart/PiePlot.js +26 -6
  37. package/PieChart/formatter.js +4 -2
  38. package/PieChart/getColor.d.ts +2 -0
  39. package/PieChart/getColor.js +11 -0
  40. package/PieChart/getPieCoordinates.d.ts +7 -0
  41. package/PieChart/getPieCoordinates.js +25 -0
  42. package/PieChart/index.d.ts +1 -0
  43. package/PieChart/index.js +11 -0
  44. package/ResponsiveChartContainer/ResponsiveChartContainer.js +32 -2
  45. package/ScatterChart/Scatter.d.ts +1 -0
  46. package/ScatterChart/Scatter.js +6 -3
  47. package/ScatterChart/ScatterChart.js +32 -2
  48. package/ScatterChart/ScatterPlot.js +3 -0
  49. package/ScatterChart/getColor.d.ts +3 -0
  50. package/ScatterChart/getColor.js +31 -0
  51. package/SparkLineChart/SparkLineChart.js +15 -0
  52. package/context/CartesianContextProvider.d.ts +2 -2
  53. package/context/CartesianContextProvider.js +23 -8
  54. package/esm/BarChart/BarChart.js +32 -2
  55. package/esm/BarChart/BarPlot.js +13 -5
  56. package/esm/BarChart/extremums.js +1 -1
  57. package/esm/BarChart/getColor.js +27 -0
  58. package/esm/ChartContainer/ChartContainer.js +36 -4
  59. package/esm/ChartsAxis/ChartsAxis.js +4 -4
  60. package/esm/ChartsClipPath/ChartsClipPath.js +2 -2
  61. package/esm/ChartsLegend/ChartsLegend.js +2 -2
  62. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +7 -2
  63. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +15 -1
  64. package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +6 -3
  65. package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +13 -4
  66. package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +6 -6
  67. package/esm/ChartsXAxis/ChartsXAxis.js +7 -7
  68. package/esm/ChartsYAxis/ChartsYAxis.js +9 -6
  69. package/esm/Gauge/GaugeProvider.js +5 -5
  70. package/esm/LineChart/AnimatedArea.js +6 -5
  71. package/esm/LineChart/AnimatedLine.js +7 -5
  72. package/esm/LineChart/AreaElement.js +4 -1
  73. package/esm/LineChart/AreaPlot.js +7 -1
  74. package/esm/LineChart/LineChart.js +32 -2
  75. package/esm/LineChart/LineElement.js +4 -1
  76. package/esm/LineChart/LineHighlightPlot.js +4 -1
  77. package/esm/LineChart/LinePlot.js +7 -1
  78. package/esm/LineChart/MarkPlot.js +5 -5
  79. package/esm/LineChart/getColor.js +25 -0
  80. package/esm/PieChart/PieChart.js +32 -2
  81. package/esm/PieChart/PiePlot.js +26 -6
  82. package/esm/PieChart/formatter.js +4 -2
  83. package/esm/PieChart/getColor.js +5 -0
  84. package/esm/PieChart/getPieCoordinates.js +19 -0
  85. package/esm/PieChart/index.js +2 -1
  86. package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +32 -2
  87. package/esm/ScatterChart/Scatter.js +6 -3
  88. package/esm/ScatterChart/ScatterChart.js +32 -2
  89. package/esm/ScatterChart/ScatterPlot.js +3 -0
  90. package/esm/ScatterChart/getColor.js +25 -0
  91. package/esm/SparkLineChart/SparkLineChart.js +15 -0
  92. package/esm/context/CartesianContextProvider.js +23 -8
  93. package/esm/hooks/index.js +4 -1
  94. package/esm/hooks/useAxisEvents.js +7 -6
  95. package/esm/hooks/useChartId.js +8 -0
  96. package/esm/hooks/useSeries.js +64 -0
  97. package/esm/hooks/useSvgRef.js +9 -0
  98. package/esm/internals/colorGetter.js +22 -0
  99. package/esm/internals/colorScale.js +16 -0
  100. package/esm/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +96 -0
  101. package/esm/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +55 -0
  102. package/esm/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +41 -0
  103. package/esm/internals/components/ChartsAxesGradients/index.js +1 -0
  104. package/esm/models/colorMapping.js +1 -0
  105. package/esm/models/seriesType/index.js +6 -1
  106. package/hooks/index.d.ts +3 -0
  107. package/hooks/index.js +65 -1
  108. package/hooks/useAxisEvents.js +7 -6
  109. package/hooks/useChartId.d.ts +1 -0
  110. package/hooks/useChartId.js +16 -0
  111. package/hooks/useSeries.d.ts +45 -0
  112. package/hooks/useSeries.js +75 -0
  113. package/hooks/useSvgRef.d.ts +2 -0
  114. package/hooks/useSvgRef.js +17 -0
  115. package/hooks/useTicks.d.ts +1 -1
  116. package/index.js +1 -1
  117. package/internals/colorGetter.d.ts +5 -0
  118. package/internals/colorGetter.js +29 -0
  119. package/internals/colorScale.d.ts +5 -0
  120. package/internals/colorScale.js +24 -0
  121. package/internals/components/ChartsAxesGradients/ChartsAxesGradients.d.ts +3 -0
  122. package/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +105 -0
  123. package/internals/components/ChartsAxesGradients/ChartsContinuousGradient.d.ts +13 -0
  124. package/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +63 -0
  125. package/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.d.ts +12 -0
  126. package/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +48 -0
  127. package/internals/components/ChartsAxesGradients/index.d.ts +1 -0
  128. package/internals/components/ChartsAxesGradients/index.js +16 -0
  129. package/internals/defaultizeColor.d.ts +4 -4
  130. package/internals/defaultizeValueFormatter.d.ts +5 -5
  131. package/internals/getScale.d.ts +2 -2
  132. package/models/axis.d.ts +44 -4
  133. package/models/colorMapping.d.ts +45 -0
  134. package/models/colorMapping.js +5 -0
  135. package/models/index.d.ts +1 -1
  136. package/models/seriesType/common.d.ts +10 -2
  137. package/models/seriesType/index.d.ts +2 -0
  138. package/models/seriesType/index.js +17 -1
  139. package/modern/BarChart/BarChart.js +32 -2
  140. package/modern/BarChart/BarPlot.js +13 -5
  141. package/modern/BarChart/extremums.js +1 -1
  142. package/modern/BarChart/getColor.js +27 -0
  143. package/modern/ChartContainer/ChartContainer.js +36 -4
  144. package/modern/ChartsAxis/ChartsAxis.js +4 -4
  145. package/modern/ChartsClipPath/ChartsClipPath.js +2 -2
  146. package/modern/ChartsLegend/ChartsLegend.js +2 -2
  147. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +7 -2
  148. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +15 -1
  149. package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +6 -3
  150. package/modern/ChartsTooltip/DefaultChartsItemTooltipContent.js +13 -4
  151. package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +6 -6
  152. package/modern/ChartsXAxis/ChartsXAxis.js +7 -7
  153. package/modern/ChartsYAxis/ChartsYAxis.js +9 -6
  154. package/modern/Gauge/GaugeProvider.js +5 -5
  155. package/modern/LineChart/AnimatedArea.js +6 -5
  156. package/modern/LineChart/AnimatedLine.js +7 -5
  157. package/modern/LineChart/AreaElement.js +4 -1
  158. package/modern/LineChart/AreaPlot.js +7 -1
  159. package/modern/LineChart/LineChart.js +32 -2
  160. package/modern/LineChart/LineElement.js +4 -1
  161. package/modern/LineChart/LineHighlightPlot.js +4 -1
  162. package/modern/LineChart/LinePlot.js +7 -1
  163. package/modern/LineChart/MarkPlot.js +5 -5
  164. package/modern/LineChart/getColor.js +25 -0
  165. package/modern/PieChart/PieChart.js +32 -2
  166. package/modern/PieChart/PiePlot.js +26 -6
  167. package/modern/PieChart/formatter.js +4 -2
  168. package/modern/PieChart/getColor.js +5 -0
  169. package/modern/PieChart/getPieCoordinates.js +19 -0
  170. package/modern/PieChart/index.js +2 -1
  171. package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +32 -2
  172. package/modern/ScatterChart/Scatter.js +6 -3
  173. package/modern/ScatterChart/ScatterChart.js +32 -2
  174. package/modern/ScatterChart/ScatterPlot.js +3 -0
  175. package/modern/ScatterChart/getColor.js +25 -0
  176. package/modern/SparkLineChart/SparkLineChart.js +15 -0
  177. package/modern/context/CartesianContextProvider.js +23 -8
  178. package/modern/hooks/index.js +4 -1
  179. package/modern/hooks/useAxisEvents.js +7 -6
  180. package/modern/hooks/useChartId.js +8 -0
  181. package/modern/hooks/useSeries.js +64 -0
  182. package/modern/hooks/useSvgRef.js +9 -0
  183. package/modern/index.js +1 -1
  184. package/modern/internals/colorGetter.js +22 -0
  185. package/modern/internals/colorScale.js +16 -0
  186. package/modern/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +96 -0
  187. package/modern/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +55 -0
  188. package/modern/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +41 -0
  189. package/modern/internals/components/ChartsAxesGradients/index.js +1 -0
  190. package/modern/models/colorMapping.js +1 -0
  191. package/modern/models/seriesType/index.js +6 -1
  192. package/package.json +1 -1
@@ -366,11 +366,26 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
366
366
  width: PropTypes.number,
367
367
  /**
368
368
  * The configuration of the x-axes.
369
- * If not provided, a default axis config is used with id set to `DEFAULT_X_AXIS_KEY`.
369
+ * If not provided, a default axis config is used.
370
370
  */
371
371
  xAxis: PropTypes.arrayOf(PropTypes.shape({
372
372
  axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
373
373
  classes: PropTypes.object,
374
+ colorMap: PropTypes.oneOfType([PropTypes.shape({
375
+ color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
376
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
377
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
378
+ type: PropTypes.oneOf(['continuous']).isRequired
379
+ }), PropTypes.shape({
380
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
381
+ thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
382
+ type: PropTypes.oneOf(['piecewise']).isRequired
383
+ }), PropTypes.shape({
384
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
385
+ type: PropTypes.oneOf(['ordinal']).isRequired,
386
+ unknownColor: PropTypes.string,
387
+ values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
388
+ })]),
374
389
  data: PropTypes.array,
375
390
  dataKey: PropTypes.string,
376
391
  disableLine: PropTypes.bool,
@@ -403,11 +418,26 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
403
418
  })),
404
419
  /**
405
420
  * The configuration of the y-axes.
406
- * If not provided, a default axis config is used with id set to `DEFAULT_Y_AXIS_KEY`.
421
+ * If not provided, a default axis config is used.
407
422
  */
408
423
  yAxis: PropTypes.arrayOf(PropTypes.shape({
409
424
  axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
410
425
  classes: PropTypes.object,
426
+ colorMap: PropTypes.oneOfType([PropTypes.shape({
427
+ color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
428
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
429
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
430
+ type: PropTypes.oneOf(['continuous']).isRequired
431
+ }), PropTypes.shape({
432
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
433
+ thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
434
+ type: PropTypes.oneOf(['piecewise']).isRequired
435
+ }), PropTypes.shape({
436
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
437
+ type: PropTypes.oneOf(['ordinal']).isRequired,
438
+ unknownColor: PropTypes.string,
439
+ values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
440
+ })]),
411
441
  data: PropTypes.array,
412
442
  dataKey: PropTypes.string,
413
443
  disableLine: PropTypes.bool,
@@ -7,9 +7,10 @@ import { useTransition } from '@react-spring/web';
7
7
  import { SeriesContext } from '../context/SeriesContextProvider';
8
8
  import { CartesianContext } from '../context/CartesianContextProvider';
9
9
  import { BarElement } from './BarElement';
10
- import { isBandScaleConfig } from '../models/axis';
10
+ import { isBandScaleConfig, isPointScaleConfig } from '../models/axis';
11
11
  import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
12
- import { jsx as _jsx } from "react/jsx-runtime";
12
+ import getColor from './getColor';
13
+
13
14
  /**
14
15
  * Solution of the equations
15
16
  * W = barWidth * N + offset * (N-1)
@@ -19,6 +20,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
19
20
  * @param gapRatio The ratio of the gap between bars over the bar width.
20
21
  * @returns The bar width and the offset between bars.
21
22
  */
23
+ import { jsx as _jsx } from "react/jsx-runtime";
22
24
  function getBandSize({
23
25
  bandWidth: W,
24
26
  numberOfGroups: N,
@@ -74,6 +76,9 @@ const useAggregatedData = () => {
74
76
  throw new Error(`MUI X Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} shoud have data property.`);
75
77
  }
76
78
  baseScaleConfig = xAxisConfig;
79
+ if (isBandScaleConfig(yAxisConfig) || isPointScaleConfig(yAxisConfig)) {
80
+ throw new Error(`MUI X Charts: ${yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} shoud be a continuous type to display the bar series of id "${seriesId}".`);
81
+ }
77
82
  } else {
78
83
  if (!isBandScaleConfig(yAxisConfig)) {
79
84
  throw new Error(`MUI X Charts: ${yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} shoud be of type "band" to display the bar series of id "${seriesId}".`);
@@ -82,9 +87,13 @@ const useAggregatedData = () => {
82
87
  throw new Error(`MUI X Charts: ${yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} shoud have data property.`);
83
88
  }
84
89
  baseScaleConfig = yAxisConfig;
90
+ if (isBandScaleConfig(xAxisConfig) || isPointScaleConfig(xAxisConfig)) {
91
+ throw new Error(`MUI X Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} shoud be a continuous type to display the bar series of id "${seriesId}".`);
92
+ }
85
93
  }
86
94
  const xScale = xAxisConfig.scale;
87
95
  const yScale = yAxisConfig.scale;
96
+ const colorGetter = getColor(series[seriesId], xAxis[xAxisKey], yAxis[yAxisKey]);
88
97
  const bandWidth = baseScaleConfig.scale.bandwidth();
89
98
  const {
90
99
  barWidth,
@@ -96,8 +105,7 @@ const useAggregatedData = () => {
96
105
  });
97
106
  const barOffset = groupIndex * (barWidth + offset);
98
107
  const {
99
- stackedData,
100
- color
108
+ stackedData
101
109
  } = series[seriesId];
102
110
  return stackedData.map((values, dataIndex) => {
103
111
  const valueCoordinates = values.map(v => verticalLayout ? yScale(v) : xScale(v));
@@ -113,7 +121,7 @@ const useAggregatedData = () => {
113
121
  yOrigin: yScale(0),
114
122
  height: verticalLayout ? maxValueCoord - minValueCoord : barWidth,
115
123
  width: verticalLayout ? barWidth : maxValueCoord - minValueCoord,
116
- color,
124
+ color: colorGetter(dataIndex),
117
125
  highlightScope: series[seriesId].highlightScope
118
126
  };
119
127
  });
@@ -13,7 +13,7 @@ const getValueExtremum = params => {
13
13
  isDefaultAxis
14
14
  } = params;
15
15
  return Object.keys(series).filter(seriesId => series[seriesId].yAxisKey === axis.id || isDefaultAxis && series[seriesId].yAxisKey === undefined).reduce((acc, seriesId) => {
16
- const [seriesMin, seriesMax] = series[seriesId].stackedData.reduce((seriesAcc, values) => [Math.min(...values, ...(seriesAcc[0] === null ? [] : [seriesAcc[0]])), Math.max(...values, ...(seriesAcc[1] === null ? [] : [seriesAcc[1]]))], series[seriesId].stackedData[0]);
16
+ const [seriesMin, seriesMax] = series[seriesId].stackedData?.reduce((seriesAcc, values) => [Math.min(...values, ...(seriesAcc[0] === null ? [] : [seriesAcc[0]])), Math.max(...values, ...(seriesAcc[1] === null ? [] : [seriesAcc[1]]))], series[seriesId].stackedData[0]) ?? [null, null];
17
17
  return [acc[0] === null ? seriesMin : Math.min(seriesMin, acc[0]), acc[1] === null ? seriesMax : Math.max(seriesMax, acc[1])];
18
18
  }, [null, null]);
19
19
  };
@@ -0,0 +1,27 @@
1
+ export default function getColor(series, xAxis, yAxis) {
2
+ const verticalLayout = series.layout === 'vertical';
3
+ const bandColorScale = verticalLayout ? xAxis.colorScale : yAxis.colorScale;
4
+ const valueColorScale = verticalLayout ? yAxis.colorScale : xAxis.colorScale;
5
+ const bandValues = verticalLayout ? xAxis.data : yAxis.data;
6
+ if (valueColorScale) {
7
+ return dataIndex => {
8
+ const value = series.data[dataIndex];
9
+ const color = value === null ? series.color : valueColorScale(value);
10
+ if (color === null) {
11
+ return series.color;
12
+ }
13
+ return color;
14
+ };
15
+ }
16
+ if (bandColorScale) {
17
+ return dataIndex => {
18
+ const value = bandValues[dataIndex];
19
+ const color = value === null ? series.color : bandColorScale(value);
20
+ if (color === null) {
21
+ return series.color;
22
+ }
23
+ return color;
24
+ };
25
+ }
26
+ return () => series.color;
27
+ }
@@ -8,7 +8,9 @@ import { useReducedMotion } from '../hooks/useReducedMotion';
8
8
  import { ChartsSurface } from '../ChartsSurface';
9
9
  import { CartesianContextProvider } from '../context/CartesianContextProvider';
10
10
  import { HighlightProvider } from '../context/HighlightProvider';
11
+ import { ChartsAxesGradients } from '../internals/components/ChartsAxesGradients';
11
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { jsxs as _jsxs } from "react/jsx-runtime";
12
14
  const ChartContainer = /*#__PURE__*/React.forwardRef(function ChartContainer(props, ref) {
13
15
  const {
14
16
  width,
@@ -44,7 +46,7 @@ const ChartContainer = /*#__PURE__*/React.forwardRef(function ChartContainer(pro
44
46
  dataset: dataset,
45
47
  children: /*#__PURE__*/_jsx(InteractionProvider, {
46
48
  children: /*#__PURE__*/_jsx(HighlightProvider, {
47
- children: /*#__PURE__*/_jsx(ChartsSurface, {
49
+ children: /*#__PURE__*/_jsxs(ChartsSurface, {
48
50
  width: width,
49
51
  height: height,
50
52
  ref: handleRef,
@@ -52,7 +54,7 @@ const ChartContainer = /*#__PURE__*/React.forwardRef(function ChartContainer(pro
52
54
  title: title,
53
55
  desc: desc,
54
56
  disableAxisListener: disableAxisListener,
55
- children: children
57
+ children: [/*#__PURE__*/_jsx(ChartsAxesGradients, {}), children]
56
58
  })
57
59
  })
58
60
  })
@@ -119,11 +121,26 @@ process.env.NODE_ENV !== "production" ? ChartContainer.propTypes = {
119
121
  width: PropTypes.number.isRequired,
120
122
  /**
121
123
  * The configuration of the x-axes.
122
- * If not provided, a default axis config is used with id set to `DEFAULT_X_AXIS_KEY`.
124
+ * If not provided, a default axis config is used.
123
125
  */
124
126
  xAxis: PropTypes.arrayOf(PropTypes.shape({
125
127
  axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
126
128
  classes: PropTypes.object,
129
+ colorMap: PropTypes.oneOfType([PropTypes.shape({
130
+ color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
131
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
132
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
133
+ type: PropTypes.oneOf(['continuous']).isRequired
134
+ }), PropTypes.shape({
135
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
136
+ thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
137
+ type: PropTypes.oneOf(['piecewise']).isRequired
138
+ }), PropTypes.shape({
139
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
140
+ type: PropTypes.oneOf(['ordinal']).isRequired,
141
+ unknownColor: PropTypes.string,
142
+ values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
143
+ })]),
127
144
  data: PropTypes.array,
128
145
  dataKey: PropTypes.string,
129
146
  disableLine: PropTypes.bool,
@@ -156,11 +173,26 @@ process.env.NODE_ENV !== "production" ? ChartContainer.propTypes = {
156
173
  })),
157
174
  /**
158
175
  * The configuration of the y-axes.
159
- * If not provided, a default axis config is used with id set to `DEFAULT_Y_AXIS_KEY`.
176
+ * If not provided, a default axis config is used.
160
177
  */
161
178
  yAxis: PropTypes.arrayOf(PropTypes.shape({
162
179
  axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
163
180
  classes: PropTypes.object,
181
+ colorMap: PropTypes.oneOfType([PropTypes.shape({
182
+ color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
183
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
184
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
185
+ type: PropTypes.oneOf(['continuous']).isRequired
186
+ }), PropTypes.shape({
187
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
188
+ thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
189
+ type: PropTypes.oneOf(['piecewise']).isRequired
190
+ }), PropTypes.shape({
191
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
192
+ type: PropTypes.oneOf(['ordinal']).isRequired,
193
+ unknownColor: PropTypes.string,
194
+ values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
195
+ })]),
164
196
  data: PropTypes.array,
165
197
  dataKey: PropTypes.string,
166
198
  disableLine: PropTypes.bool,
@@ -6,12 +6,12 @@ import { ChartsXAxis } from '../ChartsXAxis';
6
6
  import { ChartsYAxis } from '../ChartsYAxis';
7
7
  import { jsx as _jsx } from "react/jsx-runtime";
8
8
  import { jsxs as _jsxs } from "react/jsx-runtime";
9
- const getAxisId = propsValue => {
9
+ const getAxisId = (propsValue, defaultAxisId) => {
10
10
  if (propsValue == null) {
11
11
  return null;
12
12
  }
13
13
  if (typeof propsValue === 'object') {
14
- return propsValue.axisId ?? null;
14
+ return propsValue.axisId ?? defaultAxisId ?? null;
15
15
  }
16
16
  return propsValue;
17
17
  };
@@ -55,8 +55,8 @@ function ChartsAxis(props) {
55
55
 
56
56
  const leftId = getAxisId(leftAxis === undefined ? yAxisIds[0] : leftAxis);
57
57
  const bottomId = getAxisId(bottomAxis === undefined ? xAxisIds[0] : bottomAxis);
58
- const topId = getAxisId(topAxis);
59
- const rightId = getAxisId(rightAxis);
58
+ const topId = getAxisId(topAxis, xAxisIds[0]);
59
+ const rightId = getAxisId(rightAxis, yAxisIds[0]);
60
60
  if (topId !== null && !xAxis[topId]) {
61
61
  throw Error([`MUI X Charts: id used for top axis "${topId}" is not defined.`, `Available ids are: ${xAxisIds.join(', ')}.`].join('\n'));
62
62
  }
@@ -1,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
3
  import PropTypes from 'prop-types';
4
- import { DrawingContext } from '../context/DrawingProvider';
4
+ import { useDrawingArea } from '../hooks/useDrawingArea';
5
5
  import { jsx as _jsx } from "react/jsx-runtime";
6
6
  /**
7
7
  * API:
@@ -18,7 +18,7 @@ function ChartsClipPath(props) {
18
18
  top,
19
19
  width,
20
20
  height
21
- } = React.useContext(DrawingContext);
21
+ } = useDrawingArea();
22
22
  const offset = _extends({
23
23
  top: 0,
24
24
  right: 0,
@@ -4,11 +4,11 @@ import PropTypes from 'prop-types';
4
4
  import { useSlotProps } from '@mui/base/utils';
5
5
  import { unstable_composeClasses as composeClasses } from '@mui/utils';
6
6
  import { useThemeProps, useTheme } from '@mui/material/styles';
7
- import { DrawingContext } from '../context/DrawingProvider';
8
7
  import { getSeriesToDisplay } from './utils';
9
8
  import { SeriesContext } from '../context/SeriesContextProvider';
10
9
  import { getLegendUtilityClass } from './chartsLegendClasses';
11
10
  import { DefaultChartsLegend } from './DefaultChartsLegend';
11
+ import { useDrawingArea } from '../hooks';
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
13
  const useUtilityClasses = ownerState => {
14
14
  const {
@@ -46,7 +46,7 @@ function ChartsLegend(inProps) {
46
46
  const classes = useUtilityClasses(_extends({}, props, {
47
47
  theme
48
48
  }));
49
- const drawingArea = React.useContext(DrawingContext);
49
+ const drawingArea = useDrawingArea();
50
50
  const series = React.useContext(SeriesContext);
51
51
  const seriesToDisplay = getSeriesToDisplay(series);
52
52
  const ChartLegendRender = slots?.legend ?? DefaultChartsLegend;
@@ -6,6 +6,7 @@ import { SeriesContext } from '../context/SeriesContextProvider';
6
6
  import { CartesianContext } from '../context/CartesianContextProvider';
7
7
  import { DefaultChartsAxisTooltipContent } from './DefaultChartsAxisTooltipContent';
8
8
  import { isCartesianSeriesType } from './utils';
9
+ import colorGetter from '../internals/colorGetter';
9
10
  import { jsx as _jsx } from "react/jsx-runtime";
10
11
  function ChartsAxisTooltipContent(props) {
11
12
  const {
@@ -33,12 +34,16 @@ function ChartsAxisTooltipContent(props) {
33
34
  const item = series[seriesType].series[seriesId];
34
35
  const axisKey = isXaxis ? item.xAxisKey : item.yAxisKey;
35
36
  if (axisKey === undefined || axisKey === USED_AXIS_ID) {
36
- rep.push(series[seriesType].series[seriesId]);
37
+ const seriesToAdd = series[seriesType].series[seriesId];
38
+ const color = colorGetter(seriesToAdd, xAxis[seriesToAdd.xAxisKey ?? xAxisIds[0]], yAxis[seriesToAdd.yAxisKey ?? yAxisIds[0]]);
39
+ rep.push(_extends({}, seriesToAdd, {
40
+ getColor: color
41
+ }));
37
42
  }
38
43
  });
39
44
  });
40
45
  return rep;
41
- }, [USED_AXIS_ID, isXaxis, series]);
46
+ }, [USED_AXIS_ID, isXaxis, series, xAxis, xAxisIds, yAxis, yAxisIds]);
42
47
  const relevantAxis = React.useMemo(() => {
43
48
  return isXaxis ? xAxis[USED_AXIS_ID] : yAxis[USED_AXIS_ID];
44
49
  }, [USED_AXIS_ID, isXaxis, xAxis, yAxis]);
@@ -4,6 +4,8 @@ import PropTypes from 'prop-types';
4
4
  import { useSlotProps } from '@mui/base/utils';
5
5
  import { SeriesContext } from '../context/SeriesContextProvider';
6
6
  import { DefaultChartsItemTooltipContent } from './DefaultChartsItemTooltipContent';
7
+ import { CartesianContext } from '../context/CartesianContextProvider';
8
+ import colorGetter from '../internals/colorGetter';
7
9
  import { jsx as _jsx } from "react/jsx-runtime";
8
10
  function ChartsItemTooltipContent(props) {
9
11
  const {
@@ -14,6 +16,16 @@ function ChartsItemTooltipContent(props) {
14
16
  contentProps
15
17
  } = props;
16
18
  const series = React.useContext(SeriesContext)[itemData.type].series[itemData.seriesId];
19
+ const axisData = React.useContext(CartesianContext);
20
+ const {
21
+ xAxis,
22
+ yAxis,
23
+ xAxisIds,
24
+ yAxisIds
25
+ } = axisData;
26
+ const defaultXAxisId = xAxisIds[0];
27
+ const defaultYAxisId = yAxisIds[0];
28
+ const getColor = series.type === 'pie' ? colorGetter(series) : colorGetter(series, xAxis[series.xAxisKey ?? defaultXAxisId], yAxis[series.yAxisKey ?? defaultYAxisId]);
17
29
  const Content = content ?? DefaultChartsItemTooltipContent;
18
30
  const chartTooltipContentProps = useSlotProps({
19
31
  elementType: Content,
@@ -22,7 +34,8 @@ function ChartsItemTooltipContent(props) {
22
34
  itemData,
23
35
  series,
24
36
  sx,
25
- classes
37
+ classes,
38
+ getColor
26
39
  },
27
40
  ownerState: {}
28
41
  });
@@ -37,6 +50,7 @@ process.env.NODE_ENV !== "production" ? ChartsItemTooltipContent.propTypes = {
37
50
  content: PropTypes.elementType,
38
51
  contentProps: PropTypes.shape({
39
52
  classes: PropTypes.object,
53
+ getColor: PropTypes.func,
40
54
  itemData: PropTypes.shape({
41
55
  dataIndex: PropTypes.number,
42
56
  seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
@@ -41,10 +41,13 @@ function DefaultChartsAxisTooltipContent(props) {
41
41
  id,
42
42
  label,
43
43
  valueFormatter,
44
- data
44
+ data,
45
+ getColor
45
46
  }) => {
46
47
  // @ts-ignore
47
- const formattedValue = valueFormatter(data[dataIndex] ?? null);
48
+ const formattedValue = valueFormatter(data[dataIndex] ?? null, {
49
+ dataIndex
50
+ });
48
51
  if (formattedValue == null) {
49
52
  return null;
50
53
  }
@@ -54,7 +57,7 @@ function DefaultChartsAxisTooltipContent(props) {
54
57
  className: clsx(classes.markCell, classes.cell),
55
58
  children: /*#__PURE__*/_jsx(ChartsTooltipMark, {
56
59
  ownerState: {
57
- color
60
+ color: getColor(dataIndex) ?? color
58
61
  },
59
62
  boxShadow: 1,
60
63
  className: classes.mark
@@ -9,7 +9,8 @@ function DefaultChartsItemTooltipContent(props) {
9
9
  series,
10
10
  itemData,
11
11
  sx,
12
- classes
12
+ classes,
13
+ getColor
13
14
  } = props;
14
15
  if (itemData.dataIndex === undefined || !series.data[itemData.dataIndex]) {
15
16
  return null;
@@ -18,14 +19,16 @@ function DefaultChartsItemTooltipContent(props) {
18
19
  displayedLabel,
19
20
  color
20
21
  } = series.type === 'pie' ? {
21
- color: series.data[itemData.dataIndex].color,
22
+ color: getColor(itemData.dataIndex),
22
23
  displayedLabel: series.data[itemData.dataIndex].label
23
24
  } : {
24
- color: series.color,
25
+ color: getColor(itemData.dataIndex) ?? series.color,
25
26
  displayedLabel: series.label
26
27
  };
27
28
  const value = series.data[itemData.dataIndex];
28
- const formattedValue = series.valueFormatter?.(value);
29
+ const formattedValue = series.valueFormatter?.(value, {
30
+ dataIndex: itemData.dataIndex
31
+ });
29
32
  return /*#__PURE__*/_jsx(ChartsTooltipPaper, {
30
33
  sx: sx,
31
34
  className: classes.root,
@@ -63,6 +66,12 @@ process.env.NODE_ENV !== "production" ? DefaultChartsItemTooltipContent.propType
63
66
  * Override or extend the styles applied to the component.
64
67
  */
65
68
  classes: PropTypes.object.isRequired,
69
+ /**
70
+ * Get the color of the item with index `dataIndex`.
71
+ * @param {number} dataIndex The data index of the item.
72
+ * @returns {string} The color to display.
73
+ */
74
+ getColor: PropTypes.func.isRequired,
66
75
  /**
67
76
  * The data used to identify the triggered item.
68
77
  */
@@ -4,23 +4,23 @@ import { Delaunay } from 'd3-delaunay';
4
4
  import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
5
5
  import { InteractionContext } from '../context/InteractionProvider';
6
6
  import { CartesianContext } from '../context/CartesianContextProvider';
7
- import { SvgContext, DrawingContext } from '../context/DrawingProvider';
8
7
  import { SeriesContext } from '../context/SeriesContextProvider';
9
8
  import { getValueToPositionMapper } from '../hooks/useScale';
10
9
  import { getSVGPoint } from '../internals/utils';
10
+ import { useDrawingArea, useSvgRef } from '../hooks';
11
11
  import { jsx as _jsx } from "react/jsx-runtime";
12
12
  function ChartsVoronoiHandler(props) {
13
13
  const {
14
14
  voronoiMaxRadius,
15
15
  onItemClick
16
16
  } = props;
17
- const svgRef = React.useContext(SvgContext);
17
+ const svgRef = useSvgRef();
18
18
  const {
19
- width,
20
- height,
19
+ left,
21
20
  top,
22
- left
23
- } = React.useContext(DrawingContext);
21
+ width,
22
+ height
23
+ } = useDrawingArea();
24
24
  const {
25
25
  xAxis,
26
26
  yAxis,
@@ -7,13 +7,13 @@ import { useSlotProps } from '@mui/base/utils';
7
7
  import { unstable_composeClasses as composeClasses } from '@mui/utils';
8
8
  import { useThemeProps, useTheme } from '@mui/material/styles';
9
9
  import { CartesianContext } from '../context/CartesianContextProvider';
10
- import { DrawingContext } from '../context/DrawingProvider';
11
10
  import { useTicks } from '../hooks/useTicks';
12
11
  import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
13
12
  import { AxisRoot } from '../internals/components/AxisSharedComponents';
14
13
  import { ChartsText } from '../ChartsText';
15
14
  import { getMinXTranslation } from '../internals/geometry';
16
15
  import { useMounted } from '../hooks/useMounted';
16
+ import { useDrawingArea } from '../hooks/useDrawingArea';
17
17
  import { getWordsByLines } from '../internals/getWordsByLines';
18
18
  import { jsx as _jsx } from "react/jsx-runtime";
19
19
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -63,7 +63,7 @@ function addLabelDimension(xTicks, {
63
63
 
64
64
  // Filter label to avoid overlap
65
65
  let currentTextLimit = 0;
66
- let previouseTextLimit = 0;
66
+ let previousTextLimit = 0;
67
67
  const direction = reverse ? -1 : 1;
68
68
  return withDimension.map((item, labelIndex) => {
69
69
  const {
@@ -77,14 +77,14 @@ function addLabelDimension(xTicks, {
77
77
  const gapRatio = 1.2; // Ratio applied to the minimal distance to add some margin.
78
78
 
79
79
  currentTextLimit = textPosition - direction * (gapRatio * distance) / 2;
80
- if (labelIndex > 0 && direction * currentTextLimit < direction * previouseTextLimit) {
80
+ if (labelIndex > 0 && direction * currentTextLimit < direction * previousTextLimit) {
81
81
  // Except for the first label, we skip all label that overlap with the last accepted.
82
- // Notice that the early return prevents `previouseTextLimit` from being updated.
82
+ // Notice that the early return prevents `previousTextLimit` from being updated.
83
83
  return _extends({}, item, {
84
84
  skipLabel: true
85
85
  });
86
86
  }
87
- previouseTextLimit = textPosition + direction * (gapRatio * distance) / 2;
87
+ previousTextLimit = textPosition + direction * (gapRatio * distance) / 2;
88
88
  return item;
89
89
  });
90
90
  }
@@ -153,7 +153,7 @@ function ChartsXAxis(inProps) {
153
153
  top,
154
154
  width,
155
155
  height
156
- } = React.useContext(DrawingContext);
156
+ } = useDrawingArea();
157
157
  const tickSize = disableTicks ? 4 : tickSizeProp;
158
158
  const positionSign = position === 'bottom' ? 1 : -1;
159
159
  const Line = slots?.axisLine ?? 'line';
@@ -346,7 +346,7 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
346
346
  */
347
347
  tickMinStep: PropTypes.number,
348
348
  /**
349
- * The number of ticks. This number is not guaranted.
349
+ * The number of ticks. This number is not guaranteed.
350
350
  * Not supported by categorical axis (band, points).
351
351
  */
352
352
  tickNumber: PropTypes.number,
@@ -7,8 +7,8 @@ import { useSlotProps } from '@mui/base/utils';
7
7
  import { unstable_composeClasses as composeClasses } from '@mui/utils';
8
8
  import { useThemeProps, useTheme } from '@mui/material/styles';
9
9
  import { CartesianContext } from '../context/CartesianContextProvider';
10
- import { DrawingContext } from '../context/DrawingProvider';
11
10
  import { useTicks } from '../hooks/useTicks';
11
+ 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';
@@ -82,7 +82,8 @@ function ChartsYAxis(inProps) {
82
82
  slotProps,
83
83
  tickPlacement,
84
84
  tickLabelPlacement,
85
- tickInterval
85
+ tickInterval,
86
+ tickLabelInterval
86
87
  } = defaultizedProps;
87
88
  const theme = useTheme();
88
89
  const classes = useUtilityClasses(_extends({}, defaultizedProps, {
@@ -93,7 +94,7 @@ function ChartsYAxis(inProps) {
93
94
  top,
94
95
  width,
95
96
  height
96
- } = React.useContext(DrawingContext);
97
+ } = useDrawingArea();
97
98
  const tickSize = disableTicks ? 4 : tickSizeProp;
98
99
  const yTicks = useTicks({
99
100
  scale: yScale,
@@ -148,17 +149,19 @@ function ChartsYAxis(inProps) {
148
149
  }, slotProps?.axisLine)), yTicks.map(({
149
150
  formattedValue,
150
151
  offset,
151
- labelOffset
152
+ labelOffset,
153
+ value
152
154
  }, index) => {
153
155
  const xTickLabel = positionSign * (tickSize + 2);
154
156
  const yTickLabel = labelOffset;
157
+ const skipLabel = typeof tickLabelInterval === 'function' && !tickLabelInterval?.(value, index);
155
158
  return /*#__PURE__*/_jsxs("g", {
156
159
  transform: `translate(0, ${offset})`,
157
160
  className: classes.tickContainer,
158
161
  children: [!disableTicks && /*#__PURE__*/_jsx(Tick, _extends({
159
162
  x2: positionSign * tickSize,
160
163
  className: classes.tick
161
- }, slotProps?.axisTick)), formattedValue !== undefined && /*#__PURE__*/_jsx(TickLabel, _extends({
164
+ }, slotProps?.axisTick)), formattedValue !== undefined && !skipLabel && /*#__PURE__*/_jsx(TickLabel, _extends({
162
165
  x: xTickLabel,
163
166
  y: yTickLabel,
164
167
  text: formattedValue.toString()
@@ -278,7 +281,7 @@ process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
278
281
  */
279
282
  tickMinStep: PropTypes.number,
280
283
  /**
281
- * The number of ticks. This number is not guaranted.
284
+ * The number of ticks. This number is not guaranteed.
282
285
  * Not supported by categorical axis (band, points).
283
286
  */
284
287
  tickNumber: PropTypes.number,
@@ -1,8 +1,8 @@
1
1
  // @ignore - do not document.
2
2
  import * as React from 'react';
3
- import { DrawingContext } from '../context/DrawingProvider';
4
3
  import { getPercentageValue } from '../internals/utils';
5
4
  import { getArcRatios, getAvailableRadius } from './utils';
5
+ import { useDrawingArea } from '../hooks/useDrawingArea';
6
6
  import { jsx as _jsx } from "react/jsx-runtime";
7
7
  export const GaugeContext = /*#__PURE__*/React.createContext({
8
8
  value: null,
@@ -36,11 +36,11 @@ export function GaugeProvider(props) {
36
36
  children
37
37
  } = props;
38
38
  const {
39
- width,
40
- height,
39
+ left,
41
40
  top,
42
- left
43
- } = React.useContext(DrawingContext);
41
+ width,
42
+ height
43
+ } = useDrawingArea();
44
44
  const ratios = getArcRatios(startAngle, endAngle);
45
45
  const innerCx = cxParam ? getPercentageValue(cxParam, width) : ratios.cx * width;
46
46
  const innerCy = cyParam ? getPercentageValue(cyParam, height) : ratios.cy * height;