artus9033 / chartjs-plugin-dragdata

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

Feature request: 'round' option for individual x/y axis #99

Open ffongmdsp opened 2 years ago

ffongmdsp commented 2 years ago

Hello,

Currently there is 'round' option - it helps my use-case tremendously. On the other hand, the x and y axes require different precision. 0.1 for x and 0 for y. Now I would do a Math.round() on the y-axis value given by onDrag(). Therefore, I think it would be useful to be able to set 'round' value on individual axis.

chrispahm commented 1 year ago

Hey @ffongmdsp,

Thanks for raising an issue! Is there a particular reason why rounding the value in the onDrag callback wouldn't work for you? I'd argue this gives the greatest flexibility for all use cases, even if you require different rounding strategies for different datasets/indeces.

While the standard rounding option is frequently used, I guess this option would be used too seldom in order to justify the additional code that would need to be maintained in the long run. But maybe I'm missing something?

For the sake of completeness, I created a small fiddle incorporating a custom rounding logic in the onDrag callback just if anyone could use a demo of the functionality: https://jsfiddle.net/jhvp6fbk/1/

ffongmdsp commented 1 year ago

Thanks a lot for the effort to explain. For me it is a matter of code re-use and API design. The plugin has already implemented 'round' function, I would guess that it is be relatively trivial to separate them into round-x and round-y, similar to the option dragX and dragY.

There is no problem with doing the separate rounding at onDrag() callback, that is what I have been doing.