/* * RRD graphing libraries, based on Flot * Part of the javascriptRRD package * Copyright (c) 2009 Frank Wuerthwein, fkw@ucsd.edu * Igor Sfiligoi, isfiligoi@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 */ /* graph_options defaults (see Flot docs for details) * { * legend: { position:"nw",noColumns:3}, * lines: { show:true }, * yaxis: { autoscaleMargin: 0.20} * } * * ds_graph_options is a dictionary of DS_name, * with each element being a graph_option * The defaults for each element are * { * title: label or ds_name // this is what is displayed in the checkboxes * 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 } // see Flot docs for details * yaxis: 1 // can be 1 or 2 * stack: 'none' // other options are 'positive' and 'negative' * } */ function rrdFlot(html_id, rrd_file, graph_options, ds_graph_options) { this.html_id=html_id; this.rrd_file=rrd_file; this.graph_options=graph_options; if (ds_graph_options==null) { this.ds_graph_options=new Object(); // empty object, just not to be null } else { this.ds_graph_options=ds_graph_options; } this.selection_range=new rrdFlotSelection(); 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"; this.legend_sel_id=this.html_id+"_legend_sel"; // 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.colSpan=3; 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); cellGraph.colSpan=3; 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 cellScaleLegend=rowScale.insertCell(-1); cellScaleLegend.vAlign="top"; cellScaleLegend.appendChild(document.createTextNode("Legend:")); cellScaleLegend.appendChild(document.createElement('br')); var forScaleLegend=document.createElement("Select"); forScaleLegend.id=this.legend_sel_id; forScaleLegend.appendChild(new Option("Top","nw")); forScaleLegend.appendChild(new Option("Bottom","sw")); forScaleLegend.appendChild(new Option("TopRight","ne")); forScaleLegend.appendChild(new Option("BottomRight","se")); forScaleLegend.appendChild(new Option("None","None")); forScaleLegend.onchange= function () {rf_this.callback_legend_changed();}; cellScaleLegend.appendChild(forScaleLegend); 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 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