Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion library/src/main/java/com/dzeio/charts/Entry.kt
Original file line number Diff line number Diff line change
@@ -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
)
2 changes: 1 addition & 1 deletion library/src/main/java/com/dzeio/charts/axis/XAxis.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion library/src/main/java/com/dzeio/charts/series/BarSerie.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions library/src/main/java/com/dzeio/charts/series/BaseSerie.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions library/src/main/java/com/dzeio/charts/series/LineSerie.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down