children order in graphviz tree

北城余情 提交于 2019-12-10 18:49:04

问题


I have following tree:

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"];
    }
}

Output is here: http://i.imgur.com/q1qXkCT.png

Order of children in first * subtree is: G H C D E F, but it should be C D E F G H. I have noticed that if I delete subgraph cluster0{ the order is right, but I can't do it this way. Can you suggest any other solution?


回答1:


Graphviz attempts to retain the lexical ordering of nodes when there is no other constraint. However, the edge labels can affect placement as they take up space and can push nodes around.

If you have a specific order that is essential, then try something like

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

to introduce the additional ordering constraint into the graph.

You need to be careful with this though, as it can distort more complex graphs in ways that are very difficult to predict.



来源:https://stackoverflow.com/questions/16637305/children-order-in-graphviz-tree

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!