From e2cec4707c1dca1e487a8f80b0903a696f025e53 Mon Sep 17 00:00:00 2001 From: chris <> Date: Tue, 2 Apr 2002 17:33:10 +0000 Subject: [PATCH] "" --- TODO | 1 + ui.c | 28 +++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/TODO b/TODO index cde3c89..aa82f61 100644 --- a/TODO +++ b/TODO @@ -15,3 +15,4 @@ $Id$ * Configurable sort criteria. * Configurable refresh rates. + diff --git a/ui.c b/ui.c index 03f5113..4abf4b1 100644 --- a/ui.c +++ b/ui.c @@ -70,15 +70,28 @@ void readable_size(float n, char* buf, int bsize, int ksize) { } } -/* Maximum and minimum rate which we plot on the bar chart. */ -static int min_rate = 1; /* 1 byte/s */ -static int max_rate = (10000000); /* 10 Mbit/s */ + +/* Barchart scales. */ +static struct { + int max, interval; +} scale[] = { + { 64000, 10 }, /* 64 kbit/s */ + { 128000, 10 }, + { 256000, 10 }, + { 1000000, 10 }, /* 1 Mbit/s */ + { 10000000, 10 }, + { 100000000, 100 }, + { 1000000000, 100 } /* 1 Gbit/s */ + }; +static int rateidx = 0, wantbiggerrate; static int get_bar_length(const int rate) { float l; if (rate <= 0) return 0; - l = (log(rate) - log(min_rate)) / (log(max_rate) - log(min_rate)); + if (rate > scale[rateidx].max) + wantbiggerrate = 1; + l = log(rate) / log(scale[rateidx].max); return (l * COLS); } @@ -87,7 +100,7 @@ static void draw_bar_scale(int* y) { if(options.showbars) { /* Draw bar graph scale on top of the window. */ mvhline(*y + 1, 0, 0, COLS); - for (i = min_rate; i <= max_rate; i *= 10) { + for (i = 1; i <= scale[rateidx].max; i *= scale[rateidx].interval) { char s[40], *p; int x; readable_size(i, s, sizeof s, 1000); @@ -334,6 +347,11 @@ void ui_print() { refresh(); + /* Bar chart auto scale */ + if (wantbiggerrate) { + ++rateidx; + wantbiggerrate = 0; + } } void ui_init() {