@mui/x-charts 7.6.2 → 7.7.1

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 (197) hide show
  1. package/BarChart/BarChart.d.ts +1 -1
  2. package/BarChart/BarChart.js +21 -104
  3. package/BarChart/BarLabel/BarLabelPlot.d.ts +0 -3
  4. package/BarChart/BarLabel/BarLabelPlot.js +1 -24
  5. package/BarChart/BarPlot.js +2 -2
  6. package/BarChart/checkScaleErrors.d.ts +5 -9
  7. package/BarChart/types.d.ts +2 -2
  8. package/BarChart/useBarChartProps.d.ts +102 -0
  9. package/BarChart/useBarChartProps.js +143 -0
  10. package/CHANGELOG.md +163 -0
  11. package/ChartContainer/ChartContainer.d.ts +4 -4
  12. package/ChartContainer/ChartContainer.js +64 -31
  13. package/ChartContainer/useChartContainerHooks.d.ts +11 -0
  14. package/ChartContainer/useChartContainerHooks.js +34 -0
  15. package/ChartContainer/usePluginsMerge.d.ts +1 -2
  16. package/ChartsAxis/ChartsAxis.js +2 -2
  17. package/ChartsAxisHighlight/ChartsAxisHighlight.js +2 -2
  18. package/ChartsGrid/ChartsGrid.js +2 -2
  19. package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +2 -2
  20. package/ChartsOverlay/index.d.ts +1 -0
  21. package/ChartsReferenceLine/ChartsXReferenceLine.js +3 -5
  22. package/ChartsReferenceLine/ChartsYReferenceLine.js +3 -5
  23. package/ChartsText/ChartsText.js +1 -3
  24. package/ChartsTooltip/ChartsAxisTooltipContent.js +8 -14
  25. package/ChartsTooltip/ChartsItemTooltipContent.js +8 -18
  26. package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +3 -3
  27. package/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
  28. package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +2 -2
  29. package/ChartsXAxis/ChartsXAxis.js +2 -2
  30. package/ChartsYAxis/ChartsYAxis.js +2 -2
  31. package/LineChart/AreaPlot.js +2 -2
  32. package/LineChart/LineChart.d.ts +2 -2
  33. package/LineChart/LineChart.js +25 -107
  34. package/LineChart/LineHighlightPlot.js +2 -2
  35. package/LineChart/LinePlot.js +2 -2
  36. package/LineChart/MarkPlot.js +2 -2
  37. package/LineChart/useLineChartProps.d.ts +117 -0
  38. package/LineChart/useLineChartProps.js +152 -0
  39. package/PieChart/PieChart.d.ts +2 -2
  40. package/PieChart/PieChart.js +1 -1
  41. package/ResponsiveChartContainer/ResizableContainer.d.ts +10 -0
  42. package/ResponsiveChartContainer/ResizableContainer.js +32 -0
  43. package/ResponsiveChartContainer/ResponsiveChartContainer.js +25 -22
  44. package/ScatterChart/ScatterChart.d.ts +1 -1
  45. package/ScatterChart/ScatterChart.js +21 -76
  46. package/ScatterChart/ScatterPlot.js +2 -2
  47. package/ScatterChart/useScatterChartProps.d.ts +86 -0
  48. package/ScatterChart/useScatterChartProps.js +116 -0
  49. package/SparkLineChart/SparkLineChart.d.ts +8 -3
  50. package/SparkLineChart/SparkLineChart.js +57 -1
  51. package/context/CartesianProvider/CartesianContext.d.ts +25 -0
  52. package/context/CartesianProvider/CartesianContext.js +21 -0
  53. package/context/CartesianProvider/CartesianProvider.d.ts +34 -0
  54. package/context/CartesianProvider/CartesianProvider.js +44 -0
  55. package/context/CartesianProvider/computeValue.d.ts +19 -0
  56. package/context/CartesianProvider/computeValue.js +89 -0
  57. package/context/CartesianProvider/getAxisExtremum.d.ts +4 -0
  58. package/context/CartesianProvider/getAxisExtremum.js +28 -0
  59. package/context/CartesianProvider/index.d.ts +9 -0
  60. package/context/CartesianProvider/index.js +51 -0
  61. package/context/CartesianProvider/normalizeAxis.d.ts +5 -0
  62. package/context/CartesianProvider/normalizeAxis.js +23 -0
  63. package/context/CartesianProvider/useCartesianContext.d.ts +2 -0
  64. package/context/CartesianProvider/useCartesianContext.js +17 -0
  65. package/context/ColorProvider.d.ts +12 -0
  66. package/context/ColorProvider.js +25 -0
  67. package/esm/BarChart/BarChart.js +21 -104
  68. package/esm/BarChart/BarLabel/BarLabelPlot.js +0 -23
  69. package/esm/BarChart/BarPlot.js +2 -2
  70. package/esm/BarChart/useBarChartProps.js +136 -0
  71. package/esm/ChartContainer/ChartContainer.js +65 -32
  72. package/esm/ChartContainer/useChartContainerHooks.js +24 -0
  73. package/esm/ChartsAxis/ChartsAxis.js +2 -2
  74. package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +2 -2
  75. package/esm/ChartsGrid/ChartsGrid.js +2 -2
  76. package/esm/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +2 -2
  77. package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +3 -5
  78. package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +3 -5
  79. package/esm/ChartsText/ChartsText.js +1 -3
  80. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +8 -14
  81. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +8 -18
  82. package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +3 -3
  83. package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
  84. package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +2 -2
  85. package/esm/ChartsXAxis/ChartsXAxis.js +2 -2
  86. package/esm/ChartsYAxis/ChartsYAxis.js +2 -2
  87. package/esm/LineChart/AreaPlot.js +2 -2
  88. package/esm/LineChart/LineChart.js +25 -107
  89. package/esm/LineChart/LineHighlightPlot.js +2 -2
  90. package/esm/LineChart/LinePlot.js +2 -2
  91. package/esm/LineChart/MarkPlot.js +2 -2
  92. package/esm/LineChart/useLineChartProps.js +144 -0
  93. package/esm/PieChart/PieChart.js +1 -1
  94. package/esm/ResponsiveChartContainer/ResizableContainer.js +26 -0
  95. package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +24 -21
  96. package/esm/ScatterChart/ScatterChart.js +21 -76
  97. package/esm/ScatterChart/ScatterPlot.js +2 -2
  98. package/esm/ScatterChart/useScatterChartProps.js +108 -0
  99. package/esm/SparkLineChart/SparkLineChart.js +57 -1
  100. package/esm/context/CartesianProvider/CartesianContext.js +13 -0
  101. package/esm/context/CartesianProvider/CartesianProvider.js +37 -0
  102. package/esm/context/CartesianProvider/computeValue.js +82 -0
  103. package/esm/context/CartesianProvider/getAxisExtremum.js +21 -0
  104. package/esm/context/CartesianProvider/index.js +10 -0
  105. package/esm/context/CartesianProvider/normalizeAxis.js +15 -0
  106. package/esm/context/CartesianProvider/useCartesianContext.js +8 -0
  107. package/esm/context/ColorProvider.js +16 -0
  108. package/esm/hooks/index.js +1 -0
  109. package/esm/hooks/useAxisEvents.js +2 -2
  110. package/esm/hooks/useColor.js +9 -0
  111. package/esm/hooks/useColorScale.js +27 -0
  112. package/esm/hooks/useReducedMotion.js +7 -0
  113. package/esm/hooks/useScale.js +3 -4
  114. package/esm/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +2 -2
  115. package/esm/internals/index.js +31 -1
  116. package/esm/internals/warning.js +13 -0
  117. package/hooks/index.d.ts +1 -0
  118. package/hooks/index.js +12 -0
  119. package/hooks/useAxisEvents.js +2 -2
  120. package/hooks/useColor.d.ts +4 -0
  121. package/hooks/useColor.js +17 -0
  122. package/hooks/useColorScale.d.ts +4 -0
  123. package/hooks/useColorScale.js +37 -0
  124. package/hooks/useDrawingArea.d.ts +2 -8
  125. package/hooks/useReducedMotion.js +7 -0
  126. package/hooks/useScale.js +3 -6
  127. package/index.js +1 -1
  128. package/internals/components/ChartsAxesGradients/ChartsAxesGradients.d.ts +2 -1
  129. package/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +2 -2
  130. package/internals/defaultizeColor.d.ts +8 -8
  131. package/internals/index.d.ts +22 -0
  132. package/internals/index.js +231 -0
  133. package/internals/warning.d.ts +1 -0
  134. package/internals/warning.js +19 -0
  135. package/models/axis.d.ts +1 -2
  136. package/models/plugin.d.ts +4 -1
  137. package/modern/BarChart/BarChart.js +21 -104
  138. package/modern/BarChart/BarLabel/BarLabelPlot.js +0 -23
  139. package/modern/BarChart/BarPlot.js +2 -2
  140. package/modern/BarChart/useBarChartProps.js +136 -0
  141. package/modern/ChartContainer/ChartContainer.js +65 -32
  142. package/modern/ChartContainer/useChartContainerHooks.js +24 -0
  143. package/modern/ChartsAxis/ChartsAxis.js +2 -2
  144. package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +2 -2
  145. package/modern/ChartsGrid/ChartsGrid.js +2 -2
  146. package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +2 -2
  147. package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +3 -5
  148. package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +3 -5
  149. package/modern/ChartsText/ChartsText.js +1 -3
  150. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +8 -14
  151. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +8 -18
  152. package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +3 -3
  153. package/modern/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
  154. package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +2 -2
  155. package/modern/ChartsXAxis/ChartsXAxis.js +2 -2
  156. package/modern/ChartsYAxis/ChartsYAxis.js +2 -2
  157. package/modern/LineChart/AreaPlot.js +2 -2
  158. package/modern/LineChart/LineChart.js +25 -107
  159. package/modern/LineChart/LineHighlightPlot.js +2 -2
  160. package/modern/LineChart/LinePlot.js +2 -2
  161. package/modern/LineChart/MarkPlot.js +2 -2
  162. package/modern/LineChart/useLineChartProps.js +144 -0
  163. package/modern/PieChart/PieChart.js +1 -1
  164. package/modern/ResponsiveChartContainer/ResizableContainer.js +26 -0
  165. package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +24 -21
  166. package/modern/ScatterChart/ScatterChart.js +21 -76
  167. package/modern/ScatterChart/ScatterPlot.js +2 -2
  168. package/modern/ScatterChart/useScatterChartProps.js +108 -0
  169. package/modern/SparkLineChart/SparkLineChart.js +57 -1
  170. package/modern/context/CartesianProvider/CartesianContext.js +13 -0
  171. package/modern/context/CartesianProvider/CartesianProvider.js +37 -0
  172. package/modern/context/CartesianProvider/computeValue.js +82 -0
  173. package/modern/context/CartesianProvider/getAxisExtremum.js +21 -0
  174. package/modern/context/CartesianProvider/index.js +10 -0
  175. package/modern/context/CartesianProvider/normalizeAxis.js +15 -0
  176. package/modern/context/CartesianProvider/useCartesianContext.js +8 -0
  177. package/modern/context/ColorProvider.js +16 -0
  178. package/modern/hooks/index.js +1 -0
  179. package/modern/hooks/useAxisEvents.js +2 -2
  180. package/modern/hooks/useColor.js +9 -0
  181. package/modern/hooks/useColorScale.js +27 -0
  182. package/modern/hooks/useReducedMotion.js +7 -0
  183. package/modern/hooks/useScale.js +3 -4
  184. package/modern/index.js +1 -1
  185. package/modern/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +2 -2
  186. package/modern/internals/index.js +31 -1
  187. package/modern/internals/warning.js +13 -0
  188. package/package.json +4 -4
  189. package/themeAugmentation/components.d.ts +12 -12
  190. package/context/CartesianContextProvider.d.ts +0 -53
  191. package/context/CartesianContextProvider.js +0 -233
  192. package/esm/context/CartesianContextProvider.js +0 -224
  193. package/esm/internals/colorGetter.js +0 -22
  194. package/internals/colorGetter.d.ts +0 -7
  195. package/internals/colorGetter.js +0 -29
  196. package/modern/context/CartesianContextProvider.js +0 -224
  197. package/modern/internals/colorGetter.js +0 -22
