UNPKG

@mui/x-charts

Version:

The community edition of MUI X Charts components.

37 lines (36 loc) 1.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getLabelTransform = getLabelTransform; /** * Return the vertical/horizontal alignment for a tick label at a given position. * @param px The normalized x position to the axis line (between -1 and 1). * @param py The normalized y position to the axis line (between -1 and 1). * @param tickLabelPosition The position of the tick label relative to the axis line. * @returns The vertical and horizontal alignment for the tick label. */ function getLabelTransform(px, py, tickLabelPosition) { if (tickLabelPosition === 'center') { return { verticalAlign: 'middle', horizontalAlign: 'middle' }; } let verticalAlign = 'middle'; let horizontalAlign = 'middle'; if (px > 0.3) { verticalAlign = tickLabelPosition === 'after' ? 'start' : 'end'; } else if (px < -0.3) { verticalAlign = tickLabelPosition === 'after' ? 'end' : 'start'; } if (py > 0.3) { horizontalAlign = tickLabelPosition === 'after' ? 'end' : 'start'; } else if (py < -0.3) { horizontalAlign = tickLabelPosition === 'after' ? 'start' : 'end'; } return { verticalAlign, horizontalAlign }; }