mirror of
https://github.com/dzeiocom/charts.git
synced 2025-07-23 13:29:54 +00:00
fix: crash while clicking on an empty chart (#50)
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user