@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
@@ -1,23 +1,15 @@
1
- import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
3
  const _excluded = ["x", "y", "style", "text", "ownerState"],
4
4
  _excluded2 = ["angle", "textAnchor", "dominantBaseline"];
5
5
  import * as React from 'react';
6
- import { getStringSize } from '../domUtils';
6
+ import PropTypes from 'prop-types';
7
+ import { getWordsByLines } from '../internals/getWordsByLines';
7
8
  import { jsx as _jsx } from "react/jsx-runtime";
8
- export function getWordsByLines({
9
- style,
10
- needsComputation,
11
- text
12
- }) {
13
- return text.split('\n').map(subText => _extends({
14
- text: subText
15
- }, needsComputation ? getStringSize(subText, style) : {
16
- width: 0,
17
- height: 0
18
- }));
19
- }
20
- export function ChartsText(props) {
9
+ /**
10
+ * Helper component to manage multiline text in SVG
11
+ */
12
+ function ChartsText(props) {
21
13
  const {
22
14
  x,
23
15
  y,
@@ -74,4 +66,29 @@ export function ChartsText(props) {
74
66
  children: line.text
75
67
  }, index))
76
68
  }));
77
- }
69
+ }
70
+ process.env.NODE_ENV !== "production" ? ChartsText.propTypes = {
71
+ // ----------------------------- Warning --------------------------------
72
+ // | These PropTypes are generated from the TypeScript type definitions |
73
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
74
+ // ----------------------------------------------------------------------
75
+ /**
76
+ * Height of a text line (in `em`).
77
+ */
78
+ lineHeight: PropTypes.number,
79
+ /**
80
+ * If `true`, the line width is computed.
81
+ * @default false
82
+ */
83
+ needsComputation: PropTypes.bool,
84
+ ownerState: PropTypes.any,
85
+ /**
86
+ * Style applied to text elements.
87
+ */
88
+ style: PropTypes.object,
89
+ /**
90
+ * Text displayed.
91
+ */
92
+ text: PropTypes.string.isRequired
93
+ } : void 0;
94
+ export { ChartsText };
@@ -0,0 +1 @@
1
+ export { ChartsText } from './ChartsText';
@@ -11,9 +11,10 @@ import { DrawingContext } from '../context/DrawingProvider';
11
11
  import useTicks from '../hooks/useTicks';
12
12
  import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
13
13
  import { AxisRoot } from '../internals/components/AxisSharedComponents';
14
- import { ChartsText, getWordsByLines } from '../internals/components/ChartsText';
14
+ import { ChartsText } from '../ChartsText';
15
15
  import { getMinXTranslation } from '../internals/geometry';
16
16
  import { useMounted } from '../hooks/useMounted';
17
+ import { getWordsByLines } from '../internals/getWordsByLines';
17
18
  import { jsx as _jsx } from "react/jsx-runtime";
18
19
  import { jsxs as _jsxs } from "react/jsx-runtime";
