mirror of
https://github.com/hubaldv/bioz-host-rs.git
synced 2025-12-06 05:11:17 +00:00
Implement clear view plot.
This commit is contained in:
15
src/plot.rs
15
src/plot.rs
@@ -1,3 +1,4 @@
|
||||
use core::f64;
|
||||
use std::collections::VecDeque;
|
||||
|
||||
use egui_plot::{PlotPoint, PlotPoints};
|
||||
@@ -9,10 +10,10 @@ pub struct TimeSeriesPlot {
|
||||
|
||||
impl TimeSeriesPlot {
|
||||
pub fn new() -> Self {
|
||||
let max_points = 100;
|
||||
let max_points = 500;
|
||||
Self {
|
||||
values: (0..max_points as i32)
|
||||
.map(|i| PlotPoint::new(i, 0.0))
|
||||
values: (-(max_points as i32)..0)
|
||||
.map(|i| PlotPoint::new(i, f64::NAN))
|
||||
.collect(), // Create x amount of (0,0) points
|
||||
max_points,
|
||||
}
|
||||
@@ -21,7 +22,7 @@ impl TimeSeriesPlot {
|
||||
pub fn add(&mut self, val: f64) {
|
||||
let last_x = self.values.back().unwrap().x;
|
||||
|
||||
if last_x >= self.max_points as f64 {
|
||||
if last_x >= 0.0 {
|
||||
self.values.pop_front();
|
||||
}
|
||||
|
||||
@@ -39,4 +40,10 @@ impl TimeSeriesPlot {
|
||||
}
|
||||
PlotPoints::Owned(Vec::from_iter(values))
|
||||
}
|
||||
|
||||
pub fn clear(&mut self) {
|
||||
self.values = (-(self.max_points as i32)..0)
|
||||
.map(|i| PlotPoint::new(i, f64::NAN))
|
||||
.collect();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user