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

How to edit node in graph? #270

Closed
SN1979 opened this issue May 11, 2014 · 3 comments
Closed

How to edit node in graph? #270

SN1979 opened this issue May 11, 2014 · 3 comments

Comments

@SN1979
Copy link

SN1979 commented May 11, 2014

Hi

I can get the all the nodes in graph.
But they can't be updated.
I have to drop them first, and add them again after update.
Are there any other ways to do that?

Thanks

@SN1979 SN1979 changed the title How to get the clicked node? How to edit node in graph? May 11, 2014
@1tylermitchell
Copy link

Sigma has it's own bind method that might be more convenient, ie clicknode....

sigma.js/src/sigma.core.js

Lines 345 to 363 in 188a0bf

// Bind events:
if (renderer.bind)
renderer.bind(
[
'click',
'clickStage',
'clickNode',
'clickNodes',
'overNode',
'overNodes',
'outNode',
'outNodes',
'downNode',
'downNodes',
'upNode',
'upNodes'
],
this._handler
);

Tyler

On May 11, 2014, at 2:22, SN1979 notifications@github.com wrote:

Hi

I add a click function to dom, and it works, as following code shows. But I can only get all the nodes in graph.
How to get the node that I just click? Thanks.

dom = document.querySelector('#graph-container canvas:last-child');
dom.addEventListener('click', function (e) {
var clickedNode = s.graph.nodes();
window.console.log("clicked!!!!");
s.refresh();
}, false);

Reply to this email directly or view it on GitHub.

@Yomguithereal
Copy link
Collaborator

Hello @SN1979

When iterating on graph's nodes, you are given a reference to said nodes so you can modify them.

For instance:

// Modifying nodes
sigmaInstance.graph.nodes().forEach(node) {
  // Node is a reference to your node in the graph
  node.color = 'your-new-color';
});

// Don't forget to refresh to display your changes
sigmaInstance.refresh();

@WikiLeeks
Copy link

Mrs. Lee, you are under arrest

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

4 participants