@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
@@ -1,13 +1,11 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
- import useId from '@mui/utils/useId';
4
3
  import PropTypes from 'prop-types';
5
4
  import { AreaPlot } from './AreaPlot';
6
5
  import { LinePlot } from './LinePlot';
7
6
  import { ResponsiveChartContainer } from '../ResponsiveChartContainer';
8
7
  import { MarkPlot } from './MarkPlot';
9
8
  import { ChartsAxis } from '../ChartsAxis/ChartsAxis';
10
- import { DEFAULT_X_AXIS_KEY } from '../constants';
11
9
  import { ChartsTooltip } from '../ChartsTooltip';
12
10
  import { ChartsLegend } from '../ChartsLegend';
13
11
  import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
@@ -15,7 +13,8 @@ import { ChartsClipPath } from '../ChartsClipPath';
15
13
  import { LineHighlightPlot } from './LineHighlightPlot';
16
14
  import { ChartsGrid } from '../ChartsGrid';
17
15
  import { ChartsOnAxisClickHandler } from '../ChartsOnAxisClickHandler';
18
- import { ChartsOverlay } from '../ChartsOverlay/ChartsOverlay';
16
+ import { ChartsOverlay } from '../ChartsOverlay';
17
+ import { useLineChartProps } from './useLineChartProps';
19
18
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
20
19
  /**
21
20
  * Demos:
@@ -29,110 +28,29 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
29
28
  */
30
29
  const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
