@mui/x-charts 7.11.0 → 7.11.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 (121) hide show
  1. package/BarChart/BarElement.d.ts +2 -1
  2. package/BarChart/BarLabel/BarLabelItem.d.ts +2 -1
  3. package/BarChart/BarPlot.js +8 -8
  4. package/BarChart/checkScaleErrors.d.ts +4 -4
  5. package/BarChart/checkScaleErrors.js +11 -11
  6. package/BarChart/extremums.js +4 -1
  7. package/BarChart/formatter.js +2 -2
  8. package/CHANGELOG.md +84 -0
  9. package/ChartsAxis/ChartsAxis.js +4 -4
  10. package/ChartsAxisHighlight/ChartsAxisHighlight.js +1 -1
  11. package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +3 -1
  12. package/ChartsOverlay/ChartsOverlay.d.ts +3 -2
  13. package/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  14. package/ChartsReferenceLine/ChartsXReferenceLine.js +1 -2
  15. package/ChartsReferenceLine/ChartsYReferenceLine.js +1 -2
  16. package/ChartsTooltip/ChartsAxisTooltipContent.js +7 -3
  17. package/ChartsTooltip/ChartsItemTooltipContent.js +4 -4
  18. package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +4 -2
  19. package/LineChart/AreaElement.d.ts +2 -1
  20. package/LineChart/AreaPlot.js +10 -6
  21. package/LineChart/LineChart.js +4 -1
  22. package/LineChart/LineElement.d.ts +2 -1
  23. package/LineChart/LineHighlightPlot.d.ts +2 -1
  24. package/LineChart/LineHighlightPlot.js +9 -5
  25. package/LineChart/LinePlot.js +10 -6
  26. package/LineChart/MarkPlot.js +9 -5
  27. package/LineChart/extremums.js +4 -1
  28. package/LineChart/formatter.js +2 -2
  29. package/PieChart/PieArc.js +1 -0
  30. package/ResponsiveChartContainer/useChartContainerDimensions.js +2 -2
  31. package/ScatterChart/ScatterChart.js +4 -1
  32. package/ScatterChart/ScatterPlot.js +6 -3
  33. package/ScatterChart/extremums.js +8 -2
  34. package/context/CartesianProvider/CartesianContext.d.ts +1 -1
  35. package/context/CartesianProvider/normalizeAxis.js +1 -1
  36. package/context/DrawingProvider.d.ts +2 -1
  37. package/context/DrawingProvider.js +7 -1
  38. package/context/SeriesContextProvider.js +1 -1
  39. package/context/ZAxisContextProvider.d.ts +1 -1
  40. package/context/ZAxisContextProvider.js +1 -1
  41. package/esm/BarChart/BarPlot.js +8 -8
  42. package/esm/BarChart/checkScaleErrors.js +11 -11
  43. package/esm/BarChart/extremums.js +4 -1
  44. package/esm/BarChart/formatter.js +2 -2
  45. package/esm/ChartsAxis/ChartsAxis.js +4 -4
  46. package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +1 -1
  47. package/esm/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +3 -1
  48. package/esm/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  49. package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +2 -3
  50. package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +2 -3
  51. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +7 -3
  52. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +4 -4
  53. package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +4 -2
  54. package/esm/LineChart/AreaPlot.js +10 -6
  55. package/esm/LineChart/LineChart.js +4 -1
  56. package/esm/LineChart/LineHighlightPlot.js +9 -5
  57. package/esm/LineChart/LinePlot.js +10 -6
  58. package/esm/LineChart/MarkPlot.js +9 -5
  59. package/esm/LineChart/extremums.js +4 -1
  60. package/esm/LineChart/formatter.js +2 -2
  61. package/esm/PieChart/PieArc.js +1 -0
  62. package/esm/ResponsiveChartContainer/useChartContainerDimensions.js +2 -2
  63. package/esm/ScatterChart/ScatterChart.js +4 -1
  64. package/esm/ScatterChart/ScatterPlot.js +6 -3
  65. package/esm/ScatterChart/extremums.js +8 -2
  66. package/esm/context/CartesianProvider/normalizeAxis.js +1 -1
  67. package/esm/context/DrawingProvider.js +7 -1
  68. package/esm/context/SeriesContextProvider.js +1 -1
  69. package/esm/context/ZAxisContextProvider.js +1 -1
  70. package/esm/hooks/useAxisEvents.js +12 -8
  71. package/esm/internals/SlotComponentPropsFromProps.js +1 -0
  72. package/esm/internals/geometry.js +1 -1
  73. package/esm/internals/getPercentageValue.js +1 -1
  74. package/esm/internals/warning.js +19 -11
  75. package/hooks/useAxisEvents.js +12 -8
  76. package/index.js +1 -1
  77. package/internals/SlotComponentPropsFromProps.d.ts +1 -0
  78. package/internals/SlotComponentPropsFromProps.js +5 -0
  79. package/internals/defaultizeColor.d.ts +7 -0
  80. package/internals/geometry.js +1 -1
  81. package/internals/getPercentageValue.js +1 -1
  82. package/internals/warning.d.ts +2 -1
  83. package/internals/warning.js +21 -12
  84. package/models/seriesType/common.d.ts +10 -0
  85. package/models/seriesType/scatter.d.ts +5 -0
  86. package/modern/BarChart/BarPlot.js +8 -8
  87. package/modern/BarChart/checkScaleErrors.js +11 -11
  88. package/modern/BarChart/extremums.js +4 -1
  89. package/modern/BarChart/formatter.js +2 -2
  90. package/modern/ChartsAxis/ChartsAxis.js +4 -4
  91. package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +1 -1
  92. package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +3 -1
  93. package/modern/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  94. package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +2 -3
  95. package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +2 -3
  96. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +7 -3
  97. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +4 -4
  98. package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +4 -2
  99. package/modern/LineChart/AreaPlot.js +10 -6
  100. package/modern/LineChart/LineChart.js +4 -1
  101. package/modern/LineChart/LineHighlightPlot.js +9 -5
  102. package/modern/LineChart/LinePlot.js +10 -6
  103. package/modern/LineChart/MarkPlot.js +9 -5
  104. package/modern/LineChart/extremums.js +4 -1
  105. package/modern/LineChart/formatter.js +2 -2
  106. package/modern/PieChart/PieArc.js +1 -0
  107. package/modern/ResponsiveChartContainer/useChartContainerDimensions.js +2 -2
  108. package/modern/ScatterChart/ScatterChart.js +4 -1
  109. package/modern/ScatterChart/ScatterPlot.js +6 -3
  110. package/modern/ScatterChart/extremums.js +8 -2
  111. package/modern/context/CartesianProvider/normalizeAxis.js +1 -1
  112. package/modern/context/DrawingProvider.js +7 -1
  113. package/modern/context/SeriesContextProvider.js +1 -1
  114. package/modern/context/ZAxisContextProvider.js +1 -1
  115. package/modern/hooks/useAxisEvents.js +12 -8
  116. package/modern/index.js +1 -1
  117. package/modern/internals/SlotComponentPropsFromProps.js +1 -0
  118. package/modern/internals/geometry.js +1 -1
  119. package/modern/internals/getPercentageValue.js +1 -1
  120. package/modern/internals/warning.js +19 -11
  121. package/package.json +3 -3
