From b47888a7cca024edfd3adf046c569e5818290f03 Mon Sep 17 00:00:00 2001 From: Brian Cappello Date: Sat, 8 Oct 2016 16:00:48 -0400 Subject: [PATCH] make horizontal lines render in alignment with monitor pixels --- src/plot/axisannotation.js | 2 +- src/plot/crosshair.js | 2 ++ src/plot/plot.js | 7 ++++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/plot/axisannotation.js b/src/plot/axisannotation.js index 89684b57..70c36200 100644 --- a/src/plot/axisannotation.js +++ b/src/plot/axisannotation.js @@ -73,7 +73,7 @@ module.exports = function(d3_svg_axis, d3_scale_linear, accessor_value, plot, pl function refresh(selection, accessor, axis, orient, format, height, width, point, translate) { var neg = orient === 'left' || orient === 'top' ? -1 : 1; - selection.attr('transform', 'translate(' + translate[0] + ',' + translate[1] + ')'); + selection.attr('transform', 'translate(' + translate[0] + ',' + (translate[1] - 0.5) + ')'); selection.select('path').attr('d', backgroundPath(accessor, axis, orient, height, width, point, neg)); selection.select('text').text(textValue(accessor, format)).call(textAttributes, accessor, axis, orient, neg); } diff --git a/src/plot/crosshair.js b/src/plot/crosshair.js index 9290b193..49013d18 100644 --- a/src/plot/crosshair.js +++ b/src/plot/crosshair.js @@ -127,6 +127,8 @@ module.exports = function(d3_select, d3_event, d3_mouse, d3_dispatch, accessor_c if(p.accessor.yv(d) === null) return null; var value = p.yScale(p.accessor.yv(d)); if(isNaN(value)) return null; + else value -= 0.5; + return 'M ' + range[0] + ' ' + value + ' L ' + range[range.length-1] + ' ' + value; }; } diff --git a/src/plot/plot.js b/src/plot/plot.js index 8c198771..3a342f2d 100644 --- a/src/plot/plot.js +++ b/src/plot/plot.js @@ -243,10 +243,11 @@ module.exports = function(d3_svg_line, d3_svg_area, d3_line_interpolate, d3_sele if(!d.length) return null; var firstDatum = d[0], - lastDatum = d[d.length-1]; + lastDatum = d[d.length-1], + yValue = Math.floor(y(accessor_value(firstDatum))) + 0.5; - return 'M ' + x(accessor_date(firstDatum)) + ' ' + y(accessor_value(firstDatum)) + - ' L ' + x(accessor_date(lastDatum)) + ' ' + y(accessor_value(lastDatum)); + return 'M ' + x(accessor_date(firstDatum)) + ' ' + yValue + + ' L ' + x(accessor_date(lastDatum)) + ' ' + yValue; }; },