cytoscape / ipycytoscape

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

rework classes in from scratch examples match other examples #306

Closed jenshnielsen closed 2 years ago

jenshnielsen commented 2 years ago

The from scratch example uses classes embedded in the data dict rather that as a top level attribute. I found that a bit confusing since Node.classes ends up being empty (and the classes has to be found within the data dict) Here I suggest reworking this and the matching style to use classes as a top level key/value pair.

Chaning the classes value within the data dict does not seem to trigger an update to the graph but I guess that is a separate issue.

github-actions[bot] commented 2 years ago

Binder :point_left: Launch a binder notebook on branch _jenshnielsen/ipycytoscape/from_scratch_unifyclasses

ianhi commented 2 years ago

thanks!

marimeireles commented 2 years ago

Hi, sorry I missed this and the question out of context: Is this attending to the issue that our docs are not up to date with the API? Or not related at all? Thank you for the contribution! :)

jenshnielsen commented 2 years ago

I am honerstly not sure since I have not fully kept up to date with the changes in the API. This change was motivated by me noticing that this notebook defined a node in json as

{"data": {"id": "BER", "label": "HBf BER", "classes": "east"}}

where as the other examples (both in ipycytoscape and in the cytoscape.js docs) defined it as

{"data": {"id": "BER", "label": "HBf BER"} "classes": "east"}

The first form puts the classes inside the data dict of the node where as the second example puts it in the classes attribute on the node it self. This then in turn has implications for how the css to style classes should be written. And for some reason I cannot get a change to the classes in the former example to trigger a change in style. E.g. if I did cytoscapeobj.graph.nodes[0].data['classes'] = "west" that would not change the color of a "east" class. But doing but doing cytoscapeobj.graph.nodes[0].classes = "west" works as expected.