feat: Add the ability to add a line at the zero point

This commit is contained in:
Florian Bouillon 2023-01-10 17:31:47 +01:00
parent e5c337ee31
commit ce565c2472
2 changed files with 12 additions and 3 deletions

View File

@ -40,7 +40,7 @@ class YAxis(
private var min: Float? = 0f private var min: Float? = 0f
private var max: Float? = null private var max: Float? = null
var drawZeroLine: Boolean = true override var drawZeroLine: Boolean = true
override var scrollEnabled: Boolean = false override var scrollEnabled: Boolean = false
@ -99,11 +99,10 @@ class YAxis(
val min = getYMin() val min = getYMin()
val max = getYMax() - min val max = getYMax() - min
val top = space.top
val bottom = space.bottom val bottom = space.bottom
var maxWidth = 0f var maxWidth = 0f
val increment = (bottom - top) / labelCount val increment = space.height() / labelCount
val valueIncrement = max / labelCount val valueIncrement = max / labelCount
for (index in 0 until labelCount) { for (index in 0 until labelCount) {
val text = onValueFormat(min + (valueIncrement * (index + 1))) val text = onValueFormat(min + (valueIncrement * (index + 1)))
@ -135,6 +134,11 @@ class YAxis(
) )
} }
if (this.drawZeroLine) {
val pos = ((1 - -min / (getYMax() - min)) * space.height() + space.top)
canvas.drawLine(0f, pos, space.right - maxWidth - 32f, pos, linePaint)
}
return maxWidth + 32f return maxWidth + 32f
} }

View File

@ -38,6 +38,11 @@ sealed interface YAxisInterface {
*/ */
var scrollEnabled: Boolean var scrollEnabled: Boolean
/**
* do the Zero line gets drawn?
*/
var drawZeroLine: Boolean
/** /**
* run when manually refreshing the system * run when manually refreshing the system
* *