Feature Request - add support for scale gesture recognition for LineTouchData.touchCallback
- Dominant language
- Dart
- Stars
- 7.6k
- Forks
- 2k
- Avg merge
- 9d 1h
- Merged PRs (30d)
- 2
Description
I thoroughly investigated a solution for supporting scale and panning of a line plot by manipulating minX and minY. I mostly followed the suggestions offered in this open [issue](https://github.com/imaNNeo/fl_chart/issues/71).
After trying many of the offered solutions and a few of my own I reached the following conclusions:
1. supporting panning of a plot is best done using `LineTouchData.touchCallback` and handling `FlPanUpdateEvent`.
2. supporting zoom is very hard to do: using a `GestureDetector` / `Listener` only seems to work properly if my FlChart is warpped in an `IgnorePointer` widget. and unfortunately `LineTouchData.touchCallback` does not support scale events.
I forked fl_chart and tried to add a `ScaleGestureRecognizer` to `RenderBaseChart` and added a bunch of `Fl***Events` for scale events. I followed the usage pattern for the other gesture recognizers however this doesn't work.
Could you advice on how this should be added?
Here is the essence of what I tried to add in `render_base_chart.dart`:
```
void initGestureRecognizers() {
_scaleGestureRecognizer = ScaleGestureRecognizer()
..onStart = (details) {
_notifyTouchEvent(FlScaleStartEvent(details));
}
..onUpdate = (details) {
_notifyTouchEvent(FlScaleUpdateEvent(details));
}
..onEnd = (details) {
_notifyTouchEvent(FlScaleEndEvent(details));
};
```
and here:
```
@override
void handleEvent(PointerEvent event, covariant BoxHitTestEntry entry) {
assert(debugHandleEvent(event, entry));
if (_touchCallback == null) {
return;
}
if (event is PointerDownEvent) {
_longPressGestureRecognizer.addPointer(event);
_tapGestureRecognizer.addPointer(event);
_panGestureRecognizer.addPointer(event);
_scaleGestureRecognizer.addPointer(event);
} else if (event is PointerHoverEvent) {
_notifyTouchEvent(FlPointerHoverEvent(event));
}
}
```
Contributor guide
Research direction
Start with render_base_chart.dart, especially initGestureRecognizers and handleEvent, and compare the existing recognizers with the proposed ScaleGestureRecognizer. Trace how FlPanUpdateEvent reaches LineTouchData.touchCallback. Done means scale start, update, and end events are supported there without disrupting the existing touch handling.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, flutter
- Domain
- data-visualization, frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100