0
我有ncurses程序打印帶寬使用的直方圖。我希望它縮放到最小值而不是始終爲0(因此,圖將從最小速度開始,而不是從零開始)。如何縮放ncurses直方圖程序的最小圖形
該圖基本上打印:
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);
}
謝謝!這正是我想要實現的。 – 2014-10-06 12:55:36