Cytoscape.js get node position from dagre layout

2.7k Views Asked by At

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?

1

There are 1 best solutions below

0
On BEST ANSWER

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.