【问题标题】:Issue with graphviz never completinggraphviz 永远无法完成的问题
【发布时间】:2013-04-03 23:53:55
【问题描述】:

谁能帮我弄清楚为什么下面的图表从不生成点?我认为这个问题与headport和tailport有关。如果我把它们拿出来就可以了,但理想情况下,出于文体原因,我希望它们留下来。

digraph G {
    nodesep = 0.5;
    0 [width=0.75, height=0.75, fontsize=20];
    1 [width=0.75, height=0.75, fontsize=20, shape=square];
    2 [width=0.75, height=0.75, fontsize=20];
    3 [width=0.75, height=0.75, fontsize=20];
    4 [width=0.75, height=0.75, fontsize=20];
    5 [width=0.75, height=0.75, fontsize=20, shape=square];
    6 [width=0.75, height=0.75, fontsize=20];
    7 [width=0.75, height=0.75, fontsize=20, shape=square];
    8 [width=0.75, height=0.75, fontsize=20, shape=square];
    9 [width=0.75, height=0.75, fontsize=20, shape=square];
    10 [width=0.75, height=0.75, fontsize=20, shape=square];
    11 [width=0.75, height=0.75, fontsize=20, shape=square];
    12 [width=0.75, height=0.75, fontsize=20];
    subgraph directed{
            rankdir= LR;rank= max;
            0->1->2->3->4->5->6->7->8->9->10->11->12;
    }
    subgraph undirected{
            rankdir= LR;rank= min;edge[tailport=n,headport=n];
            0->1[dir=none, color=red];
            0->2[dir=none, color=red];
            1->9[dir=none, color=red];
            2->3[dir=none, color=red];
            2->8[dir=none, color=red];
            3->4[dir=none, color=red];
            4->8[dir=none, color=red];
            7->9[dir=none, color=red];
            8->9[dir=none, color=red];
            9->10[dir=none, color=red];
            9->11[dir=none, color=red];
            10->11[dir=none, color=red];
    }
}

【问题讨论】:

    标签: graphviz dot edges graph-drawing


    【解决方案1】:

    很难知道你在追求什么。但是,该图存在一些问题:

    • 节点不能是多个子图的一部分 - 它们要么在图中,要么在子图中,无论它们首先出现在哪里。你的应该出现在哪里?
    • rankdirgraph 属性,不能应用于 subgraph

    编辑

    根据您的评论,这是一个没有任何子图的版本。但是,您不会喜欢边缘的布线,这是难以控制的。

    想法是将节点对齐在一条直线上,然后将其他边添加到constraint=false,以免它们影响节点的排名。

    digraph G {
        nodesep = 0.5;
        node[width=0.75, height=0.75, fontsize=20];
        rankdir=LR;
    
        0;
        1 [shape=square];
        2;
        3;
        4;
        5 [shape=square];
        6;
        7 [shape=square];
        8 [shape=square];
        9 [shape=square];
        10 [shape=square];
        11 [shape=square];
        12;
    
        0->1->2->3->4->5->6->7->8->9->10->11->12;
    
        edge[constraint=false, tailport=n,headport=n,dir=none, color=red];
        0->1;
        0->2;
        1->9;
        2->3;
        2->8;
        3->4;
        4->8;
        7->9;
        8->9;
        9->10;
        9->11;
        10->11;
    }
    

    【讨论】:

    • 基本上我有需要通过有向图和无向图连接的节点。我希望节点(编号 0-12)出现在一条直线上,有向边如下所示:0->1->2->3->4->5->6->7->8- >9->10->11->12;我希望无向边连接到节点之间的北头端口和尾端口。
    • @Karrde 我更新了我的答案。您应该将评论中的信息添加到您的问题中,这有助于了解您的目标。
    【解决方案2】:

    如果不花大量时间挖掘源代码,很难说出原因,但您可以将麻烦的元素移出第二个子图来解决问题:

    从无向子图中去掉 1->9 和 2->8,并添加到它下面:

    digraph G {
        nodesep = 0.5;
        0 [width=0.75, height=0.75, fontsize=20];
        1 [width=0.75, height=0.75, fontsize=20, shape=square];
        2 [width=0.75, height=0.75, fontsize=20];
        3 [width=0.75, height=0.75, fontsize=20];
        4 [width=0.75, height=0.75, fontsize=20];
        5 [width=0.75, height=0.75, fontsize=20, shape=square];
        6 [width=0.75, height=0.75, fontsize=20];
        7 [width=0.75, height=0.75, fontsize=20, shape=square];
        8 [width=0.75, height=0.75, fontsize=20, shape=square];
        9 [width=0.75, height=0.75, fontsize=20, shape=square];
        10 [width=0.75, height=0.75, fontsize=20, shape=square];
        11 [width=0.75, height=0.75, fontsize=20, shape=square];
        12 [width=0.75, height=0.75, fontsize=20];
        subgraph directed{
                rankdir= LR;rank= max;
                0->1->2->3->4->5->6->7->8->9->10->11->12;
        }
        subgraph undirected{
                rankdir= LR;rank= min;edge[tailport=n,headport=n];
                0->1[dir=none, color=red];
                0->2[dir=none, color=red];
                2->3[dir=none, color=red];
                3->4[dir=none, color=red];
                4->8[dir=none, color=red];
                7->9[dir=none, color=red];
                8->9[dir=none, color=red];
                9->10[dir=none, color=red];
                9->11[dir=none, color=red];
                10->11[dir=none, color=red];
        }
        1->9[dir="none", color="red", headport="n"];
        2->8[dir="none", color="red", headport="n"];
    }
    

    【讨论】:

      猜你喜欢
      • 2015-12-14
      • 1970-01-01
      • 2012-10-21
      • 1970-01-01
      • 2017-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多