From c54e62140514d1f57961822fe2df0b9b88d2d03c Mon Sep 17 00:00:00 2001 From: Frank Wuerthwein Date: Sun, 15 Feb 2009 17:35:34 +0000 Subject: Initial commit - basics work, but far from finished --- src/lib/rrdFlot.js | 265 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 265 insertions(+) create mode 100644 src/lib/rrdFlot.js diff --git a/src/lib/rrdFlot.js b/src/lib/rrdFlot.js new file mode 100644 index 0000000..2ab090b --- /dev/null +++ b/src/lib/rrdFlot.js @@ -0,0 +1,265 @@ +/* + * RRD graphing libraries, based on 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://code.google.com/p/flot/] + * + */ + +/* + * Local dependencies: + * rrdFlotSupport.py + * + * External dependencies: + * [Flot]/jquery.py + * [Flot]/jquery.flot.js + */ + +// ds_desciption and layout_opts not used yet +function rrdFlot(html_id, rrd_file, ds_description, layout_opts) { + this.html_id=html_id; + this.rrd_file=rrd_file; + this.ds_description=ds_description; + this.layout_ops=layout_opts; + + this.createHTML(); + this.populateRes(); + this.populateDScb(); + this.drawFlotGraph() +} + + +// =============================================== +// Create the HTML tags needed to host the graphs +rrdFlot.prototype.createHTML = function() { + var rf_this=this; // use obj inside other functions + + var base_el=document.getElementById(this.html_id); + + this.res_id=this.html_id+"_res"; + this.ds_cb_id=this.html_id+"_ds_cb"; + this.graph_id=this.html_id+"_graph"; + this.scale_id=this.html_id+"_scale"; + + // First clean up anything in the element + while (base_el.lastChild!=null) base_el.removeChild(base_el.lastChild); + + // Now create the layout + var external_table=document.createElement("Table"); + + // Header rwo: resulution select and DS selection title + var rowHeader=external_table.insertRow(-1); + var cellRes=rowHeader.insertCell(-1); + cellRes.appendChild(document.createTextNode("Resolution:")); + var forRes=document.createElement("Select"); + forRes.id=this.res_id; + //forRes.onChange= this.callback_res_changed; + forRes.onchange= function () {rf_this.callback_res_changed();}; + cellRes.appendChild(forRes); + + var cellDSTitle=rowHeader.insertCell(-1); + cellDSTitle.appendChild(document.createTextNode("Select elements to plot:")); + + // Graph row: main graph and DS selection block + var rowGraph=external_table.insertRow(-1); + var cellGraph=rowGraph.insertCell(-1); + var elGraph=document.createElement("Div"); + elGraph.style.width="500px"; + elGraph.style.height="300px"; + elGraph.id=this.graph_id; + cellGraph.appendChild(elGraph); + + var cellDScb=rowGraph.insertCell(-1); + cellDScb.vAlign="top"; + var formDScb=document.createElement("Form"); + formDScb.id=this.ds_cb_id; + formDScb.onchange= function () {rf_this.callback_ds_cb_changed();}; + cellDScb.appendChild(formDScb); + + // Scale row: scaled down selection graph + var rowScale=external_table.insertRow(-1); + var cellScale=rowScale.insertCell(-1); + var elScale=document.createElement("Div"); + elScale.style.width="400px"; + elScale.style.height="75px"; + elScale.id=this.scale_id; + cellScale.appendChild(elScale); + + base_el.appendChild(external_table); + + // since I created a new HTML structure, there are no graphs yet => no selection + this.selection_min=null; + this.selection_max=null; +}; + +// ====================================== +// Populate RRA and RD info +rrdFlot.prototype.populateRes = function() { + var form_el=document.getElementById(this.res_id); + + // First clean up anything in the element + while (form_el.lastChild!=null) form_el.removeChild(form_el.lastChild); + + // now populate with RRA info + var nrRRAs=this.rrd_file.getNrRRAs(); + for (var i=0; i0) { + 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; +}; + -- cgit v1.1-4-g5e80