@mui/x-charts 6.0.0-alpha.13 → 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 +6 -3
- package/BarChart/BarChart.js +7 -10
- package/BarChart/BarElement.js +2 -4
- package/BarChart/formatter.js +1 -2
- package/BarChart/legend.js +1 -2
- package/CHANGELOG.md +165 -1
- package/ChartContainer/index.js +2 -3
- package/ChartsAxis/axisClasses.js +1 -2
- package/ChartsLegend/ChartsLegend.d.ts +43 -24
- package/ChartsLegend/ChartsLegend.js +186 -148
- package/ChartsLegend/chartsLegendClasses.js +1 -2
- package/ChartsLegend/utils.d.ts +1 -6
- package/ChartsSurface.js +5 -14
- package/ChartsTooltip/ChartsAxisTooltipContent.d.ts +1 -0
- package/ChartsTooltip/ChartsAxisTooltipContent.js +17 -8
- package/ChartsTooltip/ChartsItemTooltipContent.d.ts +3 -2
- package/ChartsTooltip/ChartsItemTooltipContent.js +16 -6
- package/ChartsTooltip/ChartsTooltip.d.ts +23 -0
- package/ChartsTooltip/ChartsTooltip.js +47 -13
- package/ChartsTooltip/ChartsTooltipTable.js +6 -11
- package/ChartsTooltip/tooltipClasses.js +1 -2
- package/ChartsXAxis/ChartsXAxis.js +48 -25
- package/ChartsYAxis/ChartsYAxis.js +47 -26
- package/LineChart/AreaElement.js +2 -4
- package/LineChart/LineChart.d.ts +6 -3
- package/LineChart/LineChart.js +11 -11
- package/LineChart/LineElement.js +2 -4
- package/LineChart/LineHighlightElement.js +1 -2
- package/LineChart/MarkElement.js +1 -2
- package/LineChart/formatter.js +1 -2
- package/LineChart/legend.js +1 -2
- package/PieChart/PieArc.d.ts +1 -0
- package/PieChart/PieArc.js +6 -4
- package/PieChart/PieArcLabel.js +1 -2
- package/PieChart/PieChart.d.ts +8 -4
- package/PieChart/PieChart.js +11 -10
- package/PieChart/PiePlot.d.ts +8 -0
- package/PieChart/PiePlot.js +21 -5
- package/PieChart/formatter.js +1 -2
- package/PieChart/legend.js +1 -2
- package/ResponsiveChartContainer/index.js +2 -3
- package/ScatterChart/ScatterChart.d.ts +6 -3
- package/ScatterChart/ScatterChart.js +7 -10
- package/ScatterChart/formatter.js +1 -2
- package/ScatterChart/legend.js +1 -2
- package/SparkLineChart/SparkLineChart.d.ts +3 -3
- package/SparkLineChart/SparkLineChart.js +7 -3
- package/colorPalettes/colorPalettes.js +6 -12
- package/constants.js +5 -8
- package/context/CartesianContextProvider.js +11 -12
- package/context/DrawingProvider.d.ts +2 -0
- package/context/DrawingProvider.js +4 -4
- package/context/HighlightProvider.js +1 -2
- package/context/InteractionProvider.js +1 -2
- package/context/SeriesContextProvider.js +1 -2
- package/esm/BarChart/BarChart.js +6 -8
- package/esm/ChartsLegend/ChartsLegend.js +184 -142
- package/esm/ChartsSurface.js +3 -11
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +17 -8
- package/esm/ChartsTooltip/ChartsItemTooltipContent.js +15 -6
- package/esm/ChartsTooltip/ChartsTooltip.js +47 -12
- package/esm/ChartsXAxis/ChartsXAxis.js +47 -24
- package/esm/ChartsYAxis/ChartsYAxis.js +46 -25
- package/esm/LineChart/LineChart.js +10 -9
- package/esm/PieChart/PieArc.js +5 -2
- package/esm/PieChart/PieChart.js +11 -10
- package/esm/PieChart/PiePlot.js +17 -2
- package/esm/ScatterChart/ScatterChart.js +6 -8
- package/esm/SparkLineChart/SparkLineChart.js +6 -1
- 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 +3 -2
- package/hooks/useTicks.d.ts +2 -3
- package/hooks/useTicks.js +7 -8
- package/index.js +1 -1
- package/internals/components/AxisSharedComponents.d.ts +0 -4
- package/internals/components/AxisSharedComponents.js +18 -78
- package/internals/components/ChartsText.d.ts +32 -0
- package/internals/components/ChartsText.js +81 -0
- package/internals/defaultizeValueFormatter.js +1 -2
- package/internals/domUtils.d.ts +14 -0
- package/internals/domUtils.js +122 -0
- package/internals/stackSeries.js +2 -4
- package/legacy/BarChart/BarChart.js +6 -8
- package/legacy/ChartsLegend/ChartsLegend.js +196 -140
- package/legacy/ChartsSurface.js +2 -11
- package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +17 -8
- package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +15 -6
- package/legacy/ChartsTooltip/ChartsTooltip.js +50 -12
- package/legacy/ChartsXAxis/ChartsXAxis.js +47 -24
- package/legacy/ChartsYAxis/ChartsYAxis.js +46 -25
- package/legacy/LineChart/LineChart.js +10 -9
- package/legacy/PieChart/PieArc.js +4 -1
- package/legacy/PieChart/PieChart.js +11 -10
- package/legacy/PieChart/PiePlot.js +17 -2
- package/legacy/ScatterChart/ScatterChart.js +6 -8
- package/legacy/SparkLineChart/SparkLineChart.js +6 -1
- 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 +6 -8
- package/modern/ChartsLegend/ChartsLegend.js +184 -142
- package/modern/ChartsSurface.js +3 -11
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +17 -8
- package/modern/ChartsTooltip/ChartsItemTooltipContent.js +15 -6
- package/modern/ChartsTooltip/ChartsTooltip.js +46 -12
- package/modern/ChartsXAxis/ChartsXAxis.js +47 -24
- package/modern/ChartsYAxis/ChartsYAxis.js +46 -25
- package/modern/LineChart/LineChart.js +10 -9
- package/modern/PieChart/PieArc.js +5 -2
- package/modern/PieChart/PieChart.js +11 -10
- package/modern/PieChart/PiePlot.js +17 -2
- package/modern/ScatterChart/ScatterChart.js +6 -8
- package/modern/SparkLineChart/SparkLineChart.js +6 -1
- 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 +3 -3
package/esm/BarChart/BarChart.js
CHANGED
|
@@ -162,23 +162,19 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
162
162
|
tickNumber: PropTypes.number,
|
|
163
163
|
tickSize: PropTypes.number
|
|
164
164
|
}), PropTypes.string]),
|
|
165
|
+
/**
|
|
166
|
+
* @deprecated Consider using `slotProps.legend` instead.
|
|
167
|
+
*/
|
|
165
168
|
legend: PropTypes.shape({
|
|
166
169
|
classes: PropTypes.object,
|
|
167
170
|
direction: PropTypes.oneOf(['column', 'row']),
|
|
168
171
|
hidden: PropTypes.bool,
|
|
169
|
-
itemWidth: PropTypes.number,
|
|
170
|
-
markSize: PropTypes.number,
|
|
171
|
-
offset: PropTypes.shape({
|
|
172
|
-
x: PropTypes.number,
|
|
173
|
-
y: PropTypes.number
|
|
174
|
-
}),
|
|
175
172
|
position: PropTypes.shape({
|
|
176
173
|
horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
|
|
177
174
|
vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
|
|
178
175
|
}),
|
|
179
176
|
slotProps: PropTypes.object,
|
|
180
|
-
slots: PropTypes.object
|
|
181
|
-
spacing: PropTypes.number
|
|
177
|
+
slots: PropTypes.object
|
|
182
178
|
}),
|
|
183
179
|
margin: PropTypes.shape({
|
|
184
180
|
bottom: PropTypes.number,
|
|
@@ -244,6 +240,8 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
244
240
|
axisContent: PropTypes.elementType,
|
|
245
241
|
classes: PropTypes.object,
|
|
246
242
|
itemContent: PropTypes.elementType,
|
|
243
|
+
slotProps: PropTypes.object,
|
|
244
|
+
slots: PropTypes.object,
|
|
247
245
|
trigger: PropTypes.oneOf(['axis', 'item', 'none'])
|
|
248
246
|
}),
|
|
249
247
|
/**
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
1
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
+
const _excluded = ["label"];
|
|
2
4
|
import * as React from 'react';
|
|
3
5
|
import { useSlotProps } from '@mui/base/utils';
|
|
6
|
+
import { NoSsr } from '@mui/base/NoSsr';
|
|
4
7
|
import { unstable_composeClasses as composeClasses } from '@mui/utils';
|
|
5
8
|
import { useThemeProps, useTheme, styled } from '@mui/material/styles';
|
|
6
9
|
import { DrawingContext } from '../context/DrawingProvider';
|
|
7
10
|
import { getSeriesToDisplay } from './utils';
|
|
8
11
|
import { SeriesContext } from '../context/SeriesContextProvider';
|
|
9
12
|
import { getChartsLegendUtilityClass } from './chartsLegendClasses';
|
|
13
|
+
import { ChartsText, getWordsByLines } from '../internals/components/ChartsText';
|
|
10
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
15
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
16
|
const useUtilityClasses = ownerState => {
|
|
@@ -22,167 +26,207 @@ const useUtilityClasses = ownerState => {
|
|
|
22
26
|
};
|
|
23
27
|
return composeClasses(slots, getChartsLegendUtilityClass, classes);
|
|
24
28
|
};
|
|
25
|
-
function getTranslePosition({
|
|
26
|
-
position,
|
|
27
|
-
drawingArea
|
|
28
|
-
}) {
|
|
29
|
-
let xValue;
|
|
30
|
-
switch (position.horizontal) {
|
|
31
|
-
case 'left':
|
|
32
|
-
xValue = `calc(var(--ChartsLegend-rootOffsetX, 0px) + ${drawingArea.left}px - var(--ChartsLegend-rootWidth))`;
|
|
33
|
-
break;
|
|
34
|
-
case 'middle':
|
|
35
|
-
xValue = `calc(var(--ChartsLegend-rootOffsetX, 0px) + ${drawingArea.left + drawingArea.width / 2}px - 0.5 * var(--ChartsLegend-rootWidth))`;
|
|
36
|
-
break;
|
|
37
|
-
default:
|
|
38
|
-
xValue = `calc(var(--ChartsLegend-rootOffsetX, 0px) + ${drawingArea.left + drawingArea.width}px)`;
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
let yValue;
|
|
42
|
-
switch (position.vertical) {
|
|
43
|
-
case 'top':
|
|
44
|
-
yValue = `calc(var(--ChartsLegend-rootOffsetY, 0px) + ${drawingArea.top}px - var(--ChartsLegend-rootHeight))`;
|
|
45
|
-
break;
|
|
46
|
-
case 'middle':
|
|
47
|
-
yValue = `calc(var(--ChartsLegend-rootOffsetY, 0px) + ${drawingArea.top + drawingArea.height / 2}px - 0.5 * var(--ChartsLegend-rootHeight))`;
|
|
48
|
-
break;
|
|
49
|
-
default:
|
|
50
|
-
yValue = `calc(var(--ChartsLegend-rootOffsetY, 0px) + ${drawingArea.top + drawingArea.height}px)`;
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
return {
|
|
54
|
-
transform: `translate(${xValue}, ${yValue})`
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
29
|
export const ChartsLegendRoot = styled('g', {
|
|
58
30
|
name: 'MuiChartsLegend',
|
|
59
31
|
slot: 'Root',
|
|
60
32
|
overridesResolver: (props, styles) => styles.root
|
|
61
|
-
})(
|
|
62
|
-
ownerState
|
|
63
|
-
}) => {
|
|
64
|
-
const {
|
|
65
|
-
direction,
|
|
66
|
-
drawingArea,
|
|
67
|
-
offsetX,
|
|
68
|
-
offsetY,
|
|
69
|
-
seriesNumber,
|
|
70
|
-
position
|
|
71
|
-
} = ownerState;
|
|
72
|
-
return _extends({
|
|
73
|
-
'--ChartsLegend-rootOffsetX': typeof offsetX === 'number' ? `${offsetX}px` : undefined,
|
|
74
|
-
'--ChartsLegend-rootOffsetY': typeof offsetY === 'number' ? `${offsetY}px` : undefined,
|
|
75
|
-
'--ChartsLegend-rootWidth': direction === 'row' ? `calc(var(--ChartsLegend-itemWidth) * ${seriesNumber} + var(--ChartsLegend-rootSpacing) * ${seriesNumber - 1} )` : 'var(--ChartsLegend-itemWidth)',
|
|
76
|
-
'--ChartsLegend-rootHeight': direction === 'row' ? 'var(--ChartsLegend-itemMarkSize)' : `calc(var(--ChartsLegend-itemMarkSize) * ${seriesNumber} + var(--ChartsLegend-rootSpacing) * ${seriesNumber - 1} )`
|
|
77
|
-
}, getTranslePosition({
|
|
78
|
-
position,
|
|
79
|
-
drawingArea,
|
|
80
|
-
offsetX,
|
|
81
|
-
offsetY
|
|
82
|
-
}));
|
|
83
|
-
});
|
|
84
|
-
export const ChartsSeriesLegendGroup = styled('g', {
|
|
85
|
-
name: 'MuiChartsLegend',
|
|
86
|
-
slot: 'ChartsSeriesLegendGroup',
|
|
87
|
-
overridesResolver: (props, styles) => styles.series
|
|
88
|
-
})(({
|
|
89
|
-
ownerState
|
|
90
|
-
}) => {
|
|
91
|
-
const {
|
|
92
|
-
direction,
|
|
93
|
-
seriesIndex
|
|
94
|
-
} = ownerState;
|
|
95
|
-
if (direction === 'row') {
|
|
96
|
-
return {
|
|
97
|
-
transform: `translate(calc(${seriesIndex} * (var(--ChartsLegend-itemWidth) + var(--ChartsLegend-rootSpacing))), 0)`
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
return {
|
|
101
|
-
transform: `translate(0, calc(${seriesIndex} * (var(--ChartsLegend-itemMarkSize) + var(--ChartsLegend-rootSpacing))))`
|
|
102
|
-
};
|
|
103
|
-
});
|
|
104
|
-
export const ChartsLegendMark = styled('rect', {
|
|
105
|
-
name: 'MuiChartsLegend',
|
|
106
|
-
slot: 'Mark',
|
|
107
|
-
overridesResolver: (props, styles) => styles.mark
|
|
108
|
-
})(({
|
|
109
|
-
ownerState
|
|
110
|
-
}) => ({
|
|
111
|
-
x: 0,
|
|
112
|
-
y: 0,
|
|
113
|
-
width: 'var(--ChartsLegend-itemMarkSize)',
|
|
114
|
-
height: 'var(--ChartsLegend-itemMarkSize)',
|
|
115
|
-
fill: ownerState.color
|
|
116
|
-
}));
|
|
117
|
-
export const ChartsLegendLabel = styled('text', {
|
|
118
|
-
name: 'MuiChartsLegend',
|
|
119
|
-
slot: 'Label',
|
|
120
|
-
overridesResolver: (props, styles) => styles.label
|
|
121
|
-
})(({
|
|
122
|
-
theme
|
|
123
|
-
}) => _extends({}, theme.typography.body1, {
|
|
124
|
-
color: 'inherit',
|
|
125
|
-
transform: `translate(
|
|
126
|
-
calc(var(--ChartsLegend-itemMarkSize) + var(--ChartsLegend-labelSpacing)),
|
|
127
|
-
calc(0.5 * var(--ChartsLegend-itemMarkSize))
|
|
128
|
-
)`,
|
|
129
|
-
fill: (theme.vars || theme).palette.text.primary,
|
|
130
|
-
dominantBaseline: 'central'
|
|
131
|
-
}));
|
|
33
|
+
})({});
|
|
132
34
|
const defaultProps = {
|
|
133
35
|
position: {
|
|
134
36
|
horizontal: 'middle',
|
|
135
37
|
vertical: 'top'
|
|
136
38
|
},
|
|
137
|
-
direction: 'row'
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
39
|
+
direction: 'row'
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Transforms number or partial padding object to a defaultized padding object.
|
|
43
|
+
*/
|
|
44
|
+
const getStandardizedPadding = padding => {
|
|
45
|
+
if (typeof padding === 'number') {
|
|
46
|
+
return {
|
|
47
|
+
left: padding,
|
|
48
|
+
right: padding,
|
|
49
|
+
top: padding,
|
|
50
|
+
bottom: padding
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return _extends({
|
|
54
|
+
left: 0,
|
|
55
|
+
right: 0,
|
|
56
|
+
top: 0,
|
|
57
|
+
bottom: 0
|
|
58
|
+
}, padding);
|
|
141
59
|
};
|
|
142
60
|
function DefaultChartsLegend(props) {
|
|
143
61
|
const {
|
|
144
62
|
hidden,
|
|
145
63
|
position,
|
|
146
64
|
direction,
|
|
147
|
-
offset,
|
|
148
|
-
series,
|
|
149
65
|
seriesToDisplay,
|
|
150
66
|
drawingArea,
|
|
151
|
-
classes
|
|
67
|
+
classes,
|
|
68
|
+
itemMarkWidth = 20,
|
|
69
|
+
itemMarkHeight = 20,
|
|
70
|
+
markGap = 5,
|
|
71
|
+
itemGap = 10,
|
|
72
|
+
padding: paddingProps = 10,
|
|
73
|
+
labelStyle: inLabelStyle
|
|
152
74
|
} = props;
|
|
75
|
+
const theme = useTheme();
|
|
76
|
+
const labelStyle = React.useMemo(() => _extends({}, theme.typography.subtitle1, {
|
|
77
|
+
color: 'inherit',
|
|
78
|
+
fill: (theme.vars || theme).palette.text.primary,
|
|
79
|
+
lineHeight: 1
|
|
80
|
+
}, inLabelStyle), [inLabelStyle, theme]);
|
|
81
|
+
const padding = React.useMemo(() => getStandardizedPadding(paddingProps), [paddingProps]);
|
|
82
|
+
const getItemSpace = React.useCallback((label, style) => {
|
|
83
|
+
const linesSize = getWordsByLines({
|
|
84
|
+
style,
|
|
85
|
+
needsComputation: true,
|
|
86
|
+
text: label
|
|
87
|
+
});
|
|
88
|
+
const innerSize = {
|
|
89
|
+
innerWidth: itemMarkWidth + markGap + Math.max(...linesSize.map(size => size.width)),
|
|
90
|
+
innerHeight: Math.max(itemMarkHeight, linesSize.length * linesSize[0].height)
|
|
91
|
+
};
|
|
92
|
+
return _extends({}, innerSize, {
|
|
93
|
+
outerWidth: innerSize.innerWidth + itemGap,
|
|
94
|
+
outerHeight: innerSize.innerHeight + itemGap
|
|
95
|
+
});
|
|
96
|
+
}, [itemGap, itemMarkHeight, itemMarkWidth, markGap]);
|
|
97
|
+
const totalWidth = drawingArea.left + drawingArea.width + drawingArea.right;
|
|
98
|
+
const totalHeight = drawingArea.top + drawingArea.height + drawingArea.bottom;
|
|
99
|
+
const availableWidth = totalWidth - padding.left - padding.right;
|
|
100
|
+
const availableHeight = totalHeight - padding.top - padding.bottom;
|
|
101
|
+
const seriesWithPosition = React.useMemo(() => {
|
|
102
|
+
// Start at 0, 0. Will be modified later by padding and position.
|
|
103
|
+
let x = 0;
|
|
104
|
+
let y = 0;
|
|
105
|
+
|
|
106
|
+
// total values used to align legend later.
|
|
107
|
+
let totalWidthUsed = 0;
|
|
108
|
+
let totalHeightUsed = 0;
|
|
109
|
+
let rowIndex = 0;
|
|
110
|
+
const rowMaxHeight = [0];
|
|
111
|
+
const seriesWithRawPosition = seriesToDisplay.map(_ref => {
|
|
112
|
+
let {
|
|
113
|
+
label
|
|
114
|
+
} = _ref,
|
|
115
|
+
other = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
116
|
+
const itemSpace = getItemSpace(label, labelStyle);
|
|
117
|
+
const rep = _extends({}, other, {
|
|
118
|
+
label,
|
|
119
|
+
positionX: x,
|
|
120
|
+
positionY: y,
|
|
121
|
+
innerHeight: itemSpace.innerHeight,
|
|
122
|
+
innerWidth: itemSpace.innerWidth,
|
|
123
|
+
outerHeight: itemSpace.outerHeight,
|
|
124
|
+
outerWidth: itemSpace.outerWidth,
|
|
125
|
+
rowIndex
|
|
126
|
+
});
|
|
127
|
+
if (direction === 'row') {
|
|
128
|
+
if (x + itemSpace.innerWidth > availableWidth) {
|
|
129
|
+
// This legend item would create overflow along the x-axis, so we start a new row.
|
|
130
|
+
x = 0;
|
|
131
|
+
y += rowMaxHeight[rowIndex];
|
|
132
|
+
rowIndex += 1;
|
|
133
|
+
if (rowMaxHeight.length <= rowIndex) {
|
|
134
|
+
rowMaxHeight.push(0);
|
|
135
|
+
}
|
|
136
|
+
rep.positionX = x;
|
|
137
|
+
rep.positionY = y;
|
|
138
|
+
rep.rowIndex = rowIndex;
|
|
139
|
+
}
|
|
140
|
+
totalWidthUsed = Math.max(totalWidthUsed, x + itemSpace.outerWidth);
|
|
141
|
+
totalHeightUsed = Math.max(totalHeightUsed, y + itemSpace.outerHeight);
|
|
142
|
+
rowMaxHeight[rowIndex] = Math.max(rowMaxHeight[rowIndex], itemSpace.outerHeight);
|
|
143
|
+
x += itemSpace.outerWidth;
|
|
144
|
+
}
|
|
145
|
+
if (direction === 'column') {
|
|
146
|
+
if (y + itemSpace.innerHeight > availableHeight) {
|
|
147
|
+
// This legend item would create overflow along the y-axis, so we start a new column.
|
|
148
|
+
x = totalWidthUsed + itemGap;
|
|
149
|
+
y = 0;
|
|
150
|
+
rowIndex = 0;
|
|
151
|
+
rep.positionX = x;
|
|
152
|
+
rep.positionY = y;
|
|
153
|
+
rep.rowIndex = rowIndex;
|
|
154
|
+
}
|
|
155
|
+
if (rowMaxHeight.length <= rowIndex) {
|
|
156
|
+
rowMaxHeight.push(0);
|
|
157
|
+
}
|
|
158
|
+
totalWidthUsed = Math.max(totalWidthUsed, x + itemSpace.outerWidth);
|
|
159
|
+
totalHeightUsed = Math.max(totalHeightUsed, y + itemSpace.outerHeight);
|
|
160
|
+
rowIndex += 1;
|
|
161
|
+
y += itemSpace.outerHeight;
|
|
162
|
+
}
|
|
163
|
+
return rep;
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// Move the legend according to padding and position
|
|
167
|
+
let gapX = 0;
|
|
168
|
+
let gapY = 0;
|
|
169
|
+
switch (position.horizontal) {
|
|
170
|
+
case 'left':
|
|
171
|
+
gapX = padding.left;
|
|
172
|
+
break;
|
|
173
|
+
case 'right':
|
|
174
|
+
gapX = totalWidth - padding.right - totalWidthUsed;
|
|
175
|
+
break;
|
|
176
|
+
default:
|
|
177
|
+
gapX = (totalWidth - totalWidthUsed) / 2;
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
switch (position.vertical) {
|
|
181
|
+
case 'top':
|
|
182
|
+
gapY = padding.top;
|
|
183
|
+
break;
|
|
184
|
+
case 'bottom':
|
|
185
|
+
gapY = totalHeight - padding.bottom - totalHeightUsed;
|
|
186
|
+
break;
|
|
187
|
+
default:
|
|
188
|
+
gapY = (totalHeight - totalHeightUsed) / 2;
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
return seriesWithRawPosition.map(item => _extends({}, item, {
|
|
192
|
+
// Add the gap due to the position
|
|
193
|
+
positionX: item.positionX + gapX,
|
|
194
|
+
// Add the gap due to the position
|
|
195
|
+
positionY: item.positionY + gapY + (direction === 'row' ? rowMaxHeight[item.rowIndex] / 2 // Get the center of the entire row
|
|
196
|
+
: item.outerHeight / 2) // Get the center of the item
|
|
197
|
+
}));
|
|
198
|
+
}, [seriesToDisplay, position.horizontal, position.vertical, getItemSpace, labelStyle, direction, availableWidth, availableHeight, itemGap, padding.left, padding.right, padding.top, padding.bottom, totalWidth, totalHeight]);
|
|
153
199
|
if (hidden) {
|
|
154
200
|
return null;
|
|
155
201
|
}
|
|
156
|
-
return /*#__PURE__*/_jsx(
|
|
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
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
})]
|
|
185
|
-
}, id))
|
|
202
|
+
return /*#__PURE__*/_jsx(NoSsr, {
|
|
203
|
+
children: /*#__PURE__*/_jsx(ChartsLegendRoot, {
|
|
204
|
+
className: classes.root,
|
|
205
|
+
children: seriesWithPosition.map(({
|
|
206
|
+
id,
|
|
207
|
+
label,
|
|
208
|
+
color,
|
|
209
|
+
positionX,
|
|
210
|
+
positionY
|
|
211
|
+
}) => /*#__PURE__*/_jsxs("g", {
|
|
212
|
+
className: classes.series,
|
|
213
|
+
transform: `translate(${positionX} ${positionY})`,
|
|
214
|
+
children: [/*#__PURE__*/_jsx("rect", {
|
|
215
|
+
className: classes.mark,
|
|
216
|
+
y: -itemMarkHeight / 2,
|
|
217
|
+
width: itemMarkWidth,
|
|
218
|
+
height: itemMarkHeight,
|
|
219
|
+
fill: color
|
|
220
|
+
}), /*#__PURE__*/_jsx(ChartsText, {
|
|
221
|
+
style: labelStyle,
|
|
222
|
+
dominantBaseline: "central",
|
|
223
|
+
textAnchor: "start",
|
|
224
|
+
text: label,
|
|
225
|
+
x: itemMarkWidth + markGap,
|
|
226
|
+
y: 0
|
|
227
|
+
})]
|
|
228
|
+
}, id))
|
|
229
|
+
})
|
|
186
230
|
});
|
|
187
231
|
}
|
|
188
232
|
export function ChartsLegend(inProps) {
|
|
@@ -194,7 +238,6 @@ export function ChartsLegend(inProps) {
|
|
|
194
238
|
const {
|
|
195
239
|
position,
|
|
196
240
|
direction,
|
|
197
|
-
offset,
|
|
198
241
|
hidden,
|
|
199
242
|
slots,
|
|
200
243
|
slotProps
|
|
@@ -213,7 +256,6 @@ export function ChartsLegend(inProps) {
|
|
|
213
256
|
additionalProps: {
|
|
214
257
|
position,
|
|
215
258
|
direction,
|
|
216
|
-
offset,
|
|
217
259
|
classes,
|
|
218
260
|
drawingArea,
|
|
219
261
|
series,
|
package/esm/ChartsSurface.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
const _excluded = ["children", "width", "height", "viewBox", "disableAxisListener", "className"
|
|
3
|
+
const _excluded = ["children", "width", "height", "viewBox", "disableAxisListener", "className"];
|
|
4
4
|
import { styled } from '@mui/material/styles';
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import { useAxisEvents } from './hooks/useAxisEvents';
|
|
@@ -16,8 +16,7 @@ export const ChartsSurface = /*#__PURE__*/React.forwardRef(function ChartsSurfac
|
|
|
16
16
|
width,
|
|
17
17
|
height,
|
|
18
18
|
viewBox,
|
|
19
|
-
disableAxisListener = false
|
|
20
|
-
sx
|
|
19
|
+
disableAxisListener = false
|
|
21
20
|
} = props,
|
|
22
21
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
23
22
|
const svgView = _extends({
|
|
@@ -31,14 +30,7 @@ export const ChartsSurface = /*#__PURE__*/React.forwardRef(function ChartsSurfac
|
|
|
31
30
|
width: width,
|
|
32
31
|
height: height,
|
|
33
32
|
viewBox: `${svgView.x} ${svgView.y} ${svgView.width} ${svgView.height}`,
|
|
34
|
-
ref: ref
|
|
35
|
-
sx: [{
|
|
36
|
-
'--ChartsLegend-itemWidth': '100px',
|
|
37
|
-
'--ChartsLegend-itemMarkSize': '20px',
|
|
38
|
-
'--ChartsLegend-rootSpacing': '5px',
|
|
39
|
-
'--ChartsLegend-labelSpacing': '5px',
|
|
40
|
-
'--ChartsLegend-rootOffsetY': '-20px'
|
|
41
|
-
}, ...(Array.isArray(sx) ? sx : [sx])]
|
|
33
|
+
ref: ref
|
|
42
34
|
}, other, {
|
|
43
35
|
children: [/*#__PURE__*/_jsx("title", {
|
|
44
36
|
children: props.title
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
1
2
|
import * as React from 'react';
|
|
2
3
|
import Typography from '@mui/material/Typography';
|
|
4
|
+
import { useSlotProps } from '@mui/base/utils';
|
|
3
5
|
import { SeriesContext } from '../context/SeriesContextProvider';
|
|
4
6
|
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
5
7
|
import { ChartsTooltipCell, ChartsTooltipPaper, ChartsTooltipTable, ChartsTooltipMark, ChartsTooltipRow } from './ChartsTooltipTable';
|
|
@@ -67,6 +69,7 @@ export function DefaultChartsAxisContent(props) {
|
|
|
67
69
|
export function ChartsAxisTooltipContent(props) {
|
|
68
70
|
const {
|
|
69
71
|
content,
|
|
72
|
+
contentProps,
|
|
70
73
|
axisData,
|
|
71
74
|
sx,
|
|
72
75
|
classes
|
|
@@ -99,13 +102,19 @@ export function ChartsAxisTooltipContent(props) {
|
|
|
99
102
|
return isXaxis ? xAxis[USED_AXIS_ID] : yAxis[USED_AXIS_ID];
|
|
100
103
|
}, [USED_AXIS_ID, isXaxis, xAxis, yAxis]);
|
|
101
104
|
const Content = content != null ? content : DefaultChartsAxisContent;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
105
|
+
const chartTooltipContentProps = useSlotProps({
|
|
106
|
+
elementType: Content,
|
|
107
|
+
externalSlotProps: contentProps,
|
|
108
|
+
additionalProps: {
|
|
109
|
+
axisData,
|
|
110
|
+
series: relevantSeries,
|
|
111
|
+
axis: relevantAxis,
|
|
112
|
+
dataIndex,
|
|
113
|
+
axisValue,
|
|
114
|
+
sx,
|
|
115
|
+
classes
|
|
116
|
+
},
|
|
117
|
+
ownerState: {}
|
|
110
118
|
});
|
|
119
|
+
return /*#__PURE__*/_jsx(Content, _extends({}, chartTooltipContentProps));
|
|
111
120
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
1
2
|
import * as React from 'react';
|
|
3
|
+
import { useSlotProps } from '@mui/base/utils';
|
|
2
4
|
import { SeriesContext } from '../context/SeriesContextProvider';
|
|
3
5
|
import { ChartsTooltipTable, ChartsTooltipCell, ChartsTooltipMark, ChartsTooltipPaper, ChartsTooltipRow } from './ChartsTooltipTable';
|
|
4
6
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -57,14 +59,21 @@ export function ChartsItemTooltipContent(props) {
|
|
|
57
59
|
content,
|
|
58
60
|
itemData,
|
|
59
61
|
sx,
|
|
60
|
-
classes
|
|
62
|
+
classes,
|
|
63
|
+
contentProps
|
|
61
64
|
} = props;
|
|
62
65
|
const series = React.useContext(SeriesContext)[itemData.type].series[itemData.seriesId];
|
|
63
66
|
const Content = content != null ? content : DefaultChartsItemContent;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
const chartTooltipContentProps = useSlotProps({
|
|
68
|
+
elementType: Content,
|
|
69
|
+
externalSlotProps: contentProps,
|
|
70
|
+
additionalProps: {
|
|
71
|
+
itemData,
|
|
72
|
+
series,
|
|
73
|
+
sx,
|
|
74
|
+
classes
|
|
75
|
+
},
|
|
76
|
+
ownerState: {}
|
|
69
77
|
});
|
|
78
|
+
return /*#__PURE__*/_jsx(Content, _extends({}, chartTooltipContentProps));
|
|
70
79
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
1
2
|
import * as React from 'react';
|
|
2
3
|
import PropTypes from 'prop-types';
|
|
3
|
-
import
|
|
4
|
+
import composeClasses from '@mui/utils/composeClasses';
|
|
5
|
+
import { styled } from '@mui/material/styles';
|
|
4
6
|
import { Popper } from '@mui/base/Popper';
|
|
5
7
|
import { NoSsr } from '@mui/base/NoSsr';
|
|
8
|
+
import { useSlotProps } from '@mui/base/utils';
|
|
6
9
|
import { InteractionContext } from '../context/InteractionProvider';
|
|
7
10
|
import { generateVirtualElement, useMouseTracker, getTootipHasData } from './utils';
|
|
8
11
|
import { ChartsItemTooltipContent } from './ChartsItemTooltipContent';
|
|
@@ -21,11 +24,24 @@ const useUtilityClasses = ownerState => {
|
|
|
21
24
|
};
|
|
22
25
|
return composeClasses(slots, getTooltipUtilityClass, classes);
|
|
23
26
|
};
|
|
27
|
+
const ChartsTooltipRoot = styled(Popper, {
|
|
28
|
+
name: 'MuiChartsTooltip',
|
|
29
|
+
slot: 'Root',
|
|
30
|
+
overridesResolver: (_, styles) => styles.root
|
|
31
|
+
})(({
|
|
32
|
+
theme
|
|
33
|
+
}) => ({
|
|
34
|
+
pointerEvents: 'none',
|
|
35
|
+
zIndex: theme.zIndex.modal
|
|
36
|
+
}));
|
|
24
37
|
function ChartsTooltip(props) {
|
|
38
|
+
var _slots$popper, _slots$itemContent, _slots$axisContent;
|
|
25
39
|
const {
|
|
26
40
|
trigger = 'axis',
|
|
27
41
|
itemContent,
|
|
28
|
-
axisContent
|
|
42
|
+
axisContent,
|
|
43
|
+
slots,
|
|
44
|
+
slotProps
|
|
29
45
|
} = props;
|
|
30
46
|
const mousePosition = useMouseTracker();
|
|
31
47
|
const {
|
|
@@ -38,33 +54,40 @@ function ChartsTooltip(props) {
|
|
|
38
54
|
const classes = useUtilityClasses({
|
|
39
55
|
classes: props.classes
|
|
40
56
|
});
|
|
57
|
+
const PopperComponent = (_slots$popper = slots == null ? void 0 : slots.popper) != null ? _slots$popper : ChartsTooltipRoot;
|
|
58
|
+
const popperProps = useSlotProps({
|
|
59
|
+
elementType: PopperComponent,
|
|
60
|
+
externalSlotProps: slotProps == null ? void 0 : slotProps.popper,
|
|
61
|
+
additionalProps: {
|
|
62
|
+
open: popperOpen,
|
|
63
|
+
placement: 'right-start',
|
|
64
|
+
anchorEl: generateVirtualElement(mousePosition)
|
|
65
|
+
},
|
|
66
|
+
ownerState: {}
|
|
67
|
+
});
|
|
41
68
|
if (trigger === 'none') {
|
|
42
69
|
return null;
|
|
43
70
|
}
|
|
44
71
|
return /*#__PURE__*/_jsx(NoSsr, {
|
|
45
|
-
children: popperOpen && /*#__PURE__*/_jsx(
|
|
46
|
-
open: popperOpen,
|
|
47
|
-
placement: "right-start",
|
|
48
|
-
anchorEl: generateVirtualElement(mousePosition),
|
|
49
|
-
style: {
|
|
50
|
-
pointerEvents: 'none'
|
|
51
|
-
},
|
|
72
|
+
children: popperOpen && /*#__PURE__*/_jsx(PopperComponent, _extends({}, popperProps, {
|
|
52
73
|
children: trigger === 'item' ? /*#__PURE__*/_jsx(ChartsItemTooltipContent, {
|
|
53
74
|
itemData: displayedData,
|
|
54
|
-
content: itemContent,
|
|
75
|
+
content: (_slots$itemContent = slots == null ? void 0 : slots.itemContent) != null ? _slots$itemContent : itemContent,
|
|
76
|
+
contentProps: slotProps == null ? void 0 : slotProps.itemContent,
|
|
55
77
|
sx: {
|
|
56
78
|
mx: 2
|
|
57
79
|
},
|
|
58
80
|
classes: classes
|
|
59
81
|
}) : /*#__PURE__*/_jsx(ChartsAxisTooltipContent, {
|
|
60
82
|
axisData: displayedData,
|
|
61
|
-
content: axisContent,
|
|
83
|
+
content: (_slots$axisContent = slots == null ? void 0 : slots.axisContent) != null ? _slots$axisContent : axisContent,
|
|
84
|
+
contentProps: slotProps == null ? void 0 : slotProps.axisContent,
|
|
62
85
|
sx: {
|
|
63
86
|
mx: 2
|
|
64
87
|
},
|
|
65
88
|
classes: classes
|
|
66
89
|
})
|
|
67
|
-
})
|
|
90
|
+
}))
|
|
68
91
|
});
|
|
69
92
|
}
|
|
70
93
|
process.env.NODE_ENV !== "production" ? ChartsTooltip.propTypes = {
|
|
@@ -74,6 +97,7 @@ process.env.NODE_ENV !== "production" ? ChartsTooltip.propTypes = {
|
|
|
74
97
|
// ----------------------------------------------------------------------
|
|
75
98
|
/**
|
|
76
99
|
* Component to override the tooltip content when triger is set to 'axis'.
|
|
100
|
+
* @deprecated Use slots.axisContent instead
|
|
77
101
|
*/
|
|
78
102
|
axisContent: PropTypes.elementType,
|
|
79
103
|
/**
|
|
@@ -82,8 +106,19 @@ process.env.NODE_ENV !== "production" ? ChartsTooltip.propTypes = {
|
|
|
82
106
|
classes: PropTypes.object,
|
|
83
107
|
/**
|
|
84
108
|
* Component to override the tooltip content when triger is set to 'item'.
|
|
109
|
+
* @deprecated Use slots.itemContent instead
|
|
85
110
|
*/
|
|
86
111
|
itemContent: PropTypes.elementType,
|
|
112
|
+
/**
|
|
113
|
+
* The props used for each component slot.
|
|
114
|
+
* @default {}
|
|
115
|
+
*/
|
|
116
|
+
slotProps: PropTypes.object,
|
|
117
|
+
/**
|
|
118
|
+
* Overridable component slots.
|
|
119
|
+
* @default {}
|
|
120
|
+
*/
|
|
121
|
+
slots: PropTypes.object,
|
|
87
122
|
/**
|
|
88
123
|
* Select the kind of tooltip to display
|
|
89
124
|
* - 'item': Shows data about the item below the mouse.
|