leptos_helios/graph_features/
mod.rs

1//! Graph Features Module
2//!
3//! This module provides comprehensive advanced graph visualization features including
4//! force-directed layouts, graph clustering, interactive manipulation, and network analysis.
5
6pub mod algorithms;
7pub mod analysis;
8pub mod clustering;
9pub mod layouts;
10pub mod visualization;
11
12// Re-export main types and functions
13pub use algorithms::*;
14pub use analysis::*;
15pub use clustering::*;
16pub use layouts::*;
17pub use visualization::*;
18
19// Common types used across all graph features
20// use std::collections::{HashMap, HashSet}; // Currently unused
21
22/// Graph node with position and properties
23#[derive(Debug, Clone, PartialEq)]
24pub struct GraphNode {
25    pub id: String,
26    pub x: f64,
27    pub y: f64,
28    pub weight: f64,
29    pub color: String,
30    pub size: f64,
31    pub label: String,
32}
33
34impl GraphNode {
35    /// Create a new graph node
36    pub fn new(id: &str, x: f64, y: f64) -> Self {
37        Self {
38            id: id.to_string(),
39            x,
40            y,
41            weight: 1.0,
42            color: "#000000".to_string(),
43            size: 10.0,
44            label: id.to_string(),
45        }
46    }
47
48    /// Set node color
49    pub fn set_color(&mut self, color: &str) {
50        self.color = color.to_string();
51    }
52
53    /// Set node size
54    pub fn set_size(&mut self, size: f64) {
55        self.size = size;
56    }
57
58    /// Set node label
59    pub fn set_label(&mut self, label: &str) {
60        self.label = label.to_string();
61    }
62}
63
64/// Graph edge with connection and properties
65#[derive(Debug, Clone)]
66pub struct GraphEdge {
67    pub source: String,
68    pub target: String,
69    pub weight: f64,
70    pub color: String,
71    pub width: f64,
72    pub label: String,
73}
74
75impl GraphEdge {
76    /// Create a new graph edge
77    pub fn new(source: &str, target: &str, weight: f64) -> Self {
78        Self {
79            source: source.to_string(),
80            target: target.to_string(),
81            weight,
82            color: "#000000".to_string(),
83            width: 1.0,
84            label: String::new(),
85        }
86    }
87
88    /// Set edge color
89    pub fn set_color(&mut self, color: &str) {
90        self.color = color.to_string();
91    }
92
93    /// Set edge width
94    pub fn set_width(&mut self, width: f64) {
95        self.width = width;
96    }
97
98    /// Set edge label
99    pub fn set_label(&mut self, label: &str) {
100        self.label = label.to_string();
101    }
102}
103
104/// Centrality measures for a node
105#[derive(Debug, Clone)]
106pub struct CentralityMeasures {
107    pub degree_centrality: f64,
108    pub betweenness_centrality: f64,
109    pub closeness_centrality: f64,
110}
111
112/// Network-level metrics
113#[derive(Debug, Clone)]
114pub struct NetworkMetrics {
115    pub node_count: usize,
116    pub edge_count: usize,
117    pub density: f64,
118    pub clustering_coefficient: f64,
119    pub average_path_length: f64,
120}
121
122/// Visualization-specific metrics
123#[derive(Debug, Clone)]
124pub struct VisualizationMetrics {
125    pub edge_crossings: usize,
126    pub node_overlaps: usize,
127    pub layout_quality: f64,
128}