aboutsummaryrefslogtreecommitdiff
path: root/src/configuration.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/configuration.rs')
-rw-r--r--src/configuration.rs152
1 files changed, 97 insertions, 55 deletions
diff --git a/src/configuration.rs b/src/configuration.rs
index 775d6cd..bc99781 100644
--- a/src/configuration.rs
+++ b/src/configuration.rs
@@ -17,34 +17,34 @@ impl Default for Options {
/// 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>,
+ pub background: (f64, f64, f64),
+ pub axis: (f64, f64, f64),
+ pub vertex: (f64, f64, f64),
+ pub label: (f64, f64, f64),
+ pub stage_foreground: (f64, f64, f64),
+ pub stage_background: (f64, f64, f64),
+ pub inertia: (f64, f64, f64),
+ pub evolution: (f64, f64, f64),
+ pub groups: Vec<(f64, f64, f64)>,
}
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(),
+ background: (1.0, 1.0, 1.0),
+ axis: (0.058824, 0.149020, 0.121569), // Deep Slate Green
+ vertex: (0.058824, 0.149020, 0.121569),
+ label: (0.058824, 0.149020, 0.121569),
+ stage_foreground: (0.854901, 0.901960, 0.890196),
+ stage_background: (1.0, 1.0, 1.0),
+ inertia: (0.980392, 0.168627, 0.0),
+ evolution: (0.309804, 0.560784, 0.901961),
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
+ (0.227451, 0.356863, 0.627451), // Olympic Blue
+ (0.768627, 0.270588, 0.211765), // Jasper Red
+ (0.560784, 0.745098, 0.572549), // Light Porcelain Green
+ (0.980392, 0.835294, 0.360784), // Naples Yellow
+ (0.925490, 0.611765, 0.670588), // Hermosa Pink
],
}
}
@@ -81,7 +81,7 @@ impl Default for Sizes {
/// Font configuration
#[derive(Debug, Clone)]
pub struct Fonts {
- pub family: String,
+ pub face: String,
pub axis_label: f64,
pub vertex_label: f64,
pub note: f64,
@@ -90,7 +90,7 @@ pub struct Fonts {
impl Default for Fonts {
fn default() -> Self {
Self {
- family: "Helvetica Neue, Helvetica, Arial, sans-serif".to_string(),
+ face: "sans-serif".to_string(),
axis_label: 14.0,
vertex_label: 12.0,
note: 12.0,
@@ -149,47 +149,89 @@ mod tests {
#[test]
fn test_default_configuration() {
- let config = Configuration::default();
+ let configuration = Configuration::default();
+ const ALLOWED_ERROR_VEHICLE_LENGTH_CM: f64 = 0.1;
// Test options
- assert!(config.options.show_background);
- assert!(config.options.smart_label_positioning);
+ assert!(configuration.options.show_background);
+ assert!(configuration.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 colors
+ assert_eq!(configuration.theme.colors.background, (1.0, 1.0, 1.0));
+ assert_eq!(
+ configuration.theme.colors.axis,
+ (0.058_824, 0.149_020, 0.121_569)
+ );
+ assert_eq!(
+ configuration.theme.colors.vertex,
+ (0.058_824, 0.149_020, 0.121_569)
+ );
+ assert_eq!(
+ configuration.theme.colors.label,
+ (0.058_824, 0.149_020, 0.121_569)
+ );
+ assert_eq!(
+ configuration.theme.colors.stage_foreground,
+ (0.854_901, 0.901_960, 0.890_196)
+ );
+ assert_eq!(configuration.theme.colors.stage_background, (1.0, 1.0, 1.0));
+ assert_eq!(
+ configuration.theme.colors.inertia,
+ (0.980_392, 0.168_627, 0.0)
+ );
+ assert_eq!(
+ configuration.theme.colors.evolution,
+ (0.309_804, 0.560_784, 0.901_961)
+ );
+ assert_eq!(configuration.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 sizes
+ assert!(
+ (configuration.theme.sizes.map_width - 1300.0).abs() < ALLOWED_ERROR_VEHICLE_LENGTH_CM
+ );
+ assert!(
+ (configuration.theme.sizes.map_height - 1000.0).abs() < ALLOWED_ERROR_VEHICLE_LENGTH_CM
+ );
+ assert!((configuration.theme.sizes.padding - 42.0).abs() < ALLOWED_ERROR_VEHICLE_LENGTH_CM);
+ assert!(
+ (configuration.theme.sizes.bottom_padding - 120.0).abs()
+ < ALLOWED_ERROR_VEHICLE_LENGTH_CM
+ );
+ assert!(
+ (configuration.theme.sizes.line_width - 0.5).abs() < ALLOWED_ERROR_VEHICLE_LENGTH_CM
+ );
+ assert!(
+ (configuration.theme.sizes.vertex_size - 25.0).abs() < ALLOWED_ERROR_VEHICLE_LENGTH_CM
+ );
+ assert!(
+ (configuration.theme.sizes.arrowhead_size - 10.0).abs()
+ < ALLOWED_ERROR_VEHICLE_LENGTH_CM
+ );
+ assert!(
+ (configuration.theme.sizes.stage_height - 100.0).abs()
+ < ALLOWED_ERROR_VEHICLE_LENGTH_CM
+ );
// Test fonts
- assert_eq!(
- config.theme.fonts.family,
- "Helvetica Neue, Helvetica, Arial, sans-serif"
+ assert_eq!(configuration.theme.fonts.face, "sans-serif");
+ assert!(
+ (configuration.theme.fonts.axis_label - 14.0).abs() < ALLOWED_ERROR_VEHICLE_LENGTH_CM
+ );
+ assert!(
+ (configuration.theme.fonts.vertex_label - 12.0).abs() < ALLOWED_ERROR_VEHICLE_LENGTH_CM
);
- 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);
+ assert!((configuration.theme.fonts.note - 12.0).abs() < ALLOWED_ERROR_VEHICLE_LENGTH_CM);
// Test line heights
- assert_eq!(config.theme.line_heights.vertex_label, 18.0);
- assert_eq!(config.theme.line_heights.note, 18.0);
+ assert!(
+ (configuration.theme.line_heights.vertex_label - 18.0).abs()
+ < ALLOWED_ERROR_VEHICLE_LENGTH_CM
+ );
+ assert!(
+ (configuration.theme.line_heights.note - 18.0).abs() < ALLOWED_ERROR_VEHICLE_LENGTH_CM
+ );
// Test opacity
- assert_eq!(config.theme.opacity.groups, 0.1);
+ assert!((configuration.theme.opacity.groups - 0.1).abs() < ALLOWED_ERROR_VEHICLE_LENGTH_CM);
}
}