alyssaxuu / flowy

The minimal javascript library to create flowcharts ✨
MIT License
11.47k stars 998 forks source link

Return to previous position on snap. #72

Closed kurumbus closed 4 years ago

kurumbus commented 4 years ago

Hello! Thank you for a wonderful library.

So the issue for is that if you snap a block on some empty space it gets deleted. For us, the ideal would be to either rearrange it (as it currently is), but if someone snaps on an empty space - just return to the initial position. To be honest i kind of understand that it has something to do with release() or snapping() callbacks but don't know what exactly lol

I've read a couple of similar issues, but I can't understand what I should do. :-/

48 #32 perhaps #57

alyssaxuu commented 4 years ago

Yes, the idea is to use the method "on rearrange" to prevent the block from being deleted and instead go back to the previous position. Here's how you can do that:

function onRearrange(block, parent){
    // When a block is rearranged
    return true;
}
flowy(document.getElementById("canvas"), onGrab, onRelease, onSnap, onRearrange, spacing_x, spacing_y);