function getNearestItems(chart, position, intersect, distanceMetric) {
	var minDistance = Number.POSITIVE_INFINITY;
	var nearestItems = [];

	parseVisibleItems(chart, function(element) {
		if (intersect && !element.inRange(position.x, position.y)) {
			return;
		}

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

	return nearestItems;
}
function getNearestItems(chart, position, intersect, distanceMetric) {
	var minDistance = Number.POSITIVE_INFINITY;
	var nearestItems = [];

	parseVisibleItems(chart, function(element) {
		if (intersect && !element.inRange(position.x, position.y)) {
			return;
		}

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

	return nearestItems;
}
function getNearestItems ( chart , position , intersect , distanceMetric ) { var minDistance = Number . POSITIVE_INFINITY ; var nearestItems = [ ] ; parseVisibleItems ( chart , function ( element ) { if ( intersect && ! element . inRange ( position . x , position . y ) ) { return ; } var center = element . getCenterPoint ( ) ; var distance = distanceMetric ( position , center ) ; if ( distance < minDistance ) { nearestItems = [ element ] ; minDistance = distance ; } else if ( distance === minDistance ) { // Can have multiple items at the same distance in which case we sort by size nearestItems . push ( element ) ; } } ) ; return nearestItems ; }
Helper function to get the items nearest to the event position considering all visible items in teh chart
@param {Chart} chart - the chart to look at elements from
@param {object} position - the point to be nearest to
@param {boolean} intersect - if true, only consider items that intersect the position
@param {function} distanceMetric - function to provide the distance between points
@return {ChartElement[]} the nearest items
Helper function to get the items nearest to the event position considering all visible items in teh chart
Returns an array of items that are closest to the given position