Skip to content

Instantly share code, notes, and snippets.

@ChristopherME
Created October 24, 2021 06:14
Show Gist options
  • Save ChristopherME/310bf7dc73b61f9f7fa57734a01ff303 to your computer and use it in GitHub Desktop.
Save ChristopherME/310bf7dc73b61f9f7fa57734a01ff303 to your computer and use it in GitHub Desktop.
/**
* Calculates the Y pixel coordinate for a given transaction rate.
*
* @param higherTransactionRateValue the highest rate value in the whole list of transactions.
* @param currentTransactionRate the current transaction RATE while iterating the list of transactions.
* @param canvasHeight the canvas HEIGHT for draw the linear chart.
*
* @return [Float] Y coordinate for a transaction rate.
*/
private fun calculateYCoordinate(
higherTransactionRateValue: Double,
currentTransactionRate: Double,
canvasHeight: Float
): Float {
val maxAndCurrentValueDifference = (higherTransactionRateValue - currentTransactionRate)
.toFloat()
val relativePercentageOfScreen = (canvasHeight / higherTransactionRateValue)
.toFloat()
return maxAndCurrentValueDifference * relativePercentageOfScreen
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment