@mui/x-charts
Version:
The community edition of MUI X Charts components.
44 lines • 1.19 kB
JavaScript
import { getLabel } from "../../internals/getLabel.mjs";
const tooltipGetter = params => {
const {
series,
axesConfig,
getColor,
identifier
} = params;
const rotationAxis = axesConfig.rotation;
if (!identifier || !rotationAxis) {
return null;
}
const label = getLabel(series.label, 'tooltip');
const formatter = v => rotationAxis.valueFormatter?.(v, {
location: 'tooltip',
scale: rotationAxis.scale
}) ?? (v == null ? '' : v.toLocaleString());
return {
identifier,
color: getColor(),
label,
markType: series.labelMarkType,
values: series.data.map((value, dataIndex) => {
if (identifier.dataIndex != null && identifier.dataIndex !== dataIndex) {
return null;
}
return {
value,
formattedValue: series.valueFormatter(value, {
dataIndex
}),
markType: series.labelMarkType,
label: formatter(rotationAxis?.data?.[dataIndex])
};
}).filter(v => v !== null)
};
};
export const axisTooltipGetter = series => {
return Object.values(series).map(() => ({
direction: 'rotation',
axisId: undefined
}));
};
export default tooltipGetter;