@mui/x-charts
Version:
The community edition of the Charts components (MUI X).
75 lines • 1.61 kB
JavaScript
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
import _extends from "@babel/runtime/helpers/esm/extends";
const _excluded = ["bars", "skipAnimation"];
import * as React from 'react';
import { useTransition } from '@react-spring/web';
import { BarLabelItem } from "./BarLabelItem.js";
import { jsx as _jsx } from "react/jsx-runtime";
const leaveStyle = ({
layout,
yOrigin,
x,
width,
y,
xOrigin,
height
}) => _extends({}, layout === 'vertical' ? {
y: yOrigin,
x: x + width / 2,
height: 0,
width
} : {
y: y + height / 2,
x: xOrigin,
height,
width: 0
});
const enterStyle = ({
x,
width,
y,
height
}) => ({
x: x + width / 2,
y: y + height / 2,
height,
width
});
/**
* @ignore - internal component.
*/
function BarLabelPlot(props) {
const {
bars,
skipAnimation
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
const barLabelTransition = useTransition(bars, {
keys: bar => `${bar.seriesId}-${bar.dataIndex}`,
from: leaveStyle,
leave: null,
enter: enterStyle,
update: enterStyle,
immediate: skipAnimation
});
return /*#__PURE__*/_jsx(React.Fragment, {
children: barLabelTransition((style, {
seriesId,
dataIndex,
color,
value,
width,
height
}) => /*#__PURE__*/_jsx(BarLabelItem, _extends({
seriesId: seriesId,
dataIndex: dataIndex,
value: value,
color: color,
width: width,
height: height
}, other, {
style: style
})))
});
}
export { BarLabelPlot };