Log warnings when using non-existent options
[dygraphs.git] / auto_tests / tests / update_options.js
index b40d705..faf8f25 100644 (file)
@@ -67,7 +67,7 @@ UpdateOptionsTestCase.prototype.testStrokeSingleSeries = function() {
   var optionsForY1 = { };
 
   optionsForY1['strokeWidth'] = 3;
-  updatedOptions['Y1'] = optionsForY1;
+  updatedOptions['series'] = {'Y1': optionsForY1};
 
   // These options will allow us to jump to renderGraph_()
   // drawGraph_() will be skipped.
@@ -80,17 +80,16 @@ UpdateOptionsTestCase.prototype.testStrokeSingleSeries = function() {
 UpdateOptionsTestCase.prototype.testSingleSeriesRequiresNewPoints = function() {
   var graphDiv = document.getElementById("graph");
   var graph = new Dygraph(graphDiv, this.data, this.opts);
-  var updatedOptions = { };
-  var optionsForY1 = { };
-  var optionsForY2 = { };
-
-  // This will not require new points.
-  optionsForY1['strokeWidth'] = 2;
-  updatedOptions['Y1'] = optionsForY1;
-
-  // This will require new points.
-  optionsForY2['stepPlot'] = true;
-  updatedOptions['Y2'] = optionsForY2;
+  var updatedOptions = {
+    series: {
+      Y1: {
+        strokeWidth: 2
+      },
+      Y2: {
+        stepPlot: true
+      }
+    }
+  };
 
   // These options will not allow us to jump to renderGraph_()
   // drawGraph_() must be called
@@ -136,11 +135,39 @@ UpdateOptionsTestCase.prototype.testUpdateColors = function() {
   graph.updateOptions({ colors: colors1 });
   assertEquals(colors1, graph.getColors());
 
-  var colors2 = [ "#aaa", "#bbb", "#ccc" ];
+  // extra colors are ignored until you add additional data series.
+  var colors2 = [ "#ddd", "#eee", "#fff" ];
   graph.updateOptions({ colors: colors2 });
-  assertEquals(colors2, graph.getColors());
+  assertEquals(["#ddd", "#eee"], graph.getColors());
 
+  graph.updateOptions({ file:
+      "X,Y1,Y2,Y3\n" +
+      "2011-01-01,2,3,4\n" +
+      "2011-02-02,5,3,2\n"
+  });
+  assertEquals(colors2, graph.getColors());
 
-  graph.updateOptions({ colors: null });
+  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"));
+};