diff options
author | infirit <[email protected]> | 2014-12-18 14:19:49 +0100 |
---|---|---|
committer | infirit <[email protected]> | 2014-12-18 14:19:49 +0100 |
commit | 32ebc9dbe372feb278080958901f998ef81d5125 (patch) | |
tree | 6336fa0496c7f750a046b5da7a6426ddc16e00fb | |
parent | 9b315b69304482298749dd5a3bf527df9154f75a (diff) | |
download | mate-system-monitor-32ebc9dbe372feb278080958901f998ef81d5125.tar.bz2 mate-system-monitor-32ebc9dbe372feb278080958901f998ef81d5125.tar.xz |
Fixed logic for scaling net load when using bits
Taken from GSM commit: c3c986f6c888a274278a1e5a112befedc23abc6d
From: Conor O'Gorman <[email protected]>
Gnome bug: https://bugzilla.gnome.org/show_bug.cgi?id=656840
-rw-r--r-- | src/load-graph.cpp | 46 |
1 files changed, 39 insertions, 7 deletions
diff --git a/src/load-graph.cpp b/src/load-graph.cpp index 918ebd7..fd8817d 100644 --- a/src/load-graph.cpp +++ b/src/load-graph.cpp @@ -382,6 +382,33 @@ get_memory (LoadGraph *graph) graph->data[0][1] = swappercent; } +/* Nice Numbers for Graph Labels after Paul Heckbert + nicenum: find a "nice" number approximately equal to x. + Round the number if round=1, take ceiling if round=0 */ + +static double +nicenum (double x, int round) +{ + int expv; /* exponent of x */ + double f; /* fractional part of x */ + double nf; /* nice, rounded fraction */ + + expv = floor( log10(x) ); + f = x/pow( 10.0, expv ); /* between 1 and 10 */ + if (round) { + if ( f < 1.5 ) nf = 1.0; + else if ( f < 3.0 ) nf = 2.0; + else if ( f < 7.0 ) nf = 5.0; + else nf = 10.0; + } else { + if ( f <= 1.0 ) nf = 1.0; + else if ( f <= 2.0 ) nf = 2.0; + else if ( f <= 5.0 ) nf = 5.0; + else nf = 10.0; + } + return nf * pow(10.0, expv); +} + static void net_scale (LoadGraph *graph, guint64 din, guint64 dout) { @@ -407,15 +434,20 @@ net_scale (LoadGraph *graph, guint64 din, guint64 dout) const guint64 bak_max(new_max); if (ProcData::get_instance()->config.network_in_bits) { - // TODO: fix logic to give a nice scale with bits + // nice number is for the ticks + unsigned ticks = graph->num_bars(); - // round up to get some extra space - // yes, it can overflow - new_max = 1.1 * new_max; - // make sure max is not 0 to avoid / 0 - // default to 125 bytes == 1kbit - new_max = std::max(new_max, G_GUINT64_CONSTANT(125)); + // gets messy at low values due to division by 8 + guint64 bit_max = std::max( new_max*8, G_GUINT64_CONSTANT(10000) ); + + // our tick size leads to max + double d = nicenum(bit_max/ticks, 0); + bit_max = ticks * d; + new_max = bit_max / 8; + procman_debug("bak*8 %" G_GUINT64_FORMAT ", ticks %d, d %f" + ", bit_max %" G_GUINT64_FORMAT ", new_max %" G_GUINT64_FORMAT, + bak_max*8, ticks, d, bit_max, new_max ); } else { // round up to get some extra space // yes, it can overflow |