From 98630eefa847aefbf980309d2a51ea11a637e5ea Mon Sep 17 00:00:00 2001 From: Frank Wuerthwein Date: Sun, 10 May 2009 00:25:47 +0000 Subject: Plot a graph of multiple similar RRDs, one DS at a time --- src/lib/rrdFlotMatrix.js | 408 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 408 insertions(+) create mode 100644 src/lib/rrdFlotMatrix.js diff --git a/src/lib/rrdFlotMatrix.js b/src/lib/rrdFlotMatrix.js new file mode 100644 index 0000000..54505a5 --- /dev/null +++ b/src/lib/rrdFlotMatrix.js @@ -0,0 +1,408 @@ +/* + * 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/] + * + */ + +/* + * The rrd_files is a list of + * [rrd_id,rrd_file] pairs + * All rrd_files must have the same step, the same DSes amd the same number of RRAs. + * + */ + +/* + * Local dependencies: + * rrdFlotSupport.py + * + * External dependencies: + * [Flot]/jquery.py + * [Flot]/jquery.flot.js + */ + +/* graph_options defaults (see Flot docs for details) + * { + * legend: { position:"nw",noColumns:3}, + * lines: { show:true }, + * yaxis: { autoscaleMargin: 0.20} + * } + * + * rrd_graph_options is a dictionary of rrd_id, + * with each element being a graph_option + * The defaults for each element are + * { + * title: label or ds_name // this is what is displayed at the radio button + * checked: first_ds_in_list? //boolean + * label: title or ds_name // this is what is displayed in the legend + * color: ds_index // see Flot docs for details + * lines: { show:true, fill: true, fillColor:color } // see Flot docs for details + * } + */ + +function rrdFlotMatrix(html_id, rrd_files, graph_options, rrd_graph_options) { + this.html_id=html_id; + this.rrd_files=rrd_files; + this.graph_options=graph_options; + if (rrd_graph_options==null) { + this.rrd_graph_options=new Object(); // empty object, just not to be null + } else { + this.rrd_graph_options=rrd_graph_options; + } + this.selection_range=new rrdFlotSelection(); + + this.createHTML(); + this.populateDS(); + this.populateRes(); + this.populateRRDcb(); + this.drawFlotGraph() +} + + +// =============================================== +// Create the HTML tags needed to host the graphs +rrdFlotMatrix.prototype.createHTML = function() { + var rf_this=this; // use obj inside other functions + + var base_el=document.getElementById(this.html_id); + + this.ds_id=this.html_id+"_ds"; + this.res_id=this.html_id+"_res"; + this.rrd_cb_id=this.html_id+"_rrd_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"); + + // DS rows: select DS + var rowDS=external_table.insertRow(-1); + var cellDS=rowDS.insertCell(-1); + cellDS.colSpan=3 + cellDS.appendChild(document.createTextNode("Element:")); + var forDS=document.createElement("Select"); + forDS.id=this.ds_id; + forDS.onchange= function () {rf_this.callback_ds_changed();}; + cellDS.appendChild(forDS); + + // Header row: resulution select and DS selection title + var rowHeader=external_table.insertRow(-1); + var cellRes=rowHeader.insertCell(-1); + cellRes.colSpan=2 + cellRes.appendChild(document.createTextNode("Resolution:")); + var forRes=document.createElement("Select"); + forRes.id=this.res_id; + forRes.onchange= function () {rf_this.callback_res_changed();}; + cellRes.appendChild(forRes); + + var cellRRDTitle=rowHeader.insertCell(-1); + cellRRDTitle.appendChild(document.createTextNode("Select RRDs to plot:")); + + // Graph row: main graph and DS selection block + var rowGraph=external_table.insertRow(-1); + var cellGraph=rowGraph.insertCell(-1); + cellGraph.colSpan=2; + var elGraph=document.createElement("Div"); + elGraph.style.width="500px"; + elGraph.style.height="300px"; + elGraph.id=this.graph_id; + cellGraph.appendChild(elGraph); + + var cellRRDcb=rowGraph.insertCell(-1); + cellRRDcb.vAlign="top"; + var formRRDcb=document.createElement("Form"); + formRRDcb.id=this.rrd_cb_id; + formRRDcb.onchange= function () {rf_this.callback_rrd_cb_changed();}; + cellRRDcb.appendChild(formRRDcb); + + // Scale row: scaled down selection graph + var rowScale=external_table.insertRow(-1); + var cellScale=rowScale.insertCell(-1); + cellScale.align="right"; + var elScale=document.createElement("Div"); + elScale.style.width="250px"; + elScale.style.height="75px"; + elScale.id=this.scale_id; + cellScale.appendChild(elScale); + + var cellScaleReset=rowScale.insertCell(-1); + //cellScaleReset.vAlign="top"; + var elScaleReset=document.createElement("input"); + elScaleReset.type = "button"; + elScaleReset.value = "Reset selection"; + elScaleReset.onclick = function () {rf_this.callback_scale_reset();} + + cellScaleReset.appendChild(elScaleReset); + + base_el.appendChild(external_table); +}; + +// ====================================== +// Populate DSs, RRA and RRD info +rrdFlotMatrix.prototype.populateDS = function() { + var form_el=document.getElementById(this.ds_id); + + // First clean up anything in the element + while (form_el.lastChild!=null) form_el.removeChild(form_el.lastChild); + + var rrd_file=this.rrd_files[0][1]; // get the first one... they are all the same + // now populate with RRA info + var nrDSs=rrd_file.getNrDSs(); + for (var i=0; i0) { + for (var i=0; i