From 91765b1419fcb78da8c4625580a939c9a095e346 Mon Sep 17 00:00:00 2001 From: Frank Wuerthwein Date: Fri, 1 May 2009 02:59:27 +0000 Subject: Add rrdRRAStackFlotObj --- src/lib/rrdFlotSupport.js | 114 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) diff --git a/src/lib/rrdFlotSupport.js b/src/lib/rrdFlotSupport.js index 2fd7268..634604c 100644 --- a/src/lib/rrdFlotSupport.js +++ b/src/lib/rrdFlotSupport.js @@ -88,7 +88,121 @@ function rrdRRA2FlotObj(rrd_file,rra_idx,ds_list,want_ds_labels,want_rounding) { flot_el.label= ds_name; } out_el.data.push(flot_el); + } //end for ds_list_idx + return out_el; +} + +// return an object with an array containing Flot elements +// have a positive and a negative stack of DSes, plus DSes with no stacking +// min and max are also returned +// If one_undefined_enough==true, a whole stack is invalidated is a single element +// of the stack is invalid +function rrdRRAStackFlotObj(rrd_file,rra_idx, + ds_positive_stack_list,ds_negative_stack_list,ds_single_list, + want_ds_labels,want_rounding,one_undefined_enough) { + 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); + } + if (one_undefined_enough!=true) { // make sure it is a boolean + one_undefined_enough=false; } + + var first_el=last_update-(rra_rows-1)*step; + + var out_el={data:[], min:first_el*1000.0, max:last_update*1000.0}; + + // first the stacks stack + var stack_els=[ds_positive_stack_list,ds_negative_stack_list]; + for (stack_list_id in stack_els) { + var stack_list=stack_els[stack_list_id]; + var tmp_flot_els=[]; + var tmp_ds_ids=[]; + var tmp_nr_ids=stack_list.length; + for (ds_list_idx in stack_list) { + var ds_id=stack_list[ds_list_idx]; + var ds=rrd_file.getDS(ds_id); + var ds_name=ds.getName(); + var ds_idx=ds.getIdx(); + tmp_ds_ids.append(ds_idx); // getting this is expensive, call only once + + // initialize + var flot_el={data:[]} + if (want_ds_labels!=false) { + var ds_name=ds.getName(); + flot_el.label= ds_name; + } + tmp_flot_els.append(flot_el); + } + + var timestamp=first_el; + for (var row=0;row