Hi Luca,

This does a little bit of type cleaning and some minor cleanups in graph.c's
drawBar() function. It also fixes an overflow in the y-axis labels of graphs
generated by drawBar(). The labels would overflow at 4Gb. I'm running with
this for 2 weeks now, no problems.

--
Robbert

--- graph.c.original    2003-07-25 17:46:42.000000000 +0200
+++ graph.c     2003-07-28 10:46:23.000000000 +0200
@@ -172,12 +172,10 @@
             char  *labels[],              /* slice labels */
             float data[]) {
   gdImagePtr im;
-  int black, white, colors[64], numColors, i;
-  float maxval=0;
-  int center_x, center_y;
-  float total, yscale, txtsz, txtht;
-  unsigned long vmargin, hmargin, base, xsize, ysize, ngrid, dydat, dypix,
ydat, xpos, ypos;
-  unsigned long padding, ymax, ymin, xmax, xmin, gray;
+  int black, white, gray, colors[64], numColors, i, ngrid, base, padding;
+  int center_x, center_y, vmargin, hmargin, xsize, ysize, xpos, ypos,
dypix;
+  float maxval, total, yscale, txtsz, txtht;
+  float dydat, xmax, ymax, xmin, ymin;

   im = gdImageCreate(width, height);

@@ -190,9 +188,10 @@
   }

   /* ******************************* */
+  maxval = 0;
   for(i=0, total=0; i<num_points; i++) {
     total += data[i];
-    if(data[i] > maxval) maxval =  data[i];
+    if(data[i] > maxval) maxval = data[i];
   }

   center_x = width/3, center_y = height/2;
@@ -213,27 +212,16 @@
   dydat = maxval / ngrid; // data units between grid lines
   dypix = ysize / (ngrid + 1); // pixels between grid lines

+  // make y-axis text label from height of grid line (in data units)
   for (i = 0; i <= (ngrid + 1); i++) {
     char *theStr;
-    char str[16];
-
-    // height of grid line in units of data
-    ydat = (int)(i * dydat);
-
-    if(0) {
-      snprintf(str, sizeof(str), "%d", ydat);
-      theStr = str;
-    } else {
-      Counter c = ydat;
-      theStr = formatBytes(c, 0);
-    }
-
-    // height of grid line in pixels
-    ypos = vmargin + ysize - (int)(i*dypix);

+    theStr = formatBytes(i * dydat, 0); // make label text
     txtsz = gdFontSmall->w*strlen(theStr); // pixel-width of label
     txtht = gdFontSmall->h; // pixel-height of label

+    // height of grid line in pixels
+    ypos = vmargin + ysize - (i*dypix);
     xpos = hmargin - 10 - txtsz;
     if(xpos < 1) xpos = 1;

_______________________________________________
Ntop-dev mailing list
[EMAIL PROTECTED]
http://listgateway.unipi.it/mailman/listinfo/ntop-dev

Reply via email to