Node layering in Graphviz

3.3k views Asked by At

I'm creating a graph using Graphviz (compiled with neato). This graph contains many overlapping nodes which is perfectly fine. However, there is a group of large nodes which I prefer to always be on top of other small nodes - even-though I prefer to define the large nodes first in the graph (which makes them get painted at the very bottom).

Any way I can force this?

Edit:
Here's a small example, just to clarify what I mean:

graph G {
    node [style=filled,fillcolor=black];
    BigNode [fillcolor=skyblue,shape=Msquare];

    node [style=filled,fillcolor=red,shape=circle];
    edge [style=invis]
    1 -- BigNode[len=0.5];
    2 -- BigNode[len=1];
}

I'd like for BigNode to be painted over node 1.

2

There are 2 answers

0
Dana On BEST ANSWER

I did find one (sort of) solution...
I found that if you postpone only the node definition to the end, even if you defined edges for this node earlier, it will be painted top-most.
I realize this contradicts what I defined earlier, but this was the only possible solution in this case and it was the one I eventually had to use.

In my short example, you would do this:

graph G {
    node[style=filled,fillcolor=black];
    // Definition of BigNode moved to the end of the file
    /*BigNode [fillcolor=skyblue,shape=Msquare];*/ 

    node[style=filled,fillcolor=red,shape=circle];
    edge[style=invis]
    1 -- BigNode[len=0.5];
    2 -- BigNode[len=1];

    // Defined after already defining edges for BigNode
    BigNode [fillcolor=skyblue,shape=Msquare];
}

In the resulting graph, BigNode is painted over node 1

1
singingwolfboy On

I don't think it's possible. The official neato guide talks about node layering on pages 6 through 9. It looks like the most you can do is adjust the length of edges and pin down nodes: you can't actually control how nodes layer over each other.