Skip to content

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

Closed
kumilingus wants to merge 1 commit into
clientIO:devfrom
kumilingus:feat/fit-to-content-origin
Closed

feat(joint-core): originX/originY options for getFitToContentArea#3315
kumilingus wants to merge 1 commit into
clientIO:devfrom
kumilingus:feat/fit-to-content-origin

Conversation

@kumilingus
Copy link
Copy Markdown
Contributor

@kumilingus kumilingus commented May 15, 2026

Summary

paper.getFitToContentArea (and therefore paper.fitToContent) hard-anchored its grid at (0, 0): grid lines landed at 0, gridWidth, 2*gridWidth, ….

New options originX?: number, originY?: number (default 0, paper-local coords) shift the grid anchor so lines land at originX + n*gridWidth, originY + m*gridHeight instead. Backward compatible — omitting the opts reproduces today's behavior exactly.

Implementation

  • Paper.mjs::getFitToContentArea (src/dia/Paper.mjs):
    • Read opt.originX / opt.originY (default 0).
    • After scaling area.x / area.y by sx / sy, subtract originX * sx / originY * sy so the existing grid math operates in origin-relative space.
    • Return the rect translated back into absolute coords: new Rect(-tx/sx + originX, -ty/sy + originY, …).
  • Paper.fitToContent inherits the feature automatically via the existing opt forwarding.
  • Types updated in types/dia.d.ts (FitToContentOptions).
  • New unit tests cover three combinations: default origin (regression), non-zero origin with allowNewOrigin: 'any', and non-zero origin without allowNewOrigin.

Motivation

Consumers wanting multi-page layouts where the first page starts at a non-zero offset (e.g. a sheet preset that doesn't start at the origin) currently have no way to express it. Used by the companion @joint/react-plus PaperScroller refactor that introduces sheetX / sheetY props.

Test plan

  • yarn workspace @joint/core test-client — confirms new tests pass, no regressions.
  • Backward-compat: existing fitToContent / getFitToContentArea callers behave identically when originX / originY are omitted.

🤖 Generated with Claude Code

`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>
@kumilingus kumilingus requested a review from Geliogabalus May 15, 2026 09:22
@kumilingus
Copy link
Copy Markdown
Contributor Author

Superseded — origin commit cherry-picked into PR #3312 (feat/paper-css-only-sizing).

@kumilingus kumilingus closed this May 15, 2026
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.

1 participant