fix error when no series are visible
authorDan Vanderkam <dan@dygraphs.com>
Sat, 19 Mar 2011 16:46:52 +0000 (12:46 -0400)
committerDan Vanderkam <dan@dygraphs.com>
Sat, 19 Mar 2011 16:46:52 +0000 (12:46 -0400)
dygraph.js
tests/no-visibility.html [new file with mode: 0644]

index 5030123..64f4c18 100644 (file)
@@ -2635,6 +2635,20 @@ Dygraph.prototype.computeYAxisRanges_ = function(extremes) {
     seriesForAxis[idx].push(series);
   }
 
+  // If no series are defined or visible then fill in some reasonable defaults.
+  if (seriesForAxis.length == 0) {
+    var axis = this.axes_[0];
+    axis.computedValueRange = [0, 1];
+    var ret =
+      Dygraph.numericTicks(axis.computedValueRange[0],
+                           axis.computedValueRange[1],
+                           this,
+                           axis);
+    axis.ticks = ret.ticks;
+    this.numYDigits_ = ret.numDigits;
+    return;
+  }
+
   // Compute extreme values, a span and tick marks for each axis.
   for (var i = 0; i < this.axes_.length; i++) {
     var axis = this.axes_[i];
diff --git a/tests/no-visibility.html b/tests/no-visibility.html
new file mode 100644 (file)
index 0000000..5fcfd5b
--- /dev/null
@@ -0,0 +1,31 @@
+<html>
+  <head>
+    <title>no-visibility</title>
+    <!--[if IE]>
+    <script type="text/javascript" src="../excanvas.js"></script>
+    <![endif]-->
+    <script type="text/javascript" src="../strftime/strftime-min.js"></script>
+    <script type="text/javascript" src="../rgbcolor/rgbcolor.js"></script>
+    <script type="text/javascript" src="../dygraph-canvas.js"></script>
+    <script type="text/javascript" src="../dygraph.js"></script>
+    <script type="text/javascript" src="data.js"></script>
+  </head>
+  <body>
+    <h3>No visible series</h3>
+    <p>This test verifies that a chart will still draw without any JS errors
+    when no series are visible.</p>
+    <div id="div_g" style="width:400px; height:200px;"></div>
+
+    <script type="text/javascript">
+      g = new Dygraph(
+            document.getElementById("div_g"),
+            NoisyData, {
+              rollPeriod: 7,
+              errorBars: true,
+              visibility: [false, false]
+            }
+          );
+    </script>
+
+  </body>
+</html>