Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

getElementsAtEventForMode does not return elements with null data

Open halvtomat opened this issue 1 year ago • 4 comments

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

 if (!element.skip) {
        handler(element, index, j);
      }

src/controllers/controller.line.js


      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

halvtomat avatar Feb 29 '24 10:02 halvtomat

You linked the template reproducible sample, can you update it to your correct reproducible sample?

LeeLenaleee avatar Feb 29 '24 10:02 LeeLenaleee

You linked the template reproducible sample, can you update it to your correct reproducible sample?

Sorry, apparently I didn't save my example, fixing ASAP

halvtomat avatar Feb 29 '24 10:02 halvtomat

@LeeLenaleee Updated now!

halvtomat avatar Feb 29 '24 10:02 halvtomat

Any update on this issue? @LeeLenaleee

halvtomat avatar May 22 '24 12:05 halvtomat