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

Limiting the range of panning with the camera? #574

Closed
Holocene opened this issue May 16, 2015 · 1 comment
Closed

Limiting the range of panning with the camera? #574

Holocene opened this issue May 16, 2015 · 1 comment

Comments

@Holocene
Copy link

Hi,

I'd like to limit how far the user can pan the camera with sigma. Right now, the user can drag with their mouse so that the graph goes off screen - I'd like to stop the user from panning any further once there are no more nodes for them to see.

I found the functionsigma.utils.getBoundaries that tells me the maximum size in the graph's reference frame. For my graph, these are the values:

maxX: 220.891779987076
maxY: 61.83015864512595
minX: -53.77542585542745
minY: -58.27287883796339

I thought then to go edit the goTo method on the camera class, like this:

if (coordinates.x < bounds.minX) coordinates.x = bounds.minX;
if (coordinates.y < bounds.minY) coordinates.y = bounds.minY;
if (coordinates.x > bounds.maxX) coordinates.x = bounds.maxX;
if (coordinates.y > bounds.maxY) coordinates.y = bounds.maxY;

However, the coordinates here are from the coordinate space of the camera rather than of the graph, and I don't know how to change graph coordinates to camera coordinates. I expected to be able to find how to do this somewhere in the code, but after a few hours searching I can't seem to work it out. I tried using the cameraPosition and graphPosition methods, but they give unexpected results. How do I change graph coordinates to camera coordinates?

Do you have a suggestion on where I could look?

@Holocene
Copy link
Author

Huh, I managed to find the trick after a bit more looking: I called the getBoundaries function with the relevant read parameter:

sigma.utils.getBoundaries(this.graph,'read_cam0:',true);

and it all worked out after that.

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