Fix gvc graph generator function
This commit is contained in:
parent
72f10015d5
commit
da026219be
2 changed files with 15 additions and 11 deletions
|
@ -11,7 +11,7 @@
|
||||||
#include <gvc.h>
|
#include <gvc.h>
|
||||||
#include "r3.h"
|
#include "r3.h"
|
||||||
|
|
||||||
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(const node * tree, const char *layout, const char * format, FILE *fp);
|
int r3_tree_render(const node * tree, const char *layout, const char * format, FILE *fp);
|
||||||
|
|
||||||
|
|
24
src/gvc.c
24
src/gvc.c
|
@ -12,13 +12,13 @@
|
||||||
#include "r3_gvc.h"
|
#include "r3_gvc.h"
|
||||||
#include "zmalloc.h"
|
#include "zmalloc.h"
|
||||||
|
|
||||||
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) {
|
||||||
edge * e;
|
if (!n)
|
||||||
|
return;
|
||||||
|
|
||||||
for ( int i = 0 ; i < n->edge_len ; i++ ) {
|
for ( int i = 0 ; i < n->edge_len ; i++ ) {
|
||||||
e = n->edges[i];
|
edge * e = n->edges[i];
|
||||||
|
(*node_cnt)++;
|
||||||
node_cnt++;
|
|
||||||
|
|
||||||
Agnode_t *agn_child = NULL;
|
Agnode_t *agn_child = NULL;
|
||||||
Agedge_t *agn_edge = NULL;
|
Agedge_t *agn_edge = NULL;
|
||||||
|
@ -27,7 +27,7 @@ void r3_tree_build_ag_nodes(Agraph_t * g, Agnode_t * ag_parent_node, const node
|
||||||
if ( e && e->child && e->child->combined_pattern ) {
|
if ( e && e->child && e->child->combined_pattern ) {
|
||||||
asprintf(&nodename,"%s", e->child->combined_pattern);
|
asprintf(&nodename,"%s", e->child->combined_pattern);
|
||||||
} else {
|
} else {
|
||||||
asprintf(&nodename,"#%d", node_cnt);
|
asprintf(&nodename,"#%d", *node_cnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
agn_child = agnode(g, nodename, 1);
|
agn_child = agnode(g, nodename, 1);
|
||||||
|
@ -52,11 +52,13 @@ int r3_tree_render(const node * tree, const char *layout, const char * format, F
|
||||||
GVC_t *gvc = NULL;
|
GVC_t *gvc = NULL;
|
||||||
gvc = gvContext();
|
gvc = gvContext();
|
||||||
/* Create a simple digraph */
|
/* Create a simple digraph */
|
||||||
g = agopen("g", Agdirected, 0);
|
// g = agopen("g", Agdirected, 0);
|
||||||
|
g = agopen("g", Agundirected, 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);
|
int n = 0;
|
||||||
|
r3_tree_build_ag_nodes(g, ag_root, tree, &n);
|
||||||
gvLayout(gvc, g, layout);
|
gvLayout(gvc, g, layout);
|
||||||
gvRender(gvc, g, format, fp);
|
gvRender(gvc, g, format, fp);
|
||||||
gvFreeLayout(gvc, g);
|
gvFreeLayout(gvc, g);
|
||||||
|
@ -96,11 +98,13 @@ int r3_tree_render_file(const node * tree, const char * format, const char * fil
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Create a simple digraph */
|
/* Create a simple digraph */
|
||||||
g = agopen("g", Agdirected, 0);
|
// g = agopen("g", Agdirected, 0);
|
||||||
|
g = agopen("g", Agundirected, 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);
|
int n = 0;
|
||||||
|
r3_tree_build_ag_nodes(g, ag_root, tree, &n);
|
||||||
|
|
||||||
gvLayout(gvc, g, "dot");
|
gvLayout(gvc, g, "dot");
|
||||||
gvRenderFilename(gvc, g, format, filename);
|
gvRenderFilename(gvc, g, format, filename);
|
||||||
|
|
Loading…
Reference in a new issue