From 57ec2122156fb6aad8f478772b9ad31fa1dcff0a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Marchal?= Date: Tue, 18 May 2010 08:33:14 +0000 Subject: [PATCH] Use constants in the plotting of the logarithmic scale --- grepday.c | 50 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/grepday.c b/grepday.c index 4378d27..7d94b1d 100644 --- a/grepday.c +++ b/grepday.c @@ -29,6 +29,14 @@ #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 #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 (valBottomDepth) + 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 (valBottomDepth) { + 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 ; daynpoints ; 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"); -- 2.47.2