Log scale graphs no longer show points with values less than zero.
authorRobert Konigsberg <konigsberg@google.com>
Thu, 27 Jan 2011 22:56:20 +0000 (17:56 -0500)
committerRobert Konigsberg <konigsberg@google.com>
Thu, 27 Jan 2011 22:56:20 +0000 (17:56 -0500)
dygraph.js
tests/logscale-zero.html [new file with mode: 0644]

index ccc79b7..0390a6f 100644 (file)
@@ -2136,12 +2136,24 @@ Dygraph.prototype.drawGraph_ = function() {
 
     var seriesName = this.attr_("labels")[i];
     var connectSeparatedPoints = this.attr_('connectSeparatedPoints', i);
+    var logScale = this.attr_('logscale', i);
 
     var series = [];
     for (var j = 0; j < data.length; j++) {
-      if (data[j][i] != null || !connectSeparatedPoints) {
-        var date = data[j][0];
-        series.push([date, data[j][i]]);
+      var date = data[j][0];
+      var point = data[j][i];
+      if (logScale) {
+        // On the log scale, points less than zero do not exist.
+        // This will create a gap in the chart. Note that this ignores
+        // connectSeparatedPoints.
+        if (point < 0) {
+          point = null;
+        }
+        series.push([date, point]);
+      } else {
+        if (point != null || !connectSeparatedPoints) {
+          series.push([date, point]);
+        }
       }
     }
 
diff --git a/tests/logscale-zero.html b/tests/logscale-zero.html
new file mode 100644 (file)
index 0000000..4eb83b3
--- /dev/null
@@ -0,0 +1,45 @@
+<html>
+  <head>
+    <title>log scale</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>
+  </head>
+
+  <body>
+    <h1>Log scale demo - work in progress</h1>
+    <div id="div_g" style="width:600px; height:300px;"></div>
+      
+    <input type="button" value="log scale" onclick="logScale()">
+    <input type="button" value="linear scale" onclick="linearScale()">
+    <script type="text/javascript">
+      function Data() {
+        return "Date,A\n" +
+        "20101201,5\n"+
+        "20101202,10\n"+
+        "20101203,-1\n"+
+        "20101204,250\n"+
+        "20101205,1000\n"+
+        "20101206,30\n"+
+        "20101207,80\n"+
+        "20101208,100\n"+
+        "20101209,500\n"+
+        "";
+      }
+      var g = new Dygraph(document.getElementById("div_g"),
+                     Data, { logscale : true});
+
+      function logScale() {
+        g.updateOptions({ logscale : true });
+      }
+      function linearScale() {
+        g.updateOptions({ logscale : false });
+      }
+    </script>
+
+  </body>
+</html>