Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing a border around a set of vertices in Graphviz

Tags:

graphviz

I am trying to draw a graph with Graphviz.

I wish to draw a dotted line around a set of vertices, symbolizing that they are a part of a bigger entity.

Say for example, if I have three vertices as eggs, chicken and ham, I should be able to draw a dotted line around all three of them, and label that border as food.

like image 986
user916315 Avatar asked Dec 03 '11 07:12

user916315


1 Answers

It is possible to group nodes in graphviz by putting them into a cluster. A cluster is a special kind of subgraph which certain layout engines (dot, fdp, ...) support, and if supported, the nodes in a cluster will be drawn together.

From the documentation:

If the name of the subgraph begins with cluster, Graphviz notes the subgraph as a special cluster subgraph. If supported, the layout engine will do the layout so that the nodes belonging to the cluster are drawn together, with the entire drawing of the cluster contained within a bounding rectangle.

Note that, for good and bad, cluster subgraphs are not part of the DOT language, but solely a syntactic convention adhered to by certain of the layout engines.


Important: The ID of the subgraph has to start with cluster.


Example:

graph g{
 subgraph cluster_food {
    eggs; chicken; ham;
    label="Food";
    graph[style=dotted];
 }
}

ham, chicken and eggs

like image 102
marapet Avatar answered Oct 21 '22 02:10

marapet