@@ -24,7 +24,10 @@ export const getExtremumY = params => {
24
24
  axis,
25
25
  isDefaultAxis
26
26
  } = params;
27
- return Object.keys(series).filter(seriesId => series[seriesId].yAxisKey === axis.id || isDefaultAxis && series[seriesId].yAxisKey === undefined).reduce((acc, seriesId) => {
27
+ return Object.keys(series).filter(seriesId => {
28
+ const yAxisId = series[seriesId].yAxisId ?? series[seriesId].yAxisKey;
29
+ return yAxisId === axis.id || isDefaultAxis && yAxisId === undefined;
30
+ }).reduce((acc, seriesId) => {
28
31
  const {
29
32
  area,
30
33
  stackedData
@@ -31,7 +31,7 @@ const formatter = (params, dataset) => {
31
31
  }
32
32
  });
33
33
  } else if (dataset === undefined && process.env.NODE_ENV !== 'production') {
34
- throw new Error([`MUI X Charts: line series with id='${id}' has no data.`, 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
34
+ throw new Error([`MUI X: line series with id='${id}' has no data.`, 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
35
35
  }
36
36
  });
37
37
  const completedSeries = {};
@@ -56,7 +56,7 @@ const formatter = (params, dataset) => {
56
56
  if (typeof value !== 'number') {
57
57
  if (process.env.NODE_ENV !== 'production' && !warnedOnce && value !== null) {
58
58
  warnedOnce = true;
59
- console.error([`MUI X charts: your dataset key "${dataKey}" is used for plotting line, but contains nonnumerical elements.`, 'Line plots only support numbers and null values.']);
59
+ console.error([`MUI X: Your dataset key "${dataKey}" is used for plotting line, but contains nonnumerical elements.`, 'Line plots only support numbers and null values.']);
60
60
  }
61
61
  return null;
62
62
  }
@@ -73,6 +73,7 @@ function PieArc(props) {
73
73
  innerRadius: iR,
74
74
  outerRadius: oR
75
75
  })),
76
+ visibility: to([startAngle, endAngle], (sA, eA) => sA === eA ? 'hidden' : 'visible'),
76
77
  onClick: onClick,
77
78
  cursor: onClick ? 'pointer' : 'unset',
78
79
  ownerState: ownerState,
@@ -54,11 +54,11 @@ export const useChartContainerDimensions = (inWidth, inHeight) => {
54
54
  }, [computeSize, inHeight, inWidth]);
55
55
  if (process.env.NODE_ENV !== 'production') {
56
56
  if (displayError.current && inWidth === undefined && width === 0) {
57
- console.error(`MUI X Charts: ChartContainer does not have \`width\` prop, and its container has no \`width\` defined.`);
57
+ console.error(`MUI X: ChartContainer does not have \`width\` prop, and its container has no \`width\` defined.`);
58
58
  displayError.current = false;
59
59
  }
60
60
  if (displayError.current && inHeight === undefined && height === 0) {
61
- console.error(`MUI X Charts: ChartContainer does not have \`height\` prop, and its container has no \`height\` defined.`);
61
+ console.error(`MUI X: ChartContainer does not have \`height\` prop, and its container has no \`height\` defined.`);
62
62
  displayError.current = false;
63
63
  }
64
64
  }
@@ -41,7 +41,10 @@ const ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props,
41
41
  ref: ref
42
42
  }, chartContainerProps, {
43
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]
44
+ children: [!props.disableVoronoi && /*#__PURE__*/_jsx(ChartsVoronoiHandler, _extends({}, voronoiHandlerProps)), /*#__PURE__*/_jsx(ChartsAxis, _extends({}, chartsAxisProps)), props.grid && /*#__PURE__*/_jsx(ChartsGrid, _extends({}, gridProps)), /*#__PURE__*/_jsx("g", {
45
+ "data-drawing-container": true,
46
+ children: /*#__PURE__*/_jsx(ScatterPlot, _extends({}, scatterPlotProps))
47
+ }), /*#__PURE__*/_jsx(ChartsOverlay, _extends({}, overlayProps)), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legendProps)), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlightProps)), !props.loading && /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltipProps)), children]
45
48
  }))
