chartjs / chartjs/Chart.js

getElementsAtEventForMode does not return elements with null data

Open
#11,693 4 comments 1 reaction 0 assignees View on GitHub
type: bug
Dominant language
JavaScript
Stars
67.7k
Forks
11.9k
Avg merge
7h 39m
Merged PRs (30d)
5

Description

### Expected behavior

I expect the method to return elements at the event position regardless of the values in the data. (Even with includeInvisible = true)

I need the elements to sync a crosshair in other graphs based on the cursor location in this graph so whatever the element data values are is not relevant for my use case.

I understand that this might be expected or desired behavior in all cases but it should at least be optional.

The problem stems from these 2 code snippets in the following files.

`core/core.interaction.js`
```typescript
if (!element.skip) {
handler(element, index, j);
}
```

`src/controllers/controller.line.js`
```typescript

const parsed = this.getParsed(i);
const nullData = isNullOrUndef(parsed[vAxis]);
const iPixel = properties[iAxis] = iScale.getPixelForValue(parsed[iAxis], i);
const vPixel = properties[vAxis] = reset || nullData ? vScale.getBasePixel() : vScale.getPixelForValue(_stacked ? this.applyStack(vScale, parsed, _stacked) : parsed[vAxis], i);

properties.skip = isNaN(iPixel) || isNaN(vPixel) || nullData;
```

### Current behavior

The method filteres out elements that are null from the results.

### Reproducible sample

https://codepen.io/halvtomat/pen/vYMYyMR

### Optional extra steps/info to reproduce

Check console for elements at mouse position, drag the mouse over the area with null points, console should be filled with `ELEMENTS []`

### Possible solution

_No response_

### Context

_No response_

### chart.js version

v4.2.1

### Browser name and version

_No response_

### Link to your project

_No response_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.