-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parent / child relation is not rendered when child is added before parent #302
Comments
Note: I tried reproducing this by modifying https://cytoscape.org/cytoscape.js-cola/demo-compound.html
renders identically to
|
hmm that's no good. I wonder if this is an issue with what we're syncing (i.e. python side) or with the rendering (typescript side). Can you try adding some parent relationships to this example: https://github.com/cytoscape/ipycytoscape/blob/master/examples/Text%20on%20node.ipynb because there we will have a signal as to whether data is syncing properly via the |
Thanks, Yes I will start debugging it. It seems to me that there is some kind of sync issue with fields inside data as in thats how I discovered that #306 did not do classes like other notebooks. Unlike the html callback notebook https://github.com/cytoscape/ipycytoscape/blob/master/examples/HTML%20interaction%20with%20graph.ipynb changing the class inside data did not trigger an update to the node style. |
I wonder if this is an issue with spectate or our usage of it. It sounds like you've run into other issues with syncing the data .And looking at out MutableDict ipycytoscape/ipycytoscape/cytoscape.py Lines 149 to 173 in 2ee745f
Spectate is what lets us sync mutable data structures, which traitlets does not normally do. it's defintiely a bit sparse compared to the most recent spectate + traitlets example: https://python-spectate.readthedocs.io/en/latest/usage/spectate-in-traitlets.html |
@ianhi thanks for the hint. I will do some digging once I have a bit of time unless you get there first :) |
can you try adding the following to the end your custom node init: self.send_state("data") |
trying to force a sync via this method: https://github.com/jupyter-widgets/ipywidgets/blob/11ade00777f1d27e2e1333694e7ae7b532ad791e/python/ipywidgets/ipywidgets/widgets/widget.py#L494-L501 |
Unfortunately that did not seem to resolve the issue. I will keep looking |
So... Apparently, somehow this is related to the position of the nodes in the list. If I change the code for adding new nodes to something like the following:
Then the 2nd example works, but the first one doesn't. What if we make some kind of sorting function for this? Might get really expensive though, to add nodes on the list, so if we go with this solution we have to think this through. Thanks a lot for the great bug report and for catching this one @jenshnielsen. |
@marimeireles Thanks thats interesting. I always assumed that this had something to do with the events not being triggered correctly on the ts/js side when inserting but your example clearly show that its not that but the order of the elements. |
Digging a bit further. If I log the value of the NodeModel inside addNodeModel the value of parent is undefined if If I add the node with the parent attribute before adding the parent node but has the correct value if I do it the other way around |
Ok so this is actually a limitation of the Cytoscape.js api. If one does
directly in js on a cytoscape object this will render correctly
I guess there are two ways this could be midigated in ipycytoscape |
also note that changing the parent property via data is not actually supported in cytoscape.js after the graph has been created https://js.cytoscape.org/#notation/compound-nodes |
Bug report
Bug summary
Rendering of parent child relationship depends on the order of nodes being added
Code for reproduction
Consider the following CustomNode class which sets an optional parent child relationship
If I create a graph manually adding first the parent and then the child
This correctly renders the parent child relation ship
However if I add the nodes in the reverse order:
The parent child relationship is not shown
Actual outcome
Parent child relationship is only shown when parent is added to the graph before child.
Expected outcome
Parent Child relationships is independent of the order of the nodes being added.
Version Info
import ipycytoscape; print(ipycytoscape.__version__)
) : 1.3.2The text was updated successfully, but these errors were encountered: