From: ellson Date: Fri, 27 Jan 2006 20:12:31 +0000 (+0000) Subject: - add new function render() which is a wrapper for attach_attrs() X-Git-Tag: LAST_LIBGRAPH~32^2~6829 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=419cb36cd1402f0d0cbbe6a3577f741dc1da2377;p=graphviz - add new function render() which is a wrapper for attach_attrs() - add example python script to illustrate --- diff --git a/lib/gvc/gvc.h b/lib/gvc/gvc.h index 899281a5f..762c1c289 100644 --- a/lib/gvc/gvc.h +++ b/lib/gvc/gvc.h @@ -70,6 +70,9 @@ extern int gvLayout(GVC_t *gvc, graph_t *g, char *engine); /* Compute a layout using layout engine from command line args */ extern int gvLayoutJobs(GVC_t *gvc, graph_t *g); +/* Render layout into string attributes of the graph */ +extern void attach_attrs(graph_t *g); + /* Render layout in a specified format to an open FILE */ extern int gvRender(GVC_t *gvc, graph_t *g, char *format, FILE *out); diff --git a/tclpkg/gv/examples/layout.py b/tclpkg/gv/examples/layout.py new file mode 100755 index 000000000..9e1c274d5 --- /dev/null +++ b/tclpkg/gv/examples/layout.py @@ -0,0 +1,25 @@ +#!/usr/bin/python + +# use layout positioning from within script + +import sys +sys.path.append('/usr/lib/graphviz/python') +import gv + +# create a new empty graph +G = gv.digraph("G") + +# define a simple graph ( A->B ) +gv.edge(gv.node(G, "A"),gv.node(G, "B")) + +# compute a directed graph layout +gv.layout(G, 'dot') + +# annotate the graph with the layout information +gv.render(G) + +# do something with the layout +n = gv.firstnode(G) +while gv.ok(n) : + print "node " + gv.nameof(n) + " is at " + gv.getv(n,"pos") + n = gv.nextnode(G,n) diff --git a/tclpkg/gv/gv.cpp b/tclpkg/gv/gv.cpp index 1977b52d9..2445d6a20 100644 --- a/tclpkg/gv/gv.cpp +++ b/tclpkg/gv/gv.cpp @@ -832,25 +832,37 @@ void layout(Agraph_t *g, char *engine) err = gvLayout(gvc, g, engine); } +// annotate the graph with layout information +void render(Agraph_t *g) +{ + attach_attrs(g); +} + +// render to a filename void render(Agraph_t *g, char *format, char *filename) { int err; err = gvRenderFilename(gvc, g, format, filename); - } + +// render to stdout void render(Agraph_t *g, char *format) { int err; err = gvRender(gvc, g, format, stdout); } + +// render to a FILE void render(Agraph_t *g, char *format, FILE *f) { int err; err = gvRender(gvc, g, format, f); } + +// FIXME - render to a caller provided memory blob void render(Agraph_t *g, char *format, void **data) { // FIXME diff --git a/tclpkg/gv/gv.i b/tclpkg/gv/gv.i index 529c1ed7f..58935a72b 100644 --- a/tclpkg/gv/gv.i +++ b/tclpkg/gv/gv.i @@ -181,7 +181,10 @@ extern void rm(Agedge_t *e); extern void layout(Agraph_t *g, char *engine); /** Render */ -/*** Render a graph in a specific format */ +/*** Render a layout into attributes of the graph */ +extern void render(Agraph_t *g); + +/*** Render a layout in a specific format */ extern void render(Agraph_t *g, char *format); extern void render(Agraph_t *g, char *format, char *filename); extern void render(Agraph_t *g, char *format, FILE *f);