feat(joint-core): originX/originY options for getFitToContentArea#3365
Merged
zbynekstara merged 2 commits intoJun 15, 2026
Merged
Conversation
`getFitToContentArea` previously hard-anchored its grid at (0, 0): grid lines fell at `0, gridWidth, 2*gridWidth, …`. New `originX` / `originY` options (default `0`, paper-local coords) shift the anchor so grid lines land at `originX + n*gridWidth, originY + m*gridHeight` instead. Backward compatible — omitting the new opts reproduces today's behavior exactly. `paper.fitToContent` already forwards `opt` through, so it inherits the feature automatically. Tested via `paper.fitToContent()` with a few combinations of `allowNewOrigin` × non-zero origin. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Shifting grid anchor changes which grid lines bracket the content, so content's bounding edges may no longer align with the new grid — the returned rect grows/shifts accordingly. Prior expectation assumed the result was just the default-origin rect translated by (originX, originY), which would have left the top edge of the content outside the rect. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds optional originX / originY parameters to Paper.getFitToContentArea() (and therefore paper.fitToContent()) so grid snapping can be anchored to an arbitrary paper-local origin instead of always (0, 0).
Changes:
- Implement origin-relative grid snapping in
getFitToContentArea()by shifting the content area into an origin-relative coordinate system and shifting the returned rect back. - Extend
Paper.FitToContentOptionsTypeScript typings withoriginX/originY. - Add QUnit tests covering default origin and a non-zero origin scenario.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/joint-core/src/dia/Paper.mjs | Implements origin-relative snapping and adjusts returned rect coordinates accordingly. |
| packages/joint-core/types/dia.d.ts | Adds originX / originY to FitToContentOptions typings with documentation. |
| packages/joint-core/test/jointjs/dia/Paper.js | Adds unit tests for backward compatibility and non-zero origin snapping behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
zbynekstara
approved these changes
Jun 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
getFitToContentAreapreviously hard-anchored its grid at (0, 0): grid lines fell at0, gridWidth, 2*gridWidth, ….originX/originYoptions (default0, paper-local coords) shift the anchor so grid lines land atoriginX + n*gridWidth, originY + m*gridHeight.paper.fitToContentalready forwardsoptthrough, so it inherits the feature automatically.Test plan
originX/originYcombinations intest/jointjs/dia/Paper.jspaper.fitToContent()withallowNewOrigin× non-zero origin