Skip to content
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

cy.json() and ele.json() generate circular structures when compound nodes are present #1667

Closed
fedarko opened this issue Jan 5, 2017 · 3 comments

Comments

@fedarko
Copy link

fedarko commented Jan 5, 2017

I'm looking into exporting the JSON for a graph using Cytoscape.js to the desktop Cytoscape application. It seems that both cy.json() (when at least one compound node is present within the graph) and ele.json() (where ele refers to a compound node) generate JSON objects that cannot be passed into JSON.stringify(), and therefore can't (as far as I can tell) be exported to the desktop Cytoscape application.

When compound nodes are not in the graph, the JSON generated is not circular (calling stringify on it works). I've tested this phenomenon by opening graphs with compound nodes, calling JSON.stringify(cy.json()); from my browser's console, and observing an Uncaught TypeError: Converting circular structure to JSON error. Calling cy.remove() on all of the compound nodes in the graph results in the stringify call working without error.

For reference, I'm running Chromium 55.0.2883.75 as my browser, on Debian 8.6.

@maxkfranz
Copy link
Member

maxkfranz commented Jan 5, 2017

I just confirmed that cy.json() and ele.json() are serialisable. There are no circular references when I tried.

You may have circular references in what you're putting in .data(). You're only allowed to put plain JSON data in .data(), as the docs say. Complex objects and other temp data goes in .scratch(). Please confirm your data is correct, and provide an example graph JSON file that illustrates the bug.

@fedarko
Copy link
Author

fedarko commented Jan 5, 2017

My apologies—this was my fault. I was storing collections of certain elements within the .data() fields for compound nodes.

I did not notice anywhere in the documentation that certain types of data could not be stored in .data(), although I see now that the documentation does mention that non-JSON data can be stored in .scratch(). I'm sorry for the confusion.

@fedarko fedarko closed this as completed Jan 5, 2017
@maxkfranz
Copy link
Member

The docs are pretty long. It should be mentioned in more sections in the docs if it's not clear: #1670

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants