@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,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';
@@ -29,8 +29,9 @@ function PieArcLabelPlot(props) {
29
29
  const {
30
30
  slots,
31
31
  slotProps,
32
- innerRadius = 0,
32
+ innerRadius,
33
33
  outerRadius,
34
+ arcLabelRadius,
34
35
  cornerRadius = 0,
35
36
  paddingAngle = 0,
36
37
  id,
@@ -48,6 +49,7 @@ function PieArcLabelPlot(props) {
48
49
  const transformedData = useTransformData({
49
50
  innerRadius,
50
51
  outerRadius,
52
+ arcLabelRadius,
51
53
  cornerRadius,
52
54
  paddingAngle,
53
55
  id,
@@ -71,6 +73,7 @@ function PieArcLabelPlot(props) {
71
73
  paddingAngle: pA,
72
74
  innerRadius: iR,
73
75
  outerRadius: oR,
76
+ arcLabelRadius: aLR,
74
77
  cornerRadius: cR
75
78
  } = _ref,
76
79
  style = _objectWithoutPropertiesLoose(_ref, _excluded2);
@@ -80,6 +83,7 @@ function PieArcLabelPlot(props) {
80
83
  paddingAngle: pA,
81
84
  innerRadius: iR,
82
85
  outerRadius: oR,
86
+ arcLabelRadius: aLR,
83
87
  cornerRadius: cR,
84
88
  style: style,
85
89
  id: id,
@@ -104,6 +108,11 @@ process.env.NODE_ENV !== "production" ? PieArcLabelPlot.propTypes = {
104
108
  * The minimal angle required to display the arc label.
105
109
  */
106
110
  arcLabelMinAngle: PropTypes.number,
111
+ /**
112
+ * The radius between circle center and the arc label in px.
113
+ * @default (innerRadius - outerRadius) / 2
114
+ */
115
+ arcLabelRadius: PropTypes.number,
107
116
  /**
108
117
  * The radius applied to arc corners (similar to border radius).
109
118
  * @default 0
@@ -125,6 +134,7 @@ process.env.NODE_ENV !== "production" ? PieArcLabelPlot.propTypes = {
125
134
  */
126
135
  faded: PropTypes.shape({
127
136
  additionalRadius: PropTypes.number,
137
+ arcLabelRadius: PropTypes.number,
128
138
  color: PropTypes.string,
129
139
  cornerRadius: PropTypes.number,
130
140
  innerRadius: PropTypes.number,
@@ -136,6 +146,7 @@ process.env.NODE_ENV !== "production" ? PieArcLabelPlot.propTypes = {
136
146
  */
137
147
  highlighted: PropTypes.shape({
138
148
  additionalRadius: PropTypes.number,
149
+ arcLabelRadius: PropTypes.number,
139
150
  color: PropTypes.string,
140
151
  cornerRadius: PropTypes.number,
141
152
  innerRadius: PropTypes.number,
@@ -154,7 +165,6 @@ process.env.NODE_ENV !== "production" ? PieArcLabelPlot.propTypes = {
154
165
  innerRadius: PropTypes.number,
155
166
  /**
156
167
  * The radius between circle center and the end of the arc.
157
- * @default R_max The maximal radius that fit into the drawing area.
158
168
  */
159
169
  outerRadius: PropTypes.number.isRequired,
160
170
  /**
@@ -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';
@@ -88,6 +88,11 @@ process.env.NODE_ENV !== "production" ? PieArcPlot.propTypes = {
88
88
  // | These PropTypes are generated from the TypeScript type definitions |
89
89
  // | To update them edit the TypeScript types and run "yarn proptypes" |
90
90
  // ----------------------------------------------------------------------
91
+ /**
92
+ * The radius between circle center and the arc label in px.
93
+ * @default (innerRadius - outerRadius) / 2
94
+ */
95
+ arcLabelRadius: PropTypes.number,
91
96
  /**
92
97
  * The radius applied to arc corners (similar to border radius).
93
98
  * @default 0
@@ -109,6 +114,7 @@ process.env.NODE_ENV !== "production" ? PieArcPlot.propTypes = {
109
114
  */
110
115
  faded: PropTypes.shape({
111
116
  additionalRadius: PropTypes.number,
117
+ arcLabelRadius: PropTypes.number,
112
118
  color: PropTypes.string,
113
119
  cornerRadius: PropTypes.number,
114
120
  innerRadius: PropTypes.number,
@@ -120,6 +126,7 @@ process.env.NODE_ENV !== "production" ? PieArcPlot.propTypes = {
120
126
  */
121
127
  highlighted: PropTypes.shape({
122
128
  additionalRadius: PropTypes.number,
129
+ arcLabelRadius: PropTypes.number,
123
130
  color: PropTypes.string,
124
131
  cornerRadius: PropTypes.number,
125
132
  innerRadius: PropTypes.number,
@@ -145,7 +152,6 @@ process.env.NODE_ENV !== "production" ? PieArcPlot.propTypes = {
145
152
  onClick: PropTypes.func,
146
153
  /**
147
154
  * The radius between circle center and the end of the arc.
148
- * @default R_max The maximal radius that fit into the drawing area.
149
155
  */
150
156
  outerRadius: PropTypes.number.isRequired,
151
157
  /**
@@ -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 != null ? outerRadiusParam : availableRadius, availableRadius);
57
+ const innerRadius = getPercentageValue(innerRadiusParam != null ? innerRadiusParam : 0, availableRadius);
58
+ const cx = getPercentageValue(cxParam != null ? cxParam : '50%', width);
59
+ const cy = getPercentageValue(cyParam != null ? 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 != null ? 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 != null ? outerRadiusParam : availableRadius, availableRadius);
93
+ const innerRadius = getPercentageValue(innerRadiusParam != null ? innerRadiusParam : 0, availableRadius);
94
+ const arcLabelRadius = arcLabelRadiusParam === undefined ? (outerRadius + innerRadius) / 2 : getPercentageValue(arcLabelRadiusParam, availableRadius);
95
+ const cx = getPercentageValue(cxParam != null ? cxParam : '50%', width);
96
+ const cy = getPercentageValue(cyParam != null ? 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 != null ? 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;
@@ -34,26 +35,28 @@ export function useTransformData(series) {
34
35
  };
35
36
  }, [highlightScope, highlightedItem, seriesId]);
36
37
  const dataWithHighlight = React.useMemo(() => data.map((item, itemIndex) => {
37
- var _attibuesOverride$pad, _attibuesOverride$inn, _attibuesOverride$out, _attibuesOverride$cor;
38
+ var _attributesOverride$p, _attributesOverride$i, _attributesOverride$o, _attributesOverride$c, _ref, _attributesOverride$a;
38
39
  const {
39
40
  isHighlighted,
40
41
  isFaded
41
42
  } = getHighlightStatus(itemIndex);
42
- const attibuesOverride = _extends({
43
+ const attributesOverride = _extends({
43
44
  additionalRadius: 0
44
45
  }, isFaded && faded || isHighlighted && highlighted || {});
45
- const paddingAngle = Math.max(0, Math.PI * ((_attibuesOverride$pad = attibuesOverride.paddingAngle) != null ? _attibuesOverride$pad : basePaddingAngle) / 180);
46
- const innerRadius = Math.max(0, (_attibuesOverride$inn = attibuesOverride.innerRadius) != null ? _attibuesOverride$inn : baseInnerRadius);
47
- const outerRadius = Math.max(0, (_attibuesOverride$out = attibuesOverride.outerRadius) != null ? _attibuesOverride$out : baseOuterRadius + attibuesOverride.additionalRadius);
48
- const cornerRadius = (_attibuesOverride$cor = attibuesOverride.cornerRadius) != null ? _attibuesOverride$cor : baseCornerRadius;
49
- return _extends({}, item, attibuesOverride, {
46
+ const paddingAngle = Math.max(0, Math.PI * ((_attributesOverride$p = attributesOverride.paddingAngle) != null ? _attributesOverride$p : basePaddingAngle) / 180);
47
+ const innerRadius = Math.max(0, (_attributesOverride$i = attributesOverride.innerRadius) != null ? _attributesOverride$i : baseInnerRadius);
48
+ const outerRadius = Math.max(0, (_attributesOverride$o = attributesOverride.outerRadius) != null ? _attributesOverride$o : baseOuterRadius + attributesOverride.additionalRadius);
49
+ const cornerRadius = (_attributesOverride$c = attributesOverride.cornerRadius) != null ? _attributesOverride$c : baseCornerRadius;
50
+ const arcLabelRadius = (_ref = (_attributesOverride$a = attributesOverride.arcLabelRadius) != null ? _attributesOverride$a : baseArcLabelRadius) != null ? _ref : (innerRadius + outerRadius) / 2;
51
+ return _extends({}, item, attributesOverride, {
50
52
  isFaded,
51
53
  isHighlighted,
52
54
  paddingAngle,
53
55
  innerRadius,
54
56
  outerRadius,
55
- cornerRadius
57
+ cornerRadius,
58
+ arcLabelRadius
56
59
  });
57
- }), [baseCornerRadius, baseInnerRadius, baseOuterRadius, basePaddingAngle, data, faded, getHighlightStatus, highlighted]);
60
+ }), [baseCornerRadius, baseInnerRadius, baseOuterRadius, basePaddingAngle, baseArcLabelRadius, data, faded, getHighlightStatus, highlighted]);
58
61
  return dataWithHighlight;
59
62
  }
@@ -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])
@@ -40,7 +40,7 @@ const formatSeries = (series, colors, dataset) => {
40
40
  };
41
41
  }
42
42
  if (((_seriesGroups$type = seriesGroups[type]) == null ? void 0 : _seriesGroups$type.series[id]) !== undefined) {
43
- throw new Error(`MUI: series' id "${id}" is not unique`);
43
+ throw new Error(`MUI-X-Charts: series' id "${id}" is not unique`);
44
44
  }
45
45
  seriesGroups[type].series[id] = _extends({
46
46
  id
package/esm/index.js CHANGED
@@ -8,6 +8,7 @@ export * from './ChartsReferenceLine';
8
8
  export * from './ChartsAxis';
9
9
  export * from './ChartsXAxis';
10
10
  export * from './ChartsYAxis';
11
+ export * from './ChartsText';
11
12
  export * from './ChartsTooltip';
12
13
  export * from './ChartsLegend';
13
14
  export * from './ChartsAxisHighlight';
@@ -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
+ }
@@ -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
+ 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.`);
16
45
  }
package/index.d.ts CHANGED
@@ -8,6 +8,7 @@ export * from './ChartsReferenceLine';
8
8
  export * from './ChartsAxis';
9
9
  export * from './ChartsXAxis';
10
10
  export * from './ChartsYAxis';
11
+ export * from './ChartsText';
11
12
  export * from './ChartsTooltip';
12
13
  export * from './ChartsLegend';
13
14
  export * from './ChartsAxisHighlight';
package/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
@@ -120,6 +120,17 @@ Object.keys(_ChartsYAxis).forEach(function (key) {
120
120
  }
121
121
  });
122
122
  });
123
+ var _ChartsText = require("./ChartsText");
124
+ Object.keys(_ChartsText).forEach(function (key) {
125
+ if (key === "default" || key === "__esModule") return;
126
+ if (key in exports && exports[key] === _ChartsText[key]) return;
127
+ Object.defineProperty(exports, key, {
128
+ enumerable: true,
129
+ get: function () {
130
+ return _ChartsText[key];
131
+ }
132
+ });
133
+ });
123
134
  var _ChartsTooltip = require("./ChartsTooltip");
124
135
  Object.keys(_ChartsTooltip).forEach(function (key) {
125
136
  if (key === "default" || key === "__esModule") return;
@@ -7,8 +7,9 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
7
7
  id?: string | number | undefined;
8
8
  }[];
9
9
  type: "pie";
10
- innerRadius?: number | undefined;
11
- outerRadius?: number | undefined;
10
+ innerRadius?: string | number | undefined;
11
+ outerRadius?: string | number | undefined;
12
+ arcLabelRadius?: string | number | undefined;
12
13
  cornerRadius?: number | undefined;
13
14
  startAngle?: number | undefined;
14
15
  endAngle?: number | undefined;
@@ -16,14 +17,15 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
16
17
  sortingValues?: import("../models/seriesType").ChartsPieSorting | undefined;
17
18
  arcLabel?: "label" | "value" | "formattedValue" | ((item: import("../models/seriesType").DefaultizedPieValueType) => string) | undefined;
18
19
  arcLabelMinAngle?: number | undefined;
19
- cx?: number | undefined;
20
- cy?: number | undefined;
20
+ cx?: string | number | undefined;
21
+ cy?: string | number | undefined;
21
22
  highlighted?: {
22
23
  additionalRadius?: number | undefined;
23
24
  innerRadius?: number | undefined;
24
25
  outerRadius?: number | undefined;
25
26
  cornerRadius?: number | undefined;
26
27
  paddingAngle?: number | undefined;
28
+ arcLabelRadius?: number | undefined;
27
29
  color?: string | undefined;
28
30
  } | undefined;
29
31
  faded?: {
@@ -32,6 +34,7 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
32
34
  outerRadius?: number | undefined;
33
35
  cornerRadius?: number | undefined;
34
36
  paddingAngle?: number | undefined;
37
+ arcLabelRadius?: number | undefined;
35
38
  color?: string | undefined;
36
39
  } | undefined;
37
40
  id?: string | undefined;
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ /// <reference types="react" />
2
2
  export type ChartsTextBaseline = 'hanging' | 'central' | 'auto';
3
3
  export interface ChartsTextStyle extends React.CSSProperties {
4
4
  angle?: number;
@@ -8,7 +8,7 @@ export interface ChartsTextStyle extends React.CSSProperties {
8
8
  */
9
9
  dominantBaseline?: ChartsTextBaseline;
10
10
  }
11
- interface GetWordsByLinesParams {
11
+ export interface GetWordsByLinesParams {
12
12
  /**
13
13
  * Text displayed.
14
14
  */
@@ -23,13 +23,4 @@ interface GetWordsByLinesParams {
23
23
  */
24
24
  needsComputation?: boolean;
25
25
  }
26
- export interface ChartsTextProps extends Omit<React.SVGTextElementAttributes<SVGTextElement>, 'width' | 'ref' | 'style' | 'dominantBaseline'>, GetWordsByLinesParams {
27
- /**
28
- * Height of a text line (in `em`).
29
- */
30
- lineHeight?: number;
31
- ownerState?: any;
32
- }
33
26
  export declare function getWordsByLines({ style, needsComputation, text }: GetWordsByLinesParams): any[];
34
- export declare function ChartsText(props: ChartsTextProps): React.JSX.Element;
35
- export {};
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getWordsByLines = getWordsByLines;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _domUtils = require("./domUtils");
10
+ function getWordsByLines({
11
+ style,
12
+ needsComputation,
13
+ text
14
+ }) {
15
+ return text.split('\n').map(subText => (0, _extends2.default)({
16
+ text: subText
17
+ }, needsComputation ? (0, _domUtils.getStringSize)(subText, style) : {
18
+ width: 0,
19
+ height: 0
20
+ }));
21
+ }
@@ -10,4 +10,11 @@ export type XOR<T, U> = T | U extends object ? (Without<T, U> & U) | (Without<U,
10
10
  * @param event The mouseEvent to transform
11
11
  */
12
12
  export declare function getSVGPoint(svg: SVGSVGElement, event: MouseEvent): DOMPoint;
13
+ /**
14
+ * Helper that converts values and percentages into values.
15
+ * @param value The value provided by the developer. Can either be a number or a string with '%' or 'px'.
16
+ * @param refValue The numerical value associated to 100%.
17
+ * @returns The numerical value associated to the provided value.
18
+ */
19
+ export declare function getPercentageValue(value: number | string, refValue: number): number;
13
20
  export {};