Skip to content

Commit

Permalink
improve function parameter names
Browse files Browse the repository at this point in the history
  • Loading branch information
vergoh committed Dec 28, 2023
1 parent 1859aad commit d79acda
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 33 deletions.
38 changes: 19 additions & 19 deletions src/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void scaleimage(IMAGECONTENT *ic)
}
#endif

int drawhours(IMAGECONTENT *ic, const int xpos, const int ypos, const int rate)
int drawhours(IMAGECONTENT *ic, const int xpos, const int ypos, const int israte)
{
int i, tmax = 0, s = 0, step, prev = 0, diff = 0, chour;
int x = xpos, y = ypos, extrax = 0, extray = 0, xt = 0;
Expand Down Expand Up @@ -176,7 +176,7 @@ int drawhours(IMAGECONTENT *ic, const int xpos, const int ypos, const int rate)

for (i = 0; i < 24; i++) {
/* convert hourly transfer to hourly rate if needed */
if (rate) {
if (israte) {
if ((ic->current - hourdata[i].date) > 3600) {
hourdata[i].rx = (uint64_t)((double)hourdata[i].rx / ratediv);
hourdata[i].tx = (uint64_t)((double)hourdata[i].tx / ratediv);
Expand Down Expand Up @@ -219,7 +219,7 @@ int drawhours(IMAGECONTENT *ic, const int xpos, const int ypos, const int rate)
}

/* scale values */
scaleunit = getscale(max, rate);
scaleunit = getscale(max, israte);

s = (int)lrint(((double)scaleunit / (double)max) * (124 + extray));
if (s < SCALEMINPIXELS) {
Expand All @@ -233,15 +233,15 @@ int drawhours(IMAGECONTENT *ic, const int xpos, const int ypos, const int rate)
for (i = step; i * s <= (124 + extray + 4); i = i + step) {
gdImageDashedLine(ic->im, xt, y + 124 - (i * s), xt + 424 + extrax, y + 124 - (i * s), ic->cline);
gdImageDashedLine(ic->im, xt, y + 124 - prev - (step * s) / 2, xt + 424 + extrax, y + 124 - prev - (step * s) / 2, ic->clinel);
gdImageString(ic->im, font, x + 16 - (ic->large * 3), y + 121 - (i * s) - (ic->large * 3), (unsigned char *)getimagevalue(scaleunit * (unsigned int)i, 3, rate), ic->ctext);
gdImageString(ic->im, font, x + 16 - (ic->large * 3), y + 121 - (i * s) - (ic->large * 3), (unsigned char *)getimagevalue(scaleunit * (unsigned int)i, 3, israte), ic->ctext);
prev = i * s;
}
if ((prev + (step * s) / 2) <= (124 + extray + 4)) {
gdImageDashedLine(ic->im, xt, y + 124 - prev - (step * s) / 2, xt + 424 + extrax, y + 124 - prev - (step * s) / 2, ic->clinel);
}

/* scale text */
gdImageStringUp(ic->im, font, x - 2 - (ic->large * 14), y + 58 + (rate * 10) - (extray / 2), (unsigned char *)getimagescale(scaleunit * (unsigned int)step, rate), ic->ctext);
gdImageStringUp(ic->im, font, x - 2 - (ic->large * 14), y + 58 + (israte * 10) - (extray / 2), (unsigned char *)getimagescale(scaleunit * (unsigned int)step, israte), ic->ctext);

/* axis */
gdImageLine(ic->im, xt - 4, y + 124, xt + 430 + extrax, y + 124, ic->ctext);
Expand Down Expand Up @@ -288,7 +288,7 @@ int drawhours(IMAGECONTENT *ic, const int xpos, const int ypos, const int rate)
return 1;
}

void drawhourly(IMAGECONTENT *ic, const int rate)
void drawhourly(IMAGECONTENT *ic, const int israte)
{
int width, height, headermod = 0;

Expand All @@ -303,7 +303,7 @@ void drawhourly(IMAGECONTENT *ic, const int rate)
imageinit(ic, width, height);
layoutinit(ic, " / hourly", width, height);

if (drawhours(ic, 12, 46 - headermod + (ic->large * 40), rate)) {
if (drawhours(ic, 12, 46 - headermod + (ic->large * 40), israte)) {
drawlegend(ic, width / 2 - (ic->large * 10), 183 - headermod + (ic->large * 46), 0);
}
}
Expand Down Expand Up @@ -641,7 +641,7 @@ void drawlist(IMAGECONTENT *ic, const char *listname)
dbdatalistfree(&datalist);
}

void drawsummary(IMAGECONTENT *ic, const int layout, const int rate)
void drawsummary(IMAGECONTENT *ic, const int layout, const int israte)
{
int width, height, headermod;

Expand Down Expand Up @@ -683,17 +683,17 @@ void drawsummary(IMAGECONTENT *ic, const int layout, const int rate)
// horizontal
case 1:
if (cfg.summarygraph == 1) {
drawfiveminutes(ic, 496 + (ic->large * 174), height - 30 - (ic->large * 8), rate, 422 + (ic->large * 154), height - 68 + headermod - (ic->large * 8));
drawfiveminutes(ic, 496 + (ic->large * 174), height - 30 - (ic->large * 8), israte, 422 + (ic->large * 154), height - 68 + headermod - (ic->large * 8));
} else {
drawhours(ic, 500 + (ic->large * 160), 46 + (ic->large * 40) - headermod, rate);
drawhours(ic, 500 + (ic->large * 160), 46 + (ic->large * 40) - headermod, israte);
}
break;
// vertical
case 2:
if (cfg.summarygraph == 1) {
drawfiveminutes(ic, 8 + (ic->large * 14), height - 31 - (ic->large * 6), rate, 422 + (ic->large * 154), 132 + (ic->large * 35));
drawfiveminutes(ic, 8 + (ic->large * 14), height - 31 - (ic->large * 6), israte, 422 + (ic->large * 154), 132 + (ic->large * 35));
} else {
drawhours(ic, 12, 215 + (ic->large * 84) - headermod, rate);
drawhours(ic, 12, 215 + (ic->large * 84) - headermod, israte);
}
break;
default:
Expand Down Expand Up @@ -907,7 +907,7 @@ void drawsummary_digest(IMAGECONTENT *ic, const int x, const int y, const char *
dbdatalistfree(&datalist);
}

void drawfivegraph(IMAGECONTENT *ic, const int rate, const int resultcount, const int height)
void drawfivegraph(IMAGECONTENT *ic, const int israte, const int resultcount, const int height)
{
int imagewidth, imageheight = height, headermod = 0;

Expand All @@ -920,12 +920,12 @@ void drawfivegraph(IMAGECONTENT *ic, const int rate, const int resultcount, cons
imageinit(ic, imagewidth, imageheight);
layoutinit(ic, " / 5 minute", imagewidth, imageheight);

if (drawfiveminutes(ic, 8 + (ic->large * 14), imageheight - 30 - (ic->large * 8), rate, resultcount, imageheight - 68 + headermod - (ic->large * 8))) {
if (drawfiveminutes(ic, 8 + (ic->large * 14), imageheight - 30 - (ic->large * 8), israte, resultcount, imageheight - 68 + headermod - (ic->large * 8))) {
drawlegend(ic, imagewidth / 2 - (ic->large * 10), imageheight - 17 - (ic->large * 2), 0);
}
}

int drawfiveminutes(IMAGECONTENT *ic, const int xpos, const int ypos, const int rate, const int resultcount, const int height)
int drawfiveminutes(IMAGECONTENT *ic, const int xpos, const int ypos, const int israte, const int resultcount, const int height)
{
int x = xpos, y = ypos, i = 0, t = 0, rxh = 0, txh = 0, step = 0, s = 0, prev = 0;
uint64_t scaleunit, max;
Expand Down Expand Up @@ -992,7 +992,7 @@ int drawfiveminutes(IMAGECONTENT *ic, const int xpos, const int ypos, const int
gdImageString(ic->im, font, x - 21 - (ic->large * 3), y - 4 - (ic->large * 3), (unsigned char *)" 0", ic->ctext);

/* scale values */
scaleunit = getscale(max, rate);
scaleunit = getscale(max, israte);

s = (int)lrint(((double)scaleunit / (double)max) * t);
if (s == 0) {
Expand All @@ -1018,7 +1018,7 @@ int drawfiveminutes(IMAGECONTENT *ic, const int xpos, const int ypos, const int
for (i = step; i * s <= rxh; i = i + step) {
gdImageDashedLine(ic->im, x, y - (i * s), x + (resultcount + FIVEMINWIDTHPADDING), y - (i * s), ic->cline);
gdImageDashedLine(ic->im, x, y - prev - (step * s) / 2, x + (resultcount + FIVEMINWIDTHPADDING), y - prev - (step * s) / 2, ic->clinel);
gdImageString(ic->im, font, x - 21 - (ic->large * 3), y - 3 - (i * s) - (ic->large * 3), (unsigned char *)getimagevalue(scaleunit * (unsigned int)i, 3, rate), ic->ctext);
gdImageString(ic->im, font, x - 21 - (ic->large * 3), y - 3 - (i * s) - (ic->large * 3), (unsigned char *)getimagevalue(scaleunit * (unsigned int)i, 3, israte), ic->ctext);
prev = i * s;
}
if ((prev + (step * s) / 2) <= rxh) {
Expand All @@ -1032,7 +1032,7 @@ int drawfiveminutes(IMAGECONTENT *ic, const int xpos, const int ypos, const int
for (i = step; i * s <= txh; i = i + step) {
gdImageDashedLine(ic->im, x, y + (i * s), x + (resultcount + FIVEMINWIDTHPADDING), y + (i * s), ic->cline);
gdImageDashedLine(ic->im, x, y + prev + (step * s) / 2, x + (resultcount + FIVEMINWIDTHPADDING), y + prev + (step * s) / 2, ic->clinel);
gdImageString(ic->im, font, x - 21 - (ic->large * 3), y - 3 + (i * s) - (ic->large * 3), (unsigned char *)getimagevalue(scaleunit * (unsigned int)i, 3, rate), ic->ctext);
gdImageString(ic->im, font, x - 21 - (ic->large * 3), y - 3 + (i * s) - (ic->large * 3), (unsigned char *)getimagevalue(scaleunit * (unsigned int)i, 3, israte), ic->ctext);
prev = i * s;
}
if ((prev + (step * s) / 2) <= txh) {
Expand All @@ -1042,7 +1042,7 @@ int drawfiveminutes(IMAGECONTENT *ic, const int xpos, const int ypos, const int
y--; // y is now back on center line

/* scale text */
gdImageStringUp(ic->im, font, x - 39 - (ic->large * 14), ypos - height / 2 + (rate * 10), (unsigned char *)getimagescale(scaleunit * (unsigned int)step, rate), ic->ctext);
gdImageStringUp(ic->im, font, x - 39 - (ic->large * 14), ypos - height / 2 + (israte * 10), (unsigned char *)getimagescale(scaleunit * (unsigned int)step, israte), ic->ctext);

timestamp = datainfo.maxtime - (resultcount * 300);

Expand Down
10 changes: 5 additions & 5 deletions src/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ void drawimage(IMAGECONTENT *ic);
#if HAVE_DECL_GD_NEAREST_NEIGHBOUR
void scaleimage(IMAGECONTENT *ic);
#endif
int drawhours(IMAGECONTENT *ic, const int xpos, const int ypos, const int rate);
void drawhourly(IMAGECONTENT *ic, const int rate);
int drawhours(IMAGECONTENT *ic, const int xpos, const int ypos, const int israte);
void drawhourly(IMAGECONTENT *ic, const int israte);
void drawlist(IMAGECONTENT *ic, const char *listname);
void drawsummary(IMAGECONTENT *ic, const int layout, const int rate);
void drawsummary(IMAGECONTENT *ic, const int layout, const int israte);
void drawsummary_alltime(IMAGECONTENT *ic, const int x, const int y);
void drawsummary_digest(IMAGECONTENT *ic, const int x, const int y, const char *mode);
void drawfivegraph(IMAGECONTENT *ic, const int rate, const int resultcount, const int height);
int drawfiveminutes(IMAGECONTENT *ic, const int xpos, const int ypos, const int rate, const int resultcount, const int height);
void drawfivegraph(IMAGECONTENT *ic, const int israte, const int resultcount, const int height);
int drawfiveminutes(IMAGECONTENT *ic, const int xpos, const int ypos, const int israte, const int resultcount, const int height);
void draw95thpercentilegraph(IMAGECONTENT *ic, const int mode);
void drawpercentile(IMAGECONTENT *ic, const int mode, const int xpos, const int ypos, const int height);

Expand Down
12 changes: 6 additions & 6 deletions src/image_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ void invertcolor(int *rgb)
}
}

char *getimagevalue(const uint64_t b, const int len, const int rate)
char *getimagevalue(const uint64_t b, const int len, const int israte)
{
static char buffer[64];
int i, declen = 0, unit = 0, p = 1024;
Expand All @@ -512,7 +512,7 @@ char *getimagevalue(const uint64_t b, const int len, const int rate)
if (b == 0) {
snprintf(buffer, 64, "%*s", len, "--");
} else {
if (rate && (getunit() == 2 || getunit() == 4)) {
if (israte && (getunit() == 2 || getunit() == 4)) {
p = 1000;
unit = getunit();
}
Expand All @@ -529,7 +529,7 @@ char *getimagevalue(const uint64_t b, const int len, const int rate)
return buffer;
}

char *getimagescale(const uint64_t b, const int rate)
char *getimagescale(const uint64_t b, const int israte)
{
static char buffer[8];
int unit, div = 1, p = 1024;
Expand All @@ -539,7 +539,7 @@ char *getimagescale(const uint64_t b, const int rate)
if (b == 0) {
snprintf(buffer, 8, "--");
} else {
if (rate) {
if (israte) {
if (unit == 2 || unit == 4) {
p = 1000;
}
Expand All @@ -557,15 +557,15 @@ char *getimagescale(const uint64_t b, const int rate)
return buffer;
}

uint64_t getscale(const uint64_t input, const int rate)
uint64_t getscale(const uint64_t input, const int israte)
{
int i, unit;
unsigned int div = 1024;
uint64_t result = input;

unit = getunit();

if (rate && (unit == 2 || unit == 4)) {
if (israte && (unit == 2 || unit == 4)) {
div = 1000;
}

Expand Down
6 changes: 3 additions & 3 deletions src/image_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ void drawarrowright(IMAGECONTENT *ic, const int x, const int y);
void hextorgb(const char *input, int *rgb);
void modcolor(int *rgb, const int offset, const int force);
void invertcolor(int *rgb);
char *getimagevalue(const uint64_t b, const int len, const int rate);
char *getimagescale(const uint64_t b, const int rate);
uint64_t getscale(const uint64_t input, const int rate);
char *getimagevalue(const uint64_t b, const int len, const int israte);
char *getimagescale(const uint64_t b, const int israte);
uint64_t getscale(const uint64_t input, const int israte);

#endif

0 comments on commit d79acda

Please sign in to comment.