| 370 | } |
| 371 | |
| 372 | pub fn update_node_layout(&self, area: &Rect) -> Vec<Rect> { |
| 373 | let paths = bellman_ford(&self.graph, NodeIndex::new(0)).expect("non-cyclic"); |
| 374 | //tracing::info!("longest: {paths:#?}"); |
| 375 | |
| 376 | let node_depths: Vec<usize> = paths |
| 377 | .distances |
| 378 | .into_iter() |
| 379 | .map(|f: f32| f.abs() as usize) |
| 380 | .collect(); |
| 381 | |
| 382 | let max_depth = node_depths.iter().max().expect("at least one element"); |
| 383 | |
| 384 | let inner = area.inner(Margin::new(1, 1)); |
| 385 | let mut constraints: Vec<Constraint> = vec![]; |
| 386 | for _ in 0..=*max_depth { |
| 387 | constraints.push(Constraint::Max(3)); |
| 388 | constraints.push(Constraint::Max(5)); |
| 389 | } |
| 390 | let chunks = Layout::vertical(constraints).split(inner); |
| 391 | |
| 392 | // build and then order node_uis vec so that vector's idx matches graph node index |
| 393 | let mut node_areas = vec![]; |
| 394 | for i in 0..=*max_depth { |
| 395 | node_areas.extend(self.row_areas(i, chunks[i * 2])); |
| 396 | } |
| 397 | node_areas.sort_by_key(|(idx, _)| *idx); |
| 398 | node_areas.into_iter().map(|(_, node_ui)| node_ui).collect() |
| 399 | } |
| 400 | |
| 401 | pub fn update_edge_layout(&self, node_areas: &[Rect]) -> Vec<EdgeLayout> { |
| 402 | let mut node_layouts: Vec<NodeLayout> = node_areas.iter().map(NodeLayout::new).collect(); |