@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
|
@@ -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) {
|
|
@@ -193,7 +237,6 @@ export function ChartsLegend(inProps) {
|
|
|
193
237
|
const {
|
|
194
238
|
position,
|
|
195
239
|
direction,
|
|
196
|
-
offset,
|
|
197
240
|
hidden,
|
|
198
241
|
slots,
|
|
199
242
|
slotProps
|
|
@@ -212,7 +255,6 @@ export function ChartsLegend(inProps) {
|
|
|
212
255
|
additionalProps: {
|
|
213
256
|
position,
|
|
214
257
|
direction,
|
|
215
|
-
offset,
|
|
216
258
|
classes,
|
|
217
259
|
drawingArea,
|
|
218
260
|
series,
|
package/modern/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';
|
|
@@ -66,6 +68,7 @@ export function DefaultChartsAxisContent(props) {
|
|
|
66
68
|
export function ChartsAxisTooltipContent(props) {
|
|
67
69
|
const {
|
|
68
70
|
content,
|
|
71
|
+
contentProps,
|
|
69
72
|
axisData,
|
|
70
73
|
sx,
|
|
71
74
|
classes
|
|
@@ -98,13 +101,19 @@ export function ChartsAxisTooltipContent(props) {
|
|
|
98
101
|
return isXaxis ? xAxis[USED_AXIS_ID] : yAxis[USED_AXIS_ID];
|
|
99
102
|
}, [USED_AXIS_ID, isXaxis, xAxis, yAxis]);
|
|
100
103
|
const Content = content ?? DefaultChartsAxisContent;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
104
|
+
const chartTooltipContentProps = useSlotProps({
|
|
105
|
+
elementType: Content,
|
|
106
|
+
externalSlotProps: contentProps,
|
|
107
|
+
additionalProps: {
|
|
108
|
+
axisData,
|
|
109
|
+
series: relevantSeries,
|
|
110
|
+
axis: relevantAxis,
|
|
111
|
+
dataIndex,
|
|
112
|
+
axisValue,
|
|
113
|
+
sx,
|
|
114
|
+
classes
|
|
115
|
+
},
|
|
116
|
+
ownerState: {}
|
|
109
117
|
});
|
|
118
|
+
return /*#__PURE__*/_jsx(Content, _extends({}, chartTooltipContentProps));
|
|
110
119
|
}
|
|
@@ -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 ?? 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,23 @@ 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) {
|
|
25
38
|
const {
|
|
26
39
|
trigger = 'axis',
|
|
27
40
|
itemContent,
|
|
28
|
-
axisContent
|
|
41
|
+
axisContent,
|
|
42
|
+
slots,
|
|
43
|
+
slotProps
|
|
29
44
|
} = props;
|
|
30
45
|
const mousePosition = useMouseTracker();
|
|
31
46
|
const {
|
|
@@ -38,33 +53,40 @@ function ChartsTooltip(props) {
|
|
|
38
53
|
const classes = useUtilityClasses({
|
|
39
54
|
classes: props.classes
|
|
40
55
|
});
|
|
56
|
+
const PopperComponent = slots?.popper ?? ChartsTooltipRoot;
|
|
57
|
+
const popperProps = useSlotProps({
|
|
58
|
+
elementType: PopperComponent,
|
|
59
|
+
externalSlotProps: slotProps?.popper,
|
|
60
|
+
additionalProps: {
|
|
61
|
+
open: popperOpen,
|
|
62
|
+
placement: 'right-start',
|
|
63
|
+
anchorEl: generateVirtualElement(mousePosition)
|
|
64
|
+
},
|
|
65
|
+
ownerState: {}
|
|
66
|
+
});
|
|
41
67
|
if (trigger === 'none') {
|
|
42
68
|
return null;
|
|
43
69
|
}
|
|
44
70
|
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
|
-
},
|
|
71
|
+
children: popperOpen && /*#__PURE__*/_jsx(PopperComponent, _extends({}, popperProps, {
|
|
52
72
|
children: trigger === 'item' ? /*#__PURE__*/_jsx(ChartsItemTooltipContent, {
|
|
53
73
|
itemData: displayedData,
|
|
54
|
-
content: itemContent,
|
|
74
|
+
content: slots?.itemContent ?? itemContent,
|
|
75
|
+
contentProps: slotProps?.itemContent,
|
|
55
76
|
sx: {
|
|
56
77
|
mx: 2
|
|
57
78
|
},
|
|
58
79
|
classes: classes
|
|
59
80
|
}) : /*#__PURE__*/_jsx(ChartsAxisTooltipContent, {
|
|
60
81
|
axisData: displayedData,
|
|
61
|
-
content: axisContent,
|
|
82
|
+
content: slots?.axisContent ?? axisContent,
|
|
83
|
+
contentProps: slotProps?.axisContent,
|
|
62
84
|
sx: {
|
|
63
85
|
mx: 2
|
|
64
86
|
},
|
|
65
87
|
classes: classes
|
|
66
88
|
})
|
|
67
|
-
})
|
|
89
|
+
}))
|
|
68
90
|
});
|
|
69
91
|
}
|
|
70
92
|
process.env.NODE_ENV !== "production" ? ChartsTooltip.propTypes = {
|
|
@@ -74,6 +96,7 @@ process.env.NODE_ENV !== "production" ? ChartsTooltip.propTypes = {
|
|
|
74
96
|
// ----------------------------------------------------------------------
|
|
75
97
|
/**
|
|
76
98
|
* Component to override the tooltip content when triger is set to 'axis'.
|
|
99
|
+
* @deprecated Use slots.axisContent instead
|
|
77
100
|
*/
|
|
78
101
|
axisContent: PropTypes.elementType,
|
|
79
102
|
/**
|
|
@@ -82,8 +105,19 @@ process.env.NODE_ENV !== "production" ? ChartsTooltip.propTypes = {
|
|
|
82
105
|
classes: PropTypes.object,
|
|
83
106
|
/**
|
|
84
107
|
* Component to override the tooltip content when triger is set to 'item'.
|
|
108
|
+
* @deprecated Use slots.itemContent instead
|
|
85
109
|
*/
|
|
86
110
|
itemContent: PropTypes.elementType,
|
|
111
|
+
/**
|
|
112
|
+
* The props used for each component slot.
|
|
113
|
+
* @default {}
|
|
114
|
+
*/
|
|
115
|
+
slotProps: PropTypes.object,
|
|
116
|
+
/**
|
|
117
|
+
* Overridable component slots.
|
|
118
|
+
* @default {}
|
|
119
|
+
*/
|
|
120
|
+
slots: PropTypes.object,
|
|
87
121
|
/**
|
|
88
122
|
* Select the kind of tooltip to display
|
|
89
123
|
* - 'item': Shows data about the item below the mouse.
|