Skip to content

Commit 3815f98

Browse files
committed
[bug/CM-963]: Removed yScale ciel function.
Modified yScale calculation.
1 parent 21f7dbb commit 3815f98

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

YChartsLib/src/main/java/co/yml/charts/ui/linechart/LineChartExtensions.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package co.yml.charts.ui.linechart
22

33
import androidx.compose.ui.geometry.Offset
44
import co.yml.charts.common.model.Point
5-
import kotlin.math.ceil
65

76
/**
87
* returns total offset for given no of steps and offset .
@@ -25,9 +24,8 @@ fun getYAxisScale(
2524
val yMin = points.takeIf { it.isNotEmpty() }?.minOf { it.y } ?: 0f
2625
val yMax = points.takeIf { it.isNotEmpty() }?.maxOf { it.y } ?: 0f
2726
val totalSteps = (yMax - yMin)
28-
val temp =
27+
val scale =
2928
totalSteps / if (steps > 1) (steps - 1) else 1 // First step starts from 0 by default
30-
val scale = ceil(temp)
3129
return Triple(yMin, yMax, scale)
3230
}
3331

app/src/main/java/co/yml/ycharts/app/presentation/LineChartActivity.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import android.graphics.Typeface
44
import android.os.Bundle
55
import androidx.activity.ComponentActivity
66
import androidx.activity.compose.setContent
7-
import androidx.compose.foundation.layout.*
7+
import androidx.compose.foundation.layout.Box
8+
import androidx.compose.foundation.layout.fillMaxSize
9+
import androidx.compose.foundation.layout.fillMaxWidth
10+
import androidx.compose.foundation.layout.height
11+
import androidx.compose.foundation.layout.padding
812
import androidx.compose.foundation.lazy.LazyColumn
913
import androidx.compose.material.Scaffold
1014
import androidx.compose.runtime.Composable
@@ -98,7 +102,8 @@ private fun LineGraph1(pointsData: List<Point>) {
98102
.labelData { i ->
99103
// Add yMin to get the negative axis values to the scale
100104
val yMin = pointsData.minOf { it.y }
101-
val yScale = 50 / steps
105+
val yMax = pointsData.maxOf { it.y }
106+
val yScale = (yMax - yMin)/steps
102107
((i * yScale) + yMin).formatToSinglePrecision()
103108
}.build()
104109
val data = LineChartData(
@@ -186,7 +191,8 @@ private fun LineGraph3(pointsData: List<Point>) {
186191
.steps(steps)
187192
.labelData { i ->
188193
val yMin = pointsData.minOf { it.y }
189-
val yScale = 100 / steps
194+
val yMax = pointsData.maxOf { it.y }
195+
val yScale = (yMax - yMin)/steps
190196
((i * yScale) + yMin).formatToSinglePrecision()
191197
}
192198
.axisLineColor(Color.Red)

buildSrc/src/main/java/co/ycharts/dependency/YChartDependency.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ object YChartDependency {
1717
val COMPOSE_UI_TEST_MANIFEST by lazy { "androidx.compose.ui:ui-test-manifest:${Version.COMPOSE_UI}" }
1818
val RUNTIME_KTX by lazy { "androidx.lifecycle:lifecycle-runtime-ktx:${Version.RUNTIME_KTX}" }
1919
val MOCKK by lazy { "io.mockk:mockk:${Version.MOCKK}" }
20+
val YCHART by lazy { "co.yml:ycharts:1.0.0" }
2021
}

0 commit comments

Comments
 (0)