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

Add commands for zoom to fit #432

Merged
merged 1 commit into from
Oct 23, 2024
Merged

Conversation

jackgriffiths
Copy link
Contributor

I have added three new commands:

The "zoom to fit graph" command can be activated from a new toolbar button and with the f hotkey.

There are also some new settings that control how much padding to use when fitting the rect/nodes/graph.

  • zoomToFit.paddingLeft (default = 300)
  • zoomToFit.paddingRight (default = 50)
  • zoomToFit.paddingTop (default = 110)
  • zoomToFit.paddingBottom (default = 50)

The commands do not take palette.enabled and toolbar.enabled into account. That is why the left padding and the top padding are larger - they account for the width of the palette and the height of the toolbar.

I did consider making the commands check if the palette and the toolbar are enabled, and automatically adding extra padding if necessary. However, because the components and styles for the palette and toolbar can easily be changed, I didn't think we could assume their positions or sizes.

It means that if the palette or the toolbar is disabled, then the padding settings will also need to be adjusted to ensure the nodes are still positioned in the center of the editor. Likewise, if the palette or the toolbar is repositioned or resized, the padding settings will need to be adjusted.

It's not ideal that disabling the palette or the toolbar also requires the padding settings to be adjusted. But I think overall this solution is the simplest and most flexible. What do you think?

Copy link
Owner

@newcat newcat left a comment

Choose a reason for hiding this comment

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

Impressive, thank you!

@newcat
Copy link
Owner

newcat commented Oct 23, 2024

Regarding the padding: I think your solution is the best. As you mentioned, there are too many factors that influence the padding when taking into account toolbar/palette and it would also create a lot of coupling to those components. So having them separate and configurable is probably the better approach.

@newcat newcat merged commit 668adb4 into newcat:master Oct 23, 2024
@jackgriffiths jackgriffiths deleted the zoom-to-fit branch October 24, 2024 08:48
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.

Fit view to all nodes / Calculate panning to align with (X, Y)
2 participants