@mui/x-charts
Version:
The community edition of MUI X Charts components.
133 lines (132 loc) • 4.78 kB
JavaScript
;
'use client';
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.BarLabel = BarLabel;
exports.BarLabelComponent = void 0;
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var React = _interopRequireWildcard(require("react"));
var _styles = require("@mui/material/styles");
var _propTypes = _interopRequireDefault(require("prop-types"));
var _useAnimateBarLabel = require("../../hooks/animation/useAnimateBarLabel");
var _barLabelClasses = require("./barLabelClasses");
var _animation = require("../../internals/animation/animation");
var _jsxRuntime = require("react/jsx-runtime");
const _excluded = ["seriesId", "dataIndex", "color", "isFaded", "isHighlighted", "classes", "skipAnimation", "layout", "xOrigin", "yOrigin", "placement", "hidden"];
const BarLabelComponent = exports.BarLabelComponent = (0, _styles.styled)('text', {
name: 'MuiBarLabel',
slot: 'Root',
overridesResolver: (_, styles) => [{
[`&.${_barLabelClasses.barLabelClasses.faded}`]: styles.faded
}, {
[`&.${_barLabelClasses.barLabelClasses.highlighted}`]: styles.highlighted
}, styles.root]
})(({
theme
}) => (0, _extends2.default)({}, theme?.typography?.body2, {
stroke: 'none',
fill: (theme.vars || theme)?.palette?.text?.primary,
transitionProperty: 'opacity, fill',
transitionDuration: `${_animation.ANIMATION_DURATION_MS}ms`,
transitionTimingFunction: _animation.ANIMATION_TIMING_FUNCTION,
pointerEvents: 'none'
}));
function BarLabel(inProps) {
const props = (0, _styles.useThemeProps)({
props: inProps,
name: 'MuiBarLabel'
});
const {
isFaded,
hidden
} = props,
otherProps = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
const animatedProps = (0, _useAnimateBarLabel.useAnimateBarLabel)(props);
const textAnchor = getTextAnchor(props);
const dominantBaseline = getDominantBaseline(props);
const fadedOpacity = isFaded ? 0.3 : 1;
return /*#__PURE__*/(0, _jsxRuntime.jsx)(BarLabelComponent, (0, _extends2.default)({
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.default.object,
dataIndex: _propTypes.default.number.isRequired,
/**
* Height of the bar this label belongs to.
*/
height: _propTypes.default.number.isRequired,
/**
* If true, the bar label is hidden.
*/
hidden: _propTypes.default.bool,
isFaded: _propTypes.default.bool.isRequired,
isHighlighted: _propTypes.default.bool.isRequired,
layout: _propTypes.default.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.default.oneOf(['center', 'outside']),
seriesId: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]).isRequired,
skipAnimation: _propTypes.default.bool.isRequired,
/**
* Width of the bar this label belongs to.
*/
width: _propTypes.default.number.isRequired,
/**
* Position in the x-axis of the bar this label belongs to.
*/
x: _propTypes.default.number.isRequired,
/**
* The x-coordinate of the stack this bar label belongs to.
*/
xOrigin: _propTypes.default.number.isRequired,
/**
* Position in the y-axis of the bar this label belongs to.
*/
y: _propTypes.default.number.isRequired,
/**
* The y-coordinate of the stack this bar label belongs to.
*/
yOrigin: _propTypes.default.number.isRequired
} : void 0;