getNearestDatumDetailPerSeries method

List<DatumDetails<D>> getNearestDatumDetailPerSeries(
  1. Point<double> drawAreaPoint,
  2. bool selectAcrossAllDrawAreaComponents
)
inherited

Retrieves the datum details that are nearest to the given drawAreaPoint.

drawAreaPoint represents a point in the chart, such as a point that was clicked/tapped on by a user.

selectAcrossAllDrawAreaComponents specifies whether nearest data selection should be done across the combined draw area of all components with series draw areas, or just the chart's primary draw area bounds.

Implementation

List<DatumDetails<D>> getNearestDatumDetailPerSeries(
    Point<double> drawAreaPoint, bool selectAcrossAllDrawAreaComponents) {
  // Optionally grab the combined draw area bounds of all components. If this
  // is disabled, then we expect each series renderer to filter out the event
  // if [chartPoint] is located outside of its own component bounds.
  final boundsOverride =
      selectAcrossAllDrawAreaComponents ? drawableLayoutAreaBounds : null;

  final details = <DatumDetails<D>>[];
  _usingRenderers.forEach((String rendererId) {
    details
        .addAll(getSeriesRenderer(rendererId).getNearestDatumDetailPerSeries(
      drawAreaPoint,
      selectNearestByDomain,
      boundsOverride,
      selectOverlappingPoints: selectOverlappingPoints,
      selectExactEventLocation: selectExactEventLocation,
    ));
  });

  details.sort((DatumDetails<D> a, DatumDetails<D> b) {
    // Sort so that the nearest one is first.
    // Special sort, sort by domain distance first, then by measure distance.
    if (selectNearestByDomain) {
      final domainDiff = a.domainDistance!.compareTo(b.domainDistance!);
      if (domainDiff == 0) {
        return a.measureDistance!.compareTo(b.measureDistance!);
      }
      return domainDiff;
    } else {
      return a.relativeDistance!.compareTo(b.relativeDistance!);
    }
  });

  return details;
}