@mui/x-charts 7.22.2 → 8.0.0-alpha.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 (189) hide show
  1. package/BarChart/BarChart.d.ts +7 -7
  2. package/BarChart/BarChart.js +7 -29
  3. package/BarChart/BarElement.d.ts +1 -1
  4. package/BarChart/BarLabel/BarLabelItem.d.ts +1 -1
  5. package/BarChart/BarPlot.js +12 -4
  6. package/BarChart/extremums.js +3 -3
  7. package/BarChart/useBarChartProps.d.ts +2 -2
  8. package/BarChart/useBarChartProps.js +3 -4
  9. package/CHANGELOG.md +142 -155
  10. package/ChartContainer/ChartContainer.d.ts +16 -33
  11. package/ChartContainer/ChartContainer.js +22 -41
  12. package/{ResponsiveChartContainer → ChartContainer}/ResizableContainer.d.ts +2 -2
  13. package/{ResponsiveChartContainer → ChartContainer}/useChartContainerDimensions.d.ts +1 -1
  14. package/{ResponsiveChartContainer → ChartContainer}/useChartContainerDimensions.js +6 -4
  15. package/ChartContainer/useChartContainerProps.d.ts +11 -94
  16. package/ChartContainer/useChartContainerProps.js +42 -58
  17. package/ChartsLegend/ChartsLegend.js +0 -3
  18. package/ChartsLegend/DefaultChartsLegend.d.ts +0 -5
  19. package/ChartsLegend/DefaultChartsLegend.js +1 -12
  20. package/ChartsLegend/LegendPerItem.d.ts +1 -1
  21. package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +2 -2
  22. package/ChartsOverlay/ChartsOverlay.d.ts +1 -1
  23. package/ChartsTooltip/ChartsAxisTooltipContent.js +3 -3
  24. package/ChartsTooltip/ChartsItemTooltipContent.js +3 -3
  25. package/ChartsTooltip/ChartsTooltip.js +45 -6
  26. package/ChartsTooltip/useAxisTooltip.js +3 -3
  27. package/ChartsTooltip/useItemTooltip.js +3 -3
  28. package/ChartsTooltip/utils.d.ts +5 -13
  29. package/ChartsTooltip/utils.js +45 -42
  30. package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +3 -5
  31. package/Gauge/GaugeContainer.js +1 -1
  32. package/LineChart/AreaElement.d.ts +1 -1
  33. package/LineChart/AreaPlot.js +2 -6
  34. package/LineChart/LineChart.d.ts +7 -7
  35. package/LineChart/LineChart.js +7 -29
  36. package/LineChart/LineElement.d.ts +1 -1
  37. package/LineChart/LineHighlightPlot.d.ts +1 -1
  38. package/LineChart/LineHighlightPlot.js +2 -6
  39. package/LineChart/LinePlot.js +2 -6
  40. package/LineChart/MarkPlot.js +2 -6
  41. package/LineChart/extremums.js +10 -6
  42. package/LineChart/useLineChartProps.d.ts +2 -2
  43. package/LineChart/useLineChartProps.js +3 -4
  44. package/PieChart/PieArc.d.ts +0 -5
  45. package/PieChart/PieArc.js +1 -10
  46. package/PieChart/PieArcPlot.js +0 -5
  47. package/PieChart/PieChart.d.ts +9 -32
  48. package/PieChart/PieChart.js +17 -102
  49. package/README.md +2 -2
  50. package/ScatterChart/ScatterChart.d.ts +7 -7
  51. package/ScatterChart/ScatterChart.js +7 -29
  52. package/ScatterChart/ScatterPlot.js +3 -6
  53. package/ScatterChart/extremums.js +6 -6
  54. package/ScatterChart/useScatterChartProps.d.ts +2 -2
  55. package/ScatterChart/useScatterChartProps.js +3 -4
  56. package/SparkLineChart/SparkLineChart.d.ts +4 -4
  57. package/SparkLineChart/SparkLineChart.js +2 -2
  58. package/context/CartesianProvider/defaultizeAxis.d.ts +1 -1
  59. package/context/ChartDataProvider/ChartDataProvider.d.ts +41 -0
  60. package/{ResponsiveChartContainer/ResponsiveChartContainer.js → context/ChartDataProvider/ChartDataProvider.js} +46 -27
  61. package/context/ChartDataProvider/index.d.ts +1 -0
  62. package/context/ChartDataProvider/index.js +1 -0
  63. package/context/ChartDataProvider/useChartDataProviderProps.d.ts +97 -0
  64. package/context/ChartDataProvider/useChartDataProviderProps.js +86 -0
  65. package/{ChartContainer → context/ChartDataProvider}/useDefaultizeAxis.d.ts +12 -12
  66. package/{ChartContainer → context/ChartDataProvider}/useDefaultizeAxis.js +1 -1
  67. package/context/HighlightedProvider/HighlightedContext.d.ts +0 -8
  68. package/context/HighlightedProvider/HighlightedProvider.js +1 -16
  69. package/context/PluginProvider/ExtremumGetter.types.d.ts +2 -2
  70. package/context/ZAxisContextProvider.d.ts +1 -1
  71. package/index.d.ts +1 -2
  72. package/index.js +2 -3
  73. package/internals/defaultizeColor.d.ts +1 -8
  74. package/internals/getSymbol.js +19 -3
  75. package/internals/index.d.ts +5 -5
  76. package/internals/index.js +5 -5
  77. package/internals/useStringInterpolator.js +1 -0
  78. package/models/seriesType/bar.d.ts +1 -1
  79. package/models/seriesType/common.d.ts +0 -10
  80. package/models/seriesType/config.d.ts +1 -1
  81. package/models/seriesType/line.d.ts +1 -1
  82. package/models/seriesType/pie.d.ts +1 -1
  83. package/models/seriesType/scatter.d.ts +1 -6
  84. package/modern/BarChart/BarChart.js +7 -29
  85. package/modern/BarChart/BarPlot.js +12 -4
  86. package/modern/BarChart/extremums.js +3 -3
  87. package/modern/BarChart/useBarChartProps.js +3 -4
  88. package/modern/ChartContainer/ChartContainer.js +22 -41
  89. package/modern/{ResponsiveChartContainer → ChartContainer}/useChartContainerDimensions.js +6 -4
  90. package/modern/ChartContainer/useChartContainerProps.js +42 -58
  91. package/modern/ChartsLegend/ChartsLegend.js +0 -3
  92. package/modern/ChartsLegend/DefaultChartsLegend.js +1 -12
  93. package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +2 -2
  94. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +3 -3
  95. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +3 -3
  96. package/modern/ChartsTooltip/ChartsTooltip.js +45 -6
  97. package/modern/ChartsTooltip/useAxisTooltip.js +3 -3
  98. package/modern/ChartsTooltip/useItemTooltip.js +3 -3
  99. package/modern/ChartsTooltip/utils.js +45 -42
  100. package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +3 -5
  101. package/modern/Gauge/GaugeContainer.js +1 -1
  102. package/modern/LineChart/AreaPlot.js +2 -6
  103. package/modern/LineChart/LineChart.js +7 -29
  104. package/modern/LineChart/LineHighlightPlot.js +2 -6
  105. package/modern/LineChart/LinePlot.js +2 -6
  106. package/modern/LineChart/MarkPlot.js +2 -6
  107. package/modern/LineChart/extremums.js +10 -6
  108. package/modern/LineChart/useLineChartProps.js +3 -4
  109. package/modern/PieChart/PieArc.js +1 -10
  110. package/modern/PieChart/PieArcPlot.js +0 -5
  111. package/modern/PieChart/PieChart.js +17 -102
  112. package/modern/ScatterChart/ScatterChart.js +7 -29
  113. package/modern/ScatterChart/ScatterPlot.js +3 -6
  114. package/modern/ScatterChart/extremums.js +6 -6
  115. package/modern/ScatterChart/useScatterChartProps.js +3 -4
  116. package/modern/SparkLineChart/SparkLineChart.js +2 -2
  117. package/modern/{ResponsiveChartContainer/ResponsiveChartContainer.js → context/ChartDataProvider/ChartDataProvider.js} +46 -27
  118. package/modern/context/ChartDataProvider/index.js +1 -0
  119. package/modern/context/ChartDataProvider/useChartDataProviderProps.js +86 -0
  120. package/modern/{ChartContainer → context/ChartDataProvider}/useDefaultizeAxis.js +1 -1
  121. package/modern/context/HighlightedProvider/HighlightedProvider.js +1 -16
  122. package/modern/index.js +2 -3
  123. package/modern/internals/getSymbol.js +19 -3
  124. package/modern/internals/index.js +5 -5
  125. package/modern/internals/useStringInterpolator.js +1 -0
  126. package/node/BarChart/BarChart.js +7 -29
  127. package/node/BarChart/BarPlot.js +11 -3
  128. package/node/BarChart/extremums.js +3 -3
  129. package/node/BarChart/useBarChartProps.js +3 -4
  130. package/node/ChartContainer/ChartContainer.js +21 -40
  131. package/node/{ResponsiveChartContainer → ChartContainer}/useChartContainerDimensions.js +6 -4
  132. package/node/ChartContainer/useChartContainerProps.js +42 -59
  133. package/node/ChartsLegend/ChartsLegend.js +0 -3
  134. package/node/ChartsLegend/DefaultChartsLegend.js +1 -12
  135. package/node/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +2 -2
  136. package/node/ChartsTooltip/ChartsAxisTooltipContent.js +3 -3
  137. package/node/ChartsTooltip/ChartsItemTooltipContent.js +3 -3
  138. package/node/ChartsTooltip/ChartsTooltip.js +44 -5
  139. package/node/ChartsTooltip/useAxisTooltip.js +3 -3
  140. package/node/ChartsTooltip/useItemTooltip.js +3 -3
  141. package/node/ChartsTooltip/utils.js +46 -44
  142. package/node/ChartsVoronoiHandler/ChartsVoronoiHandler.js +3 -5
  143. package/node/Gauge/GaugeContainer.js +1 -1
  144. package/node/LineChart/AreaPlot.js +2 -6
  145. package/node/LineChart/LineChart.js +7 -29
  146. package/node/LineChart/LineHighlightPlot.js +2 -6
  147. package/node/LineChart/LinePlot.js +2 -6
  148. package/node/LineChart/MarkPlot.js +2 -6
  149. package/node/LineChart/extremums.js +10 -6
  150. package/node/LineChart/useLineChartProps.js +3 -4
  151. package/node/PieChart/PieArc.js +1 -10
  152. package/node/PieChart/PieArcPlot.js +0 -5
  153. package/node/PieChart/PieChart.js +17 -102
  154. package/node/ScatterChart/ScatterChart.js +7 -29
  155. package/node/ScatterChart/ScatterPlot.js +3 -6
  156. package/node/ScatterChart/extremums.js +6 -6
  157. package/node/ScatterChart/useScatterChartProps.js +3 -4
  158. package/node/SparkLineChart/SparkLineChart.js +2 -2
  159. package/node/{ResponsiveChartContainer/ResponsiveChartContainer.js → context/ChartDataProvider/ChartDataProvider.js} +45 -26
  160. package/node/context/ChartDataProvider/index.js +16 -0
  161. package/node/context/ChartDataProvider/useChartDataProviderProps.js +94 -0
  162. package/node/{ChartContainer → context/ChartDataProvider}/useDefaultizeAxis.js +1 -1
  163. package/node/context/HighlightedProvider/HighlightedProvider.js +1 -16
  164. package/node/index.js +5 -16
  165. package/node/internals/getSymbol.js +19 -3
  166. package/node/internals/index.js +37 -29
  167. package/node/internals/useStringInterpolator.js +2 -0
  168. package/package.json +4 -4
  169. package/ResponsiveChartContainer/ResponsiveChartContainer.d.ts +0 -24
  170. package/ResponsiveChartContainer/index.d.ts +0 -1
  171. package/ResponsiveChartContainer/index.js +0 -1
  172. package/ResponsiveChartContainer/package.json +0 -6
  173. package/ResponsiveChartContainer/useResponsiveChartContainerProps.d.ts +0 -19
  174. package/ResponsiveChartContainer/useResponsiveChartContainerProps.js +0 -70
  175. package/internals/SlotComponentPropsFromProps.d.ts +0 -1
  176. package/internals/SlotComponentPropsFromProps.js +0 -1
  177. package/models/helpers.d.ts +0 -3
  178. package/models/helpers.js +0 -1
  179. package/modern/ResponsiveChartContainer/index.js +0 -1
  180. package/modern/ResponsiveChartContainer/useResponsiveChartContainerProps.js +0 -70
  181. package/modern/internals/SlotComponentPropsFromProps.js +0 -1
  182. package/modern/models/helpers.js +0 -1
  183. package/node/ResponsiveChartContainer/index.js +0 -16
  184. package/node/ResponsiveChartContainer/useResponsiveChartContainerProps.js +0 -77
  185. package/node/internals/SlotComponentPropsFromProps.js +0 -5
  186. package/node/models/helpers.js +0 -5
  187. /package/{ResponsiveChartContainer → ChartContainer}/ResizableContainer.js +0 -0
  188. /package/modern/{ResponsiveChartContainer → ChartContainer}/ResizableContainer.js +0 -0
  189. /package/node/{ResponsiveChartContainer → ChartContainer}/ResizableContainer.js +0 -0
