Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attempt to split up datasets by NAN value so different colors can be applied #496

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion gping/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,12 @@ fn main() -> Result<()> {
}
}

let datasets: Vec<Dataset> = 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<Dataset> = 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();
Expand Down
30 changes: 29 additions & 1 deletion gping/src/plot_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)>,
Expand Down Expand Up @@ -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::<Vec<_>>()
} else {
self.data.iter().filter(|&(_, t)| !t.is_nan()).collect::<Vec<_>>()
};

// 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::<Vec<_>>().as_slice())//slice.iter().cloned().collect::<Vec<_>>())//slice.as_slice())
}


}

impl<'a> From<&'a PlotData> for Dataset<'a> {
Expand Down