Skip to main content

lichtung_plot/
kind.rs

1//! Plot-family markers and sealed configuration capabilities.
2//!
3//! Constructors return `Plot` values carrying one of these zero-sized markers.
4//! [`crate::kind::Any`] is the explicit erased marker used by heterogeneous storage.
5
6mod sealed {
7    pub trait Sealed: Clone {
8        fn into_erased(plot: crate::Plot<Self>) -> crate::Plot<super::Any>
9        where
10            Self: super::Marker;
11    }
12}
13
14/// A marker admitted as the family parameter of [`crate::Plot`].
15///
16/// This trait is sealed; callers can use its bound but cannot add plot families.
17pub trait Marker: sealed::Sealed + Clone {}
18
19/// An exact plot-family marker that can cross the explicit erasure boundary.
20///
21/// This trait is sealed. It is implemented by every concrete plot-family marker
22/// and is deliberately not implemented by [`Any`].
23pub trait ExactFamily: Marker {}
24
25/// The erased plot-family marker used by heterogeneous storage.
26#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
27pub struct Any;
28
29impl sealed::Sealed for Any {
30    fn into_erased(plot: crate::Plot<Self>) -> crate::Plot<Self> {
31        plot
32    }
33}
34impl Marker for Any {}
35
36macro_rules! markers {
37    ($($name:ident => $documentation:literal),+ $(,)?) => {
38        $(
39            #[doc = $documentation]
40            #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
41            pub struct $name;
42
43            impl sealed::Sealed for $name {
44                fn into_erased(plot: crate::Plot<Self>) -> crate::Plot<Any> {
45                    plot.erase()
46                }
47            }
48            impl Marker for $name {}
49            impl ExactFamily for $name {}
50        )+
51    };
52}
53
54markers! {
55    Scatter => "Scatter-plot family marker.",
56    Histogram => "Histogram family marker for sample-derived or caller-computed geometry.",
57    Density => "Density-plot family marker.",
58    Qq => "Normal Q-Q plot family marker.",
59    PointInterval => "Point-interval family marker.",
60    Line => "Ordinary line-series family marker.",
61    Trajectory => "Repeated-trajectory family marker.",
62    LinePath => "Source-ordered line-path family marker.",
63    Interaction => "Interaction-profile family marker.",
64    Coefficient => "Coefficient-plot family marker.",
65    Forest => "Forest-plot family marker.",
66    Dumbbell => "Dumbbell-plot family marker.",
67    Heatmap => "Heatmap family marker.",
68    Bar => "Vertical ordinary-bar family marker.",
69    HorizontalBar => "Horizontal ordinary-bar family marker.",
70    StackedBar => "Vertical stacked-bar family marker.",
71    StackedHorizontalBar => "Horizontal stacked-bar family marker.",
72    Boxplot => "Boxplot family marker.",
73    Violin => "Mirrored-violin family marker.",
74    Raincloud => "Raincloud family marker for sample-derived or caller-computed geometry.",
75    Regression => "Regression-plot family marker.",
76    Marginal => "Marginal-plot family marker.",
77    Matrix => "Scatter-matrix family marker.",
78    Beeswarm => "Beeswarm-plot family marker.",
79    Waterfall => "Waterfall-plot family marker.",
80}
81
82macro_rules! capability {
83    ($name:ident, $documentation:literal => [$($marker:ty),* $(,)?]) => {
84        #[doc = $documentation]
85        pub trait $name: Marker {}
86
87        $(impl $name for $marker {})*
88    };
89}
90
91capability!(SourceRows, "Plots that accept aligned source-row identities." => [
92    Scatter, Histogram, Density, Qq, PointInterval, Line, Trajectory, LinePath, Interaction, Coefficient, Forest,
93    Dumbbell, Heatmap, Bar, HorizontalBar, StackedBar, StackedHorizontalBar, Boxplot, Violin,
94    Raincloud, Regression, Marginal, Matrix, Beeswarm, Waterfall,
95]);
96capability!(Hue, "Plots that accept categorical color identity." => [
97    Scatter, Density, Line, Trajectory, LinePath, Interaction, Marginal, Matrix,
98]);
99capability!(Group, "Plots that accept graphical grouping identity." => [
100    Density, Line, Marginal, Matrix, Dumbbell,
101]);
102capability!(Series, "Plot markers that expose one optional positioned categorical series; precomputed raincloud geometry rejects it during preflight." => [
103    Bar, HorizontalBar, Boxplot, Violin, Raincloud,
104]);
105capability!(ContinuousColor, "Plots that configure a constructor-owned continuous color channel." => [
106    Heatmap, Beeswarm,
107]);
108capability!(NumericX, "Plots that can expose a numeric horizontal axis." => [
109    Scatter, Histogram, Density, Qq, PointInterval, Line, Trajectory, LinePath, Coefficient, Forest, Dumbbell,
110    HorizontalBar, StackedHorizontalBar, Regression, Marginal, Beeswarm, Waterfall,
111]);
112capability!(NumericY, "Plots that can expose a numeric vertical axis." => [
113    Scatter, Histogram, Density, Qq, Line, Trajectory, LinePath, Interaction, Bar, StackedBar,
114    Boxplot, Violin, Raincloud, Regression, Marginal,
115]);
116capability!(CategoricalX, "Plots that can select horizontal categorical labels; Trajectory checks its actual axis." => [
117    Trajectory, Interaction, Heatmap, Bar, StackedBar, Boxplot, Violin, Raincloud,
118]);
119capability!(XAxisText,"Exact families with actual horizontal coordinate-axis text." => [Scatter,Histogram,Density,Qq,PointInterval,Line,Trajectory,LinePath,Interaction,Coefficient,Forest,Dumbbell,Heatmap,Bar,HorizontalBar,StackedBar,StackedHorizontalBar,Boxplot,Violin,Raincloud,Regression,Marginal,Matrix,Beeswarm,Waterfall]);
120capability!(YAxisText,"Exact families with actual vertical coordinate-axis text." => [Scatter,Histogram,Density,Qq,PointInterval,Line,Trajectory,LinePath,Interaction,Coefficient,Forest,Dumbbell,Heatmap,Bar,HorizontalBar,StackedBar,StackedHorizontalBar,Boxplot,Violin,Raincloud,Regression,Marginal,Matrix,Beeswarm,Waterfall]);
121capability!(EstimateDetailText,"Estimate families with unavailable-row or adjacent-detail text." => [PointInterval,Coefficient,Forest]);
122capability!(CategoricalY, "Plots that can select vertical categorical labels." => [
123    PointInterval, Coefficient, Forest, Dumbbell, Heatmap, HorizontalBar, StackedHorizontalBar, Beeswarm, Waterfall,
124]);
125capability!(Guides, "Plots with at least one numeric axis that accept explicit guides." => [
126    Scatter, Histogram, Density, Qq, PointInterval, Line, Trajectory, LinePath, Interaction, Coefficient, Forest,
127    Dumbbell, Bar, HorizontalBar, StackedBar, StackedHorizontalBar, Boxplot, Violin, Regression,
128    Raincloud, Marginal, Beeswarm, Waterfall,
129]);
130capability!(HeatmapOptions, "Heatmap-specific configuration." => [Heatmap]);
131capability!(CategoryOrder, "Plots that consume one primary categorical order." => [
132    PointInterval, Bar, HorizontalBar, StackedBar, StackedHorizontalBar,
133]);
134capability!(SignedBars, "Bar plots that consume sign-based coloring." => [HorizontalBar]);
135capability!(ZeroLine, "Plots that consume an explicit zero reference line." => [
136    PointInterval, HorizontalBar, StackedHorizontalBar, Beeswarm,
137]);
138capability!(EstimateStatus, "Estimate displays that accept availability status." => [
139    PointInterval, Coefficient, Forest,
140]);
141capability!(Markers, "Line-like plots with configurable estimate markers." => [Line, LinePath, Interaction]);
142capability!(CoefficientOptions, "Coefficient-specific estimate-label configuration." => [
143    Coefficient,
144]);
145capability!(CategoricalScale, "Plots that consume a complete caller-owned categorical scale." => [
146    Scatter, Line, Trajectory, LinePath, Density, Bar, HorizontalBar, StackedBar,
147    StackedHorizontalBar, Boxplot, Interaction, Violin, Raincloud, Marginal, Matrix,
148]);
149capability!(TextAnnotation, "Plots with one standard panel that accept corner text." => [
150    Scatter, Histogram, Density, Qq, PointInterval, Line, Trajectory, LinePath, Interaction, Coefficient, Forest,
151    Dumbbell, Heatmap, Bar, HorizontalBar, StackedBar, StackedHorizontalBar, Boxplot, Violin,
152    Raincloud, Regression, Marginal, Beeswarm, Waterfall,
153]);
154capability!(PointOutline, "Point-rendering families with a configurable outline." => [
155    Scatter, Density, Qq, PointInterval, Line, Trajectory, LinePath, Interaction, Coefficient, Forest,
156    Dumbbell, Boxplot, Violin, Raincloud, Regression, Marginal, Matrix, Beeswarm,
157]);
158capability!(SignificanceStyle, "Plots with configurable significance-mark typography." => [
159    Bar, HorizontalBar, StackedBar, StackedHorizontalBar, Boxplot, Violin, Raincloud, Coefficient,
160]);
161
162/// Plot families that accept significance annotations with placement `P`.
163///
164/// This trait is sealed; its implementations are the exact supported
165/// plot-family and placement combinations.
166pub trait Significance<P>: Marker {}
167
168impl Significance<crate::Attached> for Bar {}
169impl Significance<crate::Attached> for HorizontalBar {}
170impl Significance<crate::Attached> for Coefficient {}
171
172impl Significance<crate::Pairwise> for Bar {}
173impl Significance<crate::Pairwise> for HorizontalBar {}
174impl Significance<crate::Pairwise> for StackedBar {}
175impl Significance<crate::Pairwise> for StackedHorizontalBar {}
176impl Significance<crate::Pairwise> for Boxplot {}
177impl Significance<crate::Pairwise> for Violin {}
178impl Significance<crate::Pairwise> for Raincloud {}
179capability!(Legend, "Plot families that can produce a configurable legend." => [
180    Scatter, Histogram, Density, Qq, PointInterval, Line, Trajectory, LinePath, Interaction,
181    Coefficient, Forest, Dumbbell, Heatmap, Bar, HorizontalBar, StackedBar,
182    StackedHorizontalBar, Boxplot, Violin, Raincloud, Regression, Marginal, Matrix,
183    Beeswarm, Waterfall,
184]);
185capability!(PointAlpha, "Plots that accept explicit observation alpha for actual point fills, independently of outlines and supplemental layers." => [
186    Scatter, Qq, PointInterval, Line, Trajectory, LinePath, Interaction, Coefficient, Forest,
187    Dumbbell, Boxplot, Violin, Raincloud, Regression, Marginal, Matrix, Beeswarm,
188]);
189capability!(LineAlpha, "Plots that accept explicit alpha for their admitted scientific strokes, using actual record, Single, series or aggregate units." => [
190    Histogram, Density, Qq, PointInterval, Line, Trajectory, LinePath, Interaction,
191    Coefficient, Forest, Dumbbell, Bar, HorizontalBar, Boxplot, Violin, Raincloud, Regression,
192]);
193capability!(FillAlpha, "Plots that accept explicit alpha for admitted area/body/cell fills, independently of outlines and supplemental layers." => [
194    Histogram, Density, Line, Heatmap, Bar, HorizontalBar, StackedBar, StackedHorizontalBar,
195    Boxplot, Violin, Raincloud, Regression, Marginal, Matrix, Waterfall,
196]);
197capability!(RawOverlay, "Distribution plots that accept raw-observation overlays." => [
198    Boxplot, Violin,
199]);
200capability!(Facet, "Plot families supported by generic faceting." => [
201    Scatter, Histogram, Density, Qq, PointInterval, Line, Trajectory, LinePath, Interaction, Coefficient, Forest,
202    Dumbbell, Heatmap, Bar, HorizontalBar, StackedBar, StackedHorizontalBar, Boxplot, Violin,
203    Raincloud, Regression, Beeswarm, Waterfall,
204]);