@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,101 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
+ var _excluded = ["id", "dataIndex", "classes", "color", "highlightScope", "innerRadius", "outerRadius", "cornerRadius", "formattedArcLabel"];
4
+ import * as React from 'react';
5
+ import { arc as d3Arc } from 'd3-shape';
6
+ import PropTypes from 'prop-types';
7
+ import composeClasses from '@mui/utils/composeClasses';
8
+ import generateUtilityClass from '@mui/utils/generateUtilityClass';
9
+ import { styled } from '@mui/material/styles';
10
+ import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
11
+ import { InteractionContext } from '../context/InteractionProvider';
12
+ import { getIsFaded, getIsHighlighted } from '../hooks/useInteractionItemProps';
13
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ export function getPieArcLabelUtilityClass(slot) {
15
+ return generateUtilityClass('MuiPieArcLabel', slot);
16
+ }
17
+ export var pieArcLabelClasses = generateUtilityClasses('MuiPieArcLabel', ['root', 'highlighted', 'faded']);
18
+ var useUtilityClasses = function useUtilityClasses(ownerState) {
19
+ var classes = ownerState.classes,
20
+ id = ownerState.id,
21
+ isFaded = ownerState.isFaded,
22
+ isHighlighted = ownerState.isHighlighted;
23
+ var slots = {
24
+ root: ['root', "series-".concat(id), isHighlighted && 'highlighted', isFaded && 'faded']
25
+ };
26
+ return composeClasses(slots, getPieArcLabelUtilityClass, classes);
27
+ };
28
+ var PieArcLabelRoot = styled('text', {
29
+ name: 'MuiPieArcLabel',
30
+ slot: 'Root',
31
+ overridesResolver: function overridesResolver(_, styles) {
32
+ return styles.root;
33
+ }
34
+ })(function (_ref) {
35
+ var theme = _ref.theme;
36
+ return {
37
+ fill: theme.palette.text.primary,
38
+ alignmentBaseline: 'baseline',
39
+ textAnchor: 'middle'
40
+ };
41
+ });
42
+ export default function PieArcLabel(props) {
43
+ var id = props.id,
44
+ dataIndex = props.dataIndex,
45
+ innerClasses = props.classes,
46
+ color = props.color,
47
+ highlightScope = props.highlightScope,
48
+ _props$innerRadius = props.innerRadius,
49
+ innerRadius = _props$innerRadius === void 0 ? 0 : _props$innerRadius,
50
+ outerRadius = props.outerRadius,
51
+ _props$cornerRadius = props.cornerRadius,
52
+ cornerRadius = _props$cornerRadius === void 0 ? 0 : _props$cornerRadius,
53
+ formattedArcLabel = props.formattedArcLabel,
54
+ other = _objectWithoutProperties(props, _excluded);
55
+ var _React$useContext = React.useContext(InteractionContext),
56
+ item = _React$useContext.item;
57
+ var isHighlighted = getIsHighlighted(item, {
58
+ type: 'pie',
59
+ seriesId: id,
60
+ dataIndex: dataIndex
61
+ }, highlightScope);
62
+ var isFaded = !isHighlighted && getIsFaded(item, {
63
+ type: 'pie',
64
+ seriesId: id,
65
+ dataIndex: dataIndex
66
+ }, highlightScope);
67
+ var ownerState = {
68
+ id: id,
69
+ dataIndex: dataIndex,
70
+ classes: innerClasses,
71
+ color: color,
72
+ isFaded: isFaded,
73
+ isHighlighted: isHighlighted
74
+ };
75
+ var classes = useUtilityClasses(ownerState);
76
+ var arcLabelPosition = formattedArcLabel ? d3Arc().cornerRadius(cornerRadius).centroid(_extends({}, other, {
77
+ innerRadius: innerRadius,
78
+ outerRadius: outerRadius
79
+ })) : [0, 0];
80
+ return /*#__PURE__*/_jsx(PieArcLabelRoot, {
81
+ className: classes.root,
82
+ x: arcLabelPosition[0],
83
+ y: arcLabelPosition[1],
84
+ children: formattedArcLabel
85
+ });
86
+ }
87
+ process.env.NODE_ENV !== "production" ? PieArcLabel.propTypes = {
88
+ // ----------------------------- Warning --------------------------------
89
+ // | These PropTypes are generated from the TypeScript type definitions |
90
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
91
+ // ----------------------------------------------------------------------
92
+ classes: PropTypes.object,
93
+ cornerRadius: PropTypes.number,
94
+ dataIndex: PropTypes.number.isRequired,
95
+ highlightScope: PropTypes.shape({
96
+ faded: PropTypes.oneOf(['global', 'none', 'series']),
97
+ highlighted: PropTypes.oneOf(['item', 'none', 'series'])
98
+ }),
99
+ innerRadius: PropTypes.number,
100
+ outerRadius: PropTypes.number.isRequired
101
+ } : void 0;
@@ -0,0 +1,297 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
+ import _extends from "@babel/runtime/helpers/esm/extends";
3
+ import * as React from 'react';
4
+ import PropTypes from 'prop-types';
5
+ import { ResponsiveChartContainer } from '../ResponsiveChartContainer';
6
+ import { ChartsAxis } from '../ChartsAxis/ChartsAxis';
7
+ import { DEFAULT_X_AXIS_KEY } from '../constants';
8
+ import { ChartsTooltip } from '../ChartsTooltip';
9
+ import { ChartsLegend } from '../ChartsLegend';
10
+ import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
11
+ import { PiePlot } from './PiePlot';
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { jsxs as _jsxs } from "react/jsx-runtime";
14
+ var defaultMargin = {
15
+ top: 5,
16
+ bottom: 5,
17
+ left: 5,
18
+ right: 100
19
+ };
20
+ function PieChart(props) {
21
+ var xAxis = props.xAxis,
22
+ yAxis = props.yAxis,
23
+ series = props.series,
24
+ width = props.width,
25
+ height = props.height,
26
+ marginProps = props.margin,
27
+ colors = props.colors,
28
+ sx = props.sx,
29
+ _props$tooltip = props.tooltip,
30
+ tooltip = _props$tooltip === void 0 ? {
31
+ trigger: 'item'
32
+ } : _props$tooltip,
33
+ _props$axisHighlight = props.axisHighlight,
34
+ axisHighlight = _props$axisHighlight === void 0 ? {
35
+ x: 'none',
36
+ y: 'none'
37
+ } : _props$axisHighlight,
38
+ _props$legend = props.legend,
39
+ legend = _props$legend === void 0 ? {
40
+ direction: 'column',
41
+ position: {
42
+ vertical: 'middle',
43
+ horizontal: 'right'
44
+ }
45
+ } : _props$legend,
46
+ _props$topAxis = props.topAxis,
47
+ topAxis = _props$topAxis === void 0 ? null : _props$topAxis,
48
+ _props$leftAxis = props.leftAxis,
49
+ leftAxis = _props$leftAxis === void 0 ? null : _props$leftAxis,
50
+ _props$rightAxis = props.rightAxis,
51
+ rightAxis = _props$rightAxis === void 0 ? null : _props$rightAxis,
52
+ _props$bottomAxis = props.bottomAxis,
53
+ bottomAxis = _props$bottomAxis === void 0 ? null : _props$bottomAxis,
54
+ children = props.children;
55
+ var margin = _extends({}, defaultMargin, marginProps);
56
+ return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
57
+ series: series.map(function (s) {
58
+ return _extends({
59
+ type: 'pie'
60
+ }, s);
61
+ }),
62
+ width: width,
63
+ height: height,
64
+ margin: margin,
65
+ xAxis: xAxis != null ? xAxis : [{
66
+ id: DEFAULT_X_AXIS_KEY,
67
+ scaleType: 'point',
68
+ data: _toConsumableArray(new Array(Math.max.apply(Math, _toConsumableArray(series.map(function (s) {
69
+ return s.data.length;
70
+ }))))).map(function (_, index) {
71
+ return index;
72
+ })
73
+ }],
74
+ yAxis: yAxis,
75
+ colors: colors,
76
+ sx: sx,
77
+ disableAxisListener: (tooltip == null ? void 0 : tooltip.trigger) !== 'axis' && (axisHighlight == null ? void 0 : axisHighlight.x) === 'none' && (axisHighlight == null ? void 0 : axisHighlight.y) === 'none',
78
+ children: [/*#__PURE__*/_jsx(ChartsAxis, {
79
+ topAxis: topAxis,
80
+ leftAxis: leftAxis,
81
+ rightAxis: rightAxis,
82
+ bottomAxis: bottomAxis
83
+ }), /*#__PURE__*/_jsx(PiePlot, {}), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legend)), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlight)), /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip)), children]
84
+ });
85
+ }
86
+ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
87
+ // ----------------------------- Warning --------------------------------
88
+ // | These PropTypes are generated from the TypeScript type definitions |
89
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
90
+ // ----------------------------------------------------------------------
91
+ axisHighlight: PropTypes.shape({
92
+ x: PropTypes.oneOf(['band', 'line', 'none']),
93
+ y: PropTypes.oneOf(['line', 'none'])
94
+ }),
95
+ /**
96
+ * Indicate which axis to display the bottom of the charts.
97
+ * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
98
+ * @default xAxisIds[0] The id of the first provided axis
99
+ */
100
+ bottomAxis: PropTypes.oneOfType([PropTypes.shape({
101
+ axisId: PropTypes.string.isRequired,
102
+ classes: PropTypes.object,
103
+ disableLine: PropTypes.bool,
104
+ disableTicks: PropTypes.bool,
105
+ fill: PropTypes.string,
106
+ label: PropTypes.string,
107
+ labelFontSize: PropTypes.number,
108
+ position: PropTypes.oneOf(['bottom', 'top']),
109
+ stroke: PropTypes.string,
110
+ tickFontSize: PropTypes.number,
111
+ tickSize: PropTypes.number
112
+ }), PropTypes.string]),
113
+ children: PropTypes.node,
114
+ className: PropTypes.string,
115
+ /**
116
+ * Color palette used to colorize multiple series.
117
+ */
118
+ colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
119
+ desc: PropTypes.string,
120
+ disableAxisListener: PropTypes.bool,
121
+ height: PropTypes.number,
122
+ /**
123
+ * Indicate which axis to display the left of the charts.
124
+ * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
125
+ * @default yAxisIds[0] The id of the first provided axis
126
+ */
127
+ leftAxis: PropTypes.oneOfType([PropTypes.shape({
128
+ axisId: PropTypes.string.isRequired,
129
+ classes: PropTypes.object,
130
+ disableLine: PropTypes.bool,
131
+ disableTicks: PropTypes.bool,
132
+ fill: PropTypes.string,
133
+ label: PropTypes.string,
134
+ labelFontSize: PropTypes.number,
135
+ position: PropTypes.oneOf(['left', 'right']),
136
+ stroke: PropTypes.string,
137
+ tickFontSize: PropTypes.number,
138
+ tickSize: PropTypes.number
139
+ }), PropTypes.string]),
140
+ legend: PropTypes.shape({
141
+ classes: PropTypes.object,
142
+ direction: PropTypes.oneOf(['column', 'row']),
143
+ hidden: PropTypes.bool,
144
+ itemWidth: PropTypes.number,
145
+ markSize: PropTypes.number,
146
+ offset: PropTypes.shape({
147
+ x: PropTypes.number,
148
+ y: PropTypes.number
149
+ }),
150
+ position: PropTypes.shape({
151
+ horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
152
+ vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
153
+ }),
154
+ spacing: PropTypes.number
155
+ }),
156
+ margin: PropTypes.shape({
157
+ bottom: PropTypes.number,
158
+ left: PropTypes.number,
159
+ right: PropTypes.number,
160
+ top: PropTypes.number
161
+ }),
162
+ /**
163
+ * Indicate which axis to display the right of the charts.
164
+ * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
165
+ * @default null
166
+ */
167
+ rightAxis: PropTypes.oneOfType([PropTypes.shape({
168
+ axisId: PropTypes.string.isRequired,
169
+ classes: PropTypes.object,
170
+ disableLine: PropTypes.bool,
171
+ disableTicks: PropTypes.bool,
172
+ fill: PropTypes.string,
173
+ label: PropTypes.string,
174
+ labelFontSize: PropTypes.number,
175
+ position: PropTypes.oneOf(['left', 'right']),
176
+ stroke: PropTypes.string,
177
+ tickFontSize: PropTypes.number,
178
+ tickSize: PropTypes.number
179
+ }), PropTypes.string]),
180
+ series: PropTypes.arrayOf(PropTypes.shape({
181
+ arcLabel: PropTypes.oneOfType([PropTypes.oneOf(['formattedValue', 'label', 'value']), PropTypes.func]),
182
+ arcLabelMinAngle: PropTypes.number,
183
+ color: PropTypes.string,
184
+ cornerRadius: PropTypes.number,
185
+ cx: PropTypes.number,
186
+ cy: PropTypes.number,
187
+ data: PropTypes.arrayOf(PropTypes.shape({
188
+ color: PropTypes.string,
189
+ id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
190
+ label: PropTypes.string,
191
+ value: PropTypes.number.isRequired
192
+ })).isRequired,
193
+ endAngle: PropTypes.number,
194
+ faded: PropTypes.shape({
195
+ additionalRadius: PropTypes.number,
196
+ cornerRadius: PropTypes.number,
197
+ innerRadius: PropTypes.number,
198
+ outerRadius: PropTypes.number
199
+ }),
200
+ highlighted: PropTypes.shape({
201
+ additionalRadius: PropTypes.number,
202
+ cornerRadius: PropTypes.number,
203
+ innerRadius: PropTypes.number,
204
+ outerRadius: PropTypes.number
205
+ }),
206
+ highlightScope: PropTypes.shape({
207
+ faded: PropTypes.oneOf(['global', 'none', 'series']),
208
+ highlighted: PropTypes.oneOf(['item', 'none', 'series'])
209
+ }),
210
+ id: PropTypes.string,
211
+ innerRadius: PropTypes.number,
212
+ outerRadius: PropTypes.number,
213
+ paddingAngle: PropTypes.number,
214
+ sortingValues: PropTypes.oneOfType([PropTypes.oneOf(['asc', 'desc', 'none']), PropTypes.func]),
215
+ startAngle: PropTypes.number,
216
+ type: PropTypes.oneOf(['pie']),
217
+ valueFormatter: PropTypes.func
218
+ })).isRequired,
219
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
220
+ title: PropTypes.string,
221
+ tooltip: PropTypes.shape({
222
+ axisContent: PropTypes.elementType,
223
+ classes: PropTypes.object,
224
+ itemContent: PropTypes.elementType,
225
+ trigger: PropTypes.oneOf(['axis', 'item', 'none'])
226
+ }),
227
+ /**
228
+ * Indicate which axis to display the top of the charts.
229
+ * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
230
+ * @default null
231
+ */
232
+ topAxis: PropTypes.oneOfType([PropTypes.shape({
233
+ axisId: PropTypes.string.isRequired,
234
+ classes: PropTypes.object,
235
+ disableLine: PropTypes.bool,
236
+ disableTicks: PropTypes.bool,
237
+ fill: PropTypes.string,
238
+ label: PropTypes.string,
239
+ labelFontSize: PropTypes.number,
240
+ position: PropTypes.oneOf(['bottom', 'top']),
241
+ stroke: PropTypes.string,
242
+ tickFontSize: PropTypes.number,
243
+ tickSize: PropTypes.number
244
+ }), PropTypes.string]),
245
+ viewBox: PropTypes.shape({
246
+ height: PropTypes.number,
247
+ width: PropTypes.number,
248
+ x: PropTypes.number,
249
+ y: PropTypes.number
250
+ }),
251
+ width: PropTypes.number,
252
+ xAxis: PropTypes.arrayOf(PropTypes.shape({
253
+ axisId: PropTypes.string,
254
+ classes: PropTypes.object,
255
+ data: PropTypes.array,
256
+ disableLine: PropTypes.bool,
257
+ disableTicks: PropTypes.bool,
258
+ fill: PropTypes.string,
259
+ id: PropTypes.string,
260
+ label: PropTypes.string,
261
+ labelFontSize: PropTypes.number,
262
+ max: PropTypes.number,
263
+ maxTicks: PropTypes.number,
264
+ min: PropTypes.number,
265
+ minTicks: PropTypes.number,
266
+ position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
267
+ scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
268
+ stroke: PropTypes.string,
269
+ tickFontSize: PropTypes.number,
270
+ tickSize: PropTypes.number,
271
+ tickSpacing: PropTypes.number,
272
+ valueFormatter: PropTypes.func
273
+ })),
274
+ yAxis: PropTypes.arrayOf(PropTypes.shape({
275
+ axisId: PropTypes.string,
276
+ classes: PropTypes.object,
277
+ data: PropTypes.array,
278
+ disableLine: PropTypes.bool,
279
+ disableTicks: PropTypes.bool,
280
+ fill: PropTypes.string,
281
+ id: PropTypes.string,
282
+ label: PropTypes.string,
283
+ labelFontSize: PropTypes.number,
284
+ max: PropTypes.number,
285
+ maxTicks: PropTypes.number,
286
+ min: PropTypes.number,
287
+ minTicks: PropTypes.number,
288
+ position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
289
+ scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
290
+ stroke: PropTypes.string,
291
+ tickFontSize: PropTypes.number,
292
+ tickSize: PropTypes.number,
293
+ tickSpacing: PropTypes.number,
294
+ valueFormatter: PropTypes.func
295
+ }))
296
+ } : void 0;
297
+ export { PieChart };
@@ -0,0 +1,89 @@
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
+ var RATIO = 180 / Math.PI;
11
+ function getItemLabel(arcLabel, arcLabelMinAngle, item) {
12
+ if (!arcLabel) {
13
+ return null;
14
+ }
15
+ var angle = (item.endAngle - item.startAngle) * RATIO;
16
+ if (angle < arcLabelMinAngle) {
17
+ return null;
18
+ }
19
+ if (typeof arcLabel === 'string') {
20
+ var _item$arcLabel;
21
+ return (_item$arcLabel = item[arcLabel]) == null ? void 0 : _item$arcLabel.toString();
22
+ }
23
+ return arcLabel(item);
24
+ }
25
+ export function PiePlot() {
26
+ var seriesData = React.useContext(SeriesContext).pie;
27
+ var _React$useContext = React.useContext(DrawingContext),
28
+ left = _React$useContext.left,
29
+ top = _React$useContext.top,
30
+ width = _React$useContext.width,
31
+ height = _React$useContext.height;
32
+ if (seriesData === undefined) {
33
+ return null;
34
+ }
35
+ var availableRadius = Math.min(width, height) / 2;
36
+ var center = {
37
+ x: left + width / 2,
38
+ y: top + height / 2
39
+ };
40
+ var series = seriesData.series,
41
+ seriesOrder = seriesData.seriesOrder;
42
+ return /*#__PURE__*/_jsx("g", {
43
+ children: seriesOrder.map(function (seriesId) {
44
+ var _series$seriesId = series[seriesId],
45
+ innerRadius = _series$seriesId.innerRadius,
46
+ outerRadius = _series$seriesId.outerRadius,
47
+ cornerRadius = _series$seriesId.cornerRadius,
48
+ arcLabel = _series$seriesId.arcLabel,
49
+ _series$seriesId$arcL = _series$seriesId.arcLabelMinAngle,
50
+ arcLabelMinAngle = _series$seriesId$arcL === void 0 ? 0 : _series$seriesId$arcL,
51
+ data = _series$seriesId.data,
52
+ cx = _series$seriesId.cx,
53
+ cy = _series$seriesId.cy,
54
+ highlighted = _series$seriesId.highlighted,
55
+ faded = _series$seriesId.faded;
56
+ return /*#__PURE__*/_jsx("g", {
57
+ transform: "translate(".concat(cx === undefined ? center.x : left + cx, ", ").concat(cy === undefined ? center.y : top + cy, ")"),
58
+ children: /*#__PURE__*/_jsxs("g", {
59
+ children: [data.map(function (item, index) {
60
+ return /*#__PURE__*/_createElement(PieArc, _extends({}, item, {
61
+ key: item.id,
62
+ innerRadius: innerRadius,
63
+ outerRadius: outerRadius != null ? outerRadius : availableRadius,
64
+ cornerRadius: cornerRadius,
65
+ id: seriesId,
66
+ color: item.color,
67
+ dataIndex: index,
68
+ highlightScope: series[seriesId].highlightScope,
69
+ highlighted: highlighted,
70
+ faded: faded
71
+ }));
72
+ }), data.map(function (item, index) {
73
+ return /*#__PURE__*/_createElement(PieArcLabel, _extends({}, item, {
74
+ key: item.id,
75
+ innerRadius: innerRadius,
76
+ outerRadius: outerRadius != null ? outerRadius : availableRadius,
77
+ cornerRadius: cornerRadius,
78
+ id: seriesId,
79
+ color: item.color,
80
+ dataIndex: index,
81
+ highlightScope: series[seriesId].highlightScope,
82
+ formattedArcLabel: getItemLabel(arcLabel, arcLabelMinAngle, item)
83
+ }));
84
+ })]
85
+ })
86
+ }, seriesId);
87
+ })
88
+ });
89
+ }
@@ -0,0 +1,55 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import { pie as d3Pie } from 'd3-shape';
3
+ var getSortingComparator = function getSortingComparator() {
4
+ var comparator = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'none';
5
+ if (typeof comparator === 'function') {
6
+ return comparator;
7
+ }
8
+ switch (comparator) {
9
+ case 'none':
10
+ return null;
11
+ case 'desc':
12
+ return function (a, b) {
13
+ return b - a;
14
+ };
15
+ case 'asc':
16
+ return function (a, b) {
17
+ return a - b;
18
+ };
19
+ default:
20
+ return null;
21
+ }
22
+ };
23
+ var formatter = function formatter(params) {
24
+ var seriesOrder = params.seriesOrder,
25
+ series = params.series;
26
+ var defaultizedSeries = {};
27
+ seriesOrder.forEach(function (seriesId) {
28
+ var _series$seriesId$star, _series$seriesId$endA, _series$seriesId$padd, _series$seriesId$sort;
29
+ var arcs = d3Pie().startAngle(2 * Math.PI * ((_series$seriesId$star = series[seriesId].startAngle) != null ? _series$seriesId$star : 0) / 360).endAngle(2 * Math.PI * ((_series$seriesId$endA = series[seriesId].endAngle) != null ? _series$seriesId$endA : 360) / 360).padAngle(2 * Math.PI * ((_series$seriesId$padd = series[seriesId].paddingAngle) != null ? _series$seriesId$padd : 0) / 360).sortValues(getSortingComparator((_series$seriesId$sort = series[seriesId].sortingValues) != null ? _series$seriesId$sort : 'none'))(series[seriesId].data.map(function (piePoint) {
30
+ return piePoint.value;
31
+ }));
32
+ defaultizedSeries[seriesId] = _extends({
33
+ valueFormatter: function valueFormatter(item) {
34
+ return item.value.toLocaleString();
35
+ }
36
+ }, series[seriesId], {
37
+ data: series[seriesId].data.map(function (item, index) {
38
+ var _item$id;
39
+ return _extends({}, item, {
40
+ id: (_item$id = item.id) != null ? _item$id : "auto-generated-pie-id-".concat(seriesId, "-").concat(index)
41
+ }, arcs[index]);
42
+ }).map(function (item) {
43
+ var _series$seriesId$valu, _series$seriesId$valu2, _series$seriesId;
44
+ return _extends({}, item, {
45
+ formattedValue: (_series$seriesId$valu = (_series$seriesId$valu2 = (_series$seriesId = series[seriesId]).valueFormatter) == null ? void 0 : _series$seriesId$valu2.call(_series$seriesId, item)) != null ? _series$seriesId$valu : item.value.toLocaleString()
46
+ });
47
+ })
48
+ });
49
+ });
50
+ return {
51
+ seriesOrder: seriesOrder,
52
+ series: defaultizedSeries
53
+ };
54
+ };
55
+ 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,16 @@
1
+ var legendGetter = function legendGetter(params) {
2
+ var seriesOrder = params.seriesOrder,
3
+ series = params.series;
4
+ return seriesOrder.flatMap(function (seriesId) {
5
+ return series[seriesId].data.map(function (item) {
6
+ return {
7
+ color: item.color,
8
+ label: item.label,
9
+ id: item.id
10
+ };
11
+ }).filter(function (item) {
12
+ return item.label !== undefined;
13
+ });
14
+ });
15
+ };
16
+ export default legendGetter;
@@ -1,5 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
3
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
+ var _excluded = ["width", "height"];
3
5
  import * as React from 'react';
