@mui/x-charts 6.18.3 → 6.18.4

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/BarPlot.js +7 -6
  2. package/BarChart/formatter.js +15 -3
  3. package/CHANGELOG.md +133 -1
  4. package/ChartsAxis/ChartsAxis.js +4 -4
  5. package/ChartsLegend/ChartsLegend.d.ts +1 -1
  6. package/ChartsLegend/ChartsLegend.js +3 -2
  7. package/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  8. package/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  9. package/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  10. package/ChartsReferenceLine/common.d.ts +1 -1
  11. package/ChartsText/ChartsText.d.ts +17 -0
  12. package/{internals/components → ChartsText}/ChartsText.js +32 -17
  13. package/ChartsText/index.d.ts +3 -0
  14. package/ChartsText/index.js +12 -0
  15. package/ChartsText/package.json +6 -0
  16. package/ChartsXAxis/ChartsXAxis.js +3 -2
  17. package/ChartsYAxis/ChartsYAxis.js +1 -1
  18. package/LineChart/AreaPlot.js +3 -2
  19. package/LineChart/LineHighlightPlot.js +2 -1
  20. package/LineChart/LinePlot.js +3 -2
  21. package/LineChart/MarkPlot.js +2 -1
  22. package/LineChart/formatter.js +14 -2
  23. package/PieChart/PieArcLabelPlot.d.ts +2 -3
  24. package/PieChart/PieArcLabelPlot.js +0 -1
  25. package/PieChart/PieArcPlot.d.ts +2 -3
  26. package/PieChart/PieArcPlot.js +0 -1
  27. package/PieChart/PieChart.js +4 -4
  28. package/PieChart/PiePlot.js +20 -15
  29. package/PieChart/dataTransform/useTransformData.d.ts +2 -3
  30. package/ResponsiveChartContainer/index.js +2 -2
  31. package/context/CartesianContextProvider.js +2 -2
  32. package/context/SeriesContextProvider.js +1 -1
  33. package/esm/BarChart/BarPlot.js +7 -5
  34. package/esm/BarChart/formatter.js +20 -4
  35. package/esm/ChartsAxis/ChartsAxis.js +4 -4
  36. package/esm/ChartsLegend/ChartsLegend.js +2 -1
  37. package/esm/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  38. package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  39. package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  40. package/esm/{internals/components → ChartsText}/ChartsText.js +33 -16
  41. package/esm/ChartsText/index.js +1 -0
  42. package/esm/ChartsXAxis/ChartsXAxis.js +2 -1
  43. package/esm/ChartsYAxis/ChartsYAxis.js +1 -1
  44. package/esm/LineChart/AreaPlot.js +3 -2
  45. package/esm/LineChart/LineHighlightPlot.js +2 -1
  46. package/esm/LineChart/LinePlot.js +3 -2
  47. package/esm/LineChart/MarkPlot.js +2 -1
  48. package/esm/LineChart/formatter.js +16 -3
  49. package/esm/PieChart/PieArcLabelPlot.js +0 -1
  50. package/esm/PieChart/PieArcPlot.js +0 -1
  51. package/esm/PieChart/PieChart.js +4 -4
  52. package/esm/PieChart/PiePlot.js +20 -15
  53. package/esm/ResponsiveChartContainer/index.js +2 -2
  54. package/esm/context/CartesianContextProvider.js +2 -2
  55. package/esm/context/SeriesContextProvider.js +1 -1
  56. package/esm/index.js +1 -0
  57. package/esm/internals/getWordsByLines.js +14 -0
  58. package/esm/internals/utils.js +40 -0
  59. package/index.d.ts +1 -0
  60. package/index.js +12 -1
  61. package/internals/defaultizeColor.d.ts +4 -4
  62. package/internals/{components/ChartsText.d.ts → getWordsByLines.d.ts} +2 -11
  63. package/internals/getWordsByLines.js +21 -0
  64. package/internals/utils.d.ts +13 -0
  65. package/internals/utils.js +42 -0
  66. package/legacy/BarChart/BarPlot.js +7 -5
  67. package/legacy/BarChart/formatter.js +23 -9
  68. package/legacy/ChartsAxis/ChartsAxis.js +4 -4
  69. package/legacy/ChartsLegend/ChartsLegend.js +2 -1
  70. package/legacy/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  71. package/legacy/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  72. package/legacy/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  73. package/legacy/{internals/components → ChartsText}/ChartsText.js +38 -22
  74. package/legacy/ChartsText/index.js +1 -0
  75. package/legacy/ChartsXAxis/ChartsXAxis.js +2 -1
  76. package/legacy/ChartsYAxis/ChartsYAxis.js +1 -1
  77. package/legacy/LineChart/AreaPlot.js +3 -2
  78. package/legacy/LineChart/LineHighlightPlot.js +2 -1
  79. package/legacy/LineChart/LinePlot.js +3 -2
  80. package/legacy/LineChart/MarkPlot.js +2 -1
  81. package/legacy/LineChart/formatter.js +19 -8
  82. package/legacy/PieChart/PieArcLabelPlot.js +0 -1
  83. package/legacy/PieChart/PieArcPlot.js +0 -1
  84. package/legacy/PieChart/PieChart.js +4 -4
  85. package/legacy/PieChart/PiePlot.js +20 -15
  86. package/legacy/ResponsiveChartContainer/index.js +2 -2
  87. package/legacy/context/CartesianContextProvider.js +2 -2
  88. package/legacy/context/SeriesContextProvider.js +1 -1
  89. package/legacy/index.js +2 -1
  90. package/legacy/internals/getWordsByLines.js +15 -0
  91. package/legacy/internals/utils.js +40 -0
  92. package/models/axis.d.ts +1 -1
  93. package/models/seriesType/config.d.ts +4 -3
  94. package/models/seriesType/pie.d.ts +29 -7
  95. package/modern/BarChart/BarPlot.js +7 -5
  96. package/modern/BarChart/formatter.js +15 -3
  97. package/modern/ChartsAxis/ChartsAxis.js +4 -4
  98. package/modern/ChartsLegend/ChartsLegend.js +2 -1
  99. package/modern/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  100. package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  101. package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  102. package/modern/{internals/components → ChartsText}/ChartsText.js +33 -16
  103. package/modern/ChartsText/index.js +1 -0
  104. package/modern/ChartsXAxis/ChartsXAxis.js +2 -1
  105. package/modern/ChartsYAxis/ChartsYAxis.js +1 -1
  106. package/modern/LineChart/AreaPlot.js +3 -2
  107. package/modern/LineChart/LineHighlightPlot.js +2 -1
  108. package/modern/LineChart/LinePlot.js +3 -2
  109. package/modern/LineChart/MarkPlot.js +2 -1
  110. package/modern/LineChart/formatter.js +14 -2
  111. package/modern/PieChart/PieArcLabelPlot.js +0 -1
  112. package/modern/PieChart/PieArcPlot.js +0 -1
  113. package/modern/PieChart/PieChart.js +4 -4
  114. package/modern/PieChart/PiePlot.js +20 -15
  115. package/modern/ResponsiveChartContainer/index.js +2 -2
  116. package/modern/context/CartesianContextProvider.js +2 -2
  117. package/modern/context/SeriesContextProvider.js +1 -1
  118. package/modern/index.js +2 -1
  119. package/modern/internals/getWordsByLines.js +14 -0
  120. package/modern/internals/utils.js +40 -0
  121. package/package.json +1 -1
