use egui::Ui;
use plotters::style::{RGBAColor, ShapeStyle};
use crate::charts::XyTimeData;
pub struct TimeData {
chart: XyTimeData,
}
impl TimeData {
pub fn new(points: &[(f32, f32)], unit: &str, caption: &str) -> Self {
let points: Vec<(f32, f32, f32)> = points
.into_iter()
.map(|(data, time)| (*data, *time, *time))
.collect();
let chart = XyTimeData::new(&points, "seconds", unit, caption);
Self { chart }
}
#[inline]
pub fn set_time(&mut self, time: f32) {
self.chart.set_time(time)
}
#[inline]
pub fn time(mut self, time: f32) -> Self {
self.set_time(time);
self
}
#[inline]
pub fn set_playback_speed(&mut self, speed: f32) {
self.chart.set_playback_speed(speed)
}
#[inline]
pub fn playback_speed(mut self, speed: f32) -> Self {
self.set_playback_speed(speed);
self
}
#[inline]
pub fn set_line_style(&mut self, line_style: ShapeStyle) {
self.chart.set_line_style(line_style)
}
#[inline]
pub fn line_style(mut self, line_style: ShapeStyle) -> Self {
self.set_line_style(line_style);
self
}
#[inline]
pub fn set_grid_style(&mut self, grid_style: ShapeStyle) {
self.chart.set_grid_style(grid_style)
}
#[inline]
pub fn grid_style(mut self, grid_style: ShapeStyle) -> Self {
self.set_grid_style(grid_style);
self
}
#[inline]
pub fn set_subgrid_style(&mut self, subgrid_style: ShapeStyle) {
self.chart.set_subgrid_style(subgrid_style)
}
#[inline]
pub fn subgrid_style(mut self, subgrid_style: ShapeStyle) -> Self {
self.set_subgrid_style(subgrid_style);
self
}
#[inline]
pub fn set_axes_style(&mut self, axes_style: ShapeStyle) {
self.chart.set_axes_style(axes_style)
}
#[inline]
pub fn axes_style(mut self, axes_style: ShapeStyle) -> Self {
self.set_axes_style(axes_style);
self
}
#[inline]
pub fn set_text_color<T>(&mut self, color: T)
where
T: Into<RGBAColor>,
{
self.chart.set_text_color(color)
}
#[inline]
pub fn text_color<T>(mut self, color: T) -> Self
where
T: Into<RGBAColor>,
{
self.set_text_color(color);
self
}
#[inline]
pub fn set_background_color<T>(&mut self, color: T)
where
T: Into<RGBAColor>,
{
self.chart.set_background_color(color);
}
#[inline]
pub fn background_color<T>(mut self, color: T) -> Self
where
T: Into<RGBAColor>,
{
self.set_background_color(color);
self
}
#[inline]
pub fn set_ratio(&mut self, ratio: f32) {
self.chart.set_ratio(ratio);
}
#[inline]
pub fn ratio(mut self, ratio: f32) -> Self {
self.set_ratio(ratio);
self
}
pub fn draw(&mut self, ui: &Ui) {
self.chart.draw(ui)
}
#[inline]
pub fn start_playback(&mut self) {
self.chart.start_playback()
}
#[inline]
pub fn stop_playback(&mut self) {
self.chart.stop_playback()
}
pub fn toggle_playback(&mut self) {
self.chart.toggle_playback()
}
#[inline]
pub fn is_playing(&self) -> bool {
self.chart.is_playing()
}
#[inline]
pub fn start_time(&self) -> f32 {
self.chart.start_time()
}
#[inline]
pub fn current_time(&mut self) -> f32 {
self.chart.current_time()
}
#[inline]
pub fn end_time(&self) -> f32 {
self.chart.end_time()
}
#[inline]
pub fn get_playback_speed(&self) -> f32 {
self.chart.get_playback_speed()
}
}