more graphviz API

This commit is contained in:
c9s 2014-06-03 18:41:55 +08:00
parent b68e14dd66
commit 4ac3d74fd3
3 changed files with 25 additions and 13 deletions

View file

@ -12,7 +12,9 @@
void r3_tree_build_ag_nodes(Agraph_t * g, Agnode_t * ag_parent_node, const node * n, int node_cnt);
int r3_tree_render_dot(const node * tree, FILE *fp);
int r3_tree_render(const node * tree, const char *layout, const char * format, FILE *fp);
int r3_tree_render_dot(const node * tree, const char *layout, FILE *fp);
int r3_tree_render_file(const node * tree, const char * format, const char * filename);

View file

@ -41,27 +41,23 @@ void r3_tree_build_ag_nodes(Agraph_t * g, Agnode_t * ag_parent_node, const node
/**
* Render a tree to tree graph image via graphviz (dot)
*/
int r3_tree_render_dot(const node * tree, FILE *fp)
int r3_tree_render(const node * tree, const char *layout, const char * format, FILE *fp)
{
Agraph_t *g;
/* set up a graphviz context - but only once even for multiple graphs */
static GVC_t *gvc;
if (!gvc) {
gvc = gvContext();
}
GVC_t *gvc = NULL;
gvc = gvContext();
/* Create a simple digraph */
g = agopen("g", Agdirected, 0);
// create self node
Agnode_t *ag_root = agnode(g, "{root}", 1);
r3_tree_build_ag_nodes(g, ag_root, tree, 0);
gvLayout(gvc, g, "dot");
gvRender(gvc, g, "dot", fp);
gvLayout(gvc, g, layout);
gvRender(gvc, g, format, fp);
gvFreeLayout(gvc, g);
agclose(g);
return 0;
@ -70,6 +66,17 @@ int r3_tree_render_dot(const node * tree, FILE *fp)
/**
* Render a tree to tree graph image via graphviz (dot)
*/
int r3_tree_render_dot(const node * tree, const char *layout, FILE *fp)
{
return r3_tree_render(tree, layout, "dot", fp);
}
/**
* Render a tree to tree graph image via graphviz (dot)
*/
@ -77,12 +84,15 @@ int r3_tree_render_file(const node * tree, const char * format, const char * fil
{
Agraph_t *g;
/* set up a graphviz context - but only once even for multiple graphs */
GVC_t *gvc = NULL;
gvc = gvContext();
/*
// set up a graphviz context - but only once even for multiple graphs
static GVC_t *gvc;
if (!gvc) {
gvc = gvContext();
}
*/
/* Create a simple digraph */
g = agopen("g", Agdirected, 0);

View file

@ -27,7 +27,7 @@ START_TEST (test_gvc_render_dot)
r3_tree_compile(n, NULL);
r3_tree_render_dot(n, stderr);
r3_tree_render_dot(n, "dot", stderr);
r3_tree_free(n);
}