Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to place edge labels ON edge in graphviz

Tags:

graphviz

dot

By default in Graphviz, edge labels are placed just to the right of the edge. I'm looking for a way to place the labels OVER the edge, centred on the edge. (It'll still be readable because I'm changing the colour of the edge).

Any ideas?

like image 426
naught101 Avatar asked Feb 28 '10 09:02

naught101


2 Answers

If this was headlabel or taillabel, you could try setting labeldistance to zero to force the label to be drawn on the edge, but as I understand, you are referring to edge label (the one on the middle of the edge). Documentation quite clearly states that labeldistance only affects headlabel and taillabel labels, but you can try your luck.

One other thing you might want to try is to make a transparent, intermediary node with a label on it. It could look like you want... But if you heavily rely on node placement algorithm, it could be unacceptable to create those 'artificial' nodes. In that case, I encourage you to join graphviz developers and add the feature you need ;) Seriously, it is very satisfying.

If you find another solution, please post it. I will be facing a similar problem in the near future.

like image 131
Paweł Polewicz Avatar answered Nov 08 '22 05:11

Paweł Polewicz


Consider adding a few blank spaces after your label. That way you are avoiding overlap with your edge arrow since graphviz labels are right-aligned. This is not an elegant solution and I would love to see a proper label alignment but it might solve your problem.

like image 31
Rohan Mukherjee Avatar answered Nov 08 '22 05:11

Rohan Mukherjee