Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graphviz --- edge label too close to another edge

Tags:

graphviz

I have the following code, and it results in the image below. As you can see, it's a little crowded around the edges and edge labels, especially around the "^a". What is the best way to create just a tad more space, so that one can clearly see which label belongs to which edge?

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

like image 585
oskarkv Avatar asked Oct 17 '12 12:10

oskarkv


2 Answers

There is no attribute in Graphviz to adjust the margin/padding around edge labels. The closest you can probably get to the effect you require is to use \n to introduce blank lines above/below your label to force space.

Obviously, this will not scale to anything automatic.

Alternately, you could try to use the ranksep attribute to force in some additional space.

like image 141
Pekka Avatar answered Oct 13 '22 22:10

Pekka


I know this is an old question, but this approach below might also be helpful, if this is what you are looking for. see the image below. i added the following to your code:

  • minlen=2 (to extend gaps between nodes)

  • tailport=n/s (to change location of the tail of the arrow to north/south)

  • headport=n/s (to change location of the head to the arrow to north or south)


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

like image 23
GSA Avatar answered Oct 13 '22 21:10

GSA