feat: add projection segment on current-period bar in charts#886
Merged
Conversation
For the 'today', 'this week', and 'this month' bars, adds a semi-transparent stacked segment showing the projected remaining tokens/cost for the period, calculated as: extra = actual / fractionElapsed - actual where fractionElapsed uses minute-level precision: - day: (hours*60 + minutes) / 1440 - week: (isoWeekDay + dayFrac) / 7 (Mon=0...Sun=6) - month: (dayOfMonth - 1 + dayFrac) / daysInMonth Applies to all chart views (total, cost, model, editor, repository). Hidden in rolling-average mode. Uses same colour family as the actual bar but at 20-25% opacity so projection is visually distinct. Projection helpers are extracted to projectionUtils.ts with full unit-test coverage (18 tests). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a semi-transparent stacked "projected remaining" segment on top of the current-period bar in every chart view (today / this week / this month).
How it works
The projection formula matches the user spec:
where
fractionElapseduses minute-level precision:(hours×60 + minutes) / 1440(isoWeekDay + dayFrac) / 7(Mon=0…Sun=6)(dayOfMonth − 1 + dayFrac) / daysInMonthVisual style
rgba(54,162,235,0.6)rgba(54,162,235,0.2)rgba(34,197,94,0.6)rgba(34,197,94,0.2)rgba(200,200,200,0.25)Tooltip shows
📈 Projected (today)/📈 Projected (this week)/📈 Projected (this month).Not shown when
Files changed
src/webview/chart/projectionUtils.ts— new:getCurrentPeriodFraction()andcomputeProjectionExtra()helperssrc/webview/chart/main.ts— adds projection dataset to all 5 chart views; enables stacking on total/cost viewstest/unit/webview-chart-projection.test.ts— 18 unit tests, all passing ✅