开发者

Graphviz: Place edge label on the other side

开发者 https://www.devze.com 2023-01-11 12:38 出处:网络
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:

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=开发者_如何学Pythondiamond,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.


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: Place edge label on the other side


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:

Graphviz: Place edge label on the other side

0

精彩评论

暂无评论...
验证码 换一张
取 消