artus9033 / chartjs-plugin-dragdata

Draggable data points plugin for Chart.js
MIT License
261 stars 55 forks source link

Request / Drag nearest point #32

Closed Shakarhaba closed 4 years ago

Shakarhaba commented 5 years ago

As you might know, we can set the mode 'nearest' to trigger the hover action of the points and the tooltips.

options = {
    hover: {
        mode: 'nearest',
        intersect: false
    },
    tooltips: {
        mode: 'nearest',
        intersect: false
    }
};

It would be perfect that the drag action would work once the point is activated with the 'nearest' mode instead of actually needing to hover over the point.

Thank you

chrispahm commented 5 years ago

Hey three, I think that would be awesome! However, I didn't have the time to think about what would be the best way to achieve this. If you got an idea it would be highly appreciated. Best Christoph

velthune commented 4 years ago

Hi @Shakarhaba, I've forked the project and added the feature, if you want to try check it out!

You can add this code on chart options prop:

dragOptions: {
    magnet: {
        to: Math.round
    }
}

I've tested on linear chart only, so I don't know the behaviour on a pie chart for instance.

chrispahm commented 4 years ago

Thanks a lot @velthune for the great implementation ❤️ I hope this is what @Shakarhaba was looking for, in any way it's a great addition. Will close this for now, please re-open if this doesn't answer the issue.