Repository navigation
fix(pstricks): map pointer coordinates through the svg's drawn scale - #41
Merged
Merged
Conversation
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
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.
Summary
Interactive pictures (
\userline,uservariableplots) read the pointer withevent.offsetX(mouse) orclientX - target.getBoundingClientRect().left(touch). Both are in screen pixels, while the drawing works in the picture's natural pixel space. When a page draws the svg smaller than its natural size (latex2js.com / mathapedia.com now zoom wide pictures down to fit a phone), the dragged vector no longer follows the finger: it lands at the scaled distance from the origin. The touch path also measuredevent.target, so a touch on a child path used that path's box.New
psgraph.pointerCoords(svg, clientX, clientY)measures the svg itself and divides out the drawn scale (rect.width / width attr). Used by both thepsgraph.pspicturelisteners and the ReactPspicturemouse/touch handlers:Unscaled pictures are unchanged (scale = 1).
Evidence
packages/html5/test/pspicture.test.tsdraws a 200px picture at 100px and moves the pointer. Fails before the fix (Expected: 100, Received: 0), passes after.pstricks202/202,html574/74 tests pass;reacttsc clean./examples/unit-circlewith this build overlaid: pointer at 75%/25% of the drawn picture puts the userline end at(0.749, 0.25)of natural size at 1024px (no zoom) and(0.749, 0.248)at 390px (zoom: 0.606). Before the fix the mobile endpoint was off.Needed for the mobile fixes in latex2js.com / mathapedia.com to keep draggable diagrams accurate. Those sites need a new
@latex2js/pstricks+latex2reactpublish to pick this up.Link to Devin session: https://app.devin.ai/sessions/7fcd2deb6fb144849a9dd3f8dc116d42
Open in Devin Desktop: https://app.devin.ai/desktop/session/7fcd2deb6fb144849a9dd3f8dc116d42?variant=devin
Requested by: @pyramation