Skip to content

Commit

Permalink
Merge pull request #134 from imaNNeoFighT/improvement/redesign-touch-…
Browse files Browse the repository at this point in the history
…sizings

fixed calculating chart size for touch handling in *_chart.dart files…
  • Loading branch information
imaNNeo authored Dec 10, 2019
2 parents fd7a79d + b93a811 commit a49b700
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 25 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
##
* fixed calculating size for handling touches bug, #126

## 0.5.2
* drawing titles using targetData instead of animating data, fixed issue #130.

Expand Down
49 changes: 43 additions & 6 deletions lib/src/chart/bar_chart/bar_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,53 +31,87 @@ class BarChartState extends AnimatedWidgetBaseState<BarChart> {
Widget build(BuildContext context) {

final BarChartData showingData = _getDate();
final Size chartSize = _getChartSize();
final BarTouchData touchData = showingData.barTouchData;

return GestureDetector(
onLongPressStart: (d) {
final Size chartSize = _getChartSize();
if (chartSize == null) {
return;
}

final BarTouchResponse response =
_touchHandler?.handleTouch(FlLongPressStart(d.localPosition), chartSize);
if (_canHandleTouch(response, touchData)) {
touchData.touchCallback(response);
}
},
onLongPressEnd: (d) async {
onLongPressEnd: (d) {
final Size chartSize = _getChartSize();
if (chartSize == null) {
return;
}

final BarTouchResponse response =
_touchHandler?.handleTouch(FlLongPressEnd(d.localPosition), chartSize);
if (_canHandleTouch(response, touchData)) {
touchData.touchCallback(response);
}
},
onLongPressMoveUpdate: (d) {
final Size chartSize = _getChartSize();
if (chartSize == null) {
return;
}

final BarTouchResponse response =
_touchHandler?.handleTouch(FlLongPressMoveUpdate(d.localPosition), chartSize);
if (_canHandleTouch(response, touchData)) {
touchData.touchCallback(response);
}
},
onPanCancel: () async {
onPanCancel: () {
final Size chartSize = _getChartSize();
if (chartSize == null) {
return;
}

final BarTouchResponse response =
_touchHandler?.handleTouch(FlPanEnd(Offset.zero, Velocity(pixelsPerSecond: Offset.zero)), chartSize);
if (_canHandleTouch(response, touchData)) {
touchData.touchCallback(response);
}
},
onPanEnd: (DragEndDetails details) async {
onPanEnd: (DragEndDetails details) {
final Size chartSize = _getChartSize();
if (chartSize == null) {
return;
}

final BarTouchResponse response =
_touchHandler?.handleTouch(FlPanEnd(Offset.zero, details.velocity), chartSize);
if (_canHandleTouch(response, touchData)) {
touchData.touchCallback(response);
}
},
onPanDown: (DragDownDetails details) {
final Size chartSize = _getChartSize();
if (chartSize == null) {
return;
}

final BarTouchResponse response =
_touchHandler?.handleTouch(FlPanStart(details.localPosition), chartSize);
if (_canHandleTouch(response, touchData)) {
touchData.touchCallback(response);
}
},
onPanUpdate: (DragUpdateDetails details) {
final Size chartSize = _getChartSize();
if (chartSize == null) {
return;
}

final BarTouchResponse response =
_touchHandler?.handleTouch(FlPanMoveUpdate(details.localPosition), chartSize);
if (_canHandleTouch(response, touchData)) {
Expand Down Expand Up @@ -132,9 +166,12 @@ class BarChartState extends AnimatedWidgetBaseState<BarChart> {
Size _getChartSize() {
if (_chartKey.currentContext != null) {
final RenderBox containerRenderBox = _chartKey.currentContext.findRenderObject();
return containerRenderBox.constraints.biggest;
if (containerRenderBox.hasSize) {
return containerRenderBox.size;
}
return null;
} else {
return getDefaultSize(context);
return null;
}
}

Expand Down
49 changes: 43 additions & 6 deletions lib/src/chart/line_chart/line_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,53 +36,87 @@ class LineChartState extends AnimatedWidgetBaseState<LineChart> {
Widget build(BuildContext context) {

final LineChartData showingData = _getDate();
final Size chartSize = _getChartSize();
final LineTouchData touchData = showingData.lineTouchData;

return GestureDetector(
onLongPressStart: (d) {
final Size chartSize = _getChartSize();
if (chartSize == null) {
return;
}

final LineTouchResponse response =
_touchHandler?.handleTouch(FlLongPressStart(d.localPosition), chartSize);
if (_canHandleTouch(response, touchData)) {
touchData.touchCallback(response);
}
},
onLongPressEnd: (d) async {
onLongPressEnd: (d) {
final Size chartSize = _getChartSize();
if (chartSize == null) {
return;
}

final LineTouchResponse response =
_touchHandler?.handleTouch(FlLongPressEnd(d.localPosition), chartSize);
if (_canHandleTouch(response, touchData)) {
touchData.touchCallback(response);
}
},
onLongPressMoveUpdate: (d) {
final Size chartSize = _getChartSize();
if (chartSize == null) {
return;
}

final LineTouchResponse response =
_touchHandler?.handleTouch(FlLongPressMoveUpdate(d.localPosition), chartSize);
if (_canHandleTouch(response, touchData)) {
touchData.touchCallback(response);
}
},
onPanCancel: () async {
onPanCancel: () {
final Size chartSize = _getChartSize();
if (chartSize == null) {
return;
}

final LineTouchResponse response =
_touchHandler?.handleTouch(FlPanEnd(Offset.zero, Velocity(pixelsPerSecond: Offset.zero)), chartSize);
if (_canHandleTouch(response, touchData)) {
touchData.touchCallback(response);
}
},
onPanEnd: (DragEndDetails details) async {
onPanEnd: (DragEndDetails details) {
final Size chartSize = _getChartSize();
if (chartSize == null) {
return;
}

final LineTouchResponse response =
_touchHandler?.handleTouch(FlPanEnd(Offset.zero, details.velocity), chartSize);
if (_canHandleTouch(response, touchData)) {
touchData.touchCallback(response);
}
},
onPanDown: (DragDownDetails details) {
final Size chartSize = _getChartSize();
if (chartSize == null) {
return;
}

final LineTouchResponse response =
_touchHandler?.handleTouch(FlPanStart(details.localPosition), chartSize);
if (_canHandleTouch(response, touchData)) {
touchData.touchCallback(response);
}
},
onPanUpdate: (DragUpdateDetails details) {
final Size chartSize = _getChartSize();
if (chartSize == null) {
return;
}

final LineTouchResponse response =
_touchHandler?.handleTouch(FlPanMoveUpdate(details.localPosition), chartSize);
if (_canHandleTouch(response, touchData)) {
Expand Down Expand Up @@ -132,9 +166,12 @@ class LineChartState extends AnimatedWidgetBaseState<LineChart> {
Size _getChartSize() {
if (_chartKey.currentContext != null) {
final RenderBox containerRenderBox = _chartKey.currentContext.findRenderObject();
return containerRenderBox.constraints.biggest;
if (containerRenderBox.hasSize) {
return containerRenderBox.size;
}
return null;
} else {
return getDefaultSize(context);
return null;
}
}

Expand Down
48 changes: 42 additions & 6 deletions lib/src/chart/pie_chart/pie_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,53 +32,86 @@ class PieChartState extends AnimatedWidgetBaseState<PieChart> {
@override
Widget build(BuildContext context) {
final PieChartData showingData = _getDate();
final Size chartSize = _getChartSize();
final PieTouchData touchData = showingData.pieTouchData;

return GestureDetector(
onLongPressStart: (d) {
final Size chartSize = _getChartSize();
if (chartSize == null) {
return;
}
final PieTouchResponse response =
_touchHandler?.handleTouch(FlLongPressStart(d.localPosition), chartSize);
if (_canHandleTouch(response, touchData)) {
touchData.touchCallback(response);
}
},
onLongPressEnd: (d) async {
onLongPressEnd: (d) {
final Size chartSize = _getChartSize();
if (chartSize == null) {
return;
}

final PieTouchResponse response =
_touchHandler?.handleTouch(FlLongPressEnd(d.localPosition), chartSize);
if (_canHandleTouch(response, touchData)) {
touchData.touchCallback(response);
}
},
onLongPressMoveUpdate: (d) {
final Size chartSize = _getChartSize();
if (chartSize == null) {
return;
}

final PieTouchResponse response =
_touchHandler?.handleTouch(FlLongPressMoveUpdate(d.localPosition), chartSize);
if (_canHandleTouch(response, touchData)) {
touchData.touchCallback(response);
}
},
onPanCancel: () async {
onPanCancel: () {
final Size chartSize = _getChartSize();
if (chartSize == null) {
return;
}

final PieTouchResponse response =
_touchHandler?.handleTouch(FlPanEnd(Offset.zero, Velocity(pixelsPerSecond: Offset.zero)), chartSize);
if (_canHandleTouch(response, touchData)) {
touchData.touchCallback(response);
}
},
onPanEnd: (DragEndDetails details) async {
onPanEnd: (DragEndDetails details) {
final Size chartSize = _getChartSize();
if (chartSize == null) {
return;
}

final PieTouchResponse response =
_touchHandler?.handleTouch(FlPanEnd(Offset.zero, details.velocity), chartSize);
if (_canHandleTouch(response, touchData)) {
touchData.touchCallback(response);
}
},
onPanDown: (DragDownDetails details) {
final Size chartSize = _getChartSize();
if (chartSize == null) {
return;
}

final PieTouchResponse response =
_touchHandler?.handleTouch(FlPanStart(details.localPosition), chartSize);
if (_canHandleTouch(response, touchData)) {
touchData.touchCallback(response);
}
},
onPanUpdate: (DragUpdateDetails details) {
final Size chartSize = _getChartSize();
if (chartSize == null) {
return;
}

final PieTouchResponse response =
_touchHandler?.handleTouch(FlPanMoveUpdate(details.localPosition), chartSize);
if (_canHandleTouch(response, touchData)) {
Expand Down Expand Up @@ -108,9 +141,12 @@ class PieChartState extends AnimatedWidgetBaseState<PieChart> {
Size _getChartSize() {
if (_chartKey.currentContext != null) {
final RenderBox containerRenderBox = _chartKey.currentContext.findRenderObject();
return containerRenderBox.constraints.biggest;
if (containerRenderBox.hasSize) {
return containerRenderBox.size;
}
return null;
} else {
return getDefaultSize(context);
return null;
}
}

Expand Down
Loading

0 comments on commit a49b700

Please sign in to comment.