mirror of
https://git.alemi.dev/dashboard.git
synced 2024-11-22 23:44:55 +01:00
fix: warnings, style, non-timeserie lock (maybe)
This commit is contained in:
parent
37d00b471a
commit
573c6991b4
4 changed files with 48 additions and 34 deletions
|
@ -1,9 +1,8 @@
|
||||||
use super::FetchError;
|
use super::FetchError;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use eframe::egui::plot::{Value, Values};
|
use eframe::egui::plot::Value;
|
||||||
use eframe::epaint::Color32;
|
use eframe::epaint::Color32;
|
||||||
use std::sync::RwLock;
|
use std::sync::RwLock;
|
||||||
use tracing::info;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Panel {
|
pub struct Panel {
|
||||||
|
@ -82,9 +81,9 @@ impl Source {
|
||||||
return (Utc::now() - *last_fetch).num_seconds() < self.interval as i64;
|
return (Utc::now() - *last_fetch).num_seconds() < self.interval as i64;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fetch(&self) -> Result<serde_json::Value, FetchError> {
|
// pub fn fetch(&self) -> Result<serde_json::Value, FetchError> {
|
||||||
fetch(self.url.as_str())
|
// fetch(self.url.as_str())
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fetch(url: &str) -> Result<serde_json::Value, FetchError> {
|
pub fn fetch(url: &str) -> Result<serde_json::Value, FetchError> {
|
||||||
|
@ -139,7 +138,7 @@ impl Metric {
|
||||||
min_x: Option<f64>,
|
min_x: Option<f64>,
|
||||||
max_x: Option<f64>,
|
max_x: Option<f64>,
|
||||||
chunk_size: Option<u32>,
|
chunk_size: Option<u32>,
|
||||||
) -> Values {
|
) -> Vec<Value> {
|
||||||
let mut values = self.data.read().expect("Values RwLock poisoned").clone();
|
let mut values = self.data.read().expect("Values RwLock poisoned").clone();
|
||||||
if let Some(min_x) = min_x {
|
if let Some(min_x) = min_x {
|
||||||
values.retain(|x| x.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 = iter.map(|x| avg_value(x)).collect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Values::from_values(values)
|
values
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,9 @@ pub fn metric_display_ui(ui: &mut Ui, metric: &Metric, _width: f32) {
|
||||||
ui.label(&metric.name);
|
ui.label(&metric.name);
|
||||||
ui.with_layout(Layout::top_down(Align::RIGHT), |ui| {
|
ui.with_layout(Layout::top_down(Align::RIGHT), |ui| {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
|
if metric.panel_id >= 0 {
|
||||||
ui.label(format!("panel: {}", metric.panel_id));
|
ui.label(format!("panel: {}", metric.panel_id));
|
||||||
|
}
|
||||||
if metric.query_y.len() > 0 {
|
if metric.query_y.len() > 0 {
|
||||||
ui.label(format!("y: {}", metric.query_y));
|
ui.label(format!("y: {}", metric.query_y));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use chrono::{Local, Utc};
|
use chrono::{Local, Utc};
|
||||||
use eframe::{egui::{
|
use eframe::{egui::{
|
||||||
plot::{Corner, GridMark, Legend, Line, Plot},
|
plot::{Corner, GridMark, Legend, Line, Plot, Values},
|
||||||
DragValue, Layout, Ui, Slider, TextEdit,
|
DragValue, Layout, Ui, Slider, TextEdit,
|
||||||
}, emath::Vec2};
|
}, emath::Vec2};
|
||||||
|
|
||||||
|
@ -73,6 +73,8 @@ pub fn panel_body_ui(ui: &mut Ui, panel: &mut Panel, metrics: &Vec<Metric>) {
|
||||||
p = p.set_margin_fraction(Vec2 { x: 0.0, y: 0.1 });
|
p = p.set_margin_fraction(Vec2 { x: 0.0, y: 0.1 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if panel.timeserie {
|
||||||
if panel.view_scroll {
|
if panel.view_scroll {
|
||||||
let _now = (Utc::now().timestamp() as f64) - (60.0 * panel.view_offset as f64);
|
let _now = (Utc::now().timestamp() as f64) - (60.0 * panel.view_offset as f64);
|
||||||
p = p.include_x(_now);
|
p = p.include_x(_now);
|
||||||
|
@ -82,8 +84,6 @@ pub fn panel_body_ui(ui: &mut Ui, panel: &mut Panel, metrics: &Vec<Metric>) {
|
||||||
.include_x(_now - (panel.view_size as f64 * 60.0)); // ??? TODO
|
.include_x(_now - (panel.view_size as f64 * 60.0)); // ??? TODO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if panel.timeserie {
|
|
||||||
p = p
|
p = p
|
||||||
.x_axis_formatter(|x, _range| timestamp_to_str(x as i64, true, false))
|
.x_axis_formatter(|x, _range| timestamp_to_str(x as i64, true, false))
|
||||||
.label_formatter(|name, value| {
|
.label_formatter(|name, value| {
|
||||||
|
@ -128,7 +128,7 @@ pub fn panel_body_ui(ui: &mut Ui, panel: &mut Panel, metrics: &Vec<Metric>) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
p.show(ui, |plot_ui| {
|
let mut lines : Vec<Line> = Vec::new();
|
||||||
let _now = Utc::now().timestamp() as f64;
|
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 _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 _size = (panel.view_size as f64) * 60.0; // TODO multiplying x60 makes sense only for timeseries
|
||||||
|
@ -137,12 +137,25 @@ pub fn panel_body_ui(ui: &mut Ui, panel: &mut Panel, metrics: &Vec<Metric>) {
|
||||||
let chunk_size = if panel.reduce { Some(panel.view_chunks) } else { None };
|
let chunk_size = if panel.reduce { Some(panel.view_chunks) } else { None };
|
||||||
for metric in metrics {
|
for metric in metrics {
|
||||||
if metric.panel_id == panel.id {
|
if metric.panel_id == panel.id {
|
||||||
// let chunks = None;
|
let values = metric.values(min_x, max_x, chunk_size);
|
||||||
let line = Line::new(metric.values(min_x, max_x, chunk_size))
|
if !panel.timeserie && panel.view_scroll && values.len() > 0 {
|
||||||
.name(metric.name.as_str())
|
let l = values.len() - 1;
|
||||||
.color(metric.color);
|
p = p.include_x(values[0].x)
|
||||||
plot_ui.line(line);
|
.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);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,7 +130,7 @@ impl eframe::App for App {
|
||||||
// let mut to_delete: Option<usize> = None;
|
// let mut to_delete: Option<usize> = None;
|
||||||
SidePanel::left("sources-bar")
|
SidePanel::left("sources-bar")
|
||||||
.width_range(280.0..=800.0)
|
.width_range(280.0..=800.0)
|
||||||
.default_width(350.0)
|
.default_width(330.0)
|
||||||
.show(ctx, |ui| {
|
.show(ctx, |ui| {
|
||||||
let panels = self.data.panels.read().expect("Panels RwLock poisoned");
|
let panels = self.data.panels.read().expect("Panels RwLock poisoned");
|
||||||
let panel_width = ui.available_width();
|
let panel_width = ui.available_width();
|
||||||
|
@ -208,7 +208,6 @@ impl eframe::App for App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if self.edit {
|
if self.edit {
|
||||||
ui.add_space(20.0);
|
|
||||||
ui.separator();
|
ui.separator();
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.heading("new source");
|
ui.heading("new source");
|
||||||
|
@ -232,6 +231,7 @@ impl eframe::App for App {
|
||||||
&panels,
|
&panels,
|
||||||
panel_width,
|
panel_width,
|
||||||
);
|
);
|
||||||
|
ui.add_space(5.0);
|
||||||
if self.padding {
|
if self.padding {
|
||||||
ui.add_space(300.0);
|
ui.add_space(300.0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue