SPB Git

spb/qwhpi Public

QHPI — Quebec Housing Price Index: quality-adjusted, hierarchically pooled housing price indexes.

Python 63.9% TypeScript 25.4% CSS 5.5% TeX 3.5% SQL 0.8% Makefile 0.5% Dockerfile 0.5%
1.2 KB · 44 lines tsx
Raw Blame History
1/**2 * =============================================================================3 * QWHPI — Quebec Weekly Housing Price Index4 * Author  : Simon-Pierre Boucher5 * Contact : contact@spboucher.ai6 * File    : web/components/Sparkline.tsx7 * Purpose : Inline SVG sparkline for stat tiles (no axes, one series).8 * =============================================================================9 */1011export default function Sparkline({12  values,13  width = 160,14  height = 40,15}: {16  values: number[];17  width?: number;18  height?: number;19}) {20  if (values.length < 2) return null;21  const min = Math.min(...values);22  const max = Math.max(...values);23  const span = max - min || 1;24  const pts = values25    .map((v, i) => {26      const x = (i / (values.length - 1)) * (width - 4) + 2;27      const y = height - 3 - ((v - min) / span) * (height - 6);28      return `${x.toFixed(1)},${y.toFixed(1)}`;29    })30    .join(" ");31  return (32    <svg width={width} height={height} role="img" aria-label="index sparkline">33      <polyline34        points={pts}35        fill="none"36        stroke="var(--series-1)"37        strokeWidth={2}38        strokeLinejoin="round"39        strokeLinecap="round"40      />41    </svg>42  );43}44