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

Snap node to grid relative to 0,0 instead start position of node #2410

Merged
merged 1 commit into from Sep 14, 2022

Conversation

wardoost
Copy link
Contributor

@wardoost wardoost commented Sep 7, 2022

I have an app where the user is able to toggle snapping and noticed some potentially undesirable behaviour. With the current implementation snapping is relative to the start position of the node. I think it makes more sense to snap relative to the centre point of the diagram so when snapping is enabled nodes can be neatly aligned relative to each other.

A quick example, let's say a diagram has a gridSize=[10, 10]. With snapping disabled snapToGrid={false} the user moves a node to [7, 7]. Then the user enables snapping snapToGrid={true}. With the current implementation when the user moves the same node it will snap to [17, 17], [27, 27] and so on. I think it makes more sense the node would snap to [10, 10], [20, 20] or [30, 30].

My proposed code changes fix this though it's a quick solution but I'm keen to rethink how to implement this if the maintainers of this library think this is a good change 🙂

@bcakmakoglu
Copy link
Contributor

#2415

Didn't realize there's a PR for the issue - just linking for visibility.

@moklick
Copy link
Member

moklick commented Sep 14, 2022

Hey @wardoost

thanks for your PR! Everything looks good to me :)

@moklick moklick marked this pull request as ready for review September 14, 2022 12:15
@moklick moklick merged commit ceced01 into xyflow:main Sep 14, 2022
@moklick
Copy link
Member

moklick commented Sep 14, 2022

released in released in v10.3.17

@WillBaker2017
Copy link

Hello, @wardoost @moklick @bcakmakoglu
I just submitted a new feature request regarding this merge. #2440
I was using the old snapGrid and would like a toggle between the two (0, 0 and reverencing current x, y position)

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

Successfully merging this pull request may close these issues.

None yet

4 participants