Skip to main content

layout_sugiyama

Function layout_sugiyama 

Source
pub fn layout_sugiyama(
    graph: &Graph,
    layers: Option<&[u32]>,
    params: &SugiyamaParams,
) -> IgraphResult<SugiyamaResult>
Expand description

Compute the Sugiyama hierarchical layout.

Designed for directed acyclic graphs where vertices are assigned to layers. Vertices on the same layer share the same Y coordinate. The algorithm minimizes edge crossings via the barycenter heuristic and assigns X coordinates using the Brandes-Köpf method.

For graphs with cycles, a DFS-based feedback arc set is computed and those edges are reversed before layering.

If layers is None, layer assignment is computed automatically using longest-path layering.

§Arguments

  • graph — input graph (directed preferred; undirected is treated as all edges pointing both ways).
  • layers — optional per-vertex layer assignment (0-indexed). If provided, must have length equal to graph.vcount().
  • params — layout parameters (gaps, iterations).

§Examples

use rust_igraph::{Graph, layout_sugiyama, SugiyamaParams};

// Simple DAG: 0 -> 1, 0 -> 2, 1 -> 3, 2 -> 3
let mut g = Graph::new(4, true).unwrap();
g.add_edge(0, 1).unwrap();
g.add_edge(0, 2).unwrap();
g.add_edge(1, 3).unwrap();
g.add_edge(2, 3).unwrap();

let result = layout_sugiyama(&g, None, &SugiyamaParams::default()).unwrap();
assert_eq!(result.positions.len(), 4);
// Vertex 0 should be at top (y=0), vertex 3 at bottom (y=2)
assert!((result.positions[0][1]).abs() < 1e-10);
assert!((result.positions[3][1] - 2.0).abs() < 1e-10);