@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.
Files changed (124) hide show
  1. package/BarChart/BarChart.d.ts +21 -5
  2. package/BarChart/BarChart.js +27 -5
  3. package/CHANGELOG.md +73 -9
  4. package/ChartsGrid/ChartsGrid.d.ts +30 -0
  5. package/ChartsGrid/ChartsGrid.js +128 -0
  6. package/ChartsGrid/chartsGridClasses.d.ts +13 -0
  7. package/ChartsGrid/chartsGridClasses.js +14 -0
  8. package/ChartsGrid/index.d.ts +2 -0
  9. package/ChartsGrid/index.js +27 -0
  10. package/ChartsGrid/package.json +6 -0
  11. package/ChartsSurface.js +6 -4
  12. package/ChartsXAxis/ChartsXAxis.js +2 -2
  13. package/ChartsYAxis/ChartsYAxis.js +2 -2
  14. package/Gauge/Gauge.d.ts +13 -0
  15. package/Gauge/Gauge.js +156 -0
  16. package/Gauge/GaugeContainer.d.ts +19 -0
  17. package/Gauge/GaugeContainer.js +216 -0
  18. package/Gauge/GaugeProvider.d.ts +117 -0
  19. package/Gauge/GaugeProvider.js +96 -0
  20. package/Gauge/GaugeReferenceArc.d.ts +2 -0
  21. package/Gauge/GaugeReferenceArc.js +44 -0
  22. package/Gauge/GaugeValueArc.d.ts +2 -0
  23. package/Gauge/GaugeValueArc.js +51 -0
  24. package/Gauge/GaugeValueText.d.ts +15 -0
  25. package/Gauge/GaugeValueText.js +77 -0
  26. package/Gauge/gaugeClasses.d.ts +14 -0
  27. package/Gauge/gaugeClasses.js +15 -0
  28. package/Gauge/index.d.ts +7 -0
  29. package/Gauge/index.js +87 -0
  30. package/Gauge/package.json +6 -0
  31. package/Gauge/utils.d.ts +19 -0
  32. package/Gauge/utils.js +75 -0
  33. package/LineChart/LineChart.d.ts +24 -5
  34. package/LineChart/LineChart.js +31 -5
  35. package/PieChart/PieArc.d.ts +4 -4
  36. package/PieChart/PieArc.js +9 -9
  37. package/PieChart/PieArcLabelPlot.js +13 -13
  38. package/PieChart/PieChart.d.ts +22 -0
  39. package/PieChart/PieChart.js +22 -0
  40. package/ResponsiveChartContainer/ResponsiveChartContainer.js +2 -66
  41. package/ResponsiveChartContainer/useChartContainerDimensions.d.ts +2 -0
  42. package/ResponsiveChartContainer/useChartContainerDimensions.js +76 -0
  43. package/ScatterChart/ScatterChart.d.ts +18 -0
  44. package/ScatterChart/ScatterChart.js +25 -0
  45. package/esm/BarChart/BarChart.js +27 -5
  46. package/esm/ChartsGrid/ChartsGrid.js +121 -0
  47. package/esm/ChartsGrid/chartsGridClasses.js +6 -0
  48. package/esm/ChartsGrid/index.js +2 -0
  49. package/esm/ChartsSurface.js +6 -4
  50. package/esm/ChartsXAxis/ChartsXAxis.js +1 -1
  51. package/esm/ChartsYAxis/ChartsYAxis.js +1 -1
  52. package/esm/Gauge/Gauge.js +149 -0
  53. package/esm/Gauge/GaugeContainer.js +211 -0
  54. package/esm/Gauge/GaugeProvider.js +85 -0
  55. package/esm/Gauge/GaugeReferenceArc.js +35 -0
  56. package/esm/Gauge/GaugeValueArc.js +42 -0
  57. package/esm/Gauge/GaugeValueText.js +69 -0
  58. package/esm/Gauge/gaugeClasses.js +7 -0
  59. package/esm/Gauge/index.js +7 -0
  60. package/esm/Gauge/utils.js +68 -0
  61. package/esm/LineChart/LineChart.js +31 -5
  62. package/esm/PieChart/PieArc.js +9 -9
  63. package/esm/PieChart/PieArcLabelPlot.js +13 -13
  64. package/esm/PieChart/PieChart.js +22 -0
  65. package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +2 -66
  66. package/esm/ResponsiveChartContainer/useChartContainerDimensions.js +66 -0
  67. package/esm/ScatterChart/ScatterChart.js +25 -0
  68. package/esm/hooks/useTicks.js +2 -3
  69. package/esm/index.js +2 -0
  70. package/hooks/useTicks.d.ts +1 -2
  71. package/hooks/useTicks.js +2 -3
  72. package/index.d.ts +2 -0
  73. package/index.js +23 -1
  74. package/legacy/BarChart/BarChart.js +27 -5
  75. package/legacy/ChartsGrid/ChartsGrid.js +119 -0
  76. package/legacy/ChartsGrid/chartsGridClasses.js +6 -0
  77. package/legacy/ChartsGrid/index.js +2 -0
  78. package/legacy/ChartsSurface.js +5 -3
  79. package/legacy/ChartsXAxis/ChartsXAxis.js +1 -1
  80. package/legacy/ChartsYAxis/ChartsYAxis.js +1 -1
  81. package/legacy/Gauge/Gauge.js +146 -0
  82. package/legacy/Gauge/GaugeContainer.js +215 -0
  83. package/legacy/Gauge/GaugeProvider.js +87 -0
  84. package/legacy/Gauge/GaugeReferenceArc.js +37 -0
  85. package/legacy/Gauge/GaugeValueArc.js +44 -0
  86. package/legacy/Gauge/GaugeValueText.js +66 -0
  87. package/legacy/Gauge/gaugeClasses.js +7 -0
  88. package/legacy/Gauge/index.js +7 -0
  89. package/legacy/Gauge/utils.js +84 -0
  90. package/legacy/LineChart/LineChart.js +31 -5
  91. package/legacy/PieChart/PieArc.js +10 -10
  92. package/legacy/PieChart/PieArcLabelPlot.js +14 -14
  93. package/legacy/PieChart/PieChart.js +22 -0
  94. package/legacy/ResponsiveChartContainer/ResponsiveChartContainer.js +7 -77
  95. package/legacy/ResponsiveChartContainer/useChartContainerDimensions.js +73 -0
  96. package/legacy/ScatterChart/ScatterChart.js +25 -0
  97. package/legacy/hooks/useTicks.js +2 -3
  98. package/legacy/index.js +3 -1
  99. package/modern/BarChart/BarChart.js +27 -5
  100. package/modern/ChartsGrid/ChartsGrid.js +121 -0
  101. package/modern/ChartsGrid/chartsGridClasses.js +6 -0
  102. package/modern/ChartsGrid/index.js +2 -0
  103. package/modern/ChartsSurface.js +6 -4
  104. package/modern/ChartsXAxis/ChartsXAxis.js +1 -1
  105. package/modern/ChartsYAxis/ChartsYAxis.js +1 -1
  106. package/modern/Gauge/Gauge.js +149 -0
  107. package/modern/Gauge/GaugeContainer.js +208 -0
  108. package/modern/Gauge/GaugeProvider.js +85 -0
  109. package/modern/Gauge/GaugeReferenceArc.js +35 -0
  110. package/modern/Gauge/GaugeValueArc.js +42 -0
  111. package/modern/Gauge/GaugeValueText.js +69 -0
  112. package/modern/Gauge/gaugeClasses.js +7 -0
  113. package/modern/Gauge/index.js +7 -0
  114. package/modern/Gauge/utils.js +68 -0
  115. package/modern/LineChart/LineChart.js +31 -5
  116. package/modern/PieChart/PieArc.js +9 -9
  117. package/modern/PieChart/PieArcLabelPlot.js +13 -13
  118. package/modern/PieChart/PieChart.js +22 -0
  119. package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +2 -66
  120. package/modern/ResponsiveChartContainer/useChartContainerDimensions.js +66 -0
  121. package/modern/ScatterChart/ScatterChart.js +25 -0
  122. package/modern/hooks/useTicks.js +2 -3
  123. package/modern/index.js +3 -1
  124. package/package.json +4 -4
