fkling / JSNetworkX

Build, process and analyze graphs in JavaScript (port of NetworkX)
https://felix-kling.de/jsnetworkx/
Other
761 stars 184 forks source link

Unclear if can create graph from JSON #12

Closed sholsapp closed 11 years ago

sholsapp commented 11 years ago

I have JSON prepared from the Python version of networkx, and it's unclear if I can create a jsnetworkx object from this JSON data at https://github.com/fkling/JSNetworkX/blob/master/jsnx/classes/graph.js#L45.

Is this possible?

fkling commented 11 years ago

You cannot use JSON directly, you have to pass an array or object of edges (i.e. you have to parse the JSON first). It basically accepts the same data structures as the Python version. For example:

jsnx.Graph([[1,2], [2,3]]);
// or
jsnx.Graph({2: [1,3]});
sholsapp commented 11 years ago

Okay, thanks. It's easy enough to convert the JSON object into this format.