Skip to main content

lichtung_plot/builder/
text_layout.rs

1//! Typed attachments at real text owners, retained through explicit erasure.
2
3use super::Plot;
4use crate::{guides::GuideTextRole, text::TextLayout};
5
6macro_rules! role {
7    ($name:ident,$bound:ident,$field:ident) => {impl<K:crate::kind::$bound> Plot<K> {
8        #[doc=concat!("Replace the `",stringify!($field),"` text owner's complete layout default.")]
9        #[must_use]
10        pub fn $name(mut self,layout:TextLayout) -> Self {self.description.payload_mut().text_layouts.$field=Some(layout);self}
11    }};
12    ($name:ident,$bound:ident,$field:ident,$index:expr) => {impl<K:crate::kind::$bound> Plot<K> {
13        #[doc=concat!("Replace the `",stringify!($field),"` text owner's complete layout default.")]
14        #[must_use]
15        pub fn $name(mut self,layout:TextLayout) -> Self {self.description.payload_mut().text_layouts.$field[$index]=Some(layout);self}
16    }};
17}
18role!(x_tick_text_layout, XAxisText, ticks, 0);
19role!(y_tick_text_layout, YAxisText, ticks, 1);
20role!(facet_row_text_layout, Facet, facet, 0);
21role!(facet_column_text_layout, Facet, facet, 1);
22role!(estimate_detail_text_layout, EstimateDetailText, estimate);
23role!(significance_text_layout, SignificanceStyle, significance);
24
25impl<K: crate::kind::Legend> Plot<K> {
26    /// Replace one actual guide role's default; authored whole requests take precedence.
27    #[must_use]
28    pub fn guide_text_layout(mut self, role: GuideTextRole, layout: TextLayout) -> Self {
29        self.description.payload_mut().text_layouts.guide[role.index()] = Some(layout);
30        self
31    }
32}
33impl Plot<crate::kind::Matrix> {
34    /// Configure the actual left-edge variable titles, not cell ticks.
35    #[must_use]
36    pub fn matrix_row_text_layout(mut self, layout: TextLayout) -> Self {
37        self.description.payload_mut().text_layouts.matrix[0] = Some(layout);
38        self
39    }
40    /// Configure the actual bottom-edge variable titles, not cell ticks.
41    #[must_use]
42    pub fn matrix_column_text_layout(mut self, layout: TextLayout) -> Self {
43        self.description.payload_mut().text_layouts.matrix[1] = Some(layout);
44        self
45    }
46}
47impl Plot<crate::kind::Heatmap> {
48    /// Configure active finite cell value text, retaining independent contrast roles.
49    #[must_use]
50    pub fn value_text_layout(mut self, layout: TextLayout) -> Self {
51        self.description.payload_mut().text_layouts.value = Some(layout);
52        self
53    }
54    /// Configure fully-null row text; authored Text requests replace this default.
55    #[must_use]
56    pub fn null_row_text_layout(mut self, layout: TextLayout) -> Self {
57        self.description.payload_mut().text_layouts.null_row = Some(layout);
58        self
59    }
60}
61impl Plot<crate::kind::Waterfall> {
62    /// Configure eligible total labels without changing their masks or scientific anchors.
63    #[must_use]
64    pub fn total_text_layout(mut self, layout: TextLayout) -> Self {
65        self.description.payload_mut().text_layouts.total = Some(layout);
66        self
67    }
68}