【问题标题】:How to force two nodes to be side by side?如何强制两个节点并排?
【发布时间】:2012-10-15 10:43:15
【问题描述】:

我用dot -Tsvg做了一个图表。

这是我制作的点语言文件:

digraph genealogy {
    size = "7,7";
    node [fontsize = "10", shape = "box", style="filled", fillcolor="aquamarine"];
    p1 [ fillcolor="aquamarine", label="node" ];
    p2 [ fillcolor="aquamarine", label="node" ];
    p3 [ fillcolor="aquamarine", label="node" ];
    p4 [ fillcolor="aquamarine", label="node" ];
    p5 [ fillcolor="aquamarine", label="node" ];
    p6 [ fillcolor="aquamarine", label="node" ];
    p7 [ fillcolor="aquamarine", label="node" ];
    p8 [ fillcolor="aquamarine", label="node" ];
    p9 [ fillcolor="aquamarine", label="node" ];
    p11 [ fillcolor="aquamarine", label="node" ];
    p12 [ fillcolor="aquamarine", label="node" ];
    p13 [ fillcolor="aquamarine", label="node" ];
    p16 [ fillcolor="aquamarine", label="node" ];
    p17 [ fillcolor="aquamarine", label="node" ];
    b1 [ shape = "point", style="filled", fillcolor="white" ];
    p3 -> b1 [arrowhead = "none", color="red"];
    b2 [ shape = "point", style="filled", fillcolor="white" ];
    p2 -> b2 [arrowhead = "none", color="red"];
    p3 -> b2 [arrowhead = "none", color="red"];
    b3 [ shape = "point", style="filled", fillcolor="white" ];
    p4 -> b3 [arrowhead = "none", color="red"];
    p5 -> b3 [arrowhead = "none", color="red"];
    b4 [ shape = "point", style="filled", fillcolor="white" ];
    p6 -> b4 [arrowhead = "none", color="red"];
    p11 -> b4 [arrowhead = "none", color="red"];
    b2 -> p1 [arrowhead = "onormal", color="red"];
    b3 -> p2 [arrowhead = "onormal", color="red"];
    b3 -> p6 [arrowhead = "onormal", color="red"];
    b3 -> p7 [arrowhead = "onormal", color="red"];
    b4 -> p8 [arrowhead = "onormal", color="red"];
    b4 -> p9 [arrowhead = "onormal", color="red"];
    b1 -> p12 [arrowhead = "onormal", color="red"];
    b1 -> p13 [arrowhead = "onormal", color="red"];
    b1 -> p16 [arrowhead = "onormal", color="red"];
    p4 -> p5 [dir="none", arrowhead = "none",  color="blue"];
    p7 -> p17 [dir="none", arrowhead = "none",  color="blue"];
}

这是结果:

我想强制由蓝线连接的节点并排(水平),而不是彼此下方或另一个疯狂的位置。

这可能吗?

【问题讨论】:

    标签: nodes graph-theory graphviz dot


    【解决方案1】:

    您可以使用 rank 属性。设置 rank="same" 或 rank="source" 可能会有帮助。这会将两个节点置于相同等级或最低等级。以下是其中一种可能性:

    digraph genealogy {
        size = "7,7";
        node [fontsize = "10", shape = "box", style="filled", fillcolor="aquamarine"];
    
        subgraph _1 {
         rank="same";
         p4 [ fillcolor="aquamarine", label="node" ];
         p5 [ fillcolor="aquamarine", label="node" ];
         p4 -> p5 [dir="none", arrowhead = "none",  color="blue"];
    }
        subgraph _2 {   
        rank="source";  
        p7 [ fillcolor="aquamarine", label="node" ];
        p17 [ fillcolor="aquamarine", label="node" ];
        p7 -> p17 [dir="none", arrowhead = "none",  color="blue"];
    }
    
    p1 [ fillcolor="aquamarine", label="node" ];
    p2 [ fillcolor="aquamarine", label="node" ];
    p3 [ fillcolor="aquamarine", label="node" ];
    p6 [ fillcolor="aquamarine", label="node" ];
    p8 [ fillcolor="aquamarine", label="node" ];
    p9 [ fillcolor="aquamarine", label="node" ];
    p11 [ fillcolor="aquamarine", label="node" ];
    p12 [ fillcolor="aquamarine", label="node" ];
    p13 [ fillcolor="aquamarine", label="node" ];
    p16 [ fillcolor="aquamarine", label="node" ];
    b1 [ shape = "point", style="filled", fillcolor="white" ];
    p3 -> b1 [arrowhead = "none", color="red"];
    b2 [ shape = "point", style="filled", fillcolor="white" ];
    p2 -> b2 [arrowhead = "none", color="red"];
    p3 -> b2 [arrowhead = "none", color="red"];
    b3 [ shape = "point", style="filled", fillcolor="white" ];
    p4 -> b3 [arrowhead = "none", color="red"];
    p5 -> b3 [arrowhead = "none", color="red"];
    b4 [ shape = "point", style="filled", fillcolor="white" ];
    p6 -> b4 [arrowhead = "none", color="red"];
    p11 -> b4 [arrowhead = "none", color="red"];
    b2 -> p1 [arrowhead = "onormal", color="red"];
    b3 -> p2 [arrowhead = "onormal", color="red"];
    b3 -> p6 [arrowhead = "onormal", color="red"];
    b3 -> p7 [arrowhead = "onormal", color="red"];
    b4 -> p8 [arrowhead = "onormal", color="red"];
    b4 -> p9 [arrowhead = "onormal", color="red"];
    b1 -> p12 [arrowhead = "onormal", color="red"];
    b1 -> p13 [arrowhead = "onormal", color="red"];
    b1 -> p16 [arrowhead = "onormal", color="red"];
    
    }
    

    【讨论】:

      【解决方案2】:

      只是为了缩短另一个答案:使用rank="same" 选项将您想要并排的节点放在子图中。

      之前:

      digraph G {
      A, B
          //subgraph {
          //  rank="same"
              C, D
          //}
      A -> B -> C -> D
      }
      

      之后:

      digraph G {
      A, B
          subgraph {
              rank="same"
              C, D
          }
      A -> B -> C -> D
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-11-09
        • 1970-01-01
        • 1970-01-01
        • 2013-09-30
        • 1970-01-01
        • 2013-02-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多