user3433534
user3433534

Reputation: 23

Graphviz how to separate nodes equally (possibly with nodesep)?

I am making a graph using dot that splits into 4 parallel rows with links between them (see code below). I have organised the starting nodes into a subgraph using rank=same to ensure they start in line vertically, and then used edge[weight] to ensure each row is a straight horizontal line.

Due to the links between the rows, the initial nodes are unequally spaced vertically. Is there a way of setting them to be equal distance (i.e. increasing the distance between rows C,D,E to match the distance between B,C)? I have tried using nodesep in the subgraph but there is no effect. Any ideas? Thanks

graph Example {

rankdir=LR
ordering=out

{ rank=same
b1
c1
d1
e1
}

a1--b1
a1--c1
a1--a2--d1
a2--e1

edge[weight=100]

b1--b2--b3--b4
c1--c2--c3--c4
d1--d2--d3--d4
e1--e2--e3--e4

edge[weight=1]
b1--bc--c3

}

Upvotes: 2

Views: 2390

Answers (2)

marapet
marapet

Reputation: 56566

This may be a case for invisible nodes (and edges...).

Just add some invisible nodes between the rank=same subgraph to force exactly one node between the lines:

graph Example {

rankdir=LR
ordering=out

{ rank=same
    b1 [group=b]
    c1 [group=c]
    d1 [group=d]
    e1 [group=e]
    // invisible nodes
    node[style=invis]
    edge[style=invis]
    b1--i1--c1--i2--d1--i3--e1
}
node [group=b]
b1--b2--b3--b4
node [group=c]
c1--c2--c3--c4
node [group=d]
d1--d2--d3--d4
node [group=e]
e1--e2--e3--e4

node[group=""]
a1--b1
a1--c1
a1--a2--d1
a2--e1

b1--bc--c3

}

I also used groups to suggest straight lines instead of weight.

Upvotes: 0

geert3
geert3

Reputation: 7341

What you are (I think) trying to achieve is the default behavior of graphviz/dot. I think if you remove all "steering" in your graph, you'll get exactly what you need. At least in the below graph, nodes are vertically evenly distributed on each "rank".

graph Example {

rankdir=LR
ordering=out

a1--b1
a1--c1
a1--a2--d1
a2--e1
b1--b2--b3--b4
c1--c2--c3--c4
d1--d2--d3--d4
e1--e2--e3--e4
b1--bc--c3
}

Upvotes: 0

Related Questions