artus9033 / chartjs-plugin-dragdata

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

scatter plot data points disappear at 0 #39

Closed AzNdevil closed 4 years ago

AzNdevil commented 4 years ago

hi, love your plugin, its the only one that can do x and y axis dragging with chartjs

anyways, i am having issues with the datapoint disappearing if y axis is dragged around/below 0 datapoint is will also be stuck to x axis at 0 if it is dragged around/over 0 on the x axis

however, if i force and limit the x or y point to be at 0.1, everything is fine

i have tried a few browsers and confirmed it is not browser related

mind having a look and see if its an error on my side or a bug in the plugin? attached html to reproduce issue, thanks

test.zip

chrispahm commented 4 years ago

Hi, thanks for raising an issue!

I just checked and the issue you are raising was initially fixed by @wladimiiir in his PR https://github.com/chrispahm/chartjs-plugin-dragdata/pull/35. However, due to myself being inconsiderate in follow-up commits I removed his fix on accident. Sorry @wladimiiir and @AzNdevil 😢

You can see your use case working when using his branch: Fiddle

I won't be getting to update the master up until the coming weeks. But this issue again showed that the amount of features in this plugin, together with the varieties of charts supported is definitely in need of a set of test to ensure it's still working for all use cases when an update is made. I opened a new issue https://github.com/chrispahm/chartjs-plugin-dragdata/issues/40 discussing these tests, please feel free to have a look and send a PR 😄

AzNdevil commented 4 years ago

thanks a lot for your help! appreciate it unfortunately i am not skilled enough to help fix bugs but i do play around with what i have created

the fix worked partially, datapoint doesnt disappear now but with this version there seems to be a different issue

i am trying to lock certain datapoints so they cant be dragged around so i added some code to onDrag() to return false on index 0

steps to reproduce

  1. drag on the 0,0 point, it doesnt move on screen
  2. drag any other point, 0,0 moves to where i last dragged it

https://jsfiddle.net/cju16esa/1/

chrispahm commented 4 years ago

Alright,

I took the time to have a more detailed look into your issue once again. Indeed, the first time I had a look I didn't really check the source code that well, and now realized that you returned false to the onDrag callback function. The readme states: "To avoid dragging specific data points inside a draggable dataset, you can return false to function onDragStart." Keep in mind that the onDragStart function receives two arguments, where the second argument is not the index but rather the element that was dragged. I updated your fiddle to return false in the onDragStart function, and used the current minified plugin from the master branch. At least I can see no problems now, please let me know if there is still any trouble.

https://jsfiddle.net/bt5d4p97/2/

chrispahm commented 4 years ago

Will close for now, please re-open if the issue persists.