From bfbfbfc49140e88753823e01abdc1ffc12e44ba2 Mon Sep 17 00:00:00 2001 From: Frank Wuerthwein Date: Mon, 16 Feb 2009 13:04:50 +0000 Subject: Move trim_data into a new class: rrdFlotSelection, in the rrdFlotSupport module --- src/lib/rrdFlot.js | 39 +++++---------------------------------- src/lib/rrdFlotSupport.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 34 deletions(-) diff --git a/src/lib/rrdFlot.js b/src/lib/rrdFlot.js index 2ab090b..146f816 100644 --- a/src/lib/rrdFlot.js +++ b/src/lib/rrdFlot.js @@ -32,6 +32,8 @@ function rrdFlot(html_id, rrd_file, ds_description, layout_opts) { this.ds_description=ds_description; this.layout_ops=layout_opts; + this.selection_range=new rrdFlotSelection(); + this.createHTML(); this.populateRes(); this.populateDScb(); @@ -96,10 +98,6 @@ rrdFlot.prototype.createHTML = function() { 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; }; // ====================================== @@ -199,7 +197,7 @@ rrdFlot.prototype.bindFlotGraph = function(flot_data) { selection: { mode: "x" }, }; - var graph_data=this.trim_flot_data(flot_data); + var graph_data=this.selection_range.trim_flot_data(flot_data); //var scale_data=flot_data.clone(); var scale_data=flot_data; @@ -214,9 +212,9 @@ rrdFlot.prototype.bindFlotGraph = function(flot_data) { // now connect the two $(graph_jq_id).bind("plotselected", function (event, ranges) { // do the zooming - rf_this.selection_min=ranges.xaxis.from; + rf_this.selection_range.setFromFlotRanges(ranges); rf_this.selection_max=ranges.xaxis.to; - graph = $.plot($(graph_jq_id), rf_this.trim_flot_data(flot_data), graph_options); + graph = $.plot($(graph_jq_id), rf_this.selection_range.trim_flot_data(flot_data), graph_options); // don't fire event on the scale to prevent eternal loop scale.setSelection(ranges, true); @@ -236,30 +234,3 @@ rrdFlot.prototype.callback_ds_cb_changed = function() { this.drawFlotGraph(); }; - -// ======================================================= -// Given an array of flot lines, limit to the selection -rrdFlot.prototype.trim_flot_data = function(flot_data) { - var out_data=[]; - 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; -}; - diff --git a/src/lib/rrdFlotSupport.js b/src/lib/rrdFlotSupport.js index 8aa9e49..ede309c 100644 --- a/src/lib/rrdFlotSupport.js +++ b/src/lib/rrdFlotSupport.js @@ -43,3 +43,48 @@ function rrdDS2FlotSeries(rrd_file,ds_id,rra_idx,want_label) { } } +// ====================================== +// Helper class for handling selections +// ======================================================= +function rrdFlotSelection() { + this.selection_min=null; + this.selection_max=null; +} + +// reset to a state where ther is no selection +rrdFlotSelection.prototype.reset = function() { + this.selection_min=null; + this.selection_max=null; +} + +// given the selection ranges, set internal variable accordingly +rrdFlotSelection.prototype.setFromFlotRanges = function(ranges) { + this.selection_min=ranges.xaxis.from; + this.selection_max=ranges.xaxis.to; +} + +// Given an array of flot lines, limit to the selection +rrdFlotSelection.prototype.trim_flot_data = function(flot_data) { + var out_data=[]; + 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