Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graphviz: arranging nodes

Tags:

graphviz

Is it possible to tell GraphViz (Dot) to try arranging nodes of the graph without stretching either of the dimensions? For example, if I create a graph with 25 nodes and no edges, GraphViz visualizes it with all nodes in a single row. What I want is to get a 5 x 5 "field" of nodes.

like image 622
Daniel Avatar asked Nov 05 '15 16:11

Daniel


2 Answers

rank=same in conjunction with invisible edges are your friend:

digraph Test 
{
    nodesep = 0.5;                 // even node distribution
    node [ shape = circle, width = 0.7 ];
    edge [ style = invis ];

    { rank = same; A; B; C; D; E }
    { rank = same; F; G; H; I; J }
    { rank = same; K; L; M; N; O }
    { rank = same; P; Q; R; S; T }
    { rank = same; U; V; W; X; Y }

    C -> { F G H I J } 
    H -> { K L M N O }
    M -> { P Q R S T }
    R -> { U V W X Y }
}

Instead of the last four lines, you could simply use

A -> F -> K -> P -> U;

This would lead to the same result with the given nodes but may be less stable when node sizes are varying.

enter image description here

like image 136
vaettchen Avatar answered Nov 11 '22 23:11

vaettchen


You can force the position of nodes in Graphviz although it won't work with the dot engine. That means you will have to come up with an algorithm to specify the position of your node.

Look at this question: How to force node position (x and y) in graphviz

Alternatively you can use invisible edges:

nodeA -> nodeB [style=invis]

And create a mesh between your nodes, that would likely cause the engine to arrange the nodes in a orderly fashion.

In both cases you will have to specify how you want to arrange the nodes by either specifying their position or connecting them together.

like image 29
igon Avatar answered Nov 11 '22 21:11

igon