mirror of
https://github.com/dzeiocom/charts.git
synced 2025-04-23 19:12:10 +00:00
fix: YAxis not putting value on first line (#19)
This commit is contained in:
parent
b1b209035c
commit
68c906e78e
@ -104,14 +104,14 @@ class YAxis(
|
|||||||
val bottom = space.bottom
|
val bottom = space.bottom
|
||||||
var maxWidth = 0f
|
var maxWidth = 0f
|
||||||
|
|
||||||
val increment = space.height() / labelCount
|
val increment = space.height() / (labelCount - 1)
|
||||||
val valueIncrement = max / labelCount
|
val valueIncrement = max / (labelCount - 1)
|
||||||
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))
|
||||||
textLabel.getTextBounds(text, 0, text.length, rect)
|
textLabel.getTextBounds(text, 0, text.length, rect)
|
||||||
maxWidth = maxWidth.coerceAtLeast(rect.width().toFloat())
|
maxWidth = maxWidth.coerceAtLeast(rect.width().toFloat())
|
||||||
|
|
||||||
val posY = bottom - (index + 1) * increment
|
val posY = bottom - index * increment
|
||||||
|
|
||||||
canvas.drawText(
|
canvas.drawText(
|
||||||
text,
|
text,
|
||||||
@ -121,7 +121,6 @@ class YAxis(
|
|||||||
)
|
)
|
||||||
// canvas.drawDottedLine(0f, posY, canvas.width.toFloat(), posY, 40f, linePaint)
|
// canvas.drawDottedLine(0f, posY, canvas.width.toFloat(), posY, 40f, linePaint)
|
||||||
canvas.drawLine(space.left, posY, space.right - maxWidth - 32f, posY, linePaint)
|
canvas.drawLine(space.left, posY, space.right - maxWidth - 32f, posY, linePaint)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for ((y, settings) in lines) {
|
for ((y, settings) in lines) {
|
||||||
|
@ -114,7 +114,7 @@ class MainFragment : Fragment() {
|
|||||||
scrollEnabled = true
|
scrollEnabled = true
|
||||||
|
|
||||||
// change the number of labels
|
// change the number of labels
|
||||||
labelCount = 10
|
labelCount = 11
|
||||||
|
|
||||||
// change how labels are displayed
|
// change how labels are displayed
|
||||||
onValueFormat = { "${it.roundToInt()}g"}
|
onValueFormat = { "${it.roundToInt()}g"}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user