use super::aesthetics::GlobalAesthetics;
use crate::Precision;
use crate::coordinate::CoordinateTrait;
use crate::core::context::PanelContext;
use crate::encode::Channel;
use crate::error::ChartonError;
use crate::scale::{Expansion, Scale, ScaleDomain};
use crate::visual::color::SingleColor;
use crate::visual::shape::PointShape;
use std::sync::Arc;
#[derive(Clone, Copy, Debug)]
pub struct PointElementConfig {
pub x: f64,
pub y: f64,
pub shape: PointShape,
pub size: f64,
pub fill: SingleColor,
pub stroke: SingleColor,
pub stroke_width: f64,
pub opacity: f64,
}
pub struct CircleConfig {
pub x: Precision,
pub y: Precision,
pub radius: Precision,
pub fill: SingleColor,
pub stroke: SingleColor,
pub stroke_width: Precision,
pub opacity: Precision,
}
pub struct RectConfig {
pub x: Precision,
pub y: Precision,
pub width: Precision,
pub height: Precision,
pub fill: SingleColor,
pub stroke: SingleColor,
pub stroke_width: Precision,
pub opacity: Precision,
}
pub struct PathConfig {
pub points: Vec<(Precision, Precision)>,
pub stroke: SingleColor,
pub stroke_width: Precision,
pub opacity: Precision,
pub dash: Vec<Precision>,
}
pub struct PolygonConfig {
pub points: Vec<(Precision, Precision)>,
pub fill: SingleColor,
pub stroke: SingleColor,
pub stroke_width: Precision,
pub fill_opacity: Precision,
pub stroke_opacity: Precision,
}
pub struct TextConfig {
pub x: Precision,
pub y: Precision,
pub text: String,
pub font_size: Precision,
pub font_family: String,
pub color: SingleColor,
pub text_anchor: String, pub font_weight: String, pub opacity: Precision,
}
pub struct LineConfig {
pub x1: Precision,
pub y1: Precision,
pub x2: Precision,
pub y2: Precision,
pub color: SingleColor,
pub width: Precision,
pub opacity: Precision,
pub dash: Vec<Precision>,
}
pub struct GradientRectConfig {
pub x: Precision,
pub y: Precision,
pub width: Precision,
pub height: Precision,
pub stops: Vec<(Precision, SingleColor)>,
pub is_vertical: bool,
pub id_suffix: String,
}
pub trait RenderBackend {
fn draw_circle(&mut self, config: CircleConfig);
fn draw_rect(&mut self, config: RectConfig);
fn draw_path(&mut self, config: PathConfig);
fn draw_polygon(&mut self, config: PolygonConfig);
fn draw_text(&mut self, config: TextConfig);
fn draw_line(&mut self, config: LineConfig);
fn draw_gradient_rect(&mut self, config: GradientRectConfig);
}
pub trait MarkRenderer {
fn render_marks(
&self,
backend: &mut dyn RenderBackend,
context: &PanelContext,
) -> Result<(), ChartonError>;
}
pub trait Layer: MarkRenderer + Send + Sync {
fn requires_axes(&self) -> bool;
fn get_field(&self, channel: Channel) -> Option<String>;
fn get_scale(&self, channel: Channel) -> Option<Scale>;
fn get_expand(&self, channel: Channel) -> Option<Expansion>;
fn get_data_bounds(&self, channel: Channel) -> Result<ScaleDomain, ChartonError>;
fn inject_resolved_scales(
&self,
coord: Arc<dyn CoordinateTrait>,
aesthetics: &GlobalAesthetics,
);
}