【问题标题】:children order in graphviz tree在graphviz树中的儿童顺序
【发布时间】:2020-10-09 17:38:12
【问题描述】:

我有以下树:

digraph G {
    subgraph cluster0{
        37[label="+"];
        42[label="a"];
        44[label="b"];
        47[label="*"];
        46[label="c"];
        49[label="d"];
        51[label="e"];
        53[label="f"];
        55[label="g"];
        57[label="h"];
        61[label="*"];
        60[label="i"];
        63[label="j"];
        37 -> 42[label="c"];
        37 -> 44[label="c"];
        37 -> 47[label="c"];
        37 -> 61[label="c"];
        42 -> 37[label="p"];
        44 -> 37[label="p"];
        47 -> 37[label="p"];
        47 -> 46[label="c"];
        47 -> 49[label="c"];
        47 -> 51[label="c"];
        47 -> 53[label="c"];
        47 -> 55[label="c"];
        47 -> 57[label="c"];
        46 -> 47[label="p"];
        49 -> 47[label="p"];
        51 -> 47[label="p"];
        53 -> 47[label="p"];
        55 -> 47[label="p"];
        57 -> 47[label="p"];
        61 -> 37[label="p"];
        61 -> 60[label="c"];
        61 -> 63[label="c"];
        60 -> 61[label="p"];
        63 -> 61[label="p"];
    }
}

输出在这里:http://i.imgur.com/q1qXkCT.png

第一个* 子树中的孩子的顺序是:G H C D E F,但它应该是C D E F G H。 我注意到如果我删除subgraph cluster0{ 顺序是正确的,但我不能这样做。 您能提出其他解决方案吗?

【问题讨论】:

    标签: graphviz dot


    【解决方案1】:

    Graphviz 尝试在没有其他约束时保留节点的词法顺序。但是,边缘标签会影响放置,因为它们会占用空间并会推动节点。

    如果您有必要的特定订单,请尝试类似

    { rank = same; 
    46 -> 49 -> 51 -> 53 -> 55 -> 57 [style = invis];
    }
    

    在图中引入额外的排序约束。

    但您需要小心这一点,因为它会以难以预测的方式扭曲更复杂的图表。

    集群进一步使大型图中的问题复杂化,因为它们隐含地试图使子图更紧凑并引入非集群成员无法跨越的边界框。

    【讨论】:

    • 我不知道这是否是解决这个问题的预期方法,但它对我的中等复杂图表很有帮助。由于我认为 graphviz 对此没有“真正”的解决方案,因此我对您的解决方法感到满意...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-10
    相关资源
    最近更新 更多