@mui/x-charts 7.0.0-alpha.2 → 7.0.0-alpha.4
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/BarElement.d.ts +5 -1
- package/BarChart/BarElement.js +24 -1
- package/BarChart/index.d.ts +2 -1
- package/BarChart/index.js +15 -4
- package/CHANGELOG.md +364 -0
- package/ChartsLegend/index.d.ts +1 -0
- package/ChartsLegend/index.js +11 -0
- package/ChartsTooltip/ChartsAxisTooltipContent.d.ts +5 -2
- package/ChartsTooltip/ChartsAxisTooltipContent.js +93 -73
- package/ChartsTooltip/ChartsItemTooltipContent.d.ts +5 -2
- package/ChartsTooltip/ChartsItemTooltipContent.js +38 -57
- package/ChartsTooltip/DefaultChartsAxisTooltipContent.d.ts +7 -0
- package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +174 -0
- package/ChartsTooltip/DefaultChartsItemTooltipContent.d.ts +8 -0
- package/ChartsTooltip/DefaultChartsItemTooltipContent.js +99 -0
- package/ChartsTooltip/index.d.ts +4 -0
- package/ChartsTooltip/index.js +44 -0
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.d.ts +14 -0
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +174 -0
- package/ChartsVoronoiHandler/index.d.ts +1 -0
- package/ChartsVoronoiHandler/index.js +16 -0
- package/ChartsVoronoiHandler/package.json +6 -0
- package/ChartsYAxis/ChartsYAxis.js +6 -4
- package/LineChart/extremums.js +25 -8
- package/LineChart/index.d.ts +1 -1
- package/LineChart/index.js +11 -11
- package/PieChart/PieArc.d.ts +5 -2
- package/PieChart/PieArc.js +17 -2
- package/PieChart/PieArcLabel.d.ts +1 -1
- package/PieChart/PieArcLabel.js +5 -10
- package/PieChart/PieArcLabelPlot.d.ts +5 -1
- package/PieChart/PieArcLabelPlot.js +91 -3
- package/PieChart/PieArcPlot.d.ts +5 -1
- package/PieChart/PieArcPlot.js +90 -3
- package/PieChart/index.d.ts +3 -1
- package/PieChart/index.js +26 -4
- package/README.md +0 -1
- package/ScatterChart/Scatter.js +15 -6
- package/ScatterChart/ScatterChart.d.ts +7 -1
- package/ScatterChart/ScatterChart.js +18 -1
- package/ScatterChart/index.d.ts +1 -1
- package/ScatterChart/index.js +8 -8
- package/SparkLineChart/SparkLineChart.js +1 -0
- package/context/InteractionProvider.d.ts +10 -0
- package/context/InteractionProvider.js +21 -1
- package/esm/BarChart/BarElement.js +26 -2
- package/esm/BarChart/index.js +2 -1
- package/esm/ChartsLegend/index.js +2 -1
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +95 -75
- package/esm/ChartsTooltip/ChartsItemTooltipContent.js +40 -58
- package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +168 -0
- package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +92 -0
- package/esm/ChartsTooltip/index.js +5 -1
- package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +168 -0
- package/esm/ChartsVoronoiHandler/index.js +1 -0
- package/esm/ChartsYAxis/ChartsYAxis.js +6 -4
- package/esm/LineChart/extremums.js +25 -8
- package/esm/LineChart/index.js +1 -1
- package/esm/PieChart/PieArc.js +18 -2
- package/esm/PieChart/PieArcLabel.js +7 -11
- package/esm/PieChart/PieArcLabelPlot.js +92 -3
- package/esm/PieChart/PieArcPlot.js +91 -3
- package/esm/PieChart/index.js +3 -1
- package/esm/ScatterChart/Scatter.js +15 -6
- package/esm/ScatterChart/ScatterChart.js +18 -1
- package/esm/ScatterChart/index.js +1 -1
- package/esm/SparkLineChart/SparkLineChart.js +1 -0
- package/esm/context/InteractionProvider.js +21 -1
- package/esm/hooks/useAxisEvents.js +20 -27
- package/esm/hooks/useInteractionItemProps.js +4 -1
- package/esm/index.js +1 -0
- package/esm/internals/defaultizeValueFormatter.js +4 -3
- package/esm/internals/utils.js +11 -0
- package/hooks/useAxisEvents.js +20 -27
- package/hooks/useInteractionItemProps.d.ts +2 -2
- package/hooks/useInteractionItemProps.js +4 -1
- package/index.d.ts +1 -0
- package/index.js +12 -1
- package/internals/defaultizeColor.d.ts +1 -0
- package/internals/defaultizeValueFormatter.d.ts +3 -1
- package/internals/defaultizeValueFormatter.js +3 -3
- package/internals/utils.d.ts +6 -0
- package/internals/utils.js +12 -0
- package/legacy/BarChart/BarElement.js +26 -2
- package/legacy/BarChart/index.js +2 -1
- package/legacy/ChartsLegend/index.js +2 -1
- package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +95 -74
- package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +40 -55
- package/legacy/ChartsTooltip/DefaultChartsAxisTooltipContent.js +167 -0
- package/legacy/ChartsTooltip/DefaultChartsItemTooltipContent.js +89 -0
- package/legacy/ChartsTooltip/index.js +5 -1
- package/legacy/ChartsVoronoiHandler/ChartsVoronoiHandler.js +162 -0
- package/legacy/ChartsVoronoiHandler/index.js +1 -0
- package/legacy/ChartsYAxis/ChartsYAxis.js +6 -4
- package/legacy/LineChart/extremums.js +29 -14
- package/legacy/LineChart/index.js +1 -1
- package/legacy/PieChart/PieArc.js +18 -2
- package/legacy/PieChart/PieArcLabel.js +7 -11
- package/legacy/PieChart/PieArcLabelPlot.js +92 -3
- package/legacy/PieChart/PieArcPlot.js +91 -3
- package/legacy/PieChart/index.js +3 -1
- package/legacy/ScatterChart/Scatter.js +18 -7
- package/legacy/ScatterChart/ScatterChart.js +18 -1
- package/legacy/ScatterChart/index.js +1 -1
- package/legacy/SparkLineChart/SparkLineChart.js +1 -0
- package/legacy/context/InteractionProvider.js +21 -1
- package/legacy/hooks/useAxisEvents.js +20 -27
- package/legacy/hooks/useInteractionItemProps.js +6 -1
- package/legacy/index.js +2 -1
- package/legacy/internals/defaultizeValueFormatter.js +4 -3
- package/legacy/internals/utils.js +11 -0
- package/models/seriesType/config.d.ts +5 -1
- package/models/seriesType/scatter.d.ts +6 -1
- package/modern/BarChart/BarElement.js +26 -2
- package/modern/BarChart/index.js +2 -1
- package/modern/ChartsLegend/index.js +2 -1
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +95 -74
- package/modern/ChartsTooltip/ChartsItemTooltipContent.js +40 -58
- package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +167 -0
- package/modern/ChartsTooltip/DefaultChartsItemTooltipContent.js +92 -0
- package/modern/ChartsTooltip/index.js +5 -1
- package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +166 -0
- package/modern/ChartsVoronoiHandler/index.js +1 -0
- package/modern/ChartsYAxis/ChartsYAxis.js +6 -4
- package/modern/LineChart/extremums.js +25 -8
- package/modern/LineChart/index.js +1 -1
- package/modern/PieChart/PieArc.js +18 -2
- package/modern/PieChart/PieArcLabel.js +7 -11
- package/modern/PieChart/PieArcLabelPlot.js +92 -3
- package/modern/PieChart/PieArcPlot.js +91 -3
- package/modern/PieChart/index.js +3 -1
- package/modern/ScatterChart/Scatter.js +15 -6
- package/modern/ScatterChart/ScatterChart.js +18 -1
- package/modern/ScatterChart/index.js +1 -1
- package/modern/SparkLineChart/SparkLineChart.js +1 -0
- package/modern/context/InteractionProvider.js +21 -1
- package/modern/hooks/useAxisEvents.js +20 -27
- package/modern/hooks/useInteractionItemProps.js +4 -1
- package/modern/index.js +2 -1
- package/modern/internals/defaultizeValueFormatter.js +3 -3
- package/modern/internals/utils.js +11 -0
- package/package.json +6 -4
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import clsx from 'clsx';
|
|
4
|
+
import Typography from '@mui/material/Typography';
|
|
5
|
+
import { ChartsTooltipCell, ChartsTooltipPaper, ChartsTooltipTable, ChartsTooltipMark, ChartsTooltipRow } from './ChartsTooltipTable';
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
8
|
+
function DefaultChartsAxisTooltipContent(props) {
|
|
9
|
+
const {
|
|
10
|
+
series,
|
|
11
|
+
axis,
|
|
12
|
+
dataIndex,
|
|
13
|
+
axisValue,
|
|
14
|
+
sx,
|
|
15
|
+
classes
|
|
16
|
+
} = props;
|
|
17
|
+
if (dataIndex == null) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const axisFormatter = axis.valueFormatter ?? (v => v.toLocaleString());
|
|
21
|
+
return /*#__PURE__*/_jsx(ChartsTooltipPaper, {
|
|
22
|
+
sx: sx,
|
|
23
|
+
className: classes.root,
|
|
24
|
+
children: /*#__PURE__*/_jsxs(ChartsTooltipTable, {
|
|
25
|
+
className: classes.table,
|
|
26
|
+
children: [axisValue != null && !axis.hideTooltip && /*#__PURE__*/_jsx("thead", {
|
|
27
|
+
children: /*#__PURE__*/_jsx(ChartsTooltipRow, {
|
|
28
|
+
children: /*#__PURE__*/_jsx(ChartsTooltipCell, {
|
|
29
|
+
colSpan: 3,
|
|
30
|
+
children: /*#__PURE__*/_jsx(Typography, {
|
|
31
|
+
children: axisFormatter(axisValue)
|
|
32
|
+
})
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
}), /*#__PURE__*/_jsx("tbody", {
|
|
36
|
+
children: series.map(({
|
|
37
|
+
color,
|
|
38
|
+
id,
|
|
39
|
+
label,
|
|
40
|
+
valueFormatter,
|
|
41
|
+
data
|
|
42
|
+
}) => {
|
|
43
|
+
const formattedValue = valueFormatter(data[dataIndex]);
|
|
44
|
+
if (formattedValue == null) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
return /*#__PURE__*/_jsxs(ChartsTooltipRow, {
|
|
48
|
+
className: classes.row,
|
|
49
|
+
children: [/*#__PURE__*/_jsx(ChartsTooltipCell, {
|
|
50
|
+
className: clsx(classes.markCell, classes.cell),
|
|
51
|
+
children: /*#__PURE__*/_jsx(ChartsTooltipMark, {
|
|
52
|
+
ownerState: {
|
|
53
|
+
color
|
|
54
|
+
},
|
|
55
|
+
boxShadow: 1,
|
|
56
|
+
className: classes.mark
|
|
57
|
+
})
|
|
58
|
+
}), /*#__PURE__*/_jsx(ChartsTooltipCell, {
|
|
59
|
+
className: clsx(classes.labelCell, classes.cell),
|
|
60
|
+
children: label ? /*#__PURE__*/_jsx(Typography, {
|
|
61
|
+
children: label
|
|
62
|
+
}) : null
|
|
63
|
+
}), /*#__PURE__*/_jsx(ChartsTooltipCell, {
|
|
64
|
+
className: clsx(classes.valueCell, classes.cell),
|
|
65
|
+
children: /*#__PURE__*/_jsx(Typography, {
|
|
66
|
+
children: formattedValue
|
|
67
|
+
})
|
|
68
|
+
})]
|
|
69
|
+
}, id);
|
|
70
|
+
})
|
|
71
|
+
})]
|
|
72
|
+
})
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
process.env.NODE_ENV !== "production" ? DefaultChartsAxisTooltipContent.propTypes = {
|
|
76
|
+
// ----------------------------- Warning --------------------------------
|
|
77
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
78
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
79
|
+
// ----------------------------------------------------------------------
|
|
80
|
+
/**
|
|
81
|
+
* The properties of the triggered axis.
|
|
82
|
+
*/
|
|
83
|
+
axis: PropTypes.shape({
|
|
84
|
+
axisId: PropTypes.string,
|
|
85
|
+
classes: PropTypes.object,
|
|
86
|
+
data: PropTypes.array,
|
|
87
|
+
dataKey: PropTypes.string,
|
|
88
|
+
disableLine: PropTypes.bool,
|
|
89
|
+
disableTicks: PropTypes.bool,
|
|
90
|
+
fill: PropTypes.string,
|
|
91
|
+
hideTooltip: PropTypes.bool,
|
|
92
|
+
id: PropTypes.string.isRequired,
|
|
93
|
+
label: PropTypes.string,
|
|
94
|
+
labelFontSize: PropTypes.number,
|
|
95
|
+
labelStyle: PropTypes.object,
|
|
96
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
97
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
98
|
+
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
99
|
+
scale: PropTypes.func.isRequired,
|
|
100
|
+
scaleType: PropTypes.oneOf(['time']).isRequired,
|
|
101
|
+
slotProps: PropTypes.object,
|
|
102
|
+
slots: PropTypes.object,
|
|
103
|
+
stroke: PropTypes.string,
|
|
104
|
+
tickFontSize: PropTypes.number,
|
|
105
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
106
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
107
|
+
tickLabelStyle: PropTypes.object,
|
|
108
|
+
tickMaxStep: PropTypes.number,
|
|
109
|
+
tickMinStep: PropTypes.number,
|
|
110
|
+
tickNumber: PropTypes.number.isRequired,
|
|
111
|
+
tickSize: PropTypes.number,
|
|
112
|
+
valueFormatter: PropTypes.func
|
|
113
|
+
}).isRequired,
|
|
114
|
+
/**
|
|
115
|
+
* Data identifying the triggered axis.
|
|
116
|
+
*/
|
|
117
|
+
axisData: PropTypes.shape({
|
|
118
|
+
x: PropTypes.shape({
|
|
119
|
+
index: PropTypes.number,
|
|
120
|
+
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
|
|
121
|
+
}),
|
|
122
|
+
y: PropTypes.shape({
|
|
123
|
+
index: PropTypes.number,
|
|
124
|
+
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
|
|
125
|
+
})
|
|
126
|
+
}).isRequired,
|
|
127
|
+
/**
|
|
128
|
+
* The value associated to the current mouse position.
|
|
129
|
+
*/
|
|
130
|
+
axisValue: PropTypes.any.isRequired,
|
|
131
|
+
/**
|
|
132
|
+
* Override or extend the styles applied to the component.
|
|
133
|
+
*/
|
|
134
|
+
classes: PropTypes.object.isRequired,
|
|
135
|
+
/**
|
|
136
|
+
* The index of the data item triggered.
|
|
137
|
+
*/
|
|
138
|
+
dataIndex: PropTypes.number,
|
|
139
|
+
/**
|
|
140
|
+
* The series linked to the triggered axis.
|
|
141
|
+
*/
|
|
142
|
+
series: PropTypes.arrayOf(PropTypes.shape({
|
|
143
|
+
area: PropTypes.bool,
|
|
144
|
+
color: PropTypes.string.isRequired,
|
|
145
|
+
connectNulls: PropTypes.bool,
|
|
146
|
+
curve: PropTypes.oneOf(['catmullRom', 'linear', 'monotoneX', 'monotoneY', 'natural', 'step', 'stepAfter', 'stepBefore']),
|
|
147
|
+
data: PropTypes.arrayOf(PropTypes.number).isRequired,
|
|
148
|
+
dataKey: PropTypes.string,
|
|
149
|
+
disableHighlight: PropTypes.bool,
|
|
150
|
+
highlightScope: PropTypes.shape({
|
|
151
|
+
faded: PropTypes.oneOf(['global', 'none', 'series']),
|
|
152
|
+
highlighted: PropTypes.oneOf(['item', 'none', 'series'])
|
|
153
|
+
}),
|
|
154
|
+
id: PropTypes.string.isRequired,
|
|
155
|
+
label: PropTypes.string,
|
|
156
|
+
showMark: PropTypes.oneOfType([PropTypes.func, PropTypes.bool]),
|
|
157
|
+
stack: PropTypes.string,
|
|
158
|
+
stackOffset: PropTypes.oneOf(['diverging', 'expand', 'none', 'silhouette', 'wiggle']),
|
|
159
|
+
stackOrder: PropTypes.oneOf(['appearance', 'ascending', 'descending', 'insideOut', 'none', 'reverse']),
|
|
160
|
+
type: PropTypes.oneOf(['line']).isRequired,
|
|
161
|
+
valueFormatter: PropTypes.func.isRequired,
|
|
162
|
+
xAxisKey: PropTypes.string,
|
|
163
|
+
yAxisKey: PropTypes.string
|
|
164
|
+
})).isRequired,
|
|
165
|
+
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
|
|
166
|
+
} : void 0;
|
|
167
|
+
export { DefaultChartsAxisTooltipContent };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import clsx from 'clsx';
|
|
4
|
+
import { ChartsTooltipTable, ChartsTooltipCell, ChartsTooltipMark, ChartsTooltipPaper, ChartsTooltipRow } from './ChartsTooltipTable';
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
|
+
function DefaultChartsItemTooltipContent(props) {
|
|
8
|
+
const {
|
|
9
|
+
series,
|
|
10
|
+
itemData,
|
|
11
|
+
sx,
|
|
12
|
+
classes
|
|
13
|
+
} = props;
|
|
14
|
+
if (itemData.dataIndex === undefined) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
const {
|
|
18
|
+
displayedLabel,
|
|
19
|
+
color
|
|
20
|
+
} = series.type === 'pie' ? {
|
|
21
|
+
color: series.data[itemData.dataIndex].color,
|
|
22
|
+
displayedLabel: series.data[itemData.dataIndex].label
|
|
23
|
+
} : {
|
|
24
|
+
color: series.color,
|
|
25
|
+
displayedLabel: series.label
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// TODO: Manage to let TS understand series.data and series.valueFormatter are coherent
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
const formattedValue = series.valueFormatter(series.data[itemData.dataIndex]);
|
|
31
|
+
return /*#__PURE__*/_jsx(ChartsTooltipPaper, {
|
|
32
|
+
sx: sx,
|
|
33
|
+
className: classes.root,
|
|
34
|
+
children: /*#__PURE__*/_jsx(ChartsTooltipTable, {
|
|
35
|
+
className: classes.table,
|
|
36
|
+
children: /*#__PURE__*/_jsx("tbody", {
|
|
37
|
+
children: /*#__PURE__*/_jsxs(ChartsTooltipRow, {
|
|
38
|
+
className: classes.row,
|
|
39
|
+
children: [/*#__PURE__*/_jsx(ChartsTooltipCell, {
|
|
40
|
+
className: clsx(classes.markCell, classes.cell),
|
|
41
|
+
children: /*#__PURE__*/_jsx(ChartsTooltipMark, {
|
|
42
|
+
ownerState: {
|
|
43
|
+
color
|
|
44
|
+
},
|
|
45
|
+
className: classes.mark
|
|
46
|
+
})
|
|
47
|
+
}), /*#__PURE__*/_jsx(ChartsTooltipCell, {
|
|
48
|
+
className: clsx(classes.labelCell, classes.cell),
|
|
49
|
+
children: displayedLabel
|
|
50
|
+
}), /*#__PURE__*/_jsx(ChartsTooltipCell, {
|
|
51
|
+
className: clsx(classes.valueCell, classes.cell),
|
|
52
|
+
children: formattedValue
|
|
53
|
+
})]
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
process.env.NODE_ENV !== "production" ? DefaultChartsItemTooltipContent.propTypes = {
|
|
60
|
+
// ----------------------------- Warning --------------------------------
|
|
61
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
62
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
63
|
+
// ----------------------------------------------------------------------
|
|
64
|
+
/**
|
|
65
|
+
* Override or extend the styles applied to the component.
|
|
66
|
+
*/
|
|
67
|
+
classes: PropTypes.object.isRequired,
|
|
68
|
+
/**
|
|
69
|
+
* The data used to identify the triggered item.
|
|
70
|
+
*/
|
|
71
|
+
itemData: PropTypes.shape({
|
|
72
|
+
dataIndex: PropTypes.number,
|
|
73
|
+
seriesId: PropTypes.string.isRequired,
|
|
74
|
+
type: PropTypes.oneOf(['bar', 'line', 'pie', 'scatter']).isRequired
|
|
75
|
+
}).isRequired,
|
|
76
|
+
/**
|
|
77
|
+
* The series linked to the triggered axis.
|
|
78
|
+
*/
|
|
79
|
+
series: PropTypes.shape({
|
|
80
|
+
color: PropTypes.string,
|
|
81
|
+
data: PropTypes.arrayOf(PropTypes.number).isRequired,
|
|
82
|
+
highlightScope: PropTypes.shape({
|
|
83
|
+
faded: PropTypes.oneOf(['global', 'none', 'series']),
|
|
84
|
+
highlighted: PropTypes.oneOf(['item', 'none', 'series'])
|
|
85
|
+
}),
|
|
86
|
+
id: PropTypes.string.isRequired,
|
|
87
|
+
type: PropTypes.oneOf(['bar', 'line', 'pie', 'scatter']).isRequired,
|
|
88
|
+
valueFormatter: PropTypes.func.isRequired
|
|
89
|
+
}).isRequired,
|
|
90
|
+
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
|
|
91
|
+
} : void 0;
|
|
92
|
+
export { DefaultChartsItemTooltipContent };
|
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
export * from './ChartsTooltip';
|
|
2
|
-
export * from './chartsTooltipClasses';
|
|
2
|
+
export * from './chartsTooltipClasses';
|
|
3
|
+
export * from './ChartsAxisTooltipContent';
|
|
4
|
+
export * from './ChartsItemTooltipContent';
|
|
5
|
+
export * from './DefaultChartsAxisTooltipContent';
|
|
6
|
+
export * from './DefaultChartsItemTooltipContent';
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { Delaunay } from 'd3-delaunay';
|
|
4
|
+
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
|
|
5
|
+
import { InteractionContext } from '../context/InteractionProvider';
|
|
6
|
+
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
7
|
+
import { SVGContext, DrawingContext } from '../context/DrawingProvider';
|
|
8
|
+
import { SeriesContext } from '../context/SeriesContextProvider';
|
|
9
|
+
import { getValueToPositionMapper } from '../hooks/useScale';
|
|
10
|
+
import { getSVGPoint } from '../internals/utils';
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
function ChartsVoronoiHandler(props) {
|
|
13
|
+
const {
|
|
14
|
+
voronoiMaxRadius
|
|
15
|
+
} = props;
|
|
16
|
+
const svgRef = React.useContext(SVGContext);
|
|
17
|
+
const {
|
|
18
|
+
width,
|
|
19
|
+
height,
|
|
20
|
+
top,
|
|
21
|
+
left
|
|
22
|
+
} = React.useContext(DrawingContext);
|
|
23
|
+
const {
|
|
24
|
+
xAxis,
|
|
25
|
+
yAxis,
|
|
26
|
+
xAxisIds,
|
|
27
|
+
yAxisIds
|
|
28
|
+
} = React.useContext(CartesianContext);
|
|
29
|
+
const {
|
|
30
|
+
dispatch
|
|
31
|
+
} = React.useContext(InteractionContext);
|
|
32
|
+
const {
|
|
33
|
+
series,
|
|
34
|
+
seriesOrder
|
|
35
|
+
} = React.useContext(SeriesContext).scatter ?? {};
|
|
36
|
+
const voronoiRef = React.useRef({});
|
|
37
|
+
const defaultXAxisId = xAxisIds[0];
|
|
38
|
+
const defaultYAxisId = yAxisIds[0];
|
|
39
|
+
useEnhancedEffect(() => {
|
|
40
|
+
dispatch({
|
|
41
|
+
type: 'updateVoronoiUsage',
|
|
42
|
+
useVoronoiInteraction: true
|
|
43
|
+
});
|
|
44
|
+
return () => {
|
|
45
|
+
dispatch({
|
|
46
|
+
type: 'updateVoronoiUsage',
|
|
47
|
+
useVoronoiInteraction: false
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
}, [dispatch]);
|
|
51
|
+
useEnhancedEffect(() => {
|
|
52
|
+
if (seriesOrder === undefined || series === undefined) {
|
|
53
|
+
// If there is no scatter chart series
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
voronoiRef.current = {};
|
|
57
|
+
let points = [];
|
|
58
|
+
seriesOrder.forEach(seriesId => {
|
|
59
|
+
const {
|
|
60
|
+
data,
|
|
61
|
+
xAxisKey,
|
|
62
|
+
yAxisKey
|
|
63
|
+
} = series[seriesId];
|
|
64
|
+
const xScale = xAxis[xAxisKey ?? defaultXAxisId].scale;
|
|
65
|
+
const yScale = yAxis[yAxisKey ?? defaultYAxisId].scale;
|
|
66
|
+
const getXPosition = getValueToPositionMapper(xScale);
|
|
67
|
+
const getYPosition = getValueToPositionMapper(yScale);
|
|
68
|
+
const seriesPoints = data.flatMap(({
|
|
69
|
+
x,
|
|
70
|
+
y
|
|
71
|
+
}) => [getXPosition(x), getYPosition(y)]);
|
|
72
|
+
voronoiRef.current[seriesId] = {
|
|
73
|
+
startIndex: points.length,
|
|
74
|
+
endIndex: points.length + seriesPoints.length
|
|
75
|
+
};
|
|
76
|
+
points = points.concat(seriesPoints);
|
|
77
|
+
});
|
|
78
|
+
voronoiRef.current.delauney = new Delaunay(points);
|
|
79
|
+
}, [defaultXAxisId, defaultYAxisId, series, seriesOrder, xAxis, yAxis]);
|
|
80
|
+
React.useEffect(() => {
|
|
81
|
+
const element = svgRef.current;
|
|
82
|
+
if (element === null) {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
const handleMouseOut = () => {
|
|
86
|
+
dispatch({
|
|
87
|
+
type: 'exitChart'
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// TODO: A perf optimisation of voronoi could be to use the last point as the intial point for the next search.
|
|
92
|
+
const handleMouseMove = event => {
|
|
93
|
+
// Get mouse coordinate in global SVG space
|
|
94
|
+
const svgPoint = getSVGPoint(svgRef.current, event);
|
|
95
|
+
const outsideX = svgPoint.x < left || svgPoint.x > left + width;
|
|
96
|
+
const outsideY = svgPoint.y < top || svgPoint.y > top + height;
|
|
97
|
+
if (outsideX || outsideY) {
|
|
98
|
+
dispatch({
|
|
99
|
+
type: 'exitChart'
|
|
100
|
+
});
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (!voronoiRef.current.delauney) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const closestPointIndex = voronoiRef.current.delauney?.find(svgPoint.x, svgPoint.y);
|
|
107
|
+
if (closestPointIndex !== undefined) {
|
|
108
|
+
const seriesId = Object.keys(voronoiRef.current).find(id => {
|
|
109
|
+
if (id === 'delauney') {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
return 2 * closestPointIndex >= voronoiRef.current[id].startIndex && 2 * closestPointIndex < voronoiRef.current[id].endIndex;
|
|
113
|
+
});
|
|
114
|
+
if (seriesId === undefined) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const dataIndex = (2 * closestPointIndex - voronoiRef.current[seriesId].startIndex) / 2;
|
|
118
|
+
if (voronoiMaxRadius !== undefined) {
|
|
119
|
+
const pointX = voronoiRef.current.delauney.points[2 * closestPointIndex];
|
|
120
|
+
const pointY = voronoiRef.current.delauney.points[2 * closestPointIndex + 1];
|
|
121
|
+
const dist2 = (pointX - svgPoint.x) ** 2 + (pointY - svgPoint.y) ** 2;
|
|
122
|
+
if (dist2 > voronoiMaxRadius ** 2) {
|
|
123
|
+
// The closest point is too far to be considered.
|
|
124
|
+
dispatch({
|
|
125
|
+
type: 'leaveItem',
|
|
126
|
+
data: {
|
|
127
|
+
type: 'scatter',
|
|
128
|
+
seriesId,
|
|
129
|
+
dataIndex
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
dispatch({
|
|
136
|
+
type: 'enterItem',
|
|
137
|
+
data: {
|
|
138
|
+
type: 'scatter',
|
|
139
|
+
seriesId,
|
|
140
|
+
dataIndex
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
element.addEventListener('mouseout', handleMouseOut);
|
|
146
|
+
element.addEventListener('mousemove', handleMouseMove);
|
|
147
|
+
return () => {
|
|
148
|
+
element.removeEventListener('mouseout', handleMouseOut);
|
|
149
|
+
element.removeEventListener('mousemove', handleMouseMove);
|
|
150
|
+
};
|
|
151
|
+
}, [svgRef, dispatch, left, width, top, height, yAxis, xAxis, voronoiMaxRadius]);
|
|
152
|
+
return /*#__PURE__*/_jsx("g", {}); // Workaround to fix docs scripts
|
|
153
|
+
}
|
|
154
|
+
process.env.NODE_ENV !== "production" ? ChartsVoronoiHandler.propTypes = {
|
|
155
|
+
// ----------------------------- Warning --------------------------------
|
|
156
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
157
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
158
|
+
// ----------------------------------------------------------------------
|
|
159
|
+
/**
|
|
160
|
+
* Defines the maximal distance between a scatter point and the pointer that triggers the interaction.
|
|
161
|
+
* If `undefined`, the radius is assumed to be infinite.
|
|
162
|
+
* @default undefined
|
|
163
|
+
*/
|
|
164
|
+
voronoiMaxRadius: PropTypes.number
|
|
165
|
+
} : void 0;
|
|
166
|
+
export { ChartsVoronoiHandler };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ChartsVoronoiHandler';
|
|
@@ -74,6 +74,8 @@ function ChartsYAxis(inProps) {
|
|
|
74
74
|
tickFontSize,
|
|
75
75
|
label,
|
|
76
76
|
labelFontSize,
|
|
77
|
+
labelStyle,
|
|
78
|
+
tickLabelStyle,
|
|
77
79
|
tickSize: tickSizeProp,
|
|
78
80
|
valueFormatter,
|
|
79
81
|
slots,
|
|
@@ -108,11 +110,11 @@ function ChartsYAxis(inProps) {
|
|
|
108
110
|
elementType: TickLabel,
|
|
109
111
|
externalSlotProps: slotProps?.axisTickLabel,
|
|
110
112
|
additionalProps: {
|
|
111
|
-
style: {
|
|
113
|
+
style: _extends({
|
|
112
114
|
fontSize: tickFontSize,
|
|
113
115
|
textAnchor: position === 'right' ? 'start' : 'end',
|
|
114
116
|
dominantBaseline: 'central'
|
|
115
|
-
},
|
|
117
|
+
}, tickLabelStyle),
|
|
116
118
|
className: classes.tickLabel
|
|
117
119
|
},
|
|
118
120
|
ownerState: {}
|
|
@@ -121,12 +123,12 @@ function ChartsYAxis(inProps) {
|
|
|
121
123
|
elementType: Label,
|
|
122
124
|
externalSlotProps: slotProps?.axisLabel,
|
|
123
125
|
additionalProps: {
|
|
124
|
-
style: {
|
|
126
|
+
style: _extends({
|
|
125
127
|
fontSize: labelFontSize,
|
|
126
128
|
angle: positionSign * 90,
|
|
127
129
|
textAnchor: 'middle',
|
|
128
130
|
dominantBaseline: 'auto'
|
|
129
|
-
}
|
|
131
|
+
}, labelStyle)
|
|
130
132
|
},
|
|
131
133
|
ownerState: {}
|
|
132
134
|
});
|
|
@@ -6,6 +6,18 @@ export const getExtremumX = params => {
|
|
|
6
6
|
const maxX = Math.max(...(axis.data ?? []));
|
|
7
7
|
return [minX, maxX];
|
|
8
8
|
};
|
|
9
|
+
function getSeriesExtremums(getValues, stackedData) {
|
|
10
|
+
if (stackedData.length === 0) {
|
|
11
|
+
return [null, null];
|
|
12
|
+
}
|
|
13
|
+
return stackedData.reduce((seriesAcc, stackedValue) => {
|
|
14
|
+
const [base, value] = getValues(stackedValue);
|
|
15
|
+
if (seriesAcc[0] === null) {
|
|
16
|
+
return [Math.min(base, value), Math.max(base, value)];
|
|
17
|
+
}
|
|
18
|
+
return [Math.min(base, value, seriesAcc[0]), Math.max(base, value, seriesAcc[1])];
|
|
19
|
+
}, getValues(stackedData[0]));
|
|
20
|
+
}
|
|
9
21
|
export const getExtremumY = params => {
|
|
10
22
|
const {
|
|
11
23
|
series,
|
|
@@ -13,16 +25,21 @@ export const getExtremumY = params => {
|
|
|
13
25
|
isDefaultAxis
|
|
14
26
|
} = params;
|
|
15
27
|
return Object.keys(series).filter(seriesId => series[seriesId].yAxisKey === axis.id || isDefaultAxis && series[seriesId].yAxisKey === undefined).reduce((acc, seriesId) => {
|
|
16
|
-
const
|
|
17
|
-
|
|
28
|
+
const {
|
|
29
|
+
area,
|
|
30
|
+
stackedData
|
|
31
|
+
} = series[seriesId];
|
|
32
|
+
const isArea = area !== undefined;
|
|
33
|
+
const getValues = isArea ? d => d : d => [d[1], d[1]]; // Since this series is not used to display an area, we do not consider the base (the d[0]).
|
|
18
34
|
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
return
|
|
22
|
-
}
|
|
23
|
-
if (
|
|
24
|
-
return
|
|
35
|
+
const seriesExtremums = getSeriesExtremums(getValues, stackedData);
|
|
36
|
+
if (acc[0] === null) {
|
|
37
|
+
return seriesExtremums;
|
|
38
|
+
}
|
|
39
|
+
if (seriesExtremums[0] === null) {
|
|
40
|
+
return acc;
|
|
25
41
|
}
|
|
42
|
+
const [seriesMin, seriesMax] = seriesExtremums;
|
|
26
43
|
return [Math.min(seriesMin, acc[0]), Math.max(seriesMax, acc[1])];
|
|
27
44
|
}, [null, null]);
|
|
28
45
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
export * from './LineChart';
|
|
1
2
|
export * from './LinePlot';
|
|
2
3
|
export * from './AreaPlot';
|
|
3
4
|
export * from './MarkPlot';
|
|
4
5
|
export * from './LineHighlightPlot';
|
|
5
|
-
export * from './LineChart';
|
|
6
6
|
export * from './AreaElement';
|
|
7
7
|
export * from './LineElement';
|
|
8
8
|
export * from './MarkElement';
|
|
@@ -2,6 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
3
|
const _excluded = ["id", "dataIndex", "classes", "color", "highlightScope", "onClick", "isFaded", "isHighlighted", "startAngle", "endAngle", "paddingAngle", "innerRadius", "outerRadius", "cornerRadius"];
|
|
4
4
|
import * as React from 'react';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
5
6
|
import { arc as d3Arc } from 'd3-shape';
|
|
6
7
|
import { animated, to } from '@react-spring/web';
|
|
7
8
|
import composeClasses from '@mui/utils/composeClasses';
|
|
@@ -37,7 +38,7 @@ const PieArcRoot = styled(animated.path, {
|
|
|
37
38
|
strokeWidth: 1,
|
|
38
39
|
strokeLinejoin: 'round'
|
|
39
40
|
}));
|
|
40
|
-
|
|
41
|
+
function PieArc(props) {
|
|
41
42
|
const {
|
|
42
43
|
id,
|
|
43
44
|
dataIndex,
|
|
@@ -82,4 +83,19 @@ export default function PieArc(props) {
|
|
|
82
83
|
seriesId: id,
|
|
83
84
|
dataIndex
|
|
84
85
|
})));
|
|
85
|
-
}
|
|
86
|
+
}
|
|
87
|
+
process.env.NODE_ENV !== "production" ? PieArc.propTypes = {
|
|
88
|
+
// ----------------------------- Warning --------------------------------
|
|
89
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
90
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
91
|
+
// ----------------------------------------------------------------------
|
|
92
|
+
classes: PropTypes.object,
|
|
93
|
+
dataIndex: PropTypes.number.isRequired,
|
|
94
|
+
highlightScope: PropTypes.shape({
|
|
95
|
+
faded: PropTypes.oneOf(['global', 'none', 'series']),
|
|
96
|
+
highlighted: PropTypes.oneOf(['item', 'none', 'series'])
|
|
97
|
+
}),
|
|
98
|
+
isFaded: PropTypes.bool.isRequired,
|
|
99
|
+
isHighlighted: PropTypes.bool.isRequired
|
|
100
|
+
} : void 0;
|
|
101
|
+
export { PieArc };
|
|
@@ -2,9 +2,9 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
3
|
const _excluded = ["id", "classes", "color", "startAngle", "endAngle", "paddingAngle", "innerRadius", "outerRadius", "cornerRadius", "formattedArcLabel", "isHighlighted", "isFaded", "style"];
|
|
4
4
|
import * as React from 'react';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
5
6
|
import { animated, to } from '@react-spring/web';
|
|
6
7
|
import { arc as d3Arc } from 'd3-shape';
|
|
7
|
-
import PropTypes from 'prop-types';
|
|
8
8
|
import composeClasses from '@mui/utils/composeClasses';
|
|
9
9
|
import generateUtilityClass from '@mui/utils/generateUtilityClass';
|
|
10
10
|
import { styled } from '@mui/material/styles';
|
|
@@ -57,7 +57,7 @@ const getLabelPosition = (formattedArcLabel, variable) => (startAngle, endAngle,
|
|
|
57
57
|
}
|
|
58
58
|
return y;
|
|
59
59
|
};
|
|
60
|
-
|
|
60
|
+
function PieArcLabel(props) {
|
|
61
61
|
const {
|
|
62
62
|
id,
|
|
63
63
|
classes: innerClasses,
|
|
@@ -98,12 +98,8 @@ process.env.NODE_ENV !== "production" ? PieArcLabel.propTypes = {
|
|
|
98
98
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
99
99
|
// ----------------------------------------------------------------------
|
|
100
100
|
classes: PropTypes.object,
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}),
|
|
107
|
-
innerRadius: PropTypes.number,
|
|
108
|
-
outerRadius: PropTypes.number.isRequired
|
|
109
|
-
} : void 0;
|
|
101
|
+
formattedArcLabel: PropTypes.string,
|
|
102
|
+
isFaded: PropTypes.bool.isRequired,
|
|
103
|
+
isHighlighted: PropTypes.bool.isRequired
|
|
104
|
+
} : void 0;
|
|
105
|
+
export { PieArcLabel };
|