diff --git a/src/app/data/source.rs b/src/app/data/source.rs index 5e0dba0..99a68ce 100644 --- a/src/app/data/source.rs +++ b/src/app/data/source.rs @@ -1,6 +1,6 @@ use super::FetchError; use chrono::{DateTime, Utc}; -use eframe::egui::plot::Value; +use eframe::egui::plot::PlotPoint; use eframe::epaint::Color32; use std::sync::RwLock; @@ -64,14 +64,14 @@ impl Default for Source { } } -fn avg_value(values: &[Value]) -> Value { +fn avg_value(values: &[PlotPoint]) -> PlotPoint { let mut x = 0.0; let mut y = 0.0; for v in values { x += v.x; y += v.y; } - return Value { + return PlotPoint { x: x / values.len() as f64, y: y / values.len() as f64, }; @@ -101,7 +101,7 @@ pub struct Metric { pub query_x: String, pub query_y: String, pub(crate) panel_id: i32, - pub(crate) data: RwLock>, + pub(crate) data: RwLock>, } impl Default for Metric { @@ -120,7 +120,7 @@ impl Default for Metric { } impl Metric { - pub fn extract(&self, value: &serde_json::Value) -> Result { + pub fn extract(&self, value: &serde_json::Value) -> Result { let x: f64; if self.query_x.len() > 0 { x = jql::walker(value, self.query_x.as_str())? @@ -132,7 +132,7 @@ impl Metric { let y = jql::walker(value, self.query_y.as_str())? .as_f64() .ok_or(FetchError::JQLError("Y query is null".to_string()))?; - Ok(Value { x, y }) + Ok(PlotPoint { x, y }) } pub fn values( @@ -141,8 +141,8 @@ impl Metric { max_x: Option, chunk_size: Option, average: bool, - ) -> Vec { - let mut values = self.data.read().expect("Values RwLock poisoned").clone(); + ) -> Vec { + let mut values = self.data.read().expect("PlotPoints RwLock poisoned").clone(); if let Some(min_x) = min_x { values.retain(|x| x.x > min_x); } @@ -153,7 +153,7 @@ impl Metric { if chunk_size > 0 { // TODO make this nested if prettier let iter = values.chunks(chunk_size as usize); - values = iter.map(|x| if average { avg_value(x) } else { if x.len() > 0 { x[x.len()-1] } else { Value {x: 0.0, y:0.0 }} }).collect(); + values = iter.map(|x| if average { avg_value(x) } else { if x.len() > 0 { x[x.len()-1] } else { PlotPoint {x: 0.0, y:0.0 }} }).collect(); } } values diff --git a/src/app/gui/panel.rs b/src/app/gui/panel.rs index c97adbb..ce7cf80 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, Values}, + plot::{Corner, GridMark, Legend, Line, Plot, PlotPoints}, DragValue, Layout, Ui, Slider, TextEdit, ScrollArea, collapsing_header::CollapsingState, Context, }, emath::Vec2}; use tracing::error; @@ -101,7 +101,7 @@ pub fn panel_title_ui(ui: &mut Ui, panel: &mut Panel, edit: bool) { // TODO make } else { ui.heading(panel.name.as_str()); } - ui.with_layout(Layout::right_to_left(), |ui| { + ui.with_layout(Layout::right_to_left(eframe::emath::Align::Min), |ui| { ui.horizontal(|ui| { ui.toggle_value(&mut panel.view_scroll, "🔒"); ui.separator(); @@ -222,8 +222,9 @@ pub fn panel_body_ui(ui: &mut Ui, panel: &mut Panel, metrics: &Vec) { // .include_y(values[0].y) // .include_y(values[l].y); // } + let values_splice : Vec<[f64;2]> = values.iter().map(|x| [x.x, x.y]).collect(); lines.push( - Line::new(Values::from_values(values)) + Line::new(values_splice) .name(metric.name.as_str()) .color(metric.color) ); diff --git a/src/app/gui/scaffold.rs b/src/app/gui/scaffold.rs index ee29827..bf4004b 100644 --- a/src/app/gui/scaffold.rs +++ b/src/app/gui/scaffold.rs @@ -86,7 +86,7 @@ pub fn header(app: &mut App, ui: &mut Ui, frame: &mut Frame) { ui.with_layout(Layout::top_down(Align::RIGHT), |ui| { ui.horizontal(|ui| { if ui.small_button("×").clicked() { - frame.quit(); + frame.close(); } }); }); diff --git a/src/app/util.rs b/src/app/util.rs index 41bbca3..fbad312 100644 --- a/src/app/util.rs +++ b/src/app/util.rs @@ -1,5 +1,5 @@ use chrono::{DateTime, Local, NaiveDateTime, Utc}; -use eframe::egui::{Color32, plot::Value}; +use eframe::egui::{Color32, plot::PlotPoint}; use std::{sync::Arc, error::Error, path::PathBuf}; use tracing_subscriber::Layer; @@ -8,7 +8,7 @@ use super::data::{ApplicationState, source::Metric}; // if you're handling more than terabytes of data, it's the future and you ought to update this code! const PREFIXES: &'static [&'static str] = &["", "k", "M", "G", "T"]; -pub fn serialize_values(values: &Vec, metric: &Metric, path: PathBuf) -> Result<(), Box> { +pub fn serialize_values(values: &Vec, metric: &Metric, path: PathBuf) -> Result<(), Box> { let mut wtr = csv::Writer::from_writer(std::fs::File::create(path)?); wtr.write_record(&[metric.name.as_str(), metric.query_x.as_str(), metric.query_y.as_str()])?; for v in values { @@ -18,7 +18,7 @@ pub fn serialize_values(values: &Vec, metric: &Metric, path: PathBuf) -> Ok(()) } -pub fn deserialize_values(path: PathBuf) -> Result<(String, String, String, Vec), Box> { +pub fn deserialize_values(path: PathBuf) -> Result<(String, String, String, Vec), Box> { let mut values = Vec::new(); let mut rdr = csv::Reader::from_reader(std::fs::File::open(path)?); @@ -33,7 +33,7 @@ pub fn deserialize_values(path: PathBuf) -> Result<(String, String, String, Vec< } for result in rdr.records() { if let Ok(record) = result { - values.push(Value { x: record[1].parse::()?, y: record[2].parse::()? }); + values.push(PlotPoint { x: record[1].parse::()?, y: record[2].parse::()? }); } }