@@ -2,7 +2,6 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWith
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
3
  const _excluded = ["bars", "skipAnimation"];
4
4
  import * as React from 'react';
5
- import PropTypes from 'prop-types';
6
5
  import { useTransition } from '@react-spring/web';
7
6
  import { BarLabelItem } from './BarLabelItem';
8
7
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -73,26 +72,4 @@ function BarLabelPlot(props) {
73
72
  })))
74
73
  });
75
74
  }
76
- process.env.NODE_ENV !== "production" ? BarLabelPlot.propTypes = {
77
- // ----------------------------- Warning --------------------------------
78
- // | These PropTypes are generated from the TypeScript type definitions |
79
- // | To update them edit the TypeScript types and run "pnpm proptypes" |
80
- // ----------------------------------------------------------------------
81
- barLabel: PropTypes.oneOfType([PropTypes.oneOf(['value']), PropTypes.func]),
82
- bars: PropTypes.arrayOf(PropTypes.shape({
83
- color: PropTypes.string.isRequired,
84
- dataIndex: PropTypes.number.isRequired,
85
- height: PropTypes.number.isRequired,
86
- layout: PropTypes.oneOf(['horizontal', 'vertical']),
87
- maskId: PropTypes.string.isRequired,
88
- seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
89
- value: PropTypes.number,
90
- width: PropTypes.number.isRequired,
91
- x: PropTypes.number.isRequired,
92
- xOrigin: PropTypes.number.isRequired,
93
- y: PropTypes.number.isRequired,
94
- yOrigin: PropTypes.number.isRequired
95
- })).isRequired,
96
- skipAnimation: PropTypes.bool
97
- } : void 0;
98
75
  export { BarLabelPlot };
