@mui/x-charts 6.18.3 → 6.18.7
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/BarPlot.js +7 -6
- package/BarChart/formatter.js +15 -3
- package/CHANGELOG.md +175 -1
- package/ChartsAxis/ChartsAxis.js +4 -4
- package/ChartsLegend/ChartsLegend.d.ts +1 -1
- package/ChartsLegend/ChartsLegend.js +3 -2
- package/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/ChartsReferenceLine/common.d.ts +1 -1
- package/ChartsText/ChartsText.d.ts +17 -0
- package/{internals/components → ChartsText}/ChartsText.js +32 -17
- package/ChartsText/index.d.ts +3 -0
- package/ChartsText/index.js +12 -0
- package/ChartsText/package.json +6 -0
- package/ChartsXAxis/ChartsXAxis.js +3 -2
- package/ChartsYAxis/ChartsYAxis.js +1 -1
- package/LineChart/AreaPlot.js +3 -2
- package/LineChart/LineHighlightPlot.js +2 -1
- package/LineChart/LinePlot.js +3 -2
- package/LineChart/MarkPlot.js +2 -1
- package/LineChart/formatter.js +14 -2
- package/PieChart/PieArcLabelPlot.d.ts +2 -3
- package/PieChart/PieArcLabelPlot.js +0 -1
- package/PieChart/PieArcPlot.d.ts +2 -3
- package/PieChart/PieArcPlot.js +0 -1
- package/PieChart/PieChart.js +4 -4
- package/PieChart/PiePlot.js +20 -15
- package/PieChart/dataTransform/useTransformData.d.ts +2 -3
- package/ResponsiveChartContainer/index.js +2 -2
- package/context/CartesianContextProvider.js +2 -2
- package/context/SeriesContextProvider.js +1 -1
- package/esm/BarChart/BarPlot.js +7 -5
- package/esm/BarChart/formatter.js +20 -4
- package/esm/ChartsAxis/ChartsAxis.js +4 -4
- package/esm/ChartsLegend/ChartsLegend.js +2 -1
- package/esm/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/esm/{internals/components → ChartsText}/ChartsText.js +33 -16
- package/esm/ChartsText/index.js +1 -0
- package/esm/ChartsXAxis/ChartsXAxis.js +2 -1
- package/esm/ChartsYAxis/ChartsYAxis.js +1 -1
- package/esm/LineChart/AreaPlot.js +3 -2
- package/esm/LineChart/LineHighlightPlot.js +2 -1
- package/esm/LineChart/LinePlot.js +3 -2
- package/esm/LineChart/MarkPlot.js +2 -1
- package/esm/LineChart/formatter.js +16 -3
- package/esm/PieChart/PieArcLabelPlot.js +0 -1
- package/esm/PieChart/PieArcPlot.js +0 -1
- package/esm/PieChart/PieChart.js +4 -4
- package/esm/PieChart/PiePlot.js +20 -15
- package/esm/ResponsiveChartContainer/index.js +2 -2
- package/esm/context/CartesianContextProvider.js +2 -2
- package/esm/context/SeriesContextProvider.js +1 -1
- package/esm/index.js +1 -0
- package/esm/internals/getWordsByLines.js +14 -0
- package/esm/internals/utils.js +40 -0
- package/index.d.ts +1 -0
- package/index.js +12 -1
- package/internals/defaultizeColor.d.ts +4 -4
- package/internals/{components/ChartsText.d.ts → getWordsByLines.d.ts} +2 -11
- package/internals/getWordsByLines.js +21 -0
- package/internals/utils.d.ts +13 -0
- package/internals/utils.js +42 -0
- package/legacy/BarChart/BarPlot.js +7 -5
- package/legacy/BarChart/formatter.js +23 -9
- package/legacy/ChartsAxis/ChartsAxis.js +4 -4
- package/legacy/ChartsLegend/ChartsLegend.js +2 -1
- package/legacy/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/legacy/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/legacy/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/legacy/{internals/components → ChartsText}/ChartsText.js +38 -22
- package/legacy/ChartsText/index.js +1 -0
- package/legacy/ChartsXAxis/ChartsXAxis.js +2 -1
- package/legacy/ChartsYAxis/ChartsYAxis.js +1 -1
- package/legacy/LineChart/AreaPlot.js +3 -2
- package/legacy/LineChart/LineHighlightPlot.js +2 -1
- package/legacy/LineChart/LinePlot.js +3 -2
- package/legacy/LineChart/MarkPlot.js +2 -1
- package/legacy/LineChart/formatter.js +19 -8
- package/legacy/PieChart/PieArcLabelPlot.js +0 -1
- package/legacy/PieChart/PieArcPlot.js +0 -1
- package/legacy/PieChart/PieChart.js +4 -4
- package/legacy/PieChart/PiePlot.js +20 -15
- package/legacy/ResponsiveChartContainer/index.js +2 -2
- package/legacy/context/CartesianContextProvider.js +2 -2
- package/legacy/context/SeriesContextProvider.js +1 -1
- package/legacy/index.js +2 -1
- package/legacy/internals/getWordsByLines.js +15 -0
- package/legacy/internals/utils.js +40 -0
- package/models/axis.d.ts +1 -1
- package/models/seriesType/config.d.ts +4 -3
- package/models/seriesType/pie.d.ts +29 -7
- package/modern/BarChart/BarPlot.js +7 -5
- package/modern/BarChart/formatter.js +15 -3
- package/modern/ChartsAxis/ChartsAxis.js +4 -4
- package/modern/ChartsLegend/ChartsLegend.js +2 -1
- package/modern/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/modern/{internals/components → ChartsText}/ChartsText.js +33 -16
- package/modern/ChartsText/index.js +1 -0
- package/modern/ChartsXAxis/ChartsXAxis.js +2 -1
- package/modern/ChartsYAxis/ChartsYAxis.js +1 -1
- package/modern/LineChart/AreaPlot.js +3 -2
- package/modern/LineChart/LineHighlightPlot.js +2 -1
- package/modern/LineChart/LinePlot.js +3 -2
- package/modern/LineChart/MarkPlot.js +2 -1
- package/modern/LineChart/formatter.js +14 -2
- package/modern/PieChart/PieArcLabelPlot.js +0 -1
- package/modern/PieChart/PieArcPlot.js +0 -1
- package/modern/PieChart/PieChart.js +4 -4
- package/modern/PieChart/PiePlot.js +20 -15
- package/modern/ResponsiveChartContainer/index.js +2 -2
- package/modern/context/CartesianContextProvider.js +2 -2
- package/modern/context/SeriesContextProvider.js +1 -1
- package/modern/index.js +2 -1
- package/modern/internals/getWordsByLines.js +14 -0
- package/modern/internals/utils.js +40 -0
- package/package.json +1 -1
|
@@ -1,35 +1,26 @@
|
|
|
1
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
3
|
var _excluded = ["x", "y", "style", "text", "ownerState"],
|
|
4
4
|
_excluded2 = ["angle", "textAnchor", "dominantBaseline"];
|
|
5
5
|
import * as React from 'react';
|
|
6
|
-
import
|
|
6
|
+
import PropTypes from 'prop-types';
|
|
7
|
+
import { getWordsByLines } from '../internals/getWordsByLines';
|
|
7
8
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return text.split('\n').map(function (subText) {
|
|
13
|
-
return _extends({
|
|
14
|
-
text: subText
|
|
15
|
-
}, needsComputation ? getStringSize(subText, style) : {
|
|
16
|
-
width: 0,
|
|
17
|
-
height: 0
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
export function ChartsText(props) {
|
|
9
|
+
/**
|
|
10
|
+
* Helper component to manage multiline text in SVG
|
|
11
|
+
*/
|
|
12
|
+
function ChartsText(props) {
|
|
22
13
|
var x = props.x,
|
|
23
14
|
y = props.y,
|
|
24
15
|
styleProps = props.style,
|
|
25
16
|
text = props.text,
|
|
26
17
|
ownerState = props.ownerState,
|
|
27
18
|
textProps = _objectWithoutProperties(props, _excluded);
|
|
28
|
-
var
|
|
29
|
-
angle =
|
|
30
|
-
textAnchor =
|
|
31
|
-
dominantBaseline =
|
|
32
|
-
style = _objectWithoutProperties(
|
|
19
|
+
var _ref = styleProps != null ? styleProps : {},
|
|
20
|
+
angle = _ref.angle,
|
|
21
|
+
textAnchor = _ref.textAnchor,
|
|
22
|
+
dominantBaseline = _ref.dominantBaseline,
|
|
23
|
+
style = _objectWithoutProperties(_ref, _excluded2);
|
|
33
24
|
var wordsByLines = React.useMemo(function () {
|
|
34
25
|
return getWordsByLines({
|
|
35
26
|
style: style,
|
|
@@ -76,4 +67,29 @@ export function ChartsText(props) {
|
|
|
76
67
|
}, index);
|
|
77
68
|
})
|
|
78
69
|
}));
|
|
79
|
-
}
|
|
70
|
+
}
|
|
71
|
+
process.env.NODE_ENV !== "production" ? ChartsText.propTypes = {
|
|
72
|
+
// ----------------------------- Warning --------------------------------
|
|
73
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
74
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
75
|
+
// ----------------------------------------------------------------------
|
|
76
|
+
/**
|
|
77
|
+
* Height of a text line (in `em`).
|
|
78
|
+
*/
|
|
79
|
+
lineHeight: PropTypes.number,
|
|
80
|
+
/**
|
|
81
|
+
* If `true`, the line width is computed.
|
|
82
|
+
* @default false
|
|
83
|
+
*/
|
|
84
|
+
needsComputation: PropTypes.bool,
|
|
85
|
+
ownerState: PropTypes.any,
|
|
86
|
+
/**
|
|
87
|
+
* Style applied to text elements.
|
|
88
|
+
*/
|
|
89
|
+
style: PropTypes.object,
|
|
90
|
+
/**
|
|
91
|
+
* Text displayed.
|
|
92
|
+
*/
|
|
93
|
+
text: PropTypes.string.isRequired
|
|
94
|
+
} : void 0;
|
|
95
|
+
export { ChartsText };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ChartsText } from './ChartsText';
|
|
@@ -12,9 +12,10 @@ import { DrawingContext } from '../context/DrawingProvider';
|
|
|
12
12
|
import useTicks from '../hooks/useTicks';
|
|
13
13
|
import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
|
|
14
14
|
import { AxisRoot } from '../internals/components/AxisSharedComponents';
|
|
15
|
-
import { ChartsText
|
|
15
|
+
import { ChartsText } from '../ChartsText';
|
|
16
16
|
import { getMinXTranslation } from '../internals/geometry';
|
|
17
17
|
import { useMounted } from '../hooks/useMounted';
|
|
18
|
+
import { getWordsByLines } from '../internals/getWordsByLines';
|
|
18
19
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
19
20
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
20
21
|
var useUtilityClasses = function useUtilityClasses(ownerState) {
|
|
@@ -10,7 +10,7 @@ import { CartesianContext } from '../context/CartesianContextProvider';
|
|
|
10
10
|
import { DrawingContext } from '../context/DrawingProvider';
|
|
11
11
|
import useTicks from '../hooks/useTicks';
|
|
12
12
|
import { AxisRoot } from '../internals/components/AxisSharedComponents';
|
|
13
|
-
import { ChartsText } from '../
|
|
13
|
+
import { ChartsText } from '../ChartsText';
|
|
14
14
|
import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
|
|
15
15
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
16
16
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -9,6 +9,7 @@ import { CartesianContext } from '../context/CartesianContextProvider';
|
|
|
9
9
|
import { AreaElement } from './AreaElement';
|
|
10
10
|
import { getValueToPositionMapper } from '../hooks/useScale';
|
|
11
11
|
import getCurveFactory from '../internals/getCurve';
|
|
12
|
+
import { DEFAULT_X_AXIS_KEY } from '../constants';
|
|
12
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
14
|
/**
|
|
14
15
|
* Demos:
|
|
@@ -56,10 +57,10 @@ function AreaPlot(props) {
|
|
|
56
57
|
var xData = xAxis[xAxisKey].data;
|
|
57
58
|
if (process.env.NODE_ENV !== 'production') {
|
|
58
59
|
if (xData === undefined) {
|
|
59
|
-
throw new Error("
|
|
60
|
+
throw new Error("MUI-X-Charts: ".concat(xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : "The x-axis with id \"".concat(xAxisKey, "\""), " should have data property to be able to display a line plot."));
|
|
60
61
|
}
|
|
61
62
|
if (xData.length < stackedData.length) {
|
|
62
|
-
throw new Error("MUI: data length of the x axis (".concat(xData.length, " items) is lower than the length of series (").concat(stackedData.length, " items)"));
|
|
63
|
+
throw new Error("MUI-X-Charts: The data length of the x axis (".concat(xData.length, " items) is lower than the length of series (").concat(stackedData.length, " items)"));
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
66
|
var areaPath = d3Area().x(function (d) {
|
|
@@ -8,6 +8,7 @@ import { CartesianContext } from '../context/CartesianContextProvider';
|
|
|
8
8
|
import { LineHighlightElement } from './LineHighlightElement';
|
|
9
9
|
import { getValueToPositionMapper } from '../hooks/useScale';
|
|
10
10
|
import { InteractionContext } from '../context/InteractionProvider';
|
|
11
|
+
import { DEFAULT_X_AXIS_KEY } from '../constants';
|
|
11
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
13
|
/**
|
|
13
14
|
* Demos:
|
|
@@ -63,7 +64,7 @@ function LineHighlightPlot(props) {
|
|
|
63
64
|
var yScale = yAxis[yAxisKey].scale;
|
|
64
65
|
var xData = xAxis[xAxisKey].data;
|
|
65
66
|
if (xData === undefined) {
|
|
66
|
-
throw new Error("
|
|
67
|
+
throw new Error("MUI-X-Charts: ".concat(xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : "The x-axis with id \"".concat(xAxisKey, "\""), " should have data property to be able to display a line plot."));
|
|
67
68
|
}
|
|
68
69
|
var x = xScale(xData[highlightedIndex]);
|
|
69
70
|
var y = yScale(stackedData[highlightedIndex][1]); // This should not be undefined since y should not be a band scale
|
|
@@ -9,6 +9,7 @@ import { CartesianContext } from '../context/CartesianContextProvider';
|
|
|
9
9
|
import { LineElement } from './LineElement';
|
|
10
10
|
import { getValueToPositionMapper } from '../hooks/useScale';
|
|
11
11
|
import getCurveFactory from '../internals/getCurve';
|
|
12
|
+
import { DEFAULT_X_AXIS_KEY } from '../constants';
|
|
12
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
14
|
/**
|
|
14
15
|
* Demos:
|
|
@@ -55,10 +56,10 @@ function LinePlot(props) {
|
|
|
55
56
|
var xData = xAxis[xAxisKey].data;
|
|
56
57
|
if (process.env.NODE_ENV !== 'production') {
|
|
57
58
|
if (xData === undefined) {
|
|
58
|
-
throw new Error("
|
|
59
|
+
throw new Error("MUI-X-Charts: ".concat(xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : "The x-axis with id \"".concat(xAxisKey, "\""), " should have data property to be able to display a line plot"));
|
|
59
60
|
}
|
|
60
61
|
if (xData.length < stackedData.length) {
|
|
61
|
-
throw new Error("MUI: data length of the x axis (".concat(xData.length, " items) is lower than the length of series (").concat(stackedData.length, " items)"));
|
|
62
|
+
throw new Error("MUI-X-Charts: The data length of the x axis (".concat(xData.length, " items) is lower than the length of series (").concat(stackedData.length, " items)"));
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
var linePath = d3Line().x(function (d) {
|
|
@@ -8,6 +8,7 @@ import { SeriesContext } from '../context/SeriesContextProvider';
|
|
|
8
8
|
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
9
9
|
import { MarkElement } from './MarkElement';
|
|
10
10
|
import { getValueToPositionMapper } from '../hooks/useScale';
|
|
11
|
+
import { DEFAULT_X_AXIS_KEY } from '../constants';
|
|
11
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
13
|
/**
|
|
13
14
|
* Demos:
|
|
@@ -71,7 +72,7 @@ function MarkPlot(props) {
|
|
|
71
72
|
return true;
|
|
72
73
|
};
|
|
73
74
|
if (xData === undefined) {
|
|
74
|
-
throw new Error("
|
|
75
|
+
throw new Error("MUI-X-Charts: ".concat(xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : "The x-axis with id \"".concat(xAxisKey, "\""), " should have data property to be able to display a line plot"));
|
|
75
76
|
}
|
|
76
77
|
return xData == null ? void 0 : xData.map(function (x, index) {
|
|
77
78
|
var value = data[index] == null ? null : stackedData[index][1];
|
|
@@ -4,14 +4,17 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
|
4
4
|
import { stack as d3Stack } from 'd3-shape';
|
|
5
5
|
import { getStackingGroups } from '../internals/stackSeries';
|
|
6
6
|
import defaultizeValueFormatter from '../internals/defaultizeValueFormatter';
|
|
7
|
+
var warnedOnce = false;
|
|
8
|
+
|
|
7
9
|
// For now it's a copy past of bar charts formatter, but maybe will diverge later
|
|
8
10
|
var formatter = function formatter(params, dataset) {
|
|
11
|
+
var _ref;
|
|
9
12
|
var seriesOrder = params.seriesOrder,
|
|
10
13
|
series = params.series;
|
|
11
14
|
var stackingGroups = getStackingGroups(params);
|
|
12
15
|
|
|
13
16
|
// Create a data set with format adapted to d3
|
|
14
|
-
var d3Dataset = dataset != null ?
|
|
17
|
+
var d3Dataset = (_ref = dataset) != null ? _ref : [];
|
|
15
18
|
seriesOrder.forEach(function (id) {
|
|
16
19
|
var data = series[id].data;
|
|
17
20
|
if (data !== undefined) {
|
|
@@ -23,7 +26,7 @@ var formatter = function formatter(params, dataset) {
|
|
|
23
26
|
}
|
|
24
27
|
});
|
|
25
28
|
} else if (dataset === undefined && process.env.NODE_ENV !== 'production') {
|
|
26
|
-
throw new Error(["MUI: line series with id='".concat(id, "' has no data."), 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
|
|
29
|
+
throw new Error(["MUI-X-Charts: line series with id='".concat(id, "' has no data."), 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
|
|
27
30
|
}
|
|
28
31
|
});
|
|
29
32
|
var completedSeries = {};
|
|
@@ -44,13 +47,21 @@ var formatter = function formatter(params, dataset) {
|
|
|
44
47
|
ids.forEach(function (id, index) {
|
|
45
48
|
var dataKey = series[id].dataKey;
|
|
46
49
|
completedSeries[id] = _extends({}, series[id], {
|
|
47
|
-
data: dataKey ? dataset.map(function (
|
|
48
|
-
|
|
50
|
+
data: dataKey ? dataset.map(function (data) {
|
|
51
|
+
var value = data[dataKey];
|
|
52
|
+
if (typeof value !== 'number') {
|
|
53
|
+
if (process.env.NODE_ENV !== 'production' && !warnedOnce && value !== null) {
|
|
54
|
+
warnedOnce = true;
|
|
55
|
+
console.error(["MUI-X charts: your dataset key \"".concat(dataKey, "\" is used for plotting line, but contains nonnumerical elements."), 'Line plots only support numbers and null values.']);
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
return value;
|
|
49
60
|
}) : series[id].data,
|
|
50
|
-
stackedData: stackedSeries[index].map(function (
|
|
51
|
-
var
|
|
52
|
-
a =
|
|
53
|
-
b =
|
|
61
|
+
stackedData: stackedSeries[index].map(function (_ref2) {
|
|
62
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
|
63
|
+
a = _ref3[0],
|
|
64
|
+
b = _ref3[1];
|
|
54
65
|
return [a, b];
|
|
55
66
|
})
|
|
56
67
|
});
|
|
@@ -155,7 +155,6 @@ process.env.NODE_ENV !== "production" ? PieArcLabelPlot.propTypes = {
|
|
|
155
155
|
innerRadius: PropTypes.number,
|
|
156
156
|
/**
|
|
157
157
|
* The radius between circle center and the end of the arc.
|
|
158
|
-
* @default R_max The maximal radius that fit into the drawing area.
|
|
159
158
|
*/
|
|
160
159
|
outerRadius: PropTypes.number.isRequired,
|
|
161
160
|
/**
|
|
@@ -145,7 +145,6 @@ process.env.NODE_ENV !== "production" ? PieArcPlot.propTypes = {
|
|
|
145
145
|
onClick: PropTypes.func,
|
|
146
146
|
/**
|
|
147
147
|
* The radius between circle center and the end of the arc.
|
|
148
|
-
* @default R_max The maximal radius that fit into the drawing area.
|
|
149
148
|
*/
|
|
150
149
|
outerRadius: PropTypes.number.isRequired,
|
|
151
150
|
/**
|
|
@@ -252,8 +252,8 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
|
|
|
252
252
|
arcLabelMinAngle: PropTypes.number,
|
|
253
253
|
color: PropTypes.string,
|
|
254
254
|
cornerRadius: PropTypes.number,
|
|
255
|
-
cx: PropTypes.number,
|
|
256
|
-
cy: PropTypes.number,
|
|
255
|
+
cx: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
256
|
+
cy: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
257
257
|
data: PropTypes.arrayOf(PropTypes.shape({
|
|
258
258
|
color: PropTypes.string,
|
|
259
259
|
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
@@ -282,8 +282,8 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
|
|
|
282
282
|
highlighted: PropTypes.oneOf(['item', 'none', 'series'])
|
|
283
283
|
}),
|
|
284
284
|
id: PropTypes.string,
|
|
285
|
-
innerRadius: PropTypes.number,
|
|
286
|
-
outerRadius: PropTypes.number,
|
|
285
|
+
innerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
286
|
+
outerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
287
287
|
paddingAngle: PropTypes.number,
|
|
288
288
|
sortingValues: PropTypes.oneOfType([PropTypes.oneOf(['asc', 'desc', 'none']), PropTypes.func]),
|
|
289
289
|
startAngle: PropTypes.number,
|
|
@@ -4,6 +4,7 @@ import { SeriesContext } from '../context/SeriesContextProvider';
|
|
|
4
4
|
import { DrawingContext } from '../context/DrawingProvider';
|
|
5
5
|
import { PieArcPlot } from './PieArcPlot';
|
|
6
6
|
import { PieArcLabelPlot } from './PieArcLabelPlot';
|
|
7
|
+
import { getPercentageValue } from '../internals/utils';
|
|
7
8
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
9
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
9
10
|
/**
|
|
@@ -31,30 +32,30 @@ function PiePlot(props) {
|
|
|
31
32
|
return null;
|
|
32
33
|
}
|
|
33
34
|
var availableRadius = Math.min(width, height) / 2;
|
|
34
|
-
var center = {
|
|
35
|
-
x: left + width / 2,
|
|
36
|
-
y: top + height / 2
|
|
37
|
-
};
|
|
38
35
|
var series = seriesData.series,
|
|
39
36
|
seriesOrder = seriesData.seriesOrder;
|
|
40
37
|
return /*#__PURE__*/_jsxs("g", {
|
|
41
38
|
children: [seriesOrder.map(function (seriesId) {
|
|
42
39
|
var _series$seriesId = series[seriesId],
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
innerRadiusParam = _series$seriesId.innerRadius,
|
|
41
|
+
outerRadiusParam = _series$seriesId.outerRadius,
|
|
45
42
|
cornerRadius = _series$seriesId.cornerRadius,
|
|
46
43
|
paddingAngle = _series$seriesId.paddingAngle,
|
|
47
44
|
data = _series$seriesId.data,
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
cxParam = _series$seriesId.cx,
|
|
46
|
+
cyParam = _series$seriesId.cy,
|
|
50
47
|
highlighted = _series$seriesId.highlighted,
|
|
51
48
|
faded = _series$seriesId.faded,
|
|
52
49
|
highlightScope = _series$seriesId.highlightScope;
|
|
50
|
+
var outerRadius = getPercentageValue(outerRadiusParam != null ? outerRadiusParam : availableRadius, availableRadius);
|
|
51
|
+
var innerRadius = getPercentageValue(innerRadiusParam != null ? innerRadiusParam : 0, availableRadius);
|
|
52
|
+
var cx = getPercentageValue(cxParam != null ? cxParam : '50%', width);
|
|
53
|
+
var cy = getPercentageValue(cyParam != null ? cyParam : '50%', height);
|
|
53
54
|
return /*#__PURE__*/_jsx("g", {
|
|
54
|
-
transform: "translate(".concat(
|
|
55
|
+
transform: "translate(".concat(left + cx, ", ").concat(top + cy, ")"),
|
|
55
56
|
children: /*#__PURE__*/_jsx(PieArcPlot, {
|
|
56
57
|
innerRadius: innerRadius,
|
|
57
|
-
outerRadius: outerRadius
|
|
58
|
+
outerRadius: outerRadius,
|
|
58
59
|
cornerRadius: cornerRadius,
|
|
59
60
|
paddingAngle: paddingAngle,
|
|
60
61
|
id: seriesId,
|
|
@@ -70,18 +71,22 @@ function PiePlot(props) {
|
|
|
70
71
|
}, seriesId);
|
|
71
72
|
}), seriesOrder.map(function (seriesId) {
|
|
72
73
|
var _series$seriesId2 = series[seriesId],
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
innerRadiusParam = _series$seriesId2.innerRadius,
|
|
75
|
+
outerRadiusParam = _series$seriesId2.outerRadius,
|
|
75
76
|
cornerRadius = _series$seriesId2.cornerRadius,
|
|
76
77
|
paddingAngle = _series$seriesId2.paddingAngle,
|
|
77
78
|
arcLabel = _series$seriesId2.arcLabel,
|
|
78
79
|
arcLabelMinAngle = _series$seriesId2.arcLabelMinAngle,
|
|
79
80
|
data = _series$seriesId2.data,
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
cxParam = _series$seriesId2.cx,
|
|
82
|
+
cyParam = _series$seriesId2.cy,
|
|
82
83
|
highlightScope = _series$seriesId2.highlightScope;
|
|
84
|
+
var outerRadius = getPercentageValue(outerRadiusParam != null ? outerRadiusParam : availableRadius, availableRadius);
|
|
85
|
+
var innerRadius = getPercentageValue(innerRadiusParam != null ? innerRadiusParam : 0, availableRadius);
|
|
86
|
+
var cx = getPercentageValue(cxParam != null ? cxParam : '50%', width);
|
|
87
|
+
var cy = getPercentageValue(cyParam != null ? cyParam : '50%', height);
|
|
83
88
|
return /*#__PURE__*/_jsx("g", {
|
|
84
|
-
transform: "translate(".concat(
|
|
89
|
+
transform: "translate(".concat(left + cx, ", ").concat(top + cy, ")"),
|
|
85
90
|
children: /*#__PURE__*/_jsx(PieArcLabelPlot, {
|
|
86
91
|
innerRadius: innerRadius,
|
|
87
92
|
outerRadius: outerRadius != null ? outerRadius : availableRadius,
|
|
@@ -67,11 +67,11 @@ var useChartDimensions = function useChartDimensions(inWidth, inHeight) {
|
|
|
67
67
|
}, [computeSize, inHeight, inWidth]);
|
|
68
68
|
if (process.env.NODE_ENV !== 'production') {
|
|
69
69
|
if (displayError.current && inWidth === undefined && width === 0) {
|
|
70
|
-
console.error("MUI:
|
|
70
|
+
console.error("MUI-X-Charts: ChartContainer does not have `width` prop, and its container has no `width` defined.");
|
|
71
71
|
displayError.current = false;
|
|
72
72
|
}
|
|
73
73
|
if (displayError.current && inHeight === undefined && height === 0) {
|
|
74
|
-
console.error("MUI:
|
|
74
|
+
console.error("MUI-X-Charts: ChartContainer does not have `height` prop, and its container has no `height` defined.");
|
|
75
75
|
displayError.current = false;
|
|
76
76
|
}
|
|
77
77
|
}
|
|
@@ -54,7 +54,7 @@ function CartesianContextProvider(_ref) {
|
|
|
54
54
|
return axisConfig;
|
|
55
55
|
}
|
|
56
56
|
if (dataset === undefined) {
|
|
57
|
-
throw Error('MUI: x-axis uses `dataKey` but no `dataset` is provided.');
|
|
57
|
+
throw Error('MUI-X-Charts: x-axis uses `dataKey` but no `dataset` is provided.');
|
|
58
58
|
}
|
|
59
59
|
return _extends({}, axisConfig, {
|
|
60
60
|
data: dataset.map(function (d) {
|
|
@@ -70,7 +70,7 @@ function CartesianContextProvider(_ref) {
|
|
|
70
70
|
return axisConfig;
|
|
71
71
|
}
|
|
72
72
|
if (dataset === undefined) {
|
|
73
|
-
throw Error('MUI: y-axis uses `dataKey` but no `dataset` is provided.');
|
|
73
|
+
throw Error('MUI-X-Charts: y-axis uses `dataKey` but no `dataset` is provided.');
|
|
74
74
|
}
|
|
75
75
|
return _extends({}, axisConfig, {
|
|
76
76
|
data: dataset.map(function (d) {
|
|
@@ -39,7 +39,7 @@ var formatSeries = function formatSeries(series, colors, dataset) {
|
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
if (((_seriesGroups$type = seriesGroups[type]) == null ? void 0 : _seriesGroups$type.series[id]) !== undefined) {
|
|
42
|
-
throw new Error("MUI: series' id \"".concat(id, "\" is not unique"));
|
|
42
|
+
throw new Error("MUI-X-Charts: series' id \"".concat(id, "\" is not unique"));
|
|
43
43
|
}
|
|
44
44
|
seriesGroups[type].series[id] = _extends({
|
|
45
45
|
id: id
|
package/legacy/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @mui/x-charts v6.18.
|
|
2
|
+
* @mui/x-charts v6.18.7
|
|
3
3
|
*
|
|
4
4
|
* @license MIT
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
@@ -15,6 +15,7 @@ export * from './ChartsReferenceLine';
|
|
|
15
15
|
export * from './ChartsAxis';
|
|
16
16
|
export * from './ChartsXAxis';
|
|
17
17
|
export * from './ChartsYAxis';
|
|
18
|
+
export * from './ChartsText';
|
|
18
19
|
export * from './ChartsTooltip';
|
|
19
20
|
export * from './ChartsAxisHighlight';
|
|
20
21
|
export * from './BarChart';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { getStringSize } from './domUtils';
|
|
3
|
+
export function getWordsByLines(_ref) {
|
|
4
|
+
var style = _ref.style,
|
|
5
|
+
needsComputation = _ref.needsComputation,
|
|
6
|
+
text = _ref.text;
|
|
7
|
+
return text.split('\n').map(function (subText) {
|
|
8
|
+
return _extends({
|
|
9
|
+
text: subText
|
|
10
|
+
}, needsComputation ? getStringSize(subText, style) : {
|
|
11
|
+
width: 0,
|
|
12
|
+
height: 0
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -2,4 +2,44 @@
|
|
|
2
2
|
export function getSymbol(shape) {
|
|
3
3
|
var symbolNames = 'circle cross diamond square star triangle wye'.split(/ /);
|
|
4
4
|
return symbolNames.indexOf(shape) || 0;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Transform mouse event position to corrdinates inside the SVG.
|
|
8
|
+
* @param svg The SVG element
|
|
9
|
+
* @param event The mouseEvent to transform
|
|
10
|
+
*/
|
|
11
|
+
export function getSVGPoint(svg, event) {
|
|
12
|
+
var pt = svg.createSVGPoint();
|
|
13
|
+
pt.x = event.clientX;
|
|
14
|
+
pt.y = event.clientY;
|
|
15
|
+
return pt.matrixTransform(svg.getScreenCTM().inverse());
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Helper that converts values and percentages into values.
|
|
20
|
+
* @param value The value provided by the developer. Can either be a number or a string with '%' or 'px'.
|
|
21
|
+
* @param refValue The numerical value associated to 100%.
|
|
22
|
+
* @returns The numerical value associated to the provided value.
|
|
23
|
+
*/
|
|
24
|
+
export function getPercentageValue(value, refValue) {
|
|
25
|
+
if (typeof value === 'number') {
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
if (value === '100%') {
|
|
29
|
+
// Avoid potential rounding issues
|
|
30
|
+
return refValue;
|
|
31
|
+
}
|
|
32
|
+
if (value.endsWith('%')) {
|
|
33
|
+
var percentage = Number.parseFloat(value.slice(0, value.length - 1));
|
|
34
|
+
if (!Number.isNaN(percentage)) {
|
|
35
|
+
return percentage * refValue / 100;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (value.endsWith('px')) {
|
|
39
|
+
var val = Number.parseFloat(value.slice(0, value.length - 2));
|
|
40
|
+
if (!Number.isNaN(val)) {
|
|
41
|
+
return val;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
throw Error("MUI-Charts: Received an unknown value \"".concat(value, "\". It should be a number, or a string with a percentage value."));
|
|
5
45
|
}
|
package/models/axis.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import type { ScaleBand, ScaleLogarithmic, ScalePower, ScaleTime, ScaleLinear, ScalePoint } from 'd3-scale';
|
|
3
3
|
import { ChartsAxisClasses } from '../ChartsAxis/axisClasses';
|
|
4
4
|
import type { TickParams } from '../hooks/useTicks';
|
|
5
|
-
import { ChartsTextProps } from '../
|
|
5
|
+
import { ChartsTextProps } from '../ChartsText';
|
|
6
6
|
export type D3Scale<Domain extends {
|
|
7
7
|
toString(): string;
|
|
8
8
|
} = number | Date | string, Range = number, Output = number> = ScaleBand<Domain> | ScaleLogarithmic<Range, Output> | ScalePoint<Domain> | ScalePower<Range, Output> | ScaleTime<Range, Output> | ScaleLinear<Range, Output>;
|
|
@@ -77,10 +77,11 @@ export type FormatterResult<T extends ChartSeriesType> = {
|
|
|
77
77
|
} ? {
|
|
78
78
|
stackingGroups: StackingGroupsType;
|
|
79
79
|
} : {});
|
|
80
|
-
export type
|
|
80
|
+
export type DatasetElementType<T> = {
|
|
81
81
|
[key: string]: T;
|
|
82
|
-
}
|
|
83
|
-
export type
|
|
82
|
+
};
|
|
83
|
+
export type DatasetType<T = number | string | Date | null | undefined> = DatasetElementType<T>[];
|
|
84
|
+
export type Formatter<T extends ChartSeriesType> = (params: FormatterParams<T>, dataset?: DatasetType) => FormatterResult<T>;
|
|
84
85
|
export type LegendParams = {
|
|
85
86
|
/**
|
|
86
87
|
* The color used in the legend
|
|
@@ -17,14 +17,18 @@ export interface PieSeriesType<Tdata = PieValueType> extends CommonSeriesType<Td
|
|
|
17
17
|
data: Tdata[];
|
|
18
18
|
/**
|
|
19
19
|
* The radius between circle center and the begining of the arc.
|
|
20
|
+
* Can be a number (in px) or a string with a percentage such as '50%'.
|
|
21
|
+
* The '100%' is the maximal radius that fit into the drawing area.
|
|
20
22
|
* @default 0
|
|
21
23
|
*/
|
|
22
|
-
innerRadius?: number;
|
|
24
|
+
innerRadius?: number | string;
|
|
23
25
|
/**
|
|
24
26
|
* The radius between circle center and the end of the arc.
|
|
25
|
-
*
|
|
27
|
+
* Can be a number (in px) or a string with a percentage such as '50%'.
|
|
28
|
+
* The '100%' is the maximal radius that fit into the drawing area.
|
|
29
|
+
* @default '100%'
|
|
26
30
|
*/
|
|
27
|
-
outerRadius?: number;
|
|
31
|
+
outerRadius?: number | string;
|
|
28
32
|
/**
|
|
29
33
|
* The radius applied to arc corners (similar to border radius).
|
|
30
34
|
* @default 0
|
|
@@ -56,14 +60,18 @@ export interface PieSeriesType<Tdata = PieValueType> extends CommonSeriesType<Td
|
|
|
56
60
|
arcLabelMinAngle?: number;
|
|
57
61
|
/**
|
|
58
62
|
* The x coordinate of the pie center.
|
|
59
|
-
*
|
|
63
|
+
* Can be a number (in px) or a string with a percentage such as '50%'.
|
|
64
|
+
* The '100%' is the width the drawing area.
|
|
65
|
+
* @default '50%'
|
|
60
66
|
*/
|
|
61
|
-
cx?: number;
|
|
67
|
+
cx?: number | string;
|
|
62
68
|
/**
|
|
63
69
|
* The y coordinate of the pie center.
|
|
64
|
-
*
|
|
70
|
+
* Can be a number (in px) or a string with a percentage such as '50%'.
|
|
71
|
+
* The '100%' is the height the drawing area.
|
|
72
|
+
* @default '50%'
|
|
65
73
|
*/
|
|
66
|
-
cy?: number;
|
|
74
|
+
cy?: number | string;
|
|
67
75
|
/**
|
|
68
76
|
* Override the arc attibutes when it is highlighted.
|
|
69
77
|
*/
|
|
@@ -107,3 +115,17 @@ export type PieItemIdentifier = {
|
|
|
107
115
|
export interface DefaultizedPieSeriesType extends DefaultizedProps<PieSeriesType, CommonDefaultizedProps> {
|
|
108
116
|
data: DefaultizedPieValueType[];
|
|
109
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Props received when the parent components has done the percentage conversion.
|
|
120
|
+
*/
|
|
121
|
+
export interface ComputedPieRadius {
|
|
122
|
+
/**
|
|
123
|
+
* The radius between circle center and the begining of the arc.
|
|
124
|
+
* @default 0
|
|
125
|
+
*/
|
|
126
|
+
innerRadius?: number;
|
|
127
|
+
/**
|
|
128
|
+
* The radius between circle center and the end of the arc.
|
|
129
|
+
*/
|
|
130
|
+
outerRadius: number;
|
|
131
|
+
}
|
|
@@ -8,7 +8,8 @@ import { SeriesContext } from '../context/SeriesContextProvider';
|
|
|
8
8
|
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
9
9
|
import { BarElement } from './BarElement';
|
|
10
10
|
import { isBandScaleConfig } from '../models/axis';
|
|
11
|
-
import {
|
|
11
|
+
import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
|
|
12
|
+
|
|
12
13
|
/**
|
|
13
14
|
* Solution of the equations
|
|
14
15
|
* W = barWidth * N + offset * (N-1)
|
|
@@ -18,6 +19,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
18
19
|
* @param gapRatio The ratio of the gap between bars over the bar width.
|
|
19
20
|
* @returns The bar width and the offset between bars.
|
|
20
21
|
*/
|
|
22
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
21
23
|
function getBandSize({
|
|
22
24
|
bandWidth: W,
|
|
23
25
|
numberOfGroups: N,
|
|
@@ -67,18 +69,18 @@ const useCompletedData = () => {
|
|
|
67
69
|
let baseScaleConfig;
|
|
68
70
|
if (verticalLayout) {
|
|
69
71
|
if (!isBandScaleConfig(xAxisConfig)) {
|
|
70
|
-
throw new Error(`
|
|
72
|
+
throw new Error(`MUI-X-Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} shoud be of type "band" to display the bar series of id "${seriesId}"`);
|
|
71
73
|
}
|
|
72
74
|
if (xAxis[xAxisKey].data === undefined) {
|
|
73
|
-
throw new Error(`
|
|
75
|
+
throw new Error(`MUI-X-Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} shoud have data property`);
|
|
74
76
|
}
|
|
75
77
|
baseScaleConfig = xAxisConfig;
|
|
76
78
|
} else {
|
|
77
79
|
if (!isBandScaleConfig(yAxisConfig)) {
|
|
78
|
-
throw new Error(`
|
|
80
|
+
throw new Error(`MUI-X-Charts: ${yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} shoud be of type "band" to display the bar series of id "${seriesId}"`);
|
|
79
81
|
}
|
|
80
82
|
if (yAxis[yAxisKey].data === undefined) {
|
|
81
|
-
throw new Error(`
|
|
83
|
+
throw new Error(`MUI-X-Charts: ${yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} shoud have data property`);
|
|
82
84
|
}
|
|
83
85
|
baseScaleConfig = yAxisConfig;
|
|
84
86
|
}
|