From a2e569ddf51f5c395846bb6162921fdafbded3de Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Thu, 18 Apr 2024 21:43:48 +0300 Subject: [PATCH] Fix empty bar chart issue --- .../lists/sections/viewholders/BarChartViewHolder.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/viewholders/BarChartViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/viewholders/BarChartViewHolder.kt index c6f9ff774ffb..a637bc7045b9 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/viewholders/BarChartViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/viewholders/BarChartViewHolder.kt @@ -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() @@ -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): BarDataSet { val dataSet = BarDataSet(cut, "Data") chart.renderer.paintRender.shader = null