From c72fd4690f668f80a8c74262b08ff4a1af05552e Mon Sep 17 00:00:00 2001 From: javi Date: Mon, 18 Nov 2013 17:30:13 +0100 Subject: [PATCH] added setOptions method to provider.json #21 --- lib/torque/provider.json.js | 39 ++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/lib/torque/provider.json.js b/lib/torque/provider.json.js index f7aa707..17b401d 100644 --- a/lib/torque/provider.json.js +++ b/lib/torque/provider.json.js @@ -335,6 +335,36 @@ setColumn: function(column, isTime) { this.options.column = column; this.options.is_time = isTime === undefined ? true: false; + this.reload(); + }, + + setResolution: function(res) { + this.options.resolution = res; + }, + + setOptions: function(opt) { + var refresh = false; + + if(opt.resolution !== undefined && opt.resolution !== this.options.resolution) { + this.options.resolution = opt.resolution; + refresh = true; + } + + if(opt.steps !== undefined && opt.steps !== this.options.steps) { + this.setSteps(opt.steps, { silent: true }); + refresh = true; + } + + if(opt.column !== undefined && opt.column !== this.options.column) { + this.options.column = opt.column; + refresh = true; + } + + if (refresh) this.reload(); + + }, + + reload: function() { this._ready = false; this._fetchKeySpan(); }, @@ -342,8 +372,7 @@ setSQL: function(sql) { if (this.options.sql != sql) { this.options.sql = sql; - this._ready = false; - this._fetchKeySpan(); + this.options.reload(); } }, @@ -351,13 +380,13 @@ return Math.min(this.options.steps, this.options.data_steps); }, - setSteps: function(steps) { + setSteps: function(steps, opt) { + opt = opt || {} if (this.options.steps !== steps) { this.options.steps = steps; this.options.step = (this.options.end - this.options.start)/this.getSteps(); this.options.step = this.options.step || 1; - this._ready = false; - this._fetchKeySpan(); + if (!opt.silent) this.reload() } },