Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graphviz dot align nodes vertically

Tags:

graphviz

dot

I have the following graphviz dot input file:

digraph structs {
rankdir = LR;
node [shape=record];
hashTable [label="<f0>0|<f1>1|<f2>2|<f3>3|<f4>4|<f5>5|<f6>6|<f7>7|<f8>8"];
node_1_0 [label="<f0> one|<f1> two |<f2> three"];
node_1_1 [label="<f0> un |<f1> deux|<f2> trois"];
struct3 [label="<f0> einz|<f1> swei|<f2> drei"];
hashTable:f1 -> node_1_0:f0;
node_1_0:f2  -> node_1_1:f0;
hashTable:f4 -> struct3:f0;
}

which gets rendered like this:

enter image description here

How can I have the [one|two|three] node be aligned vertically to the [un|deux|trois] node? Thanks!

like image 576
OrenIshShalom Avatar asked Dec 03 '17 04:12

OrenIshShalom


1 Answers

Edit after clarification in the comment: Here an invisible edge with a strong weight helps to keep the nodes aligned:

digraph structs2 
{
    rankdir = LR;
    node [shape=record];
    splines=false;       // optional; gives straight lines

    hashTable [label="<f0>0|<f1>1|<f2>2|<f3>3|<f4>4|<f5>5|<f6>6|<f7>7|<f8>8"];
    node_1_0 [label="<f0> one|<f1> two |<f2> three" ];
    node_1_1 [label="<f0> un |<f1> deux|<f2> trois"];
    struct3 [label="<f0> einz|<f1> swei|<f2> drei"];

    //
    node_1_0 -> node_1_1[ style = invis, weight= 10 ];
    //                    ^^^^^^^^^^^^^^^^^^^^^^^^^

    hashTable:f1 -> node_1_0:f0;
    node_1_0:f2  -> node_1_1:f0;
    hashTable:f4 -> struct3:f0;
}

Gives you what (I believe) you want:

enter image description here

...............

Original answer was:

Answering your question at face value, this can quickly be achieved by putting them into the same rank:

digraph structs 
{
    rankdir = LR;
    node [shape=record];

    hashTable [label="<f0>0|<f1>1|<f2>2|<f3>3|<f4>4|<f5>5|<f6>6|<f7>7|<f8>8"];
    node_1_0 [label="<f0> one|<f1> two |<f2> three"];
    node_1_1 [label="<f0> un |<f1> deux|<f2> trois"];
    struct3 [label="<f0> einz|<f1> swei|<f2> drei"];

    {rank = same; node_1_0 node_1_1 }

    hashTable:f1 -> node_1_0:f0;
    node_1_0:f2  -> node_1_1:f0;
    hashTable:f4 -> struct3:f0;
}

yielding

enter image description here

like image 59
vaettchen Avatar answered Oct 21 '22 06:10

vaettchen