Skip to content

feat: add Fit to Screen zoom control utility#36

Open
Babin123456 wants to merge 1 commit into
itzzavdhesh:mainfrom
Babin123456:feat/canvas-fit-to-screen
Open

feat: add Fit to Screen zoom control utility#36
Babin123456 wants to merge 1 commit into
itzzavdhesh:mainfrom
Babin123456:feat/canvas-fit-to-screen

Conversation

@Babin123456

@Babin123456 Babin123456 commented Jun 27, 2026

Copy link
Copy Markdown

Related Issue

Closes #25

Summary

This PR adds a "Fit to Screen" utility button to the flowchart canvas zoom panel HUD.

Changes Made

  • Created handleFitToScreen calculation function.
  • Computed flowchart boundary limits and calculated scale adjustments against container dimensions.
  • Centered pan coordinates on content center relative to scale.
  • Embedded a "Fit" button next to "Reset" in the zoom dashboard HUD.

Testing

  • Tested locally by adding a large chain of decision and input blocks.
  • verified clicking "Fit" scales down and centers all elements within the canvas border viewport.

Screenshots

N/A

Impact

Improves canvas controls usability.

Checklist

  • Code follows project standards
  • Tested locally
  • No unrelated changes included
  • Responsive design verified
  • Accessibility considered

Summary by cubic

Adds a "Fit to Screen" control to the canvas so users can quickly scale and center all blocks in view. Improves zoom usability on large flowcharts.

  • New Features
    • Added handleFitToScreen to compute node bounds and fit content to the container with padding; clamps scale between 0.4 and 2 (2-decimal precision).
    • Recenters pan on the content center and rounds to whole pixels.
    • Added a "Fit" button next to "Reset" in the zoom HUD with an info toast.

Written for commit 0d950ff. Summary will update on new commits.

Review in cubic

@vercel

vercel Bot commented Jun 27, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the itzzavdhesh's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown

✅ Thanks! This PR is linked to #25 and will close it automatically when merged.

@github-actions github-actions Bot added ELUSOC enhancement New feature or request VETERAN labels Jun 27, 2026
@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Babin123456, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 57 minutes and 28 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0f9ea734-2ba2-446a-8e0e-ae5eec59f988

📥 Commits

Reviewing files that changed from the base of the PR and between 22009dd and 0d950ff.

📒 Files selected for processing (1)
  • src/components/CenterCanvas.tsx
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/components/CenterCanvas.tsx">

<violation number="1" location="src/components/CenterCanvas.tsx:127">
P1: Fit-to-screen uses inconsistent zoom clamping range [0.4, 2] instead of the canvas-wide [0.25, 3], which can prevent large/small charts from actually fitting to the viewport.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

const scaleX = (containerWidth - padding) / contentWidth;
const scaleY = (containerHeight - padding) / contentHeight;
let newScale = Math.min(scaleX, scaleY);
newScale = Math.min(Math.max(0.4, newScale), 2);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1: Fit-to-screen uses inconsistent zoom clamping range [0.4, 2] instead of the canvas-wide [0.25, 3], which can prevent large/small charts from actually fitting to the viewport.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/components/CenterCanvas.tsx, line 127:

<comment>Fit-to-screen uses inconsistent zoom clamping range [0.4, 2] instead of the canvas-wide [0.25, 3], which can prevent large/small charts from actually fitting to the viewport.</comment>

<file context>
@@ -99,6 +99,45 @@ export default function CenterCanvas({
+    const scaleX = (containerWidth - padding) / contentWidth;
+    const scaleY = (containerHeight - padding) / contentHeight;
+    let newScale = Math.min(scaleX, scaleY);
+    newScale = Math.min(Math.max(0.4, newScale), 2);
+    newScale = parseFloat(newScale.toFixed(2));
+
</file context>
Suggested change
newScale = Math.min(Math.max(0.4, newScale), 2);
newScale = Math.min(Math.max(0.25, newScale), 3);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ELUSOC enhancement New feature or request VETERAN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] [ELUSoC_2026] Add Fit to Screen Zoom Utility

1 participant