#include "common.h"
#include "vnstati.h"
#include "misc.h"
#include "image.h"
void initimagecontent(IMAGECONTENT *ic)
{
ic->showheader = 1;
ic->showedge = 1;
ic->showlegend = 1;
ic->altdate = 0;
ic->headertext[0] = '\0';
}
void drawimage(IMAGECONTENT *ic)
{
switch (cfg.qmode) {
case 1:
drawdaily(ic);
break;
case 2:
drawmonthly(ic);
break;
case 3:
drawtop(ic);
break;
case 5:
if (cfg.slayout) {
drawsummary(ic, 0, 0);
} else {
drawoldsummary(ic, 0, 0);
}
break;
case 51:
if (cfg.slayout) {
drawsummary(ic, 1, cfg.hourlyrate);
} else {
drawoldsummary(ic, 1, cfg.hourlyrate);
}
break;
case 52:
if (cfg.slayout) {
drawsummary(ic, 2, cfg.hourlyrate);
} else {
drawoldsummary(ic, 2, cfg.hourlyrate);
}
break;
case 7:
drawhourly(ic, cfg.hourlyrate);
break;
default:
break;
}
/* enable background transparency if needed */
if (cfg.transbg) {
gdImageColorTransparent(ic->im, ic->cbackground);
}
}
void colorinit(IMAGECONTENT *ic)
{
int rgb[3];
/* text, edge and header colors */
hextorgb(cfg.ctext, rgb);
ic->ctext = gdImageColorAllocate(ic->im, rgb[0], rgb[1], rgb[2]);
colorinitcheck("ctext", ic->ctext, cfg.ctext, rgb);
hextorgb(cfg.cedge, rgb);
ic->cedge = gdImageColorAllocate(ic->im, rgb[0], rgb[1], rgb[2]);
colorinitcheck("cedge", ic->cedge, cfg.cedge, rgb);
hextorgb(cfg.cheader, rgb);
ic->cheader = gdImageColorAllocate(ic->im, rgb[0], rgb[1], rgb[2]);
colorinitcheck("cheader", ic->cheader, cfg.cheader, rgb);
hextorgb(cfg.cheadertitle, rgb);
ic->cheadertitle = gdImageColorAllocate(ic->im, rgb[0], rgb[1], rgb[2]);
colorinitcheck("cheadertitle", ic->cheadertitle, cfg.cheadertitle, rgb);
hextorgb(cfg.cheaderdate, rgb);
ic->cheaderdate = gdImageColorAllocate(ic->im, rgb[0], rgb[1], rgb[2]);
colorinitcheck("cheaderdate", ic->cheaderdate, cfg.cheaderdate, rgb);
/* lines */
hextorgb(cfg.cline, rgb);
ic->cline = gdImageColorAllocate(ic->im, rgb[0], rgb[1], rgb[2]);
colorinitcheck("cline", ic->cline, cfg.cline, rgb);
if (cfg.clinel[0] == '-') {
modcolor(rgb, 50, 1);
} else {
hextorgb(cfg.clinel, rgb);
}
ic->clinel = gdImageColorAllocate(ic->im, rgb[0], rgb[1], rgb[2]);
colorinitcheck("clinel", ic->clinel, cfg.clinel, rgb);
/* background */
hextorgb(cfg.cbg, rgb);
ic->cbackground = gdImageColorAllocate(ic->im, rgb[0], rgb[1], rgb[2]);
colorinitcheck("cbackground", ic->cbackground, cfg.cbg, rgb);
modcolor(rgb, -35, 0);
ic->cvnstat = gdImageColorAllocate(ic->im, rgb[0], rgb[1], rgb[2]);
colorinitcheck("cvnstat", ic->cvnstat, cfg.cbg, rgb);
hextorgb(cfg.cbg, rgb);
modcolor(rgb, -15, 0);
ic->cbgoffset = gdImageColorAllocate(ic->im, rgb[0], rgb[1], rgb[2]);
colorinitcheck("cbgoffset", ic->cbgoffset, cfg.cbg, rgb);
/* rx */
hextorgb(cfg.crx, rgb);
ic->crx = gdImageColorAllocate(ic->im, rgb[0], rgb[1], rgb[2]);
colorinitcheck("crx", ic->crx, cfg.crx, rgb);
if (cfg.crxd[0] == '-') {
modcolor(rgb, -50, 1);
} else {
hextorgb(cfg.crxd, rgb);
}
ic->crxd = gdImageColorAllocate(ic->im, rgb[0], rgb[1], rgb[2]);
colorinitcheck("crxd", ic->crxd, cfg.crxd, rgb);
/* tx */
hextorgb(cfg.ctx, rgb);
ic->ctx = gdImageColorAllocate(ic->im, rgb[0], rgb[1], rgb[2]);
colorinitcheck("ctx", ic->ctx, cfg.ctx, rgb);
if (cfg.ctxd[0] == '-') {
modcolor(rgb, -50, 1);
} else {
hextorgb(cfg.ctxd, rgb);
}
ic->ctxd = gdImageColorAllocate(ic->im, rgb[0], rgb[1], rgb[2]);
colorinitcheck("ctxd", ic->ctxd, cfg.ctxd, rgb);
}
void colorinitcheck(const char *color, int value, const char *cfgtext, const int *rgb)
{
if (value==-1) {
printf("Error: ImageColorAllocate failed.\n");
printf(" C: \"%s\" T: \"%s\" RGB: %d/%d/%d\n", color, cfgtext, rgb[0], rgb[1], rgb[2]);
exit(EXIT_FAILURE);
}
}
void layoutinit(IMAGECONTENT *ic, char *title, int width, int height)
{
struct tm *d;
char datestring[64];
/* get time in given format */
d = localtime(&data.lastupdated);
strftime(datestring, 64, cfg.hformat, d);
/* background, edges */
gdImageFill(ic->im, 0, 0, ic->cbackground);
if (ic->showedge) {
gdImageRectangle(ic->im, 0, 0, width-1, height-1, ic->cedge);
}
/* titlebox with title */
if (ic->showheader) {
gdImageFilledRectangle(ic->im, 2+ic->showedge, 2+ic->showedge, width-3-ic->showedge, 24, ic->cheader);
gdImageString(ic->im, gdFontGetGiant(), 12, 5+ic->showedge, (unsigned char*)title, ic->cheadertitle);
}
/* date */
if (!ic->showheader || ic->altdate) {
gdImageString(ic->im, gdFontGetTiny(), 5+ic->showedge, height-12-ic->showedge, (unsigned char*)datestring, ic->cvnstat);
} else {
gdImageString(ic->im, gdFontGetTiny(), width-(((int)strlen(datestring))*gdFontGetTiny()->w+12), 9+ic->showedge, (unsigned char*)datestring, ic->cheaderdate);
}
/* generator */
gdImageString(ic->im, gdFontGetTiny(), width-114-ic->showedge, height-12-ic->showedge, (unsigned char*)"vnStat / Teemu Toivola", ic->cvnstat);
}
void drawlegend(IMAGECONTENT *ic, int x, int y)
{
if (!ic->showlegend) {
return;
}
/* color legend */
gdImageString(ic->im, gdFontGetSmall(), x, y, (unsigned char*)"rx tx", ic->ctext);
gdImageFilledRectangle(ic->im, x-12, y+4, x-6, y+10, ic->crx);
gdImageRectangle(ic->im, x-12, y+4, x-6, y+10, ic->ctext);
gdImageFilledRectangle(ic->im, x+30, y+4, x+36, y+10, ic->ctx);
gdImageRectangle(ic->im, x+30, y+4, x+36, y+10, ic->ctext);
}
void drawbar(IMAGECONTENT *ic, int x, int y, int len, uint64_t rx, int rxk, uint64_t tx, int txk, uint64_t max)
{
int l;
rx=mbkbtokb(rx, rxk);
tx=mbkbtokb(tx, txk);
if ((rx+tx)!=max) {
len=((rx+tx)/(float)max)*len;
}
if (len!=0) {
if (tx>rx) {
l=rintf((rx/(float)(rx+tx)*len));
gdImageFilledRectangle(ic->im, x, y+YBEGINOFFSET, x+l, y+YENDOFFSET, ic->crx);
gdImageRectangle(ic->im, x, y+YBEGINOFFSET, x+l, y+YENDOFFSET, ic->crxd);
gdImageFilledRectangle(ic->im, x+l, y+YBEGINOFFSET, x+len, y+YENDOFFSET, ic->ctx);
gdImageRectangle(ic->im, x+l, y+YBEGINOFFSET, x+len, y+YENDOFFSET, ic->ctxd);
} else {
l=rintf((tx/(float)(rx+tx)*len));
gdImageFilledRectangle(ic->im, x, y+YBEGINOFFSET, x+(len-l), y+YENDOFFSET, ic->crx);
gdImageRectangle(ic->im, x, y+YBEGINOFFSET, x+(len-l), y+YENDOFFSET, ic->crxd);
gdImageFilledRectangle(ic->im, x+(len-l), y+YBEGINOFFSET, x+len, y+YENDOFFSET, ic->ctx);
gdImageRectangle(ic->im, x+(len-l), y+YBEGINOFFSET, x+len, y+YENDOFFSET, ic->ctxd);
}
}
}
void drawpole(IMAGECONTENT *ic, int x, int y, int len, uint64_t rx, uint64_t tx, uint64_t max)
{
int l;
l = (rx/(float)max)*len;
gdImageFilledRectangle(ic->im, x, y+(len-l), x+7, y+len, ic->crx);
l = (tx/(float)max)*len;
gdImageFilledRectangle(ic->im, x+5, y+(len-l), x+12, y+len, ic->ctx);
}
void drawdonut(IMAGECONTENT *ic, int x, int y, float rxp, float txp)
{
int rxarc = 0, txarc = 0;
if ( (int)(rxp + txp) > 0 ) {
rxarc = 360 * (rxp / (float)100);
if ( (int)(rxp + txp) == 100 ) {
txarc = 360 - rxarc;
} else {
txarc = 360 * (txp / (float)100);
}
/* fix possible graphical glitch */
if (!rxarc) {
rxarc = 1;
}
if (!txarc) {
txarc = 1;
}
}
gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 0, 360, ic->cbgoffset, 0);
if ( (int)(rxp + txp) > 0 ) {
gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270, 270+txarc, ic->ctx, 0);
gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270, 270+txarc, ic->ctxd, gdEdged|gdNoFill);
gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270+txarc, 270+txarc+rxarc, ic->crx, 0);
gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270+txarc, 270+txarc+rxarc, ic->crxd, gdEdged|gdNoFill);
gdImageFilledArc(ic->im, x, y, DINRAD, DINRAD, 270, 270+txarc, ic->ctxd, gdEdged|gdNoFill);
gdImageFilledArc(ic->im, x, y, DINRAD, DINRAD, 270+txarc, 270+txarc+rxarc, ic->crxd, gdEdged|gdNoFill);
}
gdImageFilledArc(ic->im, x, y, DINRAD-2, DINRAD-2, 0, 360, ic->cbackground, 0);
}
void drawhours(IMAGECONTENT *ic, int x, int y, int rate)
{
int i, tmax=0, s=0, step, prev=0, diff=0, chour;
flo
没有合适的资源?快使用搜索试试~ 我知道了~
vnstat-1.18.tar.gz
需积分: 5 0 下载量 146 浏览量
2024-03-14
11:40:43
上传
评论
收藏 237KB GZ 举报
温馨提示
共93个文件
h:28个
c:28个
vnstat:4个
openwrt的dl库,下载软件代码包
资源推荐
资源详情
资源评论
收起资源包目录
vnstat-1.18.tar.gz (93个子文件)
vnstat-1.18
compile 7KB
configure 202KB
CHANGES 13KB
README 2KB
INSTALL_OSX 2KB
man
vnstat.1 14KB
vnstatd.1 8KB
vnstati.1 6KB
vnstat.conf.5 10KB
aclocal.m4 49KB
UPGRADE 1KB
test-driver 4KB
INSTALL_BSD 5KB
src
dbshow.h 390B
cfg.h 468B
misc.h 743B
fs.c 5KB
ibw.h 282B
misc.c 9KB
cfg.c 22KB
dbaccess.c 20KB
vnstati.h 441B
daemon.h 928B
config.h.in 6KB
image.h 2KB
dbshow.c 33KB
vnstati.c 11KB
common.c 6KB
image.c 45KB
dbcache.h 570B
dbcache.c 6KB
vnstat.c 31KB
common.h 8KB
id.h 188B
dbjson.c 3KB
ifinfo.c 14KB
id.c 2KB
dbjson.h 254B
vnstat.h 985B
vnstatd.c 7KB
fs.h 481B
ifinfo.h 681B
traffic.c 11KB
traffic.h 141B
ibw.c 4KB
dbaccess.h 662B
dbxml.h 231B
dbmerge.h 168B
daemon.c 16KB
vnstatd.h 66B
dbxml.c 3KB
dbmerge.c 4KB
configure.ac 3KB
tests
config_tests.c 6KB
daemon_tests.c 22KB
fs_tests.c 4KB
ifinfo_tests.h 88B
id_tests.h 76B
vnstat_tests.h 1KB
config_tests.h 88B
misc_tests.h 82B
fs_tests.h 76B
id_tests.c 1KB
ifinfo_tests.c 16KB
database_tests.h 94B
vnstat_tests.c 7KB
database_tests.c 31KB
misc_tests.c 12KB
common_tests.h 88B
common_tests.c 9KB
daemon_tests.h 125B
examples
launchd
net.humdi.vnstat.plist 631B
init.d
ubuntu
vnstat 3KB
redhat
vnstat 1KB
debian
vnstat 3KB
centos
vnstat 1KB
vnstat.cgi 5KB
systemd
vnstat.service 542B
vnstat-json.cgi 778B
vnstat-json.php 741B
upstart
vnstat.conf 164B
config.sub 35KB
Makefile.in 113KB
config.guess 44KB
INSTALL 6KB
install-sh 14KB
cfg
vnstat.conf 4KB
FAQ 4KB
UNINSTALL 346B
Makefile.am 5KB
COPYING 18KB
missing 7KB
depcomp 23KB
共 93 条
- 1
资源评论
Cool2Feel
- 粉丝: 187
- 资源: 188
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功