@@ -10,7 +10,7 @@ import { CartesianContext } from '../context/CartesianContextProvider';
10
10
  import { DrawingContext } from '../context/DrawingProvider';
11
11
  import useTicks from '../hooks/useTicks';
12
12
  import { AxisRoot } from '../internals/components/AxisSharedComponents';
13
- import { ChartsText } from '../internals/components/ChartsText';
13
+ import { ChartsText } from '../ChartsText';
14
14
  import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
15
15
  import { jsx as _jsx } from "react/jsx-runtime";
16
16
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -9,6 +9,7 @@ import { CartesianContext } from '../context/CartesianContextProvider';
9
9
  import { AreaElement } from './AreaElement';
10
10
  import { getValueToPositionMapper } from '../hooks/useScale';
11
11
  import getCurveFactory from '../internals/getCurve';
12
+ import { DEFAULT_X_AXIS_KEY } from '../constants';
12
13
  import { jsx as _jsx } from "react/jsx-runtime";
13
14
  /**
14
15
  * Demos:
@@ -56,10 +57,10 @@ function AreaPlot(props) {
56
57
  var xData = xAxis[xAxisKey].data;
57
58
  if (process.env.NODE_ENV !== 'production') {
58
59
  if (xData === undefined) {
59
- throw new Error("Axis of id \"".concat(xAxisKey, "\" should have data property to be able to display a line plot."));
60
+ throw new Error("MUI-X-Charts: ".concat(xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : "The x-axis with id \"".concat(xAxisKey, "\""), " should have data property to be able to display a line plot."));
60
61
  }
61
62
  if (xData.length < stackedData.length) {
62
- throw new Error("MUI: data length of the x axis (".concat(xData.length, " items) is lower than the length of series (").concat(stackedData.length, " items)"));
63
+ throw new Error("MUI-X-Charts: The data length of the x axis (".concat(xData.length, " items) is lower than the length of series (").concat(stackedData.length, " items)"));
63
64
  }
64
65
  }
65
66
  var areaPath = d3Area().x(function (d) {
@@ -8,6 +8,7 @@ import { CartesianContext } from '../context/CartesianContextProvider';
8
8
  import { LineHighlightElement } from './LineHighlightElement';
9
9
  import { getValueToPositionMapper } from '../hooks/useScale';
10
10
  import { InteractionContext } from '../context/InteractionProvider';
11
+ import { DEFAULT_X_AXIS_KEY } from '../constants';
11
12
  import { jsx as _jsx } from "react/jsx-runtime";
12
13
  /**
13
14
  * Demos:
@@ -63,7 +64,7 @@ function LineHighlightPlot(props) {
63
64
  var yScale = yAxis[yAxisKey].scale;
64
65
  var xData = xAxis[xAxisKey].data;
65
66
  if (xData === undefined) {
66
- throw new Error("Axis of id \"".concat(xAxisKey, "\" should have data property to be able to display a line plot."));
67
+ throw new Error("MUI-X-Charts: ".concat(xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : "The x-axis with id \"".concat(xAxisKey, "\""), " should have data property to be able to display a line plot."));
67
68
  }
68
69
  var x = xScale(xData[highlightedIndex]);
69
70
  var y = yScale(stackedData[highlightedIndex][1]); // This should not be undefined since y should not be a band scale
@@ -9,6 +9,7 @@ import { CartesianContext } from '../context/CartesianContextProvider';
9
9
  import { LineElement } from './LineElement';
10
10
  import { getValueToPositionMapper } from '../hooks/useScale';
11
11
  import getCurveFactory from '../internals/getCurve';
12
+ import { DEFAULT_X_AXIS_KEY } from '../constants';
12
13
  import { jsx as _jsx } from "react/jsx-runtime";
13
14
  /**
14
15
  * Demos:
@@ -55,10 +56,10 @@ function LinePlot(props) {
55
56
  var xData = xAxis[xAxisKey].data;
56
57
  if (process.env.NODE_ENV !== 'production') {
57
58
  if (xData === undefined) {
58
- throw new Error("Axis of id \"".concat(xAxisKey, "\" should have data property to be able to display a line plot"));
59
+ throw new Error("MUI-X-Charts: ".concat(xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : "The x-axis with id \"".concat(xAxisKey, "\""), " should have data property to be able to display a line plot"));
59
60
  }
60
61
  if (xData.length < stackedData.length) {
61
- throw new Error("MUI: data length of the x axis (".concat(xData.length, " items) is lower than the length of series (").concat(stackedData.length, " items)"));
62
+ throw new Error("MUI-X-Charts: The data length of the x axis (".concat(xData.length, " items) is lower than the length of series (").concat(stackedData.length, " items)"));
62
63
  }
63
64
  }
64
65
  var linePath = d3Line().x(function (d) {
@@ -8,6 +8,7 @@ import { SeriesContext } from '../context/SeriesContextProvider';
8
8
  import { CartesianContext } from '../context/CartesianContextProvider';
9
9
  import { MarkElement } from './MarkElement';
10
10
  import { getValueToPositionMapper } from '../hooks/useScale';
11
+ import { DEFAULT_X_AXIS_KEY } from '../constants';
11
12
  import { jsx as _jsx } from "react/jsx-runtime";
12
13
  /**
13
14
  * Demos:
@@ -71,7 +72,7 @@ function MarkPlot(props) {
71
72
  return true;
72
73
  };
73
74
  if (xData === undefined) {
74
- throw new Error("Axis of id \"".concat(xAxisKey, "\" should have data property to be able to display a line plot"));
75
+ throw new Error("MUI-X-Charts: ".concat(xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : "The x-axis with id \"".concat(xAxisKey, "\""), " should have data property to be able to display a line plot"));
75
76
  }
76
77
  return xData == null ? void 0 : xData.map(function (x, index) {
77
78
  var value = data[index] == null ? null : stackedData[index][1];
@@ -4,14 +4,17 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
4
  import { stack as d3Stack } from 'd3-shape';
5
5
  import { getStackingGroups } from '../internals/stackSeries';
6
6
  import defaultizeValueFormatter from '../internals/defaultizeValueFormatter';
7
+ var warnedOnce = false;
8
+
7
9
  // For now it's a copy past of bar charts formatter, but maybe will diverge later
8
10
  var formatter = function formatter(params, dataset) {
11
+ var _ref;
9
12
  var seriesOrder = params.seriesOrder,
10
13
  series = params.series;
11
14
  var stackingGroups = getStackingGroups(params);
12
15
 
13
16
  // Create a data set with format adapted to d3
14
- var d3Dataset = dataset != null ? dataset : [];
17
+ var d3Dataset = (_ref = dataset) != null ? _ref : [];
15
18
  seriesOrder.forEach(function (id) {
16
19
  var data = series[id].data;
17
20
  if (data !== undefined) {
@@ -23,7 +26,7 @@ var formatter = function formatter(params, dataset) {
23
26
  }
24
27
  });
25
28
  } else if (dataset === undefined && process.env.NODE_ENV !== 'production') {
26
- throw new Error(["MUI: line series with id='".concat(id, "' has no data."), 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
29
+ throw new Error(["MUI-X-Charts: line series with id='".concat(id, "' has no data."), 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
27
30
  }
28
31
  });
29
32
  var completedSeries = {};
@@ -44,13 +47,21 @@ var formatter = function formatter(params, dataset) {
44
47
  ids.forEach(function (id, index) {
45
48
  var dataKey = series[id].dataKey;
46
49
  completedSeries[id] = _extends({}, series[id], {
47
- data: dataKey ? dataset.map(function (d) {
48
- return d[dataKey];
50
+ data: dataKey ? dataset.map(function (data) {
51
+ var value = data[dataKey];
52
+ if (typeof value !== 'number') {
53
+ if (process.env.NODE_ENV !== 'production' && !warnedOnce && value !== null) {
54
+ warnedOnce = true;
55
+ console.error(["MUI-X charts: your dataset key \"".concat(dataKey, "\" is used for plotting line, but contains nonnumerical elements."), 'Line plots only support numbers and null values.']);
56
+ }
57
+ return 0;
58
+ }
59
+ return value;
49
60
  }) : series[id].data,
50
- stackedData: stackedSeries[index].map(function (_ref) {
51
- var _ref2 = _slicedToArray(_ref, 2),
52
- a = _ref2[0],
53
- b = _ref2[1];
61
+ stackedData: stackedSeries[index].map(function (_ref2) {
62
+ var _ref3 = _slicedToArray(_ref2, 2),
63
+ a = _ref3[0],
64
+ b = _ref3[1];
54
65
  return [a, b];
55
66
  })
56
67
  });
@@ -155,7 +155,6 @@ process.env.NODE_ENV !== "production" ? PieArcLabelPlot.propTypes = {
155
155
  innerRadius: PropTypes.number,
156
156
  /**
157
157
  * The radius between circle center and the end of the arc.
158
- * @default R_max The maximal radius that fit into the drawing area.
159
158
  */
