Forcing orthogonal (vertical or horizontal) edges with dot
Asked Answered
A

1

35

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 ?

Anora answered 3/3, 2013 at 22:42 Comment(0)
P
46

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

Puckery answered 17/4, 2013 at 12:35 Comment(1)
I am using graphviz 3.2.1 and 'ortho' isn't working for me either :(. It looks just like shortest straight lines between nodes.Cowey

© 2022 - 2024 — McMap. All rights reserved.