Reputation: 1
This code place nodes in correct places.
digraph g {
edge [dir=none];
node [shape=box,fillcolor="palegreen",style="filled"];
a -> b;
a -> c
b -> c
b -> d
b -> e
d -> e
c -> f
e -> f
a [label="A",pos="150,155!"];
b [label="B",fillcolor="red",pos="75,75!"];
c [label="C",pos="230,75!"];
d [label="D",pos="0,0!"];
e [label="E",pos="150,0!"];
f [label="F",pos="300,0!"];
}
How can I place nodes like this without specifying pos in nodes?
Upvotes: 0
Views: 854
Reputation: 3654
Try
digraph g {
edge [dir=none];
node [shape=box,fillcolor="palegreen",style="filled"];
a -> b;
a -> c
b -> c
b -> d
b -> e
d -> e
c -> f [constraint = false]; // Use to relax weight of edge
e -> f
{ rank = same; b; c; } // Force specific nodes onto same height
{ rank = same; d; e; f; }
a [label="A"];
b [label="B",fillcolor="red"];
c [label="C"];
d [label="D"];
e [label="E"];
f [label="F"];
}
The edge attribute constraint = false
is used to prevent the edge for affecting the position of the edges. If the exact horizontal positioning is not critical, take this one out to avoid later problems.
The rank = same
attribute is used to force nodes to the same level in the graph and will override the natural hierarchy driven by the edges. You can also use the constraint attribute to have some of the edges be discounted when determining height.
The choice depends on your source data structure, and whether you expect to be able to generate the graphs without any editing.
Upvotes: 1