UNPKG

react-sparklines-ts

Version:

Beautiful and expressive Sparklines component for React (continued)

23 lines (22 loc) 931 B
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; function lastDirection(points) { Math.sign = Math.sign || ((x) => (x > 0 ? 1 : -1)); return points.length < 2 ? 0 : Math.sign(points[points.length - 2].y - points[points.length - 1].y); } export default function SparklinesSpots(props) { let { size, spotColors } = props; const { points, width, height, style } = props; if (!size) size = 2; if (!spotColors) spotColors = { "-1": "red", "0": "black", "1": "green", }; const startSpot = (_jsx("circle", { cx: points[0].x, cy: points[0].y, r: size, style: style })); const endSpot = (_jsx("circle", { cx: points[points.length - 1].x, cy: points[points.length - 1].y, r: size, style: style || { fill: spotColors[lastDirection(points)] } })); return (_jsxs("g", { children: [style && startSpot, endSpot] })); }