From: Dan Vanderkam Date: Mon, 14 Dec 2009 13:35:51 +0000 (-0800) Subject: allow dateWindow to be set explicitly in layout (previously it was deduced from the... X-Git-Tag: v1.0.0~783 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=f6401bf68f1ccec4c891b2b6bf40982fb806b32d;p=dygraphs.git allow dateWindow to be set explicitly in layout (previously it was deduced from the data) --- diff --git a/dygraph-canvas.js b/dygraph-canvas.js index a848001..c3a8296 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -37,14 +37,19 @@ DygraphLayout.prototype.evaluate = function() { DygraphLayout.prototype._evaluateLimits = function() { this.minxval = this.maxxval = null; - for (var name in this.datasets) { - if (!this.datasets.hasOwnProperty(name)) continue; - var series = this.datasets[name]; - var x1 = series[0][0]; - if (!this.minxval || x1 < this.minxval) this.minxval = x1; - - var x2 = series[series.length - 1][0]; - if (!this.maxxval || x2 > this.maxxval) this.maxxval = x2; + if (this.options.dateWindow) { + this.minxval = this.options.dateWindow[0]; + this.maxxval = this.options.dateWindow[1]; + } else { + for (var name in this.datasets) { + if (!this.datasets.hasOwnProperty(name)) continue; + var series = this.datasets[name]; + var x1 = series[0][0]; + if (!this.minxval || x1 < this.minxval) this.minxval = x1; + + var x2 = series[series.length - 1][0]; + if (!this.maxxval || x2 > this.maxxval) this.maxxval = x2; + } } this.xrange = this.maxxval - this.minxval; this.xscale = (this.xrange != 0 ? 1/this.xrange : 1.0); diff --git a/dygraph.js b/dygraph.js index 8895a39..386781d 100644 --- a/dygraph.js +++ b/dygraph.js @@ -1248,11 +1248,14 @@ Dygraph.prototype.drawGraph_ = function(data) { this.addXTicks_(); // Tell PlotKit to use this new data and render itself + if (this.dateWindow_) { + this.layout_.updateOptions({dateWindow: this.dateWindow_}); + } this.layout_.evaluateWithError(); this.plotter_.clear(); this.plotter_.render(); - this.canvas_.getContext('2d').clearRect(0, 0, - this.canvas_.width, this.canvas_.height); + this.canvas_.getContext('2d').clearRect(0, 0, this.canvas_.width, + this.canvas_.height); }; /** diff --git a/tests/dateWindow.html b/tests/dateWindow.html new file mode 100644 index 0000000..14ad893 --- /dev/null +++ b/tests/dateWindow.html @@ -0,0 +1,31 @@ + + + dateWindow + + + + + + +

dateWindow is set to something other than an x-value in the data set. + Grid lines should still go through data points.

+ +
+ + + +