@mui/x-charts 7.17.0 → 7.18.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 (115) hide show
  1. package/BarChart/BarChart.js +10 -0
  2. package/CHANGELOG.md +98 -5
  3. package/ChartsLegend/ChartsLegend.d.ts +2 -2
  4. package/ChartsTooltip/index.d.ts +3 -0
  5. package/ChartsTooltip/index.js +4 -1
  6. package/ChartsTooltip/useAxisTooltip.d.ts +18 -0
  7. package/ChartsTooltip/useAxisTooltip.js +84 -0
  8. package/ChartsTooltip/useItemTooltip.d.ts +10 -0
  9. package/ChartsTooltip/useItemTooltip.js +64 -0
  10. package/ChartsTooltip/utils.d.ts +2 -1
  11. package/LineChart/AnimatedLine.js +12 -22
  12. package/LineChart/LineChart.js +10 -0
  13. package/PieChart/PieChart.js +10 -0
  14. package/ResponsiveChartContainer/ResponsiveChartContainer.d.ts +10 -0
  15. package/ResponsiveChartContainer/ResponsiveChartContainer.js +10 -0
  16. package/ResponsiveChartContainer/useChartContainerDimensions.d.ts +1 -1
  17. package/ResponsiveChartContainer/useChartContainerDimensions.js +32 -8
  18. package/ResponsiveChartContainer/useResponsiveChartContainerProps.js +3 -2
  19. package/ScatterChart/ScatterChart.js +10 -0
  20. package/SparkLineChart/SparkLineChart.js +10 -0
  21. package/context/CartesianProvider/CartesianProvider.js +3 -3
  22. package/context/CartesianProvider/getAxisExtremum.d.ts +1 -1
  23. package/context/CartesianProvider/getAxisExtremum.js +5 -4
  24. package/context/CartesianProvider/index.d.ts +0 -5
  25. package/context/CartesianProvider/index.js +1 -6
  26. package/context/PluginProvider/ExtremumGetter.types.d.ts +1 -0
  27. package/context/PluginProvider/Plugin.types.d.ts +4 -0
  28. package/context/PluginProvider/PluginContext.js +3 -1
  29. package/context/PluginProvider/index.d.ts +2 -0
  30. package/context/PluginProvider/index.js +3 -1
  31. package/context/PluginProvider/mergePlugins.d.ts +10 -0
  32. package/context/PluginProvider/mergePlugins.js +11 -1
  33. package/context/PluginProvider/useRadiusExtremumGetter.d.ts +4 -0
  34. package/context/PluginProvider/useRadiusExtremumGetter.js +17 -0
  35. package/context/PluginProvider/useRotationExtremumGetter.d.ts +4 -0
  36. package/context/PluginProvider/useRotationExtremumGetter.js +17 -0
  37. package/context/PolarProvider/Polar.types.d.ts +42 -0
  38. package/context/PolarProvider/Polar.types.js +1 -0
  39. package/context/PolarProvider/PolarContext.d.ts +4 -0
  40. package/context/PolarProvider/PolarContext.js +13 -0
  41. package/context/PolarProvider/PolarProvider.d.ts +4 -0
  42. package/context/PolarProvider/PolarProvider.js +49 -0
  43. package/context/PolarProvider/getAxisExtremum.d.ts +4 -0
  44. package/context/PolarProvider/getAxisExtremum.js +20 -0
  45. package/context/PolarProvider/index.d.ts +0 -0
  46. package/context/PolarProvider/index.js +0 -0
  47. package/context/PolarProvider/usePolarContext.d.ts +2 -0
  48. package/context/PolarProvider/usePolarContext.js +10 -0
  49. package/index.js +1 -1
  50. package/internals/computeAxisValue.d.ts +38 -0
  51. package/{context/CartesianProvider/computeValue.js → internals/computeAxisValue.js} +28 -15
  52. package/internals/index.d.ts +1 -0
  53. package/internals/index.js +1 -0
  54. package/models/axis.d.ts +20 -0
  55. package/models/seriesType/config.d.ts +6 -2
  56. package/modern/BarChart/BarChart.js +10 -0
  57. package/modern/ChartsTooltip/index.js +4 -1
  58. package/modern/ChartsTooltip/useAxisTooltip.js +84 -0
  59. package/modern/ChartsTooltip/useItemTooltip.js +64 -0
  60. package/modern/LineChart/AnimatedLine.js +12 -22
  61. package/modern/LineChart/LineChart.js +10 -0
  62. package/modern/PieChart/PieChart.js +10 -0
  63. package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +10 -0
  64. package/modern/ResponsiveChartContainer/useChartContainerDimensions.js +32 -8
  65. package/modern/ResponsiveChartContainer/useResponsiveChartContainerProps.js +3 -2
  66. package/modern/ScatterChart/ScatterChart.js +10 -0
  67. package/modern/SparkLineChart/SparkLineChart.js +10 -0
  68. package/modern/context/CartesianProvider/CartesianProvider.js +3 -3
  69. package/modern/context/CartesianProvider/getAxisExtremum.js +5 -4
  70. package/modern/context/CartesianProvider/index.js +1 -6
  71. package/modern/context/PluginProvider/PluginContext.js +3 -1
  72. package/modern/context/PluginProvider/index.js +3 -1
  73. package/modern/context/PluginProvider/mergePlugins.js +11 -1
  74. package/modern/context/PluginProvider/useRadiusExtremumGetter.js +17 -0
  75. package/modern/context/PluginProvider/useRotationExtremumGetter.js +17 -0
  76. package/modern/context/PolarProvider/Polar.types.js +1 -0
  77. package/modern/context/PolarProvider/PolarContext.js +13 -0
  78. package/modern/context/PolarProvider/PolarProvider.js +49 -0
  79. package/modern/context/PolarProvider/getAxisExtremum.js +20 -0
  80. package/modern/context/PolarProvider/index.js +0 -0
  81. package/modern/context/PolarProvider/usePolarContext.js +10 -0
  82. package/modern/index.js +1 -1
  83. package/modern/{context/CartesianProvider/computeValue.js → internals/computeAxisValue.js} +28 -15
  84. package/modern/internals/index.js +1 -0
  85. package/node/BarChart/BarChart.js +10 -0
  86. package/node/ChartsTooltip/index.js +42 -1
  87. package/node/ChartsTooltip/useAxisTooltip.js +90 -0
  88. package/node/ChartsTooltip/useItemTooltip.js +71 -0
  89. package/node/LineChart/AnimatedLine.js +12 -22
  90. package/node/LineChart/LineChart.js +10 -0
  91. package/node/PieChart/PieChart.js +10 -0
  92. package/node/ResponsiveChartContainer/ResponsiveChartContainer.js +10 -0
  93. package/node/ResponsiveChartContainer/useChartContainerDimensions.js +32 -8
  94. package/node/ResponsiveChartContainer/useResponsiveChartContainerProps.js +3 -2
  95. package/node/ScatterChart/ScatterChart.js +10 -0
  96. package/node/SparkLineChart/SparkLineChart.js +10 -0
  97. package/node/context/CartesianProvider/CartesianProvider.js +3 -3
  98. package/node/context/CartesianProvider/getAxisExtremum.js +5 -4
  99. package/node/context/CartesianProvider/index.js +1 -13
  100. package/node/context/PluginProvider/PluginContext.js +3 -1
  101. package/node/context/PluginProvider/index.js +22 -0
  102. package/node/context/PluginProvider/mergePlugins.js +11 -1
  103. package/node/context/PluginProvider/useRadiusExtremumGetter.js +23 -0
  104. package/node/context/PluginProvider/useRotationExtremumGetter.js +23 -0
  105. package/node/context/PolarProvider/Polar.types.js +5 -0
  106. package/node/context/PolarProvider/PolarContext.js +20 -0
  107. package/node/context/PolarProvider/PolarProvider.js +54 -0
  108. package/node/context/PolarProvider/getAxisExtremum.js +27 -0
  109. package/node/context/PolarProvider/index.js +1 -0
  110. package/node/context/PolarProvider/usePolarContext.js +17 -0
  111. package/node/index.js +1 -1
  112. package/node/{context/CartesianProvider/computeValue.js → internals/computeAxisValue.js} +29 -16
  113. package/node/internals/index.js +12 -0
  114. package/package.json +4 -4
  115. package/context/CartesianProvider/computeValue.d.ts +0 -30