160
159
  outerRadius: PropTypes.number.isRequired,
161
160
  /**
@@ -145,7 +145,6 @@ process.env.NODE_ENV !== "production" ? PieArcPlot.propTypes = {
145
145
  onClick: PropTypes.func,
146
146
  /**
147
147
  * The radius between circle center and the end of the arc.
148
- * @default R_max The maximal radius that fit into the drawing area.
149
148
  */
150
149
  outerRadius: PropTypes.number.isRequired,
151
150
  /**
@@ -252,8 +252,8 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
252
252
  arcLabelMinAngle: PropTypes.number,
253
253
  color: PropTypes.string,
254
254
  cornerRadius: PropTypes.number,
255
- cx: PropTypes.number,
256
- cy: PropTypes.number,
255
+ cx: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
256
+ cy: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
257
257
  data: PropTypes.arrayOf(PropTypes.shape({
258
258
  color: PropTypes.string,
259
259
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
@@ -282,8 +282,8 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
282
282
  highlighted: PropTypes.oneOf(['item', 'none', 'series'])
283
283
  }),
284
284
  id: PropTypes.string,
285
- innerRadius: PropTypes.number,
286
- outerRadius: PropTypes.number,
285
+ innerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
286
+ outerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
287
287
  paddingAngle: PropTypes.number,
288
288
  sortingValues: PropTypes.oneOfType([PropTypes.oneOf(['asc', 'desc', 'none']), PropTypes.func]),
289
289
  startAngle: PropTypes.number,
@@ -4,6 +4,7 @@ import { SeriesContext } from '../context/SeriesContextProvider';
4
4
  import { DrawingContext } from '../context/DrawingProvider';
5
5
  import { PieArcPlot } from './PieArcPlot';
6
6
  import { PieArcLabelPlot } from './PieArcLabelPlot';
7
+ import { getPercentageValue } from '../internals/utils';
7
8
  import { jsx as _jsx } from "react/jsx-runtime";
8
9
  import { jsxs as _jsxs } from "react/jsx-runtime";
9
10
  /**
@@ -31,30 +32,30 @@ function PiePlot(props) {
31
32
  return null;
32
33
  }
33
34
  var availableRadius = Math.min(width, height) / 2;
34
- var center = {
35
- x: left + width / 2,
36
- y: top + height / 2
37
- };
38
35
  var series = seriesData.series,
39
36
  seriesOrder = seriesData.seriesOrder;
40
37
  return /*#__PURE__*/_jsxs("g", {
41
38
  children: [seriesOrder.map(function (seriesId) {
42
39
  var _series$seriesId = series[seriesId],
43
- innerRadius = _series$seriesId.innerRadius,
44
- outerRadius = _series$seriesId.outerRadius,
40
+ innerRadiusParam = _series$seriesId.innerRadius,
41
+ outerRadiusParam = _series$seriesId.outerRadius,
45
42
  cornerRadius = _series$seriesId.cornerRadius,
46
43
  paddingAngle = _series$seriesId.paddingAngle,
47
44
  data = _series$seriesId.data,
48
- cx = _series$seriesId.cx,
49
- cy = _series$seriesId.cy,
45
+ cxParam = _series$seriesId.cx,
46
+ cyParam = _series$seriesId.cy,
50
47
  highlighted = _series$seriesId.highlighted,
51
48
  faded = _series$seriesId.faded,
52
49
  highlightScope = _series$seriesId.highlightScope;
50
+ var outerRadius = getPercentageValue(outerRadiusParam != null ? outerRadiusParam : availableRadius, availableRadius);
51
+ var innerRadius = getPercentageValue(innerRadiusParam != null ? innerRadiusParam : 0, availableRadius);
52
+ var cx = getPercentageValue(cxParam != null ? cxParam : '50%', width);
53
+ var cy = getPercentageValue(cyParam != null ? cyParam : '50%', height);
53
54
  return /*#__PURE__*/_jsx("g", {
54
- transform: "translate(".concat(cx === undefined ? center.x : left + cx, ", ").concat(cy === undefined ? center.y : top + cy, ")"),
55
+ transform: "translate(".concat(left + cx, ", ").concat(top + cy, ")"),
55
56
  children: /*#__PURE__*/_jsx(PieArcPlot, {
56
57
  innerRadius: innerRadius,
57
- outerRadius: outerRadius != null ? outerRadius : availableRadius,
58
+ outerRadius: outerRadius,
58
59
  cornerRadius: cornerRadius,
59
60
  paddingAngle: paddingAngle,
60
61
  id: seriesId,
@@ -70,18 +71,22 @@ function PiePlot(props) {
70
71
  }, seriesId);
71
72
  }), seriesOrder.map(function (seriesId) {
72
73
  var _series$seriesId2 = series[seriesId],
73
- innerRadius = _series$seriesId2.innerRadius,
74
- outerRadius = _series$seriesId2.outerRadius,
74
+ innerRadiusParam = _series$seriesId2.innerRadius,
75
+ outerRadiusParam = _series$seriesId2.outerRadius,
75
76
  cornerRadius = _series$seriesId2.cornerRadius,
76
77
  paddingAngle = _series$seriesId2.paddingAngle,
77
78
  arcLabel = _series$seriesId2.arcLabel,
78
79
  arcLabelMinAngle = _series$seriesId2.arcLabelMinAngle,
79
80
  data = _series$seriesId2.data,
80
- cx = _series$seriesId2.cx,
81
- cy = _series$seriesId2.cy,
81
+ cxParam = _series$seriesId2.cx,
82
+ cyParam = _series$seriesId2.cy,
82
83
  highlightScope = _series$seriesId2.highlightScope;
84
+ var outerRadius = getPercentageValue(outerRadiusParam != null ? outerRadiusParam : availableRadius, availableRadius);
85
+ var innerRadius = getPercentageValue(innerRadiusParam != null ? innerRadiusParam : 0, availableRadius);
86
+ var cx = getPercentageValue(cxParam != null ? cxParam : '50%', width);
87
+ var cy = getPercentageValue(cyParam != null ? cyParam : '50%', height);
83
88
  return /*#__PURE__*/_jsx("g", {
84
- transform: "translate(".concat(cx === undefined ? center.x : left + cx, ", ").concat(cy === undefined ? center.y : top + cy, ")"),
89
+ transform: "translate(".concat(left + cx, ", ").concat(top + cy, ")"),
85
90
  children: /*#__PURE__*/_jsx(PieArcLabelPlot, {
86
91
  innerRadius: innerRadius,
87
92
  outerRadius: outerRadius != null ? outerRadius : availableRadius,
@@ -67,11 +67,11 @@ var useChartDimensions = function useChartDimensions(inWidth, inHeight) {
67
67
  }, [computeSize, inHeight, inWidth]);
68
68
  if (process.env.NODE_ENV !== 'production') {
69
69
  if (displayError.current && inWidth === undefined && width === 0) {
70
- console.error("MUI: Charts does not have `width` prop, and its container has no `width` defined.");
70
+ console.error("MUI-X-Charts: ChartContainer does not have `width` prop, and its container has no `width` defined.");
71
71
  displayError.current = false;
72
72
  }
73
73
  if (displayError.current && inHeight === undefined && height === 0) {
74
- console.error("MUI: Charts does not have `height` prop, and its container has no `height` defined.");
74
+ console.error("MUI-X-Charts: ChartContainer does not have `height` prop, and its container has no `height` defined.");
75
75
  displayError.current = false;
76
76
  }
77
77
  }
@@ -54,7 +54,7 @@ function CartesianContextProvider(_ref) {
54
54
  return axisConfig;
55
55
  }
56
56
  if (dataset === undefined) {
57
- throw Error('MUI: x-axis uses `dataKey` but no `dataset` is provided.');
57
+ throw Error('MUI-X-Charts: x-axis uses `dataKey` but no `dataset` is provided.');
58
58
  }
59
59
  return _extends({}, axisConfig, {
60
60
  data: dataset.map(function (d) {
@@ -70,7 +70,7 @@ function CartesianContextProvider(_ref) {
70
70
  return axisConfig;
71
71
  }
72
72
  if (dataset === undefined) {
73
- throw Error('MUI: y-axis uses `dataKey` but no `dataset` is provided.');
73
+ throw Error('MUI-X-Charts: y-axis uses `dataKey` but no `dataset` is provided.');
74
74
  }
75
75
  return _extends({}, axisConfig, {
76
76
  data: dataset.map(function (d) {
@@ -39,7 +39,7 @@ var formatSeries = function formatSeries(series, colors, dataset) {
39
39
  };
40
40
  }
41
41
  if (((_seriesGroups$type = seriesGroups[type]) == null ? void 0 : _seriesGroups$type.series[id]) !== undefined) {
42
- throw new Error("MUI: series' id \"".concat(id, "\" is not unique"));
42
+ throw new Error("MUI-X-Charts: series' id \"".concat(id, "\" is not unique"));
43
43
  }
44
44
  seriesGroups[type].series[id] = _extends({
45
45
  id: id
package/legacy/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v6.18.3
2
+ * @mui/x-charts v6.18.4
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -15,6 +15,7 @@ export * from './ChartsReferenceLine';
15
15
  export * from './ChartsAxis';
16
16
  export * from './ChartsXAxis';
17
17
  export * from './ChartsYAxis';
18
+ export * from './ChartsText';
18
19
  export * from './ChartsTooltip';
19
20
  export * from './ChartsAxisHighlight';
20
21
  export * from './BarChart';
@@ -0,0 +1,15 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import { getStringSize } from './domUtils';
3
+ export function getWordsByLines(_ref) {
4
+ var style = _ref.style,
5
+ needsComputation = _ref.needsComputation,
6
+ text = _ref.text;
7
+ return text.split('\n').map(function (subText) {
8
+ return _extends({
9
+ text: subText
10
+ }, needsComputation ? getStringSize(subText, style) : {
11
+ width: 0,
12
+ height: 0
13
+ });
14
+ });
15
+ }
@@ -2,4 +2,44 @@
2
2
  export function getSymbol(shape) {
3
3
  var symbolNames = 'circle cross diamond square star triangle wye'.split(/ /);
4
4
  return symbolNames.indexOf(shape) || 0;
5
+ }
6
+ /**
7
+ * Transform mouse event position to corrdinates inside the SVG.
8
+ * @param svg The SVG element
9
+ * @param event The mouseEvent to transform
10
+ */
11
+ export function getSVGPoint(svg, event) {
12
+ var pt = svg.createSVGPoint();
13
+ pt.x = event.clientX;
14
+ pt.y = event.clientY;
15
+ return pt.matrixTransform(svg.getScreenCTM().inverse());
16
+ }
17
+
18
+ /**
19
+ * Helper that converts values and percentages into values.
20
+ * @param value The value provided by the developer. Can either be a number or a string with '%' or 'px'.
21
+ * @param refValue The numerical value associated to 100%.
22
+ * @returns The numerical value associated to the provided value.
23
+ */
24
+ export function getPercentageValue(value, refValue) {
25
+ if (typeof value === 'number') {
26
+ return value;
27
+ }
28
+ if (value === '100%') {
29
+ // Avoid potential rounding issues
30
+ return refValue;
31
+ }
32
+ if (value.endsWith('%')) {
33
+ var percentage = Number.parseFloat(value.slice(0, value.length - 1));
34
+ if (!Number.isNaN(percentage)) {
35
+ return percentage * refValue / 100;
36
+ }
37
+ }
38
+ if (value.endsWith('px')) {
39
+ var val = Number.parseFloat(value.slice(0, value.length - 2));
40
+ if (!Number.isNaN(val)) {
41
+ return val;
42
+ }
43
+ }
44
+ throw Error("MUI-Charts: Received an unknown value \"".concat(value, "\". It should be a number, or a string with a percentage value."));
5
45
  }
package/models/axis.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  import type { ScaleBand, ScaleLogarithmic, ScalePower, ScaleTime, ScaleLinear, ScalePoint } from 'd3-scale';
3
3
  import { ChartsAxisClasses } from '../ChartsAxis/axisClasses';
4
4
  import type { TickParams } from '../hooks/useTicks';
5
- import { ChartsTextProps } from '../internals/components/ChartsText';
5
+ import { ChartsTextProps } from '../ChartsText';
6
6
  export type D3Scale<Domain extends {
7
7
  toString(): string;
8
8
  } = number | Date | string, Range = number, Output = number> = ScaleBand<Domain> | ScaleLogarithmic<Range, Output> | ScalePoint<Domain> | ScalePower<Range, Output> | ScaleTime<Range, Output> | ScaleLinear<Range, Output>;
@@ -77,10 +77,11 @@ export type FormatterResult<T extends ChartSeriesType> = {
77
77
  } ? {
78
78
  stackingGroups: StackingGroupsType;
79
79
  } : {});
80
- export type DatasetType<T extends number | string | Date = number | string | Date> = {
80
+ export type DatasetElementType<T> = {
81
81
  [key: string]: T;
82
- }[];
83
- export type Formatter<T extends ChartSeriesType> = (params: FormatterParams<T>, dataset?: DatasetType<number>) => FormatterResult<T>;
82
+ };
83
+ export type DatasetType<T = number | string | Date | null | undefined> = DatasetElementType<T>[];
84
+ export type Formatter<T extends ChartSeriesType> = (params: FormatterParams<T>, dataset?: DatasetType) => FormatterResult<T>;
84
85
  export type LegendParams = {
85
86
  /**
86
87
  * The color used in the legend
@@ -17,14 +17,18 @@ export interface PieSeriesType<Tdata = PieValueType> extends CommonSeriesType<Td
17
17
  data: Tdata[];
18
18
  /**
19
19
  * The radius between circle center and the begining of the arc.
20
+ * Can be a number (in px) or a string with a percentage such as '50%'.
21
+ * The '100%' is the maximal radius that fit into the drawing area.
20
22
  * @default 0
21
23
  */
22
- innerRadius?: number;
24
+ innerRadius?: number | string;
23
25
  /**
24
26
  * The radius between circle center and the end of the arc.
25
- * @default R_max The maximal radius that fit into the drawing area.
27
+ * Can be a number (in px) or a string with a percentage such as '50%'.
28
+ * The '100%' is the maximal radius that fit into the drawing area.
29
+ * @default '100%'
26
30
  */
27
- outerRadius?: number;
31
+ outerRadius?: number | string;
28
32
  /**
29
33
  * The radius applied to arc corners (similar to border radius).
30
34
  * @default 0
@@ -56,14 +60,18 @@ export interface PieSeriesType<Tdata = PieValueType> extends CommonSeriesType<Td
56
60
  arcLabelMinAngle?: number;
57
61
  /**
58
62
  * The x coordinate of the pie center.
59
- * @default width/2 the center of the drawing area.
63
+ * Can be a number (in px) or a string with a percentage such as '50%'.
64
+ * The '100%' is the width the drawing area.
65
+ * @default '50%'
60
66
  */
61
- cx?: number;
67
+ cx?: number | string;
62
68
  /**
63
69
  * The y coordinate of the pie center.
64
- * @default height/2 the center of the drawing area.
70
+ * Can be a number (in px) or a string with a percentage such as '50%'.
71
+ * The '100%' is the height the drawing area.
72
+ * @default '50%'
65
73
  */
66
- cy?: number;
74
+ cy?: number | string;
67
75
  /**
68
76
  * Override the arc attibutes when it is highlighted.
69
77
  */
@@ -107,3 +115,17 @@ export type PieItemIdentifier = {
107
115
  export interface DefaultizedPieSeriesType extends DefaultizedProps<PieSeriesType, CommonDefaultizedProps> {
108
116
  data: DefaultizedPieValueType[];
109
117
  }
118
+ /**
119
+ * Props received when the parent components has done the percentage conversion.
120
+ */
121
+ export interface ComputedPieRadius {
122
+ /**
123
+ * The radius between circle center and the begining of the arc.
124
+ * @default 0
125
+ */
126
+ innerRadius?: number;
127
+ /**
128
+ * The radius between circle center and the end of the arc.
129
+ */
130
+ outerRadius: number;
131
+ }
@@ -8,7 +8,8 @@ import { SeriesContext } from '../context/SeriesContextProvider';
8
8
  import { CartesianContext } from '../context/CartesianContextProvider';
9
9
  import { BarElement } from './BarElement';
10
10
  import { isBandScaleConfig } from '../models/axis';
11
- import { jsx as _jsx } from "react/jsx-runtime";
11
+ import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
12
+
12
13
  /**
13
14
  * Solution of the equations
14
15
  * W = barWidth * N + offset * (N-1)
@@ -18,6 +19,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
18
19
  * @param gapRatio The ratio of the gap between bars over the bar width.
19
20
  * @returns The bar width and the offset between bars.
20
21
  */
22
+ import { jsx as _jsx } from "react/jsx-runtime";
21
23
  function getBandSize({
22
24
  bandWidth: W,
23
25
  numberOfGroups: N,
@@ -67,18 +69,18 @@ const useCompletedData = () => {
67
69
  let baseScaleConfig;
68
70
  if (verticalLayout) {
69
71
  if (!isBandScaleConfig(xAxisConfig)) {
70
- throw new Error(`Axis with id "${xAxisKey}" shoud be of type "band" to display the bar series of id "${seriesId}"`);
72
+ 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}"`);
71
73
  }
72
74
  if (xAxis[xAxisKey].data === undefined) {
73
- throw new Error(`Axis with id "${xAxisKey}" shoud have data property`);
75
+ throw new Error(`MUI-X-Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} shoud have data property`);
74
76
  }
75
77
  baseScaleConfig = xAxisConfig;
76
78
  } else {
77
79
  if (!isBandScaleConfig(yAxisConfig)) {
78
- throw new Error(`Axis with id "${yAxisKey}" shoud be of type "band" to display the bar series of id "${seriesId}"`);
80
+ 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}"`);
79
81
  }
80
82
  if (yAxis[yAxisKey].data === undefined) {
81
- throw new Error(`Axis with id "${xAxisKey}" shoud have data property`);
83
+ throw new Error(`MUI-X-Charts: ${yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} shoud have data property`);
82
84
  }
83
85
  baseScaleConfig = yAxisConfig;
84
86
  }
@@ -2,6 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import { stack as d3Stack } from 'd3-shape';
3
3
  import { getStackingGroups } from '../internals/stackSeries';
4
4
  import defaultizeValueFormatter from '../internals/defaultizeValueFormatter';
5
+ let warnOnce = false;
5
6
  const formatter = (params, dataset) => {
6
7
  const {
7
8
  seriesOrder,
@@ -24,7 +25,7 @@ const formatter = (params, dataset) => {
24
25
  }
25
26
  });
26
27
  } else if (dataset === undefined) {
27
- throw new Error([`MUI: 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-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
29
  }
29
30
  });
30
31
  const completedSeries = {};
@@ -39,13 +40,24 @@ const formatter = (params, dataset) => {
39
40
  // Use dataKey if needed and available
40
41
  const dataKey = series[id].dataKey;
41
42
  return series[id].data === undefined && dataKey !== undefined ? dataKey : id;
42
- })).order(stackingOrder).offset(stackingOffset)(d3Dataset);
43
+ })).value((d, key) => d[key] ?? 0) // defaultize null value to 0
44
+ .order(stackingOrder).offset(stackingOffset)(d3Dataset);
43
45
  ids.forEach((id, index) => {
44
46
  const dataKey = series[id].dataKey;
45
47
  completedSeries[id] = _extends({
46
48
  layout: 'vertical'
47
49
  }, series[id], {
48
- data: dataKey ? dataset.map(d => d[dataKey]) : series[id].data,
50
+ data: dataKey ? dataset.map(data => {
51
+ const value = data[dataKey];
52
+ if (typeof value !== 'number') {
53
+ if (process.env.NODE_ENV !== 'production' && !warnOnce && value !== null) {
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.']);
56
+ }
57
+ return 0;
58
+ }
59
+ return value;
60
+ }) : series[id].data,
49
61
  stackedData: stackedSeries[index].map(([a, b]) => [a, b])
50
62
  });
51
63
  });
@@ -58,16 +58,16 @@ function ChartsAxis(props) {
58
58
  const topId = getAxisId(topAxis);
59
59
  const rightId = getAxisId(rightAxis);
60
60
  if (topId !== null && !xAxis[topId]) {
61
- throw Error(`MUI: id used for top axis "${topId}" is not defined`);
61
+ throw Error([`MUI-X-Charts: id used for top axis "${topId}" is not defined.`, `Available ids are: ${xAxisIds.join(', ')}.`].join('\n'));
62
62
  }
63
63
  if (leftId !== null && !yAxis[leftId]) {
64
- throw Error(`MUI: id used for left axis "${leftId}" is not defined`);
64
+ throw Error([`MUI-X-Charts: id used for left axis "${leftId}" is not defined.`, `Available ids are: ${yAxisIds.join(', ')}.`].join('\n'));
65
65
  }
66
66
  if (rightId !== null && !yAxis[rightId]) {
67
- throw Error(`MUI: id used for right axis "${rightId}" is not defined`);
67
+ throw Error([`MUI-X-Charts: id used for right axis "${rightId}" is not defined.`, `Available ids are: ${yAxisIds.join(', ')}.`].join('\n'));
68
68
  }
69
69
  if (bottomId !== null && !xAxis[bottomId]) {
70
- throw Error(`MUI: id used for bottom axis "${bottomId}" is not defined`);
70
+ throw Error([`MUI-X-Charts: id used for bottom axis "${bottomId}" is not defined.`, `Available ids are: ${xAxisIds.join(', ')}.`].join('\n'));
71
71
  }
72
72
  const topAxisProps = mergeProps(topAxis, slots, slotProps);
73
73
  const bottomAxisProps = mergeProps(bottomAxis, slots, slotProps);
@@ -11,7 +11,8 @@ import { DrawingContext } from '../context/DrawingProvider';
11
11
  import { getSeriesToDisplay } from './utils';
12
12
  import { SeriesContext } from '../context/SeriesContextProvider';
13
13
  import { getLegendUtilityClass } from './chartsLegendClasses';
14
- import { ChartsText, getWordsByLines } from '../internals/components/ChartsText';
14
+ import { ChartsText } from '../ChartsText';
15
+ import { getWordsByLines } from '../internals/getWordsByLines';
15
16
  import { jsx as _jsx } from "react/jsx-runtime";
16
17
  import { jsxs as _jsxs } from "react/jsx-runtime";
17
18
  const useUtilityClasses = ownerState => {
@@ -6,10 +6,10 @@ import { ChartsYReferenceLine } from './ChartsYReferenceLine';
6
6
  import { jsx as _jsx } from "react/jsx-runtime";
7
7
  function ChartsReferenceLine(props) {
8
8
  if (props.x !== undefined && props.y !== undefined) {
9
- throw new Error('MUI-X: The ChartsReferenceLine can not have both `x` and `y` props set.');
9
+ throw new Error('MUI-X-Charts: The ChartsReferenceLine can not have both `x` and `y` props set.');
10
10
  }
11
11
  if (props.x === undefined && props.y === undefined) {
12
- throw new Error('MUI-X: The ChartsReferenceLine should have a value in `x` or `y` prop.');
12
+ throw new Error('MUI-X-Charts: The ChartsReferenceLine should have a value in `x` or `y` prop.');
13
13
  }
14
14
  if (props.x !== undefined) {
15
15
  return /*#__PURE__*/_jsx(ChartsXReferenceLine, _extends({}, props));
@@ -3,7 +3,7 @@ import * as React from 'react';
3
3
  import composeClasses from '@mui/utils/composeClasses';
4
4
  import { useDrawingArea, useXScale } from '../hooks';
5
5
  import { ReferenceLineRoot } from './common';
6
- import { ChartsText } from '../internals/components/ChartsText';
6
+ import { ChartsText } from '../ChartsText';
7
7
  import { getReferenceLineUtilityClass } from './chartsReferenceLineClasses';
8
8
  import { jsx as _jsx } from "react/jsx-runtime";
9
9
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -3,7 +3,7 @@ import * as React from 'react';
3
3
  import composeClasses from '@mui/utils/composeClasses';
4
4
  import { useDrawingArea, useYScale } from '../hooks';
5
5
  import { ReferenceLineRoot } from './common';
6
- import { ChartsText } from '../internals/components/ChartsText';
6
+ import { ChartsText } from '../ChartsText';
7
7
  import { getReferenceLineUtilityClass } from './chartsReferenceLineClasses';
8
8
  import { jsx as _jsx } from "react/jsx-runtime";
9
9
  import { jsxs as _jsxs } from "react/jsx-runtime";