2013-04-02 75 views
2

我知道有一些相关的问题,但我想知道是否有更好的解决方案,迫使graphviz保持节点的位置按照定义的顺序。GraphViz保留节点位置点

这是我的问题: 我有两个子图与每5个节点。每个节点都连接到另一个图的每个节点。我希望节点从1-1到1-5顺序保持。但graphviz总是把它们混合起来。

这里是曲线图,我使用DOT:

digraph G { 
rankdir=LR; 
ranksep=4.0; 
subgraph cluster_1 { 
rank=same; 
label="Nr:1"; 
"1-1" [width=1, shape=circle, style=filled, fillcolor="#E3A869", label="1-1"]; 
"1-2" [width=1, shape=circle, style=filled, fillcolor="#E3A869", label="1-2"]; 
"1-3" [width=1, shape=circle, style=filled, fillcolor="#E3A869", label="1-3"]; 
"1-4" [width=1, shape=circle, style=filled, fillcolor="#E3A869", label="1-4"]; 
"1-5" [width=1, shape=circle, style=filled, fillcolor="#E3A869", label="1-5"]; 
} 

subgraph cluster_2 { 
rank=same; 
label="Nr:2"; 
"2-1" [width=1, shape=circle, style=filled, fillcolor="#E3A869", label="2-1"]; 
"1-1" -> "2-1" [color=blue, labelfontcolor="#009933", fontsize="10.0", penwidth=1]; 
"1-2" -> "2-1" [color=blue, labelfontcolor="#009933", fontsize="10.0", penwidth=1]; 
"1-3" -> "2-1" [color=blue, labelfontcolor="#009933", fontsize="10.0", penwidth=1]; 
"1-4" -> "2-1" [color=blue, labelfontcolor="#009933", fontsize="10.0", penwidth=1]; 
"1-5" -> "2-1" [color=blue, labelfontcolor="#009933", fontsize="10.0", penwidth=1]; 
"2-2" [width=1, shape=circle, style=filled, fillcolor="#E3A869", label="2-2"]; 
"1-1" -> "2-2" [color=blue, labelfontcolor="#009933", fontsize="10.0", penwidth=1]; 
"1-2" -> "2-2" [color=blue, labelfontcolor="#009933", fontsize="10.0", penwidth=1]; 
"1-3" -> "2-2" [color=blue, labelfontcolor="#009933", fontsize="10.0", penwidth=1]; 
"1-4" -> "2-2" [color=blue, labelfontcolor="#009933", fontsize="10.0", penwidth=1]; 
"1-5" -> "2-2" [color=blue, labelfontcolor="#009933", fontsize="10.0", penwidth=1]; 
"2-3" [width=1, shape=circle, style=filled, fillcolor="#E3A869", label="2-3"]; 
"1-1" -> "2-3" [color=blue, labelfontcolor="#009933", fontsize="10.0", penwidth=1]; 
"1-2" -> "2-3" [color=blue, labelfontcolor="#009933", fontsize="10.0", penwidth=1]; 
"1-3" -> "2-3" [color=blue, labelfontcolor="#009933", fontsize="10.0", penwidth=1]; 
"1-4" -> "2-3" [color=blue, labelfontcolor="#009933", fontsize="10.0", penwidth=1]; 
"1-5" -> "2-3" [color=blue, labelfontcolor="#009933", fontsize="10.0", penwidth=1]; 
"2-4" [width=1, shape=circle, style=filled, fillcolor="#E3A869", label="2-4"]; 
"1-1" -> "2-4" [color=blue, labelfontcolor="#009933", fontsize="10.0", penwidth=1]; 
"1-2" -> "2-4" [color=blue, labelfontcolor="#009933", fontsize="10.0", penwidth=1]; 
"1-3" -> "2-4" [color=blue, labelfontcolor="#009933", fontsize="10.0", penwidth=1]; 
"1-4" -> "2-4" [color=blue, labelfontcolor="#009933", fontsize="10.0", penwidth=1]; 
"1-5" -> "2-4" [color=blue, labelfontcolor="#009933", fontsize="10.0", penwidth=1]; 
"2-5" [width=1, shape=circle, style=filled, fillcolor="#E3A869", label="2-5"]; 
"1-1" -> "2-5" [color=blue, labelfontcolor="#009933", fontsize="10.0", penwidth=1]; 
"1-2" -> "2-5" [color=blue, labelfontcolor="#009933", fontsize="10.0", penwidth=1]; 
"1-3" -> "2-5" [color=blue, labelfontcolor="#009933", fontsize="10.0", penwidth=1]; 
"1-4" -> "2-5" [color=blue, labelfontcolor="#009933", fontsize="10.0", penwidth=1]; 
"1-5" -> "2-5" [color=blue, labelfontcolor="#009933", fontsize="10.0", penwidth=1]; 
} 

Nodes in wrong order

回答

7

使用一些不可见边到一个子图内订购节点,避免LR秩方向及其怪癖,使用直边splines=false),其不影响可见蓝节点连接的节点排名(constraint=false),应用默认样式,以尽量减少重复和重新排序图形标记让我以下:

digraph G { 
    nodesep=4.0; 
    splines=false; 

    node[width=1, shape=circle, style=filled, fillcolor="#E3A869"]; 
    edge[style=invis]; 

    subgraph cluster_1 { 
     label="Nr:1"; 
     "1-1" -> "1-2" -> "1-3" -> "1-4" -> "1-5"; 
    } 

    subgraph cluster_2 { 
     label="Nr:2"; 
     "2-1" -> "2-2" -> "2-3" -> "2-4" -> "2-5"; 
    } 

    edge[style=solid, color=blue, penwidth=1, constraint=false]; 

    "1-1" -> "2-1"; 
    "1-2" -> "2-1"; 
    "1-3" -> "2-1"; 
    "1-4" -> "2-1"; 
    "1-5" -> "2-1"; 

    "1-1" -> "2-2"; 
    "1-2" -> "2-2"; 
    "1-3" -> "2-2"; 
    "1-4" -> "2-2"; 
    "1-5" -> "2-2"; 

    "1-1" -> "2-3"; 
    "1-2" -> "2-3"; 
    "1-3" -> "2-3"; 
    "1-4" -> "2-3"; 
    "1-5" -> "2-3"; 

    "1-1" -> "2-4"; 
    "1-2" -> "2-4"; 
    "1-3" -> "2-4"; 
    "1-4" -> "2-4"; 
    "1-5" -> "2-4"; 

    "1-1" -> "2-5"; 
    "1-2" -> "2-5"; 
    "1-3" -> "2-5"; 
    "1-4" -> "2-5"; 
    "1-5" -> "2-5"; 
} 

graphivz output with subgraph nodes ordered using invisible edges

+0

THX marapet 1!特别是隐藏eges与splines = false相结合的提示使其发挥作用! – PlagTag

+0

节点排序的不可见边缘...聪明! –