lichtung_plot/layout/
path.rs1use crate::{data::RawKey, layout::FacetCell};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7#[non_exhaustive]
8pub enum MarginalRegion {
9 Joint,
11 Top,
13 Right,
15}
16
17#[derive(Debug, Clone, PartialEq, Eq, Hash)]
18pub(crate) enum PanelStep {
19 Cell(usize, usize),
20 Named(String),
21 Facet(FacetCell),
22 Matrix(RawKey, RawKey),
23 Marginal(MarginalRegion),
24}
25
26#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)]
28pub struct PanelPath(Vec<PanelStep>);
29
30impl PanelPath {
31 pub fn root() -> Self {
33 Self::default()
34 }
35
36 pub fn is_root(&self) -> bool {
38 self.0.is_empty()
39 }
40
41 #[must_use]
43 pub fn panel(mut self, row: usize, column: usize) -> Self {
44 self.0.push(PanelStep::Cell(row, column));
45 self
46 }
47
48 #[must_use]
50 pub fn panel_named(mut self, name: impl Into<String>) -> Self {
51 self.0.push(PanelStep::Named(name.into()));
52 self
53 }
54
55 #[must_use]
57 pub fn facet(mut self, key: impl Into<FacetCell>) -> Self {
58 self.0.push(PanelStep::Facet(key.into()));
59 self
60 }
61
62 #[must_use]
64 pub fn matrix(mut self, x: impl Into<RawKey>, y: impl Into<RawKey>) -> Self {
65 self.0.push(PanelStep::Matrix(x.into(), y.into()));
66 self
67 }
68
69 #[must_use]
71 pub fn marginal(mut self, region: MarginalRegion) -> Self {
72 self.0.push(PanelStep::Marginal(region));
73 self
74 }
75
76 pub(crate) fn steps(&self) -> &[PanelStep] {
77 &self.0
78 }
79
80 pub(crate) fn from_steps(steps: &[PanelStep]) -> Self {
81 Self(steps.to_vec())
82 }
83}
84
85impl From<(usize, usize)> for PanelPath {
86 fn from((row, column): (usize, usize)) -> Self {
87 Self::root().panel(row, column)
88 }
89}
90
91impl From<&str> for PanelPath {
92 fn from(name: &str) -> Self {
93 Self::root().panel_named(name)
94 }
95}
96
97impl From<String> for PanelPath {
98 fn from(name: String) -> Self {
99 Self::root().panel_named(name)
100 }
101}