| 1 |
\section{The \gviz\ context} |
| 2 |
\label{sec:gvc} |
| 3 |
|
| 4 |
Up to now, we have used a \gviz\ context \gvc\ without |
| 5 |
considering its purpose. As suggested earlier, this value is used |
| 6 |
to store various layout information that is independent of a particular |
| 7 |
graph and its attributes. |
| 8 |
It holds the data associated with plugins, parsed-command lines, |
| 9 |
script engines, and anything else with a scope potentially larger |
| 10 |
than one graph, up to the scope of the application. |
| 11 |
In addition, it maintains lists of the |
| 12 |
available layout algorithms and renderers; it also records the most recent |
| 13 |
layout algorithm applied to a graph. It can be used to specify multiple |
| 14 |
renderings of a given graph layout into different associated files. |
| 15 |
It is also used to store various global information used during |
| 16 |
rendering. |
| 17 |
|
| 18 |
There should be just one \gvc\ created for the entire |
| 19 |
duration of an application. |
| 20 |
A single \gvc\ value can be used with multiple graphs, though |
| 21 |
with only one graph at a time. In addition, if {\tt gvLayout()} |
| 22 |
was invoked for a graph and \gvc, then {\tt gvFreeLayout()} should |
| 23 |
be called before using {\tt gvLayout()} again, even on the same graph. |
| 24 |
|
| 25 |
Normally, one creates a \gvc\ by a call to: |
| 26 |
\begin{verbatim} |
| 27 |
extern GVC_t *gvContext(); |
| 28 |
\end{verbatim} |
| 29 |
which is what we have used in the examples shown here. |
| 30 |
|
| 31 |
One can initialize a \gvc\ to record a list of graphs, layout algorithms |
| 32 |
and renderers. To do this, the application should |
| 33 |
call the function {\tt gvParseArgs}: |
| 34 |
\begin{verbatim} |
| 35 |
extern void gvParseArgs(GVC_t* gvc, int argc, char* argv[]); |
| 36 |
\end{verbatim} |
| 37 |
This function takes the context value, plus an array of strings |
| 38 |
using the same conventions as the parameters to {\tt main} function |
| 39 |
in a C program. In particular, {\tt argc} should be the number of |
| 40 |
values in {\tt argv}. If the base part of {\tt argv[0]} ({\tt argv[0]} with the |
| 41 |
directory portion removed) is the name of one of the |
| 42 |
layout algorithms, this will be bound to the \gvc\ value and used |
| 43 |
at layout time. |
| 44 |
(This can always be overridden by supplying a {\tt "-K"} flag, or by |
| 45 |
supplying a {\tt "layout"} attribute in the graph.) |
| 46 |
The remaining {\tt argv} values, if any, are interpreted exactly like |
| 47 |
the allowed command line flags for any \gviz\ program. |
| 48 |
Thus, {\tt "-T"} can be used to set the output type, and {\tt "-o"} |
| 49 |
can be used to specify the output files. |
| 50 |
|
| 51 |
For example, the application can use a synthetic argument list |
| 52 |
\begin{verbatim} |
| 53 |
GVC_t* gvc = gcContext(); |
| 54 |
char* args[] = { |
| 55 |
"dot", |
| 56 |
"-Tgif", /* gif output */ |
| 57 |
"-oabc.gif" /* output to file abc.gif */ |
| 58 |
}; |
| 59 |
gvParseArgs (gvc, sizeof(args)/sizeof(char*), args); |
| 60 |
\end{verbatim} |
| 61 |
to specify a dot layout in {\tt GIF} output written to the file {\tt abc.gif}. |
| 62 |
Another approach is to use a program's actual argument list, |
| 63 |
after removing flags not handled by \gviz. |
| 64 |
|
| 65 |
Most of the information is stored in a \gvc\ value for use during |
| 66 |
rendering. However, |
| 67 |
if the {\tt argv} array contains non-flag arguments, i.e., strings |
| 68 |
after the first not beginning with {\tt "-"}, these are taken |
| 69 |
to be input files defining a stream of graphs to be drawn. |
| 70 |
These graphs can be accessed by calls to {\tt gvNextInputGraph}. |
| 71 |
|
| 72 |
Once the \gvc\ has been initialized this way, the application can |
| 73 |
call {\tt gvNextInputGraph} to get each input graph in sequence, and |
| 74 |
then invoke {\tt gvLayoutJobs} and {\tt gvRenderJobs} |
| 75 |
to do the specified layouts and renderings. See |
| 76 |
Appendix~\ref{sec:dot} for a typical example of this approach. |
| 77 |
|
| 78 |
We note that {\tt gvLayout} basically attaches the graph |
| 79 |
and layout algorithm to the \gvc, as would be done by |
| 80 |
{\tt gvParseArgs}, and then invokes {\tt gvLayoutJobs}. A similar |
| 81 |
remark holds for {\tt gvRender} and {\tt gvRenderJobs}. |
| 82 |
|
| 83 |
\subsection{Version-specific data} |
| 84 |
\label{sec:info} |
| 85 |
|
| 86 |
When the \gvc\ is created, it stores version and build date information |
| 87 |
that can be used by renderers to identify which version of \gviz\ produced |
| 88 |
the output. It is also what is printed when a layout program is given the {\tt -V} |
| 89 |
flag. This information is stored as an array of three {\tt char*}, giving the |
| 90 |
name, version number and build date, respectively. |
| 91 |
These can be accessed via the functions: |
| 92 |
\begin{verbatim} |
| 93 |
extern char **gvcInfo(GVC_t*); |
| 94 |
extern char *gvcVersion(GVC_t*); |
| 95 |
extern char *gvcBuildDate(GVC_t*); |
| 96 |
\end{verbatim} |
| 97 |
|