Skip to content

Commit

Permalink
fix(overlay): convert x pixels to point value
Browse files Browse the repository at this point in the history
Touch listener returns X Point value instead of pixels in screen.

Fixes #13
  • Loading branch information
Pfuster12 committed Jun 22, 2020
1 parent 15985a5 commit 00cbc70
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ class LiveChartTouchOverlay(context: Context, attrs: AttributeSet?)
}
}

private fun Float.xPixelsToPoint(): Float {
return this*xBoundsToPixels()
}

/**
* Transform a X Axis data point to screen pixels.
*/
Expand All @@ -264,7 +268,7 @@ class LiveChartTouchOverlay(context: Context, attrs: AttributeSet?)
overlayPoint.y = coordinates[1] - (chartStyle.overlayCircleDiameter/2)

touchListener?.onTouchCallback(DataPoint(
x = coordinates[0],
x = coordinates[0].xPixelsToPoint(),
y = coordinates[1].yPixelsToPoint()
))

Expand All @@ -285,7 +289,7 @@ class LiveChartTouchOverlay(context: Context, attrs: AttributeSet?)
overlayPoint.y = coordinates[1] - (chartStyle.overlayCircleDiameter/2)

touchListener?.onTouchCallback(DataPoint(
x = coordinates[0],
x = coordinates[0].xPixelsToPoint(),
y = coordinates[1].yPixelsToPoint()
))

Expand Down

0 comments on commit 00cbc70

Please sign in to comment.