| 1 |
\section{Introduction} |
| 2 |
\label{sec:intro} |
| 3 |
The \gviz\ package consists of a variety of software for drawing |
| 4 |
attributed graphs. It implements a handful of common graph layout |
| 5 |
algorithms. These are: |
| 6 |
\begin{description} |
| 7 |
\item[dot] A Sugiyama-style hierarchical layout \cite{stt,gknv:methods}. |
| 8 |
\item[neato] A ``symmetric'' layout algorithm based on stress reduction. |
| 9 |
This is a variation of multidimensional scaling \cite{kruskal,cohen}. The |
| 10 |
default implementation uses stress majorization \cite{gkn}. |
| 11 |
An alternate implementation uses the Kamada-Kawai algorithm \cite{kk} |
| 12 |
\item[fdp] An implementation of the Fruchterman-Reingold force-directed |
| 13 |
algorithm \cite{fr} |
| 14 |
for ``symmetric'' layouts. This layout is similar to neato, but there |
| 15 |
are performance and feature differences. |
| 16 |
\item[sfdp] A multiscale force-directed layout using a spring-electrical |
| 17 |
model \cite{sfdp}. |
| 18 |
\item[twopi] A radial layout as described by Wills \cite{nicheworks}. |
| 19 |
\item[circo] A circular layout combining aspects of the |
| 20 |
work of Six and Tollis \cite{st,st2} and Kaufmann and Wiese \cite{kw}. |
| 21 |
\item[patchwork] An implementation of squarified treemaps \cite{sqtreemap}. |
| 22 |
\item[osage] A layout algorithm for clustered graphs based on user specifications. |
| 23 |
\end{description} |
| 24 |
In addition, \gviz\ provides an assortment of more general-purpose |
| 25 |
graph algorithms, such as transitive reduction, which have proven useful in |
| 26 |
the context of graph drawing. |
| 27 |
|
| 28 |
The package was designed \cite{gviz} |
| 29 |
to rely on the |
| 30 |
``program-as-filter'' model of software, in which distinct graph |
| 31 |
operations or transformations are embodied as programs. Graph drawing |
| 32 |
and manipulation are achieved by using the output of one filter as |
| 33 |
the input of another, with each filter recognizing a common, text-based |
| 34 |
graph format. |
| 35 |
One thus has an algebra of graphs, using a scripting language to provide |
| 36 |
the base language with variables and function application and composition. |
| 37 |
|
| 38 |
Despite the simplicity and utility of this approach, some |
| 39 |
applications need or desire to use the software as a library with |
| 40 |
bindings in a non-scripting language, rather than as primitives composed |
| 41 |
using a scripting language. The \gviz\ software provides a variety of |
| 42 |
ways to achieve |
| 43 |
this, running a spectrum from very simple but somewhat inflexible to |
| 44 |
fairly complex but offering a good deal of application control. |
| 45 |
|
| 46 |
\subsection{String-based layouts} |
| 47 |
The simplest mechanism for doing this consists of using the filter |
| 48 |
approach in disguise. The application, perhaps using the \gviz\ \graph\ |
| 49 |
library, constructs a representation of a graph in the |
| 50 |
\DOT\ language. The application can then invoke the desired layout |
| 51 |
program, e.g., using {\tt system} or {\tt popen} on a Unix system, |
| 52 |
passing the graph using an intermediate file or a pipe. The layout |
| 53 |
program computes position information for the graph, attaches this |
| 54 |
as attributes, and delivers the graph back to the application through |
| 55 |
another file or pipe. The application can then read in the graph, |
| 56 |
and apply the geometric information as necessary. This is the |
| 57 |
approach used by many applications, e.g., dotty \cite{dotty} and |
| 58 |
grappa \cite{grappa}, which |
| 59 |
rely on \gviz. |
| 60 |
|
| 61 |
There are several \gviz\ output formats which can be used in this |
| 62 |
approach. As with all output formats, they are specified by |
| 63 |
using a {\tt -T} flag when invoking the layout program. |
| 64 |
The input to the programs must always be in the \DOT\ language. |
| 65 |
|
| 66 |
\subsubsection{dot} |
| 67 |
\label{sect:dot} |
| 68 |
This format relies on the \DOT\ language to describe the graphs, with attributes |
| 69 |
attached as name-value pairs. |
| 70 |
|
| 71 |
The \graph\ library provides a parser for graphs represented |
| 72 |
in \DOT. Using this, it is easy to read the graphs and query the |
| 73 |
desired attributes using {\tt agget} or {\tt agxget}. |
| 74 |
For more information on these functions, see Section~\ref{sec:attributes}. |
| 75 |
The string representations of the various types referred to are |
| 76 |
described in Appendix~\ref{sec:types}. |
| 77 |
|
| 78 |
On output, the graph will have a {\tt bb} attribute of type {\tt rectangle}, |
| 79 |
specifying the bounding box of the drawing. |
| 80 |
If the graph has a label, its position is specified by the {\tt lp} |
| 81 |
attribute of type {\tt point}. |
| 82 |
|
| 83 |
Each node gets {\tt pos}, {\tt width} and {\tt height} attributes. |
| 84 |
The first has type {\tt point}, and indicates the center of the node |
| 85 |
in points. The |
| 86 |
{\tt width} and {\tt height} attributes are floating point numbers |
| 87 |
giving the width and height, in inches, of the node's bounding box. |
| 88 |
If the node has a record shape, the record rectangles are given in the |
| 89 |
{\tt rects} attribute. This has the format of a space-separated list |
| 90 |
of rectangles. |
| 91 |
If the node is a polygon (including ellipses) and the {\tt vertices} |
| 92 |
attribute is defined for nodes, this attribute will contain the |
| 93 |
vertices of the node, in inches, as a space-separated list of {\tt pointf} |
| 94 |
values. |
| 95 |
For ellipses, the curve is sampled, the number of points used being |
| 96 |
controlled by the {\tt samplepoints} attribute. |
| 97 |
The points are given relative to the center of the node. |
| 98 |
Note also that the points only give the node's basic shape; they do |
| 99 |
not reflect any internal structure. If the node has |
| 100 |
{\tt peripheries} greater than one, |
| 101 |
or a shape like {\tt "Msquare"}, the {\tt vertices} |
| 102 |
attribute does not represent the extra curves or lines. |
| 103 |
|
| 104 |
Every edge is assigned a {\tt pos} attribute having {\tt splineType} |
| 105 |
type. If the edge has a label, the label position is given in the |
| 106 |
{\tt lp} of type {\tt point}. |
| 107 |
|
| 108 |
\subsubsection{xdot} |
| 109 |
\label{sect:xdot} |
| 110 |
|
| 111 |
The {\tt xdot} format is a strict extension of the {\tt dot} format, in that it |
| 112 |
provides the same attributes as {\tt dot} as well as additional drawing |
| 113 |
attributes. These additional attributes specify how to draw each component of |
| 114 |
the graph using primitive graphics operations. This can be particularly |
| 115 |
helpful in dealing with node shapes and edge arrowheads. |
| 116 |
Unlike the information provided by the {\tt vertices} attribute |
| 117 |
described above, |
| 118 |
the extra attributes in {\tt xdot} provide all geometric drawing information, |
| 119 |
including the various types of arrowheads and multiline labels with |
| 120 |
variations in alignment. In addition, all the parameters use the same |
| 121 |
units. |
| 122 |
|
| 123 |
There are six new attributes, listed in Table~\ref{table:xdot}. |
| 124 |
These drawing attributes are only attached to nodes and edges. |
| 125 |
\begin{table}[htb] |
| 126 |
\centering |
| 127 |
\begin{tabular}[t]{|ll|} \hline |
| 128 |
{\tt \_draw\_} & General drawing operations \\ |
| 129 |
{\tt \_ldraw\_} & Label drawing operations \\ |
| 130 |
{\tt \_hdraw\_} & Head arrowhead \\ |
| 131 |
{\tt \_tdraw\_} & Tail arrowhead \\ |
| 132 |
{\tt \_hldraw\_} & Head label \\ |
| 133 |
{\tt \_tldraw\_} & Tail label \\ |
| 134 |
\hline |
| 135 |
\end{tabular} |
| 136 |
\caption{{\tt xdot} drawing attributes} |
| 137 |
\label{table:xdot} |
| 138 |
\end{table} |
| 139 |
Clearly, the last four attributes are only attached to edges. |
| 140 |
|
| 141 |
The value of these attributes are strings consisting of the concatenation of |
| 142 |
some (multi-)set of the 7 drawing operations listed in Table~\ref{table:xops}. |
| 143 |
The color, font name, and style values supplied in the $C$, $c$, $F$, |
| 144 |
and $S$ operations have the same format and interpretation |
| 145 |
as the {\tt color}, {\tt fontname}, and |
| 146 |
{\tt style} attributes in the source graph. |
| 147 |
\begin{table}[htb] |
| 148 |
\centering |
| 149 |
\begin{tabular}[t]{|lp{4.5in}|} \hline |
| 150 |
${\tt E}\ x_0\ y_0\ w\ h$ & Filled ellipse with equation |
| 151 |
$((x - x_0)/w)^2 + ((y - y_0)/h)^2 = 1$ \\ |
| 152 |
${\tt e}\ x_0\ y_0\ w\ h$ & Unfilled ellipse with equation |
| 153 |
$((x - x_0)/w)^2 + ((y - y_0)/h)^2 = 1$ \\ |
| 154 |
${\tt P}\ n\ x_1\ y_1\ \ldots\ x_n\ y_n$ & Filled polygon with the |
| 155 |
given $n$ vertices \\ |
| 156 |
${\tt p}\ n\ x_1\ y_1\ \ldots\ x_n\ y_n$ & Unfilled polygon with the |
| 157 |
given $n$ vertices \\ |
| 158 |
${\tt L}\ n\ x_1\ y_1\ \ldots\ x_n\ y_n$ & Polyline with the |
| 159 |
given $n$ vertices \\ |
| 160 |
${\tt B}\ n\ x_1\ y_1\ \ldots\ x_n\ y_n$ & B-spline with the |
| 161 |
given $n$ control points. $n \equiv 1 mod 3$ and $n \geq 4$ \\ |
| 162 |
${\tt b}\ n\ x_1\ y_1\ \ldots\ x_n\ y_n$ & Filled B-spline with the |
| 163 |
given $n$ control points. $n \equiv 1 mod 3$ and $n \geq 4$ \\ |
| 164 |
${\tt T}\ x\ y\ j\ w\ n\ {\tt -}c_{1}c_{2}\cdots c_{n}$ & |
| 165 |
Text drawn using the baseline point $(x,y)$. The text consists of the |
| 166 |
$n$ bytes following {\tt '-'}. The text should be left-aligned (centered, |
| 167 |
right-aligned) on the point if $j$ is -1 (0, 1), respectively. The |
| 168 |
value $w$ gives the width of the text as computed by the library. \\ |
| 169 |
${\tt t}\ f$ & |
| 170 |
Set font characteristics. The integer f is the OR of BOLD=1, ITALIC=2, UNDERLINE=4, SUPERSCRIPT=8, SUBSCRIPT=16, and STRIKE-THROUGH=32. \\ |
| 171 |
${\tt C}\ n\ {\tt -}c_{1}c_{2}\cdots c_{n}$ & Set color used to fill closed |
| 172 |
regions. The |
| 173 |
color is specified by the $n$ characters following {\tt '-'}. \\ |
| 174 |
${\tt c}\ n\ {\tt -}c_{1}c_{2}\cdots c_{n}$ & Set pen color, the color used |
| 175 |
for text and line drawing. The |
| 176 |
color is specified by the $n$ characters following {\tt '-'}. \\ |
| 177 |
${\tt F}\ s\ n\ {\tt -}c_{1}c_{2}\cdots c_{n}$ & Set font. The font |
| 178 |
size is $s$ points. The font name |
| 179 |
is specified by the $n$ characters following {\tt '-'}. \\ |
| 180 |
${\tt S}\ n\ {\tt -}c_{1}c_{2}\cdots c_{n}$ & Set style attribute. The |
| 181 |
style value is specified by the $n$ characters following {\tt '-'}. \\ |
| 182 |
${\tt I}\ x\ y\ j\ w\ n\ {\tt -}c_{1}c_{2}\cdots c_{n}$ & |
| 183 |
Externally-specified image drawn in the box with lower left corner $(x,y)$ |
| 184 |
and upper right corner $(x+w,y+h)$. The name of the image consists of the $n$ bytes following '-'. This is usually a bitmap image. Note that the image size, even when converted from pixels to points, might be different from the required size $(w,h)$. It is assumed the renderer will perform the necessary scaling.\\ |
| 185 |
\hline |
| 186 |
\end{tabular} |
| 187 |
\caption{{\tt xdot} drawing operations} |
| 188 |
\label{table:xops} |
| 189 |
\end{table} |
| 190 |
|
| 191 |
In handling alignment, the application may want to recompute the string |
| 192 |
width using its own font drawing primitives. |
| 193 |
|
| 194 |
The text operation is only used in the {\tt label} attributes. |
| 195 |
Normally, the non-text graphics |
| 196 |
operations are only used in the non-label attributes. |
| 197 |
If, however, a node has {\tt shape="record"} or an HTML-like label is |
| 198 |
involved, a label attribute may also contain various graphics operations. |
| 199 |
In addition, if the {\tt decorate} attribute is set on an edge, its |
| 200 |
{\tt label} attribute will also contain a polyline operation. |
| 201 |
|
| 202 |
All coordinates and sizes are in points. |
| 203 |
If an edge or |
| 204 |
node is invisible, no drawing operations are attached to it. |
| 205 |
|
| 206 |
\subsubsection{plain} |
| 207 |
|
| 208 |
The {\tt plain} format is line-based and very simple to parse. This works |
| 209 |
well for applications which need or wish to avoid using the \graph\ |
| 210 |
library. The price for this simplicity is that the format |
| 211 |
encodes very little detailed layout information beyond basic position |
| 212 |
information. If an application needs more than what is supplied in the |
| 213 |
format, it should use the {\tt dot} or {\tt xdot} format. |
| 214 |
|
| 215 |
There are four types of lines: {\tt graph}, {\tt node}, |
| 216 |
{\tt edge} and {\tt stop}. The output |
| 217 |
consists of a single {\tt graph} line; a sequence of {\tt node} lines, one |
| 218 |
for each node; a sequence of {\tt edge} lines, one for each edge; and |
| 219 |
a single terminating {\tt stop} line. All units are in inches, |
| 220 |
represented by a floating point number. |
| 221 |
|
| 222 |
As noted, the statements have very simple formats. |
| 223 |
\begin{tabbing} |
| 224 |
\indent \indent \= {\em {\tt graph} scale width height} \\ |
| 225 |
\> {\em {\tt node} name x y width height label style shape color fillcolor} \\ |
| 226 |
\> {\em {\tt edge} tail head n $x_1$ $y_1$ ... $x_n$ $y_n$ [label xl yl] style color} \\ |
| 227 |
\> {\tt stop} |
| 228 |
\end{tabbing} |
| 229 |
|
| 230 |
We now describe the statements in more detail. |
| 231 |
\begin{description} |
| 232 |
\item[graph] |
| 233 |
The {\em width} and {\em height} values give the |
| 234 |
width and height of the drawing. The |
| 235 |
lower left corner of the drawing is at the origin. |
| 236 |
The {\em scale} value indicates |
| 237 |
how the drawing should be scaled if a {\tt size} attribute was given and the |
| 238 |
drawing needs to be scaled to conform to that size. If no scaling is |
| 239 |
necessary, it will be set to 1.0. Note that all graph, node and edge |
| 240 |
coordinates and lengths are given unscaled. |
| 241 |
\item[node] |
| 242 |
The {\em name} value is the name of the node, and |
| 243 |
{\em x} and {\em y} give the node's position. |
| 244 |
The {\em width} and {\em height} are the width and height of the node. |
| 245 |
The {\em label}, {\em style}, |
| 246 |
{\em shape}, {\em color} and {\em fillcolor} values |
| 247 |
give the node's label, style, shape, color and |
| 248 |
fillcolor, respectively, using default attribute values where necessary. |
| 249 |
If the node does not have a {\tt style} attribute, {\tt "solid"} is used. |
| 250 |
\item[edge] |
| 251 |
The {\em tail} and {\em head} values give the names of the head and tail nodes. |
| 252 |
{\em n} is the number of control points defining the B-spline forming the edge. |
| 253 |
This is followed by $2*n$ numbers giving the x and y coordinates of the |
| 254 |
control points in order from tail to head. If the edge has a {\tt label} |
| 255 |
attribute, |
| 256 |
this comes next, followed by the x and y coordinates of the label's position. |
| 257 |
The edge description is completed by the edge's style and color. As with |
| 258 |
nodes, if a style is not defined, {\tt "solid"} is used. |
| 259 |
\end{description} |
| 260 |
|
| 261 |
\subsubsection{plain-ext} |
| 262 |
The {\tt plain-ext} format is identical with the {\tt plain} format, |
| 263 |
except that port names are attached to the node names in an edge, |
| 264 |
when applicable. It uses the usual \DOT\ representation, where port |
| 265 |
{\em p} of node {\em n} is given as {\tt {\em n}:{\em p}}. |
| 266 |
|
| 267 |
\subsubsection{GXL and GML} |
| 268 |
The GXL \cite{gxl} dialect of XML and GML \cite{gml} are a widely used standards for |
| 269 |
representing attributed graphs as text, especially in the graph |
| 270 |
drawing and software engineering communities. There |
| 271 |
are many tools available for parsing and analyzing graphs represented |
| 272 |
in these formats. And, as GXL is based on XML, it is amenable to the panoply of |
| 273 |
XML tools. |
| 274 |
|
| 275 |
Various graph drawing and manipulation packages either |
| 276 |
use GXL or GML as their main graph language, or provide a translator. |
| 277 |
In this, \gviz\ is no different. We supply the programs |
| 278 |
{\tt gv2gxl}, {\tt gxl2gv}, {\tt gv2gml} and {\tt gml2gv} |
| 279 |
for converting between the DOT and |
| 280 |
these formats. Thus, if an application is XML-based, to use the |
| 281 |
\gviz\ tools, it needs to insert these filters as appropriate between |
| 282 |
its I/O and the \gviz\ layout programs. |
| 283 |
|
| 284 |
\subsection{\gviz\ as a library} |
| 285 |
The role of this document is to describe how an application can use the |
| 286 |
\gviz\ software as a library rather than as a set of programs. It will |
| 287 |
describe the intended API at various levels, concentrating on the purpose |
| 288 |
of the functions from an application standpoint, and the way the |
| 289 |
library functions should be used together, e.g., that one has to call |
| 290 |
function A before function B. The intention is not to provide |
| 291 |
detailed manual pages, partly because most of the functions have a high-level |
| 292 |
interface, often just taking a graph pointer as the sole argument. |
| 293 |
The real semantic details are embedded in the |
| 294 |
attributes of the graph, which are described elsewhere. |
| 295 |
|
| 296 |
The remainder of this manual describes how to build an application |
| 297 |
using \gviz\ as a library in the usual sense. |
| 298 |
The next section presents the basic technique for using the \gviz\ code. Since |
| 299 |
the other approaches are merely ramifications and extensions of the |
| 300 |
basic approach, the section also serves as an overview for all uses. |
| 301 |
Section~\ref{sec:layouts} breaks each layout algorithm apart into |
| 302 |
its individual steps. |
| 303 |
With this information, the application has the option of eliminating |
| 304 |
certain of the steps. For example, all of the layout algorithms can |
| 305 |
layout edges as splines. If the application intends to draw all edges |
| 306 |
as line segments, it would probably wish to avoid the spline computation, |
| 307 |
especially as it is moderately expensive in terms of time. |
| 308 |
Section~\ref{sec:layout_info} explains how an application can invoke the |
| 309 |
\gviz\ renderers, thereby generating a drawing of a graph in |
| 310 |
a concrete graphics format such as {\em png} or {\em PostScript}. |
| 311 |
For an application intending to do its own rendering, |
| 312 |
Section~\ref{sec:renderers} recommends a technique which allows the |
| 313 |
\gviz\ library to handle all of the bookkeeping details related to |
| 314 |
data structures and machine-dependent representations while the |
| 315 |
application need only supply a few basic graphics functions. |
| 316 |
Section~\ref{sec:unconnect} |
| 317 |
discusses an auxiliary library for dealing with graphs containing |
| 318 |
multiple connected components. |
| 319 |
|
| 320 |
{\bf N.B. Using \gviz\ as a library is not thread-safe.} |