0

When describing a graph with graphviz, I sometimes find I want two vertices to appear closer together than the layout engine I chose places them. Is there a way to hint that I want them closer?

I'm mostly interested in the case of two connected vertices, so an answer specific to that case is fine.


Concrete example:

digraph G {
  node [shape="circle"];
  Start [shape="none" label=""];
  C [shape="doublecircle"];
  Start -> A;
  A -> B [label="0,1"];
  B -> C [label="0,1"];
  C -> D [label="0,1"];
  D -> D [label="0,1"];
}

enter image description here I want the vertices Start and A to be closer.

einpoklum
  • 118,144
  • 57
  • 340
  • 684

2 Answers2

1

You can't do that, but you can make nearly everything else twice as big, here is a start. (But you can't increase the size of an edge to self)

digraph G {
  rankdir=LR
  edge[minlen=2 fontsize=28 arrowsize=2 penwidth=2]
  node[fontsize=28 height=1 penwidth=2]
  graph[fontsize=28 penwidth=2]
  node [shape="circle"];
  Start [shape="none" label=""];
  C [shape="doublecircle"];
  Start -> A[minlen=1]; // not twice the size to get the requested effect
  A -> B [label="0,1"];
  B -> C [label="0,1"];
  C -> D [label="0,1"];
  D -> D [label="0,1"];
}

enter image description here

Jens
  • 2,327
  • 25
  • 34
  • Well, this is too much of a special case; and with the self-edge, it's not clear I'm better off than I was before. But thanks for the effort... – einpoklum Aug 08 '20 at 19:39
0

[this answer applies specifically to dot]

  • there is no edge-level attribute that explicitly sets or changes edge length
  • the graph-level nodesep attribute sets minimum distance between two nodes of same rank

so:

digraph G {
  nodesep=.17
  {
  rank=same
  node [shape="circle"];
  Start [shape="none" label=""];
  C [shape="doublecircle"];
  Start -> A;
  A -> B [label="0,1"];
  B -> C [label="0,1"];
  C -> D [label="0,1"];
  D -> D [label="0,1"];
  }
}

produces:
enter image description here

To increase the distance between the other nodes, you can add spaces to the labels.

I'm not wild about it either, but this change:

  B -> C [label="       0,1       "]; // pad to make label (and edge) longer

produced this:
enter image description here

sroush
  • 5,375
  • 2
  • 5
  • 11
  • You mean, the edges will be at least as long as the labels? Mmm... I dunno, I don't much like this approach. – einpoklum Aug 08 '20 at 19:27