cytoscape / ipycytoscape

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

Positioning nodes individually with position:{'x':10,'y':20} influenced by layout? #216

Closed joseberlines closed 3 years ago

joseberlines commented 3 years ago

I have the following data:

`nodes4 = [{'id': 'UNO', 'label': '0.0-0.0','position_x': 0.0, 'position_y': 0.0}, {'id': 'DOS', 'label': '100.0-50.0', 'position_x': 100.0, 'position_y': 50.0}, {'id': 'TRES', 'label': '200.0-100.0', 'position_x': 200.0, 'position_y': 100.0}, {'id': 'CUATRO', 'label': '300.0-150.0', 'position_x': 300.0, 'position_y': 150.0}, {'id': 'CINCO', 'label': '600.0-150.0', 'position_x': 600.0, 'position_y': 150.0}]

edges4 = [{'id': 'line1', 'source': 'UNO', 'target': 'DOS', 'label': 'line1'}, {'id': 'line2', 'source': 'UNO', 'target': 'TRES', 'label':'line2'}, {'id': 'line3', 'source': 'DOS', 'target': 'TRES', 'label': 'line3'}, {'id': 'line4', 'source': 'TRES', 'target': 'CUATRO', 'label': 'line4'}, {'id': 'line5', 'source': 'CUATRO', 'target': 'CINCO', 'label': 'line5'} ] `

generating the following graph:

[Node(data={'id': 'UNO', 'label': '0.0-0.0', 'classes': 'no_class'}, position={'x': 0.0, 'y': 0.0}), Node(data={'id': 'DOS', 'label': '100.0-50.0', 'classes': 'no_class'}, position={'x': 100.0, 'y': 50.0}), Node(data={'id': 'TRES', 'label': '200.0-100.0', 'classes': 'no_class'}, position={'x': 200.0, 'y': 100.0}), Node(data={'id': 'CUATRO', 'label': '300.0-150.0', 'classes': 'no_class'}, position={'x': 300.0, 'y': 150.0}), Node(data={'id': 'CINCO', 'label': '600.0-150.0', 'classes': 'no_class'}, position={'x': 600.0, 'y': 150.0})]

[Edge(classes='no_class', data={'id': 'line1', 'source': 'UNO', 'target': 'DOS'}, position={}), Edge(classes='no_class', data={'id': 'line2', 'source': 'UNO', 'target': 'TRES'}, position={}), Edge(classes='no_class', data={'id': 'line3', 'source': 'DOS', 'target': 'TRES'}, position={}), Edge(classes='no_class', data={'id': 'line4', 'source': 'TRES', 'target': 'CUATRO'}, position={}), Edge(classes='no_class', data={'id': 'line5', 'source': 'CUATRO', 'target': 'CINCO'}, position={})]

resulting in:

Screenshot 2020-12-23 at 20 42 19

the position of the nodes are not displayed according to the position coordinates.

I also observe that:

G.get_layout()

gives: {'name': 'cola'}

But I never declared layout = cola. Is cola a default value? in https://js.cytoscape.org/#notation/position it looks like the position is taken by the nodes only when there is no layout specified.

is that right? Should I (somehow) delete the cola layout?

TK-21st commented 3 years ago

Stumbled upon the same issue and realized I should call G.set_layout(name='preset') to force position.

See cytoscope.js layout documentation

marimeireles commented 3 years ago

I'll close this as resolved. Thank you for jumping in @TK-21st ! :cherry_blossom: