30

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 ?

Community
  • 1
  • 1
nocbos
  • 361
  • 1
  • 4
  • 6

1 Answers1

42

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

Potherca
  • 10,796
  • 5
  • 60
  • 79
  • I am using graphviz 3.2.1 and 'ortho' isn't working for me either :(. It looks just like shortest straight lines between nodes. – David Doria Mar 16 '20 at 15:29