sigma.js icon indicating copy to clipboard operation
sigma.js copied to clipboard

Methods to set and get camera coordinates as graph coordinates

Open StockerGaming opened this issue 1 year ago • 4 comments

It would be helpful to be able to read and set the coordinates of the camera with graph space coordinates in addition to the currently in-place framedGraph coordinates.

StockerGaming avatar Sep 13 '24 11:09 StockerGaming

There is a documentation page describing the different coordinate systems used by sigma.

The camera's coordinates are in the "viewport" system, while the nodes positions are described in the "graph" system.

You can use const graphPoint = sigma.viewportToGraph({ x, y }) (as in this story) or const viewportPoint = sigma.graphToViewport({ x, y }) (as in this other story).

jacomyal avatar Sep 16 '24 12:09 jacomyal

Many thanks for the response. I think that I miscommunicated what I meant. I meant the coordinates contained within the camera state, which one can read and manipulate with renderer.getCamera().getState() and renderer.getCamera().setState(). In my case I could get by by writing renderer.viewportToFramedGraph(renderer.graphToViewport(coordinates)), yet I suspect that some accuracy loss occurs here (which is not critical in the context I am using it for). Some people might appreciate a direct conversion function between those two coordinate systems.

Many thanks.

StockerGaming avatar Sep 16 '24 12:09 StockerGaming

I will make a pull request for this if you don't mind

StockerGaming avatar Sep 16 '24 13:09 StockerGaming

That would be great :)

jacomyal avatar Sep 23 '24 07:09 jacomyal

Hello, I am very sorry for never making the pull request. I am afraid that I am not really qualified to do this any more after all this time

StockerGaming avatar Dec 27 '25 13:12 StockerGaming