visibleSegmentAt method

  1. @override
ChartSegment? visibleSegmentAt(
  1. Offset position
)
override

Implementation

@override
ChartSegment? visibleSegmentAt(Offset position) {
  if (segments.isEmpty) {
    return null;
  }

  final int segmentsCount = segments.length;
  if (canFindLinearVisibleIndexes) {
    if (visibleIndexes.isNotEmpty) {
      final int start = visibleIndexes[0];
      final int end = visibleIndexes[1];
      for (int i = start; i <= end; i++) {
        if (i < segmentsCount) {
          final ChartSegment segment = segments[i];
          if (segment.contains(position)) {
            return segment;
          }
        }
      }
    }
  } else {
    for (final int index in visibleIndexes) {
      if (index < segmentsCount) {
        final ChartSegment segment = segments[index];
        if (segment.contains(position)) {
          return segment;
        }
      }
    }
  }

  return null;
}