Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: return nearest non-null point on interaction when spanGaps=true #11986

Merged
merged 7 commits into from
Jan 3, 2025

Conversation

marisst
Copy link
Contributor

@marisst marisst commented Jan 2, 2025

Currently this configuration

{
    type: 'line',
    data: {
        labels: [1, 2, 3, 4, 5, 6, 7, 8, 9],
        datasets: [{
            label: "# of Votes",
            data: [12, 19, null, null, null, null, 5, 2, 3],
            spanGaps: true,
        }]
    },
    options: {
        interaction: {
            mode: 'nearest',
            axis: 'x',
            intersect: false
        }
    }
}

produces the following interaction - please pay attention to when and where the tooltip appears.

before.mov

Bug: No tooltip is shown while the mouse is between x: 3 and x: 6 despite spanGaps being true. This happens when chart contains null points.

This PR contains changes in binarySeach wrapper function in core.interaction.js fixing the error. It also contains 1 new test with 12 test cases in core.interaction.tests.js.

Now the above configuration results in:

after.mov

Issues fixed:

etimberg
etimberg previously approved these changes Jan 2, 2025
kurkle
kurkle previously approved these changes Jan 3, 2025
src/core/core.interaction.js Outdated Show resolved Hide resolved
test/specs/core.interaction.tests.js Outdated Show resolved Hide resolved
@LeeLenaleee LeeLenaleee added this to the Version 4.4.8 milestone Jan 3, 2025
LeeLenaleee
LeeLenaleee previously approved these changes Jan 3, 2025
@marisst marisst dismissed stale reviews from LeeLenaleee, kurkle, and etimberg via fe0cd3d January 3, 2025 14:23
etimberg
etimberg previously approved these changes Jan 3, 2025
LeeLenaleee
LeeLenaleee previously approved these changes Jan 3, 2025
@marisst marisst dismissed stale reviews from LeeLenaleee and etimberg via 7c20804 January 3, 2025 15:01
@marisst marisst requested a review from kurkle January 3, 2025 15:01
@etimberg etimberg merged commit a77a63b into chartjs:master Jan 3, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants