[rrd-developers] Re: Strange Y labels in 1.2.9 with --alt-autoscale

Tobias Oetiker oetiker at ee.ethz.ch
Sun Jun 12 22:36:54 MEST 2005


Hi Kai,

you might want to try this:

Index: rrd_graph.c
===================================================================
--- rrd_graph.c	(revision 620)
+++ rrd_graph.c	(working copy)
@@ -394,7 +394,7 @@
 	      delt = im->maxval - im->minval;
 	      adj = delt * 0.1;
 	      fact = 2.0 * pow(10.0,
-		    floor(log10(max(fabs(im->minval), fabs(im->maxval)))) - 2);
+		    floor(log10(max(fabs(im->minval), fabs(im->maxval))/im->magfact)) - 2);
 	      if (delt < fact) {
 		adj = (fact - delt) * 0.55;
 #ifdef DEBUG
@@ -432,10 +432,6 @@
 		    -sensiblevalues[i] >=scaled_max)
 		    im->maxval = -sensiblevalues[i]*(im->magfact);
 	    }
-	    /* no sensiblevalues found. we switch to ALTYGRID mode */
-	    if (sensiblevalues[i] == 0){
-		im->extra_flags |= ALTYGRID;
-	    }
 	}
     } else {
 	/* adjust min and max to the grid definition if there is one */
@@ -1549,21 +1545,12 @@
     if(isnan(im->ygridstep)){
 	if(im->extra_flags & ALTYGRID) {
 	    /* find the value with max number of digits. Get number of digits */
-	    decimals = ceil(log10(max(fabs(im->maxval), fabs(im->minval))));
+	    decimals = ceil(log10(max(fabs(im->maxval), fabs(im->minval))*im->viewfactor/im->magfact));
 	    if(decimals <= 0) /* everything is small. make place for zero */
 		decimals = 1;

-	    fractionals = floor(log10(range));
-	    if(fractionals < 0) { /* small amplitude. */
-		int len = decimals - fractionals + 1;
-		if (im->unitslength < len) im->unitslength = len;
-		sprintf(im->ygrid_scale.labfmt, "%%%d.%df", len, -fractionals + 1);
-	    } else {
-		int len = decimals + 1;
-		if (im->unitslength < len) im->unitslength = len;
-		sprintf(im->ygrid_scale.labfmt, "%%%d.1f", len);
-	    }
-	    im->ygrid_scale.gridstep = pow((double)10, (double)fractionals);
+	    im->ygrid_scale.gridstep = pow((double)10, floor(log10(range)));
+
 	    if(im->ygrid_scale.gridstep == 0) /* range is one -> 0.1 is reasonable scale */
 		im->ygrid_scale.gridstep = 0.1;
 	    /* should have at least 5 lines but no more then 15 */
@@ -1580,6 +1567,16 @@
 		im->ygrid_scale.gridstep /= 5;
 		im->ygrid_scale.labfact = 5;
 	    }
+	    fractionals = floor(log10(im->ygrid_scale.gridstep*(double)im->ygrid_scale.labfact*im->viewfactor/im->magfact));
+	    if(fractionals < 0) { /* small amplitude. */
+		int len = decimals - fractionals + 1;
+		if (im->unitslength < len+2) im->unitslength = len+2;
+		sprintf(im->ygrid_scale.labfmt, "%%%d.%df%s", len, -fractionals,(im->symbol != ' ' ? " %c" : ""));
+	    } else {
+		int len = decimals + 1;
+		if (im->unitslength < len+2) im->unitslength = len+2;
+		sprintf(im->ygrid_scale.labfmt, "%%%d.1f%s", len, ( im->symbol != ' ' ? " %c" : "" ));
+	    }
 	}
 	else {
 	    for(i=0;ylab[i].grid > 0;i++){
@@ -1624,23 +1621,27 @@
        if ( Y0 >= im->yorigin-im->ysize
 	         && Y0 <= im->yorigin){
 	    if(i % im->ygrid_scale.labfact == 0){
-		if (i==0 || im->symbol == ' ') {
-		    if(MaxY < 10) {
-			if(im->extra_flags & ALTYGRID) {
-			    sprintf(graph_label,im->ygrid_scale.labfmt,scaledstep*im->viewfactor*i);
-			}
-			else {
-			    sprintf(graph_label,"%4.1f",scaledstep*im->viewfactor*i);
-			}
-		    } else {
-			sprintf(graph_label,"%4.0f",scaledstep*im->viewfactor*i);
-		    }
+		if (im->symbol == ' ') {
+ 		    if(im->extra_flags & ALTYGRID) {
+		        sprintf(graph_label,im->ygrid_scale.labfmt,scaledstep*im->viewfactor*i);
+                    } else {
+                        if(MaxY < 10) {
+		           sprintf(graph_label,"%4.1f",scaledstep*im->viewfactor*i);
+  		        } else {
+			   sprintf(graph_label,"%4.0f",scaledstep*im->viewfactor*i);
+		        }
+                    }
 		}else {
-		    if(MaxY < 10){
-			sprintf(graph_label,"%4.1f %c",scaledstep*im->viewfactor*i, im->symbol);
-		    } else {
-			sprintf(graph_label,"%4.0f %c",scaledstep*im->viewfactor*i, im->symbol);
-		    }
+		    char sisym = ( i == 0  ? ' ' : im->symbol);
+ 		    if(im->extra_flags & ALTYGRID) {
+		        sprintf(graph_label,im->ygrid_scale.labfmt,scaledstep*im->viewfactor*i,sisym);
+                    } else {
+  		        if(MaxY < 10){
+		   	  sprintf(graph_label,"%4.1f %c",scaledstep*im->viewfactor*i, sisym);
+		        } else {
+		   	  sprintf(graph_label,"%4.0f %c",scaledstep*im->viewfactor*i, sisym);
+		        }
+                    }
 		}

 	       gfx_new_text ( im->canvas,

-- 
 ______    __   _
/_  __/_  / /  (_) Oetiker @ ISG.EE, ETL F24.2, ETH, CH-8092 Zurich
 / // _ \/ _ \/ /  System Manager, Time Lord, Coder, Designer, Coach
/_/ \.__/_.__/_/   http://people.ee.ethz.ch/oetiker +41(0)44-632-5286

--
Unsubscribe mailto:rrd-developers-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-developers-request at list.ee.ethz.ch?subject=help
Archive     http://lists.ee.ethz.ch/rrd-developers
WebAdmin    http://lists.ee.ethz.ch/lsg2.cgi



More information about the rrd-developers mailing list