Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: crash while clicking on an empty chart #50

Merged
merged 1 commit into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions library/src/main/java/com/dzeio/charts/ChartView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down