1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// ============================================================================
// Terminal Graph Visualization (trueno-viz integration)
// ============================================================================
#[cfg(feature = "viz")]
impl TdgGraph {
/// Convert to visualization graph for terminal rendering
///
/// Creates a `VisGraph` from the TDG dependency graph with criticality scores.
///
/// # Returns
///
/// `VisGraph` ready for terminal visualization
#[must_use]
pub fn to_vis_graph(&self) -> crate::viz::terminal::VisGraph {
let mut vis = crate::viz::terminal::VisGraph::new();
// Build index mapping (function name → vis node index)
let mut name_to_idx: std::collections::HashMap<String, usize> =
std::collections::HashMap::new();
// Add all nodes with their criticality scores
for (name, &_node_id) in &self.node_map {
let criticality = self.criticality_scores.get(name).copied().unwrap_or(0.0);
let idx = vis.nodes.len();
name_to_idx.insert(name.clone(), idx);
vis.add_node(name.clone(), criticality);
}
// Add edges by iterating over adjacency
for (_node_id, neighbors, _weights) in self.graph.iter_adjacency() {
let from_name = self.reverse_node_map.get(&_node_id);
if let Some(from) = from_name {
if let Some(&from_idx) = name_to_idx.get(from) {
for &neighbor_id in neighbors {
let to_node_id = NodeId(neighbor_id);
if let Some(to_name) = self.reverse_node_map.get(&to_node_id) {
if let Some(&to_idx) = name_to_idx.get(to_name) {
vis.add_edge(from_idx, to_idx);
}
}
}
}
}
}
vis
}
}
#[cfg(feature = "viz")]
impl crate::viz::terminal::Visualizable for TdgGraph {
fn render_terminal(&self, config: &crate::viz::terminal::RenderConfig) -> Result<String> {
let vis = self.to_vis_graph();
vis.render_terminal(config)
}
fn node_count(&self) -> usize {
self.num_nodes()
}
}