@patternfly/react-charts
Version:
This library provides a set of React chart components for use with the PatternFly reference implementation.
46 lines • 2.76 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { cloneElement, Fragment } from 'react';
import hoistNonReactStatics from 'hoist-non-react-statics';
import { VictoryBar } from 'victory-bar';
import { getComparativeMeasureData } from './utils/chart-bullet-data';
import { ChartBar } from '../ChartBar/ChartBar';
import { ChartContainer } from '../ChartContainer/ChartContainer';
import { ChartBulletStyles } from '../ChartTheme/ChartStyles';
import { ChartTooltip } from '../ChartTooltip/ChartTooltip';
import { getBulletComparativeMeasureTheme } from '../ChartUtils/chart-theme-types';
export const ChartBulletComparativeMeasure = ({ allowTooltip = true, ariaDesc, ariaTitle, barWidth = ChartBulletStyles.comparativeMeasureWidth, constrainToVisibleArea = false, data, domain, horizontal = true, labels, measureComponent = _jsx(ChartBar, {}), // Using bar instead of line for tooltip functionality
padding, standalone = true, themeColor, y,
// destructure last
theme = getBulletComparativeMeasureTheme(themeColor), height = theme.bar.height, width = theme.bar.width, labelComponent = _jsx(ChartTooltip, {}) }) => {
const computedData = getComparativeMeasureData({
data,
theme,
y
});
// Label component
//
// Note: SVG height and width are provided by ChartBullet as a workaround to support constrainToVisibleArea
const tooltip = cloneElement(labelComponent, Object.assign({ constrainToVisibleArea, dx: () => {
if (horizontal) {
return 0;
}
const result = typeof barWidth === 'function' ? barWidth(data) : barWidth;
return result / 2;
}, dy: () => {
if (!horizontal) {
return 0;
}
const result = typeof barWidth === 'function' ? barWidth(data) : barWidth;
return -(result / 2);
}, orientation: 'top' }, labelComponent.props));
const measure = computedData.map((dataPoint, index) => cloneElement(measureComponent, Object.assign({ barWidth, data: [Object.assign({}, dataPoint)], domain,
height,
horizontal, labelComponent: allowTooltip ? tooltip : undefined, labels, key: `pf-chart-bullet-comparative-measure-${index}`, padding, standalone: false, theme,
themeColor,
width }, measureComponent.props)));
return standalone ? (_jsx(ChartContainer, { desc: ariaDesc, height: height, title: ariaTitle, width: width, children: measure })) : (_jsx(Fragment, { children: measure }));
};
ChartBulletComparativeMeasure.displayName = 'ChartBulletComparativeMeasure';
// Note: VictoryBar.role must be hoisted
hoistNonReactStatics(ChartBulletComparativeMeasure, VictoryBar);
//# sourceMappingURL=ChartBulletComparativeMeasure.js.map