use esoc_gfx::canvas::Canvas;
use esoc_gfx::transform::CoordinateTransform;
use crate::theme::Theme;
#[derive(Clone, Copy, Debug)]
pub struct DataBounds {
pub x_min: f64,
pub x_max: f64,
pub y_min: f64,
pub y_max: f64,
}
impl DataBounds {
pub fn new(x_min: f64, x_max: f64, y_min: f64, y_max: f64) -> Self {
Self {
x_min,
x_max,
y_min,
y_max,
}
}
pub fn union(self, other: Self) -> Self {
Self {
x_min: self.x_min.min(other.x_min),
x_max: self.x_max.max(other.x_max),
y_min: self.y_min.min(other.y_min),
y_max: self.y_max.max(other.y_max),
}
}
pub fn pad(self, fraction: f64) -> Self {
let x_pad = (self.x_max - self.x_min) * fraction;
let y_pad = (self.y_max - self.y_min) * fraction;
Self {
x_min: self.x_min - x_pad,
x_max: self.x_max + x_pad,
y_min: self.y_min - y_pad,
y_max: self.y_max + y_pad,
}
}
}
pub trait SeriesRenderer {
fn data_bounds(&self) -> DataBounds;
fn render(
&self,
canvas: &mut Canvas,
transform: &CoordinateTransform,
theme: &Theme,
series_index: usize,
);
fn label(&self) -> Option<&str>;
}