-
Notifications
You must be signed in to change notification settings - Fork 38
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
How to save collapsed status of nodes in json data? #38
Comments
For now, you could use the data('collapsedChildren') attribute of the element for that. It stores the children of this element, when it is collapsed. So if yourElement.data('collapsedChildren') is defined and contains things, then yourElement is collapsed. |
Thank you for your reply. I wonder that json like |
What is saved inside collapsedChildren is the entire cytoscape element. With all the cytoscape properties, as is. So I'm not sure that what you propose would work... |
I see. It looks reasonable that I would load graph json data containing collapsed marked element data, then after loading graph json data, |
And when saving data, the mark meaning collapsed node should be updated and the elements are exported with the marks. |
I'm also interested in this feature, however I would like to define upfront which compounds are collapsed/expanded (i.e. directly from the JSON source). |
@hotpeperoncino one way of saving collapsed nodes is the following. First you need to get all collapsed children in the graph. In v3.0.11, you can use var allNodes = cy.nodes();
allNodes = allNodes.union(api.getAllCollapsedChildrenRecursively()); Now you have all the nodes in the graph. When saving the nodes, you need to save the collapse state of nodes too. Just saving the state of collapsed nodes is sufficient (no need to save the state for all nodes). You can get the nodes which are collapsed as follows and set their state: var collapsedNodes = allNodes.filter(".cy-expand-collapse-collapsed-node");
collapsedNodes.data("collapse", true); // state stored in collapsed field After saving nodes with collapsed state, it is easy to get them back: load it as usual, after loading, collapse the nodes which were collapsed before. Let's say, you store the status in a data field called // collapse nodes
if (cy.nodes("[collapse]").length > 0 ){
cy.expandCollapse('get').collapse(cy.nodes("[collapse]", {layoutBy: null}));
} |
@stklik First define the compounds which are collapsed by adding an attribute to their data field - for example // collapse nodes
if (cy.nodes("[collapse]").length > 0 ){ // assuming collapse state is stored in collapse data field
cy.expandCollapse('get').collapse(cy.nodes("[collapse]", {layoutBy: null}));
} |
As well you broke a core cy.json() method, now it produces not JSON-serializable object since it has circular links. |
I have created a workaround which allows for collapsed graphs to be stringified and saved to backend and restored thus avoiding the dreaded cyclic object issue. I am uncertain if there is a more elegant way to do this? workaround here if anyone is interested.. Also thanks alot for this superb cytoscape extension! |
I made a different workaround inspired by bentole's workaround. Before any function that could get messed up because of collapsed nodes, I uncollapse them by calllng collapseFix on those nodes, and afterwards I call collapseFixRestore. |
@itf @bentole @hotpeperoncino Now unstable version has |
I'd like to save the node status whether the node is collapsed or not in json data, and then restore it to the visualized graph with keeping the collapsed status. When using some libraries "collapsed" member in json data indicates the collapsed status of each nodes.
For example, the collapsed status can be stored as other json data, then after loading the elements json, according to the collapsed status json, the collapsed function can be applied to the graph.
What method is supposed as the regular method in this library?
The text was updated successfully, but these errors were encountered: