From: Neal Nelson Date: Thu, 27 Jan 2011 14:48:01 +0000 (+0100) Subject: - Stop charts with no visible plots from crashing. X-Git-Tag: v1.0.0~536^2~1^2~8 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=81856f70cb6840dbe476a90f99beb66118908687;p=dygraphs.git - Stop charts with no visible plots from crashing. - Add noZoomFlagChange option to stop the zoom flags being updated when the dateWindow or valueRange is changed programmatically. --- diff --git a/docs/index.html b/docs/index.html index 9d295aa..a2a2b5f 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1025,6 +1025,17 @@ perl -ne 'BEGIN{print "Month,Nominal,Real\n"} chomp; ($m,$cpi,$low,$close,$high) + + noZoomFlagChange + + + + When this flag is passed along with either the dateWindow or valueRange options, the zoom flags are not changed to reflect a zoomed state. + This is primarily useful for when the display area of a chart is changed programmatically and also where manual zooming is allowed and use is made of the isZoomed method to determine this. +
Tests: no-zoom-change
+ + + diff --git a/dygraph.js b/dygraph.js index 4539382..d28fad3 100644 --- a/dygraph.js +++ b/dygraph.js @@ -2104,18 +2104,22 @@ Dygraph.prototype.drawGraph_ = function() { this.layout_.addDataset(this.attr_("labels")[i], datasets[i]); } - // TODO(danvk): this method doesn't need to return anything. - var out = this.computeYAxisRanges_(extremes); - var axes = out[0]; - var seriesToAxisMap = out[1]; - this.layout_.updateOptions( { yAxes: axes, - seriesToAxisMap: seriesToAxisMap - } ); - + if (datasets.length > 0) { + // TODO(danvk): this method doesn't need to return anything. + var out = this.computeYAxisRanges_(extremes); + var axes = out[0]; + var seriesToAxisMap = out[1]; + this.layout_.updateOptions( { yAxes: axes, + seriesToAxisMap: seriesToAxisMap + } ); + } this.addXTicks_(); + // Save the X axis zoomed status as the updateOptions call will tend to set it errorneously + var tmp_zoomed_x = this.zoomed_x_; // Tell PlotKit to use this new data and render itself this.layout_.updateOptions({dateWindow: this.dateWindow_}); + this.zoomed_x_ = tmp_zoomed_x; this.layout_.evaluateWithError(); this.plotter_.clear(); this.plotter_.render(); @@ -2138,12 +2142,12 @@ Dygraph.prototype.drawGraph_ = function() { * indices are into the axes_ array. */ Dygraph.prototype.computeYAxes_ = function() { - var valueWindow; + var valueWindows; if (this.axes_ != undefined) { // Preserve valueWindow settings. - valueWindow = []; + valueWindows = []; for (var index = 0; index < this.axes_.length; index++) { - valueWindow.push(this.axes_[index].valueWindow); + valueWindows.push(this.axes_[index].valueWindow); } } @@ -2220,10 +2224,10 @@ Dygraph.prototype.computeYAxes_ = function() { } this.seriesToAxisMap_ = seriesToAxisFiltered; - if (valueWindow != undefined) { + if (valueWindows != undefined) { // Restore valueWindow settings. - for (var index = 0; index < valueWindow.length; index++) { - this.axes_[index].valueWindow = valueWindow[index]; + for (var index = 0; index < valueWindows.length; index++) { + this.axes_[index].valueWindow = valueWindows[index]; } } }; @@ -2921,9 +2925,11 @@ Dygraph.prototype.updateOptions = function(attrs) { } if ('dateWindow' in attrs) { this.dateWindow_ = attrs.dateWindow; - this.zoomed_x_ = attrs.dateWindow != null; + if (!('noZoomFlagChange' in attrs)) { + this.zoomed_x_ = attrs.dateWindow != null; + } } - if ('valueRange' in attrs) { + if ('valueRange' in attrs && !('noZoomFlagChange' in attrs)) { this.zoomed_y_ = attrs.valueRange != null; } diff --git a/tests/no-zoom-change.html b/tests/no-zoom-change.html new file mode 100644 index 0000000..e1b93d0 --- /dev/null +++ b/tests/no-zoom-change.html @@ -0,0 +1,132 @@ + + + zoom + + + + + + + + +

Click the buttons to change the date and value windows of the chart.

+

Window coordinates (in dates and values):

+
+
+
+

+ Toggle the check box below to determine the difference in operation of the zoom flags + when the date and value windows of the chart are changed using the arrows underneath. +

+ Do not change zoom +
+ +
+

Zoomed: False

+

Zoomed X: False

+

Zoomed Y: False

+

+
+

+

+

+ + +

+

+

+
+
+
+

+ + +

+
+ + +