if(typeof jrrd == 'undefined') { var jrrd = {}; } jrrd.downloadBinary = function(url) { var d = new MochiKit.Async.Deferred(); $.ajax({ url: url, dataType: 'text', cache: false, beforeSend: function(request) { try { request.overrideMimeType('text/plain; charset=x-user-defined'); } catch(e) { // IE doesn't support overrideMimeType } }, success: function(data) { try { d.callback(new BinaryFile(data)); } catch(e) { d.errback(e); } }, error: function(xhr, textStatus, errorThrown) { // Special case for IE which handles binary data slightly // differently. if(textStatus == 'parsererror') { if (typeof xhr.responseBody != 'undefined') { return this.success(xhr.responseBody); } } d.errback(new Error(xhr.status)); } }); return d; }; jrrd.RrdQuery = function(rrd) { this.rrd = rrd; }; jrrd.RrdQuery.prototype.getData = function(startTime, endTime, dsId) { var startTimestamp = startTime.getTime()/1000; var endTimestamp = endTime.getTime()/1000; if(dsId == null) { dsId = 0; } var ds = this.rrd.getDS(dsId); var consolidationFunc = 'AVERAGE'; var lastUpdated = this.rrd.getLastUpdate(); // If end time stamp is beyond the range of this rrd then reset it if(lastUpdated < endTimestamp) { endTimestamp = lastUpdated; } var bestRRA = null; for(var i=0; i -1 && this.lastUpdate < endTimestamp )) { this._download = jrrd.downloadBinary(this.url) .addCallback( function(self, binary) { // Upon successful download convert the resulting binary // into an RRD file and pass it on to the next callback // in the chain. var rrd = new RRDFile(binary); self.lastUpdate = rrd.getLastUpdate(); return rrd; }, this); } // Set up a deferred which will call getData on the local RrdQuery object // returning a flot compatible data object to the caller. var ret = new MochiKit.Async.Deferred().addCallback( function(startTime, endTime, dsId, rrd) { return new jrrd.RrdQuery(rrd).getData(startTime, endTime, dsId); }, startTime, endTime, dsId); // Add a pair of callbacks to the current download which will callback the // result which we setup above. this._download.addBoth( function(ret, res) { if(res instanceof Error) { ret.errback(res); } else { ret.callback(res); } return res; }, ret); return ret; }; jrrd.RrdQueryDsProxy = function(rrdQuery, dsId) { this.rrdQuery = rrdQuery; this.dsId = dsId; }; jrrd.RrdQueryDsProxy.prototype.getData = function(startTime, endTime) { return this.rrdQuery.getData(startTime, endTime, this.dsId); }; jrrd.Chart = function(template, options) { this.template = template; this.options = options; this.data = []; }; jrrd.Chart.prototype.addData = function(label, db) { this.data.push([label, db]); }; jrrd.Chart.prototype.draw = function(startTime, endTime) { var results = []; for(var i=0; i