@@ -0,0 +1,149 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
+ const _excluded = ["text", "children", "classes"];
4
+ import * as React from 'react';
5
+ import PropTypes from 'prop-types';
6
+ import composeClasses from '@mui/utils/composeClasses';
7
+ import { GaugeContainer } from './GaugeContainer';
8
+ import { GaugeValueArc } from './GaugeValueArc';
9
+ import { GaugeReferenceArc } from './GaugeReferenceArc';
10
+ import { getGaugeUtilityClass } from './gaugeClasses';
11
+ import { GaugeValueText } from './GaugeValueText';
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { jsxs as _jsxs } from "react/jsx-runtime";
14
+ const useUtilityClasses = props => {
15
+ const {
16
+ classes
17
+ } = props;
18
+ const slots = {
19
+ root: ['root'],
20
+ valueArc: ['valueArc'],
21
+ referenceArc: ['referenceArc'],
22
+ valueText: ['valueText']
23
+ };
24
+ return composeClasses(slots, getGaugeUtilityClass, classes);
25
+ };
26
+ function Gauge(props) {
27
+ const {
28
+ text,
29
+ children
30
+ } = props,
31
+ other = _objectWithoutPropertiesLoose(props, _excluded);
32
+ const classes = useUtilityClasses(props);
33
+ return /*#__PURE__*/_jsxs(GaugeContainer, _extends({}, other, {
34
+ className: classes.root,
35
+ children: [/*#__PURE__*/_jsx(GaugeReferenceArc, {
36
+ className: classes.referenceArc
37
+ }), /*#__PURE__*/_jsx(GaugeValueArc, {
38
+ className: classes.valueArc
39
+ }), /*#__PURE__*/_jsx(GaugeValueText, {
40
+ className: classes.valueText,
41
+ text: text
42
+ }), children]
43
+ }));
44
+ }
45
+ process.env.NODE_ENV !== "production" ? Gauge.propTypes = {
46
+ // ----------------------------- Warning --------------------------------
47
+ // | These PropTypes are generated from the TypeScript type definitions |
48
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
49
+ // ----------------------------------------------------------------------
50
+ children: PropTypes.node,
51
+ classes: PropTypes.object,
52
+ className: PropTypes.string,
53
+ /**
54
+ * The radius applied to arc corners (similar to border radius).
55
+ * Set it to '50%' to get rounded arc.
56
+ * @default 0
57
+ */
58
+ cornerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
59
+ /**
60
+ * The x coordinate of the arc center.
61
+ * Can be a number (in px) or a string with a percentage such as '50%'.
62
+ * The '100%' is the width the drawing area.
63
+ */
64
+ cx: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
65
+ /**
66
+ * The y coordinate of the arc center.
67
+ * Can be a number (in px) or a string with a percentage such as '50%'.
68
+ * The '100%' is the height the drawing area.
69
+ */
70
+ cy: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
71
+ desc: PropTypes.string,
72
+ /**
73
+ * If `true`, the charts will not listen to the mouse move event.
74
+ * It might break interactive features, but will improve performance.
75
+ * @default false
76
+ */
77
+ disableAxisListener: PropTypes.bool,
78
+ /**
79
+ * The end angle (deg).
80
+ * @default 360
81
+ */
82
+ endAngle: PropTypes.number,
83
+ /**
84
+ * The height of the chart in px. If not defined, it takes the height of the parent element.
85
+ * @default undefined
86
+ */
87
+ height: PropTypes.number,
88
+ /**
89
+ * The radius between circle center and the begining of the arc.
90
+ * Can be a number (in px) or a string with a percentage such as '50%'.
91
+ * The '100%' is the maximal radius that fit into the drawing area.
92
+ * @default '80%'
93
+ */
94
+ innerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
95
+ /**
96
+ * The margin between the SVG and the drawing area.
97
+ * It's used for leaving some space for extra information such as the x- and y-axis or legend.
98
+ * Accepts an object with the optional properties: `top`, `bottom`, `left`, and `right`.
99
+ * @default object Depends on the charts type.
100
+ */
101
+ margin: PropTypes.shape({
102
+ bottom: PropTypes.number,
103
+ left: PropTypes.number,
104
+ right: PropTypes.number,
105
+ top: PropTypes.number
106
+ }),
107
+ /**
108
+ * The radius between circle center and the end of the arc.
109
+ * Can be a number (in px) or a string with a percentage such as '50%'.
110
+ * The '100%' is the maximal radius that fit into the drawing area.
111
+ * @default '100%'
112
+ */
113
+ outerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
114
+ /**
115
+ * The start angle (deg).
116
+ * @default 0
117
+ */
118
+ startAngle: PropTypes.number,
119
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
120
+ text: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
121
+ title: PropTypes.string,
122
+ /**
123
+ * The value of the gauge.
124
+ * Set to `null` to not display a value.
125
+ */
126
+ value: PropTypes.number,
127
+ /**
128
+ * The maximal value of the gauge.
129
+ * @default 100
130
+ */
131
+ valueMax: PropTypes.number,
132
+ /**
133
+ * The minimal value of the gauge.
134
+ * @default 0
135
+ */
136
+ valueMin: PropTypes.number,
137
+ viewBox: PropTypes.shape({
138
+ height: PropTypes.number,
139
+ width: PropTypes.number,
140
+ x: PropTypes.number,
141
+ y: PropTypes.number
142
+ }),
143
+ /**
144
+ * The width of the chart in px. If not defined, it takes the width of the parent element.
145
+ * @default undefined
146
+ */
147
+ width: PropTypes.number
148
+ } : void 0;
149
+ export { Gauge };
@@ -0,0 +1,211 @@
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
+ var _ownerState$width, _ownerState$height;
21
+ return {
22
+ width: (_ownerState$width = ownerState.width) != null ? _ownerState$width : '100%',
23
+ height: (_ownerState$height = ownerState.height) != null ? _ownerState$height : '100%',
24
+ display: 'flex',
25
+ position: 'relative',
26
+ flexGrow: 1,
27
+ flexDirection: 'column',
28
+ alignItems: 'center',
29
+ justifyContent: 'center',
30
+ overflow: 'hidden',
31
+ '&>svg': {
32
+ width: '100%',
33
+ height: '100%'
34
+ },
35
+ '& text': {
36
+ fill: (theme.vars || theme).palette.text.primary
37
+ }
38
+ };
39
+ });
40
+ const GaugeContainer = /*#__PURE__*/React.forwardRef(function GaugeContainer(props, ref) {
41
+ const {
42
+ width: inWidth,
43
+ height: inHeight,
44
+ margin,
45
+ title,
46
+ desc,
47
+ value,
48
+ valueMin = 0,
49
+ valueMax = 100,
50
+ startAngle,
51
+ endAngle,
52
+ outerRadius,
53
+ innerRadius,
54
+ cornerRadius,
55
+ cx,
56
+ cy,
57
+ children
58
+ } = props,
59
+ other = _objectWithoutPropertiesLoose(props, _excluded);
60
+ const [containerRef, width, height] = useChartContainerDimensions(inWidth, inHeight);
61
+ const svgRef = React.useRef(null);
62
+ const handleRef = useForkRef(ref, svgRef);
63
+ return /*#__PURE__*/_jsx(ResizableContainer, _extends({
64
+ ref: containerRef,
65
+ ownerState: {
66
+ width: inWidth,
67
+ height: inHeight
68
+ },
69
+ role: "meter",
70
+ "aria-valuenow": value === null ? undefined : value,
71
+ "aria-valuemin": valueMin,
72
+ "aria-valuemax": valueMax
73
+ }, other, {
74
+ children: width && height ? /*#__PURE__*/_jsx(DrawingProvider, {
75
+ width: width,
76
+ height: height,
77
+ margin: _extends({
78
+ left: 10,
79
+ right: 10,
80
+ top: 10,
81
+ bottom: 10
82
+ }, margin),
83
+ svgRef: svgRef,
84
+ children: /*#__PURE__*/_jsx(GaugeProvider, {
85
+ value: value,
86
+ valueMin: valueMin,
87
+ valueMax: valueMax,
88
+ startAngle: startAngle,
89
+ endAngle: endAngle,
90
+ outerRadius: outerRadius,
91
+ innerRadius: innerRadius,
92
+ cornerRadius: cornerRadius,
93
+ cx: cx,
94
+ cy: cy,
95
+ children: /*#__PURE__*/_jsx(ChartsSurface, {
96
+ width: width,
97
+ height: height,
98
+ ref: handleRef,
99
+ title: title,
100
+ desc: desc,
101
+ disableAxisListener: true,
102
+ "aria-hidden": "true",
103
+ children: children
104
+ })
105
+ })
106
+ }) : null
107
+ }));
108
+ });
109
+ process.env.NODE_ENV !== "production" ? GaugeContainer.propTypes = {
110
+ // ----------------------------- Warning --------------------------------
111
+ // | These PropTypes are generated from the TypeScript type definitions |
112
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
113
+ // ----------------------------------------------------------------------
114
+ children: PropTypes.node,
115
+ className: PropTypes.string,
116
+ /**
117
+ * The radius applied to arc corners (similar to border radius).
118
+ * Set it to '50%' to get rounded arc.
119
+ * @default 0
120
+ */
121
+ cornerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
122
+ /**
123
+ * The x coordinate of the arc center.
124
+ * Can be a number (in px) or a string with a percentage such as '50%'.
125
+ * The '100%' is the width the drawing area.
126
+ */
127
+ cx: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
128
+ /**
129
+ * The y coordinate of the arc center.
130
+ * Can be a number (in px) or a string with a percentage such as '50%'.
131
+ * The '100%' is the height the drawing area.
132
+ */
133
+ cy: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
134
+ desc: PropTypes.string,
135
+ /**
136
+ * If `true`, the charts will not listen to the mouse move event.
137
+ * It might break interactive features, but will improve performance.
138
+ * @default false
139
+ */
140
+ disableAxisListener: PropTypes.bool,
141
+ /**
142
+ * The end angle (deg).
143
+ * @default 360
144
+ */
145
+ endAngle: PropTypes.number,
146
+ /**
147
+ * The height of the chart in px. If not defined, it takes the height of the parent element.
148
+ * @default undefined
149
+ */
150
+ height: PropTypes.number,
151
+ /**
152
+ * The radius between circle center and the begining of the arc.
153
+ * Can be a number (in px) or a string with a percentage such as '50%'.
154
+ * The '100%' is the maximal radius that fit into the drawing area.
155
+ * @default '80%'
156
+ */
157
+ innerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
158
+ /**
159
+ * The margin between the SVG and the drawing area.
160
+ * It's used for leaving some space for extra information such as the x- and y-axis or legend.
161
+ * Accepts an object with the optional properties: `top`, `bottom`, `left`, and `right`.
162
+ * @default object Depends on the charts type.
163
+ */
164
+ margin: PropTypes.shape({
165
+ bottom: PropTypes.number,
166
+ left: PropTypes.number,
167
+ right: PropTypes.number,
168
+ top: PropTypes.number
169
+ }),
170
+ /**
171
+ * The radius between circle center and the end of the arc.
172
+ * Can be a number (in px) or a string with a percentage such as '50%'.
173
+ * The '100%' is the maximal radius that fit into the drawing area.
174
+ * @default '100%'
175
+ */
176
+ outerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
177
+ /**
178
+ * The start angle (deg).
179
+ * @default 0
180
+ */
181
+ startAngle: PropTypes.number,
182
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
183
+ title: PropTypes.string,
184
+ /**
185
+ * The value of the gauge.
186
+ * Set to `null` to not display a value.
187
+ */
188
+ value: PropTypes.number,
189
+ /**
190
+ * The maximal value of the gauge.
191
+ * @default 100
192
+ */
193
+ valueMax: PropTypes.number,
194
+ /**
195
+ * The minimal value of the gauge.
196
+ * @default 0
197
+ */
198
+ valueMin: PropTypes.number,
199
+ viewBox: PropTypes.shape({
200
+ height: PropTypes.number,
201
+ width: PropTypes.number,
202
+ x: PropTypes.number,
203
+ y: PropTypes.number
204
+ }),
205
+ /**
206
+ * The width of the chart in px. If not defined, it takes the width of the parent element.
207
+ * @default undefined
208
+ */
209
+ width: PropTypes.number
210
+ } : void 0;
211
+ 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 != null ? outerRadiusParam : maxRadius, maxRadius);
58
+ const innerRadius = getPercentageValue(innerRadiusParam != null ? innerRadiusParam : '80%', maxRadius);
59
+ const cornerRadius = getPercentageValue(cornerRadiusParam != null ? 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,7 @@
1
+ export * from './Gauge';
2
+ export * from './GaugeContainer';
3
+ export * from './GaugeValueText';
4
+ export * from './GaugeValueArc';
5
+ export * from './GaugeReferenceArc';
6
+ export * from './gaugeClasses';
7
+ export { useGaugeState } from './GaugeProvider';
@@ -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
+ }