From 7231ff14f9ce38927360e4e11f9881ad67f63b2e Mon Sep 17 00:00:00 2001 From: alisonjm Date: Tue, 24 May 2011 20:50:15 +0000 Subject: Added more rrdflot_defaults: able to specify checked DSs, RRA and zoom window via rrdFlot(). --- src/lib/rrdFlot.js | 107 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 95 insertions(+), 12 deletions(-) diff --git a/src/lib/rrdFlot.js b/src/lib/rrdFlot.js index e972621..812ed1c 100644 --- a/src/lib/rrdFlot.js +++ b/src/lib/rrdFlot.js @@ -47,7 +47,8 @@ * stack: 'none' // other options are 'positive' and 'negative' * } * - * rrdflot_defeaults defaults (see Flot docs for details) + * //overwrites other defaults; mostly used for linking via the URL + * rrdflot_defaults defaults (see Flot docs for details) * { * legend: "Top" //Starting location of legend. Options are: * //"Top","Bottom","TopRight","BottomRight","None". @@ -55,9 +56,18 @@ * multi_ds: false //"true" appends the name of the aggregation function to the * //name of the DS element. Useful for when an element is displayed * //more than once but under different aggregation functions. + * use_checked_DSs: true //boolean to use checked_DSs below (which override all other checking procedure) + * checked_DSs: [] //array of DSs names to be plotted (so that they can be specified via URL link.) + * use_rra: true //use the rra below + * specified_rra: idx //index (int) of rra to be plotted * } */ +var local_checked_DSs = []; +var selected_rra = 0; +var window_min=0; +var window_max=0; + function rrdFlot(html_id, rrd_file, graph_options, ds_graph_options, rrdflot_defaults) { this.html_id=html_id; this.rrd_file=rrd_file; @@ -74,6 +84,7 @@ function rrdFlot(html_id, rrd_file, graph_options, ds_graph_options, rrdflot_def } this.selection_range=new rrdFlotSelection(); + graph_info={}; this.createHTML(); this.populateRes(); this.populateDScb(); @@ -100,7 +111,7 @@ rrdFlot.prototype.createHTML = function() { // Now create the layout var external_table=document.createElement("Table"); - // Header rwo: resulution select and DS selection title + // Header two: resulution select and DS selection title var rowHeader=external_table.insertRow(-1); var cellRes=rowHeader.insertCell(-1); cellRes.colSpan=3; @@ -191,6 +202,7 @@ rrdFlot.prototype.populateRes = function() { var rra_label=rfs_format_time(step)+" ("+rfs_format_time(period)+" total)"; form_el.appendChild(new Option(rra_label,i)); } + if(this.rrdflot_defaults.use_rra) {form_el.selectedIndex = this.rrdflot_defaults.rra;} }; rrdFlot.prototype.populateDScb = function() { @@ -218,8 +230,12 @@ rrdFlot.prototype.populateDScb = function() { var name2=ds.getName(); } else {var name=ds.getName(); var name2=ds.getName();} - var title=name; - var checked=(i==0); // only first checked by default + var title=name; + if(this.rrdflot_defaults.use_checked_DSs) { + if(this.rrdflot_defaults.checked_DSs.length==0) { + var checked=(i==0); // only first checked by default + } else{checked=false;} + } else {var checked=(i==0);} if (this.ds_graph_options[name]!=null) { var dgo=this.ds_graph_options[name]; if (dgo['title']!=null) { @@ -229,11 +245,23 @@ rrdFlot.prototype.populateDScb = function() { // use label as a second choiceit title=dgo['label']; } // else leave the ds name - if (dgo['checked']!=null) { - // if the user provided the title, use it - checked=dgo['checked']; + if(this.rrdflot_defaults.use_checked_DSs) { + if(this.rrdflot_defaults.checked_DSs.length==0) { + // if the user provided the title, use it + checked=dgo['checked']; + } + } else { + if (dgo['checked']!=null) { + checked=dgo['checked']; + } } } + if(this.rrdflot_defaults.use_checked_DSs) { + if(this.rrdflot_defaults.checked_DSs==null) {continue;} + for(var j=0;j0) { for (var i=0; i