@mui/x-charts 6.0.0-alpha.14 → 6.0.0-alpha.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BarChart/BarChart.d.ts +16 -2
- package/BarChart/BarChart.js +49 -11
- package/BarChart/BarElement.d.ts +1318 -3
- package/BarChart/BarElement.js +10 -8
- package/BarChart/BarPlot.d.ts +17 -1
- package/BarChart/BarPlot.js +152 -66
- package/CHANGELOG.md +169 -0
- package/ChartContainer/index.js +5 -2
- package/ChartsAxis/ChartsAxis.js +18 -2
- package/ChartsAxis/axisClasses.d.ts +1 -1
- package/ChartsAxisHighlight/ChartsAxisHighlight.js +2 -2
- package/ChartsClipPath/ChartsClipPath.js +2 -2
- package/ChartsLegend/ChartsLegend.d.ts +44 -24
- package/ChartsLegend/ChartsLegend.js +191 -145
- package/ChartsLegend/utils.d.ts +1 -6
- package/ChartsSurface.js +5 -13
- package/ChartsTooltip/ChartsAxisTooltipContent.js +2 -2
- package/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
- package/ChartsTooltip/ChartsTooltip.js +2 -2
- package/ChartsTooltip/utils.js +2 -2
- package/ChartsXAxis/ChartsXAxis.js +151 -40
- package/ChartsYAxis/ChartsYAxis.js +76 -33
- package/LineChart/AreaElement.d.ts +10 -0
- package/LineChart/AreaElement.js +12 -2
- package/LineChart/AreaPlot.d.ts +11 -0
- package/LineChart/AreaPlot.js +13 -2
- package/LineChart/LineChart.d.ts +13 -0
- package/LineChart/LineChart.js +40 -10
- package/LineChart/LineElement.d.ts +10 -0
- package/LineChart/LineElement.js +12 -2
- package/LineChart/LineHighlightElement.d.ts +10 -0
- package/LineChart/LineHighlightElement.js +12 -2
- package/LineChart/LineHighlightPlot.d.ts +10 -0
- package/LineChart/LineHighlightPlot.js +12 -2
- package/LineChart/LinePlot.d.ts +10 -0
- package/LineChart/LinePlot.js +12 -2
- package/LineChart/MarkElement.d.ts +10 -0
- package/LineChart/MarkElement.js +12 -2
- package/LineChart/MarkPlot.d.ts +10 -0
- package/LineChart/MarkPlot.js +12 -2
- package/PieChart/PieArc.js +2 -2
- package/PieChart/PieArcLabel.js +2 -2
- package/PieChart/PieChart.d.ts +13 -0
- package/PieChart/PieChart.js +41 -10
- package/PieChart/PiePlot.d.ts +10 -0
- package/PieChart/PiePlot.js +12 -2
- package/ResponsiveChartContainer/index.js +4 -4
- package/ScatterChart/Scatter.d.ts +10 -0
- package/ScatterChart/Scatter.js +12 -2
- package/ScatterChart/ScatterChart.d.ts +13 -0
- package/ScatterChart/ScatterChart.js +40 -10
- package/ScatterChart/ScatterPlot.d.ts +10 -0
- package/ScatterChart/ScatterPlot.js +12 -2
- package/SparkLineChart/SparkLineChart.d.ts +9 -0
- package/SparkLineChart/SparkLineChart.js +16 -2
- package/constants.js +1 -1
- package/context/CartesianContextProvider.js +20 -12
- package/context/DrawingProvider.d.ts +2 -0
- package/context/DrawingProvider.js +4 -2
- package/context/HighlightProvider.js +2 -2
- package/context/InteractionProvider.js +2 -2
- package/context/SeriesContextProvider.js +2 -2
- package/esm/BarChart/BarChart.js +47 -9
- package/esm/BarChart/BarElement.js +7 -4
- package/esm/BarChart/BarPlot.js +152 -67
- package/esm/ChartContainer/index.js +3 -0
- package/esm/ChartsAxis/ChartsAxis.js +16 -0
- package/esm/ChartsLegend/ChartsLegend.js +188 -142
- package/esm/ChartsSurface.js +3 -11
- package/esm/ChartsXAxis/ChartsXAxis.js +148 -37
- package/esm/ChartsYAxis/ChartsYAxis.js +73 -30
- package/esm/LineChart/AreaElement.js +10 -0
- package/esm/LineChart/AreaPlot.js +11 -0
- package/esm/LineChart/LineChart.js +38 -8
- package/esm/LineChart/LineElement.js +10 -0
- package/esm/LineChart/LineHighlightElement.js +10 -0
- package/esm/LineChart/LineHighlightPlot.js +10 -0
- package/esm/LineChart/LinePlot.js +10 -0
- package/esm/LineChart/MarkElement.js +10 -0
- package/esm/LineChart/MarkPlot.js +10 -0
- package/esm/PieChart/PieChart.js +39 -8
- package/esm/PieChart/PiePlot.js +10 -0
- package/esm/ResponsiveChartContainer/index.js +2 -2
- package/esm/ScatterChart/Scatter.js +10 -0
- package/esm/ScatterChart/ScatterChart.js +38 -8
- package/esm/ScatterChart/ScatterPlot.js +10 -0
- package/esm/SparkLineChart/SparkLineChart.js +14 -0
- package/esm/constants.js +1 -1
- package/esm/context/CartesianContextProvider.js +19 -11
- package/esm/context/DrawingProvider.js +2 -0
- package/esm/hooks/useChartDimensions.js +2 -0
- package/esm/hooks/useMounted.js +16 -0
- package/esm/hooks/useReducedMotion.js +27 -0
- package/esm/hooks/useTicks.js +15 -9
- package/esm/internals/components/AxisSharedComponents.js +15 -70
- package/esm/internals/components/ChartsText.js +75 -0
- package/esm/internals/domUtils.js +113 -0
- package/esm/internals/geometry.js +36 -0
- package/hooks/useAxisEvents.js +2 -2
- package/hooks/useChartDimensions.d.ts +2 -0
- package/hooks/useChartDimensions.js +4 -2
- package/hooks/useDrawingArea.js +2 -2
- package/hooks/useInteractionItemProps.js +2 -2
- package/hooks/useMounted.d.ts +1 -0
- package/hooks/useMounted.js +25 -0
- package/hooks/useReducedMotion.d.ts +8 -0
- package/hooks/useReducedMotion.js +33 -0
- package/hooks/useScale.d.ts +2 -2
- package/hooks/useScale.js +2 -2
- package/hooks/useTicks.d.ts +19 -11
- package/hooks/useTicks.js +18 -12
- package/index.js +1 -1
- package/internals/components/AxisSharedComponents.d.ts +0 -4
- package/internals/components/AxisSharedComponents.js +16 -71
- package/internals/components/ChartsText.d.ts +35 -0
- package/internals/components/ChartsText.js +85 -0
- package/internals/defaultizeColor.d.ts +1 -1
- package/internals/domUtils.d.ts +13 -0
- package/internals/domUtils.js +122 -0
- package/internals/geometry.d.ts +9 -0
- package/internals/geometry.js +42 -0
- package/legacy/BarChart/BarChart.js +47 -9
- package/legacy/BarChart/BarElement.js +6 -3
- package/legacy/BarChart/BarPlot.js +151 -63
- package/legacy/ChartContainer/index.js +3 -0
- package/legacy/ChartsAxis/ChartsAxis.js +16 -0
- package/legacy/ChartsLegend/ChartsLegend.js +203 -140
- package/legacy/ChartsSurface.js +2 -11
- package/legacy/ChartsXAxis/ChartsXAxis.js +152 -39
- package/legacy/ChartsYAxis/ChartsYAxis.js +73 -30
- package/legacy/LineChart/AreaElement.js +10 -0
- package/legacy/LineChart/AreaPlot.js +11 -0
- package/legacy/LineChart/LineChart.js +38 -8
- package/legacy/LineChart/LineElement.js +10 -0
- package/legacy/LineChart/LineHighlightElement.js +10 -0
- package/legacy/LineChart/LineHighlightPlot.js +10 -0
- package/legacy/LineChart/LinePlot.js +10 -0
- package/legacy/LineChart/MarkElement.js +10 -0
- package/legacy/LineChart/MarkPlot.js +10 -0
- package/legacy/PieChart/PieChart.js +39 -8
- package/legacy/PieChart/PiePlot.js +10 -0
- package/legacy/ResponsiveChartContainer/index.js +2 -2
- package/legacy/ScatterChart/Scatter.js +10 -0
- package/legacy/ScatterChart/ScatterChart.js +38 -8
- package/legacy/ScatterChart/ScatterPlot.js +10 -0
- package/legacy/SparkLineChart/SparkLineChart.js +14 -0
- package/legacy/constants.js +1 -1
- package/legacy/context/CartesianContextProvider.js +19 -11
- package/legacy/context/DrawingProvider.js +2 -0
- package/legacy/hooks/useChartDimensions.js +2 -0
- package/legacy/hooks/useMounted.js +21 -0
- package/legacy/hooks/useReducedMotion.js +27 -0
- package/legacy/hooks/useTicks.js +16 -9
- package/legacy/index.js +1 -1
- package/legacy/internals/components/AxisSharedComponents.js +9 -63
- package/legacy/internals/components/ChartsText.js +77 -0
- package/legacy/internals/domUtils.js +121 -0
- package/legacy/internals/geometry.js +37 -0
- package/models/axis.d.ts +25 -7
- package/models/layout.d.ts +7 -6
- package/models/seriesType/line.d.ts +2 -2
- package/modern/BarChart/BarChart.js +47 -9
- package/modern/BarChart/BarElement.js +7 -4
- package/modern/BarChart/BarPlot.js +149 -65
- package/modern/ChartContainer/index.js +3 -0
- package/modern/ChartsAxis/ChartsAxis.js +16 -0
- package/modern/ChartsLegend/ChartsLegend.js +188 -142
- package/modern/ChartsSurface.js +3 -11
- package/modern/ChartsXAxis/ChartsXAxis.js +148 -37
- package/modern/ChartsYAxis/ChartsYAxis.js +73 -30
- package/modern/LineChart/AreaElement.js +10 -0
- package/modern/LineChart/AreaPlot.js +11 -0
- package/modern/LineChart/LineChart.js +38 -8
- package/modern/LineChart/LineElement.js +10 -0
- package/modern/LineChart/LineHighlightElement.js +10 -0
- package/modern/LineChart/LineHighlightPlot.js +10 -0
- package/modern/LineChart/LinePlot.js +10 -0
- package/modern/LineChart/MarkElement.js +10 -0
- package/modern/LineChart/MarkPlot.js +10 -0
- package/modern/PieChart/PieChart.js +39 -8
- package/modern/PieChart/PiePlot.js +10 -0
- package/modern/ResponsiveChartContainer/index.js +2 -2
- package/modern/ScatterChart/Scatter.js +10 -0
- package/modern/ScatterChart/ScatterChart.js +38 -8
- package/modern/ScatterChart/ScatterPlot.js +10 -0
- package/modern/SparkLineChart/SparkLineChart.js +14 -0
- package/modern/constants.js +1 -1
- package/modern/context/CartesianContextProvider.js +19 -11
- package/modern/context/DrawingProvider.js +2 -0
- package/modern/hooks/useChartDimensions.js +2 -0
- package/modern/hooks/useMounted.js +16 -0
- package/modern/hooks/useReducedMotion.js +27 -0
- package/modern/hooks/useTicks.js +15 -9
- package/modern/index.js +1 -1
- package/modern/internals/components/AxisSharedComponents.js +15 -70
- package/modern/internals/components/ChartsText.js +75 -0
- package/modern/internals/domUtils.js +113 -0
- package/modern/internals/geometry.js +36 -0
- package/package.json +5 -3
|
@@ -1,12 +1,18 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
1
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
+
var _excluded = ["rotate", "dominantBaseline"],
|
|
5
|
+
_excluded2 = ["label"];
|
|
2
6
|
import * as React from 'react';
|
|
3
7
|
import { useSlotProps } from '@mui/base/utils';
|
|
8
|
+
import { NoSsr } from '@mui/base/NoSsr';
|
|
4
9
|
import { unstable_composeClasses as composeClasses } from '@mui/utils';
|
|
5
10
|
import { useThemeProps, useTheme, styled } from '@mui/material/styles';
|
|
6
11
|
import { DrawingContext } from '../context/DrawingProvider';
|
|
7
12
|
import { getSeriesToDisplay } from './utils';
|
|
8
13
|
import { SeriesContext } from '../context/SeriesContextProvider';
|
|
9
14
|
import { getChartsLegendUtilityClass } from './chartsLegendClasses';
|
|
15
|
+
import { ChartsText, getWordsByLines } from '../internals/components/ChartsText';
|
|
10
16
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
17
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
18
|
var useUtilityClasses = function useUtilityClasses(ownerState) {
|
|
@@ -20,165 +26,224 @@ var useUtilityClasses = function useUtilityClasses(ownerState) {
|
|
|
20
26
|
};
|
|
21
27
|
return composeClasses(slots, getChartsLegendUtilityClass, classes);
|
|
22
28
|
};
|
|
23
|
-
function getTranslePosition(_ref) {
|
|
24
|
-
var position = _ref.position,
|
|
25
|
-
drawingArea = _ref.drawingArea;
|
|
26
|
-
var xValue;
|
|
27
|
-
switch (position.horizontal) {
|
|
28
|
-
case 'left':
|
|
29
|
-
xValue = "calc(var(--ChartsLegend-rootOffsetX, 0px) + ".concat(drawingArea.left, "px - var(--ChartsLegend-rootWidth))");
|
|
30
|
-
break;
|
|
31
|
-
case 'middle':
|
|
32
|
-
xValue = "calc(var(--ChartsLegend-rootOffsetX, 0px) + ".concat(drawingArea.left + drawingArea.width / 2, "px - 0.5 * var(--ChartsLegend-rootWidth))");
|
|
33
|
-
break;
|
|
34
|
-
default:
|
|
35
|
-
xValue = "calc(var(--ChartsLegend-rootOffsetX, 0px) + ".concat(drawingArea.left + drawingArea.width, "px)");
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
var yValue;
|
|
39
|
-
switch (position.vertical) {
|
|
40
|
-
case 'top':
|
|
41
|
-
yValue = "calc(var(--ChartsLegend-rootOffsetY, 0px) + ".concat(drawingArea.top, "px - var(--ChartsLegend-rootHeight))");
|
|
42
|
-
break;
|
|
43
|
-
case 'middle':
|
|
44
|
-
yValue = "calc(var(--ChartsLegend-rootOffsetY, 0px) + ".concat(drawingArea.top + drawingArea.height / 2, "px - 0.5 * var(--ChartsLegend-rootHeight))");
|
|
45
|
-
break;
|
|
46
|
-
default:
|
|
47
|
-
yValue = "calc(var(--ChartsLegend-rootOffsetY, 0px) + ".concat(drawingArea.top + drawingArea.height, "px)");
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
transform: "translate(".concat(xValue, ", ").concat(yValue, ")")
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
29
|
export var ChartsLegendRoot = styled('g', {
|
|
55
30
|
name: 'MuiChartsLegend',
|
|
56
31
|
slot: 'Root',
|
|
57
32
|
overridesResolver: function overridesResolver(props, styles) {
|
|
58
33
|
return styles.root;
|
|
59
34
|
}
|
|
60
|
-
})(
|
|
61
|
-
var ownerState = _ref2.ownerState;
|
|
62
|
-
var direction = ownerState.direction,
|
|
63
|
-
drawingArea = ownerState.drawingArea,
|
|
64
|
-
offsetX = ownerState.offsetX,
|
|
65
|
-
offsetY = ownerState.offsetY,
|
|
66
|
-
seriesNumber = ownerState.seriesNumber,
|
|
67
|
-
position = ownerState.position;
|
|
68
|
-
return _extends({
|
|
69
|
-
'--ChartsLegend-rootOffsetX': typeof offsetX === 'number' ? "".concat(offsetX, "px") : undefined,
|
|
70
|
-
'--ChartsLegend-rootOffsetY': typeof offsetY === 'number' ? "".concat(offsetY, "px") : undefined,
|
|
71
|
-
'--ChartsLegend-rootWidth': direction === 'row' ? "calc(var(--ChartsLegend-itemWidth) * ".concat(seriesNumber, " + var(--ChartsLegend-rootSpacing) * ").concat(seriesNumber - 1, " )") : 'var(--ChartsLegend-itemWidth)',
|
|
72
|
-
'--ChartsLegend-rootHeight': direction === 'row' ? 'var(--ChartsLegend-itemMarkSize)' : "calc(var(--ChartsLegend-itemMarkSize) * ".concat(seriesNumber, " + var(--ChartsLegend-rootSpacing) * ").concat(seriesNumber - 1, " )")
|
|
73
|
-
}, getTranslePosition({
|
|
74
|
-
position: position,
|
|
75
|
-
drawingArea: drawingArea,
|
|
76
|
-
offsetX: offsetX,
|
|
77
|
-
offsetY: offsetY
|
|
78
|
-
}));
|
|
79
|
-
});
|
|
80
|
-
export var ChartsSeriesLegendGroup = styled('g', {
|
|
81
|
-
name: 'MuiChartsLegend',
|
|
82
|
-
slot: 'ChartsSeriesLegendGroup',
|
|
83
|
-
overridesResolver: function overridesResolver(props, styles) {
|
|
84
|
-
return styles.series;
|
|
85
|
-
}
|
|
86
|
-
})(function (_ref3) {
|
|
87
|
-
var ownerState = _ref3.ownerState;
|
|
88
|
-
var direction = ownerState.direction,
|
|
89
|
-
seriesIndex = ownerState.seriesIndex;
|
|
90
|
-
if (direction === 'row') {
|
|
91
|
-
return {
|
|
92
|
-
transform: "translate(calc(".concat(seriesIndex, " * (var(--ChartsLegend-itemWidth) + var(--ChartsLegend-rootSpacing))), 0)")
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
return {
|
|
96
|
-
transform: "translate(0, calc(".concat(seriesIndex, " * (var(--ChartsLegend-itemMarkSize) + var(--ChartsLegend-rootSpacing))))")
|
|
97
|
-
};
|
|
98
|
-
});
|
|
99
|
-
export var ChartsLegendMark = styled('rect', {
|
|
100
|
-
name: 'MuiChartsLegend',
|
|
101
|
-
slot: 'Mark',
|
|
102
|
-
overridesResolver: function overridesResolver(props, styles) {
|
|
103
|
-
return styles.mark;
|
|
104
|
-
}
|
|
105
|
-
})(function (_ref4) {
|
|
106
|
-
var ownerState = _ref4.ownerState;
|
|
107
|
-
return {
|
|
108
|
-
x: 0,
|
|
109
|
-
y: 0,
|
|
110
|
-
width: 'var(--ChartsLegend-itemMarkSize)',
|
|
111
|
-
height: 'var(--ChartsLegend-itemMarkSize)',
|
|
112
|
-
fill: ownerState.color
|
|
113
|
-
};
|
|
114
|
-
});
|
|
115
|
-
export var ChartsLegendLabel = styled('text', {
|
|
116
|
-
name: 'MuiChartsLegend',
|
|
117
|
-
slot: 'Label',
|
|
118
|
-
overridesResolver: function overridesResolver(props, styles) {
|
|
119
|
-
return styles.label;
|
|
120
|
-
}
|
|
121
|
-
})(function (_ref5) {
|
|
122
|
-
var theme = _ref5.theme;
|
|
123
|
-
return _extends({}, theme.typography.body1, {
|
|
124
|
-
color: 'inherit',
|
|
125
|
-
transform: "translate(\n calc(var(--ChartsLegend-itemMarkSize) + var(--ChartsLegend-labelSpacing)),\n calc(0.5 * var(--ChartsLegend-itemMarkSize))\n )",
|
|
126
|
-
fill: (theme.vars || theme).palette.text.primary,
|
|
127
|
-
dominantBaseline: 'central'
|
|
128
|
-
});
|
|
129
|
-
});
|
|
35
|
+
})({});
|
|
130
36
|
var defaultProps = {
|
|
131
37
|
position: {
|
|
132
38
|
horizontal: 'middle',
|
|
133
39
|
vertical: 'top'
|
|
134
40
|
},
|
|
135
|
-
direction: 'row'
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
41
|
+
direction: 'row'
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Transforms number or partial padding object to a defaultized padding object.
|
|
45
|
+
*/
|
|
46
|
+
var getStandardizedPadding = function getStandardizedPadding(padding) {
|
|
47
|
+
if (typeof padding === 'number') {
|
|
48
|
+
return {
|
|
49
|
+
left: padding,
|
|
50
|
+
right: padding,
|
|
51
|
+
top: padding,
|
|
52
|
+
bottom: padding
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return _extends({
|
|
56
|
+
left: 0,
|
|
57
|
+
right: 0,
|
|
58
|
+
top: 0,
|
|
59
|
+
bottom: 0
|
|
60
|
+
}, padding);
|
|
139
61
|
};
|
|
140
62
|
function DefaultChartsLegend(props) {
|
|
141
63
|
var hidden = props.hidden,
|
|
142
64
|
position = props.position,
|
|
143
65
|
direction = props.direction,
|
|
144
|
-
offset = props.offset,
|
|
145
|
-
series = props.series,
|
|
146
66
|
seriesToDisplay = props.seriesToDisplay,
|
|
147
67
|
drawingArea = props.drawingArea,
|
|
148
|
-
classes = props.classes
|
|
68
|
+
classes = props.classes,
|
|
69
|
+
_props$itemMarkWidth = props.itemMarkWidth,
|
|
70
|
+
itemMarkWidth = _props$itemMarkWidth === void 0 ? 20 : _props$itemMarkWidth,
|
|
71
|
+
_props$itemMarkHeight = props.itemMarkHeight,
|
|
72
|
+
itemMarkHeight = _props$itemMarkHeight === void 0 ? 20 : _props$itemMarkHeight,
|
|
73
|
+
_props$markGap = props.markGap,
|
|
74
|
+
markGap = _props$markGap === void 0 ? 5 : _props$markGap,
|
|
75
|
+
_props$itemGap = props.itemGap,
|
|
76
|
+
itemGap = _props$itemGap === void 0 ? 10 : _props$itemGap,
|
|
77
|
+
_props$padding = props.padding,
|
|
78
|
+
paddingProps = _props$padding === void 0 ? 10 : _props$padding,
|
|
79
|
+
inLabelStyle = props.labelStyle;
|
|
80
|
+
var theme = useTheme();
|
|
81
|
+
var labelStyle = React.useMemo(function () {
|
|
82
|
+
return _extends({}, theme.typography.subtitle1, {
|
|
83
|
+
color: 'inherit',
|
|
84
|
+
dominantBaseline: 'central',
|
|
85
|
+
textAnchor: 'start',
|
|
86
|
+
fill: (theme.vars || theme).palette.text.primary,
|
|
87
|
+
lineHeight: 1
|
|
88
|
+
}, inLabelStyle);
|
|
89
|
+
},
|
|
90
|
+
// To say to TS that the dominantBaseline and textAnchor are correct
|
|
91
|
+
[inLabelStyle, theme]);
|
|
92
|
+
var padding = React.useMemo(function () {
|
|
93
|
+
return getStandardizedPadding(paddingProps);
|
|
94
|
+
}, [paddingProps]);
|
|
95
|
+
var getItemSpace = React.useCallback(function (label) {
|
|
96
|
+
var inStyle = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
97
|
+
var rotate = inStyle.rotate,
|
|
98
|
+
dominantBaseline = inStyle.dominantBaseline,
|
|
99
|
+
style = _objectWithoutProperties(inStyle, _excluded);
|
|
100
|
+
var linesSize = getWordsByLines({
|
|
101
|
+
style: style,
|
|
102
|
+
needsComputation: true,
|
|
103
|
+
text: label
|
|
104
|
+
});
|
|
105
|
+
var innerSize = {
|
|
106
|
+
innerWidth: itemMarkWidth + markGap + Math.max.apply(Math, _toConsumableArray(linesSize.map(function (size) {
|
|
107
|
+
return size.width;
|
|
108
|
+
}))),
|
|
109
|
+
innerHeight: Math.max(itemMarkHeight, linesSize.length * linesSize[0].height)
|
|
110
|
+
};
|
|
111
|
+
return _extends({}, innerSize, {
|
|
112
|
+
outerWidth: innerSize.innerWidth + itemGap,
|
|
113
|
+
outerHeight: innerSize.innerHeight + itemGap
|
|
114
|
+
});
|
|
115
|
+
}, [itemGap, itemMarkHeight, itemMarkWidth, markGap]);
|
|
116
|
+
var totalWidth = drawingArea.left + drawingArea.width + drawingArea.right;
|
|
117
|
+
var totalHeight = drawingArea.top + drawingArea.height + drawingArea.bottom;
|
|
118
|
+
var availableWidth = totalWidth - padding.left - padding.right;
|
|
119
|
+
var availableHeight = totalHeight - padding.top - padding.bottom;
|
|
120
|
+
var seriesWithPosition = React.useMemo(function () {
|
|
121
|
+
// Start at 0, 0. Will be modified later by padding and position.
|
|
122
|
+
var x = 0;
|
|
123
|
+
var y = 0;
|
|
124
|
+
|
|
125
|
+
// total values used to align legend later.
|
|
126
|
+
var totalWidthUsed = 0;
|
|
127
|
+
var totalHeightUsed = 0;
|
|
128
|
+
var rowIndex = 0;
|
|
129
|
+
var rowMaxHeight = [0];
|
|
130
|
+
var seriesWithRawPosition = seriesToDisplay.map(function (_ref) {
|
|
131
|
+
var label = _ref.label,
|
|
132
|
+
other = _objectWithoutProperties(_ref, _excluded2);
|
|
133
|
+
var itemSpace = getItemSpace(label, labelStyle);
|
|
134
|
+
var rep = _extends({}, other, {
|
|
135
|
+
label: label,
|
|
136
|
+
positionX: x,
|
|
137
|
+
positionY: y,
|
|
138
|
+
innerHeight: itemSpace.innerHeight,
|
|
139
|
+
innerWidth: itemSpace.innerWidth,
|
|
140
|
+
outerHeight: itemSpace.outerHeight,
|
|
141
|
+
outerWidth: itemSpace.outerWidth,
|
|
142
|
+
rowIndex: rowIndex
|
|
143
|
+
});
|
|
144
|
+
if (direction === 'row') {
|
|
145
|
+
if (x + itemSpace.innerWidth > availableWidth) {
|
|
146
|
+
// This legend item would create overflow along the x-axis, so we start a new row.
|
|
147
|
+
x = 0;
|
|
148
|
+
y += rowMaxHeight[rowIndex];
|
|
149
|
+
rowIndex += 1;
|
|
150
|
+
if (rowMaxHeight.length <= rowIndex) {
|
|
151
|
+
rowMaxHeight.push(0);
|
|
152
|
+
}
|
|
153
|
+
rep.positionX = x;
|
|
154
|
+
rep.positionY = y;
|
|
155
|
+
rep.rowIndex = rowIndex;
|
|
156
|
+
}
|
|
157
|
+
totalWidthUsed = Math.max(totalWidthUsed, x + itemSpace.outerWidth);
|
|
158
|
+
totalHeightUsed = Math.max(totalHeightUsed, y + itemSpace.outerHeight);
|
|
159
|
+
rowMaxHeight[rowIndex] = Math.max(rowMaxHeight[rowIndex], itemSpace.outerHeight);
|
|
160
|
+
x += itemSpace.outerWidth;
|
|
161
|
+
}
|
|
162
|
+
if (direction === 'column') {
|
|
163
|
+
if (y + itemSpace.innerHeight > availableHeight) {
|
|
164
|
+
// This legend item would create overflow along the y-axis, so we start a new column.
|
|
165
|
+
x = totalWidthUsed + itemGap;
|
|
166
|
+
y = 0;
|
|
167
|
+
rowIndex = 0;
|
|
168
|
+
rep.positionX = x;
|
|
169
|
+
rep.positionY = y;
|
|
170
|
+
rep.rowIndex = rowIndex;
|
|
171
|
+
}
|
|
172
|
+
if (rowMaxHeight.length <= rowIndex) {
|
|
173
|
+
rowMaxHeight.push(0);
|
|
174
|
+
}
|
|
175
|
+
totalWidthUsed = Math.max(totalWidthUsed, x + itemSpace.outerWidth);
|
|
176
|
+
totalHeightUsed = Math.max(totalHeightUsed, y + itemSpace.outerHeight);
|
|
177
|
+
rowIndex += 1;
|
|
178
|
+
y += itemSpace.outerHeight;
|
|
179
|
+
}
|
|
180
|
+
return rep;
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
// Move the legend according to padding and position
|
|
184
|
+
var gapX = 0;
|
|
185
|
+
var gapY = 0;
|
|
186
|
+
switch (position.horizontal) {
|
|
187
|
+
case 'left':
|
|
188
|
+
gapX = padding.left;
|
|
189
|
+
break;
|
|
190
|
+
case 'right':
|
|
191
|
+
gapX = totalWidth - padding.right - totalWidthUsed;
|
|
192
|
+
break;
|
|
193
|
+
default:
|
|
194
|
+
gapX = (totalWidth - totalWidthUsed) / 2;
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
switch (position.vertical) {
|
|
198
|
+
case 'top':
|
|
199
|
+
gapY = padding.top;
|
|
200
|
+
break;
|
|
201
|
+
case 'bottom':
|
|
202
|
+
gapY = totalHeight - padding.bottom - totalHeightUsed;
|
|
203
|
+
break;
|
|
204
|
+
default:
|
|
205
|
+
gapY = (totalHeight - totalHeightUsed) / 2;
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
return seriesWithRawPosition.map(function (item) {
|
|
209
|
+
return _extends({}, item, {
|
|
210
|
+
// Add the gap due to the position
|
|
211
|
+
positionX: item.positionX + gapX,
|
|
212
|
+
// Add the gap due to the position
|
|
213
|
+
positionY: item.positionY + gapY + (direction === 'row' ? rowMaxHeight[item.rowIndex] / 2 // Get the center of the entire row
|
|
214
|
+
: item.outerHeight / 2) // Get the center of the item
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
}, [seriesToDisplay, position.horizontal, position.vertical, getItemSpace, labelStyle, direction, availableWidth, availableHeight, itemGap, padding.left, padding.right, padding.top, padding.bottom, totalWidth, totalHeight]);
|
|
149
218
|
if (hidden) {
|
|
150
219
|
return null;
|
|
151
220
|
}
|
|
152
|
-
return /*#__PURE__*/_jsx(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
className: classes.label,
|
|
179
|
-
children: label
|
|
180
|
-
})]
|
|
181
|
-
}, id);
|
|
221
|
+
return /*#__PURE__*/_jsx(NoSsr, {
|
|
222
|
+
children: /*#__PURE__*/_jsx(ChartsLegendRoot, {
|
|
223
|
+
className: classes.root,
|
|
224
|
+
children: seriesWithPosition.map(function (_ref2) {
|
|
225
|
+
var id = _ref2.id,
|
|
226
|
+
label = _ref2.label,
|
|
227
|
+
color = _ref2.color,
|
|
228
|
+
positionX = _ref2.positionX,
|
|
229
|
+
positionY = _ref2.positionY;
|
|
230
|
+
return /*#__PURE__*/_jsxs("g", {
|
|
231
|
+
className: classes.series,
|
|
232
|
+
transform: "translate(".concat(positionX, " ").concat(positionY, ")"),
|
|
233
|
+
children: [/*#__PURE__*/_jsx("rect", {
|
|
234
|
+
className: classes.mark,
|
|
235
|
+
y: -itemMarkHeight / 2,
|
|
236
|
+
width: itemMarkWidth,
|
|
237
|
+
height: itemMarkHeight,
|
|
238
|
+
fill: color
|
|
239
|
+
}), /*#__PURE__*/_jsx(ChartsText, {
|
|
240
|
+
style: labelStyle,
|
|
241
|
+
text: label,
|
|
242
|
+
x: itemMarkWidth + markGap,
|
|
243
|
+
y: 0
|
|
244
|
+
})]
|
|
245
|
+
}, id);
|
|
246
|
+
})
|
|
182
247
|
})
|
|
183
248
|
});
|
|
184
249
|
}
|
|
@@ -190,7 +255,6 @@ export function ChartsLegend(inProps) {
|
|
|
190
255
|
});
|
|
191
256
|
var position = props.position,
|
|
192
257
|
direction = props.direction,
|
|
193
|
-
offset = props.offset,
|
|
194
258
|
hidden = props.hidden,
|
|
195
259
|
slots = props.slots,
|
|
196
260
|
slotProps = props.slotProps;
|
|
@@ -208,7 +272,6 @@ export function ChartsLegend(inProps) {
|
|
|
208
272
|
additionalProps: {
|
|
209
273
|
position: position,
|
|
210
274
|
direction: direction,
|
|
211
|
-
offset: offset,
|
|
212
275
|
classes: classes,
|
|
213
276
|
drawingArea: drawingArea,
|
|
214
277
|
series: series,
|
package/legacy/ChartsSurface.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
4
|
-
var _excluded = ["children", "width", "height", "viewBox", "disableAxisListener", "className"
|
|
3
|
+
var _excluded = ["children", "width", "height", "viewBox", "disableAxisListener", "className"];
|
|
5
4
|
import { styled } from '@mui/material/styles';
|
|
6
5
|
import * as React from 'react';
|
|
7
6
|
import { useAxisEvents } from './hooks/useAxisEvents';
|
|
@@ -21,7 +20,6 @@ export var ChartsSurface = /*#__PURE__*/React.forwardRef(function ChartsSurface(
|
|
|
21
20
|
_props$disableAxisLis = props.disableAxisListener,
|
|
22
21
|
disableAxisListener = _props$disableAxisLis === void 0 ? false : _props$disableAxisLis,
|
|
23
22
|
className = props.className,
|
|
24
|
-
sx = props.sx,
|
|
25
23
|
other = _objectWithoutProperties(props, _excluded);
|
|
26
24
|
var svgView = _extends({
|
|
27
25
|
width: width,
|
|
@@ -34,14 +32,7 @@ export var ChartsSurface = /*#__PURE__*/React.forwardRef(function ChartsSurface(
|
|
|
34
32
|
width: width,
|
|
35
33
|
height: height,
|
|
36
34
|
viewBox: "".concat(svgView.x, " ").concat(svgView.y, " ").concat(svgView.width, " ").concat(svgView.height),
|
|
37
|
-
ref: ref
|
|
38
|
-
sx: [{
|
|
39
|
-
'--ChartsLegend-itemWidth': '100px',
|
|
40
|
-
'--ChartsLegend-itemMarkSize': '20px',
|
|
41
|
-
'--ChartsLegend-rootSpacing': '5px',
|
|
42
|
-
'--ChartsLegend-labelSpacing': '5px',
|
|
43
|
-
'--ChartsLegend-rootOffsetY': '-20px'
|
|
44
|
-
}].concat(_toConsumableArray(Array.isArray(sx) ? sx : [sx]))
|
|
35
|
+
ref: ref
|
|
45
36
|
}, other, {
|
|
46
37
|
children: [/*#__PURE__*/_jsx("title", {
|
|
47
38
|
children: props.title
|