RFC: make horizontal lines render in alignment with monitor pixels #169
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi. I noticed that horizontal lines were often rendering in a "blurry" way, and this PR is the result of my trip down the rabbit hole of SVG rendering. (See this answer on StackOverflow, and the comment on it.)
The short of it is, horizontal/vertical lines should be drawn on half pixel values, instead of integer pixel values. You can see upstream d3 does this when drawing axes (link to relevant source code).
If you look at my changes, you'll notice that for drawing the crosshairs I used
-0.5
, while for indicator plots I used+0.5
. I don't have a logical explanation for you there, other than that visually, those modifications seem to reliably give the desired result. (Yea, kinda hand wavy... I wish I had a better understanding of why, but, no such luck :( To see what I mean, compare the overbought/oversold lines to the axis ticks d3 draws, and the crosshair line to the crosshair cursor the OS draws. It helps if you turn off dasharray/opacity styles.)Other comments:
Thanks!