react-native-chart-kit
Version:
Beautiful React Native charts for dashboards, reports, and data-rich mobile apps.
53 lines (52 loc) • 1.8 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { createSvgTestId } from "../../../svg-renderer/index";
export const resolveDotColor = ({ color, fallback, seriesColor, theme }) => {
if (color === "background") {
return theme.background;
}
if (color === "series") {
return seriesColor;
}
return color || fallback;
};
const createDiamondPath = ({ size, x, y }) => {
const radius = size / 2;
return [
`M ${x} ${y - radius}`,
`L ${x + radius} ${y}`,
`L ${x} ${y + radius}`,
`L ${x - radius} ${y}`,
"Z"
].join(" ");
};
export const renderDefaultDot = ({ color, config, point, theme }, renderer) => {
const fill = resolveDotColor({
color: config.fill,
fallback: theme.background,
seriesColor: color,
theme
});
const stroke = resolveDotColor({
color: config.stroke,
fallback: color,
seriesColor: color,
theme
});
const dotKey = `dot-${point.seriesKey}-${point.index}`;
const commonProps = {
testID: createSvgTestId("line-dot", point.seriesKey, point.index),
fill,
opacity: config.opacity,
stroke,
strokeWidth: config.strokeWidth
};
const { Circle, Path, Rect } = renderer;
const size = config.radius * 2;
if (config.shape === "square") {
return (_jsx(Rect, { x: point.x - size / 2, y: point.y - size / 2, width: size, height: size, rx: Math.min(3, config.radius * 0.45), ...commonProps }, dotKey));
}
if (config.shape === "diamond") {
return (_jsx(Path, { d: createDiamondPath({ x: point.x, y: point.y, size }), ...commonProps }, dotKey));
}
return (_jsx(Circle, { cx: point.x, cy: point.y, r: config.radius, ...commonProps }, dotKey));
};