cytoscape / ipycytoscape

A Cytoscape Jupyter widget
https://ipycytoscape.readthedocs.io/en/master/
BSD 3-Clause "New" or "Revised" License
261 stars 62 forks source link

Positioning of nodes/edges doesn't work #254

Open marimeireles opened 3 years ago

marimeireles commented 3 years ago

You can create a Node instance and try to set a position with:

node1.position = {"x":1, "y":2000}

Or do something completely else, the node will appear in the same place in the screen.

I have to read more into it but I wonder if it's because we're not interacting with Phosphor correctly. I don't think the problem is related with the spectate problem of deep objects like dictionaries not being sync. because we have other examples in the code like the data attr. that's also a dict, but it's working fine.

This bug was first issued by @DnlRKorn on the QS channel. Thanks @DnlRKorn! :)

marimeireles commented 3 years ago

I have to jump out for now and will be out for the wknd, but hopefully I can pick this up again a bit on Monday!

martinRenou commented 3 years ago

You might want to check if this code is executed properly with a console.log? https://github.com/QuantStack/ipycytoscape/blob/master/src/graph.ts#L176

fpom commented 1 year ago

I managed to assign positions to nodes proceeding as follows:

cy = CytoscapeWidget()
# ... populate your graph
pos = {...} # map nodes id to pairs of floats.
for node in cy.graph.nodes:
    x, y = pos[node.data["id"]]
    node.position = {"x" : x, "y" : y}
cy.relayout()