Skip to content

Add stacked daily bars and a 7-day window to Total Spend - #123

Open
mstallone wants to merge 1 commit into
mainfrom
feat/total-spend-charts
Open

Add stacked daily bars and a 7-day window to Total Spend#123
mstallone wants to merge 1 commit into
mainfrom
feat/total-spend-charts

Conversation

@mstallone

Copy link
Copy Markdown
Owner

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

  • The card only showed a pie of period composition, so spend over time was hard to read.
  • The middle period was Yesterday — one day — not a week of calendar days.
  • 30-day totals had no day-by-day breakdown on the card.

What this changes

  • Period switcher is Today / 7 Days / 30 Days. Existing installs that stored Yesterday land on 7 Days.
  • A pie/bar capsule next to the period picker; both choices persist.
  • Bar view is one stacked bar per calendar day (idle days stay as a thin stub). Cost and Tokens stack by provider; Cost/MTok is a blended rate per day because rates cannot stack.
  • Pie and bars both prefer daily usage history so they share one window; Today still falls back to the spend tile when history is missing.
  • iCloud-merged daily series is kept on the rendered snapshot so 7-day bars include peer Macs.
  • Share screenshot follows the on-screen chart kind.

Heads-up

  • Per-provider Today / Yesterday / Last 30 Days rows are not part of this change.
  • 30 Days uses the same history window as Usage Trend (today plus previous days), so the stacked bars add up to the pie.

Tests

  • swift test --filter TotalSpendAggregatorTests --filter UsageHistoryAggregatorTests

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.
@mstallone
mstallone requested a lite review from Copilot September 5, 2026 03:11
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 TotalSpendAggregator to 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.

Comment on lines +186 to +188
case .costPerMtok:
guard totalUSD > 0, totalTokens > 0 else { return 0 }
return (totalUSD / totalTokens) * 1_000_000
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.

2 participants