@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
@@ -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 0;
58
+ }
59
+ return value;
60
+ }) : series[id].data,
49
61
  stackedData: stackedSeries[index].map(([a, b]) => [a, b])
50
62
  });
51
63
  });
@@ -152,7 +152,6 @@ process.env.NODE_ENV !== "production" ? PieArcLabelPlot.propTypes = {
152
152
  innerRadius: PropTypes.number,
153
153
  /**
154
154
  * 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
155
  */
157
156
  outerRadius: PropTypes.number.isRequired,
158
157
  /**
@@ -144,7 +144,6 @@ process.env.NODE_ENV !== "production" ? PieArcPlot.propTypes = {
144
144
  onClick: PropTypes.func,
145
145
  /**
146
146
  * 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
147
  */
149
148
  outerRadius: PropTypes.number.isRequired,
150
149
  /**
@@ -240,8 +240,8 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
240
240
  arcLabelMinAngle: PropTypes.number,
241
241
  color: PropTypes.string,
242
242
  cornerRadius: PropTypes.number,
243
- cx: PropTypes.number,
244
- cy: PropTypes.number,
243
+ cx: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
244
+ cy: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
245
245
  data: PropTypes.arrayOf(PropTypes.shape({
246
246
  color: PropTypes.string,
247
247
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
@@ -270,8 +270,8 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
270
270
  highlighted: PropTypes.oneOf(['item', 'none', 'series'])
271
271
  }),
272
272
  id: PropTypes.string,
273
- innerRadius: PropTypes.number,
274
- outerRadius: PropTypes.number,
273
+ innerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
274
+ outerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
275
275
  paddingAngle: PropTypes.number,
276
276
  sortingValues: PropTypes.oneOfType([PropTypes.oneOf(['asc', 'desc', 'none']), PropTypes.func]),
277
277
  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,19 +77,23 @@ function PiePlot(props) {
76
77
  }, seriesId);
77
78
  }), seriesOrder.map(seriesId => {
78
79
  const {
79
- innerRadius,
80
- outerRadius,
80
+ innerRadius: innerRadiusParam,
81
+ outerRadius: outerRadiusParam,
81
82
  cornerRadius,
82
83
  paddingAngle,
83
84
  arcLabel,
84
85
  arcLabelMinAngle,
85
86
  data,
86
- cx,
87
- cy,
87
+ cx: cxParam,
88
+ cy: cyParam,
88
89
  highlightScope
89
90
  } = series[seriesId];
91
+ const outerRadius = getPercentageValue(outerRadiusParam ?? availableRadius, availableRadius);
92
+ const innerRadius = getPercentageValue(innerRadiusParam ?? 0, availableRadius);
93
+ const cx = getPercentageValue(cxParam ?? '50%', width);
94
+ const cy = getPercentageValue(cyParam ?? '50%', height);
90
95
  return /*#__PURE__*/_jsx("g", {
91
- transform: `translate(${cx === undefined ? center.x : left + cx}, ${cy === undefined ? center.y : top + cy})`,
96
+ transform: `translate(${left + cx}, ${top + cy})`,
92
97
  children: /*#__PURE__*/_jsx(PieArcLabelPlot, {
93
98
  innerRadius: innerRadius,
94
99
  outerRadius: outerRadius ?? availableRadius,
@@ -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
package/modern/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,14 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import { getStringSize } from './domUtils';
3
+ export function getWordsByLines({
4
+ style,
5
+ needsComputation,
6
+ text
7
+ }) {
8
+ return text.split('\n').map(subText => _extends({
9
+ text: subText
10
+ }, needsComputation ? getStringSize(subText, style) : {
11
+ width: 0,
12
+ height: 0
13
+ }));
14
+ }
@@ -2,4 +2,44 @@
2
2
  export function getSymbol(shape) {
3
3
  const 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
+ const 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
+ const 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
+ const 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 "${value}". It should be a number, or a string with a percentage value.`);
5
45
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-charts",
3
- "version": "6.18.3",
3
+ "version": "6.18.4",
4
4
  "description": "The community edition of the charts components (MUI X).",
5
5
  "author": "MUI Team",
6
6
  "main": "./index.js",