contains method
Implementation
@override
List<ChartSegment> contains(Offset position) {
if (animationController != null && animationController!.isAnimating) {
return <ChartSegment>[];
}
final List<ChartSegment> segmentCollection = <ChartSegment>[];
int index = 0;
double delta = 0;
num? nearPointX;
num? nearPointY;
for (final ChartSegment segment in segments) {
if (segment is LineSegment<T, D>) {
nearPointX ??= segment.series.xValues[0];
nearPointY ??= segment.series.yAxis!.visibleRange!.minimum;
final Rect rect = segment.series.paintBounds;
final num touchXValue =
segment.series.xAxis!.pixelToPoint(rect, position.dx, position.dy);
final num touchYValue =
segment.series.yAxis!.pixelToPoint(rect, position.dx, position.dy);
final double curX = segment.series.xValues[index].toDouble();
final double curY = segment.series.yValues[index].toDouble();
if (delta == touchXValue - curX) {
if ((touchYValue - curY).abs() > (touchYValue - nearPointY).abs()) {
segmentCollection.clear();
}
segmentCollection.add(segment);
} else if ((touchXValue - curX).abs() <=
(touchXValue - nearPointX).abs()) {
nearPointX = curX;
nearPointY = curY;
delta = touchXValue - curX;
segmentCollection.clear();
segmentCollection.add(segment);
}
}
index++;
}
return segmentCollection;
}