Skip to content

Commit b90a74e

Browse files
committed
Fix hourly curve alignment with forecast cell centers
The curve points were being distributed from x=0 to x=totalWidth using a step calculation, causing misalignment with the HStack cells which center their content at (index + 0.5) * cellWidth. Changed the x-coordinate calculation to match the cell center positions, aligning temperature dots with their corresponding hour labels and icons.
1 parent e6d3b4b commit b90a74e

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

example_projects/Weather/Weather/Views/Sections/HourlyForecastCard.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ private struct HourlyCurve: View {
100100
let minTemp = temperatures.min() ?? 0
101101
let maxTemp = temperatures.max() ?? minTemp + 1
102102
let range = max(maxTemp - minTemp, 1)
103-
let step = size.width / CGFloat(max(forecasts.count - 1, 1))
103+
let cellWidth = size.width / CGFloat(forecasts.count)
104104
let pad: CGFloat = 8
105105

106106
return forecasts.enumerated().map { index, forecast in
107107
let normalized = CGFloat(forecast.temperatureC - minTemp) / CGFloat(range)
108108
return CGPoint(
109-
x: CGFloat(index) * step,
109+
x: (CGFloat(index) + 0.5) * cellWidth,
110110
y: pad + (1 - normalized) * (size.height - pad * 2)
111111
)
112112
}

0 commit comments

Comments
 (0)