Skip to content

Add linkCurveRotation to adjust self-loop angles on curved links - #397

Open
Geoc2022 wants to merge 2 commits into
vasturiano:masterfrom
Geoc2022:master
Open

Add linkCurveRotation to adjust self-loop angles on curved links#397
Geoc2022 wants to merge 2 commits into
vasturiano:masterfrom
Geoc2022:master

Conversation

@Geoc2022

@Geoc2022 Geoc2022 commented Jun 5, 2026

Copy link
Copy Markdown

Currently, self-links (edges that start and end at the same node) are always positioned in the top-right quadrant, which can overlap other links and reduce readability.

This PR introduces a new property, linkCurveRotation, that works similarly to linkCurvature. It allows users to rotate the curvature axis of each link independently. The property accepts a number (in radians), a string, or a function.

Now users can create diagrams like the following:
Screen Shot 2026-06-05 at 15 55 09

See #396 for more info.

Comment thread src/canvas-force-graph.js Outdated
x: (start.x + end.x) / 2 + d * Math.cos(a - Math.PI / 2),
y: (start.y + end.y) / 2 + d * Math.sin(a - Math.PI / 2)
x: (start.x + end.x) / 2 + d * Math.cos(a - Math.PI / 2 + rotation),
y: (start.y + end.y) / 2 + d * Math.sin(a - Math.PI / 2 + rotation)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for the PR @Geoc2022. I'm just trying to understand what's supposed to happen when this prop is used in the context of a regular link from one node to another. Is there some use case that the single linkCurvature doesn't cover and it also needs an additional rotation prop?

@Geoc2022 Geoc2022 Jun 5, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It was intended to mirror the same functionality as in 3d-force-graph, but no, I can't think of many use cases in 2D that would require it. So, I think it's perfectly fine to remove it to improve clarity. Either way adding rotation to self-loops is the only important change.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Ok, in that case would you mind removing the code that affects regular links? And for usage clarity I'd suggest changing the prop name to something more explicit that it applies only to self-links, like linkSelfCurveRotation.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Sure, just fixed it.

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.

2 participants