"use client"; import React from "react"; // Fixed categorical order from the validated reference palette (dataviz skill, // references/palette.md) — never cycled or reassigned per-render, so the same category // always gets the same color across a session. export const CATEGORICAL_COLORS = ["#2a78d6", "#eb6834", "#1baf7a", "#eda100", "#e87ba4", "#4a3aa7", "#e34948"]; export type BarDatum = { label: string; value: number }; // A simple, dependency-free horizontal bar list: thin rounded track, filled bar, direct value // label. Suited to comparing a handful of categories' magnitude (the job most reports need) — // per the dataviz skill's form heuristic, magnitude-by-category is exactly a bar chart's job. export function HorizontalBarChart({ data, valueFormatter, labelWidthClass = "w-28", }: { data: BarDatum[]; valueFormatter?: (v: number) => string; labelWidthClass?: string; }) { const max = Math.max(1, ...data.map(d => Math.abs(d.value))); const fmt = valueFormatter || ((v: number) => String(v)); return (
{data.map((d, i) => (
{d.label}
0 ? 2 : 0, (Math.abs(d.value) / max) * 100)}%`, backgroundColor: CATEGORICAL_COLORS[i % CATEGORICAL_COLORS.length] }} />
{fmt(d.value)}
))} {data.length === 0 &&
No data to chart.
}
); }