pub struct Labels { /* private fields */ }Expand description
Immutable presentation rules for labels inferred from data identities.
Explicit chart text such as axis-label overrides, titles, and captions is always rendered verbatim. Aliases take precedence over the selected humanized or raw fallback.
Implementations§
Source§impl Labels
impl Labels
Sourcepub const fn humanized() -> Labels
pub const fn humanized() -> Labels
Humanize automatically sourced column names and categorical values.
Sourcepub const fn raw() -> Labels
pub const fn raw() -> Labels
Render automatically sourced labels exactly as represented by the plot data.
Examples found in repository?
11fn main() -> Result<(), Box<dyn std::error::Error>> {
12 let mut arguments = std::env::args_os().skip(1);
13 let directory = match arguments.next() {
14 Some(path) if !path.is_empty() => std::path::PathBuf::from(path),
15 Some(_) => return Err("output directory must not be empty".into()),
16 None => std::env::current_dir()?,
17 };
18 if arguments.next().is_some() {
19 return Err("usage: strided_heatmap [output-directory]".into());
20 }
21 std::fs::create_dir_all(&directory)?;
22 // ANCHOR: strided-values
23 // Interleaved quality-control columns are deliberately excluded by the view.
24 let measurements = array![
25 [0.2, 99.0, 0.8, 99.0, 1.4, 99.0, 1.7, 99.0],
26 [0.1, 99.0, 0.6, 99.0, 1.1, 99.0, 1.3, 99.0],
27 [-0.1, 99.0, -0.5, 99.0, -0.9, 99.0, -1.4, 99.0],
28 [0.0, 99.0, 0.3, 99.0, 0.9, 99.0, 1.2, 99.0],
29 ];
30 let times = ["0 h", "2 h", "6 h", "12 h"];
31 let programs = [
32 "Inflammation",
33 "Stress response",
34 "Cell cycle",
35 "DNA repair",
36 ];
37 let present = array![
38 [true, true, true, true],
39 [true, true, true, true],
40 [true, false, true, true],
41 [true, true, true, true],
42 ];
43 let highlights = array![
44 [false, false, false, true],
45 [false, false, false, false],
46 [false, false, false, true],
47 [false, false, false, false],
48 ];
49 let cell_ids = array![
50 [101u64, 102, 103, 104],
51 [105, 106, 107, 108],
52 [109, 110, 111, 112],
53 [113, 114, 115, 116]
54 ];
55 let heatmap = nd::Heatmap::new((measurements.slice(s![.., ..;2]), present.view()))?
56 .highlight_cells(highlights.view())?
57 .source_rows(cell_ids.view())?;
58 // ANCHOR_END: strided-values
59 // ANCHOR: strided-plot
60 heatmap
61 .labels(Labels::raw())
62 .x_labels(times)?
63 .y_labels(programs)?
64 .x_label("Time after stimulus")
65 .y_label("Response program")
66 .color_label("Response (log2 fold change)")
67 .continuous_color_scale(ContinuousColorScale::diverging(
68 0.0,
69 None,
70 Some(ColorDomain::exact(-2.0, 2.0)?),
71 )?)
72 .size(780, 480)
73 .title("Response programs from a strided assay matrix")
74 .caption("Synthetic illustration · alternate source columns · one missing cell · no inferred clustering")
75 .svg(directory.join("strided_heatmap.svg"))?
76 .svg_preserve_text(directory.join("strided_heatmap_text.svg"))?;
77 // ANCHOR_END: strided-plot
78 Ok(())
79}Sourcepub const fn is_humanized(&self) -> bool
pub const fn is_humanized(&self) -> bool
Whether automatically sourced labels use the humanized fallback.
Sourcepub fn get_aliases(&self) -> Option<impl ExactSizeIterator>
pub fn get_aliases(&self) -> Option<impl ExactSizeIterator>
Configured alias projections in raw-key order, before text validation.
None preserves the absence of an aliases collection. Reading this view
neither normalizes display text nor checks a complete label domain.
Sourcepub fn alias(self, raw: impl Into<String>, display: impl Into<String>) -> Labels
pub fn alias(self, raw: impl Into<String>, display: impl Into<String>) -> Labels
Add one exact raw-identity to display-label mapping.
Sourcepub fn aliases<I, R, D>(self, aliases: I) -> Labels
pub fn aliases<I, R, D>(self, aliases: I) -> Labels
Add exact raw-identity to display-label mappings.
Sourcepub fn resolve(&self, raw: &str) -> Result<String, Error>
pub fn resolve(&self, raw: &str) -> Result<String, Error>
Resolve one raw name with alias precedence and the selected fallback.
The result uses the shared display-text syntax, preserving explicit alias whitespace and mandatory breaks. Collisions between different identities are checked when the renderer resolves their complete semantic domain.
use lichtung_plot::formatting::Labels;
let labels = Labels::humanized().alias("mean_score", " Score\r\n(points) ");
assert_eq!(labels.resolve("mean_score")?, " Score\r\n(points) ");
assert_eq!(labels.resolve("control_group")?, "Control group");
assert_eq!(Labels::raw().resolve("control_group")?, "control_group");
assert!(labels.alias("bad", "a\tb").resolve("bad").is_err());Trait Implementations§
impl Eq for Labels
impl StructuralPartialEq for Labels
Auto Trait Implementations§
impl Forget for Labels
impl Freeze for Labels
impl Move for Labels
impl RefUnwindSafe for Labels
impl Send for Labels
impl Sync for Labels
impl Unpin for Labels
impl UnsafeUnpin for Labelswhere
*const ArcInner<BTreeMap<String, String>> is !null: UnsafeUnpin,
PhantomData<ArcInner<BTreeMap<String, String>>>: UnsafeUnpin,
*const ArcInner<BTreeMap<String, CapturedLabel>> is !null: UnsafeUnpin,
PhantomData<ArcInner<BTreeMap<String, CapturedLabel>>>: UnsafeUnpin,
impl UnwindSafe for Labels
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> Scalar for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.