@mui/x-charts 7.10.0 → 7.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BarChart/BarChart.js +2 -2
- package/BarChart/BarElement.d.ts +2 -1
- package/BarChart/BarLabel/BarLabelItem.d.ts +2 -1
- package/BarChart/BarPlot.js +8 -8
- package/BarChart/checkScaleErrors.d.ts +4 -4
- package/BarChart/checkScaleErrors.js +11 -11
- package/BarChart/extremums.js +4 -1
- package/BarChart/formatter.js +2 -2
- package/BarChart/useBarChartProps.js +38 -33
- package/CHANGELOG.md +169 -0
- package/ChartContainer/ChartContainer.d.ts +28 -2
- package/ChartContainer/ChartContainer.js +25 -66
- package/ChartContainer/useChartContainerHooks.d.ts +1 -1
- package/ChartContainer/useChartContainerHooks.js +2 -2
- package/ChartContainer/useChartContainerProps.d.ts +86 -0
- package/ChartContainer/useChartContainerProps.js +95 -0
- package/ChartContainer/useDefaultizeAxis.d.ts +36 -0
- package/ChartContainer/useDefaultizeAxis.js +29 -0
- package/ChartsAxis/ChartsAxis.js +4 -4
- package/ChartsAxisHighlight/ChartsAxisHighlight.js +1 -1
- package/ChartsLegend/ChartsLegend.d.ts +3 -12
- package/ChartsLegend/ContinuousColorLegend.d.ts +65 -0
- package/ChartsLegend/ContinuousColorLegend.js +398 -0
- package/ChartsLegend/DefaultChartsLegend.d.ts +7 -50
- package/ChartsLegend/DefaultChartsLegend.js +13 -198
- package/ChartsLegend/LegendPerItem.d.ts +61 -0
- package/ChartsLegend/LegendPerItem.js +151 -0
- package/ChartsLegend/PiecewiseColorLegend.d.ts +26 -0
- package/ChartsLegend/PiecewiseColorLegend.js +169 -0
- package/ChartsLegend/chartsLegend.types.d.ts +31 -0
- package/ChartsLegend/chartsLegend.types.js +5 -0
- package/ChartsLegend/index.d.ts +2 -0
- package/ChartsLegend/index.js +22 -0
- package/ChartsLegend/legend.types.d.ts +62 -0
- package/ChartsLegend/legend.types.js +5 -0
- package/ChartsLegend/legendItemsPlacement.d.ts +3 -0
- package/ChartsLegend/legendItemsPlacement.js +79 -0
- package/ChartsLegend/useAxis.d.ts +7 -0
- package/ChartsLegend/useAxis.js +47 -0
- package/ChartsLegend/utils.d.ts +1 -8
- package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +3 -1
- package/ChartsOverlay/ChartsOverlay.d.ts +3 -2
- package/ChartsReferenceLine/ChartsReferenceLine.d.ts +1 -1
- package/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/ChartsReferenceLine/ChartsXReferenceLine.js +1 -2
- package/ChartsReferenceLine/ChartsYReferenceLine.js +1 -2
- package/ChartsSurface.js +3 -1
- package/ChartsTooltip/ChartsAxisTooltipContent.js +7 -3
- package/ChartsTooltip/ChartsItemTooltipContent.js +4 -4
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +30 -20
- package/ChartsXAxis/ChartsXAxis.js +1 -1
- package/ChartsYAxis/ChartsYAxis.js +15 -3
- package/Gauge/Gauge.d.ts +1 -4
- package/Gauge/Gauge.js +9 -6
- package/Gauge/GaugeContainer.js +8 -4
- package/Gauge/GaugeProvider.js +9 -9
- package/LineChart/AnimatedArea.js +2 -2
- package/LineChart/AnimatedLine.js +2 -2
- package/LineChart/AreaElement.d.ts +2 -1
- package/LineChart/AreaPlot.js +10 -6
- package/LineChart/LineChart.js +5 -2
- package/LineChart/LineElement.d.ts +2 -1
- package/LineChart/LineHighlightPlot.d.ts +2 -1
- package/LineChart/LineHighlightPlot.js +17 -5
- package/LineChart/LinePlot.js +10 -6
- package/LineChart/MarkElement.js +2 -2
- package/LineChart/MarkPlot.js +13 -25
- package/LineChart/extremums.js +4 -1
- package/LineChart/formatter.js +2 -2
- package/LineChart/useLineChartProps.js +38 -33
- package/PieChart/PieArc.js +1 -0
- package/PieChart/PieChart.d.ts +1 -4
- package/PieChart/PieChart.js +40 -34
- package/PieChart/PiePlot.js +6 -6
- package/PieChart/getPieCoordinates.js +3 -3
- package/ResponsiveChartContainer/ResponsiveChartContainer.js +8 -20
- package/ResponsiveChartContainer/useChartContainerDimensions.d.ts +5 -1
- package/ResponsiveChartContainer/useChartContainerDimensions.js +8 -4
- package/ResponsiveChartContainer/useResponsiveChartContainerProps.d.ts +20 -0
- package/ResponsiveChartContainer/useResponsiveChartContainerProps.js +73 -0
- package/ScatterChart/Scatter.js +6 -9
- package/ScatterChart/ScatterChart.js +4 -1
- package/ScatterChart/ScatterPlot.js +6 -3
- package/ScatterChart/extremums.js +8 -2
- package/ScatterChart/useScatterChartProps.js +35 -30
- package/SparkLineChart/SparkLineChart.js +27 -22
- package/context/CartesianProvider/CartesianContext.d.ts +1 -1
- package/context/CartesianProvider/CartesianProvider.d.ts +2 -3
- package/context/CartesianProvider/CartesianProvider.js +18 -7
- package/context/CartesianProvider/computeValue.d.ts +32 -9
- package/context/CartesianProvider/computeValue.js +20 -16
- package/context/CartesianProvider/defaultizeAxis.d.ts +36 -0
- package/context/CartesianProvider/defaultizeAxis.js +21 -0
- package/context/CartesianProvider/index.d.ts +0 -1
- package/context/CartesianProvider/index.js +1 -3
- package/context/CartesianProvider/normalizeAxis.d.ts +1 -1
- package/context/CartesianProvider/normalizeAxis.js +2 -2
- package/context/DrawingProvider.d.ts +12 -0
- package/context/DrawingProvider.js +15 -2
- package/context/HighlightedProvider/HighlightedProvider.js +2 -2
- package/context/SeriesContextProvider.js +1 -1
- package/context/ZAxisContextProvider.d.ts +1 -1
- package/context/ZAxisContextProvider.js +1 -1
- package/esm/BarChart/BarChart.js +2 -2
- package/esm/BarChart/BarPlot.js +8 -8
- package/esm/BarChart/checkScaleErrors.js +11 -11
- package/esm/BarChart/extremums.js +4 -1
- package/esm/BarChart/formatter.js +2 -2
- package/esm/BarChart/useBarChartProps.js +38 -33
- package/esm/ChartContainer/ChartContainer.js +25 -66
- package/esm/ChartContainer/useChartContainerHooks.js +2 -2
- package/esm/ChartContainer/useChartContainerProps.js +87 -0
- package/esm/ChartContainer/useDefaultizeAxis.js +19 -0
- package/esm/ChartsAxis/ChartsAxis.js +4 -4
- package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +1 -1
- package/esm/ChartsLegend/ContinuousColorLegend.js +390 -0
- package/esm/ChartsLegend/DefaultChartsLegend.js +14 -198
- package/esm/ChartsLegend/LegendPerItem.js +141 -0
- package/esm/ChartsLegend/PiecewiseColorLegend.js +161 -0
- package/esm/ChartsLegend/chartsLegend.types.js +1 -0
- package/esm/ChartsLegend/index.js +2 -0
- package/esm/ChartsLegend/legend.types.js +1 -0
- package/esm/ChartsLegend/legendItemsPlacement.js +72 -0
- package/esm/ChartsLegend/useAxis.js +39 -0
- package/esm/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +3 -1
- package/esm/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +2 -3
- package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +2 -3
- package/esm/ChartsSurface.js +3 -1
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +7 -3
- package/esm/ChartsTooltip/ChartsItemTooltipContent.js +4 -4
- package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +30 -20
- package/esm/ChartsXAxis/ChartsXAxis.js +1 -1
- package/esm/ChartsYAxis/ChartsYAxis.js +15 -3
- package/esm/Gauge/Gauge.js +8 -5
- package/esm/Gauge/GaugeContainer.js +8 -4
- package/esm/Gauge/GaugeProvider.js +1 -1
- package/esm/LineChart/AnimatedArea.js +1 -1
- package/esm/LineChart/AnimatedLine.js +1 -1
- package/esm/LineChart/AreaPlot.js +10 -6
- package/esm/LineChart/LineChart.js +5 -2
- package/esm/LineChart/LineHighlightPlot.js +17 -5
- package/esm/LineChart/LinePlot.js +10 -6
- package/esm/LineChart/MarkElement.js +1 -1
- package/esm/LineChart/MarkPlot.js +12 -24
- package/esm/LineChart/extremums.js +4 -1
- package/esm/LineChart/formatter.js +2 -2
- package/esm/LineChart/useLineChartProps.js +38 -33
- package/esm/PieChart/PieArc.js +1 -0
- package/esm/PieChart/PieChart.js +39 -33
- package/esm/PieChart/PiePlot.js +1 -1
- package/esm/PieChart/getPieCoordinates.js +1 -1
- package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +8 -20
- package/esm/ResponsiveChartContainer/useChartContainerDimensions.js +8 -4
- package/esm/ResponsiveChartContainer/useResponsiveChartContainerProps.js +65 -0
- package/esm/ScatterChart/Scatter.js +6 -9
- package/esm/ScatterChart/ScatterChart.js +4 -1
- package/esm/ScatterChart/ScatterPlot.js +6 -3
- package/esm/ScatterChart/extremums.js +8 -2
- package/esm/ScatterChart/useScatterChartProps.js +35 -30
- package/esm/SparkLineChart/SparkLineChart.js +27 -22
- package/esm/context/CartesianProvider/CartesianProvider.js +18 -7
- package/esm/context/CartesianProvider/computeValue.js +20 -16
- package/esm/context/CartesianProvider/defaultizeAxis.js +13 -0
- package/esm/context/CartesianProvider/index.js +1 -3
- package/esm/context/CartesianProvider/normalizeAxis.js +2 -2
- package/esm/context/DrawingProvider.js +15 -2
- package/esm/context/HighlightedProvider/HighlightedProvider.js +2 -2
- package/esm/context/SeriesContextProvider.js +1 -1
- package/esm/context/ZAxisContextProvider.js +1 -1
- package/esm/hooks/useAxisEvents.js +14 -17
- package/esm/hooks/useDrawingArea.js +5 -3
- package/esm/hooks/useReducedMotion.js +4 -2
- package/esm/internals/SlotComponentPropsFromProps.js +1 -0
- package/esm/internals/cleanId.js +6 -0
- package/esm/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +3 -2
- package/esm/internals/geometry.js +1 -1
- package/esm/internals/{utils.js → getPercentageValue.js} +1 -13
- package/esm/internals/getSymbol.js +5 -0
- package/esm/internals/index.js +3 -1
- package/esm/internals/isDefined.js +3 -0
- package/esm/internals/notNull.js +3 -0
- package/esm/internals/ts-generic.js +1 -0
- package/esm/internals/warning.js +19 -11
- package/hooks/useAxisEvents.js +14 -17
- package/hooks/useDrawingArea.js +5 -3
- package/hooks/useReducedMotion.js +4 -2
- package/index.js +1 -1
- package/internals/SlotComponentPropsFromProps.d.ts +1 -0
- package/internals/SlotComponentPropsFromProps.js +5 -0
- package/internals/cleanId.d.ts +4 -0
- package/internals/cleanId.js +12 -0
- package/internals/components/ChartsAxesGradients/ChartsContinuousGradient.d.ts +6 -0
- package/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +3 -2
- package/internals/defaultizeColor.d.ts +7 -0
- package/internals/geometry.js +1 -1
- package/internals/getPercentageValue.d.ts +7 -0
- package/internals/{utils.js → getPercentageValue.js} +1 -15
- package/internals/getSymbol.d.ts +2 -0
- package/internals/getSymbol.js +11 -0
- package/internals/index.d.ts +3 -1
- package/internals/index.js +25 -5
- package/internals/isDefined.d.ts +1 -0
- package/internals/isDefined.js +9 -0
- package/internals/notNull.d.ts +1 -0
- package/internals/notNull.js +9 -0
- package/internals/ts-generic.d.ts +5 -0
- package/internals/ts-generic.js +5 -0
- package/internals/warning.d.ts +2 -1
- package/internals/warning.js +21 -12
- package/models/axis.d.ts +5 -2
- package/models/helpers.d.ts +1 -0
- package/models/seriesType/common.d.ts +10 -0
- package/models/seriesType/config.d.ts +2 -16
- package/models/seriesType/scatter.d.ts +5 -0
- package/modern/BarChart/BarChart.js +2 -2
- package/modern/BarChart/BarPlot.js +8 -8
- package/modern/BarChart/checkScaleErrors.js +11 -11
- package/modern/BarChart/extremums.js +4 -1
- package/modern/BarChart/formatter.js +2 -2
- package/modern/BarChart/useBarChartProps.js +38 -33
- package/modern/ChartContainer/ChartContainer.js +25 -66
- package/modern/ChartContainer/useChartContainerHooks.js +2 -2
- package/modern/ChartContainer/useChartContainerProps.js +87 -0
- package/modern/ChartContainer/useDefaultizeAxis.js +19 -0
- package/modern/ChartsAxis/ChartsAxis.js +4 -4
- package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +1 -1
- package/modern/ChartsLegend/ContinuousColorLegend.js +390 -0
- package/modern/ChartsLegend/DefaultChartsLegend.js +14 -198
- package/modern/ChartsLegend/LegendPerItem.js +141 -0
- package/modern/ChartsLegend/PiecewiseColorLegend.js +161 -0
- package/modern/ChartsLegend/chartsLegend.types.js +1 -0
- package/modern/ChartsLegend/index.js +2 -0
- package/modern/ChartsLegend/legend.types.js +1 -0
- package/modern/ChartsLegend/legendItemsPlacement.js +72 -0
- package/modern/ChartsLegend/useAxis.js +39 -0
- package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +3 -1
- package/modern/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +2 -3
- package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +2 -3
- package/modern/ChartsSurface.js +3 -1
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +7 -3
- package/modern/ChartsTooltip/ChartsItemTooltipContent.js +4 -4
- package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +30 -20
- package/modern/ChartsXAxis/ChartsXAxis.js +1 -1
- package/modern/ChartsYAxis/ChartsYAxis.js +15 -3
- package/modern/Gauge/Gauge.js +8 -5
- package/modern/Gauge/GaugeContainer.js +8 -4
- package/modern/Gauge/GaugeProvider.js +1 -1
- package/modern/LineChart/AnimatedArea.js +1 -1
- package/modern/LineChart/AnimatedLine.js +1 -1
- package/modern/LineChart/AreaPlot.js +10 -6
- package/modern/LineChart/LineChart.js +5 -2
- package/modern/LineChart/LineHighlightPlot.js +17 -5
- package/modern/LineChart/LinePlot.js +10 -6
- package/modern/LineChart/MarkElement.js +1 -1
- package/modern/LineChart/MarkPlot.js +12 -24
- package/modern/LineChart/extremums.js +4 -1
- package/modern/LineChart/formatter.js +2 -2
- package/modern/LineChart/useLineChartProps.js +38 -33
- package/modern/PieChart/PieArc.js +1 -0
- package/modern/PieChart/PieChart.js +39 -33
- package/modern/PieChart/PiePlot.js +1 -1
- package/modern/PieChart/getPieCoordinates.js +1 -1
- package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +8 -20
- package/modern/ResponsiveChartContainer/useChartContainerDimensions.js +8 -4
- package/modern/ResponsiveChartContainer/useResponsiveChartContainerProps.js +65 -0
- package/modern/ScatterChart/Scatter.js +6 -9
- package/modern/ScatterChart/ScatterChart.js +4 -1
- package/modern/ScatterChart/ScatterPlot.js +6 -3
- package/modern/ScatterChart/extremums.js +8 -2
- package/modern/ScatterChart/useScatterChartProps.js +35 -30
- package/modern/SparkLineChart/SparkLineChart.js +27 -22
- package/modern/context/CartesianProvider/CartesianProvider.js +18 -7
- package/modern/context/CartesianProvider/computeValue.js +20 -16
- package/modern/context/CartesianProvider/defaultizeAxis.js +13 -0
- package/modern/context/CartesianProvider/index.js +1 -3
- package/modern/context/CartesianProvider/normalizeAxis.js +2 -2
- package/modern/context/DrawingProvider.js +15 -2
- package/modern/context/HighlightedProvider/HighlightedProvider.js +2 -2
- package/modern/context/SeriesContextProvider.js +1 -1
- package/modern/context/ZAxisContextProvider.js +1 -1
- package/modern/hooks/useAxisEvents.js +14 -17
- package/modern/hooks/useDrawingArea.js +5 -3
- package/modern/hooks/useReducedMotion.js +4 -2
- package/modern/index.js +1 -1
- package/modern/internals/SlotComponentPropsFromProps.js +1 -0
- package/modern/internals/cleanId.js +6 -0
- package/modern/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +3 -2
- package/modern/internals/geometry.js +1 -1
- package/modern/internals/{utils.js → getPercentageValue.js} +1 -13
- package/modern/internals/getSymbol.js +5 -0
- package/modern/internals/index.js +3 -1
- package/modern/internals/isDefined.js +3 -0
- package/modern/internals/notNull.js +3 -0
- package/modern/internals/ts-generic.js +1 -0
- package/modern/internals/warning.js +19 -11
- package/package.json +4 -4
- package/internals/utils.d.ts +0 -18
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.ContinuousColorLegend = ContinuousColorLegend;
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
var React = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
var _styles = require("@mui/material/styles");
|
|
12
|
+
var _ChartsContinuousGradient = _interopRequireDefault(require("../internals/components/ChartsAxesGradients/ChartsContinuousGradient"));
|
|
13
|
+
var _hooks = require("../hooks");
|
|
14
|
+
var _getScale = require("../internals/getScale");
|
|
15
|
+
var _getPercentageValue = require("../internals/getPercentageValue");
|
|
16
|
+
var _ChartsText = require("../ChartsText");
|
|
17
|
+
var _domUtils = require("../internals/domUtils");
|
|
18
|
+
var _useAxis = require("./useAxis");
|
|
19
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
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
|
+
function getPositionOffset(position, legendBox, svgBox) {
|
|
23
|
+
let offsetX = 0;
|
|
24
|
+
let offsetY = 0;
|
|
25
|
+
switch (position.horizontal) {
|
|
26
|
+
case 'left':
|
|
27
|
+
offsetX = 0;
|
|
28
|
+
break;
|
|
29
|
+
case 'middle':
|
|
30
|
+
offsetX = (svgBox.width - legendBox.width) / 2;
|
|
31
|
+
break;
|
|
32
|
+
case 'right':
|
|
33
|
+
default:
|
|
34
|
+
offsetX = svgBox.width - legendBox.width;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
switch (position.vertical) {
|
|
38
|
+
case 'top':
|
|
39
|
+
offsetY = 0;
|
|
40
|
+
break;
|
|
41
|
+
case 'middle':
|
|
42
|
+
offsetY = (svgBox.height - legendBox.height) / 2;
|
|
43
|
+
break;
|
|
44
|
+
case 'bottom':
|
|
45
|
+
default:
|
|
46
|
+
offsetY = svgBox.height - legendBox.height;
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
offsetX,
|
|
51
|
+
offsetY
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Takes placement parameters and element bounding boxes.
|
|
57
|
+
* Returns the x, y coordinates of the elements. And the textAnchor, dominantBaseline for texts.
|
|
58
|
+
*/
|
|
59
|
+
function getElementPositions(text1Box, barBox, text2Box, params) {
|
|
60
|
+
if (params.direction === 'column') {
|
|
61
|
+
const text1 = {
|
|
62
|
+
y: text1Box.height,
|
|
63
|
+
dominantBaseline: 'auto'
|
|
64
|
+
};
|
|
65
|
+
const text2 = {
|
|
66
|
+
y: text1Box.height + 2 * params.spacing + barBox.height,
|
|
67
|
+
dominantBaseline: 'hanging'
|
|
68
|
+
};
|
|
69
|
+
const bar = {
|
|
70
|
+
y: text1Box.height + params.spacing
|
|
71
|
+
};
|
|
72
|
+
const totalWidth = Math.max(text1Box.width, barBox.width, text2Box.width);
|
|
73
|
+
const totalHeight = text1Box.height + barBox.height + text2Box.height + 2 * params.spacing;
|
|
74
|
+
const boundingBox = {
|
|
75
|
+
width: totalWidth,
|
|
76
|
+
height: totalHeight
|
|
77
|
+
};
|
|
78
|
+
switch (params.align) {
|
|
79
|
+
case 'start':
|
|
80
|
+
return {
|
|
81
|
+
text1: (0, _extends2.default)({}, text1, {
|
|
82
|
+
textAnchor: 'start',
|
|
83
|
+
x: 0
|
|
84
|
+
}),
|
|
85
|
+
text2: (0, _extends2.default)({}, text2, {
|
|
86
|
+
textAnchor: 'start',
|
|
87
|
+
x: 0
|
|
88
|
+
}),
|
|
89
|
+
bar: (0, _extends2.default)({}, bar, {
|
|
90
|
+
x: 0
|
|
91
|
+
}),
|
|
92
|
+
boundingBox
|
|
93
|
+
};
|
|
94
|
+
case 'end':
|
|
95
|
+
return {
|
|
96
|
+
text1: (0, _extends2.default)({}, text1, {
|
|
97
|
+
textAnchor: 'end',
|
|
98
|
+
x: totalWidth
|
|
99
|
+
}),
|
|
100
|
+
text2: (0, _extends2.default)({}, text2, {
|
|
101
|
+
textAnchor: 'end',
|
|
102
|
+
x: totalWidth
|
|
103
|
+
}),
|
|
104
|
+
bar: (0, _extends2.default)({}, bar, {
|
|
105
|
+
x: totalWidth - barBox.width
|
|
106
|
+
}),
|
|
107
|
+
boundingBox
|
|
108
|
+
};
|
|
109
|
+
case 'middle':
|
|
110
|
+
default:
|
|
111
|
+
return {
|
|
112
|
+
text1: (0, _extends2.default)({}, text1, {
|
|
113
|
+
textAnchor: 'middle',
|
|
114
|
+
x: totalWidth / 2
|
|
115
|
+
}),
|
|
116
|
+
text2: (0, _extends2.default)({}, text2, {
|
|
117
|
+
textAnchor: 'middle',
|
|
118
|
+
x: totalWidth / 2
|
|
119
|
+
}),
|
|
120
|
+
bar: (0, _extends2.default)({}, bar, {
|
|
121
|
+
x: totalWidth / 2 - barBox.width / 2
|
|
122
|
+
}),
|
|
123
|
+
boundingBox
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
const text1 = {
|
|
128
|
+
x: text1Box.width,
|
|
129
|
+
textAnchor: 'end'
|
|
130
|
+
};
|
|
131
|
+
const text2 = {
|
|
132
|
+
x: text1Box.width + 2 * params.spacing + barBox.width,
|
|
133
|
+
textAnchor: 'start'
|
|
134
|
+
};
|
|
135
|
+
const bar = {
|
|
136
|
+
x: text1Box.width + params.spacing
|
|
137
|
+
};
|
|
138
|
+
const totalHeight = Math.max(text1Box.height, barBox.height, text2Box.height);
|
|
139
|
+
const totalWidth = text1Box.width + barBox.width + text2Box.width + 2 * params.spacing;
|
|
140
|
+
const boundingBox = {
|
|
141
|
+
width: totalWidth,
|
|
142
|
+
height: totalHeight
|
|
143
|
+
};
|
|
144
|
+
switch (params.align) {
|
|
145
|
+
case 'start':
|
|
146
|
+
return {
|
|
147
|
+
text1: (0, _extends2.default)({}, text1, {
|
|
148
|
+
dominantBaseline: 'hanging',
|
|
149
|
+
y: 0
|
|
150
|
+
}),
|
|
151
|
+
text2: (0, _extends2.default)({}, text2, {
|
|
152
|
+
dominantBaseline: 'hanging',
|
|
153
|
+
y: 0
|
|
154
|
+
}),
|
|
155
|
+
bar: (0, _extends2.default)({}, bar, {
|
|
156
|
+
y: 0
|
|
157
|
+
}),
|
|
158
|
+
boundingBox
|
|
159
|
+
};
|
|
160
|
+
case 'end':
|
|
161
|
+
return {
|
|
162
|
+
text1: (0, _extends2.default)({}, text1, {
|
|
163
|
+
dominantBaseline: 'auto',
|
|
164
|
+
y: totalHeight
|
|
165
|
+
}),
|
|
166
|
+
text2: (0, _extends2.default)({}, text2, {
|
|
167
|
+
dominantBaseline: 'auto',
|
|
168
|
+
y: totalHeight
|
|
169
|
+
}),
|
|
170
|
+
bar: (0, _extends2.default)({}, bar, {
|
|
171
|
+
y: totalHeight - barBox.height
|
|
172
|
+
}),
|
|
173
|
+
boundingBox
|
|
174
|
+
};
|
|
175
|
+
case 'middle':
|
|
176
|
+
default:
|
|
177
|
+
return {
|
|
178
|
+
text1: (0, _extends2.default)({}, text1, {
|
|
179
|
+
dominantBaseline: 'central',
|
|
180
|
+
y: totalHeight / 2
|
|
181
|
+
}),
|
|
182
|
+
text2: (0, _extends2.default)({}, text2, {
|
|
183
|
+
dominantBaseline: 'central',
|
|
184
|
+
y: totalHeight / 2
|
|
185
|
+
}),
|
|
186
|
+
bar: (0, _extends2.default)({}, bar, {
|
|
187
|
+
y: totalHeight / 2 - barBox.height / 2
|
|
188
|
+
}),
|
|
189
|
+
boundingBox
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
const defaultLabelFormatter = ({
|
|
195
|
+
formattedValue
|
|
196
|
+
}) => formattedValue;
|
|
197
|
+
function ContinuousColorLegend(props) {
|
|
198
|
+
const theme = (0, _styles.useTheme)();
|
|
199
|
+
const {
|
|
200
|
+
id: idProp,
|
|
201
|
+
minLabel = defaultLabelFormatter,
|
|
202
|
+
maxLabel = defaultLabelFormatter,
|
|
203
|
+
scaleType = 'linear',
|
|
204
|
+
direction,
|
|
205
|
+
length = '50%',
|
|
206
|
+
thickness = 5,
|
|
207
|
+
spacing = 4,
|
|
208
|
+
align = 'middle',
|
|
209
|
+
labelStyle = theme.typography.subtitle1,
|
|
210
|
+
position,
|
|
211
|
+
axisDirection,
|
|
212
|
+
axisId
|
|
213
|
+
} = props;
|
|
214
|
+
const chartId = (0, _hooks.useChartId)();
|
|
215
|
+
const id = idProp ?? `gradient-legend-${chartId}`;
|
|
216
|
+
const isRTL = theme.direction === 'rtl';
|
|
217
|
+
const axisItem = (0, _useAxis.useAxis)({
|
|
218
|
+
axisDirection,
|
|
219
|
+
axisId
|
|
220
|
+
});
|
|
221
|
+
const {
|
|
222
|
+
width,
|
|
223
|
+
height,
|
|
224
|
+
left,
|
|
225
|
+
right,
|
|
226
|
+
top,
|
|
227
|
+
bottom
|
|
228
|
+
} = (0, _hooks.useDrawingArea)();
|
|
229
|
+
const refLength = direction === 'column' ? height + top + bottom : width + left + right;
|
|
230
|
+
const size = (0, _getPercentageValue.getPercentageValue)(length, refLength);
|
|
231
|
+
const isReversed = direction === 'column';
|
|
232
|
+
const colorMap = axisItem?.colorMap;
|
|
233
|
+
if (!colorMap || !colorMap.type || colorMap.type !== 'continuous') {
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Define the coordinate to color mapping
|
|
238
|
+
|
|
239
|
+
const colorScale = axisItem.colorScale;
|
|
240
|
+
const minValue = colorMap.min ?? 0;
|
|
241
|
+
const maxValue = colorMap.max ?? 100;
|
|
242
|
+
const scale = (0, _getScale.getScale)(scaleType, [minValue, maxValue], isReversed ? [size, 0] : [0, size]);
|
|
243
|
+
|
|
244
|
+
// Get texts to display
|
|
245
|
+
|
|
246
|
+
const formattedMin = axisItem.valueFormatter?.(minValue, {
|
|
247
|
+
location: 'legend'
|
|
248
|
+
}) ?? minValue.toLocaleString();
|
|
249
|
+
const formattedMax = axisItem.valueFormatter?.(maxValue, {
|
|
250
|
+
location: 'legend'
|
|
251
|
+
}) ?? maxValue.toLocaleString();
|
|
252
|
+
const minText = typeof minLabel === 'string' ? minLabel : minLabel({
|
|
253
|
+
value: minValue ?? 0,
|
|
254
|
+
formattedValue: formattedMin
|
|
255
|
+
});
|
|
256
|
+
const maxText = typeof maxLabel === 'string' ? maxLabel : maxLabel({
|
|
257
|
+
value: maxValue ?? 0,
|
|
258
|
+
formattedValue: formattedMax
|
|
259
|
+
});
|
|
260
|
+
const text1 = isReversed ? maxText : minText;
|
|
261
|
+
const text2 = isReversed ? minText : maxText;
|
|
262
|
+
const text1Box = (0, _domUtils.getStringSize)(text1, (0, _extends2.default)({}, labelStyle));
|
|
263
|
+
const text2Box = (0, _domUtils.getStringSize)(text2, (0, _extends2.default)({}, labelStyle));
|
|
264
|
+
|
|
265
|
+
// Place bar and texts
|
|
266
|
+
|
|
267
|
+
const barBox = direction === 'column' || isRTL && direction === 'row' ? {
|
|
268
|
+
width: thickness,
|
|
269
|
+
height: size
|
|
270
|
+
} : {
|
|
271
|
+
width: size,
|
|
272
|
+
height: thickness
|
|
273
|
+
};
|
|
274
|
+
const legendPositions = getElementPositions(text1Box, barBox, text2Box, {
|
|
275
|
+
spacing,
|
|
276
|
+
align,
|
|
277
|
+
direction
|
|
278
|
+
});
|
|
279
|
+
const svgBoundingBox = {
|
|
280
|
+
width: width + left + right,
|
|
281
|
+
height: height + top + bottom
|
|
282
|
+
};
|
|
283
|
+
const positionOffset = getPositionOffset((0, _extends2.default)({
|
|
284
|
+
horizontal: 'middle',
|
|
285
|
+
vertical: 'top'
|
|
286
|
+
}, position), legendPositions.boundingBox, svgBoundingBox);
|
|
287
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(React.Fragment, {
|
|
288
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsContinuousGradient.default, {
|
|
289
|
+
isReversed: isReversed,
|
|
290
|
+
gradientId: id,
|
|
291
|
+
size: size,
|
|
292
|
+
direction: direction === 'row' ? 'x' : 'y',
|
|
293
|
+
scale: scale,
|
|
294
|
+
colorScale: colorScale,
|
|
295
|
+
colorMap: colorMap,
|
|
296
|
+
gradientUnits: "objectBoundingBox"
|
|
297
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsText.ChartsText, {
|
|
298
|
+
text: text1,
|
|
299
|
+
x: positionOffset.offsetX + legendPositions.text1.x,
|
|
300
|
+
y: positionOffset.offsetY + legendPositions.text1.y,
|
|
301
|
+
style: (0, _extends2.default)({
|
|
302
|
+
dominantBaseline: legendPositions.text1.dominantBaseline,
|
|
303
|
+
textAnchor: legendPositions.text1.textAnchor
|
|
304
|
+
}, labelStyle)
|
|
305
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("rect", (0, _extends2.default)({
|
|
306
|
+
x: positionOffset.offsetX + legendPositions.bar.x,
|
|
307
|
+
y: positionOffset.offsetY + legendPositions.bar.y
|
|
308
|
+
}, barBox, {
|
|
309
|
+
fill: `url(#${id})`
|
|
310
|
+
})), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsText.ChartsText, {
|
|
311
|
+
text: text2,
|
|
312
|
+
x: positionOffset.offsetX + legendPositions.text2.x,
|
|
313
|
+
y: positionOffset.offsetY + legendPositions.text2.y,
|
|
314
|
+
style: (0, _extends2.default)({
|
|
315
|
+
dominantBaseline: legendPositions.text2.dominantBaseline,
|
|
316
|
+
textAnchor: legendPositions.text2.textAnchor
|
|
317
|
+
}, labelStyle)
|
|
318
|
+
})]
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
process.env.NODE_ENV !== "production" ? ContinuousColorLegend.propTypes = {
|
|
322
|
+
// ----------------------------- Warning --------------------------------
|
|
323
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
324
|
+
// | To update them edit the TypeScript types and run "pnpm proptypes" |
|
|
325
|
+
// ----------------------------------------------------------------------
|
|
326
|
+
/**
|
|
327
|
+
* The alignment of the texts with the gradient bar.
|
|
328
|
+
* @default 'middle'
|
|
329
|
+
*/
|
|
330
|
+
align: _propTypes.default.oneOf(['end', 'middle', 'start']),
|
|
331
|
+
/**
|
|
332
|
+
* The axis direction containing the color configuration to represent.
|
|
333
|
+
* @default 'z'
|
|
334
|
+
*/
|
|
335
|
+
axisDirection: _propTypes.default.oneOf(['x', 'y', 'z']),
|
|
336
|
+
/**
|
|
337
|
+
* The id of the axis item with the color configuration to represent.
|
|
338
|
+
* @default The first axis item.
|
|
339
|
+
*/
|
|
340
|
+
axisId: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
|
|
341
|
+
/**
|
|
342
|
+
* The direction of the legend layout.
|
|
343
|
+
* The default depends on the chart.
|
|
344
|
+
*/
|
|
345
|
+
direction: _propTypes.default.oneOf(['column', 'row']),
|
|
346
|
+
/**
|
|
347
|
+
* A unique identifier for the gradient.
|
|
348
|
+
* @default auto-generated id
|
|
349
|
+
*/
|
|
350
|
+
id: _propTypes.default.string,
|
|
351
|
+
/**
|
|
352
|
+
* The style applied to labels.
|
|
353
|
+
* @default theme.typography.subtitle1
|
|
354
|
+
*/
|
|
355
|
+
labelStyle: _propTypes.default.object,
|
|
356
|
+
/**
|
|
357
|
+
* The length of the gradient bar.
|
|
358
|
+
* Can be a number (in px) or a string with a percentage such as '50%'.
|
|
359
|
+
* The '100%' is the length of the svg.
|
|
360
|
+
* @default '50%'
|
|
361
|
+
*/
|
|
362
|
+
length: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
|
|
363
|
+
/**
|
|
364
|
+
* The label to display at the maximum side of the gradient.
|
|
365
|
+
* Can either be a string, or a function.
|
|
366
|
+
* If not defined, the formatted maximal value is display.
|
|
367
|
+
* @default ({ formattedValue }) => formattedValue
|
|
368
|
+
*/
|
|
369
|
+
maxLabel: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.string]),
|
|
370
|
+
/**
|
|
371
|
+
* The label to display at the minimum side of the gradient.
|
|
372
|
+
* Can either be a string, or a function.
|
|
373
|
+
* @default ({ formattedValue }) => formattedValue
|
|
374
|
+
*/
|
|
375
|
+
minLabel: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.string]),
|
|
376
|
+
/**
|
|
377
|
+
* The position of the legend.
|
|
378
|
+
*/
|
|
379
|
+
position: _propTypes.default.shape({
|
|
380
|
+
horizontal: _propTypes.default.oneOf(['left', 'middle', 'right']).isRequired,
|
|
381
|
+
vertical: _propTypes.default.oneOf(['bottom', 'middle', 'top']).isRequired
|
|
382
|
+
}),
|
|
383
|
+
/**
|
|
384
|
+
* The scale used to display gradient colors.
|
|
385
|
+
* @default 'linear'
|
|
386
|
+
*/
|
|
387
|
+
scaleType: _propTypes.default.oneOf(['linear', 'log', 'pow', 'sqrt', 'time', 'utc']),
|
|
388
|
+
/**
|
|
389
|
+
* The space between the gradient bar and the labels.
|
|
390
|
+
* @default 4
|
|
391
|
+
*/
|
|
392
|
+
spacing: _propTypes.default.number,
|
|
393
|
+
/**
|
|
394
|
+
* The thickness of the gradient bar.
|
|
395
|
+
* @default 5
|
|
396
|
+
*/
|
|
397
|
+
thickness: _propTypes.default.number
|
|
398
|
+
} : void 0;
|
|
@@ -1,59 +1,16 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { DrawingArea } from '../context/DrawingProvider';
|
|
3
|
-
import { AnchorPosition, Direction } from './utils';
|
|
4
2
|
import { FormattedSeries } from '../context/SeriesContextProvider';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import { CardinalDirections } from '../models/layout';
|
|
9
|
-
import type { ChartsLegendProps } from './ChartsLegend';
|
|
10
|
-
export type ChartsLegendRootOwnerState = {
|
|
11
|
-
position: AnchorPosition;
|
|
12
|
-
direction: Direction;
|
|
13
|
-
drawingArea: DrawingArea;
|
|
14
|
-
offsetX?: number;
|
|
15
|
-
offsetY?: number;
|
|
16
|
-
seriesNumber: number;
|
|
17
|
-
};
|
|
18
|
-
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>>, {}>;
|
|
19
|
-
export interface LegendRendererProps extends DefaultizedProps<Omit<ChartsLegendProps, 'slots' | 'slotProps'>, 'direction' | 'position'> {
|
|
3
|
+
import { LegendPerItemProps } from './LegendPerItem';
|
|
4
|
+
import { DrawingArea } from '../context/DrawingProvider';
|
|
5
|
+
export interface LegendRendererProps extends Omit<LegendPerItemProps, 'itemsToDisplay'> {
|
|
20
6
|
series: FormattedSeries;
|
|
21
|
-
seriesToDisplay:
|
|
22
|
-
drawingArea: DrawingArea;
|
|
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;
|
|
7
|
+
seriesToDisplay: LegendPerItemProps['itemsToDisplay'];
|
|
49
8
|
/**
|
|
50
|
-
*
|
|
51
|
-
* Can either be a single number, or an object with top, left, bottom, right properties.
|
|
52
|
-
* @default 10
|
|
9
|
+
* @deprecated Use the `useDrawingArea` hook instead.
|
|
53
10
|
*/
|
|
54
|
-
|
|
11
|
+
drawingArea: Omit<DrawingArea, 'isPointInside'>;
|
|
55
12
|
}
|
|
56
|
-
declare function DefaultChartsLegend(props: LegendRendererProps): React.JSX.Element
|
|
13
|
+
declare function DefaultChartsLegend(props: LegendRendererProps): React.JSX.Element;
|
|
57
14
|
declare namespace DefaultChartsLegend {
|
|
58
15
|
var propTypes: any;
|
|
59
16
|
}
|