feat: improved plot marks

made timeserie plot marks align to days and hours.
Also added some collapsable empty space at the
bottom of sources panel to allow to shift the last ones up
some space and still be able to edit their color.
This commit is contained in:
əlemi 2022-06-11 05:51:40 +02:00
parent 7b9b25a7cf
commit 73678c8fe7
No known key found for this signature in database
GPG key ID: BBCBFE5D7244634E
2 changed files with 48 additions and 19 deletions

View file

@ -5,6 +5,7 @@ pub mod util;
use std::sync::Arc; use std::sync::Arc;
use chrono::Utc; use chrono::Utc;
use eframe::egui; use eframe::egui;
use eframe::egui::plot::GridMark;
use eframe::egui::{RichText, plot::{Line, Plot}, Color32}; use eframe::egui::{RichText, plot::{Line, Plot}, Color32};
use self::data::ApplicationState; use self::data::ApplicationState;
@ -152,6 +153,10 @@ impl eframe::App for App {
}); });
}); });
} }
ui.collapsing("extra space", |ui| {
ui.add_space(300.0);
ui.separator();
})
}); });
}); });
} }
@ -201,14 +206,29 @@ impl eframe::App for App {
} }
if panel.timeserie { if panel.timeserie {
p = p.x_axis_formatter(|x, _range| timestamp_to_str(x as i64)); p = p.x_axis_formatter(|x, _range| timestamp_to_str(x as i64, true, false));
p = p.label_formatter(|name, value| { p = p.label_formatter(|name, value| {
if !name.is_empty() { if !name.is_empty() {
return format!("{}\nx = {}\ny = {:.1}", name, timestamp_to_str(value.x as i64), value.y) return format!("{}\nx = {}\ny = {:.1}", name, timestamp_to_str(value.x as i64, false, true), value.y)
} else { } else {
return format!("x = {}\ny = {:.1}", timestamp_to_str(value.x as i64), value.y); return format!("x = {}\ny = {:.1}", timestamp_to_str(value.x as i64, false, true), value.y);
} }
}); });
p = p.x_grid_spacer(|grid| {
let (start, end) = grid.bounds;
let mut counter = (start as i64) - ((start as i64) % 3600);
let mut out : Vec<GridMark> = Vec::new();
loop {
counter += 3600;
if counter > end as i64 { break; }
if counter % 86400 == 0 {
out.push(GridMark { value: counter as f64, step_size: 86400 as f64 })
} else if counter % 3600 == 0 {
out.push(GridMark { value: counter as f64, step_size: 3600 as f64 });
}
}
return out;
});
} }
p.show(ui, |plot_ui| { p.show(ui, |plot_ui| {

View file

@ -1,5 +1,5 @@
// if you're handling more than terabytes of data, it's the future and you ought to update this code! // if you're handling more than terabytes of data, it's the future and you ought to update this code!
use chrono::{DateTime, Utc, NaiveDateTime}; use chrono::{DateTime, NaiveDateTime, Utc, Local};
use eframe::egui::Color32; use eframe::egui::Color32;
const PREFIXES: &'static [&'static str] = &["", "k", "M", "G", "T"]; const PREFIXES: &'static [&'static str] = &["", "k", "M", "G", "T"];
@ -15,11 +15,20 @@ pub fn human_size(size:u64) -> String {
return format!("{:.3} {}B", buf, PREFIXES[prefix]); return format!("{:.3} {}B", buf, PREFIXES[prefix]);
} }
pub fn timestamp_to_str(t:i64) -> String { pub fn timestamp_to_str(t: i64, date: bool, time: bool) -> String {
format!( format!(
"{}", "{}",
DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(t, 0), Utc) DateTime::<Local>::from(DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(t, 0), Utc)).format(
.format("%Y/%m/%d %H:%M:%S") if date && time {
"%Y/%m/%d %H:%M:%S"
} else if date {
"%Y/%m/%d"
} else if time {
"%H:%M:%S"
} else {
"%s"
}
)
) )
} }