UNPKG

@mui/x-charts

Version:

The community edition of MUI X Charts components.

115 lines (113 loc) 4.23 kB
"use strict"; 'use client'; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; Object.defineProperty(exports, "__esModule", { value: true }); exports.useAxisProps = void 0; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose")); var _useSlotProps = _interopRequireDefault(require("@mui/utils/useSlotProps")); var _styles = require("@mui/material/styles"); var _RtlProvider = require("@mui/system/RtlProvider"); var _ChartsText = require("../ChartsText"); var _useAxis = require("../hooks/useAxis"); var _defaultTextPlacement = require("../ChartsText/defaultTextPlacement"); var _invertTextAnchor = require("../internals/invertTextAnchor"); var _utilities = require("./utilities"); var _isBandScale = require("../internals/isBandScale"); var _isInfinity = require("../internals/isInfinity"); const _excluded = ["scale", "tickNumber", "reverse"]; const useAxisProps = inProps => { const { yAxis, yAxisIds } = (0, _useAxis.useYAxes)(); const _yAxis = yAxis[inProps.axisId ?? yAxisIds[0]], { scale: yScale, tickNumber, reverse } = _yAxis, settings = (0, _objectWithoutPropertiesLoose2.default)(_yAxis, _excluded); // eslint-disable-next-line material-ui/mui-name-matches-component-name const themedProps = (0, _styles.useThemeProps)({ props: (0, _extends2.default)({}, settings, inProps), name: 'MuiChartsYAxis' }); const defaultizedProps = (0, _extends2.default)({}, _utilities.defaultProps, themedProps); const { position, tickLabelStyle, labelStyle, slots, slotProps } = defaultizedProps; const theme = (0, _styles.useTheme)(); const isRtl = (0, _RtlProvider.useRtl)(); const classes = (0, _utilities.useUtilityClasses)(defaultizedProps); const positionSign = position === 'right' ? 1 : -1; const tickFontSize = typeof tickLabelStyle?.fontSize === 'number' ? tickLabelStyle.fontSize : 12; const Line = slots?.axisLine ?? 'line'; const Tick = slots?.axisTick ?? 'line'; const TickLabel = slots?.axisTickLabel ?? _ChartsText.ChartsText; const Label = slots?.axisLabel ?? _ChartsText.ChartsText; const defaultTextAnchor = (0, _defaultTextPlacement.getDefaultTextAnchor)((position === 'right' ? -90 : 90) - (tickLabelStyle?.angle ?? 0)); const defaultDominantBaseline = (0, _defaultTextPlacement.getDefaultBaseline)((position === 'right' ? -90 : 90) - (tickLabelStyle?.angle ?? 0)); const axisTickLabelProps = (0, _useSlotProps.default)({ elementType: TickLabel, externalSlotProps: slotProps?.axisTickLabel, additionalProps: { style: (0, _extends2.default)({}, theme.typography.caption, { fontSize: tickFontSize, textAnchor: isRtl ? (0, _invertTextAnchor.invertTextAnchor)(defaultTextAnchor) : defaultTextAnchor, dominantBaseline: defaultDominantBaseline }, tickLabelStyle) }, className: classes.tickLabel, ownerState: {} }); const axisLabelProps = (0, _useSlotProps.default)({ elementType: Label, externalSlotProps: slotProps?.axisLabel, additionalProps: { style: (0, _extends2.default)({}, theme.typography.body1, { lineHeight: 1, fontSize: 14, angle: positionSign * 90, textAnchor: 'middle', dominantBaseline: 'text-before-edge' }, labelStyle) }, ownerState: {} }); const lineProps = (0, _useSlotProps.default)({ elementType: Line, externalSlotProps: slotProps?.axisLine, additionalProps: { strokeLinecap: 'square' }, ownerState: {} }); const domain = yScale.domain(); const isScaleBand = (0, _isBandScale.isBandScale)(yScale); const skipAxisRendering = isScaleBand && domain.length === 0 || !isScaleBand && domain.some(_isInfinity.isInfinity) || position === 'none'; return { yScale, defaultizedProps, tickNumber, positionSign, skipAxisRendering, classes, Line, Tick, TickLabel, Label, axisTickLabelProps, axisLabelProps, lineProps, reverse, isRtl }; }; exports.useAxisProps = useAxisProps;