Feature: enable zoom scalable dragging#43
Open
mislavivanda wants to merge 1 commit intoekymo:masterfrom
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
🌐What Is Zoom Scalable Dragging?
Zoom-scalable dragging adjusts the drag speed based on the current zoom level. For example:
🔗Relation to Previous Dragging Fix(PR#42)
The code changes in this PR address the same flickering issue described in the previously mentioned PR#42.
The key difference is in how drag speed is handled:
⚙️How it works
The original drag flickering issue is caused by scaling the
distXanddistYvalues using the zoomfactor. This scaling is unnecessary because both (pox,poy) - the drag start point - and (snap.xMouse,snap.yMouse) - the current cursor position - are already computed relative to the current zoom level.When scaling is applied:
distX,distY) becomes larger than it actually is.As a result, the
viewBoxorigin is adjusted more than it should be, and the updated origin does not align the view such that (snap.xMouse,snap.yMouse) overlaps with (pox,poy).This misalignment leads to a feedback loop: the discrepancy between the two points keeps growing, resulting in larger and larger
distX/distYvalues being applied which causes the erratic flickering behavior.✅The Fix
To fix this, we ensure that applying the drag delta correctly shifts the view so that the starting drag point (
pox,poy) moves to the current cursor position (snap.xMouse,snap.yMouse).We achieve this by setting:
This offsets (
pox,poy) bydistXanddistYin the direction opposite to the cursor movement, relative to the current mouse position (snap.xMouse,snap.yMouse). Then, when the drag action updates theviewBoxorigin using those samedistX/distYvalues, the view shifts accordingly bringing (pox,poy) into alignment with the cursor at (snap.xMouse,snap.yMouse).This ensures stable and predictable drag behavior, matching the intended and expected outcome.