summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Wall <richard@largo>2010-12-30 00:37:31 +0000
committerRichard Wall <richard@largo>2010-12-30 00:37:31 +0000
commitc71886f059b6d2ad68f55a37c891f26898a5c7be (patch)
tree141d330ca9fbdb3ae5946a7e22830cf070080eeb
parent579605cb677a0345688c5421b0075b26111c4393 (diff)
Refactor rrdqueryremote to allow a new query for available data sources.
-rw-r--r--jarmon/jarmon.js84
-rw-r--r--jarmon/jarmon.test.js14
2 files changed, 79 insertions, 19 deletions
diff --git a/jarmon/jarmon.js b/jarmon/jarmon.js
index 406c4d1..a66a93b 100644
--- a/jarmon/jarmon.js
+++ b/jarmon/jarmon.js
@@ -275,23 +275,11 @@ jarmon.RrdQueryRemote = function(url, unit, downloader) {
this._download = null;
};
-jarmon.RrdQueryRemote.prototype.getData = function(startTime, endTime, dsId) {
- /**
- * Return a Flot compatible data series asynchronously.
- *
- * @method getData
- * @param startTime {Number} The start timestamp
- * @param endTime {Number} The end timestamp
- * @param dsId {Variant} identifier of the RRD datasource (string or number)
- * @return {Object} A Deferred which calls back with a flot data series.
- **/
- var endTimestamp = endTime/1000;
- // Download the rrd if there has never been a download or if the last
- // completed download had a lastUpdated timestamp less than the requested
- // end time.
- // Don't start another download if one is already in progress.
- if(!this._download || (this._download.fired > -1 && this.lastUpdate < endTimestamp )) {
+jarmon.RrdQueryRemote.prototype._callRemote = function(methodName, args) {
+ // Download the rrd if there has never been a download and don't start
+ // another download if one is already in progress.
+ if(!this._download) {
this._download = this.downloader(this.url)
.addCallback(
function(self, binary) {
@@ -307,9 +295,10 @@ jarmon.RrdQueryRemote.prototype.getData = function(startTime, endTime, dsId) {
// 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(self, startTime, endTime, dsId, rrd) {
- return new jarmon.RrdQuery(rrd, self.unit).getData(startTime, endTime, dsId);
- }, this, startTime, endTime, dsId);
+ function(self, methodName, args, rrd) {
+ var rq = new jarmon.RrdQuery(rrd, self.unit);
+ return rq[methodName].apply(rq, args);
+ }, this, methodName, args);
// Add a pair of callbacks to the current download which will callback the
// result which we setup above.
@@ -326,6 +315,23 @@ jarmon.RrdQueryRemote.prototype.getData = function(startTime, endTime, dsId) {
return ret;
};
+
+jarmon.RrdQueryRemote.prototype.getData = function(startTime, endTime, dsId) {
+ /**
+ * Return a Flot compatible data series asynchronously.
+ *
+ * @method getData
+ * @param startTime {Number} The start timestamp
+ * @param endTime {Number} The end timestamp
+ * @param dsId {Variant} identifier of the RRD datasource (string or number)
+ * @return {Object} A Deferred which calls back with a flot data series.
+ **/
+ if(this.lastUpdate < endTime/1000) {
+ this._download = null;
+ }
+ return this._callRemote('getData', [startTime, endTime, dsId]);
+};
+
/**
* Wraps RrdQueryRemote to provide access to a different RRD DSs within a
* single RrdDataSource.
@@ -654,6 +660,46 @@ jarmon.Chart.fromRecipe = function(recipes, templateFactory, downloader) {
};
+/**
+ * Generate a form through which to manipulate the data sources for a chart
+ *
+ * @class jarmon.ChartConfig
+ * @constructor
+ **/
+jarmon.ChartConfig = function($tpl) {
+ this.$tpl = $tpl;
+};
+
+jarmon.ChartConfig.prototype.draw = function() {
+ $('<form/>').append(
+ $('<div/>').append(
+ $('<label/>').append(
+ ['URL', ': '].join(''),
+ $('<input/>', {name: 'rrd_url'})
+ )
+ ),
+ $('<div/>').append(
+ $('<input/>', {type: 'submit', value: 'submit'})
+ )
+ ).submit(
+ function(e) {
+ var d = new jarmon.RrdQueryRemote(this['rrd_url'])
+ $(this).append(
+ $('<div/>').append(
+ $('<label/>').append(
+ ['DS', ': '].join(''),
+ $('<input/>', {name: 'rrd_ds'})
+ )
+ )
+ );
+
+ return false;
+ }
+ ).appendTo(this.$tpl);
+}
+
+
+
// Options common to all the chart on this page
jarmon.Chart.BASE_OPTIONS = {
grid: {
diff --git a/jarmon/jarmon.test.js b/jarmon/jarmon.test.js
index c838023..fda076f 100644
--- a/jarmon/jarmon.test.js
+++ b/jarmon/jarmon.test.js
@@ -301,6 +301,20 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) {
}));
+ Y.Test.Runner.add(new Y.Test.Case({
+ name: "jarmon.ChartConfig",
+
+ test_draw: function () {
+ /**
+ * Test that a rendered chart has the correct dimensions, legend,
+ * axis, labels etc
+ **/
+ var c = new jarmon.ChartConfig($('<div/>').appendTo($('body')));
+ c.draw();
+ },
+ }));
+
+
//initialize the console
var yconsole = new Y.Console({
newestOnTop: false,