* Returns items at the same index. If the options.intersect parameter is true, we only return items if we intersect something * If the options.intersect mode is false, we find the nearest item and return the items at the same index as that item * @function Chart.Interaction.modes.index * @s
(chart, e, options, useFinalPosition)
| 267 | * @return {InteractionItem[]} - items that are found |
| 268 | */ |
| 269 | index(chart, e, options, useFinalPosition) { |
| 270 | const position = getRelativePosition(e, chart); |
| 271 | // Default axis for index mode is 'x' to match old behaviour |
| 272 | const axis = options.axis || 'x'; |
| 273 | const includeInvisible = options.includeInvisible || false; |
| 274 | const items = options.intersect |
| 275 | ? getIntersectItems(chart, position, axis, useFinalPosition, includeInvisible) |
| 276 | : getNearestItems(chart, position, axis, false, useFinalPosition, includeInvisible); |
| 277 | const elements = []; |
| 278 | |
| 279 | if (!items.length) { |
| 280 | return []; |
| 281 | } |
| 282 | |
| 283 | chart.getSortedVisibleDatasetMetas().forEach((meta) => { |
| 284 | const index = items[0].index; |
| 285 | const element = meta.data[index]; |
| 286 | |
| 287 | // don't count items that are skipped (null data) |
| 288 | if (element && !element.skip) { |
| 289 | elements.push({element, datasetIndex: meta.index, index}); |
| 290 | } |
| 291 | }); |
| 292 | |
| 293 | return elements; |
| 294 | }, |
| 295 | |
| 296 | /** |
| 297 | * Returns items in the same dataset. If the options.intersect parameter is true, we only return items if we intersect something |
nothing calls this directly
no test coverage detected