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

Any way to add node to center of canvas? #153

Open
LivInTheLookingGlass opened this issue Jul 24, 2015 · 10 comments
Open

Any way to add node to center of canvas? #153

LivInTheLookingGlass opened this issue Jul 24, 2015 · 10 comments

Comments

@LivInTheLookingGlass
Copy link

Sorry if I'm missing something obvious, but as near as I can tell, the point of insertion for nodes is wandering all over the place. I just want a reliable way to add nodes to the center of any given canvas, and have them rearrange accordingly afterwards.

Is there a way to do this?

@anvaka
Copy link
Owner

anvaka commented Jul 25, 2015

I believe this is a miss on my end - I cannot find this documented in the current repository.

What you are looking for is layout.setNodePosition(nodeId, x, y) - the method will override default node position and set it to the given x and y.

It was documented in the ngraph.forcelayout module, but not here.

Please let me know if this works for you.

@LivInTheLookingGlass
Copy link
Author

I'm not exactly sure how to call this method. When I try to use the ngraph syntax, it says that "require is not defined". When I try to access it via "graph.layout", it's undefined.

Can you cure my stupid?

@LivInTheLookingGlass
Copy link
Author

Just for reference, this is me trying to solve Issue #2 on my repo.

In addition to my comment above, I've tried going into each node and changing their position to {x:0,y:0}, but it appears that this location still drifts over time.

@LivInTheLookingGlass
Copy link
Author

using the method you described, it's still drifting. I'm currently calling layout.setNodePosition(nodeId,0,0); on every addition, yet this point still drifts significantly over time.

I'm going to try a workaround to see if I can give you more data to work off of. I'll get back to you in a bit.

@LivInTheLookingGlass
Copy link
Author

Just found out that layout.setNodePosition() was calling a non-existent method, so that would explain some. I decided to try going in and replacing force_directed_bodies properties, and that works for a little while, but the program quickly crashes. Still, though, there's no noticeable drift in that time.

@LivInTheLookingGlass
Copy link
Author

Wow, so I'm a little embarrassed here.

Turns out when I forked this project, I never checked what version of Vivagraph it was using. It was nearly 2 years old. So yeah, my fault, not yours. I'm still having trouble properly placing 2/4 of my node types, but that's on me, not you.

I still wish there was a way to automatically do this, but feel free to consider this closed.

@anvaka
Copy link
Owner

anvaka commented Jul 28, 2015

Hi @gappleto97

The layout object created here should be exactly the same as ngraph.forcelayout (see here how it's created internally). So documentation for ngraph.forcelayout applies to vivagraph too.

Still, though, there's no noticeable drift in that time.

I'm not sure I understand. Are you trying to prevent nodes from flying away?

@LivInTheLookingGlass
Copy link
Author

No. When I call addNode(), the location it adds them at changes over time.
I'm trying to prevent this from happening, and add to the center of the
canvas.

Using the above hack makes it relatively stable, but for some reason I'm
not catching all of the nodes I'm adding. And even if I was, it's still
wasting processor time to do it. Center by default would be more efficient.
Is there some obvious way that I'm missing? Could I perhaps pass in a
force_directed_body object on creation?
On Jul 28, 2015 12:15 AM, "Andrei Kashcha" notifications@github.com wrote:

Hi @gappleto97 https://github.com/gappleto97

The layout object created here

var layout = Viva.Graph.Layout.forceDirected(graph, {
springLength : 10,
springCoeff : 0.0008,
dragCoeff : 0.02,
gravity : -1.2
});

should be exactly the same as ngraph.forcelayout (see here
forceDirected: require('ngraph.forcelayout'),

how it's created internally). So documentation for ngraph.forcelayout
applies to vivagraph too.

Still, though, there's no noticeable drift in that time.

I'm not sure I understand. Are you trying to prevent nodes from flying
away?


Reply to this email directly or view it on GitHub
#153 (comment).

@anvaka
Copy link
Owner

anvaka commented Jul 28, 2015

Ah, I see what you mean.

Physics simulator will attempt to to put node as close as possible towards its neighbors. This is by design, since in most cases it will reduce amount of required work.

What this means - if you add your node via addLink() it will use connection information to position those nodes.

Have you tried calling layout.setNodePosition(nodeId, 0, 0), to override default initial position with the latest version of the library? What happens?

@LivInTheLookingGlass
Copy link
Author

I have. I haven't tried it on the most recent version yet (again, was using
a 2 year old one...), but in that one the location would also shift over
time. It was quite confusing.

I'll try it on the new version tomorrow. Hopefully that will work better.
On Jul 28, 2015 1:07 AM, "Andrei Kashcha" notifications@github.com wrote:

Ah, I see what you mean.

Physics simulator will attempt to to put node as close as possible towards
its neighbors. This is by design, since in most cases it will reduce amount
of required work.

What this means - if you add your node via addLink() it will use
connection information to position those nodes.

Have you tried calling layout.setNodePosition(nodeId, 0, 0), to override
default initial position with the latest version of the library? What
happens?


Reply to this email directly or view it on GitHub
#153 (comment).

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

2 participants