31

In a directed graph, if there is a cycle, the graphviz makes that edge really short.

Is there a parameter that would let me change the length of the cyclic edge, so that the graph looks a bit uniform.

digraph ER {
  rankdir="LR";
  //orientation=landscape;
    node [shape=ellipse, fontsize=30];
  {node [label="Original"] old;}
  {node [label="Final"] new;}
  {node [label="Intermediate"] ir;}

old -> ir [label="suggest", fontsize=30];
ir -> ir [label="validate", fontsize=30, len=f];
ir -> new [label = "finalize", fontsize=30];
}

enter image description here

nbro
  • 15,395
  • 32
  • 113
  • 196
A. K.
  • 34,395
  • 15
  • 52
  • 89

7 Answers7

19

Edit: Sorry, my answer will make edges longer, but not the self referencing edges you need.

len doesn't work in dot, but minlen does.

https://www.graphviz.org/doc/info/attrs.html#d:minlen

x->y
[minlen=5]
compound eye
  • 1,898
  • 18
  • 23
8

len doesn't works in dot, but you can try this trick:

digraph G {
rankdir=LR
a->b[dir=both]
b->c[dir=both,label="        "]// Just use the space to increase the edge length
}

If rankdir=TB, use label="\n" (repeat the \n as necessary) to increase the length.

Fuhrmanator
  • 11,459
  • 6
  • 62
  • 111
wener
  • 7,191
  • 6
  • 54
  • 78
5

I found that the following attribute nodesep worked to solve this problem with sfdp.

From nodesep | Graphviz:

For layouts other than dot

nodesep affects the spacing between loops on a single node, or multiedges between a pair of nodes.

Note that this is a graph attribute, so the value is the same for all edges in the graph.

Wolf
  • 9,679
  • 7
  • 62
  • 108
slydon
  • 74
  • 1
  • 1
3

From dot(1):

len=f sets the optimal length of an edge.  The default is 1.0.
Igor Chubin
  • 61,765
  • 13
  • 122
  • 144
  • 8
    for `dot` must work `minlen`, but in this case it does not work anyway :( – Igor Chubin Jul 02 '12 at 10:23
  • 1
    From the very same manpage, the line above it reads: *(neato and fdp-specific attributes)*. Since `fdp` and `neato` are specifically meant for *undirected* graphs rather than directed graphs, `len` doesn't apply here. – Martijn Pieters Dec 06 '19 at 17:27
3

You can make the cyclic edge longer by adding a bunch of invisible cyclic edges before your visible one, like this:

digraph ER {
  rankdir="LR";
  //orientation=landscape;
    node [shape=ellipse, fontsize=30];
  {node [label="Original"] old;}
  {node [label="Final"] new;}
  {node [label="Intermediate"] ir;}

old -> ir [label="suggest", fontsize=30];
ir -> ir [style="invis"]
ir -> ir [style="invis"]
ir -> ir [style="invis"]
ir -> ir [style="invis"]
ir -> ir [label="validate", fontsize=30, len=f];
ir -> new [label = "finalize", fontsize=30];
}

OP's corrected graph

albert
  • 8,285
  • 3
  • 19
  • 32
Paul Breen
  • 85
  • 5
2

In .dot language, the edge connects two notes with different ranks. The length of edge is equal to (difference in ranks)*ranksep

default ranksep (in graph attribute) is 0.75 inch, so edge of adjacent nodes will be 0.75 inch.

To reduce the edge length, you set ranksep into a smaller value in graph atrribute

2

There's another approach that I now use for this:

I use graphviz to output the file in dot format

dot -T dot -Kneato -o ./positioned.dot ./input.dot

This file will contain the Bezier curve definitions for every edge. I manually change the points to curve the way I want it to draw.

This may look a little daunting at first but once you figure out, how they work this isn't hard, I'm inching towards a script that will do this for me automatically

then re-run dot with your edited positioned file as the input

dot -T png -Kneato -O ./positioned.dot

With this approach I've pretty much turned dot into my text based visio replacement

compound eye
  • 1,898
  • 18
  • 23