cytoscape.jsdagre

Cytoscape.js get node position from dagre layout


In order to make zigzag like edges I need to make some calculations and for that I need every node's position on the layout and I am having some trouble achieving that.

I am trying to get the node's position this way:

cy.$('#1891').position()

but no matter which id I use, I always get {x: 0, y: 0} values.

When I add an event like this:

cy.on('mouseover', 'node', function(evt){
    var node = evt.target;
    console.log(node.position());
});

I get every node's postion.

What would be the right way of getting every node's position from dagre layout?


Solution

  • I found the solution.

    It was a silly mistake by me. I was trying to get the node's position before the layout was applied. Putting the cy.$('#1891').position(); after the layout.run(); did the trick.