pack.3 9.4 KB

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