I would like to read node/edges information for a graph (sigma.js) from a JSON variable. While it's quite easy to use an external JSON file as input via a JSON parser, I could not find a way to use a JSON object directly defined in the JavaScript code. There seems to exist a method called 'read', but I could not get it to work (Source: https://github.com/jacomyal/sigma.js/wiki/Graph-API). Could someone give me a hint?
This is what I would like to have:
data = {
"nodes": [
{
"id": "n0",
"label": "A node",
"x": 0,
"y": 0,
"size": 3
},
{
"id": "n1",
"label": "Another node",
"x": 3,
"y": 1,
"size": 2
},
],
"edges": [
{
"id": "e0",
"source": "n0",
"target": "n1"
},
]
}
sigma.parsers.json( data , {
container: 'container',
settings: {
defaultNodeColor: '#ec5148'
}
});
Thank you, cheers, Michael
Add your data as follows:
s = new sigma({
graph: data,
container: 'container',
settings: {
defaultNodeColor: '#ec5148'
}
});
See also: json-is-not-read-by-sigma-js
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With