From 02ca8af6e6ce10bb00300ba40ba24cfeed0c126a Mon Sep 17 00:00:00 2001 From: Ryan Gaus Date: Thu, 7 Jun 2018 15:43:17 -0400 Subject: [PATCH] chore(bug): fix vertical offset line chart issue If a vertical offset was defined, this would cause overlays and rules to be offset upward by the number of pixels included in the offset. Fixed by applying the inverse offset to all y axis values. --- src/charts/line-chart/axes.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/charts/line-chart/axes.js b/src/charts/line-chart/axes.js index 3d5e0c1..ab65c58 100644 --- a/src/charts/line-chart/axes.js +++ b/src/charts/line-chart/axes.js @@ -128,10 +128,9 @@ export function yAxisMinMax({ let x = -1 * (leftMargin - leftOffset); let y = scale(d.value) + axisFontSize * 0.4; - // Adjust the first datapoint to match with the vertical baseline of the chart. - if (d.value === firstEventYValue) { - y -= (defaultDataset.verticalBaselineOffset || 0); - } + // Adjust datapoints upward to take into account vertical offset defined on default dataset + y -= (defaultDataset.verticalBaselineOffset || 0); + return `translate(${x},${y})`; }); mergeSelection.select('.axis-y-point-label') @@ -161,7 +160,7 @@ export function yAxisMinMax({ .attr('x', leftMargin - leftOffset) .attr('y', -1 * (axisFontSize * 0.4)) .attr('width', graphWidth) - .attr('height', d => scale(0) - scale(d.value)) + .attr('height', d => (scale(0) - scale(d.value)) + (defaultDataset.verticalBaselineOffset || 0)) .attr('fill', d => { if (d.hasShadow) { return 'rgba(65, 152, 255, 0.1)';