mirror of
https://github.com/dzeiocom/charts.git
synced 2025-04-23 11:02:10 +00:00
feat: Add the ability to add a line at the zero point
This commit is contained in:
parent
e5c337ee31
commit
ce565c2472
@ -40,7 +40,7 @@ class YAxis(
|
||||
private var min: Float? = 0f
|
||||
private var max: Float? = null
|
||||
|
||||
var drawZeroLine: Boolean = true
|
||||
override var drawZeroLine: Boolean = true
|
||||
|
||||
override var scrollEnabled: Boolean = false
|
||||
|
||||
@ -99,11 +99,10 @@ class YAxis(
|
||||
|
||||
val min = getYMin()
|
||||
val max = getYMax() - min
|
||||
val top = space.top
|
||||
val bottom = space.bottom
|
||||
var maxWidth = 0f
|
||||
|
||||
val increment = (bottom - top) / labelCount
|
||||
val increment = space.height() / labelCount
|
||||
val valueIncrement = max / labelCount
|
||||
for (index in 0 until labelCount) {
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,11 @@ sealed interface YAxisInterface {
|
||||
*/
|
||||
var scrollEnabled: Boolean
|
||||
|
||||
/**
|
||||
* do the Zero line gets drawn?
|
||||
*/
|
||||
var drawZeroLine: Boolean
|
||||
|
||||
/**
|
||||
* run when manually refreshing the system
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user