93

I am using Graphviz 2.30. Horizontal positioning for labels works out, but in a few cases, a modified angle would be desired.

For instance, I tried various values for angle here but without any effect:

ABB -> ABACUS[label="applied", fontname="Arial", fontsize=15, labelangle=110];

How can I display labels in line with (i.e. parallel to) the edge when using a Graphviz digraph.

The entire digraph will not be posted due to an NDA. In addition, the rotation will be applied only to a few labels.

I have read similar threads like this or another (or a thread about alignment for instance) but without any help regarding my issue.

mnemonic
  • 1,605
  • 2
  • 17
  • 26
  • 2
    'labelangle' only works with headlabels and taillabels, furthermore it does not rotate the label, but only defines (together with labeldistance) where to place the label (which is still a horizontal line). Angle 0 is going from the start/end point along the edge. With angle + / - labels can be printed above or below the edge. With distance 0 the angle is without effect. I would also be very much interested in having labels rotated to follow the edges, which afaik is unsolved still. – bug313 Feb 05 '14 at 01:38
  • 2
    I'm getting the feeling that there's just no way to do this. But since the absence of features is rarely documented (it would lead to an infinite amount of documentation), it's hard to write an authoritative answer about this. Unless you can point out that there's no mention of anything like this in the entire documentation, nor in any obscure corner of the codebase. – bigblind Mar 12 '14 at 13:30
  • 1
    Text elements in Graphviz are all bounded with a regular box during positioning. The algorithm tries really hard to avoid crossing these box boundaries during edge placement. If a label could be rotated, these boxes would become much larger resulting in substantial pressure on display area. If the labels can overlap edges or nodes, then they could be rotated later in the imaging pipeline. – Pekka Apr 08 '15 at 14:01
  • 1
    actually you can find it in documentation: https://github.com/ellson/graphviz/blob/master/doc/internal_todo.html "? - Allow text at an angle" – MK. Oct 16 '15 at 02:23

2 Answers2

6

Using dot2latex allows you to specify lblstyle attribute. The value of lblstyle is used by PGF/TikZ in pdf generation.

One can specify parallel labels like this:

digraph G {
    edge [lblstyle="above, sloped"];
    a -> b [label="ab"];
    b -> c [label="bc"];
    c -> a [label="ca"];
}

To generate the pdf

$ dot2tex --tikzedgelabel file.dot > file.tex
$ pdflatex file.tex

The result is

enter image description here

malbarbo
  • 10,717
  • 1
  • 42
  • 57
  • 1
    Unfortunately you would have to know the angles of all labels when generating the graph; the OP would like to display their labels parallel with the edge, at whatever angle the edge happens to be. – Galax Jul 11 '16 at 20:07
  • 1
    @Galax Thanks for your comment. I fixed the answer. – malbarbo Jul 11 '16 at 21:11
  • Great find- that's a handy feature of `dot`, I didn't notice it before (or maybe it's new). – Galax Jul 11 '16 at 21:20
0

Edit: another answer found an option that now exists to align text with edges.

Your best option may be to export the graph as an SVG and use Illustrator or Inkscape to fine-tune it. This is only practical when producing a few graphs.

I frequently have to tweak the output from Graphviz and Gephi; they give me a good starting point though.

Galax
  • 1,441
  • 7
  • 6
  • You can edit the exported SVG even in [Microsoft Office](https://support.microsoft.com/en-us/office/edit-svg-images-in-microsoft-office-365-69f29d39-194a-4072-8c35-dbe5e7ea528c)! – Leponzo Oct 25 '21 at 05:30