UNPKG

@mui/x-charts

Version:

The community edition of MUI X Charts components.

126 lines (125 loc) 4.09 kB
'use client'; import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose"; import _extends from "@babel/runtime/helpers/esm/extends"; const _excluded = ["seriesId", "dataIndex", "color", "isFaded", "isHighlighted", "classes", "skipAnimation", "layout", "xOrigin", "yOrigin", "placement", "hidden"]; import * as React from 'react'; import { styled, useThemeProps } from '@mui/material/styles'; import PropTypes from 'prop-types'; import { useAnimateBarLabel } from "../../hooks/animation/useAnimateBarLabel.js"; import { barLabelClasses } from "./barLabelClasses.js"; import { ANIMATION_DURATION_MS, ANIMATION_TIMING_FUNCTION } from "../../internals/animation/animation.js"; import { jsx as _jsx } from "react/jsx-runtime"; export const BarLabelComponent = styled('text', { name: 'MuiBarLabel', slot: 'Root', overridesResolver: (_, styles) => [{ [`&.${barLabelClasses.faded}`]: styles.faded }, { [`&.${barLabelClasses.highlighted}`]: styles.highlighted }, styles.root] })(({ theme }) => _extends({}, theme?.typography?.body2, { stroke: 'none', fill: (theme.vars || theme)?.palette?.text?.primary, transitionProperty: 'opacity, fill', transitionDuration: `${ANIMATION_DURATION_MS}ms`, transitionTimingFunction: ANIMATION_TIMING_FUNCTION, pointerEvents: 'none' })); function BarLabel(inProps) { const props = useThemeProps({ props: inProps, name: 'MuiBarLabel' }); const { isFaded, hidden } = props, otherProps = _objectWithoutPropertiesLoose(props, _excluded); const animatedProps = useAnimateBarLabel(props); const textAnchor = getTextAnchor(props); const dominantBaseline = getDominantBaseline(props); const fadedOpacity = isFaded ? 0.3 : 1; return /*#__PURE__*/_jsx(BarLabelComponent, _extends({ textAnchor: textAnchor, dominantBaseline: dominantBaseline, opacity: hidden ? 0 : fadedOpacity }, otherProps, animatedProps)); } function getTextAnchor({ placement, layout, xOrigin, x }) { if (placement === 'outside') { if (layout === 'horizontal') { return x < xOrigin ? 'end' : 'start'; } return 'middle'; } return 'middle'; } function getDominantBaseline({ placement, layout, yOrigin, y }) { if (placement === 'outside') { if (layout === 'horizontal') { return 'central'; } return y < yOrigin ? 'auto' : 'hanging'; } return 'central'; } process.env.NODE_ENV !== "production" ? BarLabel.propTypes = { // ----------------------------- Warning -------------------------------- // | These PropTypes are generated from the TypeScript type definitions | // | To update them edit the TypeScript types and run "pnpm proptypes" | // ---------------------------------------------------------------------- classes: PropTypes.object, dataIndex: PropTypes.number.isRequired, /** * Height of the bar this label belongs to. */ height: PropTypes.number.isRequired, /** * If true, the bar label is hidden. */ hidden: PropTypes.bool, isFaded: PropTypes.bool.isRequired, isHighlighted: PropTypes.bool.isRequired, layout: PropTypes.oneOf(['horizontal', 'vertical']).isRequired, /** * The placement of the bar label. * It controls whether the label is rendered in the center or outside the bar. * @default 'center' */ placement: PropTypes.oneOf(['center', 'outside']), seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired, skipAnimation: PropTypes.bool.isRequired, /** * Width of the bar this label belongs to. */ width: PropTypes.number.isRequired, /** * Position in the x-axis of the bar this label belongs to. */ x: PropTypes.number.isRequired, /** * The x-coordinate of the stack this bar label belongs to. */ xOrigin: PropTypes.number.isRequired, /** * Position in the y-axis of the bar this label belongs to. */ y: PropTypes.number.isRequired, /** * The y-coordinate of the stack this bar label belongs to. */ yOrigin: PropTypes.number.isRequired } : void 0; export { BarLabel };