ChartInteractionHelper class

Helper class for detecting chart interactions.

This utility class provides optimized static methods to detect taps and hovers on various chart elements such as points, bars, segments, and shapes.

All methods include comprehensive input validation to prevent NaN and Infinity errors, and use efficient algorithms (e.g., squared distance calculations) for better performance.

Performance

  • Uses squared distance calculations to avoid expensive sqrt operations
  • Early exit optimizations for bounds checking
  • Single-pass algorithms where possible
  • Comprehensive input validation
  • Cached calculations where applicable

Example

final result = ChartInteractionHelper.findNearestPoint(
  tapPosition,
  dataSets,
  chartSize,
  minX, maxX, minY, maxY,
  ChartInteractionConstants.tapRadius,
);

if (result != null && result.isHit) {
  print('Tapped: ${result.point!.y}');
}

See also:

Constructors

ChartInteractionHelper()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

findBar(Offset tapPosition, List<ChartDataSet> dataSets, Size chartSize, double minX, double maxX, double minY, double maxY, double barWidth) ChartInteractionResult?
Find bar at tap location (optimized with early exit).
findFunnelSegment(Offset tapPosition, List<PieData> data, Size size, double animationProgress) ChartInteractionResult?
Find funnel chart segment at tap location.
findNearestPoint(Offset tapPosition, List<ChartDataSet> dataSets, Size chartSize, double minX, double maxX, double minY, double maxY, double tapRadius) ChartInteractionResult?
Find nearest point to tap location (optimized with early exit and squared distance).
findPieSegment(Offset tapPosition, List<PieData> data, Size size, double centerSpaceRadius) ChartInteractionResult?
Find pie/donut chart segment at tap location.
findPyramidSegment(Offset tapPosition, List<PieData> data, Size size, double animationProgress) ChartInteractionResult?
Find pyramid chart segment at tap location.
findRadarPoint(Offset tapPosition, List<RadarDataSet> dataSets, Size size, double maxValue, double animationProgress) ChartInteractionResult?
Find radar chart point at tap location.