mirror of
https://github.com/dzeiocom/charts.git
synced 2025-04-23 02:52:10 +00:00
fix: values not respecting YMin
This commit is contained in:
parent
4c9b4bd2a6
commit
d24e9ae1cb
@ -5,7 +5,6 @@ import android.graphics.Color
|
||||
import android.graphics.Paint
|
||||
import android.graphics.Rect
|
||||
import android.graphics.RectF
|
||||
import android.util.Log
|
||||
import com.dzeio.charts.ChartView
|
||||
import com.dzeio.charts.utils.drawRoundRect
|
||||
|
||||
@ -33,6 +32,13 @@ class BarSerie(
|
||||
textAlign = Paint.Align.CENTER
|
||||
}
|
||||
|
||||
var textExternalPaint = Paint().apply {
|
||||
isAntiAlias = true
|
||||
color = Color.BLACK
|
||||
textSize = 30f
|
||||
textAlign = Paint.Align.CENTER
|
||||
}
|
||||
|
||||
private val rect = Rect()
|
||||
|
||||
override fun onDraw(canvas: Canvas, drawableSpace: RectF) {
|
||||
@ -45,7 +51,8 @@ class BarSerie(
|
||||
|
||||
for (entry in displayedEntries) {
|
||||
// calculated height in percent from 0 to 100
|
||||
val top = (1 - entry.y / max) * drawableSpace.height() + drawableSpace.top
|
||||
val top = ((1 - (entry.y - min) / (max - min)) * drawableSpace.height() + drawableSpace.top)
|
||||
.coerceAtMost(drawableSpace.bottom)
|
||||
var posX = drawableSpace.left + view.xAxis.getPositionOnRect(
|
||||
entry,
|
||||
drawableSpace
|
||||
@ -114,7 +121,7 @@ class BarSerie(
|
||||
text,
|
||||
textLeft,
|
||||
textY,
|
||||
textPaint
|
||||
if (doDisplayIn) textPaint else textExternalPaint
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -35,13 +35,14 @@ class LineSerie(
|
||||
val displayedEntries = getDisplayedEntries()
|
||||
displayedEntries.sortBy { it.x }
|
||||
val max = view.yAxis.getYMax()
|
||||
val min = view.yAxis.getYMin()
|
||||
|
||||
var previousPosX: Float? = null
|
||||
var previousPosY: Float? = null
|
||||
|
||||
for (entry in displayedEntries) {
|
||||
// calculated height in percent from 0 to 100
|
||||
val top = (1 - entry.y / max) * drawableSpace.height() + drawableSpace.top
|
||||
val top = (1 - (entry.y - min) / (max - min)) * drawableSpace.height() + drawableSpace.top
|
||||
val posX = (drawableSpace.left +
|
||||
view.xAxis.getPositionOnRect(entry, drawableSpace) +
|
||||
view.xAxis.getEntryWidth(drawableSpace) / 2f).toFloat()
|
||||
|
Loading…
x
Reference in New Issue
Block a user