Merge branch 'master' of https://github.com/danvk/dygraphs into auto-tests
authorRobert Konigsberg <konigsberg@google.com>
Thu, 6 Jun 2013 11:27:07 +0000 (07:27 -0400)
committerRobert Konigsberg <konigsberg@google.com>
Thu, 6 Jun 2013 11:27:07 +0000 (07:27 -0400)
auto_tests/tests/custom_bars.js
auto_tests/tests/grid_per_axis.js
dygraph-layout.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 e5c960f..9731514 100644 (file)
@@ -251,7 +251,7 @@ GridPerAxisTestCase.prototype.testPerAxisGridWidth = function() {
 };
 GridPerAxisTestCase.prototype.testGridLinePattern = function() {
   var opts = {
-    width : 480,
+    width : 120,
     height : 320,
     errorBars : false,
     drawXGrid : false,
@@ -291,7 +291,7 @@ GridPerAxisTestCase.prototype.testGridLinePattern = function() {
   }
   var x, y;
   // Step through all gridlines of the axis
-  for ( var i = 0; i < yGridlines.length; i++) {
+  for (var i = 0; i < yGridlines.length; i++) {
     y = halfDown(g.toDomYCoord(yGridlines[i], 0));
     // Step through the pixels of the line and test the pattern.
     for (x = halfUp(g.plotter_.area.x); x < g.plotter_.area.w; x++) {
@@ -304,11 +304,11 @@ GridPerAxisTestCase.prototype.testGridLinePattern = function() {
       var pattern = (Math.floor((x) / 10)) % 2;
       switch (pattern) {
       case 0: // fill
-        assertEquals("Unexpected filled grid-pattern color found at pixel: x: " + x + "y: "
+        assertEquals("Unexpected filled grid-pattern color found at pixel: x: " + x + " y: "
             + y, [ 0, 0, 255 ], drawnPixel);
         break;
       case 1: // no fill
-        assertEquals("Unexpected empty grid-pattern color found at pixel: x: " + x + "y: "
+        assertEquals("Unexpected empty grid-pattern color found at pixel: x: " + x + " y: "
             + y, [ 0, 0, 0 ], drawnPixel);
         break;
       }
index 4b600f7..54496aa 100644 (file)
@@ -63,7 +63,7 @@ DygraphLayout.prototype.getPlotArea = function() {
 };
 
 // Compute the box which the chart should be drawn in. This is the canvas's
-// box, less space needed for axis and chart labels.
+// box, less space needed for axis, chart labels, and other plug-ins.
 // NOTE: This should only be called by Dygraph.predraw_().
 DygraphLayout.prototype.computePlotArea = function() {
   var area = {
@@ -162,10 +162,6 @@ DygraphLayout.prototype.setYAxes = function (yAxes) {
   this.yAxes_ = yAxes;
 };
 
-DygraphLayout.prototype.setDateWindow = function(dateWindow) {
-  this.dateWindow_ = dateWindow;
-};
-
 DygraphLayout.prototype.evaluate = function() {
   this._evaluateLimits();
   this._evaluateLineCharts();
index 466ce92..dc3b798 100644 (file)
@@ -2484,7 +2484,6 @@ Dygraph.prototype.drawGraph_ = function() {
   // Save the X axis zoomed status as the updateOptions call will tend to set it erroneously
   var tmp_zoomed_x = this.zoomed_x_;
   // Tell PlotKit to use this new data and render itself
-  this.layout_.setDateWindow(this.dateWindow_);
   this.zoomed_x_ = tmp_zoomed_x;
   this.layout_.evaluateWithError();
   this.renderGraph_(is_initial_draw);
@@ -2825,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]);