getHighlight method

  1. @override
Highlight? getHighlight(
  1. double x,
  2. double y
)
override

Returns the highlight for the touch at the pixel position (x, y), or null when the touch lies outside the chart radius, no entry lies under its angle or the chart has no data. The hole of a pie chart is not excluded.

Implementation

@override
Highlight? getHighlight(double x, double y) {
  final chart = this.chart;
  final touchDistanceToCenter = chart.distanceToCenter(x, y);

  if (touchDistanceToCenter > chart.radius) return null;

  var angle = chart.getAngleForPoint(x, y);

  if (chart is PieChart) {
    angle /= chart.animator.phaseY;
  }

  final index = chart.getIndexForAngle(angle);

  final entryCount = chart.data?.maxEntryCountSet?.entryCount ?? 0;
  if (index < 0 || index >= entryCount) return null;

  return getClosestHighlight(index, x, y);
}