@mui/x-charts 7.3.1 → 7.4.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 (147) hide show
  1. package/BarChart/BarChart.d.ts +4 -3
  2. package/BarChart/BarChart.js +22 -6
  3. package/BarChart/BarClipPath.d.ts +14 -0
  4. package/BarChart/BarClipPath.js +50 -0
  5. package/BarChart/BarPlot.d.ts +4 -0
  6. package/BarChart/BarPlot.js +108 -36
  7. package/BarChart/getRadius.d.ts +15 -0
  8. package/BarChart/getRadius.js +37 -0
  9. package/BarChart/types.d.ts +25 -0
  10. package/BarChart/types.js +5 -0
  11. package/CHANGELOG.md +141 -5
  12. package/ChartsAxis/axisClasses.d.ts +1 -1
  13. package/ChartsGrid/ChartsGrid.js +22 -11
  14. package/ChartsOverlay/ChartsLoadingOverlay.d.ts +3 -0
  15. package/ChartsOverlay/ChartsLoadingOverlay.js +43 -0
  16. package/ChartsOverlay/ChartsNoDataOverlay.d.ts +3 -0
  17. package/ChartsOverlay/ChartsNoDataOverlay.js +43 -0
  18. package/ChartsOverlay/ChartsOverlay.d.ts +35 -0
  19. package/ChartsOverlay/ChartsOverlay.js +41 -0
  20. package/ChartsOverlay/index.d.ts +3 -0
  21. package/ChartsOverlay/index.js +26 -0
  22. package/ChartsOverlay/package.json +6 -0
  23. package/ChartsReferenceLine/ChartsReferenceLine.js +1 -1
  24. package/ChartsReferenceLine/common.d.ts +1 -1
  25. package/ChartsTooltip/ChartsAxisTooltipContent.d.ts +1 -1
  26. package/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  27. package/ChartsTooltip/ChartsTooltip.d.ts +2 -2
  28. package/ChartsTooltip/ChartsTooltip.js +2 -2
  29. package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +1 -1
  30. package/ChartsXAxis/ChartsXAxis.d.ts +1 -1
  31. package/ChartsXAxis/ChartsXAxis.js +7 -0
  32. package/ChartsYAxis/ChartsYAxis.d.ts +1 -1
  33. package/ChartsYAxis/ChartsYAxis.js +7 -0
  34. package/Gauge/Gauge.js +1 -1
  35. package/Gauge/GaugeContainer.js +1 -1
  36. package/Gauge/GaugeProvider.d.ts +2 -2
  37. package/Gauge/GaugeProvider.js +1 -1
  38. package/Gauge/gaugeClasses.d.ts +2 -2
  39. package/Gauge/utils.d.ts +1 -1
  40. package/Gauge/utils.js +4 -4
  41. package/LineChart/AreaElement.d.ts +1 -1
  42. package/LineChart/LineChart.d.ts +4 -3
  43. package/LineChart/LineChart.js +12 -2
  44. package/LineChart/LineElement.d.ts +1 -1
  45. package/LineChart/MarkElement.d.ts +1 -1
  46. package/PieChart/PieArc.d.ts +1 -1
  47. package/PieChart/PieArcLabel.d.ts +1 -1
  48. package/PieChart/PieArcLabel.js +1 -1
  49. package/PieChart/PieArcLabelPlot.d.ts +1 -1
  50. package/PieChart/PieArcLabelPlot.js +3 -3
  51. package/PieChart/PieArcPlot.d.ts +1 -1
  52. package/PieChart/PieArcPlot.js +3 -3
  53. package/PieChart/PieChart.d.ts +4 -3
  54. package/PieChart/PieChart.js +15 -2
  55. package/ScatterChart/ScatterChart.d.ts +4 -3
  56. package/ScatterChart/ScatterChart.js +12 -2
  57. package/context/SeriesContextProvider.js +1 -1
  58. package/esm/BarChart/BarChart.js +22 -6
  59. package/esm/BarChart/BarClipPath.js +42 -0
  60. package/esm/BarChart/BarPlot.js +109 -37
  61. package/esm/BarChart/getRadius.js +30 -0
  62. package/esm/BarChart/types.js +1 -0
  63. package/esm/ChartsGrid/ChartsGrid.js +23 -12
  64. package/esm/ChartsOverlay/ChartsLoadingOverlay.js +34 -0
  65. package/esm/ChartsOverlay/ChartsNoDataOverlay.js +34 -0
  66. package/esm/ChartsOverlay/ChartsOverlay.js +31 -0
  67. package/esm/ChartsOverlay/index.js +3 -0
  68. package/esm/ChartsReferenceLine/ChartsReferenceLine.js +1 -1
  69. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  70. package/esm/ChartsTooltip/ChartsTooltip.js +2 -2
  71. package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +1 -1
  72. package/esm/ChartsXAxis/ChartsXAxis.js +7 -0
  73. package/esm/ChartsYAxis/ChartsYAxis.js +7 -0
  74. package/esm/Gauge/Gauge.js +1 -1
  75. package/esm/Gauge/GaugeContainer.js +1 -1
  76. package/esm/Gauge/GaugeProvider.js +1 -1
  77. package/esm/Gauge/utils.js +4 -4
  78. package/esm/LineChart/LineChart.js +12 -2
  79. package/esm/PieChart/PieArcLabel.js +1 -1
  80. package/esm/PieChart/PieArcLabelPlot.js +3 -3
  81. package/esm/PieChart/PieArcPlot.js +3 -3
  82. package/esm/PieChart/PieChart.js +15 -2
  83. package/esm/ScatterChart/ScatterChart.js +12 -2
  84. package/esm/context/SeriesContextProvider.js +1 -1
  85. package/esm/hooks/useReducedMotion.js +1 -1
  86. package/esm/hooks/useScale.js +1 -1
  87. package/esm/hooks/useTicks.js +4 -0
  88. package/esm/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +5 -5
  89. package/esm/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +3 -3
  90. package/esm/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +3 -3
  91. package/esm/internals/utils.js +1 -1
  92. package/hooks/useReducedMotion.d.ts +1 -1
  93. package/hooks/useReducedMotion.js +1 -1
  94. package/hooks/useScale.d.ts +4 -4
  95. package/hooks/useScale.js +1 -1
  96. package/hooks/useTicks.js +4 -0
  97. package/index.js +1 -1
  98. package/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +5 -5
  99. package/internals/components/ChartsAxesGradients/ChartsContinuousGradient.d.ts +1 -1
  100. package/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +3 -3
  101. package/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.d.ts +1 -1
  102. package/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +3 -3
  103. package/internals/utils.d.ts +1 -1
  104. package/internals/utils.js +1 -1
  105. package/models/axis.d.ts +1 -1
  106. package/models/seriesType/bar.d.ts +1 -1
  107. package/models/seriesType/line.d.ts +1 -1
  108. package/models/seriesType/pie.d.ts +4 -4
  109. package/modern/BarChart/BarChart.js +22 -6
  110. package/modern/BarChart/BarClipPath.js +42 -0
  111. package/modern/BarChart/BarPlot.js +109 -37
  112. package/modern/BarChart/getRadius.js +30 -0
  113. package/modern/BarChart/types.js +1 -0
  114. package/modern/ChartsGrid/ChartsGrid.js +23 -12
  115. package/modern/ChartsOverlay/ChartsLoadingOverlay.js +34 -0
  116. package/modern/ChartsOverlay/ChartsNoDataOverlay.js +34 -0
  117. package/modern/ChartsOverlay/ChartsOverlay.js +31 -0
  118. package/modern/ChartsOverlay/index.js +3 -0
  119. package/modern/ChartsReferenceLine/ChartsReferenceLine.js +1 -1
  120. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  121. package/modern/ChartsTooltip/ChartsTooltip.js +2 -2
  122. package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +1 -1
  123. package/modern/ChartsXAxis/ChartsXAxis.js +7 -0
  124. package/modern/ChartsYAxis/ChartsYAxis.js +7 -0
  125. package/modern/Gauge/Gauge.js +1 -1
  126. package/modern/Gauge/GaugeContainer.js +1 -1
  127. package/modern/Gauge/GaugeProvider.js +1 -1
  128. package/modern/Gauge/utils.js +4 -4
  129. package/modern/LineChart/LineChart.js +12 -2
  130. package/modern/PieChart/PieArcLabel.js +1 -1
  131. package/modern/PieChart/PieArcLabelPlot.js +3 -3
  132. package/modern/PieChart/PieArcPlot.js +3 -3
  133. package/modern/PieChart/PieChart.js +15 -2
  134. package/modern/ScatterChart/ScatterChart.js +12 -2
  135. package/modern/context/SeriesContextProvider.js +1 -1
  136. package/modern/hooks/useReducedMotion.js +1 -1
  137. package/modern/hooks/useScale.js +1 -1
  138. package/modern/hooks/useTicks.js +4 -0
  139. package/modern/index.js +1 -1
  140. package/modern/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +5 -5
  141. package/modern/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +3 -3
  142. package/modern/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +3 -3
  143. package/modern/internals/utils.js +1 -1
  144. package/package.json +2 -2
  145. package/themeAugmentation/components.d.ts +4 -0
  146. package/themeAugmentation/overrides.d.ts +2 -0
  147. package/themeAugmentation/props.d.ts +2 -0
