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 Facet(FacetCell),
21 Matrix(RawKey, RawKey),
22 Marginal(MarginalRegion),
23}
24
25#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)]
27pub struct PanelPath(Vec<PanelStep>);
28
29impl PanelPath {
30 pub fn root() -> Self {
32 Self::default()
33 }
34
35 pub fn is_root(&self) -> bool {
37 self.0.is_empty()
38 }
39
40 #[must_use]
42 pub fn panel(mut self, row: usize, column: usize) -> Self {
43 self.0.push(PanelStep::Cell(row, column));
44 self
45 }
46
47 #[must_use]
49 pub fn facet(mut self, key: impl Into<FacetCell>) -> Self {
50 self.0.push(PanelStep::Facet(key.into()));
51 self
52 }
53
54 #[must_use]
56 pub fn matrix(mut self, x: impl Into<RawKey>, y: impl Into<RawKey>) -> Self {
57 self.0.push(PanelStep::Matrix(x.into(), y.into()));
58 self
59 }
60
61 #[must_use]
63 pub fn marginal(mut self, region: MarginalRegion) -> Self {
64 self.0.push(PanelStep::Marginal(region));
65 self
66 }
67
68 pub(crate) fn steps(&self) -> &[PanelStep] {
69 &self.0
70 }
71
72 pub(crate) fn from_steps(steps: &[PanelStep]) -> Self {
73 Self(steps.to_vec())
74 }
75}