Skip to main content

lichtung_plot_ndarray/frontend/
status.rs

1use super::PlotAdapter;
2use crate::error::binding;
3use crate::{
4    binding::{BooleanInput, CategoryInput},
5    data::EstimateStatus,
6    kind, AdapterError,
7};
8
9impl<K: kind::EstimateStatus> PlotAdapter<'_, K> {
10    /// Explicitly map Boolean true/false to Estimated/NotEstimable; null is an error.
11    pub fn estimate_status_boolean(
12        mut self,
13        input: impl BooleanInput,
14    ) -> std::result::Result<Self, AdapterError> {
15        if input.cell_shape().is_some() || input.selected_columns().is_some() {
16            return Err(binding(
17                "estimate status",
18                "expected one Boolean variable, not a cell grid",
19            ));
20        }
21        let capture = self.capture();
22        let values = capture.bind(input, 1, |input, source| {
23            input.bind_boolean(source, "estimate status")
24        })?;
25        self.aligned("estimate status", values.name(), values.len())?;
26        self.plot = self.plot.estimate_status_boolean(values)?;
27        Ok(self)
28    }
29    /// Map exact raw categorical statuses, rejecting missing/unmapped observations.
30    pub fn estimate_status_categorical<I, S>(
31        mut self,
32        input: impl CategoryInput,
33        mapping: I,
34    ) -> std::result::Result<Self, AdapterError>
35    where
36        I: IntoIterator<Item = (S, EstimateStatus)>,
37        S: AsRef<str>,
38    {
39        let capture = self.capture();
40        let values = capture.bind(input, 1, |input, source| {
41            input.bind_category(source, "estimate status")
42        })?;
43        self.aligned("estimate status", values.name(), values.len())?;
44        self.plot = self.plot.estimate_status_categorical(values, mapping)?;
45        Ok(self)
46    }
47}
48
49impl<K: kind::Marker> PlotAdapter<'_, K> {
50    /// Read the native estimate availability declaration, without looking up the source again.
51    pub fn get_estimate_status(&self) -> Option<&crate::data::EstimateStatusBinding> {
52        self.plot.get_estimate_status()
53    }
54}