chartjs / Chart.js

Simple HTML5 Charts using the <canvas> tag
https://www.chartjs.org/
MIT License
63.92k stars 11.89k forks source link

getElementsAtEventForMode does not return elements with null data #11693

Open halvtomat opened 4 months ago

halvtomat commented 4 months ago

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

LeeLenaleee commented 4 months ago

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

halvtomat commented 4 months ago

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 commented 4 months ago

@LeeLenaleee Updated now!

halvtomat commented 1 month ago

Any update on this issue? @LeeLenaleee