Pre loader

Is there an example available that can detect if a data point has been tapped on (ignoring drags)?

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

1
0

Nevernmind I created this OnTouchListener that when applied to the surface works:

private class DataPointTapDetector(
    private val context: Context,
    private val renderableSeries: XyRenderableSeriesBase,
    private val data: Pair<List<Date>, List<Double>>,
    private val onDataPointTapped: (date: Date, value: Double) -> Unit
) : OnTouchListener {

    private var downX = 0f
    private var downY = 0f
    private val tapThreshold = 10

    @SuppressLint("ClickableViewAccessibility")
    override fun onTouch(v: View, event: MotionEvent): Boolean {
        when (event.action) {
            MotionEvent.ACTION_DOWN -> {
                downX = event.x
                downY = event.y
            }

            MotionEvent.ACTION_UP -> {
                val upX = event.x
                val upY = event.y
                val deltaX = abs(downX - upX)
                val deltaY = abs(downY - upY)

                if (deltaX < tapThreshold && deltaY < tapThreshold) {
                    val hitTestInfo = HitTestInfo()
                    val hitTestRadius =
                        context.resources.getDimension(R.dimen.min_button_size) / 2
                    renderableSeries.hitTest(
                        hitTestInfo,
                        upX,
                        upY,
                        hitTestRadius
                    )
                    if (hitTestInfo.isHit) {
                        val index = hitTestInfo.dataSeriesIndex
                        val date = data.first[index]
                        val value = data.second[index]
                        onDataPointTapped(date, value)
                    }
                }
            }
        }
        return false
    }
}
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.