From 1d8ba239695f7c4952333bc2035849381ad77e24 Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Sun, 28 Nov 2021 14:14:15 +0000 Subject: [PATCH] Use dashboards to show the graphs --- bare-metrics-gui/src/config.rs | 6 +++--- bare-metrics-gui/src/main.rs | 24 ++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/bare-metrics-gui/src/config.rs b/bare-metrics-gui/src/config.rs index a223496..974ebbe 100644 --- a/bare-metrics-gui/src/config.rs +++ b/bare-metrics-gui/src/config.rs @@ -3,11 +3,11 @@ use serde::Deserialize; #[derive(Deserialize, Default, Clone)] pub struct DashboardConfig { - graphs: Vec, + pub graphs: Vec, } #[derive(Deserialize, Clone)] pub struct GraphConfig { - name: String, - kind: MetricKind, + pub name: String, + pub kind: MetricKind, } diff --git a/bare-metrics-gui/src/main.rs b/bare-metrics-gui/src/main.rs index cd27d24..6a97e98 100644 --- a/bare-metrics-gui/src/main.rs +++ b/bare-metrics-gui/src/main.rs @@ -22,9 +22,29 @@ pub struct MetricsGui { impl App for MetricsGui { fn update(&mut self, ctx: &CtxRef, _frame: &mut Frame<'_>) { + let Self { + requester, + dashboard, + } = self; CentralPanel::default().show(ctx, |ui| { - ui.label("Hah"); - Graph::draw(ui, MetricId(0), &self.requester); + egui::ScrollArea::new([false, true]).show(ui, |ui| { + if let Some(dashboard) = dashboard { + let window = requester.shared.current_window.read().unwrap(); + for graph in dashboard.graphs.iter() { + ui.label(&graph.name); + + if let Some(metric) = window.metrics.get(&graph.name) { + // TODO support multiple labelled metrics + if let Some((_, first_one)) = metric.iter().next() { + Graph::draw(ui, *first_one, requester); + } + } + } + } else { + ui.label("(no dashboard)"); + Graph::draw(ui, MetricId(0), &requester); + } + }); }); }