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

Incorrect Hover Behavior on Nodes and a Potential Solution #1399

Closed
foxton9 opened this issue Jan 13, 2024 · 3 comments
Closed

Incorrect Hover Behavior on Nodes and a Potential Solution #1399

foxton9 opened this issue Jan 13, 2024 · 3 comments
Labels

Comments

@foxton9
Copy link

foxton9 commented Jan 13, 2024

  • Sigma.js version : 3.0.0-beta.4
  • Graphology version : 0.23.0
  • Operating system: Windows 10
  • Web browser: Firefox 121.0.1
     
  • Steps to reproduce
    • Run the Code Sandbox example
    • Move the cursor towards any hoverable node, and then move around it.
    • Observe the point at which the node becomes hovered.
       
  • Expected behavior
    The node should become hovered as the cursor enters the node.
  • Actual behavior
    Only when the cusor positioned at the buttom-right side of the node with some offset, the intended node will become hovered.

#1398 reported similar issues.
 

  • Possible cause and solution

The issue might be due to DPI scaling not being accounted for in the coordinate calculation in the getNodeAtPosition function.

const { x, y } = position;
const color = getPixelColor(this.webGLContexts.nodes, this.frameBuffers.nodes, x, y, this.pickingDownSizingRatio);

Updating the coordinate calculation to consider the device's pixel ratio could solve this this issue, however, it's worth considering that there may be other potential problems that have been missed.

The code change could be as follows:

const { x, y } = position;
const canvasX = x * this.pixelRatio
const canvasY = y * this.pixelRatio

const color = getPixelColor(this.webGLContexts.nodes, this.frameBuffers.nodes, canvasX, canvasY, this.pickingDownSizingRatio);

 

Pixel ratio should also be the considered when binding pickingTexture.

this.width / this.pickingDownSizingRatio,
this.height / this.pickingDownSizingRatio,

by multiplying the ratio

this.width * this.pixelRatio / this.pickingDownSizingRatio,
this.height * this.pixelRatio / this.pickingDownSizingRatio,

This method appears to resolve an error that was reported in the browser console.

WebGL warning: drawArraysInstanced: Drawing to a destination rect smaller than the viewport rect. (This warning will only be given once)

@foxton9 foxton9 added the bug label Jan 13, 2024
@temuera
Copy link

temuera commented Jan 15, 2024

+1

@foxton9 foxton9 changed the title Incorrect Hover Behavior on Nodes Due to Potential Coordinate Offset in getPixelColor Incorrect Hover Behavior on Nodes and a Potential Solution Jan 16, 2024
NiBrc added a commit to UniTuebingen-BDVA/sigma.js that referenced this issue Jan 17, 2024
jacomyal added a commit that referenced this issue Jan 18, 2024
This commit adds the devicePixelRatio into consideration when calling
getPixelColor as suggested by foxton9 (thanks a lot!), and also fixes
the texture size.

Without fixing the texture size, the first fix would work, but only on a
fraction of the stage, with a devicePixelRatio different than 1 (for
instance, with a devicePixelRatio of 2, only a fourth of the screen
would be interactive...).
@jacomyal
Copy link
Owner

Thanks a lot for this very detailed report. I just pushed the fix (based on your inquiry, thanks again), and I hope to release a new beta tomorrow, with fixes on the other issues you linked.

@jacomyal
Copy link
Owner

Version 3.0.0-beta.5 has just been published, and includes the fix for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants