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

osk*_*rkv 8 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>> ];
    }
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Pek*_*kka 10

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

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

或者,您可以尝试使用该ranksep属性强制进入一些额外的空间.


Til*_*ilo 7

如果xlabel没有解决它,那么将标签包装在表中有时可能是一种解决方法.例如:

q_1 -> q_2 [ label = <<table cellpadding="10" border="0" cellborder="0">
                        <tr><td>&epsilon;</td></tr>
                      </table>>, 
             constraint = false ];
Run Code Online (Sandbox Code Playgroud)

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


小智 5

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

  • 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>> ];
    }
}
Run Code Online (Sandbox Code Playgroud)

图像