@mui/x-charts 7.0.0-beta.0 → 7.0.0-beta.2
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 +2 -1
- package/BarChart/BarChart.js +33 -12
- package/BarChart/BarElement.d.ts +20 -13
- package/BarChart/BarElement.js +7 -3
- package/BarChart/BarPlot.d.ts +11 -6
- package/BarChart/BarPlot.js +28 -15
- package/BarChart/formatter.js +1 -1
- package/CHANGELOG.md +406 -1
- package/ChartContainer/ChartContainer.js +6 -4
- package/ChartsAxis/ChartsAxis.js +4 -4
- package/ChartsLegend/ChartsLegend.d.ts +5 -54
- package/ChartsLegend/ChartsLegend.js +2 -307
- package/ChartsLegend/DefaultChartsLegend.d.ts +60 -0
- package/ChartsLegend/DefaultChartsLegend.js +294 -0
- package/ChartsLegend/index.d.ts +1 -0
- package/ChartsLegend/index.js +11 -0
- package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.d.ts +20 -0
- package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +83 -0
- package/ChartsOnAxisClickHandler/index.d.ts +1 -0
- package/ChartsOnAxisClickHandler/index.js +16 -0
- package/ChartsOnAxisClickHandler/package.json +6 -0
- package/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/ChartsReferenceLine/common.d.ts +2 -1
- package/ChartsTooltip/ChartsAxisTooltipContent.js +6 -5
- package/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
- package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +7 -5
- package/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
- package/ChartsTooltip/utils.d.ts +4 -1
- package/ChartsTooltip/utils.js +15 -0
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.d.ts +7 -0
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
- package/ChartsXAxis/ChartsXAxis.js +13 -9
- package/ChartsYAxis/ChartsYAxis.js +1 -1
- package/LineChart/AnimatedArea.d.ts +1361 -0
- package/LineChart/AnimatedArea.js +111 -0
- package/LineChart/AnimatedLine.d.ts +1361 -0
- package/LineChart/AnimatedLine.js +113 -0
- package/LineChart/AreaElement.d.ts +19 -18
- package/LineChart/AreaElement.js +17 -34
- package/LineChart/AreaPlot.d.ts +12 -7
- package/LineChart/AreaPlot.js +91 -58
- package/LineChart/LineChart.d.ts +13 -4
- package/LineChart/LineChart.js +45 -14
- package/LineChart/LineElement.d.ts +19 -18
- package/LineChart/LineElement.js +16 -36
- package/LineChart/LineHighlightElement.d.ts +3 -2
- package/LineChart/LineHighlightElement.js +5 -3
- package/LineChart/LinePlot.d.ts +12 -7
- package/LineChart/LinePlot.js +89 -56
- package/LineChart/MarkElement.d.ts +8 -4
- package/LineChart/MarkElement.js +27 -13
- package/LineChart/MarkPlot.d.ts +8 -1
- package/LineChart/MarkPlot.js +80 -51
- package/LineChart/formatter.js +1 -1
- package/LineChart/index.d.ts +2 -0
- package/LineChart/index.js +22 -0
- package/PieChart/PieArc.d.ts +3 -2
- package/PieChart/PieArc.js +1 -0
- package/PieChart/PieArcLabel.d.ts +3 -2
- package/PieChart/PieArcLabel.js +1 -0
- package/PieChart/PieArcLabelPlot.d.ts +1 -1
- package/PieChart/PieArcLabelPlot.js +2 -2
- package/PieChart/PieArcPlot.d.ts +2 -2
- package/PieChart/PieArcPlot.js +7 -7
- package/PieChart/PieChart.d.ts +1 -1
- package/PieChart/PieChart.js +14 -12
- package/PieChart/PiePlot.d.ts +1 -1
- package/PieChart/PiePlot.js +4 -4
- package/ResponsiveChartContainer/ResponsiveChartContainer.js +6 -4
- package/ScatterChart/Scatter.d.ts +7 -1
- package/ScatterChart/Scatter.js +17 -3
- package/ScatterChart/ScatterChart.d.ts +8 -2
- package/ScatterChart/ScatterChart.js +21 -10
- package/ScatterChart/ScatterPlot.d.ts +1 -1
- package/ScatterChart/ScatterPlot.js +10 -2
- package/SparkLineChart/SparkLineChart.d.ts +1 -1
- package/SparkLineChart/SparkLineChart.js +7 -4
- package/context/CartesianContextProvider.js +8 -6
- package/context/DrawingProvider.d.ts +6 -1
- package/context/DrawingProvider.js +9 -2
- package/context/InteractionProvider.d.ts +3 -3
- package/esm/BarChart/BarChart.js +33 -12
- package/esm/BarChart/BarElement.js +7 -3
- package/esm/BarChart/BarPlot.js +27 -15
- package/esm/BarChart/formatter.js +1 -1
- package/esm/ChartContainer/ChartContainer.js +6 -4
- package/esm/ChartsAxis/ChartsAxis.js +4 -4
- package/esm/ChartsLegend/ChartsLegend.js +2 -307
- package/esm/ChartsLegend/DefaultChartsLegend.js +286 -0
- package/esm/ChartsLegend/index.js +1 -0
- package/esm/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +77 -0
- package/esm/ChartsOnAxisClickHandler/index.js +1 -0
- package/esm/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +6 -5
- package/esm/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
- package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +8 -5
- package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
- package/esm/ChartsTooltip/utils.js +12 -0
- package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
- package/esm/ChartsXAxis/ChartsXAxis.js +13 -9
- package/esm/ChartsYAxis/ChartsYAxis.js +1 -1
- package/esm/LineChart/AnimatedArea.js +103 -0
- package/esm/LineChart/AnimatedLine.js +105 -0
- package/esm/LineChart/AreaElement.js +16 -33
- package/esm/LineChart/AreaPlot.js +92 -59
- package/esm/LineChart/LineChart.js +45 -14
- package/esm/LineChart/LineElement.js +16 -35
- package/esm/LineChart/LineHighlightElement.js +5 -3
- package/esm/LineChart/LinePlot.js +90 -57
- package/esm/LineChart/MarkElement.js +27 -13
- package/esm/LineChart/MarkPlot.js +80 -51
- package/esm/LineChart/formatter.js +1 -1
- package/esm/LineChart/index.js +2 -0
- package/esm/PieChart/PieArc.js +1 -0
- package/esm/PieChart/PieArcLabel.js +1 -0
- package/esm/PieChart/PieArcLabelPlot.js +2 -2
- package/esm/PieChart/PieArcPlot.js +7 -7
- package/esm/PieChart/PieChart.js +14 -12
- package/esm/PieChart/PiePlot.js +4 -4
- package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +6 -4
- package/esm/ScatterChart/Scatter.js +17 -3
- package/esm/ScatterChart/ScatterChart.js +21 -10
- package/esm/ScatterChart/ScatterPlot.js +10 -2
- package/esm/SparkLineChart/SparkLineChart.js +7 -4
- package/esm/context/CartesianContextProvider.js +8 -6
- package/esm/context/DrawingProvider.js +9 -2
- package/esm/hooks/useDrawingArea.js +7 -3
- package/esm/index.js +1 -0
- package/esm/internals/geometry.js +1 -1
- package/esm/internals/useAnimatedPath.js +29 -0
- package/esm/internals/utils.js +7 -0
- package/hooks/useDrawingArea.d.ts +2 -0
- package/hooks/useDrawingArea.js +7 -3
- package/index.d.ts +1 -0
- package/index.js +12 -1
- package/internals/defaultizeColor.d.ts +16 -16
- package/internals/defaultizeValueFormatter.d.ts +4 -7
- package/internals/geometry.js +1 -1
- package/internals/stackSeries.d.ts +4 -7
- package/internals/useAnimatedPath.d.ts +1 -0
- package/internals/useAnimatedPath.js +38 -0
- package/internals/utils.d.ts +4 -0
- package/internals/utils.js +8 -0
- package/legacy/BarChart/BarChart.js +33 -12
- package/legacy/BarChart/BarElement.js +6 -2
- package/legacy/BarChart/BarPlot.js +28 -14
- package/legacy/BarChart/formatter.js +1 -1
- package/legacy/ChartContainer/ChartContainer.js +6 -4
- package/legacy/ChartsAxis/ChartsAxis.js +4 -4
- package/legacy/ChartsLegend/ChartsLegend.js +2 -323
- package/legacy/ChartsLegend/DefaultChartsLegend.js +302 -0
- package/legacy/ChartsLegend/index.js +1 -0
- package/legacy/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +75 -0
- package/legacy/ChartsOnAxisClickHandler/index.js +1 -0
- package/legacy/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/legacy/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/legacy/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +6 -7
- package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
- package/legacy/ChartsTooltip/DefaultChartsAxisTooltipContent.js +8 -5
- package/legacy/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
- package/legacy/ChartsTooltip/utils.js +12 -0
- package/legacy/ChartsVoronoiHandler/ChartsVoronoiHandler.js +88 -44
- package/legacy/ChartsXAxis/ChartsXAxis.js +12 -8
- package/legacy/ChartsYAxis/ChartsYAxis.js +1 -1
- package/legacy/LineChart/AnimatedArea.js +102 -0
- package/legacy/LineChart/AnimatedLine.js +104 -0
- package/legacy/LineChart/AreaElement.js +15 -35
- package/legacy/LineChart/AreaPlot.js +102 -66
- package/legacy/LineChart/LineChart.js +45 -14
- package/legacy/LineChart/LineElement.js +15 -37
- package/legacy/LineChart/LineHighlightElement.js +5 -3
- package/legacy/LineChart/LinePlot.js +97 -63
- package/legacy/LineChart/MarkElement.js +30 -12
- package/legacy/LineChart/MarkPlot.js +83 -53
- package/legacy/LineChart/formatter.js +1 -1
- package/legacy/LineChart/index.js +2 -0
- package/legacy/PieChart/PieArc.js +1 -0
- package/legacy/PieChart/PieArcLabel.js +1 -0
- package/legacy/PieChart/PieArcLabelPlot.js +2 -2
- package/legacy/PieChart/PieArcPlot.js +7 -7
- package/legacy/PieChart/PieChart.js +14 -12
- package/legacy/PieChart/PiePlot.js +4 -4
- package/legacy/ResponsiveChartContainer/ResponsiveChartContainer.js +6 -4
- package/legacy/ScatterChart/Scatter.js +19 -3
- package/legacy/ScatterChart/ScatterChart.js +21 -10
- package/legacy/ScatterChart/ScatterPlot.js +10 -2
- package/legacy/SparkLineChart/SparkLineChart.js +8 -5
- package/legacy/context/CartesianContextProvider.js +8 -6
- package/legacy/context/DrawingProvider.js +11 -2
- package/legacy/hooks/useDrawingArea.js +7 -3
- package/legacy/index.js +2 -1
- package/legacy/internals/geometry.js +1 -1
- package/legacy/internals/useAnimatedPath.js +32 -0
- package/legacy/internals/utils.js +7 -0
- package/models/axis.d.ts +7 -2
- package/models/seriesType/common.d.ts +2 -1
- package/models/seriesType/config.d.ts +7 -12
- package/models/seriesType/line.d.ts +2 -2
- package/models/seriesType/pie.d.ts +7 -3
- package/models/seriesType/scatter.d.ts +5 -2
- package/modern/BarChart/BarChart.js +33 -12
- package/modern/BarChart/BarElement.js +7 -3
- package/modern/BarChart/BarPlot.js +27 -15
- package/modern/BarChart/formatter.js +1 -1
- package/modern/ChartContainer/ChartContainer.js +6 -4
- package/modern/ChartsAxis/ChartsAxis.js +4 -4
- package/modern/ChartsLegend/ChartsLegend.js +2 -307
- package/modern/ChartsLegend/DefaultChartsLegend.js +286 -0
- package/modern/ChartsLegend/index.js +1 -0
- package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +75 -0
- package/modern/ChartsOnAxisClickHandler/index.js +1 -0
- package/modern/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +6 -5
- package/modern/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
- package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +7 -5
- package/modern/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
- package/modern/ChartsTooltip/utils.js +12 -0
- package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
- package/modern/ChartsXAxis/ChartsXAxis.js +13 -9
- package/modern/ChartsYAxis/ChartsYAxis.js +1 -1
- package/modern/LineChart/AnimatedArea.js +103 -0
- package/modern/LineChart/AnimatedLine.js +105 -0
- package/modern/LineChart/AreaElement.js +16 -33
- package/modern/LineChart/AreaPlot.js +91 -58
- package/modern/LineChart/LineChart.js +45 -14
- package/modern/LineChart/LineElement.js +16 -35
- package/modern/LineChart/LineHighlightElement.js +5 -3
- package/modern/LineChart/LinePlot.js +89 -56
- package/modern/LineChart/MarkElement.js +27 -13
- package/modern/LineChart/MarkPlot.js +80 -51
- package/modern/LineChart/formatter.js +1 -1
- package/modern/LineChart/index.js +2 -0
- package/modern/PieChart/PieArc.js +1 -0
- package/modern/PieChart/PieArcLabel.js +1 -0
- package/modern/PieChart/PieArcLabelPlot.js +2 -2
- package/modern/PieChart/PieArcPlot.js +7 -7
- package/modern/PieChart/PieChart.js +14 -12
- package/modern/PieChart/PiePlot.js +4 -4
- package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +6 -4
- package/modern/ScatterChart/Scatter.js +17 -3
- package/modern/ScatterChart/ScatterChart.js +21 -10
- package/modern/ScatterChart/ScatterPlot.js +10 -2
- package/modern/SparkLineChart/SparkLineChart.js +7 -4
- package/modern/context/CartesianContextProvider.js +8 -6
- package/modern/context/DrawingProvider.js +9 -2
- package/modern/hooks/useDrawingArea.js +7 -3
- package/modern/index.js +2 -1
- package/modern/internals/geometry.js +1 -1
- package/modern/internals/useAnimatedPath.js +29 -0
- package/modern/internals/utils.js +7 -0
- package/package.json +6 -5
|
@@ -1,21 +1,15 @@
|
|
|
1
|
-
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
const _excluded = ["rotate", "dominantBaseline"],
|
|
4
|
-
_excluded2 = ["label"];
|
|
5
2
|
import * as React from 'react';
|
|
6
3
|
import PropTypes from 'prop-types';
|
|
7
4
|
import { useSlotProps } from '@mui/base/utils';
|
|
8
|
-
import { NoSsr } from '@mui/base/NoSsr';
|
|
9
5
|
import { unstable_composeClasses as composeClasses } from '@mui/utils';
|
|
10
|
-
import { useThemeProps, useTheme
|
|
6
|
+
import { useThemeProps, useTheme } from '@mui/material/styles';
|
|
11
7
|
import { DrawingContext } from '../context/DrawingProvider';
|
|
12
8
|
import { getSeriesToDisplay } from './utils';
|
|
13
9
|
import { SeriesContext } from '../context/SeriesContextProvider';
|
|
14
10
|
import { getLegendUtilityClass } from './chartsLegendClasses';
|
|
15
|
-
import {
|
|
16
|
-
import { getWordsByLines } from '../internals/getWordsByLines';
|
|
11
|
+
import { DefaultChartsLegend } from './DefaultChartsLegend';
|
|
17
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
19
13
|
const useUtilityClasses = ownerState => {
|
|
20
14
|
const {
|
|
21
15
|
classes,
|
|
@@ -29,11 +23,6 @@ const useUtilityClasses = ownerState => {
|
|
|
29
23
|
};
|
|
30
24
|
return composeClasses(slots, getLegendUtilityClass, classes);
|
|
31
25
|
};
|
|
32
|
-
export const ChartsLegendRoot = styled('g', {
|
|
33
|
-
name: 'MuiChartsLegend',
|
|
34
|
-
slot: 'Root',
|
|
35
|
-
overridesResolver: (props, styles) => styles.root
|
|
36
|
-
})({});
|
|
37
26
|
const defaultProps = {
|
|
38
27
|
position: {
|
|
39
28
|
horizontal: 'middle',
|
|
@@ -41,300 +30,6 @@ const defaultProps = {
|
|
|
41
30
|
},
|
|
42
31
|
direction: 'row'
|
|
43
32
|
};
|
|
44
|
-
/**
|
|
45
|
-
* Transforms number or partial padding object to a defaultized padding object.
|
|
46
|
-
*/
|
|
47
|
-
const getStandardizedPadding = padding => {
|
|
48
|
-
if (typeof padding === 'number') {
|
|
49
|
-
return {
|
|
50
|
-
left: padding,
|
|
51
|
-
right: padding,
|
|
52
|
-
top: padding,
|
|
53
|
-
bottom: padding
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
return _extends({
|
|
57
|
-
left: 0,
|
|
58
|
-
right: 0,
|
|
59
|
-
top: 0,
|
|
60
|
-
bottom: 0
|
|
61
|
-
}, padding);
|
|
62
|
-
};
|
|
63
|
-
function DefaultChartsLegend(props) {
|
|
64
|
-
const {
|
|
65
|
-
hidden,
|
|
66
|
-
position,
|
|
67
|
-
direction,
|
|
68
|
-
seriesToDisplay,
|
|
69
|
-
drawingArea,
|
|
70
|
-
classes,
|
|
71
|
-
itemMarkWidth = 20,
|
|
72
|
-
itemMarkHeight = 20,
|
|
73
|
-
markGap = 5,
|
|
74
|
-
itemGap = 10,
|
|
75
|
-
padding: paddingProps = 10,
|
|
76
|
-
labelStyle: inLabelStyle
|
|
77
|
-
} = props;
|
|
78
|
-
const theme = useTheme();
|
|
79
|
-
const labelStyle = React.useMemo(() => _extends({}, theme.typography.subtitle1, {
|
|
80
|
-
color: 'inherit',
|
|
81
|
-
dominantBaseline: 'central',
|
|
82
|
-
textAnchor: 'start',
|
|
83
|
-
fill: (theme.vars || theme).palette.text.primary,
|
|
84
|
-
lineHeight: 1
|
|
85
|
-
}, inLabelStyle),
|
|
86
|
-
// To say to TS that the dominantBaseline and textAnchor are correct
|
|
87
|
-
[inLabelStyle, theme]);
|
|
88
|
-
const padding = React.useMemo(() => getStandardizedPadding(paddingProps), [paddingProps]);
|
|
89
|
-
const getItemSpace = React.useCallback((label, inStyle = {}) => {
|
|
90
|
-
const style = _objectWithoutPropertiesLoose(inStyle, _excluded);
|
|
91
|
-
const linesSize = getWordsByLines({
|
|
92
|
-
style,
|
|
93
|
-
needsComputation: true,
|
|
94
|
-
text: label
|
|
95
|
-
});
|
|
96
|
-
const innerSize = {
|
|
97
|
-
innerWidth: itemMarkWidth + markGap + Math.max(...linesSize.map(size => size.width)),
|
|
98
|
-
innerHeight: Math.max(itemMarkHeight, linesSize.length * linesSize[0].height)
|
|
99
|
-
};
|
|
100
|
-
return _extends({}, innerSize, {
|
|
101
|
-
outerWidth: innerSize.innerWidth + itemGap,
|
|
102
|
-
outerHeight: innerSize.innerHeight + itemGap
|
|
103
|
-
});
|
|
104
|
-
}, [itemGap, itemMarkHeight, itemMarkWidth, markGap]);
|
|
105
|
-
const totalWidth = drawingArea.left + drawingArea.width + drawingArea.right;
|
|
106
|
-
const totalHeight = drawingArea.top + drawingArea.height + drawingArea.bottom;
|
|
107
|
-
const availableWidth = totalWidth - padding.left - padding.right;
|
|
108
|
-
const availableHeight = totalHeight - padding.top - padding.bottom;
|
|
109
|
-
const seriesWithPosition = React.useMemo(() => {
|
|
110
|
-
// Start at 0, 0. Will be modified later by padding and position.
|
|
111
|
-
let x = 0;
|
|
112
|
-
let y = 0;
|
|
113
|
-
|
|
114
|
-
// total values used to align legend later.
|
|
115
|
-
let totalWidthUsed = 0;
|
|
116
|
-
let totalHeightUsed = 0;
|
|
117
|
-
let rowIndex = 0;
|
|
118
|
-
const rowMaxHeight = [0];
|
|
119
|
-
const seriesWithRawPosition = seriesToDisplay.map(_ref => {
|
|
120
|
-
let {
|
|
121
|
-
label
|
|
122
|
-
} = _ref,
|
|
123
|
-
other = _objectWithoutPropertiesLoose(_ref, _excluded2);
|
|
124
|
-
const itemSpace = getItemSpace(label, labelStyle);
|
|
125
|
-
const rep = _extends({}, other, {
|
|
126
|
-
label,
|
|
127
|
-
positionX: x,
|
|
128
|
-
positionY: y,
|
|
129
|
-
innerHeight: itemSpace.innerHeight,
|
|
130
|
-
innerWidth: itemSpace.innerWidth,
|
|
131
|
-
outerHeight: itemSpace.outerHeight,
|
|
132
|
-
outerWidth: itemSpace.outerWidth,
|
|
133
|
-
rowIndex
|
|
134
|
-
});
|
|
135
|
-
if (direction === 'row') {
|
|
136
|
-
if (x + itemSpace.innerWidth > availableWidth) {
|
|
137
|
-
// This legend item would create overflow along the x-axis, so we start a new row.
|
|
138
|
-
x = 0;
|
|
139
|
-
y += rowMaxHeight[rowIndex];
|
|
140
|
-
rowIndex += 1;
|
|
141
|
-
if (rowMaxHeight.length <= rowIndex) {
|
|
142
|
-
rowMaxHeight.push(0);
|
|
143
|
-
}
|
|
144
|
-
rep.positionX = x;
|
|
145
|
-
rep.positionY = y;
|
|
146
|
-
rep.rowIndex = rowIndex;
|
|
147
|
-
}
|
|
148
|
-
totalWidthUsed = Math.max(totalWidthUsed, x + itemSpace.outerWidth);
|
|
149
|
-
totalHeightUsed = Math.max(totalHeightUsed, y + itemSpace.outerHeight);
|
|
150
|
-
rowMaxHeight[rowIndex] = Math.max(rowMaxHeight[rowIndex], itemSpace.outerHeight);
|
|
151
|
-
x += itemSpace.outerWidth;
|
|
152
|
-
}
|
|
153
|
-
if (direction === 'column') {
|
|
154
|
-
if (y + itemSpace.innerHeight > availableHeight) {
|
|
155
|
-
// This legend item would create overflow along the y-axis, so we start a new column.
|
|
156
|
-
x = totalWidthUsed + itemGap;
|
|
157
|
-
y = 0;
|
|
158
|
-
rowIndex = 0;
|
|
159
|
-
rep.positionX = x;
|
|
160
|
-
rep.positionY = y;
|
|
161
|
-
rep.rowIndex = rowIndex;
|
|
162
|
-
}
|
|
163
|
-
if (rowMaxHeight.length <= rowIndex) {
|
|
164
|
-
rowMaxHeight.push(0);
|
|
165
|
-
}
|
|
166
|
-
totalWidthUsed = Math.max(totalWidthUsed, x + itemSpace.outerWidth);
|
|
167
|
-
totalHeightUsed = Math.max(totalHeightUsed, y + itemSpace.outerHeight);
|
|
168
|
-
rowIndex += 1;
|
|
169
|
-
y += itemSpace.outerHeight;
|
|
170
|
-
}
|
|
171
|
-
return rep;
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
// Move the legend according to padding and position
|
|
175
|
-
let gapX = 0;
|
|
176
|
-
let gapY = 0;
|
|
177
|
-
switch (position.horizontal) {
|
|
178
|
-
case 'left':
|
|
179
|
-
gapX = padding.left;
|
|
180
|
-
break;
|
|
181
|
-
case 'right':
|
|
182
|
-
gapX = totalWidth - padding.right - totalWidthUsed;
|
|
183
|
-
break;
|
|
184
|
-
default:
|
|
185
|
-
gapX = (totalWidth - totalWidthUsed) / 2;
|
|
186
|
-
break;
|
|
187
|
-
}
|
|
188
|
-
switch (position.vertical) {
|
|
189
|
-
case 'top':
|
|
190
|
-
gapY = padding.top;
|
|
191
|
-
break;
|
|
192
|
-
case 'bottom':
|
|
193
|
-
gapY = totalHeight - padding.bottom - totalHeightUsed;
|
|
194
|
-
break;
|
|
195
|
-
default:
|
|
196
|
-
gapY = (totalHeight - totalHeightUsed) / 2;
|
|
197
|
-
break;
|
|
198
|
-
}
|
|
199
|
-
return seriesWithRawPosition.map(item => _extends({}, item, {
|
|
200
|
-
// Add the gap due to the position
|
|
201
|
-
positionX: item.positionX + gapX,
|
|
202
|
-
// Add the gap due to the position
|
|
203
|
-
positionY: item.positionY + gapY + (direction === 'row' ? rowMaxHeight[item.rowIndex] / 2 // Get the center of the entire row
|
|
204
|
-
: item.outerHeight / 2) // Get the center of the item
|
|
205
|
-
}));
|
|
206
|
-
}, [seriesToDisplay, position.horizontal, position.vertical, getItemSpace, labelStyle, direction, availableWidth, availableHeight, itemGap, padding.left, padding.right, padding.top, padding.bottom, totalWidth, totalHeight]);
|
|
207
|
-
if (hidden) {
|
|
208
|
-
return null;
|
|
209
|
-
}
|
|
210
|
-
return /*#__PURE__*/_jsx(NoSsr, {
|
|
211
|
-
children: /*#__PURE__*/_jsx(ChartsLegendRoot, {
|
|
212
|
-
className: classes.root,
|
|
213
|
-
children: seriesWithPosition.map(({
|
|
214
|
-
id,
|
|
215
|
-
label,
|
|
216
|
-
color,
|
|
217
|
-
positionX,
|
|
218
|
-
positionY
|
|
219
|
-
}) => /*#__PURE__*/_jsxs("g", {
|
|
220
|
-
className: classes.series,
|
|
221
|
-
transform: `translate(${positionX} ${positionY})`,
|
|
222
|
-
children: [/*#__PURE__*/_jsx("rect", {
|
|
223
|
-
className: classes.mark,
|
|
224
|
-
y: -itemMarkHeight / 2,
|
|
225
|
-
width: itemMarkWidth,
|
|
226
|
-
height: itemMarkHeight,
|
|
227
|
-
fill: color
|
|
228
|
-
}), /*#__PURE__*/_jsx(ChartsText, {
|
|
229
|
-
style: labelStyle,
|
|
230
|
-
text: label,
|
|
231
|
-
x: itemMarkWidth + markGap,
|
|
232
|
-
y: 0
|
|
233
|
-
})]
|
|
234
|
-
}, id))
|
|
235
|
-
})
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
process.env.NODE_ENV !== "production" ? DefaultChartsLegend.propTypes = {
|
|
239
|
-
// ----------------------------- Warning --------------------------------
|
|
240
|
-
// | These PropTypes are generated from the TypeScript type definitions |
|
|
241
|
-
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
242
|
-
// ----------------------------------------------------------------------
|
|
243
|
-
/**
|
|
244
|
-
* Override or extend the styles applied to the component.
|
|
245
|
-
*/
|
|
246
|
-
classes: PropTypes.object.isRequired,
|
|
247
|
-
/**
|
|
248
|
-
* The direction of the legend layout.
|
|
249
|
-
* The default depends on the chart.
|
|
250
|
-
*/
|
|
251
|
-
direction: PropTypes.oneOf(['column', 'row']).isRequired,
|
|
252
|
-
drawingArea: PropTypes.shape({
|
|
253
|
-
bottom: PropTypes.number.isRequired,
|
|
254
|
-
height: PropTypes.number.isRequired,
|
|
255
|
-
left: PropTypes.number.isRequired,
|
|
256
|
-
right: PropTypes.number.isRequired,
|
|
257
|
-
top: PropTypes.number.isRequired,
|
|
258
|
-
width: PropTypes.number.isRequired
|
|
259
|
-
}).isRequired,
|
|
260
|
-
/**
|
|
261
|
-
* Set to true to hide the legend.
|
|
262
|
-
*/
|
|
263
|
-
hidden: PropTypes.bool,
|
|
264
|
-
/**
|
|
265
|
-
* Space between two legend items (in px).
|
|
266
|
-
* @default 10
|
|
267
|
-
*/
|
|
268
|
-
itemGap: PropTypes.number,
|
|
269
|
-
/**
|
|
270
|
-
* Height of the item mark (in px).
|
|
271
|
-
* @default 20
|
|
272
|
-
*/
|
|
273
|
-
itemMarkHeight: PropTypes.number,
|
|
274
|
-
/**
|
|
275
|
-
* Width of the item mark (in px).
|
|
276
|
-
* @default 20
|
|
277
|
-
*/
|
|
278
|
-
itemMarkWidth: PropTypes.number,
|
|
279
|
-
/**
|
|
280
|
-
* Style applied to legend labels.
|
|
281
|
-
* @default theme.typography.subtitle1
|
|
282
|
-
*/
|
|
283
|
-
labelStyle: PropTypes.object,
|
|
284
|
-
/**
|
|
285
|
-
* Space between the mark and the label (in px).
|
|
286
|
-
* @default 5
|
|
287
|
-
*/
|
|
288
|
-
markGap: PropTypes.number,
|
|
289
|
-
/**
|
|
290
|
-
* Legend padding (in px).
|
|
291
|
-
* Can either be a single number, or an object with top, left, bottom, right properties.
|
|
292
|
-
* @default 0
|
|
293
|
-
*/
|
|
294
|
-
padding: PropTypes.oneOfType([PropTypes.number, PropTypes.shape({
|
|
295
|
-
bottom: PropTypes.number,
|
|
296
|
-
left: PropTypes.number,
|
|
297
|
-
right: PropTypes.number,
|
|
298
|
-
top: PropTypes.number
|
|
299
|
-
})]),
|
|
300
|
-
position: PropTypes.shape({
|
|
301
|
-
horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
|
|
302
|
-
vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
|
|
303
|
-
}).isRequired,
|
|
304
|
-
series: PropTypes.shape({
|
|
305
|
-
bar: PropTypes.shape({
|
|
306
|
-
series: PropTypes.object.isRequired,
|
|
307
|
-
seriesOrder: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
308
|
-
stackingGroups: PropTypes.arrayOf(PropTypes.shape({
|
|
309
|
-
ids: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
310
|
-
stackingOffset: PropTypes.func.isRequired,
|
|
311
|
-
stackingOrder: PropTypes.func.isRequired
|
|
312
|
-
})).isRequired
|
|
313
|
-
}),
|
|
314
|
-
line: PropTypes.shape({
|
|
315
|
-
series: PropTypes.object.isRequired,
|
|
316
|
-
seriesOrder: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
317
|
-
stackingGroups: PropTypes.arrayOf(PropTypes.shape({
|
|
318
|
-
ids: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
319
|
-
stackingOffset: PropTypes.func.isRequired,
|
|
320
|
-
stackingOrder: PropTypes.func.isRequired
|
|
321
|
-
})).isRequired
|
|
322
|
-
}),
|
|
323
|
-
pie: PropTypes.shape({
|
|
324
|
-
series: PropTypes.object.isRequired,
|
|
325
|
-
seriesOrder: PropTypes.arrayOf(PropTypes.string).isRequired
|
|
326
|
-
}),
|
|
327
|
-
scatter: PropTypes.shape({
|
|
328
|
-
series: PropTypes.object.isRequired,
|
|
329
|
-
seriesOrder: PropTypes.arrayOf(PropTypes.string).isRequired
|
|
330
|
-
})
|
|
331
|
-
}).isRequired,
|
|
332
|
-
seriesToDisplay: PropTypes.arrayOf(PropTypes.shape({
|
|
333
|
-
color: PropTypes.string.isRequired,
|
|
334
|
-
id: PropTypes.string.isRequired,
|
|
335
|
-
label: PropTypes.string.isRequired
|
|
336
|
-
})).isRequired
|
|
337
|
-
} : void 0;
|
|
338
33
|
function ChartsLegend(inProps) {
|
|
339
34
|
var _slots$legend;
|
|
340
35
|
const props = useThemeProps({
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
+
const _excluded = ["rotate", "dominantBaseline"],
|
|
4
|
+
_excluded2 = ["label"];
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
import PropTypes from 'prop-types';
|
|
7
|
+
import { NoSsr } from '@mui/base/NoSsr';
|
|
8
|
+
import { useTheme, styled } from '@mui/material/styles';
|
|
9
|
+
import { ChartsText } from '../ChartsText';
|
|
10
|
+
import { getWordsByLines } from '../internals/getWordsByLines';
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
export const ChartsLegendRoot = styled('g', {
|
|
14
|
+
name: 'MuiChartsLegend',
|
|
15
|
+
slot: 'Root',
|
|
16
|
+
overridesResolver: (props, styles) => styles.root
|
|
17
|
+
})({});
|
|
18
|
+
/**
|
|
19
|
+
* Transforms number or partial padding object to a defaultized padding object.
|
|
20
|
+
*/
|
|
21
|
+
const getStandardizedPadding = padding => {
|
|
22
|
+
if (typeof padding === 'number') {
|
|
23
|
+
return {
|
|
24
|
+
left: padding,
|
|
25
|
+
right: padding,
|
|
26
|
+
top: padding,
|
|
27
|
+
bottom: padding
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return _extends({
|
|
31
|
+
left: 0,
|
|
32
|
+
right: 0,
|
|
33
|
+
top: 0,
|
|
34
|
+
bottom: 0
|
|
35
|
+
}, padding);
|
|
36
|
+
};
|
|
37
|
+
function DefaultChartsLegend(props) {
|
|
38
|
+
const {
|
|
39
|
+
hidden,
|
|
40
|
+
position,
|
|
41
|
+
direction,
|
|
42
|
+
seriesToDisplay,
|
|
43
|
+
drawingArea,
|
|
44
|
+
classes,
|
|
45
|
+
itemMarkWidth = 20,
|
|
46
|
+
itemMarkHeight = 20,
|
|
47
|
+
markGap = 5,
|
|
48
|
+
itemGap = 10,
|
|
49
|
+
padding: paddingProps = 10,
|
|
50
|
+
labelStyle: inLabelStyle
|
|
51
|
+
} = props;
|
|
52
|
+
const theme = useTheme();
|
|
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 = 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
|
+
|
|
148
|
+
// Move the legend according to padding and position
|
|
149
|
+
let gapX = 0;
|
|
150
|
+
let gapY = 0;
|
|
151
|
+
switch (position.horizontal) {
|
|
152
|
+
case 'left':
|
|
153
|
+
gapX = padding.left;
|
|
154
|
+
break;
|
|
155
|
+
case 'right':
|
|
156
|
+
gapX = totalWidth - padding.right - totalWidthUsed;
|
|
157
|
+
break;
|
|
158
|
+
default:
|
|
159
|
+
gapX = (totalWidth - totalWidthUsed) / 2;
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
switch (position.vertical) {
|
|
163
|
+
case 'top':
|
|
164
|
+
gapY = padding.top;
|
|
165
|
+
break;
|
|
166
|
+
case 'bottom':
|
|
167
|
+
gapY = totalHeight - padding.bottom - totalHeightUsed;
|
|
168
|
+
break;
|
|
169
|
+
default:
|
|
170
|
+
gapY = (totalHeight - totalHeightUsed) / 2;
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
return seriesWithRawPosition.map(item => _extends({}, item, {
|
|
174
|
+
// Add the gap due to the position
|
|
175
|
+
positionX: item.positionX + gapX,
|
|
176
|
+
// Add the gap due to the position
|
|
177
|
+
positionY: item.positionY + gapY + (direction === 'row' ? rowMaxHeight[item.rowIndex] / 2 // Get the center of the entire row
|
|
178
|
+
: item.outerHeight / 2) // Get the center of the item
|
|
179
|
+
}));
|
|
180
|
+
}, [seriesToDisplay, position.horizontal, position.vertical, getItemSpace, labelStyle, direction, availableWidth, availableHeight, itemGap, padding.left, padding.right, padding.top, padding.bottom, totalWidth, totalHeight]);
|
|
181
|
+
if (hidden) {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
return /*#__PURE__*/_jsx(NoSsr, {
|
|
185
|
+
children: /*#__PURE__*/_jsx(ChartsLegendRoot, {
|
|
186
|
+
className: classes.root,
|
|
187
|
+
children: seriesWithPosition.map(({
|
|
188
|
+
id,
|
|
189
|
+
label,
|
|
190
|
+
color,
|
|
191
|
+
positionX,
|
|
192
|
+
positionY
|
|
193
|
+
}) => /*#__PURE__*/_jsxs("g", {
|
|
194
|
+
className: classes.series,
|
|
195
|
+
transform: `translate(${positionX} ${positionY})`,
|
|
196
|
+
children: [/*#__PURE__*/_jsx("rect", {
|
|
197
|
+
className: classes.mark,
|
|
198
|
+
y: -itemMarkHeight / 2,
|
|
199
|
+
width: itemMarkWidth,
|
|
200
|
+
height: itemMarkHeight,
|
|
201
|
+
fill: color
|
|
202
|
+
}), /*#__PURE__*/_jsx(ChartsText, {
|
|
203
|
+
style: labelStyle,
|
|
204
|
+
text: label,
|
|
205
|
+
x: itemMarkWidth + markGap,
|
|
206
|
+
y: 0
|
|
207
|
+
})]
|
|
208
|
+
}, id))
|
|
209
|
+
})
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
process.env.NODE_ENV !== "production" ? DefaultChartsLegend.propTypes = {
|
|
213
|
+
// ----------------------------- Warning --------------------------------
|
|
214
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
215
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
216
|
+
// ----------------------------------------------------------------------
|
|
217
|
+
/**
|
|
218
|
+
* Override or extend the styles applied to the component.
|
|
219
|
+
*/
|
|
220
|
+
classes: PropTypes.object.isRequired,
|
|
221
|
+
/**
|
|
222
|
+
* The direction of the legend layout.
|
|
223
|
+
* The default depends on the chart.
|
|
224
|
+
*/
|
|
225
|
+
direction: PropTypes.oneOf(['column', 'row']).isRequired,
|
|
226
|
+
drawingArea: PropTypes.shape({
|
|
227
|
+
bottom: PropTypes.number.isRequired,
|
|
228
|
+
height: PropTypes.number.isRequired,
|
|
229
|
+
left: PropTypes.number.isRequired,
|
|
230
|
+
right: PropTypes.number.isRequired,
|
|
231
|
+
top: PropTypes.number.isRequired,
|
|
232
|
+
width: PropTypes.number.isRequired
|
|
233
|
+
}).isRequired,
|
|
234
|
+
/**
|
|
235
|
+
* Set to true to hide the legend.
|
|
236
|
+
* @default false
|
|
237
|
+
*/
|
|
238
|
+
hidden: PropTypes.bool,
|
|
239
|
+
/**
|
|
240
|
+
* Space between two legend items (in px).
|
|
241
|
+
* @default 10
|
|
242
|
+
*/
|
|
243
|
+
itemGap: PropTypes.number,
|
|
244
|
+
/**
|
|
245
|
+
* Height of the item mark (in px).
|
|
246
|
+
* @default 20
|
|
247
|
+
*/
|
|
248
|
+
itemMarkHeight: PropTypes.number,
|
|
249
|
+
/**
|
|
250
|
+
* Width of the item mark (in px).
|
|
251
|
+
* @default 20
|
|
252
|
+
*/
|
|
253
|
+
itemMarkWidth: PropTypes.number,
|
|
254
|
+
/**
|
|
255
|
+
* Style applied to legend labels.
|
|
256
|
+
* @default theme.typography.subtitle1
|
|
257
|
+
*/
|
|
258
|
+
labelStyle: PropTypes.object,
|
|
259
|
+
/**
|
|
260
|
+
* Space between the mark and the label (in px).
|
|
261
|
+
* @default 5
|
|
262
|
+
*/
|
|
263
|
+
markGap: PropTypes.number,
|
|
264
|
+
/**
|
|
265
|
+
* Legend padding (in px).
|
|
266
|
+
* Can either be a single number, or an object with top, left, bottom, right properties.
|
|
267
|
+
* @default 10
|
|
268
|
+
*/
|
|
269
|
+
padding: PropTypes.oneOfType([PropTypes.number, PropTypes.shape({
|
|
270
|
+
bottom: PropTypes.number,
|
|
271
|
+
left: PropTypes.number,
|
|
272
|
+
right: PropTypes.number,
|
|
273
|
+
top: PropTypes.number
|
|
274
|
+
})]),
|
|
275
|
+
position: PropTypes.shape({
|
|
276
|
+
horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
|
|
277
|
+
vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
|
|
278
|
+
}).isRequired,
|
|
279
|
+
series: PropTypes.object.isRequired,
|
|
280
|
+
seriesToDisplay: PropTypes.arrayOf(PropTypes.shape({
|
|
281
|
+
color: PropTypes.string.isRequired,
|
|
282
|
+
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
283
|
+
label: PropTypes.string.isRequired
|
|
284
|
+
})).isRequired
|
|
285
|
+
} : void 0;
|
|
286
|
+
export { DefaultChartsLegend };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { SVGContext } from '../context/DrawingProvider';
|
|
4
|
+
import { InteractionContext } from '../context/InteractionProvider';
|
|
5
|
+
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
6
|
+
import { SeriesContext } from '../context/SeriesContextProvider';
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
function ChartsOnAxisClickHandler(props) {
|
|
9
|
+
const {
|
|
10
|
+
onAxisClick
|
|
11
|
+
} = props;
|
|
12
|
+
const svgRef = React.useContext(SVGContext);
|
|
13
|
+
const series = React.useContext(SeriesContext);
|
|
14
|
+
const {
|
|
15
|
+
axis
|
|
16
|
+
} = React.useContext(InteractionContext);
|
|
17
|
+
const {
|
|
18
|
+
xAxisIds,
|
|
19
|
+
xAxis,
|
|
20
|
+
yAxisIds,
|
|
21
|
+
yAxis
|
|
22
|
+
} = React.useContext(CartesianContext);
|
|
23
|
+
React.useEffect(() => {
|
|
24
|
+
const element = svgRef.current;
|
|
25
|
+
if (element === null || !onAxisClick) {
|
|
26
|
+
return () => {};
|
|
27
|
+
}
|
|
28
|
+
const handleMouseClick = event => {
|
|
29
|
+
var _USED_AXIS_ID$data;
|
|
30
|
+
event.preventDefault();
|
|
31
|
+
const isXaxis = (axis.x && axis.x.index) !== undefined;
|
|
32
|
+
const USED_AXIS_ID = isXaxis ? xAxisIds[0] : yAxisIds[0];
|
|
33
|
+
const dataIndex = isXaxis ? axis.x && axis.x.index : axis.y && axis.y.index;
|
|
34
|
+
if (dataIndex == null) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const seriesValues = {};
|
|
38
|
+
Object.keys(series).filter(seriesType => ['bar', 'line'].includes(seriesType)).forEach(seriesType => {
|
|
39
|
+
var _series$seriesType;
|
|
40
|
+
(_series$seriesType = series[seriesType]) == null || _series$seriesType.seriesOrder.forEach(seriesId => {
|
|
41
|
+
const seriesItem = series[seriesType].series[seriesId];
|
|
42
|
+
const axisKey = isXaxis ? seriesItem.xAxisKey : seriesItem.yAxisKey;
|
|
43
|
+
if (axisKey === undefined || axisKey === USED_AXIS_ID) {
|
|
44
|
+
seriesValues[seriesId] = seriesItem.data[dataIndex];
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
const axisValue = (_USED_AXIS_ID$data = (isXaxis ? xAxis : yAxis)[USED_AXIS_ID].data) == null ? void 0 : _USED_AXIS_ID$data[dataIndex];
|
|
49
|
+
onAxisClick(event, {
|
|
50
|
+
dataIndex,
|
|
51
|
+
axisValue,
|
|
52
|
+
seriesValues
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
element.addEventListener('click', handleMouseClick);
|
|
56
|
+
return () => {
|
|
57
|
+
element.removeEventListener('click', handleMouseClick);
|
|
58
|
+
};
|
|
59
|
+
}, [axis.x, axis.y, onAxisClick, series, svgRef, xAxis, xAxisIds, yAxis, yAxisIds]);
|
|
60
|
+
|
|
61
|
+
// eslint-disable-next-line react/jsx-no-useless-fragment
|
|
62
|
+
return /*#__PURE__*/_jsx(React.Fragment, {});
|
|
63
|
+
}
|
|
64
|
+
process.env.NODE_ENV !== "production" ? ChartsOnAxisClickHandler.propTypes = {
|
|
65
|
+
// ----------------------------- Warning --------------------------------
|
|
66
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
67
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
68
|
+
// ----------------------------------------------------------------------
|
|
69
|
+
/**
|
|
70
|
+
* The function called for onClick events.
|
|
71
|
+
* The second argument contains information about all line/bar elements at the current mouse position.
|
|
72
|
+
* @param {MouseEvent} event The mouse event recorded on the `<svg/>` element.
|
|
73
|
+
* @param {null | AxisData} data The data about the clicked axis and items associated with it.
|
|
74
|
+
*/
|
|
75
|
+
onAxisClick: PropTypes.func
|
|
76
|
+
} : void 0;
|
|
77
|
+
export { ChartsOnAxisClickHandler };
|