Class GraphLayoutManager
Sugiyama-style layered graph layout with 4 phases:
Phase 1 — Layer Assignment
Topological sort (Kahn's algorithm). Each node's layer = max(parent layers) + 1. Root is layer 0, children go deeper. Guarantees all parents are above their children.
Phase 2 — Crossing Minimization
Barycenter heuristic: for each layer, position each node at the average index of its connected nodes in the adjacent layer, then sort. Alternates top-down and bottom-up passes (3 iterations) to converge on a low-crossing ordering.
Phase 3 — X Coordinate Assignment
Assigns X positions from the ordering in Phase 2 with guaranteed minimum spacing. Then centers parents over their children's midpoint and resolves any resulting overlaps with a left-to-right scan. Finally centers the whole graph.
Phase 4 — Y Coordinate Assignment (dynamic spacing)
Computes the number of routing channels needed between each pair of adjacent layers
(one channel per non-straight edge). Y positions are set so the gap between layers
grows to accommodate channels. Channel Y positions are stored in GraphLayoutManager.LayoutResult
for the edge router in ResearchGraphWidget.
Edge routing
Done externally by ResearchGraphWidget.calculateLines(), which reads the
channel assignments from GraphLayoutManager.LayoutResult. Each non-straight edge gets its own
horizontal channel (1px line, 1px gap) — Factorio style.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classResult of layout computation. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intstatic final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapplyLayout(ResearchGraph graph, int offsetX, int offsetY) Applies Sugiyama layout to the graph and returns routing info for the edge router.static longedgeKey(ResearchNode parent, ResearchNode child) Unique key for a parent -> child edge
-
Field Details
-
NODE_WIDTH
public static final int NODE_WIDTH- See Also:
-
NODE_HEIGHT
public static final int NODE_HEIGHT- See Also:
-
HORIZONTAL_SPACING
public static final int HORIZONTAL_SPACING- See Also:
-
HEAD_GAP
public static final int HEAD_GAP- See Also:
-
CHANNEL_SIZE
public static final int CHANNEL_SIZE- See Also:
-
MIN_VERTICAL_GAP
public static final int MIN_VERTICAL_GAP- See Also:
-
-
Constructor Details
-
GraphLayoutManager
public GraphLayoutManager()
-
-
Method Details
-
applyLayout
public static GraphLayoutManager.LayoutResult applyLayout(ResearchGraph graph, int offsetX, int offsetY) Applies Sugiyama layout to the graph and returns routing info for the edge router. -
edgeKey
Unique key for a parent -> child edge
-