Commit 739cefd5 authored by David Schnur's avatar David Schnur

Add sub-pixel adjustments to avoid blurry markings.

Fixes #1210.
parent e5d22378
...@@ -1963,26 +1963,34 @@ Licensed under the MIT license. ...@@ -1963,26 +1963,34 @@ Licensed under the MIT license.
yrange.from = Math.max(yrange.from, yrange.axis.min); yrange.from = Math.max(yrange.from, yrange.axis.min);
yrange.to = Math.min(yrange.to, yrange.axis.max); yrange.to = Math.min(yrange.to, yrange.axis.max);
if (xrange.from == xrange.to && yrange.from == yrange.to) var xequal = xrange.from === xrange.to,
yequal = yrange.from === yrange.to;
if (xequal && yequal) {
continue; continue;
}
// then draw // then draw
xrange.from = xrange.axis.p2c(xrange.from); xrange.from = Math.floor(xrange.axis.p2c(xrange.from));
xrange.to = xrange.axis.p2c(xrange.to); xrange.to = Math.floor(xrange.axis.p2c(xrange.to));
yrange.from = yrange.axis.p2c(yrange.from); yrange.from = Math.floor(yrange.axis.p2c(yrange.from));
yrange.to = yrange.axis.p2c(yrange.to); yrange.to = Math.floor(yrange.axis.p2c(yrange.to));
if (xrange.from == xrange.to || yrange.from == yrange.to) { if (xequal || yequal) {
// draw line var lineWidth = m.lineWidth || options.grid.markingsLineWidth,
subPixel = lineWidth % 2 ? 0.5 : 0;
ctx.beginPath(); ctx.beginPath();
ctx.strokeStyle = m.color || options.grid.markingsColor; ctx.strokeStyle = m.color || options.grid.markingsColor;
ctx.lineWidth = m.lineWidth || options.grid.markingsLineWidth; ctx.lineWidth = lineWidth;
ctx.moveTo(xrange.from, yrange.from); if (xequal) {
ctx.lineTo(xrange.to, yrange.to); ctx.moveTo(xrange.to + subPixel, yrange.from);
ctx.lineTo(xrange.to + subPixel, yrange.to);
} else {
ctx.moveTo(xrange.from, yrange.to + subPixel);
ctx.lineTo(xrange.to, yrange.to + subPixel);
}
ctx.stroke(); ctx.stroke();
} } else {
else {
// fill area
ctx.fillStyle = m.color || options.grid.markingsColor; ctx.fillStyle = m.color || options.grid.markingsColor;
ctx.fillRect(xrange.from, yrange.to, ctx.fillRect(xrange.from, yrange.to,
xrange.to - xrange.from, xrange.to - xrange.from,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment