* Helper function to get the items matching along the given X or Y axis * @param chart - the chart to look at elements from * @param position - the point to be nearest to, in relative coordinates * @param axis - the axis to match * @param [intersect] - if true, only consider items that intersect
( chart: Chart, position: Point, axis: 'x' | 'y', intersect?: boolean, useFinalPosition?: boolean )
| 297 | * @return the nearest items |
| 298 | */ |
| 299 | function getAxisItems( |
| 300 | chart: Chart, |
| 301 | position: Point, |
| 302 | axis: 'x' | 'y', |
| 303 | intersect?: boolean, |
| 304 | useFinalPosition?: boolean |
| 305 | ): InteractionItem[] { |
| 306 | const items: InteractionItem[] = []; |
| 307 | const rangeMethod = axis === 'x' ? 'inXRange' : 'inYRange'; |
| 308 | let intersectsItem = false; |
| 309 | |
| 310 | evaluateInteractionItems(chart, axis, position, (element: InteractionElement, datasetIndex: number, index: number) => { |
| 311 | if (element[rangeMethod] && element[rangeMethod](position[axis], useFinalPosition)) { |
| 312 | items.push({element, datasetIndex, index}); |
| 313 | intersectsItem = intersectsItem || element.inRange(position.x, position.y, useFinalPosition); |
| 314 | } |
| 315 | }); |
| 316 | |
| 317 | // If we want to trigger on an intersect and we don't have any items |
| 318 | // that intersect the position, return nothing |
| 319 | if (intersect && !intersectsItem) { |
| 320 | return []; |
| 321 | } |
| 322 | return items; |
| 323 | } |
| 324 | |
| 325 | /** |
| 326 | * Contains interaction related functions |
no test coverage detected