From 6172f7fa207ffdbb47f9737b25ce72342976387d Mon Sep 17 00:00:00 2001 From: Igor Sfiligoi Date: Thu, 7 Nov 2013 01:33:17 +0000 Subject: Add rrdFlotMatrixAsync --- src/lib/rrdFlotAsync.js | 102 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 85 insertions(+), 17 deletions(-) diff --git a/src/lib/rrdFlotAsync.js b/src/lib/rrdFlotAsync.js index c6d0999..6785867 100644 --- a/src/lib/rrdFlotAsync.js +++ b/src/lib/rrdFlotAsync.js @@ -14,7 +14,7 @@ * binaryXHR.js * rrdFile.js and/or rrdMultiFile.js * optionally rrdFilter.js - * rrdFlot.js + * rrdFlot.js and/or rrdFlotMatrix.js * * Those modules may have other requirements. * @@ -29,7 +29,7 @@ * The object passed as the sole argument is guaranteed to have the following arguments * obj.rrd_data * obj.graph_options - * obj.ds_graph_options + * obj.ds_graph_options or obj.rrd_graph_options * obj.rrdflot_defaults * obj.ds_op_list * obj.rra_op_list @@ -130,6 +130,25 @@ function rrdFlotMultiAsyncCallback(bf,arr) { } } +/* Another internal helper function */ +function rrdFlotMultiAsyncReload(obj,url_list) { + obj.files_needed=url_list.length; + obj.url_list=url_list; + delete obj.loaded_data; + obj.loaded_data=[]; + obj.files_loaded=0; + for (i in url_list) { + try { + FetchBinaryURLAsync(url_list[i],rrdFlotMultiAsyncCallback,[obj,i]); + } catch (err) { + alert("Failed loading "+url_list[i]+". You may get a partial result in the graph.\n"+err); + obj.files_needed--; + } + } +}; + + + /* Use url_list==null if you do not know the urls yet */ function rrdFlotSumAsync(html_id, url_list, graph_options, ds_graph_options, rrdflot_defaults, // see rrdFlot.js::rrdFlot for documentation of these @@ -157,21 +176,8 @@ function rrdFlotSumAsync(html_id, url_list, } } -rrdFlotSumAsync.prototype.reload = function(url_list) { - this.files_needed=url_list.length; - this.url_list=url_list; - delete this.loaded_data; - this.loaded_data=[]; - this.files_loaded=0; - for (i in url_list) { - try { - FetchBinaryURLAsync(url_list[i],rrdFlotMultiAsyncCallback,[this,i]); - } catch (err) { - alert("Failed loading "+url_list[i]+". You may get a partial result in the graph.\n"+err); - this.files_needed--; - } - } -}; +rrdFlotSumAsync.prototype.reload = function(url_list) {rrdFlotMultiAsyncReload(this,url_list);} + rrdFlotSumAsync.prototype.callback = function() { if (this.rrd_flot_obj!=null) delete this.rrd_flot_obj; @@ -193,3 +199,65 @@ rrdFlotSumAsync.prototype.callback = function() { this.rrd_flot_obj=new rrdFlot(this.html_id, rrd_sum, this.graph_options, this.ds_graph_options, this.rrdflot_defaults); }; +// ================================================================================================================ + +/* Use url_list==null if you do not know the urls yet */ +function rrdFlotMatrixAsync(html_id, + url_pair_list, ds_list, // see rrdFlotMatrix.js::rrdFlotMatrix for documentation of these + graph_options, rrd_graph_options, rrdflot_defaults, // see rrdFlotMatrix.js::rrdFlotMatrix for documentation of these + ds_op_list, // if defined, see rrdFilter.js::RRDFilterOp for documentation + rra_op_list, // if defined, see rrdFilter.js::RRDRRAFilterAvg for documentation + customization_callback // if defined, see above + ) { + this.html_id=html_id; + this.url_pair_list=url_pair_list; + this.ds_list=ds_list; + this.graph_options=graph_options; + this.rrd_graph_options=rrd_graph_options; + this.rrdflot_defaults=rrdflot_defaults; + this.ds_op_list=ds_op_list; + this.rra_op_list=rra_op_list; + + this.customization_callback=customization_callback; + + this.rrd_flot_obj=null; + this.rrd_data=null; //rrd_data will contain the data of the first url; still useful to explore the DS and RRA structure + + this.loaded_data=null; + + this.url_list=null; + if (url_pair_list!=null) { + this.reload(url_pair_list); + } +} + +rrdFlotMatrixAsync.prototype.reload = function(url_pair_list) { + this.url_pair_list=url_pair_list; + var url_list=[]; + for (var i in this.url_pair_list) { + url_list.push(this.url_pair_list[i][1]); + } + + rrdFlotMultiAsyncReload(this,url_list); +} + +rrdFlotMatrixAsync.prototype.callback = function() { + if (this.rrd_flot_obj!=null) delete this.rrd_flot_obj; + + var real_data_arr=new Array(); + for (var i in this.loaded_data) { + // account for failed loaded urls + var el=this.loaded_data[i]; + if (el!=undefined) real_data_arr.push([this.url_pair_list[i][0],el]); + } + this.rrd_data=real_data_arr[0]; + + if (this.customization_callback!=undefined) this.customization_callback(this); + + for (var i in real_data_arr) { + if (this.ds_op_list!=undefined) real_data_arr[i]=new RRDFilterOp(real_data_arr[i],this.ds_op_list); + if (this.rra_op_list!=undefined) real_data_arr[i]=new RRDRRAFilterAvg(real_data_arr[i],this.rra_op_list); + } + this.rrd_flot_obj=new rrdFlotMatrix(this.html_id, real_data_arr, this.ds_list, this.graph_options, this.rrd_graph_options, this.rrdflot_defaults); +}; + -- cgit v1.1-4-g5e80