diff --git a/gping/src/main.rs b/gping/src/main.rs index 69c9df2d..56860de0 100644 --- a/gping/src/main.rs +++ b/gping/src/main.rs @@ -522,7 +522,12 @@ fn main() -> Result<()> { } } - let datasets: Vec = app.data.iter().map(|d| d.into()).collect(); + // TODO: extract the nan datapoints and add them as a second dataset with .style(Style::default().fg(Color::Red));ter(|(_, x)| !x.is_nan()).collect(); + + let datasets: Vec = app.data.iter().flat_map(|d| vec![ + d.split_datasets(true), + d.split_datasets(false) + ].into_iter()).collect(); let y_axis_bounds = app.y_axis_bounds(); let x_axis_bounds = app.x_axis_bounds(); diff --git a/gping/src/plot_data.rs b/gping/src/plot_data.rs index dc6848d1..5f215719 100644 --- a/gping/src/plot_data.rs +++ b/gping/src/plot_data.rs @@ -4,10 +4,11 @@ use core::option::Option; use core::option::Option::{None, Some}; use core::time::Duration; use itertools::Itertools; -use tui::style::Style; +use tui::style::{Color, Style}; use tui::symbols; use tui::widgets::{Dataset, GraphType, Paragraph}; + pub struct PlotData { pub display: String, pub data: Vec<(f64, f64)>, @@ -98,6 +99,33 @@ impl PlotData { Paragraph::new(format!("t/o {to:?}")).style(self.style), ] } + + pub fn split_datasets(&self, nan:bool) -> Dataset { + let slice = if nan { + self.data.iter().filter(|&(_, t)| t.is_nan()).collect::>() + } else { + self.data.iter().filter(|&(_, t)| !t.is_nan()).collect::>() + }; + + // let slice_ref: &[(_, _)] = if slice.is_empty() { + // &[] // Pass an empty slice if the dataset is empty + // } else { + // &slice // Pass the actual dataset reference + // }; + // let owned_data: Vec<(f64, f64)> = slice.into_iter().cloned().collect(); + + Dataset::default() + .marker(if self.simple_graphics { + symbols::Marker::Dot + } else { + symbols::Marker::Braille + }) + .style(if !nan {self.style} else {Style::default().fg(Color::Red)}) + .graph_type(GraphType::Line) + .data(slice.iter().map(|&x| *x).collect::>().as_slice())//slice.iter().cloned().collect::>())//slice.as_slice()) + } + + } impl<'a> From<&'a PlotData> for Dataset<'a> {