Skip to content
This repository has been archived by the owner on Jul 29, 2019. It is now read-only.

Network: How to save new positions for each nodes after draging #2017

Closed
JamieZhang2016 opened this issue Aug 11, 2016 · 7 comments
Closed

Comments

@JamieZhang2016
Copy link

JamieZhang2016 commented Aug 11, 2016

I'm new to vis, hope someone can help me on my question.

In my codes for drawing the network chart: var network = new vis.Network(container, data, options);
each time re-open the network chart, the nodes positions are randomly set, which is fine for me. (I didn't set fixed for individual node)

But sometimes my user want to re-position the nodes by draging, then how can I save the adjusted position for all nodes? Then after refresh or re-open the page/chart, they can see the nodes in the saved positions.

Thanks.

@JamieZhang2016 JamieZhang2016 changed the title How to save new positions for each nodes after draging Network: How to save new positions for each nodes after draging Aug 11, 2016
@abcbaby
Copy link

abcbaby commented Aug 11, 2016

Once the dragging event stops, you can do this:

_.forEach(nodes, function(item) {
    var positions = network.getPositions(item.id);
    item.positionX = positions[item.id].x;
    item.positionY = positions[item.id].y;
});

@JamieZhang2016
Copy link
Author

JamieZhang2016 commented Aug 11, 2016

Thanks dragonzone, I think I get the idea how to get nodes X and Y. I will save the value in somewhere.

Can you please also advise me how to set x and y with fixed position when build the nodes? I tired to find some sample codes but I could not. Thanks.

@abcbaby
Copy link

abcbaby commented Aug 12, 2016

Here is an example you can check out: https://jsfiddle.net/tsee1ap0/1/

Note: all this information you can get from the documentation here: http://visjs.org/docs/network/

@Stexxen
Copy link
Contributor

Stexxen commented Aug 17, 2016

Another example is here - http://visjs.org/examples/network/exampleApplications/nodeLegend.html

but bear in mind this issue - #1857 which is fixed in the develop branch.

@JamieZhang2016
Copy link
Author

Thanks dragonzone & Stexxen, very good examples. I will try to finish my assignments.

@mojoaxel
Copy link
Member

mojoaxel commented Aug 18, 2016

I think we can close this.
@JamieZhang2016 Feel free to reopen if you have more questions regarding saving the position of the nodes.

@SubashRamaiah
Copy link

Hello Everyone, I'm new to Vis js.

Is it possible to get dragged nodes only?? If yes can you please share the code.

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

No branches or pull requests

5 participants