diff options
author | Frank Wuerthwein <fkw@ucsd.edu> | 2009-03-18 12:56:28 +0000 |
---|---|---|
committer | Frank Wuerthwein <fkw@ucsd.edu> | 2009-03-18 12:56:28 +0000 |
commit | 3d31ceb2029dc34f327023f4d35d7e7b048805a1 (patch) | |
tree | d1718c41420f1841641137049649a4fd53640632 /src/lib/rrdFlotSupport.js | |
parent | f08fcb2a69d028a2a66922b4ab724ac1b55605f1 (diff) |
Add timestamp rounding
Diffstat (limited to 'src/lib/rrdFlotSupport.js')
-rw-r--r-- | src/lib/rrdFlotSupport.js | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/lib/rrdFlotSupport.js b/src/lib/rrdFlotSupport.js index 75e05a4..87b6698 100644 --- a/src/lib/rrdFlotSupport.js +++ b/src/lib/rrdFlotSupport.js @@ -20,7 +20,7 @@ // Return a Flot-like data structure
// Since Flot does not properly handle empty elements, min and max are returned, too
-function rrdDS2FlotSeries(rrd_file,ds_id,rra_idx) {
+function rrdDS2FlotSeries(rrd_file,ds_id,rra_idx,want_rounding) {
var ds=rrd_file.getDS(ds_id);
var ds_name=ds.getName();
var ds_idx=ds.getIdx();
@@ -29,6 +29,12 @@ function rrdDS2FlotSeries(rrd_file,ds_id,rra_idx) { var last_update=rrd_file.getLastUpdate();
var step=rra.getStep();
+ if (want_rounding!=false) {
+ // round last_update to step
+ // so that all elements are sync
+ last_update-=(last_update%step);
+ }
+
var first_el=last_update-(rra_rows-1)*step;
var timestamp=first_el;
var flot_series=[];
@@ -45,11 +51,17 @@ function rrdDS2FlotSeries(rrd_file,ds_id,rra_idx) { // return an object with an array containing Flot elements, one per DS
// min and max are also returned
-function rrdRRA2FlotObj(rrd_file,rra_idx,ds_list,want_ds_labels) {
+function rrdRRA2FlotObj(rrd_file,rra_idx,ds_list,want_ds_labels,want_rounding) {
var rra=rrd_file.getRRA(rra_idx);
var rra_rows=rra.getNrRows();
var last_update=rrd_file.getLastUpdate();
var step=rra.getStep();
+ if (want_rounding!=false) {
+ // round last_update to step
+ // so that all elements are sync
+ last_update-=(last_update%step);
+ }
+
var first_el=last_update-(rra_rows-1)*step;
var out_el={data:[], min:first_el*1000.0, max:last_update*1000.0};
|