lichtung-plot 0.3.0

Strongly typed scientific plotting with deterministic SVG and PNG output
Documentation
//! Readback of actual owning scientific declarations.

use std::sync::Arc;

use super::{
    ArrayValues, AxisValues, DateValues, DurationValues, EstimateStatus, IntegerValues, KeyColumns,
    RawKeyValues, TimeValues, VariableValues,
};
use crate::{
    plots::{HistogramGeometry, HistogramKde, RaincloudGeometry},
    scales::AlphaEncoding,
    BooleanValues, CategoryValues, NumericValues,
};

macro_rules! payloads {
    ($($variant:ident($ty:ty) => $name:literal),+ $(,)?) => {
        /// Owned original values as supplied to the native declaration.
        #[derive(Debug, Clone)]
        #[non_exhaustive]
        #[expect(clippy::large_enum_variant, reason = "own the exact public native payload types through the shared DataValue snapshot")]
        pub enum DataPayload {
            $(#[doc = concat!("Actual ", $name, " values.")] $variant($ty),)+
        }

        /// Discriminant of the actual native payload, independent of its role.
        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
        #[non_exhaustive]
        pub enum DataValueType {
            $(#[doc = concat!("Actual ", $name, " payload.")] $variant,)+
        }

        impl DataPayload {
            /// The actual payload type.
            pub const fn value_type(&self) -> DataValueType {
                match self {
                    $(Self::$variant(_) => DataValueType::$variant,)+
                }
            }
        }

        impl DataValueType {
            /// Canonical spelling for typed language bindings.
            #[doc(hidden)]
            pub const fn as_str(self) -> &'static str {
                match self {
                    $(Self::$variant => $name,)+
                }
            }
        }
    };
}

payloads!(
    Numeric(NumericValues) => "numeric",
    Category(CategoryValues) => "category",
    RawKeys(RawKeyValues) => "raw_keys",
    Boolean(BooleanValues) => "boolean",
    Integer(IntegerValues) => "integer",
    Date(DateValues) => "date",
    Instant(TimeValues) => "instant",
    Duration(DurationValues) => "duration",
    Axis(AxisValues) => "axis",
    Array(ArrayValues) => "array",
    EstimateStatuses(Arc<[EstimateStatus]>) => "estimate_statuses",
    HistogramKde(HistogramKde) => "histogram_kde",
    HistogramGeometry(HistogramGeometry) => "histogram_geometry",
    RaincloudGeometry(RaincloudGeometry) => "raincloud_geometry",
    Variables(VariableValues) => "variables",
    KeyColumns(KeyColumns) => "key_columns",
    AlphaEncoding(AlphaEncoding) => "alpha_encoding",
);