Skip to content

Commit f967427

Browse files
authored
🐛 fix time_indicator disable option (#76)
1 parent e62b440 commit f967427

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

src/modules/display/hourly.rs

+22-21
Original file line numberDiff line numberDiff line change
@@ -181,20 +181,19 @@ impl HourlyForecast {
181181
}
182182

183183
pub fn prepare(weather: &Weather, params: &Params, day_index: usize) -> Result<Self> {
184-
let (temperatures, weather_codes, precipitation): (&[f32], &[u8], Vec<u8>);
185184
let Times { current_hour, night, .. } = weather.get_times(params.config.units.time, day_index);
186185

187186
// The graph splits one hour into three "levels": last, current and next.
188187
// We slice 25 items to use the 25th in the last "next"-level of a graph.
189-
// If it's the end of one day we show the weather of the next day
190188
let day_start_idx = day_index * 24;
191189
let day_end_idx = day_start_idx + 24;
192190
let next_day_start_idx = day_end_idx + 1;
193191
let next_day_end_idx = next_day_start_idx + 24;
194192

193+
let (temperatures, weather_codes, precipitation): (&[f32], &[u8], Vec<u8>);
194+
let (mut temps, mut codes, mut prec);
195195
// If it's the last possible requested day, the last index(start_index of the 7th day) is not available.
196196
// Therefore we'll extend the values by 1. For this we simply use the last value of the array twice.
197-
let (mut temps, mut codes, mut prec);
198197
if day_index == 6 {
199198
temperatures = {
200199
temps = weather.hourly.temperature_2m[day_start_idx..].to_vec();
@@ -219,42 +218,44 @@ impl HourlyForecast {
219218
.map(|x| x.ceil() as u8)
220219
.collect::<Vec<u8>>(),
221220
};
222-
} else if current_hour != day_end_idx - 1 || day_index == 6 {
223-
temperatures = &weather.hourly.temperature_2m[day_start_idx..=day_end_idx];
224-
weather_codes = &weather.hourly.weathercode[day_start_idx..=day_end_idx];
221+
// If it's the end of one day we show the weather of the next day
222+
} else if current_hour == day_end_idx - 1 {
223+
temperatures = &weather.hourly.temperature_2m[next_day_start_idx..=next_day_end_idx];
224+
weather_codes = &weather.hourly.weathercode[next_day_start_idx..=next_day_end_idx];
225225
precipitation = match params.config.units.precipitation {
226226
Precipitation::probability => {
227-
weather.hourly.precipitation_probability[day_start_idx..=day_end_idx].to_vec()
227+
weather.hourly.precipitation_probability[next_day_start_idx..=next_day_end_idx].to_vec()
228228
}
229-
_ => weather.hourly.precipitation[day_start_idx..=day_end_idx]
229+
_ => weather.hourly.precipitation[next_day_start_idx..=next_day_end_idx]
230230
.iter()
231231
.map(|x| x.ceil() as u8)
232232
.collect::<Vec<u8>>(),
233233
};
234234
} else {
235-
temperatures = &weather.hourly.temperature_2m[next_day_start_idx..=next_day_end_idx];
236-
weather_codes = &weather.hourly.weathercode[next_day_start_idx..=next_day_end_idx];
235+
temperatures = &weather.hourly.temperature_2m[day_start_idx..=day_end_idx];
236+
weather_codes = &weather.hourly.weathercode[day_start_idx..=day_end_idx];
237237
precipitation = match params.config.units.precipitation {
238238
Precipitation::probability => {
239-
weather.hourly.precipitation_probability[next_day_start_idx..=next_day_end_idx].to_vec()
239+
weather.hourly.precipitation_probability[day_start_idx..=day_end_idx].to_vec()
240240
}
241-
_ => weather.hourly.precipitation[next_day_start_idx..=next_day_end_idx]
241+
_ => weather.hourly.precipitation[day_start_idx..=day_end_idx]
242242
.iter()
243243
.map(|x| x.ceil() as u8)
244244
.collect::<Vec<u8>>(),
245245
};
246246
};
247247

248-
let time_indicator_col = match day_index {
249-
0 => Some(
248+
let time_indicator_col = if day_index == 0 && params.config.gui.graph.time_indicator {
249+
let col_adjustment = if current_hour == day_end_idx - 1 {
250+
// if it's the last hour of the day, the time idicator will be placed at the beginning of the graph
251+
1
252+
} else {
250253
// add 3 cols to adjust to the multiple chars used to display the current hour below the chart
251-
if current_hour != day_end_idx - 1 {
252-
(current_hour * 3) + 3
253-
} else {
254-
1
255-
} + (Timelike::minute(&Utc::now()) / 20) as usize,
256-
),
257-
_ => None,
254+
(current_hour * 3) + 3
255+
};
256+
Some(col_adjustment + (Timelike::minute(&Utc::now()) / 20) as usize)
257+
} else {
258+
None
258259
};
259260

260261
let temp_max_min = format!(

0 commit comments

Comments
 (0)