From 191fca35d1eb8c3562febdc0160f50f453b43ea9 Mon Sep 17 00:00:00 2001 From: iamtoruk Date: Fri, 10 Jul 2026 16:10:32 -0700 Subject: [PATCH] feat(app): Overview capsule chart + list row components CapsuleChart renders one .c bar per history.daily entry with the peak day gradient-glowed (.c.hi) and runner-up plain blue (.c.hi2); axis top is the peak day's spend. ListRow is the reusable .li row (rank, model .mdot, title+sub, value, chevron) plus seriesColorForModel() for the palette dots. --- app/renderer/components/CapsuleChart.tsx | 79 ++++++++++++++++++++++++ app/renderer/components/ListRow.tsx | 51 +++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 app/renderer/components/CapsuleChart.tsx create mode 100644 app/renderer/components/ListRow.tsx diff --git a/app/renderer/components/CapsuleChart.tsx b/app/renderer/components/CapsuleChart.tsx new file mode 100644 index 00000000..05d0c47c --- /dev/null +++ b/app/renderer/components/CapsuleChart.tsx @@ -0,0 +1,79 @@ +import type { DailyHistoryEntry } from '../lib/types' + +/** "YYYY-MM-DD" → "Mon D" (parsed as a local date to avoid a TZ day-shift). */ +export function fmtDay(key: string): string { + const [y, m, d] = key.split('-').map(Number) + if (!y || !m || !d) return key + return new Date(y, m - 1, d).toLocaleDateString('en-US', { month: 'short', day: 'numeric' }) +} + +/** Axis-label formatting: whole dollars once we're past $10, else one decimal. */ +function fmtAxis(v: number): string { + if (v >= 10) return String(Math.round(v)) + return v.toFixed(1) +} + +/** + * The daily-spend capsule chart. One `.c` bar per `history.daily` entry, height + * = cost / axisMax where axisMax is the peak day's spend, so the tallest bar + * fills the plot (CSS `min-height` shows a stub for $0 days). The peak day gets + * the gradient+glow treatment (`.c.hi`), the runner-up plain blue (`.c.hi2`). + * Gridline labels read peak / half / zero; the day axis shows up to five evenly + * spaced dates. + */ +export function CapsuleChart({ daily }: { daily: DailyHistoryEntry[] }) { + const costs = daily.map(d => d.cost) + const max = costs.reduce((m, c) => (c > m ? c : m), 0) + const axisMax = max > 0 ? max : 1 + + // Peak (.c.hi) = highest-cost day, runner-up (.c.hi2) = second highest. Strict + // `>` keeps the earliest day on ties and never highlights a $0 day. + let peak = -1 + let second = -1 + costs.forEach((c, i) => { + if (c <= 0) return + if (peak === -1 || c > costs[peak]) { + second = peak + peak = i + } else if (second === -1 || c > costs[second]) { + second = i + } + }) + + const n = daily.length + const labelIdx = [ + ...new Set(n <= 5 ? daily.map((_, i) => i) : [0, 0.25, 0.5, 0.75, 1].map(f => Math.round(f * (n - 1)))), + ] + + return ( + <> +
+
+ {fmtAxis(axisMax)} +
+
+ {fmtAxis(axisMax / 2)} +
+
+ 0 +
+
+ {costs.map((c, i) => { + const cls = i === peak ? 'c hi' : i === second ? 'c hi2' : 'c' + const height = Math.max(0, Math.min(100, (c / axisMax) * 100)) + return ( +
+
+
+ ) + })} +
+
+
+ {labelIdx.map(i => ( + {fmtDay(daily[i].date)} + ))} +
+ + ) +} diff --git a/app/renderer/components/ListRow.tsx b/app/renderer/components/ListRow.tsx new file mode 100644 index 00000000..c1b5cbc1 --- /dev/null +++ b/app/renderer/components/ListRow.tsx @@ -0,0 +1,51 @@ +import type { CSSProperties, ReactNode } from 'react' + +/** + * Series-dot colour for a model name, per the wireframe palette + * (blue=Opus, purple=Sonnet, lavender=Haiku, cyan=GPT/Codex). Unknown or + * unmatched models fall back to a neutral slate rather than a fabricated series. + */ +export function seriesColorForModel(model?: string): string { + const m = (model ?? '').toLowerCase() + if (m.includes('opus')) return 'var(--blue)' + if (m.includes('sonnet')) return 'var(--purple)' + if (m.includes('haiku')) return 'var(--lav)' + if (m.includes('gpt') || m.includes('codex')) return 'var(--cyan)' + return 'var(--t3)' +} + +/** + * A `.li` list row: optional rank `.no`, optional model series `.mdot`, a + * title + sub line `.lx`, an optional right-aligned `.val`, and the chevron. + * Presentational; used by Overview's "most expensive sessions" and reusable by + * later sections. + */ +export function ListRow({ + no, + dotColor, + title, + sub, + value, + valueClass, +}: { + no?: ReactNode + dotColor?: string + title: ReactNode + sub?: ReactNode + value?: ReactNode + valueClass?: string +}) { + const dot: CSSProperties | undefined = dotColor ? { background: dotColor } : undefined + return ( +
+ {no !== undefined && {no}} + {dotColor !== undefined && } +
+ {title} + {sub !== undefined && {sub}} +
+ {value !== undefined && {value}} + › +
+ ) +}