jerosoler / Drawflow

Simple flow library 🖥️🖱️
https://jerosoler.github.io/Drawflow/
MIT License
4.65k stars 722 forks source link

Grid Snap #129

Open dennisong45 opened 3 years ago

dennisong45 commented 3 years ago

Is it possible to have a grid snap layout? Thank you

jerosoler commented 3 years ago

Hello @dennisong45

It cannot be adjusted automatically.

It would have to be adjusted when moving a node or adding it.

You can correct the position with this example: Increase the position by +100.

    editor.on('nodeMoved', function(id) {
        // console.log("Node moved " + id);
        const module = editor.getModuleFromNodeId(id);
        const data = editor.getNodeFromId(id);
        const pos_x = data.pos_x;
        const pos_y = data.pos_y;

        // Fix position: // Your Logic Here. 
        editor.drawflow.drawflow[module].data[id].pos_x = pos_x + 100;
        editor.drawflow.drawflow[module].data[id].pos_y = pos_y + 100;
        document.getElementById(`node-${id}`).style.left = (pos_x + 100) + "px";
        document.getElementById(`node-${id}`).style.top = (pos_y + 100) + "px";
        editor.updateConnectionNodes(`node-${id}`);

    })

Jero

Co-Maheshh commented 1 year ago

Not worked for me. i want when i click on editor and moving that time multiple nodes are restrict to move. right now its moving so want to restrict moving multiple node.

Co-Maheshh commented 1 year ago

@jerosoler
can you please give sample example for how we can restrict moving multiple nodes at the same time.

Thanks in advance.