Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid edge intersection in graphviz

Tags:

graphviz

Suppose we have the following simple graph:

digraph Test {

    Start[shape = doublecircle];
    Foo[shape = square];
    Bar[shape = diamond];
    Baz[shape = square];
    Xyz[shape = square];

    Start -> Foo;
    Foo:s -> Bar:n;
    Bar:w -> Baz:n;
    Bar:e -> Xyz:n;
    Baz:s -> Foo:n;

}

Which is rendered as follows:

Rendered graph

Is there a way to tell graphviz to draw edge Baz -> Foo without intersections with Foo -> Bar nor Bar -> Baz?

like image 434
user882813 Avatar asked Dec 25 '22 16:12

user882813


2 Answers

when it comes to graphviz layout, the best you can do is trying as much as possible to not interfere :)

taking out compass_pt from your file:

digraph Test {

    Start[shape = doublecircle];
    Foo[shape = square];
    Bar[shape = diamond];
    Baz[shape = square];
    Xyz[shape = square];

    Start -> Foo;
    Foo -> Bar;
    Bar -> Baz;
    Bar -> Xyz;
    Baz -> Foo;

}

and you get:

enter image description here

like image 164
Guy Gavriely Avatar answered Dec 28 '22 07:12

Guy Gavriely


Adding an invisible node should do the trick:

enter image description here

digraph Test {

    Start[shape = doublecircle];
    Foo[shape = square];
    Bar[shape = diamond];
    Baz[shape = square];
    Xyz[shape = square];

    // "invisible" node to connect baz to foo
    BazToFoo [shape=none, label="", height=0, width=0]

    Start -> Foo;
    Foo:s -> Bar:n;
    Bar:w -> Baz:n;
    Bar:e -> Xyz:n;
    Baz:s -> BazToFoo [dir=none] // remove the arrowhead
    BazToFoo -> Foo:n;

}
like image 44
Potherca Avatar answered Dec 28 '22 06:12

Potherca