From: erg Date: Fri, 28 Jan 2011 21:24:44 +0000 (+0000) Subject: Allow twopi to note vertex picked as root if not specified X-Git-Tag: LAST_LIBGRAPH~32^2~1082 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=10eb4da7dd932c000d51731e748b2c0fec7a303b;p=graphviz Allow twopi to note vertex picked as root if not specified --- diff --git a/lib/twopigen/circle.c b/lib/twopigen/circle.c index 67714177d..7dcdc52b3 100644 --- a/lib/twopigen/circle.c +++ b/lib/twopigen/circle.c @@ -339,7 +339,7 @@ static void dumpGraph(Agraph_t * g) * Also, if center != 0, we are guaranteed that center is * in the graph. */ -void circleLayout(Agraph_t * sg, Agnode_t * center) +Agnode_t* circleLayout(Agraph_t * sg, Agnode_t * center) { int maxNStepsToCenter; @@ -347,7 +347,7 @@ void circleLayout(Agraph_t * sg, Agnode_t * center) Agnode_t *n = agfstnode(sg); ND_pos(n)[0] = 0; ND_pos(n)[1] = 0; - return; + return center; } initLayout(sg); @@ -367,4 +367,5 @@ void circleLayout(Agraph_t * sg, Agnode_t * center) setAbsolutePos(sg, maxNStepsToCenter); /* dumpGraph (sg); */ + return center; } diff --git a/lib/twopigen/circle.h b/lib/twopigen/circle.h index c54ebb6ad..822f5015f 100644 --- a/lib/twopigen/circle.h +++ b/lib/twopigen/circle.h @@ -39,7 +39,7 @@ extern "C" { #define SPAN(n) (RDATA(n)->span) #define THETA(n) (RDATA(n)->theta) - extern void circleLayout(Agraph_t * sg, Agnode_t * center); + extern Agnode_t* circleLayout(Agraph_t * sg, Agnode_t * center); extern void twopi_layout(Agraph_t * g); extern void twopi_cleanup(Agraph_t * g); extern void twopi_init_graph(graph_t * g); diff --git a/lib/twopigen/twopiinit.c b/lib/twopigen/twopiinit.c index 0d3d5e9b0..b0ee53b7a 100644 --- a/lib/twopigen/twopiinit.c +++ b/lib/twopigen/twopiinit.c @@ -65,14 +65,21 @@ void twopi_layout(Agraph_t * g) { Agnode_t *ctr = 0; char *s; + int setRoot = 0; twopi_init_graph(g); s = agget(g, "root"); - if (s && (*s != '\0')) { - ctr = agfindnode(g, s); - if (!ctr) { - agerr(AGWARN, "specified root node \"%s\" was not found.", s); - agerr(AGPREV, "Using default calculation for root node\n"); + if ((s = agget(g, "root"))) { + if (*s) { + ctr = agfindnode(g, s); + if (!ctr) { + agerr(AGWARN, "specified root node \"%s\" was not found.", s); + agerr(AGPREV, "Using default calculation for root node\n"); + setRoot = 1; + } + } + else { + setRoot = 1; } } if (agnnodes(g)) { @@ -84,7 +91,9 @@ void twopi_layout(Agraph_t * g) ccs = ccomps(g, &ncc, 0); if (ncc == 1) { - circleLayout(g, ctr); + c = circleLayout(g, ctr); + if (setRoot && !ctr) + ctr = c; free(ND_alg(agfstnode(g))); adjustNodes(g); spline_edges(g); @@ -100,7 +109,9 @@ void twopi_layout(Agraph_t * g) else c = 0; nodeInduce(sg); - circleLayout(sg, c); + c = circleLayout(sg, c); + if (setRoot && !ctr) + ctr = c; adjustNodes(sg); setEdgeType (sg, ET_LINE); spline_edges(sg); @@ -113,6 +124,8 @@ void twopi_layout(Agraph_t * g) } free(ccs); } + if (setRoot) + agset (g, "root", agnameof (ctr)); dotneato_postprocess(g); }