【问题标题】:Graphviz dot align nodes verticallyGraphviz 点垂直对齐节点
【发布时间】:2018-05-16 20:34:01
【问题描述】:

我有以下 graphviz 点输入文件:

digraph structs {
rankdir = LR;
node [shape=record];
hashTable [label="<f0>0|<f1>1|<f2>2|<f3>3|<f4>4|<f5>5|<f6>6|<f7>7|<f8>8"];
node_1_0 [label="<f0> one|<f1> two |<f2> three"];
node_1_1 [label="<f0> un |<f1> deux|<f2> trois"];
struct3 [label="<f0> einz|<f1> swei|<f2> drei"];
hashTable:f1 -> node_1_0:f0;
node_1_0:f2  -> node_1_1:f0;
hashTable:f4 -> struct3:f0;
}

渲染如下:

如何让 [one|two|three] 节点与 [un|deux|trois] 节点垂直对齐?谢谢!

【问题讨论】:

    标签: graphviz dot


    【解决方案1】:

    编辑在评论澄清后:这里有一个不可见的边缘,具有很强的权重有助于保持节点对齐:

    digraph structs2 
    {
        rankdir = LR;
        node [shape=record];
        splines=false;       // optional; gives straight lines
    
        hashTable [label="<f0>0|<f1>1|<f2>2|<f3>3|<f4>4|<f5>5|<f6>6|<f7>7|<f8>8"];
        node_1_0 [label="<f0> one|<f1> two |<f2> three" ];
        node_1_1 [label="<f0> un |<f1> deux|<f2> trois"];
        struct3 [label="<f0> einz|<f1> swei|<f2> drei"];
    
        //
        node_1_0 -> node_1_1[ style = invis, weight= 10 ];
        //                    ^^^^^^^^^^^^^^^^^^^^^^^^^
    
        hashTable:f1 -> node_1_0:f0;
        node_1_0:f2  -> node_1_1:f0;
        hashTable:f4 -> struct3:f0;
    }
    

    给你(我相信)你想要的:

    .......

    原来的答案是:

    从表面上回答您的问题,这可以通过将它们归为同一等级来快速实现:

    digraph structs 
    {
        rankdir = LR;
        node [shape=record];
    
        hashTable [label="<f0>0|<f1>1|<f2>2|<f3>3|<f4>4|<f5>5|<f6>6|<f7>7|<f8>8"];
        node_1_0 [label="<f0> one|<f1> two |<f2> three"];
        node_1_1 [label="<f0> un |<f1> deux|<f2> trois"];
        struct3 [label="<f0> einz|<f1> swei|<f2> drei"];
    
        {rank = same; node_1_0 node_1_1 }
    
        hashTable:f1 -> node_1_0:f0;
        node_1_0:f2  -> node_1_1:f0;
        hashTable:f4 -> struct3:f0;
    }
    

    屈服

    【讨论】:

    • 为什么rankdir = LR;rank = same;结合可以产生垂直对齐,而不是水平对齐?
    • rankdir = LR 水平表示依赖顺序,因此在层次上,右低于左。 rank = same 表示层次相同的级别,然后必然是垂直对齐的。
    猜你喜欢
    • 2014-08-02
    • 2015-01-21
    • 1970-01-01
    • 1970-01-01
    • 2021-01-27
    • 2013-05-13
    • 2019-01-27
    • 2021-11-30
    • 2021-08-22
    相关资源
    最近更新 更多