lichtung-plot-ndarray 0.2.0

Direct scientific plotting from logical ndarray views and columns
Documentation
use super::PlotAdapter;
use crate::error::binding;
use crate::{
    binding::{BooleanInput, CategoryInput},
    data::EstimateStatus,
    kind, AdapterError,
};

impl<K: kind::EstimateStatus> PlotAdapter<'_, K> {
    /// Explicitly map Boolean true/false to Estimated/NotEstimable; null is an error.
    pub fn estimate_status_boolean(
        mut self,
        input: impl BooleanInput,
    ) -> std::result::Result<Self, AdapterError> {
        if input.cell_shape().is_some() || input.selected_columns().is_some() {
            return Err(binding(
                "estimate status",
                "expected one Boolean variable, not a cell grid",
            ));
        }
        let capture = self.capture();
        let values = capture.bind(input, 1, |input, source| {
            input.bind_boolean(source, "estimate status")
        })?;
        self.aligned("estimate status", values.name(), values.len())?;
        self.plot = self.plot.estimate_status_boolean(values)?;
        Ok(self)
    }
    /// Map exact raw categorical statuses, rejecting missing/unmapped observations.
    pub fn estimate_status_categorical<I, S>(
        mut self,
        input: impl CategoryInput,
        mapping: I,
    ) -> std::result::Result<Self, AdapterError>
    where
        I: IntoIterator<Item = (S, EstimateStatus)>,
        S: AsRef<str>,
    {
        let capture = self.capture();
        let values = capture.bind(input, 1, |input, source| {
            input.bind_category(source, "estimate status")
        })?;
        self.aligned("estimate status", values.name(), values.len())?;
        self.plot = self.plot.estimate_status_categorical(values, mapping)?;
        Ok(self)
    }
}

impl<K: kind::Marker> PlotAdapter<'_, K> {
    /// Read the native estimate availability declaration, without looking up the source again.
    pub fn get_estimate_status(&self) -> Option<&crate::data::EstimateStatusBinding> {
        self.plot.get_estimate_status()
    }
}