From bae54e43b21b732a368426fe1ff4517fc9c3e01a Mon Sep 17 00:00:00 2001 From: Frank Wuerthwein Date: Fri, 8 May 2009 23:45:53 +0000 Subject: Move format_time from rrdFlot into rrdFlotSupport --- src/lib/rrdFlot.js | 38 +------------------------------------- src/lib/rrdFlotSupport.js | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 37 deletions(-) diff --git a/src/lib/rrdFlot.js b/src/lib/rrdFlot.js index e57ff6d..bc9a8a6 100644 --- a/src/lib/rrdFlot.js +++ b/src/lib/rrdFlot.js @@ -138,42 +138,6 @@ rrdFlot.prototype.createHTML = function() { // ====================================== // Populate RRA and RD info rrdFlot.prototype.populateRes = function() { - function format_time(s) { - if (s<120) { - return s+"s"; - } else { - var s60=s%60; - var m=(s-s60)/60; - if ((m<10) && (s60>9)) { - return m+":"+s60+"min"; - } if (m<120) { - return m+"min"; - } else { - var m60=m%60; - var h=(m-m60)/60; - if ((h<12) && (m60>9)) { - return h+":"+m60+"h"; - } if (h<48) { - return h+"h"; - } else { - var h24=h%24; - var d=(h-h24)/24; - if ((d<7) && (h24>0)) { - return d+" days "+h24+"h"; - } if (d<60) { - return d+" days"; - } else { - var d30=d%30; - var mt=(d-d30)/30; - return mt+" months"; - } - } - } - - } - } - - var form_el=document.getElementById(this.res_id); // First clean up anything in the element @@ -186,7 +150,7 @@ rrdFlot.prototype.populateRes = function() { var step=rra.getStep(); var rows=rra.getNrRows(); var period=step*rows; - var rra_label=format_time(step)+" ("+format_time(period)+" total)"; + var rra_label=rfs_format_time(step)+" ("+rfs_format_time(period)+" total)"; form_el.appendChild(new Option(rra_label,i)); } }; diff --git a/src/lib/rrdFlotSupport.js b/src/lib/rrdFlotSupport.js index ec460fd..3110eda 100644 --- a/src/lib/rrdFlotSupport.js +++ b/src/lib/rrdFlotSupport.js @@ -261,3 +261,41 @@ rrdFlotSelection.prototype.trim_data = function(data_list) { return out_data; }; +// ====================================== +// Miscelabeous helper functions +// ====================================== + +function rfs_format_time(s) { + if (s<120) { + return s+"s"; + } else { + var s60=s%60; + var m=(s-s60)/60; + if ((m<10) && (s60>9)) { + return m+":"+s60+"min"; + } if (m<120) { + return m+"min"; + } else { + var m60=m%60; + var h=(m-m60)/60; + if ((h<12) && (m60>9)) { + return h+":"+m60+"h"; + } if (h<48) { + return h+"h"; + } else { + var h24=h%24; + var d=(h-h24)/24; + if ((d<7) && (h24>0)) { + return d+" days "+h24+"h"; + } if (d<60) { + return d+" days"; + } else { + var d30=d%30; + var mt=(d-d30)/30; + return mt+" months"; + } + } + } + + } +} -- cgit v1.1-4-g5e80