mirror of
https://git.alemi.dev/dashboard.git
synced 2024-11-22 07:24:52 +01:00
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:
parent
569c5615d3
commit
99439e44d5
2 changed files with 48 additions and 19 deletions
|
@ -5,6 +5,7 @@ pub mod util;
|
|||
use std::sync::Arc;
|
||||
use chrono::Utc;
|
||||
use eframe::egui;
|
||||
use eframe::egui::plot::GridMark;
|
||||
use eframe::egui::{RichText, plot::{Line, Plot}, Color32};
|
||||
|
||||
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 {
|
||||
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| {
|
||||
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 {
|
||||
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| {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// 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;
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
pub fn timestamp_to_str(t:i64) -> String {
|
||||
pub fn timestamp_to_str(t: i64, date: bool, time: bool) -> String {
|
||||
format!(
|
||||
"{}",
|
||||
DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(t, 0), Utc)
|
||||
.format("%Y/%m/%d %H:%M:%S")
|
||||
DateTime::<Local>::from(DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(t, 0), Utc)).format(
|
||||
if date && time {
|
||||
"%Y/%m/%d %H:%M:%S"
|
||||
} else if date {
|
||||
"%Y/%m/%d"
|
||||
} else if time {
|
||||
"%H:%M:%S"
|
||||
} else {
|
||||
"%s"
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue