From: Emden R. Gansner Date: Thu, 27 Mar 2014 16:49:39 +0000 (-0400) Subject: Replace scaling from overlap=scale, and make it a general option X-Git-Tag: 2.38.0~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=33696069ea15fdfd492bed2ea2ed16ce1e0cb23e;p=graphviz Replace scaling from overlap=scale, and make it a general option before overlap removal. Thus, we remove the special-purpose code from twopi. In time, this might take on the semantics of overlap_scaling. --- diff --git a/lib/neatogen/adjust.c b/lib/neatogen/adjust.c index c09920860..3b4ffae62 100644 --- a/lib/neatogen/adjust.c +++ b/lib/neatogen/adjust.c @@ -1025,22 +1025,6 @@ setPrismValues (Agraph_t* g, char* s, adjust_data* dp) dp->scaling = late_double(g, agfindgraphattr(g, "overlap_scaling"), -4.0, -1.e10); } -/* setScaleValue: - * Initialize and set scale value - */ -static void -setScaleValue (Agraph_t* g, char* s, adjust_data* dp) -{ - double v; - char* p; - - v = strtod (s, &p); - if (p == s) /* no number */ - dp->scaling = 0; - else - dp->scaling = v; -} - /* getAdjustMode: * Convert string value to internal value of adjustment mode. * If s is NULL or empty, return NONE. @@ -1063,8 +1047,6 @@ static adjust_data *getAdjustMode(Agraph_t* g, char *s, adjust_data* dp) dp->print = ap->print; if (ap->mode == AM_PRISM) setPrismValues (g, s + ap->len, dp); - else if (ap->mode == AM_NSCALE) - setScaleValue (g, s + ap->len, dp); break; } ap++; @@ -1096,18 +1078,33 @@ adjust_data *graphAdjustMode(graph_t *G, adjust_data* dp, char* dflt) return (getAdjustMode (G, am ? am : (dflt ? dflt : ""), dp)); } +#define ISZERO(d) ((fabs(d) < 0.000000001)) + /* simpleScaling: */ -static int simpleScale (graph_t* g, double sc) +static int simpleScale (graph_t* g) { + pointf sc; node_t* n; + int i; + char* p; - if (sc == 1) return 0; - for (n = agfstnode(g); n; n = agnxtnode(g,n)) { - ND_pos(n)[0] *= sc; - ND_pos(n)[1] *= sc; + if ((p = agget(g, "scale"))) { + if ((i = sscanf(p, "%lf,%lf", &sc.x, &sc.y))) { + if (ISZERO(sc.x)) return 0; + if (i == 1) sc.y = sc.x; + else if (ISZERO(sc.y)) return 0; + if ((sc.y == 1) && (sc.x == 1)) return 0; + if (Verbose) + fprintf (stderr, "scale = (%.03f,%.03f)\n", sc.x, sc.y); + for (n = agfstnode(g); n; n = agnxtnode(g,n)) { + ND_pos(n)[0] *= sc.x; + ND_pos(n)[1] *= sc.y; + } + return 1; + } } - return 1; + return 0; } /* removeOverlapWith: @@ -1124,6 +1121,7 @@ removeOverlapWith (graph_t * G, adjust_data* am) return 0; nret = normalize (G); + nret += simpleScale (G); if (am->mode == AM_NONE) return nret; @@ -1135,10 +1133,7 @@ removeOverlapWith (graph_t * G, adjust_data* am) /* start_timer(); */ switch (am->mode) { case AM_NSCALE: - if (am->scaling) - ret = simpleScale(G, am->scaling); - else - ret = scAdjust(G, 1); + ret = scAdjust(G, 1); break; case AM_SCALEXY: ret = scAdjust(G, 0); diff --git a/lib/twopigen/twopiinit.c b/lib/twopigen/twopiinit.c index ab09874a8..a5fabeb82 100644 --- a/lib/twopigen/twopiinit.c +++ b/lib/twopigen/twopiinit.c @@ -51,21 +51,6 @@ static void twopi_init_node_edge(graph_t * g) } } -static void scaleGraph (graph_t * g, node_t* root, pointf sc) -{ - pointf ctr; - node_t* n; - - ctr.x = ND_pos(root)[0]; - ctr.y = ND_pos(root)[1]; - - for (n = agfstnode(g); n; n = agnxtnode (g, n)) { - if (n == root) continue; - ND_pos(n)[0] = sc.x*(ND_pos(n)[0] - ctr.x) + ctr.x; - ND_pos(n)[1] = sc.y*(ND_pos(n)[1] - ctr.y) + ctr.y; - } -} - void twopi_init_graph(graph_t * g) { setEdgeType (g, ET_LINE); @@ -107,8 +92,6 @@ void twopi_layout(Agraph_t * g) if ((r = sscanf (s, "%lf,%lf",&sc.x,&sc.y))) { if (r == 1) sc.y = sc.x; doScale = 1; - if (Verbose) - fprintf (stderr, "scale = (%f,%f)\n", sc.x, sc.y); } } @@ -128,8 +111,6 @@ void twopi_layout(Agraph_t * g) n = agfstnode(g); free(ND_alg(n)); ND_alg(n) = NULL; - if (doScale) - scaleGraph (g, c, sc); adjustNodes(g); spline_edges(g); } else { @@ -147,8 +128,6 @@ void twopi_layout(Agraph_t * g) c = circleLayout(sg, c); if (setRoot && !ctr) ctr = c; - if (doScale) - scaleGraph (sg, c, sc); adjustNodes(sg); } n = agfstnode(g);