"use client"; import { useMemo } from "react"; import { Bar, BarChart, CartesianGrid, Cell, LabelList, XAxis, YAxis, } from "recharts"; import { scaleSymlog } from "d3-scale"; import { ChartContainer, ChartTooltip, ChartTooltipContent, type ChartConfig, } from "../ui/chart"; import { ChartMessage } from "./ChartMessage"; import type { HomepageSummary } from "../../lib/homepageSummary"; import { SYMLOG_CONSTANT, compactNumber, symlogTicks, type ChartState, } from "../../lib/homepageChart"; import { buildRanking } from "../../lib/homepageChartData"; const TOP_N = 12; // Ranked horizontal bars — an aggregate over the window, not a time series. With // one bar at ~27k and a floor in the hundreds, a symlog value axis keeps the // small channels readable next to the leader (linear via the scale toggle). export function LeaderboardChart({ summary, state, }: { summary: HomepageSummary; state: ChartState; }) { const { rows, max } = useMemo( () => buildRanking(summary, state, TOP_N), [summary, state], ); const symlog = useMemo(() => scaleSymlog().constant(SYMLOG_CONSTANT), []); if (rows.length === 0) { return No data for this view yet.; } const config: ChartConfig = { value: { label: "Transcripts" } }; const isSymlog = state.scale === "symlog"; const domainMax = Math.max(10, max); const ticks = isSymlog ? symlogTicks(domainMax) : undefined; return ( compactNumber(v)} tickLine={false} axisLine={false} tick={{ fill: "var(--chart-axis)", fontSize: 12 }} /> } /> {rows.map((r) => ( ))} compactNumber(v)} className="fill-[var(--muted-foreground)] text-xs tabular-nums" /> ); }