diff options
author | Jo-Philipp Wich <jo@mein.io> | 2018-07-03 10:56:50 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2018-07-03 10:58:14 +0200 |
commit | 7b43e67219a7d7204bd006b5a7cb8b72d07f156c (patch) | |
tree | 1bfd0889e4841ab4241d133a25f46e0c1d1650f1 /modules/luci-mod-admin-full | |
parent | 9f2672f2cc0f07ef9ea431bd9294036df2bed7c9 (diff) |
luci-mod-admin-full: improve Y-axis scaling in bandwidth graph
Calculate a peak that causes the vertical scale to use even values.
Fixes #1424.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-mod-admin-full')
-rw-r--r-- | modules/luci-mod-admin-full/luasrc/view/admin_status/bandwidth.htm | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/modules/luci-mod-admin-full/luasrc/view/admin_status/bandwidth.htm b/modules/luci-mod-admin-full/luasrc/view/admin_status/bandwidth.htm index b7594bfd4..ba0ab0f68 100644 --- a/modules/luci-mod-admin-full/luasrc/view/admin_status/bandwidth.htm +++ b/modules/luci-mod-admin-full/luasrc/view/admin_status/bandwidth.htm @@ -209,10 +209,16 @@ data_rx_avg = (data_rx_avg / Math.max(data_rx.length, 1)); data_tx_avg = (data_tx_avg / Math.max(data_tx.length, 1)); + var size = Math.floor(Math.log2(data_max)), + div = Math.pow(2, size - (size % 10)), + mult = data_max / div, + mult = (mult < 5) ? 2 : ((mult < 50) ? 10 : ((mult < 500) ? 100 : 1000)); + + data_max = data_max + (mult * div) - (data_max % (mult * div)); + /* remember current timestamp, calculate horizontal scale */ data_stamp = data[data.length-1][TIME]; - data_scale = height / (data_max * 1.1); - + data_scale = height / data_max; /* plot data */ var pt_rx = '0,' + height; @@ -239,9 +245,9 @@ line_rx.setAttribute('points', pt_rx); line_tx.setAttribute('points', pt_tx); - label_25.firstChild.data = bandwidth_label(1.1 * 0.25 * data_max); - label_50.firstChild.data = bandwidth_label(1.1 * 0.50 * data_max); - label_75.firstChild.data = bandwidth_label(1.1 * 0.75 * data_max); + label_25.firstChild.data = bandwidth_label(0.25 * data_max); + label_50.firstChild.data = bandwidth_label(0.50 * data_max); + label_75.firstChild.data = bandwidth_label(0.75 * data_max); label_rx_cur.innerHTML = bandwidth_label(data_rx[data_rx.length-1], true); label_tx_cur.innerHTML = bandwidth_label(data_tx[data_tx.length-1], true); |