Skip to content

Label geometry x=1433 corruption when dragging edge label - division by near-zero totalLength in getRelativePoint #5498

@PeoTiko

Description

@PeoTiko

Preflight Checklist

Describe the bug
When dragging an edge label, it flies to an extremely distant position, causing the canvas to expand massively. The corrupted XML shows geometry x="1433" — far outside the valid range of -1 to 1 for relative mode.

To Reproduce

  1. Create an edge with a label in draw.io
  2. Drag the label along the edge
  3. The label jumps to a far-off position
  4. Open Extras → Edit Diagram — the XML shows an abnormally large x value in mxGeometry

Expected behavior
The label stays near the edge. geometry.x should remain within [-1, 1] in relative mode.

Root Cause (technical)
The bug is in mxGraphView.prototype.getRelativePoint in mxGraphView.js:

return new mxPoint(
    ((totalLength / 2 - length - projlen) / totalLength) * -2,
    yDistance / this.scale
);

When edgeState.length (totalLength) is zero or near-zero at the moment dragging begins, the division produces an extremely large value (e.g. 143.3), which then gets written into geometry.x as 1433 via moveLabel:

geometry.x = Math.round(pt.x * 10000) / 10000;

Corrupted XML example

<mxGeometry x="1433" y="-1" relative="1" as="geometry">

Suggested Fix
Clamp the result before returning:

if (totalLength === 0) {
    return new mxPoint(0, 0);
}
var resultX = ((totalLength / 2 - length - projlen) / totalLength) * -2;
resultX = Math.max(-1, Math.min(1, resultX));
return new mxPoint(resultX, yDistance / this.scale);

draw.io version: 28.1.1
Desktop:

  • OS: Windows 11

Tested in incognito mode with extensions off: yes

Additional context
None.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions