@mui/x-charts 7.10.0 → 7.11.0
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/formatter.js +1 -1
- package/BarChart/useBarChartProps.js +38 -33
- package/CHANGELOG.md +85 -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/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/ChartsReferenceLine/ChartsReferenceLine.d.ts +1 -1
- package/ChartsSurface.js +3 -1
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +26 -18
- 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/LineChart.js +2 -2
- package/LineChart/LineHighlightPlot.js +8 -0
- package/LineChart/MarkElement.js +2 -2
- package/LineChart/MarkPlot.js +4 -20
- package/LineChart/formatter.js +1 -1
- package/LineChart/useLineChartProps.js +38 -33
- 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 +6 -2
- package/ResponsiveChartContainer/useResponsiveChartContainerProps.d.ts +20 -0
- package/ResponsiveChartContainer/useResponsiveChartContainerProps.js +73 -0
- package/ScatterChart/Scatter.js +6 -9
- package/ScatterChart/useScatterChartProps.js +35 -30
- package/SparkLineChart/SparkLineChart.js +27 -22
- 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 +1 -1
- package/context/DrawingProvider.d.ts +11 -0
- package/context/DrawingProvider.js +9 -2
- package/context/HighlightedProvider/HighlightedProvider.js +2 -2
- package/esm/BarChart/BarChart.js +2 -2
- package/esm/BarChart/formatter.js +1 -1
- 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/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/ChartsSurface.js +3 -1
- package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +26 -18
- 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/LineChart.js +2 -2
- package/esm/LineChart/LineHighlightPlot.js +8 -0
- package/esm/LineChart/MarkElement.js +1 -1
- package/esm/LineChart/MarkPlot.js +3 -19
- package/esm/LineChart/formatter.js +1 -1
- package/esm/LineChart/useLineChartProps.js +38 -33
- 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 +6 -2
- package/esm/ResponsiveChartContainer/useResponsiveChartContainerProps.js +65 -0
- package/esm/ScatterChart/Scatter.js +6 -9
- 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 +1 -1
- package/esm/context/DrawingProvider.js +9 -2
- package/esm/context/HighlightedProvider/HighlightedProvider.js +2 -2
- package/esm/hooks/useAxisEvents.js +3 -10
- package/esm/hooks/useDrawingArea.js +5 -3
- package/esm/hooks/useReducedMotion.js +4 -2
- package/esm/internals/cleanId.js +6 -0
- package/esm/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +3 -2
- 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/hooks/useAxisEvents.js +3 -10
- package/hooks/useDrawingArea.js +5 -3
- package/hooks/useReducedMotion.js +4 -2
- package/index.js +1 -1
- 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/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/models/axis.d.ts +5 -2
- package/models/helpers.d.ts +1 -0
- package/models/seriesType/config.d.ts +2 -16
- package/modern/BarChart/BarChart.js +2 -2
- package/modern/BarChart/formatter.js +1 -1
- 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/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/ChartsSurface.js +3 -1
- package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +26 -18
- 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/LineChart.js +2 -2
- package/modern/LineChart/LineHighlightPlot.js +8 -0
- package/modern/LineChart/MarkElement.js +1 -1
- package/modern/LineChart/MarkPlot.js +3 -19
- package/modern/LineChart/formatter.js +1 -1
- package/modern/LineChart/useLineChartProps.js +38 -33
- 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 +6 -2
- package/modern/ResponsiveChartContainer/useResponsiveChartContainerProps.js +65 -0
- package/modern/ScatterChart/Scatter.js +6 -9
- 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 +1 -1
- package/modern/context/DrawingProvider.js +9 -2
- package/modern/context/HighlightedProvider/HighlightedProvider.js +2 -2
- package/modern/hooks/useAxisEvents.js +3 -10
- package/modern/hooks/useDrawingArea.js +5 -3
- package/modern/hooks/useReducedMotion.js +4 -2
- package/modern/index.js +1 -1
- package/modern/internals/cleanId.js +6 -0
- package/modern/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +3 -2
- 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/package.json +4 -4
- package/internals/utils.d.ts +0 -18
|
@@ -4,212 +4,24 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.ChartsLegendRoot = void 0;
|
|
8
7
|
exports.DefaultChartsLegend = DefaultChartsLegend;
|
|
9
|
-
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
10
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
11
10
|
var React = _interopRequireWildcard(require("react"));
|
|
12
11
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
13
|
-
var
|
|
14
|
-
var _styles = require("@mui/material/styles");
|
|
15
|
-
var _ChartsText = require("../ChartsText");
|
|
16
|
-
var _getWordsByLines = require("../internals/getWordsByLines");
|
|
12
|
+
var _LegendPerItem = require("./LegendPerItem");
|
|
17
13
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
18
|
-
const _excluded = ["
|
|
19
|
-
_excluded2 = ["label"];
|
|
14
|
+
const _excluded = ["drawingArea", "seriesToDisplay"];
|
|
20
15
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
21
16
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
22
|
-
const ChartsLegendRoot = exports.ChartsLegendRoot = (0, _styles.styled)('g', {
|
|
23
|
-
name: 'MuiChartsLegend',
|
|
24
|
-
slot: 'Root',
|
|
25
|
-
overridesResolver: (props, styles) => styles.root
|
|
26
|
-
})({});
|
|
27
|
-
/**
|
|
28
|
-
* Transforms number or partial padding object to a defaultized padding object.
|
|
29
|
-
*/
|
|
30
|
-
const getStandardizedPadding = padding => {
|
|
31
|
-
if (typeof padding === 'number') {
|
|
32
|
-
return {
|
|
33
|
-
left: padding,
|
|
34
|
-
right: padding,
|
|
35
|
-
top: padding,
|
|
36
|
-
bottom: padding
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
return (0, _extends2.default)({
|
|
40
|
-
left: 0,
|
|
41
|
-
right: 0,
|
|
42
|
-
top: 0,
|
|
43
|
-
bottom: 0
|
|
44
|
-
}, padding);
|
|
45
|
-
};
|
|
46
17
|
function DefaultChartsLegend(props) {
|
|
47
18
|
const {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
itemMarkWidth = 20,
|
|
55
|
-
itemMarkHeight = 20,
|
|
56
|
-
markGap = 5,
|
|
57
|
-
itemGap = 10,
|
|
58
|
-
padding: paddingProps = 10,
|
|
59
|
-
labelStyle: inLabelStyle
|
|
60
|
-
} = props;
|
|
61
|
-
const theme = (0, _styles.useTheme)();
|
|
62
|
-
const isRTL = theme.direction === 'rtl';
|
|
63
|
-
const labelStyle = React.useMemo(() => (0, _extends2.default)({}, theme.typography.subtitle1, {
|
|
64
|
-
color: 'inherit',
|
|
65
|
-
dominantBaseline: 'central',
|
|
66
|
-
textAnchor: 'start',
|
|
67
|
-
fill: (theme.vars || theme).palette.text.primary,
|
|
68
|
-
lineHeight: 1
|
|
69
|
-
}, inLabelStyle),
|
|
70
|
-
// To say to TS that the dominantBaseline and textAnchor are correct
|
|
71
|
-
[inLabelStyle, theme]);
|
|
72
|
-
const padding = React.useMemo(() => getStandardizedPadding(paddingProps), [paddingProps]);
|
|
73
|
-
const getItemSpace = React.useCallback((label, inStyle = {}) => {
|
|
74
|
-
const style = (0, _objectWithoutPropertiesLoose2.default)(inStyle, _excluded);
|
|
75
|
-
const linesSize = (0, _getWordsByLines.getWordsByLines)({
|
|
76
|
-
style,
|
|
77
|
-
needsComputation: true,
|
|
78
|
-
text: label
|
|
79
|
-
});
|
|
80
|
-
const innerSize = {
|
|
81
|
-
innerWidth: itemMarkWidth + markGap + Math.max(...linesSize.map(size => size.width)),
|
|
82
|
-
innerHeight: Math.max(itemMarkHeight, linesSize.length * linesSize[0].height)
|
|
83
|
-
};
|
|
84
|
-
return (0, _extends2.default)({}, innerSize, {
|
|
85
|
-
outerWidth: innerSize.innerWidth + itemGap,
|
|
86
|
-
outerHeight: innerSize.innerHeight + itemGap
|
|
87
|
-
});
|
|
88
|
-
}, [itemGap, itemMarkHeight, itemMarkWidth, markGap]);
|
|
89
|
-
const totalWidth = drawingArea.left + drawingArea.width + drawingArea.right;
|
|
90
|
-
const totalHeight = drawingArea.top + drawingArea.height + drawingArea.bottom;
|
|
91
|
-
const availableWidth = totalWidth - padding.left - padding.right;
|
|
92
|
-
const availableHeight = totalHeight - padding.top - padding.bottom;
|
|
93
|
-
const [seriesWithPosition, legendWidth, legendHeight] = React.useMemo(() => {
|
|
94
|
-
// Start at 0, 0. Will be modified later by padding and position.
|
|
95
|
-
let x = 0;
|
|
96
|
-
let y = 0;
|
|
97
|
-
|
|
98
|
-
// total values used to align legend later.
|
|
99
|
-
let totalWidthUsed = 0;
|
|
100
|
-
let totalHeightUsed = 0;
|
|
101
|
-
let rowIndex = 0;
|
|
102
|
-
const rowMaxHeight = [0];
|
|
103
|
-
const seriesWithRawPosition = seriesToDisplay.map(_ref => {
|
|
104
|
-
let {
|
|
105
|
-
label
|
|
106
|
-
} = _ref,
|
|
107
|
-
other = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded2);
|
|
108
|
-
const itemSpace = getItemSpace(label, labelStyle);
|
|
109
|
-
const rep = (0, _extends2.default)({}, other, {
|
|
110
|
-
label,
|
|
111
|
-
positionX: x,
|
|
112
|
-
positionY: y,
|
|
113
|
-
innerHeight: itemSpace.innerHeight,
|
|
114
|
-
innerWidth: itemSpace.innerWidth,
|
|
115
|
-
outerHeight: itemSpace.outerHeight,
|
|
116
|
-
outerWidth: itemSpace.outerWidth,
|
|
117
|
-
rowIndex
|
|
118
|
-
});
|
|
119
|
-
if (direction === 'row') {
|
|
120
|
-
if (x + itemSpace.innerWidth > availableWidth) {
|
|
121
|
-
// This legend item would create overflow along the x-axis, so we start a new row.
|
|
122
|
-
x = 0;
|
|
123
|
-
y += rowMaxHeight[rowIndex];
|
|
124
|
-
rowIndex += 1;
|
|
125
|
-
if (rowMaxHeight.length <= rowIndex) {
|
|
126
|
-
rowMaxHeight.push(0);
|
|
127
|
-
}
|
|
128
|
-
rep.positionX = x;
|
|
129
|
-
rep.positionY = y;
|
|
130
|
-
rep.rowIndex = rowIndex;
|
|
131
|
-
}
|
|
132
|
-
totalWidthUsed = Math.max(totalWidthUsed, x + itemSpace.outerWidth);
|
|
133
|
-
totalHeightUsed = Math.max(totalHeightUsed, y + itemSpace.outerHeight);
|
|
134
|
-
rowMaxHeight[rowIndex] = Math.max(rowMaxHeight[rowIndex], itemSpace.outerHeight);
|
|
135
|
-
x += itemSpace.outerWidth;
|
|
136
|
-
}
|
|
137
|
-
if (direction === 'column') {
|
|
138
|
-
if (y + itemSpace.innerHeight > availableHeight) {
|
|
139
|
-
// This legend item would create overflow along the y-axis, so we start a new column.
|
|
140
|
-
x = totalWidthUsed + itemGap;
|
|
141
|
-
y = 0;
|
|
142
|
-
rowIndex = 0;
|
|
143
|
-
rep.positionX = x;
|
|
144
|
-
rep.positionY = y;
|
|
145
|
-
rep.rowIndex = rowIndex;
|
|
146
|
-
}
|
|
147
|
-
if (rowMaxHeight.length <= rowIndex) {
|
|
148
|
-
rowMaxHeight.push(0);
|
|
149
|
-
}
|
|
150
|
-
totalWidthUsed = Math.max(totalWidthUsed, x + itemSpace.outerWidth);
|
|
151
|
-
totalHeightUsed = Math.max(totalHeightUsed, y + itemSpace.outerHeight);
|
|
152
|
-
rowIndex += 1;
|
|
153
|
-
y += itemSpace.outerHeight;
|
|
154
|
-
}
|
|
155
|
-
return rep;
|
|
156
|
-
});
|
|
157
|
-
return [seriesWithRawPosition.map(item => (0, _extends2.default)({}, item, {
|
|
158
|
-
positionY: item.positionY + (direction === 'row' ? rowMaxHeight[item.rowIndex] / 2 // Get the center of the entire row
|
|
159
|
-
: item.outerHeight / 2) // Get the center of the item
|
|
160
|
-
})), totalWidthUsed, totalHeightUsed];
|
|
161
|
-
}, [seriesToDisplay, getItemSpace, labelStyle, direction, availableWidth, availableHeight, itemGap]);
|
|
162
|
-
const gapX = React.useMemo(() => {
|
|
163
|
-
switch (position.horizontal) {
|
|
164
|
-
case 'left':
|
|
165
|
-
return padding.left;
|
|
166
|
-
case 'right':
|
|
167
|
-
return totalWidth - padding.right - legendWidth;
|
|
168
|
-
default:
|
|
169
|
-
return (totalWidth - legendWidth) / 2;
|
|
170
|
-
}
|
|
171
|
-
}, [position.horizontal, padding.left, padding.right, totalWidth, legendWidth]);
|
|
172
|
-
const gapY = React.useMemo(() => {
|
|
173
|
-
switch (position.vertical) {
|
|
174
|
-
case 'top':
|
|
175
|
-
return padding.top;
|
|
176
|
-
case 'bottom':
|
|
177
|
-
return totalHeight - padding.bottom - legendHeight;
|
|
178
|
-
default:
|
|
179
|
-
return (totalHeight - legendHeight) / 2;
|
|
180
|
-
}
|
|
181
|
-
}, [position.vertical, padding.top, padding.bottom, totalHeight, legendHeight]);
|
|
182
|
-
if (hidden) {
|
|
183
|
-
return null;
|
|
184
|
-
}
|
|
185
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_NoSsr.NoSsr, {
|
|
186
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(ChartsLegendRoot, {
|
|
187
|
-
className: classes.root,
|
|
188
|
-
children: seriesWithPosition.map(({
|
|
189
|
-
id,
|
|
190
|
-
label,
|
|
191
|
-
color,
|
|
192
|
-
positionX,
|
|
193
|
-
positionY
|
|
194
|
-
}) => /*#__PURE__*/(0, _jsxRuntime.jsxs)("g", {
|
|
195
|
-
className: classes.series,
|
|
196
|
-
transform: `translate(${gapX + (isRTL ? legendWidth - positionX : positionX)} ${gapY + positionY})`,
|
|
197
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("rect", {
|
|
198
|
-
className: classes.mark,
|
|
199
|
-
x: isRTL ? -itemMarkWidth : 0,
|
|
200
|
-
y: -itemMarkHeight / 2,
|
|
201
|
-
width: itemMarkWidth,
|
|
202
|
-
height: itemMarkHeight,
|
|
203
|
-
fill: color
|
|
204
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsText.ChartsText, {
|
|
205
|
-
style: labelStyle,
|
|
206
|
-
text: label,
|
|
207
|
-
x: (isRTL ? -1 : 1) * (itemMarkWidth + markGap),
|
|
208
|
-
y: 0
|
|
209
|
-
})]
|
|
210
|
-
}, id))
|
|
211
|
-
})
|
|
212
|
-
});
|
|
19
|
+
seriesToDisplay
|
|
20
|
+
} = props,
|
|
21
|
+
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
|
22
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_LegendPerItem.LegendPerItem, (0, _extends2.default)({}, other, {
|
|
23
|
+
itemsToDisplay: seriesToDisplay
|
|
24
|
+
}));
|
|
213
25
|
}
|
|
214
26
|
process.env.NODE_ENV !== "production" ? DefaultChartsLegend.propTypes = {
|
|
215
27
|
// ----------------------------- Warning --------------------------------
|
|
@@ -219,12 +31,15 @@ process.env.NODE_ENV !== "production" ? DefaultChartsLegend.propTypes = {
|
|
|
219
31
|
/**
|
|
220
32
|
* Override or extend the styles applied to the component.
|
|
221
33
|
*/
|
|
222
|
-
classes: _propTypes.default.object
|
|
34
|
+
classes: _propTypes.default.object,
|
|
223
35
|
/**
|
|
224
36
|
* The direction of the legend layout.
|
|
225
37
|
* The default depends on the chart.
|
|
226
38
|
*/
|
|
227
39
|
direction: _propTypes.default.oneOf(['column', 'row']).isRequired,
|
|
40
|
+
/**
|
|
41
|
+
* @deprecated Use the `useDrawingArea` hook instead.
|
|
42
|
+
*/
|
|
228
43
|
drawingArea: _propTypes.default.shape({
|
|
229
44
|
bottom: _propTypes.default.number.isRequired,
|
|
230
45
|
height: _propTypes.default.number.isRequired,
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { DrawingArea } from '../context/DrawingProvider';
|
|
3
|
+
import { DefaultizedProps } from '../models/helpers';
|
|
4
|
+
import { ChartsTextStyle } from '../ChartsText';
|
|
5
|
+
import { CardinalDirections } from '../models/layout';
|
|
6
|
+
import type { ChartsLegendProps } from './ChartsLegend';
|
|
7
|
+
import { LegendItemParams } from './chartsLegend.types';
|
|
8
|
+
import { AnchorPosition, Direction } from './legend.types';
|
|
9
|
+
export type ChartsLegendRootOwnerState = {
|
|
10
|
+
position: AnchorPosition;
|
|
11
|
+
direction: Direction;
|
|
12
|
+
drawingArea: DrawingArea;
|
|
13
|
+
offsetX?: number;
|
|
14
|
+
offsetY?: number;
|
|
15
|
+
seriesNumber: number;
|
|
16
|
+
};
|
|
17
|
+
export declare const ChartsLegendRoot: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, Pick<React.SVGProps<SVGGElement>, keyof React.SVGProps<SVGGElement>>, {}>;
|
|
18
|
+
export interface LegendPerItemProps extends DefaultizedProps<Omit<ChartsLegendProps, 'slots' | 'slotProps'>, 'direction' | 'position'> {
|
|
19
|
+
/**
|
|
20
|
+
* The ordered array of item to display in the legend.
|
|
21
|
+
*/
|
|
22
|
+
itemsToDisplay: LegendItemParams[];
|
|
23
|
+
classes?: Record<'mark' | 'series' | 'root', string>;
|
|
24
|
+
/**
|
|
25
|
+
* Style applied to legend labels.
|
|
26
|
+
* @default theme.typography.subtitle1
|
|
27
|
+
*/
|
|
28
|
+
labelStyle?: ChartsTextStyle;
|
|
29
|
+
/**
|
|
30
|
+
* Width of the item mark (in px).
|
|
31
|
+
* @default 20
|
|
32
|
+
*/
|
|
33
|
+
itemMarkWidth?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Height of the item mark (in px).
|
|
36
|
+
* @default 20
|
|
37
|
+
*/
|
|
38
|
+
itemMarkHeight?: number;
|
|
39
|
+
/**
|
|
40
|
+
* Space between the mark and the label (in px).
|
|
41
|
+
* @default 5
|
|
42
|
+
*/
|
|
43
|
+
markGap?: number;
|
|
44
|
+
/**
|
|
45
|
+
* Space between two legend items (in px).
|
|
46
|
+
* @default 10
|
|
47
|
+
*/
|
|
48
|
+
itemGap?: number;
|
|
49
|
+
/**
|
|
50
|
+
* Legend padding (in px).
|
|
51
|
+
* Can either be a single number, or an object with top, left, bottom, right properties.
|
|
52
|
+
* @default 10
|
|
53
|
+
*/
|
|
54
|
+
padding?: number | Partial<CardinalDirections<number>>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Internal component to display an array of items as a legend.
|
|
58
|
+
* Used for series legend, and threshold color legend.
|
|
59
|
+
* @ignore - Do not document
|
|
60
|
+
*/
|
|
61
|
+
export declare function LegendPerItem(props: LegendPerItemProps): React.JSX.Element | null;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.ChartsLegendRoot = void 0;
|
|
8
|
+
exports.LegendPerItem = LegendPerItem;
|
|
9
|
+
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
10
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
|
+
var React = _interopRequireWildcard(require("react"));
|
|
12
|
+
var _NoSsr = require("@mui/base/NoSsr");
|
|
13
|
+
var _styles = require("@mui/material/styles");
|
|
14
|
+
var _ChartsText = require("../ChartsText");
|
|
15
|
+
var _getWordsByLines = require("../internals/getWordsByLines");
|
|
16
|
+
var _legendItemsPlacement = require("./legendItemsPlacement");
|
|
17
|
+
var _useDrawingArea = require("../hooks/useDrawingArea");
|
|
18
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
19
|
+
const _excluded = ["rotate", "dominantBaseline"];
|
|
20
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
21
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
22
|
+
const ChartsLegendRoot = exports.ChartsLegendRoot = (0, _styles.styled)('g', {
|
|
23
|
+
name: 'MuiChartsLegend',
|
|
24
|
+
slot: 'Root',
|
|
25
|
+
overridesResolver: (props, styles) => styles.root
|
|
26
|
+
})({});
|
|
27
|
+
/**
|
|
28
|
+
* Transforms number or partial padding object to a defaultized padding object.
|
|
29
|
+
*/
|
|
30
|
+
const getStandardizedPadding = padding => {
|
|
31
|
+
if (typeof padding === 'number') {
|
|
32
|
+
return {
|
|
33
|
+
left: padding,
|
|
34
|
+
right: padding,
|
|
35
|
+
top: padding,
|
|
36
|
+
bottom: padding
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return (0, _extends2.default)({
|
|
40
|
+
left: 0,
|
|
41
|
+
right: 0,
|
|
42
|
+
top: 0,
|
|
43
|
+
bottom: 0
|
|
44
|
+
}, padding);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Internal component to display an array of items as a legend.
|
|
49
|
+
* Used for series legend, and threshold color legend.
|
|
50
|
+
* @ignore - Do not document
|
|
51
|
+
*/
|
|
52
|
+
function LegendPerItem(props) {
|
|
53
|
+
const {
|
|
54
|
+
hidden,
|
|
55
|
+
position,
|
|
56
|
+
direction,
|
|
57
|
+
itemsToDisplay,
|
|
58
|
+
classes,
|
|
59
|
+
itemMarkWidth = 20,
|
|
60
|
+
itemMarkHeight = 20,
|
|
61
|
+
markGap = 5,
|
|
62
|
+
itemGap = 10,
|
|
63
|
+
padding: paddingProps = 10,
|
|
64
|
+
labelStyle: inLabelStyle
|
|
65
|
+
} = props;
|
|
66
|
+
const theme = (0, _styles.useTheme)();
|
|
67
|
+
const isRTL = theme.direction === 'rtl';
|
|
68
|
+
const drawingArea = (0, _useDrawingArea.useDrawingArea)();
|
|
69
|
+
const labelStyle = React.useMemo(() => (0, _extends2.default)({}, theme.typography.subtitle1, {
|
|
70
|
+
color: 'inherit',
|
|
71
|
+
dominantBaseline: 'central',
|
|
72
|
+
textAnchor: 'start',
|
|
73
|
+
fill: (theme.vars || theme).palette.text.primary,
|
|
74
|
+
lineHeight: 1
|
|
75
|
+
}, inLabelStyle),
|
|
76
|
+
// To say to TS that the dominantBaseline and textAnchor are correct
|
|
77
|
+
[inLabelStyle, theme]);
|
|
78
|
+
const padding = React.useMemo(() => getStandardizedPadding(paddingProps), [paddingProps]);
|
|
79
|
+
const getItemSpace = React.useCallback((label, inStyle = {}) => {
|
|
80
|
+
const style = (0, _objectWithoutPropertiesLoose2.default)(inStyle, _excluded);
|
|
81
|
+
const linesSize = (0, _getWordsByLines.getWordsByLines)({
|
|
82
|
+
style,
|
|
83
|
+
needsComputation: true,
|
|
84
|
+
text: label
|
|
85
|
+
});
|
|
86
|
+
const innerSize = {
|
|
87
|
+
innerWidth: itemMarkWidth + markGap + Math.max(...linesSize.map(size => size.width)),
|
|
88
|
+
innerHeight: Math.max(itemMarkHeight, linesSize.length * linesSize[0].height)
|
|
89
|
+
};
|
|
90
|
+
return (0, _extends2.default)({}, innerSize, {
|
|
91
|
+
outerWidth: innerSize.innerWidth + itemGap,
|
|
92
|
+
outerHeight: innerSize.innerHeight + itemGap
|
|
93
|
+
});
|
|
94
|
+
}, [itemGap, itemMarkHeight, itemMarkWidth, markGap]);
|
|
95
|
+
const totalWidth = drawingArea.left + drawingArea.width + drawingArea.right;
|
|
96
|
+
const totalHeight = drawingArea.top + drawingArea.height + drawingArea.bottom;
|
|
97
|
+
const availableWidth = totalWidth - padding.left - padding.right;
|
|
98
|
+
const availableHeight = totalHeight - padding.top - padding.bottom;
|
|
99
|
+
const [itemsWithPosition, legendWidth, legendHeight] = React.useMemo(() => (0, _legendItemsPlacement.legendItemPlacements)(itemsToDisplay, getItemSpace, labelStyle, direction, availableWidth, availableHeight, itemGap), [itemsToDisplay, getItemSpace, labelStyle, direction, availableWidth, availableHeight, itemGap]);
|
|
100
|
+
const gapX = React.useMemo(() => {
|
|
101
|
+
switch (position.horizontal) {
|
|
102
|
+
case 'left':
|
|
103
|
+
return padding.left;
|
|
104
|
+
case 'right':
|
|
105
|
+
return totalWidth - padding.right - legendWidth;
|
|
106
|
+
default:
|
|
107
|
+
return (totalWidth - legendWidth) / 2;
|
|
108
|
+
}
|
|
109
|
+
}, [position.horizontal, padding.left, padding.right, totalWidth, legendWidth]);
|
|
110
|
+
const gapY = React.useMemo(() => {
|
|
111
|
+
switch (position.vertical) {
|
|
112
|
+
case 'top':
|
|
113
|
+
return padding.top;
|
|
114
|
+
case 'bottom':
|
|
115
|
+
return totalHeight - padding.bottom - legendHeight;
|
|
116
|
+
default:
|
|
117
|
+
return (totalHeight - legendHeight) / 2;
|
|
118
|
+
}
|
|
119
|
+
}, [position.vertical, padding.top, padding.bottom, totalHeight, legendHeight]);
|
|
120
|
+
if (hidden) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_NoSsr.NoSsr, {
|
|
124
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(ChartsLegendRoot, {
|
|
125
|
+
className: classes?.root,
|
|
126
|
+
children: itemsWithPosition.map(({
|
|
127
|
+
id,
|
|
128
|
+
label,
|
|
129
|
+
color,
|
|
130
|
+
positionX,
|
|
131
|
+
positionY
|
|
132
|
+
}) => /*#__PURE__*/(0, _jsxRuntime.jsxs)("g", {
|
|
133
|
+
className: classes?.series,
|
|
134
|
+
transform: `translate(${gapX + (isRTL ? legendWidth - positionX : positionX)} ${gapY + positionY})`,
|
|
135
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("rect", {
|
|
136
|
+
className: classes?.mark,
|
|
137
|
+
x: isRTL ? -itemMarkWidth : 0,
|
|
138
|
+
y: -itemMarkHeight / 2,
|
|
139
|
+
width: itemMarkWidth,
|
|
140
|
+
height: itemMarkHeight,
|
|
141
|
+
fill: color
|
|
142
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsText.ChartsText, {
|
|
143
|
+
style: labelStyle,
|
|
144
|
+
text: label,
|
|
145
|
+
x: (isRTL ? -1 : 1) * (itemMarkWidth + markGap),
|
|
146
|
+
y: 0
|
|
147
|
+
})]
|
|
148
|
+
}, id))
|
|
149
|
+
})
|
|
150
|
+
});
|
|
151
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ColorLegendSelector, PiecewiseLabelFormatterParams } from './legend.types';
|
|
3
|
+
import { LegendPerItemProps } from './LegendPerItem';
|
|
4
|
+
export interface PiecewiseColorLegendProps extends ColorLegendSelector, Omit<LegendPerItemProps, 'itemsToDisplay'> {
|
|
5
|
+
/**
|
|
6
|
+
* Hide the first item of the legend, corresponding to the [-infinity, min] piece.
|
|
7
|
+
* @default false
|
|
8
|
+
*/
|
|
9
|
+
hideFirst?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Hide the last item of the legend, corresponding to the [max, +infinity] piece.
|
|
12
|
+
* @default false
|
|
13
|
+
*/
|
|
14
|
+
hideLast?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Format the legend labels.
|
|
17
|
+
* @param {PiecewiseLabelFormatterParams} params The bound of the piece to format.
|
|
18
|
+
* @returns {string|null} The displayed label, or `null` to skip the item.
|
|
19
|
+
*/
|
|
20
|
+
labelFormatter?: (params: PiecewiseLabelFormatterParams) => string | null;
|
|
21
|
+
}
|
|
22
|
+
declare function PiecewiseColorLegend(props: PiecewiseColorLegendProps): React.JSX.Element | null;
|
|
23
|
+
declare namespace PiecewiseColorLegend {
|
|
24
|
+
var propTypes: any;
|
|
25
|
+
}
|
|
26
|
+
export { PiecewiseColorLegend };
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.PiecewiseColorLegend = PiecewiseColorLegend;
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
10
|
+
var React = _interopRequireWildcard(require("react"));
|
|
11
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
12
|
+
var _useAxis = require("./useAxis");
|
|
13
|
+
var _LegendPerItem = require("./LegendPerItem");
|
|
14
|
+
var _notNull = require("../internals/notNull");
|
|
15
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
16
|
+
const _excluded = ["axisDirection", "axisId", "hideFirst", "hideLast", "labelFormatter"];
|
|
17
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
18
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
19
|
+
function defaultLabelFormatter(params) {
|
|
20
|
+
if (params.min === null) {
|
|
21
|
+
return `<${params.formattedMax}`;
|
|
22
|
+
}
|
|
23
|
+
if (params.max === null) {
|
|
24
|
+
return `>${params.formattedMin}`;
|
|
25
|
+
}
|
|
26
|
+
return `${params.formattedMin}-${params.formattedMax}`;
|
|
27
|
+
}
|
|
28
|
+
function PiecewiseColorLegend(props) {
|
|
29
|
+
const {
|
|
30
|
+
axisDirection,
|
|
31
|
+
axisId,
|
|
32
|
+
hideFirst,
|
|
33
|
+
hideLast,
|
|
34
|
+
labelFormatter = defaultLabelFormatter
|
|
35
|
+
} = props,
|
|
36
|
+
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
|
37
|
+
const axisItem = (0, _useAxis.useAxis)({
|
|
38
|
+
axisDirection,
|
|
39
|
+
axisId
|
|
40
|
+
});
|
|
41
|
+
const colorMap = axisItem?.colorMap;
|
|
42
|
+
if (!colorMap || !colorMap.type || colorMap.type !== 'piecewise') {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
const valueFormatter = v => axisItem.valueFormatter?.(v, {
|
|
46
|
+
location: 'legend'
|
|
47
|
+
}) ?? v.toLocaleString();
|
|
48
|
+
const formattedLabels = colorMap.thresholds.map(valueFormatter);
|
|
49
|
+
const itemsToDisplay = colorMap.colors.map((color, index) => {
|
|
50
|
+
const isFirst = index === 0;
|
|
51
|
+
const isLast = index === colorMap.colors.length - 1;
|
|
52
|
+
if (hideFirst && isFirst || hideLast && isLast) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
const label = labelFormatter((0, _extends2.default)({}, index === 0 ? {
|
|
56
|
+
min: null,
|
|
57
|
+
formattedMin: null
|
|
58
|
+
} : {
|
|
59
|
+
min: colorMap.thresholds[index - 1],
|
|
60
|
+
formattedMin: formattedLabels[index - 1]
|
|
61
|
+
}, index === colorMap.colors.length - 1 ? {
|
|
62
|
+
max: null,
|
|
63
|
+
formattedMax: null
|
|
64
|
+
} : {
|
|
65
|
+
max: colorMap.thresholds[index],
|
|
66
|
+
formattedMax: formattedLabels[index]
|
|
67
|
+
}));
|
|
68
|
+
if (label === null) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
id: label,
|
|
73
|
+
color,
|
|
74
|
+
label
|
|
75
|
+
};
|
|
76
|
+
}).filter(_notNull.notNull);
|
|
77
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_LegendPerItem.LegendPerItem, (0, _extends2.default)({}, other, {
|
|
78
|
+
itemsToDisplay: itemsToDisplay
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
process.env.NODE_ENV !== "production" ? PiecewiseColorLegend.propTypes = {
|
|
82
|
+
// ----------------------------- Warning --------------------------------
|
|
83
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
84
|
+
// | To update them edit the TypeScript types and run "pnpm proptypes" |
|
|
85
|
+
// ----------------------------------------------------------------------
|
|
86
|
+
/**
|
|
87
|
+
* The axis direction containing the color configuration to represent.
|
|
88
|
+
* @default 'z'
|
|
89
|
+
*/
|
|
90
|
+
axisDirection: _propTypes.default.oneOf(['x', 'y', 'z']),
|
|
91
|
+
/**
|
|
92
|
+
* The id of the axis item with the color configuration to represent.
|
|
93
|
+
* @default The first axis item.
|
|
94
|
+
*/
|
|
95
|
+
axisId: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
|
|
96
|
+
/**
|
|
97
|
+
* Override or extend the styles applied to the component.
|
|
98
|
+
*/
|
|
99
|
+
classes: _propTypes.default.object,
|
|
100
|
+
/**
|
|
101
|
+
* The direction of the legend layout.
|
|
102
|
+
* The default depends on the chart.
|
|
103
|
+
*/
|
|
104
|
+
direction: _propTypes.default.oneOf(['column', 'row']).isRequired,
|
|
105
|
+
/**
|
|
106
|
+
* Set to true to hide the legend.
|
|
107
|
+
* @default false
|
|
108
|
+
*/
|
|
109
|
+
hidden: _propTypes.default.bool,
|
|
110
|
+
/**
|
|
111
|
+
* Hide the first item of the legend, corresponding to the [-infinity, min] piece.
|
|
112
|
+
* @default false
|
|
113
|
+
*/
|
|
114
|
+
hideFirst: _propTypes.default.bool,
|
|
115
|
+
/**
|
|
116
|
+
* Hide the last item of the legend, corresponding to the [max, +infinity] piece.
|
|
117
|
+
* @default false
|
|
118
|
+
*/
|
|
119
|
+
hideLast: _propTypes.default.bool,
|
|
120
|
+
/**
|
|
121
|
+
* Space between two legend items (in px).
|
|
122
|
+
* @default 10
|
|
123
|
+
*/
|
|
124
|
+
itemGap: _propTypes.default.number,
|
|
125
|
+
/**
|
|
126
|
+
* Height of the item mark (in px).
|
|
127
|
+
* @default 20
|
|
128
|
+
*/
|
|
129
|
+
itemMarkHeight: _propTypes.default.number,
|
|
130
|
+
/**
|
|
131
|
+
* Width of the item mark (in px).
|
|
132
|
+
* @default 20
|
|
133
|
+
*/
|
|
134
|
+
itemMarkWidth: _propTypes.default.number,
|
|
135
|
+
/**
|
|
136
|
+
* Format the legend labels.
|
|
137
|
+
* @param {PiecewiseLabelFormatterParams} params The bound of the piece to format.
|
|
138
|
+
* @returns {string|null} The displayed label, or `null` to skip the item.
|
|
139
|
+
*/
|
|
140
|
+
labelFormatter: _propTypes.default.func,
|
|
141
|
+
/**
|
|
142
|
+
* Style applied to legend labels.
|
|
143
|
+
* @default theme.typography.subtitle1
|
|
144
|
+
*/
|
|
145
|
+
labelStyle: _propTypes.default.object,
|
|
146
|
+
/**
|
|
147
|
+
* Space between the mark and the label (in px).
|
|
148
|
+
* @default 5
|
|
149
|
+
*/
|
|
150
|
+
markGap: _propTypes.default.number,
|
|
151
|
+
/**
|
|
152
|
+
* Legend padding (in px).
|
|
153
|
+
* Can either be a single number, or an object with top, left, bottom, right properties.
|
|
154
|
+
* @default 10
|
|
155
|
+
*/
|
|
156
|
+
padding: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.shape({
|
|
157
|
+
bottom: _propTypes.default.number,
|
|
158
|
+
left: _propTypes.default.number,
|
|
159
|
+
right: _propTypes.default.number,
|
|
160
|
+
top: _propTypes.default.number
|
|
161
|
+
})]),
|
|
162
|
+
/**
|
|
163
|
+
* The position of the legend.
|
|
164
|
+
*/
|
|
165
|
+
position: _propTypes.default.shape({
|
|
166
|
+
horizontal: _propTypes.default.oneOf(['left', 'middle', 'right']).isRequired,
|
|
167
|
+
vertical: _propTypes.default.oneOf(['bottom', 'middle', 'top']).isRequired
|
|
168
|
+
}).isRequired
|
|
169
|
+
} : void 0;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ChartsTextStyle } from '../ChartsText';
|
|
2
|
+
export interface LegendItemParams {
|
|
3
|
+
/**
|
|
4
|
+
* The color used in the legend
|
|
5
|
+
*/
|
|
6
|
+
color: string;
|
|
7
|
+
/**
|
|
8
|
+
* The label displayed in the legend
|
|
9
|
+
*/
|
|
10
|
+
label: string;
|
|
11
|
+
/**
|
|
12
|
+
* The identifier of the legend element.
|
|
13
|
+
* Used for internal purpose such as `key` props
|
|
14
|
+
*/
|
|
15
|
+
id: number | string;
|
|
16
|
+
}
|
|
17
|
+
export interface LegendItemWithPosition extends LegendItemParams {
|
|
18
|
+
positionX: number;
|
|
19
|
+
positionY: number;
|
|
20
|
+
innerHeight: number;
|
|
21
|
+
innerWidth: number;
|
|
22
|
+
outerHeight: number;
|
|
23
|
+
outerWidth: number;
|
|
24
|
+
rowIndex: number;
|
|
25
|
+
}
|
|
26
|
+
export type GetItemSpaceType = (label: string, inStyle?: ChartsTextStyle) => {
|
|
27
|
+
innerWidth: number;
|
|
28
|
+
innerHeight: number;
|
|
29
|
+
outerWidth: number;
|
|
30
|
+
outerHeight: number;
|
|
31
|
+
};
|