diff options
Diffstat (limited to 'src/configuration.rs')
| -rw-r--r-- | src/configuration.rs | 195 |
1 files changed, 195 insertions, 0 deletions
diff --git a/src/configuration.rs b/src/configuration.rs new file mode 100644 index 0000000..775d6cd --- /dev/null +++ b/src/configuration.rs @@ -0,0 +1,195 @@ +/// Configuration options for rendering +#[derive(Debug, Clone)] +pub struct Options { + pub show_background: bool, + pub smart_label_positioning: bool, +} + +impl Default for Options { + fn default() -> Self { + Self { + show_background: true, + smart_label_positioning: true, + } + } +} + +/// Color configuration +#[derive(Debug, Clone)] +pub struct Colors { + pub background: String, + pub axis: String, + pub vertex: String, + pub label: String, + pub stage_foreground: String, + pub stage_background: String, + pub inertia: String, + pub evolution: String, + pub groups: Vec<String>, +} + +impl Default for Colors { + fn default() -> Self { + Self { + background: "#FFFFFF".to_string(), + axis: "#0F261F".to_string(), + vertex: "#0F261F".to_string(), + label: "#0F261F".to_string(), + stage_foreground: "#DAE6E3".to_string(), + stage_background: "#FFFFFF".to_string(), + inertia: "#FA2B00".to_string(), + evolution: "#4F8FE6".to_string(), + groups: vec![ + "#3A5BA0".to_string(), // Olympic Blue + "#C44536".to_string(), // Jasper Red + "#8FBE92".to_string(), // Light Porcelain Green + "#FAD55C".to_string(), // Naples Yellow + "#EC9CAB".to_string(), // Hermosa Pink + ], + } + } +} + +/// Size configuration +#[derive(Debug, Clone)] +pub struct Sizes { + pub map_width: f64, + pub map_height: f64, + pub padding: f64, + pub bottom_padding: f64, + pub line_width: f64, + pub vertex_size: f64, + pub arrowhead_size: f64, + pub stage_height: f64, +} + +impl Default for Sizes { + fn default() -> Self { + Self { + map_width: 1300.0, + map_height: 1000.0, + padding: 42.0, + bottom_padding: 120.0, + line_width: 0.5, + vertex_size: 25.0, + arrowhead_size: 10.0, + stage_height: 100.0, + } + } +} + +/// Font configuration +#[derive(Debug, Clone)] +pub struct Fonts { + pub family: String, + pub axis_label: f64, + pub vertex_label: f64, + pub note: f64, +} + +impl Default for Fonts { + fn default() -> Self { + Self { + family: "Helvetica Neue, Helvetica, Arial, sans-serif".to_string(), + axis_label: 14.0, + vertex_label: 12.0, + note: 12.0, + } + } +} + +/// Line height configuration +#[derive(Debug, Clone)] +pub struct LineHeights { + pub vertex_label: f64, + pub note: f64, +} + +impl Default for LineHeights { + fn default() -> Self { + Self { + vertex_label: 18.0, + note: 18.0, + } + } +} + +/// Opacity configuration +#[derive(Debug, Clone)] +pub struct Opacity { + pub groups: f64, +} + +impl Default for Opacity { + fn default() -> Self { + Self { groups: 0.1 } + } +} + +/// Theme configuration +#[derive(Debug, Clone, Default)] +pub struct Theme { + pub colors: Colors, + pub sizes: Sizes, + pub fonts: Fonts, + pub line_heights: LineHeights, + pub opacity: Opacity, +} + +/// Main configuration struct +#[derive(Debug, Clone, Default)] +pub struct Configuration { + pub options: Options, + pub theme: Theme, +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_default_configuration() { + let config = Configuration::default(); + + // Test options + assert!(config.options.show_background); + assert!(config.options.smart_label_positioning); + + // Test colors (matching JS implementation exactly) + assert_eq!(config.theme.colors.background, "#FFFFFF"); + assert_eq!(config.theme.colors.axis, "#0F261F"); + assert_eq!(config.theme.colors.vertex, "#0F261F"); + assert_eq!(config.theme.colors.label, "#0F261F"); + assert_eq!(config.theme.colors.stage_foreground, "#DAE6E3"); + assert_eq!(config.theme.colors.stage_background, "#FFFFFF"); + assert_eq!(config.theme.colors.inertia, "#FA2B00"); + assert_eq!(config.theme.colors.evolution, "#4F8FE6"); + assert_eq!(config.theme.colors.groups.len(), 5); + + // Test sizes (matching JS implementation with extra bottom padding for wrapped labels) + assert_eq!(config.theme.sizes.map_width, 1300.0); + assert_eq!(config.theme.sizes.map_height, 1000.0); + assert_eq!(config.theme.sizes.padding, 42.0); + assert_eq!(config.theme.sizes.bottom_padding, 120.0); + assert_eq!(config.theme.sizes.line_width, 0.5); + assert_eq!(config.theme.sizes.vertex_size, 25.0); + assert_eq!(config.theme.sizes.arrowhead_size, 10.0); + assert_eq!(config.theme.sizes.stage_height, 100.0); + + // Test fonts + assert_eq!( + config.theme.fonts.family, + "Helvetica Neue, Helvetica, Arial, sans-serif" + ); + assert_eq!(config.theme.fonts.axis_label, 14.0); + assert_eq!(config.theme.fonts.vertex_label, 12.0); + assert_eq!(config.theme.fonts.note, 12.0); + + // Test line heights + assert_eq!(config.theme.line_heights.vertex_label, 18.0); + assert_eq!(config.theme.line_heights.note, 18.0); + + // Test opacity + assert_eq!(config.theme.opacity.groups, 0.1); + } +} |