From 26e1c1c6ee4531625125e6592f98f1a75cc2b91f Mon Sep 17 00:00:00 2001 From: Edd Barrett Date: Wed, 30 Oct 2024 10:42:38 +0000 Subject: [PATCH] Reporter: inidicate the date of the last data point. Just lets us know what data we have up until. --- reporter/src/main.rs | 7 ++++++- reporter/src/plot.rs | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/reporter/src/main.rs b/reporter/src/main.rs index eacbce8..57e6727 100644 --- a/reporter/src/main.rs +++ b/reporter/src/main.rs @@ -215,7 +215,12 @@ fn main() { abs_lines, output_path, ); - plot(&config); + + let last_x = plot(&config); + + // Inidcate when the last data point was collected. + write!(html, "

Last X value is {}

", last_x).unwrap(); + write!( html, "", diff --git a/reporter/src/plot.rs b/reporter/src/plot.rs index 235344e..942a1c4 100644 --- a/reporter/src/plot.rs +++ b/reporter/src/plot.rs @@ -116,7 +116,11 @@ fn find_plot_extents(lines: &HashMap) -> (Range>, } /// Plot some data into a SVG file. -pub fn plot(config: &PlotConfig) { +/// +/// If we are plotting more than one line, then they are assumed to contain the same x-values. +/// +/// Returns the last (rightmost) X value. +pub fn plot(config: &PlotConfig) -> DateTime { let (x_extent, y_extent) = find_plot_extents(&config.lines); let drawing = BitMapBackend::new(&config.output_path, (850, 600)).into_drawing_area(); @@ -145,11 +149,18 @@ pub fn plot(config: &PlotConfig) { .draw() .unwrap(); + let mut last_x = None; for (vm, line) in &config.lines { let colour = line.colour; // Sort the points so that the line doesn't zig-zag back and forth across the X-axis. let mut sorted_points = line.points.iter().map(|p| (p.x, p.y)).collect::>(); sorted_points.sort_by(|p1, p2| p1.0.partial_cmp(&p2.0).unwrap()); + + // Cache the rightmost X value. + if last_x.is_none() { + last_x = Some(sorted_points.last().unwrap().0); + } + // Draw line. chart .draw_series(LineSeries::new(sorted_points, colour)) @@ -175,4 +186,6 @@ pub fn plot(config: &PlotConfig) { .unwrap(); drawing.present().unwrap(); + + last_x.unwrap() }