fix: crash while clicking on an empty chart (#50)

This commit is contained in:
Florian Bouillon 2023-02-08 17:18:48 +01:00 committed by GitHub
parent fe20f90654
commit b2c51f7be1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 7 deletions

View File

@ -4,16 +4,13 @@ buildscript {
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:7.4.0")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath("com.android.tools.build:gradle:7.4.1")
}
}
plugins {
id("com.android.application") version "7.4.0" apply false
id("com.android.library") version "7.4.0" apply false
id("com.android.application") version "7.4.1" apply false
id("com.android.library") version "7.4.1" apply false
id("org.jetbrains.kotlin.android") version "1.7.0" apply false
}

View File

@ -1,6 +1,6 @@
#Sun Aug 07 22:38:24 CEST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-rc-1-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

View File

@ -42,6 +42,9 @@ class ChartView @JvmOverloads constructor(context: Context?, attrs: AttributeSet
var lastMovementX = 0.0
var lastMovementY = 0f
setOnChartMoved { movementX, movementY ->
if (getDataset().isEmpty()) {
return@setOnChartMoved
}
if (xAxis.scrollEnabled) {
xAxis.x += (movementX - lastMovementX) * xAxis.getDataWidth() / width
lastMovementX = movementX.toDouble()
@ -59,6 +62,9 @@ class ChartView @JvmOverloads constructor(context: Context?, attrs: AttributeSet
refresh()
}
setOnChartClick { x, y ->
if (getDataset().isEmpty()) {
return@setOnChartClick
}
// Log.d("Chart clicked at", "$x, $y")
val dataset = series.map { it.getDisplayedEntries() }.reduce { acc, entries ->
acc.addAll(entries)