react-native-chart-kit
Version:
Beautiful React Native charts for dashboards, reports, and data-rich mobile apps.
19 lines (18 loc) • 1.67 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { getFontFamilyProps } from "../line/text";
const tooltipLineHeight = 18;
export const renderDefaultBarChartTooltip = ({ config, height, width, x, y, bar }, renderer) => {
if (renderer.capabilities?.text === false) {
return null;
}
const contentX = x + config.padding;
const hasLabel = bar.xLabel.trim().length > 0;
const labelY = y + config.padding + config.labelFontSize;
const valueY = hasLabel
? labelY + tooltipLineHeight
: y + config.padding + config.fontSize;
const hasShadow = config.shadowOpacity > 0;
const { Circle, Group, Rect, Text } = renderer;
const valueText = `${bar.seriesLabel}: ${bar.formattedValue}`;
return (_jsxs(Group, { children: [hasShadow ? (_jsx(Rect, { x: x + config.shadowOffsetX, y: y + config.shadowOffsetY, width: width, height: height, rx: config.borderRadius, fill: config.shadowColor, opacity: config.shadowOpacity })) : null, _jsx(Rect, { x: x, y: y, width: width, height: height, rx: config.borderRadius, fill: config.backgroundColor, stroke: config.borderColor, strokeOpacity: 0.2, strokeWidth: 1 }), hasLabel ? (_jsx(Text, { x: contentX, y: labelY, fill: config.labelColor, fontSize: config.labelFontSize, fontWeight: "600", text: bar.xLabel, ...getFontFamilyProps(config.fontFamily), children: bar.xLabel })) : null, _jsx(Circle, { cx: contentX + 3, cy: valueY - config.fontSize * 0.32, r: 3, fill: bar.color }), _jsx(Text, { x: contentX + 12, y: valueY, fill: config.textColor, fontSize: config.fontSize, text: valueText, ...getFontFamilyProps(config.fontFamily), children: valueText })] }));
};