Add granular change to style so user doesn't have to repeat the content of style every time they want to update it
See original GitHub issueThe issue: every time style
is updated the user needs to copy the old style and add the new parts to it if they want to include something new. E.g: if you have a style set on your graph and now you want to add new commands to this style, instead of simply calling the set_style
method with your new commands, you need to copy all the style content of your graph + the new commands.
See 1, https://github.com/cytoscape/ipycytoscape/issues/270, https://github.com/cytoscape/ipycytoscape/issues/197.
Explanation: This happens because cytoscape.js, the library which ipycytoscape draws from, need to have the following style configuration to show up arrows:
{
"selector": "edge.directed",
"style": {
"curve-style": "bezier",
"target-arrow-shape": "triangle",
"target-arrow-color": "#9dbaea",
},
},
(Of course you can change the shape and color of the arrow, but it’s necessary to specify these three attrs in order to see them).
The problem here is that because of traitlets implementation (the library in which Jupyter lab depends on to sync the backend with the frontend attrs) doesn’t offer support to deep objects like lists or dictionaries. In other words, it’s only syncing simple objects like ints and strings automatically.
Fortunately, I was able to overcome this issue in ipycytoscape using a library called spectate. However, spectate doesn’t seem to be able to sync nested deep objects, aka, a dict inside a dict as we have when creating styles
.
One way to fix it: creating an API like this. Positive: seems like it will work Negative: too much code to write, very different from current API, users will have to change their code
Another way to fix it: make the MutableDict
work with this.
Positive: less code, more elegant solution, minimal changes to current API. users will also have to change their code, but just by adding one word.
Negative: I spent some time looking into it and couldn’t make it work. Not sure why.
Thinking it further, ideally I think we would have both solutions as we strive to keep cytoscape.js and ipycy as close as possible API wise.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6
Top GitHub Comments
Okay! Earlier today I got the answer! It’s pretty simple: We just have to adapt the deepcopy code from
set_layout
. Just have to take care to not overwritekeys
and to keep thecytoscape.style
object as aMutableDict
. I’m not sure when I’ll be able to implement it cause I want to work on other things now, so if anyone feels like it, please feel free. I’ll try to do it some time this week!This can be done in many parts. One attribute you add will already help! 😉