1mod 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
14pub trait Marker: sealed::Sealed + Clone {}
18
19pub trait ExactFamily: Marker {}
24
25#[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! capabilities {
83 ($($name:ident, $documentation:literal => [$($marker:ident),* $(,)?]);+ $(;)?) => {
84 $(
85 #[doc = $documentation]
86 pub trait $name: Marker {}
87 $(impl $name for $marker {})*
88 )+
89
90 #[derive(Clone, Copy)]
91 pub(crate) enum Capability {
92 $($name),+
93 }
94
95 impl Capability {
96 pub(crate) const fn admits(self, kind: crate::spec::PlotKind) -> bool {
97 match self {
98 $(Self::$name => matches!(kind, $(crate::spec::PlotKind::$marker)|*)),+
99 }
100 }
101 }
102 };
103}
104
105capabilities! {
106 SourceRows, "Plots that accept aligned source-row identities." => [
107 Scatter, Histogram, Density, Qq, PointInterval, Line, Trajectory, LinePath, Interaction, Coefficient, Forest,
108 Dumbbell, Heatmap, Bar, HorizontalBar, StackedBar, StackedHorizontalBar, Boxplot, Violin,
109 Raincloud, Regression, Marginal, Matrix, Beeswarm, Waterfall,
110 ];
111 Hue, "Plots that accept categorical color identity." => [
112 Scatter, Density, Line, Trajectory, LinePath, Interaction, Marginal, Matrix,
113 ];
114 Group, "Plots that accept graphical grouping identity." => [
115 Density, Line, Marginal, Matrix, Dumbbell,
116 ];
117 Series, "Plot markers that expose one optional positioned categorical series; precomputed raincloud geometry rejects it during preflight." => [
118 Bar, HorizontalBar, Boxplot, Violin, Raincloud,
119 ];
120 ContinuousColor, "Plots that configure a constructor-owned continuous color channel." => [
121 Heatmap, Beeswarm,
122 ];
123 NumericX, "Plots that can expose a numeric horizontal axis." => [
124 Scatter, Histogram, Density, Qq, PointInterval, Line, Trajectory, LinePath, Coefficient, Forest, Dumbbell,
125 HorizontalBar, StackedHorizontalBar, Regression, Marginal, Beeswarm, Waterfall,
126 ];
127 NumericY, "Plots that can expose a numeric vertical axis." => [
128 Scatter, Histogram, Density, Qq, Line, Trajectory, LinePath, Interaction, Bar, StackedBar,
129 Boxplot, Violin, Raincloud, Regression, Marginal,
130 ];
131 CategoricalX, "Plots that can select horizontal categorical labels; Trajectory checks its actual axis." => [
132 Trajectory, Interaction, Heatmap, Bar, StackedBar, Boxplot, Violin, Raincloud,
133 ];
134 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];
135 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];
136 EstimateDetailText,"Estimate families with unavailable-row or adjacent-detail text." => [PointInterval,Coefficient,Forest];
137 CategoricalY, "Plots that can select vertical categorical labels." => [
138 PointInterval, Coefficient, Forest, Dumbbell, Heatmap, HorizontalBar, StackedHorizontalBar, Beeswarm, Waterfall,
139 ];
140 Guides, "Plots with at least one numeric axis that accept explicit guides." => [
141 Scatter, Histogram, Density, Qq, PointInterval, Line, Trajectory, LinePath, Interaction, Coefficient, Forest,
142 Dumbbell, Bar, HorizontalBar, StackedBar, StackedHorizontalBar, Boxplot, Violin, Regression,
143 Raincloud, Marginal, Beeswarm, Waterfall,
144 ];
145 HeatmapOptions, "Heatmap-specific configuration." => [Heatmap];
146 CategoryOrder, "Plots that consume one primary categorical order." => [
147 PointInterval, Bar, HorizontalBar, StackedBar, StackedHorizontalBar,
148 ];
149 SignedBars, "Bar plots that consume sign-based coloring." => [HorizontalBar];
150 ZeroLine, "Plots that consume an explicit zero reference line." => [
151 PointInterval, HorizontalBar, StackedHorizontalBar, Beeswarm,
152 ];
153 EstimateStatus, "Estimate displays that accept availability status." => [
154 PointInterval, Coefficient, Forest,
155 ];
156 Markers, "Line-like plots with configurable estimate markers." => [Line, LinePath, Interaction];
157 CoefficientOptions, "Coefficient-specific estimate-label configuration." => [
158 Coefficient,
159 ];
160 CategoricalScale, "Plots that consume a complete caller-owned categorical scale." => [
161 Scatter, Line, Trajectory, LinePath, Density, Bar, HorizontalBar, StackedBar,
162 StackedHorizontalBar, Boxplot, Interaction, Violin, Raincloud, Marginal, Matrix,
163 ];
164 TextAnnotation, "Plots with one standard panel that accept corner text." => [
165 Scatter, Histogram, Density, Qq, PointInterval, Line, Trajectory, LinePath, Interaction, Coefficient, Forest,
166 Dumbbell, Heatmap, Bar, HorizontalBar, StackedBar, StackedHorizontalBar, Boxplot, Violin,
167 Raincloud, Regression, Marginal, Beeswarm, Waterfall,
168 ];
169 PointOutline, "Point-rendering families with a configurable outline." => [
170 Scatter, Density, Qq, PointInterval, Line, Trajectory, LinePath, Interaction, Coefficient, Forest,
171 Dumbbell, Boxplot, Violin, Raincloud, Regression, Marginal, Matrix, Beeswarm,
172 ];
173 SignificanceStyle, "Plots with configurable significance-mark typography." => [
174 Bar, HorizontalBar, StackedBar, StackedHorizontalBar, Boxplot, Violin, Raincloud, Coefficient,
175 ];
176
177 Legend, "Plot families that can produce a configurable legend." => [
178 Scatter, Histogram, Density, Qq, PointInterval, Line, Trajectory, LinePath, Interaction,
179 Coefficient, Forest, Dumbbell, Heatmap, Bar, HorizontalBar, StackedBar,
180 StackedHorizontalBar, Boxplot, Violin, Raincloud, Regression, Marginal, Matrix,
181 Beeswarm, Waterfall,
182 ];
183 PointAlpha, "Plots that accept explicit observation alpha for actual point fills, independently of outlines and supplemental layers." => [
184 Scatter, Qq, PointInterval, Line, Trajectory, LinePath, Interaction, Coefficient, Forest,
185 Dumbbell, Boxplot, Violin, Raincloud, Regression, Marginal, Matrix, Beeswarm,
186 ];
187 LineAlpha, "Plots that accept explicit alpha for their admitted scientific strokes, using actual record, Single, series or aggregate units." => [
188 Histogram, Density, Qq, PointInterval, Line, Trajectory, LinePath, Interaction,
189 Coefficient, Forest, Dumbbell, Bar, HorizontalBar, Boxplot, Violin, Raincloud, Regression,
190 ];
191 FillAlpha, "Plots that accept explicit alpha for admitted area/body/cell fills, independently of outlines and supplemental layers." => [
192 Histogram, Density, Line, Heatmap, Bar, HorizontalBar, StackedBar, StackedHorizontalBar,
193 Boxplot, Violin, Raincloud, Regression, Marginal, Matrix, Waterfall,
194 ];
195 RawOverlay, "Distribution plots that accept raw-observation overlays." => [
196 Boxplot, Violin,
197 ];
198 Facet, "Plot families supported by generic faceting." => [
199 Scatter, Histogram, Density, Qq, PointInterval, Line, Trajectory, LinePath, Interaction, Coefficient, Forest,
200 Dumbbell, Heatmap, Bar, HorizontalBar, StackedBar, StackedHorizontalBar, Boxplot, Violin,
201 Raincloud, Regression, Beeswarm, Waterfall,
202 ];
203}
204
205pub trait Significance<P>: Marker {}
210
211macro_rules! significance_capability {
212 ($placement:ident, $method:ident => [$($marker:ident),+]) => {
213 $(impl Significance<crate::elements::$placement> for $marker {})+
214 impl crate::spec::PlotKind {
215 pub(crate) const fn $method(self) -> bool {
216 matches!(self, $(Self::$marker)|+)
217 }
218 }
219 };
220}
221significance_capability!(Attached, admits_attached_significance => [Bar, HorizontalBar, Coefficient]);
222significance_capability!(Pairwise, admits_pairwise_significance => [
223 Bar, HorizontalBar, StackedBar, StackedHorizontalBar, Boxplot, Violin, Raincloud
224]);