@@ -181,20 +181,19 @@ impl HourlyForecast {
181
181
}
182
182
183
183
pub fn prepare ( weather : & Weather , params : & Params , day_index : usize ) -> Result < Self > {
184
- let ( temperatures, weather_codes, precipitation) : ( & [ f32 ] , & [ u8 ] , Vec < u8 > ) ;
185
184
let Times { current_hour, night, .. } = weather. get_times ( params. config . units . time , day_index) ;
186
185
187
186
// The graph splits one hour into three "levels": last, current and next.
188
187
// 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
190
188
let day_start_idx = day_index * 24 ;
191
189
let day_end_idx = day_start_idx + 24 ;
192
190
let next_day_start_idx = day_end_idx + 1 ;
193
191
let next_day_end_idx = next_day_start_idx + 24 ;
194
192
193
+ let ( temperatures, weather_codes, precipitation) : ( & [ f32 ] , & [ u8 ] , Vec < u8 > ) ;
194
+ let ( mut temps, mut codes, mut prec) ;
195
195
// If it's the last possible requested day, the last index(start_index of the 7th day) is not available.
196
196
// 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) ;
198
197
if day_index == 6 {
199
198
temperatures = {
200
199
temps = weather. hourly . temperature_2m [ day_start_idx..] . to_vec ( ) ;
@@ -219,42 +218,44 @@ impl HourlyForecast {
219
218
. map ( |x| x. ceil ( ) as u8 )
220
219
. collect :: < Vec < u8 > > ( ) ,
221
220
} ;
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] ;
225
225
precipitation = match params. config . units . precipitation {
226
226
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 ( )
228
228
}
229
- _ => weather. hourly . precipitation [ day_start_idx ..=day_end_idx ]
229
+ _ => weather. hourly . precipitation [ next_day_start_idx ..=next_day_end_idx ]
230
230
. iter ( )
231
231
. map ( |x| x. ceil ( ) as u8 )
232
232
. collect :: < Vec < u8 > > ( ) ,
233
233
} ;
234
234
} 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 ] ;
237
237
precipitation = match params. config . units . precipitation {
238
238
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 ( )
240
240
}
241
- _ => weather. hourly . precipitation [ next_day_start_idx ..=next_day_end_idx ]
241
+ _ => weather. hourly . precipitation [ day_start_idx ..=day_end_idx ]
242
242
. iter ( )
243
243
. map ( |x| x. ceil ( ) as u8 )
244
244
. collect :: < Vec < u8 > > ( ) ,
245
245
} ;
246
246
} ;
247
247
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 {
250
253
// 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
258
259
} ;
259
260
260
261
let temp_max_min = format ! (
0 commit comments