lichtung-plot 0.2.0

Strongly typed scientific plotting with deterministic SVG and PNG output
Documentation
//! Owned native inputs and authored configuration, separate from an operation.

use super::{
    Arc, AuthoredAxisSpec, AxisScale, BarPointLayer, BarSpacing, BooleanValues, Bounds,
    CategoryOrders, CategoryValues, FacetSpec, GuideSpec, HeatmapAnnotations, HeatmapLayout,
    HeatmapNullRowAnnotation, HistogramBins, HistogramComposite, HistogramStat, Labels,
    LegendPolicy, LinePathStyle, NumericFormat, PlotInput, PlotKind, PlotTextAnnotation,
    PointLayer, QqLine, RawOverlay, RegressionBand, SourceRows, Theme, WaterfallLabels,
};

#[derive(Clone)]
pub(crate) struct PlotDescription {
    pub(crate) identity: crate::data::InstanceId,
    pub(super) kind: PlotKind,
    pub(super) root_size: crate::layout::RootRequest,
    pub(super) title: crate::Text,
    pub(super) subtitle: crate::Text,
    pub(super) significance_mark_style: Option<crate::elements::SignificanceMarkStyle>,
    pub(super) legend_composition: crate::guides::LegendComposition,
    pub(super) raw_overlay: RawOverlay,
    pub(super) regression_band: RegressionBand,
    pub(super) line_path_style: LinePathStyle,
    pub(super) interaction_connectors: Option<bool>,
    pub(super) payload: Arc<SharedPayload>,
}

#[derive(Clone)]
#[expect(
    clippy::struct_excessive_bools,
    reason = "independent authored chart switches"
)]
pub(super) struct SharedPayload {
    pub(super) input: Arc<PlotInput>,
    pub(super) binding_revisions:
        std::collections::HashMap<crate::data::DataRole, crate::data::InstanceId>,
    pub(super) domain_revisions:
        std::collections::HashMap<crate::data::DomainSlot, crate::data::InstanceId>,
    pub(super) alpha: crate::alpha::AlphaInputs,
    pub(super) source_rows: Option<SourceRows>,
    pub(super) series: Option<CategoryValues>,
    pub(super) hue: Option<CategoryValues>,
    pub(super) group: Option<CategoryValues>,
    pub(super) caption: crate::Text,
    pub(super) x_label: crate::Text,
    pub(super) y_label: crate::Text,
    pub(super) labels: Labels,
    pub(super) axes: [AuthoredAxisSpec; 2],
    pub(super) text_layouts: crate::text::roles::TextRoles,
    pub(super) theme: Option<Arc<Theme>>,
    pub(super) default_theme: Option<Arc<Theme>>,
    pub(super) significance: Vec<crate::significance::SignificanceAnnotation>,
    pub(super) bar_spacing: BarSpacing,
    pub(super) histogram_bins: HistogramBins,
    pub(super) histogram_stat: Option<HistogramStat>,
    pub(super) histogram_composite: Arc<HistogramComposite>,
    pub(super) qq_line: QqLine,
    pub(super) point_outline_visible: bool,
    pub(super) legend_policy: LegendPolicy,
    pub(super) color_label: crate::Text,
    pub(super) raincloud_hue_label: crate::Text,
    pub(super) color_label_format: Option<Arc<NumericFormat>>,
    pub(super) continuous_color_scale: Option<crate::theme::ContinuousColorScale>,
    pub(super) heatmap_layout: HeatmapLayout,
    pub(super) heatmap_annotations: HeatmapAnnotations,
    pub(super) heatmap_null_row_annotations: Vec<HeatmapNullRowAnnotation>,
    pub(super) highlight_cells: Option<BooleanValues>,
    pub(super) estimate_labels: Option<NumericFormat>,
    pub(super) category_orders: CategoryOrders,
    pub(super) color_by_sign: bool,
    pub(super) zero_line: bool,
    pub(super) line_band: Option<Bounds>,
    pub(super) estimate_status: Option<crate::data::EstimateStatusBinding>,
    pub(super) markers_visible: bool,
    pub(super) coefficient_reference_line: Option<f64>,
    pub(super) axis_scale: AxisScale,
    pub(super) facet: Option<FacetSpec>,
    pub(super) interaction_styles: Option<Vec<crate::plots::InteractionStyle>>,
    pub(super) categorical_color_scale: Option<crate::theme::CategoricalColorScale>,
    pub(super) waterfall_labels: Option<WaterfallLabels>,
    pub(super) total_format: Option<Arc<NumericFormat>>,
    pub(super) guides: Vec<GuideSpec>,
    pub(super) point_layers: Vec<PointLayer>,
    pub(super) bar_point_layers: Vec<BarPointLayer>,
    pub(super) panel_text_annotations: Vec<PlotTextAnnotation>,
}

impl PlotDescription {
    pub(crate) const fn legend_composition_spec(&self) -> crate::guides::LegendComposition {
        self.legend_composition
    }

    pub(super) fn new(input: PlotInput, kind: PlotKind) -> Self {
        Self {
            identity: crate::data::InstanceId::new(),
            kind,
            root_size: crate::layout::RootRequest::Natural,
            title: crate::Text::UNSET,
            subtitle: crate::Text::UNSET,
            significance_mark_style: None,
            legend_composition: crate::guides::LegendComposition::Combined,
            raw_overlay: RawOverlay::default(),
            regression_band: RegressionBand::default(),
            line_path_style: LinePathStyle::default(),
            interaction_connectors: None,
            payload: Arc::new(SharedPayload {
                input: Arc::new(input),
                binding_revisions: std::collections::HashMap::new(),
                domain_revisions: std::collections::HashMap::new(),
                alpha: crate::alpha::AlphaInputs::default(),
                source_rows: None,
                series: None,
                hue: None,
                group: None,
                caption: crate::Text::UNSET,
                x_label: crate::Text::UNSET,
                y_label: crate::Text::UNSET,
                labels: Labels::default(),
                axes: [AuthoredAxisSpec::default(), AuthoredAxisSpec::default()],
                text_layouts: crate::text::roles::TextRoles::default(),
                theme: None,
                default_theme: Theme::captured_default(),
                significance: Vec::new(),
                bar_spacing: BarSpacing::default(),
                histogram_bins: HistogramBins::default(),
                histogram_stat: None,
                histogram_composite: Arc::new(HistogramComposite::default()),
                qq_line: QqLine::default(),
                point_outline_visible: true,
                legend_policy: LegendPolicy::Automatic,
                color_label: crate::Text::UNSET,
                raincloud_hue_label: crate::Text::UNSET,
                color_label_format: None,
                continuous_color_scale: None,
                heatmap_layout: HeatmapLayout::default(),
                heatmap_annotations: HeatmapAnnotations::default(),
                heatmap_null_row_annotations: Vec::new(),
                highlight_cells: None,
                estimate_labels: None,
                category_orders: CategoryOrders::default(),
                color_by_sign: false,
                zero_line: false,
                line_band: None,
                estimate_status: None,
                markers_visible: true,
                coefficient_reference_line: None,
                axis_scale: AxisScale::Linear,
                facet: None,
                interaction_styles: None,
                categorical_color_scale: None,
                waterfall_labels: None,
                total_format: None,
                guides: Vec::new(),
                point_layers: Vec::new(),
                bar_point_layers: Vec::new(),
                panel_text_annotations: Vec::new(),
            }),
        }
    }

    pub(super) fn payload_mut(&mut self) -> &mut SharedPayload {
        Arc::make_mut(&mut self.payload)
    }
}