@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
@@ -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;
@@ -7,8 +7,8 @@ import { styled } from '@mui/material/styles';
7
7
  import { color as d3Color } from 'd3-color';
8
8
  import { animated, useSpring } from '@react-spring/web';
9
9
  import { useAnimatedPath } from '../internals/useAnimatedPath';
10
- import { DrawingContext } from '../context/DrawingProvider';
11
10
  import { cleanId } from '../internals/utils';
11
+ import { useChartId, useDrawingArea } from '../hooks';
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import { jsxs as _jsxs } from "react/jsx-runtime";
14
14
  export const AreaElementPath = styled(animated.path, {
@@ -19,7 +19,7 @@ export const AreaElementPath = styled(animated.path, {
19
19
  ownerState
20
20
  }) => ({
21
21
  stroke: 'none',
22
- fill: ownerState.isHighlighted ? d3Color(ownerState.color).brighter(1).formatHex() : d3Color(ownerState.color).brighter(0.5).formatHex(),
22
+ fill: ownerState.gradientId && `url(#${ownerState.gradientId})` || ownerState.isHighlighted && d3Color(ownerState.color).brighter(1).formatHex() || d3Color(ownerState.color).brighter(0.5).formatHex(),
23
23
  transition: 'opacity 0.2s ease-in, fill 0.2s ease-in',
24
24
  opacity: ownerState.isFaded ? 0.3 : 1
25
25
  }));
@@ -46,9 +46,9 @@ function AnimatedArea(props) {
46
46
  right,
47
47
  bottom,
48
48
  width,
49
- height,
50
- chartId
51
- } = React.useContext(DrawingContext);
49
+ height
50
+ } = useDrawingArea();
51
+ const chartId = useChartId();
52
52
  const path = useAnimatedPath(d, skipAnimation);
