Merge pull request #250 from wimme/patch-4
authorRobert Konigsberg <konigsberg@gmail.com>
Thu, 6 Jun 2013 02:11:44 +0000 (19:11 -0700)
committerRobert Konigsberg <konigsberg@gmail.com>
Thu, 6 Jun 2013 02:11:44 +0000 (19:11 -0700)
LogScale and customBars with negative values

auto_tests/tests/custom_bars.js
dygraph.js

index 2169ade..231dcd8 100644 (file)
@@ -151,3 +151,33 @@ CustomBarsTestCase.prototype.testCustomBarsLogScale = function() {
        [247.5, 152.02209814465604]],
       { fillStyle: "#00ff00" });
 };
+
+CustomBarsTestCase.prototype.testCustomBarsWithNegativeValuesInLogScale =
+    function() {
+  var graph = document.getElementById("graph");
+
+  var count = 0;
+  var drawPointCallback = function() {
+    count++;
+  };
+
+  var g = new Dygraph(graph,
+      [
+        [1, [10, 20,30]],
+        [2, [5, 10, 15]],
+        [3, [-1, 5, 10]]
+      ],
+      {
+        drawPoints: true,
+        drawPointCallback : drawPointCallback,
+        customBars: true
+      });
+
+  // Normally all three points would be drawn.
+  assertEquals(3, count);
+  count = 0;
+
+  // In log scale, the third point shouldn't be shown.
+  g.updateOptions({ logscale : true });
+  assertEquals(2, count);
+};
index bd11c24..dc3b798 100644 (file)
@@ -2824,12 +2824,20 @@ Dygraph.prototype.extractSeries_ = function(rawData, i, logScale) {
     if (logScale) {
       // On the log scale, points less than zero do not exist.
       // This will create a gap in the chart.
-      if (point <= 0) {
+      if (errorBars || customBars) {
+        // point.length is either 2 (errorBars) or 3 (customBars)
+        for (var k = 0; k < point.length; k++) {
+          if (point[k] <= 0) {
+            point = null;
+            break;
+          }
+        }
+      } else if (point <= 0) {
         point = null;
       }
     }
     // Fix null points to fit the display type standard.
-    if(point !== null) {
+    if (point !== null) {
       series.push([x, point]);
     } else {
       series.push([x, errorBars ? [null, null] : customBars ? [null, null, null] : point]);