Fix error when labelsDiv=null (was affecting unboxed-spark test)
authorDan Vanderkam <dan@dygraphs.com>
Sat, 17 Mar 2012 18:09:39 +0000 (14:09 -0400)
committerDan Vanderkam <dan@dygraphs.com>
Sat, 17 Mar 2012 18:09:39 +0000 (14:09 -0400)
auto_tests/tests/pathological_cases.js
dygraph.js

index c134b5f..21ff30a 100644 (file)
@@ -35,3 +35,16 @@ pathologicalCasesTestCase.prototype.testOnePoint = function() {
   var graph = document.getElementById("graph");
   var g = new Dygraph(graph, data, opts);
 };
+
+pathologicalCasesTestCase.prototype.testNullLegend = function() {
+  var opts = {
+    width: 480,
+    height: 320,
+    labelsDiv: null
+  };
+  var data = "X,Y\n" +
+             "1,2\n";
+
+  var graph = document.getElementById("graph");
+  var g = new Dygraph(graph, data, opts);
+};
index 79b53a9..045c394 100644 (file)
@@ -1842,6 +1842,8 @@ Dygraph.prototype.generateLegendHTML_ = function(x, sel_points, oneEmWidth) {
  */
 Dygraph.prototype.setLegendHTML_ = function(x, sel_points) {
   var labelsDiv = this.attr_("labelsDiv");
+  if (!labelsDiv) return;
+
   var sizeSpan = document.createElement('span');
   // Calculates the width of 1em in pixels for the legend.
   sizeSpan.setAttribute('style', 'margin: 0; padding: 0 0 0 1em; border: 0;');