@@ -0,0 +1,42 @@
1
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
+ import _extends from "@babel/runtime/helpers/esm/extends";
3
+ const _excluded = ["style", "maskId"];
4
+ import * as React from 'react';
5
+ import { animated } from '@react-spring/web';
6
+ import { getRadius } from './getRadius';
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ const buildInset = corners => `inset(0px round ${corners.topLeft}px ${corners.topRight}px ${corners.bottomRight}px ${corners.bottomLeft}px)`;
9
+ function BarClipRect(props) {
10
+ const radiusData = props.ownerState;
11
+ return /*#__PURE__*/_jsx(animated.rect, {
12
+ style: _extends({}, props.style, {
13
+ clipPath: (props.ownerState.layout === 'vertical' ? props.style?.height : props.style?.width).to(value => buildInset({
14
+ topLeft: Math.min(value, getRadius('top-left', radiusData)),
15
+ topRight: Math.min(value, getRadius('top-right', radiusData)),
16
+ bottomRight: Math.min(value, getRadius('bottom-right', radiusData)),
17
+ bottomLeft: Math.min(value, getRadius('bottom-left', radiusData))
18
+ }))
19
+ })
20
+ });
21
+ }
22
+ /**
23
+ * @ignore - internal component.
24
+ */
25
+ function BarClipPath(props) {
26
+ const {
27
+ style,
28
+ maskId
29
+ } = props,
30
+ rest = _objectWithoutPropertiesLoose(props, _excluded);
31
+ if (!props.borderRadius || props.borderRadius <= 0) {
32
+ return null;
33
+ }
34
+ return /*#__PURE__*/_jsx("clipPath", {
35
+ id: maskId,
36
+ children: /*#__PURE__*/_jsx(BarClipRect, {
37
+ ownerState: rest,
38
+ style: style
39
+ })
40
+ });
41
+ }
42
+ export { BarClipPath };
@@ -1,6 +1,6 @@
1
1
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
- const _excluded = ["skipAnimation", "onItemClick"];
3
+ const _excluded = ["skipAnimation", "onItemClick", "borderRadius"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import { useTransition } from '@react-spring/web';
@@ -10,6 +10,8 @@ import { BarElement } from './BarElement';
10
10
  import { isBandScaleConfig, isPointScaleConfig } from '../models/axis';
11
11
  import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
12
12
  import getColor from './getColor';
13
+ import { useChartId } from '../hooks';
14
+ import { BarClipPath } from './BarClipPath';
13
15
 
14
16
  /**
15
17
  * Solution of the equations
@@ -20,7 +22,7 @@ import getColor from './getColor';
20
22
  * @param gapRatio The ratio of the gap between bars over the bar width.
21
23
  * @returns The bar width and the offset between bars.
22
24
  */
23
- import { jsx as _jsx } from "react/jsx-runtime";
25
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
24
26
  function getBandSize({
25
27
  bandWidth: W,
26
28
  numberOfGroups: N,
@@ -46,6 +48,7 @@ const useAggregatedData = () => {
46
48
  seriesOrder: []
47
49
  };
48
50
  const axisData = React.useContext(CartesianContext);
51
+ const chartId = useChartId();
49
52
  const {
50
53
  series,
51
54
  stackingGroups
@@ -58,6 +61,7 @@ const useAggregatedData = () => {
58
61
  } = axisData;
59
62
  const defaultXAxisId = xAxisIds[0];
60
63
  const defaultYAxisId = yAxisIds[0];
64
+ const masks = {};
61
65
  const data = stackingGroups.flatMap(({
62
66
  ids: groupIds
63
67
  }, groupIndex) => {
@@ -70,25 +74,25 @@ const useAggregatedData = () => {
70
74
  let baseScaleConfig;
71
75
  if (verticalLayout) {
72
76
  if (!isBandScaleConfig(xAxisConfig)) {
73
- throw new Error(`MUI X Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} shoud be of type "band" to display the bar series of id "${seriesId}".`);
77
+ throw new Error(`MUI X Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} should be of type "band" to display the bar series of id "${seriesId}".`);
74
78
  }
75
79
  if (xAxis[xAxisKey].data === undefined) {
76
- throw new Error(`MUI X Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} shoud have data property.`);
80
+ throw new Error(`MUI X Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} should have data property.`);
77
81
  }
78
82
  baseScaleConfig = xAxisConfig;
79
83
  if (isBandScaleConfig(yAxisConfig) || isPointScaleConfig(yAxisConfig)) {
80
- throw new Error(`MUI X Charts: ${yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} shoud be a continuous type to display the bar series of id "${seriesId}".`);
84
+ throw new Error(`MUI X Charts: ${yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} should be a continuous type to display the bar series of id "${seriesId}".`);
81
85
  }
82
86
  } else {
83
87
  if (!isBandScaleConfig(yAxisConfig)) {
84
- throw new Error(`MUI X Charts: ${yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} shoud be of type "band" to display the bar series of id "${seriesId}".`);
88
+ throw new Error(`MUI X Charts: ${yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} should be of type "band" to display the bar series of id "${seriesId}".`);
85
89
  }
86
90
  if (yAxis[yAxisKey].data === undefined) {
87
- throw new Error(`MUI X Charts: ${yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} shoud have data property.`);
91
+ throw new Error(`MUI X Charts: ${yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} should have data property.`);
88
92
  }
89
93
  baseScaleConfig = yAxisConfig;
90
94
  if (isBandScaleConfig(xAxisConfig) || isPointScaleConfig(xAxisConfig)) {
91
- throw new Error(`MUI X Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} shoud be a continuous type to display the bar series of id "${seriesId}".`);
95
+ throw new Error(`MUI X Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} should be a continuous type to display the bar series of id "${seriesId}".`);
92
96
  }
93
97
  }
94
98
  const xScale = xAxisConfig.scale;
@@ -111,7 +115,8 @@ const useAggregatedData = () => {
111
115
  const valueCoordinates = values.map(v => verticalLayout ? yScale(v) : xScale(v));
112
116
  const minValueCoord = Math.round(Math.min(...valueCoordinates));
113
117
  const maxValueCoord = Math.round(Math.max(...valueCoordinates));
114
- return {
118
+ const stackId = series[seriesId].stack;
119
+ const result = {
115
120
  seriesId,
116
121
  dataIndex,
117
122
  layout: series[seriesId].layout,
@@ -122,14 +127,41 @@ const useAggregatedData = () => {
122
127
  height: verticalLayout ? maxValueCoord - minValueCoord : barWidth,
123
128
  width: verticalLayout ? barWidth : maxValueCoord - minValueCoord,
124
129
  color: colorGetter(dataIndex),
125
- highlightScope: series[seriesId].highlightScope
130
+ highlightScope: series[seriesId].highlightScope,
131
+ value: series[seriesId].data[dataIndex],
132
+ maskId: `${chartId}_${stackId || seriesId}_${groupIndex}_${dataIndex}`
126
133
  };
134
+ if (!masks[result.maskId]) {
135
+ masks[result.maskId] = {
136
+ id: result.maskId,
137
+ width: 0,
138
+ height: 0,
139
+ hasNegative: false,
140
+ hasPositive: false,
141
+ layout: result.layout,
142
+ xOrigin: xScale(0),
143
+ yOrigin: yScale(0),
144
+ x: 0,
145
+ y: 0
146
+ };
147
+ }
148
+ const mask = masks[result.maskId];
149
+ mask.width = result.layout === 'vertical' ? result.width : mask.width + result.width;
150
+ mask.height = result.layout === 'vertical' ? mask.height + result.height : result.height;
151
+ mask.x = Math.min(mask.x === 0 ? Infinity : mask.x, result.x);
152
+ mask.y = Math.min(mask.y === 0 ? Infinity : mask.y, result.y);
153
+ mask.hasNegative = mask.hasNegative || (result.value ?? 0) < 0;
154
+ mask.hasPositive = mask.hasPositive || (result.value ?? 0) > 0;
155
+ return result;
127
156
  });
128
157
  });
129
158
  });
130
- return data;
159
+ return {
160
+ completedData: data,
161
+ masksData: Object.values(masks)
162
+ };
131
163
  };
132
- const getOutStyle = ({
164
+ const leaveStyle = ({
133
165
  layout,
134
166
  yOrigin,
135
167
  x,
@@ -148,7 +180,7 @@ const getOutStyle = ({
148
180
  height,
149
181
  width: 0
150
182
  });
151
- const getInStyle = ({
183
+ const enterStyle = ({
152
184
  x,
153
185
  width,
154
186
  y,
@@ -172,41 +204,77 @@ const getInStyle = ({
172
204
  * - [BarPlot API](https://mui.com/x/api/charts/bar-plot/)
173
205
  */
174
206
  function BarPlot(props) {
175
- const completedData = useAggregatedData();
207
+ const {
208
+ completedData,
209
+ masksData
210
+ } = useAggregatedData();
176
211
  const {
177
212
  skipAnimation,
178
- onItemClick
213
+ onItemClick,
214
+ borderRadius
179
215
  } = props,
180
216
  other = _objectWithoutPropertiesLoose(props, _excluded);
181
217
  const transition = useTransition(completedData, {
182
218
  keys: bar => `${bar.seriesId}-${bar.dataIndex}`,
183
- from: getOutStyle,
184
- leave: getOutStyle,
185
- enter: getInStyle,
186
- update: getInStyle,
219
+ from: leaveStyle,
220
+ leave: leaveStyle,
221
+ enter: enterStyle,
222
+ update: enterStyle,
223
+ immediate: skipAnimation
224
+ });
225
+ const maskTransition = useTransition(masksData, {
226
+ keys: v => v.id,
227
+ from: leaveStyle,
228
+ leave: leaveStyle,
229
+ enter: enterStyle,
230
+ update: enterStyle,
187
231
  immediate: skipAnimation
188
232
  });
189
- return /*#__PURE__*/_jsx(React.Fragment, {
190
- children: transition((style, {
233
+ return /*#__PURE__*/_jsxs(React.Fragment, {
234
+ children: [maskTransition((style, {
235
+ id,
236
+ hasPositive,
237
+ hasNegative,
238
+ layout
239
+ }) => {
240
+ return /*#__PURE__*/_jsx(BarClipPath, {
241
+ maskId: id,
242
+ borderRadius: borderRadius,
243
+ hasNegative: hasNegative,
244
+ hasPositive: hasPositive,
245
+ layout: layout,
246
+ style: style
247
+ });
248
+ }), transition((style, {
191
249
  seriesId,
192
250
  dataIndex,
193
251
  color,
194
- highlightScope
195
- }) => /*#__PURE__*/_jsx(BarElement, _extends({
196
- id: seriesId,
197
- dataIndex: dataIndex,
198
- highlightScope: highlightScope,
199
- color: color
200
- }, other, {
201
- onClick: onItemClick && (event => {
202
- onItemClick(event, {
203
- type: 'bar',
204
- seriesId,
205
- dataIndex
206
- });
207
- }),
208
- style: style
209
- })))
252
+ highlightScope,
253
+ maskId
254
+ }) => {
255
+ const barElement = /*#__PURE__*/_jsx(BarElement, _extends({
256
+ id: seriesId,
257
+ dataIndex: dataIndex,
258
+ color: color,
259
+ highlightScope: highlightScope
260
+ }, other, {
261
+ onClick: onItemClick && (event => {
262
+ onItemClick(event, {
263
+ type: 'bar',
264
+ seriesId,
265
+ dataIndex
266
+ });
267
+ }),
268
+ style: style
269
+ }));
270
+ if (!borderRadius || borderRadius <= 0) {
271
+ return barElement;
272
+ }
273
+ return /*#__PURE__*/_jsx("g", {
274
+ clipPath: `url(#${maskId})`,
275
+ children: barElement
276
+ });
277
+ })]
210
278
  });
211
279
  }
212
280
  process.env.NODE_ENV !== "production" ? BarPlot.propTypes = {
@@ -214,6 +282,10 @@ process.env.NODE_ENV !== "production" ? BarPlot.propTypes = {
214
282
  // | These PropTypes are generated from the TypeScript type definitions |
215
283
  // | To update them edit the TypeScript types and run "yarn proptypes" |
216
284
  // ----------------------------------------------------------------------
285
+ /**
286
+ * Defines the border radius of the bar element.
287
+ */
288
+ borderRadius: PropTypes.number,
217
289
  /**
218
290
  * Callback fired when a bar item is clicked.
219
291
  * @param {React.MouseEvent<SVGElement, MouseEvent>} event The event source of the callback.
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Returns if the corner should have a radius or not based on the layout and the data.
3
+ * @param {GetRadiusCorner} corner The corner to check.
4
+ * @param {GetRadiusData} cornerData The data for the corner.
5
+ * @returns {number} The radius for the corner.
6
+ */
7
+ export const getRadius = (corner, {
8
+ hasNegative,
9
+ hasPositive,
10
+ borderRadius,
11
+ layout
12
+ }) => {
13
+ if (!borderRadius) {
14
+ return 0;
15
+ }
16
+ const isVertical = layout === 'vertical';
17
+ if (corner === 'top-left' && (isVertical && hasPositive || !isVertical && hasNegative)) {
18
+ return borderRadius;
19
+ }
20
+ if (corner === 'top-right' && (isVertical && hasPositive || !isVertical && hasPositive)) {
21
+ return borderRadius;
22
+ }
23
+ if (corner === 'bottom-right' && (isVertical && hasNegative || !isVertical && hasPositive)) {
24
+ return borderRadius;
25
+ }
26
+ if (corner === 'bottom-left' && (isVertical && hasNegative || !isVertical && hasNegative)) {
27
+ return borderRadius;
28
+ }
29
+ return 0;
30
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -4,7 +4,7 @@ const _excluded = ["vertical", "horizontal"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import composeClasses from '@mui/utils/composeClasses';
7
- import { styled } from '@mui/material/styles';
7
+ import { styled, useThemeProps } from '@mui/material/styles';
8
8
  import { CartesianContext } from '../context/CartesianContextProvider';
9
9
  import { useTicks } from '../hooks/useTicks';
10
10
  import { getChartsGridUtilityClass, chartsGridClasses } from './chartsGridClasses';
@@ -12,15 +12,22 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
12
12
  const GridRoot = styled('g', {
13
13
  name: 'MuiChartsGrid',
14
14
  slot: 'Root',
15
- overridesResolver: (props, styles) => styles.root
15
+ overridesResolver: (props, styles) => [{
16
+ [`&.${chartsGridClasses.verticalLine}`]: styles.verticalLine
17
+ }, {
18
+ [`&.${chartsGridClasses.horizontalLine}`]: styles.horizontalLine
19
+ }, styles.root]
20
+ })({});
21
+ const GridLine = styled('line', {
22
+ name: 'MuiChartsGrid',
23
+ slot: 'Line',
24
+ overridesResolver: (props, styles) => styles.line
16
25
  })(({
17
26
  theme
18
27
  }) => ({
19
- [`& .${chartsGridClasses.line}`]: {
20
- stroke: (theme.vars || theme).palette.divider,
21
- shapeRendering: 'crispEdges',
22
- strokeWidth: 1
23
- }
28
+ stroke: (theme.vars || theme).palette.divider,
29
+ shapeRendering: 'crispEdges',
30
+ strokeWidth: 1
24
31
  }));
25
32
  const useUtilityClasses = ({
26
33
  classes
@@ -42,18 +49,22 @@ const useUtilityClasses = ({
42
49
  * - [ChartsGrid API](https://mui.com/x/api/charts/charts-axis/)
43
50
  */
44
51
  function ChartsGrid(props) {
52
+ const themeProps = useThemeProps({
53
+ props,
54
+ name: 'MuiChartsGrid'
55
+ });
45
56
  const {
46
57
  vertical,
47
58
  horizontal
48
- } = props,
49
- other = _objectWithoutPropertiesLoose(props, _excluded);
59
+ } = themeProps,
60
+ other = _objectWithoutPropertiesLoose(themeProps, _excluded);
50
61
  const {
51
62
  xAxis,
52
63
  xAxisIds,
53
64
  yAxis,
54
65
  yAxisIds
55
66
  } = React.useContext(CartesianContext);
56
- const classes = useUtilityClasses(props);
67
+ const classes = useUtilityClasses(themeProps);
57
68
  const horizontalAxisId = yAxisIds[0];
58
69
  const verticalAxisId = xAxisIds[0];
59
70
  const {
@@ -81,7 +92,7 @@ function ChartsGrid(props) {
81
92
  children: [vertical && xTicks.map(({
82
93
  formattedValue,
83
94
  offset
84
- }) => /*#__PURE__*/_jsx("line", {
95
+ }) => /*#__PURE__*/_jsx(GridLine, {
85
96
  y1: yScale.range()[0],
86
97
  y2: yScale.range()[1],
87
98
  x1: offset,
@@ -90,7 +101,7 @@ function ChartsGrid(props) {
90
101
  }, `vertical-${formattedValue}`)), horizontal && yTicks.map(({
91
102
  formattedValue,
92
103
  offset
93
- }) => /*#__PURE__*/_jsx("line", {
104
+ }) => /*#__PURE__*/_jsx(GridLine, {
94
105
  y1: offset,
95
106
  y2: offset,
96
107
  x1: xScale.range()[0],
@@ -0,0 +1,34 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
+ const _excluded = ["message"];
4
+ import * as React from 'react';
5
+ import { styled } from '@mui/material/styles';
6
+ import { useDrawingArea } from '../hooks/useDrawingArea';
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ const StyledText = styled('text')(({
9
+ theme
10
+ }) => ({
11
+ stroke: 'none',
12
+ fill: theme.palette.text.primary,
13
+ shapeRendering: 'crispEdges',
14
+ textAnchor: 'middle',
15
+ dominantBaseline: 'middle'
16
+ }));
17
+ export function ChartsLoadingOverlay(props) {
18
+ const {
19
+ message
20
+ } = props,
21
+ other = _objectWithoutPropertiesLoose(props, _excluded);
22
+ const {
23
+ top,
24
+ left,
25
+ height,
26
+ width
27
+ } = useDrawingArea();
28
+ return /*#__PURE__*/_jsx(StyledText, _extends({
29
+ x: left + width / 2,
30
+ y: top + height / 2
31
+ }, other, {
32
+ children: message ?? 'Loading data ...'
33
+ }));
34
+ }
@@ -0,0 +1,34 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
+ const _excluded = ["message"];
4
+ import * as React from 'react';
5
+ import { styled } from '@mui/material/styles';
6
+ import { useDrawingArea } from '../hooks/useDrawingArea';
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ const StyledText = styled('text')(({
9
+ theme
10
+ }) => ({
11
+ stroke: 'none',
12
+ fill: theme.palette.text.primary,
13
+ shapeRendering: 'crispEdges',
14
+ textAnchor: 'middle',
15
+ dominantBaseline: 'middle'
16
+ }));
17
+ export function ChartsNoDataOverlay(props) {
18
+ const {
19
+ message
20
+ } = props,
21
+ other = _objectWithoutPropertiesLoose(props, _excluded);
22
+ const {
23
+ top,
24
+ left,
25
+ height,
26
+ width
27
+ } = useDrawingArea();
28
+ return /*#__PURE__*/_jsx(StyledText, _extends({
29
+ x: left + width / 2,
30
+ y: top + height / 2
31
+ }, other, {
32
+ children: message ?? 'No data to display'
33
+ }));
34
+ }
@@ -0,0 +1,31 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import * as React from 'react';
3
+ import { ChartsLoadingOverlay } from './ChartsLoadingOverlay';
4
+ import { useSeries } from '../hooks/useSeries';
5
+ import { ChartsNoDataOverlay } from './ChartsNoDataOverlay';
6
+ import { jsx as _jsx } from "react/jsx-runtime";
7
+ export function useNoData() {
8
+ const seriesPerType = useSeries();
9
+ return Object.values(seriesPerType).every(seriesOfGivenType => {
10
+ if (!seriesOfGivenType) {
11
+ return true;
12
+ }
13
+ const {
14
+ series,
15
+ seriesOrder
16
+ } = seriesOfGivenType;
17
+ return seriesOrder.every(seriesId => series[seriesId].data.length === 0);
18
+ });
19
+ }
20
+ export function ChartsOverlay(props) {
21
+ const noData = useNoData();
22
+ if (props.loading) {
23
+ const LoadingOverlay = props.slots?.loadingOverlay ?? ChartsLoadingOverlay;
24
+ return /*#__PURE__*/_jsx(LoadingOverlay, _extends({}, props.slotProps?.loadingOverlay));
25
+ }
26
+ if (noData) {
27
+ const NoDataOverlay = props.slots?.noDataOverlay ?? ChartsNoDataOverlay;
28
+ return /*#__PURE__*/_jsx(NoDataOverlay, _extends({}, props.slotProps?.noDataOverlay));
29
+ }
30
+ return null;
31
+ }
@@ -0,0 +1,3 @@
1
+ export { ChartsOverlay } from './ChartsOverlay';
2
+ export { ChartsLoadingOverlay } from './ChartsLoadingOverlay';
3
+ export { ChartsNoDataOverlay } from './ChartsNoDataOverlay';
@@ -52,7 +52,7 @@ process.env.NODE_ENV !== "production" ? ChartsReferenceLine.propTypes = {
52
52
  */
53
53
  lineStyle: PropTypes.object,
54
54
  /**
55
- * Additional space arround the label in px.
55
+ * Additional space around the label in px.
56
56
  * Can be a number or an object `{ x, y }` to distinguish space with the reference line and space with axes.
57
57
  * @default 5
58
58
  */
@@ -106,7 +106,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxisTooltipContent.propTypes = {
106
106
  value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
107
107
  })
108
108
  }),
109
- axisValue: PropTypes.any,
109
+ axisValue: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]),
110
110
  classes: PropTypes.object,
111
111
  dataIndex: PropTypes.number,
112
112
  series: PropTypes.arrayOf(PropTypes.object),
@@ -113,7 +113,7 @@ process.env.NODE_ENV !== "production" ? ChartsTooltip.propTypes = {
113
113
  // | To update them edit the TypeScript types and run "yarn proptypes" |
114
114
  // ----------------------------------------------------------------------
115
115
  /**
116
- * Component to override the tooltip content when triger is set to 'axis'.
116
+ * Component to override the tooltip content when trigger is set to 'axis'.
117
117
  * @deprecated Use slots.axisContent instead
118
118
  */
119
119
  axisContent: PropTypes.elementType,
@@ -122,7 +122,7 @@ process.env.NODE_ENV !== "production" ? ChartsTooltip.propTypes = {
122
122
  */
123
123
  classes: PropTypes.object,
124
124
  /**
125
- * Component to override the tooltip content when triger is set to 'item'.
125
+ * Component to override the tooltip content when trigger is set to 'item'.
126
126
  * @deprecated Use slots.itemContent instead
127
127
  */
128
128
  itemContent: PropTypes.elementType,
@@ -100,7 +100,7 @@ process.env.NODE_ENV !== "production" ? DefaultChartsAxisTooltipContent.propType
100
100
  /**
101
101
  * The value associated to the current mouse position.
102
102
  */
103
- axisValue: PropTypes.any.isRequired,
103
+ axisValue: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]),
104
104
  /**
105
105
  * Override or extend the styles applied to the component.
106
106
  */
@@ -203,6 +203,13 @@ function ChartsXAxis(inProps) {
203
203
  },
204
204
  ownerState: {}
205
205
  });
206
+ const domain = xScale.domain();
207
+ if (domain.length === 0 || domain[0] === domain[1]) {
208
+ // Skip axis rendering if
209
+ // - the data is empty (for band and point axis)
210
+ // - No data is associated to the axis (other scale types)
211
+ return null;
212
+ }
206
213
  return /*#__PURE__*/_jsxs(AxisRoot, {
207
214
  transform: `translate(0, ${position === 'bottom' ? top + height : top})`,
208
215
  className: classes.root,
@@ -138,6 +138,13 @@ function ChartsYAxis(inProps) {
138
138
  },
139
139
  ownerState: {}
140
140
  });
141
+ const domain = yScale.domain();
142
+ if (domain.length === 0 || domain[0] === domain[1]) {
143
+ // Skip axis rendering if
144
+ // - the data is empty (for band and point axis)
145
+ // - No data is associated to the axis (other scale types)
146
+ return null;
147
+ }
141
148
  return /*#__PURE__*/_jsxs(AxisRoot, {
142
149
  transform: `translate(${position === 'right' ? left + width : left}, 0)`,
143
150
  className: classes.root,
@@ -84,7 +84,7 @@ process.env.NODE_ENV !== "production" ? Gauge.propTypes = {
84
84
  */
85
85
  height: PropTypes.number,
86
86
  /**
87
- * The radius between circle center and the begining of the arc.
87
+ * The radius between circle center and the beginning of the arc.
88
88
  * Can be a number (in px) or a string with a percentage such as '50%'.
89
89
  * The '100%' is the maximal radius that fit into the drawing area.
90
90
  * @default '80%'
@@ -145,7 +145,7 @@ process.env.NODE_ENV !== "production" ? GaugeContainer.propTypes = {
145
145
  */
146
146
  height: PropTypes.number,
147
147
  /**
148
- * The radius between circle center and the begining of the arc.
148
+ * The radius between circle center and the beginning of the arc.
149
149
  * Can be a number (in px) or a string with a percentage such as '50%'.
150
150
  * The '100%' is the maximal radius that fit into the drawing area.
151
151
  * @default '80%'
@@ -48,7 +48,7 @@ export function GaugeProvider(props) {
48
48
  let cy = top + innerCy;
49
49
  const maxRadius = getAvailableRadius(innerCx, innerCy, width, height, ratios);
50
50
 
51
- // If the center is not defined, after computation of the available radius, udpate the center to use the remaining space.
51
+ // If the center is not defined, after computation of the available radius, update the center to use the remaining space.
52
52
  if (cxParam === undefined) {
53
53
  const usedWidth = maxRadius * (ratios.maxX - ratios.minX);
54
54
  cx = left + (width - usedWidth) / 2 + ratios.cx * usedWidth;
@@ -7,7 +7,7 @@ function getPoint(angle) {
7
7
  }
8
8
 
9
9
  /**
10
- * Retruns the ratio of the arc bounding box and its center.
10
+ * Returns the ratio of the arc bounding box and its center.
11
11
  * @param startAngle The start angle (in deg)
12
12
  * @param endAngle The end angle (in deg)
13
13
  */
@@ -20,9 +20,9 @@ export function getArcRatios(startAngle, endAngle) {
20
20
  const maxAngle = Math.max(startAngle, endAngle);
21
21
  const initialAngle = Math.floor(minAngle / 90) * 90;
22
22
  for (let step = 1; step <= 4; step += 1) {
23
- const cartinalAngle = initialAngle + step * 90;
24
- if (cartinalAngle < maxAngle) {
25
- points.push(getPoint(cartinalAngle));
23
+ const cardinalAngle = initialAngle + step * 90;
24
+ if (cardinalAngle < maxAngle) {
25
+ points.push(getPoint(cardinalAngle));
26
26
  }
27
27
  }
28
28
  const minX = Math.min(...points.map(([x]) => x));