fix: grouped barchart not displaying second bar if y is the same (#28)

This commit is contained in:
Florian Bouillon 2023-01-12 23:27:16 +01:00 committed by GitHub
parent 4612fd7189
commit 890d474ab4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 6 deletions

View File

@ -1,10 +1,13 @@
package com.dzeio.charts
import com.dzeio.charts.series.SerieInterface
/**
* A Base entry for any charts
*/
data class Entry(
var x: Double,
var y: Float,
var color: Int? = null
var color: Int? = null,
var serie: SerieInterface? = null
)

View File

@ -52,7 +52,7 @@ class XAxis(
}
override fun getPositionOnRect(entry: Entry, drawableSpace: RectF): Double {
val result = drawableSpace.width() * (entry.x - x) / getDataWidth()
val result = drawableSpace.left + drawableSpace.width() * (entry.x - x) / getDataWidth()
if (view.type == ChartType.GROUPED) {
val serie = view.series.find { it.entries.contains(entry) }
val index = view.series.indexOf(serie)

View File

@ -65,7 +65,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(
var posX = view.xAxis.getPositionOnRect(
entry,
drawableSpace
).toFloat()

View File

@ -25,6 +25,12 @@ sealed class BaseSerie(
override var yAxisPosition: YAxisPosition = YAxisPosition.RIGHT
override var entries: ArrayList<Entry> = arrayListOf()
set(values) {
for (value in values) {
value.serie = this
}
field = values
}
override fun getDisplayedEntries(): ArrayList<Entry> {
val minX = view.xAxis.x

View File

@ -68,9 +68,10 @@ class LineSerie(
entriesCurrentY[entry.x]!!.value = top
}
val posX = (drawableSpace.left +
view.xAxis.getPositionOnRect(entry, drawableSpace) +
view.xAxis.getEntryWidth(drawableSpace) / 2f).toFloat()
val posX = (
view.xAxis.getPositionOnRect(entry, drawableSpace) +
view.xAxis.getEntryWidth(drawableSpace) / 2f
).toFloat()
// handle color recoloration
val paint = Paint(linePaint)