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

Node is not below its parent when creating the tree #353

Open
GuilhermeRabelo opened this issue May 20, 2024 · 1 comment
Open

Node is not below its parent when creating the tree #353

GuilhermeRabelo opened this issue May 20, 2024 · 1 comment

Comments

@GuilhermeRabelo
Copy link

GuilhermeRabelo commented May 20, 2024

Hello!! Could you guys help me, I've been having this problem for a few days and I can't find a solution. I'm trying to create a tree using dag mode "td", but when I add a new node to the tree, it mixes with the nodes of another parent, and is not beneath his father (which is the behavior I expected), so I have to click on the node and drag it to be below the parent it was supposed to, any suggestions on how to adjust this?

I created a code reproducing the problem I have, just click on the "pedro" node:
https://codepen.io/GRabelo/pen/wvOEejz

Evidence:
https://github.com/vasturiano/force-graph/assets/43557775/b880fbcf-a187-40ae-9e7a-79fde408e40a

Thanks in advance!! Really appreciate it this lib!!

@vasturiano
Copy link
Owner

vasturiano commented Jun 5, 2024

Olá Guilherme, thanks for reaching out.

This happens because when a node is initiated its initial coordinates are arbitrary, and if that position ends up being on the other side of the existing nodes on that same level, their repelling force doesn't allow the new node to "cross" them and find its ultimate most optimal horizontal position.

A simple thing you can do to optimize this is to give the new node initial attributes of x and y that are equal to the parent, that way it will more easily find its optimal position.

Like this: https://codepen.io/vasturiano/pen/JjqJGpg

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