mirror of
https://git.alemi.dev/dashboard.git
synced 2024-11-12 19:29:18 +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,42 +1,51 @@
|
|||
// 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"];
|
||||
const PREFIXES: &'static [&'static str] = &["", "k", "M", "G", "T"];
|
||||
|
||||
pub fn human_size(size:u64) -> String {
|
||||
let mut buf : f64 = size as f64;
|
||||
let mut prefix : usize = 0;
|
||||
while buf > 1024.0 && prefix < PREFIXES.len() -1 {
|
||||
pub fn human_size(size: u64) -> String {
|
||||
let mut buf: f64 = size as f64;
|
||||
let mut prefix: usize = 0;
|
||||
while buf > 1024.0 && prefix < PREFIXES.len() - 1 {
|
||||
buf /= 1024.0;
|
||||
prefix += 1;
|
||||
}
|
||||
|
||||
|
||||
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"
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
pub fn unpack_color(c: u32) -> Color32 {
|
||||
let r : u8 = (c >> 0) as u8;
|
||||
let g : u8 = (c >> 8) as u8;
|
||||
let b : u8 = (c >> 16) as u8;
|
||||
let a : u8 = (c >> 24) as u8;
|
||||
let r: u8 = (c >> 0) as u8;
|
||||
let g: u8 = (c >> 8) as u8;
|
||||
let b: u8 = (c >> 16) as u8;
|
||||
let a: u8 = (c >> 24) as u8;
|
||||
return Color32::from_rgba_unmultiplied(r, g, b, a);
|
||||
}
|
||||
|
||||
pub fn repack_color(c: Color32) -> u32 {
|
||||
let mut out : u32 = 0;
|
||||
let mut out: u32 = 0;
|
||||
let mut offset = 0;
|
||||
for el in c.to_array() {
|
||||
out |= ((el & 0xFF) as u32) << offset;
|
||||
offset += 8;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue