你如何强制在点上的节点上排名?

时间:2009-07-09 14:36:01

标签: graph graphviz dot state-machine graph-layout

我有一些graphviz点格式的相对简单(自动生成)的图形。这些显示了通过状态机的路径,但是当我希望图形处于状态顺序时,dot有一个稍微混乱的习惯,即决定两个节点必须在同一个等级上。我尝试了很多设置(包括下面列出的:n:s以及weight),但我无法说服dot将第三个置于上面第四国。

我有很多图表存在这个问题:点似乎有一些内部因素决定如果两个节点处于同一级别会更好,并且没有什么可以覆盖它。我甚至有代码指定一个节点应该是rank=sink,但是dot决定将另一个节点放在它下面。

有没有办法建议点,节点的顺序比任何其他约束更重要?

用于生成图形的代码如下所示:

digraph {
    ERROR [label="Error"];
    FirstSTATE [label="Initial State" URL="\ref FirstSTATE"];
    FirstSTATE -> SecondSTATE;
    SecondSTATE [label="Second State" URL="\ref SecondSTATE"];
    SecondSTATE -> ThirdSTATE;
    ThirdSTATE [label="Third State" URL="\ref ThirdSTATE"];
    FourthSTATE [label="Fouth State?" shape="diamond"];
    ThirdSTATE:s -> FourthSTATE:n [weight=50];
    FourthSTATE -> FifthSTATE [label="Yes" ];
    FourthSTATE -> ThirdSTATE [label="No"];
    FifthSTATE [label="Fifth State" URL="\ref FifthSTATE"];
    SixthSTATE [label="Sixth State?" shape="diamond"];
    SixthSTATE -> ERROR [label="Yes" ];
    SixthSTATE -> SeventhSTATE [label="No"];
    FifthSTATE -> SixthSTATE;
    SeventhSTATE [label="Seventh State" URL="\ref SeventhSTATE"];
    SeventhSTATE -> EighthSTATE;
    EighthSTATE [label="Eighth State" URL="\ref EighthSTATE"];
    NinthSTATE [label="Ninth State?" shape="diamond"];
    NinthSTATE -> TenthSTATE [label="Yes" ];
    NinthSTATE -> EighthSTATE [label="No"];
    EighthSTATE -> NinthSTATE;
    TenthSTATE [label="Tenth State" URL="\ref TenthSTATE"];
    EleventhSTATE [label="Eleventh State?" shape="diamond"];
    EleventhSTATE -> ERROR [label="Yes" ];
    EleventhSTATE -> TwelfthSTATE [label="No" ];
    TenthSTATE -> EleventhSTATE;
    TwelfthSTATE [label="Twelfth State" URL="\ref TwelfthSTATE"];
}

图表目前看起来像这样: Dot Graph

1 个答案:

答案 0 :(得分:12)

使用“constraint = false”。

http://www.graphviz.org/doc/info/attrs.html#d:constraint

在你的图表中:

FourthSTATE -> ThirdSTATE [label="No" constraint=false] ;

你会得到:

digraph {
    ERROR [label="Error"];
    FirstSTATE [label="Initial State" URL="\ref FirstSTATE"];
    FirstSTATE -> SecondSTATE;
    SecondSTATE [label="Second State" URL="\ref SecondSTATE"];
    SecondSTATE -> ThirdSTATE;
    ThirdSTATE [label="Third State" URL="\ref ThirdSTATE"];
    FourthSTATE [label="Fouth State?" shape="diamond"];
    ThirdSTATE -> FourthSTATE;
    FourthSTATE -> FifthSTATE [label="Yes" ];
    FourthSTATE -> ThirdSTATE [label="No" constraint=false] ;
    FifthSTATE [label="Fifth State" URL="\ref FifthSTATE"];
    SixthSTATE [label="Sixth State?" shape="diamond"];
    SixthSTATE -> ERROR [label="Yes" ];
    SixthSTATE -> SeventhSTATE [label="No"];
    FifthSTATE -> SixthSTATE;
    SeventhSTATE [label="Seventh State" URL="\ref SeventhSTATE"];
    SeventhSTATE -> EighthSTATE;
    EighthSTATE [label="Eighth State" URL="\ref EighthSTATE"];
    NinthSTATE [label="Ninth State?" shape="diamond"];
    NinthSTATE -> TenthSTATE [label="Yes" ];
    NinthSTATE -> EighthSTATE [label="No"];
    EighthSTATE -> NinthSTATE;
    TenthSTATE [label="Tenth State" URL="\ref TenthSTATE"];
    EleventhSTATE [label="Eleventh State?" shape="diamond"];
    EleventhSTATE -> ERROR [label="Yes" ];
    EleventhSTATE -> TwelfthSTATE [label="No" ];
    TenthSTATE -> EleventhSTATE;
    TwelfthSTATE [label="Twelfth State" URL="\ref TwelfthSTATE"];
}