UNPKG

@mui/x-charts

Version:

The community edition of MUI X Charts components.

115 lines (110 loc) 3.41 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; Object.defineProperty(exports, "__esModule", { value: true }); exports.getXAxisCoordinates = getXAxisCoordinates; exports.getYAxisCoordinates = getYAxisCoordinates; exports.useXAxisCoordinates = useXAxisCoordinates; exports.useYAxisCoordinates = useYAxisCoordinates; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _styles = require("@mui/material/styles"); var _useDrawingArea = require("./useDrawingArea"); var _useAxis = require("./useAxis"); var _utilities = require("../ChartsXAxis/utilities"); function getXAxisCoordinates(drawingArea, computedAxis) { const { position, offset, height: axisHeight } = computedAxis; if (position === 'none') { return null; } let top; if (position === 'top') { top = drawingArea.top - axisHeight - offset; } else { top = drawingArea.top + drawingArea.height + offset; } const left = drawingArea.left; const bottom = top + axisHeight; const right = drawingArea.left + drawingArea.width; return { left, top, right, bottom }; } /** * Get the coordinates of the given X axis. The coordinates are relative to the SVG's origin. * @param axisId The id of the X axis. * @returns {AxisCoordinates | null} The coordinates of the X axis or null if the axis does not exist or has position: 'none'. */ function useXAxisCoordinates(axisId) { const { xAxis: xAxes } = (0, _useAxis.useXAxes)(); const drawingArea = (0, _useDrawingArea.useDrawingArea)(); const axis = xAxes[axisId]; // FIXME(v9): Remove // eslint-disable-next-line mui/material-ui-name-matches-component-name const themedProps = (0, _styles.useThemeProps)({ props: axis, name: 'MuiChartsXAxis' }); if (!axis) { return null; } const defaultizedProps = (0, _extends2.default)({}, _utilities.defaultProps, themedProps); return getXAxisCoordinates(drawingArea, defaultizedProps); } function getYAxisCoordinates(drawingArea, computedAxis) { const { position, offset, width: axisWidth } = computedAxis; if (position === 'none') { return null; } let left; if (position === 'right') { left = drawingArea.left + drawingArea.width + offset; } else { left = drawingArea.left - axisWidth - offset; } const top = drawingArea.top; const bottom = drawingArea.top + drawingArea.height; const right = left + axisWidth; return { left, top, right, bottom }; } /** * Returns the coordinates of the given Y axis. The coordinates are relative to the SVG's origin. * @param axisId The id of the Y axis. * @returns {AxisCoordinates | null} The coordinates of the Y axis or null if the axis does not exist or has position: 'none'. */ function useYAxisCoordinates(axisId) { const { yAxis: yAxes } = (0, _useAxis.useYAxes)(); const drawingArea = (0, _useDrawingArea.useDrawingArea)(); const axis = yAxes[axisId]; // FIXME(v9): Remove // eslint-disable-next-line mui/material-ui-name-matches-component-name const themedProps = (0, _styles.useThemeProps)({ props: axis, name: 'MuiChartsYAxis' }); if (!axis) { return null; } const defaultizedProps = (0, _extends2.default)({}, _utilities.defaultProps, themedProps); return getYAxisCoordinates(drawingArea, defaultizedProps); }