lichtung-plot-ndarray 0.3.0

Direct scientific plotting from logical ndarray views and columns
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
//! Local inventory of native configuration; scientific behavior stays in core.
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> {
            /// Append an independently bound native or adapter layer.
            #[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> {
    /// Borrow the currently bound native facet.
    #[must_use]
    pub fn get_facet(&self) -> Option<&crate::layout::FacetSpec> {
        self.plot.get_facet()
    }
}

impl<K: kind::Marker> PlotAdapter<'_, K> {
    /// Borrow the explicitly selected local theme.
    pub fn get_theme(&self) -> Option<&Theme> {
        self.plot.get_theme()
    }

    /// Borrow the retained construction default.
    pub fn get_default_theme(&self) -> Option<&Theme> {
        self.plot.get_default_theme()
    }

    /// Inspect the authored point alpha encoding without ending source lookup.
    pub fn get_point_alpha(&self) -> &crate::scales::AlphaEncoding {
        self.plot.get_point_alpha()
    }

    /// Inspect the authored line alpha encoding without ending source lookup.
    pub fn get_line_alpha(&self) -> &crate::scales::AlphaEncoding {
        self.plot.get_line_alpha()
    }

    /// Inspect the authored fill alpha encoding without ending source lookup.
    pub fn get_fill_alpha(&self) -> &crate::scales::AlphaEncoding {
        self.plot.get_fill_alpha()
    }

    /// Borrow the native authored label policy.
    #[must_use]
    pub fn get_labels(&self) -> &crate::formatting::Labels {
        self.plot.get_labels()
    }

    /// Request an exact physical size, retaining the native source lookup.
    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)
    }

    /// Validate the chart without publishing or releasing source lookup.
    pub fn preflight(&self) -> crate::Result<()> {
        self.plot.preflight()
    }

    /// Use the native per-call options without releasing source lookup.
    pub fn preflight_with_operation(
        &self,
        options: &crate::operation::OperationOptions,
    ) -> crate::Result<()> {
        self.plot.preflight_with_operation(options)
    }

    /// Prepare the native layout without releasing source lookup.
    pub fn layout_report(&self) -> crate::Result<crate::layout::LayoutReport> {
        self.plot.layout_report()
    }

    /// Prepare the layout using the native per-call operation options.
    pub fn layout_report_with_operation(
        &self,
        options: &crate::operation::OperationOptions,
    ) -> crate::Result<crate::layout::LayoutReport> {
        self.plot.layout_report_with_operation(options)
    }

    /// Publish with the selected native device.
    pub fn save_with(
        &self,
        path: impl AsRef<Path>,
        format: impl Into<crate::output::Format>,
    ) -> crate::Result<Output> {
        self.plot.save_with(path, format)
    }

    /// Publish using this call's cancellation and interrupt options.
    pub fn save_with_operation(
        &self,
        path: impl AsRef<Path>,
        format: impl Into<crate::output::Format>,
        options: &crate::operation::OperationOptions,
    ) -> crate::Result<Output> {
        self.plot.save_with_operation(path, format, options)
    }

    /// Encode the complete native artifact in owned memory.
    pub fn encode(
        &self,
        format: impl Into<crate::output::Format>,
    ) -> crate::Result<std::sync::Arc<[u8]>> {
        self.plot.encode(format)
    }

    /// Encode under this call's operation options.
    pub fn encode_with_operation(
        &self,
        format: impl Into<crate::output::Format>,
        options: &crate::operation::OperationOptions,
    ) -> crate::Result<std::sync::Arc<[u8]>> {
        self.plot.encode_with_operation(format, options)
    }

    /// Write one complete artifact to the caller's stream.
    pub fn write_to(
        &self,
        writer: &mut dyn std::io::Write,
        format: impl Into<crate::output::Format>,
    ) -> crate::Result<Output> {
        self.plot.write_to(writer, format)
    }

    /// Write a stream under this call's operation options.
    pub fn write_to_with_operation(
        &self,
        writer: &mut dyn std::io::Write,
        format: impl Into<crate::output::Format>,
        options: &crate::operation::OperationOptions,
    ) -> crate::Result<Output> {
        self.plot.write_to_with_operation(writer, format, options)
    }

    /// Read source-sized straight RGBA8 samples.
    pub fn pixels(&self) -> crate::Result<crate::output::PixelBuffer> {
        self.plot.pixels()
    }

    /// Read immutable samples with explicit options.
    pub fn pixels_with_options(
        &self,
        options: crate::output::PixelOptions,
    ) -> crate::Result<crate::output::PixelBuffer> {
        self.plot.pixels_with_options(options)
    }

    /// Read immutable samples under this call's operation options.
    pub fn pixels_with_options_with_operation(
        &self,
        options: crate::output::PixelOptions,
        operation: &crate::operation::OperationOptions,
    ) -> crate::Result<crate::output::PixelBuffer> {
        self.plot
            .pixels_with_options_with_operation(options, operation)
    }

    /// Fill a caller-owned pixel target without releasing source lookup.
    pub fn pixels_into(&self, target: crate::output::PixelTarget<'_>) -> crate::Result<()> {
        self.plot.pixels_into(target)
    }

    /// Fill a pixel target using explicit native sampling and representation.
    pub fn pixels_into_with_options(
        &self,
        target: crate::output::PixelTarget<'_>,
        options: crate::output::PixelOptions,
    ) -> crate::Result<()> {
        self.plot.pixels_into_with_options(target, options)
    }

    /// Fill a pixel target under this call's operation options.
    pub fn pixels_into_with_options_with_operation(
        &self,
        target: crate::output::PixelTarget<'_>,
        options: crate::output::PixelOptions,
        operation: &crate::operation::OperationOptions,
    ) -> crate::Result<()> {
        self.plot
            .pixels_into_with_options_with_operation(target, options, operation)
    }
    /// Compose independently prepared items on this native adapter snapshot.
    pub fn compose(
        &self,
        items: impl IntoIterator<Item = crate::composition::Placement>,
    ) -> crate::Result<crate::composition::Composite> {
        self.plot.compose(items)
    }
    /// Compose with an explicit viewport expansion policy.
    pub fn compose_with_options(
        &self,
        items: impl IntoIterator<Item = crate::composition::Placement>,
        options: crate::composition::ComposeOptions,
    ) -> crate::Result<crate::composition::Composite> {
        self.plot.compose_with_options(items, options)
    }
    /// Compose with this call's operation and viewport options.
    pub fn compose_with_operation(
        &self,
        items: impl IntoIterator<Item = crate::composition::Placement>,
        options: crate::composition::ComposeOptions,
        operation: &crate::operation::OperationOptions,
    ) -> crate::Result<crate::composition::Composite> {
        self.plot.compose_with_operation(items, options, operation)
    }
    /// Freeze one reusable output without publishing or releasing source lookup.
    pub fn render(&self) -> crate::Result<Output> {
        self.plot.render()
    }

    /// Use the native per-call options without releasing source lookup.
    pub fn render_with_operation(
        &self,
        options: &crate::operation::OperationOptions,
    ) -> crate::Result<Output> {
        self.plot.render_with_operation(options)
    }

    /// Freeze one output and the scientific values from that same native preparation.
    pub fn render_with_results(&self) -> crate::Result<crate::stats::RenderWithResults> {
        self.plot.render_with_results()
    }

    /// Use explicit options for the same-preparation result operation.
    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)
    }

    /// Append caller-owned native significance annotations with their placement type.
    #[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
    }
    /// Render and publish SVG, returning the native reusable Output.
    pub fn svg(&self, path: impl AsRef<Path>) -> crate::Result<Output> {
        self.plot.svg(path)
    }

    /// Render and publish using the native operation options.
    pub fn svg_with_operation(
        &self,
        path: impl AsRef<Path>,
        options: &crate::operation::OperationOptions,
    ) -> crate::Result<Output> {
        self.plot.svg_with_operation(path, options)
    }
    /// Render and publish SVG retaining selectable text.
    pub fn svg_preserve_text(&self, path: impl AsRef<Path>) -> crate::Result<Output> {
        self.plot.svg_preserve_text(path)
    }

    /// Render and publish using the native operation options.
    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)
    }
    /// Render and publish a 300-DPI PNG.
    pub fn png(&self, path: impl AsRef<Path>) -> crate::Result<Output> {
        self.plot.png(path)
    }

    /// Render and publish using the native operation options.
    pub fn png_with_operation(
        &self,
        path: impl AsRef<Path>,
        options: &crate::operation::OperationOptions,
    ) -> crate::Result<Output> {
        self.plot.png_with_operation(path, options)
    }
    /// Render and publish a source-sized PNG.
    pub fn png_preview(&self, path: impl AsRef<Path>) -> crate::Result<Output> {
        self.plot.png_preview(path)
    }

    /// Render and publish using the native operation options.
    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)
    }
    /// Publish using native caller-owned PNG sizing and encoding options.
    pub fn png_with_options(
        &self,
        path: impl AsRef<Path>,
        options: PngOptions,
    ) -> crate::Result<Output> {
        self.plot.png_with_options(path, options)
    }

    /// Render and publish using native device and operation 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)
    }
}

