1use crate::layout::Layout;
4use crate::significance::SignificancePlan;
5use crate::{NumericFormat, NumericValues};
6
7mod bar;
8mod categorical;
9mod estimate;
10mod facet;
11mod output;
12pub(crate) mod ticks;
13
14pub use bar::{
15 BarInput, BarSamples, Bootstrap, ConfidenceInterval, ErrorBar, PercentileInterval,
16 StandardDeviation, StandardError,
17};
18pub(crate) use bar::{BarSource, ConfidenceIntervalAlgorithm, ErrorBarKind};
19pub use categorical::{CategoricalColorMap, CategoryOrder, ValueSort};
20pub use estimate::{
21 AxisScale, Bounds, CoefficientInput, EstimateStatus, InteractionStyle, LinePathStyle,
22 PointShape, QqLine, RegressionBand, SignificanceMarkStyle, TextWeight,
23};
24pub use facet::{FacetScales, FacetSpec};
25pub use output::{PngCompression, PngOptions, PngSizing};
26pub use ticks::{
27 TickContext, TickGeneration, TickPositions, TickRequirement, TickSingleton, TickSpace,
28};
29mod category_labels;
30pub use category_labels::{CategoryLabelSelection, LabelEndpoints};
31
32#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
34pub enum BarSpacing {
35 #[default]
37 Comfort,
38 Compact,
40}
41
42#[derive(Debug, Clone, Copy, PartialEq, Default)]
44pub enum HistogramBins {
45 #[default]
49 Auto,
50 Count(usize),
53 Width(f64),
57}
58
59#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
61pub enum HistogramStat {
62 #[default]
64 Count,
65 Probability,
67 Density,
69}
70
71impl HistogramStat {
72 pub const fn name(self) -> &'static str {
74 match self {
75 Self::Count => "count",
76 Self::Probability => "probability",
77 Self::Density => "density",
78 }
79 }
80}
81
82#[derive(Debug, Clone)]
84pub enum HistogramKde {
85 Internal,
87 Precomputed {
99 x: NumericValues,
101 y: NumericValues,
103 },
104}
105
106impl HistogramKde {
107 pub const fn get_precomputed(&self) -> Option<(&NumericValues, &NumericValues)> {
109 match self {
110 Self::Internal => None,
111 Self::Precomputed { x, y } => Some((x, y)),
112 }
113 }
114}
115
116impl PartialEq for HistogramKde {
117 fn eq(&self, other: &Self) -> bool {
118 match (self, other) {
119 (Self::Internal, Self::Internal) => true,
120 (
121 Self::Precomputed { x, y },
122 Self::Precomputed {
123 x: other_x,
124 y: other_y,
125 },
126 ) => {
127 crate::geometry::numeric_equal(x, other_x)
128 && crate::geometry::numeric_equal(y, other_y)
129 }
130 _ => false,
131 }
132 }
133}
134
135#[derive(Debug, Clone, PartialEq, Default)]
137pub enum HistogramComposite {
138 #[default]
140 HistogramOnly,
141 KdeAndRug(HistogramKde),
143}
144
145impl HistogramComposite {
146 pub(crate) const fn is_enabled(&self) -> bool {
147 matches!(self, Self::KdeAndRug(_))
148 }
149}
150
151#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
153pub enum DataAreaCorner {
154 TopLeft,
156 TopRight,
158 BottomLeft,
160 BottomRight,
162}
163
164#[derive(Debug, Clone, PartialEq, Eq)]
166pub struct PlotTextAnnotation {
167 position: crate::text::TextPosition,
168 text: crate::Text,
169}
170
171impl PlotTextAnnotation {
172 pub fn new(corner: DataAreaCorner, text: impl Into<crate::Text>) -> Result<Self, crate::Error> {
177 Self::at(crate::text::TextPosition::corner(corner), text)
178 }
179
180 pub fn at(
182 position: crate::text::TextPosition,
183 text: impl Into<crate::Text>,
184 ) -> Result<Self, crate::Error> {
185 let text = text.into();
186 text.required_source("panel text")?;
187 Ok(Self { position, text })
188 }
189
190 #[must_use]
192 pub const fn position(&self) -> &crate::text::TextPosition {
193 &self.position
194 }
195
196 #[must_use]
198 pub fn text(&self) -> &str {
199 self.text.as_str()
200 }
201
202 pub(crate) const fn content(&self) -> &crate::Text {
203 &self.text
204 }
205}
206
207#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
213pub enum RawOverlay {
214 #[default]
216 Hidden,
217 Points,
219 Jittered,
222}
223
224impl RawOverlay {
225 #[must_use]
227 pub const fn is_visible(self) -> bool {
228 !matches!(self, Self::Hidden)
229 }
230}
231
232#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
234pub enum HeatmapLayout {
235 #[default]
237 Cartesian,
238 LowerTriangle {
240 diagonal: bool,
242 },
243 UpperTriangle {
245 diagonal: bool,
247 },
248}
249
250#[derive(Debug, Clone, PartialEq, Eq, Default)]
252pub enum HeatmapAnnotations {
253 #[default]
255 Hidden,
256 Values(NumericFormat),
258}
259
260#[derive(Debug, Clone, PartialEq, Eq)]
262pub struct HeatmapNullRowAnnotation {
263 row_label: String,
264 text: crate::Text,
265}
266
267impl HeatmapNullRowAnnotation {
268 pub fn new(
272 row_label: impl Into<String>,
273 text: impl Into<crate::Text>,
274 ) -> Result<Self, crate::Error> {
275 let annotation = Self {
276 row_label: row_label.into(),
277 text: text.into(),
278 };
279 validate_heatmap_annotation_label(&annotation.row_label, "row label")?;
280 annotation
281 .text
282 .required_source("heatmap fully-null row annotation text")?;
283 Ok(annotation)
284 }
285
286 #[must_use]
288 pub fn row_label(&self) -> &str {
289 &self.row_label
290 }
291
292 #[must_use]
294 pub fn text(&self) -> &str {
295 self.text.as_str()
296 }
297
298 pub(crate) const fn content(&self) -> &crate::Text {
299 &self.text
300 }
301}
302
303fn validate_heatmap_annotation_label(value: &str, role: &str) -> Result<(), crate::Error> {
304 if value.is_empty() || value.trim() != value || value.chars().any(char::is_control) {
305 return Err(crate::Error::Data(format!(
306 "heatmap fully-null row annotation {role} must be nonempty, trimmed, and contain no control characters"
307 ).into()));
308 }
309 Ok(())
310}
311
312#[derive(Debug, Clone, PartialEq, Eq)]
331pub struct DumbbellEndpoints {
332 left_label: String,
333 left_color: crate::Color,
334 right_label: String,
335 right_color: crate::Color,
336}
337
338impl DumbbellEndpoints {
339 pub fn new(
341 left_label: impl Into<String>,
342 left_color: crate::Color,
343 right_label: impl Into<String>,
344 right_color: crate::Color,
345 ) -> Result<Self, crate::Error> {
346 let endpoints = Self {
347 left_label: left_label.into(),
348 left_color,
349 right_label: right_label.into(),
350 right_color,
351 };
352 if endpoints.left_label.trim().is_empty() || endpoints.right_label.trim().is_empty() {
353 return Err(crate::Error::Data(
354 "dumbbell endpoint labels must not be empty".into(),
355 ));
356 }
357 if endpoints.left_label.trim() != endpoints.left_label
358 || endpoints.right_label.trim() != endpoints.right_label
359 || endpoints.left_label.chars().any(char::is_control)
360 || endpoints.right_label.chars().any(char::is_control)
361 {
362 return Err(crate::Error::Data(
363 "dumbbell endpoint labels must contain no surrounding whitespace or control characters"
364 .into(),
365 ));
366 }
367 if endpoints.left_label == endpoints.right_label {
368 return Err(crate::Error::Data(
369 "dumbbell endpoint labels must be distinct".into(),
370 ));
371 }
372 Ok(endpoints)
373 }
374
375 #[must_use]
377 pub fn left_label(&self) -> &str {
378 &self.left_label
379 }
380
381 #[must_use]
383 pub const fn left_color(&self) -> crate::Color {
384 self.left_color
385 }
386
387 #[must_use]
389 pub fn right_label(&self) -> &str {
390 &self.right_label
391 }
392
393 #[must_use]
395 pub const fn right_color(&self) -> crate::Color {
396 self.right_color
397 }
398}
399
400#[derive(Debug, Clone, PartialEq, Eq)]
402pub struct WaterfallLabels {
403 base: crate::Text,
404 terminal: crate::Text,
405}
406
407impl WaterfallLabels {
408 pub fn new(
412 base: impl Into<crate::Text>,
413 terminal: impl Into<crate::Text>,
414 ) -> Result<Self, crate::Error> {
415 let labels = Self {
416 base: base.into(),
417 terminal: terminal.into(),
418 };
419 labels.base.required_source("waterfall base label")?;
420 labels
421 .terminal
422 .required_source("waterfall terminal label")?;
423 Ok(labels)
424 }
425
426 #[must_use]
428 pub fn base(&self) -> &str {
429 self.base.as_str()
430 }
431
432 #[must_use]
434 pub fn terminal(&self) -> &str {
435 self.terminal.as_str()
436 }
437
438 pub(crate) const fn contents(&self) -> [&crate::Text; 2] {
439 [&self.base, &self.terminal]
440 }
441}
442
443#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
445pub enum CanvasLegendPolicy {
446 #[default]
448 PerPlot,
449 Shared,
451 Hidden,
453}
454
455#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
462pub enum LegendComposition {
463 #[default]
465 Combined,
466 Separate,
472}
473
474#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
479pub enum LegendPosition {
480 #[default]
482 Auto,
483 InsideTopLeft,
485 InsideTop,
487 InsideTopRight,
489 InsideRightTop,
491 InsideRight,
493 InsideRightBottom,
495 InsideBottomLeft,
497 InsideBottom,
499 InsideBottomRight,
501 InsideLeftTop,
503 InsideLeft,
505 InsideLeftBottom,
507 OutsideRightTop,
509 OutsideRight,
511 OutsideRightBottom,
513 OutsideTopLeft,
515 OutsideTop,
517 OutsideTopRight,
519 OutsideBottomLeft,
521 OutsideBottom,
523 OutsideBottomRight,
525 OutsideLeftTop,
527 OutsideLeft,
529 OutsideLeftBottom,
531}
532
533#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
535pub enum LegendPolicy {
536 #[default]
538 Automatic,
539 Hidden,
541 Visible(LegendPosition),
543}
544
545impl LegendPolicy {
546 pub(crate) const fn position(self) -> LegendPosition {
547 match self {
548 Self::Visible(position) => position,
549 Self::Automatic | Self::Hidden => LegendPosition::Auto,
550 }
551 }
552}
553
554macro_rules! define_plot_kinds {
555 ($($variant:ident => $documentation:literal),+ $(,)?) => {
556 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
558 #[non_exhaustive]
559 pub enum PlotKind {
560 $(
561 #[doc = $documentation]
562 $variant,
563 )+
564 }
565 };
566}
567
568define_plot_kinds! {
569 Scatter => "Scatter plot.",
570 Histogram => "Single-series numeric histogram with an optional KDE-and-rug density composite.",
571 Density => "Gaussian kernel density estimate.",
572 Qq => "Quantile-quantile plot against a standard normal distribution.",
573 PointInterval => "Point estimates with explicit lower and upper interval bounds.",
574 Line => "Grouped ordered numeric series with optional precomputed ribbons.",
575 Trajectory => "Explicit-group repeated trajectories with neutral connectors.",
576 LinePath => "Numeric paths in source-row order with optional group keys.",
577 Interaction => "Precomputed interaction profiles with explicit bounds and optional closed trace styles.",
578 Coefficient => "Named model coefficients with optional drawable bounds.",
579 Forest => "Complete interval estimates with an explicit scientific null.",
580 Dumbbell => "Horizontal paired endpoint estimates with optional replicate identity.",
581 Heatmap => "Categorical grid with a continuous numeric fill.",
582 Bar => "Bar plot with CI error bars.",
583 HorizontalBar => "Horizontal bar plot.",
584 StackedBar => "Stacked vertical bar plot using one categorical series.",
585 StackedHorizontalBar => "Stacked horizontal bar plot using one categorical series.",
586 Boxplot => "Box-and-whisker plot.",
587 Violin => "Mirrored KDE violins with centered inner summaries.",
588 Raincloud => "One-sided KDE clouds with separated summaries and complete observation strips.",
589 Regression => "Regression plot (scatter + fit line).",
590 Marginal => "Marginal plot (marginal histograms + central scatter).",
591 Matrix => "Scatter matrix (small multiples).",
592 Beeswarm => "Categorical rows of collision-separated points with continuous x and color values.",
593 Waterfall => "Cumulative signed deltas between a base and terminal value.",
594}
595
596impl PlotKind {
597 pub const fn name(self) -> &'static str {
599 match self {
600 Self::Scatter => "scatter",
601 Self::Histogram => "histogram",
602 Self::Density => "density",
603 Self::Qq => "qq",
604 Self::PointInterval => "point_interval",
605 Self::Line => "line",
606 Self::Trajectory => "trajectory",
607 Self::LinePath => "line_path",
608 Self::Interaction => "interaction",
609 Self::Coefficient => "coefficient",
610 Self::Forest => "forest",
611 Self::Dumbbell => "dumbbell",
612 Self::Heatmap => "heatmap",
613 Self::Bar => "bar",
614 Self::HorizontalBar => "horizontal_bar",
615 Self::StackedBar => "stacked_bar",
616 Self::StackedHorizontalBar => "stacked_horizontal_bar",
617 Self::Boxplot => "boxplot",
618 Self::Violin => "violin",
619 Self::Raincloud => "raincloud",
620 Self::Regression => "regression",
621 Self::Marginal => "marginal",
622 Self::Matrix => "matrix",
623 Self::Beeswarm => "beeswarm",
624 Self::Waterfall => "waterfall",
625 }
626 }
627
628 pub(crate) const fn uses_unified_series(self) -> bool {
629 matches!(
630 self,
631 Self::Bar
632 | Self::HorizontalBar
633 | Self::StackedBar
634 | Self::StackedHorizontalBar
635 | Self::Boxplot
636 | Self::Violin
637 | Self::Raincloud
638 )
639 }
640
641 pub(crate) const fn supports_significance_annotations(self) -> bool {
642 self.admits_attached_significance() || self.admits_pairwise_significance()
643 }
644
645 pub(crate) const fn legend_default(self, explicit_y_limits: bool) -> LegendDefault {
646 match self {
647 Self::HorizontalBar | Self::StackedHorizontalBar | Self::Dumbbell => {
648 LegendDefault::TopRight(LegendClearance::HorizontalMaximum)
649 }
650 Self::Bar
651 | Self::StackedBar
652 | Self::Line
653 | Self::Trajectory
654 | Self::LinePath
655 | Self::Interaction
656 | Self::Boxplot
657 | Self::Violin
658 | Self::Raincloud
659 | Self::Regression => LegendDefault::TopRight(LegendClearance::VerticalMaximum),
660 Self::Scatter | Self::Marginal if !explicit_y_limits => {
661 LegendDefault::TopRight(LegendClearance::VerticalMaximum)
662 }
663 Self::Matrix => LegendDefault::SelfManaged,
664 _ => LegendDefault::LowestOverlap,
665 }
666 }
667}
668
669#[derive(Debug, Clone, Copy, PartialEq, Eq)]
670pub(crate) enum LegendDefault {
671 LowestOverlap,
672 TopRight(LegendClearance),
673 SelfManaged,
674}
675
676#[derive(Debug, Clone, Copy, PartialEq, Eq)]
677pub(crate) enum LegendClearance {
678 HorizontalMaximum,
679 VerticalMaximum,
680}
681
682use crate::Error;
683
684pub(crate) struct PlotMeasureContext<'v, 'src> {
687 pub(crate) registered: &'v crate::orchestrator::registration::PlotRegistration<'src>,
688 pub(crate) assignment: crate::orchestrator::assignment::RootPlotAssignmentRef<'v>,
689 pub(crate) canvas: Option<&'src crate::Canvas>,
690 pub(crate) text: &'v crate::text::TextService,
691 pub(crate) operation: &'v crate::font::canonical::OperationContext,
692 pub(crate) intrinsic: &'v crate::orchestrator::root::PlotIntrinsics,
693 pub(crate) guides: crate::decorations::legend::discrete::scoped::GuideConsumption<'v>,
694 pub(crate) fit_scope: &'v crate::layout::fit::FitScope,
695}
696
697impl<'v, 'src> PlotMeasureContext<'v, 'src> {
698 pub(crate) const fn fit_scope(&self) -> &'v crate::layout::fit::FitScope {
699 self.fit_scope
700 }
701
702 pub(crate) const fn intrinsic(&self) -> &'v crate::orchestrator::root::PlotIntrinsics {
703 self.intrinsic
704 }
705
706 pub(crate) fn family(&self) -> Result<crate::orchestrator::registration::FamilyRef<'v>, Error> {
707 crate::layout::interior::InteriorRoute::classify(self.registered.family.kind())
708 .validate(self.registered.source)?;
709 self.registered.family()
710 }
711
712 #[expect(
713 clippy::unnecessary_wraps,
714 reason = "the fixed fallible axis-pair interface projects prepared operands without adding validation"
715 )]
716 pub(crate) fn axis_pair(
717 &self,
718 scope: crate::orchestrator::assignment::AxisPairScope,
719 ) -> Result<crate::orchestrator::assignment::AxisPairRef<'v>, Error> {
720 use crate::layout::AxisSide::{Bottom, Left};
721 use crate::orchestrator::assignment::{AssignedAxisRef, AxisDomainAssignments as D};
722 use crate::orchestrator::assignment::{AxisPairRef, AxisPairScope as S};
723 use crate::orchestrator::registration::{AxisSlot as A, MarginalStrip};
724 let axes = &self.registered.axes;
725 let source = self.registered.source;
726 let pair = match (scope, &self.assignment.local.domains) {
727 (S::Pair, D::Pair(domains)) => {
728 [(A::Pair(Bottom), &domains[0]), (A::Pair(Left), &domains[1])]
729 }
730 (S::MarginalCentral, D::Marginal { central, .. }) => [
731 (A::MarginalCentral(Bottom), ¢ral[0]),
732 (A::MarginalCentral(Left), ¢ral[1]),
733 ],
734 (
735 S::MarginalTop,
736 D::Marginal {
737 central,
738 strip_density,
739 },
740 ) => [
741 (A::MarginalCentral(Bottom), ¢ral[0]),
742 (
743 A::MarginalStripDensity(MarginalStrip::Top),
744 &strip_density[0],
745 ),
746 ],
747 (
748 S::MarginalRight,
749 D::Marginal {
750 central,
751 strip_density,
752 },
753 ) => [
754 (
755 A::MarginalStripDensity(MarginalStrip::Right),
756 &strip_density[1],
757 ),
758 (A::MarginalCentral(Left), ¢ral[1]),
759 ],
760 (S::MatrixCell { row, column }, D::Matrix { variables, .. }) => [
761 (A::MatrixVariable(column), &variables[column]),
762 (A::MatrixVariable(row), &variables[row]),
763 ],
764 (
765 S::MatrixDiagonalDensity { variable },
766 D::Matrix {
767 variables,
768 diagonal_density,
769 },
770 ) => [
771 (A::MatrixVariable(variable), &variables[variable]),
772 (
773 A::MatrixDiagonalDensity(variable),
774 &diagonal_density[variable],
775 ),
776 ],
777 _ => unreachable!("axis pair belongs to the selected interior route"),
778 };
779 Ok(AxisPairRef {
780 axes: pair.map(|(slot, domain)| AssignedAxisRef {
781 base: axes.axis_at(source, slot),
782 domain,
783 }),
784 })
785 }
786
787 pub(crate) fn data(&self) -> Result<crate::data::PlotData<'src, 'v>, Error> {
788 self.registered.data(self.operation)
789 }
790
791 pub(crate) fn request(&self) -> crate::text::TextRequestContext<'v, 'src> {
792 crate::text::TextRequestContext::new(&self.registered.appearance, self.text)
793 }
794
795 #[expect(
796 clippy::unnecessary_wraps,
797 reason = "native measurements share the existing fallible range-reader interface"
798 )]
799 pub(crate) fn axis_range(&self, side: crate::layout::AxisSide) -> Result<(f64, f64), Error> {
800 use crate::orchestrator::assignment::AxisDomainAssignments;
801 let index = usize::from(side == crate::layout::AxisSide::Left);
802 let pair = match &self.assignment.local.domains {
803 AxisDomainAssignments::Pair(pair) => pair,
804 AxisDomainAssignments::Marginal { central, .. } => central,
805 AxisDomainAssignments::Matrix { .. } => {
806 unreachable!("Matrix selects an indexed axis pair")
807 }
808 };
809 Ok(pair[index].extent.pair())
810 }
811
812 pub(crate) fn prepared_category_labels(
813 &self,
814 side: usize,
815 ) -> Option<&'v [crate::layout::AxisTick]> {
816 Some(&self.registered.axes.coordinate()?.categories(side)?.ticks)
817 }
818
819 pub(crate) fn semantic_inputs(
820 &self,
821 scope: crate::orchestrator::assignment::AxisPairScope,
822 ) -> Result<[crate::layout::AxisSemanticInputs; 2], Error> {
823 use crate::orchestrator::assignment::AssignedAxisRef;
824
825 let mut inputs = self
826 .axis_pair(scope)?
827 .axes
828 .map(AssignedAxisRef::semantic_inputs);
829 for (side, input) in inputs.iter_mut().enumerate() {
830 input
831 .text_layout
832 .clone_from(&self.registered.appearance.text_layouts.ticks[side]);
833 }
834 Ok(inputs)
835 }
836}
837
838#[derive(Debug)]
842pub(crate) struct PlotRenderResult {
843 pub(crate) layout: Layout,
844 pub(crate) axes: Option<crate::layout::AxisSystemPlan>,
845 pub(crate) grid_axis_gutters: Option<[f64; 4]>,
846 pub(crate) x_domain: AxisDomain,
847 pub(crate) y_domain: AxisDomain,
848 pub(crate) significance: Option<SignificancePlan>,
849 pub(crate) discrete_guide:
850 Option<std::sync::Arc<crate::decorations::legend::discrete::PreparedGuide>>,
851 pub(crate) decoration_mode: DecorationMode,
852 pub(crate) x_tick_keys: Option<Vec<String>>,
853 pub(crate) y_tick_keys: Option<Vec<String>>,
854 pub(crate) deferred_annotation_text: Vec<crate::layout::DeferredAnnotationTextPlan>,
855 pub(crate) producer_text: Vec<crate::render::backend::PlacedText>,
856 pub(crate) panel_text: Vec<crate::decorations::panel_text::PlotTextAnnotationPlan>,
857 pub(crate) self_managed_legend: Option<std::sync::Arc<crate::decorations::legend::Legend>>,
858 pub(crate) matrix_axes: Option<std::sync::Arc<crate::plots::matrix::MatrixAxisPlan>>,
859 pub(crate) marks: Option<std::sync::Arc<crate::layout::interior::SelectedMarkPlan>>,
860 pub(crate) annotations: Option<std::sync::Arc<crate::layout::interior::SelectedAnnotationPlan>>,
861 pub(crate) numeric_presentation:
862 Option<std::sync::Arc<crate::numeric::set::NumericPresentation>>,
863}
864
865#[derive(Debug, Clone, Copy, PartialEq, Eq)]
867pub(crate) enum AxisDomain {
868 Continuous,
869 Categorical,
870}
871
872#[derive(Debug, Clone, Copy, PartialEq, Eq)]
873pub(crate) enum DecorationMode {
874 Standard,
875 SelfManaged,
876}
877
878impl PlotRenderResult {
879 pub(crate) fn draw_body(
880 &self,
881 owner: &crate::layout::PanelPath,
882 source: &crate::builder::PlotDescription,
883 backend: &mut dyn crate::render::backend::Backend,
884 ) -> Result<DecorationMode, Error> {
885 self.marks
886 .as_ref()
887 .ok_or_else(|| Error::Render("selected mark payload is missing".into()))?
888 .draw(owner, source, backend)?;
889 crate::render::backend::with_paint(
890 backend,
891 owner,
892 crate::layout::PaintRole::Annotation,
893 None,
894 |backend| {
895 self.annotations
896 .as_ref()
897 .ok_or_else(|| Error::Render("selected annotation payload is missing".into()))?
898 .draw(backend)
899 },
900 )?;
901 Ok(self.decoration_mode)
902 }
903
904 pub(crate) fn new(
905 layout: Layout,
906 discrete_guide: Option<std::sync::Arc<crate::decorations::legend::discrete::PreparedGuide>>,
907 ) -> Self {
908 Self {
909 layout,
910 axes: None,
911 grid_axis_gutters: None,
912 x_domain: AxisDomain::Continuous,
913 y_domain: AxisDomain::Continuous,
914 significance: None,
915 discrete_guide,
916 decoration_mode: DecorationMode::Standard,
917 x_tick_keys: None,
918 y_tick_keys: None,
919 deferred_annotation_text: Vec::new(),
920 producer_text: Vec::new(),
921 panel_text: Vec::new(),
922 self_managed_legend: None,
923 matrix_axes: None,
924 marks: None,
925 annotations: None,
926 numeric_presentation: None,
927 }
928 }
929
930 pub(crate) fn with_self_managed_decorations(mut self) -> Self {
931 self.decoration_mode = DecorationMode::SelfManaged;
932 self
933 }
934
935 pub(crate) fn with_resolved_axis_keys(
936 mut self,
937 x_keys: Vec<String>,
938 y_keys: Vec<String>,
939 ) -> Self {
940 self.x_tick_keys = Some(x_keys);
941 self.y_tick_keys = Some(y_keys);
942 self
943 }
944}