Skip to content

Commit

Permalink
Merge pull request #20674 from wordpress-mobile/fix/empty-bar-chart-i…
Browse files Browse the repository at this point in the history
…ssue

Fix empty bar chart issue
  • Loading branch information
aditi-bhatia authored Apr 19, 2024
2 parents f761209 + a2e569d commit 7722b6e
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class BarChartViewHolder(parent: ViewGroup) : BlockListItemViewHolder(
val dataSet = if (hasData) {
buildDataSet(context, mappedEntries)
} else {
BarDataSet(emptyList(), "Empty")
buildEmptyDataSet(cutEntries.size)
}
item.onBarChartDrawn?.invoke(dataSet.entryCount)
val dataSets = mutableListOf<IBarDataSet>()
Expand Down Expand Up @@ -208,6 +208,11 @@ class BarChartViewHolder(parent: ViewGroup) : BlockListItemViewHolder(
}
}

private fun buildEmptyDataSet(count: Int): BarDataSet {
val emptyValues = (0 until count).map { index -> BarEntry(index.toFloat(), 0f, "empty") }
return BarDataSet(emptyValues, "Empty").apply { setDrawValues(false) }
}

private fun buildDataSet(context: Context, cut: List<BarEntry>): BarDataSet {
val dataSet = BarDataSet(cut, "Data")
chart.renderer.paintRender.shader = null
Expand Down

0 comments on commit 7722b6e

Please sign in to comment.