@mui/x-charts 7.0.0-alpha.4 → 7.0.0-alpha.7

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 (134) hide show
  1. package/BarChart/BarPlot.js +7 -6
  2. package/BarChart/formatter.js +15 -3
  3. package/CHANGELOG.md +524 -0
  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/PieArcLabel.d.ts +1 -0
  24. package/PieChart/PieArcLabel.js +7 -8
  25. package/PieChart/PieArcLabelPlot.d.ts +2 -3
  26. package/PieChart/PieArcLabelPlot.js +14 -4
  27. package/PieChart/PieArcPlot.d.ts +2 -3
  28. package/PieChart/PieArcPlot.js +8 -2
  29. package/PieChart/PieChart.js +7 -4
  30. package/PieChart/PiePlot.js +23 -15
  31. package/PieChart/dataTransform/transition.js +9 -2
  32. package/PieChart/dataTransform/useTransformData.d.ts +3 -3
  33. package/PieChart/dataTransform/useTransformData.js +11 -8
  34. package/ResponsiveChartContainer/index.js +2 -2
  35. package/context/CartesianContextProvider.js +2 -2
  36. package/context/SeriesContextProvider.js +1 -1
  37. package/esm/BarChart/BarPlot.js +7 -5
  38. package/esm/BarChart/formatter.js +20 -4
  39. package/esm/ChartsAxis/ChartsAxis.js +4 -4
  40. package/esm/ChartsLegend/ChartsLegend.js +2 -1
  41. package/esm/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  42. package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  43. package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  44. package/esm/{internals/components → ChartsText}/ChartsText.js +33 -16
  45. package/esm/ChartsText/index.js +1 -0
  46. package/esm/ChartsXAxis/ChartsXAxis.js +2 -1
  47. package/esm/ChartsYAxis/ChartsYAxis.js +1 -1
  48. package/esm/LineChart/AreaPlot.js +3 -2
  49. package/esm/LineChart/LineHighlightPlot.js +2 -1
  50. package/esm/LineChart/LinePlot.js +3 -2
  51. package/esm/LineChart/MarkPlot.js +2 -1
  52. package/esm/LineChart/formatter.js +16 -3
  53. package/esm/PieChart/PieArcLabel.js +7 -8
  54. package/esm/PieChart/PieArcLabelPlot.js +14 -4
  55. package/esm/PieChart/PieArcPlot.js +8 -2
  56. package/esm/PieChart/PieChart.js +7 -4
  57. package/esm/PieChart/PiePlot.js +23 -15
  58. package/esm/PieChart/dataTransform/transition.js +9 -2
  59. package/esm/PieChart/dataTransform/useTransformData.js +12 -9
  60. package/esm/ResponsiveChartContainer/index.js +2 -2
  61. package/esm/context/CartesianContextProvider.js +2 -2
  62. package/esm/context/SeriesContextProvider.js +1 -1
  63. package/esm/index.js +1 -0
  64. package/esm/internals/getWordsByLines.js +14 -0
  65. package/esm/internals/utils.js +29 -0
  66. package/index.d.ts +1 -0
  67. package/index.js +12 -1
  68. package/internals/defaultizeColor.d.ts +7 -4
  69. package/internals/{components/ChartsText.d.ts → getWordsByLines.d.ts} +2 -11
  70. package/internals/getWordsByLines.js +21 -0
  71. package/internals/utils.d.ts +7 -0
  72. package/internals/utils.js +30 -0
  73. package/legacy/BarChart/BarPlot.js +7 -5
  74. package/legacy/BarChart/formatter.js +23 -9
  75. package/legacy/ChartsAxis/ChartsAxis.js +4 -4
  76. package/legacy/ChartsLegend/ChartsLegend.js +2 -1
  77. package/legacy/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  78. package/legacy/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  79. package/legacy/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  80. package/legacy/{internals/components → ChartsText}/ChartsText.js +38 -22
  81. package/legacy/ChartsText/index.js +1 -0
  82. package/legacy/ChartsXAxis/ChartsXAxis.js +2 -1
  83. package/legacy/ChartsYAxis/ChartsYAxis.js +1 -1
  84. package/legacy/LineChart/AreaPlot.js +3 -2
  85. package/legacy/LineChart/LineHighlightPlot.js +2 -1
  86. package/legacy/LineChart/LinePlot.js +3 -2
  87. package/legacy/LineChart/MarkPlot.js +2 -1
  88. package/legacy/LineChart/formatter.js +19 -8
  89. package/legacy/PieChart/PieArcLabel.js +7 -8
  90. package/legacy/PieChart/PieArcLabelPlot.js +14 -5
  91. package/legacy/PieChart/PieArcPlot.js +9 -2
  92. package/legacy/PieChart/PieChart.js +7 -4
  93. package/legacy/PieChart/PiePlot.js +23 -15
  94. package/legacy/PieChart/dataTransform/transition.js +9 -2
  95. package/legacy/PieChart/dataTransform/useTransformData.js +12 -9
  96. package/legacy/ResponsiveChartContainer/index.js +2 -2
  97. package/legacy/context/CartesianContextProvider.js +2 -2
  98. package/legacy/context/SeriesContextProvider.js +1 -1
  99. package/legacy/index.js +2 -1
  100. package/legacy/internals/getWordsByLines.js +15 -0
  101. package/legacy/internals/utils.js +29 -0
  102. package/models/axis.d.ts +1 -1
  103. package/models/seriesType/config.d.ts +4 -3
  104. package/models/seriesType/pie.d.ts +43 -7
  105. package/modern/BarChart/BarPlot.js +7 -5
  106. package/modern/BarChart/formatter.js +15 -3
  107. package/modern/ChartsAxis/ChartsAxis.js +4 -4
  108. package/modern/ChartsLegend/ChartsLegend.js +2 -1
  109. package/modern/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  110. package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  111. package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  112. package/modern/{internals/components → ChartsText}/ChartsText.js +33 -16
  113. package/modern/ChartsText/index.js +1 -0
  114. package/modern/ChartsXAxis/ChartsXAxis.js +2 -1
  115. package/modern/ChartsYAxis/ChartsYAxis.js +1 -1
  116. package/modern/LineChart/AreaPlot.js +3 -2
  117. package/modern/LineChart/LineHighlightPlot.js +2 -1
  118. package/modern/LineChart/LinePlot.js +3 -2
  119. package/modern/LineChart/MarkPlot.js +2 -1
  120. package/modern/LineChart/formatter.js +14 -2
  121. package/modern/PieChart/PieArcLabel.js +7 -8
  122. package/modern/PieChart/PieArcLabelPlot.js +14 -4
  123. package/modern/PieChart/PieArcPlot.js +8 -2
  124. package/modern/PieChart/PieChart.js +7 -4
  125. package/modern/PieChart/PiePlot.js +23 -15
  126. package/modern/PieChart/dataTransform/transition.js +9 -2
  127. package/modern/PieChart/dataTransform/useTransformData.js +11 -8
  128. package/modern/ResponsiveChartContainer/index.js +2 -2
  129. package/modern/context/CartesianContextProvider.js +2 -2
  130. package/modern/context/SeriesContextProvider.js +1 -1
  131. package/modern/index.js +2 -1
  132. package/modern/internals/getWordsByLines.js +14 -0
  133. package/modern/internals/utils.js +29 -0
  134. package/package.json +5 -5
