| 1 |
.TH LIBPACK 3 "04 APRIL 2009" |
| 2 |
.SH NAME |
| 3 |
\fBlibpack\fR \- support for connected components |
| 4 |
.SH SYNOPSIS |
| 5 |
.ta .75i 1.5i 2.25i 3i 3.75i 4.5i 5.25i 6i |
| 6 |
.PP |
| 7 |
.nf |
| 8 |
\f5 |
| 9 |
#include <graphviz/pack.h> |
| 10 |
|
| 11 |
typedef enum { l_clust, l_node, l_graph, l_array} pack_mode; |
| 12 |
|
| 13 |
typedef struct { |
| 14 |
float aspect; /* desired aspect ratio */ |
| 15 |
int sz; /* row/column size size */ |
| 16 |
unsigned int margin; /* margin left around objects, in points */ |
| 17 |
int doSplines; /* use splines in constructing graph shape */ |
| 18 |
pack_mode mode; /* granularity and method */ |
| 19 |
boolean *fixed; /* fixed[i] == true implies g[i] should not be moved */ |
| 20 |
packval_t* vals; /* for arrays, sort numbers */ |
| 21 |
int flags; |
| 22 |
} pack_info; |
| 23 |
|
| 24 |
point* putRects(int ng, boxf* bbs, pack_info* pinfo); |
| 25 |
int packRects(int ng, boxf* bbs, pack_info* pinfo); |
| 26 |
|
| 27 |
point* putGraphs (int, Agraph_t**, Agraph_t*, pack_info*); |
| 28 |
int packGraphs (int, Agraph_t**, Agraph_t*, pack_info*); |
| 29 |
int packSubgraphs (int, Agraph_t**, Agraph_t*, pack_info*); |
| 30 |
|
| 31 |
pack_mode getPackMode (Agraph_t*, pack_mode dflt); |
| 32 |
int getPack (Agraph_t*, int, int); |
| 33 |
|
| 34 |
int isConnected (Agraph_t*); |
| 35 |
Agraph_t** ccomps (Agraph_t*, int*, char*); |
| 36 |
Agraph_t** pccomps (Agraph_t*, int*, char*, boolean*); |
| 37 |
int nodeInduce (Agraph_t*); |
| 38 |
|
| 39 |
\fP |
| 40 |
.fi |
| 41 |
.SH DESCRIPTION |
| 42 |
\fIlibpack\fP supports the use of connected components in the |
| 43 |
context of laying out graphs using other \fIgraphviz\fP libraries. |
| 44 |
One set of functions can be used to take a single graph and |
| 45 |
break it apart into connected components. A complementary set |
| 46 |
of functions takes a collection of graphs (not necessarily components |
| 47 |
of a single graph) which have been laid out separately, and packs them |
| 48 |
together. |
| 49 |
|
| 50 |
As this library is meant to be used with \fIlibcommon\fP, it relies |
| 51 |
on the \fIAgraphinfo_t\fP, \fIAgnodeinfo_t\fP and \fIAgedgeinfo_t\fP used |
| 52 |
in that |
| 53 |
library. The specific dependencies are given below in the function |
| 54 |
descriptions. |
| 55 |
|
| 56 |
.SS "Creating components" |
| 57 |
.PP |
| 58 |
.SS " Agraph_t** ccomps (Agraph_t* g, int* cnt, char* pfx)" |
| 59 |
The function \fIccomps\fP takes a graph \fIg\fP and returns an array |
| 60 |
of pointers to subgraphs of \fIg\fP which are its connected components. |
| 61 |
\fIcnt\fP is set to the number of components. If \fIpfx\fP is non-NULL, |
| 62 |
it is used as a prefix for the names of the subgraphs; otherwise, the |
| 63 |
string ``_cc_'' is used. |
| 64 |
Note that the subgraphs only contain the relevant nodes, not any |
| 65 |
corresponding edges. Depending on the use, this allows the caller |
| 66 |
to retrieve edge information from the root graph. |
| 67 |
.PP |
| 68 |
The array returned is obtained from \fImalloc\fP and must be freed by |
| 69 |
the caller. The function relies on the \fImark\fP field in |
| 70 |
\fIAgnodeinfo_t\fP. |
| 71 |
.PP |
| 72 |
.SS " Agraph_t** pccomps (Agraph_t* g, int* cnt, char* pfx, boolean* pinned)" |
| 73 |
This is identical to \fIccomps\fP except that is puts all pinned nodes |
| 74 |
in the first component returned. In addition, if \fIpinned\fP is non-NULL, |
| 75 |
it is set to true if pinned nodes are found and false otherwise. |
| 76 |
.PP |
| 77 |
.SS " int nodeInduce (Agraph_t* g)" |
| 78 |
This function takes a subgraph \fIg\fP and finds all edges in its root |
| 79 |
graph both of whose endpoints are in \fIg\fP. It returns the number of |
| 80 |
such edges and, if this edge is not already |
| 81 |
in the subgraph, it is added. |
| 82 |
.PP |
| 83 |
.SS " int isConnected (Agraph_t* g)" |
| 84 |
This function returns non-zero if the graph \fIg\fP is connected. |
| 85 |
|
| 86 |
.SS "Packing components" |
| 87 |
.PP |
| 88 |
.SS " point* putGraphs (int ng, Agraph_t** gs, Agraph_t* root, pack_info ip)" |
| 89 |
\fIputGraphs\fP packs together a collection of laid out graphs into a |
| 90 |
single layout which avoids any overlap. It takes as input \fIng\fP |
| 91 |
graphs \fIgs\fP. For each graph, it is assumed that all the nodes have |
| 92 |
been positioned using \fIpos\fP, and that the \fIxsize\fP and \fIysize\fP |
| 93 |
fields have been set. |
| 94 |
.PP |
| 95 |
If \fIroot\fP is non-NULL, it is taken as the root |
| 96 |
graph of the subgraphs \fIgs\fP and is used to find the edges. Otherwise, |
| 97 |
\fIputGraphs\fP uses the edges found in each graph \fIgs[i]\fP. |
| 98 |
.PP |
| 99 |
For the modes \fIl_node\fP, \fIl_clust\fP, and \fIl_graph\fP, |
| 100 |
the packing is done using the polyomino-based |
| 101 |
algorithm of Freivalds et al. This allows for a fairly tight packing, in |
| 102 |
which a convex part of one graph might be inserted into the concave part |
| 103 |
of another. |
| 104 |
The granularity of the polyominoes used depends on the value of |
| 105 |
\fIip\->mode\fP. If this is \fIl_node\fP, a polyomino is constructed |
| 106 |
to approximate the nodes and edges. If this is \fIl_clust\fP, the |
| 107 |
polyomino treats top-level clusters as single rectangles, unioned |
| 108 |
with the polyominoes for the remaining nodes and edges. If the value |
| 109 |
is \fIl_graph\fP, the polyomino for a graph is a single rectangle |
| 110 |
corresponding to the bounding box of the graph. |
| 111 |
.PP |
| 112 |
The mode \fIl_node\fP specifies that the graphs should be packed as an |
| 113 |
array. |
| 114 |
.PP |
| 115 |
If \fIip\->doSplines\fP is true, the function uses the spline information |
| 116 |
in the \fIspl\fP field of an edge, if it exists. |
| 117 |
Otherwise, the algorithm represents an edge as a |
| 118 |
straight line segment connecting node centers. |
| 119 |
.PP |
| 120 |
The parameter \fIip\->margin\fP specifies a boundary of \fImargin\fP points |
| 121 |
to be allowed around each node. It must be non-negative. |
| 122 |
.PP |
| 123 |
The parameter \fIip\->fixed\fP, if non-null, should point to an array |
| 124 |
of \fIng\fP booleans. If \fIip\->fixed[i]\fP is true, graph \fIgs[i]\fP |
| 125 |
should be left at its original position. The packing will first first |
| 126 |
place all of the fixed graphs, then fill in the with the remaining |
| 127 |
graphs. |
| 128 |
.PP |
| 129 |
The function returns an array of points which can be used as the origin of |
| 130 |
the bounding box of each graph. If the |
| 131 |
graphs are translated to these positions, none of the graph components |
| 132 |
will overlap. |
| 133 |
The array returned is obtained from \fImalloc\fP and must be freed by |
| 134 |
the caller. If any problem occurs, \fIputGraphs\fP returns NULL. |
| 135 |
As a side-effect, at its start, \fIputGraphs\fP sets the \fIbb\fP |
| 136 |
of each graph to reflect its initial layout. Note that \fIputGraphs\fP |
| 137 |
does not do any translation or change the input graphs in any other way |
| 138 |
than setting the \fIbb\fP. |
| 139 |
.PP |
| 140 |
This function uses the \fIbb\fP field in \fIAgraphinfo_t\fP, |
| 141 |
the \fIpos\fP, \fIxsize\fP and \fIysize\fP fields in \fInodehinfo_t\fP and |
| 142 |
the \fIspl\fP field in \fIAedgeinfo_t\fP. |
| 143 |
.PP |
| 144 |
.SS " int packGraphs (int ng, Agraph_t** gs, Agraph_t* root, pack_info* ip)" |
| 145 |
This function takes \fIng\fP subgraphs \fIgs\fP of a root graph \fIroot\fP |
| 146 |
and calls \fIputGraphs\fP with the given arguments to generate |
| 147 |
a packing of the subgraphs. If successful, it then invokes |
| 148 |
shifts the subgraphs to their new positions. It returns 0 on success. |
| 149 |
.PP |
| 150 |
.SS " int packSubgraphs (int ng, Agraph_t** gs, Agraph_t* root, pack_info* ip)" |
| 151 |
This function simply calls \fIpackGraphs\fP with the given arguments, and |
| 152 |
then recomputes the bounding box of the \fIroot\fP graph. |
| 153 |
.PP |
| 154 |
.SS " int pack_graph(int ng, Agraph_t** gs, Agraph_t* root, boolean* fixed)" |
| 155 |
uses \fIpackSubgraphs\fP to place the individual subgraphs into a single layout |
| 156 |
with the parameters obtained from \fIgetPackInfo\fP. If successful, |
| 157 |
\fIdotneato_postprocess\fP is called on the root graph. |
| 158 |
.PP |
| 159 |
.SS " point* putRects (int ng, boxf* bbs, pack_info* ip)" |
| 160 |
\fIputRects\fP packs together a collection of rectangles into a |
| 161 |
single layout which avoids any overlap. It takes as input \fIng\fP |
| 162 |
rectangles \fIbbs\fP. |
| 163 |
.PP |
| 164 |
Its behavior and return value are analogous to those of \fIputGraphs\fP. |
| 165 |
However, the modes \fIl_node\fP and \fIl_clust\fP are illegal. |
| 166 |
The fields \fIfixed\fP and \fIdoSplines\fP of \fIip\fP |
| 167 |
are unused. |
| 168 |
.PP |
| 169 |
.SS " int packRects (int ng, boxf* bbs, pack_info* ip)" |
| 170 |
\fIpackRects\fP is analogous to \fIpackGraphs\fP: it calls |
| 171 |
\fIputRects\fP and, if this is successful, it translates |
| 172 |
the rectangles in \fIbbs\fP appropriately. |
| 173 |
.SS "Utility functions" |
| 174 |
The library provides several functions which can be used to tailor the |
| 175 |
packing based on graph attributes. |
| 176 |
.SS " pack_mode parsePackModeInfo(char* p, pack_mode dflt, pack_info* pinfo)" |
| 177 |
analyzes \fIp\fP as a string representation of pack mode, storing the |
| 178 |
information in \fIpinfo\fP. |
| 179 |
If \fIp\fP is "cluster", it returns |
| 180 |
\fIl_clust\fP; for "graph", it returns \fIl_graph\fP; |
| 181 |
for "node", it returns \fIl_node\fP; |
| 182 |
for "array", it returns \fIl_array\fP; |
| 183 |
for "aspect", it returns \fIl_aspect\fP; |
| 184 |
otherwise, it returns \fIdflt\fP. |
| 185 |
Related data is also stored in \fIpinfo\fP. |
| 186 |
.SS " pack_mode getPackModeInfo(Agraph_t * g, pack_mode dflt, pack_info* pinfo)" |
| 187 |
This function processes the graph's \fI"packmode"\fP attribute, storing the |
| 188 |
information in \fIpinfo\fP. It returns \fIpinfo\->mode\fP. |
| 189 |
The attribute is processed using \fIparsePackModeInfo\fP with \fIdflt\fP passed |
| 190 |
as the default argument. |
| 191 |
.SS " pack_mode getPackMode (Agraph_t* g, pack_mode dflt)" |
| 192 |
This function returns a \fIpack_mode\fP associated with \fIg\fP. |
| 193 |
.SS " int getPack (Agraph_t* g, int not_def, int dflt)" |
| 194 |
This function queries the graph attribute \fI"pack"\fP. If this is |
| 195 |
defined as a non-negative integer, the integer is returned; if it |
| 196 |
is defined as "true", the value \fIdflt\fP is returned; otherwise, |
| 197 |
the value \fInot_def\fP is returned. |
| 198 |
.SS " pack_mode getPackInfo(Agraph_t * g, pack_mode dflt, int dfltMargin, pack_info* pinfo)" |
| 199 |
This function calls both \fIgetPackModeInfo\fP and \fIgetPack\fP, storing the |
| 200 |
information in \fIpinfo\fP. \fIdfltMargin\fP is used for both integer arguments |
| 201 |
of \fIgetPack\fP, with the result saved as \fIpinfo\->margin\fP. |
| 202 |
It returns \fIpinfo\->mode\fP. |
| 203 |
.SH SEE ALSO |
| 204 |
.BR dot (1), |
| 205 |
.BR neato (1), |
| 206 |
.BR twopi (1), |
| 207 |
.BR cgraph (3) |
| 208 |
.br |
| 209 |
K. Freivalds et al., "Disconnected Graph Layout and the Polyomino |
| 210 |
Packing Approach", GD0'01, LNCS 2265, pp. 378-391. |
| 211 |
|
| 212 |
.SH "BUGS" |
| 213 |
The packing does not take into account edge or graph labels. |
| 214 |
.SH AUTHORS |
| 215 |
Emden Gansner ([email protected]). |