]> granicus.if.org Git - graphviz/commitdiff
add another example to dot.demo/
authorellson <devnull@localhost>
Wed, 23 Nov 2005 13:21:52 +0000 (13:21 +0000)
committerellson <devnull@localhost>
Wed, 23 Nov 2005 13:21:52 +0000 (13:21 +0000)
dot.demo/Makefile
dot.demo/example.c [new file with mode: 0644]

index 01ca2f84e829b2368185944e3da1106075f42a2a..2fc3e58e90e10773b641e66dcfc3a2b019431316 100644 (file)
@@ -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 (file)
index 0000000..f3bf184
--- /dev/null
@@ -0,0 +1,49 @@
+#include <gvc.h>
+
+#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;
+}