Skip to content

Commit e7f6b4b

Browse files
committed
Fix fallback arrow: derive position and angle from smooth-step path geometry
1 parent 4121f31 commit e7f6b4b

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

src/lib/components/edges/OrthogonalEdge.svelte

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -505,13 +505,19 @@
505505
return { x: endPoint.x, y: endPoint.y, angle };
506506
}
507507
508-
// Fallback (smoothstep): arrow based on target position, use unadjusted target
509-
let angle = 0;
510-
if (targetPosition === 'left') angle = 180;
511-
else if (targetPosition === 'top') angle = -90;
512-
else if (targetPosition === 'bottom') angle = 90;
508+
// Fallback (smoothstep): derive arrow position and angle from SVG path geometry
509+
const { path } = pathInfo();
510+
if (path) {
511+
const svgPath = document.createElementNS('http://www.w3.org/2000/svg', 'path');
512+
svgPath.setAttribute('d', path);
513+
const totalLength = svgPath.getTotalLength();
514+
const endPoint = svgPath.getPointAtLength(totalLength);
515+
const nearEnd = svgPath.getPointAtLength(totalLength - 5);
516+
const angle = Math.atan2(endPoint.y - nearEnd.y, endPoint.x - nearEnd.x) * (180 / Math.PI);
517+
return { x: endPoint.x, y: endPoint.y, angle };
518+
}
513519
514-
return { x: targetX, y: targetY, angle };
520+
return { x: tgt.x, y: tgt.y, angle: 0 };
515521
});
516522
</script>
517523

0 commit comments

Comments
 (0)