// Original role and declaration queries forward the same owning native values.
impl<K: crate::kind::Marker> PlotAdapter<'_, K> {
    /// Discover actual original inputs in the native plot.
    pub fn data_roles(
        &self,
    ) -> std::result::Result<Vec<crate::data::DataRoleInfo>, crate::AdapterError> {
        Ok(self.plot.data_roles()?)
    }

    /// Inspect original inputs of an actual declaration.
    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)?)
    }

    /// Inspect original inputs of actual declarations in a panel.
    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)?)
    }

    /// Read an actual original input, without source lookup.
    pub fn data(
        &self,
        selector: impl Into<crate::data::DataSelector>,
    ) -> std::result::Result<crate::data::DataValue, crate::AdapterError> {
        Ok(self.plot.data(selector)?)
    }

    /// Discover actual native scientific layer declarations.
    pub fn elements(
        &self,
        query: crate::elements::ElementQuery,
    ) -> std::result::Result<Vec<crate::elements::ElementRef>, crate::AdapterError> {
        Ok(self.plot.elements(query)?)
    }

    /// Find an actual native declaration.
    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)?)
    }

    /// Read an owning native declaration snapshot.
    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> {
    /// Read actual supplied significance annotations.
    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> {
            /// Prepare actual scientific values without rendering.
            pub fn stat_result(&self) -> crate::Result<$result> {
                self.plot.stat_result()
            }
            /// Prepare with native operation options.
            pub fn stat_result_with_operation(
                &self,
                options: &crate::operation::OperationOptions,
            ) -> crate::Result<$result> {
                self.plot.stat_result_with_operation(options)
            }
            /// Prepare actual values for the selected scientific panel.
            pub fn stat_result_in(
                &self,
                panel: &crate::layout::PanelPath,
            ) -> crate::Result<$result> {
                self.plot.stat_result_in(panel)
            }
            /// Prepare the selected panel with explicit operation options.
            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> {
            /// Prepare the actual selected original group of a density panel.
            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)
            }

            /// Prepare an original density group with per-call resource options.
            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> {
            /// Prepare actual density values for the selected scientific region.
            pub fn stat_result_in(
                &self,
                panel: &crate::layout::PanelPath,
            ) -> crate::Result<crate::plots::DensityResult> {
                self.plot.stat_result_in(panel)
            }

            /// Prepare the selected region with operation options.
            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);

impl<K: kind::Marker> PlotAdapter<'_, K> {
    /// Capture the actual native declaration and its input requirements.
    pub fn get_recipe(&self) -> crate::Result<crate::recipe::Recipe> {
        self.plot.get_recipe()
    }

    /// Write this native declaration and return the same Recipe.
    pub fn recipe(&self, path: impl AsRef<Path>) -> crate::Result<crate::recipe::Recipe> {
        self.plot.recipe(path)
    }
    /// Capture the selected full or visual native declaration.
    pub fn get_recipe_with_scope(
        &self,
        scope: crate::recipe::PlotRecipeScope,
    ) -> crate::Result<crate::recipe::Recipe> {
        self.plot.get_recipe_with_scope(scope)
    }

    /// Write the selected native declaration and return that same Recipe.
    pub fn recipe_with_scope(
        &self,
        path: impl AsRef<Path>,
        scope: crate::recipe::PlotRecipeScope,
    ) -> crate::Result<crate::recipe::Recipe> {
        self.plot.recipe_with_scope(path, scope)
    }

    /// Apply visual requests to this native plot, preserving its source context.
    pub fn apply_style<'a>(
        mut self,
        source: impl Into<crate::recipe::StyleSource<'a>>,
    ) -> crate::Result<Self> {
        self.plot = self.plot.apply_style(source)?;
        Ok(self)
    }
}