2.0.0 release fixes (#815)
[dygraphs.git] / src / plugins / grid.js
index bf6e3fe..626ed94 100644 (file)
@@ -15,7 +15,6 @@ Current bits of jankiness:
 
 "use strict";
 
-
 /**
  * Draws the gridlines, i.e. the gray horizontal & vertical lines running the
  * length of the chart.
@@ -62,28 +61,27 @@ grid.prototype.willDrawChart = function(e) {
     ticks = layout.yticks;
     ctx.save();
     // draw grids for the different y axes
-    for (i = 0; i < ticks.length; i++) {
-      var axis = ticks[i][0];
-      if(drawGrid[axis]) {
+    ticks.forEach(tick => {
+      if (!tick.has_tick) return;
+      var axis = tick.axis;
+      if (drawGrid[axis]) {
+        ctx.save();
         if (stroking[axis]) {
-          ctx.installPattern(strokePattern[axis]);
+          if (ctx.setLineDash) ctx.setLineDash(strokePattern[axis]);
         }
         ctx.strokeStyle = strokeStyles[axis];
         ctx.lineWidth = lineWidths[axis];
 
         x = halfUp(area.x);
-        y = halfDown(area.y + ticks[i][1] * area.h);
+        y = halfDown(area.y + tick.pos * area.h);
         ctx.beginPath();
         ctx.moveTo(x, y);
         ctx.lineTo(x + area.w, y);
-        ctx.closePath();
         ctx.stroke();
 
-        if (stroking[axis]) {
-          ctx.uninstallPattern();
-        }
+        ctx.restore();
       }
-    }
+    });
     ctx.restore();
   }
 
@@ -94,21 +92,22 @@ grid.prototype.willDrawChart = function(e) {
     var strokePattern = g.getOptionForAxis('gridLinePattern', 'x');
     var stroking = strokePattern && (strokePattern.length >= 2);
     if (stroking) {
-      ctx.installPattern(strokePattern);
+      if (ctx.setLineDash) ctx.setLineDash(strokePattern);
     }
     ctx.strokeStyle = g.getOptionForAxis('gridLineColor', 'x');
     ctx.lineWidth = g.getOptionForAxis('gridLineWidth', 'x');
-    for (i = 0; i < ticks.length; i++) {
-      x = halfUp(area.x + ticks[i][0] * area.w);
+    ticks.forEach(tick => {
+      if (!tick.has_tick) return;
+      x = halfUp(area.x + tick.pos * area.w);
       y = halfDown(area.y + area.h);
       ctx.beginPath();
       ctx.moveTo(x, y);
       ctx.lineTo(x, area.y);
       ctx.closePath();
       ctx.stroke();
-    }
+    });
     if (stroking) {
-      ctx.uninstallPattern();
+      if (ctx.setLineDash) ctx.setLineDash([]);
     }
     ctx.restore();
   }