Skip to content

fix: restore preview edge default target position on cell hover#1025

Merged
redfish4ktc merged 3 commits into
maxGraph:mainfrom
LOUISNOYEZ:fix/connection_handler_preview_restore_default_position
Apr 28, 2026
Merged

fix: restore preview edge default target position on cell hover#1025
redfish4ktc merged 3 commits into
maxGraph:mainfrom
LOUISNOYEZ:fix/connection_handler_preview_restore_default_position

Conversation

@LOUISNOYEZ
Copy link
Copy Markdown

@LOUISNOYEZ LOUISNOYEZ commented Mar 24, 2026

PR Checklist

  • Addresses an existing open issue: closes #<the_issue_number_here>. If not, explain why (minor changes, etc.).
  • You have discussed this issue with the maintainers of maxGraph, and you are assigned to the issue.
  • The scope of the PR is sufficiently narrow to be examined in a single session. A PR covering several issues must be split into separate PRs. Do not create a large PR, otherwise it cannot be reviewed and you will be asked to split it later or the PR will be closed.
  • I have added tests to prove my fix is effective or my feature works. This can be done in the form of automatic tests in packages/core/_tests_ or a new or altered Storybook story in packages/html/stories (an existing story may also demonstrate the change).
  • I have provided screenshot/videos to demonstrate the change. If no releavant, explain why.
  • I have added or edited necessary documentation, or no docs changes are needed.
  • The PR title follows the "Conventional Commits" guidelines.

Overview

Restore connection handler mxgraph behavior.
Delete preview edge entryX and entryY style properties when hovering a cell without without hovering a specific target connection point instead of setting them to 0. Currently, the connection preview entry position snaps to the top left corner of cell shapes, which is not intended behavior.

Bug description

Demonstration using the Anchor story

  • Current maxgraph behavior : The connection preview snaps to the top left of the cell shape.
connection_preview_wrong.mp4
  • Intended mxgraph behavior : The connection preview snaps to the bottom center of the cell shape.
connection_preview_right.mp4

Analysis

The behavior change was introduced in commit 648e324 where the connection handler file was changed from

if (constraint != null && constraint.point != null) {
this.edgeState.style.entryX = constraint.point.x;
this.edgeState.style.entryY = constraint.point.y;
} else {
delete this.edgeState.style.entryX;
delete this.edgeState.style.entryY;
}

to

if (constraint && constraint.point) {
this.edgeState.style.entryX = constraint.point.x;
this.edgeState.style.entryY = constraint.point.y;
} else {
this.edgeState.style.entryX = 0;
this.edgeState.style.entryY = 0;
}

Which remains to this day. Fixing the issue consists in reverting to the original code.

Notes

  • Although this pull request reverts to the initial mxgraph behavior, it provides no motivation for the initial behavior in the first place.
  • I've added no tests under packages/core/__tests__ as the issue is related to a transient rendering artefact. Correctness can be assed using any story involving the connection handler where its updateEdgeState method has not been overriden.

Keywords

closes #841

Summary by CodeRabbit

  • Bug Fixes

    • Improved edge preview rendering by removing stale connection coordinate styling when preview constraints are absent, producing more accurate connection visuals.
  • Documentation

    • Expanded and clarified connection-point docs: normalized entryX/entryY/exitX/exitY semantics (typical 0–1 range), how perimeter falls back to center, and how pixel offsets (entryDx/entryDy/exitDx/exitDy) apply after point computation.

delete preview edge entryX and entryY style properties when hovering a cell without without hovering a specific target connection point.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 24, 2026

Walkthrough

When no connection constraint.point exists, ConnectionHandler.updateEdgeState now deletes edgeState.style.entryX and edgeState.style.entryY instead of setting them to 0. JSDoc for CellStateStyle connection-point properties was expanded and clarified.

Changes

Cohort / File(s) Summary
Edge Style Property Handling
packages/core/src/view/plugin/ConnectionHandler.ts
In updateEdgeState, remove edgeState.style.entryX and edgeState.style.entryY via delete when no constraint.point is present, replacing prior assignments of 0.
Type / JSDoc Clarifications
packages/core/src/types.ts
Expanded and corrected JSDoc for CellStateStyle connection properties (entryX/entryY, exitX/exitY, entryDx/entryDy, exitDx/exitDy, entryPerimeter, exitPerimeter, perimeter), clarifying normalized coordinate semantics, offsets, and fallback behaviors.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested labels

enhancement

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The PR description is comprehensive and complete: includes a filled checklist, clear bug description with videos, analysis of the problematic change, and references issue #841. All essential information is provided.
Linked Issues check ✅ Passed The code changes directly address issue #841 by removing entryX/entryY property deletion and setting them to 0, restoring mxGraph behavior where the preview matches final edge points.
Out of Scope Changes check ✅ Passed All changes are in-scope: documentation updates clarify connection-point styling properties in types.ts, and ConnectionHandler.ts changes fix the preview behavior issue described in #841.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly and concisely describes the main fix: restoring the preview edge's default target position behavior on cell hover, which directly aligns with the changeset's primary objective.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@LOUISNOYEZ LOUISNOYEZ marked this pull request as ready for review March 24, 2026 11:22
@tbouffard
Copy link
Copy Markdown
Member

ℹ️ I have been looking at the entryX/entryY properties. entryX is "The connection point in relative horizontal coordinates of an edge with its target terminal."
Setting entryX=0 and entryY=0, means that the constraint point is set to the point on the top left of the shape, which is what we previously saw.
When not setting entryX and entryY, no constraint point is used, and this is what we want to use here. See

const x = edge.style[source ? 'exitX' : 'entryX'];
if (x !== undefined) {
const y = edge.style[source ? 'exitY' : 'entryY'];
if (y !== undefined) {
point = new Point(x, y);
}
}

@sonarqubecloud
Copy link
Copy Markdown

@tbouffard tbouffard changed the title fix(connection): restore connection handler mxGraph behavior fix: restore preview edge default target position on cell hover Apr 28, 2026
Copy link
Copy Markdown

@redfish4ktc redfish4ktc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for this contribution and sorry for having taken so long to review it 😸

@redfish4ktc redfish4ktc merged commit fc7aa28 into maxGraph:main Apr 28, 2026
10 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.

Orthogonal Story: the edge connection preview not always match the final edge points

3 participants