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

Tobias Oetiker oetiker at ee.ethz.ch
Thu Jun 16 22:21:43 MEST 2005


Monday Kai Risku wrote:

> Hi!
> The patch made things a little better, but it is still not perfect. Now
> the labels do get a decimal, but there is still some unwanted rounding
> going on.
>
> I inserted the following debug-statement into draw_horizontal_grid:
>
> 	fprintf(stderr, "graph_label = '%s' for %7.4f\n",
> 		graph_label, scaledstep*im->viewfactor*i);
>
> And this is the result:
>
> graph_label = '68.0 G' for 67.9865
> graph_label = '68.2 G' for 68.1728
> graph_label = '68.4 G' for 68.3591
> graph_label = '68.5 G' for 68.5453
> graph_label = '68.7 G' for 68.7316

:-) so how about this:

Index: rrd_graph.c
===================================================================
--- rrd_graph.c (revision 639)
+++ rrd_graph.c (working copy)
@@ -1547,7 +1547,7 @@
            if(decimals <= 0) /* everything is small. make place for zero */
                decimals = 1;

-           im->ygrid_scale.gridstep = pow((double)10, floor(log10(range)));
+           im->ygrid_scale.gridstep = pow((double)10, floor(log10(range*im->viewfactor/im->magfact)))/im->viewfactor*im->magfact;

            if(im->ygrid_scale.gridstep == 0) /* range is one -> 0.1 is reasonable scale */
                im->ygrid_scale.gridstep = 0.1;

cheers
tobi

>
> Some further debugging reveals that this only happens when using base
> 1024, and then I just realized what is happening! The gridlines are
> actually placed on nice even numbers according to base 1000, but then
> the values recalculated to base 1024 become what can be seen in my
> printf-debugging above.
>
> Perhaps this insight gives Tobi enough ideas to come up with a
> definitive fix!
>
> Regards,
> 	Kai
>
> --
> Kai.Risku at arrak.fi     GSM  +358-40-767 8282
> Oy Arrak Software Ab   http://www.arrak.fi
>
>
> > -----Original Message-----
> > From: Tobias Oetiker [mailto:oetiker at ee.ethz.ch]
> > Sent: Sunday, 12 June, 2005 23:37
> > To: Kai Risku
> > Cc: rrd-developers at list.ee.ethz.ch
> > Subject: Re: [rrd-developers] Re: Strange Y labels in 1.2.9 with
> --alt-
> > autoscale
> >
> > 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
>

-- 
 ______    __   _
/_  __/_  / /  (_) 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