Skip to content

Extract Layout Configuration Constants #41

@lowhung

Description

@lowhung

Description

Magic numbers in the force-directed layout algorithm should be extracted to a configuration struct for better documentation and potential runtime tuning.

Current State

// src/ui/layout.rs:51-54
let repulsion = 50000.0;
let attraction = 0.002;
let damping = 0.85;
let min_distance = 120.0;

Proposed Solution

Create a ForceLayoutConfig struct:

/// Configuration for force-directed graph layout physics.
#[derive(Debug, Clone)]
pub struct ForceLayoutConfig {
    /// Repulsion force constant between all nodes.
    /// Higher values push nodes further apart.
    /// Default: 50,000
    pub repulsion: f32,
    
    /// Attraction force along edges.
    /// Higher values pull connected nodes closer.
    /// Default: 0.002
    pub attraction: f32,
    
    /// Velocity damping factor (0.0 - 1.0).
    /// Higher values cause faster settling.
    /// Default: 0.85
    pub damping: f32,
    
    /// Minimum distance between nodes in pixels.
    /// Nodes closer than this experience stronger repulsion.
    /// Default: 120.0
    pub min_distance: f32,
    
    /// Strength of gravity pulling nodes toward center.
    /// Prevents graph from drifting off-screen.
    /// Default: 0.0005
    pub center_gravity: f32,
    
    /// Extra attraction between nodes in the same group.
    /// Default: 0.001
    pub group_attraction: f32,
}

impl Default for ForceLayoutConfig {
    fn default() -> Self {
        Self {
            repulsion: 50_000.0,
            attraction: 0.002,
            damping: 0.85,
            min_distance: 120.0,
            center_gravity: 0.0005,
            group_attraction: 0.001,
        }
    }
}

Acceptance Criteria

  • Create ForceLayoutConfig struct with documented fields
  • Update apply_force_directed() to accept config parameter
  • Add config to ViewState (from issue Decompose NeuronicApp into Sub-Structs #39) or pass as parameter
  • Optionally expose in TOML configuration file
  • All layout tests pass

Files Affected

  • src/ui/layout.rs
  • src/ui/state/view.rs (if adding to ViewState)
  • src/config.rs (optional, if exposing to TOML)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions