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

Fix camera view resetting on label visibility change #215

Merged
merged 1 commit into from
Apr 4, 2024

Conversation

ghsteff
Copy link
Contributor

@ghsteff ghsteff commented Apr 3, 2024

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

The camera resets while zooming in on a big graph when label visibility switches

The camera also resets while dragging nodes when other nodes are out view.

Issue Number: #213 #214

What is the new behavior?

The camera doesn't re-center automatically when nodes/labels update. Centering the camera is now left to be handled on a case-by-case basis using the centerGraph method from GraphCanvasRef

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

The node.labelVisible field was triggering a re-render when it updated that would cause the camera to re-center if any nodes were out of view. Same thing was happening when dragging a node which updates node.position

BEFORE

Screen.Recording.2024-04-03.at.12.55.48.PM.mov

AFTER

Screen.Recording.2024-04-03.at.12.54.28.PM.mov

This removes the automatic centering behavior whenever the nodes array updates

The labelVisible field within a node was causing issues when it updated because it would cause a re-render that would trigger the camera to re-center

Centering the camera is now left to be handled on a case-by-case basis using the centerGraph method from GraphCanvasRef
Copy link

netlify bot commented Apr 3, 2024

Deploy Preview for reagraph ready!

Name Link
🔨 Latest commit a00e206
🔍 Latest deploy log https://app.netlify.com/sites/reagraph/deploys/660db4d09c16210008ac7996
😎 Deploy Preview https://deploy-preview-215--reagraph.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@@ -178,12 +178,6 @@ export const useCenterGraph = ({
// Center the graph once nodes are loaded on mount
await centerNodes(nodes, { animated: false });
mounted.current = true;
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait - so now it won't auto center?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It still auto centers on selection and mount, but not whenever nodes change. I was thinking about something like a deep compare to only trigger the centering if one of the node.position's changed, but then dragging while zoomed is still an issue.

The dragging issue makes this feel hard enough to predict when or when not to re-center that I figured leaving it to be handled outside the canvas was the safest move

Copy link
Member

@amcdnl amcdnl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New clarrification of impacts of new code

@amcdnl amcdnl merged commit 9319815 into master Apr 4, 2024
5 checks passed
@amcdnl amcdnl deleted the fix/Camera-view-resetting branch April 4, 2024 15:52
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

Successfully merging this pull request may close these issues.

Organising nodes with fairly big network always resets the view Zoom resets after label visibility changes
2 participants