Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions lib/src/chart/line_chart/line_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1385,7 +1385,7 @@ class LineChartPainter extends AxisChartPainter<LineChartData> {
}

/// Find the nearest spot (based on distanceCalculator)
final sortedSpots = <FlSpot>[];
FlSpot? nearestSpot;
double? smallestDistance;
for (final spot in barData.spots) {
if (spot.isNull()) continue;
Expand All @@ -1398,22 +1398,24 @@ class LineChartPainter extends AxisChartPainter<LineChartData> {
);

if (distance <= data.lineTouchData.touchSpotThreshold) {
smallestDistance ??= distance;
if (nearestSpot == null) {
nearestSpot = spot;
smallestDistance = distance;
continue;
}

if (distance < smallestDistance) {
sortedSpots.insert(0, spot);
if (distance < smallestDistance!) {
nearestSpot = spot;
smallestDistance = distance;
} else {
sortedSpots.add(spot);
}
}
}

if (sortedSpots.isNotEmpty) {
if (nearestSpot != null) {
return TouchLineBarSpot(
barData,
barDataPosition,
sortedSpots.first,
nearestSpot,
smallestDistance!,
);
} else {
Expand Down
Loading