@mui/x-charts 7.0.0-beta.1 → 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 +37 -13
- package/BarChart/BarElement.d.ts +20 -13
- package/BarChart/BarElement.js +1 -0
- package/BarChart/BarPlot.d.ts +3 -5
- package/BarChart/BarPlot.js +9 -10
- package/CHANGELOG.md +223 -1
- package/ChartContainer/ChartContainer.js +6 -4
- package/ChartsAxis/ChartsAxis.js +4 -4
- 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/ChartsLegend/ChartsLegend.d.ts +5 -54
- package/ChartsLegend/ChartsLegend.js +2 -307
- package/ChartsLegend/DefaultChartsLegend.d.ts +60 -0
- package/ChartsLegend/DefaultChartsLegend.js +294 -0
- package/ChartsLegend/index.d.ts +1 -0
- package/ChartsLegend/index.js +11 -0
- package/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/ChartsReferenceLine/common.d.ts +2 -1
- package/ChartsSurface.js +6 -4
- package/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
- package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +1 -1
- package/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
- package/ChartsTooltip/utils.d.ts +1 -0
- package/ChartsTooltip/utils.js +7 -0
- package/ChartsXAxis/ChartsXAxis.js +15 -11
- package/ChartsYAxis/ChartsYAxis.js +3 -3
- 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/AnimatedArea.js +1 -1
- package/LineChart/AnimatedLine.js +1 -1
- package/LineChart/AreaElement.d.ts +2 -1
- package/LineChart/AreaElement.js +1 -1
- package/LineChart/LineChart.d.ts +24 -5
- package/LineChart/LineChart.js +41 -13
- package/LineChart/LineElement.d.ts +2 -1
- package/LineChart/LineElement.js +1 -1
- package/LineChart/LineHighlightElement.d.ts +3 -2
- package/LineChart/LineHighlightElement.js +2 -1
- package/LineChart/MarkElement.d.ts +3 -2
- package/LineChart/MarkElement.js +1 -0
- package/PieChart/PieArc.d.ts +7 -6
- package/PieChart/PieArc.js +10 -9
- package/PieChart/PieArcLabel.d.ts +3 -2
- package/PieChart/PieArcLabel.js +1 -0
- package/PieChart/PieArcLabelPlot.js +14 -14
- package/PieChart/PieArcPlot.js +1 -1
- package/PieChart/PieChart.d.ts +22 -0
- package/PieChart/PieChart.js +32 -8
- package/ResponsiveChartContainer/ResponsiveChartContainer.js +8 -70
- package/ResponsiveChartContainer/useChartContainerDimensions.d.ts +2 -0
- package/ResponsiveChartContainer/useChartContainerDimensions.js +76 -0
- package/ScatterChart/ScatterChart.d.ts +18 -0
- package/ScatterChart/ScatterChart.js +35 -8
- package/SparkLineChart/SparkLineChart.d.ts +1 -1
- package/SparkLineChart/SparkLineChart.js +5 -4
- package/context/CartesianContextProvider.js +8 -6
- package/esm/BarChart/BarChart.js +37 -13
- package/esm/BarChart/BarElement.js +1 -0
- package/esm/BarChart/BarPlot.js +8 -10
- package/esm/ChartContainer/ChartContainer.js +6 -4
- package/esm/ChartsAxis/ChartsAxis.js +4 -4
- package/esm/ChartsGrid/ChartsGrid.js +121 -0
- package/esm/ChartsGrid/chartsGridClasses.js +6 -0
- package/esm/ChartsGrid/index.js +2 -0
- package/esm/ChartsLegend/ChartsLegend.js +2 -307
- package/esm/ChartsLegend/DefaultChartsLegend.js +286 -0
- package/esm/ChartsLegend/index.js +1 -0
- package/esm/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/esm/ChartsSurface.js +6 -4
- package/esm/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
- package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +2 -2
- package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
- package/esm/ChartsTooltip/utils.js +6 -0
- package/esm/ChartsXAxis/ChartsXAxis.js +14 -10
- package/esm/ChartsYAxis/ChartsYAxis.js +2 -2
- 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/AnimatedArea.js +1 -1
- package/esm/LineChart/AnimatedLine.js +1 -1
- package/esm/LineChart/AreaElement.js +1 -1
- package/esm/LineChart/LineChart.js +41 -13
- package/esm/LineChart/LineElement.js +1 -1
- package/esm/LineChart/LineHighlightElement.js +2 -1
- package/esm/LineChart/MarkElement.js +1 -0
- package/esm/PieChart/PieArc.js +10 -9
- package/esm/PieChart/PieArcLabel.js +1 -0
- package/esm/PieChart/PieArcLabelPlot.js +14 -14
- package/esm/PieChart/PieArcPlot.js +1 -1
- package/esm/PieChart/PieChart.js +32 -8
- package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +8 -70
- package/esm/ResponsiveChartContainer/useChartContainerDimensions.js +66 -0
- package/esm/ScatterChart/ScatterChart.js +35 -8
- package/esm/SparkLineChart/SparkLineChart.js +5 -4
- package/esm/context/CartesianContextProvider.js +8 -6
- 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/internals/defaultizeColor.d.ts +16 -16
- package/internals/defaultizeValueFormatter.d.ts +4 -7
- package/internals/stackSeries.d.ts +4 -7
- package/legacy/BarChart/BarChart.js +37 -13
- package/legacy/BarChart/BarElement.js +1 -0
- package/legacy/BarChart/BarPlot.js +10 -10
- package/legacy/ChartContainer/ChartContainer.js +6 -4
- package/legacy/ChartsAxis/ChartsAxis.js +4 -4
- package/legacy/ChartsGrid/ChartsGrid.js +119 -0
- package/legacy/ChartsGrid/chartsGridClasses.js +6 -0
- package/legacy/ChartsGrid/index.js +2 -0
- package/legacy/ChartsLegend/ChartsLegend.js +2 -323
- package/legacy/ChartsLegend/DefaultChartsLegend.js +302 -0
- package/legacy/ChartsLegend/index.js +1 -0
- package/legacy/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/legacy/ChartsSurface.js +5 -3
- package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
- package/legacy/ChartsTooltip/DefaultChartsAxisTooltipContent.js +2 -2
- package/legacy/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
- package/legacy/ChartsTooltip/utils.js +6 -0
- package/legacy/ChartsXAxis/ChartsXAxis.js +13 -9
- package/legacy/ChartsYAxis/ChartsYAxis.js +2 -2
- 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/AnimatedArea.js +1 -1
- package/legacy/LineChart/AnimatedLine.js +1 -1
- package/legacy/LineChart/AreaElement.js +1 -1
- package/legacy/LineChart/LineChart.js +41 -13
- package/legacy/LineChart/LineElement.js +1 -1
- package/legacy/LineChart/LineHighlightElement.js +2 -1
- package/legacy/LineChart/MarkElement.js +1 -0
- package/legacy/PieChart/PieArc.js +11 -10
- package/legacy/PieChart/PieArcLabel.js +1 -0
- package/legacy/PieChart/PieArcLabelPlot.js +15 -15
- package/legacy/PieChart/PieArcPlot.js +1 -1
- package/legacy/PieChart/PieChart.js +32 -8
- package/legacy/ResponsiveChartContainer/ResponsiveChartContainer.js +13 -81
- package/legacy/ResponsiveChartContainer/useChartContainerDimensions.js +73 -0
- package/legacy/ScatterChart/ScatterChart.js +35 -8
- package/legacy/SparkLineChart/SparkLineChart.js +6 -5
- package/legacy/context/CartesianContextProvider.js +8 -6
- package/legacy/hooks/useTicks.js +2 -3
- package/legacy/index.js +3 -1
- package/models/axis.d.ts +7 -2
- package/models/seriesType/common.d.ts +2 -1
- package/models/seriesType/config.d.ts +7 -12
- package/models/seriesType/line.d.ts +2 -2
- package/models/seriesType/pie.d.ts +7 -3
- package/models/seriesType/scatter.d.ts +5 -2
- package/modern/BarChart/BarChart.js +37 -13
- package/modern/BarChart/BarElement.js +1 -0
- package/modern/BarChart/BarPlot.js +8 -10
- package/modern/ChartContainer/ChartContainer.js +6 -4
- package/modern/ChartsAxis/ChartsAxis.js +4 -4
- package/modern/ChartsGrid/ChartsGrid.js +121 -0
- package/modern/ChartsGrid/chartsGridClasses.js +6 -0
- package/modern/ChartsGrid/index.js +2 -0
- package/modern/ChartsLegend/ChartsLegend.js +2 -307
- package/modern/ChartsLegend/DefaultChartsLegend.js +286 -0
- package/modern/ChartsLegend/index.js +1 -0
- package/modern/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/modern/ChartsSurface.js +6 -4
- package/modern/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
- package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +2 -2
- package/modern/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
- package/modern/ChartsTooltip/utils.js +6 -0
- package/modern/ChartsXAxis/ChartsXAxis.js +14 -10
- package/modern/ChartsYAxis/ChartsYAxis.js +2 -2
- 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/AnimatedArea.js +1 -1
- package/modern/LineChart/AnimatedLine.js +1 -1
- package/modern/LineChart/AreaElement.js +1 -1
- package/modern/LineChart/LineChart.js +41 -13
- package/modern/LineChart/LineElement.js +1 -1
- package/modern/LineChart/LineHighlightElement.js +2 -1
- package/modern/LineChart/MarkElement.js +1 -0
- package/modern/PieChart/PieArc.js +10 -9
- package/modern/PieChart/PieArcLabel.js +1 -0
- package/modern/PieChart/PieArcLabelPlot.js +14 -14
- package/modern/PieChart/PieArcPlot.js +1 -1
- package/modern/PieChart/PieChart.js +32 -8
- package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +8 -70
- package/modern/ResponsiveChartContainer/useChartContainerDimensions.js +66 -0
- package/modern/ScatterChart/ScatterChart.js +35 -8
- package/modern/SparkLineChart/SparkLineChart.js +5 -4
- package/modern/context/CartesianContextProvider.js +8 -6
- package/modern/hooks/useTicks.js +2 -3
- package/modern/index.js +3 -1
- package/package.json +4 -4
package/legacy/ChartsSurface.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
-
var _excluded = ["children", "width", "height", "viewBox", "disableAxisListener", "className"];
|
|
3
|
+
var _excluded = ["children", "width", "height", "viewBox", "disableAxisListener", "className", "title", "desc"];
|
|
4
4
|
import { styled } from '@mui/material/styles';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import * as React from 'react';
|
|
@@ -21,6 +21,8 @@ var ChartsSurface = /*#__PURE__*/React.forwardRef(function ChartsSurface(props,
|
|
|
21
21
|
_props$disableAxisLis = props.disableAxisListener,
|
|
22
22
|
disableAxisListener = _props$disableAxisLis === void 0 ? false : _props$disableAxisLis,
|
|
23
23
|
className = props.className,
|
|
24
|
+
title = props.title,
|
|
25
|
+
desc = props.desc,
|
|
24
26
|
other = _objectWithoutProperties(props, _excluded);
|
|
25
27
|
var svgView = _extends({
|
|
26
28
|
width: width,
|
|
@@ -36,9 +38,9 @@ var ChartsSurface = /*#__PURE__*/React.forwardRef(function ChartsSurface(props,
|
|
|
36
38
|
ref: ref
|
|
37
39
|
}, other, {
|
|
38
40
|
children: [/*#__PURE__*/_jsx("title", {
|
|
39
|
-
children:
|
|
41
|
+
children: title
|
|
40
42
|
}), /*#__PURE__*/_jsx("desc", {
|
|
41
|
-
children:
|
|
43
|
+
children: desc
|
|
42
44
|
}), children]
|
|
43
45
|
}));
|
|
44
46
|
});
|
|
@@ -37,7 +37,7 @@ process.env.NODE_ENV !== "production" ? ChartsItemTooltipContent.propTypes = {
|
|
|
37
37
|
classes: PropTypes.object,
|
|
38
38
|
itemData: PropTypes.shape({
|
|
39
39
|
dataIndex: PropTypes.number,
|
|
40
|
-
seriesId: PropTypes.string.isRequired,
|
|
40
|
+
seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
41
41
|
type: PropTypes.oneOf(['bar', 'line', 'pie', 'scatter']).isRequired
|
|
42
42
|
}),
|
|
43
43
|
series: PropTypes.object,
|
|
@@ -45,7 +45,7 @@ process.env.NODE_ENV !== "production" ? ChartsItemTooltipContent.propTypes = {
|
|
|
45
45
|
}),
|
|
46
46
|
itemData: PropTypes.shape({
|
|
47
47
|
dataIndex: PropTypes.number,
|
|
48
|
-
seriesId: PropTypes.string.isRequired,
|
|
48
|
+
seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
49
49
|
type: PropTypes.oneOf(['bar', 'line', 'pie', 'scatter']).isRequired
|
|
50
50
|
}).isRequired,
|
|
51
51
|
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
|
|
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
|
|
|
3
3
|
import clsx from 'clsx';
|
|
4
4
|
import Typography from '@mui/material/Typography';
|
|
5
5
|
import { ChartsTooltipCell, ChartsTooltipPaper, ChartsTooltipTable, ChartsTooltipMark, ChartsTooltipRow } from './ChartsTooltipTable';
|
|
6
|
-
import { isCartesianSeries } from './utils';
|
|
6
|
+
import { isCartesianSeries, utcFormatter } from './utils';
|
|
7
7
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
8
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
9
9
|
function DefaultChartsAxisTooltipContent(props) {
|
|
@@ -18,7 +18,7 @@ function DefaultChartsAxisTooltipContent(props) {
|
|
|
18
18
|
return null;
|
|
19
19
|
}
|
|
20
20
|
var axisFormatter = (_axis$valueFormatter = axis.valueFormatter) != null ? _axis$valueFormatter : function (v) {
|
|
21
|
-
return v.toLocaleString();
|
|
21
|
+
return axis.scaleType === 'utc' ? utcFormatter(v) : v.toLocaleString();
|
|
22
22
|
};
|
|
23
23
|
return /*#__PURE__*/_jsx(ChartsTooltipPaper, {
|
|
24
24
|
sx: sx,
|
|
@@ -66,7 +66,7 @@ process.env.NODE_ENV !== "production" ? DefaultChartsItemTooltipContent.propType
|
|
|
66
66
|
*/
|
|
67
67
|
itemData: PropTypes.shape({
|
|
68
68
|
dataIndex: PropTypes.number,
|
|
69
|
-
seriesId: PropTypes.string.isRequired,
|
|
69
|
+
seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
70
70
|
type: PropTypes.oneOf(['bar', 'line', 'pie', 'scatter']).isRequired
|
|
71
71
|
}).isRequired,
|
|
72
72
|
/**
|
|
@@ -94,4 +94,10 @@ export function isCartesianSeriesType(seriesType) {
|
|
|
94
94
|
}
|
|
95
95
|
export function isCartesianSeries(series) {
|
|
96
96
|
return isCartesianSeriesType(series.type);
|
|
97
|
+
}
|
|
98
|
+
export function utcFormatter(v) {
|
|
99
|
+
if (v instanceof Date) {
|
|
100
|
+
return v.toUTCString();
|
|
101
|
+
}
|
|
102
|
+
return v.toLocaleString();
|
|
97
103
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
2
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
3
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
-
var _excluded = ["scale", "tickNumber"];
|
|
4
|
+
var _excluded = ["scale", "tickNumber", "reverse"];
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
7
7
|
import { useSlotProps } from '@mui/base/utils';
|
|
@@ -9,7 +9,7 @@ import { unstable_composeClasses as composeClasses } from '@mui/utils';
|
|
|
9
9
|
import { useThemeProps, useTheme } from '@mui/material/styles';
|
|
10
10
|
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
11
11
|
import { DrawingContext } from '../context/DrawingProvider';
|
|
12
|
-
import useTicks from '../hooks/useTicks';
|
|
12
|
+
import { useTicks } from '../hooks/useTicks';
|
|
13
13
|
import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
|
|
14
14
|
import { AxisRoot } from '../internals/components/AxisSharedComponents';
|
|
15
15
|
import { ChartsText } from '../ChartsText';
|
|
@@ -34,6 +34,7 @@ var useUtilityClasses = function useUtilityClasses(ownerState) {
|
|
|
34
34
|
function addLabelDimension(xTicks, _ref) {
|
|
35
35
|
var style = _ref.tickLabelStyle,
|
|
36
36
|
tickLabelInterval = _ref.tickLabelInterval,
|
|
37
|
+
reverse = _ref.reverse,
|
|
37
38
|
isMounted = _ref.isMounted;
|
|
38
39
|
var withDimension = xTicks.map(function (tick) {
|
|
39
40
|
if (!isMounted || tick.formattedValue === undefined) {
|
|
@@ -63,8 +64,9 @@ function addLabelDimension(xTicks, _ref) {
|
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
// Filter label to avoid overlap
|
|
66
|
-
var
|
|
67
|
-
var
|
|
67
|
+
var currentTextLimit = 0;
|
|
68
|
+
var previouseTextLimit = 0;
|
|
69
|
+
var direction = reverse ? -1 : 1;
|
|
68
70
|
return withDimension.map(function (item, labelIndex) {
|
|
69
71
|
var width = item.width,
|
|
70
72
|
offset = item.offset,
|
|
@@ -74,15 +76,15 @@ function addLabelDimension(xTicks, _ref) {
|
|
|
74
76
|
var textPosition = offset + labelOffset;
|
|
75
77
|
var gapRatio = 1.2; // Ratio applied to the minimal distance to add some margin.
|
|
76
78
|
|
|
77
|
-
|
|
78
|
-
if (labelIndex > 0 &&
|
|
79
|
+
currentTextLimit = textPosition - direction * (gapRatio * distance) / 2;
|
|
80
|
+
if (labelIndex > 0 && direction * currentTextLimit < direction * previouseTextLimit) {
|
|
79
81
|
// Except for the first label, we skip all label that overlap with the last accepted.
|
|
80
|
-
// Notice that the early return prevents `
|
|
82
|
+
// Notice that the early return prevents `previouseTextLimit` from being updated.
|
|
81
83
|
return _extends({}, item, {
|
|
82
84
|
skipLabel: true
|
|
83
85
|
});
|
|
84
86
|
}
|
|
85
|
-
|
|
87
|
+
previouseTextLimit = textPosition + direction * (gapRatio * distance) / 2;
|
|
86
88
|
return item;
|
|
87
89
|
});
|
|
88
90
|
}
|
|
@@ -114,6 +116,7 @@ function ChartsXAxis(inProps) {
|
|
|
114
116
|
_React$useContext2$xA = _React$useContext2.xAxis[(_props$axisId = props.axisId) != null ? _props$axisId : xAxisIds[0]],
|
|
115
117
|
xScale = _React$useContext2$xA.scale,
|
|
116
118
|
tickNumber = _React$useContext2$xA.tickNumber,
|
|
119
|
+
reverse = _React$useContext2$xA.reverse,
|
|
117
120
|
settings = _objectWithoutProperties(_React$useContext2$xA, _excluded);
|
|
118
121
|
var isMounted = useMounted();
|
|
119
122
|
var defaultizedProps = _extends({}, defaultProps, settings, props);
|
|
@@ -169,6 +172,7 @@ function ChartsXAxis(inProps) {
|
|
|
169
172
|
var xTicksWithDimension = addLabelDimension(xTicks, {
|
|
170
173
|
tickLabelStyle: axisTickLabelProps.style,
|
|
171
174
|
tickLabelInterval: tickLabelInterval,
|
|
175
|
+
reverse: reverse,
|
|
172
176
|
isMounted: isMounted
|
|
173
177
|
});
|
|
174
178
|
var labelRefPoint = {
|
|
@@ -231,7 +235,7 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
|
|
|
231
235
|
* The id of the axis to render.
|
|
232
236
|
* If undefined, it will be the first defined axis.
|
|
233
237
|
*/
|
|
234
|
-
axisId: PropTypes.string,
|
|
238
|
+
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
235
239
|
/**
|
|
236
240
|
* Override or extend the styles applied to the component.
|
|
237
241
|
*/
|
|
@@ -8,7 +8,7 @@ import { unstable_composeClasses as composeClasses } from '@mui/utils';
|
|
|
8
8
|
import { useThemeProps, useTheme } from '@mui/material/styles';
|
|
9
9
|
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
10
10
|
import { DrawingContext } from '../context/DrawingProvider';
|
|
11
|
-
import useTicks from '../hooks/useTicks';
|
|
11
|
+
import { useTicks } from '../hooks/useTicks';
|
|
12
12
|
import { AxisRoot } from '../internals/components/AxisSharedComponents';
|
|
13
13
|
import { ChartsText } from '../ChartsText';
|
|
14
14
|
import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
|
|
@@ -163,7 +163,7 @@ process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
|
|
|
163
163
|
* The id of the axis to render.
|
|
164
164
|
* If undefined, it will be the first defined axis.
|
|
165
165
|
*/
|
|
166
|
-
axisId: PropTypes.string,
|
|
166
|
+
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
167
167
|
/**
|
|
168
168
|
* Override or extend the styles applied to the component.
|
|
169
169
|
*/
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
+
var _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
|
+
var useUtilityClasses = function useUtilityClasses(props) {
|
|
15
|
+
var classes = props.classes;
|
|
16
|
+
var slots = {
|
|
17
|
+
root: ['root'],
|
|
18
|
+
valueArc: ['valueArc'],
|
|
19
|
+
referenceArc: ['referenceArc'],
|
|
20
|
+
valueText: ['valueText']
|
|
21
|
+
};
|
|
22
|
+
return composeClasses(slots, getGaugeUtilityClass, classes);
|
|
23
|
+
};
|
|
24
|
+
function Gauge(props) {
|
|
25
|
+
var text = props.text,
|
|
26
|
+
children = props.children,
|
|
27
|
+
propsClasses = props.classes,
|
|
28
|
+
other = _objectWithoutProperties(props, _excluded);
|
|
29
|
+
var classes = useUtilityClasses(props);
|
|
30
|
+
return /*#__PURE__*/_jsxs(GaugeContainer, _extends({}, other, {
|
|
31
|
+
className: classes.root,
|
|
32
|
+
children: [/*#__PURE__*/_jsx(GaugeReferenceArc, {
|
|
33
|
+
className: classes.referenceArc
|
|
34
|
+
}), /*#__PURE__*/_jsx(GaugeValueArc, {
|
|
35
|
+
className: classes.valueArc
|
|
36
|
+
}), /*#__PURE__*/_jsx(GaugeValueText, {
|
|
37
|
+
className: classes.valueText,
|
|
38
|
+
text: text
|
|
39
|
+
}), children]
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
process.env.NODE_ENV !== "production" ? Gauge.propTypes = {
|
|
43
|
+
// ----------------------------- Warning --------------------------------
|
|
44
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
45
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
46
|
+
// ----------------------------------------------------------------------
|
|
47
|
+
children: PropTypes.node,
|
|
48
|
+
classes: PropTypes.object,
|
|
49
|
+
className: PropTypes.string,
|
|
50
|
+
/**
|
|
51
|
+
* The radius applied to arc corners (similar to border radius).
|
|
52
|
+
* Set it to '50%' to get rounded arc.
|
|
53
|
+
* @default 0
|
|
54
|
+
*/
|
|
55
|
+
cornerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
56
|
+
/**
|
|
57
|
+
* The x coordinate of the arc center.
|
|
58
|
+
* Can be a number (in px) or a string with a percentage such as '50%'.
|
|
59
|
+
* The '100%' is the width the drawing area.
|
|
60
|
+
*/
|
|
61
|
+
cx: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
62
|
+
/**
|
|
63
|
+
* The y coordinate of the arc center.
|
|
64
|
+
* Can be a number (in px) or a string with a percentage such as '50%'.
|
|
65
|
+
* The '100%' is the height the drawing area.
|
|
66
|
+
*/
|
|
67
|
+
cy: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
68
|
+
desc: PropTypes.string,
|
|
69
|
+
/**
|
|
70
|
+
* If `true`, the charts will not listen to the mouse move event.
|
|
71
|
+
* It might break interactive features, but will improve performance.
|
|
72
|
+
* @default false
|
|
73
|
+
*/
|
|
74
|
+
disableAxisListener: PropTypes.bool,
|
|
75
|
+
/**
|
|
76
|
+
* The end angle (deg).
|
|
77
|
+
* @default 360
|
|
78
|
+
*/
|
|
79
|
+
endAngle: PropTypes.number,
|
|
80
|
+
/**
|
|
81
|
+
* The height of the chart in px. If not defined, it takes the height of the parent element.
|
|
82
|
+
* @default undefined
|
|
83
|
+
*/
|
|
84
|
+
height: PropTypes.number,
|
|
85
|
+
/**
|
|
86
|
+
* The radius between circle center and the begining of the arc.
|
|
87
|
+
* Can be a number (in px) or a string with a percentage such as '50%'.
|
|
88
|
+
* The '100%' is the maximal radius that fit into the drawing area.
|
|
89
|
+
* @default '80%'
|
|
90
|
+
*/
|
|
91
|
+
innerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
92
|
+
/**
|
|
93
|
+
* The margin between the SVG and the drawing area.
|
|
94
|
+
* It's used for leaving some space for extra information such as the x- and y-axis or legend.
|
|
95
|
+
* Accepts an object with the optional properties: `top`, `bottom`, `left`, and `right`.
|
|
96
|
+
* @default object Depends on the charts type.
|
|
97
|
+
*/
|
|
98
|
+
margin: PropTypes.shape({
|
|
99
|
+
bottom: PropTypes.number,
|
|
100
|
+
left: PropTypes.number,
|
|
101
|
+
right: PropTypes.number,
|
|
102
|
+
top: PropTypes.number
|
|
103
|
+
}),
|
|
104
|
+
/**
|
|
105
|
+
* The radius between circle center and the end of the arc.
|
|
106
|
+
* Can be a number (in px) or a string with a percentage such as '50%'.
|
|
107
|
+
* The '100%' is the maximal radius that fit into the drawing area.
|
|
108
|
+
* @default '100%'
|
|
109
|
+
*/
|
|
110
|
+
outerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
111
|
+
/**
|
|
112
|
+
* The start angle (deg).
|
|
113
|
+
* @default 0
|
|
114
|
+
*/
|
|
115
|
+
startAngle: PropTypes.number,
|
|
116
|
+
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
|
117
|
+
text: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
|
|
118
|
+
title: PropTypes.string,
|
|
119
|
+
/**
|
|
120
|
+
* The value of the gauge.
|
|
121
|
+
* Set to `null` to not display a value.
|
|
122
|
+
*/
|
|
123
|
+
value: PropTypes.number,
|
|
124
|
+
/**
|
|
125
|
+
* The maximal value of the gauge.
|
|
126
|
+
* @default 100
|
|
127
|
+
*/
|
|
128
|
+
valueMax: PropTypes.number,
|
|
129
|
+
/**
|
|
130
|
+
* The minimal value of the gauge.
|
|
131
|
+
* @default 0
|
|
132
|
+
*/
|
|
133
|
+
valueMin: PropTypes.number,
|
|
134
|
+
viewBox: PropTypes.shape({
|
|
135
|
+
height: PropTypes.number,
|
|
136
|
+
width: PropTypes.number,
|
|
137
|
+
x: PropTypes.number,
|
|
138
|
+
y: PropTypes.number
|
|
139
|
+
}),
|
|
140
|
+
/**
|
|
141
|
+
* The width of the chart in px. If not defined, it takes the width of the parent element.
|
|
142
|
+
* @default undefined
|
|
143
|
+
*/
|
|
144
|
+
width: PropTypes.number
|
|
145
|
+
} : void 0;
|
|
146
|
+
export { Gauge };
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
4
|
+
var _excluded = ["width", "height", "margin", "title", "desc", "value", "valueMin", "valueMax", "startAngle", "endAngle", "outerRadius", "innerRadius", "cornerRadius", "cx", "cy", "children"];
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
import PropTypes from 'prop-types';
|
|
7
|
+
import useForkRef from '@mui/utils/useForkRef';
|
|
8
|
+
import { styled } from '@mui/material/styles';
|
|
9
|
+
import { useChartContainerDimensions } from '../ResponsiveChartContainer/useChartContainerDimensions';
|
|
10
|
+
import { ChartsSurface } from '../ChartsSurface';
|
|
11
|
+
import { DrawingProvider } from '../context/DrawingProvider';
|
|
12
|
+
import { GaugeProvider } from './GaugeProvider';
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
var ResizableContainer = styled('div', {
|
|
15
|
+
name: 'MuiGauge',
|
|
16
|
+
slot: 'Container'
|
|
17
|
+
})(function (_ref) {
|
|
18
|
+
var _ownerState$width, _ownerState$height;
|
|
19
|
+
var ownerState = _ref.ownerState,
|
|
20
|
+
theme = _ref.theme;
|
|
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
|
+
var GaugeContainer = /*#__PURE__*/React.forwardRef(function GaugeContainer(props, ref) {
|
|
41
|
+
var inWidth = props.width,
|
|
42
|
+
inHeight = props.height,
|
|
43
|
+
margin = props.margin,
|
|
44
|
+
title = props.title,
|
|
45
|
+
desc = props.desc,
|
|
46
|
+
value = props.value,
|
|
47
|
+
_props$valueMin = props.valueMin,
|
|
48
|
+
valueMin = _props$valueMin === void 0 ? 0 : _props$valueMin,
|
|
49
|
+
_props$valueMax = props.valueMax,
|
|
50
|
+
valueMax = _props$valueMax === void 0 ? 100 : _props$valueMax,
|
|
51
|
+
startAngle = props.startAngle,
|
|
52
|
+
endAngle = props.endAngle,
|
|
53
|
+
outerRadius = props.outerRadius,
|
|
54
|
+
innerRadius = props.innerRadius,
|
|
55
|
+
cornerRadius = props.cornerRadius,
|
|
56
|
+
cx = props.cx,
|
|
57
|
+
cy = props.cy,
|
|
58
|
+
children = props.children,
|
|
59
|
+
other = _objectWithoutProperties(props, _excluded);
|
|
60
|
+
var _useChartContainerDim = useChartContainerDimensions(inWidth, inHeight),
|
|
61
|
+
_useChartContainerDim2 = _slicedToArray(_useChartContainerDim, 3),
|
|
62
|
+
containerRef = _useChartContainerDim2[0],
|
|
63
|
+
width = _useChartContainerDim2[1],
|
|
64
|
+
height = _useChartContainerDim2[2];
|
|
65
|
+
var svgRef = React.useRef(null);
|
|
66
|
+
var handleRef = useForkRef(ref, svgRef);
|
|
67
|
+
return /*#__PURE__*/_jsx(ResizableContainer, _extends({
|
|
68
|
+
ref: containerRef,
|
|
69
|
+
ownerState: {
|
|
70
|
+
width: inWidth,
|
|
71
|
+
height: inHeight
|
|
72
|
+
},
|
|
73
|
+
role: "meter",
|
|
74
|
+
"aria-valuenow": value === null ? undefined : value,
|
|
75
|
+
"aria-valuemin": valueMin,
|
|
76
|
+
"aria-valuemax": valueMax
|
|
77
|
+
}, other, {
|
|
78
|
+
children: width && height ? /*#__PURE__*/_jsx(DrawingProvider, {
|
|
79
|
+
width: width,
|
|
80
|
+
height: height,
|
|
81
|
+
margin: _extends({
|
|
82
|
+
left: 10,
|
|
83
|
+
right: 10,
|
|
84
|
+
top: 10,
|
|
85
|
+
bottom: 10
|
|
86
|
+
}, margin),
|
|
87
|
+
svgRef: svgRef,
|
|
88
|
+
children: /*#__PURE__*/_jsx(GaugeProvider, {
|
|
89
|
+
value: value,
|
|
90
|
+
valueMin: valueMin,
|
|
91
|
+
valueMax: valueMax,
|
|
92
|
+
startAngle: startAngle,
|
|
93
|
+
endAngle: endAngle,
|
|
94
|
+
outerRadius: outerRadius,
|
|
95
|
+
innerRadius: innerRadius,
|
|
96
|
+
cornerRadius: cornerRadius,
|
|
97
|
+
cx: cx,
|
|
98
|
+
cy: cy,
|
|
99
|
+
children: /*#__PURE__*/_jsx(ChartsSurface, {
|
|
100
|
+
width: width,
|
|
101
|
+
height: height,
|
|
102
|
+
ref: handleRef,
|
|
103
|
+
title: title,
|
|
104
|
+
desc: desc,
|
|
105
|
+
disableAxisListener: true,
|
|
106
|
+
"aria-hidden": "true",
|
|
107
|
+
children: children
|
|
108
|
+
})
|
|
109
|
+
})
|
|
110
|
+
}) : null
|
|
111
|
+
}));
|
|
112
|
+
});
|
|
113
|
+
process.env.NODE_ENV !== "production" ? GaugeContainer.propTypes = {
|
|
114
|
+
// ----------------------------- Warning --------------------------------
|
|
115
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
116
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
117
|
+
// ----------------------------------------------------------------------
|
|
118
|
+
children: PropTypes.node,
|
|
119
|
+
className: PropTypes.string,
|
|
120
|
+
/**
|
|
121
|
+
* The radius applied to arc corners (similar to border radius).
|
|
122
|
+
* Set it to '50%' to get rounded arc.
|
|
123
|
+
* @default 0
|
|
124
|
+
*/
|
|
125
|
+
cornerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
126
|
+
/**
|
|
127
|
+
* The x coordinate of the arc center.
|
|
128
|
+
* Can be a number (in px) or a string with a percentage such as '50%'.
|
|
129
|
+
* The '100%' is the width the drawing area.
|
|
130
|
+
*/
|
|
131
|
+
cx: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
132
|
+
/**
|
|
133
|
+
* The y coordinate of the arc center.
|
|
134
|
+
* Can be a number (in px) or a string with a percentage such as '50%'.
|
|
135
|
+
* The '100%' is the height the drawing area.
|
|
136
|
+
*/
|
|
137
|
+
cy: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
138
|
+
desc: PropTypes.string,
|
|
139
|
+
/**
|
|
140
|
+
* If `true`, the charts will not listen to the mouse move event.
|
|
141
|
+
* It might break interactive features, but will improve performance.
|
|
142
|
+
* @default false
|
|
143
|
+
*/
|
|
144
|
+
disableAxisListener: PropTypes.bool,
|
|
145
|
+
/**
|
|
146
|
+
* The end angle (deg).
|
|
147
|
+
* @default 360
|
|
148
|
+
*/
|
|
149
|
+
endAngle: PropTypes.number,
|
|
150
|
+
/**
|
|
151
|
+
* The height of the chart in px. If not defined, it takes the height of the parent element.
|
|
152
|
+
* @default undefined
|
|
153
|
+
*/
|
|
154
|
+
height: PropTypes.number,
|
|
155
|
+
/**
|
|
156
|
+
* The radius between circle center and the begining of the arc.
|
|
157
|
+
* Can be a number (in px) or a string with a percentage such as '50%'.
|
|
158
|
+
* The '100%' is the maximal radius that fit into the drawing area.
|
|
159
|
+
* @default '80%'
|
|
160
|
+
*/
|
|
161
|
+
innerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
162
|
+
/**
|
|
163
|
+
* The margin between the SVG and the drawing area.
|
|
164
|
+
* It's used for leaving some space for extra information such as the x- and y-axis or legend.
|
|
165
|
+
* Accepts an object with the optional properties: `top`, `bottom`, `left`, and `right`.
|
|
166
|
+
* @default object Depends on the charts type.
|
|
167
|
+
*/
|
|
168
|
+
margin: PropTypes.shape({
|
|
169
|
+
bottom: PropTypes.number,
|
|
170
|
+
left: PropTypes.number,
|
|
171
|
+
right: PropTypes.number,
|
|
172
|
+
top: PropTypes.number
|
|
173
|
+
}),
|
|
174
|
+
/**
|
|
175
|
+
* The radius between circle center and the end of the arc.
|
|
176
|
+
* Can be a number (in px) or a string with a percentage such as '50%'.
|
|
177
|
+
* The '100%' is the maximal radius that fit into the drawing area.
|
|
178
|
+
* @default '100%'
|
|
179
|
+
*/
|
|
180
|
+
outerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
181
|
+
/**
|
|
182
|
+
* The start angle (deg).
|
|
183
|
+
* @default 0
|
|
184
|
+
*/
|
|
185
|
+
startAngle: PropTypes.number,
|
|
186
|
+
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
|
187
|
+
title: PropTypes.string,
|
|
188
|
+
/**
|
|
189
|
+
* The value of the gauge.
|
|
190
|
+
* Set to `null` to not display a value.
|
|
191
|
+
*/
|
|
192
|
+
value: PropTypes.number,
|
|
193
|
+
/**
|
|
194
|
+
* The maximal value of the gauge.
|
|
195
|
+
* @default 100
|
|
196
|
+
*/
|
|
197
|
+
valueMax: PropTypes.number,
|
|
198
|
+
/**
|
|
199
|
+
* The minimal value of the gauge.
|
|
200
|
+
* @default 0
|
|
201
|
+
*/
|
|
202
|
+
valueMin: PropTypes.number,
|
|
203
|
+
viewBox: PropTypes.shape({
|
|
204
|
+
height: PropTypes.number,
|
|
205
|
+
width: PropTypes.number,
|
|
206
|
+
x: PropTypes.number,
|
|
207
|
+
y: PropTypes.number
|
|
208
|
+
}),
|
|
209
|
+
/**
|
|
210
|
+
* The width of the chart in px. If not defined, it takes the width of the parent element.
|
|
211
|
+
* @default undefined
|
|
212
|
+
*/
|
|
213
|
+
width: PropTypes.number
|
|
214
|
+
} : void 0;
|
|
215
|
+
export { GaugeContainer };
|
|
@@ -0,0 +1,87 @@
|
|
|
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 var 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
|
+
var _props$value = props.value,
|
|
23
|
+
value = _props$value === void 0 ? null : _props$value,
|
|
24
|
+
_props$valueMin = props.valueMin,
|
|
25
|
+
valueMin = _props$valueMin === void 0 ? 0 : _props$valueMin,
|
|
26
|
+
_props$valueMax = props.valueMax,
|
|
27
|
+
valueMax = _props$valueMax === void 0 ? 100 : _props$valueMax,
|
|
28
|
+
_props$startAngle = props.startAngle,
|
|
29
|
+
startAngle = _props$startAngle === void 0 ? 0 : _props$startAngle,
|
|
30
|
+
_props$endAngle = props.endAngle,
|
|
31
|
+
endAngle = _props$endAngle === void 0 ? 360 : _props$endAngle,
|
|
32
|
+
outerRadiusParam = props.outerRadius,
|
|
33
|
+
innerRadiusParam = props.innerRadius,
|
|
34
|
+
cornerRadiusParam = props.cornerRadius,
|
|
35
|
+
cxParam = props.cx,
|
|
36
|
+
cyParam = props.cy,
|
|
37
|
+
children = props.children;
|
|
38
|
+
var _React$useContext = React.useContext(DrawingContext),
|
|
39
|
+
width = _React$useContext.width,
|
|
40
|
+
height = _React$useContext.height,
|
|
41
|
+
top = _React$useContext.top,
|
|
42
|
+
left = _React$useContext.left;
|
|
43
|
+
var ratios = getArcRatios(startAngle, endAngle);
|
|
44
|
+
var innerCx = cxParam ? getPercentageValue(cxParam, width) : ratios.cx * width;
|
|
45
|
+
var innerCy = cyParam ? getPercentageValue(cyParam, height) : ratios.cy * height;
|
|
46
|
+
var cx = left + innerCx;
|
|
47
|
+
var cy = top + innerCy;
|
|
48
|
+
var maxRadius = getAvailableRadius(innerCx, innerCy, width, height, ratios);
|
|
49
|
+
|
|
50
|
+
// If the center is not defined, after computation of the available radius, udpate the center to use the remaining space.
|
|
51
|
+
if (cxParam === undefined) {
|
|
52
|
+
var usedWidth = maxRadius * (ratios.maxX - ratios.minX);
|
|
53
|
+
cx = left + (width - usedWidth) / 2 + ratios.cx * usedWidth;
|
|
54
|
+
}
|
|
55
|
+
if (cyParam === undefined) {
|
|
56
|
+
var usedHeight = maxRadius * (ratios.maxY - ratios.minY);
|
|
57
|
+
cy = top + (height - usedHeight) / 2 + ratios.cy * usedHeight;
|
|
58
|
+
}
|
|
59
|
+
var outerRadius = getPercentageValue(outerRadiusParam != null ? outerRadiusParam : maxRadius, maxRadius);
|
|
60
|
+
var innerRadius = getPercentageValue(innerRadiusParam != null ? innerRadiusParam : '80%', maxRadius);
|
|
61
|
+
var cornerRadius = getPercentageValue(cornerRadiusParam != null ? cornerRadiusParam : 0, outerRadius - innerRadius);
|
|
62
|
+
var contextValue = React.useMemo(function () {
|
|
63
|
+
var startAngleRad = Math.PI * startAngle / 180;
|
|
64
|
+
var endAngleRad = Math.PI * endAngle / 180;
|
|
65
|
+
return {
|
|
66
|
+
value: value,
|
|
67
|
+
valueMin: valueMin,
|
|
68
|
+
valueMax: valueMax,
|
|
69
|
+
startAngle: startAngleRad,
|
|
70
|
+
endAngle: endAngleRad,
|
|
71
|
+
outerRadius: outerRadius,
|
|
72
|
+
innerRadius: innerRadius,
|
|
73
|
+
cornerRadius: cornerRadius,
|
|
74
|
+
cx: cx,
|
|
75
|
+
cy: cy,
|
|
76
|
+
maxRadius: maxRadius,
|
|
77
|
+
valueAngle: value === null ? null : startAngleRad + (endAngleRad - startAngleRad) * (value - valueMin) / (valueMax - valueMin)
|
|
78
|
+
};
|
|
79
|
+
}, [value, valueMin, valueMax, startAngle, endAngle, outerRadius, innerRadius, cornerRadius, cx, cy, maxRadius]);
|
|
80
|
+
return /*#__PURE__*/_jsx(GaugeContext.Provider, {
|
|
81
|
+
value: contextValue,
|
|
82
|
+
children: children
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
export function useGaugeState() {
|
|
86
|
+
return React.useContext(GaugeContext);
|
|
87
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
var StyledPath = styled('path', {
|
|
8
|
+
name: 'MuiGauge',
|
|
9
|
+
slot: 'ReferenceArc',
|
|
10
|
+
overridesResolver: function overridesResolver(props, styles) {
|
|
11
|
+
return styles.referenceArc;
|
|
12
|
+
}
|
|
13
|
+
})(function (_ref) {
|
|
14
|
+
var theme = _ref.theme;
|
|
15
|
+
return {
|
|
16
|
+
fill: (theme.vars || theme).palette.divider
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
export function GaugeReferenceArc(props) {
|
|
20
|
+
var _useGaugeState = useGaugeState(),
|
|
21
|
+
startAngle = _useGaugeState.startAngle,
|
|
22
|
+
endAngle = _useGaugeState.endAngle,
|
|
23
|
+
outerRadius = _useGaugeState.outerRadius,
|
|
24
|
+
innerRadius = _useGaugeState.innerRadius,
|
|
25
|
+
cornerRadius = _useGaugeState.cornerRadius,
|
|
26
|
+
cx = _useGaugeState.cx,
|
|
27
|
+
cy = _useGaugeState.cy;
|
|
28
|
+
return /*#__PURE__*/_jsx(StyledPath, _extends({
|
|
29
|
+
transform: "translate(".concat(cx, ", ").concat(cy, ")"),
|
|
30
|
+
d: d3Arc().cornerRadius(cornerRadius)({
|
|
31
|
+
startAngle: startAngle,
|
|
32
|
+
endAngle: endAngle,
|
|
33
|
+
innerRadius: innerRadius,
|
|
34
|
+
outerRadius: outerRadius
|
|
35
|
+
})
|
|
36
|
+
}, props));
|
|
37
|
+
}
|