I am making an example program to understand the feasibility of an idea.
What I’m trying to do is to create a graph and use graphviz to calculate the node position.
I wrote this piece of code but it doesn’t seem to work.
What am I doing wrong?
Can someone help me out?
#include <graphviz/gvc.h>
int main(int argc, const char * argv []) {
GVC_t *gvc = gvContext();
// Create a simple digraph
Agraph_t *g = agopen("g", Agdirected, 0);
Agnode_t *n = agnode(g, "n", 1);
Agnode_t *m = agnode(g, "m", 1);
Agedge_t *e = agedge(g, n, m, 0, 1);
// Set an attribute - in this case one that affects the visible rendering
agsafeset(n, "color", "red", "");
// Use the directed graph layout engine
gvLayout(gvc, g, "dot");
printf("%s\n", agget(n, "pos"));
// Free layout data
gvFreeLayout(gvc, g);
// Free graph structures
agclose(g);
// close output file, free context, and return number of errors
gvFreeContext(gvc);
}
In particular, function agget() returns me an empty string.