On trackball position changing happens multiple times in long press

I am using a chart with a trackball and I am interested in haptic every time the trackball passes a point. 

I added this callback:

  onTrackballPositionChanging: (args) {
          HapticFeedback.selectionClick();
        },


In the current situation, if we move with the trackball but stay in the same spot for a few seconds (and maybe we move a little up and down with the finger, but at the same point on the X-axis), The haptic is activated several times. 


How can this be prevented?


3 Replies

HK Hariharasudhan Kanagaraj Syncfusion Team July 5, 2023 11:54 AM UTC

Hi,


We have analyzed your query, the onTrackballPositionChanging callback will be called whenever the position of the trackball changes and it is the current behavior of the SfCartesianChart.


To achieve your requirement using the onTrackballPositionChanging callback, we can compare the current x position and the next x position using TrackballArgs as per the following code snippet.


SfCartesianChart(

  onTrackballPositionChanging: (TrackballArgs trackballArgs) {

    if (x != trackballArgs.chartPointInfo.chartDataPoint!.x) {

      HapticFeedback.selectionClick();

      x = trackballArgs.chartPointInfo.chartDataPoint!.x;

    }

  },

  primaryXAxis: NumericAxis(),

  primaryYAxis: NumericAxis(),

  series: <CartesianSeries<ChartSampleData, num>>[

    ColumnSeries(

      dataSource: data,

      xValueMapper: (ChartSampleData sales, int index) => sales.x,

      yValueMapper: (ChartSampleData sales, int index) => sales.y,

    )

  ],

  trackballBehavior: _trackballBehavior,

),


Also attached the sample below for your reference.


Regards,

Hari Hara Sudhan. K


Attachment: 183239_f53e888e.zip


IA Iyar Avital July 5, 2023 02:33 PM UTC

Thank you!



HK Hariharasudhan Kanagaraj Syncfusion Team July 6, 2023 04:19 AM UTC

Hi Iyar Avital,


Most Welcome. Kindly get back to us if you have further queries. We are always happy to assist you.


Regards,

Hari Hara Sudhan. K


Loader.
Up arrow icon