diff --git a/bare-metrics-gui/src/graph.rs b/bare-metrics-gui/src/graph.rs index 7f7f941..312ec33 100644 --- a/bare-metrics-gui/src/graph.rs +++ b/bare-metrics-gui/src/graph.rs @@ -40,11 +40,12 @@ pub struct HeatmapRect { density: f64, } -#[derive(Clone, Debug, Default)] +#[derive(Clone, Debug)] pub struct HistogramWindow { pub heatmap: Vec, pub min_density: f64, pub max_density: f64, + pub y_axis: RangeInclusive, } #[derive(Clone, Debug, Default)] @@ -62,12 +63,15 @@ impl UnsummarisedHistogramWindow { let mut min_density = f64::INFINITY; let mut max_density = f64::NEG_INFINITY; + let mut min_val = f64::INFINITY; + let mut max_val = f64::NEG_INFINITY; for (xa, xb, hist) in self.map.iter() { - let min_val = hist.min(); - let max_val = hist.max(); + let min_this_slice = hist.min(); + min_val = min_val.min(min_this_slice as f64); + max_val = max_val.max(hist.max() as f64); - let mut prev = min_val; + let mut prev = min_this_slice; for q in (1..=10).map(|i| i as f64 * 0.1) { // TODO improve this. It's going to be a bit off because of the way that // numbers can be 'equivalent' etc ... @@ -95,17 +99,21 @@ impl UnsummarisedHistogramWindow { //debug!("hist min {:?} max {:?}", hist.min(), hist.max()); } + let y_axis = min_val..=max_val; + debug!("yaxis {:?}", y_axis); HistogramWindow { heatmap, min_density, max_density, + y_axis, } } } -#[derive(Clone, Debug, Default)] +#[derive(Clone, Debug)] pub struct ScalarWindow { - points: Vec<(UnixTimestampMilliseconds, f64)>, + pub points: Vec<(UnixTimestampMilliseconds, f64)>, + pub y_axis: RangeInclusive, } pub struct MetricsLogReadingRequester { @@ -392,12 +400,22 @@ impl MetricsLogReaderManager { histograms.insert(*metric_id, Default::default()); } MetricKind::Gauge => { - metrics_window.gauges.insert(*metric_id, Default::default()); + metrics_window.gauges.insert( + *metric_id, + ScalarWindow { + points: vec![], + y_axis: 0.0..=0.0, + }, + ); } MetricKind::Counter => { - metrics_window - .counters - .insert(*metric_id, Default::default()); + metrics_window.counters.insert( + *metric_id, + ScalarWindow { + points: vec![], + y_axis: 0.0..=0.0, + }, + ); } } } @@ -707,7 +725,18 @@ impl Graph { // This range is reversed because screen coordinates go down, but we'd like them to go // up since this is more of a mathematical graph. - let y_axis = 300.0..=0.0; + let y_axis = if let Some(histogram) = current_window.histograms.get(&metric_id) { + histogram.y_axis.clone().into_inner() + } else if let Some(scalar) = current_window + .counters + .get(&metric_id) + .or_else(|| current_window.gauges.get(&metric_id)) + { + scalar.y_axis.clone().into_inner() + } else { + (0.0, 10.0) + }; + let y_axis = (y_axis.1)..=(y_axis.0); // let display_transform = // emath::RectTransform::from_to(Rect::from_x_y_ranges(x_axis, y_axis), display_rect);