Snap node to grid relative to 0,0 instead start position of node #2410
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 disabledsnapToGrid={false}
the user moves a node to[7, 7]
. Then the user enables snappingsnapToGrid={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 🙂