Skip to content

fix(chart): align road risers with same-day datapoint risers - #347

Merged
narthur merged 3 commits into
mainfrom
fix/chart-derail-riser-alignment
Jul 23, 2026
Merged

fix(chart): align road risers with same-day datapoint risers#347
narthur merged 3 commits into
mainfrom
fix/chart-derail-riser-alignment

Conversation

@narthur

@narthur narthur commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

What

Make buzz view's goal-progress chart match Beeminder's own graph at a derailment: the bright red line's vertical jump and the same-day datapoint's vertical riser now draw in the same column (overlapping), instead of several columns apart.

Why it looked wrong

Beeminder day-snaps both the road (roadall) knots and the datapoints onto one shared local-midnight grid before plotting, so a derail's road step and its #DERAIL datapoint line up. Buzz did neither:

  • Road knots kept their raw mid-day (deadline-aligned) timestamps, while datapoints were bucketed to local midnight — so a road step and a same-day datapoint landed in different columns.
  • The road was sampled at each column's left edge while datapoints bucket to the column at-or-before them (int truncation), adding a further one-column offset.

Result: on narthur/abed (a real derailment — road jumps 30 → 10091 on Jul 20, #DERAIL datapoint on the same day) the red riser sat 4 columns right of the blue one.

The fix

  1. daysnapRoad — floor every parsed road segment boundary to local midnight (beebrain's daysnap equivalent), and recompute slopePerDay from the snapped boundaries.
  2. Right-edge column sampling in roadValuesForTimeframe — sample each column at its right edge so a day-snapped knot's value change lands in the same column as a same-day datapoint node. The last column is clamped to endTime so the rightmost ("today") column never shows a value extrapolated past the window.

Before → after (real narthur/abed chart)

Before — stray red riser offset right of the blue one:

before

After — the red road riser is hidden directly behind the blue datapoint riser (same column; blue drawn on top), exactly as on Beeminder's graph:

   10149 ┤                                            ●──────●──────●──────────
    9134 ┤                                            │
     ...                                              │
       0 ┼●─────●─────●─────────────────────────●─────╯
          ┬                      ┬                      ┬                      ┬
          Jul 13              Jul 16                 Jul 20               Jul 23

(No stray red segment: the road step now coincides with the datapoint riser and is overdrawn by blue.)

Notes

  • Right-edge sampling is a deliberate whole-road convention (matches the datapoint columns); at terminal resolution the sub-column shift on sloped roads is invisible — it only matters at vertical jumps, which is exactly where it makes the chart correct.
  • This does not widen the chart window into the future — Beeminder's default graph also shows some future road, but that's a separate change.

Test plan

  • go test ./... — green.
  • New/updated tests: TestRoadStepAlignsWithSameDayDatapoint (road step and same-day datapoint node share a column, at two widths), TestDaysnapRoad (flooring, vertical-step equality, sub-day collapse, slopePerDay recompute), TestRoadValuesForTimeframe (right-edge sampling + last-column clamp regression case).
  • Verified by rendering the real narthur/abed goal before/after.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved chart alignment by ensuring road changes and datapoints that occur on the same day appear in the same column.
    • Corrected road sampling at chart column boundaries.
    • Prevented chart values from extending beyond the selected timeframe.

narthur and others added 3 commits July 23, 2026 15:00
Day-snap bright-red-line knots onto the local-midnight day grid the
datapoints are bucketed on (mirroring beebrain's stampIn/daysnap), and
sample each chart column at its right edge so a knot's value change
lands in the same column as a same-day datapoint node. Without this a
derailment's road jump — stored at a mid-day knot time — drew several
columns away from its #DERAIL datapoint instead of overlapping as on
Beeminder's own graph.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Clamp roadValuesForTimeframe's last-column sample to endTime so the
rightmost column never shows a road value extrapolated past the window
(auto-applied low-risk: overshoot clamp + regression test, daysnapRoad
unit test, slices.IndexFunc in new test). Recompute slopePerDay from
snapped boundaries in daysnapRoad so valueAt's before-start
extrapolation can't use a stale pre-snap slope.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…stDaysnapRoad

(auto-applied low-risk: parsed segments share exact boundary floats, so
the check only re-verified pure-function determinism)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: PinePeakDigital/coderabbit/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 4358ebe3-bf83-470f-a11a-727e8cc992ca

📥 Commits

Reviewing files that changed from the base of the PR and between 3909fc0 and f35f82a.

📒 Files selected for processing (3)
  • chart.go
  • chart_test.go
  • road_test.go

📝 Walkthrough

Walkthrough

Changes

Goal chart alignment

Layer / File(s) Summary
Road day snapping
chart.go, chart_test.go
Road segment boundaries are floored to local midnight, slopes are recalculated, and chart rendering applies the snapped road. Tests cover day snapping and datapoint-step alignment.
Right-edge road sampling
chart.go, road_test.go
Road values are sampled at column right edges, with the final sample clamped to endTime; tests update expected values and verify clamping.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: aligning road risers with same-day datapoint risers.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/chart-derail-riser-alignment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown

🚀 Pre-release Build Ready

Test builds are ready! Install directly using the bin command:

# Install the pre-release
bin install https://github.com/PinePeakDigital/buzz/releases/tag/pr-347-latest buzz-pr-347
# Run the pre-release
buzz-pr-347
# Uninstall the pre-release
bin remove buzz-pr-347

Direct Download Links

Or download binaries directly from the pre-release page:

💡 No GitHub login required for downloads!

🗑️ This pre-release will be automatically deleted when the PR is closed.

@github-actions

Copy link
Copy Markdown

🎬 Demo

Recorded from this PR's build (fictional data):

buzz demo

Regenerated on each push to this PR.

@narthur
narthur merged commit 4ac9220 into main Jul 23, 2026
6 checks passed
@narthur
narthur deleted the fix/chart-derail-riser-alignment branch July 23, 2026 22:03
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