UNPKG

@mui/x-charts

Version:

The community edition of MUI X Charts components.

55 lines (52 loc) 1.8 kB
"use strict"; 'use client'; Object.defineProperty(exports, "__esModule", { value: true }); exports.getValueToPositionMapper = getValueToPositionMapper; exports.useRadiusScale = useRadiusScale; exports.useRotationScale = useRotationScale; exports.useXScale = useXScale; exports.useYScale = useYScale; var _isBandScale = require("../internals/isBandScale"); var _useAxis = require("./useAxis"); /** * For a given scale return a function that map value to their position. * Useful when dealing with specific scale such as band. * @param {D3Scale} scale The scale to use * @returns {(value: any) => number} A function that map value to their position */ function getValueToPositionMapper(scale) { if ((0, _isBandScale.isBandScale)(scale)) { return value => (scale(value) ?? 0) + scale.bandwidth() / 2; } return value => scale(value); } /** * Get the X scale. * * @param {AxisId | undefined} axisId - If provided returns the scale for the x axis with axisId, else returns the values for the default x axis. * @returns {AxisScaleConfig[S]['scale']} The scale for the specified X axis. */ function useXScale(axisId) { const axis = (0, _useAxis.useXAxis)(axisId); return axis.scale; } /** * Get the Y scale. * * @param {AxisId | undefined} axisId - If provided returns the scale for the y axis with axisId, else returns the values for the default y axis. * @returns {AxisScaleConfig[S]['scale']} The scale for the specified Y axis. */ function useYScale(axisId) { const axis = (0, _useAxis.useYAxis)(axisId); return axis.scale; } function useRotationScale(identifier) { const axis = (0, _useAxis.useRotationAxis)(identifier); return axis?.scale; } function useRadiusScale(identifier) { const axis = (0, _useAxis.useRadiusAxis)(identifier); return axis?.scale; }