需要绘制一个复杂的图形,其中将包含3种类型的边以及几种预定义的节点类型。

是否可以定义更多(例如,不仅一个默认值)“边缘类型”(或节点类型)以供以后使用?

意思是这样的:

edge [colorscheme=paired12, color=8, fontsize=11, fontname="Arial narrow"];
edge2 [colorscheme=paired12, color=3, fontsize=11, fontname="Arial narrow", style=bold];
edge3 [colorscheme=paired12, color=5, fontsize=14, fontname="Arial narrow"];

node1 -> node2; /* will use the default edge definition from the above */
node2 -> node3 [edgetype=edge2]; /* will use the second edge definition */
node2 -> node4 [edgetype=edge3]; /* and so on... */

上面的ofc不正确-仅用于解释...

最佳答案

如果您了解基本知识,则使用gvpr很简单:
input.dot

digraph test {
    node1 -> node2[label="test 1"]; /* will use the default edge definition from the above */
    node2 -> node3 [label="test 2", edgetype="edge2"]; /* will use the second edge definition */
    node2 -> node4 [label="test 3", edgetype="edge3"]; /* and so on... */
}
filter.gvpr
E {
    color="red";
    fontsize=11;
    fontname="Arial narrow"
}
E[edgetype == "edge2"] {
    color="green";
    fontsize=11;
    fontname="Arial narrow";
    style="bold"
}
E[edgetype == "edge3"] {
    color="blue";
    fontsize=14;
    fontname="Arial narrow"
}

带命令
gvpr -c -f filter.gvpr -o output.dot input.dot
将产生output.dot文件:
digraph test {
    node1 -> node2   [color=red,
        fontname="Arial narrow",
        fontsize=11,
        label="test 1"];
    node2 -> node3   [color=green,
        edgetype=edge2,
        fontname="Arial narrow",
        fontsize=11,
        label="test 2",
        style=bold];
    node2 -> node4   [color=blue,
        edgetype=edge3,
        fontname="Arial narrow",
        fontsize=14,
        label="test 3"];
}

关于graphviz定义更多 "defaults",我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8195642/

10-10 18:16