mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-15 14:29:25 +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);
|
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;
|
||||||
|
@@ -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());
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user