mirror of
https://git.alemi.dev/dashboard.git
synced 2024-11-22 15:34:54 +01:00
fix: eframe update
This commit is contained in:
parent
058553506d
commit
c026d0def3
4 changed files with 18 additions and 17 deletions
|
@ -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<Vec<Value>>,
|
||||
pub(crate) data: RwLock<Vec<PlotPoint>>,
|
||||
}
|
||||
|
||||
impl Default for Metric {
|
||||
|
@ -120,7 +120,7 @@ impl Default for Metric {
|
|||
}
|
||||
|
||||
impl Metric {
|
||||
pub fn extract(&self, value: &serde_json::Value) -> Result<Value, FetchError> {
|
||||
pub fn extract(&self, value: &serde_json::Value) -> Result<PlotPoint, FetchError> {
|
||||
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<f64>,
|
||||
chunk_size: Option<u32>,
|
||||
average: bool,
|
||||
) -> Vec<Value> {
|
||||
let mut values = self.data.read().expect("Values RwLock poisoned").clone();
|
||||
) -> Vec<PlotPoint> {
|
||||
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
|
||||
|
|
|
@ -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<Metric>) {
|
|||
// .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)
|
||||
);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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<Value>, metric: &Metric, path: PathBuf) -> Result<(), Box<dyn Error>> {
|
||||
pub fn serialize_values(values: &Vec<PlotPoint>, metric: &Metric, path: PathBuf) -> Result<(), Box<dyn Error>> {
|
||||
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<Value>, metric: &Metric, path: PathBuf) ->
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn deserialize_values(path: PathBuf) -> Result<(String, String, String, Vec<Value>), Box<dyn Error>> {
|
||||
pub fn deserialize_values(path: PathBuf) -> Result<(String, String, String, Vec<PlotPoint>), Box<dyn Error>> {
|
||||
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::<f64>()?, y: record[2].parse::<f64>()? });
|
||||
values.push(PlotPoint { x: record[1].parse::<f64>()?, y: record[2].parse::<f64>()? });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue