mirror of
https://github.com/hubaldv/bioz-host-rs.git
synced 2025-12-06 05:11:17 +00:00
Created basic sinus output via postcard rpc.
This commit is contained in:
42
src/plot.rs
Normal file
42
src/plot.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
use std::collections::VecDeque;
|
||||
|
||||
use egui_plot::{PlotPoint, PlotPoints};
|
||||
|
||||
pub struct TimeSeriesPlot {
|
||||
pub values: VecDeque<PlotPoint>,
|
||||
max_points: usize,
|
||||
}
|
||||
|
||||
impl TimeSeriesPlot {
|
||||
pub fn new() -> Self {
|
||||
let max_points = 2000;
|
||||
Self {
|
||||
values: (0..max_points as i32)
|
||||
.map(|i| PlotPoint::new(i, 0.0))
|
||||
.collect(), // Create x amount of (0,0) points
|
||||
max_points,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add(&mut self, val: f64) {
|
||||
let last_x = self.values.back().unwrap().x;
|
||||
|
||||
if last_x >= self.max_points as f64 {
|
||||
self.values.pop_front();
|
||||
}
|
||||
|
||||
self.values.push_back(PlotPoint::new(last_x + 1.0, val));
|
||||
}
|
||||
|
||||
pub fn plot_values(&self) -> PlotPoints {
|
||||
PlotPoints::Owned(Vec::from_iter(self.values.iter().copied()))
|
||||
}
|
||||
|
||||
pub fn plot_values_negative(&self) -> PlotPoints {
|
||||
let mut values = Vec::from_iter(self.values.iter().copied());
|
||||
for point in &mut values {
|
||||
point.y = -point.y;
|
||||
}
|
||||
PlotPoints::Owned(Vec::from_iter(values))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user