Graphviz忽略排名属性,如果节点之间没有边。

3

我正在使用Graphviz来呈现一些分层结构。到目前为止,使用子图并没有达到我想要的效果。

就是我想要得到的结果。

enter image description here

(颜色代表层次结构中的不同级别,因此它们需要遵循这个顺序)。为了制作这个图片,我使用了无形链接,但在真实世界的情况下这确实不是一个选项。

然而,目前我得到的是 enter image description here

使用这个.dot文件

graph {
    // Global config
    rankdir=BT
    node [style="filled" fontcolor="white" shape="box"]
    // Rank (hierarchies)
    { rank=same; 258 }
    { rank=same; 259 }
    { rank=same; 260 }
    { rank=same; 261 262 }
    // Nodes
    // Tasks
    258 [label="John Cleese" fillcolor="#E8B04D"]
    // Project Goals
    259 [label="Michael Palin" fillcolor="#C0C56B"]
    // Identities
    260 [label="Eric Idle" fillcolor="#FF8D61"]
    // Virtues
    261 [label="Graham Chapman" fillcolor="crimson"]
    262 [label="Terry Jones" fillcolor="crimson"]
    // Edges
    259 -- 260 [style="bold" color="#3790af"]
}

Graphviz是否可以在边之前考虑排名?如果可以,我该如何操作?
1个回答

4

通过添加一些不可见的边缘,您可以轻松解决问题,这些边缘使您正确设置的各个等级按照您的要求工作。请注意,在底部附近简单添加了三个不可见的边缘:

graph {
    // Global config
    rankdir=BT
    node [style="filled" fontcolor="white" shape="box"]
    // Rank (hierarchies)
    { rank=same; 258 }
    { rank=same; 259 }
    { rank=same; 260 }
    { rank=same; 261 bl 262 }
    // Nodes
    // Tasks
    258 [label="John Cleese" fillcolor="#E8B04D"]

    // Project Goals
    259 [label="Michael Palin" fillcolor="#C0C56B"]

    // Identities
    260 [label="Eric Idle" fillcolor="#FF8D61"]

    // Virtues
    261 [label="Graham Chapman" fillcolor="crimson"]
    262 [label="Terry Jones" fillcolor="crimson"]

    // Edges
    259 -- 260 [style="bold" color="#3790af"]
258--259 [style=invis]
260--261 [style=invis]
260--262 [style=invis]
260--bl [style=invis]

bl [style=invis label="" height=0, width=0]

}

我还在中心添加了一个不可见的平衡节点bl,以帮助更好地居中图形。 enter image description here

谢谢Tom。我已经尝试过了,它确实有效。实际上,我正在寻找一种替代方法,因为像我所说的,通过编程添加这些幻影边可能非常复杂。如果没有其他选择,我就必须这样做! - Sebastialonso
@Sebastialonso 好的,谢谢,看一下我的最新编辑,如果有帮助的话可以更好地平衡图形。不幸的是,即使使用 rank-same,呈现引擎也无法区分各个子图应该在不同的排名上,除非有某种边缘。 - TomServo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接