Skip to content

fix(#1532): diagram edge weight encodes cardinality, not master-part - #1533

Open
dimitri-yatsenko wants to merge 1 commit into
masterfrom
fix/1532-edge-weight-rule
Open

fix(#1532): diagram edge weight encodes cardinality, not master-part#1533
dimitri-yatsenko wants to merge 1 commit into
masterfrom
fix/1532-edge-weight-rule

Conversation

@dimitri-yatsenko

Copy link
Copy Markdown
Member

Part 1 of #1532 — the correctness fix (not style). The style restyle (palette, entity groups, direction, renamed-edge color) will follow as a separate PR.

The rule

Line weight is binary and encodes cardinality only:

  • thick (penwidth 2) — the foreign key constitutes the child's entire primary key → 1:1.
  • thin (penwidth 0.75) — the child has primary-key attributes beyond those the FK contributes (newly declared, or inherited from another FK) → multi-valued.

The visible penwidth already followed this (via the multi edge flag). This PR removes the misleading master-part conflation in the layout weight hint (set_weight(3 if master_part else 1)) — master-part is not a weight; a part almost always adds a key attribute, so its edge is thin under the same rule — and drives weight from the same predicate so the two never diverge.

Rename-safe

multi = set(FK child-columns) != set(child PK) compares in child-column space, so a renamed FK that is the child's whole primary key is correctly 1:1/thick. (The parent-PK-vs-child-PK name comparison sketched in the issue would break under renaming; this does not.)

Test

tests/integration/test_diagram_edge_weight.py renders a diagram and asserts penwidth for four cases: 1:1 (thick), multi-valued (thin), master→part (thin), and renamed-1:1 (thick). Green on MySQL 8.0 and PostgreSQL 15.

Docs companion: datajoint/datajoint-docs#247.

Line weight is binary and encodes cardinality only: thick when the foreign key
constitutes the child's entire primary key (1:1), thin when the child has
primary-key attributes beyond those the FK contributes (multi-valued) — newly
declared or inherited from another FK. penwidth already followed this via multi;
remove the misleading master-part conflation in the layout weight and drive it
from the same predicate so the two never diverge.

Rename-safe: multi compares the child's referencing columns to the child primary
key (both child-column space), so a renamed FK that is the child's whole PK is
correctly 1:1/thick. Adds a guardrail test (1:1, multi, master-part, renamed-1:1).
@dimitri-yatsenko dimitri-yatsenko added the bug Indicates an unexpected problem or unintended behavior label Aug 10, 2026
@dimitri-yatsenko
dimitri-yatsenko marked this pull request as ready for review August 10, 2026 21:41
@dimitri-yatsenko

Copy link
Copy Markdown
Member Author

@ttngu207 @MilagrosMarin — part of the diagram-notation set (#1533 edge-weight → #1534 restyle → #1536 no-context fix). New style shown on a real pipeline: https://github.com/datajoint/lcms-demo/tree/viz/diagram-restyle-1534 (datajoint/lcms-demo#3).

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

Labels

bug Indicates an unexpected problem or unintended behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant