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

Labels in JSON #72

Open
mgarf opened this issue Jan 30, 2015 · 2 comments
Open

Labels in JSON #72

mgarf opened this issue Jan 30, 2015 · 2 comments

Comments

@mgarf
Copy link

mgarf commented Jan 30, 2015

Hi,

I am currently using this to build out a visualization of my create your own adventure game. Currently I have a script that scans and pushes the lvl identifier into the node and edge arrays with no problem. I noticed in other examples not using JSON you are able to provide an alternate label to the node identifier. Is that possible to do in JSON?

like what is done here:

var fir = graph.newNode({label: 'Sicilian Fir'});

but with JSON.

I hope I am posting in the right place.

@jorgenskogmo
Copy link

+1 for this one!
The springyui renderer (at line 327) seems to support a "data" property for the nodes, but how do we provide this (with JSON).

@dhotson
Copy link
Owner

dhotson commented Feb 20, 2015

Heya,

Yep, this is possible.

The object passed at node creation is accessible as the node's data property.

e.g.

var node = graph.newNode({ xyz: 42 });

// You can assign a label manually like this:
node.data.label = 'Hello';

// Or access a node's properties..
console.log(node.data.xyz); // => 42

Also, depending on the format of your data, if it's a JSON string you'll need to parse it first:

node.data = JSON.parse('{"label": "Hello"}')

Does that answer your question?

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

3 participants