How to set a graph-filling-area?

2019-08-19 08:34发布

问题:

How to set the graph to try to fill the area allocated to it? With an increase in the number of nodes, it simply decreases in size, but also remains in one line, although the vertical size (40) allows placement down. If you remove the rankdir, then it places vertically, but also in one line.

digraph "test_graph"{
  rankdir = LR;
  bgcolor = whitesmoke;
  graph [size = "15, 40"];
  node [shape = circle,
        style = filled,
        margin = 0,
        fontsize = 14,
        color = sandybrown];
  edge [fontsize = 10,
        arrowhead = vee];
  1->2 [label = "R"];
  2->3 [label = "R"];
  3->4 [label = "R"];
  3->5 [label = "B"];
  4->1 [label = "R"];
  5->6 [label = "U"];
  6->7 [label = "U"];
  7->8 [label = "U"];
  7->9 [label = "F"];
  8->5 [label = "U"];
  9->10 [label = "F"];
  10->11 [label = "D"];
  11->12 [label = "D"];
  12->13 [label = "D"];
  13->10 [label = "D"];
  13->14 [label = "L"];
  14->15 [label = "L"];
  15->16 [label = "D"];
  16->17 [label = "D"];
  17->18 [label = "D"];
  17->19 [label = "L"];
  18->15 [label = "D"];
  19->20 [label = "F"];
  20->21 [label = "F"];
  21->22 [label = "F"];
  21->23 [label = "L"];
  22->19 [label = "F"];
  23->24 [label = "L"];
  24->25 [label = "F"];
}

回答1:

You will need to select suitable nodes that

  • are connected by one edge
  • connect to other nodes in a way that fills the available width as you like it

and then

  • connect them in the desired order by invisible edges (so that you avoid graphviz reordering them)
  • ranking them on the same lavel so that they appear one below the other

In concrete terms this means that adding

1 -> 10 -> 19[ style = invis ];
{ rank = same; 1 10 19 }

just before the closing curly brace, as the last two lines, will produce

which is, as far as I understand your requirement, what you want.



标签: graphviz dot