use super::PlotAdapter;
use crate::{
coordinates::{AxisScale, AxisTick, CategoryLabelSelection, CategoryOrder, TickGeneration},
data::EstimateStatus,
elements::{
BarPointLayer, GuideSpec, PlotTextAnnotation, PointLayer, Significance,
SignificanceMarkStyle,
},
guides::{GuideTextRole, LegendComposition, LegendPolicy},
kind,
output::PngOptions,
plots::{
BarSpacing, HeatmapAnnotations, HeatmapLayout, HeatmapNullRowAnnotation,
HistogramComposite, InteractionStyle, LinePathStyle, QqLine, RawOverlay, WaterfallLabels,
},
scales::{CategoricalColorScale, ContinuousColorScale},
stats::{HistogramBins, HistogramStat, RegressionBand},
text::{TextAlignment, TextLayout},
NumericFormat, Output, Text, Theme,
};
use std::path::Path;
macro_rules! forward {
($name:ident($($arg:ident:$ty:ty),*) $(=>$bound:ident)?) => {
impl<K:kind::Marker> PlotAdapter<'_,K> {
#[doc=concat!("Forward native [`crate::Plot::",stringify!($name),"`] configuration.")]
#[must_use]
pub fn $name(mut self,$($arg:$ty),*)->Self $(where K:kind::$bound)? { self.plot=self.plot.$name($($arg),*); self }
}
};
}
forward!(title(text:impl Into<Text>));
forward!(subtitle(text:impl Into<Text>));
forward!(caption(text:impl Into<Text>));
forward!(x_label(text:impl Into<Text>));
forward!(y_label(text:impl Into<Text>));
forward!(clear_title_style());
forward!(clear_title_layout());
forward!(clear_subtitle_style());
forward!(clear_subtitle_layout());
forward!(clear_caption_style());
forward!(clear_caption_layout());
forward!(clear_x_label_style());
forward!(clear_x_label_layout());
forward!(clear_y_label_style());
forward!(clear_y_label_layout());
forward!(clear_color_label_style()=>ContinuousColor);
forward!(clear_color_label_layout()=>ContinuousColor);
forward!(title_alignment(alignment:TextAlignment));
forward!(subtitle_alignment(alignment:TextAlignment));
forward!(theme(theme:impl Into<Option<Theme>>));
forward!(default_theme(theme: impl Into<Option<Theme>>));
forward!(width(width:u32));
forward!(max_width(maximum:u32));
forward!(size(width:u32,height:u32));
forward!(color_label(label:impl Into<Text>)=>ContinuousColor);
forward!(color_label_format(format:NumericFormat)=>ContinuousColor);
forward!(heatmap_null_row_annotation(annotation:HeatmapNullRowAnnotation)=>HeatmapOptions);
forward!(estimate_labels(format:NumericFormat)=>CoefficientOptions);
forward!(significance_mark_style(style:SignificanceMarkStyle)=>SignificanceStyle);
forward!(text_annotation(annotation:PlotTextAnnotation)=>TextAnnotation);
forward!(x_category_labels(selection:CategoryLabelSelection)=>CategoricalX);
forward!(y_category_labels(selection:CategoryLabelSelection)=>CategoricalY);
forward!(category_order(order:impl Into<CategoryOrder>)=>CategoryOrder);
forward!(x_category_order(order:impl Into<CategoryOrder>)=>HeatmapOptions);
forward!(y_category_order(order:impl Into<CategoryOrder>)=>HeatmapOptions);
forward!(x_limits(min:f64,max:f64)=>NumericX);
forward!(y_limits(min:f64,max:f64)=>NumericY);
forward!(x_ticks(ticks:Vec<AxisTick>)=>NumericX);
forward!(y_ticks(ticks:Vec<AxisTick>)=>NumericY);
forward!(x_tick_generation(generation:TickGeneration)=>NumericX);
forward!(y_tick_generation(generation:TickGeneration)=>NumericY);
forward!(x_tick_format(format:NumericFormat)=>NumericX);
forward!(y_tick_format(format:NumericFormat)=>NumericY);
forward!(guide(guide:GuideSpec)=>Guides);
forward!(categorical_color_scale(scale:CategoricalColorScale)=>CategoricalScale);
forward!(continuous_color_scale(scale:ContinuousColorScale)=>ContinuousColor);
forward!(color_by_sign()=>SignedBars);
forward!(zero_line()=>ZeroLine);
forward!(hide_point_outline()=>PointOutline);
forward!(show_markers(visible:bool)=>Markers);
forward!(legend(policy:LegendPolicy)=>Legend);
forward!(legend_composition(composition:LegendComposition)=>Legend);
forward!(raw_overlay(overlay:RawOverlay)=>RawOverlay);
forward!(estimate_status(statuses:impl IntoIterator<Item=EstimateStatus>)=>EstimateStatus);
forward!(x_tick_text_layout(layout:TextLayout)=>XAxisText);
forward!(y_tick_text_layout(layout:TextLayout)=>YAxisText);
forward!(facet_row_text_layout(layout:TextLayout)=>Facet);
forward!(facet_column_text_layout(layout:TextLayout)=>Facet);
forward!(estimate_detail_text_layout(layout:TextLayout)=>EstimateDetailText);
forward!(significance_text_layout(layout:TextLayout)=>SignificanceStyle);
forward!(guide_text_layout(role:GuideTextRole,layout:TextLayout)=>Legend);
macro_rules! family_forward {
($kind:ident,$name:ident($($arg:ident:$ty:ty),*)) => {
impl PlotAdapter<'_,kind::$kind> {
#[doc=concat!("Forward native ",stringify!($kind)," `",stringify!($name),"` configuration.")]
#[must_use]
pub fn $name(mut self,$($arg:$ty),*)->Self { self.plot=self.plot.$name($($arg),*); self }
}
};
}
family_forward!(Heatmap,layout(layout:HeatmapLayout));
family_forward!(Heatmap,annotations(annotations:HeatmapAnnotations));
family_forward!(Heatmap,value_text_layout(layout:TextLayout));
family_forward!(Heatmap,null_row_text_layout(layout:TextLayout));
family_forward!(Forest,scale(scale:AxisScale));
family_forward!(Bar,spacing(spacing:BarSpacing));
family_forward!(HorizontalBar,spacing(spacing:BarSpacing));
family_forward!(Histogram,bins(bins:HistogramBins));
family_forward!(Histogram,stat(stat:HistogramStat));
family_forward!(Histogram,composite(composite:HistogramComposite));
family_forward!(Qq,reference_line(line:QqLine));
family_forward!(Regression,band(band:RegressionBand));
family_forward!(LinePath,style(style:LinePathStyle));
family_forward!(Raincloud,hue_label(label:impl Into<Text>));
family_forward!(Raincloud, clear_hue_label_style());
family_forward!(Raincloud, clear_hue_label_layout());
family_forward!(Coefficient,reference_line(value:f64));
family_forward!(Interaction,connectors(visible:bool));
family_forward!(Interaction,styles(styles:impl IntoIterator<Item=InteractionStyle>));
family_forward!(Waterfall,total_format(format:NumericFormat));
family_forward!(Waterfall,total_labels(labels:WaterfallLabels));
family_forward!(Waterfall,total_text_layout(layout:TextLayout));
family_forward!(Matrix,matrix_row_text_layout(layout:TextLayout));
family_forward!(Matrix,matrix_column_text_layout(layout:TextLayout));
macro_rules! layer_forward {
($family:ident,$layer:ty) => {
impl PlotAdapter<'_, kind::$family> {
#[must_use]
pub fn point_layer(mut self, layer: impl Into<$layer>) -> Self {
self.plot = self.plot.point_layer(layer.into());
self
}
}
};
}
layer_forward!(Line, PointLayer);
layer_forward!(Bar, BarPointLayer);
layer_forward!(HorizontalBar, BarPointLayer);
impl<K: kind::Facet> PlotAdapter<'_, K> {
#[must_use]
pub fn get_facet(&self) -> Option<&crate::layout::FacetSpec> {
self.plot.get_facet()
}
}
impl<K: kind::Marker> PlotAdapter<'_, K> {
pub fn get_theme(&self) -> Option<&Theme> {
self.plot.get_theme()
}
pub fn get_default_theme(&self) -> Option<&Theme> {
self.plot.get_default_theme()
}
pub fn get_point_alpha(&self) -> &crate::scales::AlphaEncoding {
self.plot.get_point_alpha()
}
pub fn get_line_alpha(&self) -> &crate::scales::AlphaEncoding {
self.plot.get_line_alpha()
}
pub fn get_fill_alpha(&self) -> &crate::scales::AlphaEncoding {
self.plot.get_fill_alpha()
}
#[must_use]
pub fn get_labels(&self) -> &crate::formatting::Labels {
self.plot.get_labels()
}
pub fn size_with_unit(
mut self,
width: f64,
height: f64,
unit: crate::layout::SizeUnit,
) -> crate::Result<Self> {
self.plot = self.plot.size_with_unit(width, height, unit)?;
Ok(self)
}
pub fn preflight(&self) -> crate::Result<()> {
self.plot.preflight()
}
pub fn preflight_with_operation(
&self,
options: &crate::operation::OperationOptions,
) -> crate::Result<()> {
self.plot.preflight_with_operation(options)
}
pub fn render(&self) -> crate::Result<Output> {
self.plot.render()
}
pub fn render_with_operation(
&self,
options: &crate::operation::OperationOptions,
) -> crate::Result<Output> {
self.plot.render_with_operation(options)
}
pub fn render_with_results(&self) -> crate::Result<crate::stats::RenderWithResults> {
self.plot.render_with_results()
}
pub fn render_with_results_with_operation(
&self,
options: &crate::operation::OperationOptions,
) -> crate::Result<crate::stats::RenderWithResults> {
self.plot.render_with_results_with_operation(options)
}
#[must_use]
pub fn significance<P>(mut self, annotations: impl IntoIterator<Item = Significance<P>>) -> Self
where
K: kind::Significance<P>,
{
self.plot = self.plot.significance(annotations);
self
}
pub fn svg(&self, path: impl AsRef<Path>) -> crate::Result<Output> {
self.plot.svg(path)
}
pub fn svg_with_operation(
&self,
path: impl AsRef<Path>,
options: &crate::operation::OperationOptions,
) -> crate::Result<Output> {
self.plot.svg_with_operation(path, options)
}
pub fn svg_preserve_text(&self, path: impl AsRef<Path>) -> crate::Result<Output> {
self.plot.svg_preserve_text(path)
}
pub fn svg_preserve_text_with_operation(
&self,
path: impl AsRef<Path>,
options: &crate::operation::OperationOptions,
) -> crate::Result<Output> {
self.plot.svg_preserve_text_with_operation(path, options)
}
pub fn png(&self, path: impl AsRef<Path>) -> crate::Result<Output> {
self.plot.png(path)
}
pub fn png_with_operation(
&self,
path: impl AsRef<Path>,
options: &crate::operation::OperationOptions,
) -> crate::Result<Output> {
self.plot.png_with_operation(path, options)
}
pub fn png_preview(&self, path: impl AsRef<Path>) -> crate::Result<Output> {
self.plot.png_preview(path)
}
pub fn png_preview_with_operation(
&self,
path: impl AsRef<Path>,
options: &crate::operation::OperationOptions,
) -> crate::Result<Output> {
self.plot.png_preview_with_operation(path, options)
}
pub fn png_with_options(
&self,
path: impl AsRef<Path>,
options: PngOptions,
) -> crate::Result<Output> {
self.plot.png_with_options(path, options)
}
pub fn png_with_options_with_operation(
&self,
path: impl AsRef<Path>,
options: PngOptions,
operation: &crate::operation::OperationOptions,
) -> crate::Result<Output> {
self.plot
.png_with_options_with_operation(path, options, operation)
}
}
impl<K: crate::kind::Marker> PlotAdapter<'_, K> {
pub fn data_roles(
&self,
) -> std::result::Result<Vec<crate::data::DataRoleInfo>, crate::AdapterError> {
Ok(self.plot.data_roles()?)
}
pub fn data_roles_at(
&self,
target: &crate::elements::ElementRef,
) -> std::result::Result<Vec<crate::data::DataRoleInfo>, crate::AdapterError> {
Ok(self.plot.data_roles_at(target)?)
}
pub fn data_roles_in(
&self,
panel: &crate::layout::PanelPath,
) -> std::result::Result<Vec<crate::data::DataRoleInfo>, crate::AdapterError> {
Ok(self.plot.data_roles_in(panel)?)
}
pub fn data(
&self,
selector: impl Into<crate::data::DataSelector>,
) -> std::result::Result<crate::data::DataValue, crate::AdapterError> {
Ok(self.plot.data(selector)?)
}
pub fn elements(
&self,
query: crate::elements::ElementQuery,
) -> std::result::Result<Vec<crate::elements::ElementRef>, crate::AdapterError> {
Ok(self.plot.elements(query)?)
}
pub fn element_ref(
&self,
query: impl Into<crate::elements::ElementQuery>,
) -> std::result::Result<crate::elements::ElementRef, crate::AdapterError> {
Ok(self.plot.element_ref(query)?)
}
pub fn read_element(
&self,
reference: &crate::elements::ElementRef,
) -> std::result::Result<crate::elements::ElementSnapshot, crate::AdapterError> {
Ok(self.plot.read_element(reference)?)
}
}
impl<K: kind::Marker> PlotAdapter<'_, K> {
pub fn get_significance(&self) -> Option<&[crate::elements::SignificanceAnnotation]> {
self.plot.get_significance()
}
}
macro_rules! stat_result {
($kind:ident, $result:ty) => {
impl PlotAdapter<'_, kind::$kind> {
pub fn stat_result(&self) -> crate::Result<$result> {
self.plot.stat_result()
}
pub fn stat_result_with_operation(
&self,
options: &crate::operation::OperationOptions,
) -> crate::Result<$result> {
self.plot.stat_result_with_operation(options)
}
pub fn stat_result_in(
&self,
panel: &crate::layout::PanelPath,
) -> crate::Result<$result> {
self.plot.stat_result_in(panel)
}
pub fn stat_result_in_with_operation(
&self,
panel: &crate::layout::PanelPath,
options: &crate::operation::OperationOptions,
) -> crate::Result<$result> {
self.plot.stat_result_in_with_operation(panel, options)
}
}
};
}
stat_result!(Histogram, crate::plots::HistogramResult);
stat_result!(Density, crate::plots::DensityResult);
stat_result!(Qq, crate::plots::ProbabilityPlotResult);
stat_result!(Regression, crate::stats::FitResult);
stat_result!(Bar, crate::stats::StatResult);
stat_result!(HorizontalBar, crate::stats::StatResult);
stat_result!(StackedBar, crate::stats::StatResult);
stat_result!(StackedHorizontalBar, crate::stats::StatResult);
stat_result!(Interaction, crate::stats::StatResult);
stat_result!(Waterfall, crate::stats::StatResult);
stat_result!(Boxplot, crate::plots::BoxSummary);
stat_result!(Violin, crate::plots::DensityProfiles);
stat_result!(Raincloud, crate::plots::RaincloudGeometry);
stat_result!(PointInterval, crate::stats::StatResult);
stat_result!(Forest, crate::stats::StatResult);
stat_result!(Coefficient, crate::stats::StatResult);
macro_rules! density_group_result {
($kind:ident) => {
impl PlotAdapter<'_, kind::$kind> {
pub fn stat_result_group(
&self,
panel: &crate::layout::PanelPath,
group: &crate::data::GroupKey,
) -> crate::Result<crate::plots::DensityResult> {
self.plot.stat_result_group(panel, group)
}
pub fn stat_result_group_with_operation(
&self,
panel: &crate::layout::PanelPath,
group: &crate::data::GroupKey,
options: &crate::operation::OperationOptions,
) -> crate::Result<crate::plots::DensityResult> {
self.plot
.stat_result_group_with_operation(panel, group, options)
}
}
};
}
density_group_result!(Density);
density_group_result!(Marginal);
density_group_result!(Matrix);
macro_rules! regional_density_result {
($kind:ident) => {
impl PlotAdapter<'_, kind::$kind> {
pub fn stat_result_in(
&self,
panel: &crate::layout::PanelPath,
) -> crate::Result<crate::plots::DensityResult> {
self.plot.stat_result_in(panel)
}
pub fn stat_result_in_with_operation(
&self,
panel: &crate::layout::PanelPath,
options: &crate::operation::OperationOptions,
) -> crate::Result<crate::plots::DensityResult> {
self.plot.stat_result_in_with_operation(panel, options)
}
}
};
}
regional_density_result!(Marginal);
regional_density_result!(Matrix);