Graphviz DOT arrange Nodes in circles, layout too "compact"
Asked Answered
F

3

21

I'm halfway there please see the edit

OK here's my problem, I'm generating a graph of a python module, including all the files with their functions/methods/classes.

I want to arrange it so, that nodes gather in circles around their parent nodes, currently everything is on one gargantuan horizontal row, which makes the thing >50k pixels wide and also let's the svg converter fail(only renders about the half of the graph).

I went through the docs but couldn't find anything that seems to do the trick.

So the question is:
Is there a simple way to do this or do I have to layout the whole thing by myself? :/

EDIT:
Thanks to Andrews comment I've got the right layout, the only problem now is that it's a bit to "compact"... so the question now is, how to fix this?

Test

Finfoot answered 16/4, 2010 at 0:0 Comment(3)
have you tried using the "neato" layout? It might give a result like what you want.Sphygmomanometer
Just tried it via the command line switch -K, kinda works see my edit.Finfoot
A little late, but when you get this overlapped layouts with neato just set "overlap=false".Discoid
C
36

i've mentioned all of the most significant parameters that influence your current layout and then suggested values for those parameters. Still, i suspect you can get the layout that you want just from applying a couple of these suggestions.

  • reduce the edge weight, eg, [weight=0.5]; this will make the edges longer, causing the tight clusters you currently see in your graph to 'fan out'.

  • get rid of the node borders, node_A [color=none; shape=plaintext]; especially for oval-shaped nodes, a substantial fraction of the total node space is 'unused' (ie, not used to display the node label).

  • explicitly set the font size for the nodes (the node borders are enlarged so that they surround the node text, which means that the font size and amount of text for a given node has a significant effect on its size); [fontsize=11] should be large enough to be legible yet also reduce the 'cluttered' appearance (the default size is 14).

  • increase minimum separation between nodes, via 'nodesep'; eg, nodesep=2.0; this will directly address your objection regarding your graph being "too compact." ('nodesep' and 'ranksep' probably affect how dot draws a graph more than any other parameters for node, edge, or graph. In your case, it looks like you have only two ranks of nodes; 'ranksep' sets the minimum distance between nodes of different ranks--it looks like all of the nodes that comprise your graph are of the same rank (except for few top level nodes in the centers).

  • explicitly set total graph size, eg, size="7.75,10.25" (ensures that your graph fits on an 8.5 x 11 page and that it occupies the entire space)

  • And one purely aesthetic suggestion that at most will only help your graph appear less cluttered: the default fontcolor for both edges and nodes is black. The majority of the ink on your graph is from those two structures (particularly if you remove the node borders), so i would for instance set either the node (text) fontcolor or the edge fontcolor to "blue" to help the eye distinguish the two sets of graph structures.

Crapulent answered 16/4, 2010 at 4:47 Comment(2)
In fact, i had a very similar issue reported here and using the ranksep was the key configuration to fan out the graph. Thanks!Mahayana
Could you lead me to documentation of this? With working code samples?Dollarfish
S
7

If it is too compact, you will want to mess with the edge length. You have a couple options depending on the graph layout:

  1. If your layout is sfdp or fdp, tweak the graph property K. Default is 0.3.
  2. For neato (or fdp), tweak the edge property len. Default is 1.0 for neato and 0.3 for fdp.
  3. For dot you can use the edge property minlen which is the minimum edge length. Default is 1.

You might also want to mess with the graph property model which determines clustering behavior. Specifically, try subset. I believe this handles len for you: http://www.graphviz.org/doc/info/attrs.html#d:model

Also, you can remove overlaps all together with scaling techniques: http://www.graphviz.org/doc/info/attrs.html#d:overlap

Sorites answered 24/5, 2010 at 17:5 Comment(0)
D
0

I have around 500 nodes and used doug's recommendation.

This is my sample code that works (in python):

f = Digraph('companies',filename='companies.gv',
          edge_attr={'weight':'1',
                     'fontsize':'11',
                     'fontcolor':'blue',
                     'len':'4'},
          graph_attr={'fixedsize':'false', 
                      'bgcolor':'transparent'},
          node_attr={'fontsize':'11', 
                     'shape':'plaintext', 
                     'color':'none',
                     'fontcolor':'black'})

f.attr(layout="neato")
f.attr(nodesep='3')
f.attr(ranksep='3')
f.attr(size='5000,5000')
Disprize answered 20/7, 2018 at 2:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.