@mui/x-charts 6.0.0-alpha.0 → 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.
- package/BarChart/BarChart.js +8 -5
- package/BarChart/legend.d.ts +3 -0
- package/BarChart/legend.js +20 -0
- package/CHANGELOG.md +136 -8
- package/ChartsAxis/ChartsAxis.d.ts +4 -4
- package/ChartsAxis/ChartsAxis.js +4 -4
- package/ChartsLegend/ChartsLegend.d.ts +5 -1
- package/ChartsLegend/ChartsLegend.js +5 -1
- package/ChartsLegend/utils.d.ts +1 -1
- package/ChartsLegend/utils.js +12 -1
- package/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/ChartsTooltip/ChartsItemTooltipContent.js +11 -2
- package/ChartsTooltip/ChartsTooltipTable.js +8 -8
- package/LineChart/LineChart.js +8 -5
- package/LineChart/legend.d.ts +3 -0
- package/LineChart/legend.js +20 -0
- package/PieChart/PieArc.d.ts +36 -0
- package/PieChart/PieArc.js +128 -0
- package/PieChart/PieArcLabel.d.ts +36 -0
- package/PieChart/PieArcLabel.js +113 -0
- package/PieChart/PieChart.d.ts +20 -0
- package/PieChart/PieChart.js +292 -0
- package/PieChart/PiePlot.d.ts +2 -0
- package/PieChart/PiePlot.js +98 -0
- package/PieChart/formatter.d.ts +3 -0
- package/PieChart/formatter.js +49 -0
- package/PieChart/index.d.ts +4 -0
- package/PieChart/index.js +47 -0
- package/PieChart/legend.d.ts +3 -0
- package/PieChart/legend.js +19 -0
- package/PieChart/package.json +6 -0
- package/README.md +30 -2
- package/ResponsiveChartContainer/index.js +91 -25
- package/ScatterChart/Scatter.js +1 -1
- package/ScatterChart/ScatterChart.js +5 -4
- package/ScatterChart/legend.d.ts +3 -0
- package/ScatterChart/legend.js +20 -0
- package/context/SeriesContextProvider.js +11 -1
- package/esm/BarChart/BarChart.js +8 -5
- package/esm/BarChart/legend.js +13 -0
- package/esm/ChartsAxis/ChartsAxis.js +4 -4
- package/esm/ChartsLegend/ChartsLegend.js +5 -1
- package/esm/ChartsLegend/utils.js +11 -1
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/esm/ChartsTooltip/ChartsItemTooltipContent.js +11 -3
- package/esm/ChartsTooltip/ChartsTooltipTable.js +8 -8
- package/esm/LineChart/LineChart.js +8 -5
- package/esm/LineChart/legend.js +13 -0
- package/esm/PieChart/PieArc.js +117 -0
- package/esm/PieChart/PieArcLabel.js +101 -0
- package/esm/PieChart/PieChart.js +285 -0
- package/esm/PieChart/PiePlot.js +92 -0
- package/esm/PieChart/formatter.js +48 -0
- package/esm/PieChart/index.js +4 -0
- package/esm/PieChart/legend.js +12 -0
- package/esm/ResponsiveChartContainer/index.js +94 -26
- package/esm/ScatterChart/Scatter.js +1 -1
- package/esm/ScatterChart/ScatterChart.js +5 -4
- package/esm/ScatterChart/legend.js +13 -0
- package/esm/context/SeriesContextProvider.js +11 -1
- package/esm/index.js +1 -0
- package/esm/internals/defaultizeColor.js +7 -0
- package/esm/models/seriesType/index.js +1 -8
- package/index.d.ts +1 -0
- package/index.js +12 -1
- package/internals/defaultizeColor.d.ts +35 -0
- package/internals/defaultizeColor.js +7 -0
- package/legacy/BarChart/BarChart.js +10 -7
- package/legacy/BarChart/legend.js +15 -0
- package/legacy/ChartsAxis/ChartsAxis.js +4 -4
- package/legacy/ChartsLegend/ChartsLegend.js +5 -1
- package/legacy/ChartsLegend/utils.js +12 -6
- package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +3 -1
- package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +10 -3
- package/legacy/ChartsTooltip/ChartsTooltipTable.js +7 -9
- package/legacy/LineChart/LineChart.js +10 -7
- package/legacy/LineChart/legend.js +15 -0
- package/legacy/PieChart/PieArc.js +118 -0
- package/legacy/PieChart/PieArcLabel.js +101 -0
- package/legacy/PieChart/PieChart.js +297 -0
- package/legacy/PieChart/PiePlot.js +89 -0
- package/legacy/PieChart/formatter.js +55 -0
- package/legacy/PieChart/index.js +4 -0
- package/legacy/PieChart/legend.js +16 -0
- package/legacy/ResponsiveChartContainer/index.js +89 -26
- package/legacy/ScatterChart/Scatter.js +1 -1
- package/legacy/ScatterChart/ScatterChart.js +5 -4
- package/legacy/ScatterChart/legend.js +15 -0
- package/legacy/context/SeriesContextProvider.js +11 -1
- package/legacy/index.js +2 -1
- package/legacy/internals/defaultizeColor.js +9 -0
- package/legacy/models/seriesType/index.js +1 -8
- package/models/seriesType/bar.d.ts +1 -1
- package/models/seriesType/common.d.ts +1 -1
- package/models/seriesType/config.d.ts +29 -2
- package/models/seriesType/index.d.ts +7 -3
- package/models/seriesType/index.js +11 -0
- package/models/seriesType/line.d.ts +1 -1
- package/models/seriesType/pie.d.ts +103 -3
- package/models/seriesType/scatter.d.ts +1 -1
- package/modern/BarChart/BarChart.js +8 -5
- package/modern/BarChart/legend.js +13 -0
- package/modern/ChartsAxis/ChartsAxis.js +4 -4
- package/modern/ChartsLegend/ChartsLegend.js +5 -1
- package/modern/ChartsLegend/utils.js +11 -1
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/modern/ChartsTooltip/ChartsItemTooltipContent.js +11 -2
- package/modern/ChartsTooltip/ChartsTooltipTable.js +8 -8
- package/modern/LineChart/LineChart.js +8 -5
- package/modern/LineChart/legend.js +13 -0
- package/modern/PieChart/PieArc.js +116 -0
- package/modern/PieChart/PieArcLabel.js +101 -0
- package/modern/PieChart/PieChart.js +285 -0
- package/modern/PieChart/PiePlot.js +91 -0
- package/modern/PieChart/formatter.js +41 -0
- package/modern/PieChart/index.js +4 -0
- package/modern/PieChart/legend.js +12 -0
- package/modern/ResponsiveChartContainer/index.js +91 -25
- package/modern/ScatterChart/Scatter.js +1 -1
- package/modern/ScatterChart/ScatterChart.js +5 -4
- package/modern/ScatterChart/legend.js +13 -0
- package/modern/context/SeriesContextProvider.js +11 -1
- package/modern/index.js +2 -1
- package/modern/internals/defaultizeColor.js +7 -0
- package/modern/models/seriesType/index.js +1 -8
- package/package.json +1 -3
|
@@ -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,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,11 +1,16 @@
|
|
|
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
|
-
import
|
|
6
|
+
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
|
|
7
|
+
import ownerWindow from '@mui/utils/ownerWindow';
|
|
8
|
+
import { styled } from '@mui/material/styles';
|
|
5
9
|
import { ChartContainer } from '../ChartContainer';
|
|
6
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
11
|
var useChartDimensions = function useChartDimensions(inWidth, inHeight) {
|
|
8
|
-
var
|
|
12
|
+
var rootRef = React.useRef(null);
|
|
13
|
+
var displayError = React.useRef(false);
|
|
9
14
|
var _React$useState = React.useState(0),
|
|
10
15
|
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
11
16
|
width = _React$useState2[0],
|
|
@@ -14,44 +19,102 @@ var useChartDimensions = function useChartDimensions(inWidth, inHeight) {
|
|
|
14
19
|
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
|
15
20
|
height = _React$useState4[0],
|
|
16
21
|
setHeight = _React$useState4[1];
|
|
22
|
+
|
|
23
|
+
// Adaptation of the `computeSizeAndPublishResizeEvent` from the grid.
|
|
24
|
+
var computeSize = React.useCallback(function () {
|
|
25
|
+
var mainEl = rootRef == null ? void 0 : rootRef.current;
|
|
26
|
+
if (!mainEl) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
var win = ownerWindow(mainEl);
|
|
30
|
+
var computedStyle = win.getComputedStyle(mainEl);
|
|
31
|
+
var newHeight = parseFloat(computedStyle.height) || 0;
|
|
32
|
+
var newWidth = parseFloat(computedStyle.width) || 0;
|
|
33
|
+
setWidth(newWidth);
|
|
34
|
+
setHeight(newHeight);
|
|
35
|
+
}, []);
|
|
17
36
|
React.useEffect(function () {
|
|
18
|
-
|
|
19
|
-
|
|
37
|
+
// Ensure the error detection occurs after the first rendering.
|
|
38
|
+
displayError.current = true;
|
|
39
|
+
}, []);
|
|
40
|
+
useEnhancedEffect(function () {
|
|
41
|
+
if (inWidth !== undefined && inHeight !== undefined) {
|
|
20
42
|
return function () {};
|
|
21
43
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
44
|
+
computeSize();
|
|
45
|
+
var elementToObserve = rootRef.current;
|
|
46
|
+
if (typeof ResizeObserver === 'undefined') {
|
|
47
|
+
return function () {};
|
|
48
|
+
}
|
|
49
|
+
var animationFrame;
|
|
50
|
+
var observer = new ResizeObserver(function () {
|
|
51
|
+
// See https://github.com/mui/mui-x/issues/8733
|
|
52
|
+
animationFrame = window.requestAnimationFrame(function () {
|
|
53
|
+
computeSize();
|
|
54
|
+
});
|
|
32
55
|
});
|
|
33
|
-
|
|
56
|
+
if (elementToObserve) {
|
|
57
|
+
observer.observe(elementToObserve);
|
|
58
|
+
}
|
|
34
59
|
return function () {
|
|
35
|
-
|
|
60
|
+
if (animationFrame) {
|
|
61
|
+
window.cancelAnimationFrame(animationFrame);
|
|
62
|
+
}
|
|
63
|
+
if (elementToObserve) {
|
|
64
|
+
observer.unobserve(elementToObserve);
|
|
65
|
+
}
|
|
36
66
|
};
|
|
37
|
-
}, [
|
|
38
|
-
|
|
67
|
+
}, [computeSize, inHeight, inWidth]);
|
|
68
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
69
|
+
if (displayError.current && inWidth === undefined && width === 0) {
|
|
70
|
+
console.error("MUI: Charts does not have `width` prop, and its container has no `width` defined.");
|
|
71
|
+
displayError.current = false;
|
|
72
|
+
}
|
|
73
|
+
if (displayError.current && inHeight === undefined && height === 0) {
|
|
74
|
+
console.error("MUI: Charts does not have `height` prop, and its container has no `height` defined.");
|
|
75
|
+
displayError.current = false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return [rootRef, inWidth != null ? inWidth : width, inHeight != null ? inHeight : height];
|
|
39
79
|
};
|
|
80
|
+
var ResizableContainer = styled('div', {
|
|
81
|
+
name: 'MuiResponsiveChart',
|
|
82
|
+
slot: 'Container'
|
|
83
|
+
})(function (_ref) {
|
|
84
|
+
var _ownerState$width, _ownerState$height;
|
|
85
|
+
var ownerState = _ref.ownerState;
|
|
86
|
+
return {
|
|
87
|
+
width: (_ownerState$width = ownerState.width) != null ? _ownerState$width : '100%',
|
|
88
|
+
height: (_ownerState$height = ownerState.height) != null ? _ownerState$height : '100%',
|
|
89
|
+
display: 'flex',
|
|
90
|
+
position: 'relative',
|
|
91
|
+
flexGrow: 1,
|
|
92
|
+
flexDirection: 'column',
|
|
93
|
+
alignItems: 'center',
|
|
94
|
+
justifyContent: 'center',
|
|
95
|
+
overflow: 'hidden',
|
|
96
|
+
'&>svg': {
|
|
97
|
+
width: '100%',
|
|
98
|
+
height: '100%'
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
});
|
|
40
102
|
export function ResponsiveChartContainer(props) {
|
|
41
|
-
var
|
|
42
|
-
|
|
103
|
+
var propsWidth = props.width,
|
|
104
|
+
propsHeight = props.height,
|
|
105
|
+
other = _objectWithoutProperties(props, _excluded);
|
|
106
|
+
var _useChartDimensions = useChartDimensions(propsWidth, propsHeight),
|
|
43
107
|
_useChartDimensions2 = _slicedToArray(_useChartDimensions, 3),
|
|
44
108
|
containerRef = _useChartDimensions2[0],
|
|
45
109
|
width = _useChartDimensions2[1],
|
|
46
110
|
height = _useChartDimensions2[2];
|
|
47
|
-
return /*#__PURE__*/_jsx(
|
|
111
|
+
return /*#__PURE__*/_jsx(ResizableContainer, {
|
|
48
112
|
ref: containerRef,
|
|
49
|
-
|
|
50
|
-
width:
|
|
51
|
-
height:
|
|
52
|
-
padding: 0
|
|
113
|
+
ownerState: {
|
|
114
|
+
width: props.width,
|
|
115
|
+
height: props.height
|
|
53
116
|
},
|
|
54
|
-
children: /*#__PURE__*/_jsx(ChartContainer, _extends({},
|
|
117
|
+
children: /*#__PURE__*/_jsx(ChartContainer, _extends({}, other, {
|
|
55
118
|
width: width,
|
|
56
119
|
height: height
|
|
57
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
|
|
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,
|
|
@@ -62,7 +62,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
62
62
|
y: PropTypes.oneOf(['line', 'none'])
|
|
63
63
|
}),
|
|
64
64
|
/**
|
|
65
|
-
* Indicate which axis to display the
|
|
65
|
+
* Indicate which axis to display the bottom of the charts.
|
|
66
66
|
* Can be a string (the id of the axis) or an object `ChartsXAxisProps`
|
|
67
67
|
* @default xAxisIds[0] The id of the first provided axis
|
|
68
68
|
*/
|
|
@@ -89,7 +89,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
89
89
|
disableAxisListener: PropTypes.bool,
|
|
90
90
|
height: PropTypes.number,
|
|
91
91
|
/**
|
|
92
|
-
* Indicate which axis to display the
|
|
92
|
+
* Indicate which axis to display the left of the charts.
|
|
93
93
|
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`
|
|
94
94
|
* @default yAxisIds[0] The id of the first provided axis
|
|
95
95
|
*/
|
|
@@ -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({
|
|
@@ -128,7 +129,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
128
129
|
top: PropTypes.number
|
|
129
130
|
}),
|
|
130
131
|
/**
|
|
131
|
-
* Indicate which axis to display the
|
|
132
|
+
* Indicate which axis to display the right of the charts.
|
|
132
133
|
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`
|
|
133
134
|
* @default null
|
|
134
135
|
*/
|
|
@@ -173,7 +174,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
173
174
|
trigger: PropTypes.oneOf(['axis', 'item', 'none'])
|
|
174
175
|
}),
|
|
175
176
|
/**
|
|
176
|
-
* Indicate which axis to display the
|
|
177
|
+
* Indicate which axis to display the top of the charts.
|
|
177
178
|
* Can be a string (the id of the axis) or an object `ChartsXAxisProps`
|
|
178
179
|
* @default null
|
|
179
180
|
*/
|
|
@@ -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;
|