@mui/x-charts 6.0.0-alpha.9 → 6.18.1
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 +26 -5
- package/BarChart/BarChart.js +93 -17
- package/BarChart/BarElement.d.ts +1319 -4
- package/BarChart/BarElement.js +10 -10
- package/BarChart/BarPlot.d.ts +17 -1
- package/BarChart/BarPlot.js +152 -66
- package/BarChart/formatter.js +2 -3
- package/BarChart/legend.js +1 -2
- package/CHANGELOG.md +797 -59
- package/ChartContainer/index.js +7 -5
- package/ChartsAxis/ChartsAxis.d.ts +9 -0
- package/ChartsAxis/ChartsAxis.js +33 -7
- package/ChartsAxis/axisClasses.d.ts +3 -3
- package/ChartsAxis/axisClasses.js +1 -2
- package/ChartsAxisHighlight/ChartsAxisHighlight.d.ts +21 -0
- package/ChartsAxisHighlight/ChartsAxisHighlight.js +61 -22
- package/ChartsClipPath/ChartsClipPath.d.ts +5 -0
- package/ChartsClipPath/ChartsClipPath.js +7 -2
- package/ChartsLegend/ChartsLegend.d.ts +45 -24
- package/ChartsLegend/ChartsLegend.js +193 -151
- package/ChartsLegend/chartsLegendClasses.d.ts +1 -1
- package/ChartsLegend/chartsLegendClasses.js +3 -4
- package/ChartsLegend/utils.d.ts +1 -6
- package/ChartsReferenceLine/ChartsReferenceLine.d.ts +10 -0
- package/ChartsReferenceLine/ChartsReferenceLine.js +78 -0
- package/ChartsReferenceLine/ChartsXReferenceLine.d.ts +13 -0
- package/ChartsReferenceLine/ChartsXReferenceLine.js +112 -0
- package/ChartsReferenceLine/ChartsYReferenceLine.d.ts +13 -0
- package/ChartsReferenceLine/ChartsYReferenceLine.js +112 -0
- package/ChartsReferenceLine/chartsReferenceLineClasses.d.ts +15 -0
- package/ChartsReferenceLine/chartsReferenceLineClasses.js +14 -0
- package/ChartsReferenceLine/common.d.ts +41 -0
- package/ChartsReferenceLine/common.js +27 -0
- package/ChartsReferenceLine/index.d.ts +2 -0
- package/ChartsReferenceLine/index.js +27 -0
- package/ChartsReferenceLine/package.json +6 -0
- package/ChartsSurface.d.ts +12 -1
- package/ChartsSurface.js +9 -18
- package/ChartsTooltip/ChartsAxisTooltipContent.d.ts +1 -0
- package/ChartsTooltip/ChartsAxisTooltipContent.js +46 -32
- package/ChartsTooltip/ChartsItemTooltipContent.d.ts +3 -2
- package/ChartsTooltip/ChartsItemTooltipContent.js +18 -9
- package/ChartsTooltip/ChartsTooltip.d.ts +32 -0
- package/ChartsTooltip/ChartsTooltip.js +62 -18
- package/ChartsTooltip/ChartsTooltipTable.d.ts +3 -10
- package/ChartsTooltip/ChartsTooltipTable.js +22 -20
- package/ChartsTooltip/tooltipClasses.js +1 -2
- package/ChartsTooltip/utils.js +2 -2
- package/ChartsXAxis/ChartsXAxis.d.ts +9 -0
- package/ChartsXAxis/ChartsXAxis.js +170 -45
- package/ChartsYAxis/ChartsYAxis.d.ts +9 -0
- package/ChartsYAxis/ChartsYAxis.js +95 -38
- package/LineChart/AreaElement.d.ts +11 -1
- package/LineChart/AreaElement.js +14 -6
- package/LineChart/AreaPlot.d.ts +11 -0
- package/LineChart/AreaPlot.js +27 -8
- package/LineChart/LineChart.d.ts +23 -3
- package/LineChart/LineChart.js +89 -17
- package/LineChart/LineElement.d.ts +11 -1
- package/LineChart/LineElement.js +14 -6
- package/LineChart/LineHighlightElement.d.ts +10 -0
- package/LineChart/LineHighlightElement.js +13 -4
- package/LineChart/LineHighlightPlot.d.ts +10 -0
- package/LineChart/LineHighlightPlot.js +15 -4
- package/LineChart/LinePlot.d.ts +10 -0
- package/LineChart/LinePlot.js +25 -12
- package/LineChart/MarkElement.d.ts +10 -0
- package/LineChart/MarkElement.js +14 -5
- package/LineChart/MarkPlot.d.ts +10 -0
- package/LineChart/MarkPlot.js +42 -10
- package/LineChart/formatter.js +5 -5
- package/LineChart/legend.js +1 -2
- package/PieChart/PieArc.d.ts +11 -13
- package/PieChart/PieArc.js +28 -60
- package/PieChart/PieArcLabel.d.ts +8 -9
- package/PieChart/PieArcLabel.js +46 -38
- package/PieChart/PieArcLabelPlot.d.ts +28 -0
- package/PieChart/PieArcLabelPlot.js +99 -0
- package/PieChart/PieArcPlot.d.ts +35 -0
- package/PieChart/PieArcPlot.js +92 -0
- package/PieChart/PieChart.d.ts +19 -5
- package/PieChart/PieChart.js +95 -18
- package/PieChart/PiePlot.d.ts +15 -9
- package/PieChart/PiePlot.js +77 -55
- package/PieChart/dataTransform/transition.d.ts +4 -0
- package/PieChart/dataTransform/transition.js +136 -0
- package/PieChart/dataTransform/useTransformData.d.ts +15 -0
- package/PieChart/dataTransform/useTransformData.js +67 -0
- package/PieChart/formatter.js +1 -2
- package/PieChart/legend.js +1 -2
- package/README.md +8 -14
- package/ResponsiveChartContainer/index.d.ts +13 -3
- package/ResponsiveChartContainer/index.js +7 -8
- package/ScatterChart/Scatter.d.ts +10 -0
- package/ScatterChart/Scatter.js +12 -2
- package/ScatterChart/ScatterChart.d.ts +16 -3
- package/ScatterChart/ScatterChart.js +77 -16
- package/ScatterChart/ScatterPlot.d.ts +10 -0
- package/ScatterChart/ScatterPlot.js +12 -2
- package/ScatterChart/formatter.js +1 -2
- package/ScatterChart/legend.js +1 -2
- package/SparkLineChart/SparkLineChart.d.ts +12 -3
- package/SparkLineChart/SparkLineChart.js +50 -7
- package/colorPalettes/colorPalettes.js +6 -12
- package/constants.js +5 -8
- package/context/CartesianContextProvider.d.ts +26 -1
- package/context/CartesianContextProvider.js +42 -16
- package/context/DrawingProvider.d.ts +25 -0
- package/context/DrawingProvider.js +18 -6
- package/context/HighlightProvider.d.ts +17 -0
- package/context/HighlightProvider.js +3 -4
- package/context/InteractionProvider.d.ts +6 -0
- package/context/InteractionProvider.js +3 -4
- package/context/SeriesContextProvider.d.ts +5 -0
- package/context/SeriesContextProvider.js +3 -4
- package/esm/BarChart/BarChart.js +90 -13
- 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 +32 -5
- package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +57 -20
- package/esm/ChartsClipPath/ChartsClipPath.js +5 -0
- package/esm/ChartsLegend/ChartsLegend.js +190 -144
- package/esm/ChartsLegend/chartsLegendClasses.js +1 -1
- package/esm/ChartsReferenceLine/ChartsReferenceLine.js +70 -0
- package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +105 -0
- package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +105 -0
- package/esm/ChartsReferenceLine/chartsReferenceLineClasses.js +6 -0
- package/esm/ChartsReferenceLine/common.js +20 -0
- package/esm/ChartsReferenceLine/index.js +2 -0
- package/esm/ChartsSurface.js +4 -12
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +44 -30
- package/esm/ChartsTooltip/ChartsItemTooltipContent.js +15 -7
- package/esm/ChartsTooltip/ChartsTooltip.js +59 -14
- package/esm/ChartsTooltip/ChartsTooltipTable.js +17 -10
- package/esm/ChartsXAxis/ChartsXAxis.js +168 -43
- package/esm/ChartsYAxis/ChartsYAxis.js +93 -36
- package/esm/LineChart/AreaElement.js +10 -0
- package/esm/LineChart/AreaPlot.js +26 -6
- package/esm/LineChart/LineChart.js +86 -13
- package/esm/LineChart/LineElement.js +10 -0
- package/esm/LineChart/LineHighlightElement.js +10 -0
- package/esm/LineChart/LineHighlightPlot.js +13 -2
- package/esm/LineChart/LinePlot.js +25 -14
- package/esm/LineChart/MarkElement.js +11 -1
- package/esm/LineChart/MarkPlot.js +40 -8
- package/esm/LineChart/formatter.js +7 -3
- package/esm/PieChart/PieArc.js +26 -58
- package/esm/PieChart/PieArcLabel.js +43 -34
- package/esm/PieChart/PieArcLabelPlot.js +92 -0
- package/esm/PieChart/PieArcPlot.js +84 -0
- package/esm/PieChart/PieChart.js +93 -16
- package/esm/PieChart/PiePlot.js +76 -57
- package/esm/PieChart/dataTransform/transition.js +130 -0
- package/esm/PieChart/dataTransform/useTransformData.js +59 -0
- package/esm/ResponsiveChartContainer/index.js +3 -3
- package/esm/ScatterChart/Scatter.js +10 -0
- package/esm/ScatterChart/ScatterChart.js +74 -12
- package/esm/ScatterChart/ScatterPlot.js +10 -0
- package/esm/SparkLineChart/SparkLineChart.js +47 -3
- package/esm/constants.js +1 -1
- package/esm/context/CartesianContextProvider.js +41 -14
- package/esm/context/DrawingProvider.js +14 -0
- package/esm/hooks/useChartDimensions.js +2 -0
- package/esm/hooks/useMounted.js +16 -0
- package/esm/hooks/useReducedMotion.js +27 -0
- package/esm/hooks/useTicks.js +15 -9
- package/esm/index.js +1 -0
- package/esm/internals/components/AxisSharedComponents.js +15 -70
- package/esm/internals/components/ChartsText.js +77 -0
- package/esm/internals/domUtils.js +113 -0
- package/esm/internals/geometry.js +36 -0
- package/hooks/useAxisEvents.js +2 -2
- package/hooks/useChartDimensions.d.ts +2 -0
- package/hooks/useChartDimensions.js +5 -4
- 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 +19 -11
- package/hooks/useTicks.js +19 -14
- package/index.d.ts +1 -0
- package/index.js +12 -1
- package/internals/components/AxisSharedComponents.d.ts +0 -4
- package/internals/components/AxisSharedComponents.js +18 -78
- package/internals/components/ChartsText.d.ts +35 -0
- package/internals/components/ChartsText.js +87 -0
- package/internals/defaultizeColor.d.ts +7 -2
- package/internals/defaultizeValueFormatter.js +1 -2
- package/internals/domUtils.d.ts +13 -0
- package/internals/domUtils.js +122 -0
- package/internals/geometry.d.ts +9 -0
- package/internals/geometry.js +42 -0
- package/internals/isBandScale.d.ts +3 -1
- package/internals/stackSeries.js +2 -4
- package/internals/utils.d.ts +5 -0
- package/legacy/BarChart/BarChart.js +90 -13
- 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 +32 -5
- package/legacy/ChartsAxisHighlight/ChartsAxisHighlight.js +60 -20
- package/legacy/ChartsClipPath/ChartsClipPath.js +5 -0
- package/legacy/ChartsLegend/ChartsLegend.js +205 -142
- package/legacy/ChartsLegend/chartsLegendClasses.js +1 -1
- package/legacy/ChartsReferenceLine/ChartsReferenceLine.js +70 -0
- package/legacy/ChartsReferenceLine/ChartsXReferenceLine.js +105 -0
- package/legacy/ChartsReferenceLine/ChartsYReferenceLine.js +105 -0
- package/legacy/ChartsReferenceLine/chartsReferenceLineClasses.js +6 -0
- package/legacy/ChartsReferenceLine/common.js +20 -0
- package/legacy/ChartsReferenceLine/index.js +2 -0
- package/legacy/ChartsSurface.js +3 -12
- package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +22 -10
- package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +15 -7
- package/legacy/ChartsTooltip/ChartsTooltip.js +62 -14
- package/legacy/ChartsTooltip/ChartsTooltipTable.js +34 -26
- package/legacy/ChartsXAxis/ChartsXAxis.js +176 -50
- package/legacy/ChartsYAxis/ChartsYAxis.js +97 -41
- package/legacy/LineChart/AreaElement.js +10 -0
- package/legacy/LineChart/AreaPlot.js +31 -7
- package/legacy/LineChart/LineChart.js +86 -13
- package/legacy/LineChart/LineElement.js +10 -0
- package/legacy/LineChart/LineHighlightElement.js +10 -0
- package/legacy/LineChart/LineHighlightPlot.js +13 -2
- package/legacy/LineChart/LinePlot.js +29 -12
- package/legacy/LineChart/MarkElement.js +11 -1
- package/legacy/LineChart/MarkPlot.js +39 -8
- package/legacy/LineChart/formatter.js +7 -3
- package/legacy/PieChart/PieArc.js +30 -62
- package/legacy/PieChart/PieArcLabel.js +48 -34
- package/legacy/PieChart/PieArcLabelPlot.js +93 -0
- package/legacy/PieChart/PieArcPlot.js +84 -0
- package/legacy/PieChart/PieChart.js +93 -16
- package/legacy/PieChart/PiePlot.js +76 -59
- package/legacy/PieChart/dataTransform/transition.js +142 -0
- package/legacy/PieChart/dataTransform/useTransformData.js +60 -0
- package/legacy/ResponsiveChartContainer/index.js +3 -3
- package/legacy/ScatterChart/Scatter.js +10 -0
- package/legacy/ScatterChart/ScatterChart.js +74 -12
- package/legacy/ScatterChart/ScatterPlot.js +10 -0
- package/legacy/SparkLineChart/SparkLineChart.js +47 -3
- package/legacy/constants.js +1 -1
- package/legacy/context/CartesianContextProvider.js +41 -14
- package/legacy/context/DrawingProvider.js +14 -0
- package/legacy/hooks/useChartDimensions.js +2 -0
- package/legacy/hooks/useMounted.js +21 -0
- package/legacy/hooks/useReducedMotion.js +27 -0
- package/legacy/hooks/useTicks.js +16 -9
- package/legacy/index.js +2 -1
- package/legacy/internals/components/AxisSharedComponents.js +11 -65
- package/legacy/internals/components/ChartsText.js +79 -0
- package/legacy/internals/domUtils.js +121 -0
- package/legacy/internals/geometry.js +37 -0
- package/models/axis.d.ts +58 -20
- package/models/layout.d.ts +13 -6
- package/models/seriesType/common.d.ts +16 -0
- package/models/seriesType/line.d.ts +8 -3
- package/models/seriesType/pie.d.ts +5 -1
- package/modern/BarChart/BarChart.js +90 -13
- 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 +31 -5
- package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +57 -20
- package/modern/ChartsClipPath/ChartsClipPath.js +5 -0
- package/modern/ChartsLegend/ChartsLegend.js +190 -144
- package/modern/ChartsLegend/chartsLegendClasses.js +1 -1
- package/modern/ChartsReferenceLine/ChartsReferenceLine.js +70 -0
- package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +104 -0
- package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +104 -0
- package/modern/ChartsReferenceLine/chartsReferenceLineClasses.js +6 -0
- package/modern/ChartsReferenceLine/common.js +20 -0
- package/modern/ChartsReferenceLine/index.js +2 -0
- package/modern/ChartsSurface.js +4 -12
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +44 -30
- package/modern/ChartsTooltip/ChartsItemTooltipContent.js +15 -7
- package/modern/ChartsTooltip/ChartsTooltip.js +58 -14
- package/modern/ChartsTooltip/ChartsTooltipTable.js +17 -10
- package/modern/ChartsXAxis/ChartsXAxis.js +167 -42
- package/modern/ChartsYAxis/ChartsYAxis.js +92 -35
- package/modern/LineChart/AreaElement.js +10 -0
- package/modern/LineChart/AreaPlot.js +25 -6
- package/modern/LineChart/LineChart.js +86 -13
- package/modern/LineChart/LineElement.js +10 -0
- package/modern/LineChart/LineHighlightElement.js +10 -0
- package/modern/LineChart/LineHighlightPlot.js +13 -2
- package/modern/LineChart/LinePlot.js +23 -10
- package/modern/LineChart/MarkElement.js +11 -1
- package/modern/LineChart/MarkPlot.js +40 -8
- package/modern/LineChart/formatter.js +4 -3
- package/modern/PieChart/PieArc.js +26 -57
- package/modern/PieChart/PieArcLabel.js +43 -34
- package/modern/PieChart/PieArcLabelPlot.js +90 -0
- package/modern/PieChart/PieArcPlot.js +83 -0
- package/modern/PieChart/PieChart.js +93 -16
- package/modern/PieChart/PiePlot.js +76 -55
- package/modern/PieChart/dataTransform/transition.js +130 -0
- package/modern/PieChart/dataTransform/useTransformData.js +58 -0
- package/modern/ResponsiveChartContainer/index.js +3 -3
- package/modern/ScatterChart/Scatter.js +10 -0
- package/modern/ScatterChart/ScatterChart.js +74 -12
- package/modern/ScatterChart/ScatterPlot.js +10 -0
- package/modern/SparkLineChart/SparkLineChart.js +47 -3
- package/modern/constants.js +1 -1
- package/modern/context/CartesianContextProvider.js +40 -13
- package/modern/context/DrawingProvider.js +14 -0
- package/modern/hooks/useChartDimensions.js +2 -0
- package/modern/hooks/useMounted.js +16 -0
- package/modern/hooks/useReducedMotion.js +27 -0
- package/modern/hooks/useTicks.js +15 -9
- package/modern/index.js +2 -1
- package/modern/internals/components/AxisSharedComponents.js +15 -70
- package/modern/internals/components/ChartsText.js +77 -0
- package/modern/internals/domUtils.js +113 -0
- package/modern/internals/geometry.js +36 -0
- package/package.json +9 -6
- package/themeAugmentation/components.d.ts +1 -0
- package/themeAugmentation/overrides.d.ts +2 -0
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
const _excluded = ["scale", "
|
|
3
|
+
const _excluded = ["scale", "tickNumber"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
|
+
import { useSlotProps } from '@mui/base/utils';
|
|
6
7
|
import { unstable_composeClasses as composeClasses } from '@mui/utils';
|
|
7
8
|
import { useThemeProps, useTheme } from '@mui/material/styles';
|
|
8
9
|
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
9
10
|
import { DrawingContext } from '../context/DrawingProvider';
|
|
10
11
|
import useTicks from '../hooks/useTicks';
|
|
11
12
|
import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
|
|
12
|
-
import {
|
|
13
|
+
import { AxisRoot } from '../internals/components/AxisSharedComponents';
|
|
14
|
+
import { ChartsText, getWordsByLines } from '../internals/components/ChartsText';
|
|
15
|
+
import { getMinXTranslation } from '../internals/geometry';
|
|
16
|
+
import { useMounted } from '../hooks/useMounted';
|
|
13
17
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
18
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
15
19
|
const useUtilityClasses = ownerState => {
|
|
@@ -27,42 +31,112 @@ const useUtilityClasses = ownerState => {
|
|
|
27
31
|
};
|
|
28
32
|
return composeClasses(slots, getAxisUtilityClass, classes);
|
|
29
33
|
};
|
|
34
|
+
function addLabelDimension(xTicks, {
|
|
35
|
+
tickLabelStyle: style,
|
|
36
|
+
tickLabelInterval,
|
|
37
|
+
isMounted
|
|
38
|
+
}) {
|
|
39
|
+
const withDimension = xTicks.map(tick => {
|
|
40
|
+
if (!isMounted || tick.formattedValue === undefined) {
|
|
41
|
+
return _extends({}, tick, {
|
|
42
|
+
width: 0,
|
|
43
|
+
height: 0
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
const tickSizes = getWordsByLines({
|
|
47
|
+
style,
|
|
48
|
+
needsComputation: true,
|
|
49
|
+
text: tick.formattedValue
|
|
50
|
+
});
|
|
51
|
+
return _extends({}, tick, {
|
|
52
|
+
width: Math.max(...tickSizes.map(size => size.width)),
|
|
53
|
+
height: Math.max(tickSizes.length * tickSizes[0].height)
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
if (typeof tickLabelInterval === 'function') {
|
|
57
|
+
return withDimension.map((item, index) => _extends({}, item, {
|
|
58
|
+
skipLabel: !tickLabelInterval(item.value, index)
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Filter label to avoid overlap
|
|
63
|
+
let textStart = 0;
|
|
64
|
+
let textEnd = 0;
|
|
65
|
+
return withDimension.map((item, labelIndex) => {
|
|
66
|
+
const {
|
|
67
|
+
width,
|
|
68
|
+
offset,
|
|
69
|
+
labelOffset,
|
|
70
|
+
height
|
|
71
|
+
} = item;
|
|
72
|
+
const distance = getMinXTranslation(width, height, style?.angle);
|
|
73
|
+
const textPosition = offset + labelOffset;
|
|
74
|
+
const 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
|
const 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
|
};
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Demos:
|
|
97
|
+
*
|
|
98
|
+
* - [Axis](https://mui.com/x/react-charts/axis/)
|
|
99
|
+
*
|
|
100
|
+
* API:
|
|
101
|
+
*
|
|
102
|
+
* - [ChartsXAxis API](https://mui.com/x/api/charts/charts-x-axis/)
|
|
103
|
+
*/
|
|
38
104
|
function ChartsXAxis(inProps) {
|
|
39
105
|
const props = useThemeProps({
|
|
40
106
|
props: _extends({}, defaultProps, inProps),
|
|
41
107
|
name: 'MuiChartsXAxis'
|
|
42
108
|
});
|
|
109
|
+
const {
|
|
110
|
+
xAxisIds
|
|
111
|
+
} = React.useContext(CartesianContext);
|
|
43
112
|
const _React$useContext = React.useContext(CartesianContext),
|
|
44
|
-
|
|
113
|
+
_ref = props.axisId ?? xAxisIds[0],
|
|
45
114
|
{
|
|
46
115
|
xAxis: {
|
|
47
|
-
[
|
|
116
|
+
[_ref]: {
|
|
48
117
|
scale: xScale,
|
|
49
|
-
|
|
118
|
+
tickNumber
|
|
50
119
|
}
|
|
51
120
|
}
|
|
52
121
|
} = _React$useContext,
|
|
53
|
-
settings = _objectWithoutPropertiesLoose(_React$useContext.xAxis[
|
|
122
|
+
settings = _objectWithoutPropertiesLoose(_React$useContext.xAxis[_ref], _excluded);
|
|
123
|
+
const isMounted = useMounted();
|
|
54
124
|
const defaultizedProps = _extends({}, defaultProps, settings, props);
|
|
55
125
|
const {
|
|
56
126
|
position,
|
|
57
127
|
disableLine,
|
|
58
128
|
disableTicks,
|
|
59
|
-
|
|
129
|
+
tickLabelStyle,
|
|
60
130
|
label,
|
|
131
|
+
labelStyle,
|
|
132
|
+
tickFontSize,
|
|
61
133
|
labelFontSize,
|
|
62
134
|
tickSize: tickSizeProp,
|
|
63
135
|
valueFormatter,
|
|
64
136
|
slots,
|
|
65
|
-
slotProps
|
|
137
|
+
slotProps,
|
|
138
|
+
tickInterval,
|
|
139
|
+
tickLabelInterval
|
|
66
140
|
} = defaultizedProps;
|
|
67
141
|
const theme = useTheme();
|
|
68
142
|
const classes = useUtilityClasses(_extends({}, defaultizedProps, {
|
|
@@ -75,20 +149,52 @@ function ChartsXAxis(inProps) {
|
|
|
75
149
|
height
|
|
76
150
|
} = React.useContext(DrawingContext);
|
|
77
151
|
const tickSize = disableTicks ? 4 : tickSizeProp;
|
|
152
|
+
const positionSign = position === 'bottom' ? 1 : -1;
|
|
153
|
+
const Line = slots?.axisLine ?? 'line';
|
|
154
|
+
const Tick = slots?.axisTick ?? 'line';
|
|
155
|
+
const TickLabel = slots?.axisTickLabel ?? ChartsText;
|
|
156
|
+
const Label = slots?.axisLabel ?? ChartsText;
|
|
157
|
+
const axisTickLabelProps = useSlotProps({
|
|
158
|
+
elementType: TickLabel,
|
|
159
|
+
externalSlotProps: slotProps?.axisTickLabel,
|
|
160
|
+
additionalProps: {
|
|
161
|
+
style: _extends({
|
|
162
|
+
textAnchor: 'middle',
|
|
163
|
+
dominantBaseline: position === 'bottom' ? 'hanging' : 'auto',
|
|
164
|
+
fontSize: tickFontSize ?? 12
|
|
165
|
+
}, tickLabelStyle),
|
|
166
|
+
className: classes.tickLabel
|
|
167
|
+
},
|
|
168
|
+
className: classes.tickLabel,
|
|
169
|
+
ownerState: {}
|
|
170
|
+
});
|
|
78
171
|
const xTicks = useTicks({
|
|
79
172
|
scale: xScale,
|
|
80
|
-
|
|
81
|
-
valueFormatter
|
|
173
|
+
tickNumber,
|
|
174
|
+
valueFormatter,
|
|
175
|
+
tickInterval
|
|
176
|
+
});
|
|
177
|
+
const xTicksWithDimension = addLabelDimension(xTicks, {
|
|
178
|
+
tickLabelStyle: axisTickLabelProps.style,
|
|
179
|
+
tickLabelInterval,
|
|
180
|
+
isMounted
|
|
82
181
|
});
|
|
83
|
-
const positionSigne = position === 'bottom' ? 1 : -1;
|
|
84
182
|
const labelRefPoint = {
|
|
85
183
|
x: left + width / 2,
|
|
86
|
-
y:
|
|
184
|
+
y: positionSign * (tickSize + 22)
|
|
87
185
|
};
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
186
|
+
const axisLabelProps = useSlotProps({
|
|
187
|
+
elementType: Label,
|
|
188
|
+
externalSlotProps: slotProps?.axisLabel,
|
|
189
|
+
additionalProps: {
|
|
190
|
+
style: _extends({
|
|
191
|
+
fontSize: labelFontSize ?? 14,
|
|
192
|
+
textAnchor: 'middle',
|
|
193
|
+
dominantBaseline: position === 'bottom' ? 'hanging' : 'auto'
|
|
194
|
+
}, labelStyle)
|
|
195
|
+
},
|
|
196
|
+
ownerState: {}
|
|
197
|
+
});
|
|
92
198
|
return /*#__PURE__*/_jsxs(AxisRoot, {
|
|
93
199
|
transform: `translate(0, ${position === 'bottom' ? top + height : top})`,
|
|
94
200
|
className: classes.root,
|
|
@@ -96,40 +202,33 @@ function ChartsXAxis(inProps) {
|
|
|
96
202
|
x1: xScale.range()[0],
|
|
97
203
|
x2: xScale.range()[1],
|
|
98
204
|
className: classes.line
|
|
99
|
-
}, slotProps?.axisLine)),
|
|
205
|
+
}, slotProps?.axisLine)), xTicksWithDimension.map(({
|
|
100
206
|
formattedValue,
|
|
101
207
|
offset,
|
|
102
|
-
labelOffset
|
|
208
|
+
labelOffset,
|
|
209
|
+
skipLabel
|
|
103
210
|
}, index) => {
|
|
104
211
|
const xTickLabel = labelOffset ?? 0;
|
|
105
|
-
const yTickLabel =
|
|
212
|
+
const yTickLabel = positionSign * (tickSize + 3);
|
|
106
213
|
return /*#__PURE__*/_jsxs("g", {
|
|
107
214
|
transform: `translate(${offset}, 0)`,
|
|
108
215
|
className: classes.tickContainer,
|
|
109
216
|
children: [!disableTicks && /*#__PURE__*/_jsx(Tick, _extends({
|
|
110
|
-
y2:
|
|
217
|
+
y2: positionSign * tickSize,
|
|
111
218
|
className: classes.tick
|
|
112
|
-
}, slotProps?.axisTick)), formattedValue !== undefined && /*#__PURE__*/_jsx(TickLabel, _extends({
|
|
219
|
+
}, slotProps?.axisTick)), formattedValue !== undefined && !skipLabel && /*#__PURE__*/_jsx(TickLabel, _extends({
|
|
113
220
|
x: xTickLabel,
|
|
114
|
-
y: yTickLabel
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
fontSize: tickFontSize
|
|
118
|
-
},
|
|
119
|
-
className: classes.tickLabel
|
|
120
|
-
}, slotProps?.axisTickLabel, {
|
|
121
|
-
children: formattedValue
|
|
221
|
+
y: yTickLabel
|
|
222
|
+
}, axisTickLabelProps, {
|
|
223
|
+
text: formattedValue.toString()
|
|
122
224
|
}))]
|
|
123
225
|
}, index);
|
|
124
|
-
}), label && /*#__PURE__*/_jsx(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
}, slotProps?.axisLabel, {
|
|
131
|
-
children: label
|
|
132
|
-
}))]
|
|
226
|
+
}), label && /*#__PURE__*/_jsx("g", {
|
|
227
|
+
className: classes.label,
|
|
228
|
+
children: /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, axisLabelProps, {
|
|
229
|
+
text: label
|
|
230
|
+
}))
|
|
231
|
+
})]
|
|
133
232
|
});
|
|
134
233
|
}
|
|
135
234
|
process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
|
|
@@ -138,9 +237,10 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
|
|
|
138
237
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
139
238
|
// ----------------------------------------------------------------------
|
|
140
239
|
/**
|
|
141
|
-
*
|
|
240
|
+
* The id of the axis to render.
|
|
241
|
+
* If undefined, it will be the first defined axis.
|
|
142
242
|
*/
|
|
143
|
-
axisId: PropTypes.string
|
|
243
|
+
axisId: PropTypes.string,
|
|
144
244
|
/**
|
|
145
245
|
* Override or extend the styles applied to the component.
|
|
146
246
|
*/
|
|
@@ -167,8 +267,13 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
|
|
|
167
267
|
/**
|
|
168
268
|
* The font size of the axis label.
|
|
169
269
|
* @default 14
|
|
270
|
+
* @deprecated Consider using `labelStyle.fontSize` instead.
|
|
170
271
|
*/
|
|
171
272
|
labelFontSize: PropTypes.number,
|
|
273
|
+
/**
|
|
274
|
+
* The style applied to the axis label.
|
|
275
|
+
*/
|
|
276
|
+
labelStyle: PropTypes.object,
|
|
172
277
|
/**
|
|
173
278
|
* Position of the axis.
|
|
174
279
|
*/
|
|
@@ -191,8 +296,28 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
|
|
|
191
296
|
/**
|
|
192
297
|
* The font size of the axis ticks text.
|
|
193
298
|
* @default 12
|
|
299
|
+
* @deprecated Consider using `tickLabelStyle.fontSize` instead.
|
|
194
300
|
*/
|
|
195
301
|
tickFontSize: PropTypes.number,
|
|
302
|
+
/**
|
|
303
|
+
* Defines which ticks are displayed. Its value can be:
|
|
304
|
+
* - 'auto' In such case the ticks are computed based on axis scale and other parameters.
|
|
305
|
+
* - a filtering function of the form `(value, index) => boolean` which is available only if the axis has a data property.
|
|
306
|
+
* - an array containing the values where ticks should be displayed.
|
|
307
|
+
* @default 'auto'
|
|
308
|
+
*/
|
|
309
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
310
|
+
/**
|
|
311
|
+
* Defines which ticks get its label displayed. Its value can be:
|
|
312
|
+
* - 'auto' In such case, labels are displayed if they do not overlap with the previous one.
|
|
313
|
+
* - a filtering function of the form (value, index) => boolean. Warning: the index is tick index, not data ones.
|
|
314
|
+
* @default 'auto'
|
|
315
|
+
*/
|
|
316
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
317
|
+
/**
|
|
318
|
+
* The style applied to ticks text.
|
|
319
|
+
*/
|
|
320
|
+
tickLabelStyle: PropTypes.object,
|
|
196
321
|
/**
|
|
197
322
|
* Maximal step between two ticks.
|
|
198
323
|
* When using time data, the value is assumed to be in ms.
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
const _excluded = ["scale", "
|
|
3
|
+
const _excluded = ["scale", "tickNumber"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
|
+
import { useSlotProps } from '@mui/base/utils';
|
|
6
7
|
import { unstable_composeClasses as composeClasses } from '@mui/utils';
|
|
7
8
|
import { useThemeProps, useTheme } from '@mui/material/styles';
|
|
8
9
|
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
9
10
|
import { DrawingContext } from '../context/DrawingProvider';
|
|
10
11
|
import useTicks from '../hooks/useTicks';
|
|
11
|
-
import {
|
|
12
|
+
import { AxisRoot } from '../internals/components/AxisSharedComponents';
|
|
13
|
+
import { ChartsText } from '../internals/components/ChartsText';
|
|
12
14
|
import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
|
|
13
15
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
16
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -35,22 +37,35 @@ const defaultProps = {
|
|
|
35
37
|
labelFontSize: 14,
|
|
36
38
|
tickSize: 6
|
|
37
39
|
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Demos:
|
|
43
|
+
*
|
|
44
|
+
* - [Axis](https://mui.com/x/react-charts/axis/)
|
|
45
|
+
*
|
|
46
|
+
* API:
|
|
47
|
+
*
|
|
48
|
+
* - [ChartsYAxis API](https://mui.com/x/api/charts/charts-y-axis/)
|
|
49
|
+
*/
|
|
38
50
|
function ChartsYAxis(inProps) {
|
|
39
51
|
const props = useThemeProps({
|
|
40
52
|
props: _extends({}, defaultProps, inProps),
|
|
41
53
|
name: 'MuiChartsYAxis'
|
|
42
54
|
});
|
|
55
|
+
const {
|
|
56
|
+
yAxisIds
|
|
57
|
+
} = React.useContext(CartesianContext);
|
|
43
58
|
const _React$useContext = React.useContext(CartesianContext),
|
|
44
|
-
|
|
59
|
+
_ref = props.axisId ?? yAxisIds[0],
|
|
45
60
|
{
|
|
46
61
|
yAxis: {
|
|
47
|
-
[
|
|
62
|
+
[_ref]: {
|
|
48
63
|
scale: yScale,
|
|
49
|
-
|
|
64
|
+
tickNumber
|
|
50
65
|
}
|
|
51
66
|
}
|
|
52
67
|
} = _React$useContext,
|
|
53
|
-
settings = _objectWithoutPropertiesLoose(_React$useContext.yAxis[
|
|
68
|
+
settings = _objectWithoutPropertiesLoose(_React$useContext.yAxis[_ref], _excluded);
|
|
54
69
|
const defaultizedProps = _extends({}, defaultProps, settings, props);
|
|
55
70
|
const {
|
|
56
71
|
position,
|
|
@@ -77,18 +92,44 @@ function ChartsYAxis(inProps) {
|
|
|
77
92
|
const tickSize = disableTicks ? 4 : tickSizeProp;
|
|
78
93
|
const yTicks = useTicks({
|
|
79
94
|
scale: yScale,
|
|
80
|
-
|
|
95
|
+
tickNumber,
|
|
81
96
|
valueFormatter
|
|
82
97
|
});
|
|
83
|
-
const
|
|
98
|
+
const positionSign = position === 'right' ? 1 : -1;
|
|
84
99
|
const labelRefPoint = {
|
|
85
|
-
x:
|
|
100
|
+
x: positionSign * (tickFontSize + tickSize + 10),
|
|
86
101
|
y: top + height / 2
|
|
87
102
|
};
|
|
88
|
-
const Line = slots?.axisLine ??
|
|
89
|
-
const Tick = slots?.axisTick ??
|
|
90
|
-
const TickLabel = slots?.axisTickLabel ??
|
|
91
|
-
const Label = slots?.axisLabel ??
|
|
103
|
+
const Line = slots?.axisLine ?? 'line';
|
|
104
|
+
const Tick = slots?.axisTick ?? 'line';
|
|
105
|
+
const TickLabel = slots?.axisTickLabel ?? ChartsText;
|
|
106
|
+
const Label = slots?.axisLabel ?? ChartsText;
|
|
107
|
+
const axisTickLabelProps = useSlotProps({
|
|
108
|
+
elementType: TickLabel,
|
|
109
|
+
externalSlotProps: slotProps?.axisTickLabel,
|
|
110
|
+
additionalProps: {
|
|
111
|
+
style: {
|
|
112
|
+
fontSize: tickFontSize,
|
|
113
|
+
textAnchor: position === 'right' ? 'start' : 'end',
|
|
114
|
+
dominantBaseline: 'central'
|
|
115
|
+
},
|
|
116
|
+
className: classes.tickLabel
|
|
117
|
+
},
|
|
118
|
+
ownerState: {}
|
|
119
|
+
});
|
|
120
|
+
const axisLabelProps = useSlotProps({
|
|
121
|
+
elementType: Label,
|
|
122
|
+
externalSlotProps: slotProps?.axisLabel,
|
|
123
|
+
additionalProps: {
|
|
124
|
+
style: {
|
|
125
|
+
fontSize: labelFontSize,
|
|
126
|
+
angle: positionSign * 90,
|
|
127
|
+
textAnchor: 'middle',
|
|
128
|
+
dominantBaseline: 'auto'
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
ownerState: {}
|
|
132
|
+
});
|
|
92
133
|
return /*#__PURE__*/_jsxs(AxisRoot, {
|
|
93
134
|
transform: `translate(${position === 'right' ? left + width : left}, 0)`,
|
|
94
135
|
className: classes.root,
|
|
@@ -101,36 +142,26 @@ function ChartsYAxis(inProps) {
|
|
|
101
142
|
offset,
|
|
102
143
|
labelOffset
|
|
103
144
|
}, index) => {
|
|
104
|
-
const xTickLabel =
|
|
145
|
+
const xTickLabel = positionSign * (tickSize + 2);
|
|
105
146
|
const yTickLabel = labelOffset;
|
|
106
147
|
return /*#__PURE__*/_jsxs("g", {
|
|
107
148
|
transform: `translate(0, ${offset})`,
|
|
108
149
|
className: classes.tickContainer,
|
|
109
150
|
children: [!disableTicks && /*#__PURE__*/_jsx(Tick, _extends({
|
|
110
|
-
x2:
|
|
151
|
+
x2: positionSign * tickSize,
|
|
111
152
|
className: classes.tick
|
|
112
153
|
}, slotProps?.axisTick)), formattedValue !== undefined && /*#__PURE__*/_jsx(TickLabel, _extends({
|
|
113
154
|
x: xTickLabel,
|
|
114
155
|
y: yTickLabel,
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
fontSize: tickFontSize
|
|
118
|
-
},
|
|
119
|
-
className: classes.tickLabel
|
|
120
|
-
}, slotProps?.axisTickLabel, {
|
|
121
|
-
children: formattedValue.toLocaleString()
|
|
122
|
-
}))]
|
|
156
|
+
text: formattedValue.toString()
|
|
157
|
+
}, axisTickLabelProps))]
|
|
123
158
|
}, index);
|
|
124
|
-
}), label && /*#__PURE__*/_jsx(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
className: classes.label
|
|
131
|
-
}, slotProps?.axisLabel, {
|
|
132
|
-
children: label
|
|
133
|
-
}))]
|
|
159
|
+
}), label && /*#__PURE__*/_jsx("g", {
|
|
160
|
+
className: classes.label,
|
|
161
|
+
children: /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, axisLabelProps, {
|
|
162
|
+
text: label
|
|
163
|
+
}))
|
|
164
|
+
})]
|
|
134
165
|
});
|
|
135
166
|
}
|
|
136
167
|
process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
|
|
@@ -139,9 +170,10 @@ process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
|
|
|
139
170
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
140
171
|
// ----------------------------------------------------------------------
|
|
141
172
|
/**
|
|
142
|
-
*
|
|
173
|
+
* The id of the axis to render.
|
|
174
|
+
* If undefined, it will be the first defined axis.
|
|
143
175
|
*/
|
|
144
|
-
axisId: PropTypes.string
|
|
176
|
+
axisId: PropTypes.string,
|
|
145
177
|
/**
|
|
146
178
|
* Override or extend the styles applied to the component.
|
|
147
179
|
*/
|
|
@@ -168,8 +200,13 @@ process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
|
|
|
168
200
|
/**
|
|
169
201
|
* The font size of the axis label.
|
|
170
202
|
* @default 14
|
|
203
|
+
* @deprecated Consider using `labelStyle.fontSize` instead.
|
|
171
204
|
*/
|
|
172
205
|
labelFontSize: PropTypes.number,
|
|
206
|
+
/**
|
|
207
|
+
* The style applied to the axis label.
|
|
208
|
+
*/
|
|
209
|
+
labelStyle: PropTypes.object,
|
|
173
210
|
/**
|
|
174
211
|
* Position of the axis.
|
|
175
212
|
*/
|
|
@@ -192,8 +229,28 @@ process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
|
|
|
192
229
|
/**
|
|
193
230
|
* The font size of the axis ticks text.
|
|
194
231
|
* @default 12
|
|
232
|
+
* @deprecated Consider using `tickLabelStyle.fontSize` instead.
|
|
195
233
|
*/
|
|
196
234
|
tickFontSize: PropTypes.number,
|
|
235
|
+
/**
|
|
236
|
+
* Defines which ticks are displayed. Its value can be:
|
|
237
|
+
* - 'auto' In such case the ticks are computed based on axis scale and other parameters.
|
|
238
|
+
* - a filtering function of the form `(value, index) => boolean` which is available only if the axis has a data property.
|
|
239
|
+
* - an array containing the values where ticks should be displayed.
|
|
240
|
+
* @default 'auto'
|
|
241
|
+
*/
|
|
242
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
243
|
+
/**
|
|
244
|
+
* Defines which ticks get its label displayed. Its value can be:
|
|
245
|
+
* - 'auto' In such case, labels are displayed if they do not overlap with the previous one.
|
|
246
|
+
* - a filtering function of the form (value, index) => boolean. Warning: the index is tick index, not data ones.
|
|
247
|
+
* @default 'auto'
|
|
248
|
+
*/
|
|
249
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
250
|
+
/**
|
|
251
|
+
* The style applied to ticks text.
|
|
252
|
+
*/
|
|
253
|
+
tickLabelStyle: PropTypes.object,
|
|
197
254
|
/**
|
|
198
255
|
* Maximal step between two ticks.
|
|
199
256
|
* When using time data, the value is assumed to be in ms.
|
|
@@ -55,6 +55,16 @@ AreaElementPath.propTypes = {
|
|
|
55
55
|
}).isRequired,
|
|
56
56
|
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
|
|
57
57
|
};
|
|
58
|
+
/**
|
|
59
|
+
* Demos:
|
|
60
|
+
*
|
|
61
|
+
* - [Lines](https://mui.com/x/react-charts/lines/)
|
|
62
|
+
* - [Areas demonstration](https://mui.com/x/react-charts/areas-demo/)
|
|
63
|
+
*
|
|
64
|
+
* API:
|
|
65
|
+
*
|
|
66
|
+
* - [AreaElement API](https://mui.com/x/api/charts/area-element/)
|
|
67
|
+
*/
|
|
58
68
|
function AreaElement(props) {
|
|
59
69
|
const {
|
|
60
70
|
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
|
const {
|
|
15
26
|
slots,
|
|
@@ -41,20 +52,28 @@ function AreaPlot(props) {
|
|
|
41
52
|
const {
|
|
42
53
|
xAxisKey = defaultXAxisId,
|
|
43
54
|
yAxisKey = defaultYAxisId,
|
|
44
|
-
stackedData
|
|
55
|
+
stackedData,
|
|
56
|
+
data,
|
|
57
|
+
connectNulls
|
|
45
58
|
} = series[seriesId];
|
|
46
59
|
const xScale = getValueToPositionMapper(xAxis[xAxisKey].scale);
|
|
47
60
|
const yScale = yAxis[yAxisKey].scale;
|
|
48
61
|
const xData = xAxis[xAxisKey].data;
|
|
49
|
-
if (
|
|
50
|
-
|
|
62
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
63
|
+
if (xData === undefined) {
|
|
64
|
+
throw new Error(`Axis of id "${xAxisKey}" should have data property to be able to display a line plot.`);
|
|
65
|
+
}
|
|
66
|
+
if (xData.length < stackedData.length) {
|
|
67
|
+
throw new Error(`MUI: data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items)`);
|
|
68
|
+
}
|
|
51
69
|
}
|
|
52
|
-
const areaPath = d3Area().x(d => xScale(d.x)).y0(d => yScale(d.y[0])).y1(d => yScale(d.y[1]));
|
|
70
|
+
const areaPath = d3Area().x(d => xScale(d.x)).defined((_, i) => connectNulls || data[i] != null).y0(d => d.y && yScale(d.y[0])).y1(d => d.y && yScale(d.y[1]));
|
|
53
71
|
const curve = getCurveFactory(series[seriesId].curve);
|
|
54
|
-
const
|
|
72
|
+
const formattedData = xData?.map((x, index) => ({
|
|
55
73
|
x,
|
|
56
74
|
y: stackedData[index]
|
|
57
|
-
}));
|
|
75
|
+
})) ?? [];
|
|
76
|
+
const d3Data = connectNulls ? formattedData.filter((_, i) => data[i] != null) : formattedData;
|
|
58
77
|
return !!series[seriesId].area && /*#__PURE__*/_jsx(AreaElement, {
|
|
59
78
|
id: seriesId,
|
|
60
79
|
d: areaPath.curve(curve)(d3Data) || undefined,
|