![](https://csdnimg.cn/release/download_crawler_static/9518204/bga.jpg)
Graphviz Library Manual, August 21, 2014 10
third argument specifies whether or not a node of the given name should be created if it does not already
exist.
Edges are created using agedge by passing in the edge’s two nodes. If the graph is not strict, additional
calls to agedge with the same arguments will create additional edges between the two nodes. The string
argument allows you to supply a further name to distinguish between edges with the same head and tail.
If the graph is strict, extra calls will simply return the already existing edge. For directed graphs, the first
and second node arguments are taken to be the tail and head nodes, respectively. For undirected graph, they
still play this role for the functions agfstout and agfstin, but when checking if an edge exists with
agedge or agfindedge, the order is irrelevant. As with agnode, the final argument specifies whether
or not the edge should be created if it does not yet exist.
As suggested above, a graph can also contain subgraphs. These are created using agsubg:
Agraph_t
*
agsubg(Agraph_t
*
, char
*
, int);
The first argument is the immediate parent graph; the second argument is the name of the subgraph; the final
argument indicates if the subgraph should be created.
Subgraphs play three roles in Graphviz. First, a subgraph can be used to represent graph structure,
indicating that certain nodes and edges should be grouped together. This is the usual role for subgraphs
and typically specifies semantic information about the graph components. In this generality, the drawing
software makes no use of subgraphs, but maintains the structure for use elsewhere within an application.
In the second role, a subgraph can provide a context for setting attributes. In Graphviz, these are often
attributes used by the layout and rendering functions. For example, the application could specify that blue
is the default color for nodes. Then, every node within the subgraph will have color blue. In the context of
graph drawing, a more interesting example is:
subgraph {
rank = same; A; B; C;
}
This (anonymous) subgraph specifies that the nodes A, B and C should all be placed on the same rank if
drawn using dot.
The third role for subgraphs combines the previous two. If the name of the subgraph begins with
"cluster", Graphviz identifies the subgraph as a special cluster subgraph. The drawing software
1
will
do the layout of the graph so that the nodes belonging to the cluster are drawn together, with the entire
drawing of the cluster contained within a bounding rectangle.
We note here some important fields used in nodes, edges and graphs. If np, ep and gp are pointers to a
node, edge and graph, respectively, agnameof(np) and agraphof(np) give the name of the node and
the root graph containing it, agtail(ep) and aghead(ep) give the tail and head nodes of the edge,
and agroot(gp) gives the root graph containing the subgraph. For the root graph, this field will point to
itself.
2.1.1 Attributes
In addition to the abstract graph structure provided by nodes, edges and subgraphs, the Graphviz libraries
also support graph attributes. These are simply string-valued name/value pairs. Attributes are used to specify
any additional information which cannot be encoded in the abstract graph. In particular, the attributes are
heavily used by the drawing software to tailor the various geometric and visual aspects of the drawing.
1
if supported