@@ -4,7 +4,7 @@ const _excluded = ["skipAnimation", "onItemClick", "borderRadius", "barLabel"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import { useTransition } from '@react-spring/web';
7
- import { CartesianContext } from '../context/CartesianContextProvider';
7
+ import { useCartesianContext } from '../context/CartesianProvider';
8
8
  import { BarElement } from './BarElement';
9
9
  import getColor from './getColor';
10
10
  import { useChartId } from '../hooks';
@@ -47,7 +47,7 @@ const useAggregatedData = () => {
47
47
  stackingGroups: [],
48
48
  seriesOrder: []
49
49
  };
50
- const axisData = React.useContext(CartesianContext);
50
+ const axisData = useCartesianContext();
51
51
  const chartId = useChartId();
52
52
  const {
53
53
  series,
@@ -0,0 +1,136 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import useId from '@mui/utils/useId';
3
+ import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
4
+
5
+ /**
6
+ * A helper function that extracts BarChartProps from the input props
7
+ * and returns an object with props for the children components of BarChart.
8
+ *
9
+ * @param props The input props for BarChart
10
+ * @returns An object with props for the children components of BarChart
11
+ */
12
+ export const useBarChartProps = props => {
13
+ const {
14
+ xAxis,
15
+ yAxis,
16
+ series,
17
+ width,
18
+ height,
19
+ margin,
20
+ colors,
21
+ dataset,
22
+ sx,
23
+ tooltip,
24
+ onAxisClick,
25
+ axisHighlight,
26
+ legend,
27
+ grid,
28
+ topAxis,
29
+ leftAxis,
30
+ rightAxis,
31
+ bottomAxis,
32
+ children,
33
+ slots,
34
+ slotProps,
35
+ skipAnimation,
36
+ loading,
37
+ layout,
38
+ onItemClick,
39
+ highlightedItem,
40
+ onHighlightChange,
41
+ borderRadius,
42
+ barLabel
43
+ } = props;
44
+ const id = useId();
45
+ const clipPathId = `${id}-clip-path`;
46
+ const hasHorizontalSeries = layout === 'horizontal' || layout === undefined && series.some(item => item.layout === 'horizontal');
47
+ const defaultAxisConfig = {
48
+ scaleType: 'band',
49
+ data: Array.from({
50
+ length: Math.max(...series.map(s => (s.data ?? dataset ?? []).length))
51
+ }, (_, index) => index)
52
+ };
53
+ const chartContainerProps = {
54
+ series: series.map(s => _extends({
55
+ type: 'bar'
56
+ }, s, {
57
+ layout: hasHorizontalSeries ? 'horizontal' : 'vertical'
58
+ })),
59
+ width,
60
+ height,
61
+ margin,
62
+ colors,
63
+ dataset,
64
+ xAxis: xAxis ?? (hasHorizontalSeries ? undefined : [_extends({
65
+ id: DEFAULT_X_AXIS_KEY
66
+ }, defaultAxisConfig)]),
67
+ yAxis: yAxis ?? (hasHorizontalSeries ? [_extends({
68
+ id: DEFAULT_Y_AXIS_KEY
69
+ }, defaultAxisConfig)] : undefined),
70
+ sx,
71
+ highlightedItem,
72
+ onHighlightChange,
73
+ disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none' && !onAxisClick
74
+ };
75
+ const barPlotProps = {
76
+ onItemClick,
77
+ slots,
78
+ slotProps,
79
+ skipAnimation,
80
+ borderRadius,
81
+ barLabel
82
+ };
83
+ const axisClickHandlerProps = {
84
+ onAxisClick
85
+ };
86
+ const gridProps = {
87
+ vertical: grid?.vertical,
88
+ horizontal: grid?.horizontal
89
+ };
90
+ const clipPathGroupProps = {
91
+ clipPath: `url(#${clipPathId})`
92
+ };
93
+ const clipPathProps = {
94
+ id: clipPathId
95
+ };
96
+ const overlayProps = {
97
+ slots,
98
+ slotProps,
99
+ loading
100
+ };
101
+ const chartsAxisProps = {
102
+ topAxis,
103
+ leftAxis,
104
+ rightAxis,
105
+ bottomAxis,
106
+ slots,
107
+ slotProps
108
+ };
109
+ const axisHighlightProps = _extends({}, hasHorizontalSeries ? {
110
+ y: 'band'
111
+ } : {
112
+ x: 'band'
113
+ }, axisHighlight);
114
+ const legendProps = _extends({}, legend, {
115
+ slots,
116
+ slotProps
117
+ });
118
+ const tooltipProps = _extends({}, tooltip, {
119
+ slots,
120
+ slotProps
121
+ });
122
+ return {
123
+ chartContainerProps,
124
+ barPlotProps,
125
+ axisClickHandlerProps,
126
+ gridProps,
127
+ clipPathProps,
128
+ clipPathGroupProps,
129
+ overlayProps,
130
+ chartsAxisProps,
131
+ axisHighlightProps,
132
+ legendProps,
133
+ tooltipProps,
134
+ children
135
+ };
136
+ };
@@ -1,15 +1,14 @@
1
1
  import * as React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import useForkRef from '@mui/utils/useForkRef';
4
3
  import { DrawingProvider } from '../context/DrawingProvider';
5
4
  import { SeriesContextProvider } from '../context/SeriesContextProvider';
6
5
  import { InteractionProvider } from '../context/InteractionProvider';
7
- import { useReducedMotion } from '../hooks/useReducedMotion';
6
+ import { ColorProvider } from '../context/ColorProvider';
8
7
  import { ChartsSurface } from '../ChartsSurface';
9
- import { CartesianContextProvider } from '../context/CartesianContextProvider';
8
+ import { CartesianContextProvider } from '../context/CartesianProvider';
10
9
  import { ChartsAxesGradients } from '../internals/components/ChartsAxesGradients';
11
- import { HighlightedProvider } from '../context';
12
- import { usePluginsMerge } from './usePluginsMerge';
10
+ import { HighlightedProvider, ZAxisContextProvider } from '../context';
11
+ import { useChartContainerHooks } from './useChartContainerHooks';
13
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
13
  const ChartContainer = /*#__PURE__*/React.forwardRef(function ChartContainer(props, ref) {
15
14
  const {
@@ -19,6 +18,7 @@ const ChartContainer = /*#__PURE__*/React.forwardRef(function ChartContainer(pro
19
18
  margin,
20
19
  xAxis,
21
20
  yAxis,
21
+ zAxis,
22
22
  colors,
23
23
  dataset,
24
24
  sx,
@@ -30,40 +30,50 @@ const ChartContainer = /*#__PURE__*/React.forwardRef(function ChartContainer(pro
30
30
  plugins,
31
31
  children
32
32
  } = props;
33
- const svgRef = React.useRef(null);
34
- const handleRef = useForkRef(ref, svgRef);
35
33
  const {
36
- seriesFormatters
37
- } = usePluginsMerge(plugins);
38
- useReducedMotion(); // a11y reduce motion (see: https://react-spring.dev/docs/utilities/use-reduced-motion)
39
-
34
+ svgRef,
35
+ handleRef,
36
+ xExtremumGetters,
37
+ yExtremumGetters,
38
+ seriesFormatters,
39
+ colorProcessors
40
+ } = useChartContainerHooks(ref, plugins);
40
41
  return /*#__PURE__*/_jsx(DrawingProvider, {
41
42
  width: width,
42
43
  height: height,
43
44
  margin: margin,
44
45
  svgRef: svgRef,
45
- children: /*#__PURE__*/_jsx(SeriesContextProvider, {
46
- series: series,
47
- colors: colors,
48
- dataset: dataset,
49
- seriesFormatters: seriesFormatters,
50
- children: /*#__PURE__*/_jsx(CartesianContextProvider, {
51
- xAxis: xAxis,
52
- yAxis: yAxis,
46
+ children: /*#__PURE__*/_jsx(ColorProvider, {
47
+ colorProcessors: colorProcessors,
48
+ children: /*#__PURE__*/_jsx(SeriesContextProvider, {
49
+ series: series,
50
+ colors: colors,
53
51
  dataset: dataset,
54
- children: /*#__PURE__*/_jsx(InteractionProvider, {
55
- children: /*#__PURE__*/_jsx(HighlightedProvider, {
56
- highlightedItem: highlightedItem,
57
- onHighlightChange: onHighlightChange,
58
- children: /*#__PURE__*/_jsxs(ChartsSurface, {
59
- width: width,
60
- height: height,
61
- ref: handleRef,
62
- sx: sx,
63
- title: title,
64
- desc: desc,
65
- disableAxisListener: disableAxisListener,
66
- children: [/*#__PURE__*/_jsx(ChartsAxesGradients, {}), children]
52
+ seriesFormatters: seriesFormatters,
53
+ children: /*#__PURE__*/_jsx(CartesianContextProvider, {
54
+ xAxis: xAxis,
55
+ yAxis: yAxis,
56
+ dataset: dataset,
57
+ xExtremumGetters: xExtremumGetters,
58
+ yExtremumGetters: yExtremumGetters,
59
+ children: /*#__PURE__*/_jsx(ZAxisContextProvider, {
60
+ zAxis: zAxis,
61
+ dataset: dataset,
62
+ children: /*#__PURE__*/_jsx(InteractionProvider, {
63
+ children: /*#__PURE__*/_jsx(HighlightedProvider, {
64
+ highlightedItem: highlightedItem,
65
+ onHighlightChange: onHighlightChange,
66
+ children: /*#__PURE__*/_jsxs(ChartsSurface, {
67
+ width: width,
68
+ height: height,
69
+ ref: handleRef,
70
+ sx: sx,
71
+ title: title,
72
+ desc: desc,
73
+ disableAxisListener: disableAxisListener,
74
+ children: [/*#__PURE__*/_jsx(ChartsAxesGradients, {}), children]
75
+ })
76
+ })
67
77
  })
68
78
  })
69
79
  })
@@ -251,6 +261,29 @@ process.env.NODE_ENV !== "production" ? ChartContainer.propTypes = {
251
261
  tickPlacement: PropTypes.oneOf(['end', 'extremities', 'middle', 'start']),
252
262
  tickSize: PropTypes.number,
253
263
  valueFormatter: PropTypes.func
264
+ })),
265
+ /**
266
+ * The configuration of the z-axes.
267
+ */
268
+ zAxis: PropTypes.arrayOf(PropTypes.shape({
269
+ colorMap: PropTypes.oneOfType([PropTypes.shape({
270
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
271
+ type: PropTypes.oneOf(['ordinal']).isRequired,
272
+ unknownColor: PropTypes.string,
273
+ values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
274
+ }), PropTypes.shape({
275
+ color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
276
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
277
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
278
+ type: PropTypes.oneOf(['continuous']).isRequired
279
+ }), PropTypes.shape({
280
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
281
+ thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
282
+ type: PropTypes.oneOf(['piecewise']).isRequired
283
+ })]),
284
+ data: PropTypes.array,
285
+ dataKey: PropTypes.string,
286
+ id: PropTypes.string
254
287
  }))
255
288
  } : void 0;
256
289
  export { ChartContainer };
@@ -0,0 +1,24 @@
1
+ import useForkRef from '@mui/utils/useForkRef';
2
+ import * as React from 'react';
3
+ import { usePluginsMerge } from './usePluginsMerge';
4
+ import { useReducedMotion } from '../hooks/useReducedMotion';
5
+ export const useChartContainerHooks = (ref, plugins) => {
6
+ const svgRef = React.useRef(null);
7
+ const handleRef = useForkRef(ref, svgRef);
8
+ const {
9
+ xExtremumGetters,
10
+ yExtremumGetters,
11
+ seriesFormatters,
12
+ colorProcessors
13
+ } = usePluginsMerge(plugins);
14
+ useReducedMotion(); // a11y reduce motion (see: https://react-spring.dev/docs/utilities/use-reduced-motion)
15
+
16
+ return {
17
+ svgRef,
18
+ handleRef,
19
+ xExtremumGetters,
20
+ yExtremumGetters,
21
+ seriesFormatters,
22
+ colorProcessors
23
+ };
24
+ };
@@ -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 { CartesianContext } from '../context/CartesianContextProvider';
4
+ import { useCartesianContext } from '../context/CartesianProvider';
5
5
  import { ChartsXAxis } from '../ChartsXAxis';
6
6
  import { ChartsYAxis } from '../ChartsYAxis';
7
7
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
@@ -47,7 +47,7 @@ function ChartsAxis(props) {
47
47
  xAxisIds,
48
48
  yAxis,
49
49
  yAxisIds
50
- } = React.useContext(CartesianContext);
50
+ } = useCartesianContext();
51
51
 
52
52
  // TODO: use for plotting line without ticks or any thing
53
53
  // const drawingArea = React.useContext(DrawingContext);
@@ -6,7 +6,7 @@ import generateUtilityClass from '@mui/utils/generateUtilityClass';
6
6
  import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
7
7
  import { styled } from '@mui/material/styles';
8
8
  import { InteractionContext } from '../context/InteractionProvider';
9
- import { CartesianContext } from '../context/CartesianContextProvider';
9
+ import { useCartesianContext } from '../context/CartesianProvider';
10
10
  import { getValueToPositionMapper } from '../hooks/useScale';
11
11
  import { isBandScale } from '../internals/isBandScale';
12
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
@@ -55,7 +55,7 @@ function ChartsAxisHighlight(props) {
55
55
  xAxis,
56
56
  yAxisIds,
57
57
  yAxis
58
- } = React.useContext(CartesianContext);
58
+ } = useCartesianContext();
59
59
  const classes = useUtilityClasses();
60
60
  const USED_X_AXIS_ID = xAxisIds[0];
61
61
  const USED_Y_AXIS_ID = yAxisIds[0];
@@ -5,7 +5,7 @@ import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import composeClasses from '@mui/utils/composeClasses';
7
7
  import { styled, useThemeProps } from '@mui/material/styles';
8
- import { CartesianContext } from '../context/CartesianContextProvider';
8
+ import { useCartesianContext } from '../context/CartesianProvider';
9
9
  import { useTicks } from '../hooks/useTicks';
10
10
  import { getChartsGridUtilityClass, chartsGridClasses } from './chartsGridClasses';
11
11
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
@@ -63,7 +63,7 @@ function ChartsGrid(props) {
63
63
  xAxisIds,
64
64
  yAxis,
65
65
  yAxisIds
66
- } = React.useContext(CartesianContext);
66
+ } = useCartesianContext();
67
67
  const classes = useUtilityClasses(themeProps);
68
68
  const horizontalAxisId = yAxisIds[0];
69
69
  const verticalAxisId = xAxisIds[0];
@@ -1,9 +1,9 @@
1
1
  import * as React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { InteractionContext } from '../context/InteractionProvider';
4
- import { CartesianContext } from '../context/CartesianContextProvider';
5
4
  import { useSeries } from '../hooks/useSeries';
6
5
  import { useSvgRef } from '../hooks';
6
+ import { useCartesianContext } from '../context/CartesianProvider';
7
7
  import { jsx as _jsx } from "react/jsx-runtime";
8
8
  function ChartsOnAxisClickHandler(props) {
9
9
  const {
@@ -19,7 +19,7 @@ function ChartsOnAxisClickHandler(props) {
19
19
  xAxis,
20
20
  yAxisIds,
21
21
  yAxis
22
- } = React.useContext(CartesianContext);
22
+ } = useCartesianContext();
23
23
  React.useEffect(() => {
24
24
  const element = svgRef.current;
25
25
  if (element === null || !onAxisClick) {
@@ -5,6 +5,7 @@ import { useDrawingArea, useXScale } from '../hooks';
5
5
  import { ReferenceLineRoot } from './common';
6
6
  import { ChartsText } from '../ChartsText';
7
7
  import { getReferenceLineUtilityClass } from './chartsReferenceLineClasses';
8
+ import { buildWarning } from '../internals/warning';
8
9
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
9
10
  const getTextParams = ({
10
11
  top,
@@ -46,7 +47,7 @@ export function getXReferenceLineClasses(classes) {
46
47
  label: ['label']
47
48
  }, getReferenceLineUtilityClass, classes);
48
49
  }
49
- let warnedOnce = false;
50
+ const valueError = buildWarning((value, id) => `MUI X Charts: the value ${value} does not exist in the data of x axis with id ${id}.`, 'error');
50
51
  function ChartsXReferenceLine(props) {
51
52
  const {
52
53
  x,
@@ -66,10 +67,7 @@ function ChartsXReferenceLine(props) {
66
67
  const xPosition = xAxisScale(x);
67
68
  if (xPosition === undefined) {
68
69
  if (process.env.NODE_ENV !== 'production') {
69
- if (!warnedOnce) {
70
- warnedOnce = true;
71
- console.error(`MUI X Charts: the value ${x} does not exist in the data of x axis with id ${axisId}.`);
72
- }
70
+ valueError(x, axisId);
73
71
  }
74
72
  return null;
75
73
  }
@@ -5,6 +5,7 @@ import { useDrawingArea, useYScale } from '../hooks';
5
5
  import { ReferenceLineRoot } from './common';
6
6
  import { ChartsText } from '../ChartsText';
7
7
  import { getReferenceLineUtilityClass } from './chartsReferenceLineClasses';
8
+ import { buildWarning } from '../internals/warning';
8
9
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
9
10
  const getTextParams = ({
10
11
  left,
@@ -39,7 +40,6 @@ const getTextParams = ({
39
40
  };
40
41
  }
41
42
  };
42
- let warnedOnce = false;
43
43
  export function getYReferenceLineClasses(classes) {
44
44
  return composeClasses({
45
45
  root: ['root', 'horizontal'],
@@ -47,6 +47,7 @@ export function getYReferenceLineClasses(classes) {
47
47
  label: ['label']
48
48
  }, getReferenceLineUtilityClass, classes);
49
49
  }
50
+ const valueError = buildWarning((value, id) => `MUI X Charts: the value ${value} does not exist in the data of y axis with id ${id}.`, 'error');
50
51
  function ChartsYReferenceLine(props) {
51
52
  const {
52
53
  y,
@@ -66,10 +67,7 @@ function ChartsYReferenceLine(props) {
66
67
  const yPosition = yAxisScale(y);
67
68
  if (yPosition === undefined) {
68
69
  if (process.env.NODE_ENV !== 'production') {
69
- if (!warnedOnce) {
70
- warnedOnce = true;
71
- console.error(`MUI X Charts: the value ${y} does not exist in the data of y axis with id ${axisId}.`);
72
- }
70
+ valueError(y, axisId);
73
71
  }
74
72
  return null;
75
73
  }
@@ -49,10 +49,8 @@ function ChartsText(props) {
49
49
  if (angle) {
50
50
  transforms.push(`rotate(${angle}, ${x}, ${y})`);
51
51
  }
52
- if (transforms.length) {
53
- textProps.transform = transforms.join(' ');
54
- }
55
52
  return /*#__PURE__*/_jsx("text", _extends({}, textProps, {
53
+ transform: transforms.length > 0 ? transforms.join(' ') : undefined,
56
54
  x: x,
57
55
  y: y,
58
56
  textAnchor: textAnchor,
@@ -2,11 +2,11 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
3
  import PropTypes from 'prop-types';
4
4
  import { useSlotProps } from '@mui/base/utils';
5
- import { CartesianContext } from '../context/CartesianContextProvider';
5
+ import { useCartesianContext } from '../context/CartesianProvider';
6
6
  import { DefaultChartsAxisTooltipContent } from './DefaultChartsAxisTooltipContent';
7
- import { isCartesianSeriesType } from '../internals/isCartesian';
8
- import colorGetter from '../internals/colorGetter';
9
7
  import { ZAxisContext } from '../context/ZAxisContextProvider';
8
+ import { useColorProcessor } from '../hooks/useColor';
9
+ import { isCartesianSeriesType } from '../internals/isCartesian';
10
10
  import { useSeries } from '../hooks/useSeries';
11
11
  import { jsx as _jsx } from "react/jsx-runtime";
12
12
  function ChartsAxisTooltipContent(props) {
@@ -25,12 +25,13 @@ function ChartsAxisTooltipContent(props) {
25
25
  xAxis,
26
26
  yAxisIds,
27
27
  yAxis
28
- } = React.useContext(CartesianContext);
28
+ } = useCartesianContext();
29
29
  const {
30
30
  zAxisIds,
31
31
  zAxis
32
32
  } = React.useContext(ZAxisContext);
33
33
  const series = useSeries();
34
+ const colorProcessors = useColorProcessor();
34
35
  const USED_AXIS_ID = isXaxis ? xAxisIds[0] : yAxisIds[0];
35
36
  const relevantSeries = React.useMemo(() => {
36
37
  const rep = [];
@@ -40,15 +41,8 @@ function ChartsAxisTooltipContent(props) {
40
41
  const axisKey = isXaxis ? item.xAxisKey : item.yAxisKey;
41
42
  if (axisKey === undefined || axisKey === USED_AXIS_ID) {
42
43
  const seriesToAdd = series[seriesType].series[seriesId];
43
- let getColor;
44
- switch (seriesToAdd.type) {
45
- case 'scatter':
46
- getColor = colorGetter(seriesToAdd, xAxis[seriesToAdd.xAxisKey ?? xAxisIds[0]], yAxis[seriesToAdd.yAxisKey ?? yAxisIds[0]], zAxis[seriesToAdd.zAxisKey ?? zAxisIds[0]]);
47
- break;
48
- default:
49
- getColor = colorGetter(seriesToAdd, xAxis[seriesToAdd.xAxisKey ?? xAxisIds[0]], yAxis[seriesToAdd.yAxisKey ?? yAxisIds[0]]);
50
- break;
51
- }
44
+ const zAxisKey = seriesToAdd.zAxisKey ?? zAxisIds[0];
45
+ const getColor = colorProcessors[seriesType]?.(seriesToAdd, xAxis[seriesToAdd.xAxisKey ?? xAxisIds[0]], yAxis[seriesToAdd.yAxisKey ?? yAxisIds[0]], zAxisKey && zAxis[zAxisKey]) ?? (() => '');
52
46
  rep.push(_extends({}, seriesToAdd, {
53
47
  getColor
54
48
  }));
@@ -56,7 +50,7 @@ function ChartsAxisTooltipContent(props) {
56
50
  });
57
51
  });
58
52
  return rep;
59
- }, [USED_AXIS_ID, isXaxis, series, xAxis, xAxisIds, yAxis, yAxisIds, zAxis, zAxisIds]);
53
+ }, [USED_AXIS_ID, colorProcessors, isXaxis, series, xAxis, xAxisIds, yAxis, yAxisIds, zAxis, zAxisIds]);
60
54
  const relevantAxis = React.useMemo(() => {
61
55
  return isXaxis ? xAxis[USED_AXIS_ID] : yAxis[USED_AXIS_ID];
62
56
  }, [USED_AXIS_ID, isXaxis, xAxis, yAxis]);
@@ -3,9 +3,9 @@ import * as React from 'react';
3
3
  import PropTypes from 'prop-types';
4
4
  import { useSlotProps } from '@mui/base/utils';
5
5
  import { DefaultChartsItemTooltipContent } from './DefaultChartsItemTooltipContent';
6
- import { CartesianContext } from '../context/CartesianContextProvider';
7
- import colorGetter from '../internals/colorGetter';
6
+ import { useCartesianContext } from '../context/CartesianProvider';
8
7
  import { ZAxisContext } from '../context/ZAxisContextProvider';
8
+ import { useColorProcessor } from '../hooks/useColor';
9
9
  import { useSeries } from '../hooks/useSeries';
10
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
11
  function ChartsItemTooltipContent(props) {
@@ -22,26 +22,16 @@ function ChartsItemTooltipContent(props) {
22
22
  yAxis,
23
23
  xAxisIds,
24
24
  yAxisIds
25
- } = React.useContext(CartesianContext);
25
+ } = useCartesianContext();
26
26
  const {
27
27
  zAxis,
28
28
  zAxisIds
29
29
  } = React.useContext(ZAxisContext);
30
- const defaultXAxisId = xAxisIds[0];
31
- const defaultYAxisId = yAxisIds[0];
32
- const defaultZAxisId = zAxisIds[0];
33
- let getColor;
34
- switch (series.type) {
35
- case 'pie':
36
- getColor = colorGetter(series);
37
- break;
38
- case 'scatter':
39
- getColor = colorGetter(series, xAxis[series.xAxisKey ?? defaultXAxisId], yAxis[series.yAxisKey ?? defaultYAxisId], zAxis[series.zAxisKey ?? defaultZAxisId]);
40
- break;
41
- default:
42
- getColor = colorGetter(series, xAxis[series.xAxisKey ?? defaultXAxisId], yAxis[series.yAxisKey ?? defaultYAxisId]);
43
- break;
44
- }
30
+ const colorProcessors = useColorProcessor();
31
+ const xAxisKey = series.xAxisKey ?? xAxisIds[0];
32
+ const yAxisKey = series.yAxisKey ?? yAxisIds[0];
33
+ const zAxisKey = series.zAxisKey ?? zAxisIds[0];
34
+ const getColor = colorProcessors[series.type]?.(series, xAxisKey && xAxis[xAxisKey], yAxisKey && yAxis[yAxisKey], zAxisKey && zAxis[zAxisKey]) ?? (() => '');
45
35
  const Content = content ?? DefaultChartsItemTooltipContent;
46
36
  const chartTooltipContentProps = useSlotProps({
47
37
  elementType: Content,
@@ -38,7 +38,6 @@ function DefaultChartsAxisTooltipContent(props) {
38
38
  })
39
39
  }), /*#__PURE__*/_jsx("tbody", {
40
40
  children: series.filter(isCartesianSeries).map(({
41
- color,
42
41
  id,
43
42
  label,
44
43
  valueFormatter,
@@ -53,12 +52,13 @@ function DefaultChartsAxisTooltipContent(props) {
53
52
  return null;
54
53
  }
55
54
  const formattedLabel = getLabel(label, 'tooltip');
55
+ const color = getColor(dataIndex);
56
56
  return /*#__PURE__*/_jsxs(ChartsTooltipRow, {
57
57
  className: classes.row,
58
58
  children: [/*#__PURE__*/_jsx(ChartsTooltipCell, {
59
59
  className: clsx(classes.markCell, classes.cell),
60
- children: /*#__PURE__*/_jsx(ChartsTooltipMark, {
61
- color: getColor(dataIndex) ?? color,
60
+ children: color && /*#__PURE__*/_jsx(ChartsTooltipMark, {
61
+ color: color,
62
62
  className: classes.mark
63
63
  })
64
64
  }), /*#__PURE__*/_jsx(ChartsTooltipCell, {
@@ -23,7 +23,7 @@ function DefaultChartsItemTooltipContent(props) {
23
23
  color: getColor(itemData.dataIndex),
24
24
  displayedLabel: getLabel(series.data[itemData.dataIndex].label, 'tooltip')
25
25
  } : {
26
- color: getColor(itemData.dataIndex) ?? series.color,
26
+ color: getColor(itemData.dataIndex),
27
27
  displayedLabel: getLabel(series.label, 'tooltip')
28
28
  };
29
29
  const value = series.type === 'pie' ? _extends({}, series.data[itemData.dataIndex], {
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
3
3
  import { Delaunay } from 'd3-delaunay';
4
4
  import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
5
5
  import { InteractionContext } from '../context/InteractionProvider';
6
- import { CartesianContext } from '../context/CartesianContextProvider';
6
+ import { useCartesianContext } from '../context/CartesianProvider';
7
7
  import { getValueToPositionMapper } from '../hooks/useScale';
8
8
  import { getSVGPoint } from '../internals/utils';
9
9
  import { useDrawingArea, useSvgRef } from '../hooks';
@@ -27,7 +27,7 @@ function ChartsVoronoiHandler(props) {
27
27
  yAxis,
28
28
  xAxisIds,
29
29
  yAxisIds
30
- } = React.useContext(CartesianContext);
30
+ } = useCartesianContext();
31
31
  const {
32
32
  dispatch
33
33
  } = React.useContext(InteractionContext);