Fix issue 249 & add regression test
authorDan Vanderkam <danvk@google.com>
Tue, 3 Jan 2012 22:37:13 +0000 (17:37 -0500)
committerDan Vanderkam <danvk@google.com>
Tue, 3 Jan 2012 22:37:13 +0000 (17:37 -0500)
auto_tests/tests/update_options.js
dygraph.js

index 482b92b..ac28e99 100644 (file)
@@ -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"));
+};
index 79bc7ca..9264961 100644 (file)
@@ -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