fix(dashboard): step the CPR levels; whitespace never broke the line - #178
Merged
Merged
Conversation
Per-day CPR (#174) drew a shallow DIAGONAL from one day's levels to the next on 1m and 5m instead of separate horizontal bands. The cause is in the library, not the data. lightweight-charts 5.2.1 runs `rows.filter(hasValue)` in its data layer, so the whitespace point the bands carried -- a time with no value, meant to break the stroke -- never reached the series. The line was one continuous path and the gap never existed. The whitespace contributed exactly one empty column. Two things stretched that artifact from a step into a long diagonal: a band's `to` of 15:29 is not a 5-minute bucket boundary, and bands were admitted on interval overlap alone, so a CSV older than the live window produced a run of bands with no candles under them. Each level now carries ONE point per band, placed on the first loaded candle at or after the band's start, drawn with `LineType.WithSteps` -- the renderer's step branch is `lineTo(x, previousY)` then `lineTo(x, y)`, so a slope is unreachable. A band with no loaded candle is skipped, which leaves the previous level running rather than drawing into empty space, and every point sits on a real bar time so the CPR series adds no columns to the shared scale. Measured on a scratch server against the five-year CSV, in the shape that reproduces it -- history ending days before the live window. Summed vertical travel of each level line across the view, before -> after: pivot 43.4px -> 0.0, BC/TC 47.9 -> 0.0, PDH/PDL 50.8 -> 0.2, R1/R2 22.5 -> 0.0, S1/S2 66.3 -> 0.0. 1m, 5m and Daily all step cleanly and the group toggles still follow immediately. ADR-0017 asserted the whitespace mechanism, so it carries a correction rather than a quiet edit. The LLD gains both traps, including why the #174 pixel check passed: it measured column HEIGHT, which a shallow diagonal satisfies by construction. Co-Authored-By: Claude Opus 5 <noreply@anthropic.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.
What
Per-day CPR (#174) drew a shallow diagonal from one day's levels to the next on the 1m and 5m timeframes instead of separate horizontal bands. This fixes it.
Root cause
Proven from the vendored bundle, not inferred. A whitespace point cannot break a line series in lightweight-charts 5.2.1 — the data layer strips it before the series ever sees it:
A whitespace row carries no value tuple (
Wt), sofilter(_s)removes it. The renderer then strokes one continuous path. The whitespace contributed exactly one thing: a spare time-scale column.Two things stretched the artifact from a short step into a long diagonal:
tois 15:29 and 5-minute buckets end at 15:25, so every session injected columns no candle occupies.The fix
Each level now carries one point per band, placed on the first loaded candle at or after the band's start, drawn with
LineType.WithSteps. The renderer's step branch islineTo(x, previousY)thenlineTo(x, y)— horizontal, then vertical — so a slope is unreachable in it. A band with no loaded candle is skipped, which leaves the previous level running rather than drawing it into empty space, and every point sits on a time the candle series already owns, so the CPR series adds zero columns to the shared scale.Rejected: a custom
ISeriesPrimitive(true gaps, ~100 lines of new rendering code and a new failure surface) and one series per band (rebuilds hundreds of series on every scroll).Verification
Scratch server on port 8799 against the real five-year CSV, in the shape that reproduces it — history ending days before the live window, so the chart splices across sessions with candles and no band.
Summed vertical travel of each level line across the view, before → after:
1m, 5m and Daily all step cleanly; Daily still shows monthly bands and its caption still matches the drawn level; the group toggles still follow immediately.
Gates: both unittest suites (606 + 28), pytest (1,580), coverage policy + 74.2 % total locally, ruff, mypy ×2, compileall, bandit as CI runs it, pre-commit,
node --check.Notes worth reading
test_the_cpr_levels_are_drawn_as_steps_and_never_rely_on_whitespaceis a source assertion — there is no JS runtime here. It fails on the pre-fix script (verified) and exists so a future edit that "restores the gap" with a whitespace point fails here instead of shipping the diagonal back.#ef5f5f/#35c46b, which are R1/R2 and S1/S2 and the candle colours.🤖 Generated with Claude Code