From 21e4cf042e0aecc8f2bd83cd1762d7d679c69b51 Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Sat, 27 Nov 2021 23:38:06 +0000 Subject: [PATCH] Autoscale the graph vertically --- bare-metrics-gui/src/graph.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/bare-metrics-gui/src/graph.rs b/bare-metrics-gui/src/graph.rs index 312ec33..3fd26e4 100644 --- a/bare-metrics-gui/src/graph.rs +++ b/bare-metrics-gui/src/graph.rs @@ -116,6 +116,20 @@ pub struct ScalarWindow { pub y_axis: RangeInclusive, } +impl ScalarWindow { + pub fn summarise_in_place(&mut self) { + let mut min_point = f64::INFINITY; + let mut max_point = f64::NEG_INFINITY; + + for (_, point) in self.points.iter() { + min_point = min_point.min(*point); + max_point = max_point.max(*point); + } + + self.y_axis = min_point..=max_point; + } +} + pub struct MetricsLogReadingRequester { pub shared: Arc, pub tx: Sender, @@ -529,6 +543,13 @@ impl MetricsLogReaderManager { .insert(metric_id, unsummarised_histogram.summarise()); } + for (metric_id, gauge) in metrics_window.gauges.iter_mut() { + gauge.summarise_in_place(); + } + for (metric_id, counter) in metrics_window.counters.iter_mut() { + counter.summarise_in_place(); + } + Ok(metrics_window) }