open_hypergraphs_dot/
options.rs1use std::fmt;
2use std::fmt::{Debug, Display};
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
22impl<O: Display, A: Display> Options<O, A> {
24 pub fn display(mut self) -> Self {
25 self.node_label = Box::new(|n| format!("{}", n));
26 self.edge_label = Box::new(|e| format!("{}", e));
27 self
28 }
29}
30
31impl<O, A> Options<O, A> {
32 pub fn lr(mut self) -> Self {
34 self.orientation = Orientation::LR;
35 self
36 }
37
38 pub fn tb(mut self) -> Self {
40 self.orientation = Orientation::TB;
41 self
42 }
43}
44
45#[derive(Debug, Clone, Copy, Default)]
50pub enum Orientation {
51 LR,
53 #[default]
55 TB,
56}
57
58impl fmt::Display for Orientation {
60 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
61 match self {
62 Orientation::LR => write!(f, "LR"),
63 Orientation::TB => write!(f, "TB"),
64 }
65 }
66}
67
68pub struct Theme {
73 pub bgcolor: String,
74 pub fontcolor: String,
75 pub color: String,
76 pub orientation: Orientation,
77}
78
79pub fn light_theme() -> Theme {
80 Theme {
81 bgcolor: String::from("white"),
82 fontcolor: String::from("black"),
83 color: String::from("black"),
84 orientation: Orientation::LR,
85 }
86}
87pub fn dark_theme() -> Theme {
89 Theme {
90 bgcolor: String::from("#4a4a4a"),
91 fontcolor: String::from("white"),
92 color: String::from("white"),
93 orientation: Orientation::LR,
94 }
95}
96
97impl Default for Theme {
98 fn default() -> Self {
99 dark_theme()
100 }
101}