4
6
  import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
5
7
  import ownerWindow from '@mui/utils/ownerWindow';
@@ -90,11 +92,18 @@ var ResizableContainer = styled('div', {
90
92
  flexDirection: 'column',
91
93
  alignItems: 'center',
92
94
  justifyContent: 'center',
93
- overflow: 'hidden'
95
+ overflow: 'hidden',
96
+ '&>svg': {
97
+ width: '100%',
98
+ height: '100%'
99
+ }
94
100
  };
95
101
  });
96
102
  export function ResponsiveChartContainer(props) {
97
- var _useChartDimensions = useChartDimensions(props.width, props.height),
103
+ var propsWidth = props.width,
104
+ propsHeight = props.height,
105
+ other = _objectWithoutProperties(props, _excluded);
106
+ var _useChartDimensions = useChartDimensions(propsWidth, propsHeight),
98
107
  _useChartDimensions2 = _slicedToArray(_useChartDimensions, 3),
99
108
  containerRef = _useChartDimensions2[0],
100
109
  width = _useChartDimensions2[1],
@@ -105,7 +114,7 @@ export function ResponsiveChartContainer(props) {
105
114
  width: props.width,
106
115
  height: props.height
107
116
  },
108
- children: /*#__PURE__*/_jsx(ChartContainer, _extends({}, props, {
117
+ children: /*#__PURE__*/_jsx(ChartContainer, _extends({}, other, {
109
118
  width: width,
110
119
  height: height
111
120
  }))
@@ -79,7 +79,7 @@ process.env.NODE_ENV !== "production" ? Scatter.propTypes = {
79
79
  color: PropTypes.string.isRequired,
80
80
  markerSize: PropTypes.number.isRequired,
81
81
  series: PropTypes.shape({
82
- color: PropTypes.string.isRequired,
82
+ color: PropTypes.string,
83
83
  data: PropTypes.arrayOf(PropTypes.shape({
84
84
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
85
85
  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,15 @@
1
+ var legendGetter = function legendGetter(params) {
2
+ var seriesOrder = params.seriesOrder,
3
+ series = params.series;
4
+ var data = seriesOrder.map(function (seriesId) {
5
+ return {
6
+ color: series[seriesId].color,
7
+ label: series[seriesId].label,
8
+ id: seriesId
9
+ };
10
+ });
11
+ return data.filter(function (item) {
12
+ return item.label !== undefined;
13
+ });
14
+ };
15
+ 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 var SeriesContext = /*#__PURE__*/React.createContext({});
11
12
  var 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
  var formatSeries = function formatSeries(series, colors) {
17
27
  // Group series by type
18
28
  var seriesGroups = {};
package/legacy/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';