mod sealed {
pub trait Sealed: Clone {
fn into_erased(plot: crate::Plot<Self>) -> crate::Plot<super::Any>
where
Self: super::Marker;
}
}
pub trait Marker: sealed::Sealed + Clone {}
pub trait ExactFamily: Marker {}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Any;
impl sealed::Sealed for Any {
fn into_erased(plot: crate::Plot<Self>) -> crate::Plot<Self> {
plot
}
}
impl Marker for Any {}
macro_rules! markers {
($($name:ident => $documentation:literal),+ $(,)?) => {
$(
#[doc = $documentation]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct $name;
impl sealed::Sealed for $name {
fn into_erased(plot: crate::Plot<Self>) -> crate::Plot<Any> {
plot.erase()
}
}
impl Marker for $name {}
impl ExactFamily for $name {}
)+
};
}
markers! {
Scatter => "Scatter-plot family marker.",
Histogram => "Histogram family marker for sample-derived or caller-computed geometry.",
Density => "Density-plot family marker.",
Qq => "Normal Q-Q plot family marker.",
PointInterval => "Point-interval family marker.",
Line => "Ordinary line-series family marker.",
Trajectory => "Repeated-trajectory family marker.",
LinePath => "Source-ordered line-path family marker.",
Interaction => "Interaction-profile family marker.",
Coefficient => "Coefficient-plot family marker.",
Forest => "Forest-plot family marker.",
Dumbbell => "Dumbbell-plot family marker.",
Heatmap => "Heatmap family marker.",
Bar => "Vertical ordinary-bar family marker.",
HorizontalBar => "Horizontal ordinary-bar family marker.",
StackedBar => "Vertical stacked-bar family marker.",
StackedHorizontalBar => "Horizontal stacked-bar family marker.",
Boxplot => "Boxplot family marker.",
Violin => "Mirrored-violin family marker.",
Raincloud => "Raincloud family marker for sample-derived or caller-computed geometry.",
Regression => "Regression-plot family marker.",
Marginal => "Marginal-plot family marker.",
Matrix => "Scatter-matrix family marker.",
Beeswarm => "Beeswarm-plot family marker.",
Waterfall => "Waterfall-plot family marker.",
}
macro_rules! capabilities {
($($name:ident, $documentation:literal => [$($marker:ident),* $(,)?]);+ $(;)?) => {
$(
#[doc = $documentation]
pub trait $name: Marker {}
$(impl $name for $marker {})*
)+
#[derive(Clone, Copy)]
pub(crate) enum Capability {
$($name),+
}
impl Capability {
pub(crate) const fn admits(self, kind: crate::spec::PlotKind) -> bool {
match self {
$(Self::$name => matches!(kind, $(crate::spec::PlotKind::$marker)|*)),+
}
}
}
};
}
capabilities! {
SourceRows, "Plots that accept aligned source-row identities." => [
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,
];
Hue, "Plots that accept categorical color identity." => [
Scatter, Density, Line, Trajectory, LinePath, Interaction, Marginal, Matrix,
];
Group, "Plots that accept graphical grouping identity." => [
Density, Line, Marginal, Matrix, Dumbbell,
];
Series, "Plot markers that expose one optional positioned categorical series; precomputed raincloud geometry rejects it during preflight." => [
Bar, HorizontalBar, Boxplot, Violin, Raincloud,
];
ContinuousColor, "Plots that configure a constructor-owned continuous color channel." => [
Heatmap, Beeswarm,
];
NumericX, "Plots that can expose a numeric horizontal axis." => [
Scatter, Histogram, Density, Qq, PointInterval, Line, Trajectory, LinePath, Coefficient, Forest, Dumbbell,
HorizontalBar, StackedHorizontalBar, Regression, Marginal, Beeswarm, Waterfall,
];
NumericY, "Plots that can expose a numeric vertical axis." => [
Scatter, Histogram, Density, Qq, Line, Trajectory, LinePath, Interaction, Bar, StackedBar,
Boxplot, Violin, Raincloud, Regression, Marginal,
];
CategoricalX, "Plots that can select horizontal categorical labels; Trajectory checks its actual axis." => [
Trajectory, Interaction, Heatmap, Bar, StackedBar, Boxplot, Violin, Raincloud,
];
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];
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];
EstimateDetailText,"Estimate families with unavailable-row or adjacent-detail text." => [PointInterval,Coefficient,Forest];
CategoricalY, "Plots that can select vertical categorical labels." => [
PointInterval, Coefficient, Forest, Dumbbell, Heatmap, HorizontalBar, StackedHorizontalBar, Beeswarm, Waterfall,
];
Guides, "Plots with at least one numeric axis that accept explicit guides." => [
Scatter, Histogram, Density, Qq, PointInterval, Line, Trajectory, LinePath, Interaction, Coefficient, Forest,
Dumbbell, Bar, HorizontalBar, StackedBar, StackedHorizontalBar, Boxplot, Violin, Regression,
Raincloud, Marginal, Beeswarm, Waterfall,
];
HeatmapOptions, "Heatmap-specific configuration." => [Heatmap];
CategoryOrder, "Plots that consume one primary categorical order." => [
PointInterval, Bar, HorizontalBar, StackedBar, StackedHorizontalBar,
];
SignedBars, "Bar plots that consume sign-based coloring." => [HorizontalBar];
ZeroLine, "Plots that consume an explicit zero reference line." => [
PointInterval, HorizontalBar, StackedHorizontalBar, Beeswarm,
];
EstimateStatus, "Estimate displays that accept availability status." => [
PointInterval, Coefficient, Forest,
];
Markers, "Line-like plots with configurable estimate markers." => [Line, LinePath, Interaction];
CoefficientOptions, "Coefficient-specific estimate-label configuration." => [
Coefficient,
];
CategoricalScale, "Plots that consume a complete caller-owned categorical scale." => [
Scatter, Line, Trajectory, LinePath, Density, Bar, HorizontalBar, StackedBar,
StackedHorizontalBar, Boxplot, Interaction, Violin, Raincloud, Marginal, Matrix,
];
TextAnnotation, "Plots with one standard panel that accept corner text." => [
Scatter, Histogram, Density, Qq, PointInterval, Line, Trajectory, LinePath, Interaction, Coefficient, Forest,
Dumbbell, Heatmap, Bar, HorizontalBar, StackedBar, StackedHorizontalBar, Boxplot, Violin,
Raincloud, Regression, Marginal, Beeswarm, Waterfall,
];
PointOutline, "Point-rendering families with a configurable outline." => [
Scatter, Density, Qq, PointInterval, Line, Trajectory, LinePath, Interaction, Coefficient, Forest,
Dumbbell, Boxplot, Violin, Raincloud, Regression, Marginal, Matrix, Beeswarm,
];
SignificanceStyle, "Plots with configurable significance-mark typography." => [
Bar, HorizontalBar, StackedBar, StackedHorizontalBar, Boxplot, Violin, Raincloud, Coefficient,
];
Legend, "Plot families that can produce a configurable legend." => [
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,
];
PointAlpha, "Plots that accept explicit observation alpha for actual point fills, independently of outlines and supplemental layers." => [
Scatter, Qq, PointInterval, Line, Trajectory, LinePath, Interaction, Coefficient, Forest,
Dumbbell, Boxplot, Violin, Raincloud, Regression, Marginal, Matrix, Beeswarm,
];
LineAlpha, "Plots that accept explicit alpha for their admitted scientific strokes, using actual record, Single, series or aggregate units." => [
Histogram, Density, Qq, PointInterval, Line, Trajectory, LinePath, Interaction,
Coefficient, Forest, Dumbbell, Bar, HorizontalBar, Boxplot, Violin, Raincloud, Regression,
];
FillAlpha, "Plots that accept explicit alpha for admitted area/body/cell fills, independently of outlines and supplemental layers." => [
Histogram, Density, Line, Heatmap, Bar, HorizontalBar, StackedBar, StackedHorizontalBar,
Boxplot, Violin, Raincloud, Regression, Marginal, Matrix, Waterfall,
];
RawOverlay, "Distribution plots that accept raw-observation overlays." => [
Boxplot, Violin,
];
Facet, "Plot families supported by generic faceting." => [
Scatter, Histogram, Density, Qq, PointInterval, Line, Trajectory, LinePath, Interaction, Coefficient, Forest,
Dumbbell, Heatmap, Bar, HorizontalBar, StackedBar, StackedHorizontalBar, Boxplot, Violin,
Raincloud, Regression, Beeswarm, Waterfall,
];
}
pub trait Significance<P>: Marker {}
macro_rules! significance_capability {
($placement:ident, $method:ident => [$($marker:ident),+]) => {
$(impl Significance<crate::elements::$placement> for $marker {})+
impl crate::spec::PlotKind {
pub(crate) const fn $method(self) -> bool {
matches!(self, $(Self::$marker)|+)
}
}
};
}
significance_capability!(Attached, admits_attached_significance => [Bar, HorizontalBar, Coefficient]);
significance_capability!(Pairwise, admits_pairwise_significance => [
Bar, HorizontalBar, StackedBar, StackedHorizontalBar, Boxplot, Violin, Raincloud
]);