Skip to content

Edge label positioning#533

Draft
Wagner-Laranjeiras wants to merge 2 commits into
eclipse-sprotty:masterfrom
Wagner-Laranjeiras:wagner-laranjeiras/514/edge-label-positioning
Draft

Edge label positioning#533
Wagner-Laranjeiras wants to merge 2 commits into
eclipse-sprotty:masterfrom
Wagner-Laranjeiras:wagner-laranjeiras/514/edge-label-positioning

Conversation

@Wagner-Laranjeiras

Copy link
Copy Markdown

Fix #514: respect external positions for edge labels

Summary

When using the ELK layout integration, edge labels were rendered at the position
computed by Sprotty's EdgeLayoutPostprocessor instead of the position chosen by
ELK. This PR introduces a small cross-package marker that lets a layout engine
declare "this label's position is final, please don't recompute it," and routes
the rendering pipeline accordingly.

Fixes #514.

Changes

  • sprotty-protocol — adds a new ExternallyPositioned interface so layout
    engines and the framework can speak about externally-set positions.
  • sprotty-elkapplyEdge now marks every edge label it positions with
    externallyPositioned: true.
  • sprottyEdgeLayoutPostprocessor skips externally-positioned labels;
    LocationPostprocessor (the default position applier) is updated to handle
    them instead, so they still get a transform reflecting ELK's coordinates.
  • A new checkExternallyPositioned type guard in features/edge-layout/model.ts
    mirrors the existing checkEdgePlacement pattern.

The fix is opt-in: only labels positioned by an external engine are affected.
Existing diagrams that rely on EdgeLayoutPostprocessor's default behavior are
unchanged.

Testing

  • New unit test in packages/sprotty-elk/src/elk-layout.spec.ts verifies that
    the ELK adapter marks edge labels as externallyPositioned.
  • Existing tests in the same suite continue to pass.
  • Manually verified in the random-graph example with NODES = 2, EDGES = 1
    and an edge label, mirroring the issue's reproduction. With the fix applied,
    the label appears at ELK's chosen position; reverting the marker assignment
    reproduces the original bug.

Signed-off-by: Wagner Laranjeiras <wagner.laranjeiras@typefox.io>
Signed-off-by: Wagner Laranjeiras <wagner.laranjeiras@typefox.io>
@Wagner-Laranjeiras Wagner-Laranjeiras changed the title Wagner laranjeiras/514/edge label positioning Edge label positioning Jun 3, 2026
@gfontorbe

Copy link
Copy Markdown
Contributor

Hi @Wagner-Laranjeiras , thanks for the contribution.

This is a good start. However the approach completely bypasses the post-processing if the label has been placed by ELK. This create the issue that rotation and bounding to the edge are not preserved (making every label "free").

Ideally this should also be layout engine agnostic and not depend on sprotty-elk

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.

ELK Edge Label is not positioned correctly

2 participants