lichtung_plot/builder.rs
1//! `lichtung-plot::builder` — the native `Plot` builder API.
2//!
3//! Semantic constructors accept immutable Rust-native values. Configuration is
4//! chained before `.svg(path)` or `.png(path)` borrows the configured plot.
5//!
6//! Significance annotations are caller-owned display inputs. The renderer never
7//! performs hypothesis tests or adjusts p-values.
8
9use std::marker::PhantomData;
10use std::sync::Arc;
11
12mod accessors;
13mod alpha;
14mod configuration;
15mod facets;
16mod layout;
17mod text_clear;
18mod text_layout;
19
20pub(crate) use layout::{measure_root_frame, RootFrameDomainInput};
21
22use crate::input::{AxisValues, PlotInput};
23use crate::layers::{BarPointLayer, GuideSpec, PointLayer};
24use crate::layout::AuthoredAxisSpec;
25use crate::spec::{
26 AxisScale, BarSpacing, CategoryOrder, DumbbellEndpoints, FacetSpec, HeatmapAnnotations,
27 HeatmapLayout, HeatmapNullRowAnnotation, HistogramBins, HistogramComposite, HistogramStat,
28 LegendPolicy, LinePathStyle, PlotKind, PlotTextAnnotation, QqLine, RawOverlay, RegressionBand,
29 WaterfallLabels,
30};
31use crate::theme::Theme;
32use crate::Labels;
33use crate::{
34 BarInput, BooleanValues, Bounds, CategoryValues, CoefficientInput, HistogramInput,
35 NumericFormat, NumericValues, RaincloudInput, SourceRows,
36};
37
38/// One configured semantic plot backed by immutable Rust-native values.
39///
40/// `K` is a zero-sized plot-family marker from [`crate::kind`]. Omitting it
41/// means [`crate::kind::Any`], the erased form used by heterogeneous storage.
42/// Family-specific methods are available only through exact-marker inherent
43/// implementations or a corresponding sealed capability.
44/// Without a sizing call, dimensions derive from content. [`Self::width`] fixes
45/// width with content-derived height; [`Self::size`] fixes both dimensions.
46/// The latest sizing call replaces the complete request. Final dimensions are
47/// inspected on [`crate::Output`], after the scene has been frozen.
48///
49/// ```compile_fail
50/// use lichtung_plot::{kind, Plot};
51/// fn removed_width_getter(plot: &Plot<kind::Scatter>) {
52/// let _ = plot.width();
53/// }
54/// ```
55///
56/// ```compile_fail
57/// use lichtung_plot::{kind, Plot};
58/// fn removed_height_getter(plot: &Plot<kind::Scatter>) {
59/// let _ = plot.height();
60/// }
61/// ```
62///
63/// ```compile_fail
64/// use lichtung_plot::{kind, Plot};
65/// fn removed_identity_alias(plot: &Plot<kind::Scatter>) {
66/// let _ = plot.plot_kind();
67/// }
68/// ```
69///
70/// ```compile_fail
71/// use lichtung_plot::{kind, Plot};
72/// fn internal_family_options(plot: &Plot<kind::Histogram>) {
73/// let _ = plot.histogram_bins_spec();
74/// }
75/// ```
76///
77/// ```compile_fail
78/// use lichtung_plot::{kind, Plot};
79/// fn internal_renderer_configuration(plot: &Plot<kind::Scatter>) {
80/// let _ = plot.x_axis_spec();
81/// }
82/// ```
83///
84/// ```compile_fail
85/// use lichtung_plot::{kind, Plot};
86/// fn internal_palette(plot: &Plot<kind::Scatter>) {
87/// let _ = plot.palette();
88/// }
89/// ```
90///
91/// ```compile_fail
92/// use lichtung_plot::{kind, Plot};
93/// fn internal_layout(plot: &Plot<kind::Scatter>) {
94/// let _ = plot.canvas_layout();
95/// }
96/// ```
97///
98/// ```compile_fail
99/// use lichtung_plot::{NumericValues, Plot};
100/// let plot = Plot::scatter(
101/// NumericValues::new("x", [1.0]),
102/// NumericValues::new("y", [2.0]),
103/// );
104/// let _ = plot.x_tick_count(3);
105/// ```
106///
107/// ```compile_fail
108/// use lichtung_plot::{NumericValues, Plot};
109/// let plot = Plot::scatter(
110/// NumericValues::new("x", [1.0]),
111/// NumericValues::new("y", [2.0]),
112/// );
113/// let _ = plot.y_tick_count(3);
114/// ```
115///
116/// ```compile_fail
117/// use lichtung_plot::{HistogramBins, NumericValues, Plot};
118/// let plot = Plot::scatter(
119/// NumericValues::new("x", [1.0]),
120/// NumericValues::new("y", [2.0]),
121/// );
122/// let _ = plot.bins(HistogramBins::Count(4));
123/// ```
124///
125/// ```compile_fail
126/// use lichtung_plot::{HistogramBins, HistogramInput, NumericValues, Plot};
127/// let plot = Plot::histogram(HistogramInput::samples(
128/// NumericValues::new("value", [1.0]),
129/// )).erase();
130/// let _ = plot.bins(HistogramBins::Count(4));
131/// ```
132///
133/// ```compile_fail
134/// use lichtung_plot::{BarInput, CategoryValues, ContinuousColorScale, NumericValues, Plot};
135/// let plot = Plot::bar(
136/// CategoryValues::new("category", ["a"]).unwrap(),
137/// BarInput::estimates(NumericValues::new("value", [1.0])),
138/// );
139/// let _ = plot.continuous_color_scale(ContinuousColorScale::sequential(None, None).unwrap());
140/// ```
141///
142/// ```compile_fail
143/// use lichtung_plot::{HistogramInput, NumericValues, Plot, RawOverlay};
144/// let plot = Plot::histogram(HistogramInput::samples(NumericValues::new("value", [1.0])));
145/// let _ = plot.raw_overlay(RawOverlay::Points);
146/// ```
147///
148/// ```compile_fail
149/// use lichtung_plot::{Bounds, NumericValues, Plot};
150/// let plot = Plot::regression(
151/// NumericValues::new("x", [1.0]),
152/// NumericValues::new("y", [2.0]),
153/// );
154/// let bounds = Bounds::new(
155/// NumericValues::new("lower", [0.0]),
156/// NumericValues::new("upper", [3.0]),
157/// );
158/// let _ = plot.band(bounds);
159/// ```
160///
161/// ```compile_fail
162/// use lichtung_plot::{NumericValues, Plot, Significance, SignificanceMark};
163/// let plot = Plot::scatter(
164/// NumericValues::new("x", [1.0]),
165/// NumericValues::new("y", [2.0]),
166/// );
167/// let _ = plot.significance([
168/// Significance::at("a", SignificanceMark::OneStar),
169/// ]);
170/// ```
171///
172/// ```compile_fail
173/// use lichtung_plot::{NumericValues, Plot, Significance, SignificanceMark};
174/// let plot = Plot::scatter(
175/// NumericValues::new("x", [1.0]),
176/// NumericValues::new("y", [2.0]),
177/// );
178/// let _ = plot.significance([
179/// Significance::between("a", "b", SignificanceMark::OneStar),
180/// ]);
181/// ```
182///
183/// ```compile_fail
184/// use lichtung_plot::{CategoryValues, NumericValues, Plot, Significance, SignificanceMark};
185/// let plot = Plot::boxplot(
186/// CategoryValues::new("category", ["a"]).unwrap(),
187/// NumericValues::new("value", [1.0]),
188/// );
189/// let _ = plot.significance([
190/// Significance::at("a", SignificanceMark::OneStar),
191/// ]);
192/// ```
193///
194/// ```compile_fail
195/// use lichtung_plot::{CategoryValues, CoefficientInput, NumericValues, Plot, Significance, SignificanceMark};
196/// let plot = Plot::coefficient(
197/// CategoryValues::new("term", ["a", "b"]).unwrap(),
198/// CoefficientInput::estimates(NumericValues::new("estimate", [1.0, 2.0])),
199/// );
200/// let _ = plot.significance([
201/// Significance::between("a", "b", SignificanceMark::OneStar),
202/// ]);
203/// ```
204///
205/// ```compile_fail
206/// use lichtung_plot::{CategoryValues, CoefficientInput, NumericValues, Plot};
207/// struct Wrapped(CoefficientInput);
208/// impl Into<CoefficientInput> for Wrapped {
209/// fn into(self) -> CoefficientInput { self.0 }
210/// }
211/// let _ = Plot::coefficient(
212/// CategoryValues::new("term", ["a"]).unwrap(),
213/// Wrapped(CoefficientInput::estimates(NumericValues::new("estimate", [1.0]))),
214/// );
215/// ```
216///
217/// ```compile_fail
218/// use lichtung_plot::{Bounds, CategoryValues, NumericValues, Plot};
219/// let plot = Plot::trajectory(
220/// NumericValues::new("x", [1.0, 2.0]),
221/// NumericValues::new("y", [2.0, 3.0]),
222/// CategoryValues::new("subject", ["a", "a"]).unwrap(),
223/// );
224/// let _ = plot.band(Bounds::new(
225/// NumericValues::new("lower", [1.0, 2.0]),
226/// NumericValues::new("upper", [3.0, 4.0]),
227/// ));
228/// ```
229///
230/// ```compile_fail
231/// use lichtung_plot::{CategoryValues, NumericValues, Plot};
232/// let plot = Plot::trajectory(
233/// NumericValues::new("x", [1.0, 2.0]),
234/// NumericValues::new("y", [2.0, 3.0]),
235/// CategoryValues::new("subject", ["a", "a"]).unwrap(),
236/// );
237/// let _ = plot.markers(false);
238/// ```
239///
240/// ```compile_fail
241/// use lichtung_plot::{CategoryValues, NumericValues, Plot};
242/// let plot = Plot::trajectory(
243/// NumericValues::new("x", [1.0, 2.0]),
244/// NumericValues::new("y", [2.0, 3.0]),
245/// CategoryValues::new("subject", ["a", "a"]).unwrap(),
246/// );
247/// let _ = plot.group(CategoryValues::new("replacement", ["b", "b"]).unwrap());
248/// ```
249///
250/// ```compile_fail
251/// use lichtung_plot::{Bounds, CategoryValues, NumericValues, Plot};
252/// let plot = Plot::line_path(
253/// NumericValues::new("x", [1.0, 2.0]),
254/// NumericValues::new("y", [2.0, 3.0]),
255/// CategoryValues::new("path", ["a", "a"]).unwrap(),
256/// );
257/// let _ = plot.band(Bounds::new(
258/// NumericValues::new("lower", [1.0, 2.0]),
259/// NumericValues::new("upper", [3.0, 4.0]),
260/// ));
261/// ```
262///
263/// ```compile_fail
264/// use lichtung_plot::{CategoryValues, NumericValues, Plot, PointLayer};
265/// let plot = Plot::line_path(
266/// NumericValues::new("x", [1.0, 2.0]),
267/// NumericValues::new("y", [2.0, 3.0]),
268/// CategoryValues::new("path", ["a", "a"]).unwrap(),
269/// );
270/// let layer = PointLayer::new(
271/// NumericValues::new("x", [1.5]),
272/// NumericValues::new("y", [2.5]),
273/// );
274/// let _ = plot.point_layer(layer);
275/// ```
276///
277/// ```compile_fail
278/// use lichtung_plot::{CategoryValues, NumericValues, Plot};
279/// let plot = Plot::line_path(
280/// NumericValues::new("x", [1.0, 2.0]),
281/// NumericValues::new("y", [2.0, 3.0]),
282/// CategoryValues::new("path", ["a", "a"]).unwrap(),
283/// );
284/// let _ = plot.group(CategoryValues::new("replacement", ["b", "b"]).unwrap());
285/// ```
286///
287/// ```compile_fail
288/// use lichtung_plot::{Bounds, CategoryValues, NumericValues, Plot};
289/// let plot = Plot::interaction(
290/// CategoryValues::new("condition", ["before", "after"]).unwrap(),
291/// NumericValues::new("estimate", [1.0, 2.0]),
292/// CategoryValues::new("group", ["a", "a"]).unwrap(),
293/// Bounds::new(
294/// NumericValues::new("lower", [0.5, 1.5]),
295/// NumericValues::new("upper", [1.5, 2.5]),
296/// ),
297/// );
298/// let _ = plot.group(CategoryValues::new("replacement", ["b", "b"]).unwrap());
299/// ```
300///
301/// ```compile_fail
302/// use lichtung_plot::{LinePathStyle, NumericValues, Plot};
303/// let plot = Plot::line(
304/// NumericValues::new("x", [1.0, 2.0]),
305/// NumericValues::new("y", [2.0, 3.0]),
306/// );
307/// let _ = plot.style(LinePathStyle::Hue);
308/// ```
309///
310/// ```compile_fail
311/// use lichtung_plot::{CategoryValues, NumericValues, Plot};
312/// let _ = Plot::line(
313/// CategoryValues::new("x", ["before", "after"]).unwrap(),
314/// NumericValues::new("y", [1.0, 2.0]),
315/// );
316/// ```
317///
318/// ```compile_fail
319/// use lichtung_plot::{CategoryValues, NumericValues, Plot};
320/// let _ = Plot::dumbbell(
321/// CategoryValues::new("category", ["a"]).unwrap(),
322/// NumericValues::new("left", [1.0]),
323/// NumericValues::new("right", [2.0]),
324/// );
325/// ```
326///
327/// ```compile_fail
328/// use lichtung_plot::{BarSpacing, CategoryValues, NumericValues, Plot};
329/// let plot = Plot::stacked_bar(
330/// CategoryValues::new("category", ["a"]).unwrap(),
331/// NumericValues::new("value", [1.0]),
332/// CategoryValues::new("group", ["g"]).unwrap(),
333/// );
334/// let _ = plot.spacing(BarSpacing::Compact);
335/// ```
336///
337/// ```compile_fail
338/// use lichtung_plot::{CategoryValues, NumericValues, Plot};
339/// let plot = Plot::stacked_bar(
340/// CategoryValues::new("category", ["a"]).unwrap(),
341/// NumericValues::new("value", [1.0]),
342/// CategoryValues::new("series", ["g"]).unwrap(),
343/// );
344/// let _ = plot.series(CategoryValues::new("replacement", ["h"]).unwrap());
345/// ```
346///
347/// ```compile_fail
348/// use lichtung_plot::{CategoryValues, NumericValues, Plot};
349/// let plot = Plot::stacked_horizontal_bar(
350/// CategoryValues::new("category", ["a"]).unwrap(),
351/// NumericValues::new("value", [1.0]),
352/// CategoryValues::new("series", ["g"]).unwrap(),
353/// );
354/// let _ = plot.series(CategoryValues::new("replacement", ["h"]).unwrap());
355/// ```
356///
357/// ```compile_fail
358/// use lichtung_plot::{BarInput, CategoryValues, NumericValues, Plot};
359/// let plot = Plot::bar(
360/// CategoryValues::new("category", ["a"]).unwrap(),
361/// BarInput::estimates(NumericValues::new("value", [1.0])),
362/// );
363/// let _ = plot.group(CategoryValues::new("series", ["g"]).unwrap());
364/// ```
365///
366/// ```compile_fail
367/// use lichtung_plot::{CategoryValues, NumericValues, Plot};
368/// let plot = Plot::horizontal_bar(
369/// CategoryValues::new("category", ["a"]).unwrap(),
370/// lichtung_plot::BarInput::estimates(NumericValues::new("value", [1.0])),
371/// );
372/// let _ = plot.hue(CategoryValues::new("series", ["g"]).unwrap());
373/// ```
374///
375/// ```compile_fail
376/// use lichtung_plot::{CategoryValues, NumericValues, Plot};
377/// let plot = Plot::boxplot(
378/// CategoryValues::new("category", ["a"]).unwrap(),
379/// NumericValues::new("value", [1.0]),
380/// );
381/// let _ = plot.group(CategoryValues::new("series", ["g"]).unwrap());
382/// ```
383///
384/// ```compile_fail
385/// use lichtung_plot::{CategoryValues, NumericValues, Plot};
386/// let plot = Plot::violin(
387/// CategoryValues::new("category", ["a", "a"]).unwrap(),
388/// NumericValues::new("value", [1.0, 2.0]),
389/// );
390/// let _ = plot.hue(CategoryValues::new("series", ["g", "g"]).unwrap());
391/// ```
392///
393/// ```compile_fail
394/// use lichtung_plot::{CategoryValues, NumericValues, Plot, RaincloudInput};
395/// let plot = Plot::raincloud(RaincloudInput::samples(
396/// CategoryValues::new("category", ["a", "a"]).unwrap(),
397/// NumericValues::new("value", [1.0, 2.0]),
398/// ));
399/// let _ = plot.hue(CategoryValues::new("series", ["g", "g"]).unwrap());
400/// ```
401///
402/// ```compile_fail
403/// use lichtung_plot::{CategoryValues, NumericValues, Plot};
404/// let plot = Plot::line(
405/// NumericValues::new("x", [1.0, 2.0]),
406/// NumericValues::new("y", [2.0, 3.0]),
407/// );
408/// let _ = plot.series(CategoryValues::new("series", ["g", "g"]).unwrap());
409/// ```
410///
411/// ```compile_fail
412/// use lichtung_plot::{CategoryValues, NumericValues, Plot};
413/// let plot = Plot::heatmap(
414/// CategoryValues::new("x", ["a"]).unwrap(),
415/// CategoryValues::new("y", ["b"]).unwrap(),
416/// NumericValues::new("fill", [1.0]),
417/// );
418/// let _ = plot.color(NumericValues::new("replacement", [2.0]));
419/// ```
420///
421/// ```compile_fail
422/// use lichtung_plot::{CategoryValues, NumericValues, Plot};
423/// let plot = Plot::beeswarm(
424/// CategoryValues::new("category", ["a"]).unwrap(),
425/// NumericValues::new("value", [1.0]),
426/// NumericValues::new("color", [2.0]),
427/// );
428/// let _ = plot.color(NumericValues::new("replacement", [3.0]));
429/// ```
430///
431/// ```compile_fail
432/// use lichtung_plot::{CategoryValues, FacetSpec, NumericValues, Plot};
433/// let plot = Plot::matrix(vec![
434/// NumericValues::new("x", [1.0]),
435/// NumericValues::new("y", [2.0]),
436/// ]);
437/// let _ = plot.facet(FacetSpec::column(
438/// CategoryValues::new("panel", ["a"]).unwrap(),
439/// ));
440/// ```
441///
442/// ```compile_fail
443/// use lichtung_plot::{CategoryValues, FacetSpec, NumericValues, Plot};
444/// let plot = Plot::marginal(
445/// NumericValues::new("x", [1.0]),
446/// NumericValues::new("y", [2.0]),
447/// );
448/// let _ = plot.facet(FacetSpec::column(
449/// CategoryValues::new("panel", ["a"]).unwrap(),
450/// ));
451/// ```
452#[derive(Clone)]
453pub struct Plot<K: crate::kind::Marker = crate::kind::Any> {
454 description: PlotDescription,
455 marker: PhantomData<K>,
456}
457
458mod description;
459pub(crate) use description::PlotDescription;
460
461#[derive(Clone, Default)]
462struct CategoryOrders {
463 primary: CategoryOrder,
464 x: CategoryOrder,
465 y: CategoryOrder,
466}
467
468/// Coordinated replacements and complete numeric policies for a fixed child owner.
469#[expect(
470 clippy::type_complexity,
471 reason = "the original narrow axis snapshots retain only comparison values, not authored or working axis owners"
472)]
473pub(crate) struct ComposedInputs {
474 output_dimensions: Option<(u32, u32)>,
475 text_layouts: crate::text::roles::TextRoles,
476 prose: [crate::Text; 3],
477 axis_titles: [crate::Text; 2],
478 x_axis_spec: (
479 Option<(f64, f64)>,
480 crate::layout::RangeProvenance,
481 crate::TickGeneration,
482 crate::CategoryLabelSelection,
483 Option<Arc<NumericFormat>>,
484 Option<Vec<crate::AxisTick>>,
485 ),
486 y_axis_spec: (
487 Option<(f64, f64)>,
488 crate::layout::RangeProvenance,
489 crate::TickGeneration,
490 crate::CategoryLabelSelection,
491 Option<Arc<NumericFormat>>,
492 Option<Vec<crate::AxisTick>>,
493 ),
494 resolved_facet_x_range: Option<(f64, f64)>,
495 global_hue_levels: Option<Vec<String>>,
496 global_group_levels: Option<Vec<String>>,
497 global_collective_pairs: Option<Vec<crate::data::CollectivePair>>,
498 global_line_condition_levels: Option<Vec<String>>,
499 axis_gutter_owner: crate::orchestrator::registration::GutterOwner,
500 y_tick_labels_visible: bool,
501 render_scope: Option<String>,
502 legend_policy: LegendPolicy,
503 suppress_continuous_guide: bool,
504 root_size: crate::layout::RootRequest,
505 numeric: crate::numeric::inputs::NumericInputs,
506 alpha: crate::alpha::AlphaInputs,
507 pub(crate) guides: crate::decorations::legend::discrete::scoped::ScopedGuideInputs,
508}
509
510impl Plot<crate::kind::Any> {
511 fn new<K: crate::kind::Marker>(input: PlotInput, kind: PlotKind) -> Plot<K> {
512 Plot {
513 description: PlotDescription::new(input, kind),
514 marker: PhantomData,
515 }
516 }
517
518 /// Construct a scatter plot.
519 #[must_use]
520 pub fn scatter(x: NumericValues, y: NumericValues) -> Plot<crate::kind::Scatter> {
521 Self::new(PlotInput::Scatter { x, y }, PlotKind::Scatter)
522 }
523
524 /// Construct a histogram.
525 #[must_use]
526 pub fn histogram(input: HistogramInput) -> Plot<crate::kind::Histogram> {
527 let geometry = input.geometry_input().is_some();
528 let mut plot = Self::new(PlotInput::Histogram { input }, PlotKind::Histogram);
529 if geometry {
530 plot.description.payload_mut().histogram_stat = HistogramStat::Density;
531 }
532 plot
533 }
534
535 /// Construct a Gaussian density plot.
536 #[must_use]
537 pub fn density(values: NumericValues) -> Plot<crate::kind::Density> {
538 Self::new(PlotInput::Density { values }, PlotKind::Density)
539 }
540
541 /// Construct a normal Q-Q plot.
542 #[must_use]
543 pub fn qq(values: NumericValues) -> Plot<crate::kind::Qq> {
544 Self::new(PlotInput::Qq { values }, PlotKind::Qq)
545 }
546
547 /// Construct a point-interval plot.
548 #[must_use]
549 pub fn point_interval(
550 category: CategoryValues,
551 estimate: NumericValues,
552 bounds: Bounds,
553 ) -> Plot<crate::kind::PointInterval> {
554 Self::new(
555 PlotInput::PointInterval {
556 estimate,
557 category,
558 bounds,
559 },
560 PlotKind::PointInterval,
561 )
562 }
563
564 /// Construct an ordered line plot.
565 #[must_use]
566 pub fn line(x: NumericValues, y: NumericValues) -> Plot<crate::kind::Line> {
567 Self::new(
568 PlotInput::Line {
569 x: AxisValues::Numeric(x),
570 y,
571 },
572 PlotKind::Line,
573 )
574 }
575
576 /// Construct explicit-group repeated trajectories.
577 #[must_use]
578 pub fn trajectory(
579 x: impl Into<AxisValues>,
580 y: NumericValues,
581 group: CategoryValues,
582 ) -> Plot<crate::kind::Trajectory> {
583 Self::new(
584 PlotInput::Trajectory {
585 x: x.into(),
586 y,
587 group,
588 },
589 PlotKind::Trajectory,
590 )
591 }
592
593 /// Construct explicit-group numeric paths in source-row order.
594 #[must_use]
595 pub fn line_path(
596 x: NumericValues,
597 y: NumericValues,
598 group: CategoryValues,
599 ) -> Plot<crate::kind::LinePath> {
600 Self::new(PlotInput::LinePath { x, y, group }, PlotKind::LinePath)
601 }
602
603 /// Construct a precomputed interaction-profile plot.
604 #[must_use]
605 pub fn interaction(
606 condition: CategoryValues,
607 estimate: NumericValues,
608 group: CategoryValues,
609 bounds: Bounds,
610 ) -> Plot<crate::kind::Interaction> {
611 Self::new(
612 PlotInput::Interaction {
613 condition,
614 estimate,
615 group,
616 bounds,
617 },
618 PlotKind::Interaction,
619 )
620 }
621
622 /// Construct a model-coefficient plot.
623 #[must_use]
624 pub fn coefficient(
625 term: CategoryValues,
626 input: CoefficientInput,
627 ) -> Plot<crate::kind::Coefficient> {
628 Self::new(
629 PlotInput::Coefficient { input, term },
630 PlotKind::Coefficient,
631 )
632 }
633
634 /// Construct a forest plot with complete bounds and a scientific reference.
635 #[must_use]
636 pub fn forest(
637 term: CategoryValues,
638 estimate: NumericValues,
639 bounds: Bounds,
640 reference: f64,
641 ) -> Plot<crate::kind::Forest> {
642 Self::new(
643 PlotInput::Forest {
644 estimate,
645 term,
646 bounds,
647 reference,
648 },
649 PlotKind::Forest,
650 )
651 }
652
653 /// Construct a horizontal paired-endpoint dumbbell plot.
654 #[must_use]
655 pub fn dumbbell(
656 category: CategoryValues,
657 left: NumericValues,
658 right: NumericValues,
659 endpoints: DumbbellEndpoints,
660 ) -> Plot<crate::kind::Dumbbell> {
661 Self::new(
662 PlotInput::Dumbbell {
663 category,
664 left,
665 right,
666 endpoints,
667 },
668 PlotKind::Dumbbell,
669 )
670 }
671
672 /// Construct a categorical heatmap.
673 #[must_use]
674 pub fn heatmap(
675 x: CategoryValues,
676 y: CategoryValues,
677 fill: NumericValues,
678 ) -> Plot<crate::kind::Heatmap> {
679 Self::new(PlotInput::Heatmap { x, y, fill }, PlotKind::Heatmap)
680 }
681
682 /// Construct a vertical bar plot.
683 #[must_use]
684 pub fn bar(category: CategoryValues, input: impl Into<BarInput>) -> Plot<crate::kind::Bar> {
685 Self::new(
686 PlotInput::Bar {
687 category,
688 input: input.into(),
689 },
690 PlotKind::Bar,
691 )
692 }
693
694 /// Construct a horizontal bar plot.
695 #[must_use]
696 pub fn horizontal_bar(
697 category: CategoryValues,
698 input: impl Into<BarInput>,
699 ) -> Plot<crate::kind::HorizontalBar> {
700 Self::new(
701 PlotInput::HorizontalBar {
702 category,
703 input: input.into(),
704 },
705 PlotKind::HorizontalBar,
706 )
707 }
708
709 /// Construct a stacked vertical bar plot.
710 #[must_use]
711 pub fn stacked_bar(
712 category: CategoryValues,
713 value: NumericValues,
714 series: CategoryValues,
715 ) -> Plot<crate::kind::StackedBar> {
716 Self::new(
717 PlotInput::StackedBar {
718 category,
719 value,
720 series,
721 },
722 PlotKind::StackedBar,
723 )
724 }
725
726 /// Construct a stacked horizontal bar plot.
727 #[must_use]
728 pub fn stacked_horizontal_bar(
729 category: CategoryValues,
730 value: NumericValues,
731 series: CategoryValues,
732 ) -> Plot<crate::kind::StackedHorizontalBar> {
733 Self::new(
734 PlotInput::StackedHorizontalBar {
735 category,
736 value,
737 series,
738 },
739 PlotKind::StackedHorizontalBar,
740 )
741 }
742
743 /// Construct a box-and-whisker plot.
744 #[must_use]
745 pub fn boxplot(category: CategoryValues, value: NumericValues) -> Plot<crate::kind::Boxplot> {
746 Self::new(PlotInput::Boxplot { category, value }, PlotKind::Boxplot)
747 }
748
749 /// Construct a violin plot.
750 #[must_use]
751 pub fn violin(category: CategoryValues, value: NumericValues) -> Plot<crate::kind::Violin> {
752 Self::new(PlotInput::Violin { category, value }, PlotKind::Violin)
753 }
754
755 /// Construct a raincloud plot.
756 #[must_use]
757 pub fn raincloud(input: RaincloudInput) -> Plot<crate::kind::Raincloud> {
758 Self::new(PlotInput::Raincloud { input }, PlotKind::Raincloud)
759 }
760
761 /// Construct a regression plot.
762 #[must_use]
763 pub fn regression(x: NumericValues, y: NumericValues) -> Plot<crate::kind::Regression> {
764 Self::new(PlotInput::Regression { x, y }, PlotKind::Regression)
765 }
766
767 /// Construct a marginal plot.
768 #[must_use]
769 pub fn marginal(x: NumericValues, y: NumericValues) -> Plot<crate::kind::Marginal> {
770 Self::new(PlotInput::Marginal { x, y }, PlotKind::Marginal)
771 }
772
773 /// Construct a scatter matrix from ordered named numeric variables.
774 #[must_use]
775 pub fn matrix(variables: Vec<NumericValues>) -> Plot<crate::kind::Matrix> {
776 Self::new(PlotInput::Matrix { variables }, PlotKind::Matrix)
777 }
778
779 /// Construct a categorical beeswarm plot with continuous color values.
780 #[must_use]
781 pub fn beeswarm(
782 category: CategoryValues,
783 value: NumericValues,
784 color: NumericValues,
785 ) -> Plot<crate::kind::Beeswarm> {
786 Self::new(
787 PlotInput::Beeswarm {
788 value,
789 category,
790 color,
791 },
792 PlotKind::Beeswarm,
793 )
794 }
795
796 /// Construct a cumulative signed-delta waterfall plot.
797 #[must_use]
798 pub fn waterfall(
799 labels: CategoryValues,
800 deltas: NumericValues,
801 base: f64,
802 ) -> Plot<crate::kind::Waterfall> {
803 Self::new(
804 PlotInput::Waterfall {
805 labels,
806 deltas,
807 base,
808 },
809 PlotKind::Waterfall,
810 )
811 }
812}
813
814impl<K: crate::kind::ExactFamily> Plot<K> {
815 /// Consume this plot and erase its compile-time family marker.
816 ///
817 /// Every owned input and configuration field is moved unchanged.
818 ///
819 /// An erased plot cannot be erased a second time:
820 ///
821 /// ```compile_fail
822 /// use lichtung_plot::{NumericValues, Plot};
823 /// let erased: Plot = Plot::scatter(
824 /// NumericValues::new("x", [1.0]),
825 /// NumericValues::new("y", [2.0]),
826 /// ).erase();
827 /// let _ = erased.erase();
828 /// ```
829 #[must_use]
830 pub fn erase(self) -> Plot<crate::kind::Any> {
831 Plot {
832 description: self.description,
833 marker: PhantomData,
834 }
835 }
836}