@mui/x-charts 6.0.0-alpha.1 → 6.0.0-alpha.2

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 (117) hide show
  1. package/BarChart/BarChart.js +1 -0
  2. package/BarChart/legend.d.ts +3 -0
  3. package/BarChart/legend.js +20 -0
  4. package/CHANGELOG.md +62 -0
  5. package/ChartsLegend/ChartsLegend.d.ts +5 -1
  6. package/ChartsLegend/ChartsLegend.js +5 -1
  7. package/ChartsLegend/utils.d.ts +1 -1
  8. package/ChartsLegend/utils.js +12 -1
  9. package/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  10. package/ChartsTooltip/ChartsItemTooltipContent.js +11 -2
  11. package/LineChart/LineChart.js +1 -0
  12. package/LineChart/legend.d.ts +3 -0
  13. package/LineChart/legend.js +20 -0
  14. package/PieChart/PieArc.d.ts +36 -0
  15. package/PieChart/PieArc.js +128 -0
  16. package/PieChart/PieArcLabel.d.ts +36 -0
  17. package/PieChart/PieArcLabel.js +113 -0
  18. package/PieChart/PieChart.d.ts +20 -0
  19. package/PieChart/PieChart.js +292 -0
  20. package/PieChart/PiePlot.d.ts +2 -0
  21. package/PieChart/PiePlot.js +98 -0
  22. package/PieChart/formatter.d.ts +3 -0
  23. package/PieChart/formatter.js +49 -0
  24. package/PieChart/index.d.ts +4 -0
  25. package/PieChart/index.js +47 -0
  26. package/PieChart/legend.d.ts +3 -0
  27. package/PieChart/legend.js +19 -0
  28. package/PieChart/package.json +6 -0
  29. package/README.md +2 -2
  30. package/ResponsiveChartContainer/index.js +14 -3
  31. package/ScatterChart/Scatter.js +1 -1
  32. package/ScatterChart/ScatterChart.js +1 -0
  33. package/ScatterChart/legend.d.ts +3 -0
  34. package/ScatterChart/legend.js +20 -0
  35. package/context/SeriesContextProvider.js +11 -1
  36. package/esm/BarChart/BarChart.js +1 -0
  37. package/esm/BarChart/legend.js +13 -0
  38. package/esm/ChartsLegend/ChartsLegend.js +5 -1
  39. package/esm/ChartsLegend/utils.js +11 -1
  40. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  41. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +11 -3
  42. package/esm/LineChart/LineChart.js +1 -0
  43. package/esm/LineChart/legend.js +13 -0
  44. package/esm/PieChart/PieArc.js +117 -0
  45. package/esm/PieChart/PieArcLabel.js +101 -0
  46. package/esm/PieChart/PieChart.js +285 -0
  47. package/esm/PieChart/PiePlot.js +92 -0
  48. package/esm/PieChart/formatter.js +48 -0
  49. package/esm/PieChart/index.js +4 -0
  50. package/esm/PieChart/legend.js +12 -0
  51. package/esm/ResponsiveChartContainer/index.js +14 -3
  52. package/esm/ScatterChart/Scatter.js +1 -1
  53. package/esm/ScatterChart/ScatterChart.js +1 -0
  54. package/esm/ScatterChart/legend.js +13 -0
  55. package/esm/context/SeriesContextProvider.js +11 -1
  56. package/esm/index.js +1 -0
  57. package/esm/internals/defaultizeColor.js +7 -0
  58. package/esm/models/seriesType/index.js +1 -8
  59. package/index.d.ts +1 -0
  60. package/index.js +12 -1
  61. package/internals/defaultizeColor.d.ts +35 -0
  62. package/internals/defaultizeColor.js +7 -0
  63. package/legacy/BarChart/BarChart.js +1 -0
  64. package/legacy/BarChart/legend.js +15 -0
  65. package/legacy/ChartsLegend/ChartsLegend.js +5 -1
  66. package/legacy/ChartsLegend/utils.js +12 -6
  67. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +3 -1
  68. package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +10 -3
  69. package/legacy/LineChart/LineChart.js +1 -0
  70. package/legacy/LineChart/legend.js +15 -0
  71. package/legacy/PieChart/PieArc.js +118 -0
  72. package/legacy/PieChart/PieArcLabel.js +101 -0
  73. package/legacy/PieChart/PieChart.js +297 -0
  74. package/legacy/PieChart/PiePlot.js +89 -0
  75. package/legacy/PieChart/formatter.js +55 -0
  76. package/legacy/PieChart/index.js +4 -0
  77. package/legacy/PieChart/legend.js +16 -0
  78. package/legacy/ResponsiveChartContainer/index.js +12 -3
  79. package/legacy/ScatterChart/Scatter.js +1 -1
  80. package/legacy/ScatterChart/ScatterChart.js +1 -0
  81. package/legacy/ScatterChart/legend.js +15 -0
  82. package/legacy/context/SeriesContextProvider.js +11 -1
  83. package/legacy/index.js +2 -1
  84. package/legacy/internals/defaultizeColor.js +9 -0
  85. package/legacy/models/seriesType/index.js +1 -8
  86. package/models/seriesType/bar.d.ts +1 -1
  87. package/models/seriesType/common.d.ts +1 -1
  88. package/models/seriesType/config.d.ts +29 -2
  89. package/models/seriesType/index.d.ts +7 -3
  90. package/models/seriesType/index.js +11 -0
  91. package/models/seriesType/line.d.ts +1 -1
  92. package/models/seriesType/pie.d.ts +103 -3
  93. package/models/seriesType/scatter.d.ts +1 -1
  94. package/modern/BarChart/BarChart.js +1 -0
  95. package/modern/BarChart/legend.js +13 -0
  96. package/modern/ChartsLegend/ChartsLegend.js +5 -1
  97. package/modern/ChartsLegend/utils.js +11 -1
  98. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  99. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +11 -2
  100. package/modern/LineChart/LineChart.js +1 -0
  101. package/modern/LineChart/legend.js +13 -0
  102. package/modern/PieChart/PieArc.js +116 -0
  103. package/modern/PieChart/PieArcLabel.js +101 -0
  104. package/modern/PieChart/PieChart.js +285 -0
  105. package/modern/PieChart/PiePlot.js +91 -0
  106. package/modern/PieChart/formatter.js +41 -0
  107. package/modern/PieChart/index.js +4 -0
  108. package/modern/PieChart/legend.js +12 -0
  109. package/modern/ResponsiveChartContainer/index.js +14 -3
  110. package/modern/ScatterChart/Scatter.js +1 -1
  111. package/modern/ScatterChart/ScatterChart.js +1 -0
  112. package/modern/ScatterChart/legend.js +13 -0
  113. package/modern/context/SeriesContextProvider.js +11 -1
  114. package/modern/index.js +2 -1
  115. package/modern/internals/defaultizeColor.js +7 -0
  116. package/modern/models/seriesType/index.js +1 -8
  117. package/package.json +1 -1
