fix state diagram edge label position

This commit is contained in:
darshanr0107
2025-06-24 14:50:20 +05:30
parent e7970c66ee
commit 24257de8a6
2 changed files with 21 additions and 0 deletions

View File

@@ -638,6 +638,10 @@ export const insertEdge = function (elem, edge, clusterDb, diagramType, startNod
addEdgeMarkers(svgPath, edge, url, id, diagramType, strokeColor); addEdgeMarkers(svgPath, edge, url, id, diagramType, strokeColor);
if (!utils.isPointInDAttr(points, svgPath.attr('d'))) {
pointsHasChanged = true;
}
let paths = {}; let paths = {};
if (pointsHasChanged) { if (pointsHasChanged) {
paths.updatedPath = points; paths.updatedPath = points;

View File

@@ -884,6 +884,7 @@ export default {
runFunc, runFunc,
entityDecode, entityDecode,
insertTitle, insertTitle,
isPointInDAttr,
parseFontSize, parseFontSize,
InitIDGenerator, InitIDGenerator,
}; };
@@ -960,3 +961,19 @@ export function handleUndefinedAttr(
) { ) {
return attrValue ?? null; return attrValue ?? null;
} }
export function isPointInDAttr(points: Point[], dAttr: string) {
if (!points || points.length < 2 || !dAttr) {
return false;
}
const point = points[1];
const roundedX = Math.round(point.x);
const roundedY = Math.round(point.y);
const sanitizedD = dAttr.replace(/(\d+\.\d+)/g, (match) =>
Math.round(parseFloat(match)).toString()
);
return sanitizedD.includes(roundedX.toString()) || sanitizedD.includes(roundedY.toString());
}