Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 43d771e

Browse files
authored
Merge pull request imaNNeo#57 from imaNNeoFighT/feature/tap
Feature/tap
2 parents 40d9ac8 + a042674 commit 43d771e

File tree

17 files changed

+102
-28
lines changed

17 files changed

+102
-28
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 0.1.6
2+
* added `enableNormalTouch` property to chart's TouchData to handle normal taps, and enabled by default.
3+
14
## 0.1.5
25
* reverted getPixelY() on axis_chart_painter to solve the regression bug (fixed issue #48)
36
* (fix) BelowBar considers its own color stops refs #46

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Thank you all!
3636

3737
```kotlin
3838
dependencies:
39-
fl_chart: ^0.1.5
39+
fl_chart: ^0.1.6
4040
```
4141

4242

example/lib/line_chart/samples/line_chart_sample3.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class LineChartSample3 extends StatelessWidget {
1818
style: TextStyle(color: Colors.green, fontWeight: FontWeight.bold, fontSize: 16),),
1919
const Text(' and ',
2020
style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold, fontSize: 16),),
21-
const Text('Indiactors',
21+
const Text('Indicators',
2222
style: TextStyle(color: Colors.blue, fontWeight: FontWeight.bold, fontSize: 16),),
2323
],
2424
),

example/lib/pie_chart/samples/pie_chart_sample2.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ class PieChart2State extends State {
7070

7171
pieTouchedResultStreamController = StreamController();
7272
pieTouchedResultStreamController.stream.distinct().listen((details) {
73-
print(details);
7473
if (details == null) {
7574
return;
7675
}

lib/fl_chart.dart

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,25 @@ class _FlChartState extends State<FlChart> {
5757
Widget build(BuildContext context) {
5858
return GestureDetector(
5959
onLongPressStart: (d) {
60-
_touchInputNotifier.value = FlLongPressStart(
61-
_globalToLocal(context, d.globalPosition),
62-
);
60+
_touchInputNotifier.value = FlLongPressStart(d.localPosition);
6361
},
6462
onLongPressEnd: (d) {
65-
_touchInputNotifier.value = FlLongPressEnd(
66-
_globalToLocal(context, d.globalPosition),
67-
);
63+
_touchInputNotifier.value = FlLongPressEnd(d.localPosition);
6864
},
6965
onLongPressMoveUpdate: (d) {
70-
_touchInputNotifier.value = FlLongPressMoveUpdate(
71-
_globalToLocal(context, d.globalPosition),
72-
);
66+
_touchInputNotifier.value = FlLongPressMoveUpdate(d.localPosition);
67+
},
68+
onPanCancel: () {
69+
_touchInputNotifier.value = FlPanEnd(Offset.zero);
70+
},
71+
onPanEnd: (DragEndDetails details) {
72+
_touchInputNotifier.value = FlPanEnd(Offset.zero);
73+
},
74+
onPanDown: (DragDownDetails details) {
75+
_touchInputNotifier.value = FlPanStart(details.localPosition);
76+
},
77+
onPanUpdate: (DragUpdateDetails details) {
78+
_touchInputNotifier.value = FlPanMoveUpdate(details.localPosition);
7379
},
7480
child: CustomPaint(
7581
painter: widget.chart.painter(
@@ -80,11 +86,6 @@ class _FlChartState extends State<FlChart> {
8086
);
8187
}
8288

83-
Offset _globalToLocal(BuildContext context, Offset globalPosition) {
84-
final RenderBox box = context.findRenderObject();
85-
return box.globalToLocal(globalPosition);
86-
}
87-
8889
@override
8990
void dispose() {
9091
super.dispose();

lib/src/chart/bar_chart/bar_chart_data.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,12 @@ class BarTouchData extends FlTouchData {
226226

227227
const BarTouchData({
228228
bool enabled = true,
229+
bool enableNormalTouch = true,
229230
this.touchTooltipData = const TouchTooltipData(),
230231
this.touchExtraThreshold = const EdgeInsets.all(4),
231232
this.allowTouchBarBackDraw = false,
232233
StreamSink<BarTouchResponse> touchResponseSink,
233-
}) : super(enabled, touchResponseSink);
234+
}) : super(enabled, touchResponseSink, enableNormalTouch);
234235

235236
}
236237

lib/src/chart/base/axis_chart/axis_chart_painter.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ abstract class AxisChartPainter<D extends AxisChartData> extends BaseChartPainte
115115
}
116116

117117
void drawTouchTooltip(Canvas canvas, Size viewSize, TouchTooltipData tooltipData, List<TouchedSpot> touchedSpots) {
118-
119-
if (touchInputNotifier.value is FlLongPressEnd) {
118+
119+
if (!shouldDrawTouch()) {
120120
return;
121121
}
122122

lib/src/chart/base/base_chart/base_chart_data.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,14 @@ class FlTouchData {
5151
/// determines enable or disable the touch in the chart
5252
final bool enabled;
5353

54+
/// determines that charts should respond to normal touch events or not
55+
final bool enableNormalTouch;
56+
5457
/// chart notifies the touch responses through this [StreamSink]
5558
/// in form of a [BaseTouchResponse] class
5659
final StreamSink<BaseTouchResponse> touchResponseSink;
5760

58-
const FlTouchData(this.enabled, this.touchResponseSink);
61+
const FlTouchData(this.enabled, this.touchResponseSink, this.enableNormalTouch);
5962
}
6063

6164

lib/src/chart/base/base_chart/base_chart_painter.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,22 @@ abstract class BaseChartPainter<D extends BaseChartData> extends CustomPainter {
100100
/// we should use this to offset our y axis when we drawing the chart,
101101
/// and the height space we can use to draw chart is[getChartUsableDrawSize.height]
102102
double getTopOffsetDrawSize() => 0;
103+
104+
/// checks that the touchInput is eligible to draw,
105+
/// and child painters can use this function to check then draw their default touch behaviors.
106+
bool shouldDrawTouch() {
107+
if (touchInputNotifier == null || shouldDrawTouch == null) {
108+
return false;
109+
}
110+
111+
if (touchInputNotifier.value is FlLongPressEnd || touchInputNotifier.value is FlPanEnd) {
112+
return false;
113+
}
114+
115+
if (touchInputNotifier.value is FlTouchNormapInput && !data.touchData.enableNormalTouch) {
116+
return false;
117+
}
118+
119+
return true;
120+
}
103121
}

lib/src/chart/base/base_chart/touch_input.dart

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ abstract class FlTouchInput {
99
Offset getOffset();
1010
}
1111

12-
class FlLongPressStart extends FlTouchInput {
12+
abstract class FlTouchLongInput extends FlTouchInput {}
13+
14+
class FlLongPressStart extends FlTouchLongInput {
1315

1416
final Offset localPosition;
1517

@@ -22,7 +24,7 @@ class FlLongPressStart extends FlTouchInput {
2224

2325
}
2426

25-
class FlLongPressMoveUpdate extends FlTouchInput {
27+
class FlLongPressMoveUpdate extends FlTouchLongInput {
2628

2729
final Offset localPosition;
2830

@@ -35,7 +37,7 @@ class FlLongPressMoveUpdate extends FlTouchInput {
3537

3638
}
3739

38-
class FlLongPressEnd extends FlTouchInput {
40+
class FlLongPressEnd extends FlTouchLongInput {
3941

4042
final Offset localPosition;
4143

@@ -46,4 +48,46 @@ class FlLongPressEnd extends FlTouchInput {
4648
return localPosition;
4749
}
4850

51+
}
52+
53+
54+
abstract class FlTouchNormapInput extends FlTouchInput {}
55+
56+
class FlPanStart extends FlTouchNormapInput {
57+
58+
final Offset localPosition;
59+
60+
FlPanStart(this.localPosition);
61+
62+
@override
63+
Offset getOffset() {
64+
return localPosition;
65+
}
66+
67+
}
68+
69+
class FlPanMoveUpdate extends FlTouchNormapInput {
70+
71+
final Offset localPosition;
72+
73+
FlPanMoveUpdate(this.localPosition);
74+
75+
@override
76+
Offset getOffset() {
77+
return localPosition;
78+
}
79+
80+
}
81+
82+
class FlPanEnd extends FlTouchNormapInput {
83+
84+
final Offset localPosition;
85+
86+
FlPanEnd(this.localPosition);
87+
88+
@override
89+
Offset getOffset() {
90+
return localPosition;
91+
}
92+
4993
}

0 commit comments

Comments
 (0)