From: Dan Vanderkam Date: Tue, 3 Jan 2012 22:37:13 +0000 (-0500) Subject: Fix issue 249 & add regression test X-Git-Tag: v1.0.0~380 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=4a0cb9c4671b5c212da6ebc71e25fb9d1aaec692;p=dygraphs.git Fix issue 249 & add regression test --- diff --git a/auto_tests/tests/update_options.js b/auto_tests/tests/update_options.js index 482b92b..ac28e99 100644 --- a/auto_tests/tests/update_options.js +++ b/auto_tests/tests/update_options.js @@ -151,3 +151,24 @@ UpdateOptionsTestCase.prototype.testUpdateColors = function() { graph.updateOptions({ colors: null, file: this.data }); assertEquals(defaultColors, graph.getColors()); } + +// Regression test for http://code.google.com/p/dygraphs/issues/detail?id=249 +// Verifies that setting 'legend: always' via update immediately shows the +// legend. +UpdateOptionsTestCase.prototype.testUpdateLegendAlways = function() { + var graphDiv = document.getElementById("graph"); + var graph = new Dygraph(graphDiv, this.data, this.opts); + + var legend = document.getElementsByClassName("dygraph-legend"); + assertEquals(1, legend.length); + legend = legend[0]; + assertEquals("", legend.innerHTML); + + graph.updateOptions({legend: 'always'}); + + legend = document.getElementsByClassName("dygraph-legend"); + assertEquals(1, legend.length); + legend = legend[0]; + assertNotEquals(-1, legend.textContent.indexOf("Y1")); + assertNotEquals(-1, legend.textContent.indexOf("Y2")); +}; diff --git a/dygraph.js b/dygraph.js index 79bc7ca..9264961 100644 --- a/dygraph.js +++ b/dygraph.js @@ -2051,10 +2051,10 @@ Dygraph.prototype.renderGraph_ = function(is_initial_draw, clearSelection) { this.canvas_.getContext('2d').clearRect(0, 0, this.canvas_.width, this.canvas_.height); - if (is_initial_draw) { - // Generate a static legend before any particular point is selected. - this.setLegendHTML_(); - } else { + // Generate a static legend before any particular point is selected. + this.setLegendHTML_(); + + if (!is_initial_draw) { if (clearSelection) { if (typeof(this.selPoints_) !== 'undefined' && this.selPoints_.length) { // We should select the point nearest the page x/y here, but it's easier