@mui/x-charts 6.0.0-alpha.15 → 6.0.0-alpha.17
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 +13 -2
- package/BarChart/BarChart.js +45 -3
- package/BarChart/BarElement.d.ts +1318 -3
- package/BarChart/BarElement.js +10 -8
- package/BarChart/BarPlot.d.ts +17 -1
- package/BarChart/BarPlot.js +152 -66
- package/BarChart/formatter.js +1 -1
- package/CHANGELOG.md +131 -0
- package/ChartContainer/index.js +5 -2
- package/ChartsAxis/ChartsAxis.js +18 -2
- package/ChartsAxis/axisClasses.d.ts +1 -1
- package/ChartsAxisHighlight/ChartsAxisHighlight.js +2 -2
- package/ChartsClipPath/ChartsClipPath.js +2 -2
- package/ChartsLegend/ChartsLegend.d.ts +2 -1
- package/ChartsLegend/ChartsLegend.js +12 -8
- package/ChartsSurface.js +2 -2
- package/ChartsTooltip/ChartsAxisTooltipContent.js +29 -23
- package/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
- package/ChartsTooltip/ChartsTooltip.js +2 -2
- package/ChartsTooltip/utils.js +2 -2
- package/ChartsXAxis/ChartsXAxis.js +123 -35
- package/ChartsYAxis/ChartsYAxis.js +38 -16
- package/LineChart/AreaElement.d.ts +10 -0
- package/LineChart/AreaElement.js +12 -2
- package/LineChart/AreaPlot.d.ts +11 -0
- package/LineChart/AreaPlot.js +24 -7
- package/LineChart/LineChart.d.ts +10 -0
- package/LineChart/LineChart.js +36 -2
- package/LineChart/LineElement.d.ts +10 -0
- package/LineChart/LineElement.js +12 -2
- package/LineChart/LineHighlightElement.d.ts +10 -0
- package/LineChart/LineHighlightElement.js +12 -2
- package/LineChart/LineHighlightPlot.d.ts +10 -0
- package/LineChart/LineHighlightPlot.js +14 -3
- package/LineChart/LinePlot.d.ts +10 -0
- package/LineChart/LinePlot.js +22 -11
- package/LineChart/MarkElement.d.ts +10 -0
- package/LineChart/MarkElement.js +12 -2
- package/LineChart/MarkPlot.d.ts +10 -0
- package/LineChart/MarkPlot.js +40 -9
- package/LineChart/formatter.js +4 -3
- package/PieChart/PieArc.js +2 -2
- package/PieChart/PieArcLabel.js +2 -2
- package/PieChart/PieChart.d.ts +10 -0
- package/PieChart/PieChart.js +37 -2
- package/PieChart/PiePlot.d.ts +10 -0
- package/PieChart/PiePlot.js +12 -2
- package/ResponsiveChartContainer/index.js +4 -4
- package/ScatterChart/Scatter.d.ts +10 -0
- package/ScatterChart/Scatter.js +12 -2
- package/ScatterChart/ScatterChart.d.ts +10 -0
- package/ScatterChart/ScatterChart.js +36 -2
- package/ScatterChart/ScatterPlot.d.ts +10 -0
- package/ScatterChart/ScatterPlot.js +12 -2
- package/SparkLineChart/SparkLineChart.d.ts +9 -0
- package/SparkLineChart/SparkLineChart.js +16 -2
- package/context/CartesianContextProvider.js +10 -2
- package/context/DrawingProvider.js +2 -2
- package/context/HighlightProvider.js +2 -2
- package/context/InteractionProvider.js +2 -2
- package/context/SeriesContextProvider.js +2 -2
- package/esm/BarChart/BarChart.js +43 -1
- package/esm/BarChart/BarElement.js +7 -4
- package/esm/BarChart/BarPlot.js +152 -67
- package/esm/BarChart/formatter.js +1 -1
- package/esm/ChartContainer/index.js +3 -0
- package/esm/ChartsAxis/ChartsAxis.js +16 -0
- package/esm/ChartsLegend/ChartsLegend.js +10 -6
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +27 -21
- package/esm/ChartsXAxis/ChartsXAxis.js +122 -34
- package/esm/ChartsYAxis/ChartsYAxis.js +36 -14
- package/esm/LineChart/AreaElement.js +10 -0
- package/esm/LineChart/AreaPlot.js +24 -6
- package/esm/LineChart/LineChart.js +34 -0
- package/esm/LineChart/LineElement.js +10 -0
- package/esm/LineChart/LineHighlightElement.js +10 -0
- package/esm/LineChart/LineHighlightPlot.js +12 -1
- package/esm/LineChart/LinePlot.js +23 -14
- package/esm/LineChart/MarkElement.js +10 -0
- package/esm/LineChart/MarkPlot.js +38 -7
- package/esm/LineChart/formatter.js +7 -3
- package/esm/PieChart/PieChart.js +35 -0
- package/esm/PieChart/PiePlot.js +10 -0
- package/esm/ResponsiveChartContainer/index.js +2 -2
- package/esm/ScatterChart/Scatter.js +10 -0
- package/esm/ScatterChart/ScatterChart.js +34 -0
- package/esm/ScatterChart/ScatterPlot.js +10 -0
- package/esm/SparkLineChart/SparkLineChart.js +14 -0
- package/esm/context/CartesianContextProvider.js +8 -0
- package/esm/hooks/useMounted.js +16 -0
- package/esm/hooks/useReducedMotion.js +27 -0
- package/esm/hooks/useTicks.js +12 -6
- package/esm/internals/components/ChartsText.js +19 -13
- package/esm/internals/geometry.js +36 -0
- package/hooks/useAxisEvents.js +2 -2
- package/hooks/useChartDimensions.js +2 -2
- package/hooks/useDrawingArea.js +2 -2
- package/hooks/useInteractionItemProps.js +2 -2
- package/hooks/useMounted.d.ts +1 -0
- package/hooks/useMounted.js +25 -0
- package/hooks/useReducedMotion.d.ts +8 -0
- package/hooks/useReducedMotion.js +33 -0
- package/hooks/useScale.d.ts +2 -2
- package/hooks/useScale.js +2 -2
- package/hooks/useTicks.d.ts +18 -9
- package/hooks/useTicks.js +14 -8
- package/index.js +1 -1
- package/internals/components/ChartsText.d.ts +11 -8
- package/internals/components/ChartsText.js +21 -15
- package/internals/defaultizeColor.d.ts +2 -2
- package/internals/domUtils.d.ts +0 -1
- package/internals/geometry.d.ts +9 -0
- package/internals/geometry.js +42 -0
- package/legacy/BarChart/BarChart.js +43 -1
- package/legacy/BarChart/BarElement.js +6 -3
- package/legacy/BarChart/BarPlot.js +151 -63
- package/legacy/BarChart/formatter.js +1 -1
- package/legacy/ChartContainer/index.js +3 -0
- package/legacy/ChartsAxis/ChartsAxis.js +16 -0
- package/legacy/ChartsLegend/ChartsLegend.js +14 -7
- package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +5 -1
- package/legacy/ChartsXAxis/ChartsXAxis.js +126 -36
- package/legacy/ChartsYAxis/ChartsYAxis.js +36 -14
- package/legacy/LineChart/AreaElement.js +10 -0
- package/legacy/LineChart/AreaPlot.js +27 -7
- package/legacy/LineChart/LineChart.js +34 -0
- package/legacy/LineChart/LineElement.js +10 -0
- package/legacy/LineChart/LineHighlightElement.js +10 -0
- package/legacy/LineChart/LineHighlightPlot.js +12 -1
- package/legacy/LineChart/LinePlot.js +25 -12
- package/legacy/LineChart/MarkElement.js +10 -0
- package/legacy/LineChart/MarkPlot.js +37 -7
- package/legacy/LineChart/formatter.js +7 -3
- package/legacy/PieChart/PieChart.js +35 -0
- package/legacy/PieChart/PiePlot.js +10 -0
- package/legacy/ResponsiveChartContainer/index.js +2 -2
- package/legacy/ScatterChart/Scatter.js +10 -0
- package/legacy/ScatterChart/ScatterChart.js +34 -0
- package/legacy/ScatterChart/ScatterPlot.js +10 -0
- package/legacy/SparkLineChart/SparkLineChart.js +14 -0
- package/legacy/context/CartesianContextProvider.js +8 -0
- package/legacy/hooks/useMounted.js +21 -0
- package/legacy/hooks/useReducedMotion.js +27 -0
- package/legacy/hooks/useTicks.js +13 -6
- package/legacy/index.js +1 -1
- package/legacy/internals/components/ChartsText.js +17 -15
- package/legacy/internals/geometry.js +37 -0
- package/models/axis.d.ts +19 -2
- package/models/seriesType/line.d.ts +3 -3
- package/modern/BarChart/BarChart.js +43 -1
- package/modern/BarChart/BarElement.js +7 -4
- package/modern/BarChart/BarPlot.js +149 -65
- package/modern/BarChart/formatter.js +1 -1
- package/modern/ChartContainer/index.js +3 -0
- package/modern/ChartsAxis/ChartsAxis.js +16 -0
- package/modern/ChartsLegend/ChartsLegend.js +10 -6
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +27 -21
- package/modern/ChartsXAxis/ChartsXAxis.js +122 -34
- package/modern/ChartsYAxis/ChartsYAxis.js +36 -14
- package/modern/LineChart/AreaElement.js +10 -0
- package/modern/LineChart/AreaPlot.js +22 -5
- package/modern/LineChart/LineChart.js +34 -0
- package/modern/LineChart/LineElement.js +10 -0
- package/modern/LineChart/LineHighlightElement.js +10 -0
- package/modern/LineChart/LineHighlightPlot.js +12 -1
- package/modern/LineChart/LinePlot.js +20 -9
- package/modern/LineChart/MarkElement.js +10 -0
- package/modern/LineChart/MarkPlot.js +38 -7
- package/modern/LineChart/formatter.js +4 -3
- package/modern/PieChart/PieChart.js +35 -0
- package/modern/PieChart/PiePlot.js +10 -0
- package/modern/ResponsiveChartContainer/index.js +2 -2
- package/modern/ScatterChart/Scatter.js +10 -0
- package/modern/ScatterChart/ScatterChart.js +34 -0
- package/modern/ScatterChart/ScatterPlot.js +10 -0
- package/modern/SparkLineChart/SparkLineChart.js +14 -0
- package/modern/context/CartesianContextProvider.js +8 -0
- package/modern/hooks/useMounted.js +16 -0
- package/modern/hooks/useReducedMotion.js +27 -0
- package/modern/hooks/useTicks.js +12 -6
- package/modern/index.js +1 -1
- package/modern/internals/components/ChartsText.js +19 -13
- package/modern/internals/geometry.js +36 -0
- package/package.json +5 -3
|
@@ -95,11 +95,15 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
|
|
|
95
95
|
fill: PropTypes.string,
|
|
96
96
|
label: PropTypes.string,
|
|
97
97
|
labelFontSize: PropTypes.number,
|
|
98
|
+
labelStyle: PropTypes.object,
|
|
98
99
|
position: PropTypes.oneOf(['bottom', 'top']),
|
|
99
100
|
slotProps: PropTypes.object,
|
|
100
101
|
slots: PropTypes.object,
|
|
101
102
|
stroke: PropTypes.string,
|
|
102
103
|
tickFontSize: PropTypes.number,
|
|
104
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
105
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
106
|
+
tickLabelStyle: PropTypes.object,
|
|
103
107
|
tickMaxStep: PropTypes.number,
|
|
104
108
|
tickMinStep: PropTypes.number,
|
|
105
109
|
tickNumber: PropTypes.number,
|
|
@@ -118,11 +122,15 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
|
|
|
118
122
|
fill: PropTypes.string,
|
|
119
123
|
label: PropTypes.string,
|
|
120
124
|
labelFontSize: PropTypes.number,
|
|
125
|
+
labelStyle: PropTypes.object,
|
|
121
126
|
position: PropTypes.oneOf(['left', 'right']),
|
|
122
127
|
slotProps: PropTypes.object,
|
|
123
128
|
slots: PropTypes.object,
|
|
124
129
|
stroke: PropTypes.string,
|
|
125
130
|
tickFontSize: PropTypes.number,
|
|
131
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
132
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
133
|
+
tickLabelStyle: PropTypes.object,
|
|
126
134
|
tickMaxStep: PropTypes.number,
|
|
127
135
|
tickMinStep: PropTypes.number,
|
|
128
136
|
tickNumber: PropTypes.number,
|
|
@@ -141,11 +149,15 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
|
|
|
141
149
|
fill: PropTypes.string,
|
|
142
150
|
label: PropTypes.string,
|
|
143
151
|
labelFontSize: PropTypes.number,
|
|
152
|
+
labelStyle: PropTypes.object,
|
|
144
153
|
position: PropTypes.oneOf(['left', 'right']),
|
|
145
154
|
slotProps: PropTypes.object,
|
|
146
155
|
slots: PropTypes.object,
|
|
147
156
|
stroke: PropTypes.string,
|
|
148
157
|
tickFontSize: PropTypes.number,
|
|
158
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
159
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
160
|
+
tickLabelStyle: PropTypes.object,
|
|
149
161
|
tickMaxStep: PropTypes.number,
|
|
150
162
|
tickMinStep: PropTypes.number,
|
|
151
163
|
tickNumber: PropTypes.number,
|
|
@@ -174,11 +186,15 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
|
|
|
174
186
|
fill: PropTypes.string,
|
|
175
187
|
label: PropTypes.string,
|
|
176
188
|
labelFontSize: PropTypes.number,
|
|
189
|
+
labelStyle: PropTypes.object,
|
|
177
190
|
position: PropTypes.oneOf(['bottom', 'top']),
|
|
178
191
|
slotProps: PropTypes.object,
|
|
179
192
|
slots: PropTypes.object,
|
|
180
193
|
stroke: PropTypes.string,
|
|
181
194
|
tickFontSize: PropTypes.number,
|
|
195
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
196
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
197
|
+
tickLabelStyle: PropTypes.object,
|
|
182
198
|
tickMaxStep: PropTypes.number,
|
|
183
199
|
tickMinStep: PropTypes.number,
|
|
184
200
|
tickNumber: PropTypes.number,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
1
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
-
var _excluded = ["
|
|
4
|
+
var _excluded = ["rotate", "dominantBaseline"],
|
|
5
|
+
_excluded2 = ["label"];
|
|
5
6
|
import * as React from 'react';
|
|
6
7
|
import { useSlotProps } from '@mui/base/utils';
|
|
7
8
|
import { NoSsr } from '@mui/base/NoSsr';
|
|
@@ -80,14 +81,22 @@ function DefaultChartsLegend(props) {
|
|
|
80
81
|
var labelStyle = React.useMemo(function () {
|
|
81
82
|
return _extends({}, theme.typography.subtitle1, {
|
|
82
83
|
color: 'inherit',
|
|
84
|
+
dominantBaseline: 'central',
|
|
85
|
+
textAnchor: 'start',
|
|
83
86
|
fill: (theme.vars || theme).palette.text.primary,
|
|
84
87
|
lineHeight: 1
|
|
85
88
|
}, inLabelStyle);
|
|
86
|
-
},
|
|
89
|
+
},
|
|
90
|
+
// To say to TS that the dominantBaseline and textAnchor are correct
|
|
91
|
+
[inLabelStyle, theme]);
|
|
87
92
|
var padding = React.useMemo(function () {
|
|
88
93
|
return getStandardizedPadding(paddingProps);
|
|
89
94
|
}, [paddingProps]);
|
|
90
|
-
var getItemSpace = React.useCallback(function (label
|
|
95
|
+
var getItemSpace = React.useCallback(function (label) {
|
|
96
|
+
var inStyle = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
97
|
+
var rotate = inStyle.rotate,
|
|
98
|
+
dominantBaseline = inStyle.dominantBaseline,
|
|
99
|
+
style = _objectWithoutProperties(inStyle, _excluded);
|
|
91
100
|
var linesSize = getWordsByLines({
|
|
92
101
|
style: style,
|
|
93
102
|
needsComputation: true,
|
|
@@ -120,7 +129,7 @@ function DefaultChartsLegend(props) {
|
|
|
120
129
|
var rowMaxHeight = [0];
|
|
121
130
|
var seriesWithRawPosition = seriesToDisplay.map(function (_ref) {
|
|
122
131
|
var label = _ref.label,
|
|
123
|
-
other = _objectWithoutProperties(_ref,
|
|
132
|
+
other = _objectWithoutProperties(_ref, _excluded2);
|
|
124
133
|
var itemSpace = getItemSpace(label, labelStyle);
|
|
125
134
|
var rep = _extends({}, other, {
|
|
126
135
|
label: label,
|
|
@@ -229,8 +238,6 @@ function DefaultChartsLegend(props) {
|
|
|
229
238
|
fill: color
|
|
230
239
|
}), /*#__PURE__*/_jsx(ChartsText, {
|
|
231
240
|
style: labelStyle,
|
|
232
|
-
dominantBaseline: "central",
|
|
233
|
-
textAnchor: "start",
|
|
234
241
|
text: label,
|
|
235
242
|
x: itemMarkWidth + markGap,
|
|
236
243
|
y: 0
|
|
@@ -41,6 +41,10 @@ export function DefaultChartsAxisContent(props) {
|
|
|
41
41
|
label = _ref.label,
|
|
42
42
|
valueFormatter = _ref.valueFormatter,
|
|
43
43
|
data = _ref.data;
|
|
44
|
+
var formattedValue = valueFormatter(data[dataIndex]);
|
|
45
|
+
if (formattedValue == null) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
44
48
|
return /*#__PURE__*/_jsxs(ChartsTooltipRow, {
|
|
45
49
|
children: [/*#__PURE__*/_jsx(ChartsTooltipCell, {
|
|
46
50
|
className: classes.markCell,
|
|
@@ -58,7 +62,7 @@ export function DefaultChartsAxisContent(props) {
|
|
|
58
62
|
}), /*#__PURE__*/_jsx(ChartsTooltipCell, {
|
|
59
63
|
className: classes.valueCell,
|
|
60
64
|
children: /*#__PURE__*/_jsx(Typography, {
|
|
61
|
-
children:
|
|
65
|
+
children: formattedValue
|
|
62
66
|
})
|
|
63
67
|
})]
|
|
64
68
|
}, id);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
4
|
var _excluded = ["scale", "tickNumber"];
|
|
4
5
|
import * as React from 'react';
|
|
@@ -11,7 +12,9 @@ import { DrawingContext } from '../context/DrawingProvider';
|
|
|
11
12
|
import useTicks from '../hooks/useTicks';
|
|
12
13
|
import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
|
|
13
14
|
import { AxisRoot } from '../internals/components/AxisSharedComponents';
|
|
14
|
-
import { ChartsText } from '../internals/components/ChartsText';
|
|
15
|
+
import { ChartsText, getWordsByLines } from '../internals/components/ChartsText';
|
|
16
|
+
import { getMinXTranslation } from '../internals/geometry';
|
|
17
|
+
import { useMounted } from '../hooks/useMounted';
|
|
15
18
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
16
19
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
20
|
var useUtilityClasses = function useUtilityClasses(ownerState) {
|
|
@@ -27,12 +30,65 @@ var useUtilityClasses = function useUtilityClasses(ownerState) {
|
|
|
27
30
|
};
|
|
28
31
|
return composeClasses(slots, getAxisUtilityClass, classes);
|
|
29
32
|
};
|
|
33
|
+
function addLabelDimension(xTicks, _ref) {
|
|
34
|
+
var style = _ref.tickLabelStyle,
|
|
35
|
+
tickLabelInterval = _ref.tickLabelInterval,
|
|
36
|
+
isMounted = _ref.isMounted;
|
|
37
|
+
var withDimension = xTicks.map(function (tick) {
|
|
38
|
+
if (!isMounted || tick.formattedValue === undefined) {
|
|
39
|
+
return _extends({}, tick, {
|
|
40
|
+
width: 0,
|
|
41
|
+
height: 0
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
var tickSizes = getWordsByLines({
|
|
45
|
+
style: style,
|
|
46
|
+
needsComputation: true,
|
|
47
|
+
text: tick.formattedValue
|
|
48
|
+
});
|
|
49
|
+
return _extends({}, tick, {
|
|
50
|
+
width: Math.max.apply(Math, _toConsumableArray(tickSizes.map(function (size) {
|
|
51
|
+
return size.width;
|
|
52
|
+
}))),
|
|
53
|
+
height: Math.max(tickSizes.length * tickSizes[0].height)
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
if (typeof tickLabelInterval === 'function') {
|
|
57
|
+
return withDimension.map(function (item, index) {
|
|
58
|
+
return _extends({}, item, {
|
|
59
|
+
skipLabel: !tickLabelInterval(item.value, index)
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Filter label to avoid overlap
|
|
65
|
+
var textStart = 0;
|
|
66
|
+
var textEnd = 0;
|
|
67
|
+
return withDimension.map(function (item, labelIndex) {
|
|
68
|
+
var width = item.width,
|
|
69
|
+
offset = item.offset,
|
|
70
|
+
labelOffset = item.labelOffset,
|
|
71
|
+
height = item.height;
|
|
72
|
+
var distance = getMinXTranslation(width, height, style == null ? void 0 : style.angle);
|
|
73
|
+
var textPosition = offset + labelOffset;
|
|
74
|
+
var gapRatio = 1.2; // Ratio applied to the minimal distance to add some margin.
|
|
75
|
+
|
|
76
|
+
textStart = textPosition - gapRatio * distance / 2;
|
|
77
|
+
if (labelIndex > 0 && textStart < textEnd) {
|
|
78
|
+
// Except for the first label, we skip all label that overlap with the last accepted.
|
|
79
|
+
// Notice that the early return prevents `textEnd` from being updated.
|
|
80
|
+
return _extends({}, item, {
|
|
81
|
+
skipLabel: true
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
textEnd = textPosition + gapRatio * distance / 2;
|
|
85
|
+
return item;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
30
88
|
var defaultProps = {
|
|
31
89
|
position: 'bottom',
|
|
32
90
|
disableLine: false,
|
|
33
91
|
disableTicks: false,
|
|
34
|
-
tickFontSize: 12,
|
|
35
|
-
labelFontSize: 14,
|
|
36
92
|
tickSize: 6
|
|
37
93
|
};
|
|
38
94
|
function ChartsXAxis(inProps) {
|
|
@@ -46,17 +102,22 @@ function ChartsXAxis(inProps) {
|
|
|
46
102
|
xScale = _React$useContext$xAx.scale,
|
|
47
103
|
tickNumber = _React$useContext$xAx.tickNumber,
|
|
48
104
|
settings = _objectWithoutProperties(_React$useContext$xAx, _excluded);
|
|
105
|
+
var isMounted = useMounted();
|
|
49
106
|
var defaultizedProps = _extends({}, defaultProps, settings, props);
|
|
50
107
|
var position = defaultizedProps.position,
|
|
51
108
|
disableLine = defaultizedProps.disableLine,
|
|
52
109
|
disableTicks = defaultizedProps.disableTicks,
|
|
53
|
-
|
|
110
|
+
tickLabelStyle = defaultizedProps.tickLabelStyle,
|
|
54
111
|
label = defaultizedProps.label,
|
|
112
|
+
labelStyle = defaultizedProps.labelStyle,
|
|
113
|
+
tickFontSize = defaultizedProps.tickFontSize,
|
|
55
114
|
labelFontSize = defaultizedProps.labelFontSize,
|
|
56
115
|
tickSizeProp = defaultizedProps.tickSize,
|
|
57
116
|
valueFormatter = defaultizedProps.valueFormatter,
|
|
58
117
|
slots = defaultizedProps.slots,
|
|
59
|
-
slotProps = defaultizedProps.slotProps
|
|
118
|
+
slotProps = defaultizedProps.slotProps,
|
|
119
|
+
tickInterval = defaultizedProps.tickInterval,
|
|
120
|
+
tickLabelInterval = defaultizedProps.tickLabelInterval;
|
|
60
121
|
var theme = useTheme();
|
|
61
122
|
var classes = useUtilityClasses(_extends({}, defaultizedProps, {
|
|
62
123
|
theme: theme
|
|
@@ -67,16 +128,7 @@ function ChartsXAxis(inProps) {
|
|
|
67
128
|
width = _React$useContext2.width,
|
|
68
129
|
height = _React$useContext2.height;
|
|
69
130
|
var tickSize = disableTicks ? 4 : tickSizeProp;
|
|
70
|
-
var
|
|
71
|
-
scale: xScale,
|
|
72
|
-
tickNumber: tickNumber,
|
|
73
|
-
valueFormatter: valueFormatter
|
|
74
|
-
});
|
|
75
|
-
var positionSigne = position === 'bottom' ? 1 : -1;
|
|
76
|
-
var labelRefPoint = {
|
|
77
|
-
x: left + width / 2,
|
|
78
|
-
y: positionSigne * (tickFontSize + tickSize + 10)
|
|
79
|
-
};
|
|
131
|
+
var positionSign = position === 'bottom' ? 1 : -1;
|
|
80
132
|
var Line = (_slots$axisLine = slots == null ? void 0 : slots.axisLine) != null ? _slots$axisLine : 'line';
|
|
81
133
|
var Tick = (_slots$axisTick = slots == null ? void 0 : slots.axisTick) != null ? _slots$axisTick : 'line';
|
|
82
134
|
var TickLabel = (_slots$axisTickLabel = slots == null ? void 0 : slots.axisTickLabel) != null ? _slots$axisTickLabel : ChartsText;
|
|
@@ -85,27 +137,40 @@ function ChartsXAxis(inProps) {
|
|
|
85
137
|
elementType: TickLabel,
|
|
86
138
|
externalSlotProps: slotProps == null ? void 0 : slotProps.axisTickLabel,
|
|
87
139
|
additionalProps: {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
fontSize: tickFontSize
|
|
92
|
-
},
|
|
140
|
+
style: _extends({
|
|
141
|
+
textAnchor: 'middle',
|
|
142
|
+
dominantBaseline: position === 'bottom' ? 'hanging' : 'auto',
|
|
143
|
+
fontSize: tickFontSize != null ? tickFontSize : 12
|
|
144
|
+
}, tickLabelStyle),
|
|
93
145
|
className: classes.tickLabel
|
|
94
146
|
},
|
|
95
147
|
className: classes.tickLabel,
|
|
96
148
|
ownerState: {}
|
|
97
149
|
});
|
|
150
|
+
var xTicks = useTicks({
|
|
151
|
+
scale: xScale,
|
|
152
|
+
tickNumber: tickNumber,
|
|
153
|
+
valueFormatter: valueFormatter,
|
|
154
|
+
tickInterval: tickInterval
|
|
155
|
+
});
|
|
156
|
+
var xTicksWithDimension = addLabelDimension(xTicks, {
|
|
157
|
+
tickLabelStyle: axisTickLabelProps.style,
|
|
158
|
+
tickLabelInterval: tickLabelInterval,
|
|
159
|
+
isMounted: isMounted
|
|
160
|
+
});
|
|
161
|
+
var labelRefPoint = {
|
|
162
|
+
x: left + width / 2,
|
|
163
|
+
y: positionSign * (tickSize + 22)
|
|
164
|
+
};
|
|
98
165
|
var axisLabelProps = useSlotProps({
|
|
99
166
|
elementType: Label,
|
|
100
167
|
externalSlotProps: slotProps == null ? void 0 : slotProps.axisLabel,
|
|
101
168
|
additionalProps: {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
},
|
|
108
|
-
className: classes.label
|
|
169
|
+
style: _extends({
|
|
170
|
+
fontSize: labelFontSize != null ? labelFontSize : 14,
|
|
171
|
+
textAnchor: 'middle',
|
|
172
|
+
dominantBaseline: position === 'bottom' ? 'hanging' : 'auto'
|
|
173
|
+
}, labelStyle)
|
|
109
174
|
},
|
|
110
175
|
ownerState: {}
|
|
111
176
|
});
|
|
@@ -116,22 +181,22 @@ function ChartsXAxis(inProps) {
|
|
|
116
181
|
x1: xScale.range()[0],
|
|
117
182
|
x2: xScale.range()[1],
|
|
118
183
|
className: classes.line
|
|
119
|
-
}, slotProps == null ? void 0 : slotProps.axisLine)),
|
|
120
|
-
var formattedValue =
|
|
121
|
-
offset =
|
|
122
|
-
labelOffset =
|
|
184
|
+
}, slotProps == null ? void 0 : slotProps.axisLine)), xTicksWithDimension.map(function (_ref2, index) {
|
|
185
|
+
var formattedValue = _ref2.formattedValue,
|
|
186
|
+
offset = _ref2.offset,
|
|
187
|
+
labelOffset = _ref2.labelOffset,
|
|
188
|
+
skipLabel = _ref2.skipLabel;
|
|
123
189
|
var xTickLabel = labelOffset != null ? labelOffset : 0;
|
|
124
|
-
var yTickLabel =
|
|
190
|
+
var yTickLabel = positionSign * (tickSize + 3);
|
|
125
191
|
return /*#__PURE__*/_jsxs("g", {
|
|
126
192
|
transform: "translate(".concat(offset, ", 0)"),
|
|
127
193
|
className: classes.tickContainer,
|
|
128
194
|
children: [!disableTicks && /*#__PURE__*/_jsx(Tick, _extends({
|
|
129
|
-
y2:
|
|
195
|
+
y2: positionSign * tickSize,
|
|
130
196
|
className: classes.tick
|
|
131
|
-
}, slotProps == null ? void 0 : slotProps.axisTick)), formattedValue !== undefined && /*#__PURE__*/_jsx(TickLabel, _extends({
|
|
197
|
+
}, slotProps == null ? void 0 : slotProps.axisTick)), formattedValue !== undefined && !skipLabel && /*#__PURE__*/_jsx(TickLabel, _extends({
|
|
132
198
|
x: xTickLabel,
|
|
133
|
-
y: yTickLabel
|
|
134
|
-
"transform-origin": "".concat(xTickLabel, "px ").concat(yTickLabel, "px")
|
|
199
|
+
y: yTickLabel
|
|
135
200
|
}, axisTickLabelProps, {
|
|
136
201
|
text: formattedValue.toString()
|
|
137
202
|
}))]
|
|
@@ -179,8 +244,13 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
|
|
|
179
244
|
/**
|
|
180
245
|
* The font size of the axis label.
|
|
181
246
|
* @default 14
|
|
247
|
+
* @deprecated Consider using `labelStyle.fontSize` instead.
|
|
182
248
|
*/
|
|
183
249
|
labelFontSize: PropTypes.number,
|
|
250
|
+
/**
|
|
251
|
+
* The style applied to the axis label.
|
|
252
|
+
*/
|
|
253
|
+
labelStyle: PropTypes.object,
|
|
184
254
|
/**
|
|
185
255
|
* Position of the axis.
|
|
186
256
|
*/
|
|
@@ -203,8 +273,28 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
|
|
|
203
273
|
/**
|
|
204
274
|
* The font size of the axis ticks text.
|
|
205
275
|
* @default 12
|
|
276
|
+
* @deprecated Consider using `tickLabelStyle.fontSize` instead.
|
|
206
277
|
*/
|
|
207
278
|
tickFontSize: PropTypes.number,
|
|
279
|
+
/**
|
|
280
|
+
* Defines which ticks are displayed. Its value can be:
|
|
281
|
+
* - 'auto' In such case the ticks are computed based on axis scale and other parameters.
|
|
282
|
+
* - a filtering function of the form `(value, index) => boolean` which is available only if the axis has a data property.
|
|
283
|
+
* - an array containing the values where ticks should be displayed.
|
|
284
|
+
* @default 'auto'
|
|
285
|
+
*/
|
|
286
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
287
|
+
/**
|
|
288
|
+
* Defines which ticks get its label displayed. Its value can be:
|
|
289
|
+
* - 'auto' In such case, labels are displayed if they do not overlap with the previous one.
|
|
290
|
+
* - a filtering function of the form (value, index) => boolean. Warning: the index is tick index, not data ones.
|
|
291
|
+
* @default 'auto'
|
|
292
|
+
*/
|
|
293
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
294
|
+
/**
|
|
295
|
+
* The style applied to ticks text.
|
|
296
|
+
*/
|
|
297
|
+
tickLabelStyle: PropTypes.object,
|
|
208
298
|
/**
|
|
209
299
|
* Maximal step between two ticks.
|
|
210
300
|
* When using time data, the value is assumed to be in ms.
|
|
@@ -72,9 +72,9 @@ function ChartsYAxis(inProps) {
|
|
|
72
72
|
tickNumber: tickNumber,
|
|
73
73
|
valueFormatter: valueFormatter
|
|
74
74
|
});
|
|
75
|
-
var
|
|
75
|
+
var positionSign = position === 'right' ? 1 : -1;
|
|
76
76
|
var labelRefPoint = {
|
|
77
|
-
x:
|
|
77
|
+
x: positionSign * (tickFontSize + tickSize + 10),
|
|
78
78
|
y: top + height / 2
|
|
79
79
|
};
|
|
80
80
|
var Line = (_slots$axisLine = slots == null ? void 0 : slots.axisLine) != null ? _slots$axisLine : 'line';
|
|
@@ -85,10 +85,10 @@ function ChartsYAxis(inProps) {
|
|
|
85
85
|
elementType: TickLabel,
|
|
86
86
|
externalSlotProps: slotProps == null ? void 0 : slotProps.axisTickLabel,
|
|
87
87
|
additionalProps: {
|
|
88
|
-
textAnchor: position === 'right' ? 'start' : 'end',
|
|
89
|
-
dominantBaseline: 'central',
|
|
90
88
|
style: {
|
|
91
|
-
fontSize: tickFontSize
|
|
89
|
+
fontSize: tickFontSize,
|
|
90
|
+
textAnchor: position === 'right' ? 'start' : 'end',
|
|
91
|
+
dominantBaseline: 'central'
|
|
92
92
|
},
|
|
93
93
|
className: classes.tickLabel
|
|
94
94
|
},
|
|
@@ -98,14 +98,12 @@ function ChartsYAxis(inProps) {
|
|
|
98
98
|
elementType: Label,
|
|
99
99
|
externalSlotProps: slotProps == null ? void 0 : slotProps.axisLabel,
|
|
100
100
|
additionalProps: {
|
|
101
|
-
textAnchor: 'middle',
|
|
102
|
-
dominantBaseline: 'auto',
|
|
103
101
|
style: {
|
|
104
102
|
fontSize: labelFontSize,
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
103
|
+
angle: positionSign * 90,
|
|
104
|
+
textAnchor: 'middle',
|
|
105
|
+
dominantBaseline: 'auto'
|
|
106
|
+
}
|
|
109
107
|
},
|
|
110
108
|
ownerState: {}
|
|
111
109
|
});
|
|
@@ -120,18 +118,17 @@ function ChartsYAxis(inProps) {
|
|
|
120
118
|
var formattedValue = _ref.formattedValue,
|
|
121
119
|
offset = _ref.offset,
|
|
122
120
|
labelOffset = _ref.labelOffset;
|
|
123
|
-
var xTickLabel =
|
|
121
|
+
var xTickLabel = positionSign * (tickSize + 2);
|
|
124
122
|
var yTickLabel = labelOffset;
|
|
125
123
|
return /*#__PURE__*/_jsxs("g", {
|
|
126
124
|
transform: "translate(0, ".concat(offset, ")"),
|
|
127
125
|
className: classes.tickContainer,
|
|
128
126
|
children: [!disableTicks && /*#__PURE__*/_jsx(Tick, _extends({
|
|
129
|
-
x2:
|
|
127
|
+
x2: positionSign * tickSize,
|
|
130
128
|
className: classes.tick
|
|
131
129
|
}, slotProps == null ? void 0 : slotProps.axisTick)), formattedValue !== undefined && /*#__PURE__*/_jsx(TickLabel, _extends({
|
|
132
130
|
x: xTickLabel,
|
|
133
131
|
y: yTickLabel,
|
|
134
|
-
"transform-origin": "".concat(xTickLabel, "px ").concat(yTickLabel, "px"),
|
|
135
132
|
text: formattedValue.toString()
|
|
136
133
|
}, axisTickLabelProps))]
|
|
137
134
|
}, index);
|
|
@@ -178,8 +175,13 @@ process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
|
|
|
178
175
|
/**
|
|
179
176
|
* The font size of the axis label.
|
|
180
177
|
* @default 14
|
|
178
|
+
* @deprecated Consider using `labelStyle.fontSize` instead.
|
|
181
179
|
*/
|
|
182
180
|
labelFontSize: PropTypes.number,
|
|
181
|
+
/**
|
|
182
|
+
* The style applied to the axis label.
|
|
183
|
+
*/
|
|
184
|
+
labelStyle: PropTypes.object,
|
|
183
185
|
/**
|
|
184
186
|
* Position of the axis.
|
|
185
187
|
*/
|
|
@@ -202,8 +204,28 @@ process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
|
|
|
202
204
|
/**
|
|
203
205
|
* The font size of the axis ticks text.
|
|
204
206
|
* @default 12
|
|
207
|
+
* @deprecated Consider using `tickLabelStyle.fontSize` instead.
|
|
205
208
|
*/
|
|
206
209
|
tickFontSize: PropTypes.number,
|
|
210
|
+
/**
|
|
211
|
+
* Defines which ticks are displayed. Its value can be:
|
|
212
|
+
* - 'auto' In such case the ticks are computed based on axis scale and other parameters.
|
|
213
|
+
* - a filtering function of the form `(value, index) => boolean` which is available only if the axis has a data property.
|
|
214
|
+
* - an array containing the values where ticks should be displayed.
|
|
215
|
+
* @default 'auto'
|
|
216
|
+
*/
|
|
217
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
218
|
+
/**
|
|
219
|
+
* Defines which ticks get its label displayed. Its value can be:
|
|
220
|
+
* - 'auto' In such case, labels are displayed if they do not overlap with the previous one.
|
|
221
|
+
* - a filtering function of the form (value, index) => boolean. Warning: the index is tick index, not data ones.
|
|
222
|
+
* @default 'auto'
|
|
223
|
+
*/
|
|
224
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
225
|
+
/**
|
|
226
|
+
* The style applied to ticks text.
|
|
227
|
+
*/
|
|
228
|
+
tickLabelStyle: PropTypes.object,
|
|
207
229
|
/**
|
|
208
230
|
* Maximal step between two ticks.
|
|
209
231
|
* When using time data, the value is assumed to be in ms.
|
|
@@ -56,6 +56,16 @@ AreaElementPath.propTypes = {
|
|
|
56
56
|
}).isRequired,
|
|
57
57
|
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
|
|
58
58
|
};
|
|
59
|
+
/**
|
|
60
|
+
* Demos:
|
|
61
|
+
*
|
|
62
|
+
* - [Lines](https://mui.com/x/react-charts/lines/)
|
|
63
|
+
* - [Areas demonstration](https://mui.com/x/react-charts/areas-demo/)
|
|
64
|
+
*
|
|
65
|
+
* API:
|
|
66
|
+
*
|
|
67
|
+
* - [AreaElement API](https://mui.com/x/api/charts/area-element/)
|
|
68
|
+
*/
|
|
59
69
|
function AreaElement(props) {
|
|
60
70
|
var _slots$area;
|
|
61
71
|
var id = props.id,
|
|
@@ -10,6 +10,17 @@ import { AreaElement } from './AreaElement';
|
|
|
10
10
|
import { getValueToPositionMapper } from '../hooks/useScale';
|
|
11
11
|
import getCurveFactory from '../internals/getCurve';
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
/**
|
|
14
|
+
* Demos:
|
|
15
|
+
*
|
|
16
|
+
* - [Lines](https://mui.com/x/react-charts/lines/)
|
|
17
|
+
* - [Areas demonstration](https://mui.com/x/react-charts/areas-demo/)
|
|
18
|
+
* - [Stacking](https://mui.com/x/react-charts/stacking/)
|
|
19
|
+
*
|
|
20
|
+
* API:
|
|
21
|
+
*
|
|
22
|
+
* - [AreaPlot API](https://mui.com/x/api/charts/area-plot/)
|
|
23
|
+
*/
|
|
13
24
|
function AreaPlot(props) {
|
|
14
25
|
var slots = props.slots,
|
|
15
26
|
slotProps = props.slotProps,
|
|
@@ -31,32 +42,41 @@ function AreaPlot(props) {
|
|
|
31
42
|
children: stackingGroups.flatMap(function (_ref) {
|
|
32
43
|
var groupIds = _ref.ids;
|
|
33
44
|
return groupIds.flatMap(function (seriesId) {
|
|
45
|
+
var _xData$map;
|
|
34
46
|
var _series$seriesId = series[seriesId],
|
|
35
47
|
_series$seriesId$xAxi = _series$seriesId.xAxisKey,
|
|
36
48
|
xAxisKey = _series$seriesId$xAxi === void 0 ? defaultXAxisId : _series$seriesId$xAxi,
|
|
37
49
|
_series$seriesId$yAxi = _series$seriesId.yAxisKey,
|
|
38
50
|
yAxisKey = _series$seriesId$yAxi === void 0 ? defaultYAxisId : _series$seriesId$yAxi,
|
|
39
|
-
stackedData = _series$seriesId.stackedData
|
|
51
|
+
stackedData = _series$seriesId.stackedData,
|
|
52
|
+
data = _series$seriesId.data;
|
|
40
53
|
var xScale = getValueToPositionMapper(xAxis[xAxisKey].scale);
|
|
41
54
|
var yScale = yAxis[yAxisKey].scale;
|
|
42
55
|
var xData = xAxis[xAxisKey].data;
|
|
43
|
-
if (
|
|
44
|
-
|
|
56
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
57
|
+
if (xData === undefined) {
|
|
58
|
+
throw new Error("Axis of id \"".concat(xAxisKey, "\" should have data property to be able to display a line plot."));
|
|
59
|
+
}
|
|
60
|
+
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
|
+
}
|
|
45
63
|
}
|
|
46
64
|
var areaPath = d3Area().x(function (d) {
|
|
47
65
|
return xScale(d.x);
|
|
66
|
+
}).defined(function (_, i) {
|
|
67
|
+
return data[i] != null;
|
|
48
68
|
}).y0(function (d) {
|
|
49
|
-
return yScale(d.y[0]);
|
|
69
|
+
return d.y && yScale(d.y[0]);
|
|
50
70
|
}).y1(function (d) {
|
|
51
|
-
return yScale(d.y[1]);
|
|
71
|
+
return d.y && yScale(d.y[1]);
|
|
52
72
|
});
|
|
53
73
|
var curve = getCurveFactory(series[seriesId].curve);
|
|
54
|
-
var d3Data = xData == null ? void 0 : xData.map(function (x, index) {
|
|
74
|
+
var d3Data = (_xData$map = xData == null ? void 0 : xData.map(function (x, index) {
|
|
55
75
|
return {
|
|
56
76
|
x: x,
|
|
57
77
|
y: stackedData[index]
|
|
58
78
|
};
|
|
59
|
-
});
|
|
79
|
+
})) != null ? _xData$map : [];
|
|
60
80
|
return !!series[seriesId].area && /*#__PURE__*/_jsx(AreaElement, {
|
|
61
81
|
id: seriesId,
|
|
62
82
|
d: areaPath.curve(curve)(d3Data) || undefined,
|