@@ -9,7 +9,7 @@ import { useTransition } from '@react-spring/web';
9
9
  import { useCartesianContext } from "../context/CartesianProvider/index.js";
10
10
  import { BarElement } from "./BarElement.js";
11
11
  import getColor from "./getColor.js";
12
- import { useChartId } from "../hooks/index.js";
12
+ import { useChartId, useDrawingArea } from "../hooks/index.js";
13
13
  import { BarClipPath } from "./BarClipPath.js";
14
14
  import { BarLabelPlot } from "./BarLabel/BarLabelPlot.js";
15
15
  import { checkScaleErrors } from "./checkScaleErrors.js";
@@ -51,6 +51,7 @@ const useAggregatedData = () => {
51
51
  seriesOrder: []
52
52
  };
53
53
  const axisData = useCartesianContext();
54
+ const drawingArea = useDrawingArea();
54
55
  const chartId = useChartId();
55
56
  const {
56
57
  series,
@@ -68,9 +69,13 @@ const useAggregatedData = () => {
68
69
  const data = stackingGroups.flatMap(({
69
70
  ids: groupIds
70
71
  }, groupIndex) => {
72
+ const xMin = drawingArea.left;
73
+ const xMax = drawingArea.left + drawingArea.width;
74
+ const yMin = drawingArea.top;
75
+ const yMax = drawingArea.top + drawingArea.height;
71
76
  return groupIds.flatMap(seriesId => {
72
- const xAxisId = series[seriesId].xAxisId ?? series[seriesId].xAxisKey ?? defaultXAxisId;
73
- const yAxisId = series[seriesId].yAxisId ?? series[seriesId].yAxisKey ?? defaultYAxisId;
77
+ const xAxisId = series[seriesId].xAxisId ?? defaultXAxisId;
78
+ const yAxisId = series[seriesId].yAxisId ?? defaultYAxisId;
74
79
  const xAxisConfig = xAxis[xAxisId];
75
80
  const yAxisConfig = yAxis[yAxisId];
76
81
  const verticalLayout = series[seriesId].layout === 'vertical';
@@ -111,6 +116,9 @@ const useAggregatedData = () => {
111
116
  value: series[seriesId].data[dataIndex],
112
117
  maskId: `${chartId}_${stackId || seriesId}_${groupIndex}_${dataIndex}`
113
118
  };
119
+ if (result.x > xMax || result.x + result.width < xMin || result.y > yMax || result.y + result.height < yMin) {
120
+ return null;
121
+ }
114
122
  if (!masks[result.maskId]) {
115
123
  masks[result.maskId] = {
116
124
  id: result.maskId,
@@ -133,7 +141,7 @@ const useAggregatedData = () => {
133
141
  mask.hasNegative = mask.hasNegative || (result.value ?? 0) < 0;
134
142
  mask.hasPositive = mask.hasPositive || (result.value ?? 0) > 0;
135
143
  return result;
136
- });
144
+ }).filter(rectangle => rectangle !== null);
137
145
  });
138
146
  });
139
147
  return {
@@ -36,7 +36,7 @@ const getValueExtremum = direction => params => {
36
36
  isDefaultAxis
37
37
  } = params;
38
38
  return Object.keys(series).filter(seriesId => {
39
- const yAxisId = series[seriesId].yAxisId ?? series[seriesId].yAxisKey;
39
+ const yAxisId = series[seriesId].yAxisId;
40
40
  return yAxisId === axis.id || isDefaultAxis && yAxisId === undefined;
41
41
  }).reduce((acc, seriesId) => {
42
42
  const {
@@ -45,8 +45,8 @@ const getValueExtremum = direction => params => {
45
45
  const filter = getFilters?.({
46
46
  currentAxisId: axis.id,
47
47
  isDefaultAxis,
48
- seriesXAxisId: series[seriesId].xAxisId ?? series[seriesId].xAxisKey,
49
- seriesYAxisId: series[seriesId].yAxisId ?? series[seriesId].yAxisKey
48
+ seriesXAxisId: series[seriesId].xAxisId,
49
+ seriesYAxisId: series[seriesId].yAxisId
50
50
  });
51
51
  const [seriesMin, seriesMax] = stackedData?.reduce((seriesAcc, values, index) => {
52
52
  if (filter && (!filter(createResult(values[0], direction), index) || !filter(createResult(values[1], direction), index))) {
@@ -2,7 +2,7 @@
2
2
 
3
3
  import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
5
- const _excluded = ["xAxis", "yAxis", "series", "width", "height", "margin", "colors", "dataset", "sx", "tooltip", "onAxisClick", "axisHighlight", "legend", "grid", "topAxis", "leftAxis", "rightAxis", "bottomAxis", "children", "slots", "slotProps", "skipAnimation", "loading", "layout", "onItemClick", "highlightedItem", "onHighlightChange", "borderRadius", "barLabel", "className"];
5
+ const _excluded = ["xAxis", "yAxis", "series", "width", "height", "margin", "colors", "dataset", "sx", "tooltip", "onAxisClick", "axisHighlight", "grid", "topAxis", "leftAxis", "rightAxis", "bottomAxis", "children", "slots", "slotProps", "skipAnimation", "loading", "layout", "onItemClick", "highlightedItem", "onHighlightChange", "borderRadius", "barLabel", "className", "hideLegend"];
6
6
  import useId from '@mui/utils/useId';
7
7
  import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from "../constants/index.js";
8
8
  /**
@@ -26,7 +26,6 @@ export const useBarChartProps = props => {
26
26
  tooltip,
27
27
  onAxisClick,
28
28
  axisHighlight,
29
- legend,
30
29
  grid,
31
30
  topAxis,
32
31
  leftAxis,
@@ -117,10 +116,10 @@ export const useBarChartProps = props => {
117
116
  } : {
118
117
  x: 'band'
119
118
  }, axisHighlight);
120
- const legendProps = _extends({}, legend, {
119
+ const legendProps = {
121
120
  slots,
122
121
  slotProps
123
- });
122
+ };
124
123
  const tooltipProps = _extends({}, tooltip, {
125
124
  slots,
126
125
  slotProps
@@ -3,47 +3,18 @@
3
3
  import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
- import { DrawingProvider } from "../context/DrawingProvider.js";
7
- import { SeriesProvider } from "../context/SeriesProvider/index.js";
8
- import { InteractionProvider } from "../context/InteractionProvider.js";
9
- import { ChartsSurface } from "../ChartsSurface/index.js";
10
- import { CartesianProvider } from "../context/CartesianProvider/index.js";
11
- import { ChartsAxesGradients } from "../internals/components/ChartsAxesGradients/index.js";
12
- import { HighlightedProvider, ZAxisContextProvider } from "../context/index.js";
13
- import { PluginProvider } from "../context/PluginProvider/index.js";
6
+ import { ChartDataProvider } from "../context/ChartDataProvider/index.js";
7
+ import { ResizableContainer } from "./ResizableContainer.js";
14
8
  import { useChartContainerProps } from "./useChartContainerProps.js";
15
- import { AnimationProvider } from "../context/AnimationProvider/index.js";
16
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
9
+ import { jsx as _jsx } from "react/jsx-runtime";
17
10
  const ChartContainer = /*#__PURE__*/React.forwardRef(function ChartContainer(props, ref) {
18
11
  const {
19
- children,
20
- drawingProviderProps,
21
- seriesProviderProps,
22
- cartesianProviderProps,
23
- zAxisContextProps,
24
- highlightedProviderProps,
25
- chartsSurfaceProps,
26
- pluginProviderProps,
27
- animationProviderProps
12
+ hasIntrinsicSize,
13
+ chartDataProviderProps,
14
+ resizableChartContainerProps
28
15
  } = useChartContainerProps(props, ref);
29
- return /*#__PURE__*/_jsx(DrawingProvider, _extends({}, drawingProviderProps, {
30
- children: /*#__PURE__*/_jsx(PluginProvider, _extends({}, pluginProviderProps, {
31
- children: /*#__PURE__*/_jsx(SeriesProvider, _extends({}, seriesProviderProps, {
32
- children: /*#__PURE__*/_jsx(CartesianProvider, _extends({}, cartesianProviderProps, {
33
- children: /*#__PURE__*/_jsx(ZAxisContextProvider, _extends({}, zAxisContextProps, {
34
- children: /*#__PURE__*/_jsx(InteractionProvider, {
35
- children: /*#__PURE__*/_jsx(HighlightedProvider, _extends({}, highlightedProviderProps, {
36
- children: /*#__PURE__*/_jsxs(ChartsSurface, _extends({}, chartsSurfaceProps, {
37
- children: [/*#__PURE__*/_jsx(ChartsAxesGradients, {}), /*#__PURE__*/_jsx(AnimationProvider, _extends({}, animationProviderProps, {
38
- children: children
39
- }))]
40
- }))
41
- }))
42
- })
43
- }))
44
- }))
45
- }))
46
- }))
16
+ return /*#__PURE__*/_jsx(ResizableContainer, _extends({}, resizableChartContainerProps, {
17
+ children: hasIntrinsicSize ? /*#__PURE__*/_jsx(ChartDataProvider, _extends({}, chartDataProviderProps)) : null
47
18
  }));
48
19
  });
49
20
  process.env.NODE_ENV !== "production" ? ChartContainer.propTypes = {
@@ -70,9 +41,9 @@ process.env.NODE_ENV !== "production" ? ChartContainer.propTypes = {
70
41
  */
71
42
  disableAxisListener: PropTypes.bool,
72
43
  /**
73
- * The height of the chart in px.
44
+ * The height of the chart in px. If not defined, it takes the height of the parent element.
74
45
  */
75
- height: PropTypes.number.isRequired,
46
+ height: PropTypes.number,
76
47
  /**
77
48
  * The item currently highlighted. Turns highlighting into a controlled prop.
78
49
  */
@@ -103,6 +74,16 @@ process.env.NODE_ENV !== "production" ? ChartContainer.propTypes = {
103
74
  * If not provided, the container supports line, bar, scatter and pie charts.
104
75
  */
105
76
  plugins: PropTypes.arrayOf(PropTypes.object),
77
+ /**
78
+ * The chart will try to wait for the parent container to resolve its size
79
+ * before it renders for the first time.
80
+ *
81
+ * This can be useful in some scenarios where the chart appear to grow after
82
+ * the first render, like when used inside a grid.
83
+ *
84
+ * @default false
85
+ */
86
+ resolveSizeBeforeRender: PropTypes.bool,
106
87
  /**
107
88
  * The array of series to display.
108
89
  * Each type of series has its own specificity.
@@ -123,9 +104,9 @@ process.env.NODE_ENV !== "production" ? ChartContainer.propTypes = {
123
104
  y: PropTypes.number
124
105
  }),
125
106
  /**
126
- * The width of the chart in px.
107
+ * The width of the chart in px. If not defined, it takes the width of the parent element.
127
108
  */
128
- width: PropTypes.number.isRequired,
109
+ width: PropTypes.number,
129
110
  /**
130
111
  * The configuration of the x-axes.
131
112
  * If not provided, a default axis config is used.
@@ -1,9 +1,11 @@
1
1
  'use client';
2
2
 
3
+ /* eslint-disable react-compiler/react-compiler */
3
4
  import * as React from 'react';
4
5
  import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
5
6
  import ownerWindow from '@mui/utils/ownerWindow';
6
7
  export const useChartContainerDimensions = (inWidth, inHeight, resolveSizeBeforeRender) => {
8
+ const hasInSize = inWidth !== undefined && inHeight !== undefined;
7
9
  const stateRef = React.useRef({
8
10
  displayError: false,
9
11
  initialCompute: true,
@@ -40,7 +42,7 @@ export const useChartContainerDimensions = (inWidth, inHeight, resolveSizeBefore
40
42
  // https://github.com/mui/mui-x/issues/13477#issuecomment-2336634785
41
43
  useEnhancedEffect(() => {
42
44
  // computeRun is used to avoid infinite loops.
43
- if (!resolveSizeBeforeRender || !stateRef.current.initialCompute || stateRef.current.computeRun > 20) {
45
+ if (hasInSize || !resolveSizeBeforeRender || !stateRef.current.initialCompute || stateRef.current.computeRun > 20) {
44
46
  return;
45
47
  }
46
48
  const computedSize = computeSize();
@@ -49,9 +51,9 @@ export const useChartContainerDimensions = (inWidth, inHeight, resolveSizeBefore
49
51
  } else if (stateRef.current.initialCompute) {
50
52
  stateRef.current.initialCompute = false;
51
53
  }
52
- }, [width, height, computeSize, resolveSizeBeforeRender]);
54
+ }, [width, height, computeSize, resolveSizeBeforeRender, hasInSize]);
53
55
  useEnhancedEffect(() => {
54
- if (inWidth !== undefined && inHeight !== undefined) {
56
+ if (hasInSize) {
55
57
  return () => {};
56
58
  }
57
59
  computeSize();
@@ -77,7 +79,7 @@ export const useChartContainerDimensions = (inWidth, inHeight, resolveSizeBefore
77
79
  observer.unobserve(elementToObserve);
78
80
  }
79
81
  };
80
- }, [computeSize, inHeight, inWidth]);
82
+ }, [computeSize, hasInSize]);
81
83
  if (process.env.NODE_ENV !== 'production') {
82
84
  if (stateRef.current.displayError && inWidth === undefined && width === 0) {
83
85
  console.error(`MUI X: ChartContainer does not have \`width\` prop, and its container has no \`width\` defined.`);
@@ -2,85 +2,69 @@
2
2
 
3
3
  import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
5
- const _excluded = ["width", "height", "series", "margin", "xAxis", "yAxis", "zAxis", "colors", "dataset", "sx", "title", "desc", "disableAxisListener", "highlightedItem", "onHighlightChange", "plugins", "children", "skipAnimation"];
6
- import * as React from 'react';
7
- import useForkRef from '@mui/utils/useForkRef';
8
- import { useDefaultizeAxis } from "./useDefaultizeAxis.js";
5
+ const _excluded = ["width", "height", "resolveSizeBeforeRender", "margin", "children", "series", "colors", "dataset", "desc", "disableAxisListener", "highlightedItem", "onHighlightChange", "plugins", "sx", "title", "viewBox", "xAxis", "yAxis", "zAxis", "skipAnimation"];
6
+ import { useChartContainerDimensions } from "./useChartContainerDimensions.js";
9
7
  export const useChartContainerProps = (props, ref) => {
10
8
  const {
11
9
  width,
12
10
  height,
13
- series,
11
+ resolveSizeBeforeRender,
14
12
  margin,
15
- xAxis,
16
- yAxis,
17
- zAxis,
13
+ children,
14
+ series,
18
15
  colors,
19
16
  dataset,
20
- sx,
21
- title,
22
17
  desc,
23
18
  disableAxisListener,
24
19
  highlightedItem,
25
20
  onHighlightChange,
26
21
  plugins,
27
- children,
22
+ sx,
23
+ title,
24
+ viewBox,
25
+ xAxis,
26
+ yAxis,
27
+ zAxis,
28
28
  skipAnimation
29
29
  } = props,
30
30
  other = _objectWithoutPropertiesLoose(props, _excluded);
31
- const svgRef = React.useRef(null);
32
- const chartSurfaceRef = useForkRef(ref, svgRef);
33
- const [defaultizedXAxis, defaultizedYAxis] = useDefaultizeAxis(xAxis, yAxis, dataset);
34
- const drawingProviderProps = {
35
- width,
36
- height,
31
+ const {
32
+ containerRef,
33
+ width: dWidth,
34
+ height: dHeight
35
+ } = useChartContainerDimensions(width, height, resolveSizeBeforeRender);
36
+ const resizableChartContainerProps = _extends({}, other, {
37
+ ownerState: {
38
+ width,
39
+ height
40
+ },
41
+ ref: containerRef
42
+ });
43
+ const chartDataProviderProps = {
37
44
  margin,
38
- svgRef
39
- };
40
- const animationProviderProps = {
41
- skipAnimation
42
- };
43
- const pluginProviderProps = {
44
- plugins
45
- };
46
- const seriesProviderProps = {
45
+ children,
47
46
  series,
48
47
  colors,
49
- dataset
50
- };
51
- const cartesianProviderProps = {
52
- xAxis: defaultizedXAxis,
53
- yAxis: defaultizedYAxis,
54
- dataset
55
- };
56
- const zAxisContextProps = {
57
- zAxis,
58
- dataset
59
- };
60
- const highlightedProviderProps = {
48
+ dataset,
49
+ desc,
50
+ disableAxisListener,
61
51
  highlightedItem,
62
- onHighlightChange
63
- };
64
- const chartsSurfaceProps = _extends({}, other, {
65
- width,
66
- height,
67
- ref: chartSurfaceRef,
52
+ onHighlightChange,
53
+ plugins,
68
54
  sx,
69
55
  title,
70
- desc,
71
- disableAxisListener
72
- });
56
+ viewBox,
57
+ xAxis,
58
+ yAxis,
59
+ zAxis,
60
+ skipAnimation,
61
+ width: dWidth,
62
+ height: dHeight,
63
+ ref
64
+ };
73
65
  return {
74
- children,
75
- drawingProviderProps,
76
- seriesProviderProps,
77
- cartesianProviderProps,
78
- zAxisContextProps,
79
- highlightedProviderProps,
80
- chartsSurfaceProps,
81
- pluginProviderProps,
82
- animationProviderProps,
83
- xAxis: defaultizedXAxis,
84
- yAxis: defaultizedYAxis
66
+ hasIntrinsicSize: Boolean(dWidth && dHeight),
67
+ chartDataProviderProps,
68
+ resizableChartContainerProps
85
69
  };
86
70
  };
@@ -11,7 +11,6 @@ import { useThemeProps, useTheme } from '@mui/material/styles';
11
11
  import { getSeriesToDisplay } from "./utils.js";
12
12
  import { getLegendUtilityClass } from "./chartsLegendClasses.js";
13
13
  import { DefaultChartsLegend } from "./DefaultChartsLegend.js";
14
- import { useDrawingArea } from "../hooks/index.js";
15
14
  import { useSeries } from "../hooks/useSeries.js";
16
15
  import { jsx as _jsx } from "react/jsx-runtime";
17
16
  const useUtilityClasses = ownerState => {
@@ -50,7 +49,6 @@ function ChartsLegend(inProps) {
50
49
  const classes = useUtilityClasses(_extends({}, defaultizedProps, {
51
50
  theme
52
51
  }));
53
- const drawingArea = useDrawingArea();
54
52
  const series = useSeries();
55
53
  const seriesToDisplay = getSeriesToDisplay(series);
56
54
  const ChartLegendRender = slots?.legend ?? DefaultChartsLegend;
@@ -59,7 +57,6 @@ function ChartsLegend(inProps) {
59
57
  externalSlotProps: slotProps?.legend,
60
58
  additionalProps: _extends({}, other, {
61
59
  classes,
62
- drawingArea,
63
60
  series,
64
61
  seriesToDisplay
65
62
  }),
@@ -2,7 +2,7 @@
2
2
 
3
3
  import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
5
- const _excluded = ["drawingArea", "seriesToDisplay", "hidden", "onItemClick"];
5
+ const _excluded = ["seriesToDisplay", "hidden", "onItemClick"];
6
6
  import * as React from 'react';
7
7
  import PropTypes from 'prop-types';
8
8
  import { LegendPerItem } from "./LegendPerItem.js";
@@ -43,17 +43,6 @@ process.env.NODE_ENV !== "production" ? DefaultChartsLegend.propTypes = {
43
43
  * The default depends on the chart.
44
44
  */
45
45
  direction: PropTypes.oneOf(['column', 'row']).isRequired,
46
- /**
47
- * @deprecated Use the `useDrawingArea` hook instead.
48
- */
49
- drawingArea: PropTypes.shape({
50
- bottom: PropTypes.number.isRequired,
51
- height: PropTypes.number.isRequired,
52
- left: PropTypes.number.isRequired,
53
- right: PropTypes.number.isRequired,
54
- top: PropTypes.number.isRequired,
55
- width: PropTypes.number.isRequired
56
- }).isRequired,
57
46
  /**
58
47
  * Set to true to hide the legend.
59
48
  * @default false
@@ -39,8 +39,8 @@ function ChartsOnAxisClickHandler(props) {
39
39
  Object.keys(series).filter(seriesType => ['bar', 'line'].includes(seriesType)).forEach(seriesType => {
40
40
  series[seriesType]?.seriesOrder.forEach(seriesId => {
41
41
  const seriesItem = series[seriesType].series[seriesId];
42
- const providedXAxisId = seriesItem.xAxisId ?? seriesItem.xAxisKey;
43
- const providedYAxisId = seriesItem.yAxisId ?? seriesItem.yAxisKey;
42
+ const providedXAxisId = seriesItem.xAxisId;
43
+ const providedYAxisId = seriesItem.yAxisId;
44
44
  const axisKey = isXaxis ? providedXAxisId : providedYAxisId;
45
45
  if (axisKey === undefined || axisKey === USED_AXIS_ID) {
46
46
  seriesValues[seriesId] = seriesItem.data[dataIndex];
@@ -40,14 +40,14 @@ function ChartsAxisTooltipContent(props) {
40
40
  Object.keys(series).filter(isCartesianSeriesType).forEach(seriesType => {
41
41
  series[seriesType].seriesOrder.forEach(seriesId => {
42
42
  const item = series[seriesType].series[seriesId];
43
- const providedXAxisId = item.xAxisId ?? item.xAxisKey;
44
- const providedYAxisId = item.yAxisId ?? item.yAxisKey;
43
+ const providedXAxisId = item.xAxisId;
44
+ const providedYAxisId = item.yAxisId;
45
45
  const axisKey = isXaxis ? providedXAxisId : providedYAxisId;
46
46
  if (axisKey === undefined || axisKey === USED_AXIS_ID) {
47
47
  const seriesToAdd = series[seriesType].series[seriesId];
48
48
  const xAxisId = providedXAxisId ?? xAxisIds[0];
49
49
  const yAxisId = providedYAxisId ?? yAxisIds[0];
50
- const zAxisId = seriesToAdd.zAxisId ?? seriesToAdd.zAxisKey ?? zAxisIds[0];
50
+ const zAxisId = seriesToAdd.zAxisId ?? zAxisIds[0];
51
51
  const getColor = colorProcessors[seriesType]?.(seriesToAdd, xAxis[xAxisId], yAxis[yAxisId], zAxisId && zAxis[zAxisId]) ?? (() => '');
52
52
  rep.push(_extends({}, seriesToAdd, {
53
53
  getColor
@@ -30,9 +30,9 @@ function ChartsItemTooltipContent(props) {
30
30
  zAxisIds
31
31
  } = React.useContext(ZAxisContext);
32
32
  const colorProcessors = useColorProcessor();
33
- const xAxisId = series.xAxisId ?? series.xAxisKey ?? xAxisIds[0];
34
- const yAxisId = series.yAxisId ?? series.yAxisKey ?? yAxisIds[0];
35
- const zAxisId = series.zAxisId ?? series.zAxisKey ?? zAxisIds[0];
33
+ const xAxisId = series.xAxisId ?? xAxisIds[0];
34
+ const yAxisId = series.yAxisId ?? yAxisIds[0];
35
+ const zAxisId = series.zAxisId ?? zAxisIds[0];
36
36
  const getColor = colorProcessors[series.type]?.(series, xAxisId && xAxis[xAxisId], yAxisId && yAxis[yAxisId], zAxisId && zAxis[zAxisId]) ?? (() => '');
37
37
  const Content = content ?? DefaultChartsItemTooltipContent;
38
38
  const chartTooltipContentProps = useSlotProps({
@@ -4,12 +4,14 @@ import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import composeClasses from '@mui/utils/composeClasses';
7
+ import useLazyRef from '@mui/utils/useLazyRef';
7
8
  import { styled, useThemeProps } from '@mui/material/styles';
8
9
  import Popper from '@mui/material/Popper';
9
10
  import NoSsr from '@mui/material/NoSsr';
10
11
  import useSlotProps from '@mui/utils/useSlotProps';
11
12
  import { InteractionContext } from "../context/InteractionProvider.js";
12
- import { generateVirtualElement, useMouseTracker, getTooltipHasData } from "./utils.js";
13
+ import { useSvgRef } from "../hooks/useSvgRef.js";
14
+ import { getTooltipHasData, usePointerType } from "./utils.js";
13
15
  import { ChartsItemTooltipContent } from "./ChartsItemTooltipContent.js";
14
16
  import { ChartsAxisTooltipContent } from "./ChartsAxisTooltipContent.js";
15
17
  import { getChartsTooltipUtilityClass } from "./chartsTooltipClasses.js";
@@ -63,14 +65,20 @@ function ChartsTooltip(inProps) {
63
65
  slots,
64
66
  slotProps
65
67
  } = props;
66
- const mousePosition = useMouseTracker();
68
+ const svgRef = useSvgRef();
69
+ const pointerType = usePointerType();
70
+ const popperRef = React.useRef(null);
71
+ const positionRef = useLazyRef(() => ({
72
+ x: 0,
73
+ y: 0
74
+ }));
67
75
  const {
68
76
  item,
69
77
  axis
70
78
  } = React.useContext(InteractionContext);
71
79
  const displayedData = trigger === 'item' ? item : axis;
72
80
  const tooltipHasData = getTooltipHasData(trigger, displayedData);
73
- const popperOpen = mousePosition !== null && tooltipHasData;
81
+ const popperOpen = pointerType !== null && tooltipHasData;
74
82
  const classes = useUtilityClasses({
75
83
  classes: props.classes
76
84
  });
@@ -80,17 +88,48 @@ function ChartsTooltip(inProps) {
80
88
  externalSlotProps: slotProps?.popper,
81
89
  additionalProps: {
82
90
  open: popperOpen,
83
- placement: mousePosition?.pointerType === 'mouse' ? 'right-start' : 'top',
84
- anchorEl: generateVirtualElement(mousePosition),
91
+ placement: pointerType?.pointerType === 'mouse' ? 'right-start' : 'top',
92
+ popperRef,
93
+ anchorEl: {
94
+ getBoundingClientRect: () => ({
95
+ x: positionRef.current.x,
96
+ y: positionRef.current.y,
97
+ top: positionRef.current.y,
98
+ left: positionRef.current.x,
99
+ right: positionRef.current.x,
100
+ bottom: positionRef.current.y,
101
+ width: 0,
102
+ height: 0,
103
+ toJSON: () => ''
104
+ })
105
+ },
85
106
  modifiers: [{
86
107
  name: 'offset',
87
108
  options: {
88
- offset: [0, mousePosition?.pointerType === 'touch' ? 40 - mousePosition.height : 0]
109
+ offset: [0, pointerType?.pointerType === 'touch' ? 40 - pointerType.height : 0]
89
110
  }
90
111
  }]
91
112
  },
92
113
  ownerState: {}
93
114
  });
115
+ React.useEffect(() => {
116
+ const element = svgRef.current;
117
+ if (element === null) {
118
+ return () => {};
119
+ }
120
+ const handleMove = event => {
121
+ // eslint-disable-next-line react-compiler/react-compiler
122
+ positionRef.current = {
123
+ x: event.clientX,
124
+ y: event.clientY
125
+ };
126
+ popperRef.current?.update();
127
+ };
128
+ element.addEventListener('pointermove', handleMove);
129
+ return () => {
130
+ element.removeEventListener('pointermove', handleMove);
131
+ };
132
+ }, [svgRef, positionRef]);
94
133
  if (trigger === 'none') {
95
134
  return null;
96
135
  }
@@ -45,15 +45,15 @@ export function useAxisTooltip() {
45
45
  }
46
46
  return seriesOfType.seriesOrder.map(seriesId => {
47
47
  const seriesToAdd = seriesOfType.series[seriesId];
48
- const providedXAxisId = seriesToAdd.xAxisId ?? seriesToAdd.xAxisKey;
49
- const providedYAxisId = seriesToAdd.yAxisId ?? seriesToAdd.yAxisKey;
48
+ const providedXAxisId = seriesToAdd.xAxisId;
49
+ const providedYAxisId = seriesToAdd.yAxisId;
50
50
  const axisKey = isXaxis ? providedXAxisId : providedYAxisId;
51
51
 
52
52
  // Test if the series uses the default axis
53
53
  if (axisKey === undefined || axisKey === USED_AXIS_ID) {
54
54
  const xAxisId = providedXAxisId ?? xAxisIds[0];
55
55
  const yAxisId = providedYAxisId ?? yAxisIds[0];
56
- const zAxisId = seriesToAdd.zAxisId ?? seriesToAdd.zAxisKey ?? zAxisIds[0];
56
+ const zAxisId = seriesToAdd.zAxisId ?? zAxisIds[0];
57
57
  const color = colorProcessors[seriesType]?.(seriesToAdd, xAxis[xAxisId], yAxis[yAxisId], zAxisId && zAxis[zAxisId])(dataIndex) ?? '';
58
58
  const value = seriesToAdd.data[dataIndex] ?? null;
59
59
  const formattedValue = seriesToAdd.valueFormatter(value, {
@@ -24,9 +24,9 @@ export function useItemTooltip() {
24
24
  zAxisIds
25
25
  } = React.useContext(ZAxisContext);
26
26
  const colorProcessors = useColorProcessor();
27
- const xAxisId = series.xAxisId ?? series.xAxisKey ?? xAxisIds[0];
28
- const yAxisId = series.yAxisId ?? series.yAxisKey ?? yAxisIds[0];
29
- const zAxisId = series.zAxisId ?? series.zAxisKey ?? zAxisIds[0];
27
+ const xAxisId = series.xAxisId ?? xAxisIds[0];
28
+ const yAxisId = series.yAxisId ?? yAxisIds[0];
29
+ const zAxisId = series.zAxisId ?? zAxisIds[0];
30
30
  if (!item || item.dataIndex === undefined) {
31
31
  return null;
32
32
  }