From: ellson Date: Wed, 23 Nov 2005 13:21:52 +0000 (+0000) Subject: add another example to dot.demo/ X-Git-Tag: LAST_LIBGRAPH~32^2~6946 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9b6ff746969ad14d2de5a6104263ce89051796cd;p=graphviz add another example to dot.demo/ --- diff --git a/dot.demo/Makefile b/dot.demo/Makefile index 01ca2f84e..2fc3e58e9 100644 --- a/dot.demo/Makefile +++ b/dot.demo/Makefile @@ -1,11 +1,12 @@ CFLAGS=`pkg-config libgvc --cflags` -Wall -g -O2 LDFLAGS=-Wl,--rpath -Wl,`pkg-config libgvc --variable=libdir` `pkg-config libgvc --libs` -all: dot demo simple +all: dot demo simple example dot: dot.o demo: demo.o simple: simple.o +example: example.o clean: - rm -rf *.o dot demo simple *.png + rm -rf *.o dot demo simple example *.png diff --git a/dot.demo/example.c b/dot.demo/example.c new file mode 100644 index 000000000..f3bf184ad --- /dev/null +++ b/dot.demo/example.c @@ -0,0 +1,49 @@ +#include + +#define NO_LAYOUT_OR_RENDERING + +int main(int argc, char **argv) +{ + Agraph_t *g; + Agnode_t *n, *m; + Agedge_t *e; + Agsym_t *a; + +#ifdef NO_LAYOUT_OR_RENDERING + aginit(); +#else + /* set up a graphviz context - but only once even for multiple graphs */ + static GVC_t *gvc; + + if (!gvc) + gvc = gvContext(); +#endif + + /* Create a simple digraph */ + g = agopen("g", AGDIGRAPH); + n = agnode(g, "n"); + m = agnode(g, "m"); + e = agedge(g, n, m); + + /* Set an attribute - in this case one that affects the visible rendering */ + if (!(a = agfindattr(g->proto->n, "color"))) + a = agnodeattr(g, "color", ""); + agxset(n, a->index, "red"); + +#ifdef NO_LAYOUT_OR_RENDERING + /* Just write the graph without layout */ + agwrite(g, stdout); +#else + /* Use the directed graph layout engine */ + gvLayout(gvc, g, "dot"); + + /* Output in .dot format */ + gvRender(gvc, g, "dot", stdout); + + gvFreeLayout(gvc, g); +#endif + + agclose(g); + + return 0; +}