Skip to content

feat(chart): persist period selection and compact period picker UI#595

Merged
rajbos merged 5 commits intomainfrom
rajbos/chart-period-toggle
Apr 11, 2026
Merged

feat(chart): persist period selection and compact period picker UI#595
rajbos merged 5 commits intomainfrom
rajbos/chart-period-toggle

Conversation

@rajbos
Copy link
Copy Markdown
Owner

@rajbos rajbos commented Apr 11, 2026

Summary

Two quality-of-life improvements to the chart view's period selector.

Period persistence

The chart now remembers the last period you selected (Day / Week / Month) and reopens on it the next time you open the chart.

  • lastChartPeriod field in the extension (defaults to 'day')
  • Webview posts setPeriodPreference message whenever the user switches periods
  • Extension stores it; getChartHtml() injects initialPeriod into the page data
  • bootstrap() reads initialPeriod and sets currentPeriod before first render

Compact/inline period picker

The period toggle buttons (📅 Day / 🗓️ Week / 📆 Month) have been moved from their own row above the chart into the "📊 Charts" section heading row, right-aligned. This saves roughly one full row of vertical space.

  • Buttons are smaller pill style (11 px font, 4 px/9 px padding) — still legible
  • chart-section-header flex wrapper: heading on the left, pills on the right
  • View-type toggles (Total / By Model / By Editor / By Repository) stay as-is inside the chart shell
  • Removed the old border-bottom separator that the period row used to carry

Changes

  • vscode-extension/src/extension.tslastChartPeriod field, setPeriodPreference handler, initialPeriod in HTML data
  • vscode-extension/src/webview/chart/main.tsInitialChartData.initialPeriod, bootstrap() init, switchPeriod() message, moved period toggles into section header
  • vscode-extension/src/webview/chart/styles.css.chart-section-header, .period-controls compact overrides

rajbos and others added 5 commits April 11, 2026 23:03
…ction header

- Add lastChartPeriod field to extension; defaults to 'day'
- Handle 'setPeriodPreference' message in showChart() to store chosen period
- Pass initialPeriod in getChartHtml() so chart reopens on the last-used period
- In bootstrap(), set currentPeriod from initialData.initialPeriod before render
- In switchPeriod(), post setPeriodPreference message to extension
- Move period toggle buttons from separate row into chart section header (right-aligned)
- Period pills are smaller (11px font, 4px/9px padding) and sit alongside the heading
- Saves one full row of vertical space; compact pills save screen real estate
- Add .chart-section-header flex layout and .period-controls compact overrides

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
With ~1100 session files, the old 1000-entry limit caused constant evictions
on every analysis cycle, keeping cache hit rates around 50-60%.

3000 entries gives comfortable headroom (3x current file count). Memory cost
is ~1-2 MB which is well within VS Code extension and globalState limits.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… repo view

By Model chart:
- Rank all models by total tokens for the active period
- Show top 5 models individually (largest usage first)
- Collapse remaining models into a single 'Other models' dataset (gray)
- Eliminates the wall of 20+ legend entries visible in the screenshot

By Repository chart:
- Exclude 'Unknown' entries from repository datasets and summary cards
- 'Unknown' represents sessions with no repo context (empty window chats,
  global CLI sessions, etc.) which add noise to a per-repo breakdown
- Same filter applied to repositoryTotalsMap used for the detail panel

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…orktrees

Two bugs that caused CLI sessions in worktrees to show as 'Unknown' in
the By Repository chart:

1. CLI JSONL path extraction was dead code:
   allContentReferences was defined but never populated for non-delta
   (Copilot CLI) JSONL files. The loop only read rename_session calls.
   Now also reads tool.execution_start argument values that look like
   file paths and pushes them into allContentReferences, which is then
   fed to extractRepositoryFromContentReferences as before.

2. Git worktree detection missing in workspaceHelpers.ts:
   extractRepositoryFromContentReferences only checked for .git/config
   (standard git repo). Worktrees have .git as a FILE containing
   'gitdir: <path>/.git/worktrees/<name>'. This file was unreadable as
   a directory, silently caught, and the walk continued upward past the
   repo root without finding the remote URL.
   Now also reads .git as a file, follows the gitdir pointer, resolves
   the main .git dir (2 levels up from the worktree-specific dir), and
   reads the remote URL from its config.

Bump CACHE_VERSION 37 → 38 to invalidate stale 'no repo' cache entries
so all existing CLI sessions are re-scanned on next reload.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Previously showUsageAnalysis() awaited calculateUsageAnalysisStats() before
creating the panel, causing a ~20s blank delay when the cache was cold
(e.g. while the chart was computing its 365-day background load).

Apply the same two-phase pattern used by the chart view:
- Create the webview panel immediately
- If lastUsageAnalysisStats is cached, render it instantly
- Otherwise show a loading spinner; fire calculateUsageAnalysisStats() in the
  background and push 'updateStats' to the webview when it completes
- getUsageAnalysisHtml() now accepts UsageAnalysisStats | null
- bootstrap() shows a loading message instead of 'No data available.' when
  null, since the updateStats message handler already calls renderLayout()

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rajbos rajbos merged commit 66b421c into main Apr 11, 2026
16 checks passed
@rajbos rajbos deleted the rajbos/chart-period-toggle branch April 11, 2026 21:25
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