-
Notifications
You must be signed in to change notification settings - Fork 269
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
[Question] Re-centering tree in div on clicking a node #151
Comments
Hi @amad-person, No this unfortunately isn't part of the feature set at the moment since the An |
That makes sense, thanks @bkrem! |
No problem, sorry I can't help much right now for your use case. I'm going to leave this open for further discussion since someone else may have a good approach for this. |
Couple thoughts:
I guess what I'm trying to say is moving x and y shouldn't be too bad. I've got it working for me with the onclick event, getting the target node x and y, setting the entire graph translate based on that (note I have to put it in a timeout to wait for the actual node expand transition). So it's pretty ugly. but i guess it works. |
@bkrem If i update the state.translate property after the graph is rendered, it is not re-rendered with the new values. Where is this in the code?
Then i update the state.translate values to the newly calculated ones. No whenever I pan or zoom, the graph jumps. Similar to what you reference in this issue: |
@mwilde345 I was actually looking into this and the prop seems to be set, but react doesn't seem to re-render it. So I did some fiddling, I've done react for a cpl of weeks, so I might be waaay off on the solution. I added a key to the g component rendered by NodeWrapper. The key was just translate.x, translate.y+scale as a string. This caused the g component to re-render when translate was set. react-d3-tree/src/Tree/NodeWrapper.js Line 16 in d0bbe8d
|
like @npetzall noted above, updating the HTML attribute for
I don't know how to do smooth transitions with this approach, however. I might just forgo it |
This has been implemented via #381 and shipped as part of https://github.com/bkrem/react-d3-tree/releases/tag/v3.3.0 🚀 Centering nodes can be achieved by setting the new Closing. |
Updatehttps://github.com/bkrem/react-d3-tree/releases/tag/v3.3.1 ships a fix for a calculation bug when centering nodes via Please update to |
I'm using the CenteredTree recipe to render the tree in the center of the parent div on the initial render.
I wanted to know if it is possible to scale and re-center the rendered tree inside its parent component every time a node is expanded?
The text was updated successfully, but these errors were encountered: