Skip to main content

chartml_core/pipeline/
render_options.rs

1//! Render-time options for the three-stage pipeline.
2//!
3//! Consolidates the scattered `container_width`, `container_height`, and
4//! `param_overrides` arguments that the legacy `render_from_yaml_*` family
5//! used to take individually. A single `&RenderOptions` parameter threads
6//! through every stage (`fetch`, `transform`, `render_prepared_to_svg`,
7//! `render_to_svg_async`) so future fields (e.g. `theme`, `density`,
8//! `cancel_token`) can be added without breaking signatures.
9
10use crate::params::ParamValues;
11
12/// Render-time knobs for the chartml 5.0 pipeline.
13///
14/// Defaults preserve every legacy behavior: `width` / `height` of `None`
15/// fall through to the spec's `style.width` / `style.height`, then to the
16/// renderer's default dimensions (e.g. 800×400 for cartesian charts);
17/// `params` of `None` matches the legacy "no param overrides" path. Cloning
18/// is cheap — fields are scalar plus a small `HashMap`.
19#[derive(Debug, Clone, Default)]
20pub struct RenderOptions {
21    /// Container width override in CSS pixels. `None` means "use the spec
22    /// or the renderer's default".
23    pub width: Option<f64>,
24    /// Container height override in CSS pixels. `None` means "use the spec
25    /// or the renderer's default".
26    pub height: Option<f64>,
27    /// Interactive parameter values (e.g. dropdown selections) layered on
28    /// top of `params:` defaults declared in the YAML. `None` skips param
29    /// overrides entirely.
30    pub params: Option<ParamValues>,
31}
32
33impl RenderOptions {
34    /// Build options that only override the canvas size — no param values.
35    /// Sugar for the common "I just want a different width/height" call site.
36    pub fn with_size(width: Option<f64>, height: Option<f64>) -> Self {
37        Self {
38            width,
39            height,
40            params: None,
41        }
42    }
43
44    /// Borrow the parameter overrides (if any). Matches the
45    /// `Option<&ParamValues>` shape every internal callsite already uses.
46    pub fn params_ref(&self) -> Option<&ParamValues> {
47        self.params.as_ref()
48    }
49}