diff --git a/src/app/data/source.rs b/src/app/data/source.rs index 4f05421..1baf957 100644 --- a/src/app/data/source.rs +++ b/src/app/data/source.rs @@ -1,9 +1,8 @@ use super::FetchError; use chrono::{DateTime, Utc}; -use eframe::egui::plot::{Value, Values}; +use eframe::egui::plot::Value; use eframe::epaint::Color32; use std::sync::RwLock; -use tracing::info; #[derive(Debug)] pub struct Panel { @@ -82,9 +81,9 @@ impl Source { return (Utc::now() - *last_fetch).num_seconds() < self.interval as i64; } - pub fn fetch(&self) -> Result { - fetch(self.url.as_str()) - } + // pub fn fetch(&self) -> Result { + // fetch(self.url.as_str()) + // } } pub fn fetch(url: &str) -> Result { @@ -139,7 +138,7 @@ impl Metric { min_x: Option, max_x: Option, chunk_size: Option, - ) -> Values { + ) -> Vec { let mut values = self.data.read().expect("Values RwLock poisoned").clone(); if let Some(min_x) = min_x { values.retain(|x| x.x > min_x); @@ -154,6 +153,6 @@ impl Metric { values = iter.map(|x| avg_value(x)).collect(); } } - Values::from_values(values) + values } } diff --git a/src/app/gui/metric.rs b/src/app/gui/metric.rs index 70745b0..ce96cc1 100644 --- a/src/app/gui/metric.rs +++ b/src/app/gui/metric.rs @@ -23,7 +23,9 @@ pub fn metric_display_ui(ui: &mut Ui, metric: &Metric, _width: f32) { ui.label(&metric.name); ui.with_layout(Layout::top_down(Align::RIGHT), |ui| { ui.horizontal(|ui| { - ui.label(format!("panel: {}", metric.panel_id)); + if metric.panel_id >= 0 { + ui.label(format!("panel: {}", metric.panel_id)); + } if metric.query_y.len() > 0 { ui.label(format!("y: {}", metric.query_y)); } diff --git a/src/app/gui/panel.rs b/src/app/gui/panel.rs index f792cf7..6da6623 100644 --- a/src/app/gui/panel.rs +++ b/src/app/gui/panel.rs @@ -1,6 +1,6 @@ use chrono::{Local, Utc}; use eframe::{egui::{ - plot::{Corner, GridMark, Legend, Line, Plot}, + plot::{Corner, GridMark, Legend, Line, Plot, Values}, DragValue, Layout, Ui, Slider, TextEdit, }, emath::Vec2}; @@ -73,17 +73,17 @@ pub fn panel_body_ui(ui: &mut Ui, panel: &mut Panel, metrics: &Vec) { p = p.set_margin_fraction(Vec2 { x: 0.0, y: 0.1 }); } - if panel.view_scroll { - let _now = (Utc::now().timestamp() as f64) - (60.0 * panel.view_offset as f64); - p = p.include_x(_now); - if panel.limit { - p = p - .include_x(_now + (panel.view_size as f64 * 3.0)) - .include_x(_now - (panel.view_size as f64 * 60.0)); // ??? TODO - } - } if panel.timeserie { + if panel.view_scroll { + let _now = (Utc::now().timestamp() as f64) - (60.0 * panel.view_offset as f64); + p = p.include_x(_now); + if panel.limit { + p = p + .include_x(_now + (panel.view_size as f64 * 3.0)) + .include_x(_now - (panel.view_size as f64 * 60.0)); // ??? TODO + } + } p = p .x_axis_formatter(|x, _range| timestamp_to_str(x as i64, true, false)) .label_formatter(|name, value| { @@ -128,21 +128,34 @@ pub fn panel_body_ui(ui: &mut Ui, panel: &mut Panel, metrics: &Vec) { }); } - p.show(ui, |plot_ui| { - let _now = Utc::now().timestamp() as f64; - let _off = (panel.view_offset as f64) * 60.0; // TODO multiplying x60 makes sense only for timeseries - let _size = (panel.view_size as f64) * 60.0; // TODO multiplying x60 makes sense only for timeseries - let min_x = if panel.limit { Some(_now - _size - _off) } else { None }; - let max_x = if panel.shift { Some(_now - _off) } else { None }; - let chunk_size = if panel.reduce { Some(panel.view_chunks) } else { None }; - for metric in metrics { - if metric.panel_id == panel.id { - // let chunks = None; - let line = Line::new(metric.values(min_x, max_x, chunk_size)) - .name(metric.name.as_str()) - .color(metric.color); - plot_ui.line(line); + let mut lines : Vec = Vec::new(); + let _now = Utc::now().timestamp() as f64; + let _off = (panel.view_offset as f64) * 60.0; // TODO multiplying x60 makes sense only for timeseries + let _size = (panel.view_size as f64) * 60.0; // TODO multiplying x60 makes sense only for timeseries + let min_x = if panel.limit { Some(_now - _size - _off) } else { None }; + let max_x = if panel.shift { Some(_now - _off) } else { None }; + let chunk_size = if panel.reduce { Some(panel.view_chunks) } else { None }; + for metric in metrics { + if metric.panel_id == panel.id { + let values = metric.values(min_x, max_x, chunk_size); + if !panel.timeserie && panel.view_scroll && values.len() > 0 { + let l = values.len() - 1; + p = p.include_x(values[0].x) + .include_x(values[l].x) + .include_y(values[0].y) + .include_y(values[l].y); } + lines.push( + Line::new(Values::from_values(values)) + .name(metric.name.as_str()) + .color(metric.color) + ); + } + } + + p.show(ui, |plot_ui| { + for line in lines { + plot_ui.line(line); } }); } diff --git a/src/app/mod.rs b/src/app/mod.rs index 345d489..f22e13c 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -130,7 +130,7 @@ impl eframe::App for App { // let mut to_delete: Option = None; SidePanel::left("sources-bar") .width_range(280.0..=800.0) - .default_width(350.0) + .default_width(330.0) .show(ctx, |ui| { let panels = self.data.panels.read().expect("Panels RwLock poisoned"); let panel_width = ui.available_width(); @@ -208,7 +208,6 @@ impl eframe::App for App { } } if self.edit { - ui.add_space(20.0); ui.separator(); ui.horizontal(|ui| { ui.heading("new source"); @@ -232,6 +231,7 @@ impl eframe::App for App { &panels, panel_width, ); + ui.add_space(5.0); if self.padding { ui.add_space(300.0); }