mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-14 22:09:29 +02:00
fix state diagram edge label position
This commit is contained in:
@@ -638,6 +638,10 @@ export const insertEdge = function (elem, edge, clusterDb, diagramType, startNod
|
||||
|
||||
addEdgeMarkers(svgPath, edge, url, id, diagramType, strokeColor);
|
||||
|
||||
if (!utils.isPointInDAttr(points, svgPath.attr('d'))) {
|
||||
pointsHasChanged = true;
|
||||
}
|
||||
|
||||
let paths = {};
|
||||
if (pointsHasChanged) {
|
||||
paths.updatedPath = points;
|
||||
|
@@ -884,6 +884,7 @@ export default {
|
||||
runFunc,
|
||||
entityDecode,
|
||||
insertTitle,
|
||||
isPointInDAttr,
|
||||
parseFontSize,
|
||||
InitIDGenerator,
|
||||
};
|
||||
@@ -960,3 +961,19 @@ export function handleUndefinedAttr(
|
||||
) {
|
||||
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());
|
||||
}
|
||||
|
Reference in New Issue
Block a user