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 drag and drop methods #204

Closed
Nerah opened this issue May 29, 2019 · 10 comments
Closed

Node drag and drop methods #204

Nerah opened this issue May 29, 2019 · 10 comments
Assignees

Comments

@Nerah
Copy link

Nerah commented May 29, 2019

Is your feature request related to a problem? Please describe.
Let's imagine that I want all the data of my graph to be dynamically persistent.
Actually, it would be impossible for the position of the nodes.
If I take the time to change their position in a specific way and then refresh the graph directly, they all come back to their original position. I find it a bit frustrating.

Describe the solution you'd like
I have the feeling it would be meaningful to have the possibility to detect when a node is drag or drop.

Describe your use case
I would like to use these methods to get the actual position of a node that I just move. If it comes possible, I will be able to save the new position of the node.

Describe alternatives you've considered
I saw that there are actually instance methods to specify the behavior of the drag and drop action on nodes of the graph, like _onDragEnd(). It would be nice if we had the possibility to specify their behavior ourselves.

@stale
Copy link

stale bot commented Jul 28, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jul 28, 2019
@jiriproX
Copy link

Hi, I'm looking for that feature as well. Is there any other way how to persist node position after node drag and drop? I would need to save actual node position as initial node position for next refresh.

@stale stale bot removed the wontfix label Aug 28, 2019
@danielcaldas
Copy link
Owner

Hello @jiriproX you can actually achieve that just by saving the graph data object that you pass down to Graph as props in some storage (e.g. localStorage) and the add that as the initial state. It works like a charm. You need to use staticGraph or (yet to be released) a new upcoming property called staticGraphWithDragAndDrop that will still allow you to drag and drop nodes.

@jiriproX
Copy link

Hi Daniel, it seems that proposed solution does not work for my usecase. I download list of nodes and links from server. Then I generate default initial positions for nodes. That I can store to localStorage and use it for page reloading. At this point I want user to drag and drop nodes to some meaningful layout.
Here is the crucial point. I'm not able to store "that new meaningful" layout for next reload.
Do you have any advice how to achieve that?

@wendymungovan
Copy link

wendymungovan commented Aug 29, 2019

I have a solution but it is a little bit funky. We had to do something similar. If you extend the Graph class you can add in this function that will get at the private variables. Then your calling class will be able to call for each node and get the position when you want to do that.

/** * Gets the x,y position of the given node from the d3Nodes state * @param id node id * @returns {*|*[]} undefined or [x,y] point */ getNodePosition(id) { const node = this.state.d3Nodes.find(node =>${node.id}===${id}); return node && [node.x,node.y]; }

@jiriproX
Copy link

Requested feature seems to be delivered by onNodePositionChange callback added in PR(#228). It was merged yesterday and will be part of next release.
@danielcaldas When will be new version 2.2.x or 2.3.x released?

@danielcaldas
Copy link
Owner

Yes, @jiriproX. This will be in the next release of react-d3-graph. I'll close the issue upon release.

@jiriproX
Copy link

jiriproX commented Sep 12, 2019 via email

@danielcaldas
Copy link
Owner

Hi @jiriproX, I have another release planned by the end of the month. Please bear with me. Until there you can point your react-d3-graph dependency and consume it from master directly instead of npm. Checkout npm examples.

@danielcaldas
Copy link
Owner

Closing this with release of react-d3-graph@2.3.0.

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

No branches or pull requests

4 participants