53
53
  const {
54
54
  animatedWidth
@@ -90,6 +90,7 @@ process.env.NODE_ENV !== "production" ? AnimatedArea.propTypes = {
90
90
  ownerState: PropTypes.shape({
91
91
  classes: PropTypes.object,
92
92
  color: PropTypes.string.isRequired,
93
+ gradientId: PropTypes.string,
93
94
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
94
95
  isFaded: PropTypes.bool.isRequired,
95
96
  isHighlighted: PropTypes.bool.isRequired
@@ -7,8 +7,9 @@ import { animated, useSpring } from '@react-spring/web';
7
7
  import { color as d3Color } from 'd3-color';
8
8
  import { styled } from '@mui/material/styles';
9
9
  import { useAnimatedPath } from '../internals/useAnimatedPath';
10
- import { DrawingContext } from '../context/DrawingProvider';
11
10
  import { cleanId } from '../internals/utils';
11
+ import { useChartId } from '../hooks/useChartId';
12
+ import { useDrawingArea } from '../hooks/useDrawingArea';
12
13
  import { jsx as _jsx } from "react/jsx-runtime";
13
14
  import { jsxs as _jsxs } from "react/jsx-runtime";
14
15
  export const LineElementPath = styled(animated.path, {
@@ -21,7 +22,7 @@ export const LineElementPath = styled(animated.path, {
21
22
  strokeWidth: 2,
22
23
  strokeLinejoin: 'round',
23
24
  fill: 'none',
24
- stroke: ownerState.isHighlighted ? d3Color(ownerState.color).brighter(0.5).formatHex() : ownerState.color,
25
+ stroke: ownerState.gradientId && `url(#${ownerState.gradientId})` || ownerState.isHighlighted && d3Color(ownerState.color).brighter(0.5).formatHex() || ownerState.color,
25
26
  transition: 'opacity 0.2s ease-in, stroke 0.2s ease-in',
26
27
  opacity: ownerState.isFaded ? 0.3 : 1
27
28
  }));
@@ -48,9 +49,9 @@ function AnimatedLine(props) {
48
49
  bottom,
49
50
  width,
50
51
  height,
51
- right,
52
- chartId
53
- } = React.useContext(DrawingContext);
52
+ right
53
+ } = useDrawingArea();
54
+ const chartId = useChartId();
54
55
  const path = useAnimatedPath(d, skipAnimation);
55
56
  const {
56
57
  animatedWidth
@@ -92,6 +93,7 @@ process.env.NODE_ENV !== "production" ? AnimatedLine.propTypes = {
92
93
  ownerState: PropTypes.shape({
93
94
  classes: PropTypes.object,
94
95
  color: PropTypes.string.isRequired,
96
+ gradientId: PropTypes.string,
95
97
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
96
98
  isFaded: PropTypes.bool.isRequired,
97
99
  isHighlighted: PropTypes.bool.isRequired
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["id", "classes", "color", "highlightScope", "slots", "slotProps", "onClick"];
3
+ const _excluded = ["id", "classes", "color", "gradientId", "highlightScope", "slots", "slotProps", "onClick"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import composeClasses from '@mui/utils/composeClasses';
@@ -42,6 +42,7 @@ function AreaElement(props) {
42
42
  id,
43
43
  classes: innerClasses,
44
44
  color,
45
+ gradientId,
45
46
  highlightScope,
46
47
  slots,
47
48
  slotProps,
@@ -64,6 +65,7 @@ function AreaElement(props) {
64
65
  id,
65
66
  classes: innerClasses,
66
67
  color,
68
+ gradientId,
67
69
  isFaded,
68
70
  isHighlighted
69
71
  };
@@ -92,6 +94,7 @@ process.env.NODE_ENV !== "production" ? AreaElement.propTypes = {
92
94
  classes: PropTypes.object,
93
95
  color: PropTypes.string.isRequired,
94
96
  d: PropTypes.string.isRequired,
97
+ gradientId: PropTypes.string,
95
98
  highlightScope: PropTypes.shape({
96
99
  faded: PropTypes.oneOf(['global', 'none', 'series']),
97
100
  highlighted: PropTypes.oneOf(['item', 'none', 'series'])
@@ -10,6 +10,7 @@ import { AreaElement } from './AreaElement';
10
10
  import { getValueToPositionMapper } from '../hooks/useScale';
11
11
  import getCurveFactory from '../internals/getCurve';
12
12
  import { DEFAULT_X_AXIS_KEY } from '../constants';
13
+ import { useChartGradient } from '../internals/components/ChartsAxesGradients';
13
14
  import { jsx as _jsx } from "react/jsx-runtime";
14
15
  const useAggregatedData = () => {
15
16
  const seriesData = React.useContext(SeriesContext).line;
@@ -43,6 +44,7 @@ const useAggregatedData = () => {
43
44
  const xScale = getValueToPositionMapper(xAxis[xAxisKey].scale);
44
45
  const yScale = yAxis[yAxisKey].scale;
45
46
  const xData = xAxis[xAxisKey].data;
47
+ const gradientUsed = yAxis[yAxisKey].colorScale && [yAxisKey, 'y'] || xAxis[xAxisKey].colorScale && [xAxisKey, 'x'] || undefined;
46
48
  if (process.env.NODE_ENV !== 'production') {
47
49
  if (xData === undefined) {
48
50
  throw new Error(`MUI X Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} should have data property to be able to display a line plot.`);
@@ -60,6 +62,7 @@ const useAggregatedData = () => {
60
62
  const d3Data = connectNulls ? formattedData.filter((_, i) => data[i] != null) : formattedData;
61
63
  const d = areaPath.curve(curve)(d3Data) || '';
62
64
  return _extends({}, series[seriesId], {
65
+ gradientUsed,
63
66
  d,
64
67
  seriesId
65
68
  });
@@ -86,6 +89,7 @@ function AreaPlot(props) {
86
89
  skipAnimation
87
90
  } = props,
88
91
  other = _objectWithoutPropertiesLoose(props, _excluded);
92
+ const getGradientId = useChartGradient();
89
93
  const completedData = useAggregatedData();
90
94
  return /*#__PURE__*/_jsx("g", _extends({}, other, {
91
95
  children: completedData.reverse().map(({
@@ -93,11 +97,13 @@ function AreaPlot(props) {
93
97
  seriesId,
94
98
  color,
95
99
  highlightScope,
96
- area
100
+ area,
101
+ gradientUsed
97
102
  }) => !!area && /*#__PURE__*/_jsx(AreaElement, {
98
103
  id: seriesId,
99
104
  d: d,
100
105
  color: color,
106
+ gradientId: gradientUsed && getGradientId(...gradientUsed),
101
107
  highlightScope: highlightScope,
102
108
  slots: slots,
103
109
  slotProps: slotProps,
@@ -379,11 +379,26 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
379
379
  width: PropTypes.number,
380
380
  /**
381
381
  * The configuration of the x-axes.
382
- * If not provided, a default axis config is used with id set to `DEFAULT_X_AXIS_KEY`.
382
+ * If not provided, a default axis config is used.
383
383
  */
384
384
  xAxis: PropTypes.arrayOf(PropTypes.shape({
385
385
  axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
386
386
  classes: PropTypes.object,
387
+ colorMap: PropTypes.oneOfType([PropTypes.shape({
388
+ color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
389
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
390
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
391
+ type: PropTypes.oneOf(['continuous']).isRequired
392
+ }), PropTypes.shape({
393
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
394
+ thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
395
+ type: PropTypes.oneOf(['piecewise']).isRequired
396
+ }), PropTypes.shape({
397
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
398
+ type: PropTypes.oneOf(['ordinal']).isRequired,
399
+ unknownColor: PropTypes.string,
400
+ values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
401
+ })]),
387
402
  data: PropTypes.array,
388
403
  dataKey: PropTypes.string,
389
404
  disableLine: PropTypes.bool,
@@ -416,11 +431,26 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
416
431
  })),
417
432
  /**
418
433
  * The configuration of the y-axes.
419
- * If not provided, a default axis config is used with id set to `DEFAULT_Y_AXIS_KEY`.
434
+ * If not provided, a default axis config is used.
420
435
  */
421
436
  yAxis: PropTypes.arrayOf(PropTypes.shape({
422
437
  axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
423
438
  classes: PropTypes.object,
439
+ colorMap: PropTypes.oneOfType([PropTypes.shape({
440
+ color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
441
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
442
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
443
+ type: PropTypes.oneOf(['continuous']).isRequired
444
+ }), PropTypes.shape({
445
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
446
+ thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
447
+ type: PropTypes.oneOf(['piecewise']).isRequired
448
+ }), PropTypes.shape({
449
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
450
+ type: PropTypes.oneOf(['ordinal']).isRequired,
451
+ unknownColor: PropTypes.string,
452
+ values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
453
+ })]),
424
454
  data: PropTypes.array,
425
455
  dataKey: PropTypes.string,
426
456
  disableLine: PropTypes.bool,
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["id", "classes", "color", "highlightScope", "slots", "slotProps", "onClick"];
3
+ const _excluded = ["id", "classes", "color", "gradientId", "highlightScope", "slots", "slotProps", "onClick"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import composeClasses from '@mui/utils/composeClasses';
@@ -42,6 +42,7 @@ function LineElement(props) {
42
42
  id,
43
43
  classes: innerClasses,
44
44
  color,
45
+ gradientId,
45
46
  highlightScope,
46
47
  slots,
47
48
  slotProps,
@@ -64,6 +65,7 @@ function LineElement(props) {
64
65
  id,
65
66
  classes: innerClasses,
66
67
  color,
68
+ gradientId,
67
69
  isFaded,
68
70
  isHighlighted
69
71
  };
@@ -92,6 +94,7 @@ process.env.NODE_ENV !== "production" ? LineElement.propTypes = {
92
94
  classes: PropTypes.object,
93
95
  color: PropTypes.string.isRequired,
94
96
  d: PropTypes.string.isRequired,
97
+ gradientId: PropTypes.string,
95
98
  highlightScope: PropTypes.shape({
96
99
  faded: PropTypes.oneOf(['global', 'none', 'series']),
97
100
  highlighted: PropTypes.oneOf(['item', 'none', 'series'])
@@ -9,6 +9,7 @@ import { LineHighlightElement } from './LineHighlightElement';
9
9
  import { getValueToPositionMapper } from '../hooks/useScale';
10
10
  import { InteractionContext } from '../context/InteractionProvider';
11
11
  import { DEFAULT_X_AXIS_KEY } from '../constants';
12
+ import getColor from './getColor';
12
13
  import { jsx as _jsx } from "react/jsx-runtime";
13
14
  /**
14
15
  * Demos:
@@ -74,9 +75,11 @@ function LineHighlightPlot(props) {
74
75
  }
75
76
  const x = xScale(xData[highlightedIndex]);
76
77
  const y = yScale(stackedData[highlightedIndex][1]); // This should not be undefined since y should not be a band scale
78
+
79
+ const colorGetter = getColor(series[seriesId], xAxis[xAxisKey], yAxis[yAxisKey]);
77
80
  return /*#__PURE__*/_jsx(Element, _extends({
78
81
  id: seriesId,
79
- color: series[seriesId].color,
82
+ color: colorGetter(highlightedIndex),
80
83
  x: x,
81
84
  y: y
82
85
  }, slotProps?.lineHighlight), `${seriesId}`);
@@ -10,6 +10,7 @@ import { LineElement } from './LineElement';
10
10
  import { getValueToPositionMapper } from '../hooks/useScale';
11
11
  import getCurveFactory from '../internals/getCurve';
12
12
  import { DEFAULT_X_AXIS_KEY } from '../constants';
13
+ import { useChartGradient } from '../internals/components/ChartsAxesGradients';
13
14
  import { jsx as _jsx } from "react/jsx-runtime";
14
15
  const useAggregatedData = () => {
15
16
  const seriesData = React.useContext(SeriesContext).line;
@@ -43,6 +44,7 @@ const useAggregatedData = () => {
43
44
  const xScale = getValueToPositionMapper(xAxis[xAxisKey].scale);
44
45
  const yScale = yAxis[yAxisKey].scale;
45
46
  const xData = xAxis[xAxisKey].data;
47
+ const gradientUsed = yAxis[yAxisKey].colorScale && [yAxisKey, 'y'] || xAxis[xAxisKey].colorScale && [xAxisKey, 'x'] || undefined;
46
48
  if (process.env.NODE_ENV !== 'production') {
47
49
  if (xData === undefined) {
48
50
  throw new Error(`MUI X Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} should have data property to be able to display a line plot.`);
@@ -59,6 +61,7 @@ const useAggregatedData = () => {
59
61
  const d3Data = connectNulls ? formattedData.filter((_, i) => data[i] != null) : formattedData;
60
62
  const d = linePath.curve(getCurveFactory(series[seriesId].curve))(d3Data) || '';
61
63
  return _extends({}, series[seriesId], {
64
+ gradientUsed,
62
65
  d,
63
66
  seriesId
64
67
  });
@@ -84,18 +87,21 @@ function LinePlot(props) {
84
87
  onItemClick
85
88
  } = props,
86
89
  other = _objectWithoutPropertiesLoose(props, _excluded);
90
+ const getGradientId = useChartGradient();
87
91
  const completedData = useAggregatedData();
88
92
  return /*#__PURE__*/_jsx("g", _extends({}, other, {
89
93
  children: completedData.map(({
90
94
  d,
91
95
  seriesId,
92
96
  color,
93
- highlightScope
97
+ highlightScope,
98
+ gradientUsed
94
99
  }) => {
95
100
  return /*#__PURE__*/_jsx(LineElement, {
96
101
  id: seriesId,
97
102
  d: d,
98
103
  color: color,
104
+ gradientId: gradientUsed && getGradientId(...gradientUsed),
99
105
  highlightScope: highlightScope,
100
106
  skipAnimation: skipAnimation,
101
107
  slots: slots,
@@ -7,9 +7,10 @@ import { SeriesContext } from '../context/SeriesContextProvider';
7
7
  import { CartesianContext } from '../context/CartesianContextProvider';
8
8
  import { MarkElement } from './MarkElement';
9
9
  import { getValueToPositionMapper } from '../hooks/useScale';
10
+ import { useChartId } from '../hooks/useChartId';
10
11
  import { DEFAULT_X_AXIS_KEY } from '../constants';
11
- import { DrawingContext } from '../context/DrawingProvider';
12
12
  import { cleanId } from '../internals/utils';
13
+ import getColor from './getColor';
13
14
  import { jsx as _jsx } from "react/jsx-runtime";
14
15
  /**
15
16
  * Demos:
@@ -31,9 +32,7 @@ function MarkPlot(props) {
31
32
  other = _objectWithoutPropertiesLoose(props, _excluded);
32
33
  const seriesData = React.useContext(SeriesContext).line;
33
34
  const axisData = React.useContext(CartesianContext);
34
- const {
35
- chartId
36
- } = React.useContext(DrawingContext);
35
+ const chartId = useChartId();
37
36
  const Mark = slots?.mark ?? MarkElement;
38
37
  if (seriesData === undefined) {
39
38
  return null;
@@ -87,6 +86,7 @@ function MarkPlot(props) {
87
86
  }
88
87
  const clipId = cleanId(`${chartId}-${seriesId}-line-clip`); // We assume that if displaying line mark, the line will also be rendered
89
88
 
89
+ const colorGetter = getColor(series[seriesId], xAxis[xAxisKey], yAxis[yAxisKey]);
90
90
  return /*#__PURE__*/_jsx("g", {
91
91
  clipPath: `url(#${clipId})`,
92
92
  children: xData?.map((x, index) => {
@@ -135,7 +135,7 @@ function MarkPlot(props) {
135
135
  id: seriesId,
136
136
  dataIndex: index,
137
137
  shape: "circle",
138
- color: series[seriesId].color,
138
+ color: colorGetter(index),
139
139
  x: x,
140
140
  y: y // Don't know why TS doesn't get from the filter that y can't be null
141
141
  ,