Graphviz: Place edge label on the other side
Asked Answered
D

3

24

This may be related to How to place edge labels ON edge in graphviz: I have the following graph, which I visualize using the command dot -Teps g.dot > g.eps:

graph triple {
    node [shape=box]; User; Object; Tag;
    node [shape=diamond,style=filled]; Triple;
    {
        User -- Triple [label = "1"];
        Object -- Triple [label = "1"];
    }
    {
        rank=same;
        User;
        Object;
    }
    Triple -- Tag [label="n"];
}

I would like the result to be more symmetric by putting the label between User and Triple on the left side of the graph.

Dion answered 10/8, 2010 at 15:35 Comment(0)
C
8

And here's the second workaround using splines=false and double edges:

graph {
splines=false;
node [shape=box]; User; Object; Tag;
node [shape=diamond,style=filled]; Triple;
    {
        User   -- Triple [label = "1"];
        User   -- Triple [label = ""];
        Object -- Triple [label = ""];
        Object -- Triple [label = "1"];
    }
    {
        rank=same;
        User;
        Object;
    }
    Triple -- Tag [label="n"];
}

Output:

alt text

Communalism answered 13/1, 2011 at 0:20 Comment(0)
C
29

Manual placement of edge labels cannot be done with graphviz.

However, you could use the headlabel, labeldistance and labelangle attributes:

graph triple {
node [shape=box]; User; Object; Tag;
node [shape=diamond,style=filled]; Triple;
    {
        User   -- Triple [headlabel = "1", labeldistance=2.5, labelangle=20];
        Object -- Triple [headlabel = "1", labeldistance=2.5, labelangle=-20];
    }
    {
        rank=same;
        User;
        Object;
    }
    Triple -- Tag [label="n"];
}

Output:

graphviz output

Communalism answered 8/1, 2011 at 20:41 Comment(1)
Why do you need "rank same" in the example above?Extradite
C
8

And here's the second workaround using splines=false and double edges:

graph {
splines=false;
node [shape=box]; User; Object; Tag;
node [shape=diamond,style=filled]; Triple;
    {
        User   -- Triple [label = "1"];
        User   -- Triple [label = ""];
        Object -- Triple [label = ""];
        Object -- Triple [label = "1"];
    }
    {
        rank=same;
        User;
        Object;
    }
    Triple -- Tag [label="n"];
}

Output:

alt text

Communalism answered 13/1, 2011 at 0:20 Comment(0)
S
0

I gave up trying to get it to work in Graphviz. Instead, I rendered as a pdf, marked up the pdf to add labels myself, and then flattened the pdf into a new pdf so the markups would be part of the pdf.

Smoko answered 1/2, 2023 at 15:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.