@@ -250,10 +250,11 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
250
250
  series: PropTypes.arrayOf(PropTypes.shape({
251
251
  arcLabel: PropTypes.oneOfType([PropTypes.oneOf(['formattedValue', 'label', 'value']), PropTypes.func]),
252
252
  arcLabelMinAngle: PropTypes.number,
253
+ arcLabelRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
253
254
  color: PropTypes.string,
254
255
  cornerRadius: PropTypes.number,
255
- cx: PropTypes.number,
256
- cy: PropTypes.number,
256
+ cx: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
257
+ cy: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
257
258
  data: PropTypes.arrayOf(PropTypes.shape({
258
259
  color: PropTypes.string,
259
260
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
@@ -263,6 +264,7 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
263
264
  endAngle: PropTypes.number,
264
265
  faded: PropTypes.shape({
265
266
  additionalRadius: PropTypes.number,
267
+ arcLabelRadius: PropTypes.number,
266
268
  color: PropTypes.string,
267
269
  cornerRadius: PropTypes.number,
268
270
  innerRadius: PropTypes.number,
@@ -271,6 +273,7 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
271
273
  }),
272
274
  highlighted: PropTypes.shape({
273
275
  additionalRadius: PropTypes.number,
276
+ arcLabelRadius: PropTypes.number,
274
277
  color: PropTypes.string,
275
278
  cornerRadius: PropTypes.number,
276
279
  innerRadius: PropTypes.number,
@@ -282,8 +285,8 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
282
285
  highlighted: PropTypes.oneOf(['item', 'none', 'series'])
283
286
  }),
284
287
  id: PropTypes.string,
285
- innerRadius: PropTypes.number,
286
- outerRadius: PropTypes.number,
288
+ innerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
289
+ outerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
287
290
  paddingAngle: PropTypes.number,
288
291
  sortingValues: PropTypes.oneOfType([PropTypes.oneOf(['asc', 'desc', 'none']), PropTypes.func]),
289
292
  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,21 +71,28 @@ 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,
76
+ arcLabelRadiusParam = _series$seriesId2.arcLabelRadius,
75
77
  cornerRadius = _series$seriesId2.cornerRadius,
76
78
  paddingAngle = _series$seriesId2.paddingAngle,
77
79
  arcLabel = _series$seriesId2.arcLabel,
78
80
  arcLabelMinAngle = _series$seriesId2.arcLabelMinAngle,
79
81
  data = _series$seriesId2.data,
80
- cx = _series$seriesId2.cx,
81
- cy = _series$seriesId2.cy,
82
+ cxParam = _series$seriesId2.cx,
83
+ cyParam = _series$seriesId2.cy,
82
84
  highlightScope = _series$seriesId2.highlightScope;
85
+ var outerRadius = getPercentageValue(outerRadiusParam != null ? outerRadiusParam : availableRadius, availableRadius);
86
+ var innerRadius = getPercentageValue(innerRadiusParam != null ? innerRadiusParam : 0, availableRadius);
87
+ var arcLabelRadius = arcLabelRadiusParam === undefined ? (outerRadius + innerRadius) / 2 : getPercentageValue(arcLabelRadiusParam, availableRadius);
88
+ var cx = getPercentageValue(cxParam != null ? cxParam : '50%', width);
89
+ var cy = getPercentageValue(cyParam != null ? cyParam : '50%', height);
83
90
  return /*#__PURE__*/_jsx("g", {
84
- transform: "translate(".concat(cx === undefined ? center.x : left + cx, ", ").concat(cy === undefined ? center.y : top + cy, ")"),
91
+ transform: "translate(".concat(left + cx, ", ").concat(top + cy, ")"),
85
92
  children: /*#__PURE__*/_jsx(PieArcLabelPlot, {
86
93
  innerRadius: innerRadius,
87
94
  outerRadius: outerRadius != null ? outerRadius : availableRadius,
95
+ arcLabelRadius: arcLabelRadius,
88
96
  cornerRadius: cornerRadius,
89
97
  paddingAngle: paddingAngle,
90
98
  id: seriesId,
@@ -78,6 +78,7 @@ export var defaultLabelTransitionConfig = {
78
78
  from: function from(_ref5) {
79
79
  var innerRadius = _ref5.innerRadius,
80
80
  outerRadius = _ref5.outerRadius,
81
+ arcLabelRadius = _ref5.arcLabelRadius,
81
82
  cornerRadius = _ref5.cornerRadius,
82
83
  startAngle = _ref5.startAngle,
83
84
  endAngle = _ref5.endAngle,
@@ -86,6 +87,7 @@ export var defaultLabelTransitionConfig = {
86
87
  innerRadius: innerRadius,
87
88
  outerRadius: (innerRadius + outerRadius) / 2,
88
89
  cornerRadius: cornerRadius,
90
+ arcLabelRadius: arcLabelRadius,
89
91
  startAngle: (startAngle + endAngle) / 2,
90
92
  endAngle: (startAngle + endAngle) / 2,
91
93
  paddingAngle: paddingAngle,
@@ -99,6 +101,7 @@ export var defaultLabelTransitionConfig = {
99
101
  return {
100
102
  innerRadius: innerRadius,
101
103
  outerRadius: innerRadius,
104
+ arcLabelRadius: innerRadius,
102
105
  startAngle: (startAngle + endAngle) / 2,
103
106
  endAngle: (startAngle + endAngle) / 2,
104
107
  opacity: 0
@@ -108,12 +111,14 @@ export var defaultLabelTransitionConfig = {
108
111
  var innerRadius = _ref7.innerRadius,
109
112
  outerRadius = _ref7.outerRadius,
110
113
  startAngle = _ref7.startAngle,
111
- endAngle = _ref7.endAngle;
114
+ endAngle = _ref7.endAngle,
115
+ arcLabelRadius = _ref7.arcLabelRadius;
112
116
  return {
113
117
  innerRadius: innerRadius,
114
118
  outerRadius: outerRadius,
115
119
  startAngle: startAngle,
116
120
  endAngle: endAngle,
121
+ arcLabelRadius: arcLabelRadius,
117
122
  opacity: 1
118
123
  };
119
124
  },
@@ -123,7 +128,8 @@ export var defaultLabelTransitionConfig = {
123
128
  cornerRadius = _ref8.cornerRadius,
124
129
  startAngle = _ref8.startAngle,
125
130
  endAngle = _ref8.endAngle,
126
- paddingAngle = _ref8.paddingAngle;
131
+ paddingAngle = _ref8.paddingAngle,
132
+ arcLabelRadius = _ref8.arcLabelRadius;
127
133
  return {
128
134
  innerRadius: innerRadius,
129
135
  outerRadius: outerRadius,
@@ -131,6 +137,7 @@ export var defaultLabelTransitionConfig = {
131
137
  startAngle: startAngle,
132
138
  endAngle: endAngle,
133
139
  paddingAngle: paddingAngle,
140
+ arcLabelRadius: arcLabelRadius,
134
141
  opacity: 1
135
142
  };
136
143
  },
@@ -12,6 +12,7 @@ export function useTransformData(series) {
12
12
  basePaddingAngle = _series$paddingAngle === void 0 ? 0 : _series$paddingAngle,
13
13
  _series$innerRadius = series.innerRadius,
14
14
  baseInnerRadius = _series$innerRadius === void 0 ? 0 : _series$innerRadius,
15
+ baseArcLabelRadius = series.arcLabelRadius,
15
16
  baseOuterRadius = series.outerRadius,
16
17
  _series$cornerRadius = series.cornerRadius,
17
18
  baseCornerRadius = _series$cornerRadius === void 0 ? 0 : _series$cornerRadius;
@@ -35,26 +36,28 @@ export function useTransformData(series) {
35
36
  }, [highlightScope, highlightedItem, seriesId]);
36
37
  var dataWithHighlight = React.useMemo(function () {
37
38
  return data.map(function (item, itemIndex) {
38
- var _attibuesOverride$pad, _attibuesOverride$inn, _attibuesOverride$out, _attibuesOverride$cor;
39
+ var _attributesOverride$p, _attributesOverride$i, _attributesOverride$o, _attributesOverride$c, _ref, _attributesOverride$a;
39
40
  var _getHighlightStatus = getHighlightStatus(itemIndex),
40
41
  isHighlighted = _getHighlightStatus.isHighlighted,
41
42
  isFaded = _getHighlightStatus.isFaded;
42
- var attibuesOverride = _extends({
43
+ var attributesOverride = _extends({
43
44
  additionalRadius: 0
44
45
  }, isFaded && faded || isHighlighted && highlighted || {});
45
- var paddingAngle = Math.max(0, Math.PI * ((_attibuesOverride$pad = attibuesOverride.paddingAngle) != null ? _attibuesOverride$pad : basePaddingAngle) / 180);
46
- var innerRadius = Math.max(0, (_attibuesOverride$inn = attibuesOverride.innerRadius) != null ? _attibuesOverride$inn : baseInnerRadius);
47
- var outerRadius = Math.max(0, (_attibuesOverride$out = attibuesOverride.outerRadius) != null ? _attibuesOverride$out : baseOuterRadius + attibuesOverride.additionalRadius);
48
- var cornerRadius = (_attibuesOverride$cor = attibuesOverride.cornerRadius) != null ? _attibuesOverride$cor : baseCornerRadius;
49
- return _extends({}, item, attibuesOverride, {
46
+ var paddingAngle = Math.max(0, Math.PI * ((_attributesOverride$p = attributesOverride.paddingAngle) != null ? _attributesOverride$p : basePaddingAngle) / 180);
47
+ var innerRadius = Math.max(0, (_attributesOverride$i = attributesOverride.innerRadius) != null ? _attributesOverride$i : baseInnerRadius);
48
+ var outerRadius = Math.max(0, (_attributesOverride$o = attributesOverride.outerRadius) != null ? _attributesOverride$o : baseOuterRadius + attributesOverride.additionalRadius);
49
+ var cornerRadius = (_attributesOverride$c = attributesOverride.cornerRadius) != null ? _attributesOverride$c : baseCornerRadius;
50
+ var arcLabelRadius = (_ref = (_attributesOverride$a = attributesOverride.arcLabelRadius) != null ? _attributesOverride$a : baseArcLabelRadius) != null ? _ref : (innerRadius + outerRadius) / 2;
51
+ return _extends({}, item, attributesOverride, {
50
52
  isFaded: isFaded,
51
53
  isHighlighted: isHighlighted,
52
54
  paddingAngle: paddingAngle,
53
55
  innerRadius: innerRadius,
54
56
  outerRadius: outerRadius,
55
- cornerRadius: cornerRadius
57
+ cornerRadius: cornerRadius,
58
+ arcLabelRadius: arcLabelRadius
56
59
  });
57
60
  });
58
- }, [baseCornerRadius, baseInnerRadius, baseOuterRadius, basePaddingAngle, data, faded, getHighlightStatus, highlighted]);
61
+ }, [baseCornerRadius, baseInnerRadius, baseOuterRadius, basePaddingAngle, baseArcLabelRadius, data, faded, getHighlightStatus, highlighted]);
59
62
  return dataWithHighlight;
60
63
  }
@@ -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 v7.0.0-alpha.4
2
+ * @mui/x-charts v7.0.0-alpha.7
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 './ChartsLegend';
20
21
  export * from './ChartsAxisHighlight';
@@ -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
+ }
@@ -13,4 +13,33 @@ export function getSVGPoint(svg, event) {
13
13
  pt.x = event.clientX;
14
14
  pt.y = event.clientY;
15
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."));
16
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,25 @@ 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%'
30
+ */
31
+ outerRadius?: number | string;
32
+ /**
33
+ * The radius between circle center and the arc label.
34
+ * Can be a number (in px) or a string with a percentage such as '50%'.
35
+ * The '100%' is the maximal radius that fit into the drawing area.
36
+ * @default (innerRadius - outerRadius) / 2
26
37
  */
27
- outerRadius?: number;
38
+ arcLabelRadius?: number | string;
28
39
  /**
29
40
  * The radius applied to arc corners (similar to border radius).
30
41
  * @default 0
@@ -56,14 +67,18 @@ export interface PieSeriesType<Tdata = PieValueType> extends CommonSeriesType<Td
56
67
  arcLabelMinAngle?: number;
57
68
  /**
58
69
  * The x coordinate of the pie center.
59
- * @default width/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 width the drawing area.
72
+ * @default '50%'
60
73
  */
61
- cx?: number;
74
+ cx?: number | string;
62
75
  /**
63
76
  * The y coordinate of the pie center.
64
- * @default height/2 the center of the drawing area.
77
+ * Can be a number (in px) or a string with a percentage such as '50%'.
78
+ * The '100%' is the height the drawing area.
79
+ * @default '50%'
65
80
  */
66
- cy?: number;
81
+ cy?: number | string;
67
82
  /**
68
83
  * Override the arc attibutes when it is highlighted.
69
84
  */
@@ -77,6 +92,7 @@ export interface PieSeriesType<Tdata = PieValueType> extends CommonSeriesType<Td
77
92
  outerRadius?: number;
78
93
  cornerRadius?: number;
79
94
  paddingAngle?: number;
95
+ arcLabelRadius?: number;
80
96
  color?: string;
81
97
  };
82
98
  /**
@@ -92,6 +108,7 @@ export interface PieSeriesType<Tdata = PieValueType> extends CommonSeriesType<Td
92
108
  outerRadius?: number;
93
109
  cornerRadius?: number;
94
110
  paddingAngle?: number;
111
+ arcLabelRadius?: number;
95
112
  color?: string;
96
113
  };
97
114
  }
@@ -107,3 +124,22 @@ export type PieItemIdentifier = {
107
124
  export interface DefaultizedPieSeriesType extends DefaultizedProps<PieSeriesType, CommonDefaultizedProps> {
108
125
  data: DefaultizedPieValueType[];
109
126
  }
127
+ /**
128
+ * Props received when the parent components has done the percentage conversion.
129
+ */
130
+ export interface ComputedPieRadius {
131
+ /**
132
+ * The radius between circle center and the begining of the arc.
133
+ * @default 0
134
+ */
135
+ innerRadius?: number;
136
+ /**
137
+ * The radius between circle center and the end of the arc.
138
+ */
139
+ outerRadius: number;
140
+ /**
141
+ * The radius between circle center and the arc label in px.
142
+ * @default (innerRadius - outerRadius) / 2
143
+ */
144
+ arcLabelRadius?: number;
145
+ }
@@ -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);
@@ -12,7 +12,8 @@ import { DrawingContext } from '../context/DrawingProvider';
12
12
  import { getSeriesToDisplay } from './utils';
13
13
  import { SeriesContext } from '../context/SeriesContextProvider';
14
14
  import { getLegendUtilityClass } from './chartsLegendClasses';
15
- import { ChartsText, getWordsByLines } from '../internals/components/ChartsText';
15
+ import { ChartsText } from '../ChartsText';
16
+ import { getWordsByLines } from '../internals/getWordsByLines';
16
17
  import { jsx as _jsx } from "react/jsx-runtime";
17
18
  import { jsxs as _jsxs } from "react/jsx-runtime";
18
19
  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";