]> granicus.if.org Git - graphviz/commitdiff
Replace scaling from overlap=scale, and make it a general option
authorEmden R. Gansner <erg@alum.mit.edu>
Thu, 27 Mar 2014 16:49:39 +0000 (12:49 -0400)
committerEmden R. Gansner <erg@alum.mit.edu>
Thu, 27 Mar 2014 16:49:39 +0000 (12:49 -0400)
before overlap removal. Thus, we remove the special-purpose code
from twopi. In time, this might take on the semantics of overlap_scaling.

lib/neatogen/adjust.c
lib/twopigen/twopiinit.c

index c09920860151fd480926ccc0d3d6befb87c3c750..3b4ffae6253b2032795bf3ce831c929a116a33fa 100644 (file)
@@ -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);
index ab09874a8f9bbeb81b1592b52d5536a53d6eefc1..a5fabeb828452017f686b28cffa445a59e04f227 100644 (file)
@@ -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);