19
20
  const useUtilityClasses = ownerState => {
@@ -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:
@@ -61,10 +62,10 @@ function AreaPlot(props) {
61
62
  const xData = xAxis[xAxisKey].data;
62
63
  if (process.env.NODE_ENV !== 'production') {
63
64
  if (xData === undefined) {
64
- throw new Error(`Axis of id "${xAxisKey}" should have data property to be able to display a line plot.`);
65
+ throw new Error(`MUI-X-Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} should have data property to be able to display a line plot.`);
65
66
  }
66
67
  if (xData.length < stackedData.length) {
67
- throw new Error(`MUI: data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items)`);
68
+ throw new Error(`MUI-X-Charts: The data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items)`);
68
69
  }
69
70
  }
70
71
  const areaPath = d3Area().x(d => xScale(d.x)).defined((_, i) => connectNulls || data[i] != null).y0(d => d.y && yScale(d.y[0])).y1(d => d.y && yScale(d.y[1]));
@@ -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:
@@ -69,7 +70,7 @@ function LineHighlightPlot(props) {
69
70
  const yScale = yAxis[yAxisKey].scale;
70
71
  const xData = xAxis[xAxisKey].data;
71
72
  if (xData === undefined) {
72
- throw new Error(`Axis of id "${xAxisKey}" should have data property to be able to display a line plot.`);
73
+ throw new Error(`MUI-X-Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} should have data property to be able to display a line plot.`);
73
74
  }
74
75
  const x = xScale(xData[highlightedIndex]);
75
76
  const 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:
@@ -60,10 +61,10 @@ function LinePlot(props) {
60
61
  const xData = xAxis[xAxisKey].data;
61
62
  if (process.env.NODE_ENV !== 'production') {
62
63
  if (xData === undefined) {
63
- throw new Error(`Axis of id "${xAxisKey}" should have data property to be able to display a line plot`);
64
+ throw new Error(`MUI-X-Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} should have data property to be able to display a line plot`);
64
65
  }
65
66
  if (xData.length < stackedData.length) {
66
- throw new Error(`MUI: data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items)`);
67
+ throw new Error(`MUI-X-Charts: The data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items)`);
67
68
  }
68
69
  }
69
70
  const linePath = d3Line().x(d => xScale(d.x)).defined((_, i) => connectNulls || data[i] != null).y(d => yScale(d.y[1]));
@@ -7,6 +7,7 @@ import { SeriesContext } from '../context/SeriesContextProvider';
7
7
  import { CartesianContext } from '../context/CartesianContextProvider';
8
8
  import { MarkElement } from './MarkElement';
9
9
  import { getValueToPositionMapper } from '../hooks/useScale';
10
+ import { DEFAULT_X_AXIS_KEY } from '../constants';
10
11
  import { jsx as _jsx } from "react/jsx-runtime";
11
12
  /**
12
13
  * Demos:
@@ -75,7 +76,7 @@ function MarkPlot(props) {
75
76
  return true;
76
77
  };
77
78
  if (xData === undefined) {
78
- throw new Error(`Axis of id "${xAxisKey}" should have data property to be able to display a line plot`);
79
+ throw new Error(`MUI-X-Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} should have data property to be able to display a line plot`);
79
80
  }
80
81
  return xData?.map((x, index) => {
81
82
  const value = data[index] == null ? null : stackedData[index][1];
@@ -2,6 +2,8 @@ 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 warnedOnce = false;
6
+
5
7
  // For now it's a copy past of bar charts formatter, but maybe will diverge later
6
8
  const formatter = (params, dataset) => {
7
9
  const {
@@ -25,7 +27,7 @@ const formatter = (params, dataset) => {
25
27
  }
26
28
  });
27
29
  } else if (dataset === undefined && process.env.NODE_ENV !== 'production') {
28
- throw new Error([`MUI: line series with id='${id}' has no data.`, 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
30
+ throw new Error([`MUI-X-Charts: line series with id='${id}' has no data.`, 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
29
31
  }
30
32
  });
31
33
  const completedSeries = {};
@@ -45,7 +47,17 @@ const formatter = (params, dataset) => {
45
47
  ids.forEach((id, index) => {
46
48
  const dataKey = series[id].dataKey;
47
49
  completedSeries[id] = _extends({}, 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' && !warnedOnce && value !== null) {
54
+ warnedOnce = true;
55
+ console.error([`MUI-X charts: your dataset key "${dataKey}" is used for plotting line, but contains nonnumerical elements.`, 'Line plots only support numbers and null values.']);
56
+ }
57
+ return null;
58
+ }
59
+ return value;
60
+ }) : series[id].data,
49
61
  stackedData: stackedSeries[index].map(([a, b]) => [a, b])
50
62
  });
51
63
  });
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["id", "classes", "color", "startAngle", "endAngle", "paddingAngle", "innerRadius", "outerRadius", "cornerRadius", "formattedArcLabel", "isHighlighted", "isFaded", "style"];
3
+ const _excluded = ["id", "classes", "color", "startAngle", "endAngle", "paddingAngle", "arcLabelRadius", "cornerRadius", "formattedArcLabel", "isHighlighted", "isFaded", "style"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import { animated, to } from '@react-spring/web';
@@ -41,7 +41,7 @@ const PieArcLabelRoot = styled(animated.text, {
41
41
  * Helper to compute label position.
42
42
  * It's not an inline function because we need it in inerpolation.
43
43
  */
44
- const getLabelPosition = (formattedArcLabel, variable) => (startAngle, endAngle, padAngle, innerRadius, outerRadius, cornerRadius) => {
44
+ const getLabelPosition = (formattedArcLabel, variable) => (startAngle, endAngle, padAngle, arcLabelRadius, cornerRadius) => {
45
45
  if (!formattedArcLabel) {
46
46
  return 0;
47
47
  }
@@ -49,8 +49,8 @@ const getLabelPosition = (formattedArcLabel, variable) => (startAngle, endAngle,
49
49
  padAngle,
50
50
  startAngle,
51
51
  endAngle,
52
- innerRadius,
53
- outerRadius
52
+ innerRadius: arcLabelRadius,
53
+ outerRadius: arcLabelRadius
54
54
  });
55
55
  if (variable === 'x') {
56
56
  return x;
@@ -65,8 +65,7 @@ function PieArcLabel(props) {
65
65
  startAngle,
66
66
  endAngle,
67
67
  paddingAngle,
68
- innerRadius,
69
- outerRadius,
68
+ arcLabelRadius,
70
69
  cornerRadius,
71
70
  formattedArcLabel,
72
71
  isHighlighted,
@@ -86,8 +85,8 @@ function PieArcLabel(props) {
86
85
  className: classes.root
87
86
  }, other, {
88
87
  style: _extends({
89
- x: to([startAngle, endAngle, paddingAngle, innerRadius, outerRadius, cornerRadius], getLabelPosition(formattedArcLabel, 'x')),
90
- y: to([startAngle, endAngle, paddingAngle, innerRadius, outerRadius, cornerRadius], getLabelPosition(formattedArcLabel, 'y'))
88
+ x: to([startAngle, endAngle, paddingAngle, arcLabelRadius, cornerRadius], getLabelPosition(formattedArcLabel, 'x')),
89
+ y: to([startAngle, endAngle, paddingAngle, arcLabelRadius, cornerRadius], getLabelPosition(formattedArcLabel, 'y'))
91
90
  }, style),
92
91
  children: formattedArcLabel
93
92
  }));
@@ -1,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["slots", "slotProps", "innerRadius", "outerRadius", "cornerRadius", "paddingAngle", "id", "highlightScope", "highlighted", "faded", "data", "arcLabel", "arcLabelMinAngle", "skipAnimation"],
4
- _excluded2 = ["startAngle", "endAngle", "paddingAngle", "innerRadius", "outerRadius", "cornerRadius"];
3
+ const _excluded = ["slots", "slotProps", "innerRadius", "outerRadius", "arcLabelRadius", "cornerRadius", "paddingAngle", "id", "highlightScope", "highlighted", "faded", "data", "arcLabel", "arcLabelMinAngle", "skipAnimation"],
4
+ _excluded2 = ["startAngle", "endAngle", "paddingAngle", "innerRadius", "outerRadius", "arcLabelRadius", "cornerRadius"];
5
5
  import * as React from 'react';
6
6
  import PropTypes from 'prop-types';
7
7
  import { useTransition } from '@react-spring/web';
@@ -27,8 +27,9 @@ function PieArcLabelPlot(props) {
27
27
  const {
28
28
  slots,
29
29
  slotProps,
30
- innerRadius = 0,
30
+ innerRadius,
31
31
  outerRadius,
32
+ arcLabelRadius,
32
33
  cornerRadius = 0,
33
34
  paddingAngle = 0,
34
35
  id,
@@ -46,6 +47,7 @@ function PieArcLabelPlot(props) {
46
47
  const transformedData = useTransformData({
47
48
  innerRadius,
48
49
  outerRadius,
50
+ arcLabelRadius,
49
51
  cornerRadius,
50
52
  paddingAngle,
51
53
  id,
@@ -69,6 +71,7 @@ function PieArcLabelPlot(props) {
69
71
  paddingAngle: pA,
70
72
  innerRadius: iR,
71
73
  outerRadius: oR,
74
+ arcLabelRadius: aLR,
72
75
  cornerRadius: cR
73
76
  } = _ref,
74
77
  style = _objectWithoutPropertiesLoose(_ref, _excluded2);
@@ -78,6 +81,7 @@ function PieArcLabelPlot(props) {
78
81
  paddingAngle: pA,
79
82
  innerRadius: iR,
80
83
  outerRadius: oR,
84
+ arcLabelRadius: aLR,
81
85
  cornerRadius: cR,
82
86
  style: style,
83
87
  id: id,
@@ -102,6 +106,11 @@ process.env.NODE_ENV !== "production" ? PieArcLabelPlot.propTypes = {
102
106
  * The minimal angle required to display the arc label.
103
107
  */
104
108
  arcLabelMinAngle: PropTypes.number,
109
+ /**
110
+ * The radius between circle center and the arc label in px.
111
+ * @default (innerRadius - outerRadius) / 2
112
+ */
113
+ arcLabelRadius: PropTypes.number,
105
114
  /**
106
115
  * The radius applied to arc corners (similar to border radius).
107
116
  * @default 0
@@ -123,6 +132,7 @@ process.env.NODE_ENV !== "production" ? PieArcLabelPlot.propTypes = {
123
132
  */
124
133
  faded: PropTypes.shape({
125
134
  additionalRadius: PropTypes.number,
135
+ arcLabelRadius: PropTypes.number,
126
136
  color: PropTypes.string,
127
137
  cornerRadius: PropTypes.number,
128
138
  innerRadius: PropTypes.number,
@@ -134,6 +144,7 @@ process.env.NODE_ENV !== "production" ? PieArcLabelPlot.propTypes = {
134
144
  */
135
145
  highlighted: PropTypes.shape({
136
146
  additionalRadius: PropTypes.number,
147
+ arcLabelRadius: PropTypes.number,
137
148
  color: PropTypes.string,
138
149
  cornerRadius: PropTypes.number,
139
150
  innerRadius: PropTypes.number,
@@ -152,7 +163,6 @@ process.env.NODE_ENV !== "production" ? PieArcLabelPlot.propTypes = {
152
163
  innerRadius: PropTypes.number,
153
164
  /**
154
165
  * The radius between circle center and the end of the arc.
155
- * @default R_max The maximal radius that fit into the drawing area.
156
166
  */
157
167
  outerRadius: PropTypes.number.isRequired,
158
168
  /**
@@ -1,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
3
  const _excluded = ["slots", "slotProps", "innerRadius", "outerRadius", "cornerRadius", "paddingAngle", "id", "highlightScope", "highlighted", "faded", "data", "onClick", "skipAnimation"],
4
- _excluded2 = ["startAngle", "endAngle", "paddingAngle", "innerRadius", "outerRadius", "cornerRadius"];
4
+ _excluded2 = ["startAngle", "endAngle", "paddingAngle", "innerRadius", "arcLabelRadius", "outerRadius", "cornerRadius"];
5
5
  import * as React from 'react';
6
6
  import PropTypes from 'prop-types';
7
7
  import { useTransition } from '@react-spring/web';
@@ -87,6 +87,11 @@ process.env.NODE_ENV !== "production" ? PieArcPlot.propTypes = {
87
87
  // | These PropTypes are generated from the TypeScript type definitions |
88
88
  // | To update them edit the TypeScript types and run "yarn proptypes" |
89
89
  // ----------------------------------------------------------------------
90
+ /**
91
+ * The radius between circle center and the arc label in px.
92
+ * @default (innerRadius - outerRadius) / 2
93
+ */
94
+ arcLabelRadius: PropTypes.number,
90
95
  /**
91
96
  * The radius applied to arc corners (similar to border radius).
92
97
  * @default 0
@@ -108,6 +113,7 @@ process.env.NODE_ENV !== "production" ? PieArcPlot.propTypes = {
108
113
  */
109
114
  faded: PropTypes.shape({
110
115
  additionalRadius: PropTypes.number,
116
+ arcLabelRadius: PropTypes.number,
111
117
  color: PropTypes.string,
112
118
  cornerRadius: PropTypes.number,
113
119
  innerRadius: PropTypes.number,
@@ -119,6 +125,7 @@ process.env.NODE_ENV !== "production" ? PieArcPlot.propTypes = {
119
125
  */
120
126
  highlighted: PropTypes.shape({
121
127
  additionalRadius: PropTypes.number,
128
+ arcLabelRadius: PropTypes.number,
122
129
  color: PropTypes.string,
123
130
  cornerRadius: PropTypes.number,
124
131
  innerRadius: PropTypes.number,
@@ -144,7 +151,6 @@ process.env.NODE_ENV !== "production" ? PieArcPlot.propTypes = {
144
151
  onClick: PropTypes.func,
145
152
  /**
146
153
  * The radius between circle center and the end of the arc.
147
- * @default R_max The maximal radius that fit into the drawing area.
148
154
  */
149
155
  outerRadius: PropTypes.number.isRequired,
150
156
  /**
@@ -238,10 +238,11 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
238
238
  series: PropTypes.arrayOf(PropTypes.shape({
239
239
  arcLabel: PropTypes.oneOfType([PropTypes.oneOf(['formattedValue', 'label', 'value']), PropTypes.func]),
240
240
  arcLabelMinAngle: PropTypes.number,
241
+ arcLabelRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
241
242
  color: PropTypes.string,
242
243
  cornerRadius: PropTypes.number,
243
- cx: PropTypes.number,
244
- cy: PropTypes.number,
244
+ cx: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
245
+ cy: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
245
246
  data: PropTypes.arrayOf(PropTypes.shape({
246
247
  color: PropTypes.string,
247
248
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
@@ -251,6 +252,7 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
251
252
  endAngle: PropTypes.number,
252
253
  faded: PropTypes.shape({
253
254
  additionalRadius: PropTypes.number,
255
+ arcLabelRadius: PropTypes.number,
254
256
  color: PropTypes.string,
255
257
  cornerRadius: PropTypes.number,
256
258
  innerRadius: PropTypes.number,
@@ -259,6 +261,7 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
259
261
  }),
260
262
  highlighted: PropTypes.shape({
261
263
  additionalRadius: PropTypes.number,
264
+ arcLabelRadius: PropTypes.number,
262
265
  color: PropTypes.string,
263
266
  cornerRadius: PropTypes.number,
264
267
  innerRadius: PropTypes.number,
@@ -270,8 +273,8 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
270
273
  highlighted: PropTypes.oneOf(['item', 'none', 'series'])
271
274
  }),
272
275
  id: PropTypes.string,
273
- innerRadius: PropTypes.number,
274
- outerRadius: PropTypes.number,
276
+ innerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
277
+ outerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
275
278
  paddingAngle: PropTypes.number,
276
279
  sortingValues: PropTypes.oneOfType([PropTypes.oneOf(['asc', 'desc', 'none']), PropTypes.func]),
277
280
  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
  /**
@@ -34,10 +35,6 @@ function PiePlot(props) {
34
35
  return null;
35
36
  }
36
37
  const availableRadius = Math.min(width, height) / 2;
37
- const center = {
38
- x: left + width / 2,
39
- y: top + height / 2
40
- };
41
38
  const {
42
39
  series,
43
40
  seriesOrder
@@ -45,22 +42,26 @@ function PiePlot(props) {
45
42
  return /*#__PURE__*/_jsxs("g", {
46
43
  children: [seriesOrder.map(seriesId => {
47
44
  const {
48
- innerRadius,
49
- outerRadius,
45
+ innerRadius: innerRadiusParam,
46
+ outerRadius: outerRadiusParam,
50
47
  cornerRadius,
51
48
  paddingAngle,
52
49
  data,
53
- cx,
54
- cy,
50
+ cx: cxParam,
51
+ cy: cyParam,
55
52
  highlighted,
56
53
  faded,
57
54
  highlightScope
58
55
  } = series[seriesId];
56
+ const outerRadius = getPercentageValue(outerRadiusParam ?? availableRadius, availableRadius);
57
+ const innerRadius = getPercentageValue(innerRadiusParam ?? 0, availableRadius);
58
+ const cx = getPercentageValue(cxParam ?? '50%', width);
59
+ const cy = getPercentageValue(cyParam ?? '50%', height);
59
60
  return /*#__PURE__*/_jsx("g", {
60
- transform: `translate(${cx === undefined ? center.x : left + cx}, ${cy === undefined ? center.y : top + cy})`,
61
+ transform: `translate(${left + cx}, ${top + cy})`,
61
62
  children: /*#__PURE__*/_jsx(PieArcPlot, {
62
63
  innerRadius: innerRadius,
63
- outerRadius: outerRadius ?? availableRadius,
64
+ outerRadius: outerRadius,
64
65
  cornerRadius: cornerRadius,
65
66
  paddingAngle: paddingAngle,
66
67
  id: seriesId,
@@ -76,22 +77,29 @@ function PiePlot(props) {
76
77
  }, seriesId);
77
78
  }), seriesOrder.map(seriesId => {
78
79
  const {
79
- innerRadius,
80
- outerRadius,
80
+ innerRadius: innerRadiusParam,
81
+ outerRadius: outerRadiusParam,
82
+ arcLabelRadius: arcLabelRadiusParam,
81
83
  cornerRadius,
82
84
  paddingAngle,
83
85
  arcLabel,
84
86
  arcLabelMinAngle,
85
87
  data,
86
- cx,
87
- cy,
88
+ cx: cxParam,
89
+ cy: cyParam,
88
90
  highlightScope
89
91
  } = series[seriesId];
92
+ const outerRadius = getPercentageValue(outerRadiusParam ?? availableRadius, availableRadius);
93
+ const innerRadius = getPercentageValue(innerRadiusParam ?? 0, availableRadius);
94
+ const arcLabelRadius = arcLabelRadiusParam === undefined ? (outerRadius + innerRadius) / 2 : getPercentageValue(arcLabelRadiusParam, availableRadius);
95
+ const cx = getPercentageValue(cxParam ?? '50%', width);
96
+ const cy = getPercentageValue(cyParam ?? '50%', height);
90
97
  return /*#__PURE__*/_jsx("g", {
91
- transform: `translate(${cx === undefined ? center.x : left + cx}, ${cy === undefined ? center.y : top + cy})`,
98
+ transform: `translate(${left + cx}, ${top + cy})`,
92
99
  children: /*#__PURE__*/_jsx(PieArcLabelPlot, {
93
100
  innerRadius: innerRadius,
94
101
  outerRadius: outerRadius ?? availableRadius,
102
+ arcLabelRadius: arcLabelRadius,
95
103
  cornerRadius: cornerRadius,
96
104
  paddingAngle: paddingAngle,
97
105
  id: seriesId,
@@ -70,6 +70,7 @@ export const defaultLabelTransitionConfig = {
70
70
  from: ({
71
71
  innerRadius,
72
72
  outerRadius,
73
+ arcLabelRadius,
73
74
  cornerRadius,
74
75
  startAngle,
75
76
  endAngle,
@@ -78,6 +79,7 @@ export const defaultLabelTransitionConfig = {
78
79
  innerRadius,
79
80
  outerRadius: (innerRadius + outerRadius) / 2,
80
81
  cornerRadius,
82
+ arcLabelRadius,
81
83
  startAngle: (startAngle + endAngle) / 2,
82
84
  endAngle: (startAngle + endAngle) / 2,
83
85
  paddingAngle,
@@ -90,6 +92,7 @@ export const defaultLabelTransitionConfig = {
90
92
  }) => ({
91
93
  innerRadius,
92
94
  outerRadius: innerRadius,
95
+ arcLabelRadius: innerRadius,
93
96
  startAngle: (startAngle + endAngle) / 2,
94
97
  endAngle: (startAngle + endAngle) / 2,
95
98
  opacity: 0
@@ -98,12 +101,14 @@ export const defaultLabelTransitionConfig = {
98
101
  innerRadius,
99
102
  outerRadius,
100
103
  startAngle,
101
- endAngle
104
+ endAngle,
105
+ arcLabelRadius
102
106
  }) => ({
103
107
  innerRadius,
104
108
  outerRadius,
105
109
  startAngle,
106
110
  endAngle,
111
+ arcLabelRadius,
107
112
  opacity: 1
108
113
  }),
109
114
  update: ({
@@ -112,7 +117,8 @@ export const defaultLabelTransitionConfig = {
112
117
  cornerRadius,
113
118
  startAngle,
114
119
  endAngle,
115
- paddingAngle
120
+ paddingAngle,
121
+ arcLabelRadius
116
122
  }) => ({
117
123
  innerRadius,
118
124
  outerRadius,
@@ -120,6 +126,7 @@ export const defaultLabelTransitionConfig = {
120
126
  startAngle,
121
127
  endAngle,
122
128
  paddingAngle,
129
+ arcLabelRadius,
123
130
  opacity: 1
124
131
  }),
125
132
  config: {
@@ -11,6 +11,7 @@ export function useTransformData(series) {
11
11
  highlighted,
12
12
  paddingAngle: basePaddingAngle = 0,
13
13
  innerRadius: baseInnerRadius = 0,
14
+ arcLabelRadius: baseArcLabelRadius,
14
15
  outerRadius: baseOuterRadius,
15
16
  cornerRadius: baseCornerRadius = 0
16
17
  } = series;
@@ -38,21 +39,23 @@ export function useTransformData(series) {
38
39
  isHighlighted,
39
40
  isFaded
40
41
  } = getHighlightStatus(itemIndex);
41
- const attibuesOverride = _extends({
42
+ const attributesOverride = _extends({
42
43
  additionalRadius: 0
43
44
  }, isFaded && faded || isHighlighted && highlighted || {});
44
- const paddingAngle = Math.max(0, Math.PI * (attibuesOverride.paddingAngle ?? basePaddingAngle) / 180);
45
- const innerRadius = Math.max(0, attibuesOverride.innerRadius ?? baseInnerRadius);
46
- const outerRadius = Math.max(0, attibuesOverride.outerRadius ?? baseOuterRadius + attibuesOverride.additionalRadius);
47
- const cornerRadius = attibuesOverride.cornerRadius ?? baseCornerRadius;
48
- return _extends({}, item, attibuesOverride, {
45
+ const paddingAngle = Math.max(0, Math.PI * (attributesOverride.paddingAngle ?? basePaddingAngle) / 180);
46
+ const innerRadius = Math.max(0, attributesOverride.innerRadius ?? baseInnerRadius);
47
+ const outerRadius = Math.max(0, attributesOverride.outerRadius ?? baseOuterRadius + attributesOverride.additionalRadius);
48
+ const cornerRadius = attributesOverride.cornerRadius ?? baseCornerRadius;
49
+ const arcLabelRadius = attributesOverride.arcLabelRadius ?? baseArcLabelRadius ?? (innerRadius + outerRadius) / 2;
50
+ return _extends({}, item, attributesOverride, {
49
51
  isFaded,
50
52
  isHighlighted,
51
53
  paddingAngle,
52
54
  innerRadius,
53
55
  outerRadius,
54
- cornerRadius
56
+ cornerRadius,
57
+ arcLabelRadius
55
58
  });
56
- }), [baseCornerRadius, baseInnerRadius, baseOuterRadius, basePaddingAngle, data, faded, getHighlightStatus, highlighted]);
59
+ }), [baseCornerRadius, baseInnerRadius, baseOuterRadius, basePaddingAngle, baseArcLabelRadius, data, faded, getHighlightStatus, highlighted]);
57
60
  return dataWithHighlight;
58
61
  }
@@ -60,11 +60,11 @@ const useChartDimensions = (inWidth, inHeight) => {
60
60
  }, [computeSize, inHeight, inWidth]);
61
61
  if (process.env.NODE_ENV !== 'production') {
62
62
  if (displayError.current && inWidth === undefined && width === 0) {
63
- console.error(`MUI: Charts does not have \`width\` prop, and its container has no \`width\` defined.`);
63
+ console.error(`MUI-X-Charts: ChartContainer does not have \`width\` prop, and its container has no \`width\` defined.`);
64
64
  displayError.current = false;
65
65
  }
66
66
  if (displayError.current && inHeight === undefined && height === 0) {
67
- console.error(`MUI: Charts does not have \`height\` prop, and its container has no \`height\` defined.`);
67
+ console.error(`MUI-X-Charts: ChartContainer does not have \`height\` prop, and its container has no \`height\` defined.`);
68
68
  displayError.current = false;
69
69
  }
70
70
  }
@@ -52,7 +52,7 @@ function CartesianContextProvider({
52
52
  return axisConfig;
53
53
  }
54
54
  if (dataset === undefined) {
55
- throw Error('MUI: x-axis uses `dataKey` but no `dataset` is provided.');
55
+ throw Error('MUI-X-Charts: x-axis uses `dataKey` but no `dataset` is provided.');
56
56
  }
57
57
  return _extends({}, axisConfig, {
58
58
  data: dataset.map(d => d[dataKey])
@@ -64,7 +64,7 @@ function CartesianContextProvider({
64
64
  return axisConfig;
65
65
  }
66
66
  if (dataset === undefined) {
67
- throw Error('MUI: y-axis uses `dataKey` but no `dataset` is provided.');
67
+ throw Error('MUI-X-Charts: y-axis uses `dataKey` but no `dataset` is provided.');
68
68
  }
69
69
  return _extends({}, axisConfig, {
70
70
  data: dataset.map(d => d[dataKey])
@@ -39,7 +39,7 @@ const formatSeries = (series, colors, dataset) => {
39
39
  };
40
40
  }
41
41
  if (seriesGroups[type]?.series[id] !== undefined) {
42
- throw new Error(`MUI: series' id "${id}" is not unique`);
42
+ throw new Error(`MUI-X-Charts: series' id "${id}" is not unique`);
43
43
  }
44
44
  seriesGroups[type].series[id] = _extends({
45
45
  id