gaofeng
gaofeng

Reputation: 403

Graphviz node ordering

I want to have a diagram which has the layout as follwing :

enter image description here

But when i wrote the codes like this:

digraph g {
a->b->c;
{rank=same;b,d,e,f,g,h}
d->g [weight = 1];
d->f [weight = 10];
}

And comes like this:

enter image description here

The dot guide even recommends this:

    Edge weights also play a role when nodes are constrained to the same rank. 
    Edges with non-zero weight between these nodes are aimed across the rank 
in the samedirection (left-to-right, or top-to-bottom in a rotated drawing) as far
 as possible. This fact may be exploited to adjust node ordering by placing
 invisible edges (style="invis") where needed.

I wander why it not work?

Upvotes: 1

Views: 2447

Answers (2)

kirogasa
kirogasa

Reputation: 949

digraph g {
    a->b->c;
    {rank=same;b,d,e,f,g,h}
    d->g [weight = 0];
    d->f [weight = 1];
}

Works as you wish.

But, I also don't know why

d->g [weight = 1];
d->f [weight = 2];

doesn't work.


Maybe it depends on layout type, neato or dot or etc. See https://graphviz.gitlab.io/docs/attrs/weight/


Also

digraph {
    a -> b -> c;
    d->g
    d->f 
    {rank = same; b;d;e;f;g;h;}
}

Works. Source

Upvotes: 0

Mat
Mat

Reputation: 481

add the following line in your graph:

f->g[style=invis];

Upvotes: 2

Related Questions