danvk/dygraphs — pull request #274 by hulkholden (2013-09-21 08:06:45+00:00)
Title: grid_per_axis test improvements

In https://github.com/danvk/dygraphs/pull/266 I found that the hidpi changes broke the grid_per_axis tests. I spent some time looking at the tests, and couldn't figure out why it was testing that 5 pixels were rendered when it set the line width to 4.

I eventually realised that even width lines were rendered with 50% opaque pixels at either end*. I updated the grid_per_axis tests to better test what's happening here.

I made a couple of other tweaks, including switching the code over to use the PixelSampler utility class.

With this in place, I can iterate on the fix_hidpi patch a bit more, and ensure it's not breaking the grid rendering.

*I think the reason even width lines are drawn like this comes down to this comment in grid.js:
// 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.
function halfUp(x) { return Math.round(x) + 0.5; }
function halfDown(y){ return Math.round(y) - 0.5; }

I think this comment is true for odd lines, but not for even lines. halfUp/halfDown make the odd-width line rendering crisper at the expense of even-width lines.

Also, any idea why x is rounded up and y is rounded down?