Skip to content

Commit

Permalink
Merge pull request #60 from imaNNeoFighT/bugfix/loop
Browse files Browse the repository at this point in the history
Bugfix/loop
  • Loading branch information
imaNNeo authored Aug 20, 2019
2 parents 43d771e + 495bab0 commit 20dada0
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.2.0
* fixed a critical got stuck in draw loop bug,
* set `BarChartGroupData` x as required property to keep consistency and prevent unpredictable bugs

## 0.1.6
* added `enableNormalTouch` property to chart's TouchData to handle normal taps, and enabled by default.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Thank you all!

```kotlin
dependencies:
fl_chart: ^0.1.6
fl_chart: ^0.2.0
```


Expand Down
4 changes: 1 addition & 3 deletions example/lib/line_chart/samples/line_chart_sample1.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ class LineChartSample1State extends State<LineChartSample1> {
super.initState();

controller = StreamController();
controller.stream.distinct().listen((LineTouchResponse response){
print('response: ${response.touchInput}');
});
controller.stream.distinct().listen((LineTouchResponse response){});
}

@override
Expand Down
4 changes: 2 additions & 2 deletions lib/src/chart/bar_chart/bar_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ class BarChartGroupData {
/// to draw them independently by y value together.
/// [barsSpace] is the space between the bar lines inside group
const BarChartGroupData({
this.x,
@required this.x,
this.barRods = const [],
this.barsSpace = 2,
});
}): assert(x != null);

/// calculates the whole width of our group,
/// by adding all rod's width and group space * rods count.
Expand Down
12 changes: 9 additions & 3 deletions lib/src/chart/bar_chart/bar_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,15 @@ class BarChartPainter extends AxisChartPainter {
drawBars(canvas, size, groupBarsPosition);
drawTitles(canvas, size, groupBarsPosition);

super.drawTouchTooltip(canvas, size, data.barTouchData.touchTooltipData, [touchedSpot]);
if (touchedSpot != null) {
super.drawTouchTooltip(canvas, size, data.barTouchData.touchTooltipData, [touchedSpot]);
}

if (touchedResponseSink != null) {
if (touchedResponseSink != null && touchInputNotifier != null
&& touchInputNotifier.value != null
&& !(touchInputNotifier.value is NonTouch)) {
touchedResponseSink.add(BarTouchResponse(touchedSpot, touchInputNotifier.value));
releaseIfEndTouch();
}
}

Expand Down Expand Up @@ -342,6 +347,7 @@ class BarChartPainter extends AxisChartPainter {
return null;
}


final touch = touchInputNotifier.value;

if (touch.getOffset() == null) {
Expand Down Expand Up @@ -389,7 +395,7 @@ class BarChartPainter extends AxisChartPainter {
}
}

return BarTouchedSpot(null, null, null, null);
return null;
}

@override
Expand Down
16 changes: 15 additions & 1 deletion lib/src/chart/base/base_chart/base_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ abstract class BaseChartPainter<D extends BaseChartData> extends CustomPainter {
/// checks that the touchInput is eligible to draw,
/// and child painters can use this function to check then draw their default touch behaviors.
bool shouldDrawTouch() {
if (touchInputNotifier == null || shouldDrawTouch == null) {
if (touchInputNotifier == null
|| touchInputNotifier.value == null
|| shouldDrawTouch == null) {
return false;
}

Expand All @@ -118,4 +120,16 @@ abstract class BaseChartPainter<D extends BaseChartData> extends CustomPainter {

return true;
}

/// if the event was ended, we should release our touchInputNotifier
void releaseIfEndTouch() {
if (touchInputNotifier == null) {
return;
}
if (touchInputNotifier.value == null
|| touchInputNotifier.value is FlLongPressEnd
|| touchInputNotifier.value is FlPanEnd) {
touchInputNotifier.value = NonTouch();
}
}
}
8 changes: 8 additions & 0 deletions lib/src/chart/base/base_chart/touch_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,12 @@ class FlPanEnd extends FlTouchNormapInput {
return localPosition;
}

}


class NonTouch extends FlTouchInput {
@override
Offset getOffset() {
return null;
}
}
5 changes: 4 additions & 1 deletion lib/src/chart/line_chart/line_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,11 @@ class LineChartPainter extends AxisChartPainter {
// Draw touch tooltip on most top spot
super.drawTouchTooltip(canvas, viewSize, data.lineTouchData.touchTooltipData, touchedSpots);

if (touchedResponseSink != null) {
if (touchedResponseSink != null && touchInputNotifier != null
&& touchInputNotifier.value != null
&& !(touchInputNotifier.value.runtimeType is NonTouch)) {
touchedResponseSink.add(LineTouchResponse(touchedSpots, touchInputNotifier.value));
releaseIfEndTouch();
}
}

Expand Down
5 changes: 4 additions & 1 deletion lib/src/chart/pie_chart/pie_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ class PieChartPainter extends BaseChartPainter {
drawTexts(canvas, size);

final touched = _getTouchedDetails(canvas, size, sectionsAngle);
if (touchedResponseSink != null) {
if (touchedResponseSink != null && touchInputNotifier != null
&& touchInputNotifier.value != null
&& !(touchInputNotifier.value.runtimeType is NonTouch)) {
touchedResponseSink.add(touched);
releaseIfEndTouch();
}
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: fl_chart
description: A powerful Flutter chart library, currently supporting Line Chart, Bar Chart and Pie Chart.
version: 0.1.6
version: 0.2.0
author: Iman Khoshabi <iman.neofight@gmail.com>
homepage: https://github.com/imaNNeoFighT/fl_chart

Expand Down

0 comments on commit 20dada0

Please sign in to comment.