@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
@@ -11,6 +11,7 @@ var _SeriesContextProvider = require("../context/SeriesContextProvider");
11
11
  var _DrawingProvider = require("../context/DrawingProvider");
12
12
  var _PieArcPlot = require("./PieArcPlot");
13
13
  var _PieArcLabelPlot = require("./PieArcLabelPlot");
14
+ var _utils = require("../internals/utils");
14
15
  var _jsxRuntime = require("react/jsx-runtime");
15
16
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
16
17
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -42,10 +43,6 @@ function PiePlot(props) {
42
43
  return null;
43
44
  }
44
45
  const availableRadius = Math.min(width, height) / 2;
45
- const center = {
46
- x: left + width / 2,
47
- y: top + height / 2
48
- };
49
46
  const {
50
47
  series,
51
48
  seriesOrder
@@ -53,22 +50,26 @@ function PiePlot(props) {
53
50
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("g", {
54
51
  children: [seriesOrder.map(seriesId => {
55
52
  const {
56
- innerRadius,
57
- outerRadius,
53
+ innerRadius: innerRadiusParam,
54
+ outerRadius: outerRadiusParam,
58
55
  cornerRadius,
59
56
  paddingAngle,
60
57
  data,
61
- cx,
62
- cy,
58
+ cx: cxParam,
59
+ cy: cyParam,
63
60
  highlighted,
64
61
  faded,
65
62
  highlightScope
66
63
  } = series[seriesId];
64
+ const outerRadius = (0, _utils.getPercentageValue)(outerRadiusParam ?? availableRadius, availableRadius);
65
+ const innerRadius = (0, _utils.getPercentageValue)(innerRadiusParam ?? 0, availableRadius);
66
+ const cx = (0, _utils.getPercentageValue)(cxParam ?? '50%', width);
67
+ const cy = (0, _utils.getPercentageValue)(cyParam ?? '50%', height);
67
68
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
68
- transform: `translate(${cx === undefined ? center.x : left + cx}, ${cy === undefined ? center.y : top + cy})`,
69
+ transform: `translate(${left + cx}, ${top + cy})`,
69
70
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_PieArcPlot.PieArcPlot, {
70
71
  innerRadius: innerRadius,
71
- outerRadius: outerRadius ?? availableRadius,
72
+ outerRadius: outerRadius,
72
73
  cornerRadius: cornerRadius,
73
74
  paddingAngle: paddingAngle,
74
75
  id: seriesId,
@@ -84,22 +85,29 @@ function PiePlot(props) {
84
85
  }, seriesId);
85
86
  }), seriesOrder.map(seriesId => {
86
87
  const {
87
- innerRadius,
88
- outerRadius,
88
+ innerRadius: innerRadiusParam,
89
+ outerRadius: outerRadiusParam,
90
+ arcLabelRadius: arcLabelRadiusParam,
89
91
  cornerRadius,
90
92
  paddingAngle,
91
93
  arcLabel,
92
94
  arcLabelMinAngle,
93
95
  data,
94
- cx,
95
- cy,
96
+ cx: cxParam,
97
+ cy: cyParam,
96
98
  highlightScope
97
99
  } = series[seriesId];
100
+ const outerRadius = (0, _utils.getPercentageValue)(outerRadiusParam ?? availableRadius, availableRadius);
101
+ const innerRadius = (0, _utils.getPercentageValue)(innerRadiusParam ?? 0, availableRadius);
102
+ const arcLabelRadius = arcLabelRadiusParam === undefined ? (outerRadius + innerRadius) / 2 : (0, _utils.getPercentageValue)(arcLabelRadiusParam, availableRadius);
103
+ const cx = (0, _utils.getPercentageValue)(cxParam ?? '50%', width);
104
+ const cy = (0, _utils.getPercentageValue)(cyParam ?? '50%', height);
98
105
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
99
- transform: `translate(${cx === undefined ? center.x : left + cx}, ${cy === undefined ? center.y : top + cy})`,
106
+ transform: `translate(${left + cx}, ${top + cy})`,
100
107
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_PieArcLabelPlot.PieArcLabelPlot, {
101
108
  innerRadius: innerRadius,
102
109
  outerRadius: outerRadius ?? availableRadius,
110
+ arcLabelRadius: arcLabelRadius,
103
111
  cornerRadius: cornerRadius,
104
112
  paddingAngle: paddingAngle,
105
113
  id: seriesId,
@@ -76,6 +76,7 @@ const defaultLabelTransitionConfig = exports.defaultLabelTransitionConfig = {
76
76
  from: ({
77
77
  innerRadius,
78
78
  outerRadius,
79
+ arcLabelRadius,
79
80
  cornerRadius,
80
81
  startAngle,
81
82
  endAngle,
@@ -84,6 +85,7 @@ const defaultLabelTransitionConfig = exports.defaultLabelTransitionConfig = {
84
85
  innerRadius,
85
86
  outerRadius: (innerRadius + outerRadius) / 2,
86
87
  cornerRadius,
88
+ arcLabelRadius,
87
89
  startAngle: (startAngle + endAngle) / 2,
88
90
  endAngle: (startAngle + endAngle) / 2,
89
91
  paddingAngle,
@@ -96,6 +98,7 @@ const defaultLabelTransitionConfig = exports.defaultLabelTransitionConfig = {
96
98
  }) => ({
97
99
  innerRadius,
98
100
  outerRadius: innerRadius,
101
+ arcLabelRadius: innerRadius,
99
102
  startAngle: (startAngle + endAngle) / 2,
100
103
  endAngle: (startAngle + endAngle) / 2,
101
104
  opacity: 0
@@ -104,12 +107,14 @@ const defaultLabelTransitionConfig = exports.defaultLabelTransitionConfig = {
104
107
  innerRadius,
105
108
  outerRadius,
106
109
  startAngle,
107
- endAngle
110
+ endAngle,
111
+ arcLabelRadius
108
112
  }) => ({
109
113
  innerRadius,
110
114
  outerRadius,
111
115
  startAngle,
112
116
  endAngle,
117
+ arcLabelRadius,
113
118
  opacity: 1
114
119
  }),
115
120
  update: ({
@@ -118,7 +123,8 @@ const defaultLabelTransitionConfig = exports.defaultLabelTransitionConfig = {
118
123
  cornerRadius,
119
124
  startAngle,
120
125
  endAngle,
121
- paddingAngle
126
+ paddingAngle,
127
+ arcLabelRadius
122
128
  }) => ({
123
129
  innerRadius,
124
130
  outerRadius,
@@ -126,6 +132,7 @@ const defaultLabelTransitionConfig = exports.defaultLabelTransitionConfig = {
126
132
  startAngle,
127
133
  endAngle,
128
134
  paddingAngle,
135
+ arcLabelRadius,
129
136
  opacity: 1
130
137
  }),
131
138
  config: {
@@ -1,8 +1,8 @@
1
- import { DefaultizedPieSeriesType, DefaultizedPieValueType } from '../../models/seriesType/pie';
2
- import { DefaultizedProps } from '../../models/helpers';
1
+ import { ComputedPieRadius, DefaultizedPieSeriesType, DefaultizedPieValueType } from '../../models/seriesType/pie';
3
2
  export interface AnimatedObject {
4
3
  innerRadius: number;
5
4
  outerRadius: number;
5
+ arcLabelRadius: number;
6
6
  cornerRadius: number;
7
7
  startAngle: number;
8
8
  endAngle: number;
@@ -12,4 +12,4 @@ export interface ValueWithHighlight extends DefaultizedPieValueType, AnimatedObj
12
12
  isFaded: boolean;
13
13
  isHighlighted: boolean;
14
14
  }
15
- export declare function useTransformData(series: DefaultizedProps<Pick<DefaultizedPieSeriesType, 'innerRadius' | 'outerRadius' | 'cornerRadius' | 'paddingAngle' | 'id' | 'highlightScope' | 'highlighted' | 'faded' | 'data'>, 'outerRadius'>): ValueWithHighlight[];
15
+ export declare function useTransformData(series: Pick<DefaultizedPieSeriesType, 'cornerRadius' | 'paddingAngle' | 'id' | 'highlightScope' | 'highlighted' | 'faded' | 'data'> & ComputedPieRadius): ValueWithHighlight[];
@@ -20,6 +20,7 @@ function useTransformData(series) {
20
20
  highlighted,
21
21
  paddingAngle: basePaddingAngle = 0,
22
22
  innerRadius: baseInnerRadius = 0,
23
+ arcLabelRadius: baseArcLabelRadius,
23
24
  outerRadius: baseOuterRadius,
24
25
  cornerRadius: baseCornerRadius = 0
25
26
  } = series;
@@ -47,21 +48,23 @@ function useTransformData(series) {
47
48
  isHighlighted,
48
49
  isFaded
49
50
  } = getHighlightStatus(itemIndex);
50
- const attibuesOverride = (0, _extends2.default)({
51
+ const attributesOverride = (0, _extends2.default)({
51
52
  additionalRadius: 0
52
53
  }, isFaded && faded || isHighlighted && highlighted || {});
53
- const paddingAngle = Math.max(0, Math.PI * (attibuesOverride.paddingAngle ?? basePaddingAngle) / 180);
54
- const innerRadius = Math.max(0, attibuesOverride.innerRadius ?? baseInnerRadius);
55
- const outerRadius = Math.max(0, attibuesOverride.outerRadius ?? baseOuterRadius + attibuesOverride.additionalRadius);
56
- const cornerRadius = attibuesOverride.cornerRadius ?? baseCornerRadius;
57
- return (0, _extends2.default)({}, item, attibuesOverride, {
54
+ const paddingAngle = Math.max(0, Math.PI * (attributesOverride.paddingAngle ?? basePaddingAngle) / 180);
55
+ const innerRadius = Math.max(0, attributesOverride.innerRadius ?? baseInnerRadius);
56
+ const outerRadius = Math.max(0, attributesOverride.outerRadius ?? baseOuterRadius + attributesOverride.additionalRadius);
57
+ const cornerRadius = attributesOverride.cornerRadius ?? baseCornerRadius;
58
+ const arcLabelRadius = attributesOverride.arcLabelRadius ?? baseArcLabelRadius ?? (innerRadius + outerRadius) / 2;
59
+ return (0, _extends2.default)({}, item, attributesOverride, {
58
60
  isFaded,
59
61
  isHighlighted,
60
62
  paddingAngle,
61
63
  innerRadius,
62
64
  outerRadius,
63
- cornerRadius
65
+ cornerRadius,
66
+ arcLabelRadius
64
67
  });
65
- }), [baseCornerRadius, baseInnerRadius, baseOuterRadius, basePaddingAngle, data, faded, getHighlightStatus, highlighted]);
68
+ }), [baseCornerRadius, baseInnerRadius, baseOuterRadius, basePaddingAngle, baseArcLabelRadius, data, faded, getHighlightStatus, highlighted]);
66
69
  return dataWithHighlight;
67
70
  }
@@ -69,11 +69,11 @@ const useChartDimensions = (inWidth, inHeight) => {
69
69
  }, [computeSize, inHeight, inWidth]);
70
70
  if (process.env.NODE_ENV !== 'production') {
71
71
  if (displayError.current && inWidth === undefined && width === 0) {
72
- console.error(`MUI: Charts does not have \`width\` prop, and its container has no \`width\` defined.`);
72
+ console.error(`MUI-X-Charts: ChartContainer does not have \`width\` prop, and its container has no \`width\` defined.`);
73
73
  displayError.current = false;
74
74
  }
75
75
  if (displayError.current && inHeight === undefined && height === 0) {
76
- console.error(`MUI: Charts does not have \`height\` prop, and its container has no \`height\` defined.`);
76
+ console.error(`MUI-X-Charts: ChartContainer does not have \`height\` prop, and its container has no \`height\` defined.`);
77
77
  displayError.current = false;
78
78
  }
79
79
  }
@@ -62,7 +62,7 @@ function CartesianContextProvider({
62
62
  return axisConfig;
63
63
  }
64
64
  if (dataset === undefined) {
65
- throw Error('MUI: x-axis uses `dataKey` but no `dataset` is provided.');
65
+ throw Error('MUI-X-Charts: x-axis uses `dataKey` but no `dataset` is provided.');
66
66
  }
67
67
  return (0, _extends2.default)({}, axisConfig, {
68
68
  data: dataset.map(d => d[dataKey])
@@ -74,7 +74,7 @@ function CartesianContextProvider({
74
74
  return axisConfig;
75
75
  }
76
76
  if (dataset === undefined) {
77
- throw Error('MUI: y-axis uses `dataKey` but no `dataset` is provided.');
77
+ throw Error('MUI-X-Charts: y-axis uses `dataKey` but no `dataset` is provided.');
78
78
  }
79
79
  return (0, _extends2.default)({}, axisConfig, {
80
80
  data: dataset.map(d => d[dataKey])
@@ -49,7 +49,7 @@ const formatSeries = (series, colors, dataset) => {
49
49
  };
50
50
  }
51
51
  if (seriesGroups[type]?.series[id] !== undefined) {
52
- throw new Error(`MUI: series' id "${id}" is not unique`);
52
+ throw new Error(`MUI-X-Charts: series' id "${id}" is not unique`);
53
53
  }
54
54
  seriesGroups[type].series[id] = (0, _extends2.default)({
55
55
  id
@@ -8,7 +8,8 @@ import { SeriesContext } from '../context/SeriesContextProvider';
8
8
  import { CartesianContext } from '../context/CartesianContextProvider';
9
9
  import { BarElement } from './BarElement';
10
10
  import { isBandScaleConfig } from '../models/axis';
11
- import { jsx as _jsx } from "react/jsx-runtime";
11
+ import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
12
+
12
13
  /**
13
14
  * Solution of the equations
14
15
  * W = barWidth * N + offset * (N-1)
@@ -18,6 +19,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
18
19
  * @param gapRatio The ratio of the gap between bars over the bar width.
19
20
  * @returns The bar width and the offset between bars.
20
21
  */
22
+ import { jsx as _jsx } from "react/jsx-runtime";
21
23
  function getBandSize({
22
24
  bandWidth: W,
23
25
  numberOfGroups: N,
@@ -69,18 +71,18 @@ const useCompletedData = () => {
69
71
  let baseScaleConfig;
70
72
  if (verticalLayout) {
71
73
  if (!isBandScaleConfig(xAxisConfig)) {
72
- throw new Error(`Axis with id "${xAxisKey}" shoud be of type "band" to display the bar series of id "${seriesId}"`);
74
+ throw new Error(`MUI-X-Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} shoud be of type "band" to display the bar series of id "${seriesId}"`);
73
75
  }
74
76
  if (xAxis[xAxisKey].data === undefined) {
75
- throw new Error(`Axis with id "${xAxisKey}" shoud have data property`);
77
+ throw new Error(`MUI-X-Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} shoud have data property`);
76
78
  }
77
79
  baseScaleConfig = xAxisConfig;
78
80
  } else {
79
81
  if (!isBandScaleConfig(yAxisConfig)) {
80
- throw new Error(`Axis with id "${yAxisKey}" shoud be of type "band" to display the bar series of id "${seriesId}"`);
82
+ throw new Error(`MUI-X-Charts: ${yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} shoud be of type "band" to display the bar series of id "${seriesId}"`);
81
83
  }
82
84
  if (yAxis[yAxisKey].data === undefined) {
83
- throw new Error(`Axis with id "${xAxisKey}" shoud have data property`);
85
+ throw new Error(`MUI-X-Charts: ${yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} shoud have data property`);
84
86
  }
85
87
  baseScaleConfig = yAxisConfig;
86
88
  }
@@ -2,7 +2,9 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import { stack as d3Stack } from 'd3-shape';
3
3
  import { getStackingGroups } from '../internals/stackSeries';
4
4
  import defaultizeValueFormatter from '../internals/defaultizeValueFormatter';
5
+ let warnOnce = false;
5
6
  const formatter = (params, dataset) => {
7
+ var _ref;
6
8
  const {
7
9
  seriesOrder,
8
10
  series
@@ -10,7 +12,7 @@ const formatter = (params, dataset) => {
10
12
  const stackingGroups = getStackingGroups(params);
11
13
 
12
14
  // Create a data set with format adapted to d3
13
- const d3Dataset = dataset != null ? dataset : [];
15
+ const d3Dataset = (_ref = dataset) != null ? _ref : [];
14
16
  seriesOrder.forEach(id => {
15
17
  const data = series[id].data;
16
18
  if (data !== undefined) {
@@ -24,7 +26,7 @@ const formatter = (params, dataset) => {
24
26
  }
25
27
  });
26
28
  } else if (dataset === undefined) {
27
- throw new Error([`MUI: bar series with id='${id}' has no data.`, 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
29
+ throw new Error([`MUI-X-Charts: bar series with id='${id}' has no data.`, 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
28
30
  }
29
31
  });
30
32
  const completedSeries = {};
@@ -39,13 +41,27 @@ const formatter = (params, dataset) => {
39
41
  // Use dataKey if needed and available
40
42
  const dataKey = series[id].dataKey;
41
43
  return series[id].data === undefined && dataKey !== undefined ? dataKey : id;
42
- })).order(stackingOrder).offset(stackingOffset)(d3Dataset);
44
+ })).value((d, key) => {
45
+ var _d$key;
46
+ return (_d$key = d[key]) != null ? _d$key : 0;
47
+ }) // defaultize null value to 0
48
+ .order(stackingOrder).offset(stackingOffset)(d3Dataset);
43
49
  ids.forEach((id, index) => {
44
50
  const dataKey = series[id].dataKey;
45
51
  completedSeries[id] = _extends({
46
52
  layout: 'vertical'
47
53
  }, series[id], {
48
- data: dataKey ? dataset.map(d => d[dataKey]) : series[id].data,
54
+ data: dataKey ? dataset.map(data => {
55
+ const value = data[dataKey];
56
+ if (typeof value !== 'number') {
57
+ if (process.env.NODE_ENV !== 'production' && !warnOnce && value !== null) {
58
+ warnOnce = true;
59
+ console.error([`MUI-X charts: your dataset key "${dataKey}" is used for plotting bars, but contains nonnumerical elements.`, 'Bar plots only support numbers and null values.']);
60
+ }
61
+ return 0;
62
+ }
63
+ return value;
64
+ }) : series[id].data,
49
65
  stackedData: stackedSeries[index].map(([a, b]) => [a, b])
50
66
  });
51
67
  });
@@ -59,16 +59,16 @@ function ChartsAxis(props) {
59
59
  const topId = getAxisId(topAxis);
60
60
  const rightId = getAxisId(rightAxis);
61
61
  if (topId !== null && !xAxis[topId]) {
62
- throw Error(`MUI: id used for top axis "${topId}" is not defined`);
62
+ throw Error([`MUI-X-Charts: id used for top axis "${topId}" is not defined.`, `Available ids are: ${xAxisIds.join(', ')}.`].join('\n'));
63
63
  }
64
64
  if (leftId !== null && !yAxis[leftId]) {
65
- throw Error(`MUI: id used for left axis "${leftId}" is not defined`);
65
+ throw Error([`MUI-X-Charts: id used for left axis "${leftId}" is not defined.`, `Available ids are: ${yAxisIds.join(', ')}.`].join('\n'));
66
66
  }
67
67
  if (rightId !== null && !yAxis[rightId]) {
68
- throw Error(`MUI: id used for right axis "${rightId}" is not defined`);
68
+ throw Error([`MUI-X-Charts: id used for right axis "${rightId}" is not defined.`, `Available ids are: ${yAxisIds.join(', ')}.`].join('\n'));
69
69
  }
70
70
  if (bottomId !== null && !xAxis[bottomId]) {
71
- throw Error(`MUI: id used for bottom axis "${bottomId}" is not defined`);
71
+ throw Error([`MUI-X-Charts: id used for bottom axis "${bottomId}" is not defined.`, `Available ids are: ${xAxisIds.join(', ')}.`].join('\n'));
72
72
  }
73
73
  const topAxisProps = mergeProps(topAxis, slots, slotProps);
74
74
  const bottomAxisProps = mergeProps(bottomAxis, slots, slotProps);
@@ -12,7 +12,8 @@ import { DrawingContext } from '../context/DrawingProvider';
12
12
  import { getSeriesToDisplay } from './utils';
13
13
  import { SeriesContext } from '../context/SeriesContextProvider';
14
14
  import { getLegendUtilityClass } from './chartsLegendClasses';
15
- import { ChartsText, getWordsByLines } from '../internals/components/ChartsText';
15
+ import { ChartsText } from '../ChartsText';
16
+ import { getWordsByLines } from '../internals/getWordsByLines';
16
17
  import { jsx as _jsx } from "react/jsx-runtime";
17
18
  import { jsxs as _jsxs } from "react/jsx-runtime";
18
19
  const useUtilityClasses = ownerState => {
@@ -6,10 +6,10 @@ import { ChartsYReferenceLine } from './ChartsYReferenceLine';
6
6
  import { jsx as _jsx } from "react/jsx-runtime";
7
7
  function ChartsReferenceLine(props) {
8
8
  if (props.x !== undefined && props.y !== undefined) {
9
- throw new Error('MUI-X: The ChartsReferenceLine can not have both `x` and `y` props set.');
9
+ throw new Error('MUI-X-Charts: The ChartsReferenceLine can not have both `x` and `y` props set.');
10
10
  }
11
11
  if (props.x === undefined && props.y === undefined) {
12
- throw new Error('MUI-X: The ChartsReferenceLine should have a value in `x` or `y` prop.');
12
+ throw new Error('MUI-X-Charts: The ChartsReferenceLine should have a value in `x` or `y` prop.');
13
13
  }
14
14
  if (props.x !== undefined) {
15
15
  return /*#__PURE__*/_jsx(ChartsXReferenceLine, _extends({}, props));
@@ -3,7 +3,7 @@ import * as React from 'react';
3
3
  import composeClasses from '@mui/utils/composeClasses';
4
4
  import { useDrawingArea, useXScale } from '../hooks';
5
5
  import { ReferenceLineRoot } from './common';
6
- import { ChartsText } from '../internals/components/ChartsText';
6
+ import { ChartsText } from '../ChartsText';
7
7
  import { getReferenceLineUtilityClass } from './chartsReferenceLineClasses';
8
8
  import { jsx as _jsx } from "react/jsx-runtime";
9
9
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -3,7 +3,7 @@ import * as React from 'react';
3
3
  import composeClasses from '@mui/utils/composeClasses';
4
4
  import { useDrawingArea, useYScale } from '../hooks';
5
5
  import { ReferenceLineRoot } from './common';
6
- import { ChartsText } from '../internals/components/ChartsText';
6
+ import { ChartsText } from '../ChartsText';
7
7
  import { getReferenceLineUtilityClass } from './chartsReferenceLineClasses';
8
8
  import { jsx as _jsx } from "react/jsx-runtime";
9
9
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -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:
@@ -62,10 +63,10 @@ function AreaPlot(props) {
62
63
  const xData = xAxis[xAxisKey].data;
63
64
  if (process.env.NODE_ENV !== 'production') {
64
65
  if (xData === undefined) {
65
- throw new Error(`Axis of id "${xAxisKey}" should have data property to be able to display a line plot.`);
66
+ 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.`);
66
67
  }
67
68
  if (xData.length < stackedData.length) {
68
- throw new Error(`MUI: data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items)`);
69
+ 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)`);
69
70
  }
70
71
  }
71
72
  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:
@@ -70,7 +71,7 @@ function LineHighlightPlot(props) {
70
71
  const yScale = yAxis[yAxisKey].scale;
71
72
  const xData = xAxis[xAxisKey].data;
72
73
  if (xData === undefined) {
73
- throw new Error(`Axis of id "${xAxisKey}" should have data property to be able to display a line plot.`);
74
+ 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.`);
74
75
  }
75
76
  const x = xScale(xData[highlightedIndex]);
76
77
  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:
@@ -61,10 +62,10 @@ function LinePlot(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 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:
@@ -76,7 +77,7 @@ function MarkPlot(props) {
76
77
  return true;
77
78
  };
78
79
  if (xData === undefined) {
79
- throw new Error(`Axis of id "${xAxisKey}" should have data property to be able to display a line plot`);
80
+ 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`);
80
81
  }
81
82
  return xData == null ? void 0 : xData.map((x, index) => {
82
83
  const value = data[index] == null ? null : stackedData[index][1];
@@ -2,8 +2,11 @@ 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) => {
9
+ var _ref;
7
10
  const {
8
11
  seriesOrder,
9
12
  series
@@ -11,7 +14,7 @@ const formatter = (params, dataset) => {
11
14
  const stackingGroups = getStackingGroups(params);
12
15
 
13
16
  // Create a data set with format adapted to d3
14
- const d3Dataset = dataset != null ? dataset : [];
17
+ const d3Dataset = (_ref = dataset) != null ? _ref : [];
15
18
  seriesOrder.forEach(id => {
16
19
  const data = series[id].data;
17
20
  if (data !== undefined) {
@@ -25,7 +28,7 @@ const formatter = (params, dataset) => {
25
28
  }
26
29
  });
27
30
  } 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'));
31
+ 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
32
  }
30
33
  });
31
34
  const completedSeries = {};
@@ -48,7 +51,17 @@ const formatter = (params, dataset) => {
48
51
  ids.forEach((id, index) => {
49
52
  const dataKey = series[id].dataKey;
50
53
  completedSeries[id] = _extends({}, series[id], {
51
- data: dataKey ? dataset.map(d => d[dataKey]) : series[id].data,
54
+ data: dataKey ? dataset.map(data => {
55
+ const value = data[dataKey];
56
+ if (typeof value !== 'number') {
57
+ if (process.env.NODE_ENV !== 'production' && !warnedOnce && value !== null) {
58
+ warnedOnce = true;
59
+ 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.']);
60
+ }
61
+ return null;
62
+ }
63
+ return value;
64
+ }) : series[id].data,
52
65
  stackedData: stackedSeries[index].map(([a, b]) => [a, b])
53
66
  });
54
67
  });