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

How to read the new position of nodes after drag #108

Closed
ak4zh opened this issue Jul 31, 2022 · 11 comments
Closed

How to read the new position of nodes after drag #108

ak4zh opened this issue Jul 31, 2022 · 11 comments

Comments

@ak4zh
Copy link

ak4zh commented Jul 31, 2022

When the user moves a node its new position is not getting updated back In the input JSON data.
I have tried to bind it and use stores, but it seems the data update is not supported.

This feature is helpful because I want to render back the same flowchart that the user has customized when he visits the app next time.

I am unable to find this info in the docs.

@sher85
Copy link

sher85 commented Oct 5, 2022

@ak4zh where are you experiencing this issue, REPL on the selvet.io website? Can you share a screenshot/gif?

@ak4zh
Copy link
Author

ak4zh commented Oct 10, 2022

I want to get the new co-ordinates of the nodes so I can save it in a store and render the samediagram again which user created by dragging the nodes.
I did not find any info about getting the x,y coordinates of the node once it has been dragged by the user.

@ronvoluted
Copy link

ronvoluted commented Oct 12, 2022

Looks like Svelvet doesn't support doing this but you can modify one line in node_modules to enable it:

# ./node_modules/svelvet/Nodes/index.svelte#L46

-    if (!moved && node.id == $nodeIdSelected) {
+    if (node.id == $nodeIdSelected) {

Then you can use the clickCallback property:

const handleDrag = (node: Node): void => {
  $positions[node.id] = node.position;
}

const nodes = [
  {
    id: 1,
    width: 100,
    height: 100,
    position: { x: 0, y: 250 },
    data: { label: 'Drag me to save position in Svelte store' },
    clickCallback: handleDrag,
  },
];

@pbxothi
Copy link

pbxothi commented Nov 6, 2022

@ronvoluted thanks for the quick fix. This is useful. However, the callback is not triggered when dragged on a touch screen.

@taylien96
Copy link
Contributor

taylien96 commented Jan 6, 2023

There is now a way to get the json and upload it with an updated diagram to share changes between users!
Not closed as it's not exactly what you described but we think it may serve your purposes for now.

@franciswillian91
Copy link

same problem here, i need to save node locations after dragging and arranging my flow but i don't know how to get those properties once done.
@taylien96 you mentioned that there is a way to do this but i didn't find it.

@gurmeet-bluesheets
Copy link

@franciswillian91 I think @taylien96 is referring to this https://www.svelvet.io/docs/importDiagrams/

@gurmeet-bluesheets
Copy link

gurmeet-bluesheets commented Feb 28, 2023

@taylien96 how to handle this in the latest version? We simply cannot ask the users to download and re-upload files. @ronvoluted can you help?

@franciswillian91
Copy link

@gurmeet-bluesheets, sure makes sense i didn't discover that feature, mb ;D

@rungdung
Copy link

rungdung commented Apr 5, 2023

Indeed, I would like a built in way to persist diagrams or documentation on how to retrieve it from the store

@briangregoryholmes
Copy link
Contributor

Closing as this has fundamentally changed in Svelvet v7 and up. That said, smoothing out the DX is an active area for us. The position prop can be "bound" to using bind:position for programatic read/write access.

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

9 participants