UNPKG

react-sparklines-ts

Version:

Beautiful and expressive Sparklines component for React (continued)

16 lines (15 loc) 787 B
import { jsx as _jsx } from "react/jsx-runtime"; export default function SparklinesBars(props) { let { style } = props; const { points, height, barWidth, margin, onMouseMove } = props; if (!style) { style = { fill: "slategray" }; } const strokeWidth = 1 * (style?.strokeWidth || 0); const marginWidth = margin ? 2 * margin : 0; const width = barWidth || (points && points.length >= 2 ? Math.max(0, points[1].x - points[0].x - strokeWidth - marginWidth) : 0); return (_jsx("g", { transform: "scale(1,-1)", children: points.map((p, i) => (_jsx("rect", { x: p.x - (width + strokeWidth) / 2, y: -height, width: width, height: Math.max(0, height - p.y), style: style, onMouseMove: (e) => onMouseMove?.(p) }, i))) })); }