@patternfly/react-charts
Version:
This library provides a set of React chart components for use with the PatternFly reference implementation.
45 lines • 2.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChartLegendTooltipLabel = void 0;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const hoist_non_react_statics_1 = tslib_1.__importDefault(require("hoist-non-react-statics"));
const defaults_1 = tslib_1.__importDefault(require("lodash/defaults"));
const victory_core_1 = require("victory-core");
const ChartLabel_1 = require("../ChartLabel/ChartLabel");
const ChartStyles_1 = require("../ChartTheme/ChartStyles");
const ChartLegendTooltipLabel = (_a) => {
var { dx = 0, index = 0, legendData, legendLabelComponent = (0, jsx_runtime_1.jsx)(ChartLabel_1.ChartLabel, {}), style, text, textAnchor = 'end', valueLabelComponent = (0, jsx_runtime_1.jsx)(ChartLabel_1.ChartLabel, {}), x, y } = _a,
// destructure last
rest = tslib_1.__rest(_a, ["dx", "index", "legendData", "legendLabelComponent", "style", "text", "textAnchor", "valueLabelComponent", "x", "y"]);
const getStyle = (styles) => {
const applyDefaultStyle = (customStyle) => (0, defaults_1.default)(Object.assign({}, customStyle), {
fill: ChartStyles_1.ChartLegendTooltipStyles.label.fill
});
return Array.isArray(styles) ? styles.map(applyDefaultStyle) : applyDefaultStyle(styles);
};
const getLegendLabelComponent = () => {
const label = legendData && legendData.length ? legendData[index].name : undefined;
return (0, react_1.cloneElement)(legendLabelComponent, {
style: getStyle({}),
text: label,
textAnchor: 'start',
x,
y
});
};
const getValueLabelComponent = () => {
const _x = x + victory_core_1.Helpers.evaluateProp(dx, undefined);
return (0, react_1.cloneElement)(valueLabelComponent, Object.assign({ style: getStyle(style), text,
textAnchor, x: _x, y }, rest));
};
const legendLabel = getLegendLabelComponent();
const valueLabel = getValueLabelComponent();
return ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [legendLabel, valueLabel] }));
};
exports.ChartLegendTooltipLabel = ChartLegendTooltipLabel;
exports.ChartLegendTooltipLabel.displayName = 'ChartLegendTooltipLabel';
// Note: VictoryLabel.role must be hoisted
(0, hoist_non_react_statics_1.default)(exports.ChartLegendTooltipLabel, victory_core_1.VictoryLabel);
//# sourceMappingURL=ChartLegendTooltipLabel.js.map