@mui/x-charts
Version:
The community edition of MUI X Charts components.
8 lines • 387 B
JavaScript
import { isBandScale } from "./isBandScale.js";
export function invertScale(scale, data, value) {
if (isBandScale(scale)) {
const dataIndex = scale.bandwidth() === 0 ? Math.floor((value - Math.min(...scale.range()) + scale.step() / 2) / scale.step()) : Math.floor((value - Math.min(...scale.range())) / scale.step());
return data[dataIndex];
}
return scale.invert(value);
}