/* * Support library aimed at providing commonly used functions and classes * that may be used while plotting RRD files with Flot * * Part of the javascriptRRD package * Copyright (c) 2009 Frank Wuerthwein, fkw@ucsd.edu * * Original repository: http://javascriptrrd.sourceforge.net/ * * MIT License [http://www.opensource.org/licenses/mit-license.php] * */ /* * * Flot is a javascript plotting library developed and maintained by * Ole Laursen [http://www.flotcharts.org/] * */ // Return a Flot-like data structure // Since Flot does not properly handle empty elements, min and max are returned, too function rrdDS2FlotSeries(rrd_file,ds_id,rra_idx,want_rounding) { var ds=rrd_file.getDS(ds_id); var ds_name=ds.getName(); var ds_idx=ds.getIdx(); var rra=rrd_file.getRRA(rra_idx); var rra_rows=rra.getNrRows(); var last_update=rrd_file.getLastUpdate(); var step=rra.getStep(); if (want_rounding!=false) { // round last_update to step // so that all elements are sync last_update-=(last_update%step); } var first_el=last_update-(rra_rows-1)*step; var timestamp=first_el; var flot_series=[]; for (var i=0;imax_ts)) { max_ts=rrd_last_update; } if ((min_ts==null) || (rrd_min_ts=0) && (row_delta no filtering var out_data=[]; for (var i=0; i=this.selection_min) && (nr<=this.selection_max)) { out_data.push(data_list[i]); } } return out_data; }; // Given an array of flot lines, limit to the selection rrdFlotSelection.prototype.trim_flot_timezone_data = function(flot_data,shift) { var out_data=[]; for (var i=0; i no filtering var out_data=[]; for (var i=0; i=this.selection_min) && (nr<=this.selection_max)) { out_data.push(data_list[i]); } } return out_data; }; // ====================================== // Miscelaneous 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"; } } } } }