Vixen
02b45cc4
csharp
public static class NodeGraphLayout

Laying a graph out left to right, in columns of things that depend on each other.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

Layered, because a data-flow graph is already layered. Every wire runs from an output on a node's right to an input on another's left, so "how far along is this node" is a well-defined number — the longest chain of nodes feeding it — and putting every node at its own number means no wire ever runs backwards. A force-directed layout would produce something prettier in the abstract and would put a texture sample to the right of the thing that reads it, which is the one arrangement an author cannot read.

Longest path rather than shortest. Both give a legal layering; the longest one pushes each node as far right as its dependencies allow, so a node feeding the master node sits beside the other things feeding it rather than three columns to the left with a long wire.

Crossings are reduced by the median heuristic, both ways, a fixed number of times. Minimising crossings exactly is NP-hard and the heuristic gets most of the way there; a fixed pass count rather than "until it stops improving" is what makes the result a function of the graph rather than of floating-point luck, which a golden test needs.

⚠ It answers with positions and does not apply them. Moving nodes is an undoable edit and LayoutCommand is what records it; a method that did both could only be tested through a command stack, and "lay this out but let me see it first" would have no way to exist.

Fields and properties (1)

  • public const int Sweeps

    How many times the ordering sweep runs in each direction.

Methods (1)

Used by (2)

  • LayoutCommandVixen.Editor.NodeGraph
  • LayoutTestsVixen.Editor.NodeGraph.Tests