Add rolling-average trend line to insulin statistics charts#33
Open
Sjoerd-Bo3 wants to merge 1 commit into
Open
Add rolling-average trend line to insulin statistics charts#33Sjoerd-Bo3 wants to merge 1 commit into
Sjoerd-Bo3 wants to merge 1 commit into
Conversation
4 tasks
Overlay a centered rolling-average (moving average) line on the Total Daily Dose and Bolus Insulin bar charts in the Statistics > Insulin tab, making longer-term trends easier to read on top of the noisy per-bar values. - Add reusable rolling-average helpers to StatChartUtils: a centered moving-average computation with clamped edge windows, interval-aware window sizing, bar-center alignment offset, and a dashed legend item. - Overlay the dashed trend line on TotalDailyDoseChart and BolusStatsView (bolus line tracks the total of manual + SMB + external). - Add a legend entry so the dashed line is self-explanatory.
Sjoerd-Bo3
force-pushed
the
claude/insulin-charts-rolling-average-bbc2sb
branch
from
June 16, 2026 10:32
d14e669 to
64aca90
Compare
Sjoerd-Bo3
pushed a commit
that referenced
this pull request
Jun 16, 2026
Sync the Build branch up to upstream nightscout/Trio dev (0.8.2.1), while preserving the fork-specific features and the rolling-average trend-line work (insulin + meal charts, debug slider, gap-correct/robust averaging, carry-over lead-in) already on Build. Resolved one conflict in Localizable.xcstrings (kept the fork's extra string keys). The Statistics feature files are identical to the rebased PR branches #33 and #34.
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 rolling-average (moving average) trend line overlaid on the insulin bar charts in Statistics → Insulin, so longer-term trends are easy to read on top of the noisy per-bar values — similar to the trend line in the attached reference example.
The dashed line is added to both charts in the Insulin tab:
What changed
StatChartUtils: new reusable helpersrollingAverage(for:date:value:window:centerOffset:)— a centered moving average with clamped partial windows at the edges, so the line spans the full visible range and isn't shifted relative to the bars.rollingAverageWindow(for:)— interval-aware window (3 hours for Day; 3 days for Week; 7 days for Month/3M).barCenterOffset(for:)— re-centers the line on bar centers (bars are binned to the start of the hour/day).dashedLegendItem(label:color:)+ a smallHorizontalLineshape for a dashed legend symbol.rollingAverageStrokeStyle.TotalDailyDoseChart: overlay the dashedLineMark(catmullRom interpolation) and add a legend (the chart previously had none).BolusStatsView: overlay the dashedLineMarkover the total bolus and add a "Rolling average" entry to the existing legend.The line uses
Color.primary, so it stays high-contrast in both light and dark mode.Notes / design choices
Does this make sense for the other Statistics tabs?
If you'd like, I can extend the trend line to the Meals chart in this same PR.
Test plan
🤖 Generated with Claude Code
Generated by Claude Code