UNPKG

@mui/x-charts

Version:

The community edition of MUI X Charts components.

31 lines (30 loc) 1.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAxisIndex = getAxisIndex; var _isBandScale = require("../../../isBandScale"); var _clampAngle = require("../../../clampAngle"); /** * For a pointer coordinate, this function returns the value and dataIndex associated. * Returns `-1` if the coordinate does not match a value. */ function getAxisIndex(axisConfig, pointerValue) { const { scale, data: axisData, reverse } = axisConfig; if (!(0, _isBandScale.isBandScale)(scale)) { throw new Error('MUI X Charts: getAxisValue is not implemented for polare continuous axes.'); } if (!axisData) { return -1; } const angleGap = (0, _clampAngle.clampAngleRad)(pointerValue - Math.min(...scale.range())); const dataIndex = scale.bandwidth() === 0 ? Math.floor((angleGap + scale.step() / 2) / scale.step()) % axisData.length : Math.floor(angleGap / scale.step()); if (dataIndex < 0 || dataIndex >= axisData.length) { return -1; } return reverse ? axisData.length - 1 - dataIndex : dataIndex; }