Graphviz ---边缘标签太靠近另一边

时间:2012-10-17 12:52:40

标签: graphviz

我有以下代码,结果如下图所示。正如您所看到的,它在边缘和边缘标签周围有点拥挤,特别是在“^ a”周围。创造更多空间的最佳方法是什么,以便人们可以清楚地看到哪个标签属于哪个边缘?

digraph finite_state_machine {                                                                                                                                                                                  
    pad=0.2;
    {
        rank=same;
        node [shape = point, style = invis]; q_0;
        node [shape = doublecircle, style = solid]; q_5;
        node [shape = circle];
        q_1 [ label = <<i>q<sub>1</sub></i>> ];
        q_2 [ label = <<i>q<sub>2</sub></i>> ];
        q_3 [ label = <<i>q<sub>3</sub></i>> ];
        q_4 [ label = <<i>q<sub>4</sub></i>> ];
        q_5 [ label = <<i>q<sub>5</sub></i>> ];
        q_0 -> q_1;
        q_1 -> q_2 [ label = "." ];
        q_1 -> q_2 [ label = <&epsilon;>, constraint=false ];
        q_2 -> q_1 [ label = <&epsilon;>, constraint=false ];
        q_2 -> q_3 [ label = <<i>a</i>> ];
        q_3 -> q_4 [ label = <<i>^a</i>> ];
        q_3 -> q_4 [ label = <&epsilon;>, constraint=false ];
        q_4 -> q_3 [ label = <&epsilon;>, constraint=false ];
        q_4 -> q_5 [ label = <<i>b</i>> ];
    }
}

enter image description here

3 个答案:

答案 0 :(得分:10)

Graphviz中没有attribute来调整边缘标签周围的边距/填充。最接近您可能达到的效果是使用\n在标签上方/下方引入空行以强制空间。

显然,这不会扩展到任何自动的。

或者,您可以尝试使用ranksep属性强制增加一些空间。

答案 1 :(得分:6)

如果xlabel无法解决问题,那么将标签包装在表格中有时可以解决问题。例如:

q_1 -> q_2 [ label = <<table cellpadding="10" border="0" cellborder="0">
                        <tr><td>&epsilon;</td></tr>
                      </table>>, 
             constraint = false ];

要在一侧添加比在另一侧添加更多空间,您可以添加一个空单元格。然后代码很快变得(更多)不可读,但你可以使用一个简单的sed脚本来预处理你的点文件。

答案 2 :(得分:1)

我知道这是一个老问题,但是如果您正在寻找这种方法,那么下面的方法也可能会有所帮助。参见下图。 我在您的代码中添加了以下内容:

  • minlen = 2(以扩大节点之间的间隔)

  • tailport = n / s(将箭头尾部的位置更改为北/南)

  • headport = n / s(将头部的位置更改为向北或向南的箭头)


digraph finite_state_machine {                                                                                                                                                                                  
    pad=0.2;
    {
        rank=same;
        node [shape = point, style = invis]; q_0;
        node [shape = doublecircle, style = solid]; q_5;
        node [shape = circle];
        q_1 [ label = <<i>q<sub>1</sub></i>> ];
        q_2 [ label = <<i>q<sub>2</sub></i>> ];
        q_3 [ label = <<i>q<sub>3</sub></i>> ];
        q_4 [ label = <<i>q<sub>4</sub></i>> ];
        q_5 [ label = <<i>q<sub>5</sub></i>> ];
        q_0 -> q_1;
        q_1 -> q_2 [ label = "." ];
        q_1 -> q_2 [ label = <&epsilon;>, constraint=false, minlen=2, tailport=n, headport=n];
        q_2 -> q_1 [ label = <&epsilon;>, constraint=false, minlen=2, tailport=s, headport=s];
        q_2 -> q_3 [ label = <<i>a</i>> ];
        q_3 -> q_4 [ label = <<i>^a</i>> ];
        q_3 -> q_4 [ label = <&epsilon;>, constraint=false, minlen=2, tailport=n, headport=n];
        q_4 -> q_3 [ label = <&epsilon;>, constraint=false, minlen=2, tailport=s, headport=s];
        q_4 -> q_5 [ label = <<i>b</i>> ];
    }
}

image