0

I want to remove all connected edges to the source from parent, so is there any function that can remove all edges connected from parent to child referring by the cell.

How to get parent cell from child cell in mxgraph.

I am trying to achieve drag and drop using connectors and am i correct?

mxConnectionHandler.prototype.connect = function(source, target, evt, dropTarget){
   // First I'll connect the target and source edges
   // Later I'll remove all connected edges from parent to source
}

source.parent.getValue('value') is undefined now.

I need parent references so that it helps in saving to database as well.

I can see this: mxCell.prototype.getParent = function() from documentation, but how to use this? Please demonstrate with a small example.

Tried using cell.getParent()

Also: graph.model.getParent(cell)

But it returns: mxCell {value: undefined, geometry: undefined, style: undefined, parent: mxCell, id: "1", …}

And its value as undefined. What am I doing wrong or how to perfectly get its parent cell reference?

The only way I got this worked by appending parentid to cellid. And use array split and get cell from its id, but I am not happy doing this as I will have a lot of work when multiple edges are connected. So, I need the simplest solution.

halfer
  • 19,824
  • 17
  • 99
  • 186
Mithun Shreevatsa
  • 3,588
  • 9
  • 50
  • 95

2 Answers2

1

Firstly, lets consider the following two:

1) Child of a cell:

A cell that points to the cell we are interested for.

Code

function getChildrenOfCell(cell){
if(cell != undefined){
    let children = [];
    let edges = cell.edges;
    if(edges != null){
        for(let i = 0; i < edges.length; i++){
            if(edges[i].target.value == cell.value){
                let cellCopy = edges[i].source.clone();
                children.push(cellCopy);
            }
        }
    }
    return children;
}
else{
    return [];
}
}

2) Parent of a cell:

A cell that the cell we are interested for points to.

Code

function getParentsOfCell(cell){
if(cell != undefined){
    let parents = [];
    let edges = cell.edges;
    if(edges != null){
        for(let i = 0; i < edges.length; i++){
            if(edges[i].source.value == cell.value){
                let cellCopy;
                if(!parents.includes(edges[i].target)){
                    cellCopy = edges[i].target
                }
                parents.push(cellCopy);
            }
        }
    }
    return parents;
}
else{
    return [];
}
}
NickAth
  • 1,089
  • 1
  • 14
  • 35
0

Gave up the thought of debugging under: graph.model.getParent(cell)

The parent refers to the region and its shared with all the vertexes. Hence, came across the parent cell reference with the help of: cell.edges[0].source for single edge connection, if there are multiple edges connected from different parents, it should be cell.edges[...n].source upto you how you want to address them.

Mithun Shreevatsa
  • 3,588
  • 9
  • 50
  • 95