Skip to content

Commit

Permalink
Remove touchLineEndAtDot.
Browse files Browse the repository at this point in the history
  • Loading branch information
terryl1900 committed Mar 22, 2021
1 parent 84cf25d commit d9c7af8
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 16 deletions.
1 change: 0 additions & 1 deletion example/lib/line_chart/samples/line_chart_sample8.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ class _LineChartSample8State extends State<LineChartSample8> {
),
lineTouchData: LineTouchData(
getTouchLineEnd: (data, index) => double.infinity,
touchLineEndAtDot: false,
getTouchedSpotIndicator: (LineChartBarData barData, List<int> spotIndexes) {
return spotIndexes.map((spotIndex) {
return TouchedSpotIndicatorData(
Expand Down
11 changes: 1 addition & 10 deletions lib/src/chart/line_chart/line_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -1338,15 +1334,13 @@ class LineTouchData extends FlTouchData with EquatableMixin {
bool? handleBuiltInTouches,
GetTouchLineY? getTouchLineStart,
GetTouchLineY? getTouchLineEnd,
bool? touchLineEndAtDot,
LineTouchCallback? touchCallback,
}) : touchTooltipData = touchTooltipData ?? LineTouchTooltipData(),
getTouchedSpotIndicator = getTouchedSpotIndicator ?? defaultTouchedIndicators,
touchSpotThreshold = touchSpotThreshold ?? 10,
handleBuiltInTouches = handleBuiltInTouches ?? true,
getTouchLineStart = getTouchLineStart ?? defaultGetTouchLineStart,
getTouchLineEnd = getTouchLineEnd ?? defaultGetTouchLineEnd,
touchLineEndAtDot = touchLineEndAtDot ?? true,
touchCallback = touchCallback,
super(enabled ?? true);

Expand All @@ -1359,7 +1353,6 @@ class LineTouchData extends FlTouchData with EquatableMixin {
double? touchSpotThreshold,
GetTouchLineY? getTouchLineStart,
GetTouchLineY? getTouchLineEnd,
bool? touchLineEndAtDot,
bool? handleBuiltInTouches,
Function(LineTouchResponse)? touchCallback,
}) {
Expand All @@ -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,
);
Expand All @@ -1385,7 +1377,6 @@ class LineTouchData extends FlTouchData with EquatableMixin {
handleBuiltInTouches,
getTouchLineStart,
getTouchLineEnd,
touchLineEndAtDot,
touchCallback,
enabled,
];
Expand Down
10 changes: 7 additions & 3 deletions lib/src/chart/line_chart/line_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,15 @@ class LineChartPainter extends AxisChartPainter<LineChartData> {
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);
}
}

Expand Down
1 change: 0 additions & 1 deletion repo_files/documentations/line_chart.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|


Expand Down
1 change: 0 additions & 1 deletion test/chart/data_pool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit d9c7af8

Please sign in to comment.