more graphviz API
This commit is contained in:
parent
b68e14dd66
commit
4ac3d74fd3
3 changed files with 25 additions and 13 deletions
|
@ -12,7 +12,9 @@
|
||||||
|
|
||||||
void r3_tree_build_ag_nodes(Agraph_t * g, Agnode_t * ag_parent_node, const node * n, int node_cnt);
|
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);
|
int r3_tree_render_file(const node * tree, const char * format, const char * filename);
|
||||||
|
|
||||||
|
|
32
src/gvc.c
32
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)
|
* 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;
|
Agraph_t *g;
|
||||||
/* set up a graphviz context - but only once even for multiple graphs */
|
/* set up a graphviz context - but only once even for multiple graphs */
|
||||||
static GVC_t *gvc;
|
GVC_t *gvc = NULL;
|
||||||
|
gvc = gvContext();
|
||||||
if (!gvc) {
|
|
||||||
gvc = gvContext();
|
|
||||||
}
|
|
||||||
/* Create a simple digraph */
|
/* Create a simple digraph */
|
||||||
g = agopen("g", Agdirected, 0);
|
g = agopen("g", Agdirected, 0);
|
||||||
|
|
||||||
// create self node
|
// create self node
|
||||||
Agnode_t *ag_root = agnode(g, "{root}", 1);
|
Agnode_t *ag_root = agnode(g, "{root}", 1);
|
||||||
r3_tree_build_ag_nodes(g, ag_root, tree, 0);
|
r3_tree_build_ag_nodes(g, ag_root, tree, 0);
|
||||||
gvLayout(gvc, g, "dot");
|
gvLayout(gvc, g, layout);
|
||||||
gvRender(gvc, g, "dot", fp);
|
gvRender(gvc, g, format, fp);
|
||||||
gvFreeLayout(gvc, g);
|
gvFreeLayout(gvc, g);
|
||||||
agclose(g);
|
agclose(g);
|
||||||
return 0;
|
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)
|
* 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;
|
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;
|
static GVC_t *gvc;
|
||||||
|
|
||||||
if (!gvc) {
|
if (!gvc) {
|
||||||
gvc = gvContext();
|
gvc = gvContext();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/* Create a simple digraph */
|
/* Create a simple digraph */
|
||||||
g = agopen("g", Agdirected, 0);
|
g = agopen("g", Agdirected, 0);
|
||||||
|
|
|
@ -27,7 +27,7 @@ START_TEST (test_gvc_render_dot)
|
||||||
|
|
||||||
r3_tree_compile(n, NULL);
|
r3_tree_compile(n, NULL);
|
||||||
|
|
||||||
r3_tree_render_dot(n, stderr);
|
r3_tree_render_dot(n, "dot", stderr);
|
||||||
|
|
||||||
r3_tree_free(n);
|
r3_tree_free(n);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue