fix a bug involving calculation of span w/r/t/ includeZero
authorDan Vanderkam <danvdk@gmail.com>
Sun, 31 Jan 2010 05:10:28 +0000 (21:10 -0800)
committerDan Vanderkam <danvdk@gmail.com>
Sun, 31 Jan 2010 05:10:28 +0000 (21:10 -0800)
dygraph.js
tests/small-range-zero.html [new file with mode: 0644]

index ea25980..1df7cc1 100644 (file)
@@ -1290,6 +1290,11 @@ Dygraph.prototype.drawGraph_ = function(data) {
   if (this.valueRange_ != null) {
     this.addYTicks_(this.valueRange_[0], this.valueRange_[1]);
   } else {
+    // This affects the calculation of span, below.
+    if (this.attr_("includeZero") && minY > 0) {
+      minY = 0;
+    }
+
     // Add some padding and round up to an integer to be human-friendly.
     var span = maxY - minY;
     // special case: if we have no sense of scale, use +/-10% of the sole value.
diff --git a/tests/small-range-zero.html b/tests/small-range-zero.html
new file mode 100644 (file)
index 0000000..3226625
--- /dev/null
@@ -0,0 +1,32 @@
+<html>
+  <head>
+    <title>no range</title>
+    <!--[if IE]>
+    <script type="text/javascript" src="excanvas.js"></script>
+    <![endif]-->
+    <script type="text/javascript" src="../dygraph-combined.js"></script>
+    <script type="text/javascript" src="../dygraph-canvas.js"></script>
+    <script type="text/javascript" src="../dygraph.js"></script>
+  </head>
+  <body>
+    <p>There should be an appropriate amount of padding at the top of the chart:</p>
+    <div id="blah"></div>
+
+    <script type="text/javascript">
+    function CSV() {
+      var label = "X";
+      
+      return "date," + label + "\n20091206,2659329.631743\n20091213,2772361.123362\n20091220,2737584.647191\n20091227,2720000.550414\n20100103,2910306.897977\n20100110,2901385.313093\n20100117,2903041.312099\n20100124,2966455.128911\n";
+    }
+
+    new Dygraph(document.getElementById("blah"),
+                CSV,
+                {
+                  width: 640,
+                  height: 480,
+                  includeZero: true
+                });
+
+    </script>
+  </body>
+</html>