]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Use constants in the plotting of the logarithmic scale
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Tue, 18 May 2010 08:33:14 +0000 (08:33 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Tue, 18 May 2010 08:33:14 +0000 (08:33 +0000)
grepday.c

index 4378d278bad8d825fcae7b0fce38bcb00dc23460..7d94b1d16bd1ba4c732d10529f418bcb7c6828f3 100644 (file)
--- a/grepday.c
+++ b/grepday.c
 
 #if defined(HAVE_GD)
 
+//! The constant ln(1024).
+#define LOG1024 6.931471805599453084
+
+//! The constant to convert back a linearized binary scale (must be exp(LOGBIN)).
+#define EXPBIN 1024.
+//! The constant to linearise the logarithmic binary scale.
+#define LOGBIN LOG1024
+
 #if defined(HAVE_ICONV_H) && defined(gdFTEX_Unicode)
 #include <iconv.h>
 #define USE_ICONV 1
@@ -244,10 +252,13 @@ static void bar(struct GraphDataStruct *gdata,int x1,double y,const char *label)
    int width2;
 
    val=gdata->BottomGraph+5-(int)(y*gdata->YScale+0.5);
-
    width2=(int)(gdata->XScale/4.);
-   gdImageFilledRectangle(gdata->im, x1-width2, val, x1+width2, gdata->BottomDepth, gdata->color3);
 
+   // front side of the bar
+   if (val<gdata->BottomDepth)
+      gdImageFilledRectangle(gdata->im, x1-width2, val, x1+width2, gdata->BottomDepth, gdata->color3);
+
+   // top side of the bar
    points[0].x = x1-width2+5;
    points[0].y = val-5;
    points[1].x = x1-width2;
@@ -264,15 +275,18 @@ static void bar(struct GraphDataStruct *gdata,int x1,double y,const char *label)
 
    Sarg_gdImageStringFT(gdata,gdata->black,GraphFont,6,0.0,x1+2,val-12,label,TRP_BottomCenter);
 
-   points[0].x = x1+width2+5;
-   points[0].y = val-5;
-   points[1].x = x1+width2;
-   points[1].y = val;
-   points[2].x = x1+width2;
-   points[2].y = gdata->BottomDepth;
-   points[3].x = x1+width2+5;
-   points[3].y = gdata->BottomGraph;
-   gdImageFilledPolygon(gdata->im, points, 4, gdata->color2);
+   // lateral side of the bar
+   if (val<gdata->BottomDepth) {
+      points[0].x = x1+width2+5;
+      points[0].y = val-5;
+      points[1].x = x1+width2;
+      points[1].y = val;
+      points[2].x = x1+width2;
+      points[2].y = gdata->BottomDepth;
+      points[3].x = x1+width2+5;
+      points[3].y = gdata->BottomGraph;
+      gdImageFilledPolygon(gdata->im, points, 4, gdata->color2);
+   }
 
    return;
 }
@@ -303,10 +317,10 @@ static int greport_compute_yaxis(struct PlotStruct *pdata,struct GraphDataStruct
 
       case PTG_LogBin:
          if (pdata->ymin>0.)
-            symin=log(pdata->ymin)/log(1024);
+            symin=log(pdata->ymin)/LOGBIN;
          else
             symin=0.;
-         symax=log(pdata->ymax)/log(1024);
+         symax=log(pdata->ymax)/LOGBIN;
          ymag=1024.;
          break;
 
@@ -383,7 +397,7 @@ static void greport_draw_yaxis(struct PlotStruct *pdata,struct GraphDataStruct *
             break;
 
          case PTG_LogBin:
-            yval=pow(1024.,(double)(y0-y)/gdata->YScale+log(pdata->ymin)/log(1024));
+            yval=pow(EXPBIN,(double)(y0-y)/gdata->YScale+log(pdata->ymin)/LOGBIN);
             greport_formatbin(yval,2,YLabel,sizeof(YLabel));
             break;
 
@@ -424,6 +438,7 @@ static void greport_plot(const struct userinfostruct *uinfo,struct PlotStruct *p
    const int ZTickLength=5;
    double yval;
    char blabel[50];
+   double logpmin;
 
    memset(&gdata,0,sizeof(gdata));
 
@@ -555,6 +570,7 @@ static void greport_plot(const struct userinfostruct *uinfo,struct PlotStruct *p
    Sarg_gdImageStringFT(&gdata,gdata.black,GraphFont,10,3.141592/2,15,ImgYSize/2,pdata->YLabel,TRP_CenterLeft);
    Sarg_gdImageStringFT(&gdata,gdata.black,GraphFont,10,0.0,ImgXSize/2,ImgYSize-20,pdata->XLabel,TRP_BottomCenter);
 
+   logpmin=(pdata->ytype==PTG_LogBin && pdata->ymin>0.) ? log(pdata->ymin) : 0.;
    for (day=0 ; day<pdata->npoints ; day++) {
       if (pdata->datapoints[day]>0) {
          x1=gdata.LeftGraph-10+(int)((double)(day+1)*gdata.XScale+0.5);
@@ -575,9 +591,9 @@ static void greport_plot(const struct userinfostruct *uinfo,struct PlotStruct *p
                if (yval<=pdata->ymin)
                   yval=0.;
                else if (yval>pdata->ymax)
-                  yval=log(pdata->ymax)/log(1024)-log(pdata->ymin)/log(1024);
+                  yval=(log(pdata->ymax)-logpmin)/LOGBIN;
                else
-                  yval=log(yval)/log(1024)-log(pdata->ymin)/log(1024);
+                  yval=(log(yval)-logpmin)/LOGBIN;
                greport_formatbin(pdata->datapoints[day],1,blabel,sizeof(blabel));
                break;
             case PTG_Time:
@@ -695,7 +711,7 @@ void greport_day(const struct userinfostruct *uinfo)
    pdata.npoints=31;
    pdata.XLabel=_("DAYS");
    if(datetimeby==DATETIME_BYTE) {
-      pdata.ymin=20LL*1024LL;
+      pdata.ymin=50LL*1024LL;
       pdata.ymax=5LL*1024LL*1024LL*1024LL;
       pdata.ytype=PTG_LogBin;
       pdata.YLabel=_("BYTES");