From 8fc779ce2eee63fef1d992c11a331c2868fa0e3a Mon Sep 17 00:00:00 2001 From: "Emden R. Gansner" Date: Wed, 26 Mar 2014 17:54:45 -0400 Subject: [PATCH] Add simple scaling option during node adjustment --- lib/neatogen/adjust.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/neatogen/adjust.c b/lib/neatogen/adjust.c index 75e9a3171..c09920860 100644 --- a/lib/neatogen/adjust.c +++ b/lib/neatogen/adjust.c @@ -1025,6 +1025,22 @@ 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. @@ -1047,6 +1063,8 @@ 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++; @@ -1078,6 +1096,20 @@ adjust_data *graphAdjustMode(graph_t *G, adjust_data* dp, char* dflt) return (getAdjustMode (G, am ? am : (dflt ? dflt : ""), dp)); } +/* simpleScaling: + */ +static int simpleScale (graph_t* g, double sc) +{ + node_t* n; + + if (sc == 1) return 0; + for (n = agfstnode(g); n; n = agnxtnode(g,n)) { + ND_pos(n)[0] *= sc; + ND_pos(n)[1] *= sc; + } + return 1; +} + /* removeOverlapWith: * Use adjust_data to determine if and how to remove * node overlaps. @@ -1103,7 +1135,10 @@ removeOverlapWith (graph_t * G, adjust_data* am) /* start_timer(); */ switch (am->mode) { case AM_NSCALE: - ret = scAdjust(G, 1); + if (am->scaling) + ret = simpleScale(G, am->scaling); + else + ret = scAdjust(G, 1); break; case AM_SCALEXY: ret = scAdjust(G, 0); -- 2.50.1