Skip to main content

chartml_core/plugin/
renderer.rs

1use serde::{Deserialize, Serialize};
2
3use crate::data::DataTable;
4use crate::element::{ChartElement, Dimensions};
5use crate::error::ChartError;
6use crate::spec::VisualizeSpec;
7
8/// Configuration passed to chart renderers.
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct ChartConfig {
11    /// The visualize spec from the parsed YAML.
12    pub visualize: VisualizeSpec,
13    /// Chart title (if any).
14    pub title: Option<String>,
15    /// Available width in pixels.
16    pub width: f64,
17    /// Available height in pixels.
18    pub height: f64,
19    /// Color palette to use.
20    pub colors: Vec<String>,
21}
22
23/// Chart renderer plugin — converts data + config into a ChartElement tree.
24pub trait ChartRenderer: Send + Sync {
25    /// Render data with the given config into a ChartElement tree.
26    fn render(&self, data: &DataTable, config: &ChartConfig) -> Result<ChartElement, ChartError>;
27
28    /// Optional: provide default dimensions for this chart type.
29    fn default_dimensions(&self, _spec: &VisualizeSpec) -> Option<Dimensions> {
30        None
31    }
32}