Skip to content

feat(joint-core): originX/originY options for getFitToContentArea#3365

Merged
zbynekstara merged 2 commits into
clientIO:masterfrom
kumilingus:feat/fit-to-content-area-origin
Jun 15, 2026
Merged

feat(joint-core): originX/originY options for getFitToContentArea#3365
zbynekstara merged 2 commits into
clientIO:masterfrom
kumilingus:feat/fit-to-content-area-origin

Conversation

@kumilingus

Copy link
Copy Markdown
Contributor

Summary

  • 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.
  • Backward compatible — omitting the new opts reproduces today's behavior exactly. paper.fitToContent already forwards opt through, so it inherits the feature automatically.

Test plan

  • Added unit tests covering originX/originY combinations in test/jointjs/dia/Paper.js
  • Verify paper.fitToContent() with allowNewOrigin × non-zero origin

kumilingus and others added 2 commits June 15, 2026 15:28
`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>

Copilot AI 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.

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.FitToContentOptions TypeScript typings with originX / 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.

Comment thread packages/joint-core/test/jointjs/dia/Paper.js
@zbynekstara zbynekstara merged commit 82f2e07 into clientIO:master Jun 15, 2026
3 checks passed
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.

3 participants