fl_chart icon indicating copy to clipboard operation
fl_chart copied to clipboard

Both scaleable and draggable chart implemented

Open adamsocrat opened this issue 1 year ago • 3 comments

Implements #1720

I used the idea from #1721 and implemented FlScaleEvent but without explicitly specifying detectScale to disable drag fully when scaling. detectScale could've been set dynamically but it was combursome and couldn't get it working. Implementing a new FLTouchEvent seemed better option.

The drawback was as in #1721 mentioned PanGestureRecognizer and ScaleGestureRecognizer does not like to be used together. But ScaleGestureRecognizer event details also feeds the PanGestureRecognizer event details (except onDown) see, so instead of disabling dragging fully when you want to scale, I notify ScaleEvent when there are two points and drag when one point is in contact with the screen. Same idea of this comment

! Details feeding into FlPan...Event have been switched to Scale details. Testing may be needed.

You can get TouchEvent from touchcallback as

touchCallback: (FlTouchEvent touchEvent, lineTouchRsp) {
              if (touchEvent is FlScaleStartEvent) {
                       // https://api.flutter.dev/flutter/gestures/ScaleStartDetails-class.html
                       }
             if (touchEvent is FlScaleUpdateEvent) {
                      // You can see the details of touch event with:  touchEvent.details
                     // https://api.flutter.dev/flutter/gestures/ScaleUpdateDetails-class.html
                       }
             if (touchEvent is FlPanUpdateEvent) {
                     // NOT https://api.flutter.dev/flutter/gestures/DragUpdateDetails-class.html 
                     // https://api.flutter.dev/flutter/gestures/ScaleUpdateDetails-class.html
                       }
}

with the FlScaleEvent I am able to set minX and maxX to zoom in/out chart without the scale is being also interpreted as drag. See #71

adamsocrat avatar Aug 15 '24 14:08 adamsocrat

Would be great if this could be merged for the next implementation.

TheOlajos avatar Aug 16 '24 11:08 TheOlajos

Hi @adamsocrat @imaNNeo , joining the conversation here.

I think it might be a bit inconsistent with the rest of the flutter framework to raise scale events for 2 fingers and pan for 1 finger.

To my limited understanding, the idea behind this is that - scale is also a pan. with the scale events, you could implement pan because it already has all the necessary information. I think whatever implementation you guys end choosing, should be consistent with how GestureDetector works in this scenario.

eladm-ultrawis avatar Aug 27 '24 05:08 eladm-ultrawis

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 89.17%. Comparing base (15c66cf) to head (2db829e).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1728   +/-   ##
=======================================
  Coverage   89.17%   89.17%           
=======================================
  Files          44       44           
  Lines        3031     3031           
=======================================
  Hits         2703     2703           
  Misses        328      328           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Sep 12 '24 01:09 codecov[bot]

Hello, any progress with this ?

pelkamarcin avatar Dec 18 '24 11:12 pelkamarcin

Hello, any progress with this ?

Unfortunately I had no time to debug and implement better. I think in #1793 they are working on a better solution. So I am closing this issue.

adamsocrat avatar Dec 18 '24 11:12 adamsocrat