summaryrefslogtreecommitdiff
path: root/src/lib/rrdFlotSupport.js
diff options
context:
space:
mode:
authorFrank Wuerthwein <fkw@ucsd.edu>2009-02-16 13:04:50 +0000
committerFrank Wuerthwein <fkw@ucsd.edu>2009-02-16 13:04:50 +0000
commitbfbfbfc49140e88753823e01abdc1ffc12e44ba2 (patch)
tree85a463f7ec39f8f38d9ef066638b25938f048bda /src/lib/rrdFlotSupport.js
parent0338916cb6d08c249bad95445d619c407015bfa8 (diff)
Move trim_data into a new class: rrdFlotSelection, in the rrdFlotSupport module
Diffstat (limited to 'src/lib/rrdFlotSupport.js')
-rw-r--r--src/lib/rrdFlotSupport.js45
1 files changed, 45 insertions, 0 deletions
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<flot_data.length; i++) {
+ var data_el=flot_data[i];
+ out_data.push({label : data_el.label, data:this.trim_data(data_el.data)});
+ }
+ return out_data;
+};
+
+// Limit to selection the flot series data element
+rrdFlotSelection.prototype.trim_data = function(data_list) {
+ if (this.selection_min==null) return data_list; // no selection => no filtering
+
+ var out_data=[];
+ for (var i=0; i<data_list.length; i++) {
+ if (data_list[i]==null) continue; // protect
+ var nr=data_list[i][0];
+ if ((nr>=this.selection_min) && (nr<=this.selection_max)) {
+ out_data.push(data_list[i]);
+ }
+ }
+ return out_data;
+};
+