@@ -0,0 +1,285 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import * as React from 'react';
3
+ import PropTypes from 'prop-types';
4
+ import { ResponsiveChartContainer } from '../ResponsiveChartContainer';
5
+ import { ChartsAxis } from '../ChartsAxis/ChartsAxis';
6
+ import { DEFAULT_X_AXIS_KEY } from '../constants';
7
+ import { ChartsTooltip } from '../ChartsTooltip';
8
+ import { ChartsLegend } from '../ChartsLegend';
9
+ import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
10
+ import { PiePlot } from './PiePlot';
11
+ import { jsx as _jsx } from "react/jsx-runtime";
12
+ import { jsxs as _jsxs } from "react/jsx-runtime";
13
+ const defaultMargin = {
14
+ top: 5,
15
+ bottom: 5,
16
+ left: 5,
17
+ right: 100
18
+ };
19
+ function PieChart(props) {
20
+ const {
21
+ xAxis,
22
+ yAxis,
23
+ series,
24
+ width,
25
+ height,
26
+ margin: marginProps,
27
+ colors,
28
+ sx,
29
+ tooltip = {
30
+ trigger: 'item'
31
+ },
32
+ axisHighlight = {
33
+ x: 'none',
34
+ y: 'none'
35
+ },
36
+ legend = {
37
+ direction: 'column',
38
+ position: {
39
+ vertical: 'middle',
40
+ horizontal: 'right'
41
+ }
42
+ },
43
+ topAxis = null,
44
+ leftAxis = null,
45
+ rightAxis = null,
46
+ bottomAxis = null,
47
+ children
48
+ } = props;
49
+ const margin = _extends({}, defaultMargin, marginProps);
50
+ return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
51
+ series: series.map(s => _extends({
52
+ type: 'pie'
53
+ }, s)),
54
+ width: width,
55
+ height: height,
56
+ margin: margin,
57
+ xAxis: xAxis ?? [{
58
+ id: DEFAULT_X_AXIS_KEY,
59
+ scaleType: 'point',
60
+ data: [...new Array(Math.max(...series.map(s => s.data.length)))].map((_, index) => index)
61
+ }],
62
+ yAxis: yAxis,
63
+ colors: colors,
64
+ sx: sx,
65
+ disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none',
66
+ children: [/*#__PURE__*/_jsx(ChartsAxis, {
67
+ topAxis: topAxis,
68
+ leftAxis: leftAxis,
69
+ rightAxis: rightAxis,
70
+ bottomAxis: bottomAxis
71
+ }), /*#__PURE__*/_jsx(PiePlot, {}), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legend)), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlight)), /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip)), children]
72
+ });
73
+ }
74
+ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
75
+ // ----------------------------- Warning --------------------------------
76
+ // | These PropTypes are generated from the TypeScript type definitions |
77
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
78
+ // ----------------------------------------------------------------------
79
+ axisHighlight: PropTypes.shape({
80
+ x: PropTypes.oneOf(['band', 'line', 'none']),
81
+ y: PropTypes.oneOf(['line', 'none'])
82
+ }),
83
+ /**
84
+ * Indicate which axis to display the bottom of the charts.
85
+ * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
86
+ * @default xAxisIds[0] The id of the first provided axis
87
+ */
88
+ bottomAxis: PropTypes.oneOfType([PropTypes.shape({
89
+ axisId: PropTypes.string.isRequired,
90
+ classes: PropTypes.object,
91
+ disableLine: PropTypes.bool,
92
+ disableTicks: PropTypes.bool,
93
+ fill: PropTypes.string,
94
+ label: PropTypes.string,
95
+ labelFontSize: PropTypes.number,
96
+ position: PropTypes.oneOf(['bottom', 'top']),
97
+ stroke: PropTypes.string,
98
+ tickFontSize: PropTypes.number,
99
+ tickSize: PropTypes.number
100
+ }), PropTypes.string]),
101
+ children: PropTypes.node,
102
+ className: PropTypes.string,
103
+ /**
104
+ * Color palette used to colorize multiple series.
105
+ */
106
+ colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
107
+ desc: PropTypes.string,
108
+ disableAxisListener: PropTypes.bool,
109
+ height: PropTypes.number,
110
+ /**
111
+ * Indicate which axis to display the left of the charts.
112
+ * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
113
+ * @default yAxisIds[0] The id of the first provided axis
114
+ */
115
+ leftAxis: PropTypes.oneOfType([PropTypes.shape({
116
+ axisId: PropTypes.string.isRequired,
117
+ classes: PropTypes.object,
118
+ disableLine: PropTypes.bool,
119
+ disableTicks: PropTypes.bool,
120
+ fill: PropTypes.string,
121
+ label: PropTypes.string,
122
+ labelFontSize: PropTypes.number,
123
+ position: PropTypes.oneOf(['left', 'right']),
124
+ stroke: PropTypes.string,
125
+ tickFontSize: PropTypes.number,
126
+ tickSize: PropTypes.number
127
+ }), PropTypes.string]),
128
+ legend: PropTypes.shape({
129
+ classes: PropTypes.object,
130
+ direction: PropTypes.oneOf(['column', 'row']),
131
+ hidden: PropTypes.bool,
132
+ itemWidth: PropTypes.number,
133
+ markSize: PropTypes.number,
134
+ offset: PropTypes.shape({
135
+ x: PropTypes.number,
136
+ y: PropTypes.number
137
+ }),
138
+ position: PropTypes.shape({
139
+ horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
140
+ vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
141
+ }),
142
+ spacing: PropTypes.number
143
+ }),
144
+ margin: PropTypes.shape({
145
+ bottom: PropTypes.number,
146
+ left: PropTypes.number,
147
+ right: PropTypes.number,
148
+ top: PropTypes.number
149
+ }),
150
+ /**
151
+ * Indicate which axis to display the right of the charts.
152
+ * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
153
+ * @default null
154
+ */
155
+ rightAxis: PropTypes.oneOfType([PropTypes.shape({
156
+ axisId: PropTypes.string.isRequired,
157
+ classes: PropTypes.object,
158
+ disableLine: PropTypes.bool,
159
+ disableTicks: PropTypes.bool,
160
+ fill: PropTypes.string,
161
+ label: PropTypes.string,
162
+ labelFontSize: PropTypes.number,
163
+ position: PropTypes.oneOf(['left', 'right']),
164
+ stroke: PropTypes.string,
165
+ tickFontSize: PropTypes.number,
166
+ tickSize: PropTypes.number
167
+ }), PropTypes.string]),
168
+ series: PropTypes.arrayOf(PropTypes.shape({
169
+ arcLabel: PropTypes.oneOfType([PropTypes.oneOf(['formattedValue', 'label', 'value']), PropTypes.func]),
170
+ arcLabelMinAngle: PropTypes.number,
171
+ color: PropTypes.string,
172
+ cornerRadius: PropTypes.number,
173
+ cx: PropTypes.number,
174
+ cy: PropTypes.number,
175
+ data: PropTypes.arrayOf(PropTypes.shape({
176
+ color: PropTypes.string,
177
+ id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
178
+ label: PropTypes.string,
179
+ value: PropTypes.number.isRequired
180
+ })).isRequired,
181
+ endAngle: PropTypes.number,
182
+ faded: PropTypes.shape({
183
+ additionalRadius: PropTypes.number,
184
+ cornerRadius: PropTypes.number,
185
+ innerRadius: PropTypes.number,
186
+ outerRadius: PropTypes.number
187
+ }),
188
+ highlighted: PropTypes.shape({
189
+ additionalRadius: PropTypes.number,
190
+ cornerRadius: PropTypes.number,
191
+ innerRadius: PropTypes.number,
192
+ outerRadius: PropTypes.number
193
+ }),
194
+ highlightScope: PropTypes.shape({
195
+ faded: PropTypes.oneOf(['global', 'none', 'series']),
196
+ highlighted: PropTypes.oneOf(['item', 'none', 'series'])
197
+ }),
198
+ id: PropTypes.string,
199
+ innerRadius: PropTypes.number,
200
+ outerRadius: PropTypes.number,
201
+ paddingAngle: PropTypes.number,
202
+ sortingValues: PropTypes.oneOfType([PropTypes.oneOf(['asc', 'desc', 'none']), PropTypes.func]),
203
+ startAngle: PropTypes.number,
204
+ type: PropTypes.oneOf(['pie']),
205
+ valueFormatter: PropTypes.func
206
+ })).isRequired,
207
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
208
+ title: PropTypes.string,
209
+ tooltip: PropTypes.shape({
210
+ axisContent: PropTypes.elementType,
211
+ classes: PropTypes.object,
212
+ itemContent: PropTypes.elementType,
213
+ trigger: PropTypes.oneOf(['axis', 'item', 'none'])
214
+ }),
215
+ /**
216
+ * Indicate which axis to display the top of the charts.
217
+ * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
218
+ * @default null
219
+ */
220
+ topAxis: PropTypes.oneOfType([PropTypes.shape({
221
+ axisId: PropTypes.string.isRequired,
222
+ classes: PropTypes.object,
223
+ disableLine: PropTypes.bool,
224
+ disableTicks: PropTypes.bool,
225
+ fill: PropTypes.string,
226
+ label: PropTypes.string,
227
+ labelFontSize: PropTypes.number,
228
+ position: PropTypes.oneOf(['bottom', 'top']),
229
+ stroke: PropTypes.string,
230
+ tickFontSize: PropTypes.number,
231
+ tickSize: PropTypes.number
232
+ }), PropTypes.string]),
233
+ viewBox: PropTypes.shape({
234
+ height: PropTypes.number,
235
+ width: PropTypes.number,
236
+ x: PropTypes.number,
237
+ y: PropTypes.number
238
+ }),
239
+ width: PropTypes.number,
240
+ xAxis: PropTypes.arrayOf(PropTypes.shape({
241
+ axisId: PropTypes.string,
242
+ classes: PropTypes.object,
243
+ data: PropTypes.array,
244
+ disableLine: PropTypes.bool,
245
+ disableTicks: PropTypes.bool,
246
+ fill: PropTypes.string,
247
+ id: PropTypes.string,
248
+ label: PropTypes.string,
249
+ labelFontSize: PropTypes.number,
250
+ max: PropTypes.number,
251
+ maxTicks: PropTypes.number,
252
+ min: PropTypes.number,
253
+ minTicks: PropTypes.number,
254
+ position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
255
+ scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
256
+ stroke: PropTypes.string,
257
+ tickFontSize: PropTypes.number,
258
+ tickSize: PropTypes.number,
259
+ tickSpacing: PropTypes.number,
260
+ valueFormatter: PropTypes.func
261
+ })),
262
+ yAxis: PropTypes.arrayOf(PropTypes.shape({
263
+ axisId: PropTypes.string,
264
+ classes: PropTypes.object,
265
+ data: PropTypes.array,
266
+ disableLine: PropTypes.bool,
267
+ disableTicks: PropTypes.bool,
268
+ fill: PropTypes.string,
269
+ id: PropTypes.string,
270
+ label: PropTypes.string,
271
+ labelFontSize: PropTypes.number,
272
+ max: PropTypes.number,
273
+ maxTicks: PropTypes.number,
274
+ min: PropTypes.number,
275
+ minTicks: PropTypes.number,
276
+ position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
277
+ scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
278
+ stroke: PropTypes.string,
279
+ tickFontSize: PropTypes.number,
280
+ tickSize: PropTypes.number,
281
+ tickSpacing: PropTypes.number,
282
+ valueFormatter: PropTypes.func
283
+ }))
284
+ } : void 0;
285
+ export { PieChart };
@@ -0,0 +1,91 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import * as React from 'react';
3
+ import { SeriesContext } from '../context/SeriesContextProvider';
4
+ import PieArc from './PieArc';
5
+ import PieArcLabel from './PieArcLabel';
6
+ import { DrawingContext } from '../context/DrawingProvider';
7
+ import { createElement as _createElement } from "react";
8
+ import { jsxs as _jsxs } from "react/jsx-runtime";
9
+ import { jsx as _jsx } from "react/jsx-runtime";
10
+ const RATIO = 180 / Math.PI;
11
+ function getItemLabel(arcLabel, arcLabelMinAngle, item) {
12
+ if (!arcLabel) {
13
+ return null;
14
+ }
15
+ const angle = (item.endAngle - item.startAngle) * RATIO;
16
+ if (angle < arcLabelMinAngle) {
17
+ return null;
18
+ }
19
+ if (typeof arcLabel === 'string') {
20
+ return item[arcLabel]?.toString();
21
+ }
22
+ return arcLabel(item);
23
+ }
24
+ export function PiePlot() {
25
+ const seriesData = React.useContext(SeriesContext).pie;
26
+ const {
27
+ left,
28
+ top,
29
+ width,
30
+ height
31
+ } = React.useContext(DrawingContext);
32
+ if (seriesData === undefined) {
33
+ return null;
34
+ }
35
+ const availableRadius = Math.min(width, height) / 2;
36
+ const center = {
37
+ x: left + width / 2,
38
+ y: top + height / 2
39
+ };
40
+ const {
41
+ series,
42
+ seriesOrder
43
+ } = seriesData;
44
+ return /*#__PURE__*/_jsx("g", {
45
+ children: seriesOrder.map(seriesId => {
46
+ const {
47
+ innerRadius,
48
+ outerRadius,
49
+ cornerRadius,
50
+ arcLabel,
51
+ arcLabelMinAngle = 0,
52
+ data,
53
+ cx,
54
+ cy,
55
+ highlighted,
56
+ faded
57
+ } = series[seriesId];
58
+ return /*#__PURE__*/_jsx("g", {
59
+ transform: `translate(${cx === undefined ? center.x : left + cx}, ${cy === undefined ? center.y : top + cy})`,
60
+ children: /*#__PURE__*/_jsxs("g", {
61
+ children: [data.map((item, index) => {
62
+ return /*#__PURE__*/_createElement(PieArc, _extends({}, item, {
63
+ key: item.id,
64
+ innerRadius: innerRadius,
65
+ outerRadius: outerRadius ?? availableRadius,
66
+ cornerRadius: cornerRadius,
67
+ id: seriesId,
68
+ color: item.color,
69
+ dataIndex: index,
70
+ highlightScope: series[seriesId].highlightScope,
71
+ highlighted: highlighted,
72
+ faded: faded
73
+ }));
74
+ }), data.map((item, index) => {
75
+ return /*#__PURE__*/_createElement(PieArcLabel, _extends({}, item, {
76
+ key: item.id,
77
+ innerRadius: innerRadius,
78
+ outerRadius: outerRadius ?? availableRadius,
79
+ cornerRadius: cornerRadius,
80
+ id: seriesId,
81
+ color: item.color,
82
+ dataIndex: index,
83
+ highlightScope: series[seriesId].highlightScope,
84
+ formattedArcLabel: getItemLabel(arcLabel, arcLabelMinAngle, item)
85
+ }));
86
+ })]
87
+ })
88
+ }, seriesId);
89
+ })
90
+ });
91
+ }
@@ -0,0 +1,41 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import { pie as d3Pie } from 'd3-shape';
3
+ const getSortingComparator = (comparator = 'none') => {
4
+ if (typeof comparator === 'function') {
5
+ return comparator;
6
+ }
7
+ switch (comparator) {
8
+ case 'none':
9
+ return null;
10
+ case 'desc':
11
+ return (a, b) => b - a;
12
+ case 'asc':
13
+ return (a, b) => a - b;
14
+ default:
15
+ return null;
16
+ }
17
+ };
18
+ const formatter = params => {
19
+ const {
20
+ seriesOrder,
21
+ series
22
+ } = params;
23
+ const defaultizedSeries = {};
24
+ seriesOrder.forEach(seriesId => {
25
+ const arcs = d3Pie().startAngle(2 * Math.PI * (series[seriesId].startAngle ?? 0) / 360).endAngle(2 * Math.PI * (series[seriesId].endAngle ?? 360) / 360).padAngle(2 * Math.PI * (series[seriesId].paddingAngle ?? 0) / 360).sortValues(getSortingComparator(series[seriesId].sortingValues ?? 'none'))(series[seriesId].data.map(piePoint => piePoint.value));
26
+ defaultizedSeries[seriesId] = _extends({
27
+ valueFormatter: item => item.value.toLocaleString()
28
+ }, series[seriesId], {
29
+ data: series[seriesId].data.map((item, index) => _extends({}, item, {
30
+ id: item.id ?? `auto-generated-pie-id-${seriesId}-${index}`
31
+ }, arcs[index])).map(item => _extends({}, item, {
32
+ formattedValue: series[seriesId].valueFormatter?.(item) ?? item.value.toLocaleString()
33
+ }))
34
+ });
35
+ });
36
+ return {
37
+ seriesOrder,
38
+ series: defaultizedSeries
39
+ };
40
+ };
41
+ export default formatter;
@@ -0,0 +1,4 @@
1
+ export { PiePlot } from './PiePlot';
2
+ export { PieChart } from './PieChart';
3
+ export * from './PieArc';
4
+ export * from './PieArcLabel';
@@ -0,0 +1,12 @@
1
+ const legendGetter = params => {
2
+ const {
3
+ seriesOrder,
4
+ series
5
+ } = params;
6
+ return seriesOrder.flatMap(seriesId => series[seriesId].data.map(item => ({
7
+ color: item.color,
8
+ label: item.label,
9
+ id: item.id
10
+ })).filter(item => item.label !== undefined));
11
+ };
12
+ export default legendGetter;
@@ -1,4 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
+ const _excluded = ["width", "height"];
2
4
  import * as React from 'react';
