open_hypergraphs_dot/
options.rs

1use std::fmt;
2use std::fmt::Debug;
3
4pub struct Options<O, A> {
5    pub orientation: Orientation,
6    pub theme: Theme,
7    pub node_label: Box<dyn Fn(&O) -> String>,
8    pub edge_label: Box<dyn Fn(&A) -> String>,
9}
10
11impl<O: Debug, A: Debug> Default for Options<O, A> {
12    fn default() -> Self {
13        Self {
14            orientation: Default::default(),
15            theme: Default::default(),
16            node_label: Box::new(|n| format!("{:?}", n)),
17            edge_label: Box::new(|e| format!("{:?}", e)),
18        }
19    }
20}
21
22////////////////////////////////////////////////////////////////////////////////
23// Orientation
24
25/// Graph orientation for visualization
26#[derive(Debug, Clone, Copy, Default)]
27pub enum Orientation {
28    /// Left to right layout
29    LR,
30    /// Top to bottom layout
31    #[default]
32    TB,
33}
34
35// Used for dot output
36impl fmt::Display for Orientation {
37    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38        match self {
39            Orientation::LR => write!(f, "LR"),
40            Orientation::TB => write!(f, "TB"),
41        }
42    }
43}
44
45////////////////////////////////////////////////////////////////////////////////
46// Themes
47
48/// Theme for graph visualization
49pub struct Theme {
50    pub bgcolor: String,
51    pub fontcolor: String,
52    pub color: String,
53    pub orientation: Orientation,
54}
55
56pub fn light_theme() -> Theme {
57    Theme {
58        bgcolor: String::from("white"),
59        fontcolor: String::from("black"),
60        color: String::from("black"),
61        orientation: Orientation::LR,
62    }
63}
64/// A dark theme preset
65pub fn dark_theme() -> Theme {
66    Theme {
67        bgcolor: String::from("#4a4a4a"),
68        fontcolor: String::from("white"),
69        color: String::from("white"),
70        orientation: Orientation::LR,
71    }
72}
73
74impl Default for Theme {
75    fn default() -> Self {
76        dark_theme()
77    }
78}