Unbroke bar graph scales. bits vs bytes. Argh.
This commit is contained in:
22
ui.c
22
ui.c
@@ -187,16 +187,17 @@ void readable_size(float n, char* buf, int bsize, int ksize, int bytes) {
|
|||||||
static struct {
|
static struct {
|
||||||
int max, interval;
|
int max, interval;
|
||||||
} scale[] = {
|
} scale[] = {
|
||||||
{ 8000, 10 }, /* 64 kbit/s */
|
{ 64000, 10 }, /* 64 kbit/s */
|
||||||
{ 16000, 10 },
|
{ 128000, 10 },
|
||||||
{ 32000, 10 },
|
{ 256000, 10 },
|
||||||
{ 125000, 10 }, /* 1 Mbit/s */
|
{ 1000000, 10 }, /* 1 Mbit/s */
|
||||||
{ 1250000, 10 },
|
{ 10000000, 10 },
|
||||||
{ 12500000, 100 },
|
{ 100000000, 100 },
|
||||||
{ 125000000, 100 } /* 1 Gbit/s */
|
{ 1000000000, 100 } /* 1 Gbit/s */
|
||||||
};
|
};
|
||||||
static int rateidx = 0, wantbiggerrate;
|
static int rateidx = 0, wantbiggerrate;
|
||||||
|
|
||||||
|
/* rate in bits */
|
||||||
static int get_bar_length(const int rate) {
|
static int get_bar_length(const int rate) {
|
||||||
float l;
|
float l;
|
||||||
if (rate <= 0)
|
if (rate <= 0)
|
||||||
@@ -208,18 +209,19 @@ static int get_bar_length(const int rate) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void draw_bar_scale(int* y) {
|
static void draw_bar_scale(int* y) {
|
||||||
int i;
|
float i;
|
||||||
if(options.showbars) {
|
if(options.showbars) {
|
||||||
/* Draw bar graph scale on top of the window. */
|
/* Draw bar graph scale on top of the window. */
|
||||||
move(*y, 0);
|
move(*y, 0);
|
||||||
clrtoeol();
|
clrtoeol();
|
||||||
mvhline(*y + 1, 0, 0, COLS);
|
mvhline(*y + 1, 0, 0, COLS);
|
||||||
for (i = 1; i <= scale[rateidx].max; i *= scale[rateidx].interval) {
|
/* i in bytes */
|
||||||
|
for (i = 1.25; i * 8 <= scale[rateidx].max; i *= scale[rateidx].interval) {
|
||||||
char s[40], *p;
|
char s[40], *p;
|
||||||
int x;
|
int x;
|
||||||
readable_size(i, s, sizeof s, 1000, 0);
|
readable_size(i, s, sizeof s, 1000, 0);
|
||||||
p = s + strspn(s, " ");
|
p = s + strspn(s, " ");
|
||||||
x = get_bar_length(i);
|
x = get_bar_length(i * 8);
|
||||||
mvaddch(*y + 1, x, ACS_BTEE);
|
mvaddch(*y + 1, x, ACS_BTEE);
|
||||||
if (x + strlen(p) >= COLS)
|
if (x + strlen(p) >= COLS)
|
||||||
x = COLS - strlen(p);
|
x = COLS - strlen(p);
|
||||||
|
|||||||
Reference in New Issue
Block a user