fix: vertical lines align with local days

used to align to UTC days, which looked quite off
This commit is contained in:
əlemi 2022-06-12 12:00:25 +02:00
parent feaf8fd37a
commit ba59b62b2b
No known key found for this signature in database
GPG key ID: BBCBFE5D7244634E

View file

@ -3,7 +3,7 @@ pub mod worker;
pub mod util; pub mod util;
use std::sync::Arc; use std::sync::Arc;
use chrono::Utc; use chrono::{Utc, Local};
use eframe::egui; use eframe::egui;
use eframe::egui::plot::GridMark; use eframe::egui::plot::GridMark;
use eframe::egui::{RichText, plot::{Line, Plot}, Color32}; use eframe::egui::{RichText, plot::{Line, Plot}, Color32};
@ -215,13 +215,14 @@ impl eframe::App for App {
} }
}); });
p = p.x_grid_spacer(|grid| { p = p.x_grid_spacer(|grid| {
let offset = Local::now().offset().local_minus_utc() as i64;
let (start, end) = grid.bounds; let (start, end) = grid.bounds;
let mut counter = (start as i64) - ((start as i64) % 3600); let mut counter = (start as i64) - ((start as i64) % 3600);
let mut out : Vec<GridMark> = Vec::new(); let mut out : Vec<GridMark> = Vec::new();
loop { loop {
counter += 3600; counter += 3600;
if counter > end as i64 { break; } if counter > end as i64 { break; }
if counter % 86400 == 0 { if (counter + offset) % 86400 == 0 {
out.push(GridMark { value: counter as f64, step_size: 86400 as f64 }) out.push(GridMark { value: counter as f64, step_size: 86400 as f64 })
} else if counter % 3600 == 0 { } else if counter % 3600 == 0 {
out.push(GridMark { value: counter as f64, step_size: 3600 as f64 }); out.push(GridMark { value: counter as f64, step_size: 3600 as f64 });