mirror of
https://github.com/dzeiocom/charts.git
synced 2025-06-07 08:39:56 +00:00
fix: Negative numbers not being displayed correctly (#26)
This commit is contained in:
parent
c9fee7ca24
commit
4612fd7189
@ -81,6 +81,12 @@ class YAxis(
|
||||
}
|
||||
for (index in 0 until serie.entries.size) {
|
||||
val entry = serie.entries[index]
|
||||
if (sign(entry.y) <= 0f && nList[index] > 0f) {
|
||||
continue
|
||||
} else if (nList[index] < 0f && entry.y > 0f) {
|
||||
nList[index] = entry.y
|
||||
continue
|
||||
}
|
||||
nList[index] += entry.y
|
||||
}
|
||||
}
|
||||
@ -114,6 +120,12 @@ class YAxis(
|
||||
}
|
||||
for (index in 0 until serie.entries.size) {
|
||||
val entry = serie.entries[index]
|
||||
if (sign(entry.y) >= 0f && nList[index] < 0f) {
|
||||
continue
|
||||
} else if (nList[index] > 0f && entry.y < 0f) {
|
||||
nList[index] = entry.y
|
||||
continue
|
||||
}
|
||||
nList[index] += entry.y
|
||||
}
|
||||
}
|
||||
|
@ -64,6 +64,7 @@ class BarSerie(
|
||||
|
||||
// calculated height in percent from 0 to 100
|
||||
var top = view.yAxis.getPositionOnRect(entry, drawableSpace)
|
||||
.coerceIn(drawableSpace.top, drawableSpace.bottom)
|
||||
var posX = drawableSpace.left + view.xAxis.getPositionOnRect(
|
||||
entry,
|
||||
drawableSpace
|
||||
@ -99,7 +100,9 @@ class BarSerie(
|
||||
paint.color = entry.color!!
|
||||
}
|
||||
|
||||
var height: Float
|
||||
if (entry.y < 0) {
|
||||
height = top - zero
|
||||
canvas.drawRoundRect(
|
||||
posX,
|
||||
zero,
|
||||
@ -112,6 +115,7 @@ class BarSerie(
|
||||
paint
|
||||
)
|
||||
} else {
|
||||
height = zero - top
|
||||
canvas.drawRoundRect(
|
||||
posX,
|
||||
top,
|
||||
@ -130,31 +134,22 @@ class BarSerie(
|
||||
|
||||
textPaint.getTextBounds(text, 0, text.length, rect)
|
||||
|
||||
val textLeft = (posX + barWidth / 2)
|
||||
|
||||
if (
|
||||
// handle right side
|
||||
textLeft + rect.width() / 2 > right ||
|
||||
// handle left sie
|
||||
textLeft - rect.width() / 2 < drawableSpace.left
|
||||
) {
|
||||
continue
|
||||
}
|
||||
// text center X
|
||||
val textX = (posX + barWidth / 2)
|
||||
|
||||
val doDisplayIn =
|
||||
rect.height() < drawableSpace.bottom - top &&
|
||||
rect.width() < barWidth
|
||||
rect.height() + 32f < height
|
||||
|
||||
var textY = if (doDisplayIn) top + rect.height() + 16f else top - 16f
|
||||
if (entry.y < 0f) textY = if (doDisplayIn) top - 16f else top + rect.height() + 16f
|
||||
|
||||
if (textY < drawableSpace.top + rect.height()) {
|
||||
textY = drawableSpace.top + rect.height()
|
||||
}
|
||||
|
||||
|
||||
canvas.drawText(
|
||||
text,
|
||||
textLeft,
|
||||
textX,
|
||||
textY,
|
||||
if (doDisplayIn) textPaint else textExternalPaint
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user