UNPKG

@patternfly/react-charts

Version:

This library provides a set of React chart components for use with the PatternFly reference implementation.

41 lines 2.08 kB
import { __rest } from "tslib"; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { cloneElement, Fragment } from 'react'; import hoistNonReactStatics from 'hoist-non-react-statics'; import defaults from 'lodash/defaults'; import { Helpers, VictoryLabel } from 'victory-core'; import { ChartLabel } from '../ChartLabel/ChartLabel'; import { ChartLegendTooltipStyles } from '../ChartTheme/ChartStyles'; export const ChartLegendTooltipLabel = (_a) => { var { dx = 0, index = 0, legendData, legendLabelComponent = _jsx(ChartLabel, {}), style, text, textAnchor = 'end', valueLabelComponent = _jsx(ChartLabel, {}), x, y } = _a, // destructure last rest = __rest(_a, ["dx", "index", "legendData", "legendLabelComponent", "style", "text", "textAnchor", "valueLabelComponent", "x", "y"]); const getStyle = (styles) => { const applyDefaultStyle = (customStyle) => defaults(Object.assign({}, customStyle), { fill: ChartLegendTooltipStyles.label.fill }); return Array.isArray(styles) ? styles.map(applyDefaultStyle) : applyDefaultStyle(styles); }; const getLegendLabelComponent = () => { const label = legendData && legendData.length ? legendData[index].name : undefined; return cloneElement(legendLabelComponent, { style: getStyle({}), text: label, textAnchor: 'start', x, y }); }; const getValueLabelComponent = () => { const _x = x + Helpers.evaluateProp(dx, undefined); return cloneElement(valueLabelComponent, Object.assign({ style: getStyle(style), text, textAnchor, x: _x, y }, rest)); }; const legendLabel = getLegendLabelComponent(); const valueLabel = getValueLabelComponent(); return (_jsxs(Fragment, { children: [legendLabel, valueLabel] })); }; ChartLegendTooltipLabel.displayName = 'ChartLegendTooltipLabel'; // Note: VictoryLabel.role must be hoisted hoistNonReactStatics(ChartLegendTooltipLabel, VictoryLabel); //# sourceMappingURL=ChartLegendTooltipLabel.js.map