31
30
  const {
32
- xAxis,
33
- yAxis,
34
- series,
35
- width,
36
- height,
37
- margin,
38
- colors,
39
- dataset,
40
- sx,
41
- tooltip,
42
- onAxisClick,
43
- onAreaClick,
44
- onLineClick,
45
- onMarkClick,
46
- axisHighlight = {
47
- x: 'line'
48
- },
49
- disableLineItemHighlight,
50
- legend,
51
- grid,
52
- topAxis,
53
- leftAxis,
54
- rightAxis,
55
- bottomAxis,
56
- children,
57
- slots,
58
- slotProps,
59
- skipAnimation,
60
- loading,
61
- highlightedItem,
62
- onHighlightChange
63
- } = props;
64
- const id = useId();
65
- const clipPathId = `${id}-clip-path`;
66
- return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
67
- ref: ref,
68
- series: series.map(s => _extends({
69
- disableHighlight: !!disableLineItemHighlight,
70
- type: 'line'
71
- }, s)),
72
- width: width,
73
- height: height,
74
- margin: margin,
75
- xAxis: xAxis ?? [{
76
- id: DEFAULT_X_AXIS_KEY,
77
- scaleType: 'point',
78
- data: Array.from({
79
- length: Math.max(...series.map(s => (s.data ?? dataset ?? []).length))
80
- }, (_, index) => index)
81
- }],
82
- yAxis: yAxis,
83
- colors: colors,
84
- dataset: dataset,
85
- sx: sx,
86
- disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none' && !onAxisClick,
87
- highlightedItem: highlightedItem,
88
- onHighlightChange: onHighlightChange,
89
- children: [onAxisClick && /*#__PURE__*/_jsx(ChartsOnAxisClickHandler, {
90
- onAxisClick: onAxisClick
91
- }), grid && /*#__PURE__*/_jsx(ChartsGrid, {
92
- vertical: grid.vertical,
93
- horizontal: grid.horizontal
94
- }), /*#__PURE__*/_jsxs("g", {
95
- clipPath: `url(#${clipPathId})`,
96
- children: [/*#__PURE__*/_jsx(AreaPlot, {
97
- slots: slots,
98
- slotProps: slotProps,
99
- onItemClick: onAreaClick,
100
- skipAnimation: skipAnimation
101
- }), /*#__PURE__*/_jsx(LinePlot, {
102
- slots: slots,
103
- slotProps: slotProps,
104
- onItemClick: onLineClick,
105
- skipAnimation: skipAnimation
106
- }), /*#__PURE__*/_jsx(ChartsOverlay, {
107
- loading: loading,
108
- slots: slots,
109
- slotProps: slotProps
110
- })]
111
- }), /*#__PURE__*/_jsx(ChartsAxis, {
112
- topAxis: topAxis,
113
- leftAxis: leftAxis,
114
- rightAxis: rightAxis,
115
- bottomAxis: bottomAxis,
116
- slots: slots,
117
- slotProps: slotProps
118
- }), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlight)), /*#__PURE__*/_jsx(MarkPlot, {
119
- slots: slots,
120
- slotProps: slotProps,
121
- onItemClick: onMarkClick,
122
- skipAnimation: skipAnimation
123
- }), /*#__PURE__*/_jsx(LineHighlightPlot, {
124
- slots: slots,
125
- slotProps: slotProps
126
- }), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legend, {
127
- slots: slots,
128
- slotProps: slotProps
129
- })), !loading && /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip, {
130
- slots: slots,
131
- slotProps: slotProps
132
- })), /*#__PURE__*/_jsx(ChartsClipPath, {
133
- id: clipPathId
134
- }), children]
135
- });
31
+ chartContainerProps,
32
+ axisClickHandlerProps,
33
+ gridProps,
34
+ clipPathProps,
35
+ clipPathGroupProps,
36
+ areaPlotProps,
37
+ linePlotProps,
38
+ markPlotProps,
39
+ overlayProps,
40
+ chartsAxisProps,
41
+ axisHighlightProps,
42
+ lineHighlightPlotProps,
43
+ legendProps,
44
+ tooltipProps,
45
+ children
46
+ } = useLineChartProps(props);
47
+ return /*#__PURE__*/_jsxs(ResponsiveChartContainer, _extends({
48
+ ref: ref
49
+ }, chartContainerProps, {
50
+ children: [props.onAxisClick && /*#__PURE__*/_jsx(ChartsOnAxisClickHandler, _extends({}, axisClickHandlerProps)), props.grid && /*#__PURE__*/_jsx(ChartsGrid, _extends({}, gridProps)), /*#__PURE__*/_jsxs("g", _extends({}, clipPathGroupProps, {
51
+ children: [/*#__PURE__*/_jsx(AreaPlot, _extends({}, areaPlotProps)), /*#__PURE__*/_jsx(LinePlot, _extends({}, linePlotProps)), /*#__PURE__*/_jsx(ChartsOverlay, _extends({}, overlayProps))]
52
+ })), /*#__PURE__*/_jsx(ChartsAxis, _extends({}, chartsAxisProps)), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlightProps)), /*#__PURE__*/_jsx(MarkPlot, _extends({}, markPlotProps)), /*#__PURE__*/_jsx(LineHighlightPlot, _extends({}, lineHighlightPlotProps)), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legendProps)), !props.loading && /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltipProps)), /*#__PURE__*/_jsx(ChartsClipPath, _extends({}, clipPathProps)), children]
53
+ }));
136
54
  });
137
55
  process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
138
56
  // ----------------------------- Warning --------------------------------
