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

stop user from dragging annotation outside the canvas #92

Open
sbaz44 opened this issue Oct 18, 2021 · 3 comments
Open

stop user from dragging annotation outside the canvas #92

sbaz44 opened this issue Oct 18, 2021 · 3 comments

Comments

@sbaz44
Copy link

sbaz44 commented Oct 18, 2021

Hi. First of all thank you for creating this awesome package.
I just want to know whether I can stop the user from dragging the annotation outside the canvas,partially or fully.
If the user drags the annotation partially outside the canvas the X or Y value is negative(depending the direction).

Example:
{
mark:{
height: 219.27272727272725
type: "RECT"
width: 279.81818181818176
x: -75.09090909090902
y: 268.36363636363643
}
}

Any help would be greatly appreciated.

@ebrahimsakirmi
Copy link

@sbaz44 hey , did you found any solution regarding this please help or suggest any other libraries

@sbaz44
Copy link
Author

sbaz44 commented Oct 3, 2022

@ebrahimsakirmi I converted his package from typescript to normal react( because I dont know typescript). Then I changed the code in SHAPE.js(for typescript SHAPE.ts) to the following.

`
this.onDrag = (positionX, positionY) => {

  const { width, height } = this.annotationData.mark;
  let posX = positionX - this.dragStartOffset.offsetX;
  let posY = positionY - this.dragStartOffset.offsetY;
  let totalWidth = Math.floor(posX + width);
  let totalheight = Math.floor(posY + height);
  if (positionX - this.dragStartOffset.offsetX < 0 || totalWidth > 1280) {
  } else {
    this.annotationData.mark.x = positionX - this.dragStartOffset.offsetX;
  }
  if (positionY - this.dragStartOffset.offsetY < 0 || totalheight > 720) {
  } else {
    this.annotationData.mark.y = positionY - this.dragStartOffset.offsetY;
  }
  this.onChangeCallBack();
};`

mine image size for canvas was 1280 * 720.

@ebrahimsakirmi
Copy link

@sbaz44 hey, thanks a lot for replying back, I will give it a try for it and update you, Thanks men

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

2 participants