Skip to content

dia.Link: add getComputedLabel()/getComputedLabels() - #3528

Open
Geliogabalus wants to merge 10 commits into
clientIO:masterfrom
Geliogabalus:link-computed-labels
Open

Geliogabalus wants to merge 10 commits into
clientIO:masterfrom
Geliogabalus:link-computed-labels

Conversation

@Geliogabalus

Copy link
Copy Markdown
Contributor

Summary

  • Link#label()/labels() always return a label exactly as stored, leaving every caller to separately re-resolve it against defaultLabel/the built-in default. LinkView duplicated that merge logic in several places (rendering, label dragging, RotateLabel).
  • Adds getComputedLabel(index?)/getComputedLabels(), which return each label resolved against defaultLabel/the built-in default, centralizing that resolution into a new link-labels.mjs. LinkView now calls these instead of re-implementing the merge inline.
  • A label (or defaultLabel) may carry custom properties beyond markup/attrs/size/position - these pass through resolution unmodified, with the label's own value winning over defaultLabel's.
  • label()/labels() themselves are unchanged - still raw, as stored.

Test plan

  • grunt karma:joint - 2117/2119 passing; the 2 failures (util.breakText ellipsis, element ports > port labels label attributes) are pre-existing, unrelated to this change (confirmed present on a clean upstream/master checkout too, both in unrelated subsystems - text measurement and port label rotation matrix precision)
  • grunt test:ts - passing
  • New QUnit coverage for getComputedLabel/getComputedLabels (resolution against defaultLabel, custom property pass-through) in test/jointjs/links.js

label()/labels() always returned a label exactly as stored, leaving every
caller to separately re-resolve it against defaultLabel/the built-in default
(LinkView duplicated this merge logic in several places: rendering, label
dragging, RotateLabel). getComputedLabel()/getComputedLabels() centralize
that resolution in link-labels.mjs and expose it directly, and LinkView now
calls them instead of re-implementing the merge inline.

A label (or defaultLabel) may also carry custom properties beyond markup/
attrs/size/position - these pass through resolution unmodified, with the
label's own value winning over defaultLabel's.
Comment thread packages/joint-core/src/dia/link-labels.mjs Outdated

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.

Copilot review overview

🟡 Changes recommended

Computed labels expose shared mutable built-in markup and attributes, allowing callers to alter defaults globally.

Review effort: Balanced
Findings: 1 High severity · 1 Low severity

Open (2)
What changed in this PR

Adds computed label APIs to centralize label/default resolution and reuse it throughout link rendering and tools.

Changes:

  • Adds getComputedLabel() and getComputedLabels().
  • Refactors LinkView and RotateLabel to use resolved labels.
  • Adds types, tests, and a changeset.
File Description
.changeset/​brave-labels-resolve.md Records the new APIs.
packages/​joint-core/​src/​dia/​Link.mjs Exposes computed-label methods.
packages/​joint-core/​src/​dia/​link-labels.mjs Centralizes label resolution.
packages/​joint-core/​src/​dia/​LinkView.mjs Uses resolved labels for rendering and dragging.
packages/​joint-core/​src/​linkTools/​RotateLabel.mjs Uses computed label positions.
packages/​joint-core/​types/​dia.d.ts Declares computed-label types and methods.
packages/​joint-core/​test/​jointjs/​links.js Tests computed-label resolution.
packages/​joint-core/​test/​jointjs/​linkView.js Tests invalid computed positions.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/joint-core/src/dia/link-labels.mjs Outdated
Comment thread packages/joint-core/src/dia/Link.mjs Outdated
Comment thread packages/joint-core/src/dia/link-labels.mjs Outdated

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.

Copilot review overview

🟡 Changes recommended

It breaks numeric getLabelCoordinates() inputs and adds costly full-label cloning to a frequent geometry-update path.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
Resolved since last review (2)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Preserve numeric label position support

packages/​joint-core/​src/​dia/​LinkView.mjs:1244

This removes the method's existing support for a numeric label position: getLabelCoordinates(0.5) now reads 0.5.distance and throws, even though Link.Label.position still supports numbers. Normalize a numeric argument before validating the position object so existing JavaScript callers continue to work.

Comment thread packages/joint-core/src/dia/LinkView.mjs Outdated

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.

Copilot review overview

🟡 Changes recommended

It unintentionally removes existing runtime support for numeric positions in getLabelCoordinates().

Review effort: Balanced
Findings: 1 High severity

Open (1)
Resolved since last review (1)

Comment thread packages/joint-core/src/dia/LinkView.mjs

This branch has not been deployed

No deployments
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