highcharts / draggable-points

MIT License
32 stars 34 forks source link

drop to nearest integer #73

Closed wghglory closed 6 years ago

wghglory commented 6 years ago

Is it possible to drop point to nearest integer? For example, if user drops point at Y = 1.2, I want the final point to be placed at 1.

TorsteinHonsi commented 6 years ago

Yes, you can modify the final value in the drop event: http://jsfiddle.net/highcharts/AyUbx/3783/

wghglory commented 6 years ago

Thanks @TorsteinHonsi ! But this doesn't really solve my problem. If yAxis value ranges from 0 to 5, and when I drop any point to 1.8, that point won't slide to 2. Current solution just reads the value but it doesn't apply updated integer (2 in this case) to the chart. Please review http://jsfiddle.net/AyUbx/3785/.

TorsteinHonsi commented 6 years ago

Okay, apparently the drop event is called after the point is actually updated. An enhancement of the current logic would be to do the update in the event's defaultFunction, so that we were able to modify the new position and also to cancel the drop.

Anyway, here's how you can update the point with the modified value: http://jsfiddle.net/highcharts/AyUbx/3786/

wghglory commented 6 years ago

@TorsteinHonsi This is exactly what I need. I searched a lot but haven't found any solution. Thanks so much!