Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forcing orthogonal (vertical or horizontal) edges with dot

I would like to force dot displaying only vertical or horizontal edges between nodes.

I have found a similar request with the post Family tree layout with Dot/GraphViz, but I am not dealing with trees, so I hope there is a solution without inserting extra nodes...

If I build the following graph:

digraph G {

    splines=ortho

    A [ shape=box ]
    B [ shape=box ]
    C [ shape=box ]
    D [ shape=box ]

    A -> B
    A -> C

    B -> D
    C -> D

}

What I get is this:

enter image description here

But I would like a graph like this one:

enter image description here

How can I get such a rendering ?

Edit : the "splines" attribute seems not working as expected... Is there something I did wrong ?

like image 399
nocbos Avatar asked Mar 03 '13 22:03

nocbos


1 Answers

Your syntax seems correct. When I run it I get orthogonal edge routing (of sorts):

enter image description here

Which version do you have?

I ask because orthogonal edge routing is only available in Graphviz versions from September 28, 2010 and newer. Not all systems have more recent versions packed. On my system I had to download and manually install Graphviz to get a version newer than 2.26.3 (which is from January 26, 2010).

Assuming your actual graph contains more than 4 nodes, if you want the lines to have a bend and you don't want to add extra (invisible) nodes, you should try playing around with the graphs nodesep attribute. See code and image below.

digraph G {

    graph [splines=ortho, nodesep=1]
    node [shape=record]

    A -> {B, C} -> D
}

enter image description here

like image 152
Potherca Avatar answered Oct 09 '22 01:10

Potherca