Fix cutoff is not defined (charts fail silently) + add Today/3d ranges + vendor Chart.js#103
Open
MatrixCODEBreak wants to merge 1 commit into
Conversation
…t.js Three independent improvements; maintainer feel free to cherry-pick. 1. **Fix `ReferenceError: cutoff is not defined`** (the headline bug). applyFilter() filters daily_by_model on start/end but the hourly filter references `cutoff`, never declared. Causes charts to silently fail — loadData() aborts and panels render empty even though API data is fully populated. 2. **Add Today and 3d range buttons.** Shortest range was This Week / 7d. Both new buttons added with range bounds + labels. 3. **Vendor Chart.js locally + no-cache headers on /.** CDN sometimes blocked by ad-blockers / corp firewalls. Self-hosting chart.umd.min.js from /static/ removes the dependency. Cache- Control: no-store on / prevents stuck-cached old HTML. Verified locally: zero console errors via Playwright headless, all charts render, new buttons filter correctly.
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.
What
Three independent improvements; please cherry-pick if you only want one.
1. Fix `ReferenceError: cutoff is not defined` (the headline bug)
`applyFilter()` filters `daily_by_model` on `start`/`end` but the hourly filter just below references `cutoff`, which is never declared. This blew up every page load — `loadData()` threw mid-flight and all panels rendered empty even though the API and the database were fully populated. Spent a while chasing CDN/network issues before noticing the actual JS error in the browser console.
Fix: use the same `(!start || r.day >= start) && (!end || r.day <= end)` shape the daily filter already uses (line 745).
2. Add Today and 3d range buttons
Shortest range was "This Week" / "7d". Wanted to see same-day burn at a glance, especially during heavy work windows. Added `today` and `3d` to the range button row + `getRangeBounds()` + `RANGE_LABELS` / `RANGE_TICKS`.
3. Vendor Chart.js locally + no-cache headers on `/`
Multiple users in private setups (ad blockers like uBlock, corp firewalls, Brave shields) silently lose the jsdelivr CDN, which makes `chart.umd.min.js` 404 inside the browser. Page loads, charts don't render, no error visible without F12. Self-hosting `chart.umd.min.js` from `/static/` removes the dependency entirely.
Also added `Cache-Control: no-store` on `/` — without it, future template changes get stuck behind browser-cached old HTML (which is how I diagnosed the `cutoff` bug in the first place; my fix wasn't taking effect until I forced a hard refresh).
Verification
Loaded with Playwright headless: zero console errors, all charts render correctly, new range buttons filter the data set as expected.
Notes
Built this on top of your dashboard while debugging cost-routing on a heavy Claude Code project. Thanks for the tool — it's been the single most useful piece of observability for that work.