3
5
  import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
4
6
  import ownerWindow from '@mui/utils/ownerWindow';
@@ -82,17 +84,26 @@ const ResizableContainer = styled('div', {
82
84
  flexDirection: 'column',
83
85
  alignItems: 'center',
84
86
  justifyContent: 'center',
85
- overflow: 'hidden'
87
+ overflow: 'hidden',
88
+ '&>svg': {
89
+ width: '100%',
90
+ height: '100%'
91
+ }
86
92
  }));
87
93
  export function ResponsiveChartContainer(props) {
88
- const [containerRef, width, height] = useChartDimensions(props.width, props.height);
94
+ const {
95
+ width: propsWidth,
96
+ height: propsHeight
97
+ } = props,
98
+ other = _objectWithoutPropertiesLoose(props, _excluded);
99
+ const [containerRef, width, height] = useChartDimensions(propsWidth, propsHeight);
89
100
  return /*#__PURE__*/_jsx(ResizableContainer, {
90
101
  ref: containerRef,
91
102
  ownerState: {
92
103
  width: props.width,
93
104
  height: props.height
94
105
  },
95
- children: /*#__PURE__*/_jsx(ChartContainer, _extends({}, props, {
106
+ children: /*#__PURE__*/_jsx(ChartContainer, _extends({}, other, {
96
107
  width: width,
97
108
  height: height
98
109
  }))
@@ -82,7 +82,7 @@ process.env.NODE_ENV !== "production" ? Scatter.propTypes = {
82
82
  color: PropTypes.string.isRequired,
83
83
  markerSize: PropTypes.number.isRequired,
84
84
  series: PropTypes.shape({
85
- color: PropTypes.string.isRequired,
85
+ color: PropTypes.string,
86
86
  data: PropTypes.arrayOf(PropTypes.shape({
87
87
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
88
88
  x: PropTypes.number.isRequired,
@@ -109,6 +109,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
109
109
  legend: PropTypes.shape({
110
110
  classes: PropTypes.object,
111
111
  direction: PropTypes.oneOf(['column', 'row']),
112
+ hidden: PropTypes.bool,
112
113
  itemWidth: PropTypes.number,
113
114
  markSize: PropTypes.number,
114
115
  offset: PropTypes.shape({
@@ -0,0 +1,13 @@
1
+ const legendGetter = params => {
2
+ const {
3
+ seriesOrder,
4
+ series
5
+ } = params;
6
+ const data = seriesOrder.map(seriesId => ({
7
+ color: series[seriesId].color,
8
+ label: series[seriesId].label,
9
+ id: seriesId
10
+ }));
11
+ return data.filter(item => item.label !== undefined);
12
+ };
13
+ export default legendGetter;
@@ -4,6 +4,7 @@ import { useTheme } from '@mui/material/styles';
4
4
  import barSeriesFormatter from '../BarChart/formatter';
5
5
  import scatterSeriesFormatter from '../ScatterChart/formatter';
6
6
  import lineSeriesFormatter from '../LineChart/formatter';
7
+ import pieSeriesFormatter from '../PieChart/formatter';
7
8
  import { defaultizeColor } from '../internals/defaultizeColor';
8
9
  import { blueberryTwilightPalette } from '../colorPalettes';
9
10
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -11,8 +12,17 @@ export const SeriesContext = /*#__PURE__*/React.createContext({});
11
12
  const seriesTypeFormatter = {
12
13
  bar: barSeriesFormatter,
13
14
  scatter: scatterSeriesFormatter,
14
- line: lineSeriesFormatter
15
+ line: lineSeriesFormatter,
16
+ pie: pieSeriesFormatter
15
17
  };
18
+ /**
19
+ * This methods is the interface between what the developper is providing and what compoenents receives
20
+ * To simplify the components behaviors, it groups series by type, such that LinePlots props are not updated if soe line data are modified
21
+ * It also add defaultized values such as the ids, colors
22
+ * @param series The array of series provided by devs
23
+ * @param colors The color palette used to defaultize series colors
24
+ * @returns An object structuring all the series by type.
25
+ */
16
26
  const formatSeries = (series, colors) => {
17
27
  // Group series by type
18
28
  const seriesGroups = {};
package/modern/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v6.0.0-alpha.1
2
+ * @mui/x-charts v6.0.0-alpha.2
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -17,6 +17,7 @@ export * from './ChartsTooltip';
17
17
  export * from './ChartsAxisHighlight';
18
18
  export * from './BarChart';
19
19
  export * from './LineChart';
20
+ export * from './PieChart';
20
21
  export * from './ScatterChart';
21
22
  export * from './ChartContainer';
22
23
  export * from './ResponsiveChartContainer';
@@ -1,6 +1,13 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  const DEFAULT_COLORS = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf'];
3
3
  export function defaultizeColor(series, seriesIndex, colors = DEFAULT_COLORS) {
4
+ if (series.type === 'pie') {
5
+ return _extends({}, series, {
6
+ data: series.data.map((d, index) => _extends({
7
+ color: colors[index % colors.length]
8
+ }, d))
9
+ });
10
+ }
4
11
  return _extends({
5
12
  color: colors[seriesIndex % colors.length]
6
13
  }, series);
@@ -1,12 +1,5 @@
1
- // import { PieSeriesType } from './pie';
2
-
3
- // | PieSeriesType;
4
-
5
- // | PieSeriesType;
6
-
7
- // | PieSeriesType
8
-
9
1
  export * from './line';
10
2
  export * from './bar';
11
3
  export * from './scatter';
4
+ export * from './pie';
12
5
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-charts",
3
- "version": "6.0.0-alpha.1",
3
+ "version": "6.0.0-alpha.2",
4
4
  "description": "The community edition of the charts components (MUI X).",
5
5
  "author": "MUI Team",
6
6
  "main": "./index.js",