Skip to content

Improve cost chart detail rendering#8

Merged
iam-brain merged 1 commit intomainfrom
bryan/cost-chart-detail
Mar 13, 2026
Merged

Improve cost chart detail rendering#8
iam-brain merged 1 commit intomainfrom
bryan/cost-chart-detail

Conversation

@iam-brain
Copy link
Owner

@iam-brain iam-brain commented Mar 12, 2026

Summary

This PR upgrades the cost history chart hover detail from a single summary line into a structured per-model breakdown, while keeping the menu’s overall size stable as the pointer moves across days with very different usage patterns.

On main, the selected day can show its total cost and tokens, but the model-level context is compressed into one secondary text line and the upstream cost pipeline only keeps the top three breakdown entries. That makes busy days harder to understand once spend is split across several models, and it means the chart cannot fully explain where a day’s cost or token volume came from.

This change keeps richer per-model breakdown data intact from local scanning through decoding and CLI payload generation, then lets the chart decide how much of that information to render.

Why this approach

  • The menu should stay physically stable even after adding richer hover detail. Reserving detail height from the busiest rendered day in the loaded range avoids hover-driven resizing without permanently allocating a large empty block on quieter ranges.
  • The scanners now preserve the full sorted per-model breakdown instead of truncating it early. That keeps the data layer faithful to what was actually observed and leaves presentation decisions, like showing a limited number of rows plus an overflow summary, in the view where those rules belong.
  • Per-model token totals are threaded through the existing cost pipeline instead of being recomputed in the chart. That keeps the detail rows consistent with the same scanner output that already drives daily totals and cost calculations, and it keeps local consumers aligned on one payload shape.
  • The view still caps visible detail density. Rendering every model row on a busy day would make the menu too tall, so the chart shows the highest-signal rows first and collapses the remainder into a single aggregate row.

What changed

  • CostHistoryChartMenuView now renders a structured detail block beneath the chart:
    • a primary line for the selected day
    • per-model rows with vertical accent bars
    • per-row cost and token totals when available
    • an overflow row summarizing additional hidden models on dense days
  • The chart computes the maximum rendered breakdown row count across the currently loaded dataset and reserves that detail height up front, so the menu does not jump as hover moves between sparse and busy days.
  • CostUsageDailyReport.ModelBreakdown now carries totalTokens in addition to cost.
  • Both local cost scanners now keep the full per-model breakdown for each day instead of trimming to the top three entries, and they sort rows by cost, then token volume, then model name so the display order is deterministic.
  • The CLI cost payload now includes per-model token totals, keeping the local JSON shape aligned with what the menu consumes.
  • Focused regression coverage was added for decoding modelBreakdowns.totalTokens, preserving full model breakdowns with token totals in scanner output, and encoding the updated CLI payload.

What intentionally did not change

  • No pricing changes and no changes to day-level cost totals.
  • No scanner-side truncation rules for the new hover layout; row limiting remains a presentation concern in the menu view.
  • No changes to historical range selection or the chart’s core bar rendering outside the detail treatment.

Verification

  • ./Scripts/compile_and_run.sh
  • pnpm check

@iam-brain iam-brain merged commit cb77d5b into main Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant