@mui/x-charts 7.10.0 → 7.11.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.js +2 -2
- package/BarChart/BarElement.d.ts +2 -1
- package/BarChart/BarLabel/BarLabelItem.d.ts +2 -1
- package/BarChart/BarPlot.js +8 -8
- package/BarChart/checkScaleErrors.d.ts +4 -4
- package/BarChart/checkScaleErrors.js +11 -11
- package/BarChart/extremums.js +4 -1
- package/BarChart/formatter.js +2 -2
- package/BarChart/useBarChartProps.js +38 -33
- package/CHANGELOG.md +169 -0
- package/ChartContainer/ChartContainer.d.ts +28 -2
- package/ChartContainer/ChartContainer.js +25 -66
- package/ChartContainer/useChartContainerHooks.d.ts +1 -1
- package/ChartContainer/useChartContainerHooks.js +2 -2
- package/ChartContainer/useChartContainerProps.d.ts +86 -0
- package/ChartContainer/useChartContainerProps.js +95 -0
- package/ChartContainer/useDefaultizeAxis.d.ts +36 -0
- package/ChartContainer/useDefaultizeAxis.js +29 -0
- package/ChartsAxis/ChartsAxis.js +4 -4
- package/ChartsAxisHighlight/ChartsAxisHighlight.js +1 -1
- package/ChartsLegend/ChartsLegend.d.ts +3 -12
- package/ChartsLegend/ContinuousColorLegend.d.ts +65 -0
- package/ChartsLegend/ContinuousColorLegend.js +398 -0
- package/ChartsLegend/DefaultChartsLegend.d.ts +7 -50
- package/ChartsLegend/DefaultChartsLegend.js +13 -198
- package/ChartsLegend/LegendPerItem.d.ts +61 -0
- package/ChartsLegend/LegendPerItem.js +151 -0
- package/ChartsLegend/PiecewiseColorLegend.d.ts +26 -0
- package/ChartsLegend/PiecewiseColorLegend.js +169 -0
- package/ChartsLegend/chartsLegend.types.d.ts +31 -0
- package/ChartsLegend/chartsLegend.types.js +5 -0
- package/ChartsLegend/index.d.ts +2 -0
- package/ChartsLegend/index.js +22 -0
- package/ChartsLegend/legend.types.d.ts +62 -0
- package/ChartsLegend/legend.types.js +5 -0
- package/ChartsLegend/legendItemsPlacement.d.ts +3 -0
- package/ChartsLegend/legendItemsPlacement.js +79 -0
- package/ChartsLegend/useAxis.d.ts +7 -0
- package/ChartsLegend/useAxis.js +47 -0
- package/ChartsLegend/utils.d.ts +1 -8
- package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +3 -1
- package/ChartsOverlay/ChartsOverlay.d.ts +3 -2
- package/ChartsReferenceLine/ChartsReferenceLine.d.ts +1 -1
- package/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/ChartsReferenceLine/ChartsXReferenceLine.js +1 -2
- package/ChartsReferenceLine/ChartsYReferenceLine.js +1 -2
- package/ChartsSurface.js +3 -1
- package/ChartsTooltip/ChartsAxisTooltipContent.js +7 -3
- package/ChartsTooltip/ChartsItemTooltipContent.js +4 -4
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +30 -20
- package/ChartsXAxis/ChartsXAxis.js +1 -1
- package/ChartsYAxis/ChartsYAxis.js +15 -3
- package/Gauge/Gauge.d.ts +1 -4
- package/Gauge/Gauge.js +9 -6
- package/Gauge/GaugeContainer.js +8 -4
- package/Gauge/GaugeProvider.js +9 -9
- package/LineChart/AnimatedArea.js +2 -2
- package/LineChart/AnimatedLine.js +2 -2
- package/LineChart/AreaElement.d.ts +2 -1
- package/LineChart/AreaPlot.js +10 -6
- package/LineChart/LineChart.js +5 -2
- package/LineChart/LineElement.d.ts +2 -1
- package/LineChart/LineHighlightPlot.d.ts +2 -1
- package/LineChart/LineHighlightPlot.js +17 -5
- package/LineChart/LinePlot.js +10 -6
- package/LineChart/MarkElement.js +2 -2
- package/LineChart/MarkPlot.js +13 -25
- package/LineChart/extremums.js +4 -1
- package/LineChart/formatter.js +2 -2
- package/LineChart/useLineChartProps.js +38 -33
- package/PieChart/PieArc.js +1 -0
- package/PieChart/PieChart.d.ts +1 -4
- package/PieChart/PieChart.js +40 -34
- package/PieChart/PiePlot.js +6 -6
- package/PieChart/getPieCoordinates.js +3 -3
- package/ResponsiveChartContainer/ResponsiveChartContainer.js +8 -20
- package/ResponsiveChartContainer/useChartContainerDimensions.d.ts +5 -1
- package/ResponsiveChartContainer/useChartContainerDimensions.js +8 -4
- package/ResponsiveChartContainer/useResponsiveChartContainerProps.d.ts +20 -0
- package/ResponsiveChartContainer/useResponsiveChartContainerProps.js +73 -0
- package/ScatterChart/Scatter.js +6 -9
- package/ScatterChart/ScatterChart.js +4 -1
- package/ScatterChart/ScatterPlot.js +6 -3
- package/ScatterChart/extremums.js +8 -2
- package/ScatterChart/useScatterChartProps.js +35 -30
- package/SparkLineChart/SparkLineChart.js +27 -22
- package/context/CartesianProvider/CartesianContext.d.ts +1 -1
- package/context/CartesianProvider/CartesianProvider.d.ts +2 -3
- package/context/CartesianProvider/CartesianProvider.js +18 -7
- package/context/CartesianProvider/computeValue.d.ts +32 -9
- package/context/CartesianProvider/computeValue.js +20 -16
- package/context/CartesianProvider/defaultizeAxis.d.ts +36 -0
- package/context/CartesianProvider/defaultizeAxis.js +21 -0
- package/context/CartesianProvider/index.d.ts +0 -1
- package/context/CartesianProvider/index.js +1 -3
- package/context/CartesianProvider/normalizeAxis.d.ts +1 -1
- package/context/CartesianProvider/normalizeAxis.js +2 -2
- package/context/DrawingProvider.d.ts +12 -0
- package/context/DrawingProvider.js +15 -2
- package/context/HighlightedProvider/HighlightedProvider.js +2 -2
- package/context/SeriesContextProvider.js +1 -1
- package/context/ZAxisContextProvider.d.ts +1 -1
- package/context/ZAxisContextProvider.js +1 -1
- package/esm/BarChart/BarChart.js +2 -2
- package/esm/BarChart/BarPlot.js +8 -8
- package/esm/BarChart/checkScaleErrors.js +11 -11
- package/esm/BarChart/extremums.js +4 -1
- package/esm/BarChart/formatter.js +2 -2
- package/esm/BarChart/useBarChartProps.js +38 -33
- package/esm/ChartContainer/ChartContainer.js +25 -66
- package/esm/ChartContainer/useChartContainerHooks.js +2 -2
- package/esm/ChartContainer/useChartContainerProps.js +87 -0
- package/esm/ChartContainer/useDefaultizeAxis.js +19 -0
- package/esm/ChartsAxis/ChartsAxis.js +4 -4
- package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +1 -1
- package/esm/ChartsLegend/ContinuousColorLegend.js +390 -0
- package/esm/ChartsLegend/DefaultChartsLegend.js +14 -198
- package/esm/ChartsLegend/LegendPerItem.js +141 -0
- package/esm/ChartsLegend/PiecewiseColorLegend.js +161 -0
- package/esm/ChartsLegend/chartsLegend.types.js +1 -0
- package/esm/ChartsLegend/index.js +2 -0
- package/esm/ChartsLegend/legend.types.js +1 -0
- package/esm/ChartsLegend/legendItemsPlacement.js +72 -0
- package/esm/ChartsLegend/useAxis.js +39 -0
- package/esm/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +3 -1
- package/esm/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +2 -3
- package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +2 -3
- package/esm/ChartsSurface.js +3 -1
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +7 -3
- package/esm/ChartsTooltip/ChartsItemTooltipContent.js +4 -4
- package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +30 -20
- package/esm/ChartsXAxis/ChartsXAxis.js +1 -1
- package/esm/ChartsYAxis/ChartsYAxis.js +15 -3
- package/esm/Gauge/Gauge.js +8 -5
- package/esm/Gauge/GaugeContainer.js +8 -4
- package/esm/Gauge/GaugeProvider.js +1 -1
- package/esm/LineChart/AnimatedArea.js +1 -1
- package/esm/LineChart/AnimatedLine.js +1 -1
- package/esm/LineChart/AreaPlot.js +10 -6
- package/esm/LineChart/LineChart.js +5 -2
- package/esm/LineChart/LineHighlightPlot.js +17 -5
- package/esm/LineChart/LinePlot.js +10 -6
- package/esm/LineChart/MarkElement.js +1 -1
- package/esm/LineChart/MarkPlot.js +12 -24
- package/esm/LineChart/extremums.js +4 -1
- package/esm/LineChart/formatter.js +2 -2
- package/esm/LineChart/useLineChartProps.js +38 -33
- package/esm/PieChart/PieArc.js +1 -0
- package/esm/PieChart/PieChart.js +39 -33
- package/esm/PieChart/PiePlot.js +1 -1
- package/esm/PieChart/getPieCoordinates.js +1 -1
- package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +8 -20
- package/esm/ResponsiveChartContainer/useChartContainerDimensions.js +8 -4
- package/esm/ResponsiveChartContainer/useResponsiveChartContainerProps.js +65 -0
- package/esm/ScatterChart/Scatter.js +6 -9
- package/esm/ScatterChart/ScatterChart.js +4 -1
- package/esm/ScatterChart/ScatterPlot.js +6 -3
- package/esm/ScatterChart/extremums.js +8 -2
- package/esm/ScatterChart/useScatterChartProps.js +35 -30
- package/esm/SparkLineChart/SparkLineChart.js +27 -22
- package/esm/context/CartesianProvider/CartesianProvider.js +18 -7
- package/esm/context/CartesianProvider/computeValue.js +20 -16
- package/esm/context/CartesianProvider/defaultizeAxis.js +13 -0
- package/esm/context/CartesianProvider/index.js +1 -3
- package/esm/context/CartesianProvider/normalizeAxis.js +2 -2
- package/esm/context/DrawingProvider.js +15 -2
- package/esm/context/HighlightedProvider/HighlightedProvider.js +2 -2
- package/esm/context/SeriesContextProvider.js +1 -1
- package/esm/context/ZAxisContextProvider.js +1 -1
- package/esm/hooks/useAxisEvents.js +14 -17
- package/esm/hooks/useDrawingArea.js +5 -3
- package/esm/hooks/useReducedMotion.js +4 -2
- package/esm/internals/SlotComponentPropsFromProps.js +1 -0
- package/esm/internals/cleanId.js +6 -0
- package/esm/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +3 -2
- package/esm/internals/geometry.js +1 -1
- package/esm/internals/{utils.js → getPercentageValue.js} +1 -13
- package/esm/internals/getSymbol.js +5 -0
- package/esm/internals/index.js +3 -1
- package/esm/internals/isDefined.js +3 -0
- package/esm/internals/notNull.js +3 -0
- package/esm/internals/ts-generic.js +1 -0
- package/esm/internals/warning.js +19 -11
- package/hooks/useAxisEvents.js +14 -17
- package/hooks/useDrawingArea.js +5 -3
- package/hooks/useReducedMotion.js +4 -2
- package/index.js +1 -1
- package/internals/SlotComponentPropsFromProps.d.ts +1 -0
- package/internals/SlotComponentPropsFromProps.js +5 -0
- package/internals/cleanId.d.ts +4 -0
- package/internals/cleanId.js +12 -0
- package/internals/components/ChartsAxesGradients/ChartsContinuousGradient.d.ts +6 -0
- package/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +3 -2
- package/internals/defaultizeColor.d.ts +7 -0
- package/internals/geometry.js +1 -1
- package/internals/getPercentageValue.d.ts +7 -0
- package/internals/{utils.js → getPercentageValue.js} +1 -15
- package/internals/getSymbol.d.ts +2 -0
- package/internals/getSymbol.js +11 -0
- package/internals/index.d.ts +3 -1
- package/internals/index.js +25 -5
- package/internals/isDefined.d.ts +1 -0
- package/internals/isDefined.js +9 -0
- package/internals/notNull.d.ts +1 -0
- package/internals/notNull.js +9 -0
- package/internals/ts-generic.d.ts +5 -0
- package/internals/ts-generic.js +5 -0
- package/internals/warning.d.ts +2 -1
- package/internals/warning.js +21 -12
- package/models/axis.d.ts +5 -2
- package/models/helpers.d.ts +1 -0
- package/models/seriesType/common.d.ts +10 -0
- package/models/seriesType/config.d.ts +2 -16
- package/models/seriesType/scatter.d.ts +5 -0
- package/modern/BarChart/BarChart.js +2 -2
- package/modern/BarChart/BarPlot.js +8 -8
- package/modern/BarChart/checkScaleErrors.js +11 -11
- package/modern/BarChart/extremums.js +4 -1
- package/modern/BarChart/formatter.js +2 -2
- package/modern/BarChart/useBarChartProps.js +38 -33
- package/modern/ChartContainer/ChartContainer.js +25 -66
- package/modern/ChartContainer/useChartContainerHooks.js +2 -2
- package/modern/ChartContainer/useChartContainerProps.js +87 -0
- package/modern/ChartContainer/useDefaultizeAxis.js +19 -0
- package/modern/ChartsAxis/ChartsAxis.js +4 -4
- package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +1 -1
- package/modern/ChartsLegend/ContinuousColorLegend.js +390 -0
- package/modern/ChartsLegend/DefaultChartsLegend.js +14 -198
- package/modern/ChartsLegend/LegendPerItem.js +141 -0
- package/modern/ChartsLegend/PiecewiseColorLegend.js +161 -0
- package/modern/ChartsLegend/chartsLegend.types.js +1 -0
- package/modern/ChartsLegend/index.js +2 -0
- package/modern/ChartsLegend/legend.types.js +1 -0
- package/modern/ChartsLegend/legendItemsPlacement.js +72 -0
- package/modern/ChartsLegend/useAxis.js +39 -0
- package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +3 -1
- package/modern/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +2 -3
- package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +2 -3
- package/modern/ChartsSurface.js +3 -1
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +7 -3
- package/modern/ChartsTooltip/ChartsItemTooltipContent.js +4 -4
- package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +30 -20
- package/modern/ChartsXAxis/ChartsXAxis.js +1 -1
- package/modern/ChartsYAxis/ChartsYAxis.js +15 -3
- package/modern/Gauge/Gauge.js +8 -5
- package/modern/Gauge/GaugeContainer.js +8 -4
- package/modern/Gauge/GaugeProvider.js +1 -1
- package/modern/LineChart/AnimatedArea.js +1 -1
- package/modern/LineChart/AnimatedLine.js +1 -1
- package/modern/LineChart/AreaPlot.js +10 -6
- package/modern/LineChart/LineChart.js +5 -2
- package/modern/LineChart/LineHighlightPlot.js +17 -5
- package/modern/LineChart/LinePlot.js +10 -6
- package/modern/LineChart/MarkElement.js +1 -1
- package/modern/LineChart/MarkPlot.js +12 -24
- package/modern/LineChart/extremums.js +4 -1
- package/modern/LineChart/formatter.js +2 -2
- package/modern/LineChart/useLineChartProps.js +38 -33
- package/modern/PieChart/PieArc.js +1 -0
- package/modern/PieChart/PieChart.js +39 -33
- package/modern/PieChart/PiePlot.js +1 -1
- package/modern/PieChart/getPieCoordinates.js +1 -1
- package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +8 -20
- package/modern/ResponsiveChartContainer/useChartContainerDimensions.js +8 -4
- package/modern/ResponsiveChartContainer/useResponsiveChartContainerProps.js +65 -0
- package/modern/ScatterChart/Scatter.js +6 -9
- package/modern/ScatterChart/ScatterChart.js +4 -1
- package/modern/ScatterChart/ScatterPlot.js +6 -3
- package/modern/ScatterChart/extremums.js +8 -2
- package/modern/ScatterChart/useScatterChartProps.js +35 -30
- package/modern/SparkLineChart/SparkLineChart.js +27 -22
- package/modern/context/CartesianProvider/CartesianProvider.js +18 -7
- package/modern/context/CartesianProvider/computeValue.js +20 -16
- package/modern/context/CartesianProvider/defaultizeAxis.js +13 -0
- package/modern/context/CartesianProvider/index.js +1 -3
- package/modern/context/CartesianProvider/normalizeAxis.js +2 -2
- package/modern/context/DrawingProvider.js +15 -2
- package/modern/context/HighlightedProvider/HighlightedProvider.js +2 -2
- package/modern/context/SeriesContextProvider.js +1 -1
- package/modern/context/ZAxisContextProvider.js +1 -1
- package/modern/hooks/useAxisEvents.js +14 -17
- package/modern/hooks/useDrawingArea.js +5 -3
- package/modern/hooks/useReducedMotion.js +4 -2
- package/modern/index.js +1 -1
- package/modern/internals/SlotComponentPropsFromProps.js +1 -0
- package/modern/internals/cleanId.js +6 -0
- package/modern/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +3 -2
- package/modern/internals/geometry.js +1 -1
- package/modern/internals/{utils.js → getPercentageValue.js} +1 -13
- package/modern/internals/getSymbol.js +5 -0
- package/modern/internals/index.js +3 -1
- package/modern/internals/isDefined.js +3 -0
- package/modern/internals/notNull.js +3 -0
- package/modern/internals/ts-generic.js +1 -0
- package/modern/internals/warning.js +19 -11
- package/package.json +4 -4
- package/internals/utils.d.ts +0 -18
|
@@ -1,205 +1,18 @@
|
|
|
1
|
-
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
const _excluded = ["drawingArea", "seriesToDisplay"];
|
|
5
4
|
import * as React from 'react';
|
|
6
5
|
import PropTypes from 'prop-types';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { ChartsText } from '../ChartsText';
|
|
10
|
-
import { getWordsByLines } from '../internals/getWordsByLines';
|
|
11
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
|
-
export const ChartsLegendRoot = styled('g', {
|
|
13
|
-
name: 'MuiChartsLegend',
|
|
14
|
-
slot: 'Root',
|
|
15
|
-
overridesResolver: (props, styles) => styles.root
|
|
16
|
-
})({});
|
|
17
|
-
/**
|
|
18
|
-
* Transforms number or partial padding object to a defaultized padding object.
|
|
19
|
-
*/
|
|
20
|
-
const getStandardizedPadding = padding => {
|
|
21
|
-
if (typeof padding === 'number') {
|
|
22
|
-
return {
|
|
23
|
-
left: padding,
|
|
24
|
-
right: padding,
|
|
25
|
-
top: padding,
|
|
26
|
-
bottom: padding
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
return _extends({
|
|
30
|
-
left: 0,
|
|
31
|
-
right: 0,
|
|
32
|
-
top: 0,
|
|
33
|
-
bottom: 0
|
|
34
|
-
}, padding);
|
|
35
|
-
};
|
|
6
|
+
import { LegendPerItem } from './LegendPerItem';
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
36
8
|
function DefaultChartsLegend(props) {
|
|
37
9
|
const {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
itemMarkWidth = 20,
|
|
45
|
-
itemMarkHeight = 20,
|
|
46
|
-
markGap = 5,
|
|
47
|
-
itemGap = 10,
|
|
48
|
-
padding: paddingProps = 10,
|
|
49
|
-
labelStyle: inLabelStyle
|
|
50
|
-
} = props;
|
|
51
|
-
const theme = useTheme();
|
|
52
|
-
const isRTL = theme.direction === 'rtl';
|
|
53
|
-
const labelStyle = React.useMemo(() => _extends({}, theme.typography.subtitle1, {
|
|
54
|
-
color: 'inherit',
|
|
55
|
-
dominantBaseline: 'central',
|
|
56
|
-
textAnchor: 'start',
|
|
57
|
-
fill: (theme.vars || theme).palette.text.primary,
|
|
58
|
-
lineHeight: 1
|
|
59
|
-
}, inLabelStyle),
|
|
60
|
-
// To say to TS that the dominantBaseline and textAnchor are correct
|
|
61
|
-
[inLabelStyle, theme]);
|
|
62
|
-
const padding = React.useMemo(() => getStandardizedPadding(paddingProps), [paddingProps]);
|
|
63
|
-
const getItemSpace = React.useCallback((label, inStyle = {}) => {
|
|
64
|
-
const style = _objectWithoutPropertiesLoose(inStyle, _excluded);
|
|
65
|
-
const linesSize = getWordsByLines({
|
|
66
|
-
style,
|
|
67
|
-
needsComputation: true,
|
|
68
|
-
text: label
|
|
69
|
-
});
|
|
70
|
-
const innerSize = {
|
|
71
|
-
innerWidth: itemMarkWidth + markGap + Math.max(...linesSize.map(size => size.width)),
|
|
72
|
-
innerHeight: Math.max(itemMarkHeight, linesSize.length * linesSize[0].height)
|
|
73
|
-
};
|
|
74
|
-
return _extends({}, innerSize, {
|
|
75
|
-
outerWidth: innerSize.innerWidth + itemGap,
|
|
76
|
-
outerHeight: innerSize.innerHeight + itemGap
|
|
77
|
-
});
|
|
78
|
-
}, [itemGap, itemMarkHeight, itemMarkWidth, markGap]);
|
|
79
|
-
const totalWidth = drawingArea.left + drawingArea.width + drawingArea.right;
|
|
80
|
-
const totalHeight = drawingArea.top + drawingArea.height + drawingArea.bottom;
|
|
81
|
-
const availableWidth = totalWidth - padding.left - padding.right;
|
|
82
|
-
const availableHeight = totalHeight - padding.top - padding.bottom;
|
|
83
|
-
const [seriesWithPosition, legendWidth, legendHeight] = React.useMemo(() => {
|
|
84
|
-
// Start at 0, 0. Will be modified later by padding and position.
|
|
85
|
-
let x = 0;
|
|
86
|
-
let y = 0;
|
|
87
|
-
|
|
88
|
-
// total values used to align legend later.
|
|
89
|
-
let totalWidthUsed = 0;
|
|
90
|
-
let totalHeightUsed = 0;
|
|
91
|
-
let rowIndex = 0;
|
|
92
|
-
const rowMaxHeight = [0];
|
|
93
|
-
const seriesWithRawPosition = seriesToDisplay.map(_ref => {
|
|
94
|
-
let {
|
|
95
|
-
label
|
|
96
|
-
} = _ref,
|
|
97
|
-
other = _objectWithoutPropertiesLoose(_ref, _excluded2);
|
|
98
|
-
const itemSpace = getItemSpace(label, labelStyle);
|
|
99
|
-
const rep = _extends({}, other, {
|
|
100
|
-
label,
|
|
101
|
-
positionX: x,
|
|
102
|
-
positionY: y,
|
|
103
|
-
innerHeight: itemSpace.innerHeight,
|
|
104
|
-
innerWidth: itemSpace.innerWidth,
|
|
105
|
-
outerHeight: itemSpace.outerHeight,
|
|
106
|
-
outerWidth: itemSpace.outerWidth,
|
|
107
|
-
rowIndex
|
|
108
|
-
});
|
|
109
|
-
if (direction === 'row') {
|
|
110
|
-
if (x + itemSpace.innerWidth > availableWidth) {
|
|
111
|
-
// This legend item would create overflow along the x-axis, so we start a new row.
|
|
112
|
-
x = 0;
|
|
113
|
-
y += rowMaxHeight[rowIndex];
|
|
114
|
-
rowIndex += 1;
|
|
115
|
-
if (rowMaxHeight.length <= rowIndex) {
|
|
116
|
-
rowMaxHeight.push(0);
|
|
117
|
-
}
|
|
118
|
-
rep.positionX = x;
|
|
119
|
-
rep.positionY = y;
|
|
120
|
-
rep.rowIndex = rowIndex;
|
|
121
|
-
}
|
|
122
|
-
totalWidthUsed = Math.max(totalWidthUsed, x + itemSpace.outerWidth);
|
|
123
|
-
totalHeightUsed = Math.max(totalHeightUsed, y + itemSpace.outerHeight);
|
|
124
|
-
rowMaxHeight[rowIndex] = Math.max(rowMaxHeight[rowIndex], itemSpace.outerHeight);
|
|
125
|
-
x += itemSpace.outerWidth;
|
|
126
|
-
}
|
|
127
|
-
if (direction === 'column') {
|
|
128
|
-
if (y + itemSpace.innerHeight > availableHeight) {
|
|
129
|
-
// This legend item would create overflow along the y-axis, so we start a new column.
|
|
130
|
-
x = totalWidthUsed + itemGap;
|
|
131
|
-
y = 0;
|
|
132
|
-
rowIndex = 0;
|
|
133
|
-
rep.positionX = x;
|
|
134
|
-
rep.positionY = y;
|
|
135
|
-
rep.rowIndex = rowIndex;
|
|
136
|
-
}
|
|
137
|
-
if (rowMaxHeight.length <= rowIndex) {
|
|
138
|
-
rowMaxHeight.push(0);
|
|
139
|
-
}
|
|
140
|
-
totalWidthUsed = Math.max(totalWidthUsed, x + itemSpace.outerWidth);
|
|
141
|
-
totalHeightUsed = Math.max(totalHeightUsed, y + itemSpace.outerHeight);
|
|
142
|
-
rowIndex += 1;
|
|
143
|
-
y += itemSpace.outerHeight;
|
|
144
|
-
}
|
|
145
|
-
return rep;
|
|
146
|
-
});
|
|
147
|
-
return [seriesWithRawPosition.map(item => _extends({}, item, {
|
|
148
|
-
positionY: item.positionY + (direction === 'row' ? rowMaxHeight[item.rowIndex] / 2 // Get the center of the entire row
|
|
149
|
-
: item.outerHeight / 2) // Get the center of the item
|
|
150
|
-
})), totalWidthUsed, totalHeightUsed];
|
|
151
|
-
}, [seriesToDisplay, getItemSpace, labelStyle, direction, availableWidth, availableHeight, itemGap]);
|
|
152
|
-
const gapX = React.useMemo(() => {
|
|
153
|
-
switch (position.horizontal) {
|
|
154
|
-
case 'left':
|
|
155
|
-
return padding.left;
|
|
156
|
-
case 'right':
|
|
157
|
-
return totalWidth - padding.right - legendWidth;
|
|
158
|
-
default:
|
|
159
|
-
return (totalWidth - legendWidth) / 2;
|
|
160
|
-
}
|
|
161
|
-
}, [position.horizontal, padding.left, padding.right, totalWidth, legendWidth]);
|
|
162
|
-
const gapY = React.useMemo(() => {
|
|
163
|
-
switch (position.vertical) {
|
|
164
|
-
case 'top':
|
|
165
|
-
return padding.top;
|
|
166
|
-
case 'bottom':
|
|
167
|
-
return totalHeight - padding.bottom - legendHeight;
|
|
168
|
-
default:
|
|
169
|
-
return (totalHeight - legendHeight) / 2;
|
|
170
|
-
}
|
|
171
|
-
}, [position.vertical, padding.top, padding.bottom, totalHeight, legendHeight]);
|
|
172
|
-
if (hidden) {
|
|
173
|
-
return null;
|
|
174
|
-
}
|
|
175
|
-
return /*#__PURE__*/_jsx(NoSsr, {
|
|
176
|
-
children: /*#__PURE__*/_jsx(ChartsLegendRoot, {
|
|
177
|
-
className: classes.root,
|
|
178
|
-
children: seriesWithPosition.map(({
|
|
179
|
-
id,
|
|
180
|
-
label,
|
|
181
|
-
color,
|
|
182
|
-
positionX,
|
|
183
|
-
positionY
|
|
184
|
-
}) => /*#__PURE__*/_jsxs("g", {
|
|
185
|
-
className: classes.series,
|
|
186
|
-
transform: `translate(${gapX + (isRTL ? legendWidth - positionX : positionX)} ${gapY + positionY})`,
|
|
187
|
-
children: [/*#__PURE__*/_jsx("rect", {
|
|
188
|
-
className: classes.mark,
|
|
189
|
-
x: isRTL ? -itemMarkWidth : 0,
|
|
190
|
-
y: -itemMarkHeight / 2,
|
|
191
|
-
width: itemMarkWidth,
|
|
192
|
-
height: itemMarkHeight,
|
|
193
|
-
fill: color
|
|
194
|
-
}), /*#__PURE__*/_jsx(ChartsText, {
|
|
195
|
-
style: labelStyle,
|
|
196
|
-
text: label,
|
|
197
|
-
x: (isRTL ? -1 : 1) * (itemMarkWidth + markGap),
|
|
198
|
-
y: 0
|
|
199
|
-
})]
|
|
200
|
-
}, id))
|
|
201
|
-
})
|
|
202
|
-
});
|
|
10
|
+
seriesToDisplay
|
|
11
|
+
} = props,
|
|
12
|
+
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
13
|
+
return /*#__PURE__*/_jsx(LegendPerItem, _extends({}, other, {
|
|
14
|
+
itemsToDisplay: seriesToDisplay
|
|
15
|
+
}));
|
|
203
16
|
}
|
|
204
17
|
process.env.NODE_ENV !== "production" ? DefaultChartsLegend.propTypes = {
|
|
205
18
|
// ----------------------------- Warning --------------------------------
|
|
@@ -209,12 +22,15 @@ process.env.NODE_ENV !== "production" ? DefaultChartsLegend.propTypes = {
|
|
|
209
22
|
/**
|
|
210
23
|
* Override or extend the styles applied to the component.
|
|
211
24
|
*/
|
|
212
|
-
classes: PropTypes.object
|
|
25
|
+
classes: PropTypes.object,
|
|
213
26
|
/**
|
|
214
27
|
* The direction of the legend layout.
|
|
215
28
|
* The default depends on the chart.
|
|
216
29
|
*/
|
|
217
30
|
direction: PropTypes.oneOf(['column', 'row']).isRequired,
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated Use the `useDrawingArea` hook instead.
|
|
33
|
+
*/
|
|
218
34
|
drawingArea: PropTypes.shape({
|
|
219
35
|
bottom: PropTypes.number.isRequired,
|
|
220
36
|
height: PropTypes.number.isRequired,
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
+
const _excluded = ["rotate", "dominantBaseline"];
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { NoSsr } from '@mui/base/NoSsr';
|
|
6
|
+
import { useTheme, styled } from '@mui/material/styles';
|
|
7
|
+
import { ChartsText } from '../ChartsText';
|
|
8
|
+
import { getWordsByLines } from '../internals/getWordsByLines';
|
|
9
|
+
import { legendItemPlacements } from './legendItemsPlacement';
|
|
10
|
+
import { useDrawingArea } from '../hooks/useDrawingArea';
|
|
11
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
|
+
export const ChartsLegendRoot = styled('g', {
|
|
13
|
+
name: 'MuiChartsLegend',
|
|
14
|
+
slot: 'Root',
|
|
15
|
+
overridesResolver: (props, styles) => styles.root
|
|
16
|
+
})({});
|
|
17
|
+
/**
|
|
18
|
+
* Transforms number or partial padding object to a defaultized padding object.
|
|
19
|
+
*/
|
|
20
|
+
const getStandardizedPadding = padding => {
|
|
21
|
+
if (typeof padding === 'number') {
|
|
22
|
+
return {
|
|
23
|
+
left: padding,
|
|
24
|
+
right: padding,
|
|
25
|
+
top: padding,
|
|
26
|
+
bottom: padding
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return _extends({
|
|
30
|
+
left: 0,
|
|
31
|
+
right: 0,
|
|
32
|
+
top: 0,
|
|
33
|
+
bottom: 0
|
|
34
|
+
}, padding);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Internal component to display an array of items as a legend.
|
|
39
|
+
* Used for series legend, and threshold color legend.
|
|
40
|
+
* @ignore - Do not document
|
|
41
|
+
*/
|
|
42
|
+
export function LegendPerItem(props) {
|
|
43
|
+
const {
|
|
44
|
+
hidden,
|
|
45
|
+
position,
|
|
46
|
+
direction,
|
|
47
|
+
itemsToDisplay,
|
|
48
|
+
classes,
|
|
49
|
+
itemMarkWidth = 20,
|
|
50
|
+
itemMarkHeight = 20,
|
|
51
|
+
markGap = 5,
|
|
52
|
+
itemGap = 10,
|
|
53
|
+
padding: paddingProps = 10,
|
|
54
|
+
labelStyle: inLabelStyle
|
|
55
|
+
} = props;
|
|
56
|
+
const theme = useTheme();
|
|
57
|
+
const isRTL = theme.direction === 'rtl';
|
|
58
|
+
const drawingArea = useDrawingArea();
|
|
59
|
+
const labelStyle = React.useMemo(() => _extends({}, theme.typography.subtitle1, {
|
|
60
|
+
color: 'inherit',
|
|
61
|
+
dominantBaseline: 'central',
|
|
62
|
+
textAnchor: 'start',
|
|
63
|
+
fill: (theme.vars || theme).palette.text.primary,
|
|
64
|
+
lineHeight: 1
|
|
65
|
+
}, inLabelStyle),
|
|
66
|
+
// To say to TS that the dominantBaseline and textAnchor are correct
|
|
67
|
+
[inLabelStyle, theme]);
|
|
68
|
+
const padding = React.useMemo(() => getStandardizedPadding(paddingProps), [paddingProps]);
|
|
69
|
+
const getItemSpace = React.useCallback((label, inStyle = {}) => {
|
|
70
|
+
const style = _objectWithoutPropertiesLoose(inStyle, _excluded);
|
|
71
|
+
const linesSize = getWordsByLines({
|
|
72
|
+
style,
|
|
73
|
+
needsComputation: true,
|
|
74
|
+
text: label
|
|
75
|
+
});
|
|
76
|
+
const innerSize = {
|
|
77
|
+
innerWidth: itemMarkWidth + markGap + Math.max(...linesSize.map(size => size.width)),
|
|
78
|
+
innerHeight: Math.max(itemMarkHeight, linesSize.length * linesSize[0].height)
|
|
79
|
+
};
|
|
80
|
+
return _extends({}, innerSize, {
|
|
81
|
+
outerWidth: innerSize.innerWidth + itemGap,
|
|
82
|
+
outerHeight: innerSize.innerHeight + itemGap
|
|
83
|
+
});
|
|
84
|
+
}, [itemGap, itemMarkHeight, itemMarkWidth, markGap]);
|
|
85
|
+
const totalWidth = drawingArea.left + drawingArea.width + drawingArea.right;
|
|
86
|
+
const totalHeight = drawingArea.top + drawingArea.height + drawingArea.bottom;
|
|
87
|
+
const availableWidth = totalWidth - padding.left - padding.right;
|
|
88
|
+
const availableHeight = totalHeight - padding.top - padding.bottom;
|
|
89
|
+
const [itemsWithPosition, legendWidth, legendHeight] = React.useMemo(() => legendItemPlacements(itemsToDisplay, getItemSpace, labelStyle, direction, availableWidth, availableHeight, itemGap), [itemsToDisplay, getItemSpace, labelStyle, direction, availableWidth, availableHeight, itemGap]);
|
|
90
|
+
const gapX = React.useMemo(() => {
|
|
91
|
+
switch (position.horizontal) {
|
|
92
|
+
case 'left':
|
|
93
|
+
return padding.left;
|
|
94
|
+
case 'right':
|
|
95
|
+
return totalWidth - padding.right - legendWidth;
|
|
96
|
+
default:
|
|
97
|
+
return (totalWidth - legendWidth) / 2;
|
|
98
|
+
}
|
|
99
|
+
}, [position.horizontal, padding.left, padding.right, totalWidth, legendWidth]);
|
|
100
|
+
const gapY = React.useMemo(() => {
|
|
101
|
+
switch (position.vertical) {
|
|
102
|
+
case 'top':
|
|
103
|
+
return padding.top;
|
|
104
|
+
case 'bottom':
|
|
105
|
+
return totalHeight - padding.bottom - legendHeight;
|
|
106
|
+
default:
|
|
107
|
+
return (totalHeight - legendHeight) / 2;
|
|
108
|
+
}
|
|
109
|
+
}, [position.vertical, padding.top, padding.bottom, totalHeight, legendHeight]);
|
|
110
|
+
if (hidden) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
return /*#__PURE__*/_jsx(NoSsr, {
|
|
114
|
+
children: /*#__PURE__*/_jsx(ChartsLegendRoot, {
|
|
115
|
+
className: classes?.root,
|
|
116
|
+
children: itemsWithPosition.map(({
|
|
117
|
+
id,
|
|
118
|
+
label,
|
|
119
|
+
color,
|
|
120
|
+
positionX,
|
|
121
|
+
positionY
|
|
122
|
+
}) => /*#__PURE__*/_jsxs("g", {
|
|
123
|
+
className: classes?.series,
|
|
124
|
+
transform: `translate(${gapX + (isRTL ? legendWidth - positionX : positionX)} ${gapY + positionY})`,
|
|
125
|
+
children: [/*#__PURE__*/_jsx("rect", {
|
|
126
|
+
className: classes?.mark,
|
|
127
|
+
x: isRTL ? -itemMarkWidth : 0,
|
|
128
|
+
y: -itemMarkHeight / 2,
|
|
129
|
+
width: itemMarkWidth,
|
|
130
|
+
height: itemMarkHeight,
|
|
131
|
+
fill: color
|
|
132
|
+
}), /*#__PURE__*/_jsx(ChartsText, {
|
|
133
|
+
style: labelStyle,
|
|
134
|
+
text: label,
|
|
135
|
+
x: (isRTL ? -1 : 1) * (itemMarkWidth + markGap),
|
|
136
|
+
y: 0
|
|
137
|
+
})]
|
|
138
|
+
}, id))
|
|
139
|
+
})
|
|
140
|
+
});
|
|
141
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
const _excluded = ["axisDirection", "axisId", "hideFirst", "hideLast", "labelFormatter"];
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import { useAxis } from './useAxis';
|
|
7
|
+
import { LegendPerItem } from './LegendPerItem';
|
|
8
|
+
import { notNull } from '../internals/notNull';
|
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
function defaultLabelFormatter(params) {
|
|
11
|
+
if (params.min === null) {
|
|
12
|
+
return `<${params.formattedMax}`;
|
|
13
|
+
}
|
|
14
|
+
if (params.max === null) {
|
|
15
|
+
return `>${params.formattedMin}`;
|
|
16
|
+
}
|
|
17
|
+
return `${params.formattedMin}-${params.formattedMax}`;
|
|
18
|
+
}
|
|
19
|
+
function PiecewiseColorLegend(props) {
|
|
20
|
+
const {
|
|
21
|
+
axisDirection,
|
|
22
|
+
axisId,
|
|
23
|
+
hideFirst,
|
|
24
|
+
hideLast,
|
|
25
|
+
labelFormatter = defaultLabelFormatter
|
|
26
|
+
} = props,
|
|
27
|
+
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
28
|
+
const axisItem = useAxis({
|
|
29
|
+
axisDirection,
|
|
30
|
+
axisId
|
|
31
|
+
});
|
|
32
|
+
const colorMap = axisItem?.colorMap;
|
|
33
|
+
if (!colorMap || !colorMap.type || colorMap.type !== 'piecewise') {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const valueFormatter = v => axisItem.valueFormatter?.(v, {
|
|
37
|
+
location: 'legend'
|
|
38
|
+
}) ?? v.toLocaleString();
|
|
39
|
+
const formattedLabels = colorMap.thresholds.map(valueFormatter);
|
|
40
|
+
const itemsToDisplay = colorMap.colors.map((color, index) => {
|
|
41
|
+
const isFirst = index === 0;
|
|
42
|
+
const isLast = index === colorMap.colors.length - 1;
|
|
43
|
+
if (hideFirst && isFirst || hideLast && isLast) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
const label = labelFormatter(_extends({}, index === 0 ? {
|
|
47
|
+
min: null,
|
|
48
|
+
formattedMin: null
|
|
49
|
+
} : {
|
|
50
|
+
min: colorMap.thresholds[index - 1],
|
|
51
|
+
formattedMin: formattedLabels[index - 1]
|
|
52
|
+
}, index === colorMap.colors.length - 1 ? {
|
|
53
|
+
max: null,
|
|
54
|
+
formattedMax: null
|
|
55
|
+
} : {
|
|
56
|
+
max: colorMap.thresholds[index],
|
|
57
|
+
formattedMax: formattedLabels[index]
|
|
58
|
+
}));
|
|
59
|
+
if (label === null) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
id: label,
|
|
64
|
+
color,
|
|
65
|
+
label
|
|
66
|
+
};
|
|
67
|
+
}).filter(notNull);
|
|
68
|
+
return /*#__PURE__*/_jsx(LegendPerItem, _extends({}, other, {
|
|
69
|
+
itemsToDisplay: itemsToDisplay
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
process.env.NODE_ENV !== "production" ? PiecewiseColorLegend.propTypes = {
|
|
73
|
+
// ----------------------------- Warning --------------------------------
|
|
74
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
75
|
+
// | To update them edit the TypeScript types and run "pnpm proptypes" |
|
|
76
|
+
// ----------------------------------------------------------------------
|
|
77
|
+
/**
|
|
78
|
+
* The axis direction containing the color configuration to represent.
|
|
79
|
+
* @default 'z'
|
|
80
|
+
*/
|
|
81
|
+
axisDirection: PropTypes.oneOf(['x', 'y', 'z']),
|
|
82
|
+
/**
|
|
83
|
+
* The id of the axis item with the color configuration to represent.
|
|
84
|
+
* @default The first axis item.
|
|
85
|
+
*/
|
|
86
|
+
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
87
|
+
/**
|
|
88
|
+
* Override or extend the styles applied to the component.
|
|
89
|
+
*/
|
|
90
|
+
classes: PropTypes.object,
|
|
91
|
+
/**
|
|
92
|
+
* The direction of the legend layout.
|
|
93
|
+
* The default depends on the chart.
|
|
94
|
+
*/
|
|
95
|
+
direction: PropTypes.oneOf(['column', 'row']).isRequired,
|
|
96
|
+
/**
|
|
97
|
+
* Set to true to hide the legend.
|
|
98
|
+
* @default false
|
|
99
|
+
*/
|
|
100
|
+
hidden: PropTypes.bool,
|
|
101
|
+
/**
|
|
102
|
+
* Hide the first item of the legend, corresponding to the [-infinity, min] piece.
|
|
103
|
+
* @default false
|
|
104
|
+
*/
|
|
105
|
+
hideFirst: PropTypes.bool,
|
|
106
|
+
/**
|
|
107
|
+
* Hide the last item of the legend, corresponding to the [max, +infinity] piece.
|
|
108
|
+
* @default false
|
|
109
|
+
*/
|
|
110
|
+
hideLast: PropTypes.bool,
|
|
111
|
+
/**
|
|
112
|
+
* Space between two legend items (in px).
|
|
113
|
+
* @default 10
|
|
114
|
+
*/
|
|
115
|
+
itemGap: PropTypes.number,
|
|
116
|
+
/**
|
|
117
|
+
* Height of the item mark (in px).
|
|
118
|
+
* @default 20
|
|
119
|
+
*/
|
|
120
|
+
itemMarkHeight: PropTypes.number,
|
|
121
|
+
/**
|
|
122
|
+
* Width of the item mark (in px).
|
|
123
|
+
* @default 20
|
|
124
|
+
*/
|
|
125
|
+
itemMarkWidth: PropTypes.number,
|
|
126
|
+
/**
|
|
127
|
+
* Format the legend labels.
|
|
128
|
+
* @param {PiecewiseLabelFormatterParams} params The bound of the piece to format.
|
|
129
|
+
* @returns {string|null} The displayed label, or `null` to skip the item.
|
|
130
|
+
*/
|
|
131
|
+
labelFormatter: PropTypes.func,
|
|
132
|
+
/**
|
|
133
|
+
* Style applied to legend labels.
|
|
134
|
+
* @default theme.typography.subtitle1
|
|
135
|
+
*/
|
|
136
|
+
labelStyle: PropTypes.object,
|
|
137
|
+
/**
|
|
138
|
+
* Space between the mark and the label (in px).
|
|
139
|
+
* @default 5
|
|
140
|
+
*/
|
|
141
|
+
markGap: PropTypes.number,
|
|
142
|
+
/**
|
|
143
|
+
* Legend padding (in px).
|
|
144
|
+
* Can either be a single number, or an object with top, left, bottom, right properties.
|
|
145
|
+
* @default 10
|
|
146
|
+
*/
|
|
147
|
+
padding: PropTypes.oneOfType([PropTypes.number, PropTypes.shape({
|
|
148
|
+
bottom: PropTypes.number,
|
|
149
|
+
left: PropTypes.number,
|
|
150
|
+
right: PropTypes.number,
|
|
151
|
+
top: PropTypes.number
|
|
152
|
+
})]),
|
|
153
|
+
/**
|
|
154
|
+
* The position of the legend.
|
|
155
|
+
*/
|
|
156
|
+
position: PropTypes.shape({
|
|
157
|
+
horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
|
|
158
|
+
vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
|
|
159
|
+
}).isRequired
|
|
160
|
+
} : void 0;
|
|
161
|
+
export { PiecewiseColorLegend };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
const _excluded = ["label"];
|
|
4
|
+
export function legendItemPlacements(itemsToDisplay, getItemSpace, labelStyle, direction, availableWidth, availableHeight, itemGap) {
|
|
5
|
+
// Start at 0, 0. Will be modified later by padding and position.
|
|
6
|
+
let x = 0;
|
|
7
|
+
let y = 0;
|
|
8
|
+
|
|
9
|
+
// total values used to align legend later.
|
|
10
|
+
let totalWidthUsed = 0;
|
|
11
|
+
let totalHeightUsed = 0;
|
|
12
|
+
let rowIndex = 0;
|
|
13
|
+
const rowMaxHeight = [0];
|
|
14
|
+
const seriesWithRawPosition = itemsToDisplay.map(_ref => {
|
|
15
|
+
let {
|
|
16
|
+
label
|
|
17
|
+
} = _ref,
|
|
18
|
+
other = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
19
|
+
const itemSpace = getItemSpace(label, labelStyle);
|
|
20
|
+
const rep = _extends({}, other, {
|
|
21
|
+
label,
|
|
22
|
+
positionX: x,
|
|
23
|
+
positionY: y,
|
|
24
|
+
innerHeight: itemSpace.innerHeight,
|
|
25
|
+
innerWidth: itemSpace.innerWidth,
|
|
26
|
+
outerHeight: itemSpace.outerHeight,
|
|
27
|
+
outerWidth: itemSpace.outerWidth,
|
|
28
|
+
rowIndex
|
|
29
|
+
});
|
|
30
|
+
if (direction === 'row') {
|
|
31
|
+
if (x + itemSpace.innerWidth > availableWidth) {
|
|
32
|
+
// This legend item would create overflow along the x-axis, so we start a new row.
|
|
33
|
+
x = 0;
|
|
34
|
+
y += rowMaxHeight[rowIndex];
|
|
35
|
+
rowIndex += 1;
|
|
36
|
+
if (rowMaxHeight.length <= rowIndex) {
|
|
37
|
+
rowMaxHeight.push(0);
|
|
38
|
+
}
|
|
39
|
+
rep.positionX = x;
|
|
40
|
+
rep.positionY = y;
|
|
41
|
+
rep.rowIndex = rowIndex;
|
|
42
|
+
}
|
|
43
|
+
totalWidthUsed = Math.max(totalWidthUsed, x + itemSpace.outerWidth);
|
|
44
|
+
totalHeightUsed = Math.max(totalHeightUsed, y + itemSpace.outerHeight);
|
|
45
|
+
rowMaxHeight[rowIndex] = Math.max(rowMaxHeight[rowIndex], itemSpace.outerHeight);
|
|
46
|
+
x += itemSpace.outerWidth;
|
|
47
|
+
}
|
|
48
|
+
if (direction === 'column') {
|
|
49
|
+
if (y + itemSpace.innerHeight > availableHeight) {
|
|
50
|
+
// This legend item would create overflow along the y-axis, so we start a new column.
|
|
51
|
+
x = totalWidthUsed + itemGap;
|
|
52
|
+
y = 0;
|
|
53
|
+
rowIndex = 0;
|
|
54
|
+
rep.positionX = x;
|
|
55
|
+
rep.positionY = y;
|
|
56
|
+
rep.rowIndex = rowIndex;
|
|
57
|
+
}
|
|
58
|
+
if (rowMaxHeight.length <= rowIndex) {
|
|
59
|
+
rowMaxHeight.push(0);
|
|
60
|
+
}
|
|
61
|
+
totalWidthUsed = Math.max(totalWidthUsed, x + itemSpace.outerWidth);
|
|
62
|
+
totalHeightUsed = Math.max(totalHeightUsed, y + itemSpace.outerHeight);
|
|
63
|
+
rowIndex += 1;
|
|
64
|
+
y += itemSpace.outerHeight;
|
|
65
|
+
}
|
|
66
|
+
return rep;
|
|
67
|
+
});
|
|
68
|
+
return [seriesWithRawPosition.map(item => _extends({}, item, {
|
|
69
|
+
positionY: item.positionY + (direction === 'row' ? rowMaxHeight[item.rowIndex] / 2 // Get the center of the entire row
|
|
70
|
+
: item.outerHeight / 2) // Get the center of the item
|
|
71
|
+
})), totalWidthUsed, totalHeightUsed];
|
|
72
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ZAxisContext } from '../context/ZAxisContextProvider';
|
|
3
|
+
import { useCartesianContext } from '../context/CartesianProvider/useCartesianContext';
|
|
4
|
+
/**
|
|
5
|
+
* Helper to select an axis definition according to its direction and id.
|
|
6
|
+
*/
|
|
7
|
+
export function useAxis({
|
|
8
|
+
axisDirection,
|
|
9
|
+
axisId
|
|
10
|
+
}) {
|
|
11
|
+
const {
|
|
12
|
+
xAxis,
|
|
13
|
+
xAxisIds,
|
|
14
|
+
yAxis,
|
|
15
|
+
yAxisIds
|
|
16
|
+
} = useCartesianContext();
|
|
17
|
+
const {
|
|
18
|
+
zAxis,
|
|
19
|
+
zAxisIds
|
|
20
|
+
} = React.useContext(ZAxisContext);
|
|
21
|
+
switch (axisDirection) {
|
|
22
|
+
case 'x':
|
|
23
|
+
{
|
|
24
|
+
const id = typeof axisId === 'string' ? axisId : xAxisIds[axisId ?? 0];
|
|
25
|
+
return xAxis[id];
|
|
26
|
+
}
|
|
27
|
+
case 'y':
|
|
28
|
+
{
|
|
29
|
+
const id = typeof axisId === 'string' ? axisId : yAxisIds[axisId ?? 0];
|
|
30
|
+
return yAxis[id];
|
|
31
|
+
}
|
|
32
|
+
case 'z':
|
|
33
|
+
default:
|
|
34
|
+
{
|
|
35
|
+
const id = typeof axisId === 'string' ? axisId : zAxisIds[axisId ?? 0];
|
|
36
|
+
return zAxis[id];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -37,7 +37,9 @@ function ChartsOnAxisClickHandler(props) {
|
|
|
37
37
|
Object.keys(series).filter(seriesType => ['bar', 'line'].includes(seriesType)).forEach(seriesType => {
|
|
38
38
|
series[seriesType]?.seriesOrder.forEach(seriesId => {
|
|
39
39
|
const seriesItem = series[seriesType].series[seriesId];
|
|
40
|
-
const
|
|
40
|
+
const providedXAxisId = seriesItem.xAxisId ?? seriesItem.xAxisKey;
|
|
41
|
+
const providedYAxisId = seriesItem.yAxisId ?? seriesItem.yAxisKey;
|
|
42
|
+
const axisKey = isXaxis ? providedXAxisId : providedYAxisId;
|
|
41
43
|
if (axisKey === undefined || axisKey === USED_AXIS_ID) {
|
|
42
44
|
seriesValues[seriesId] = seriesItem.data[dataIndex];
|
|
43
45
|
}
|
|
@@ -10,10 +10,10 @@ function ChartsReferenceLine(props) {
|
|
|
10
10
|
y
|
|
11
11
|
} = props;
|
|
12
12
|
if (x !== undefined && y !== undefined) {
|
|
13
|
-
throw new Error('MUI X
|
|
13
|
+
throw new Error('MUI X: The ChartsReferenceLine cannot have both `x` and `y` props set.');
|
|
14
14
|
}
|
|
15
15
|
if (x === undefined && y === undefined) {
|
|
16
|
-
throw new Error('MUI X
|
|
16
|
+
throw new Error('MUI X: The ChartsReferenceLine should have a value in `x` or `y` prop.');
|
|
17
17
|
}
|
|
18
18
|
if (x !== undefined) {
|
|
19
19
|
return /*#__PURE__*/_jsx(ChartsXReferenceLine, _extends({}, props));
|