lichtung_plot_ndarray/frontend/
forwarding.rs1use super::PlotAdapter;
3use crate::{
4 kind, AxisScale, AxisTick, BarPointLayer, BarSpacing, CategoricalColorScale,
5 CategoryLabelSelection, CategoryOrder, ContinuousColorScale, EstimateStatus, GuideSpec,
6 GuideTextRole, HeatmapAnnotations, HeatmapLayout, HeatmapNullRowAnnotation, HistogramBins,
7 HistogramComposite, HistogramStat, InteractionStyle, LegendComposition, LegendPolicy,
8 LinePathStyle, NumericFormat, Output, PlotTextAnnotation, PngOptions, PointLayer, QqLine,
9 RawOverlay, RegressionBand, Significance, SignificanceMarkStyle, Text, TextAlignment,
10 TextLayout, Theme, TickGeneration, WaterfallLabels,
11};
12use std::path::Path;
13
14macro_rules! forward {
15 ($name:ident($($arg:ident:$ty:ty),*) $(=>$bound:ident)?) => {
16 impl<K:kind::Marker> PlotAdapter<'_,K> {
17 #[doc=concat!("Forward native [`crate::Plot::",stringify!($name),"`] configuration.")]
18 #[must_use]
19 pub fn $name(mut self,$($arg:$ty),*)->Self $(where K:kind::$bound)? { self.plot=self.plot.$name($($arg),*); self }
20 }
21 };
22}
23forward!(title(text:impl Into<Text>));
24forward!(subtitle(text:impl Into<Text>));
25forward!(caption(text:impl Into<Text>));
26forward!(x_label(text:impl Into<Text>));
27forward!(y_label(text:impl Into<Text>));
28forward!(clear_title_style());
29forward!(clear_title_layout());
30forward!(clear_subtitle_style());
31forward!(clear_subtitle_layout());
32forward!(clear_caption_style());
33forward!(clear_caption_layout());
34forward!(clear_x_label_style());
35forward!(clear_x_label_layout());
36forward!(clear_y_label_style());
37forward!(clear_y_label_layout());
38forward!(clear_color_label_style()=>ContinuousColor);
39forward!(clear_color_label_layout()=>ContinuousColor);
40forward!(title_alignment(alignment:TextAlignment));
41forward!(subtitle_alignment(alignment:TextAlignment));
42forward!(theme(theme:Theme));
43forward!(width(width:u32));
44forward!(max_width(maximum:u32));
45forward!(size(width:u32,height:u32));
46forward!(color_label(label:impl Into<Text>)=>ContinuousColor);
47forward!(color_label_format(format:NumericFormat)=>ContinuousColor);
48forward!(heatmap_null_row_annotation(annotation:HeatmapNullRowAnnotation)=>HeatmapOptions);
49forward!(estimate_labels(format:NumericFormat)=>CoefficientOptions);
50forward!(significance_mark_style(style:SignificanceMarkStyle)=>SignificanceStyle);
51forward!(text_annotation(annotation:PlotTextAnnotation)=>TextAnnotation);
52forward!(x_category_labels(selection:CategoryLabelSelection)=>CategoricalX);
53forward!(y_category_labels(selection:CategoryLabelSelection)=>CategoricalY);
54forward!(category_order(order:impl Into<CategoryOrder>)=>CategoryOrder);
55forward!(x_category_order(order:impl Into<CategoryOrder>)=>HeatmapOptions);
56forward!(y_category_order(order:impl Into<CategoryOrder>)=>HeatmapOptions);
57forward!(x_limits(min:f64,max:f64)=>NumericX);
58forward!(y_limits(min:f64,max:f64)=>NumericY);
59forward!(x_ticks(ticks:Vec<AxisTick>)=>NumericX);
60forward!(y_ticks(ticks:Vec<AxisTick>)=>NumericY);
61forward!(x_tick_generation(generation:TickGeneration)=>NumericX);
62forward!(y_tick_generation(generation:TickGeneration)=>NumericY);
63forward!(x_tick_format(format:NumericFormat)=>NumericX);
64forward!(y_tick_format(format:NumericFormat)=>NumericY);
65forward!(guide(guide:GuideSpec)=>Guides);
66forward!(categorical_color_scale(scale:CategoricalColorScale)=>CategoricalScale);
67forward!(continuous_color_scale(scale:ContinuousColorScale)=>ContinuousColor);
68forward!(color_by_sign()=>SignedBars);
69forward!(zero_line()=>ZeroLine);
70forward!(hide_point_outline()=>PointOutline);
71forward!(markers(visible:bool)=>Markers);
72forward!(legend(policy:LegendPolicy)=>Legend);
73forward!(legend_composition(composition:LegendComposition)=>Legend);
74forward!(raw_overlay(overlay:RawOverlay)=>RawOverlay);
75forward!(estimate_status(statuses:impl IntoIterator<Item=EstimateStatus>)=>EstimateStatus);
76forward!(x_tick_text_layout(layout:TextLayout)=>XAxisText);
77forward!(y_tick_text_layout(layout:TextLayout)=>YAxisText);
78forward!(facet_row_text_layout(layout:TextLayout)=>Facet);
79forward!(facet_column_text_layout(layout:TextLayout)=>Facet);
80forward!(estimate_detail_text_layout(layout:TextLayout)=>EstimateDetailText);
81forward!(significance_text_layout(layout:TextLayout)=>SignificanceStyle);
82forward!(guide_text_layout(role:GuideTextRole,layout:TextLayout)=>Legend);
83macro_rules! family_forward {
84 ($kind:ident,$name:ident($($arg:ident:$ty:ty),*)) => {
85 impl PlotAdapter<'_,kind::$kind> {
86 #[doc=concat!("Forward native ",stringify!($kind)," `",stringify!($name),"` configuration.")]
87 #[must_use]
88 pub fn $name(mut self,$($arg:$ty),*)->Self { self.plot=self.plot.$name($($arg),*); self }
89 }
90 };
91}
92family_forward!(Heatmap,layout(layout:HeatmapLayout));
93family_forward!(Heatmap,annotations(annotations:HeatmapAnnotations));
94family_forward!(Heatmap,value_text_layout(layout:TextLayout));
95family_forward!(Heatmap,null_row_text_layout(layout:TextLayout));
96family_forward!(Forest,scale(scale:AxisScale));
97family_forward!(Bar,spacing(spacing:BarSpacing));
98family_forward!(HorizontalBar,spacing(spacing:BarSpacing));
99family_forward!(Histogram,bins(bins:HistogramBins));
100family_forward!(Histogram,stat(stat:HistogramStat));
101family_forward!(Histogram,composite(composite:HistogramComposite));
102family_forward!(Qq,reference_line(line:QqLine));
103family_forward!(Regression,band(band:RegressionBand));
104family_forward!(LinePath,style(style:LinePathStyle));
105family_forward!(Coefficient,reference_line(value:f64));
106family_forward!(Interaction,connectors(visible:bool));
107family_forward!(Interaction,styles(styles:impl IntoIterator<Item=InteractionStyle>));
108family_forward!(Waterfall,total_format(format:NumericFormat));
109family_forward!(Waterfall,total_labels(labels:WaterfallLabels));
110family_forward!(Waterfall,total_text_layout(layout:TextLayout));
111family_forward!(Matrix,matrix_row_text_layout(layout:TextLayout));
112family_forward!(Matrix,matrix_column_text_layout(layout:TextLayout));
113macro_rules! layer_forward {
114 ($family:ident,$layer:ty) => {
115 impl PlotAdapter<'_, kind::$family> {
116 #[must_use]
118 pub fn point_layer(mut self, layer: impl Into<$layer>) -> Self {
119 self.plot = self.plot.point_layer(layer.into());
120 self
121 }
122 }
123 };
124}
125layer_forward!(Line, PointLayer);
126layer_forward!(Bar, BarPointLayer);
127layer_forward!(HorizontalBar, BarPointLayer);
128impl<K: kind::Marker> PlotAdapter<'_, K> {
129 #[must_use]
131 pub fn significance<P>(mut self, annotations: impl IntoIterator<Item = Significance<P>>) -> Self
132 where
133 K: kind::Significance<P>,
134 {
135 self.plot = self.plot.significance(annotations);
136 self
137 }
138 pub fn svg(&self, path: impl AsRef<Path>) -> crate::Result<Output> {
140 self.plot.svg(path)
141 }
142 pub fn svg_preserve_text(&self, path: impl AsRef<Path>) -> crate::Result<Output> {
144 self.plot.svg_preserve_text(path)
145 }
146 pub fn png(&self, path: impl AsRef<Path>) -> crate::Result<Output> {
148 self.plot.png(path)
149 }
150 pub fn png_preview(&self, path: impl AsRef<Path>) -> crate::Result<Output> {
152 self.plot.png_preview(path)
153 }
154 pub fn png_with_options(
156 &self,
157 path: impl AsRef<Path>,
158 options: PngOptions,
159 ) -> crate::Result<Output> {
160 self.plot.png_with_options(path, options)
161 }
162}