【发布时间】:2014-11-30 15:59:22
【问题描述】:
我有一个 ncurses 程序,可以打印带宽使用的直方图。我希望它可以缩放到图形最小值而不是始终为 0(因此图形将从最小速度而不是零开始)。
图表基本上是这样打印的:
if (value / max * lines < currentline)
addch('*');
else
addch(' ');
我怎样才能改变计算,使其最小化图形?
这是完整的图形打印功能:
void printgraphw(WINDOW *win, char *name,
unsigned long *array, unsigned long max, bool siunits,
int lines, int cols, int color) {
int y, x;
werase(win);
box(win, 0, 0);
mvwvline(win, 0, 1, '-', lines-1);
if (name)
mvwprintw(win, 0, cols - 5 - strlen(name), "[ %s ]",name);
mvwprintw(win, 0, 1, "[ %s/s ]", bytestostr(max, siunits));
mvwprintw(win, lines-1, 1, "[ %s/s ]", bytestostr(0.0, siunits));
wattron(win, color);
for (y = 0; y < (lines - 2); y++) {
for (x = 0; x < (cols - 3); x++) {
if (array[x] && max) {
if (lines - 3 - ((double) array[x] / max * lines) < y)
mvwaddch(win, y + 1, x + 2, '*');
}
}
}
wattroff(win, color);
wnoutrefresh(win);
}
【问题讨论】: