我有一个 gv 代码如下。我想在生成的图形中添加一些文本或图像作为页眉和页脚。

digraph  testdot {

label=" Name: MY NAME \l Address:  Address ...... \l ";

START_NODE [ shape=ellipse label= "START" ];
ERROR_NODE0 [ shape=box label= "Error0" ];
ERROR_NODE1 [ shape=box label= "Error1" ];
ERROR_NODE2 [ shape=box label= "Error2" ];
ERROR_NODE3 [ shape=box label= "Error3" ];

Statement_0 [ shape=diamond label= "if foo " ];
Statement_1 [ shape=diamond label= "if foo1" ];
Statement_2 [ shape=diamond label= "if foo2" ];
Statement_3 [ shape=diamond label= "if foo3" ];

START_NODE -> Statement_0;
Statement_0 -> Statement_1 [label= "No" ];
Statement_0 -> ERROR_NODE0 [label= "Yes" ];
Statement_1 -> Statement_2 [label= "No" ];
Statement_1 -> ERROR_NODE1 [label= "Yes" ];
Statement_2 -> Statement_3 [label= "No" ];
Statement_2 -> ERROR_NODE2 [label= "Yes" ];
Statement_3 -> Statement_4 [label= "No" ];
Statement_3 -> ERROR_NODE3 [label= "Yes" ];
}

下面是我希望输出如何的一个例子

最佳答案

如果在此任务中使用“dot”,则 dot 不允许控制图形元素的位置。也就是说,如果你知道你的图的结构,你可以使用子图、等级和隐藏边来做一些技巧。

这将是您图形的可能解决方案:

digraph  testdot {

subgraph clusterHeader {
    margin=0
    style="invis"
    HEADER [shape="box" label="This is the header"];
}

subgraph clusterMain {
    margin=0
    style="invis"
    START_NODE [ shape=ellipse label= "START" ];
    ERROR_NODE0 [ shape=box label= "Error0" ];
    ERROR_NODE1 [ shape=box label= "Error1" ];
    ERROR_NODE2 [ shape=box label= "Error2" ];
    ERROR_NODE3 [ shape=box label= "Error3" ];

    Statement_0 [ shape=diamond label= "if foo " ];
    Statement_1 [ shape=diamond label= "if foo1" ];
    Statement_2 [ shape=diamond label= "if foo2" ];
    Statement_3 [ shape=diamond label= "if foo3" ];

    START_NODE -> Statement_0;
    Statement_0 -> Statement_1 [label= "No" ];
    Statement_0 -> ERROR_NODE0 [label= "Yes" ];
    Statement_1 -> Statement_2 [label= "No" ];
    Statement_1 -> ERROR_NODE1 [label= "Yes" ];
    Statement_2 -> Statement_3 [label= "No" ];
    Statement_2 -> ERROR_NODE2 [label= "Yes" ];
    Statement_3 -> Statement_4 [label= "No" ];
    Statement_3 -> ERROR_NODE3 [label= "Yes" ];
}

subgraph clusterFooter {
    margin=0
    style="invis"
    LABEL_1 [shape="none" margin=0 label="NAME: My name\lAddress: 23 XYZ road"];
    {rank="sink"; FOOTER [shape="box" label="Footer text goes here"];}
}

// Connecting the subgraps in order. Try to connect a bottom node of your main
// clusterMain to LABEL_1
HEADER->START_NODE [style=invis];
ERROR_NODE3->LABEL_1 [style=invis weight=0];
LABEL_1->FOOTER [style=invis weight=0];

}

关于graphviz - 在graphviz中添加页眉和页脚,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27936623/

10-13 00:04