Skip to main content

lichtung_plot_ndarray/frontend/
forwarding.rs

1//! Local inventory of native configuration; scientific behavior stays in core.
2use super::PlotAdapter;
3use crate::{
4    coordinates::{AxisScale, AxisTick, CategoryLabelSelection, CategoryOrder, TickGeneration},
5    data::EstimateStatus,
6    elements::{
7        BarPointLayer, GuideSpec, PlotTextAnnotation, PointLayer, Significance,
8        SignificanceMarkStyle,
9    },
10    guides::{GuideTextRole, LegendComposition, LegendPolicy},
11    kind,
12    output::PngOptions,
13    plots::{
14        BarSpacing, HeatmapAnnotations, HeatmapLayout, HeatmapNullRowAnnotation,
15        HistogramComposite, InteractionStyle, LinePathStyle, QqLine, RawOverlay, WaterfallLabels,
16    },
17    scales::{CategoricalColorScale, ContinuousColorScale},
18    stats::{HistogramBins, HistogramStat, RegressionBand},
19    text::{TextAlignment, TextLayout},
20    NumericFormat, Output, Text, Theme,
21};
22use std::path::Path;
23
24macro_rules! forward {
25    ($name:ident($($arg:ident:$ty:ty),*) $(=>$bound:ident)?) => {
26        impl<K:kind::Marker> PlotAdapter<'_,K> {
27            #[doc=concat!("Forward native [`crate::Plot::",stringify!($name),"`] configuration.")]
28            #[must_use]
29            pub fn $name(mut self,$($arg:$ty),*)->Self $(where K:kind::$bound)? { self.plot=self.plot.$name($($arg),*); self }
30        }
31    };
32}
33forward!(title(text:impl Into<Text>));
34forward!(subtitle(text:impl Into<Text>));
35forward!(caption(text:impl Into<Text>));
36forward!(x_label(text:impl Into<Text>));
37forward!(y_label(text:impl Into<Text>));
38forward!(clear_title_style());
39forward!(clear_title_layout());
40forward!(clear_subtitle_style());
41forward!(clear_subtitle_layout());
42forward!(clear_caption_style());
43forward!(clear_caption_layout());
44forward!(clear_x_label_style());
45forward!(clear_x_label_layout());
46forward!(clear_y_label_style());
47forward!(clear_y_label_layout());
48forward!(clear_color_label_style()=>ContinuousColor);
49forward!(clear_color_label_layout()=>ContinuousColor);
50forward!(title_alignment(alignment:TextAlignment));
51forward!(subtitle_alignment(alignment:TextAlignment));
52forward!(theme(theme:impl Into<Option<Theme>>));
53forward!(default_theme(theme: impl Into<Option<Theme>>));
54forward!(width(width:u32));
55forward!(max_width(maximum:u32));
56forward!(size(width:u32,height:u32));
57forward!(color_label(label:impl Into<Text>)=>ContinuousColor);
58forward!(color_label_format(format:NumericFormat)=>ContinuousColor);
59forward!(heatmap_null_row_annotation(annotation:HeatmapNullRowAnnotation)=>HeatmapOptions);
60forward!(estimate_labels(format:NumericFormat)=>CoefficientOptions);
61forward!(significance_mark_style(style:SignificanceMarkStyle)=>SignificanceStyle);
62forward!(text_annotation(annotation:PlotTextAnnotation)=>TextAnnotation);
63forward!(x_category_labels(selection:CategoryLabelSelection)=>CategoricalX);
64forward!(y_category_labels(selection:CategoryLabelSelection)=>CategoricalY);
65forward!(category_order(order:impl Into<CategoryOrder>)=>CategoryOrder);
66forward!(x_category_order(order:impl Into<CategoryOrder>)=>HeatmapOptions);
67forward!(y_category_order(order:impl Into<CategoryOrder>)=>HeatmapOptions);
68forward!(x_limits(min:f64,max:f64)=>NumericX);
69forward!(y_limits(min:f64,max:f64)=>NumericY);
70forward!(x_ticks(ticks:Vec<AxisTick>)=>NumericX);
71forward!(y_ticks(ticks:Vec<AxisTick>)=>NumericY);
72forward!(x_tick_generation(generation:TickGeneration)=>NumericX);
73forward!(y_tick_generation(generation:TickGeneration)=>NumericY);
74forward!(x_tick_format(format:NumericFormat)=>NumericX);
75forward!(y_tick_format(format:NumericFormat)=>NumericY);
76forward!(guide(guide:GuideSpec)=>Guides);
77forward!(categorical_color_scale(scale:CategoricalColorScale)=>CategoricalScale);
78forward!(continuous_color_scale(scale:ContinuousColorScale)=>ContinuousColor);
79forward!(color_by_sign()=>SignedBars);
80forward!(zero_line()=>ZeroLine);
81forward!(hide_point_outline()=>PointOutline);
82forward!(show_markers(visible:bool)=>Markers);
83forward!(legend(policy:LegendPolicy)=>Legend);
84forward!(legend_composition(composition:LegendComposition)=>Legend);
85forward!(raw_overlay(overlay:RawOverlay)=>RawOverlay);
86forward!(estimate_status(statuses:impl IntoIterator<Item=EstimateStatus>)=>EstimateStatus);
87forward!(x_tick_text_layout(layout:TextLayout)=>XAxisText);
88forward!(y_tick_text_layout(layout:TextLayout)=>YAxisText);
89forward!(facet_row_text_layout(layout:TextLayout)=>Facet);
90forward!(facet_column_text_layout(layout:TextLayout)=>Facet);
91forward!(estimate_detail_text_layout(layout:TextLayout)=>EstimateDetailText);
92forward!(significance_text_layout(layout:TextLayout)=>SignificanceStyle);
93forward!(guide_text_layout(role:GuideTextRole,layout:TextLayout)=>Legend);
94macro_rules! family_forward {
95    ($kind:ident,$name:ident($($arg:ident:$ty:ty),*)) => {
96        impl PlotAdapter<'_,kind::$kind> {
97            #[doc=concat!("Forward native ",stringify!($kind)," `",stringify!($name),"` configuration.")]
98            #[must_use]
99            pub fn $name(mut self,$($arg:$ty),*)->Self { self.plot=self.plot.$name($($arg),*); self }
100        }
101    };
102}
103family_forward!(Heatmap,layout(layout:HeatmapLayout));
104family_forward!(Heatmap,annotations(annotations:HeatmapAnnotations));
105family_forward!(Heatmap,value_text_layout(layout:TextLayout));
106family_forward!(Heatmap,null_row_text_layout(layout:TextLayout));
107family_forward!(Forest,scale(scale:AxisScale));
108family_forward!(Bar,spacing(spacing:BarSpacing));
109family_forward!(HorizontalBar,spacing(spacing:BarSpacing));
110family_forward!(Histogram,bins(bins:HistogramBins));
111family_forward!(Histogram,stat(stat:HistogramStat));
112family_forward!(Histogram,composite(composite:HistogramComposite));
113family_forward!(Qq,reference_line(line:QqLine));
114family_forward!(Regression,band(band:RegressionBand));
115family_forward!(LinePath,style(style:LinePathStyle));
116family_forward!(Raincloud,hue_label(label:impl Into<Text>));
117family_forward!(Raincloud, clear_hue_label_style());
118family_forward!(Raincloud, clear_hue_label_layout());
119family_forward!(Coefficient,reference_line(value:f64));
120family_forward!(Interaction,connectors(visible:bool));
121family_forward!(Interaction,styles(styles:impl IntoIterator<Item=InteractionStyle>));
122family_forward!(Waterfall,total_format(format:NumericFormat));
123family_forward!(Waterfall,total_labels(labels:WaterfallLabels));
124family_forward!(Waterfall,total_text_layout(layout:TextLayout));
125family_forward!(Matrix,matrix_row_text_layout(layout:TextLayout));
126family_forward!(Matrix,matrix_column_text_layout(layout:TextLayout));
127macro_rules! layer_forward {
128    ($family:ident,$layer:ty) => {
129        impl PlotAdapter<'_, kind::$family> {
130            /// Append an independently bound native or adapter layer.
131            #[must_use]
132            pub fn point_layer(mut self, layer: impl Into<$layer>) -> Self {
133                self.plot = self.plot.point_layer(layer.into());
134                self
135            }
136        }
137    };
138}
139layer_forward!(Line, PointLayer);
140layer_forward!(Bar, BarPointLayer);
141layer_forward!(HorizontalBar, BarPointLayer);
142impl<K: kind::Facet> PlotAdapter<'_, K> {
143    /// Borrow the currently bound native facet.
144    #[must_use]
145    pub fn get_facet(&self) -> Option<&crate::layout::FacetSpec> {
146        self.plot.get_facet()
147    }
148}
149
150impl<K: kind::Marker> PlotAdapter<'_, K> {
151    /// Borrow the explicitly selected local theme.
152    pub fn get_theme(&self) -> Option<&Theme> {
153        self.plot.get_theme()
154    }
155
156    /// Borrow the retained construction default.
157    pub fn get_default_theme(&self) -> Option<&Theme> {
158        self.plot.get_default_theme()
159    }
160
161    /// Inspect the authored point alpha encoding without ending source lookup.
162    pub fn get_point_alpha(&self) -> &crate::scales::AlphaEncoding {
163        self.plot.get_point_alpha()
164    }
165
166    /// Inspect the authored line alpha encoding without ending source lookup.
167    pub fn get_line_alpha(&self) -> &crate::scales::AlphaEncoding {
168        self.plot.get_line_alpha()
169    }
170
171    /// Inspect the authored fill alpha encoding without ending source lookup.
172    pub fn get_fill_alpha(&self) -> &crate::scales::AlphaEncoding {
173        self.plot.get_fill_alpha()
174    }
175
176    /// Borrow the native authored label policy.
177    #[must_use]
178    pub fn get_labels(&self) -> &crate::formatting::Labels {
179        self.plot.get_labels()
180    }
181
182    /// Request an exact physical size, retaining the native source lookup.
183    pub fn size_with_unit(
184        mut self,
185        width: f64,
186        height: f64,
187        unit: crate::layout::SizeUnit,
188    ) -> crate::Result<Self> {
189        self.plot = self.plot.size_with_unit(width, height, unit)?;
190        Ok(self)
191    }
192
193    /// Validate the chart without publishing or releasing source lookup.
194    pub fn preflight(&self) -> crate::Result<()> {
195        self.plot.preflight()
196    }
197
198    /// Use the native per-call options without releasing source lookup.
199    pub fn preflight_with_operation(
200        &self,
201        options: &crate::operation::OperationOptions,
202    ) -> crate::Result<()> {
203        self.plot.preflight_with_operation(options)
204    }
205
206    /// Prepare the native layout without releasing source lookup.
207    pub fn layout_report(&self) -> crate::Result<crate::layout::LayoutReport> {
208        self.plot.layout_report()
209    }
210
211    /// Prepare the layout using the native per-call operation options.
212    pub fn layout_report_with_operation(
213        &self,
214        options: &crate::operation::OperationOptions,
215    ) -> crate::Result<crate::layout::LayoutReport> {
216        self.plot.layout_report_with_operation(options)
217    }
218
219    /// Publish with the selected native device.
220    pub fn save_with(
221        &self,
222        path: impl AsRef<Path>,
223        format: impl Into<crate::output::Format>,
224    ) -> crate::Result<Output> {
225        self.plot.save_with(path, format)
226    }
227
228    /// Publish using this call's cancellation and interrupt options.
229    pub fn save_with_operation(
230        &self,
231        path: impl AsRef<Path>,
232        format: impl Into<crate::output::Format>,
233        options: &crate::operation::OperationOptions,
234    ) -> crate::Result<Output> {
235        self.plot.save_with_operation(path, format, options)
236    }
237
238    /// Encode the complete native artifact in owned memory.
239    pub fn encode(
240        &self,
241        format: impl Into<crate::output::Format>,
242    ) -> crate::Result<std::sync::Arc<[u8]>> {
243        self.plot.encode(format)
244    }
245
246    /// Encode under this call's operation options.
247    pub fn encode_with_operation(
248        &self,
249        format: impl Into<crate::output::Format>,
250        options: &crate::operation::OperationOptions,
251    ) -> crate::Result<std::sync::Arc<[u8]>> {
252        self.plot.encode_with_operation(format, options)
253    }
254
255    /// Write one complete artifact to the caller's stream.
256    pub fn write_to(
257        &self,
258        writer: &mut dyn std::io::Write,
259        format: impl Into<crate::output::Format>,
260    ) -> crate::Result<Output> {
261        self.plot.write_to(writer, format)
262    }
263
264    /// Write a stream under this call's operation options.
265    pub fn write_to_with_operation(
266        &self,
267        writer: &mut dyn std::io::Write,
268        format: impl Into<crate::output::Format>,
269        options: &crate::operation::OperationOptions,
270    ) -> crate::Result<Output> {
271        self.plot.write_to_with_operation(writer, format, options)
272    }
273
274    /// Read source-sized straight RGBA8 samples.
275    pub fn pixels(&self) -> crate::Result<crate::output::PixelBuffer> {
276        self.plot.pixels()
277    }
278
279    /// Read immutable samples with explicit options.
280    pub fn pixels_with_options(
281        &self,
282        options: crate::output::PixelOptions,
283    ) -> crate::Result<crate::output::PixelBuffer> {
284        self.plot.pixels_with_options(options)
285    }
286
287    /// Read immutable samples under this call's operation options.
288    pub fn pixels_with_options_with_operation(
289        &self,
290        options: crate::output::PixelOptions,
291        operation: &crate::operation::OperationOptions,
292    ) -> crate::Result<crate::output::PixelBuffer> {
293        self.plot
294            .pixels_with_options_with_operation(options, operation)
295    }
296
297    /// Fill a caller-owned pixel target without releasing source lookup.
298    pub fn pixels_into(&self, target: crate::output::PixelTarget<'_>) -> crate::Result<()> {
299        self.plot.pixels_into(target)
300    }
301
302    /// Fill a pixel target using explicit native sampling and representation.
303    pub fn pixels_into_with_options(
304        &self,
305        target: crate::output::PixelTarget<'_>,
306        options: crate::output::PixelOptions,
307    ) -> crate::Result<()> {
308        self.plot.pixels_into_with_options(target, options)
309    }
310
311    /// Fill a pixel target under this call's operation options.
312    pub fn pixels_into_with_options_with_operation(
313        &self,
314        target: crate::output::PixelTarget<'_>,
315        options: crate::output::PixelOptions,
316        operation: &crate::operation::OperationOptions,
317    ) -> crate::Result<()> {
318        self.plot
319            .pixels_into_with_options_with_operation(target, options, operation)
320    }
321    /// Compose independently prepared items on this native adapter snapshot.
322    pub fn compose(
323        &self,
324        items: impl IntoIterator<Item = crate::composition::Placement>,
325    ) -> crate::Result<crate::composition::Composite> {
326        self.plot.compose(items)
327    }
328    /// Compose with an explicit viewport expansion policy.
329    pub fn compose_with_options(
330        &self,
331        items: impl IntoIterator<Item = crate::composition::Placement>,
332        options: crate::composition::ComposeOptions,
333    ) -> crate::Result<crate::composition::Composite> {
334        self.plot.compose_with_options(items, options)
335    }
336    /// Compose with this call's operation and viewport options.
337    pub fn compose_with_operation(
338        &self,
339        items: impl IntoIterator<Item = crate::composition::Placement>,
340        options: crate::composition::ComposeOptions,
341        operation: &crate::operation::OperationOptions,
342    ) -> crate::Result<crate::composition::Composite> {
343        self.plot.compose_with_operation(items, options, operation)
344    }
345    /// Freeze one reusable output without publishing or releasing source lookup.
346    pub fn render(&self) -> crate::Result<Output> {
347        self.plot.render()
348    }
349
350    /// Use the native per-call options without releasing source lookup.
351    pub fn render_with_operation(
352        &self,
353        options: &crate::operation::OperationOptions,
354    ) -> crate::Result<Output> {
355        self.plot.render_with_operation(options)
356    }
357
358    /// Freeze one output and the scientific values from that same native preparation.
359    pub fn render_with_results(&self) -> crate::Result<crate::stats::RenderWithResults> {
360        self.plot.render_with_results()
361    }
362
363    /// Use explicit options for the same-preparation result operation.
364    pub fn render_with_results_with_operation(
365        &self,
366        options: &crate::operation::OperationOptions,
367    ) -> crate::Result<crate::stats::RenderWithResults> {
368        self.plot.render_with_results_with_operation(options)
369    }
370
371    /// Append caller-owned native significance annotations with their placement type.
372    #[must_use]
373    pub fn significance<P>(mut self, annotations: impl IntoIterator<Item = Significance<P>>) -> Self
374    where
375        K: kind::Significance<P>,
376    {
377        self.plot = self.plot.significance(annotations);
378        self
379    }
380    /// Render and publish SVG, returning the native reusable Output.
381    pub fn svg(&self, path: impl AsRef<Path>) -> crate::Result<Output> {
382        self.plot.svg(path)
383    }
384
385    /// Render and publish using the native operation options.
386    pub fn svg_with_operation(
387        &self,
388        path: impl AsRef<Path>,
389        options: &crate::operation::OperationOptions,
390    ) -> crate::Result<Output> {
391        self.plot.svg_with_operation(path, options)
392    }
393    /// Render and publish SVG retaining selectable text.
394    pub fn svg_preserve_text(&self, path: impl AsRef<Path>) -> crate::Result<Output> {
395        self.plot.svg_preserve_text(path)
396    }
397
398    /// Render and publish using the native operation options.
399    pub fn svg_preserve_text_with_operation(
400        &self,
401        path: impl AsRef<Path>,
402        options: &crate::operation::OperationOptions,
403    ) -> crate::Result<Output> {
404        self.plot.svg_preserve_text_with_operation(path, options)
405    }
406    /// Render and publish a 300-DPI PNG.
407    pub fn png(&self, path: impl AsRef<Path>) -> crate::Result<Output> {
408        self.plot.png(path)
409    }
410
411    /// Render and publish using the native operation options.
412    pub fn png_with_operation(
413        &self,
414        path: impl AsRef<Path>,
415        options: &crate::operation::OperationOptions,
416    ) -> crate::Result<Output> {
417        self.plot.png_with_operation(path, options)
418    }
419    /// Render and publish a source-sized PNG.
420    pub fn png_preview(&self, path: impl AsRef<Path>) -> crate::Result<Output> {
421        self.plot.png_preview(path)
422    }
423
424    /// Render and publish using the native operation options.
425    pub fn png_preview_with_operation(
426        &self,
427        path: impl AsRef<Path>,
428        options: &crate::operation::OperationOptions,
429    ) -> crate::Result<Output> {
430        self.plot.png_preview_with_operation(path, options)
431    }
432    /// Publish using native caller-owned PNG sizing and encoding options.
433    pub fn png_with_options(
434        &self,
435        path: impl AsRef<Path>,
436        options: PngOptions,
437    ) -> crate::Result<Output> {
438        self.plot.png_with_options(path, options)
439    }
440
441    /// Render and publish using native device and operation options.
442    pub fn png_with_options_with_operation(
443        &self,
444        path: impl AsRef<Path>,
445        options: PngOptions,
446        operation: &crate::operation::OperationOptions,
447    ) -> crate::Result<Output> {
448        self.plot
449            .png_with_options_with_operation(path, options, operation)
450    }
451}
452
453// Original role and declaration queries forward the same owning native values.
454impl<K: crate::kind::Marker> PlotAdapter<'_, K> {
455    /// Discover actual original inputs in the native plot.
456    pub fn data_roles(
457        &self,
458    ) -> std::result::Result<Vec<crate::data::DataRoleInfo>, crate::AdapterError> {
459        Ok(self.plot.data_roles()?)
460    }
461
462    /// Inspect original inputs of an actual declaration.
463    pub fn data_roles_at(
464        &self,
465        target: &crate::elements::ElementRef,
466    ) -> std::result::Result<Vec<crate::data::DataRoleInfo>, crate::AdapterError> {
467        Ok(self.plot.data_roles_at(target)?)
468    }
469
470    /// Inspect original inputs of actual declarations in a panel.
471    pub fn data_roles_in(
472        &self,
473        panel: &crate::layout::PanelPath,
474    ) -> std::result::Result<Vec<crate::data::DataRoleInfo>, crate::AdapterError> {
475        Ok(self.plot.data_roles_in(panel)?)
476    }
477
478    /// Read an actual original input, without source lookup.
479    pub fn data(
480        &self,
481        selector: impl Into<crate::data::DataSelector>,
482    ) -> std::result::Result<crate::data::DataValue, crate::AdapterError> {
483        Ok(self.plot.data(selector)?)
484    }
485
486    /// Discover actual native scientific layer declarations.
487    pub fn elements(
488        &self,
489        query: crate::elements::ElementQuery,
490    ) -> std::result::Result<Vec<crate::elements::ElementRef>, crate::AdapterError> {
491        Ok(self.plot.elements(query)?)
492    }
493
494    /// Find an actual native declaration.
495    pub fn element_ref(
496        &self,
497        query: impl Into<crate::elements::ElementQuery>,
498    ) -> std::result::Result<crate::elements::ElementRef, crate::AdapterError> {
499        Ok(self.plot.element_ref(query)?)
500    }
501
502    /// Read an owning native declaration snapshot.
503    pub fn read_element(
504        &self,
505        reference: &crate::elements::ElementRef,
506    ) -> std::result::Result<crate::elements::ElementSnapshot, crate::AdapterError> {
507        Ok(self.plot.read_element(reference)?)
508    }
509}
510
511impl<K: kind::Marker> PlotAdapter<'_, K> {
512    /// Read actual supplied significance annotations.
513    pub fn get_significance(&self) -> Option<&[crate::elements::SignificanceAnnotation]> {
514        self.plot.get_significance()
515    }
516}
517
518macro_rules! stat_result {
519    ($kind:ident, $result:ty) => {
520        impl PlotAdapter<'_, kind::$kind> {
521            /// Prepare actual scientific values without rendering.
522            pub fn stat_result(&self) -> crate::Result<$result> {
523                self.plot.stat_result()
524            }
525            /// Prepare with native operation options.
526            pub fn stat_result_with_operation(
527                &self,
528                options: &crate::operation::OperationOptions,
529            ) -> crate::Result<$result> {
530                self.plot.stat_result_with_operation(options)
531            }
532            /// Prepare actual values for the selected scientific panel.
533            pub fn stat_result_in(
534                &self,
535                panel: &crate::layout::PanelPath,
536            ) -> crate::Result<$result> {
537                self.plot.stat_result_in(panel)
538            }
539            /// Prepare the selected panel with explicit operation options.
540            pub fn stat_result_in_with_operation(
541                &self,
542                panel: &crate::layout::PanelPath,
543                options: &crate::operation::OperationOptions,
544            ) -> crate::Result<$result> {
545                self.plot.stat_result_in_with_operation(panel, options)
546            }
547        }
548    };
549}
550stat_result!(Histogram, crate::plots::HistogramResult);
551stat_result!(Density, crate::plots::DensityResult);
552stat_result!(Qq, crate::plots::ProbabilityPlotResult);
553stat_result!(Regression, crate::stats::FitResult);
554stat_result!(Bar, crate::stats::StatResult);
555stat_result!(HorizontalBar, crate::stats::StatResult);
556stat_result!(StackedBar, crate::stats::StatResult);
557stat_result!(StackedHorizontalBar, crate::stats::StatResult);
558stat_result!(Interaction, crate::stats::StatResult);
559stat_result!(Waterfall, crate::stats::StatResult);
560stat_result!(Boxplot, crate::plots::BoxSummary);
561stat_result!(Violin, crate::plots::DensityProfiles);
562stat_result!(Raincloud, crate::plots::RaincloudGeometry);
563stat_result!(PointInterval, crate::stats::StatResult);
564stat_result!(Forest, crate::stats::StatResult);
565stat_result!(Coefficient, crate::stats::StatResult);
566
567macro_rules! density_group_result {
568    ($kind:ident) => {
569        impl PlotAdapter<'_, kind::$kind> {
570            /// Prepare the actual selected original group of a density panel.
571            pub fn stat_result_group(
572                &self,
573                panel: &crate::layout::PanelPath,
574                group: &crate::data::GroupKey,
575            ) -> crate::Result<crate::plots::DensityResult> {
576                self.plot.stat_result_group(panel, group)
577            }
578
579            /// Prepare an original density group with per-call resource options.
580            pub fn stat_result_group_with_operation(
581                &self,
582                panel: &crate::layout::PanelPath,
583                group: &crate::data::GroupKey,
584                options: &crate::operation::OperationOptions,
585            ) -> crate::Result<crate::plots::DensityResult> {
586                self.plot
587                    .stat_result_group_with_operation(panel, group, options)
588            }
589        }
590    };
591}
592density_group_result!(Density);
593density_group_result!(Marginal);
594density_group_result!(Matrix);
595
596macro_rules! regional_density_result {
597    ($kind:ident) => {
598        impl PlotAdapter<'_, kind::$kind> {
599            /// Prepare actual density values for the selected scientific region.
600            pub fn stat_result_in(
601                &self,
602                panel: &crate::layout::PanelPath,
603            ) -> crate::Result<crate::plots::DensityResult> {
604                self.plot.stat_result_in(panel)
605            }
606
607            /// Prepare the selected region with operation options.
608            pub fn stat_result_in_with_operation(
609                &self,
610                panel: &crate::layout::PanelPath,
611                options: &crate::operation::OperationOptions,
612            ) -> crate::Result<crate::plots::DensityResult> {
613                self.plot.stat_result_in_with_operation(panel, options)
614            }
615        }
616    };
617}
618regional_density_result!(Marginal);
619regional_density_result!(Matrix);
620
621impl<K: kind::Marker> PlotAdapter<'_, K> {
622    /// Capture the actual native declaration and its input requirements.
623    pub fn get_recipe(&self) -> crate::Result<crate::recipe::Recipe> {
624        self.plot.get_recipe()
625    }
626
627    /// Write this native declaration and return the same Recipe.
628    pub fn recipe(&self, path: impl AsRef<Path>) -> crate::Result<crate::recipe::Recipe> {
629        self.plot.recipe(path)
630    }
631    /// Capture the selected full or visual native declaration.
632    pub fn get_recipe_with_scope(
633        &self,
634        scope: crate::recipe::PlotRecipeScope,
635    ) -> crate::Result<crate::recipe::Recipe> {
636        self.plot.get_recipe_with_scope(scope)
637    }
638
639    /// Write the selected native declaration and return that same Recipe.
640    pub fn recipe_with_scope(
641        &self,
642        path: impl AsRef<Path>,
643        scope: crate::recipe::PlotRecipeScope,
644    ) -> crate::Result<crate::recipe::Recipe> {
645        self.plot.recipe_with_scope(path, scope)
646    }
647
648    /// Apply visual requests to this native plot, preserving its source context.
649    pub fn apply_style<'a>(
650        mut self,
651        source: impl Into<crate::recipe::StyleSource<'a>>,
652    ) -> crate::Result<Self> {
653        self.plot = self.plot.apply_style(source)?;
654        Ok(self)
655    }
656}