@mui/x-charts 6.0.0-alpha.14 → 6.0.0-alpha.15
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 +3 -0
- package/BarChart/BarChart.js +4 -8
- package/CHANGELOG.md +104 -0
- package/ChartsLegend/ChartsLegend.d.ts +43 -24
- package/ChartsLegend/ChartsLegend.js +185 -143
- package/ChartsLegend/utils.d.ts +1 -6
- package/ChartsSurface.js +3 -11
- package/ChartsXAxis/ChartsXAxis.js +48 -25
- package/ChartsYAxis/ChartsYAxis.js +47 -26
- package/LineChart/LineChart.d.ts +3 -0
- package/LineChart/LineChart.js +4 -8
- package/PieChart/PieChart.d.ts +3 -0
- package/PieChart/PieChart.js +4 -8
- package/ScatterChart/ScatterChart.d.ts +3 -0
- package/ScatterChart/ScatterChart.js +4 -8
- package/constants.js +1 -1
- package/context/CartesianContextProvider.js +10 -10
- package/context/DrawingProvider.d.ts +2 -0
- package/context/DrawingProvider.js +2 -0
- package/esm/BarChart/BarChart.js +4 -8
- package/esm/ChartsLegend/ChartsLegend.js +184 -142
- package/esm/ChartsSurface.js +3 -11
- package/esm/ChartsXAxis/ChartsXAxis.js +47 -24
- package/esm/ChartsYAxis/ChartsYAxis.js +46 -25
- package/esm/LineChart/LineChart.js +4 -8
- package/esm/PieChart/PieChart.js +4 -8
- package/esm/ScatterChart/ScatterChart.js +4 -8
- package/esm/constants.js +1 -1
- package/esm/context/CartesianContextProvider.js +11 -11
- package/esm/context/DrawingProvider.js +2 -0
- package/esm/hooks/useChartDimensions.js +2 -0
- package/esm/hooks/useTicks.js +5 -5
- package/esm/internals/components/AxisSharedComponents.js +15 -70
- package/esm/internals/components/ChartsText.js +71 -0
- package/esm/internals/domUtils.js +113 -0
- package/hooks/useChartDimensions.d.ts +2 -0
- package/hooks/useChartDimensions.js +2 -0
- package/hooks/useTicks.d.ts +2 -3
- package/hooks/useTicks.js +6 -6
- 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 +32 -0
- package/internals/components/ChartsText.js +81 -0
- package/internals/domUtils.d.ts +14 -0
- package/internals/domUtils.js +122 -0
- package/legacy/BarChart/BarChart.js +4 -8
- package/legacy/ChartsLegend/ChartsLegend.js +196 -140
- package/legacy/ChartsSurface.js +2 -11
- package/legacy/ChartsXAxis/ChartsXAxis.js +47 -24
- package/legacy/ChartsYAxis/ChartsYAxis.js +46 -25
- package/legacy/LineChart/LineChart.js +4 -8
- package/legacy/PieChart/PieChart.js +4 -8
- package/legacy/ScatterChart/ScatterChart.js +4 -8
- package/legacy/constants.js +1 -1
- package/legacy/context/CartesianContextProvider.js +11 -11
- package/legacy/context/DrawingProvider.js +2 -0
- package/legacy/hooks/useChartDimensions.js +2 -0
- package/legacy/hooks/useTicks.js +5 -5
- 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/models/axis.d.ts +6 -5
- package/models/layout.d.ts +7 -6
- package/modern/BarChart/BarChart.js +4 -8
- package/modern/ChartsLegend/ChartsLegend.js +184 -142
- package/modern/ChartsSurface.js +3 -11
- package/modern/ChartsXAxis/ChartsXAxis.js +47 -24
- package/modern/ChartsYAxis/ChartsYAxis.js +46 -25
- package/modern/LineChart/LineChart.js +4 -8
- package/modern/PieChart/PieChart.js +4 -8
- package/modern/ScatterChart/ScatterChart.js +4 -8
- package/modern/constants.js +1 -1
- package/modern/context/CartesianContextProvider.js +11 -11
- package/modern/context/DrawingProvider.js +2 -0
- package/modern/hooks/useChartDimensions.js +2 -0
- package/modern/hooks/useTicks.js +5 -5
- package/modern/index.js +1 -1
- package/modern/internals/components/AxisSharedComponents.js +15 -70
- package/modern/internals/components/ChartsText.js +71 -0
- package/modern/internals/domUtils.js +113 -0
- package/package.json +1 -1
|
@@ -1,12 +1,17 @@
|
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
1
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
+
var _excluded = ["label"];
|
|
2
5
|
import * as React from 'react';
|
|
3
6
|
import { useSlotProps } from '@mui/base/utils';
|
|
7
|
+
import { NoSsr } from '@mui/base/NoSsr';
|
|
4
8
|
import { unstable_composeClasses as composeClasses } from '@mui/utils';
|
|
5
9
|
import { useThemeProps, useTheme, styled } from '@mui/material/styles';
|
|
6
10
|
import { DrawingContext } from '../context/DrawingProvider';
|
|
7
11
|
import { getSeriesToDisplay } from './utils';
|
|
8
12
|
import { SeriesContext } from '../context/SeriesContextProvider';
|
|
9
13
|
import { getChartsLegendUtilityClass } from './chartsLegendClasses';
|
|
14
|
+
import { ChartsText, getWordsByLines } from '../internals/components/ChartsText';
|
|
10
15
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
16
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
17
|
var useUtilityClasses = function useUtilityClasses(ownerState) {
|
|
@@ -20,165 +25,218 @@ var useUtilityClasses = function useUtilityClasses(ownerState) {
|
|
|
20
25
|
};
|
|
21
26
|
return composeClasses(slots, getChartsLegendUtilityClass, classes);
|
|
22
27
|
};
|
|
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
28
|
export var ChartsLegendRoot = styled('g', {
|
|
55
29
|
name: 'MuiChartsLegend',
|
|
56
30
|
slot: 'Root',
|
|
57
31
|
overridesResolver: function overridesResolver(props, styles) {
|
|
58
32
|
return styles.root;
|
|
59
33
|
}
|
|
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
|
-
});
|
|
34
|
+
})({});
|
|
130
35
|
var defaultProps = {
|
|
131
36
|
position: {
|
|
132
37
|
horizontal: 'middle',
|
|
133
38
|
vertical: 'top'
|
|
134
39
|
},
|
|
135
|
-
direction: 'row'
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
40
|
+
direction: 'row'
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Transforms number or partial padding object to a defaultized padding object.
|
|
44
|
+
*/
|
|
45
|
+
var getStandardizedPadding = function getStandardizedPadding(padding) {
|
|
46
|
+
if (typeof padding === 'number') {
|
|
47
|
+
return {
|
|
48
|
+
left: padding,
|
|
49
|
+
right: padding,
|
|
50
|
+
top: padding,
|
|
51
|
+
bottom: padding
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return _extends({
|
|
55
|
+
left: 0,
|
|
56
|
+
right: 0,
|
|
57
|
+
top: 0,
|
|
58
|
+
bottom: 0
|
|
59
|
+
}, padding);
|
|
139
60
|
};
|
|
140
61
|
function DefaultChartsLegend(props) {
|
|
141
62
|
var hidden = props.hidden,
|
|
142
63
|
position = props.position,
|
|
143
64
|
direction = props.direction,
|
|
144
|
-
offset = props.offset,
|
|
145
|
-
series = props.series,
|
|
146
65
|
seriesToDisplay = props.seriesToDisplay,
|
|
147
66
|
drawingArea = props.drawingArea,
|
|
148
|
-
classes = props.classes
|
|
67
|
+
classes = props.classes,
|
|
68
|
+
_props$itemMarkWidth = props.itemMarkWidth,
|
|
69
|
+
itemMarkWidth = _props$itemMarkWidth === void 0 ? 20 : _props$itemMarkWidth,
|
|
70
|
+
_props$itemMarkHeight = props.itemMarkHeight,
|
|
71
|
+
itemMarkHeight = _props$itemMarkHeight === void 0 ? 20 : _props$itemMarkHeight,
|
|
72
|
+
_props$markGap = props.markGap,
|
|
73
|
+
markGap = _props$markGap === void 0 ? 5 : _props$markGap,
|
|
74
|
+
_props$itemGap = props.itemGap,
|
|
75
|
+
itemGap = _props$itemGap === void 0 ? 10 : _props$itemGap,
|
|
76
|
+
_props$padding = props.padding,
|
|
77
|
+
paddingProps = _props$padding === void 0 ? 10 : _props$padding,
|
|
78
|
+
inLabelStyle = props.labelStyle;
|
|
79
|
+
var theme = useTheme();
|
|
80
|
+
var labelStyle = React.useMemo(function () {
|
|
81
|
+
return _extends({}, theme.typography.subtitle1, {
|
|
82
|
+
color: 'inherit',
|
|
83
|
+
fill: (theme.vars || theme).palette.text.primary,
|
|
84
|
+
lineHeight: 1
|
|
85
|
+
}, inLabelStyle);
|
|
86
|
+
}, [inLabelStyle, theme]);
|
|
87
|
+
var padding = React.useMemo(function () {
|
|
88
|
+
return getStandardizedPadding(paddingProps);
|
|
89
|
+
}, [paddingProps]);
|
|
90
|
+
var getItemSpace = React.useCallback(function (label, style) {
|
|
91
|
+
var linesSize = getWordsByLines({
|
|
92
|
+
style: style,
|
|
93
|
+
needsComputation: true,
|
|
94
|
+
text: label
|
|
95
|
+
});
|
|
96
|
+
var innerSize = {
|
|
97
|
+
innerWidth: itemMarkWidth + markGap + Math.max.apply(Math, _toConsumableArray(linesSize.map(function (size) {
|
|
98
|
+
return size.width;
|
|
99
|
+
}))),
|
|
100
|
+
innerHeight: Math.max(itemMarkHeight, linesSize.length * linesSize[0].height)
|
|
101
|
+
};
|
|
102
|
+
return _extends({}, innerSize, {
|
|
103
|
+
outerWidth: innerSize.innerWidth + itemGap,
|
|
104
|
+
outerHeight: innerSize.innerHeight + itemGap
|
|
105
|
+
});
|
|
106
|
+
}, [itemGap, itemMarkHeight, itemMarkWidth, markGap]);
|
|
107
|
+
var totalWidth = drawingArea.left + drawingArea.width + drawingArea.right;
|
|
108
|
+
var totalHeight = drawingArea.top + drawingArea.height + drawingArea.bottom;
|
|
109
|
+
var availableWidth = totalWidth - padding.left - padding.right;
|
|
110
|
+
var availableHeight = totalHeight - padding.top - padding.bottom;
|
|
111
|
+
var seriesWithPosition = React.useMemo(function () {
|
|
112
|
+
// Start at 0, 0. Will be modified later by padding and position.
|
|
113
|
+
var x = 0;
|
|
114
|
+
var y = 0;
|
|
115
|
+
|
|
116
|
+
// total values used to align legend later.
|
|
117
|
+
var totalWidthUsed = 0;
|
|
118
|
+
var totalHeightUsed = 0;
|
|
119
|
+
var rowIndex = 0;
|
|
120
|
+
var rowMaxHeight = [0];
|
|
121
|
+
var seriesWithRawPosition = seriesToDisplay.map(function (_ref) {
|
|
122
|
+
var label = _ref.label,
|
|
123
|
+
other = _objectWithoutProperties(_ref, _excluded);
|
|
124
|
+
var itemSpace = getItemSpace(label, labelStyle);
|
|
125
|
+
var rep = _extends({}, other, {
|
|
126
|
+
label: label,
|
|
127
|
+
positionX: x,
|
|
128
|
+
positionY: y,
|
|
129
|
+
innerHeight: itemSpace.innerHeight,
|
|
130
|
+
innerWidth: itemSpace.innerWidth,
|
|
131
|
+
outerHeight: itemSpace.outerHeight,
|
|
132
|
+
outerWidth: itemSpace.outerWidth,
|
|
133
|
+
rowIndex: rowIndex
|
|
134
|
+
});
|
|
135
|
+
if (direction === 'row') {
|
|
136
|
+
if (x + itemSpace.innerWidth > availableWidth) {
|
|
137
|
+
// This legend item would create overflow along the x-axis, so we start a new row.
|
|
138
|
+
x = 0;
|
|
139
|
+
y += rowMaxHeight[rowIndex];
|
|
140
|
+
rowIndex += 1;
|
|
141
|
+
if (rowMaxHeight.length <= rowIndex) {
|
|
142
|
+
rowMaxHeight.push(0);
|
|
143
|
+
}
|
|
144
|
+
rep.positionX = x;
|
|
145
|
+
rep.positionY = y;
|
|
146
|
+
rep.rowIndex = rowIndex;
|
|
147
|
+
}
|
|
148
|
+
totalWidthUsed = Math.max(totalWidthUsed, x + itemSpace.outerWidth);
|
|
149
|
+
totalHeightUsed = Math.max(totalHeightUsed, y + itemSpace.outerHeight);
|
|
150
|
+
rowMaxHeight[rowIndex] = Math.max(rowMaxHeight[rowIndex], itemSpace.outerHeight);
|
|
151
|
+
x += itemSpace.outerWidth;
|
|
152
|
+
}
|
|
153
|
+
if (direction === 'column') {
|
|
154
|
+
if (y + itemSpace.innerHeight > availableHeight) {
|
|
155
|
+
// This legend item would create overflow along the y-axis, so we start a new column.
|
|
156
|
+
x = totalWidthUsed + itemGap;
|
|
157
|
+
y = 0;
|
|
158
|
+
rowIndex = 0;
|
|
159
|
+
rep.positionX = x;
|
|
160
|
+
rep.positionY = y;
|
|
161
|
+
rep.rowIndex = rowIndex;
|
|
162
|
+
}
|
|
163
|
+
if (rowMaxHeight.length <= rowIndex) {
|
|
164
|
+
rowMaxHeight.push(0);
|
|
165
|
+
}
|
|
166
|
+
totalWidthUsed = Math.max(totalWidthUsed, x + itemSpace.outerWidth);
|
|
167
|
+
totalHeightUsed = Math.max(totalHeightUsed, y + itemSpace.outerHeight);
|
|
168
|
+
rowIndex += 1;
|
|
169
|
+
y += itemSpace.outerHeight;
|
|
170
|
+
}
|
|
171
|
+
return rep;
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
// Move the legend according to padding and position
|
|
175
|
+
var gapX = 0;
|
|
176
|
+
var gapY = 0;
|
|
177
|
+
switch (position.horizontal) {
|
|
178
|
+
case 'left':
|
|
179
|
+
gapX = padding.left;
|
|
180
|
+
break;
|
|
181
|
+
case 'right':
|
|
182
|
+
gapX = totalWidth - padding.right - totalWidthUsed;
|
|
183
|
+
break;
|
|
184
|
+
default:
|
|
185
|
+
gapX = (totalWidth - totalWidthUsed) / 2;
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
switch (position.vertical) {
|
|
189
|
+
case 'top':
|
|
190
|
+
gapY = padding.top;
|
|
191
|
+
break;
|
|
192
|
+
case 'bottom':
|
|
193
|
+
gapY = totalHeight - padding.bottom - totalHeightUsed;
|
|
194
|
+
break;
|
|
195
|
+
default:
|
|
196
|
+
gapY = (totalHeight - totalHeightUsed) / 2;
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
return seriesWithRawPosition.map(function (item) {
|
|
200
|
+
return _extends({}, item, {
|
|
201
|
+
// Add the gap due to the position
|
|
202
|
+
positionX: item.positionX + gapX,
|
|
203
|
+
// Add the gap due to the position
|
|
204
|
+
positionY: item.positionY + gapY + (direction === 'row' ? rowMaxHeight[item.rowIndex] / 2 // Get the center of the entire row
|
|
205
|
+
: item.outerHeight / 2) // Get the center of the item
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
}, [seriesToDisplay, position.horizontal, position.vertical, getItemSpace, labelStyle, direction, availableWidth, availableHeight, itemGap, padding.left, padding.right, padding.top, padding.bottom, totalWidth, totalHeight]);
|
|
149
209
|
if (hidden) {
|
|
150
210
|
return null;
|
|
151
211
|
}
|
|
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
|
-
|
|
179
|
-
|
|
180
|
-
})]
|
|
181
|
-
}, id);
|
|
212
|
+
return /*#__PURE__*/_jsx(NoSsr, {
|
|
213
|
+
children: /*#__PURE__*/_jsx(ChartsLegendRoot, {
|
|
214
|
+
className: classes.root,
|
|
215
|
+
children: seriesWithPosition.map(function (_ref2) {
|
|
216
|
+
var id = _ref2.id,
|
|
217
|
+
label = _ref2.label,
|
|
218
|
+
color = _ref2.color,
|
|
219
|
+
positionX = _ref2.positionX,
|
|
220
|
+
positionY = _ref2.positionY;
|
|
221
|
+
return /*#__PURE__*/_jsxs("g", {
|
|
222
|
+
className: classes.series,
|
|
223
|
+
transform: "translate(".concat(positionX, " ").concat(positionY, ")"),
|
|
224
|
+
children: [/*#__PURE__*/_jsx("rect", {
|
|
225
|
+
className: classes.mark,
|
|
226
|
+
y: -itemMarkHeight / 2,
|
|
227
|
+
width: itemMarkWidth,
|
|
228
|
+
height: itemMarkHeight,
|
|
229
|
+
fill: color
|
|
230
|
+
}), /*#__PURE__*/_jsx(ChartsText, {
|
|
231
|
+
style: labelStyle,
|
|
232
|
+
dominantBaseline: "central",
|
|
233
|
+
textAnchor: "start",
|
|
234
|
+
text: label,
|
|
235
|
+
x: itemMarkWidth + markGap,
|
|
236
|
+
y: 0
|
|
237
|
+
})]
|
|
238
|
+
}, id);
|
|
239
|
+
})
|
|
182
240
|
})
|
|
183
241
|
});
|
|
184
242
|
}
|
|
@@ -190,7 +248,6 @@ export function ChartsLegend(inProps) {
|
|
|
190
248
|
});
|
|
191
249
|
var position = props.position,
|
|
192
250
|
direction = props.direction,
|
|
193
|
-
offset = props.offset,
|
|
194
251
|
hidden = props.hidden,
|
|
195
252
|
slots = props.slots,
|
|
196
253
|
slotProps = props.slotProps;
|
|
@@ -208,7 +265,6 @@ export function ChartsLegend(inProps) {
|
|
|
208
265
|
additionalProps: {
|
|
209
266
|
position: position,
|
|
210
267
|
direction: direction,
|
|
211
|
-
offset: offset,
|
|
212
268
|
classes: classes,
|
|
213
269
|
drawingArea: drawingArea,
|
|
214
270
|
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
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
var _excluded = ["scale", "
|
|
3
|
+
var _excluded = ["scale", "tickNumber"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
|
+
import { useSlotProps } from '@mui/base/utils';
|
|
6
7
|
import { unstable_composeClasses as composeClasses } from '@mui/utils';
|
|
7
8
|
import { useThemeProps, useTheme } from '@mui/material/styles';
|
|
8
9
|
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
9
10
|
import { DrawingContext } from '../context/DrawingProvider';
|
|
10
11
|
import useTicks from '../hooks/useTicks';
|
|
11
12
|
import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
|
|
12
|
-
import {
|
|
13
|
+
import { AxisRoot } from '../internals/components/AxisSharedComponents';
|
|
14
|
+
import { ChartsText } from '../internals/components/ChartsText';
|
|
13
15
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
16
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
15
17
|
var useUtilityClasses = function useUtilityClasses(ownerState) {
|
|
@@ -42,7 +44,7 @@ function ChartsXAxis(inProps) {
|
|
|
42
44
|
var _React$useContext = React.useContext(CartesianContext),
|
|
43
45
|
_React$useContext$xAx = _React$useContext.xAxis[props.axisId],
|
|
44
46
|
xScale = _React$useContext$xAx.scale,
|
|
45
|
-
|
|
47
|
+
tickNumber = _React$useContext$xAx.tickNumber,
|
|
46
48
|
settings = _objectWithoutProperties(_React$useContext$xAx, _excluded);
|
|
47
49
|
var defaultizedProps = _extends({}, defaultProps, settings, props);
|
|
48
50
|
var position = defaultizedProps.position,
|
|
@@ -67,7 +69,7 @@ function ChartsXAxis(inProps) {
|
|
|
67
69
|
var tickSize = disableTicks ? 4 : tickSizeProp;
|
|
68
70
|
var xTicks = useTicks({
|
|
69
71
|
scale: xScale,
|
|
70
|
-
|
|
72
|
+
tickNumber: tickNumber,
|
|
71
73
|
valueFormatter: valueFormatter
|
|
72
74
|
});
|
|
73
75
|
var positionSigne = position === 'bottom' ? 1 : -1;
|
|
@@ -75,10 +77,38 @@ function ChartsXAxis(inProps) {
|
|
|
75
77
|
x: left + width / 2,
|
|
76
78
|
y: positionSigne * (tickFontSize + tickSize + 10)
|
|
77
79
|
};
|
|
78
|
-
var Line = (_slots$axisLine = slots == null ? void 0 : slots.axisLine) != null ? _slots$axisLine :
|
|
79
|
-
var Tick = (_slots$axisTick = slots == null ? void 0 : slots.axisTick) != null ? _slots$axisTick :
|
|
80
|
-
var TickLabel = (_slots$axisTickLabel = slots == null ? void 0 : slots.axisTickLabel) != null ? _slots$axisTickLabel :
|
|
81
|
-
var Label = (_slots$axisLabel = slots == null ? void 0 : slots.axisLabel) != null ? _slots$axisLabel :
|
|
80
|
+
var Line = (_slots$axisLine = slots == null ? void 0 : slots.axisLine) != null ? _slots$axisLine : 'line';
|
|
81
|
+
var Tick = (_slots$axisTick = slots == null ? void 0 : slots.axisTick) != null ? _slots$axisTick : 'line';
|
|
82
|
+
var TickLabel = (_slots$axisTickLabel = slots == null ? void 0 : slots.axisTickLabel) != null ? _slots$axisTickLabel : ChartsText;
|
|
83
|
+
var Label = (_slots$axisLabel = slots == null ? void 0 : slots.axisLabel) != null ? _slots$axisLabel : ChartsText;
|
|
84
|
+
var axisTickLabelProps = useSlotProps({
|
|
85
|
+
elementType: TickLabel,
|
|
86
|
+
externalSlotProps: slotProps == null ? void 0 : slotProps.axisTickLabel,
|
|
87
|
+
additionalProps: {
|
|
88
|
+
textAnchor: 'middle',
|
|
89
|
+
dominantBaseline: position === 'bottom' ? 'hanging' : 'auto',
|
|
90
|
+
style: {
|
|
91
|
+
fontSize: tickFontSize
|
|
92
|
+
},
|
|
93
|
+
className: classes.tickLabel
|
|
94
|
+
},
|
|
95
|
+
className: classes.tickLabel,
|
|
96
|
+
ownerState: {}
|
|
97
|
+
});
|
|
98
|
+
var axisLabelProps = useSlotProps({
|
|
99
|
+
elementType: Label,
|
|
100
|
+
externalSlotProps: slotProps == null ? void 0 : slotProps.axisLabel,
|
|
101
|
+
additionalProps: {
|
|
102
|
+
textAnchor: 'middle',
|
|
103
|
+
dominantBaseline: position === 'bottom' ? 'hanging' : 'auto',
|
|
104
|
+
style: {
|
|
105
|
+
fontSize: labelFontSize,
|
|
106
|
+
transformOrigin: "".concat(labelRefPoint.x, "px ").concat(labelRefPoint.y, "px")
|
|
107
|
+
},
|
|
108
|
+
className: classes.label
|
|
109
|
+
},
|
|
110
|
+
ownerState: {}
|
|
111
|
+
});
|
|
82
112
|
return /*#__PURE__*/_jsxs(AxisRoot, {
|
|
83
113
|
transform: "translate(0, ".concat(position === 'bottom' ? top + height : top, ")"),
|
|
84
114
|
className: classes.root,
|
|
@@ -101,24 +131,17 @@ function ChartsXAxis(inProps) {
|
|
|
101
131
|
}, slotProps == null ? void 0 : slotProps.axisTick)), formattedValue !== undefined && /*#__PURE__*/_jsx(TickLabel, _extends({
|
|
102
132
|
x: xTickLabel,
|
|
103
133
|
y: yTickLabel,
|
|
104
|
-
"transform-origin": "".concat(xTickLabel, "px ").concat(yTickLabel, "px")
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
},
|
|
108
|
-
className: classes.tickLabel
|
|
109
|
-
}, slotProps == null ? void 0 : slotProps.axisTickLabel, {
|
|
110
|
-
children: formattedValue
|
|
134
|
+
"transform-origin": "".concat(xTickLabel, "px ").concat(yTickLabel, "px")
|
|
135
|
+
}, axisTickLabelProps, {
|
|
136
|
+
text: formattedValue.toString()
|
|
111
137
|
}))]
|
|
112
138
|
}, index);
|
|
113
|
-
}), label && /*#__PURE__*/_jsx(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
}, slotProps == null ? void 0 : slotProps.axisLabel, {
|
|
120
|
-
children: label
|
|
121
|
-
}))]
|
|
139
|
+
}), label && /*#__PURE__*/_jsx("g", {
|
|
140
|
+
className: classes.label,
|
|
141
|
+
children: /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, axisLabelProps, {
|
|
142
|
+
text: label
|
|
143
|
+
}))
|
|
144
|
+
})]
|
|
122
145
|
});
|
|
123
146
|
}
|
|
124
147
|
process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
var _excluded = ["scale", "
|
|
3
|
+
var _excluded = ["scale", "tickNumber"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
|
+
import { useSlotProps } from '@mui/base/utils';
|
|
6
7
|
import { unstable_composeClasses as composeClasses } from '@mui/utils';
|
|
7
8
|
import { useThemeProps, useTheme } from '@mui/material/styles';
|
|
8
9
|
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
9
10
|
import { DrawingContext } from '../context/DrawingProvider';
|
|
10
11
|
import useTicks from '../hooks/useTicks';
|
|
11
|
-
import {
|
|
12
|
+
import { AxisRoot } from '../internals/components/AxisSharedComponents';
|
|
13
|
+
import { ChartsText } from '../internals/components/ChartsText';
|
|
12
14
|
import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
|
|
13
15
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
16
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -42,7 +44,7 @@ function ChartsYAxis(inProps) {
|
|
|
42
44
|
var _React$useContext = React.useContext(CartesianContext),
|
|
43
45
|
_React$useContext$yAx = _React$useContext.yAxis[props.axisId],
|
|
44
46
|
yScale = _React$useContext$yAx.scale,
|
|
45
|
-
|
|
47
|
+
tickNumber = _React$useContext$yAx.tickNumber,
|
|
46
48
|
settings = _objectWithoutProperties(_React$useContext$yAx, _excluded);
|
|
47
49
|
var defaultizedProps = _extends({}, defaultProps, settings, props);
|
|
48
50
|
var position = defaultizedProps.position,
|
|
@@ -67,7 +69,7 @@ function ChartsYAxis(inProps) {
|
|
|
67
69
|
var tickSize = disableTicks ? 4 : tickSizeProp;
|
|
68
70
|
var yTicks = useTicks({
|
|
69
71
|
scale: yScale,
|
|
70
|
-
|
|
72
|
+
tickNumber: tickNumber,
|
|
71
73
|
valueFormatter: valueFormatter
|
|
72
74
|
});
|
|
73
75
|
var positionSigne = position === 'right' ? 1 : -1;
|
|
@@ -75,10 +77,38 @@ function ChartsYAxis(inProps) {
|
|
|
75
77
|
x: positionSigne * (tickFontSize + tickSize + 10),
|
|
76
78
|
y: top + height / 2
|
|
77
79
|
};
|
|
78
|
-
var Line = (_slots$axisLine = slots == null ? void 0 : slots.axisLine) != null ? _slots$axisLine :
|
|
79
|
-
var Tick = (_slots$axisTick = slots == null ? void 0 : slots.axisTick) != null ? _slots$axisTick :
|
|
80
|
-
var TickLabel = (_slots$axisTickLabel = slots == null ? void 0 : slots.axisTickLabel) != null ? _slots$axisTickLabel :
|
|
81
|
-
var Label = (_slots$axisLabel = slots == null ? void 0 : slots.axisLabel) != null ? _slots$axisLabel :
|
|
80
|
+
var Line = (_slots$axisLine = slots == null ? void 0 : slots.axisLine) != null ? _slots$axisLine : 'line';
|
|
81
|
+
var Tick = (_slots$axisTick = slots == null ? void 0 : slots.axisTick) != null ? _slots$axisTick : 'line';
|
|
82
|
+
var TickLabel = (_slots$axisTickLabel = slots == null ? void 0 : slots.axisTickLabel) != null ? _slots$axisTickLabel : ChartsText;
|
|
83
|
+
var Label = (_slots$axisLabel = slots == null ? void 0 : slots.axisLabel) != null ? _slots$axisLabel : ChartsText;
|
|
84
|
+
var axisTickLabelProps = useSlotProps({
|
|
85
|
+
elementType: TickLabel,
|
|
86
|
+
externalSlotProps: slotProps == null ? void 0 : slotProps.axisTickLabel,
|
|
87
|
+
additionalProps: {
|
|
88
|
+
textAnchor: position === 'right' ? 'start' : 'end',
|
|
89
|
+
dominantBaseline: 'central',
|
|
90
|
+
style: {
|
|
91
|
+
fontSize: tickFontSize
|
|
92
|
+
},
|
|
93
|
+
className: classes.tickLabel
|
|
94
|
+
},
|
|
95
|
+
ownerState: {}
|
|
96
|
+
});
|
|
97
|
+
var axisLabelProps = useSlotProps({
|
|
98
|
+
elementType: Label,
|
|
99
|
+
externalSlotProps: slotProps == null ? void 0 : slotProps.axisLabel,
|
|
100
|
+
additionalProps: {
|
|
101
|
+
textAnchor: 'middle',
|
|
102
|
+
dominantBaseline: 'auto',
|
|
103
|
+
style: {
|
|
104
|
+
fontSize: labelFontSize,
|
|
105
|
+
transform: "rotate(".concat(positionSigne * 90, "deg)"),
|
|
106
|
+
transformOrigin: "".concat(labelRefPoint.x, "px ").concat(labelRefPoint.y, "px")
|
|
107
|
+
},
|
|
108
|
+
className: classes.label
|
|
109
|
+
},
|
|
110
|
+
ownerState: {}
|
|
111
|
+
});
|
|
82
112
|
return /*#__PURE__*/_jsxs(AxisRoot, {
|
|
83
113
|
transform: "translate(".concat(position === 'right' ? left + width : left, ", 0)"),
|
|
84
114
|
className: classes.root,
|
|
@@ -102,24 +132,15 @@ function ChartsYAxis(inProps) {
|
|
|
102
132
|
x: xTickLabel,
|
|
103
133
|
y: yTickLabel,
|
|
104
134
|
"transform-origin": "".concat(xTickLabel, "px ").concat(yTickLabel, "px"),
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
},
|
|
108
|
-
className: classes.tickLabel
|
|
109
|
-
}, slotProps == null ? void 0 : slotProps.axisTickLabel, {
|
|
110
|
-
children: formattedValue.toLocaleString()
|
|
111
|
-
}))]
|
|
135
|
+
text: formattedValue.toString()
|
|
136
|
+
}, axisTickLabelProps))]
|
|
112
137
|
}, index);
|
|
113
|
-
}), label && /*#__PURE__*/_jsx(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
className: classes.label
|
|
120
|
-
}, slotProps == null ? void 0 : slotProps.axisLabel, {
|
|
121
|
-
children: label
|
|
122
|
-
}))]
|
|
138
|
+
}), label && /*#__PURE__*/_jsx("g", {
|
|
139
|
+
className: classes.label,
|
|
140
|
+
children: /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, axisLabelProps, {
|
|
141
|
+
text: label
|
|
142
|
+
}))
|
|
143
|
+
})]
|
|
123
144
|
});
|
|
124
145
|
}
|
|
125
146
|
process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
|
|
@@ -172,23 +172,19 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
172
172
|
tickNumber: PropTypes.number,
|
|
173
173
|
tickSize: PropTypes.number
|
|
174
174
|
}), PropTypes.string]),
|
|
175
|
+
/**
|
|
176
|
+
* @deprecated Consider using `slotProps.legend` instead.
|
|
177
|
+
*/
|
|
175
178
|
legend: PropTypes.shape({
|
|
176
179
|
classes: PropTypes.object,
|
|
177
180
|
direction: PropTypes.oneOf(['column', 'row']),
|
|
178
181
|
hidden: PropTypes.bool,
|
|
179
|
-
itemWidth: PropTypes.number,
|
|
180
|
-
markSize: PropTypes.number,
|
|
181
|
-
offset: PropTypes.shape({
|
|
182
|
-
x: PropTypes.number,
|
|
183
|
-
y: PropTypes.number
|
|
184
|
-
}),
|
|
185
182
|
position: PropTypes.shape({
|
|
186
183
|
horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
|
|
187
184
|
vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
|
|
188
185
|
}),
|
|
189
186
|
slotProps: PropTypes.object,
|
|
190
|
-
slots: PropTypes.object
|
|
191
|
-
spacing: PropTypes.number
|
|
187
|
+
slots: PropTypes.object
|
|
192
188
|
}),
|
|
193
189
|
margin: PropTypes.shape({
|
|
194
190
|
bottom: PropTypes.number,
|