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.
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++;
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:
return 0;
nret = normalize (G);
+ nret += simpleScale (G);
if (am->mode == AM_NONE)
return nret;
/* 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);
}
}
-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);
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);
}
}
n = agfstnode(g);
free(ND_alg(n));
ND_alg(n) = NULL;
- if (doScale)
- scaleGraph (g, c, sc);
adjustNodes(g);
spline_edges(g);
} else {
c = circleLayout(sg, c);
if (setRoot && !ctr)
ctr = c;
- if (doScale)
- scaleGraph (sg, c, sc);
adjustNodes(sg);
}
n = agfstnode(g);