-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Both scaleable and draggable chart implemented #1728
base: main
Are you sure you want to change the base?
Changes from all commits
89faa36
ebe9bf9
3596d35
8bc6fac
aeb5f9d
65c1940
a42706e
2db829e
573a84b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,8 +39,10 @@ abstract class RenderBaseChart<R extends BaseTouchResponse> extends RenderBox | |
|
||
late bool _validForMouseTracker; | ||
|
||
/// Recognizes pan gestures, such as onDown, onStart, onUpdate, onCancel, ... | ||
late PanGestureRecognizer _panGestureRecognizer; | ||
// Instead of drag we use scale which also includes pan gestures | ||
// Recognizes pan gestures, such as onDown, onStart, onUpdate, onCancel, ... | ||
// and detects scale gestures scroll, pinch in out, such as onStart, onUpdate, onEnd, ... | ||
late ScaleGestureRecognizer _scaleGestureRecognizer; | ||
|
||
/// Recognizes tap gestures, such as onTapDown, onTapCancel and onTapUp | ||
late TapGestureRecognizer _tapGestureRecognizer; | ||
|
@@ -50,22 +52,20 @@ abstract class RenderBaseChart<R extends BaseTouchResponse> extends RenderBox | |
|
||
/// Initializes our recognizers and implement their callbacks. | ||
void initGestureRecognizers() { | ||
_panGestureRecognizer = PanGestureRecognizer(); | ||
_panGestureRecognizer | ||
..onDown = (dragDownDetails) { | ||
_notifyTouchEvent(FlPanDownEvent(dragDownDetails)); | ||
_scaleGestureRecognizer = ScaleGestureRecognizer(); | ||
_scaleGestureRecognizer | ||
..onStart = (details) { | ||
_notifyScaleEvent(FlScaleStartEvent(details)); | ||
_notifyTouchEvent(FlPanDownEvent(details)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it okay to call both FlPanDown and FlPanStart at the same time? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably not, drag down details and scalestart details will be different and be a breaking change. Thinking of another solution |
||
_notifyTouchEvent(FlPanStartEvent(details)); | ||
} | ||
..onStart = (dragStartDetails) { | ||
_notifyTouchEvent(FlPanStartEvent(dragStartDetails)); | ||
..onUpdate = (details) { | ||
_notifyScaleEvent(FlScaleUpdateEvent(details)); | ||
_notifyTouchEvent(FlPanUpdateEvent(details)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And also for here, (something like fingerIndex) |
||
} | ||
..onUpdate = (dragUpdateDetails) { | ||
_notifyTouchEvent(FlPanUpdateEvent(dragUpdateDetails)); | ||
} | ||
..onCancel = () { | ||
_notifyTouchEvent(const FlPanCancelEvent()); | ||
} | ||
..onEnd = (dragEndDetails) { | ||
_notifyTouchEvent(FlPanEndEvent(dragEndDetails)); | ||
..onEnd = (details) { | ||
_notifyScaleEvent(FlScaleEndEvent(details)); | ||
_notifyTouchEvent(FlPanEndEvent(details)); | ||
}; | ||
|
||
_tapGestureRecognizer = TapGestureRecognizer(); | ||
|
@@ -124,7 +124,7 @@ abstract class RenderBaseChart<R extends BaseTouchResponse> extends RenderBox | |
if (event is PointerDownEvent) { | ||
_longPressGestureRecognizer.addPointer(event); | ||
_tapGestureRecognizer.addPointer(event); | ||
_panGestureRecognizer.addPointer(event); | ||
_scaleGestureRecognizer.addPointer(event); | ||
} else if (event is PointerHoverEvent) { | ||
_notifyTouchEvent(FlPointerHoverEvent(event)); | ||
} | ||
|
@@ -140,7 +140,7 @@ abstract class RenderBaseChart<R extends BaseTouchResponse> extends RenderBox | |
PointerExitEventListener? get onExit => | ||
(event) => _notifyTouchEvent(FlPointerExitEvent(event)); | ||
|
||
/// Invokes the [_touchCallback] to notify listeners of this [FlTouchEvent] | ||
/// Invokes the [_touchCallback] to notify listeners of this [FlTouchEvent] if the pointer is one or zero(exit events). | ||
/// | ||
/// We get a [BaseTouchResponse] using [getResponseAtLocation] for events which contains a localPosition. | ||
/// Then we invoke [_touchCallback] using the [event] and [response]. | ||
|
@@ -149,11 +149,16 @@ abstract class RenderBaseChart<R extends BaseTouchResponse> extends RenderBox | |
return; | ||
} | ||
final localPosition = event.localPosition; | ||
final pointerCount = event.pointerCount; | ||
|
||
R? response; | ||
if (localPosition != null) { | ||
if (localPosition != null && pointerCount == 1) { | ||
response = getResponseAtLocation(localPosition); | ||
} | ||
_touchCallback!(event, response); | ||
|
||
if (pointerCount <= 1) { | ||
_touchCallback!(event, response); | ||
} | ||
|
||
if (_mouseCursorResolver == null) { | ||
_latestMouseCursor = MouseCursor.defer; | ||
|
@@ -162,6 +167,22 @@ abstract class RenderBaseChart<R extends BaseTouchResponse> extends RenderBox | |
} | ||
} | ||
|
||
/// Invokes the [_touchCallback] to notify listeners of this [FlTouchEvent] | ||
/// | ||
/// We don't get a response for these events because they are scale events (scroll, pinch.etc) | ||
/// We just invoke [_touchCallback] using the [event]. | ||
void _notifyScaleEvent(FlTouchEvent event) { | ||
if (_touchCallback == null) { | ||
return; | ||
} | ||
|
||
final pointerCount = event.pointerCount; | ||
|
||
if (pointerCount > 1) { | ||
_touchCallback!(event, null); | ||
} | ||
} | ||
|
||
/// Represents the mouse cursor style when hovers on our chart | ||
/// In the future we can change it runtime, for example we can turn it to | ||
/// [SystemMouseCursors.click] when mouse hovers a specific point of our chart. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it get called for the second finger (when you already have your first finger, and try to add the second finger to do the scale gesture)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, I think we should have something like fingerIndex or something like that