Skip to content

Commit

Permalink
fix: Always update finger X
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Apr 29, 2022
1 parent 793a158 commit 366530e
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/AnimatedLineGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 366530e

Please sign in to comment.