From 4ac3d74fd381bb89d31dd191e7efd24b756b56ea Mon Sep 17 00:00:00 2001 From: c9s Date: Tue, 3 Jun 2014 18:41:55 +0800 Subject: [PATCH] more graphviz API --- include/r3_gvc.h | 4 +++- src/gvc.c | 32 +++++++++++++++++++++----------- tests/check_gvc.c | 2 +- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/include/r3_gvc.h b/include/r3_gvc.h index 1cd0765..4d2b56f 100644 --- a/include/r3_gvc.h +++ b/include/r3_gvc.h @@ -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); diff --git a/src/gvc.c b/src/gvc.c index 6975fef..e24a555 100644 --- a/src/gvc.c +++ b/src/gvc.c @@ -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); diff --git a/tests/check_gvc.c b/tests/check_gvc.c index 7f3371b..ae43a60 100644 --- a/tests/check_gvc.c +++ b/tests/check_gvc.c @@ -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); }