X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=src%2Fplugins%2Fgrid.js;h=626ed944e076b0b2dbb317b8c4b79d723f8f8a62;hb=fd6b8dadbaa0614671bef1508c23d6a932e25081;hp=16a83a2b8658f7eb4b0e7c71ed6005a563f423d4;hpb=e8c70e4e0f4c124a2c68eb43d6ec4e781d1bf810;p=dygraphs.git diff --git a/src/plugins/grid.js b/src/plugins/grid.js index 16a83a2..626ed94 100644 --- a/src/plugins/grid.js +++ b/src/plugins/grid.js @@ -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,9 +61,10 @@ 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]) { if (ctx.setLineDash) ctx.setLineDash(strokePattern[axis]); @@ -73,7 +73,7 @@ grid.prototype.willDrawChart = function(e) { 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); @@ -81,7 +81,7 @@ grid.prototype.willDrawChart = function(e) { ctx.restore(); } - } + }); ctx.restore(); } @@ -96,15 +96,16 @@ grid.prototype.willDrawChart = function(e) { } 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) { if (ctx.setLineDash) ctx.setLineDash([]); }