Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group nodes #872

Open
sukhwinderkaur1389 opened this issue Jun 5, 2024 · 13 comments
Open

Group nodes #872

sukhwinderkaur1389 opened this issue Jun 5, 2024 · 13 comments

Comments

@sukhwinderkaur1389
Copy link

Hi,
I have integrate group nodes code from - #423

But my nodes inside the container not moving with container.

image

Can you please help whats the issue?

@sukhwinderkaur1389
Copy link
Author

@jerosoler - Can you please update on it?

@sukhwinderkaur1389
Copy link
Author

@jerosoler - Can you please update on it?

PLease update

@jerosoler
Copy link
Owner

Updated:

With the information provided, we cannot help you.
Prepare a codepen with your problem. Where show your code.

@sukhwinderkaur1389
Copy link
Author

Updated:

With the information provided, we cannot help you. Prepare a codepen with your problem. Where show your code.

editor.addNode('GROUP', 0, 0, 1200, 100, 'GROUP', { elements: []}, ); editor.addNode('GROUP', 0, 0, 0, 100, 'GROUP', { elements: []}, );

let dragElementHover = null;
let last_x = 0;
let last_y = 0;
editor.on("mouseMove", ({x,y}) => {
    if(editor.node_selected && editor.drag && editor.node_selected.classList[1] !== "GROUP") {
        const eles = document.elementsFromPoint(x,y);
        const ele = eles.filter( ele => ele.classList[1] === "GROUP");
        if(ele.length > 0) {
            dragElementHover = ele[0];
            dragElementHover.classList.add("hover-drop");
        } else {
            if(dragElementHover != null) {
                dragElementHover.classList.remove("hover-drop");
                dragElementHover = null;
            }
        }
    } else if(editor.node_selected && editor.drag && editor.node_selected.classList[1] == "GROUP") {
        const dragNode = editor.node_selected.id.slice(5);
        const dragNodeInfo = editor.getNodeFromId(dragNode);
        const elements = dragNodeInfo.data.elements;
        elements.forEach(eleN => {

            const node = document.getElementById(`node-${eleN}`);
            var xnew = (last_x - x) * editor.precanvas.clientWidth / (editor.precanvas.clientWidth * editor.zoom);
            var ynew = (last_y - y) * editor.precanvas.clientHeight / (editor.precanvas.clientHeight * editor.zoom);

            node.style.top = (node.offsetTop - ynew) + "px";
            node.style.left = (node.offsetLeft - xnew) + "px";

            editor.drawflow.drawflow[editor.module].data[eleN].pos_x = (node.offsetLeft - xnew);
            editor.drawflow.drawflow[editor.module].data[eleN].pos_y = (node.offsetTop - ynew);
            editor.updateConnectionNodes(`node-${eleN}`);

        });
    }
    last_x = x;
    last_y = y;
})

editor.on("nodeMoved", (id) => {
    const dragNode = id;
    if(dragElementHover !== null) {
        const dropNode = dragElementHover.id.slice(5);
        if(dragNode !== dropNode) {
            removeOfGroupNode(dragNode);
            dragElementHover.classList.remove("hover-drop");
            const dropNodeInfo = editor.getNodeFromId(dropNode);
            const dropNodeInfoData = dropNodeInfo.data;
            if(dropNodeInfoData.elements.indexOf(dragNode) === -1) {
                dropNodeInfoData.elements.push(dragNode);
                editor.updateNodeDataFromId(dropNode, dropNodeInfoData);
            }
        }
        dragElementHover = null;
    } else {
        removeOfGroupNode(dragNode);
    }
})

editor.on("nodeRemoved", (id) => {
    removeOfGroupNode(id);
});

function removeOfGroupNode(id) {
    Object.keys(editor.drawflow.drawflow[editor.module].data).forEach(ele => {
        if(editor.drawflow.drawflow[editor.module].data[ele].class === "GROUP") {
            const findIndex = editor.drawflow.drawflow[editor.module].data[ele].data.elements.indexOf(id);
            if(findIndex !== -1) {
                editor.drawflow.drawflow[editor.module].data[ele].data.elements.splice(findIndex, 1);
            }
        }
   })
}

@sukhwinderkaur1389
Copy link
Author

Updated:
With the information provided, we cannot help you. Prepare a codepen with your problem. Where show your code.

editor.addNode('GROUP', 0, 0, 1200, 100, 'GROUP', { elements: []}, ); editor.addNode('GROUP', 0, 0, 0, 100, 'GROUP', { elements: []}, );

