From 366530ef9f7af7c6b5cfd0daa9c7eefe0c9a3abd Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Fri, 29 Apr 2022 17:54:45 +0200 Subject: [PATCH] fix: Always update finger X --- src/AnimatedLineGraph.tsx | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/AnimatedLineGraph.tsx b/src/AnimatedLineGraph.tsx index 11a64ea..3af8812 100644 --- a/src/AnimatedLineGraph.tsx +++ b/src/AnimatedLineGraph.tsx @@ -167,22 +167,20 @@ export function AnimatedLineGraph({ const setFingerX = useCallback( (fingerX: number) => { - if (isActive.value) { - const y = getYForX(commands.current, fingerX) + const y = getYForX(commands.current, fingerX) - if (y != null) { - circleY.current = y - circleX.current = fingerX - } - pathEnd.current = fingerX / width - - const index = Math.round((fingerX / width) * points.length) - const pointIndex = Math.min(Math.max(index, 0), points.length - 1) - const dataPoint = points[Math.round(pointIndex)] - if (dataPoint != null) onPointSelected?.(dataPoint) + if (y != null) { + circleY.current = y + circleX.current = fingerX } + pathEnd.current = fingerX / width + + const index = Math.round((fingerX / width) * points.length) + const pointIndex = Math.min(Math.max(index, 0), points.length - 1) + const dataPoint = points[Math.round(pointIndex)] + if (dataPoint != null) onPointSelected?.(dataPoint) }, - [circleX, circleY, isActive, onPointSelected, pathEnd, points, width] + [circleX, circleY, onPointSelected, pathEnd, points, width] ) const setIsActive = useCallback( (active: boolean) => {