Skip to content

Instantly share code, notes, and snippets.

@aqua30
Last active June 14, 2022 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aqua30/90bfc6239a3daf096373563b784d273c to your computer and use it in GitHub Desktop.
Save aqua30/90bfc6239a3daf096373563b784d273c to your computer and use it in GitHub Desktop.
val xAxisSpace = (size.width - paddingSpace.toPx()) / xValues.size
val yAxisSpace = size.height / yValues.size
/** placing x axis points */
for (i in xValues.indices) {
drawContext.canvas.nativeCanvas.drawText(
"${xValues[i]}",
xAxisSpace * (i + 1),
size.height - 30,
textPaint
)
}
/** placing y axis points */
for (i in yValues.indices) {
drawContext.canvas.nativeCanvas.drawText(
"${yValues[i]}",
paddingSpace.toPx() / 2f,
size.height - yAxisSpace * (i + 1),
textPaint
)
}
/** placing points */
for (i in points.indices) {
val x1 = xAxisSpace * xValues[i]
val y1 = size.height - (yAxisSpace * (points[i]/verticalStep.toFloat()))
coordinates.add(PointF(x1,y1))
/** drawing circles to indicate all the points */
drawCircle(
color = Color.Red,
radius = 10f,
center = Offset(x1,y1)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment