@mui/x-charts 7.0.0-beta.2 → 7.0.0-beta.3
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.d.ts +21 -5
- package/BarChart/BarChart.js +27 -5
- package/CHANGELOG.md +73 -9
- package/ChartsGrid/ChartsGrid.d.ts +30 -0
- package/ChartsGrid/ChartsGrid.js +128 -0
- package/ChartsGrid/chartsGridClasses.d.ts +13 -0
- package/ChartsGrid/chartsGridClasses.js +14 -0
- package/ChartsGrid/index.d.ts +2 -0
- package/ChartsGrid/index.js +27 -0
- package/ChartsGrid/package.json +6 -0
- package/ChartsSurface.js +6 -4
- package/ChartsXAxis/ChartsXAxis.js +2 -2
- package/ChartsYAxis/ChartsYAxis.js +2 -2
- package/Gauge/Gauge.d.ts +13 -0
- package/Gauge/Gauge.js +156 -0
- package/Gauge/GaugeContainer.d.ts +19 -0
- package/Gauge/GaugeContainer.js +216 -0
- package/Gauge/GaugeProvider.d.ts +117 -0
- package/Gauge/GaugeProvider.js +96 -0
- package/Gauge/GaugeReferenceArc.d.ts +2 -0
- package/Gauge/GaugeReferenceArc.js +44 -0
- package/Gauge/GaugeValueArc.d.ts +2 -0
- package/Gauge/GaugeValueArc.js +51 -0
- package/Gauge/GaugeValueText.d.ts +15 -0
- package/Gauge/GaugeValueText.js +77 -0
- package/Gauge/gaugeClasses.d.ts +14 -0
- package/Gauge/gaugeClasses.js +15 -0
- package/Gauge/index.d.ts +7 -0
- package/Gauge/index.js +87 -0
- package/Gauge/package.json +6 -0
- package/Gauge/utils.d.ts +19 -0
- package/Gauge/utils.js +75 -0
- package/LineChart/LineChart.d.ts +24 -5
- package/LineChart/LineChart.js +31 -5
- package/PieChart/PieArc.d.ts +4 -4
- package/PieChart/PieArc.js +9 -9
- package/PieChart/PieArcLabelPlot.js +13 -13
- package/PieChart/PieChart.d.ts +22 -0
- package/PieChart/PieChart.js +22 -0
- package/ResponsiveChartContainer/ResponsiveChartContainer.js +2 -66
- package/ResponsiveChartContainer/useChartContainerDimensions.d.ts +2 -0
- package/ResponsiveChartContainer/useChartContainerDimensions.js +76 -0
- package/ScatterChart/ScatterChart.d.ts +18 -0
- package/ScatterChart/ScatterChart.js +25 -0
- package/esm/BarChart/BarChart.js +27 -5
- package/esm/ChartsGrid/ChartsGrid.js +121 -0
- package/esm/ChartsGrid/chartsGridClasses.js +6 -0
- package/esm/ChartsGrid/index.js +2 -0
- package/esm/ChartsSurface.js +6 -4
- package/esm/ChartsXAxis/ChartsXAxis.js +1 -1
- package/esm/ChartsYAxis/ChartsYAxis.js +1 -1
- package/esm/Gauge/Gauge.js +149 -0
- package/esm/Gauge/GaugeContainer.js +211 -0
- package/esm/Gauge/GaugeProvider.js +85 -0
- package/esm/Gauge/GaugeReferenceArc.js +35 -0
- package/esm/Gauge/GaugeValueArc.js +42 -0
- package/esm/Gauge/GaugeValueText.js +69 -0
- package/esm/Gauge/gaugeClasses.js +7 -0
- package/esm/Gauge/index.js +7 -0
- package/esm/Gauge/utils.js +68 -0
- package/esm/LineChart/LineChart.js +31 -5
- package/esm/PieChart/PieArc.js +9 -9
- package/esm/PieChart/PieArcLabelPlot.js +13 -13
- package/esm/PieChart/PieChart.js +22 -0
- package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +2 -66
- package/esm/ResponsiveChartContainer/useChartContainerDimensions.js +66 -0
- package/esm/ScatterChart/ScatterChart.js +25 -0
- package/esm/hooks/useTicks.js +2 -3
- package/esm/index.js +2 -0
- package/hooks/useTicks.d.ts +1 -2
- package/hooks/useTicks.js +2 -3
- package/index.d.ts +2 -0
- package/index.js +23 -1
- package/legacy/BarChart/BarChart.js +27 -5
- package/legacy/ChartsGrid/ChartsGrid.js +119 -0
- package/legacy/ChartsGrid/chartsGridClasses.js +6 -0
- package/legacy/ChartsGrid/index.js +2 -0
- package/legacy/ChartsSurface.js +5 -3
- package/legacy/ChartsXAxis/ChartsXAxis.js +1 -1
- package/legacy/ChartsYAxis/ChartsYAxis.js +1 -1
- package/legacy/Gauge/Gauge.js +146 -0
- package/legacy/Gauge/GaugeContainer.js +215 -0
- package/legacy/Gauge/GaugeProvider.js +87 -0
- package/legacy/Gauge/GaugeReferenceArc.js +37 -0
- package/legacy/Gauge/GaugeValueArc.js +44 -0
- package/legacy/Gauge/GaugeValueText.js +66 -0
- package/legacy/Gauge/gaugeClasses.js +7 -0
- package/legacy/Gauge/index.js +7 -0
- package/legacy/Gauge/utils.js +84 -0
- package/legacy/LineChart/LineChart.js +31 -5
- package/legacy/PieChart/PieArc.js +10 -10
- package/legacy/PieChart/PieArcLabelPlot.js +14 -14
- package/legacy/PieChart/PieChart.js +22 -0
- package/legacy/ResponsiveChartContainer/ResponsiveChartContainer.js +7 -77
- package/legacy/ResponsiveChartContainer/useChartContainerDimensions.js +73 -0
- package/legacy/ScatterChart/ScatterChart.js +25 -0
- package/legacy/hooks/useTicks.js +2 -3
- package/legacy/index.js +3 -1
- package/modern/BarChart/BarChart.js +27 -5
- package/modern/ChartsGrid/ChartsGrid.js +121 -0
- package/modern/ChartsGrid/chartsGridClasses.js +6 -0
- package/modern/ChartsGrid/index.js +2 -0
- package/modern/ChartsSurface.js +6 -4
- package/modern/ChartsXAxis/ChartsXAxis.js +1 -1
- package/modern/ChartsYAxis/ChartsYAxis.js +1 -1
- package/modern/Gauge/Gauge.js +149 -0
- package/modern/Gauge/GaugeContainer.js +208 -0
- package/modern/Gauge/GaugeProvider.js +85 -0
- package/modern/Gauge/GaugeReferenceArc.js +35 -0
- package/modern/Gauge/GaugeValueArc.js +42 -0
- package/modern/Gauge/GaugeValueText.js +69 -0
- package/modern/Gauge/gaugeClasses.js +7 -0
- package/modern/Gauge/index.js +7 -0
- package/modern/Gauge/utils.js +68 -0
- package/modern/LineChart/LineChart.js +31 -5
- package/modern/PieChart/PieArc.js +9 -9
- package/modern/PieChart/PieArcLabelPlot.js +13 -13
- package/modern/PieChart/PieChart.js +22 -0
- package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +2 -66
- package/modern/ResponsiveChartContainer/useChartContainerDimensions.js +66 -0
- package/modern/ScatterChart/ScatterChart.js +25 -0
- package/modern/hooks/useTicks.js +2 -3
- package/modern/index.js +3 -1
- package/package.json +4 -4
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
const _excluded = ["width", "height", "margin", "title", "desc", "value", "valueMin", "valueMax", "startAngle", "endAngle", "outerRadius", "innerRadius", "cornerRadius", "cx", "cy", "children"];
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import useForkRef from '@mui/utils/useForkRef';
|
|
7
|
+
import { styled } from '@mui/material/styles';
|
|
8
|
+
import { useChartContainerDimensions } from '../ResponsiveChartContainer/useChartContainerDimensions';
|
|
9
|
+
import { ChartsSurface } from '../ChartsSurface';
|
|
10
|
+
import { DrawingProvider } from '../context/DrawingProvider';
|
|
11
|
+
import { GaugeProvider } from './GaugeProvider';
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
const ResizableContainer = styled('div', {
|
|
14
|
+
name: 'MuiGauge',
|
|
15
|
+
slot: 'Container'
|
|
16
|
+
})(({
|
|
17
|
+
ownerState,
|
|
18
|
+
theme
|
|
19
|
+
}) => ({
|
|
20
|
+
width: ownerState.width ?? '100%',
|
|
21
|
+
height: ownerState.height ?? '100%',
|
|
22
|
+
display: 'flex',
|
|
23
|
+
position: 'relative',
|
|
24
|
+
flexGrow: 1,
|
|
25
|
+
flexDirection: 'column',
|
|
26
|
+
alignItems: 'center',
|
|
27
|
+
justifyContent: 'center',
|
|
28
|
+
overflow: 'hidden',
|
|
29
|
+
'&>svg': {
|
|
30
|
+
width: '100%',
|
|
31
|
+
height: '100%'
|
|
32
|
+
},
|
|
33
|
+
'& text': {
|
|
34
|
+
fill: (theme.vars || theme).palette.text.primary
|
|
35
|
+
}
|
|
36
|
+
}));
|
|
37
|
+
const GaugeContainer = /*#__PURE__*/React.forwardRef(function GaugeContainer(props, ref) {
|
|
38
|
+
const {
|
|
39
|
+
width: inWidth,
|
|
40
|
+
height: inHeight,
|
|
41
|
+
margin,
|
|
42
|
+
title,
|
|
43
|
+
desc,
|
|
44
|
+
value,
|
|
45
|
+
valueMin = 0,
|
|
46
|
+
valueMax = 100,
|
|
47
|
+
startAngle,
|
|
48
|
+
endAngle,
|
|
49
|
+
outerRadius,
|
|
50
|
+
innerRadius,
|
|
51
|
+
cornerRadius,
|
|
52
|
+
cx,
|
|
53
|
+
cy,
|
|
54
|
+
children
|
|
55
|
+
} = props,
|
|
56
|
+
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
57
|
+
const [containerRef, width, height] = useChartContainerDimensions(inWidth, inHeight);
|
|
58
|
+
const svgRef = React.useRef(null);
|
|
59
|
+
const handleRef = useForkRef(ref, svgRef);
|
|
60
|
+
return /*#__PURE__*/_jsx(ResizableContainer, _extends({
|
|
61
|
+
ref: containerRef,
|
|
62
|
+
ownerState: {
|
|
63
|
+
width: inWidth,
|
|
64
|
+
height: inHeight
|
|
65
|
+
},
|
|
66
|
+
role: "meter",
|
|
67
|
+
"aria-valuenow": value === null ? undefined : value,
|
|
68
|
+
"aria-valuemin": valueMin,
|
|
69
|
+
"aria-valuemax": valueMax
|
|
70
|
+
}, other, {
|
|
71
|
+
children: width && height ? /*#__PURE__*/_jsx(DrawingProvider, {
|
|
72
|
+
width: width,
|
|
73
|
+
height: height,
|
|
74
|
+
margin: _extends({
|
|
75
|
+
left: 10,
|
|
76
|
+
right: 10,
|
|
77
|
+
top: 10,
|
|
78
|
+
bottom: 10
|
|
79
|
+
}, margin),
|
|
80
|
+
svgRef: svgRef,
|
|
81
|
+
children: /*#__PURE__*/_jsx(GaugeProvider, {
|
|
82
|
+
value: value,
|
|
83
|
+
valueMin: valueMin,
|
|
84
|
+
valueMax: valueMax,
|
|
85
|
+
startAngle: startAngle,
|
|
86
|
+
endAngle: endAngle,
|
|
87
|
+
outerRadius: outerRadius,
|
|
88
|
+
innerRadius: innerRadius,
|
|
89
|
+
cornerRadius: cornerRadius,
|
|
90
|
+
cx: cx,
|
|
91
|
+
cy: cy,
|
|
92
|
+
children: /*#__PURE__*/_jsx(ChartsSurface, {
|
|
93
|
+
width: width,
|
|
94
|
+
height: height,
|
|
95
|
+
ref: handleRef,
|
|
96
|
+
title: title,
|
|
97
|
+
desc: desc,
|
|
98
|
+
disableAxisListener: true,
|
|
99
|
+
"aria-hidden": "true",
|
|
100
|
+
children: children
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
}) : null
|
|
104
|
+
}));
|
|
105
|
+
});
|
|
106
|
+
process.env.NODE_ENV !== "production" ? GaugeContainer.propTypes = {
|
|
107
|
+
// ----------------------------- Warning --------------------------------
|
|
108
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
109
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
110
|
+
// ----------------------------------------------------------------------
|
|
111
|
+
children: PropTypes.node,
|
|
112
|
+
className: PropTypes.string,
|
|
113
|
+
/**
|
|
114
|
+
* The radius applied to arc corners (similar to border radius).
|
|
115
|
+
* Set it to '50%' to get rounded arc.
|
|
116
|
+
* @default 0
|
|
117
|
+
*/
|
|
118
|
+
cornerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
119
|
+
/**
|
|
120
|
+
* The x coordinate of the arc center.
|
|
121
|
+
* Can be a number (in px) or a string with a percentage such as '50%'.
|
|
122
|
+
* The '100%' is the width the drawing area.
|
|
123
|
+
*/
|
|
124
|
+
cx: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
125
|
+
/**
|
|
126
|
+
* The y coordinate of the arc center.
|
|
127
|
+
* Can be a number (in px) or a string with a percentage such as '50%'.
|
|
128
|
+
* The '100%' is the height the drawing area.
|
|
129
|
+
*/
|
|
130
|
+
cy: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
131
|
+
desc: PropTypes.string,
|
|
132
|
+
/**
|
|
133
|
+
* If `true`, the charts will not listen to the mouse move event.
|
|
134
|
+
* It might break interactive features, but will improve performance.
|
|
135
|
+
* @default false
|
|
136
|
+
*/
|
|
137
|
+
disableAxisListener: PropTypes.bool,
|
|
138
|
+
/**
|
|
139
|
+
* The end angle (deg).
|
|
140
|
+
* @default 360
|
|
141
|
+
*/
|
|
142
|
+
endAngle: PropTypes.number,
|
|
143
|
+
/**
|
|
144
|
+
* The height of the chart in px. If not defined, it takes the height of the parent element.
|
|
145
|
+
* @default undefined
|
|
146
|
+
*/
|
|
147
|
+
height: PropTypes.number,
|
|
148
|
+
/**
|
|
149
|
+
* The radius between circle center and the begining of the arc.
|
|
150
|
+
* Can be a number (in px) or a string with a percentage such as '50%'.
|
|
151
|
+
* The '100%' is the maximal radius that fit into the drawing area.
|
|
152
|
+
* @default '80%'
|
|
153
|
+
*/
|
|
154
|
+
innerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
155
|
+
/**
|
|
156
|
+
* The margin between the SVG and the drawing area.
|
|
157
|
+
* It's used for leaving some space for extra information such as the x- and y-axis or legend.
|
|
158
|
+
* Accepts an object with the optional properties: `top`, `bottom`, `left`, and `right`.
|
|
159
|
+
* @default object Depends on the charts type.
|
|
160
|
+
*/
|
|
161
|
+
margin: PropTypes.shape({
|
|
162
|
+
bottom: PropTypes.number,
|
|
163
|
+
left: PropTypes.number,
|
|
164
|
+
right: PropTypes.number,
|
|
165
|
+
top: PropTypes.number
|
|
166
|
+
}),
|
|
167
|
+
/**
|
|
168
|
+
* The radius between circle center and the end of the arc.
|
|
169
|
+
* Can be a number (in px) or a string with a percentage such as '50%'.
|
|
170
|
+
* The '100%' is the maximal radius that fit into the drawing area.
|
|
171
|
+
* @default '100%'
|
|
172
|
+
*/
|
|
173
|
+
outerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
174
|
+
/**
|
|
175
|
+
* The start angle (deg).
|
|
176
|
+
* @default 0
|
|
177
|
+
*/
|
|
178
|
+
startAngle: PropTypes.number,
|
|
179
|
+
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
|
180
|
+
title: PropTypes.string,
|
|
181
|
+
/**
|
|
182
|
+
* The value of the gauge.
|
|
183
|
+
* Set to `null` to not display a value.
|
|
184
|
+
*/
|
|
185
|
+
value: PropTypes.number,
|
|
186
|
+
/**
|
|
187
|
+
* The maximal value of the gauge.
|
|
188
|
+
* @default 100
|
|
189
|
+
*/
|
|
190
|
+
valueMax: PropTypes.number,
|
|
191
|
+
/**
|
|
192
|
+
* The minimal value of the gauge.
|
|
193
|
+
* @default 0
|
|
194
|
+
*/
|
|
195
|
+
valueMin: PropTypes.number,
|
|
196
|
+
viewBox: PropTypes.shape({
|
|
197
|
+
height: PropTypes.number,
|
|
198
|
+
width: PropTypes.number,
|
|
199
|
+
x: PropTypes.number,
|
|
200
|
+
y: PropTypes.number
|
|
201
|
+
}),
|
|
202
|
+
/**
|
|
203
|
+
* The width of the chart in px. If not defined, it takes the width of the parent element.
|
|
204
|
+
* @default undefined
|
|
205
|
+
*/
|
|
206
|
+
width: PropTypes.number
|
|
207
|
+
} : void 0;
|
|
208
|
+
export { GaugeContainer };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// @ignore - do not document.
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { DrawingContext } from '../context/DrawingProvider';
|
|
4
|
+
import { getPercentageValue } from '../internals/utils';
|
|
5
|
+
import { getArcRatios, getAvailableRadius } from './utils';
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
export const GaugeContext = /*#__PURE__*/React.createContext({
|
|
8
|
+
value: null,
|
|
9
|
+
valueMin: 0,
|
|
10
|
+
valueMax: 0,
|
|
11
|
+
startAngle: 0,
|
|
12
|
+
endAngle: 0,
|
|
13
|
+
innerRadius: 0,
|
|
14
|
+
outerRadius: 0,
|
|
15
|
+
cornerRadius: 0,
|
|
16
|
+
cx: 0,
|
|
17
|
+
cy: 0,
|
|
18
|
+
maxRadius: 0,
|
|
19
|
+
valueAngle: null
|
|
20
|
+
});
|
|
21
|
+
export function GaugeProvider(props) {
|
|
22
|
+
const {
|
|
23
|
+
value = null,
|
|
24
|
+
valueMin = 0,
|
|
25
|
+
valueMax = 100,
|
|
26
|
+
startAngle = 0,
|
|
27
|
+
endAngle = 360,
|
|
28
|
+
outerRadius: outerRadiusParam,
|
|
29
|
+
innerRadius: innerRadiusParam,
|
|
30
|
+
cornerRadius: cornerRadiusParam,
|
|
31
|
+
cx: cxParam,
|
|
32
|
+
cy: cyParam,
|
|
33
|
+
children
|
|
34
|
+
} = props;
|
|
35
|
+
const {
|
|
36
|
+
width,
|
|
37
|
+
height,
|
|
38
|
+
top,
|
|
39
|
+
left
|
|
40
|
+
} = React.useContext(DrawingContext);
|
|
41
|
+
const ratios = getArcRatios(startAngle, endAngle);
|
|
42
|
+
const innerCx = cxParam ? getPercentageValue(cxParam, width) : ratios.cx * width;
|
|
43
|
+
const innerCy = cyParam ? getPercentageValue(cyParam, height) : ratios.cy * height;
|
|
44
|
+
let cx = left + innerCx;
|
|
45
|
+
let cy = top + innerCy;
|
|
46
|
+
const maxRadius = getAvailableRadius(innerCx, innerCy, width, height, ratios);
|
|
47
|
+
|
|
48
|
+
// If the center is not defined, after computation of the available radius, udpate the center to use the remaining space.
|
|
49
|
+
if (cxParam === undefined) {
|
|
50
|
+
const usedWidth = maxRadius * (ratios.maxX - ratios.minX);
|
|
51
|
+
cx = left + (width - usedWidth) / 2 + ratios.cx * usedWidth;
|
|
52
|
+
}
|
|
53
|
+
if (cyParam === undefined) {
|
|
54
|
+
const usedHeight = maxRadius * (ratios.maxY - ratios.minY);
|
|
55
|
+
cy = top + (height - usedHeight) / 2 + ratios.cy * usedHeight;
|
|
56
|
+
}
|
|
57
|
+
const outerRadius = getPercentageValue(outerRadiusParam ?? maxRadius, maxRadius);
|
|
58
|
+
const innerRadius = getPercentageValue(innerRadiusParam ?? '80%', maxRadius);
|
|
59
|
+
const cornerRadius = getPercentageValue(cornerRadiusParam ?? 0, outerRadius - innerRadius);
|
|
60
|
+
const contextValue = React.useMemo(() => {
|
|
61
|
+
const startAngleRad = Math.PI * startAngle / 180;
|
|
62
|
+
const endAngleRad = Math.PI * endAngle / 180;
|
|
63
|
+
return {
|
|
64
|
+
value,
|
|
65
|
+
valueMin,
|
|
66
|
+
valueMax,
|
|
67
|
+
startAngle: startAngleRad,
|
|
68
|
+
endAngle: endAngleRad,
|
|
69
|
+
outerRadius,
|
|
70
|
+
innerRadius,
|
|
71
|
+
cornerRadius,
|
|
72
|
+
cx,
|
|
73
|
+
cy,
|
|
74
|
+
maxRadius,
|
|
75
|
+
valueAngle: value === null ? null : startAngleRad + (endAngleRad - startAngleRad) * (value - valueMin) / (valueMax - valueMin)
|
|
76
|
+
};
|
|
77
|
+
}, [value, valueMin, valueMax, startAngle, endAngle, outerRadius, innerRadius, cornerRadius, cx, cy, maxRadius]);
|
|
78
|
+
return /*#__PURE__*/_jsx(GaugeContext.Provider, {
|
|
79
|
+
value: contextValue,
|
|
80
|
+
children: children
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
export function useGaugeState() {
|
|
84
|
+
return React.useContext(GaugeContext);
|
|
85
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { arc as d3Arc } from 'd3-shape';
|
|
4
|
+
import { styled } from '@mui/material/styles';
|
|
5
|
+
import { useGaugeState } from './GaugeProvider';
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
const StyledPath = styled('path', {
|
|
8
|
+
name: 'MuiGauge',
|
|
9
|
+
slot: 'ReferenceArc',
|
|
10
|
+
overridesResolver: (props, styles) => styles.referenceArc
|
|
11
|
+
})(({
|
|
12
|
+
theme
|
|
13
|
+
}) => ({
|
|
14
|
+
fill: (theme.vars || theme).palette.divider
|
|
15
|
+
}));
|
|
16
|
+
export function GaugeReferenceArc(props) {
|
|
17
|
+
const {
|
|
18
|
+
startAngle,
|
|
19
|
+
endAngle,
|
|
20
|
+
outerRadius,
|
|
21
|
+
innerRadius,
|
|
22
|
+
cornerRadius,
|
|
23
|
+
cx,
|
|
24
|
+
cy
|
|
25
|
+
} = useGaugeState();
|
|
26
|
+
return /*#__PURE__*/_jsx(StyledPath, _extends({
|
|
27
|
+
transform: `translate(${cx}, ${cy})`,
|
|
28
|
+
d: d3Arc().cornerRadius(cornerRadius)({
|
|
29
|
+
startAngle,
|
|
30
|
+
endAngle,
|
|
31
|
+
innerRadius,
|
|
32
|
+
outerRadius
|
|
33
|
+
})
|
|
34
|
+
}, props));
|
|
35
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { arc as d3Arc } from 'd3-shape';
|
|
4
|
+
import { styled } from '@mui/material/styles';
|
|
5
|
+
import { useGaugeState } from './GaugeProvider';
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
const StyledPath = styled('path', {
|
|
8
|
+
name: 'MuiGauge',
|
|
9
|
+
slot: 'ReferenceArc',
|
|
10
|
+
overridesResolver: (props, styles) => styles.referenceArc
|
|
11
|
+
})(({
|
|
12
|
+
theme
|
|
13
|
+
}) => ({
|
|
14
|
+
fill: (theme.vars || theme).palette.primary.main
|
|
15
|
+
}));
|
|
16
|
+
export function GaugeValueArc(props) {
|
|
17
|
+
const {
|
|
18
|
+
value,
|
|
19
|
+
valueMin,
|
|
20
|
+
valueMax,
|
|
21
|
+
startAngle,
|
|
22
|
+
endAngle,
|
|
23
|
+
outerRadius,
|
|
24
|
+
innerRadius,
|
|
25
|
+
cornerRadius,
|
|
26
|
+
cx,
|
|
27
|
+
cy
|
|
28
|
+
} = useGaugeState();
|
|
29
|
+
if (value === null) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
const valueAngle = startAngle + (value - valueMin) / (valueMax - valueMin) * (endAngle - startAngle);
|
|
33
|
+
return /*#__PURE__*/_jsx(StyledPath, _extends({
|
|
34
|
+
transform: `translate(${cx}, ${cy})`,
|
|
35
|
+
d: d3Arc().cornerRadius(cornerRadius)({
|
|
36
|
+
startAngle,
|
|
37
|
+
endAngle: valueAngle,
|
|
38
|
+
innerRadius,
|
|
39
|
+
outerRadius
|
|
40
|
+
})
|
|
41
|
+
}, props));
|
|
42
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
const _excluded = ["text", "className"];
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import { useGaugeState } from './GaugeProvider';
|
|
7
|
+
import { ChartsText } from '../ChartsText';
|
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
+
function defaultFormatter({
|
|
10
|
+
value
|
|
11
|
+
}) {
|
|
12
|
+
return value === null ? 'NaN' : value.toLocaleString();
|
|
13
|
+
}
|
|
14
|
+
function GaugeValueText(props) {
|
|
15
|
+
const {
|
|
16
|
+
text = defaultFormatter,
|
|
17
|
+
className
|
|
18
|
+
} = props,
|
|
19
|
+
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
20
|
+
const {
|
|
21
|
+
value,
|
|
22
|
+
valueMin,
|
|
23
|
+
valueMax,
|
|
24
|
+
cx,
|
|
25
|
+
cy
|
|
26
|
+
} = useGaugeState();
|
|
27
|
+
const formattedText = typeof text === 'function' ? text({
|
|
28
|
+
value,
|
|
29
|
+
valueMin,
|
|
30
|
+
valueMax
|
|
31
|
+
}) : text;
|
|
32
|
+
if (formattedText === null) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return /*#__PURE__*/_jsx("g", {
|
|
36
|
+
className: className,
|
|
37
|
+
children: /*#__PURE__*/_jsx(ChartsText, _extends({
|
|
38
|
+
x: cx,
|
|
39
|
+
y: cy,
|
|
40
|
+
text: formattedText,
|
|
41
|
+
style: {
|
|
42
|
+
textAnchor: 'middle',
|
|
43
|
+
dominantBaseline: 'central'
|
|
44
|
+
}
|
|
45
|
+
}, other))
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
process.env.NODE_ENV !== "production" ? GaugeValueText.propTypes = {
|
|
49
|
+
// ----------------------------- Warning --------------------------------
|
|
50
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
51
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
52
|
+
// ----------------------------------------------------------------------
|
|
53
|
+
/**
|
|
54
|
+
* Height of a text line (in `em`).
|
|
55
|
+
*/
|
|
56
|
+
lineHeight: PropTypes.number,
|
|
57
|
+
/**
|
|
58
|
+
* If `true`, the line width is computed.
|
|
59
|
+
* @default false
|
|
60
|
+
*/
|
|
61
|
+
needsComputation: PropTypes.bool,
|
|
62
|
+
ownerState: PropTypes.any,
|
|
63
|
+
/**
|
|
64
|
+
* Style applied to text elements.
|
|
65
|
+
*/
|
|
66
|
+
style: PropTypes.object,
|
|
67
|
+
text: PropTypes.oneOfType([PropTypes.func, PropTypes.string])
|
|
68
|
+
} : void 0;
|
|
69
|
+
export { GaugeValueText };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
|
|
2
|
+
import generateUtilityClass from '@mui/utils/generateUtilityClass';
|
|
3
|
+
export function getGaugeUtilityClass(slot) {
|
|
4
|
+
return generateUtilityClass('MuiGauge', slot);
|
|
5
|
+
}
|
|
6
|
+
export const gaugeClasses = generateUtilityClasses('MuiGauge', ['root', 'valueArc', 'referenceArc', 'valueText']);
|
|
7
|
+
export default gaugeClasses;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
function deg2rad(angle) {
|
|
2
|
+
return Math.PI * angle / 180;
|
|
3
|
+
}
|
|
4
|
+
function getPoint(angle) {
|
|
5
|
+
const radAngle = deg2rad(angle);
|
|
6
|
+
return [Math.sin(radAngle), -Math.cos(radAngle)];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Retruns the ratio of the arc bounding box and its center.
|
|
11
|
+
* @param startAngle The start angle (in deg)
|
|
12
|
+
* @param endAngle The end angle (in deg)
|
|
13
|
+
*/
|
|
14
|
+
export function getArcRatios(startAngle, endAngle) {
|
|
15
|
+
// Set the start, end and center point.
|
|
16
|
+
const points = [[0, 0], getPoint(startAngle), getPoint(endAngle)];
|
|
17
|
+
|
|
18
|
+
// Add cardinal points included in the arc
|
|
19
|
+
const minAngle = Math.min(startAngle, endAngle);
|
|
20
|
+
const maxAngle = Math.max(startAngle, endAngle);
|
|
21
|
+
const initialAngle = Math.floor(minAngle / 90) * 90;
|
|
22
|
+
for (let step = 1; step <= 4; step += 1) {
|
|
23
|
+
const cartinalAngle = initialAngle + step * 90;
|
|
24
|
+
if (cartinalAngle < maxAngle) {
|
|
25
|
+
points.push(getPoint(cartinalAngle));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const minX = Math.min(...points.map(([x]) => x));
|
|
29
|
+
const maxX = Math.max(...points.map(([x]) => x));
|
|
30
|
+
const minY = Math.min(...points.map(([, y]) => y));
|
|
31
|
+
const maxY = Math.max(...points.map(([, y]) => y));
|
|
32
|
+
return {
|
|
33
|
+
cx: -minX / (maxX - minX),
|
|
34
|
+
cy: -minY / (maxY - minY),
|
|
35
|
+
minX,
|
|
36
|
+
maxX,
|
|
37
|
+
minY,
|
|
38
|
+
maxY
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export function getAvailableRadius(cx, cy, width, height, {
|
|
42
|
+
minX,
|
|
43
|
+
maxX,
|
|
44
|
+
minY,
|
|
45
|
+
maxY
|
|
46
|
+
}) {
|
|
47
|
+
return Math.min(...[{
|
|
48
|
+
ratio: Math.abs(minX),
|
|
49
|
+
space: cx
|
|
50
|
+
}, {
|
|
51
|
+
ratio: Math.abs(maxX),
|
|
52
|
+
space: width - cx
|
|
53
|
+
}, {
|
|
54
|
+
ratio: Math.abs(minY),
|
|
55
|
+
space: cy
|
|
56
|
+
}, {
|
|
57
|
+
ratio: Math.abs(maxY),
|
|
58
|
+
space: height - cy
|
|
59
|
+
}].map(({
|
|
60
|
+
ratio,
|
|
61
|
+
space
|
|
62
|
+
}) => {
|
|
63
|
+
if (ratio < 0.00001) {
|
|
64
|
+
return Infinity;
|
|
65
|
+
}
|
|
66
|
+
return space / ratio;
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
@@ -13,6 +13,7 @@ import { ChartsLegend } from '../ChartsLegend';
|
|
|
13
13
|
import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
|
|
14
14
|
import { ChartsClipPath } from '../ChartsClipPath';
|
|
15
15
|
import { LineHighlightPlot } from './LineHighlightPlot';
|
|
16
|
+
import { ChartsGrid } from '../ChartsGrid';
|
|
16
17
|
import { ChartsOnAxisClickHandler } from '../ChartsOnAxisClickHandler';
|
|
17
18
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
19
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -47,6 +48,7 @@ const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
|
|
|
47
48
|
},
|
|
48
49
|
disableLineItemHighlight,
|
|
49
50
|
legend,
|
|
51
|
+
grid,
|
|
50
52
|
topAxis,
|
|
51
53
|
leftAxis,
|
|
52
54
|
rightAxis,
|
|
@@ -81,6 +83,9 @@ const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
|
|
|
81
83
|
disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none' && !onAxisClick,
|
|
82
84
|
children: [onAxisClick && /*#__PURE__*/_jsx(ChartsOnAxisClickHandler, {
|
|
83
85
|
onAxisClick: onAxisClick
|
|
86
|
+
}), grid && /*#__PURE__*/_jsx(ChartsGrid, {
|
|
87
|
+
vertical: grid.vertical,
|
|
88
|
+
horizontal: grid.horizontal
|
|
84
89
|
}), /*#__PURE__*/_jsxs("g", {
|
|
85
90
|
clipPath: `url(#${clipPathId})`,
|
|
86
91
|
children: [/*#__PURE__*/_jsx(AreaPlot, {
|
|
@@ -126,11 +131,8 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
126
131
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
127
132
|
// ----------------------------------------------------------------------
|
|
128
133
|
/**
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
* - 'none': display nothing.
|
|
132
|
-
* - 'line': display a line at the current mouse position.
|
|
133
|
-
* - 'band': display a band at the current mouse position. Only available with band scale.
|
|
134
|
+
* The configuration of axes highlight.
|
|
135
|
+
* @see See {@link https://mui.com/x/react-charts/tooltip/#highlights highlight docs} for more details.
|
|
134
136
|
* @default { x: 'line' }
|
|
135
137
|
*/
|
|
136
138
|
axisHighlight: PropTypes.shape({
|
|
@@ -186,6 +188,13 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
186
188
|
* If `true`, render the line highlight item.
|
|
187
189
|
*/
|
|
188
190
|
disableLineItemHighlight: PropTypes.bool,
|
|
191
|
+
/**
|
|
192
|
+
* Option to display a cartesian grid in the background.
|
|
193
|
+
*/
|
|
194
|
+
grid: PropTypes.shape({
|
|
195
|
+
horizontal: PropTypes.bool,
|
|
196
|
+
vertical: PropTypes.bool
|
|
197
|
+
}),
|
|
189
198
|
/**
|
|
190
199
|
* The height of the chart in px. If not defined, it takes the height of the parent element.
|
|
191
200
|
* @default undefined
|
|
@@ -244,6 +253,9 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
244
253
|
right: PropTypes.number,
|
|
245
254
|
top: PropTypes.number
|
|
246
255
|
}),
|
|
256
|
+
/**
|
|
257
|
+
* Callback fired when an area element is clicked.
|
|
258
|
+
*/
|
|
247
259
|
onAreaClick: PropTypes.func,
|
|
248
260
|
/**
|
|
249
261
|
* The function called for onClick events.
|
|
@@ -252,7 +264,13 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
252
264
|
* @param {null | AxisData} data The data about the clicked axis and items associated with it.
|
|
253
265
|
*/
|
|
254
266
|
onAxisClick: PropTypes.func,
|
|
267
|
+
/**
|
|
268
|
+
* Callback fired when a line element is clicked.
|
|
269
|
+
*/
|
|
255
270
|
onLineClick: PropTypes.func,
|
|
271
|
+
/**
|
|
272
|
+
* Callback fired when a mark element is clicked.
|
|
273
|
+
*/
|
|
256
274
|
onMarkClick: PropTypes.func,
|
|
257
275
|
/**
|
|
258
276
|
* Indicate which axis to display the right of the charts.
|
|
@@ -281,6 +299,9 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
281
299
|
tickNumber: PropTypes.number,
|
|
282
300
|
tickSize: PropTypes.number
|
|
283
301
|
}), PropTypes.string]),
|
|
302
|
+
/**
|
|
303
|
+
* The series to display in the line chart.
|
|
304
|
+
*/
|
|
284
305
|
series: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
285
306
|
/**
|
|
286
307
|
* If `true`, animations are skipped.
|
|
@@ -299,6 +320,11 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
299
320
|
slots: PropTypes.object,
|
|
300
321
|
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
|
301
322
|
title: PropTypes.string,
|
|
323
|
+
/**
|
|
324
|
+
* The configuration of the tooltip.
|
|
325
|
+
* @see See {@link https://mui.com/x/react-charts/tooltip/ tooltip docs} for more details.
|
|
326
|
+
* @default { trigger: 'item' }
|
|
327
|
+
*/
|
|
302
328
|
tooltip: PropTypes.shape({
|
|
303
329
|
axisContent: PropTypes.elementType,
|
|
304
330
|
classes: PropTypes.object,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
const _excluded = ["
|
|
3
|
+
const _excluded = ["classes", "color", "cornerRadius", "dataIndex", "endAngle", "highlightScope", "id", "innerRadius", "isFaded", "isHighlighted", "onClick", "outerRadius", "paddingAngle", "startAngle"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import { arc as d3Arc } from 'd3-shape';
|
|
@@ -40,20 +40,20 @@ const PieArcRoot = styled(animated.path, {
|
|
|
40
40
|
}));
|
|
41
41
|
function PieArc(props) {
|
|
42
42
|
const {
|
|
43
|
-
id,
|
|
44
|
-
dataIndex,
|
|
45
43
|
classes: innerClasses,
|
|
46
44
|
color,
|
|
45
|
+
cornerRadius,
|
|
46
|
+
dataIndex,
|
|
47
|
+
endAngle,
|
|
47
48
|
highlightScope,
|
|
48
|
-
|
|
49
|
+
id,
|
|
50
|
+
innerRadius,
|
|
49
51
|
isFaded,
|
|
50
52
|
isHighlighted,
|
|
51
|
-
|
|
52
|
-
endAngle,
|
|
53
|
-
paddingAngle,
|
|
54
|
-
innerRadius,
|
|
53
|
+
onClick,
|
|
55
54
|
outerRadius,
|
|
56
|
-
|
|
55
|
+
paddingAngle,
|
|
56
|
+
startAngle
|
|
57
57
|
} = props,
|
|
58
58
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
59
59
|
const ownerState = {
|