Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ abstract class PieRadarChartBase<T : ChartData<out IDataSet<out Entry>>>
}

override fun getMaxVisibleCount(): Int {
return mData!!.getEntryCount()
return mData!!.entryCount
}

override fun onTouchEvent(event: MotionEvent?): Boolean {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import com.github.mikephil.charting.charts.Chart
import com.github.mikephil.charting.highlight.Highlight
import kotlin.math.sqrt

abstract class ChartTouchListener<T : Chart<*>?>(
@JvmField protected var chart: T?) : SimpleOnGestureListener(), OnTouchListener {
abstract class ChartTouchListener<T : Chart<*>>(
@JvmField protected var chart: T) : SimpleOnGestureListener(), OnTouchListener {
enum class ChartGesture {
NONE, DRAG, X_ZOOM, Y_ZOOM, PINCH_ZOOM, ROTATE, SINGLE_TAP, DOUBLE_TAP, LONG_PRESS, FLING
}
Expand All @@ -35,15 +35,15 @@ abstract class ChartTouchListener<T : Chart<*>?>(
* the gesturedetector used for detecting taps and longpresses, ...
*/
@JvmField
protected var gestureDetector: GestureDetector? = GestureDetector(chart!!.getContext(), this)
protected var gestureDetector: GestureDetector? = GestureDetector(chart.context, this)

/**
* Calls the OnChartGestureListener to do the start callback
*
* @param me
*/
fun startAction(me: MotionEvent) {
val l = chart!!.getOnChartGestureListener()
val l = chart.onChartGestureListener

if (l != null) l.onChartGestureStart(me, this.lastGesture)
}
Expand All @@ -54,7 +54,7 @@ abstract class ChartTouchListener<T : Chart<*>?>(
* @param me
*/
fun endAction(me: MotionEvent) {
val l = chart!!.getOnChartGestureListener()
val l = chart.onChartGestureListener

if (l != null) l.onChartGestureEnd(me, this.lastGesture)
}
Expand All @@ -75,10 +75,10 @@ abstract class ChartTouchListener<T : Chart<*>?>(
*/
protected fun performHighlight(highlight: Highlight?, motionEvent: MotionEvent?) {
if (highlight == null || highlight.equalTo(mLastHighlighted)) {
chart!!.highlightValue(null, true)
chart.highlightValue(null, true)
mLastHighlighted = null
} else {
chart!!.highlightValue(highlight, true)
chart.highlightValue(highlight, true)
mLastHighlighted = highlight
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.github.mikephil.charting.utils.MPPointF
import com.github.mikephil.charting.utils.convertDpToPixel
import kotlin.math.abs

class PieRadarChartTouchListener(chart: PieRadarChartBase<*>?) : ChartTouchListener<PieRadarChartBase<*>?>(chart) {
class PieRadarChartTouchListener(chart: PieRadarChartBase<*>) : ChartTouchListener<PieRadarChartBase<*>>(chart) {
private val touchStartPoint: MPPointF = MPPointF.getInstance(0f, 0f)

/**
Expand All @@ -30,7 +30,7 @@ class PieRadarChartTouchListener(chart: PieRadarChartBase<*>?) : ChartTouchListe

// if rotation by touch is enabled
// TODO: Also check if the pie itself is being touched, rather than the entire chart area
if (chart!!.isRotationEnabled) {
if (chart.isRotationEnabled) {
val x = event.x
val y = event.y

Expand All @@ -42,7 +42,7 @@ class PieRadarChartTouchListener(chart: PieRadarChartBase<*>?) : ChartTouchListe

resetVelocity()

if (chart!!.isDragDecelerationEnabled) {
if (chart.isDragDecelerationEnabled) {
sampleVelocity(x, y)
}

Expand All @@ -52,7 +52,7 @@ class PieRadarChartTouchListener(chart: PieRadarChartBase<*>?) : ChartTouchListe
}

MotionEvent.ACTION_MOVE -> {
if (chart!!.isDragDecelerationEnabled) {
if (chart.isDragDecelerationEnabled) {
sampleVelocity(x, y)
}

Expand All @@ -62,17 +62,17 @@ class PieRadarChartTouchListener(chart: PieRadarChartBase<*>?) : ChartTouchListe
) {
lastGesture = ChartGesture.ROTATE
touchMode = ROTATE
chart!!.disableScroll()
chart.disableScroll()
} else if (touchMode == ROTATE) {
updateGestureRotation(x, y)
chart?.invalidate()
chart.invalidate()
}

endAction(event)
}

MotionEvent.ACTION_UP -> {
if (chart!!.isDragDecelerationEnabled) {
if (chart.isDragDecelerationEnabled) {
stopDeceleration()

sampleVelocity(x, y)
Expand All @@ -82,11 +82,11 @@ class PieRadarChartTouchListener(chart: PieRadarChartBase<*>?) : ChartTouchListe
if (decelerationAngularVelocity != 0f) {
decelerationLastTime = AnimationUtils.currentAnimationTimeMillis()

chart?.postInvalidateOnAnimation() // This causes computeScroll to fire, recommended for this by Google
chart.postInvalidateOnAnimation() // This causes computeScroll to fire, recommended for this by Google
}
}

chart!!.enableScroll()
chart.enableScroll()
touchMode = NONE

endAction(event)
Expand All @@ -100,7 +100,7 @@ class PieRadarChartTouchListener(chart: PieRadarChartBase<*>?) : ChartTouchListe
override fun onLongPress(me: MotionEvent) {
lastGesture = ChartGesture.LONG_PRESS

val onChartGestureListener = chart!!.onChartGestureListener
val onChartGestureListener = chart.onChartGestureListener

onChartGestureListener?.onChartLongPressed(me)
}
Expand All @@ -110,15 +110,15 @@ class PieRadarChartTouchListener(chart: PieRadarChartBase<*>?) : ChartTouchListe
override fun onSingleTapUp(e: MotionEvent): Boolean {
lastGesture = ChartGesture.SINGLE_TAP

val onChartGestureListener = chart!!.onChartGestureListener
val onChartGestureListener = chart.onChartGestureListener

onChartGestureListener?.onChartSingleTapped(e)

if (!chart!!.isHighlightPerTapEnabled) {
if (!chart.isHighlightPerTapEnabled) {
return false
}

val high = chart!!.getHighlightByTouchPoint(e.x, e.y)
val high = chart.getHighlightByTouchPoint(e.x, e.y)
performHighlight(high, e)

return true
Expand All @@ -131,7 +131,7 @@ class PieRadarChartTouchListener(chart: PieRadarChartBase<*>?) : ChartTouchListe
private fun sampleVelocity(touchLocationX: Float, touchLocationY: Float) {
val currentTime = AnimationUtils.currentAnimationTimeMillis()

velocitySamples.add(AngularVelocitySample(currentTime, chart!!.getAngleForPoint(touchLocationX, touchLocationY)))
velocitySamples.add(AngularVelocitySample(currentTime, chart.getAngleForPoint(touchLocationX, touchLocationY)))

// Remove samples older than our sample time - 1 seconds
var i = 0
Expand Down Expand Up @@ -204,7 +204,7 @@ class PieRadarChartTouchListener(chart: PieRadarChartBase<*>?) : ChartTouchListe
* @param y
*/
fun setGestureStartAngle(x: Float, y: Float) {
startAngle = chart!!.getAngleForPoint(x, y) - chart!!.rawRotationAngle
startAngle = chart.getAngleForPoint(x, y) - chart.rawRotationAngle
}

/**
Expand All @@ -215,7 +215,7 @@ class PieRadarChartTouchListener(chart: PieRadarChartBase<*>?) : ChartTouchListe
* @param y
*/
fun updateGestureRotation(x: Float, y: Float) {
chart!!.rotationAngle = chart!!.getAngleForPoint(x, y) - startAngle
chart.rotationAngle = chart.getAngleForPoint(x, y) - startAngle
}

/**
Expand All @@ -232,16 +232,16 @@ class PieRadarChartTouchListener(chart: PieRadarChartBase<*>?) : ChartTouchListe

val currentTime = AnimationUtils.currentAnimationTimeMillis()

decelerationAngularVelocity *= chart!!.dragDecelerationFrictionCoef
decelerationAngularVelocity *= chart.dragDecelerationFrictionCoef

val timeInterval = (currentTime - decelerationLastTime).toFloat() / 1000f

chart!!.rotationAngle += decelerationAngularVelocity * timeInterval
chart.rotationAngle += decelerationAngularVelocity * timeInterval

decelerationLastTime = currentTime

if (abs(decelerationAngularVelocity) >= 0.001) {
chart?.postInvalidateOnAnimation() // This causes computeScroll to fire, recommended for this by Google
chart.postInvalidateOnAnimation() // This causes computeScroll to fire, recommended for this by Google
} else {
stopDeceleration()
}
Expand Down
Loading
Loading