-
Notifications
You must be signed in to change notification settings - Fork 718
Description
Preflight Checklist
- I agree to follow the [Code of Conduct](https://github.com/jgraph/drawio/blob/dev/CODE_OF_CONDUCT.md) that this project adheres to.
- I have searched the issue tracker for a bug report that matches the one I want to file, without success.
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
- Create an edge with a label in draw.io
- Drag the label along the edge
- The label jumps to a far-off position
- Open Extras → Edit Diagram — the XML shows an abnormally large
xvalue inmxGeometry
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.