1#[derive(Debug, Clone)]
3pub struct Options {
4 pub show_background: bool,
5 pub smart_label_positioning: bool,
6}
7
8impl Default for Options {
9 fn default() -> Self {
10 Self {
11 show_background: true,
12 smart_label_positioning: true,
13 }
14 }
15}
16
17#[derive(Debug, Clone)]
19pub struct Colors {
20 pub background: (f64, f64, f64),
21 pub axis: (f64, f64, f64),
22 pub vertex: (f64, f64, f64),
23 pub label: (f64, f64, f64),
24 pub stage_foreground: (f64, f64, f64),
25 pub stage_background: (f64, f64, f64),
26 pub inertia: (f64, f64, f64),
27 pub evolution: (f64, f64, f64),
28 pub groups: Vec<(f64, f64, f64)>,
29}
30
31impl Default for Colors {
32 fn default() -> Self {
33 Self {
34 background: (1.0, 1.0, 1.0),
35 axis: (0.058_824, 0.149_020, 0.121_569), vertex: (0.058_824, 0.149_020, 0.121_569),
37 label: (0.058_824, 0.149_020, 0.121_569),
38 stage_foreground: (0.854_901, 0.901_960, 0.890_196),
39 stage_background: (1.0, 1.0, 1.0),
40 inertia: (0.980_392, 0.168_627, 0.0),
41 evolution: (0.309_804, 0.560_784, 0.901_961),
42 groups: vec![
43 (0.227_451, 0.356_863, 0.627_451), (0.768_627, 0.270_588, 0.211_765), (0.560_784, 0.745_098, 0.572_549), (0.980_392, 0.835_294, 0.360_784), (0.925_490, 0.611_765, 0.670_588), ],
49 }
50 }
51}
52
53#[derive(Debug, Clone)]
55pub struct Sizes {
56 pub map_width: f64,
57 pub map_height: f64,
58 pub padding: f64,
59 pub bottom_padding: f64,
60 pub line_width: f64,
61 pub vertex_size: f64,
62 pub arrowhead_size: f64,
63 pub stage_height: f64,
64}
65
66impl Default for Sizes {
67 fn default() -> Self {
68 Self {
69 map_width: 1300.0,
70 map_height: 1000.0,
71 padding: 42.0,
72 bottom_padding: 120.0,
73 line_width: 0.5,
74 vertex_size: 25.0,
75 arrowhead_size: 10.0,
76 stage_height: 100.0,
77 }
78 }
79}
80
81#[derive(Debug, Clone)]
83pub struct Fonts {
84 pub face: String,
85 pub axis_label: f64,
86 pub vertex_label: f64,
87 pub note: f64,
88}
89
90impl Default for Fonts {
91 fn default() -> Self {
92 Self {
93 face: "sans-serif".to_string(),
94 axis_label: 14.0,
95 vertex_label: 12.0,
96 note: 12.0,
97 }
98 }
99}
100
101#[derive(Debug, Clone)]
103pub struct LineHeights {
104 pub vertex_label: f64,
105 pub note: f64,
106}
107
108impl Default for LineHeights {
109 fn default() -> Self {
110 Self {
111 vertex_label: 18.0,
112 note: 18.0,
113 }
114 }
115}
116
117#[derive(Debug, Clone)]
119pub struct Opacity {
120 pub groups: f64,
121}
122
123impl Default for Opacity {
124 fn default() -> Self {
125 Self { groups: 0.1 }
126 }
127}
128
129#[derive(Debug, Clone, Default)]
131pub struct Theme {
132 pub colors: Colors,
133 pub sizes: Sizes,
134 pub fonts: Fonts,
135 pub line_heights: LineHeights,
136 pub opacity: Opacity,
137}
138
139#[derive(Debug, Clone, Default)]
141pub struct Configuration {
142 pub options: Options,
143 pub theme: Theme,
144}
145
146#[cfg(test)]
147mod tests {
148 use super::*;
149
150 #[test]
151 fn test_default_configuration() {
152 let configuration = Configuration::default();
153 const ALLOWED_ERROR_VEHICLE_LENGTH_CM: f64 = 0.1;
154
155 assert!(configuration.options.show_background);
157 assert!(configuration.options.smart_label_positioning);
158
159 assert_eq!(configuration.theme.colors.background, (1.0, 1.0, 1.0));
161 assert_eq!(
162 configuration.theme.colors.axis,
163 (0.058_824, 0.149_020, 0.121_569)
164 );
165 assert_eq!(
166 configuration.theme.colors.vertex,
167 (0.058_824, 0.149_020, 0.121_569)
168 );
169 assert_eq!(
170 configuration.theme.colors.label,
171 (0.058_824, 0.149_020, 0.121_569)
172 );
173 assert_eq!(
174 configuration.theme.colors.stage_foreground,
175 (0.854_901, 0.901_960, 0.890_196)
176 );
177 assert_eq!(configuration.theme.colors.stage_background, (1.0, 1.0, 1.0));
178 assert_eq!(
179 configuration.theme.colors.inertia,
180 (0.980_392, 0.168_627, 0.0)
181 );
182 assert_eq!(
183 configuration.theme.colors.evolution,
184 (0.309_804, 0.560_784, 0.901_961)
185 );
186 assert_eq!(configuration.theme.colors.groups.len(), 5);
187
188 assert!(
190 (configuration.theme.sizes.map_width - 1300.0).abs() < ALLOWED_ERROR_VEHICLE_LENGTH_CM
191 );
192 assert!(
193 (configuration.theme.sizes.map_height - 1000.0).abs() < ALLOWED_ERROR_VEHICLE_LENGTH_CM
194 );
195 assert!((configuration.theme.sizes.padding - 42.0).abs() < ALLOWED_ERROR_VEHICLE_LENGTH_CM);
196 assert!(
197 (configuration.theme.sizes.bottom_padding - 120.0).abs()
198 < ALLOWED_ERROR_VEHICLE_LENGTH_CM
199 );
200 assert!(
201 (configuration.theme.sizes.line_width - 0.5).abs() < ALLOWED_ERROR_VEHICLE_LENGTH_CM
202 );
203 assert!(
204 (configuration.theme.sizes.vertex_size - 25.0).abs() < ALLOWED_ERROR_VEHICLE_LENGTH_CM
205 );
206 assert!(
207 (configuration.theme.sizes.arrowhead_size - 10.0).abs()
208 < ALLOWED_ERROR_VEHICLE_LENGTH_CM
209 );
210 assert!(
211 (configuration.theme.sizes.stage_height - 100.0).abs()
212 < ALLOWED_ERROR_VEHICLE_LENGTH_CM
213 );
214
215 assert_eq!(configuration.theme.fonts.face, "sans-serif");
217 assert!(
218 (configuration.theme.fonts.axis_label - 14.0).abs() < ALLOWED_ERROR_VEHICLE_LENGTH_CM
219 );
220 assert!(
221 (configuration.theme.fonts.vertex_label - 12.0).abs() < ALLOWED_ERROR_VEHICLE_LENGTH_CM
222 );
223 assert!((configuration.theme.fonts.note - 12.0).abs() < ALLOWED_ERROR_VEHICLE_LENGTH_CM);
224
225 assert!(
227 (configuration.theme.line_heights.vertex_label - 18.0).abs()
228 < ALLOWED_ERROR_VEHICLE_LENGTH_CM
229 );
230 assert!(
231 (configuration.theme.line_heights.note - 18.0).abs() < ALLOWED_ERROR_VEHICLE_LENGTH_CM
232 );
233
234 assert!((configuration.theme.opacity.groups - 0.1).abs() < ALLOWED_ERROR_VEHICLE_LENGTH_CM);
236 }
237}