X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph-canvas.js;h=29341e1b83bd5b0b883ad4d3d2ca30a078816275;hb=2c95097e35231ad5b40c6ce1903c77a07b3f3158;hp=c6c5b1e87b5bc6adee6fbc84f5e041d434dfd330;hpb=b304aaecb6728af27bc6f7e2b553570556e85e45;p=dygraphs.git diff --git a/dygraph-canvas.js b/dygraph-canvas.js index c6c5b1e..29341e1 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -386,8 +386,11 @@ DygraphCanvasRenderer.isSupported = function(canvasName) { * Draw an X/Y grid on top of the existing plot */ DygraphCanvasRenderer.prototype.render = function() { - // Draw the new X/Y grid + // Draw the new X/Y grid. Lines appear crisper when pixels are rounded to + // half-integers. This prevents them from drawing in two rows/cols. var ctx = this.element.getContext("2d"); + function halfUp(x){return Math.round(x)+0.5}; + function halfDown(y){return Math.round(y)-0.5}; if (this.options.underlayCallback) { this.options.underlayCallback(ctx, this.area, this.layout, this.dygraph_); @@ -401,8 +404,8 @@ DygraphCanvasRenderer.prototype.render = function() { for (var i = 0; i < ticks.length; i++) { // TODO(danvk): allow secondary axes to draw a grid, too. if (ticks[i][0] != 0) continue; - var x = this.area.x; - var y = this.area.y + ticks[i][1] * this.area.h; + var x = halfUp(this.area.x); + var y = halfDown(this.area.y + ticks[i][1] * this.area.h); ctx.beginPath(); ctx.moveTo(x, y); ctx.lineTo(x + this.area.w, y); @@ -417,8 +420,8 @@ DygraphCanvasRenderer.prototype.render = function() { ctx.strokeStyle = this.options.gridLineColor; ctx.lineWidth = this.options.axisLineWidth; for (var i=0; i