function getNearestCartesianItems(chart, position, axis, intersect, useFinalPosition, includeInvisible) {
  let items = [];
  const distanceMetric = getDistanceMetricForAxis(axis);
  let minDistance = Number.POSITIVE_INFINITY;

  function evaluationFunc(element, datasetIndex, index) {
    const inRange = element.inRange(position.x, position.y, useFinalPosition);
    if (intersect && !inRange) {
      return;
    }

    const center = element.getCenterPoint(useFinalPosition);
    const pointInArea = !!includeInvisible || chart.isPointInArea(center);
    if (!pointInArea && !inRange) {
      return;
    }

    const distance = distanceMetric(position, center);
    if (distance < minDistance) {
      items = [{element, datasetIndex, index}];
      minDistance = distance;
    } else if (distance === minDistance) {
      // Can have multiple items at the same distance in which case we sort by size
      items.push({element, datasetIndex, index});
    }
  }

  evaluateInteractionItems(chart, axis, position, evaluationFunc);
  return items;
}
Helper function to get the items nearest to the event position for a cartesian chart
@param {Chart} chart - the chart to look at elements from
@param {Point} position - the point to be nearest to, in relative coordinates
@param {string} axis - the axes along which to measure distance
@param {boolean} [intersect] - if true, only consider items that intersect the position
@param {boolean} [useFinalPosition] - use the element's animation target instead of current position
@param {boolean} [includeInvisible] - include invisible points that are outside of the chart area
@return {InteractionItem[]} the nearest items