image.c (vnstat-2.8) | : | image.c (vnstat-2.9) | ||
---|---|---|---|---|
skipping to change at line 111 | skipping to change at line 111 | |||
} | } | |||
gdImageDestroy(ic->im); | gdImageDestroy(ic->im); | |||
ic->im = im_scaled; | ic->im = im_scaled; | |||
} | } | |||
#endif | #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 rate) | |||
{ | { | |||
int i, tmax = 0, s = 0, step, prev = 0, diff = 0, chour; | int i, tmax = 0, s = 0, step, prev = 0, diff = 0, chour; | |||
int x = xpos, y = ypos, extrax = 0, extray = 0; | int x = xpos, y = ypos, extrax = 0, extray = 0, xt = 0; | |||
double ratediv; | double ratediv; | |||
uint64_t max = 1, scaleunit = 0; | uint64_t max = 1, scaleunit = 0; | |||
char buffer[32]; | char buffer[32]; | |||
struct tm *d; | struct tm *d; | |||
dbdatalist *datalist = NULL, *datalist_i = NULL; | dbdatalist *datalist = NULL, *datalist_i = NULL; | |||
dbdatalistinfo datainfo; | dbdatalistinfo datainfo; | |||
HOURDATA hourdata[24]; | HOURDATA hourdata[24]; | |||
gdFontPtr font; | gdFontPtr font; | |||
if (ic->large) { | if (ic->large) { | |||
font = gdFontGetSmall(); | font = gdFontGetSmall(); | |||
} else { | } else { | |||
font = gdFontGetTiny(); | font = gdFontGetTiny(); | |||
} | } | |||
for (i = 0; i < 24; i++) { | for (i = 0; i < 24; i++) { | |||
hourdata[i].rx = hourdata[i].tx = 0; | hourdata[i].rx = hourdata[i].tx = 0; | |||
hourdata[i].date = 0; | hourdata[i].date = 0; | |||
} | } | |||
if (!db_getdata(&datalist, &datainfo, ic->interface.name, "hour", 24) || | if (cfg.hourlygmode == 0) { | |||
datainfo.count == 0) { | buffer[0] = '\0'; | |||
} else { | ||||
snprintf(buffer, 32, "today"); | ||||
} | ||||
if (!db_getdata_range(&datalist, &datainfo, ic->interface.name, "hour", 2 | ||||
4, buffer, "") || datainfo.count == 0) { | ||||
gdImageString(ic->im, ic->font, x + (32 * ic->font->w), y + 54, ( unsigned char *)"no data available", ic->ctext); | gdImageString(ic->im, ic->font, x + (32 * ic->font->w), y + 54, ( unsigned char *)"no data available", ic->ctext); | |||
return 0; | return 0; | |||
} | } | |||
datalist_i = datalist; | datalist_i = datalist; | |||
while (datalist_i != NULL) { | while (datalist_i != NULL) { | |||
d = localtime(&datalist_i->timestamp); | d = localtime(&datalist_i->timestamp); | |||
if (hourdata[d->tm_hour].date != 0 || ic->interface.updated - dat alist_i->timestamp > 86400) { | if (hourdata[d->tm_hour].date != 0 || ic->interface.updated - dat alist_i->timestamp > 86400) { | |||
datalist_i = datalist_i->next; | datalist_i = datalist_i->next; | |||
skipping to change at line 218 | skipping to change at line 224 | |||
/* scale values */ | /* scale values */ | |||
scaleunit = getscale(max, rate); | scaleunit = getscale(max, rate); | |||
s = (int)lrint(((double)scaleunit / (double)max) * (124 + extray)); | s = (int)lrint(((double)scaleunit / (double)max) * (124 + extray)); | |||
if (s < SCALEMINPIXELS) { | if (s < SCALEMINPIXELS) { | |||
step = 2; | step = 2; | |||
} else { | } else { | |||
step = 1; | step = 1; | |||
} | } | |||
xt = x + 36; | ||||
for (i = step; i * s <= (124 + extray + 4); i = i + step) { | for (i = step; i * s <= (124 + extray + 4); i = i + step) { | |||
gdImageDashedLine(ic->im, x + 36, y + 124 - (i * s), x + 460 + ex | gdImageDashedLine(ic->im, xt, y + 124 - (i * s), xt + 424 + extra | |||
trax, y + 124 - (i * s), ic->cline); | x, y + 124 - (i * s), ic->cline); | |||
gdImageDashedLine(ic->im, x + 36, y + 124 - prev - (step * s) / 2 | gdImageDashedLine(ic->im, xt, y + 124 - prev - (step * s) / 2, xt | |||
, x + 460 + extrax, y + 124 - prev - (step * s) / 2, ic->clinel); | + 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 i nt)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 i nt)i, 3, rate), ic->ctext); | |||
prev = i * s; | prev = i * s; | |||
} | } | |||
if ((prev + (step * s) / 2) <= (124 + extray + 4)) { | if ((prev + (step * s) / 2) <= (124 + extray + 4)) { | |||
gdImageDashedLine(ic->im, x + 36, y + 124 - prev - (step * s) / 2 , x + 460 + extrax, y + 124 - prev - (step * s) / 2, ic->clinel); | gdImageDashedLine(ic->im, xt, y + 124 - prev - (step * s) / 2, xt + 424 + extrax, y + 124 - prev - (step * s) / 2, ic->clinel); | |||
} | } | |||
/* scale text */ | /* scale text */ | |||
gdImageStringUp(ic->im, font, x - 2 - (ic->large * 14), y + 58 + (rate * 10) - (extray / 2), (unsigned char *)getimagescale(scaleunit * (unsigned int)ste p, rate), ic->ctext); | gdImageStringUp(ic->im, font, x - 2 - (ic->large * 14), y + 58 + (rate * 10) - (extray / 2), (unsigned char *)getimagescale(scaleunit * (unsigned int)ste p, rate), ic->ctext); | |||
/* axis */ | /* axis */ | |||
gdImageLine(ic->im, x + 36 - 4, y + 124, x + 466 + extrax, y + 124, ic->c | gdImageLine(ic->im, xt - 4, y + 124, xt + 430 + extrax, y + 124, ic->ctex | |||
text); | t); | |||
gdImageLine(ic->im, x + 36, y - 10 - extray, x + 36, y + 124 + 4, ic->cte | gdImageLine(ic->im, xt, y - 10 - extray, xt, y + 124 + 4, ic->ctext); | |||
xt); | ||||
/* arrows */ | /* arrows */ | |||
drawarrowup(ic, x + 36, y - 9 - extray); | drawarrowup(ic, xt, y - 9 - extray); | |||
drawarrowright(ic, x + 465 + extrax, y + 124); | drawarrowright(ic, xt + 429 + extrax, y + 124); | |||
xt = x + 440 + extrax; | ||||
/* keep alignment when midnight line isn't shown s*/ | ||||
if (cfg.hourlygmode || tmax - 23 == 0) { | ||||
xt--; | ||||
} | ||||
/* x-axis values and poles */ | /* x-axis values and poles */ | |||
for (i = 0; i < 24; i++) { | for (i = 0; i < 24; i++) { | |||
s = tmax - i; | if (cfg.hourlygmode == 0) { | |||
if (s < 0) { | s = tmax - i; | |||
s += 24; | if (s < 0) { | |||
s += 24; | ||||
} | ||||
} else { | ||||
s = 23 - i; | ||||
} | } | |||
snprintf(buffer, 32, "%02d ", s); | snprintf(buffer, 32, "%02d ", s); | |||
if (hourdata[s].date == 0) { | if (hourdata[s].date == 0) { | |||
chour = ic->cline; | chour = ic->cline; | |||
} else { | } else { | |||
chour = ic->ctext; | chour = ic->ctext; | |||
} | } | |||
gdImageString(ic->im, font, x + 440 - (i * (17 + ic->large * 6)) | gdImageString(ic->im, font, xt, y + 128, (unsigned char *)buffer, | |||
+ extrax, y + 128, (unsigned char *)buffer, chour); | chour); | |||
drawpoles(ic, x + 438 - (i * (17 + ic->large * 6)) + extrax, y - | drawpoles(ic, xt - 2, y - extray, 124 + extray, hourdata[s].rx, h | |||
extray, 124 + extray, hourdata[s].rx, hourdata[s].tx, max); | ourdata[s].tx, max); | |||
gdImageLine(ic->im, x + 438 - 2 - (i * (17 + ic->large * 6)) + ex | gdImageLine(ic->im, xt - 4 - (ic->large * 3), y + 124, xt + 12 + | |||
trax, y + 124, x + 438 + 14 - (i * (17 + ic->large * 6)) + extrax, y + 124, chou | (ic->large * 3), y + 124, chour); | |||
r); | if (s == 0 && i != 23) { | |||
/* midnight line */ | ||||
gdImageLine(ic->im, xt - 5 - (ic->large * 3), y - 5 - ext | ||||
ray, xt - 5 - (ic->large * 3), y + 124 - 1, ic->clinel); | ||||
xt--; | ||||
} | ||||
xt = xt - (17 + ic->large * 6); | ||||
} | } | |||
return 1; | return 1; | |||
} | } | |||
void drawhourly(IMAGECONTENT *ic, const int rate) | void drawhourly(IMAGECONTENT *ic, const int rate) | |||
{ | { | |||
int width, height, headermod = 0; | int width, height, headermod = 0; | |||
width = 500 + (ic->large * 168); | width = 500 + (ic->large * 168); | |||
End of changes. 9 change blocks. | ||||
24 lines changed or deleted | 48 lines changed or added |