use crate::coordinate::{CoordinateTrait, Rect};
use crate::core::aesthetics::GlobalAesthetics;
use crate::theme::Theme;
use std::sync::Arc;
pub struct ChartSpec<'a> {
pub aesthetics: &'a GlobalAesthetics,
pub theme: &'a Theme,
}
pub struct PanelContext<'a> {
pub spec: &'a ChartSpec<'a>,
pub coord: Arc<dyn CoordinateTrait>,
pub panel: Rect,
}
impl<'a> PanelContext<'a> {
pub fn new(spec: &'a ChartSpec<'a>, coord: Arc<dyn CoordinateTrait>, panel: Rect) -> Self {
Self { spec, coord, panel }
}
#[inline]
pub fn transform(&self, x_norm: f64, y_norm: f64) -> (f64, f64) {
self.coord.transform(x_norm, y_norm, &self.panel)
}
pub fn transform_path(&self, points: &[(f64, f64)], is_closed: bool) -> Vec<(f64, f64)> {
self.coord.transform_path(points, is_closed, &self.panel)
}
#[inline]
pub fn x_to_px(&self, x_norm: f64) -> f64 {
self.transform(x_norm, 0.0).0
}
#[inline]
pub fn y_to_px(&self, y_norm: f64) -> f64 {
self.transform(0.0, y_norm).1
}
pub fn theme(&self) -> &Theme {
self.spec.theme
}
pub fn aesthetics(&self) -> &GlobalAesthetics {
self.spec.aesthetics
}
}