Adding header and footer in graphviz

僤鯓⒐⒋嵵緔 提交于 2019-12-06 02:40:29

问题


I have a gv code as below. I want to add some text or image as header and footer to the generated graph.

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

Below is an example of how I want the output as


回答1:


If using 'dot' for this task, dot does not allow to control the position of elements of your graph. That said, if you know the structure of your graph, you can do some tricks using subgraphs, ranks and hidden edges.

This would be a possible solution for your graph:

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

}


来源:https://stackoverflow.com/questions/27936623/adding-header-and-footer-in-graphviz

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!