From 51efed1886e353c6f74a04e57362330ccc9c7fba Mon Sep 17 00:00:00 2001 From: Leonardo Colman Lopes Date: Thu, 16 Jan 2025 10:24:18 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84=20Improve=20AllTime=20chart=20UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Leonardo Colman Lopes --- .../colman/petals/statistics/graph/AllTimeGraph.kt | 2 +- .../petals/statistics/graph/component/LineChart.kt | 1 + .../graph/data/DistributionPerDaySinceFirstUse.kt | 13 +++++++++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/br/com/colman/petals/statistics/graph/AllTimeGraph.kt b/app/src/main/kotlin/br/com/colman/petals/statistics/graph/AllTimeGraph.kt index d28209b0..e2695919 100644 --- a/app/src/main/kotlin/br/com/colman/petals/statistics/graph/AllTimeGraph.kt +++ b/app/src/main/kotlin/br/com/colman/petals/statistics/graph/AllTimeGraph.kt @@ -21,6 +21,6 @@ fun AllTimeGraph(uses: List, dateFormat: String) { labelCount = 5 granularity = 1f valueFormatter = DaysSinceFirstUseFormatter(uses, dateFormat).formatDate - addLimitLine(LimitLine(YearMonth.now().monthValue.toFloat()).apply { lineWidth = 2f }) + } } diff --git a/app/src/main/kotlin/br/com/colman/petals/statistics/graph/component/LineChart.kt b/app/src/main/kotlin/br/com/colman/petals/statistics/graph/component/LineChart.kt index a2aee7ae..8d018f63 100644 --- a/app/src/main/kotlin/br/com/colman/petals/statistics/graph/component/LineChart.kt +++ b/app/src/main/kotlin/br/com/colman/petals/statistics/graph/component/LineChart.kt @@ -30,6 +30,7 @@ fun LineChart( chart.description.text = description chart.description.textColor = colors.primary.toArgb() chart.legend.textColor = colors.primary.toArgb() + chart.setMaxVisibleValueCount(30) chart.data = LineData(datasets) chart.notifyDataSetChanged() diff --git a/app/src/main/kotlin/br/com/colman/petals/statistics/graph/data/DistributionPerDaySinceFirstUse.kt b/app/src/main/kotlin/br/com/colman/petals/statistics/graph/data/DistributionPerDaySinceFirstUse.kt index 4b87e2a3..71a40acf 100644 --- a/app/src/main/kotlin/br/com/colman/petals/statistics/graph/data/DistributionPerDaySinceFirstUse.kt +++ b/app/src/main/kotlin/br/com/colman/petals/statistics/graph/data/DistributionPerDaySinceFirstUse.kt @@ -31,13 +31,15 @@ fun createAllTimeDistributionWithMovingAverage(uses: List): List, label: String): LineDataSet { return LineDataSet(entryList, label).apply { valueFormatter = GramsValueFormatter - lineWidth = 6f + lineWidth = 3f setDrawFilled(true) - setDrawCircles(false) + setDrawCircles(true) + setDrawCircleHole(true) fillColor = Color.Cyan.copy(alpha = 0.3f).toArgb() color = Color.Cyan.toArgb() valueTextColor = Gray.toArgb() valueTextSize = 14f + mode = LineDataSet.Mode.CUBIC_BEZIER } } @@ -45,8 +47,11 @@ fun createAllTimeAverageDataSet(entryList: List, label: String): LineData return LineDataSet(entryList, label).apply { setDrawValues(false) setDrawCircles(false) - lineWidth = 6f + lineWidth = 3f color = Color.Green.toArgb() + mode = LineDataSet.Mode.CUBIC_BEZIER + enableDashedLine(10f, 5f, 0f) + } } @@ -69,7 +74,7 @@ private fun calculateMovingAverage(entries: List): List { val result = mutableListOf() for (i in entries.indices) { - val start = maxOf(0, i - 14 + 1) + val start = maxOf(0, i - 7 + 1) val end = i + 1 val windowEntries = entries.subList(start, end)