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

[@visx/drag] Enhancement to limit dx and dy #1866

Open
agoldis opened this issue Aug 5, 2024 · 0 comments
Open

[@visx/drag] Enhancement to limit dx and dy #1866

agoldis opened this issue Aug 5, 2024 · 0 comments

Comments

@agoldis
Copy link

agoldis commented Aug 5, 2024

Trying to enhance the library to limit dx and dy values for useDrag, motivation being limit the allowed distance for drag operation.

For example, without dx restrictions:

currents-2024-08-05-16.05.56.mp4

After the suggested change:

currents-2024-08-05-16.04.55.mp4

I wanted to confirm my naive implementation before opening a PR:

restrict?: {
    xMin?: number;
    xMax?: number;
    yMin?: number;
    yMax?: number;
    dxMax?: number; // new 
    dyMax?: number; // new 
    dxMin?: number; // new 
    dyMin?: number; // new 
};
let dx = dragPoint.x - x;
let dy= dragPoint.y - y;
if ( typeof restrict.dxMax === "number" && _dx > restrict.dxMax) {
  dx =  restrict.dxMax;
}
if (typeof restrict.dyMax === "number" && _dy > restrict.dyMax) {
  dy = restrict.dyMax;
}
if (typeof restrict.dxMin === "number" && _dx < restrict.dxMin) {
  dx =  restrict.dxMin;
}
if (typeof restrict.dyMin === "number" && _dy < restrict.dyMin) {
  dy =  restrict.dyMin;
}

return {
  ...currState,
  dx,
  dy,
};

Would appreciate weighing in on this approach.

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

No branches or pull requests

1 participant