From 850c2020af0e58cefeedf47613f50f7a295e47db Mon Sep 17 00:00:00 2001 From: kalitsinskyi Date: Wed, 20 Oct 2021 13:46:20 +0300 Subject: [PATCH] =?UTF-8?q?#798=20=D0=A1lipped=20chart=20when=20zoomed=20m?= =?UTF-8?q?aximum=20or=20shifted=20with=20onPan=20event?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/scale/evaluator.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/lib/scale/evaluator.js b/src/lib/scale/evaluator.js index b6726c021..68a589c8e 100644 --- a/src/lib/scale/evaluator.js +++ b/src/lib/scale/evaluator.js @@ -144,13 +144,15 @@ function showMax(width, threshold) { } function getFilteredResponse(data, left, right, xAccessor) { - const newLeftIndex = getClosestItemIndexes(data, left, xAccessor).right; - const newRightIndex = getClosestItemIndexes(data, right, xAccessor).left; + const closestLeftIndex = getClosestItemIndexes(data, left, xAccessor).right; + const closestRightIndex = getClosestItemIndexes(data, right, xAccessor).left; - const filteredData = data.slice(newLeftIndex, newRightIndex + 1); - // console.log(right, newRightIndex, dataForInterval.length); + // add extra data point on the sides, in case when + // the chart is maximum zoomed and data disappears from sides due filtering logic + const newLeftIndex = closestLeftIndex >= 1 ? closestLeftIndex - 1 : closestLeftIndex; + const newRightIndex = closestRightIndex < data.length ? closestRightIndex + 1 : closestRightIndex; - return filteredData; + return data.slice(newLeftIndex, newRightIndex + 1); } export default function({