[rrd-developers] [PATCH] sane logarithmic y-scale labels

Ian Morgan imorgan at webcon.net
Fri Aug 9 02:29:27 MEST 2002


The old "1e+nn" labels were really annoying me to no end, so, as goaded by
one mailing list post on rrd-users
(http://www.ee.ethz.ch/~slist/rrd-users/msg02951.html), I patched
rrd_graph.c myself. It's not entirely thorough, but certainly does the job
well here for use with MRTG traffic graphs. Adapt and apply as you see fit.
Applies to 1.0.39.

Now you get:

old	new
1e+00	1
1e+01	10
1e+02	100
1e+03	1 k
1e+04	10 k
1e+05	100 k
1e+06	1 M
1e+07	10 M
1e+08	100 M
1e+09	1 G
1e+10	10 G
1e+11	100 G
1e+12	1 T
1e+13	10 T
1e+14	100 T
1e+15	1 P
1e+16	10 P
1e+17	100 P
1e+18	1 E
1e+19	10 E
1e+20	100 E
1e+21	1000 E 
1e+22	10000 E
1e+23	100000 E
1e+24	1000000 E
...


Regards,
Ian Morgan
-- 
-------------------------------------------------------------------
 Ian E. Morgan        Vice President & C.O.O.         Webcon, Inc.
 imorgan at webcon.ca          PGP: #2DA40D07           www.webcon.ca
    *  Customized Linux network solutions for your business  *
-------------------------------------------------------------------


--- src/rrd_graph.c.orig	Wed Aug  7 02:50:53 2002
+++ src/rrd_graph.c	Wed Aug  7 04:33:24 2002
@@ -1970,6 +1970,8 @@
     gdPoint  polyPoints[4];
     int      styleMinor[2],styleMajor[2];
     double   value, pixperstep, minstep;
+    double   tvalue;
+    char     tvalsymbol;
 
     /* find grid spaceing */
     pixpex= (double)im->ysize / (log10(im->maxval) - log10(im->minval));
@@ -2038,7 +2040,37 @@
 	    
 	    gdImageLine(gif, polyPoints[0].x,polyPoints[0].y,
 			polyPoints[1].x,polyPoints[0].y,gdStyled);
-	    sprintf(graph_label,"%3.0e",value * yloglab[majoridx][i]);
+
+	    /* Make log scale labels sane using SI units */
+	    tvalue = value * yloglab[majoridx][i];
+	    tvalsymbol='x';
+	    if (tvalue >= 1e18) {
+	      tvalsymbol = 'E';
+	      tvalue /= 1e18;
+	    } else if (tvalue >= 1e15) {
+	      tvalsymbol = 'P';
+	      tvalue /= 1e15;
+	    } else if (tvalue >= 1e12) {
+	      tvalsymbol = 'T';
+	      tvalue /= 1e12;
+	    } else if (tvalue >= 1e9) {
+	      tvalsymbol = 'G';
+	      tvalue /= 1e9;
+	    } else if (tvalue >= 1e6) {
+	      tvalsymbol = 'M';
+	      tvalue /= 1e6;
+	    } else if (tvalue >= 1e3) {
+	      tvalsymbol = 'k';
+	      tvalue /= 1e3;
+	    }
+	    
+	    /* sprintf(graph_label,"%3.0e",tvalue); */
+	    if ( tvalsymbol == 'x' ) {
+	      sprintf(graph_label, "%.0f", tvalue);
+	    } else {
+	      sprintf(graph_label, "%.0f %c", tvalue, tvalsymbol);
+	    }
+
 	    gdImageString(gif, SmallFont,
 			  (polyPoints[0].x - (strlen(graph_label) * 
 					      SmallFont->w)-7), 

--
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://www.ee.ethz.ch/~slist/rrd-developers
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



More information about the rrd-developers mailing list