@mui/x-charts 7.9.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 +159 -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/AreaPlot.js +7 -1
- 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/extremums.js +1 -1
- 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/AreaPlot.js +7 -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/extremums.js +1 -1
- 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/AreaPlot.js +7 -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/extremums.js +1 -1
- 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
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import { useTheme } from '@mui/material/styles';
|
|
5
|
+
import ChartsContinuousGradient from '../internals/components/ChartsAxesGradients/ChartsContinuousGradient';
|
|
6
|
+
import { useChartId, useDrawingArea } from '../hooks';
|
|
7
|
+
import { getScale } from '../internals/getScale';
|
|
8
|
+
import { getPercentageValue } from '../internals/getPercentageValue';
|
|
9
|
+
import { ChartsText } from '../ChartsText';
|
|
10
|
+
import { getStringSize } from '../internals/domUtils';
|
|
11
|
+
import { useAxis } from './useAxis';
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
function getPositionOffset(position, legendBox, svgBox) {
|
|
14
|
+
let offsetX = 0;
|
|
15
|
+
let offsetY = 0;
|
|
16
|
+
switch (position.horizontal) {
|
|
17
|
+
case 'left':
|
|
18
|
+
offsetX = 0;
|
|
19
|
+
break;
|
|
20
|
+
case 'middle':
|
|
21
|
+
offsetX = (svgBox.width - legendBox.width) / 2;
|
|
22
|
+
break;
|
|
23
|
+
case 'right':
|
|
24
|
+
default:
|
|
25
|
+
offsetX = svgBox.width - legendBox.width;
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
switch (position.vertical) {
|
|
29
|
+
case 'top':
|
|
30
|
+
offsetY = 0;
|
|
31
|
+
break;
|
|
32
|
+
case 'middle':
|
|
33
|
+
offsetY = (svgBox.height - legendBox.height) / 2;
|
|
34
|
+
break;
|
|
35
|
+
case 'bottom':
|
|
36
|
+
default:
|
|
37
|
+
offsetY = svgBox.height - legendBox.height;
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
offsetX,
|
|
42
|
+
offsetY
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Takes placement parameters and element bounding boxes.
|
|
48
|
+
* Returns the x, y coordinates of the elements. And the textAnchor, dominantBaseline for texts.
|
|
49
|
+
*/
|
|
50
|
+
function getElementPositions(text1Box, barBox, text2Box, params) {
|
|
51
|
+
if (params.direction === 'column') {
|
|
52
|
+
const text1 = {
|
|
53
|
+
y: text1Box.height,
|
|
54
|
+
dominantBaseline: 'auto'
|
|
55
|
+
};
|
|
56
|
+
const text2 = {
|
|
57
|
+
y: text1Box.height + 2 * params.spacing + barBox.height,
|
|
58
|
+
dominantBaseline: 'hanging'
|
|
59
|
+
};
|
|
60
|
+
const bar = {
|
|
61
|
+
y: text1Box.height + params.spacing
|
|
62
|
+
};
|
|
63
|
+
const totalWidth = Math.max(text1Box.width, barBox.width, text2Box.width);
|
|
64
|
+
const totalHeight = text1Box.height + barBox.height + text2Box.height + 2 * params.spacing;
|
|
65
|
+
const boundingBox = {
|
|
66
|
+
width: totalWidth,
|
|
67
|
+
height: totalHeight
|
|
68
|
+
};
|
|
69
|
+
switch (params.align) {
|
|
70
|
+
case 'start':
|
|
71
|
+
return {
|
|
72
|
+
text1: _extends({}, text1, {
|
|
73
|
+
textAnchor: 'start',
|
|
74
|
+
x: 0
|
|
75
|
+
}),
|
|
76
|
+
text2: _extends({}, text2, {
|
|
77
|
+
textAnchor: 'start',
|
|
78
|
+
x: 0
|
|
79
|
+
}),
|
|
80
|
+
bar: _extends({}, bar, {
|
|
81
|
+
x: 0
|
|
82
|
+
}),
|
|
83
|
+
boundingBox
|
|
84
|
+
};
|
|
85
|
+
case 'end':
|
|
86
|
+
return {
|
|
87
|
+
text1: _extends({}, text1, {
|
|
88
|
+
textAnchor: 'end',
|
|
89
|
+
x: totalWidth
|
|
90
|
+
}),
|
|
91
|
+
text2: _extends({}, text2, {
|
|
92
|
+
textAnchor: 'end',
|
|
93
|
+
x: totalWidth
|
|
94
|
+
}),
|
|
95
|
+
bar: _extends({}, bar, {
|
|
96
|
+
x: totalWidth - barBox.width
|
|
97
|
+
}),
|
|
98
|
+
boundingBox
|
|
99
|
+
};
|
|
100
|
+
case 'middle':
|
|
101
|
+
default:
|
|
102
|
+
return {
|
|
103
|
+
text1: _extends({}, text1, {
|
|
104
|
+
textAnchor: 'middle',
|
|
105
|
+
x: totalWidth / 2
|
|
106
|
+
}),
|
|
107
|
+
text2: _extends({}, text2, {
|
|
108
|
+
textAnchor: 'middle',
|
|
109
|
+
x: totalWidth / 2
|
|
110
|
+
}),
|
|
111
|
+
bar: _extends({}, bar, {
|
|
112
|
+
x: totalWidth / 2 - barBox.width / 2
|
|
113
|
+
}),
|
|
114
|
+
boundingBox
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
} else {
|
|
118
|
+
const text1 = {
|
|
119
|
+
x: text1Box.width,
|
|
120
|
+
textAnchor: 'end'
|
|
121
|
+
};
|
|
122
|
+
const text2 = {
|
|
123
|
+
x: text1Box.width + 2 * params.spacing + barBox.width,
|
|
124
|
+
textAnchor: 'start'
|
|
125
|
+
};
|
|
126
|
+
const bar = {
|
|
127
|
+
x: text1Box.width + params.spacing
|
|
128
|
+
};
|
|
129
|
+
const totalHeight = Math.max(text1Box.height, barBox.height, text2Box.height);
|
|
130
|
+
const totalWidth = text1Box.width + barBox.width + text2Box.width + 2 * params.spacing;
|
|
131
|
+
const boundingBox = {
|
|
132
|
+
width: totalWidth,
|
|
133
|
+
height: totalHeight
|
|
134
|
+
};
|
|
135
|
+
switch (params.align) {
|
|
136
|
+
case 'start':
|
|
137
|
+
return {
|
|
138
|
+
text1: _extends({}, text1, {
|
|
139
|
+
dominantBaseline: 'hanging',
|
|
140
|
+
y: 0
|
|
141
|
+
}),
|
|
142
|
+
text2: _extends({}, text2, {
|
|
143
|
+
dominantBaseline: 'hanging',
|
|
144
|
+
y: 0
|
|
145
|
+
}),
|
|
146
|
+
bar: _extends({}, bar, {
|
|
147
|
+
y: 0
|
|
148
|
+
}),
|
|
149
|
+
boundingBox
|
|
150
|
+
};
|
|
151
|
+
case 'end':
|
|
152
|
+
return {
|
|
153
|
+
text1: _extends({}, text1, {
|
|
154
|
+
dominantBaseline: 'auto',
|
|
155
|
+
y: totalHeight
|
|
156
|
+
}),
|
|
157
|
+
text2: _extends({}, text2, {
|
|
158
|
+
dominantBaseline: 'auto',
|
|
159
|
+
y: totalHeight
|
|
160
|
+
}),
|
|
161
|
+
bar: _extends({}, bar, {
|
|
162
|
+
y: totalHeight - barBox.height
|
|
163
|
+
}),
|
|
164
|
+
boundingBox
|
|
165
|
+
};
|
|
166
|
+
case 'middle':
|
|
167
|
+
default:
|
|
168
|
+
return {
|
|
169
|
+
text1: _extends({}, text1, {
|
|
170
|
+
dominantBaseline: 'central',
|
|
171
|
+
y: totalHeight / 2
|
|
172
|
+
}),
|
|
173
|
+
text2: _extends({}, text2, {
|
|
174
|
+
dominantBaseline: 'central',
|
|
175
|
+
y: totalHeight / 2
|
|
176
|
+
}),
|
|
177
|
+
bar: _extends({}, bar, {
|
|
178
|
+
y: totalHeight / 2 - barBox.height / 2
|
|
179
|
+
}),
|
|
180
|
+
boundingBox
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const defaultLabelFormatter = ({
|
|
186
|
+
formattedValue
|
|
187
|
+
}) => formattedValue;
|
|
188
|
+
function ContinuousColorLegend(props) {
|
|
189
|
+
const theme = useTheme();
|
|
190
|
+
const {
|
|
191
|
+
id: idProp,
|
|
192
|
+
minLabel = defaultLabelFormatter,
|
|
193
|
+
maxLabel = defaultLabelFormatter,
|
|
194
|
+
scaleType = 'linear',
|
|
195
|
+
direction,
|
|
196
|
+
length = '50%',
|
|
197
|
+
thickness = 5,
|
|
198
|
+
spacing = 4,
|
|
199
|
+
align = 'middle',
|
|
200
|
+
labelStyle = theme.typography.subtitle1,
|
|
201
|
+
position,
|
|
202
|
+
axisDirection,
|
|
203
|
+
axisId
|
|
204
|
+
} = props;
|
|
205
|
+
const chartId = useChartId();
|
|
206
|
+
const id = idProp ?? `gradient-legend-${chartId}`;
|
|
207
|
+
const isRTL = theme.direction === 'rtl';
|
|
208
|
+
const axisItem = useAxis({
|
|
209
|
+
axisDirection,
|
|
210
|
+
axisId
|
|
211
|
+
});
|
|
212
|
+
const {
|
|
213
|
+
width,
|
|
214
|
+
height,
|
|
215
|
+
left,
|
|
216
|
+
right,
|
|
217
|
+
top,
|
|
218
|
+
bottom
|
|
219
|
+
} = useDrawingArea();
|
|
220
|
+
const refLength = direction === 'column' ? height + top + bottom : width + left + right;
|
|
221
|
+
const size = getPercentageValue(length, refLength);
|
|
222
|
+
const isReversed = direction === 'column';
|
|
223
|
+
const colorMap = axisItem?.colorMap;
|
|
224
|
+
if (!colorMap || !colorMap.type || colorMap.type !== 'continuous') {
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Define the coordinate to color mapping
|
|
229
|
+
|
|
230
|
+
const colorScale = axisItem.colorScale;
|
|
231
|
+
const minValue = colorMap.min ?? 0;
|
|
232
|
+
const maxValue = colorMap.max ?? 100;
|
|
233
|
+
const scale = getScale(scaleType, [minValue, maxValue], isReversed ? [size, 0] : [0, size]);
|
|
234
|
+
|
|
235
|
+
// Get texts to display
|
|
236
|
+
|
|
237
|
+
const formattedMin = axisItem.valueFormatter?.(minValue, {
|
|
238
|
+
location: 'legend'
|
|
239
|
+
}) ?? minValue.toLocaleString();
|
|
240
|
+
const formattedMax = axisItem.valueFormatter?.(maxValue, {
|
|
241
|
+
location: 'legend'
|
|
242
|
+
}) ?? maxValue.toLocaleString();
|
|
243
|
+
const minText = typeof minLabel === 'string' ? minLabel : minLabel({
|
|
244
|
+
value: minValue ?? 0,
|
|
245
|
+
formattedValue: formattedMin
|
|
246
|
+
});
|
|
247
|
+
const maxText = typeof maxLabel === 'string' ? maxLabel : maxLabel({
|
|
248
|
+
value: maxValue ?? 0,
|
|
249
|
+
formattedValue: formattedMax
|
|
250
|
+
});
|
|
251
|
+
const text1 = isReversed ? maxText : minText;
|
|
252
|
+
const text2 = isReversed ? minText : maxText;
|
|
253
|
+
const text1Box = getStringSize(text1, _extends({}, labelStyle));
|
|
254
|
+
const text2Box = getStringSize(text2, _extends({}, labelStyle));
|
|
255
|
+
|
|
256
|
+
// Place bar and texts
|
|
257
|
+
|
|
258
|
+
const barBox = direction === 'column' || isRTL && direction === 'row' ? {
|
|
259
|
+
width: thickness,
|
|
260
|
+
height: size
|
|
261
|
+
} : {
|
|
262
|
+
width: size,
|
|
263
|
+
height: thickness
|
|
264
|
+
};
|
|
265
|
+
const legendPositions = getElementPositions(text1Box, barBox, text2Box, {
|
|
266
|
+
spacing,
|
|
267
|
+
align,
|
|
268
|
+
direction
|
|
269
|
+
});
|
|
270
|
+
const svgBoundingBox = {
|
|
271
|
+
width: width + left + right,
|
|
272
|
+
height: height + top + bottom
|
|
273
|
+
};
|
|
274
|
+
const positionOffset = getPositionOffset(_extends({
|
|
275
|
+
horizontal: 'middle',
|
|
276
|
+
vertical: 'top'
|
|
277
|
+
}, position), legendPositions.boundingBox, svgBoundingBox);
|
|
278
|
+
return /*#__PURE__*/_jsxs(React.Fragment, {
|
|
279
|
+
children: [/*#__PURE__*/_jsx(ChartsContinuousGradient, {
|
|
280
|
+
isReversed: isReversed,
|
|
281
|
+
gradientId: id,
|
|
282
|
+
size: size,
|
|
283
|
+
direction: direction === 'row' ? 'x' : 'y',
|
|
284
|
+
scale: scale,
|
|
285
|
+
colorScale: colorScale,
|
|
286
|
+
colorMap: colorMap,
|
|
287
|
+
gradientUnits: "objectBoundingBox"
|
|
288
|
+
}), /*#__PURE__*/_jsx(ChartsText, {
|
|
289
|
+
text: text1,
|
|
290
|
+
x: positionOffset.offsetX + legendPositions.text1.x,
|
|
291
|
+
y: positionOffset.offsetY + legendPositions.text1.y,
|
|
292
|
+
style: _extends({
|
|
293
|
+
dominantBaseline: legendPositions.text1.dominantBaseline,
|
|
294
|
+
textAnchor: legendPositions.text1.textAnchor
|
|
295
|
+
}, labelStyle)
|
|
296
|
+
}), /*#__PURE__*/_jsx("rect", _extends({
|
|
297
|
+
x: positionOffset.offsetX + legendPositions.bar.x,
|
|
298
|
+
y: positionOffset.offsetY + legendPositions.bar.y
|
|
299
|
+
}, barBox, {
|
|
300
|
+
fill: `url(#${id})`
|
|
301
|
+
})), /*#__PURE__*/_jsx(ChartsText, {
|
|
302
|
+
text: text2,
|
|
303
|
+
x: positionOffset.offsetX + legendPositions.text2.x,
|
|
304
|
+
y: positionOffset.offsetY + legendPositions.text2.y,
|
|
305
|
+
style: _extends({
|
|
306
|
+
dominantBaseline: legendPositions.text2.dominantBaseline,
|
|
307
|
+
textAnchor: legendPositions.text2.textAnchor
|
|
308
|
+
}, labelStyle)
|
|
309
|
+
})]
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
process.env.NODE_ENV !== "production" ? ContinuousColorLegend.propTypes = {
|
|
313
|
+
// ----------------------------- Warning --------------------------------
|
|
314
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
315
|
+
// | To update them edit the TypeScript types and run "pnpm proptypes" |
|
|
316
|
+
// ----------------------------------------------------------------------
|
|
317
|
+
/**
|
|
318
|
+
* The alignment of the texts with the gradient bar.
|
|
319
|
+
* @default 'middle'
|
|
320
|
+
*/
|
|
321
|
+
align: PropTypes.oneOf(['end', 'middle', 'start']),
|
|
322
|
+
/**
|
|
323
|
+
* The axis direction containing the color configuration to represent.
|
|
324
|
+
* @default 'z'
|
|
325
|
+
*/
|
|
326
|
+
axisDirection: PropTypes.oneOf(['x', 'y', 'z']),
|
|
327
|
+
/**
|
|
328
|
+
* The id of the axis item with the color configuration to represent.
|
|
329
|
+
* @default The first axis item.
|
|
330
|
+
*/
|
|
331
|
+
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
332
|
+
/**
|
|
333
|
+
* The direction of the legend layout.
|
|
334
|
+
* The default depends on the chart.
|
|
335
|
+
*/
|
|
336
|
+
direction: PropTypes.oneOf(['column', 'row']),
|
|
337
|
+
/**
|
|
338
|
+
* A unique identifier for the gradient.
|
|
339
|
+
* @default auto-generated id
|
|
340
|
+
*/
|
|
341
|
+
id: PropTypes.string,
|
|
342
|
+
/**
|
|
343
|
+
* The style applied to labels.
|
|
344
|
+
* @default theme.typography.subtitle1
|
|
345
|
+
*/
|
|
346
|
+
labelStyle: PropTypes.object,
|
|
347
|
+
/**
|
|
348
|
+
* The length of the gradient bar.
|
|
349
|
+
* Can be a number (in px) or a string with a percentage such as '50%'.
|
|
350
|
+
* The '100%' is the length of the svg.
|
|
351
|
+
* @default '50%'
|
|
352
|
+
*/
|
|
353
|
+
length: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
354
|
+
/**
|
|
355
|
+
* The label to display at the maximum side of the gradient.
|
|
356
|
+
* Can either be a string, or a function.
|
|
357
|
+
* If not defined, the formatted maximal value is display.
|
|
358
|
+
* @default ({ formattedValue }) => formattedValue
|
|
359
|
+
*/
|
|
360
|
+
maxLabel: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
|
|
361
|
+
/**
|
|
362
|
+
* The label to display at the minimum side of the gradient.
|
|
363
|
+
* Can either be a string, or a function.
|
|
364
|
+
* @default ({ formattedValue }) => formattedValue
|
|
365
|
+
*/
|
|
366
|
+
minLabel: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
|
|
367
|
+
/**
|
|
368
|
+
* The position of the legend.
|
|
369
|
+
*/
|
|
370
|
+
position: PropTypes.shape({
|
|
371
|
+
horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
|
|
372
|
+
vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
|
|
373
|
+
}),
|
|
374
|
+
/**
|
|
375
|
+
* The scale used to display gradient colors.
|
|
376
|
+
* @default 'linear'
|
|
377
|
+
*/
|
|
378
|
+
scaleType: PropTypes.oneOf(['linear', 'log', 'pow', 'sqrt', 'time', 'utc']),
|
|
379
|
+
/**
|
|
380
|
+
* The space between the gradient bar and the labels.
|
|
381
|
+
* @default 4
|
|
382
|
+
*/
|
|
383
|
+
spacing: PropTypes.number,
|
|
384
|
+
/**
|
|
385
|
+
* The thickness of the gradient bar.
|
|
386
|
+
* @default 5
|
|
387
|
+
*/
|
|
388
|
+
thickness: PropTypes.number
|
|
389
|
+
} : void 0;
|
|
390
|
+
export { ContinuousColorLegend };
|
|
@@ -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,
|