@@ -196,6 +196,16 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
196
196
  * @param {BarItemIdentifier} barItemIdentifier The bar item identifier.
197
197
  */
198
198
  onItemClick: PropTypes.func,
199
+ /**
200
+ * The chart will try to wait for the parent container to resolve its size
201
+ * before it renders for the first time.
202
+ *
203
+ * This can be useful in some scenarios where the chart appear to grow after
204
+ * the first render, like when used inside a grid.
205
+ *
206
+ * @default false
207
+ */
208
+ resolveSizeBeforeRender: PropTypes.bool,
199
209
  /**
200
210
  * Indicate which axis to display the right of the charts.
201
211
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
@@ -4,4 +4,7 @@ export * from "./ChartsAxisTooltipContent.js";
4
4
  export * from "./ChartsItemTooltipContent.js";
5
5
  export * from "./DefaultChartsAxisTooltipContent.js";
6
6
  export * from "./DefaultChartsItemTooltipContent.js";
7
- export * from "./ChartsTooltipTable.js";
7
+ export * from "./ChartsTooltipTable.js";
8
+ export * from "./useItemTooltip.js";
9
+ export * from "./useAxisTooltip.js";
10
+ export { useMouseTracker } from "./utils.js";
@@ -0,0 +1,84 @@
1
+ 'use client';
2
+
3
+ import * as React from 'react';
4
+ import { InteractionContext } from "../context/InteractionProvider.js";
5
+ import { useSeries } from "../hooks/useSeries.js";
6
+ import { useCartesianContext } from "../context/CartesianProvider/index.js";
7
+ import { ZAxisContext } from "../context/ZAxisContextProvider.js";
8
+ import { useColorProcessor } from "../context/PluginProvider/useColorProcessor.js";
9
+ import { getLabel } from "../internals/getLabel.js";
10
+ import { isCartesianSeriesType } from "../internals/isCartesian.js";
11
+ import { utcFormatter } from "./utils.js";
12
+ export function useAxisTooltip() {
13
+ const {
14
+ axis
15
+ } = React.useContext(InteractionContext);
16
+ const series = useSeries();
17
+ const {
18
+ xAxis,
19
+ yAxis,
20
+ xAxisIds,
21
+ yAxisIds
22
+ } = useCartesianContext();
23
+ const {
24
+ zAxis,
25
+ zAxisIds
26
+ } = React.useContext(ZAxisContext);
27
+ const colorProcessors = useColorProcessor();
28
+
29
+ // By default use the x-axis
30
+ const isXaxis = axis.x !== null && axis.x.index !== -1;
31
+ const axisData = isXaxis ? axis.x && axis.x : axis.y && axis.y;
32
+ if (axisData === null) {
33
+ return null;
34
+ }
35
+ const {
36
+ index: dataIndex,
37
+ value: axisValue
38
+ } = axisData;
39
+ const USED_AXIS_ID = isXaxis ? xAxisIds[0] : yAxisIds[0];
40
+ const usedAxis = isXaxis ? xAxis[USED_AXIS_ID] : yAxis[USED_AXIS_ID];
41
+ const relevantSeries = Object.keys(series).filter(isCartesianSeriesType).flatMap(seriesType => {
42
+ const seriesOfType = series[seriesType];
43
+ if (!seriesOfType) {
44
+ return [];
45
+ }
46
+ return seriesOfType.seriesOrder.map(seriesId => {
47
+ const seriesToAdd = seriesOfType.series[seriesId];
48
+ const providedXAxisId = seriesToAdd.xAxisId ?? seriesToAdd.xAxisKey;
49
+ const providedYAxisId = seriesToAdd.yAxisId ?? seriesToAdd.yAxisKey;
50
+ const axisKey = isXaxis ? providedXAxisId : providedYAxisId;
51
+
52
+ // Test if the series uses the default axis
53
+ if (axisKey === undefined || axisKey === USED_AXIS_ID) {
54
+ const xAxisId = providedXAxisId ?? xAxisIds[0];
55
+ const yAxisId = providedYAxisId ?? yAxisIds[0];
56
+ const zAxisId = seriesToAdd.zAxisId ?? seriesToAdd.zAxisKey ?? zAxisIds[0];
57
+ const color = colorProcessors[seriesType]?.(seriesToAdd, xAxis[xAxisId], yAxis[yAxisId], zAxisId && zAxis[zAxisId])(dataIndex) ?? '';
58
+ const value = seriesToAdd.data[dataIndex] ?? null;
59
+ const formattedValue = seriesToAdd.valueFormatter(value, {
60
+ dataIndex
61
+ });
62
+ const formattedLabel = getLabel(seriesToAdd.label, 'tooltip') ?? null;
63
+ return {
64
+ seriesId,
65
+ color,
66
+ value,
67
+ formattedValue,
68
+ formattedLabel
69
+ };
70
+ }
71
+ return undefined;
72
+ });
73
+ }).filter(item => item != null);
74
+ const axisFormatter = usedAxis.valueFormatter ?? (v => usedAxis.scaleType === 'utc' ? utcFormatter(v) : v.toLocaleString());
75
+ const axisFormattedValue = axisFormatter(axisValue, {
76
+ location: 'tooltip'
77
+ });
78
+ return {
79
+ identifier: axis,
80
+ seriesItems: relevantSeries,
81
+ axisValue,
82
+ axisFormattedValue
83
+ };
84
+ }
@@ -0,0 +1,64 @@
1
+ 'use client';
2
+
3
+ import _extends from "@babel/runtime/helpers/esm/extends";
4
+ import * as React from 'react';
5
+ import { InteractionContext } from "../context/InteractionProvider.js";
6
+ import { useSeries } from "../hooks/useSeries.js";
7
+ import { useCartesianContext } from "../context/CartesianProvider/index.js";
8
+ import { ZAxisContext } from "../context/ZAxisContextProvider.js";
9
+ import { useColorProcessor } from "../context/PluginProvider/useColorProcessor.js";
10
+ import { getLabel } from "../internals/getLabel.js";
11
+ export function useItemTooltip() {
12
+ const {
13
+ item
14
+ } = React.useContext(InteractionContext);
15
+ const series = useSeries();
16
+ const {
17
+ xAxis,
18
+ yAxis,
19
+ xAxisIds,
20
+ yAxisIds
21
+ } = useCartesianContext();
22
+ const {
23
+ zAxis,
24
+ zAxisIds
25
+ } = React.useContext(ZAxisContext);
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];
30
+ if (!item || item.dataIndex === undefined) {
31
+ return null;
32
+ }
33
+ const itemSeries = series[item.type].series[item.seriesId];
34
+ const getColor = colorProcessors[itemSeries.type]?.(itemSeries, xAxisId && xAxis[xAxisId], yAxisId && yAxis[yAxisId], zAxisId && zAxis[zAxisId]) ?? (() => '');
35
+ if (itemSeries.type === 'pie') {
36
+ const point = itemSeries.data[item.dataIndex];
37
+ const label = getLabel(point.label, 'tooltip');
38
+ const value = _extends({}, point, {
39
+ label
40
+ });
41
+ const formattedValue = itemSeries.valueFormatter?.(value, {
42
+ dataIndex: item.dataIndex
43
+ });
44
+ return {
45
+ identifier: item,
46
+ color: getColor(item.dataIndex),
47
+ label,
48
+ value,
49
+ formattedValue
50
+ };
51
+ }
52
+ const label = getLabel(itemSeries.label, 'tooltip');
53
+ const value = itemSeries.data[item.dataIndex];
54
+ const formattedValue = itemSeries.valueFormatter?.(value, {
55
+ dataIndex: item.dataIndex
56
+ });
57
+ return {
58
+ identifier: item,
59
+ color: getColor(item.dataIndex),
60
+ label,
61
+ value,
62
+ formattedValue
63
+ };
64
+ }
@@ -44,29 +44,19 @@ function AnimatedLine(props) {
44
44
  ownerState
45
45
  } = props,
46
46
  other = _objectWithoutPropertiesLoose(props, _excluded);
47
- const {
48
- left,
49
- top,
50
- bottom,
51
- width,
52
- height,
53
- right
54
- } = useDrawingArea();
47
+ const drawingArea = useDrawingArea();
55
48
  const chartId = useChartId();
56
49
  const stringInterpolator = useStringInterpolator(d);
57
- const transitionAppear = useTransition([1], {
58
- from: {
59
- animatedWidth: left
60
- },
61
- to: {
62
- animatedWidth: width + left + right
63
- },
64
- enter: {
65
- animatedWidth: width + left + right
66
- },
67
- leave: {
68
- animatedWidth: left
69
- },
50
+ const transitionAppear = useTransition([drawingArea], {
51
+ from: v => ({
52
+ animatedWidth: v.left
53
+ }),
54
+ enter: v => ({
55
+ animatedWidth: v.width + v.left + v.right
56
+ }),
57
+ leave: v => ({
58
+ animatedWidth: v.width + v.left + v.right
59
+ }),
70
60
  reset: false,
71
61
  immediate: skipAnimation
72
62
  });
@@ -91,7 +81,7 @@ function AnimatedLine(props) {
91
81
  x: 0,
92
82
  y: 0,
93
83
  width: style.animatedWidth,
94
- height: top + height + bottom
84
+ height: drawingArea.top + drawingArea.height + drawingArea.bottom
95
85
  }))
96
86
  }), /*#__PURE__*/_jsx("g", {
97
87
  clipPath: `url(#${clipId})`,
@@ -200,6 +200,16 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
200
200
  * Callback fired when a mark element is clicked.
201
201
  */
202
202
  onMarkClick: PropTypes.func,
203
+ /**
204
+ * The chart will try to wait for the parent container to resolve its size
205
+ * before it renders for the first time.
206
+ *
207
+ * This can be useful in some scenarios where the chart appear to grow after
208
+ * the first render, like when used inside a grid.
209
+ *
210
+ * @default false
211
+ */
212
+ resolveSizeBeforeRender: PropTypes.bool,
203
213
  /**
204
214
  * Indicate which axis to display the right of the charts.
205
215
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
@@ -240,6 +240,16 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
240
240
  * Callback fired when a pie arc is clicked.
241
241
  */
242
242
  onItemClick: PropTypes.func,
243
+ /**
244
+ * The chart will try to wait for the parent container to resolve its size
245
+ * before it renders for the first time.
246
+ *
247
+ * This can be useful in some scenarios where the chart appear to grow after
248
+ * the first render, like when used inside a grid.
249
+ *
250
+ * @default false
251
+ */
252
+ resolveSizeBeforeRender: PropTypes.bool,
243
253
  /**
244
254
  * Indicate which axis to display the right of the charts.
245
255
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
@@ -74,6 +74,16 @@ process.env.NODE_ENV !== "production" ? ResponsiveChartContainer.propTypes = {
74
74
  * If not provided, the container supports line, bar, scatter and pie charts.
75
75
  */
76
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,
77
87
  /**
78
88
  * The array of series to display.
79
89
  * Each type of series has its own specificity.
@@ -3,8 +3,12 @@
3
3
  import * as React from 'react';
4
4
  import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
5
5
  import ownerWindow from '@mui/utils/ownerWindow';
6
- export const useChartContainerDimensions = (inWidth, inHeight) => {
7
- const displayError = React.useRef(false);
6
+ export const useChartContainerDimensions = (inWidth, inHeight, resolveSizeBeforeRender) => {
7
+ const stateRef = React.useRef({
8
+ displayError: false,
9
+ initialCompute: true,
10
+ computeRun: 0
11
+ });
8
12
  const rootRef = React.useRef(null);
9
13
  const [width, setWidth] = React.useState(0);
10
14
  const [height, setHeight] = React.useState(0);
@@ -13,7 +17,7 @@ export const useChartContainerDimensions = (inWidth, inHeight) => {
13
17
  const computeSize = React.useCallback(() => {
14
18
  const mainEl = rootRef?.current;
15
19
  if (!mainEl) {
16
- return;
20
+ return {};
17
21
  }
18
22
  const win = ownerWindow(mainEl);
19
23
  const computedStyle = win.getComputedStyle(mainEl);
@@ -21,11 +25,31 @@ export const useChartContainerDimensions = (inWidth, inHeight) => {
21
25
  const newWidth = Math.floor(parseFloat(computedStyle.width)) || 0;
22
26
  setWidth(newWidth);
23
27
  setHeight(newHeight);
28
+ return {
29
+ width: newWidth,
30
+ height: newHeight
31
+ };
24
32
  }, []);
25
33
  React.useEffect(() => {
26
34
  // Ensure the error detection occurs after the first rendering.
27
- displayError.current = true;
35
+ stateRef.current.displayError = true;
28
36
  }, []);
37
+
38
+ // This effect is used to compute the size of the container on the initial render.
39
+ // It is not bound to the raf loop to avoid an unwanted "resize" event.
40
+ // https://github.com/mui/mui-x/issues/13477#issuecomment-2336634785
41
+ useEnhancedEffect(() => {
42
+ // computeRun is used to avoid infinite loops.
43
+ if (!resolveSizeBeforeRender || !stateRef.current.initialCompute || stateRef.current.computeRun > 20) {
44
+ return;
45
+ }
46
+ const computedSize = computeSize();
47
+ if (computedSize.width !== width || computedSize.height !== height) {
48
+ stateRef.current.computeRun += 1;
49
+ } else if (stateRef.current.initialCompute) {
50
+ stateRef.current.initialCompute = false;
51
+ }
52
+ }, [width, height, computeSize, resolveSizeBeforeRender]);
29
53
  useEnhancedEffect(() => {
30
54
  if (inWidth !== undefined && inHeight !== undefined) {
31
55
  return () => {};
@@ -55,13 +79,13 @@ export const useChartContainerDimensions = (inWidth, inHeight) => {
55
79
  };
56
80
  }, [computeSize, inHeight, inWidth]);
57
81
  if (process.env.NODE_ENV !== 'production') {
58
- if (displayError.current && inWidth === undefined && width === 0) {
82
+ if (stateRef.current.displayError && inWidth === undefined && width === 0) {
59
83
  console.error(`MUI X: ChartContainer does not have \`width\` prop, and its container has no \`width\` defined.`);
60
- displayError.current = false;
84
+ stateRef.current.displayError = false;
61
85
  }
62
- if (displayError.current && inHeight === undefined && height === 0) {
86
+ if (stateRef.current.displayError && inHeight === undefined && height === 0) {
63
87
  console.error(`MUI X: ChartContainer does not have \`height\` prop, and its container has no \`height\` defined.`);
64
- displayError.current = false;
88
+ stateRef.current.displayError = false;
65
89
  }
66
90
  }
67
91
  return {
@@ -2,12 +2,13 @@
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", "margin", "children", "series", "colors", "dataset", "desc", "disableAxisListener", "highlightedItem", "onHighlightChange", "plugins", "sx", "title", "viewBox", "xAxis", "yAxis", "zAxis"];
5
+ const _excluded = ["width", "height", "resolveSizeBeforeRender", "margin", "children", "series", "colors", "dataset", "desc", "disableAxisListener", "highlightedItem", "onHighlightChange", "plugins", "sx", "title", "viewBox", "xAxis", "yAxis", "zAxis"];
6
6
  import { useChartContainerDimensions } from "./useChartContainerDimensions.js";
7
7
  export const useResponsiveChartContainerProps = (props, ref) => {
8
8
  const {
9
9
  width,
10
10
  height,
11
+ resolveSizeBeforeRender,
11
12
  margin,
12
13
  children,
13
14
  series,
@@ -30,7 +31,7 @@ export const useResponsiveChartContainerProps = (props, ref) => {
30
31
  containerRef,
31
32
  width: dWidth,
32
33
  height: dHeight
33
- } = useChartContainerDimensions(width, height);
34
+ } = useChartContainerDimensions(width, height, resolveSizeBeforeRender);
34
35
  const resizableChartContainerProps = _extends({}, other, {
35
36
  ownerState: {
36
37
  width,
@@ -177,6 +177,16 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
177
177
  * @param {ScatterItemIdentifier} scatterItemIdentifier The scatter item identifier.
178
178
  */
179
179
  onItemClick: PropTypes.func,
180
+ /**
181
+ * The chart will try to wait for the parent container to resolve its size
182
+ * before it renders for the first time.
183
+ *
184
+ * This can be useful in some scenarios where the chart appear to grow after
185
+ * the first render, like when used inside a grid.
186
+ *
187
+ * @default false
188
+ */
189
+ resolveSizeBeforeRender: PropTypes.bool,
180
190
  /**
181
191
  * Indicate which axis to display the right of the charts.
182
192
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
@@ -193,6 +193,16 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
193
193
  * @default 'line'
194
194
  */
195
195
  plotType: PropTypes.oneOf(['bar', 'line']),
196
+ /**
197
+ * The chart will try to wait for the parent container to resolve its size
198
+ * before it renders for the first time.
199
+ *
200
+ * This can be useful in some scenarios where the chart appear to grow after
201
+ * the first render, like when used inside a grid.
202
+ *
203
+ * @default false
204
+ */
205
+ resolveSizeBeforeRender: PropTypes.bool,
196
206
  /**
197
207
  * Set to `true` to highlight the value.
198
208
  * With line, it shows a point.
@@ -1,10 +1,10 @@
1
1
  'use client';
2
2
 
3
3
  import * as React from 'react';
4
+ import { computeAxisValue } from "../../internals/computeAxisValue.js";
4
5
  import { useDrawingArea } from "../../hooks/useDrawingArea.js";
5
6
  import { useSeries } from "../../hooks/useSeries.js";
6
7
  import { CartesianContext } from "./CartesianContext.js";
7
- import { computeValue } from "./computeValue.js";
8
8
  import { useXExtremumGetter } from "../PluginProvider/useXExtremumGetter.js";
9
9
  import { useYExtremumGetter } from "../PluginProvider/index.js";
10
10
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -18,14 +18,14 @@ function CartesianProvider(props) {
18
18
  const drawingArea = useDrawingArea();
19
19
  const xExtremumGetters = useXExtremumGetter();
20
20
  const yExtremumGetters = useYExtremumGetter();
21
- const xValues = React.useMemo(() => computeValue({
21
+ const xValues = React.useMemo(() => computeAxisValue({
22
22
  drawingArea,
23
23
  formattedSeries,
24
24
  axis: xAxis,
25
25
  extremumGetters: xExtremumGetters,
26
26
  axisDirection: 'x'
27
27
  }), [drawingArea, formattedSeries, xAxis, xExtremumGetters]);
28
- const yValues = React.useMemo(() => computeValue({
28
+ const yValues = React.useMemo(() => computeAxisValue({
29
29
  drawingArea,
30
30
  formattedSeries,
31
31
  axis: yAxis,
@@ -1,18 +1,19 @@
1
- const axisExtremumCallback = (acc, chartType, axis, getters, isDefaultAxis, formattedSeries, getFilters) => {
1
+ const axisExtremumCallback = (acc, chartType, axis, getters, axisIndex, formattedSeries, getFilters) => {
2
2
  const getter = getters[chartType];
3
3
  const series = formattedSeries[chartType]?.series ?? {};
4
4
  const [minChartTypeData, maxChartTypeData] = getter?.({
5
5
  series,
6
6
  axis,
7
- isDefaultAxis,
7
+ axisIndex,
8
+ isDefaultAxis: axisIndex === 0,
8
9
  getFilters
9
10
  }) ?? [Infinity, -Infinity];
10
11
  const [minData, maxData] = acc;
11
12
  return [Math.min(minChartTypeData, minData), Math.max(maxChartTypeData, maxData)];
12
13
  };
13
- export const getAxisExtremum = (axis, getters, isDefaultAxis, formattedSeries, getFilters) => {
14
+ export const getAxisExtremum = (axis, getters, axisIndex, formattedSeries, getFilters) => {
14
15
  const charTypes = Object.keys(getters);
15
- const extremums = charTypes.reduce((acc, charType) => axisExtremumCallback(acc, charType, axis, getters, isDefaultAxis, formattedSeries, getFilters), [Infinity, -Infinity]);
16
+ const extremums = charTypes.reduce((acc, charType) => axisExtremumCallback(acc, charType, axis, getters, axisIndex, formattedSeries, getFilters), [Infinity, -Infinity]);
16
17
  if (Number.isNaN(extremums[0]) || Number.isNaN(extremums[1])) {
17
18
  return [Infinity, -Infinity];
18
19
  }
@@ -1,9 +1,4 @@
1
- import { computeValue } from "./computeValue.js";
2
1
  export * from "./CartesianProvider.js";
3
2
  export * from "./CartesianContext.js";
4
3
  export * from "./useCartesianContext.js";
5
- export * from "./Cartesian.types.js";
6
- const cartesianProviderUtils = {
7
- computeValue
8
- };
9
- export { cartesianProviderUtils };
4
+ export * from "./Cartesian.types.js";
@@ -5,7 +5,9 @@ export const PluginContext = /*#__PURE__*/React.createContext({
5
5
  colorProcessors: {},
6
6
  seriesFormatters: {},
7
7
  xExtremumGetters: {},
8
- yExtremumGetters: {}
8
+ yExtremumGetters: {},
9
+ rotationExtremumGetters: {},
10
+ radiusExtremumGetters: {}
9
11
  }
10
12
  });
11
13
  if (process.env.NODE_ENV !== 'production') {
@@ -7,4 +7,6 @@ export * from "./ExtremumGetter.types.js";
7
7
  export * from "./useColorProcessor.js";
8
8
  export * from "./useSeriesFormatter.js";
9
9
  export * from "./useXExtremumGetter.js";
10
- export * from "./useYExtremumGetter.js";
10
+ export * from "./useYExtremumGetter.js";
11
+ export * from "./useRadiusExtremumGetter.js";
12
+ export * from "./useRotationExtremumGetter.js";
@@ -9,6 +9,8 @@ export function mergePlugins(plugins) {
9
9
  const colorProcessors = {};
10
10
  const xExtremumGetters = {};
11
11
  const yExtremumGetters = {};
12
+ const rotationExtremumGetters = {};
13
+ const radiusExtremumGetters = {};
12
14
  for (let i = 0; i < defaultizedPlugins.length; i += 1) {
13
15
  const plugin = defaultizedPlugins[i];
14
16
  const seriesType = plugin.seriesType;
@@ -20,11 +22,19 @@ export function mergePlugins(plugins) {
20
22
  if (plugin.yExtremumGetter) {
21
23
  yExtremumGetters[seriesType] = plugin.yExtremumGetter;
22
24
  }
25
+ if (plugin.rotationExtremumGetter) {
26
+ rotationExtremumGetters[seriesType] = plugin.rotationExtremumGetter;
27
+ }
28
+ if (plugin.radiusExtremumGetter) {
29
+ radiusExtremumGetters[seriesType] = plugin.radiusExtremumGetter;
30
+ }
23
31
  }
24
32
  return {
25
33
  seriesFormatters,
26
34
  colorProcessors,
27
35
  xExtremumGetters,
28
- yExtremumGetters
36
+ yExtremumGetters,
37
+ rotationExtremumGetters,
38
+ radiusExtremumGetters
29
39
  };
30
40
  }
@@ -0,0 +1,17 @@
1
+ 'use client';
2
+
3
+ import * as React from 'react';
4
+ import { PluginContext } from "./PluginContext.js";
5
+ export function useRadiusExtremumGetter(seriesType) {
6
+ const {
7
+ isInitialized,
8
+ data
9
+ } = React.useContext(PluginContext);
10
+ if (!isInitialized) {
11
+ throw new Error(['MUI X: Could not find the plugin context.', 'It looks like you rendered your component outside of a ChartsContainer parent component.'].join('\n'));
12
+ }
13
+ if (!seriesType) {
14
+ return data.radiusExtremumGetters;
15
+ }
16
+ return data.radiusExtremumGetters[seriesType];
17
+ }
@@ -0,0 +1,17 @@
1
+ 'use client';
2
+
3
+ import * as React from 'react';
4
+ import { PluginContext } from "./PluginContext.js";
5
+ export function useRotationExtremumGetter(seriesType) {
6
+ const {
7
+ isInitialized,
8
+ data
9
+ } = React.useContext(PluginContext);
10
+ if (!isInitialized) {
11
+ throw new Error(['MUI X: Could not find the plugin context.', 'It looks like you rendered your component outside of a ChartsContainer parent component.'].join('\n'));
12
+ }
13
+ if (!seriesType) {
14
+ return data.rotationExtremumGetters;
15
+ }
16
+ return data.rotationExtremumGetters[seriesType];
17
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ import * as React from 'react';
2
+ export const PolarContext = /*#__PURE__*/React.createContext({
3
+ isInitialized: false,
4
+ data: {
5
+ rotationAxis: {},
6
+ radiusAxis: {},
7
+ rotationAxisIds: [],
8
+ radiusAxisIds: []
9
+ }
10
+ });
11
+ if (process.env.NODE_ENV !== 'production') {
12
+ PolarContext.displayName = 'PolarContext';
13
+ }
@@ -0,0 +1,49 @@
1
+ 'use client';
2
+
3
+ import * as React from 'react';
4
+ import { computeAxisValue } from "../../internals/computeAxisValue.js";
5
+ import { useDrawingArea } from "../../hooks/useDrawingArea.js";
6
+ import { useSeries } from "../../hooks/useSeries.js";
7
+ import { PolarContext } from "./PolarContext.js";
8
+ import { useRadiusExtremumGetter } from "../PluginProvider/useRadiusExtremumGetter.js";
9
+ import { useRotationExtremumGetter } from "../PluginProvider/useRotationExtremumGetter.js";
10
+ import { jsx as _jsx } from "react/jsx-runtime";
11
+ function PolarProvider(props) {
12
+ const {
13
+ rotationAxis,
14
+ radiusAxis,
15
+ children
16
+ } = props;
17
+ const formattedSeries = useSeries();
18
+ const drawingArea = useDrawingArea();
19
+ const rotationExtremumGetters = useRotationExtremumGetter();
20
+ const radiusExtremumGetters = useRadiusExtremumGetter();
21
+ const rotationValues = React.useMemo(() => computeAxisValue({
22
+ drawingArea,
23
+ formattedSeries,
24
+ axis: rotationAxis,
25
+ extremumGetters: rotationExtremumGetters,
26
+ axisDirection: 'rotation'
27
+ }), [drawingArea, formattedSeries, rotationAxis, rotationExtremumGetters]);
28
+ const radiusValues = React.useMemo(() => computeAxisValue({
29
+ drawingArea,
30
+ formattedSeries,
31
+ axis: radiusAxis,
32
+ extremumGetters: radiusExtremumGetters,
33
+ axisDirection: 'radius'
34
+ }), [drawingArea, formattedSeries, radiusAxis, radiusExtremumGetters]);
35
+ const value = React.useMemo(() => ({
36
+ isInitialized: true,
37
+ data: {
38
+ rotationAxis: rotationValues.axis,
39
+ radiusAxis: radiusValues.axis,
40
+ rotationAxisIds: rotationValues.axisIds,
41
+ radiusAxisIds: radiusValues.axisIds
42
+ }
43
+ }), [rotationValues, radiusValues]);
44
+ return /*#__PURE__*/_jsx(PolarContext.Provider, {
45
+ value: value,
46
+ children: children
47
+ });
48
+ }
49
+ export { PolarProvider };
@@ -0,0 +1,20 @@
1
+ const axisExtremumCallback = (acc, chartType, axis, getters, axisIndex, formattedSeries) => {
2
+ const getter = getters[chartType];
3
+ const series = formattedSeries[chartType]?.series ?? {};
4
+ const [minChartTypeData, maxChartTypeData] = getter?.({
5
+ series,
6
+ axis,
7
+ axisIndex,
8
+ isDefaultAxis: axisIndex === 0
9
+ }) ?? [Infinity, -Infinity];
10
+ const [minData, maxData] = acc;
11
+ return [Math.min(minChartTypeData, minData), Math.max(maxChartTypeData, maxData)];
12
+ };
13
+ export const getAxisExtremum = (axis, getters, axisIndex, formattedSeries) => {
14
+ const charTypes = Object.keys(getters);
15
+ const extremums = charTypes.reduce((acc, charType) => axisExtremumCallback(acc, charType, axis, getters, axisIndex, formattedSeries), [Infinity, -Infinity]);
16
+ if (Number.isNaN(extremums[0]) || Number.isNaN(extremums[1])) {
17
+ return [Infinity, -Infinity];
18
+ }
19
+ return extremums;
20
+ };
File without changes