Graphviz:将边缘标签放在另一侧

时间:2010-08-10 15:35:56

标签: graphviz dot

这可能与How to place edge labels ON edge in graphviz有关:我有以下图表,我使用命令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"];
}

我希望通过在图表的左侧放置User和Triple之间的标签来使结果更加对称。

2 个答案:

答案 0 :(得分:25)

使用graphviz无法手动放置边缘标签。

但是,您可以使用headlabellabeldistancelabelangle属性:

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"];
}

输出:

graphviz output

答案 1 :(得分:6)

以下是使用splines=false和双边的第二种解决方法:

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"];
}

输出:

alt text