@@ -3,7 +3,7 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWith
3
3
  const _excluded = ["slots", "slotProps"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
- import { CartesianContext } from '../context/CartesianContextProvider';
6
+ import { useCartesianContext } from '../context/CartesianProvider';
7
7
  import { LineHighlightElement } from './LineHighlightElement';
8
8
  import { getValueToPositionMapper } from '../hooks/useScale';
9
9
  import { InteractionContext } from '../context/InteractionProvider';
@@ -28,7 +28,7 @@ function LineHighlightPlot(props) {
28
28
  } = props,
29
29
  other = _objectWithoutPropertiesLoose(props, _excluded);
30
30
  const seriesData = useLineSeries();
31
- const axisData = React.useContext(CartesianContext);
31
+ const axisData = useCartesianContext();
32
32
  const {
33
33
  axis
34
34
  } = React.useContext(InteractionContext);
@@ -4,7 +4,7 @@ const _excluded = ["slots", "slotProps", "skipAnimation", "onItemClick"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import { line as d3Line } from 'd3-shape';
7
- import { CartesianContext } from '../context/CartesianContextProvider';
7
+ import { useCartesianContext } from '../context/CartesianProvider';
8
8
  import { LineElement } from './LineElement';
9
9
  import { getValueToPositionMapper } from '../hooks/useScale';
10
10
  import getCurveFactory from '../internals/getCurve';
@@ -14,7 +14,7 @@ import { useLineSeries } from '../hooks/useSeries';
14
14
  import { jsx as _jsx } from "react/jsx-runtime";
15
15
  const useAggregatedData = () => {
16
16
  const seriesData = useLineSeries();
17
- const axisData = React.useContext(CartesianContext);
17
+ const axisData = useCartesianContext();
18
18
  if (seriesData === undefined) {
19
19
  return [];
20
20
  }
@@ -3,7 +3,7 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWith
3
3
  const _excluded = ["slots", "slotProps", "skipAnimation", "onItemClick"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
- import { CartesianContext } from '../context/CartesianContextProvider';
6
+ import { useCartesianContext } from '../context/CartesianProvider';
7
7
  import { MarkElement } from './MarkElement';
8
8
  import { getValueToPositionMapper } from '../hooks/useScale';
9
9
  import { useChartId } from '../hooks/useChartId';
@@ -31,7 +31,7 @@ function MarkPlot(props) {
31
31
  } = props,
32
32
  other = _objectWithoutPropertiesLoose(props, _excluded);
33
33
  const seriesData = useLineSeries();
34
- const axisData = React.useContext(CartesianContext);
34
+ const axisData = useCartesianContext();
35
35
  const chartId = useChartId();
36
36
  const Mark = slots?.mark ?? MarkElement;
37
37
  if (seriesData === undefined) {
@@ -0,0 +1,144 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import useId from '@mui/utils/useId';
3
+ import { DEFAULT_X_AXIS_KEY } from '../constants';
4
+ /**
5
+ * A helper function that extracts LineChartProps from the input props
6
+ * and returns an object with props for the children components of LineChart.
7
+ *
8
+ * @param props The input props for LineChart
9
+ * @returns An object with props for the children components of LineChart
10
+ */
11
+ export const useLineChartProps = props => {
12
+ const {
13
+ xAxis,
14
+ yAxis,
15
+ series,
16
+ width,
17
+ height,
18
+ margin,
19
+ colors,
20
+ dataset,
21
+ sx,
22
+ tooltip,
23
+ onAxisClick,
24
+ onAreaClick,
25
+ onLineClick,
26
+ onMarkClick,
27
+ axisHighlight,
28
+ disableLineItemHighlight,
29
+ legend,
30
+ grid,
31
+ topAxis,
32
+ leftAxis,
33
+ rightAxis,
34
+ bottomAxis,
35
+ children,
36
+ slots,
37
+ slotProps,
38
+ skipAnimation,
39
+ loading,
40
+ highlightedItem,
41
+ onHighlightChange
42
+ } = props;
43
+ const id = useId();
44
+ const clipPathId = `${id}-clip-path`;
45
+ const chartContainerProps = {
46
+ series: series.map(s => _extends({
47
+ disableHighlight: !!disableLineItemHighlight,
48
+ type: 'line'
49
+ }, s)),
50
+ width,
51
+ height,
52
+ margin,
53
+ colors,
54
+ dataset,
55
+ xAxis: xAxis ?? [{
56
+ id: DEFAULT_X_AXIS_KEY,
57
+ scaleType: 'point',
58
+ data: Array.from({
59
+ length: Math.max(...series.map(s => (s.data ?? dataset ?? []).length))
60
+ }, (_, index) => index)
61
+ }],
62
+ yAxis,
63
+ sx,
64
+ highlightedItem,
65
+ onHighlightChange,
66
+ disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none' && !onAxisClick
67
+ };
68
+ const axisClickHandlerProps = {
69
+ onAxisClick
70
+ };
71
+ const gridProps = {
72
+ vertical: grid?.vertical,
73
+ horizontal: grid?.horizontal
74
+ };
75
+ const clipPathGroupProps = {
76
+ clipPath: `url(#${clipPathId})`
77
+ };
78
+ const clipPathProps = {
79
+ id: clipPathId
80
+ };
81
+ const areaPlotProps = {
82
+ slots,
83
+ slotProps,
84
+ onAreaClick,
85
+ skipAnimation
86
+ };
87
+ const linePlotProps = {
88
+ slots,
89
+ slotProps,
90
+ onLineClick,
91
+ skipAnimation
92
+ };
93
+ const markPlotProps = {
94
+ slots,
95
+ slotProps,
96
+ onMarkClick,
97
+ skipAnimation
98
+ };
99
+ const overlayProps = {
100
+ slots,
101
+ slotProps,
102
+ loading
103
+ };
104
+ const chartsAxisProps = {
105
+ topAxis,
106
+ leftAxis,
107
+ rightAxis,
108
+ bottomAxis,
109
+ slots,
110
+ slotProps
111
+ };
112
+ const axisHighlightProps = _extends({
113
+ x: 'line'
114
+ }, axisHighlight);
115
+ const lineHighlightPlotProps = {
116
+ slots,
117
+ slotProps
118
+ };
119
+ const legendProps = _extends({}, legend, {
120
+ slots,
121
+ slotProps
122
+ });
123
+ const tooltipProps = _extends({}, tooltip, {
124
+ slots,
125
+ slotProps
126
+ });
127
+ return {
128
+ chartContainerProps,
129
+ axisClickHandlerProps,
130
+ gridProps,
131
+ clipPathProps,
132
+ clipPathGroupProps,
133
+ areaPlotProps,
134
+ linePlotProps,
135
+ markPlotProps,
136
+ overlayProps,
137
+ chartsAxisProps,
138
+ axisHighlightProps,
139
+ lineHighlightPlotProps,
140
+ legendProps,
141
+ tooltipProps,
142
+ children
143
+ };
144
+ };
@@ -9,7 +9,7 @@ import { ChartsLegend } from '../ChartsLegend';
9
9
  import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
10
10
  import { PiePlot } from './PiePlot';
11
11
  import { useIsRTL } from '../internals/useIsRTL';
12
- import { ChartsOverlay } from '../ChartsOverlay/ChartsOverlay';
12
+ import { ChartsOverlay } from '../ChartsOverlay';
13
13
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
14
  const defaultMargin = {
15
15
  top: 5,
@@ -0,0 +1,26 @@
1
+ import { styled } from '@mui/material/styles';
2
+ /**
3
+ * Wrapping div that take the shape of its parent.
4
+ *
5
+ * @ignore - do not document.
6
+ */
7
+ export const ResizableContainer = styled('div', {
8
+ name: 'MuiResponsiveChart',
9
+ slot: 'Container'
10
+ })(({
11
+ ownerState
12
+ }) => ({
13
+ width: ownerState.width ?? '100%',
14
+ height: ownerState.height ?? '100%',
15
+ display: 'flex',
16
+ position: 'relative',
17
+ flexGrow: 1,
18
+ flexDirection: 'column',
19
+ alignItems: 'center',
20
+ justifyContent: 'center',
21
+ overflow: 'hidden',
22
+ '&>svg': {
23
+ width: '100%',
24
+ height: '100%'
25
+ }
26
+ }));
@@ -3,30 +3,10 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWith
3
3
  const _excluded = ["width", "height"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
- import { styled } from '@mui/material/styles';
7
6
  import { ChartContainer } from '../ChartContainer';
8
7
  import { useChartContainerDimensions } from './useChartContainerDimensions';
8
+ import { ResizableContainer } from './ResizableContainer';
9
9
  import { jsx as _jsx } from "react/jsx-runtime";
10
- const ResizableContainer = styled('div', {
11
- name: 'MuiResponsiveChart',
12
- slot: 'Container'
13
- })(({
14
- ownerState
15
- }) => ({
16
- width: ownerState.width ?? '100%',
17
- height: ownerState.height ?? '100%',
18
- display: 'flex',
19
- position: 'relative',
20
- flexGrow: 1,
21
- flexDirection: 'column',
22
- alignItems: 'center',
23
- justifyContent: 'center',
24
- overflow: 'hidden',
25
- '&>svg': {
26
- width: '100%',
27
- height: '100%'
28
- }
29
- }));
30
10
  const ResponsiveChartContainer = /*#__PURE__*/React.forwardRef(function ResponsiveChartContainer(props, ref) {
31
11
  const {
32
12
  width: inWidth,
@@ -227,6 +207,29 @@ process.env.NODE_ENV !== "production" ? ResponsiveChartContainer.propTypes = {
227
207
  tickPlacement: PropTypes.oneOf(['end', 'extremities', 'middle', 'start']),
228
208
  tickSize: PropTypes.number,
229
209
  valueFormatter: PropTypes.func
210
+ })),
211
+ /**
212
+ * The configuration of the z-axes.
213
+ */
214
+ zAxis: PropTypes.arrayOf(PropTypes.shape({
215
+ colorMap: PropTypes.oneOfType([PropTypes.shape({
216
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
217
+ type: PropTypes.oneOf(['ordinal']).isRequired,
218
+ unknownColor: PropTypes.string,
219
+ values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
220
+ }), PropTypes.shape({
221
+ color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
222
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
223
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
224
+ type: PropTypes.oneOf(['continuous']).isRequired
225
+ }), PropTypes.shape({
226
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
227
+ thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
228
+ type: PropTypes.oneOf(['piecewise']).isRequired
229
+ })]),
230
+ data: PropTypes.array,
231
+ dataKey: PropTypes.string,
232
+ id: PropTypes.string
230
233
  }))
231
234
  } : void 0;
232
235
  export { ResponsiveChartContainer };
@@ -6,11 +6,12 @@ import { ResponsiveChartContainer } from '../ResponsiveChartContainer';
6
6
  import { ChartsAxis } from '../ChartsAxis';
7
7
  import { ChartsTooltip } from '../ChartsTooltip';
8
8
  import { ChartsLegend } from '../ChartsLegend';
9
- import { ChartsOverlay } from '../ChartsOverlay/ChartsOverlay';
9
+ import { ChartsOverlay } from '../ChartsOverlay';
10
10
  import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
11
11
  import { ChartsVoronoiHandler } from '../ChartsVoronoiHandler/ChartsVoronoiHandler';
12
12
  import { ChartsGrid } from '../ChartsGrid';
13
13
  import { ZAxisContextProvider } from '../context/ZAxisContextProvider';
14
+ import { useScatterChartProps } from './useScatterChartProps';
14
15
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
15
16
  /**
16
17
  * Demos:
@@ -24,81 +25,25 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
24
25
  */
25
26
  const ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props, ref) {
26
27
  const {
27
- xAxis,
28
- yAxis,
29
- zAxis,
30
- series,
31
- tooltip,
32
- axisHighlight,
33
- voronoiMaxRadius,
34
- disableVoronoi,
35
- legend,
36
- width,
37
- height,
38
- margin,
39
- colors,
40
- sx,
41
- grid,
42
- topAxis,
43
- leftAxis,
44
- rightAxis,
45
- bottomAxis,
46
- onItemClick,
47
- children,
48
- slots,
49
- slotProps,
50
- loading,
51
- highlightedItem,
52
- onHighlightChange
53
- } = props;
54
- return /*#__PURE__*/_jsx(ResponsiveChartContainer, {
55
- ref: ref,
56
- series: series.map(s => _extends({
57
- type: 'scatter'
58
- }, s)),
59
- width: width,
60
- height: height,
61
- margin: margin,
62
- colors: colors,
63
- xAxis: xAxis,
64
- yAxis: yAxis,
65
- sx: sx,
66
- highlightedItem: highlightedItem,
67
- onHighlightChange: onHighlightChange,
68
- children: /*#__PURE__*/_jsxs(ZAxisContextProvider, {
69
- zAxis: zAxis,
70
- children: [!disableVoronoi && /*#__PURE__*/_jsx(ChartsVoronoiHandler, {
71
- voronoiMaxRadius: voronoiMaxRadius,
72
- onItemClick: onItemClick
73
- }), /*#__PURE__*/_jsx(ChartsAxis, {
74
- topAxis: topAxis,
75
- leftAxis: leftAxis,
76
- rightAxis: rightAxis,
77
- bottomAxis: bottomAxis,
78
- slots: slots,
79
- slotProps: slotProps
80
- }), grid && /*#__PURE__*/_jsx(ChartsGrid, {
81
- vertical: grid.vertical,
82
- horizontal: grid.horizontal
83
- }), /*#__PURE__*/_jsx(ScatterPlot, {
84
- slots: slots,
85
- slotProps: slotProps,
86
- onItemClick: disableVoronoi ? onItemClick : undefined
87
- }), /*#__PURE__*/_jsx(ChartsOverlay, {
88
- loading: loading,
89
- slots: slots,
90
- slotProps: slotProps
91
- }), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legend, {
92
- slots: slots,
93
- slotProps: slotProps
94
- })), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({
95
- x: "none",
96
- y: "none"
97
- }, axisHighlight)), !loading && /*#__PURE__*/_jsx(ChartsTooltip, _extends({
98
- trigger: "item"
99
- }, tooltip)), children]
100
- })
101
- });
28
+ chartContainerProps,
29
+ zAxisProps,
30
+ voronoiHandlerProps,
31
+ chartsAxisProps,
32
+ gridProps,
33
+ scatterPlotProps,
34
+ overlayProps,
35
+ legendProps,
36
+ axisHighlightProps,
37
+ tooltipProps,
38
+ children
39
+ } = useScatterChartProps(props);
40
+ return /*#__PURE__*/_jsx(ResponsiveChartContainer, _extends({
41
+ ref: ref
42
+ }, chartContainerProps, {
43
+ children: /*#__PURE__*/_jsxs(ZAxisContextProvider, _extends({}, zAxisProps, {
44
+ children: [!props.disableVoronoi && /*#__PURE__*/_jsx(ChartsVoronoiHandler, _extends({}, voronoiHandlerProps)), /*#__PURE__*/_jsx(ChartsAxis, _extends({}, chartsAxisProps)), props.grid && /*#__PURE__*/_jsx(ChartsGrid, _extends({}, gridProps)), /*#__PURE__*/_jsx(ScatterPlot, _extends({}, scatterPlotProps)), /*#__PURE__*/_jsx(ChartsOverlay, _extends({}, overlayProps)), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legendProps)), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlightProps)), !props.loading && /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltipProps)), children]
45
+ }))
46
+ }));
102
47
  });
103
48
  process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
104
49
  // ----------------------------- Warning --------------------------------
@@ -2,7 +2,7 @@ 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 { Scatter } from './Scatter';
5
- import { CartesianContext } from '../context/CartesianContextProvider';
5
+ import { useCartesianContext } from '../context/CartesianProvider';
6
6
  import getColor from './getColor';
7
7
  import { ZAxisContext } from '../context/ZAxisContextProvider';
8
8
  import { useScatterSeries } from '../hooks/useSeries';
@@ -24,7 +24,7 @@ function ScatterPlot(props) {
24
24
  onItemClick
25
25
  } = props;
26
26
  const seriesData = useScatterSeries();
27
- const axisData = React.useContext(CartesianContext);
27
+ const axisData = useCartesianContext();
28
28
  const {
29
29
  zAxis,
30
30
  zAxisIds