X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=src%2Fplugins%2Fgrid.js;h=25126db3cbd1a19b1f7902b3c6549f7462bf6bfa;hb=bd6ee5dcf9017abcbefa480e79756a6957c5c7ed;hp=bf6e3fecfd41df0d704707d5471780f5740ea4d2;hpb=6ecc073934b76e5076f917112a24ff7094857730;p=dygraphs.git diff --git a/src/plugins/grid.js b/src/plugins/grid.js index bf6e3fe..25126db 100644 --- a/src/plugins/grid.js +++ b/src/plugins/grid.js @@ -62,26 +62,25 @@ 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]) { + for (var tick of ticks) { + if (!tick.has_tick) continue; + 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,12 +93,13 @@ 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); + for (var tick of ticks) { + if (!tick.has_tick) continue; + x = halfUp(area.x + tick.pos * area.w); y = halfDown(area.y + area.h); ctx.beginPath(); ctx.moveTo(x, y); @@ -108,7 +108,7 @@ grid.prototype.willDrawChart = function(e) { ctx.stroke(); } if (stroking) { - ctx.uninstallPattern(); + if (ctx.setLineDash) ctx.setLineDash([]); } ctx.restore(); }