From 4ecb55b5c66f7723d1f5c588af62855bd4c06faa Mon Sep 17 00:00:00 2001 From: Robert Konigsberg Date: Thu, 21 Feb 2013 15:46:01 -0500 Subject: [PATCH] Fix bug 436. Only restore axes that remain after an option update. --- auto_tests/tests/multiple_axes.js | 24 ++++++++++++++++++++++++ dygraph.js | 7 ++++++- 2 files changed, 30 insertions(+), 1 deletion(-) 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]; } } -- 2.7.4