sim51 / react-sigma

Sigma React component
https://sim51.github.io/react-sigma/
MIT License
172 stars 27 forks source link

Camera is reset when graph is updated #48

Closed jacomyal closed 1 year ago

jacomyal commented 1 year ago

When a new graph prop value is given to some SigmaContainer instance, the camera is reset. I was expecting the camera to remain the same.

The reason is visible here: https://github.com/sim51/react-sigma/blob/9b5572955a278debc9da2201717e84906b7adfec/project/packages/core/src/components/SigmaContainer.tsx#L82-L86

The fix would be to copy the camera state if an instance exists already, and set it to the new instance's camera right after it's created. Something like:

const cameraState = instance ? instance.getCamera().getState() : null;

// [...] existing code that remounts the instance

if (cameraState) instance.getCamera().setState(cameraState);