Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
492 views
in Technique[技术] by (71.8m points)

graphviz - How do I place nodes on the same level in DOT?

I want to render several trees simultaneously and place all root nodes and all leaf nodes on the same level.

Here's an example of what I'm trying to do. Root nodes A and X are on the same level, and so are leaf nodes B, D, and Z.

Graph I want

I unsuccessfully tried putting roots in one rank and leaves in another as follows:

digraph G { 
rankdir = TB;
subgraph {
A -> B
A -> C
C -> D
X -> Y
rank = same; A; X;
rank = same; B; D; Y;
} /* closing subgraph */
}

And got this outcome where everything is on the same rank. enter image description here

Any suggestions about what I should be trying? I've already got roots and leaves identified.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Putting the rank = same; ... statements in braces, e.g.:

digraph G { 
  rankdir = TB;
  subgraph {
    A -> B
    A -> C
    C -> D
    X -> Y
    // note that rank is used in the subgraph
    {rank = same; A; X;}
    {rank = same; B; D; Y;}
  } /* closing subgraph */
}

... gives the desired result:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...