From d9c7af8be0e83e2c12660a6b0a27892e210e53f7 Mon Sep 17 00:00:00 2001 From: terryl1900 Date: Mon, 22 Mar 2021 13:50:42 -0700 Subject: [PATCH] Remove touchLineEndAtDot. --- .../lib/line_chart/samples/line_chart_sample8.dart | 1 - lib/src/chart/line_chart/line_chart_data.dart | 11 +---------- lib/src/chart/line_chart/line_chart_painter.dart | 10 +++++++--- repo_files/documentations/line_chart.md | 1 - test/chart/data_pool.dart | 1 - 5 files changed, 8 insertions(+), 16 deletions(-) diff --git a/example/lib/line_chart/samples/line_chart_sample8.dart b/example/lib/line_chart/samples/line_chart_sample8.dart index 2906f2928..2a24036a5 100644 --- a/example/lib/line_chart/samples/line_chart_sample8.dart +++ b/example/lib/line_chart/samples/line_chart_sample8.dart @@ -152,7 +152,6 @@ class _LineChartSample8State extends State { ), lineTouchData: LineTouchData( getTouchLineEnd: (data, index) => double.infinity, - touchLineEndAtDot: false, getTouchedSpotIndicator: (LineChartBarData barData, List spotIndexes) { return spotIndexes.map((spotIndex) { return TouchedSpotIndicatorData( diff --git a/lib/src/chart/line_chart/line_chart_data.dart b/lib/src/chart/line_chart/line_chart_data.dart index fbdfca1f7..e71858940 100644 --- a/lib/src/chart/line_chart/line_chart_data.dart +++ b/lib/src/chart/line_chart/line_chart_data.dart @@ -1308,13 +1308,9 @@ class LineTouchData extends FlTouchData with EquatableMixin { final GetTouchLineY getTouchLineStart; /// The end point on y axis of the touch line. By default, line ends at the touched point. - /// Though the line's length will be reduce to avoid overlap with the dot if - /// [touchLineEndAtDot] is true. + /// If line end is overlap with the dot, it will be automatically adjusted to the edge of the dot. final GetTouchLineY getTouchLineEnd; - /// Sets to avoid the touch line to overlap with the dot. Default is true. - final bool touchLineEndAtDot; - /// Informs the touchResponses final LineTouchCallback? touchCallback; @@ -1338,7 +1334,6 @@ class LineTouchData extends FlTouchData with EquatableMixin { bool? handleBuiltInTouches, GetTouchLineY? getTouchLineStart, GetTouchLineY? getTouchLineEnd, - bool? touchLineEndAtDot, LineTouchCallback? touchCallback, }) : touchTooltipData = touchTooltipData ?? LineTouchTooltipData(), getTouchedSpotIndicator = getTouchedSpotIndicator ?? defaultTouchedIndicators, @@ -1346,7 +1341,6 @@ class LineTouchData extends FlTouchData with EquatableMixin { handleBuiltInTouches = handleBuiltInTouches ?? true, getTouchLineStart = getTouchLineStart ?? defaultGetTouchLineStart, getTouchLineEnd = getTouchLineEnd ?? defaultGetTouchLineEnd, - touchLineEndAtDot = touchLineEndAtDot ?? true, touchCallback = touchCallback, super(enabled ?? true); @@ -1359,7 +1353,6 @@ class LineTouchData extends FlTouchData with EquatableMixin { double? touchSpotThreshold, GetTouchLineY? getTouchLineStart, GetTouchLineY? getTouchLineEnd, - bool? touchLineEndAtDot, bool? handleBuiltInTouches, Function(LineTouchResponse)? touchCallback, }) { @@ -1370,7 +1363,6 @@ class LineTouchData extends FlTouchData with EquatableMixin { touchSpotThreshold: touchSpotThreshold ?? this.touchSpotThreshold, getTouchLineStart: getTouchLineStart ?? this.getTouchLineStart, getTouchLineEnd: getTouchLineEnd ?? this.getTouchLineEnd, - touchLineEndAtDot: touchLineEndAtDot ?? this.touchLineEndAtDot, handleBuiltInTouches: handleBuiltInTouches ?? this.handleBuiltInTouches, touchCallback: touchCallback ?? this.touchCallback, ); @@ -1385,7 +1377,6 @@ class LineTouchData extends FlTouchData with EquatableMixin { handleBuiltInTouches, getTouchLineStart, getTouchLineEnd, - touchLineEndAtDot, touchCallback, enabled, ]; diff --git a/lib/src/chart/line_chart/line_chart_painter.dart b/lib/src/chart/line_chart/line_chart_painter.dart index 600d908c0..a5fa8d8e9 100644 --- a/lib/src/chart/line_chart/line_chart_painter.dart +++ b/lib/src/chart/line_chart/line_chart_painter.dart @@ -320,11 +320,15 @@ class LineChartPainter extends AxisChartPainter { min(data.maxY, max(data.minY, data.lineTouchData.getTouchLineEnd(barData, index))); final lineStart = Offset(touchedSpot.dx, getPixelY(lineStartY, chartViewSize, holder)); var lineEnd = Offset(touchedSpot.dx, getPixelY(lineEndY, chartViewSize, holder)); - if (data.lineTouchData.touchLineEndAtDot) { + + /// If line end is inside the dot, adjust it so that it doesn't overlap with the dot. + final dotMinY = touchedSpot.dy - dotHeight / 2; + final dotMaxY = touchedSpot.dy + dotHeight / 2; + if (lineEnd.dy > dotMinY && lineEnd.dy < dotMaxY) { if (lineStart.dy < lineEnd.dy) { - lineEnd -= Offset(0, dotHeight / 2); + lineEnd -= Offset(0, lineEnd.dy - dotMinY); } else { - lineEnd += Offset(0, dotHeight / 2); + lineEnd += Offset(0, dotMaxY - lineEnd.dy); } } diff --git a/repo_files/documentations/line_chart.md b/repo_files/documentations/line_chart.md index 9afe55671..5924e6e1d 100644 --- a/repo_files/documentations/line_chart.md +++ b/repo_files/documentations/line_chart.md @@ -171,7 +171,6 @@ When you change the chart's state, it animates to the new state internally (usin |handleBuiltInTouches| set this true if you want the built in touch handling (show a tooltip bubble and an indicator on touched spots) | true| |getTouchLineStart| controls where the line starts, default is bottom of the chart| defaultGetTouchLineStart| |getTouchLineEnd| controls where the line ends, default is the touch point| defaultGetTouchLineEnd| -|touchLineEndAtDot| whether to avoid the touch line to overlap with the dot| true| |touchCallback| listen to this callback to retrieve touch events, it gives you a [LineTouchResponse](#LineTouchResponse)| null| diff --git a/test/chart/data_pool.dart b/test/chart/data_pool.dart index 7bc4ee4af..b9c5a5f39 100644 --- a/test/chart/data_pool.dart +++ b/test/chart/data_pool.dart @@ -1048,7 +1048,6 @@ final LineTouchData lineTouchData7 = LineTouchData( touchSpotThreshold: 12, touchTooltipData: lineTouchTooltipData1, getTouchLineEnd: (barData, index) => double.infinity, - touchLineEndAtDot: false, ); final String Function(HorizontalLine) horizontalLabelResolver = (horizontalLine) => 'test';