let dragElementHover = null;
let last_x = 0;
let last_y = 0;
editor.on("mouseMove", ({x,y}) => {
    if(editor.node_selected && editor.drag && editor.node_selected.classList[1] !== "GROUP") {
        const eles = document.elementsFromPoint(x,y);
        const ele = eles.filter( ele => ele.classList[1] === "GROUP");
        if(ele.length > 0) {
            dragElementHover = ele[0];
            dragElementHover.classList.add("hover-drop");
        } else {
            if(dragElementHover != null) {
                dragElementHover.classList.remove("hover-drop");
                dragElementHover = null;
            }
        }
    } else if(editor.node_selected && editor.drag && editor.node_selected.classList[1] == "GROUP") {
        const dragNode = editor.node_selected.id.slice(5);
        const dragNodeInfo = editor.getNodeFromId(dragNode);
        const elements = dragNodeInfo.data.elements;
        elements.forEach(eleN => {

            const node = document.getElementById(`node-${eleN}`);
            var xnew = (last_x - x) * editor.precanvas.clientWidth / (editor.precanvas.clientWidth * editor.zoom);
            var ynew = (last_y - y) * editor.precanvas.clientHeight / (editor.precanvas.clientHeight * editor.zoom);

            node.style.top = (node.offsetTop - ynew) + "px";
            node.style.left = (node.offsetLeft - xnew) + "px";

            editor.drawflow.drawflow[editor.module].data[eleN].pos_x = (node.offsetLeft - xnew);
            editor.drawflow.drawflow[editor.module].data[eleN].pos_y = (node.offsetTop - ynew);
            editor.updateConnectionNodes(`node-${eleN}`);

        });
    }
    last_x = x;
    last_y = y;
})

editor.on("nodeMoved", (id) => {
    const dragNode = id;
    if(dragElementHover !== null) {
        const dropNode = dragElementHover.id.slice(5);
        if(dragNode !== dropNode) {
            removeOfGroupNode(dragNode);
            dragElementHover.classList.remove("hover-drop");
            const dropNodeInfo = editor.getNodeFromId(dropNode);
            const dropNodeInfoData = dropNodeInfo.data;
            if(dropNodeInfoData.elements.indexOf(dragNode) === -1) {
                dropNodeInfoData.elements.push(dragNode);
                editor.updateNodeDataFromId(dropNode, dropNodeInfoData);
            }
        }
        dragElementHover = null;
    } else {
        removeOfGroupNode(dragNode);
    }
})

editor.on("nodeRemoved", (id) => {
    removeOfGroupNode(id);
});

function removeOfGroupNode(id) {
    Object.keys(editor.drawflow.drawflow[editor.module].data).forEach(ele => {
        if(editor.drawflow.drawflow[editor.module].data[ele].class === "GROUP") {
            const findIndex = editor.drawflow.drawflow[editor.module].data[ele].data.elements.indexOf(id);
            if(findIndex !== -1) {
                editor.drawflow.drawflow[editor.module].data[ele].data.elements.splice(findIndex, 1);
            }
        }
   })
}

@jerosoler - Please update

@jerosoler
Copy link
Owner

Not a codepen

@sukhwinderkaur1389
Copy link
Author

Not a codepen

I have used all code from #423

Its here -https://codepen.io/sukhwinder-kaur/pen/MWdvMXy

But its not fully working here

@sukhwinderkaur1389
Copy link
Author

Not a codepen

I have used all code from #423

Its here -https://codepen.io/sukhwinder-kaur/pen/MWdvMXy

But its not fully working here

Please let me know which part of code you needed, I will share

@sukhwinderkaur1389
Copy link
Author

Not a codepen

I have used all code from #423
Its here -https://codepen.io/sukhwinder-kaur/pen/MWdvMXy
But its not fully working here

Please let me know which part of code you needed, I will share

I am able to resolve this issue.

Can you please help if we can add group container ID to the nodes added inside the container???

@sukhwinderkaur1389
Copy link
Author

Not a codepen

I have used all code from #423
Its here -https://codepen.io/sukhwinder-kaur/pen/MWdvMXy
But its not fully working here

Please let me know which part of code you needed, I will share

I am able to resolve this issue.

Can you please help if we can add group container ID to the nodes added inside the container???

### On resize these are not moving

image

@sukhwinderkaur1389
Copy link
Author

Not a codepen

I have used all code from #423
Its here -https://codepen.io/sukhwinder-kaur/pen/MWdvMXy
But its not fully working here

Please let me know which part of code you needed, I will share

I am able to resolve this issue.
Can you please help if we can add group container ID to the nodes added inside the container???

### On resize these are not moving

image

@jerosoler - Can you please update on it??

@sukhwinderkaur1389
Copy link
Author

@jerosoler - after increase height of this container, height not saving in DB or exporting

@sukhwinderkaur1389
Copy link
Author

@jerosoler - after increase height of this container, height not saving in DB or exporting

@jerosoler @marclaporte @timgates42 - Can you please help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants