13

My question is essentially the same as this one but the given answer doesn't work for me.

Here is a sample rendering (source) with

compound=true;
overlap=scalexy;
splines=true;
layout=neato;

enter image description here

There is some unnecessary overlap in the edges but this isn't too bad, the main problem is all the wasted space.

I tried setting sep=-0.7; and here's what happens.

enter image description here

The spacing is much better but now there is some overlap with the nodes. I experimented with different overlap parameters and this is the only one which gives remotely acceptable results.

I tried changing to fdp layout and setting the spring constant attribute K globally but I just got stuff like this:

enter image description here

The source is all straightforward a--b--c sort of stuff, no fancy tricks.

What I want is for all edges to be shortened as much as possible (up to a minimum) provided that this adjustment doesn't introduce any new overlaps, which is where sep fails completely. That doesn't seem like it should be too hard for a layout engine to do. Is it possible with the graphviz suite? I don't mind changing rendering software, but I don't want to annotate the source on a per-node or per-edge basis.

My ideal result would be to minimize the deviation in edge length, considered one node at a time, i.e. each node would have edges of equal length apart from the necessary exceptions, but that's wishful thinking. The priority is to reduce the length of each edge with the constraint that this cannot introduce overlap.

I will accept partial solutions but they must be fully automatic and open source.

How can I do this? Thanks.

Community
  • 1
  • 1
spraff
  • 32,570
  • 22
  • 121
  • 229

3 Answers3

6

I found https://sites.google.com/site/kuabus/programming-by-hu/graphviz-test-tool, an interactive tool for parameterizing the many options and repeatedly rendering them. I went through the full list provided by the Java application, eventually ending up with this set of attributes:

overlap=false
maxiter=99999999
damping=9999999
voro_margin=.001
start=0.1
K=1
nodesep=999999999999
labelloc=c
defaultdist=9999999
size=20,20
sep=+1
normalize=99999999
labeljust=l
outputorder=nodesfirst
concentrate=true
mindist=2
fontsize=99999999
center=true
scale=.01
inputscale=99999999
levelsgap=9999999
epsilon=0.0001

I was not able to find a parameterization of neato that made producing the desired "moderately scaled" graph possible.

Thomson Comer
  • 3,919
  • 3
  • 30
  • 32
  • the site is not found. In the [Resources | Graphviz](https://graphviz.org/resources/ "Resources | Graphviz") page it says the project is abandoned – Ooker May 20 '22 at 02:39
1

You should set

overlap = compress;

this should compress it at much as possible. Try sep = +1; first, and then play with values between 0 and +1 to find the optimal setting for you.

patapouf_ai
  • 17,605
  • 13
  • 92
  • 132
  • They're all overlapping like crazy, even when I try large values for `sep`. – spraff Jan 22 '15 at 10:01
  • What value of K are you using? – patapouf_ai Jan 22 '15 at 10:04
  • Try keeping sep=1; but diminushing the spring strength. So try K=0.3 (the default) and then gradually increase that value. – patapouf_ai Jan 22 '15 at 10:05
  • 1
    Thanks for the suggestion, I will tinker, but the programmer in me knows that shortening the sparse no-collisions image I already have **without introducing new overlap** is algorithmically possible. I'm afraid this answer doesn't look like it qualifies. – spraff Jan 22 '15 at 16:53
  • You're welcome. And yes, it is definitely possible! It shouldn't be overlapping, that is why I am suspecting that your K value is too small. – patapouf_ai Jan 23 '15 at 09:49
  • I've been trying sep and k in the region of 100-1000 and they seem to be having no effect whatsoever. – spraff Jan 25 '15 at 08:48
  • I'm using `graph Foo { compound=true; overlap=compress; sep=-0.7; splines=true; layout=neato;` and the rest is just plain nodes and edges. – spraff Jan 25 '15 at 08:48
  • k in graphviz is inversly proportional to the spring constant in physics: ẍ = - k* x so I guess that at anyhting more than 100 you basically have 0 spring force in your edges so it makes no difference. Make sure you don't put the same value for sep and k, vary them independantly. If you are putting k=1000 and positive sep and they are still overlapping like crazy I'm at a lost. Then I would keep it simple and use one of the interactive viewers to move the nodes around by hand: http://www.graphviz.org/content/resources – patapouf_ai Jan 26 '15 at 09:11
  • 2
    I am in the same boat - the majority of parameters for neato seem to have no effect at all. Only `overlap`, which, if `true` causes everything to draw on top of it, and if set to any other value causes everything to be drawn with extremely long edges between nodes. – Thomson Comer Feb 08 '17 at 00:28
1

I have a graph with 50 nodes and 68 edged (sorry cannot publish the whole picture, just a fragment). Found two reasonable presets (1 and 2):

digraph {
graph[
# 1. Less overlaps but less compact.
# This is the choice for now.
layout=neato; overlap=prism; overlap_scaling=-3.5; 

# 2. More compact but some overlaps exist (may be adjusted by `sep`).
#layout=neato; overlap=voronoi; sep=-0.15; 

# The following is common.
outputorder=nodesfirst, # Will always draw edges over nodes.
splines=curved;
]
node[fontname="Helvetica",];
node[shape=box;style="filled";penwidth="0.5";width=0;height=0;margin="0.05,0.05"];
edge[label=" ";color="#000080";penwidth="0.5";arrowhead="open";arrowsize="0.7";];
. . .
}

enter image description here

Nick Legend
  • 789
  • 1
  • 7
  • 21