46
49
  }));
47
50
  });
@@ -53,12 +53,15 @@ function ScatterPlot(props) {
53
53
  xAxisKey,
54
54
  yAxisKey,
55
55
  zAxisKey,
56
+ xAxisId,
57
+ yAxisId,
58
+ zAxisId,
56
59
  markerSize,
57
60
  color
58
61
  } = series[seriesId];
59
- const colorGetter = getColor(series[seriesId], xAxis[xAxisKey ?? defaultXAxisId], yAxis[yAxisKey ?? defaultYAxisId], zAxis[zAxisKey ?? defaultZAxisId]);
60
- const xScale = xAxis[xAxisKey ?? defaultXAxisId].scale;
61
- const yScale = yAxis[yAxisKey ?? defaultYAxisId].scale;
62
+ const colorGetter = getColor(series[seriesId], xAxis[xAxisId ?? xAxisKey ?? defaultXAxisId], yAxis[yAxisId ?? yAxisKey ?? defaultYAxisId], zAxis[zAxisId ?? zAxisKey ?? defaultZAxisId]);
63
+ const xScale = xAxis[xAxisId ?? xAxisKey ?? defaultXAxisId].scale;
64
+ const yScale = yAxis[yAxisId ?? yAxisKey ?? defaultYAxisId].scale;
62
65
  return /*#__PURE__*/_jsx(ScatterItems, _extends({
63
66
  xScale: xScale,
64
67
  yScale: yScale,
@@ -13,7 +13,10 @@ export const getExtremumX = params => {
13
13
  axis,
14
14
  isDefaultAxis
15
15
  } = params;
16
- return Object.keys(series).filter(seriesId => series[seriesId].xAxisKey === axis.id || series[seriesId].xAxisKey === undefined && isDefaultAxis).reduce((acc, seriesId) => {
16
+ return Object.keys(series).filter(seriesId => {
17
+ const axisId = series[seriesId].xAxisId ?? series[seriesId].xAxisKey;
18
+ return axisId === axis.id || axisId === undefined && isDefaultAxis;
19
+ }).reduce((acc, seriesId) => {
17
20
  const seriesMinMax = series[seriesId].data.reduce((accSeries, {
18
21
  x
19
22
  }) => {
@@ -29,7 +32,10 @@ export const getExtremumY = params => {
29
32
  axis,
30
33
  isDefaultAxis
31
34
  } = params;
32
- return Object.keys(series).filter(seriesId => series[seriesId].yAxisKey === axis.id || series[seriesId].yAxisKey === undefined && isDefaultAxis).reduce((acc, seriesId) => {
35
+ return Object.keys(series).filter(seriesId => {
36
+ const axisId = series[seriesId].yAxisId ?? series[seriesId].yAxisKey;
37
+ return axisId === axis.id || axisId === undefined && isDefaultAxis;
38
+ }).reduce((acc, seriesId) => {
33
39
  const seriesMinMax = series[seriesId].data.reduce((accSeries, {
34
40
  y
35
41
  }) => {
@@ -6,7 +6,7 @@ export const normalizeAxis = (axis, dataset, axisName) => {
6
6
  return axisConfig;
7
7
  }
8
8
  if (dataset === undefined) {
9
- throw Error(`MUI X Charts: ${axisName}-axis uses \`dataKey\` but no \`dataset\` is provided.`);
9
+ throw Error(`MUI X: ${axisName}-axis uses \`dataKey\` but no \`dataset\` is provided.`);
10
10
  }
11
11
  return _extends({}, axisConfig, {
12
12
  data: dataset.map(d => d[dataKey])
@@ -42,7 +42,13 @@ export function DrawingProvider(props) {
42
42
  const isPointInside = React.useCallback(({
43
43
  x,
44
44
  y
45
- }) => x >= drawingArea.left && x <= drawingArea.left + drawingArea.width && y >= drawingArea.top && y <= drawingArea.top + drawingArea.height, [drawingArea]);
45
+ }, targetElement) => {
46
+ // For element allowed to overflow, wrapping them in <g data-drawing-container /> make them fully part of the drawing area.
47
+ if (targetElement && targetElement.closest('[data-drawing-container]')) {
48
+ return true;
49
+ }
50
+ return x >= drawingArea.left && x <= drawingArea.left + drawingArea.width && y >= drawingArea.top && y <= drawingArea.top + drawingArea.height;
51
+ }, [drawingArea]);
46
52
  const value = React.useMemo(() => _extends({
47
53
  chartId: chartId ?? ''
48
54
  }, drawingArea, {
@@ -34,7 +34,7 @@ const preprocessSeries = (series, colors, seriesFormatters, dataset) => {
34
34
  };
35
35
  }
36
36
  if (seriesGroups[type]?.series[id] !== undefined) {
37
- throw new Error(`MUI X Charts: series' id "${id}" is not unique.`);
37
+ throw new Error(`MUI X: series' id "${id}" is not unique.`);
38
38
  }
39
39
  seriesGroups[type].series[id] = _extends({
40
40
  id
@@ -22,7 +22,7 @@ function ZAxisContextProvider(props) {
22
22
  return axisConfig;
23
23
  }
24
24
  if (dataset === undefined) {
25
- throw Error('MUI X Charts: z-axis uses `dataKey` but no `dataset` is provided.');
25
+ throw Error('MUI X: z-axis uses `dataKey` but no `dataset` is provided.');
26
26
  }
27
27
  return _extends({}, axisConfig, {
28
28
  data: dataset.map(d => d[dataKey])
@@ -25,6 +25,7 @@ export const useAxisEvents = disableAxisListener => {
25
25
 
26
26
  // Use a ref to avoid rerendering on every mousemove event.
27
27
  const mousePosition = React.useRef({
28
+ isInChart: false,
28
29
  x: -1,
29
30
  y: -1
30
31
  });
@@ -84,6 +85,7 @@ export const useAxisEvents = disableAxisListener => {
84
85
  }
85
86
  const handleOut = () => {
86
87
  mousePosition.current = {
88
+ isInChart: false,
87
89
  x: -1,
88
90
  y: -1
89
91
  };
@@ -94,16 +96,18 @@ export const useAxisEvents = disableAxisListener => {
94
96
  const handleMove = event => {
95
97
  const target = 'targetTouches' in event ? event.targetTouches[0] : event;
96
98
  const svgPoint = getSVGPoint(element, target);
97
- mousePosition.current = {
98
- x: svgPoint.x,
99
- y: svgPoint.y
100
- };
101
- if (!drawingArea.isPointInside(svgPoint)) {
102
- dispatch({
103
- type: 'exitChart'
104
- });
99
+ mousePosition.current.x = svgPoint.x;
100
+ mousePosition.current.y = svgPoint.y;
101
+ if (!drawingArea.isPointInside(svgPoint, event.target)) {
102
+ if (mousePosition.current.isInChart) {
103
+ dispatch({
104
+ type: 'exitChart'
105
+ });
106
+ mousePosition.current.isInChart = false;
107
+ }
105
108
  return;
106
109
  }
110
+ mousePosition.current.isInChart = true;
107
111
  const newStateX = getNewAxisState(xAxis[usedXAxis], svgPoint.x);
108
112
  const newStateY = getNewAxisState(yAxis[usedYAxis], svgPoint.y);
109
113
  dispatch({
@@ -0,0 +1 @@
1
+ export {};
@@ -14,7 +14,7 @@ export function getMinXTranslation(width, height, angle = 0) {
14
14
  if (process.env.NODE_ENV !== 'production') {
15
15
  if (!warnedOnce && angle > 90 && angle < -90) {
16
16
  warnedOnce = true;
17
- console.warn([`MUI X Charts: It seems you applied an angle larger than 90° or smaller than -90° to an axis text.`, `This could cause some text overlapping.`, `If you encounter a use case where it's needed, please open an issue.`].join('\n'));
17
+ console.warn([`MUI X: It seems you applied an angle larger than 90° or smaller than -90° to an axis text.`, `This could cause some text overlapping.`, `If you encounter a use case where it's needed, please open an issue.`].join('\n'));
18
18
  }
19
19
  }
20
20
  const standardAngle = Math.min(Math.abs(angle) % 180, Math.abs(Math.abs(angle) % 180 - 180) % 180); // Map from R to [0, 90]
@@ -24,5 +24,5 @@ export function getPercentageValue(value, refValue) {
24
24
  return val;
25
25
  }
26
26
  }
27
- throw Error(`MUI X Charts: Received an unknown value "${value}". It should be a number, or a string with a percentage value.`);
27
+ throw Error(`MUI X: Received an unknown value "${value}". It should be a number, or a string with a percentage value.`);
28
28
  }
@@ -1,13 +1,21 @@
1
- export function buildWarning(message, gravity = 'warning') {
2
- let alreadyWarned = false;
3
- return (...args) => {
4
- if (!alreadyWarned) {
5
- alreadyWarned = true;
6
- if (gravity === 'error') {
7
- console.error(message(...args));
8
- } else {
9
- console.warn(message(...args));
10
- }
1
+ const warnedOnceCache = new Set();
2
+
3
+ // TODO move to @mui/x-internals
4
+ // TODO eventually move to @base_ui/internals. Base UI, etc. too need this helper.
5
+ export function warnOnce(message, gravity = 'warning') {
6
+ if (process.env.NODE_ENV === 'production') {
7
+ return;
8
+ }
9
+ const cleanMessage = Array.isArray(message) ? message.join('\n') : message;
10
+ if (!warnedOnceCache.has(cleanMessage)) {
11
+ warnedOnceCache.add(cleanMessage);
12
+ if (gravity === 'error') {
13
+ console.error(cleanMessage);
14
+ } else {
15
+ console.warn(cleanMessage);
11
16
  }
12
- };
17
+ }
18
+ }
19
+ export function clearWarningsCache() {
20
+ warnedOnceCache.clear();
13
21
  }
@@ -33,6 +33,7 @@ const useAxisEvents = disableAxisListener => {
33
33
 
34
34
  // Use a ref to avoid rerendering on every mousemove event.
35
35
  const mousePosition = React.useRef({
36
+ isInChart: false,
36
37
  x: -1,
37
38
  y: -1
38
39
  });
@@ -92,6 +93,7 @@ const useAxisEvents = disableAxisListener => {
92
93
  }
93
94
  const handleOut = () => {
94
95
  mousePosition.current = {
96
+ isInChart: false,
95
97
  x: -1,
96
98
  y: -1
97
99
  };
@@ -102,16 +104,18 @@ const useAxisEvents = disableAxisListener => {
102
104
  const handleMove = event => {
103
105
  const target = 'targetTouches' in event ? event.targetTouches[0] : event;
104
106
  const svgPoint = (0, _getSVGPoint.getSVGPoint)(element, target);
105
- mousePosition.current = {
106
- x: svgPoint.x,
107
- y: svgPoint.y
108
- };
109
- if (!drawingArea.isPointInside(svgPoint)) {
110
- dispatch({
111
- type: 'exitChart'
112
- });
107
+ mousePosition.current.x = svgPoint.x;
108
+ mousePosition.current.y = svgPoint.y;
109
+ if (!drawingArea.isPointInside(svgPoint, event.target)) {
110
+ if (mousePosition.current.isInChart) {
111
+ dispatch({
112
+ type: 'exitChart'
113
+ });
114
+ mousePosition.current.isInChart = false;
115
+ }
113
116
  return;
114
117
  }
118
+ mousePosition.current.isInChart = true;
115
119
  const newStateX = getNewAxisState(xAxis[usedXAxis], svgPoint.x);
116
120
  const newStateY = getNewAxisState(yAxis[usedYAxis], svgPoint.y);
117
121
  dispatch({
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v7.11.0
2
+ * @mui/x-charts v7.11.1
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -0,0 +1 @@
1
+ export type SlotComponentPropsFromProps<TProps extends {}, TOverrides extends {}, TOwnerState extends {}> = (Partial<TProps> & TOverrides) | ((ownerState: TOwnerState) => Partial<TProps> & TOverrides);
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -56,6 +56,8 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
56
56
  highlightScope?: Partial<import("..").HighlightScope>;
57
57
  xAxisKey?: string;
58
58
  yAxisKey?: string;
59
+ xAxisId?: string;
60
+ yAxisId?: string;
59
61
  stack?: string;
60
62
  stackOrder?: import("..").StackOrderType;
61
63
  } | {
@@ -76,6 +78,8 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
76
78
  highlightScope?: Partial<import("..").HighlightScope>;
77
79
  xAxisKey?: string;
78
80
  yAxisKey?: string;
81
+ xAxisId?: string;
82
+ yAxisId?: string;
79
83
  stackOrder?: import("..").StackOrderType;
80
84
  } | {
81
85
  type: "scatter";
@@ -84,10 +88,13 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
84
88
  label?: string | ((location: "tooltip" | "legend") => string);
85
89
  disableHover?: boolean;
86
90
  zAxisKey?: string;
91
+ zAxisId?: string;
87
92
  id?: import(".").SeriesId;
88
93
  color: string;
89
94
  valueFormatter?: import(".").SeriesValueFormatter<import("../models/seriesType").ScatterValueType> | undefined;
90
95
  highlightScope?: Partial<import("..").HighlightScope>;
91
96
  xAxisKey?: string;
92
97
  yAxisKey?: string;
98
+ xAxisId?: string;
99
+ yAxisId?: string;
93
100
  };
@@ -20,7 +20,7 @@ function getMinXTranslation(width, height, angle = 0) {
20
20
  if (process.env.NODE_ENV !== 'production') {
21
21
  if (!warnedOnce && angle > 90 && angle < -90) {
22
22
  warnedOnce = true;
23
- console.warn([`MUI X Charts: It seems you applied an angle larger than 90° or smaller than -90° to an axis text.`, `This could cause some text overlapping.`, `If you encounter a use case where it's needed, please open an issue.`].join('\n'));
23
+ console.warn([`MUI X: It seems you applied an angle larger than 90° or smaller than -90° to an axis text.`, `This could cause some text overlapping.`, `If you encounter a use case where it's needed, please open an issue.`].join('\n'));
24
24
  }
25
25
  }
26
26
  const standardAngle = Math.min(Math.abs(angle) % 180, Math.abs(Math.abs(angle) % 180 - 180) % 180); // Map from R to [0, 90]
@@ -30,5 +30,5 @@ function getPercentageValue(value, refValue) {
30
30
  return val;
31
31
  }
32
32
  }
33
- throw Error(`MUI X Charts: Received an unknown value "${value}". It should be a number, or a string with a percentage value.`);
33
+ throw Error(`MUI X: Received an unknown value "${value}". It should be a number, or a string with a percentage value.`);
34
34
  }
@@ -1 +1,2 @@
1
- export declare function buildWarning(message: (...args: any) => string, gravity?: 'warning' | 'error'): (...args: any) => void;
1
+ export declare function warnOnce(message: string | string[], gravity?: 'warning' | 'error'): void;
2
+ export declare function clearWarningsCache(): void;
@@ -3,17 +3,26 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.buildWarning = buildWarning;
7
- function buildWarning(message, gravity = 'warning') {
8
- let alreadyWarned = false;
9
- return (...args) => {
10
- if (!alreadyWarned) {
11
- alreadyWarned = true;
12
- if (gravity === 'error') {
13
- console.error(message(...args));
14
- } else {
15
- console.warn(message(...args));
16
- }
6
+ exports.clearWarningsCache = clearWarningsCache;
7
+ exports.warnOnce = warnOnce;
8
+ const warnedOnceCache = new Set();
9
+
10
+ // TODO move to @mui/x-internals
11
+ // TODO eventually move to @base_ui/internals. Base UI, etc. too need this helper.
12
+ function warnOnce(message, gravity = 'warning') {
13
+ if (process.env.NODE_ENV === 'production') {
14
+ return;
15
+ }
16
+ const cleanMessage = Array.isArray(message) ? message.join('\n') : message;
17
+ if (!warnedOnceCache.has(cleanMessage)) {
18
+ warnedOnceCache.add(cleanMessage);
19
+ if (gravity === 'error') {
20
+ console.error(cleanMessage);
21
+ } else {
22
+ console.warn(cleanMessage);
17
23
  }
18
- };
24
+ }
25
+ }
26
+ function clearWarningsCache() {
27
+ warnedOnceCache.clear();
19
28
  }
@@ -27,12 +27,22 @@ export type CommonDefaultizedProps = 'id' | 'valueFormatter' | 'data';
27
27
  export type CartesianSeriesType = {
28
28
  /**
29
29
  * The id of the x-axis used to render the series.
30
+ * @deprecated Use `xAxisId` instead
30
31
  */
31
32
  xAxisKey?: string;
32
33
  /**
33
34
  * The id of the y-axis used to render the series.
35
+ * @deprecated Use `xAxisId` instead
34
36
  */
35
37
  yAxisKey?: string;
38
+ /**
39
+ * The id of the x-axis used to render the series.
40
+ */
41
+ xAxisId?: string;
42
+ /**
43
+ * The id of the y-axis used to render the series.
44
+ */
45
+ yAxisId?: string;
36
46
  };
37
47
  export type StackableSeriesType = {
38
48
  /**
@@ -24,8 +24,13 @@ export interface ScatterSeriesType extends CommonSeriesType<ScatterValueType>, C
24
24
  disableHover?: boolean;
25
25
  /**
26
26
  * The id of the z-axis used to render the series.
27
+ * @deprecated Use `zAxisId` instead.
27
28
  */
28
29
  zAxisKey?: string;
30
+ /**
31
+ * The id of the z-axis used to render the series.
32
+ */
33
+ zAxisId?: string;
29
34
  }
30
35
  /**
31
36
  * An object that allows to identify a single scatter item.
@@ -66,16 +66,16 @@ const useAggregatedData = () => {
66
66
  ids: groupIds
67
67
  }, groupIndex) => {
68
68
  return groupIds.flatMap(seriesId => {
69
- const xAxisKey = series[seriesId].xAxisKey ?? defaultXAxisId;
70
- const yAxisKey = series[seriesId].yAxisKey ?? defaultYAxisId;
71
- const xAxisConfig = xAxis[xAxisKey];
72
- const yAxisConfig = yAxis[yAxisKey];
69
+ const xAxisId = series[seriesId].xAxisId ?? series[seriesId].xAxisKey ?? defaultXAxisId;
70
+ const yAxisId = series[seriesId].yAxisId ?? series[seriesId].yAxisKey ?? defaultYAxisId;
71
+ const xAxisConfig = xAxis[xAxisId];
72
+ const yAxisConfig = yAxis[yAxisId];
73
73
  const verticalLayout = series[seriesId].layout === 'vertical';
74
- checkScaleErrors(verticalLayout, seriesId, xAxisKey, xAxis, yAxisKey, yAxis);
74
+ checkScaleErrors(verticalLayout, seriesId, xAxisId, xAxis, yAxisId, yAxis);
75
75
  const baseScaleConfig = verticalLayout ? xAxisConfig : yAxisConfig;
76
76
  const xScale = xAxisConfig.scale;
77
77
  const yScale = yAxisConfig.scale;
78
- const colorGetter = getColor(series[seriesId], xAxis[xAxisKey], yAxis[yAxisKey]);
78
+ const colorGetter = getColor(series[seriesId], xAxis[xAxisId], yAxis[yAxisId]);
79
79
  const bandWidth = baseScaleConfig.scale.bandwidth();
80
80
  const {
81
81
  barWidth,
@@ -98,8 +98,8 @@ const useAggregatedData = () => {
98
98
  seriesId,
99
99
  dataIndex,
100
100
  layout: series[seriesId].layout,
101
- x: verticalLayout ? xScale(xAxis[xAxisKey].data?.[dataIndex]) + barOffset : minValueCoord,
102
- y: verticalLayout ? minValueCoord : yScale(yAxis[yAxisKey].data?.[dataIndex]) + barOffset,
101
+ x: verticalLayout ? xScale(xAxis[xAxisId].data?.[dataIndex]) + barOffset : minValueCoord,
102
+ y: verticalLayout ? minValueCoord : yScale(yAxis[yAxisId].data?.[dataIndex]) + barOffset,
103
103
  xOrigin: xScale(0),
104
104
  yOrigin: yScale(0),
105
105
  height: verticalLayout ? maxValueCoord - minValueCoord : barWidth,
@@ -1,27 +1,27 @@
1
1
  import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
2
2
  import { isBandScaleConfig, isPointScaleConfig } from '../models/axis';
3
- const getAxisMessage = (axisDirection, axisKey) => {
3
+ const getAxisMessage = (axisDirection, axisId) => {
4
4
  const axisName = `${axisDirection}-axis`;
5
- const axisKeyName = `${axisDirection}Axis`;
5
+ const axisIdName = `${axisDirection}Axis`;
6
6
  const axisDefaultKey = axisDirection === 'x' ? DEFAULT_X_AXIS_KEY : DEFAULT_Y_AXIS_KEY;
7
- return axisKey === axisDefaultKey ? `The first \`${axisKeyName}\`` : `The ${axisName} with id "${axisKey}"`;
7
+ return axisId === axisDefaultKey ? `The first \`${axisIdName}\`` : `The ${axisName} with id "${axisId}"`;
8
8
  };
9
- export function checkScaleErrors(verticalLayout, seriesId, xAxisKey, xAxis, yAxisKey, yAxis) {
10
- const xAxisConfig = xAxis[xAxisKey];
11
- const yAxisConfig = yAxis[yAxisKey];
9
+ export function checkScaleErrors(verticalLayout, seriesId, xAxisId, xAxis, yAxisId, yAxis) {
10
+ const xAxisConfig = xAxis[xAxisId];
11
+ const yAxisConfig = yAxis[yAxisId];
12
12
  const discreteAxisConfig = verticalLayout ? xAxisConfig : yAxisConfig;
13
13
  const continuousAxisConfig = verticalLayout ? yAxisConfig : xAxisConfig;
14
- const discreteAxisKey = verticalLayout ? xAxisKey : yAxisKey;
15
- const continuousAxisKey = verticalLayout ? yAxisKey : xAxisKey;
14
+ const discreteAxisId = verticalLayout ? xAxisId : yAxisId;
15
+ const continuousAxisId = verticalLayout ? yAxisId : xAxisId;
16
16
  const discreteAxisDirection = verticalLayout ? 'x' : 'y';
17
17
  const continuousAxisDirection = verticalLayout ? 'y' : 'x';
18
18
  if (!isBandScaleConfig(discreteAxisConfig)) {
19
- throw new Error(`MUI X Charts: ${getAxisMessage(discreteAxisDirection, discreteAxisKey)} should be of type "band" to display the bar series of id "${seriesId}".`);
19
+ throw new Error(`MUI X: ${getAxisMessage(discreteAxisDirection, discreteAxisId)} should be of type "band" to display the bar series of id "${seriesId}".`);
20
20
  }
21
21
  if (discreteAxisConfig.data === undefined) {
22
- throw new Error(`MUI X Charts: ${getAxisMessage(discreteAxisDirection, discreteAxisKey)} should have data property.`);
22
+ throw new Error(`MUI X: ${getAxisMessage(discreteAxisDirection, discreteAxisId)} should have data property.`);
23
23
  }
24
24
  if (isBandScaleConfig(continuousAxisConfig) || isPointScaleConfig(continuousAxisConfig)) {
25
- throw new Error(`MUI X Charts: ${getAxisMessage(continuousAxisDirection, continuousAxisKey)} should be a continuous type to display the bar series of id "${seriesId}".`);
25
+ throw new Error(`MUI X: ${getAxisMessage(continuousAxisDirection, continuousAxisId)} should be a continuous type to display the bar series of id "${seriesId}".`);
26
26
  }
27
27
  }
@@ -12,7 +12,10 @@ const getValueExtremum = params => {
12
12
  axis,
13
13
  isDefaultAxis
14
14
  } = params;
15
- return Object.keys(series).filter(seriesId => series[seriesId].yAxisKey === axis.id || isDefaultAxis && series[seriesId].yAxisKey === undefined).reduce((acc, seriesId) => {
15
+ return Object.keys(series).filter(seriesId => {
16
+ const yAxisId = series[seriesId].yAxisId ?? series[seriesId].yAxisKey;
17
+ return yAxisId === axis.id || isDefaultAxis && yAxisId === undefined;
18
+ }).reduce((acc, seriesId) => {
16
19
  const [seriesMin, seriesMax] = series[seriesId].stackedData?.reduce((seriesAcc, values) => [Math.min(...values, ...(seriesAcc[0] === null ? [] : [seriesAcc[0]])), Math.max(...values, ...(seriesAcc[1] === null ? [] : [seriesAcc[1]]))], series[seriesId].stackedData[0]) ?? [null, null];
17
20
  return [acc[0] === null ? seriesMin : Math.min(seriesMin, acc[0]), acc[1] === null ? seriesMax : Math.max(seriesMax, acc[1])];
18
21
  }, [null, null]);
@@ -25,7 +25,7 @@ const formatter = (params, dataset) => {
25
25
  }
26
26
  });
27
27
  } else if (dataset === undefined) {
28
- throw new Error([`MUI X Charts: bar series with id='${id}' has no data.`, 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
28
+ throw new Error([`MUI X: bar series with id='${id}' has no data.`, 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
29
29
  }
30
30
  });
31
31
  const completedSeries = {};
@@ -52,7 +52,7 @@ const formatter = (params, dataset) => {
52
52
  if (typeof value !== 'number') {
53
53
  if (process.env.NODE_ENV !== 'production' && !warnOnce && value !== null) {
54
54
  warnOnce = true;
55
- console.error([`MUI X charts: your dataset key "${dataKey}" is used for plotting bars, but contains nonnumerical elements.`, 'Bar plots only support numbers and null values.']);
55
+ console.error([`MUI X charts: your dataset key "${dataKey}" is used for plotting bars, but contains nonnumerical elements.`, 'Bar plots only support numbers and null values.'].join('\n'));
56
56
  }
57
57
  return 0;
58
58
  }
@@ -57,16 +57,16 @@ function ChartsAxis(props) {
57
57
  const topId = getAxisId(topAxis, xAxisIds[0]);
58
58
  const rightId = getAxisId(rightAxis, yAxisIds[0]);
59
59
  if (topId !== null && !xAxis[topId]) {
60
- throw Error([`MUI X Charts: id used for top axis "${topId}" is not defined.`, `Available ids are: ${xAxisIds.join(', ')}.`].join('\n'));
60
+ throw Error([`MUI X: id used for top axis "${topId}" is not defined.`, `Available ids are: ${xAxisIds.join(', ')}.`].join('\n'));
61
61
  }
62
62
  if (leftId !== null && !yAxis[leftId]) {
63
- throw Error([`MUI X Charts: id used for left axis "${leftId}" is not defined.`, `Available ids are: ${yAxisIds.join(', ')}.`].join('\n'));
63
+ throw Error([`MUI X: id used for left axis "${leftId}" is not defined.`, `Available ids are: ${yAxisIds.join(', ')}.`].join('\n'));
64
64
  }
65
65
  if (rightId !== null && !yAxis[rightId]) {
66
- throw Error([`MUI X Charts: id used for right axis "${rightId}" is not defined.`, `Available ids are: ${yAxisIds.join(', ')}.`].join('\n'));
66
+ throw Error([`MUI X: id used for right axis "${rightId}" is not defined.`, `Available ids are: ${yAxisIds.join(', ')}.`].join('\n'));
67
67
  }
68
68
  if (bottomId !== null && !xAxis[bottomId]) {
69
- throw Error([`MUI X Charts: id used for bottom axis "${bottomId}" is not defined.`, `Available ids are: ${xAxisIds.join(', ')}.`].join('\n'));
69
+ throw Error([`MUI X: id used for bottom axis "${bottomId}" is not defined.`, `Available ids are: ${xAxisIds.join(', ')}.`].join('\n'));
70
70
  }
71
71
  const topAxisProps = mergeProps(topAxis, slots, slotProps);
72
72
  const bottomAxisProps = mergeProps(bottomAxis, slots, slotProps);
@@ -74,7 +74,7 @@ function ChartsAxisHighlight(props) {
74
74
  const isXError = isBandScaleX && xScale(axisX.value) === undefined;
75
75
  const isYError = isBandScaleY && yScale(axisY.value) === undefined;
76
76
  if (isXError || isYError) {
77
- console.error([`MUI X Charts: The position value provided for the axis is not valid for the current scale.`, `This probably means something is wrong with the data passed to the chart.`, `The ChartsAxisHighlight component will not be displayed.`].join('\n'));
77
+ console.error([`MUI X: The position value provided for the axis is not valid for the current scale.`, `This probably means something is wrong with the data passed to the chart.`, `The ChartsAxisHighlight component will not be displayed.`].join('\n'));
78
78
  }
79
79
  }
80
80
  return /*#__PURE__*/_jsxs(React.Fragment, {
@@ -37,7 +37,9 @@ function ChartsOnAxisClickHandler(props) {
37
37
  Object.keys(series).filter(seriesType => ['bar', 'line'].includes(seriesType)).forEach(seriesType => {
38
38
  series[seriesType]?.seriesOrder.forEach(seriesId => {
39
39
  const seriesItem = series[seriesType].series[seriesId];
40
- const axisKey = isXaxis ? seriesItem.xAxisKey : seriesItem.yAxisKey;
40
+ const providedXAxisId = seriesItem.xAxisId ?? seriesItem.xAxisKey;
41
+ const providedYAxisId = seriesItem.yAxisId ?? seriesItem.yAxisKey;
42
+ const axisKey = isXaxis ? providedXAxisId : providedYAxisId;
41
43
  if (axisKey === undefined || axisKey === USED_AXIS_ID) {
42
44
  seriesValues[seriesId] = seriesItem.data[dataIndex];
43
45
  }
@@ -10,10 +10,10 @@ function ChartsReferenceLine(props) {
10
10
  y
11
11
  } = props;
12
12
  if (x !== undefined && y !== undefined) {
13
- throw new Error('MUI X Charts: The ChartsReferenceLine cannot have both `x` and `y` props set.');
13
+ throw new Error('MUI X: The ChartsReferenceLine cannot have both `x` and `y` props set.');
14
14
  }
15
15
  if (x === undefined && y === undefined) {
16
- throw new Error('MUI X Charts: The ChartsReferenceLine should have a value in `x` or `y` prop.');
16
+ throw new Error('MUI X: The ChartsReferenceLine should have a value in `x` or `y` prop.');
17
17
  }
18
18
  if (x !== undefined) {
19
19
  return /*#__PURE__*/_jsx(ChartsXReferenceLine, _extends({}, props));