mirror of
https://github.com/dzeiocom/charts.git
synced 2025-04-23 02:52:10 +00:00
feat: Add basic support for negative values in BarSerie
This commit is contained in:
parent
7a17d45257
commit
58314603ec
@ -47,12 +47,14 @@ class BarSerie(
|
|||||||
val max = view.yAxis.getYMax()
|
val max = view.yAxis.getYMax()
|
||||||
val min = view.yAxis.getYMin()
|
val min = view.yAxis.getYMin()
|
||||||
|
|
||||||
// Log.d(TAG, "${space.left}, ${space.right}")
|
val zero = ((1 - -min / (max - min)) * drawableSpace.height() + drawableSpace.top).coerceIn(
|
||||||
|
drawableSpace.top, drawableSpace.bottom
|
||||||
|
)
|
||||||
|
|
||||||
for (entry in displayedEntries) {
|
for (entry in displayedEntries) {
|
||||||
// calculated height in percent from 0 to 100
|
// calculated height in percent from 0 to 100
|
||||||
val top = ((1 - (entry.y - min) / (max - min)) * drawableSpace.height() + drawableSpace.top)
|
val top = ((1 - (entry.y - min) / (max - min)) * drawableSpace.height() + drawableSpace.top)
|
||||||
.coerceAtMost(drawableSpace.bottom)
|
.coerceIn(drawableSpace.top, drawableSpace.bottom)
|
||||||
var posX = drawableSpace.left + view.xAxis.getPositionOnRect(
|
var posX = drawableSpace.left + view.xAxis.getPositionOnRect(
|
||||||
entry,
|
entry,
|
||||||
drawableSpace
|
drawableSpace
|
||||||
@ -77,18 +79,31 @@ class BarSerie(
|
|||||||
paint.color = entry.color!!
|
paint.color = entry.color!!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (entry.y < 0) {
|
||||||
|
canvas.drawRoundRect(
|
||||||
|
posX,
|
||||||
|
zero,
|
||||||
|
right,
|
||||||
|
top,
|
||||||
|
0f,
|
||||||
|
0f,
|
||||||
|
32f,
|
||||||
|
32f,
|
||||||
|
paint
|
||||||
|
)
|
||||||
|
} else {
|
||||||
canvas.drawRoundRect(
|
canvas.drawRoundRect(
|
||||||
posX,
|
posX,
|
||||||
top,
|
top,
|
||||||
right,
|
right,
|
||||||
drawableSpace.bottom,
|
zero,
|
||||||
// 8f, 8f,
|
|
||||||
32f,
|
32f,
|
||||||
32f,
|
32f,
|
||||||
0f,
|
0f,
|
||||||
0f,
|
0f,
|
||||||
paint
|
paint
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// handle text display
|
// handle text display
|
||||||
val text = view.yAxis.onValueFormat(entry.y)
|
val text = view.yAxis.onValueFormat(entry.y)
|
||||||
@ -112,7 +127,7 @@ class BarSerie(
|
|||||||
|
|
||||||
var textY = if (doDisplayIn) top + rect.height() + 16f else top - 16f
|
var textY = if (doDisplayIn) top + rect.height() + 16f else top - 16f
|
||||||
|
|
||||||
if (textY < 0) {
|
if (textY < drawableSpace.top + rect.height()) {
|
||||||
textY = drawableSpace.top + rect.height()
|
textY = drawableSpace.top + rect.height()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user