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:
@@ -175,6 +175,7 @@ struct TrendsView: View {
|
||||
VStack(spacing: 12) {
|
||||
chart
|
||||
legend
|
||||
legendFooter
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -256,10 +257,41 @@ struct TrendsView: View {
|
||||
Text(history.name)
|
||||
.font(.caption)
|
||||
.lineLimit(1)
|
||||
if let avg = FuelHistoryStore.averagePence(history.points) {
|
||||
Text(legendFigure(avg))
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
.monospacedDigit()
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 4)
|
||||
}
|
||||
|
||||
/// The bracket figure in the chart key: absolute pence in Price mode,
|
||||
/// signed pence above the day's cheapest in vs-cheapest mode — always
|
||||
/// pence, matching the list rows (the y-axis follows the display toggle).
|
||||
private func legendFigure(_ pence: Double) -> String {
|
||||
switch mode {
|
||||
case .price:
|
||||
return String(format: "%.1fp", pence)
|
||||
case .vsCheapest:
|
||||
return pence > 0 ? String(format: "+%.1fp", pence) : String(format: "%.1fp", pence)
|
||||
}
|
||||
}
|
||||
|
||||
/// One-line descriptor under the key so the brackets are self-explanatory.
|
||||
private var legendFooter: some View {
|
||||
Group {
|
||||
if mode == .price {
|
||||
Text("Average price over the days shown")
|
||||
} else {
|
||||
Text("Average pence above the day's cheapest favourite")
|
||||
}
|
||||
}
|
||||
.font(.caption2)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user