Trends: chart key shows average price per station + descriptor footer

Legend rows now show each station's average over the days shown
in brackets (pence; signed +X.Xp in vs-cheapest mode, matching the
list-row deltas). Footer under the key explains the figure per mode.
averagePence helper (nil for empty series) + 3 tests; -showTrends
becomes a permanent QA hook like -showKeySheet.
This commit is contained in:
FuelBoard Contributor
2026-08-16 10:39:49 +01:00
parent 9aea478317
commit 430006be94
5 changed files with 71 additions and 0 deletions
+7
View File
@@ -148,6 +148,13 @@ enum FuelHistoryStore {
}
}
/// Average pence over a series' points; nil when there are no points
/// (a station with no data shows no bracket figure in the chart key).
static func averagePence(_ points: [PricePoint]) -> Double? {
guard !points.isEmpty else { return nil }
return points.reduce(0) { $0 + $1.pence } / Double(points.count)
}
/// Rebase every station's series so each day's CHEAPEST favourite sits at
/// 0 and the others show signed pence above it (mirrors the list's
/// baseline delta pattern). Days where a station has no point are gaps.