Add stacked daily bars and a 7-day window to Total Spend - #123
Conversation
The card only had a pie and Yesterday. Switch Yesterday to 7 Days and add a pie/bar toggle so 7- and 30-day views can show one stacked bar per calendar day.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
There was a problem hiding this comment.
🟡 Changes recommended
The daily Cost/MTok bar computation can blend across providers that don’t have both cost and tokens on a given day, producing incorrect per-day rates.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR upgrades the dashboard’s cross-provider Total Spend card to support a new stacked daily bar visualization and updates the middle period from Yesterday to a 7-day calendar window, while keeping share-card exports aligned with what’s on screen.
Changes:
- Adds a persisted pie vs. stacked-daily-bars switcher and updates the period picker to Today / 7 Days / 30 Days (with legacy “Yesterday” mapped to 7 Days).
- Extends
TotalSpendAggregatorto produce a calendar-true daily series (including idle days) and prefer snapshot daily history for both pie and bars. - Updates share rendering and docs to reflect the new chart modes and period behavior.
File summaries
| File | Description |
|---|---|
| Tests/RunwayTests/UsageHistoryAggregatorTests.swift | Asserts rendered snapshots retain the merged usageHistory for downstream consumers (e.g., Total Spend). |
| Tests/RunwayTests/TotalSpendAggregatorTests.swift | Adds coverage for the new 7-day period window and bar-series behavior (idle days, window bounds, fallbacks). |
| Sources/Runway/Views/TotalSpendShareCardView.swift | Switches share-card body rendering to the unified chart body (pie or bars). |
| Sources/Runway/Views/TotalSpendCard.swift | Adds chart-kind persistence + picker UI and wires share/export to include the chart kind. |
| Sources/Runway/Views/TotalSpendBarChart.swift | Introduces TotalSpendChartBody, stacked bar rendering, and a shared legend/formatting surface. |
| Sources/Runway/Support/TotalSpendAggregator.swift | Adds 7-day period support, daily window generation, daily-series aggregation, and chart-kind/metric helpers. |
| Sources/Runway/Support/ShareCardRenderer.swift | Threads chartKind into Total Spend share rendering so exports match the live card. |
| Sources/Runway/Services/UsageHistoryAggregator.swift | Ensures the rendered snapshot carries usageHistory in addition to derived metric lines. |
| docs/dashboard.md | Updates dashboard documentation for the new 7-day window and pie vs. stacked-bars chart modes. |
Review details
- Files reviewed: 9/9 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| case .costPerMtok: | ||
| guard totalUSD > 0, totalTokens > 0 else { return 0 } | ||
| return (totalUSD / totalTokens) * 1_000_000 |
TL;DR
The Total Spend card can now switch between the existing pie and stacked daily bars, and Yesterday is replaced with a 7-day window. Per-provider Yesterday tiles are unchanged.
What was happening
What this changes
Heads-up
todayplus previous days), so the stacked bars add up to the pie.Tests
swift test --filter TotalSpendAggregatorTests --filter UsageHistoryAggregatorTests