From: Robert Konigsberg Date: Thu, 21 Feb 2013 20:46:01 +0000 (-0500) Subject: Fix bug 436. Only restore axes that remain after an option update. X-Git-Tag: v1.0.0~51^2 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=4ecb55b5c66f7723d1f5c588af62855bd4c06faa;p=dygraphs.git Fix bug 436. Only restore axes that remain after an option update. --- diff --git a/auto_tests/tests/multiple_axes.js b/auto_tests/tests/multiple_axes.js index 3033190..8d94803 100644 --- a/auto_tests/tests/multiple_axes.js +++ b/auto_tests/tests/multiple_axes.js @@ -257,3 +257,27 @@ MultipleAxesTestCase.prototype.testDrawPointCallback = function() { assertEquals(1, results.y2["Y3"]); assertEquals(1, results.y2["Y4"]); }; + +// Test for http://code.google.com/p/dygraphs/issues/detail?id=436 +MultipleAxesTestCase.prototype.testRemovingSecondAxis = function() { + var data = MultipleAxesTestCase.getData(); + + var results = { y : {}, y2 : {}}; + + g = new Dygraph( + document.getElementById("graph"), + data, + { + labels: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ], + drawPoints : true, + pointSize : 3, + series : { + 'Y4': { + axis: 'y2' + } + }, + } + ); + + g.updateOptions({ series : { Y4 : { axis : 'y' } } }); +}; diff --git a/dygraph.js b/dygraph.js index f198cff..9a5be72 100644 --- a/dygraph.js +++ b/dygraph.js @@ -2472,7 +2472,12 @@ Dygraph.prototype.computeYAxes_ = function() { if (valueWindows !== undefined) { // Restore valueWindow settings. - for (index = 0; index < valueWindows.length; index++) { + + // When going from two axes back to one, we only restore + // one axis. + var idxCount = Math.min(valueWindows.length, this.axes_.length); + + for (index = 0; index < idxCount; index++) { this.axes_[index].valueWindow = valueWindows[index]; } }