-
Notifications
You must be signed in to change notification settings - Fork 27
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
Bug: React + Scatterplot subscribe listeners don't register reliably on refresh. #112
Comments
I've narrowed down the problem space a bit. In my example, I would "click" outside of the screen for the events to register. But this is now incorrect, it's when the mouse leaves the canvas space. I logged from the Line 749 in 71dc8f2
Moving upstream, I noticed that if I moved the mouse out of the canvas, the Line 3233 in 71dc8f2
It's looking more and more likely to be related to the When I logged out from the Line 3229 in 71dc8f2
The |
I think I have found the issue. The Line 461 in 71dc8f2
If you are able to move the mouse into the canvas before the initalization (it becomes out of sync). The cursor must then trigger the I was able to fix the issue by setting it to let isMouseInCanvas = true; If the cursor is not in the canvas on startup ( I think this assumption is safe? I'm not sure if this solution/assumption has any unintended side effects. Alternatively, you do a check somewhere to find out if the mouse is within the canvas on boot. |
Thanks a lot for reporting the bug, putting together the reproducible example, and digging into the code! You're right the Let me have a closer look tonight. Another idea that comes to mind is to determine the state of |
I guess that I have only tested the You would only have to check and trace mouseMoveHandler to get a better understanding. const mouseMoveHandler = (event) => {
if (!isInit || (!isMouseInCanvas && !mouseDown)) return; // <- HERE
const currentMousePosition = getRelativeMousePosition(event);
const mouseMoveDist = dist(...currentMousePosition, ...mouseDownPosition);
const mouseMovedMin = mouseMoveDist >= lassoMinDist;
if (isMouseInCanvas && !lassoActive) { // <- <- HERE
hover(raycast());
}
if (lassoActive) {
event.preventDefault();
lassoManager.extend(event, true);
} else if (mouseDown && lassoOnLongPress && mouseMovedMin) {
lassoManager.hideLongPressIndicator({
time: lassoLongPressRevertEffectTime,
});
}
if (mouseDownTimeout >= 0 && mouseMovedMin) {
clearTimeout(mouseDownTimeout);
mouseDownTimeout = -1;
}
if (mouseDown) draw = true;
}; Alternatively, you're right, |
I've put together a PR that attempts to fix the issue #114. if you have the chance, could you give it a try? |
lgtm |
@NOT-HAL9000 New version (v1.6.4) with a fix for this bug is out. Thanks again for reporting the issue and taking a stab at it! |
Introduction
I've been trying to create a custom scatterplot hook that I can drag and drop into my project.
I have it all working however I keep running into a weird event listener bug. I have tried various implementations, but they all end up with this same bug.
I don't know if this as a result of my react code, or regl-scatterplot, but I have recreated the bug locally and on stackblitz.
The reproduction code is at the bottom.
Bug Observations
The issue is that when the page is being refreshed,
Even if the event listeners didn't register, the scatterplot is still interactive (pan, zoom, select).
recording.mp4
Reproduce
The top window in the video was a local implementation, and the bottom window is accessible via the stackblitz link below.
You can find the smallest possible implementation to reproduce the code on stackblitz here. Be aware that you must click the 'Open in New Tab' button on stackblitz to reproduce.
All the code is in one file and it's only the main page component (to render the canvas) and a hook. It's a very simple implementation.
If you want to re-create the issue locally, comment in the
pages/index.js
outlines the steps.1) Install regl-scatterplot via "npm install --save regl regl-scatterplot pub-sub-es"
2) Import useCallback, useEffect, useRef, useState from react
3) Copy 'useScatterplot' hook into the index.js file next to the home component.
4) Use this 'Home' component to register event listeners and render canvas
Let me know if you have any further questions.
The text was updated successfully, but these errors were encountered: