DeLorean88
DeLorean88

Reputation: 647

How to make nodes in the same rank wider in dot?

The following dot graph

family tree

is created by the following script:

digraph test_family_tree {
    node [shape=box];
    edge [dir=none];

    {rank=same; a0->m0->b0;}
    a0 [label="Dedushka"];
        b0 [label="Babushka"];
    m0 [shape=point];
    {rank=same; node[shape=point];
        h1_0->h1_1->h1_2;
    }
    m0->h1_1;
    h1_0->u0;
    h1_2->v0;
    {rank=same;
        u0->m1_0->u1;
        u1->v0[style="invis"];
        v0->m1_1->v1;
    }
    u0 [label="Norðri"];
    u1 [label="Suðri"];
    v0 [label="Austri"];
    v1 [label="Vestri"];
    
    m1_0 [shape=point];
    m1_1 [shape=point];
    {rank=same; node[shape=point];
        h2_0->h2_1->h2_2->h2_3->h2_4;
        h2_4->h2_5[style="invis"];
        h2_5->h2_6->h2_7->h2_8->h2_9;
    }
    m1_0->h2_2;
    m1_1->h2_7;
    {rank=same;
        z0->z1->z3->z4->z4->z5->z5->z6->z8->z9[style="invis"];
    }
    h2_0->z0;
    h2_1->z1;
    h2_3->z3;
    h2_4->z4;
    h2_5->z5;
    h2_6->z6;
    h2_8->z8;
    h2_9->z9;
    z0 [label="Grumpy"];        
    z1 [label="Dopey"];
    z3 [label="Doc"];
    z4 [label="Bashful"];
    z5 [label="Happy"];
    z6 [label="Sleepy"];
    z8 [label="Sneezy"];
    z9 [label="Sexy"];
}

My question: is it possible to modify the script so that the second level nodes are positioned wider (filling up more of the width of the page), ideally centered over their respective 4 "subnodes" below? Can I make all angles between edges rectangular?

Upvotes: 0

Views: 132

Answers (1)

sroush
sroush

Reputation: 6763

An invisible node put more space between u1 & v0. Adding weight values to edges caused them to become vertical. Group attributes might have done the same thing.

digraph test_family_tree {
    node [shape=box];
    edge [dir=none];

    {rank=same; a0->m0->b0;}
    a0 [label="Dedushka"];
        b0 [label="Babushka"];
    m0 [shape=point];
    {rank=same; node[shape=point];
        h1_0->h1_1->h1_2;
    }
     
    {rank=same;
        u0->m1_0->u1;
        u1->Z0->v0[style="invis"];
        v0->m1_1->v1;
        Z0[style=invis]
    }
    u0 [label="Norðri"];
    u1 [label="Suðri"];
    v0 [label="Austri"];
    v1 [label="Vestri"];
    
    m1_0 [shape=point];
    m1_1 [shape=point];
    {rank=same; node[shape=point];
        h2_0->h2_1->h2_2->h2_3->h2_4;
        h2_4->h2_5[style="invis"];
        h2_5->h2_6->h2_7->h2_8->h2_9;
    }
    {rank=same;
        z0->z1->z3->z4->z4->z5->z5->z6->z8->z9[style="invis"];
    }
    z0 [label="Grumpy"];        
    z1 [label="Dopey"];
    z3 [label="Doc"];
    z4 [label="Bashful"];
    z5 [label="Happy"];
    z6 [label="Sleepy"];
    z8 [label="Sneezy"];
    z9 [label="Sexy"];

    edge[weight=10]
    m1_0->h2_2;
    m0->h1_1;
    m1_1->h2_7;

    h1_0->u0;
    h1_2->v0;

    h2_0->z0;
    h2_1->z1;
    h2_3->z3;
    h2_4->z4;
    h2_5->z5;
    h2_6->z6;
    h2_8->z8;
    h2_9->z9;
}

Giving:
enter image description here

Upvotes: 1

Related Questions