mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-21 16:29:40 +02:00
refactor code
This commit is contained in:
@@ -637,8 +637,9 @@ export const insertEdge = function (elem, edge, clusterDb, diagramType, startNod
|
|||||||
log.info('arrowTypeEnd', edge.arrowTypeEnd);
|
log.info('arrowTypeEnd', edge.arrowTypeEnd);
|
||||||
|
|
||||||
addEdgeMarkers(svgPath, edge, url, id, diagramType, strokeColor);
|
addEdgeMarkers(svgPath, edge, url, id, diagramType, strokeColor);
|
||||||
|
const midIndex = Math.floor(points.length / 2);
|
||||||
if (!utils.isPointInDAttr(points, svgPath.attr('d'))) {
|
const point = points[midIndex];
|
||||||
|
if (!utils.isLabelCoordinateInPath(point, svgPath.attr('d'))) {
|
||||||
pointsHasChanged = true;
|
pointsHasChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -884,7 +884,7 @@ export default {
|
|||||||
runFunc,
|
runFunc,
|
||||||
entityDecode,
|
entityDecode,
|
||||||
insertTitle,
|
insertTitle,
|
||||||
isPointInDAttr,
|
isLabelCoordinateInPath,
|
||||||
parseFontSize,
|
parseFontSize,
|
||||||
InitIDGenerator,
|
InitIDGenerator,
|
||||||
};
|
};
|
||||||
@@ -962,12 +962,16 @@ export function handleUndefinedAttr(
|
|||||||
return attrValue ?? null;
|
return attrValue ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isPointInDAttr(points: Point[], dAttr: string) {
|
/**
|
||||||
if (!points || points.length < 2 || !dAttr) {
|
* Checks if the x or y coordinate of the edge label
|
||||||
return false;
|
* appears in the given SVG path data string.
|
||||||
}
|
*
|
||||||
|
* @param point - The Point object with x and y properties to check.
|
||||||
const point = points[1];
|
* @param dAttr - SVG path data string (the 'd' attribute of an SVG path element).
|
||||||
|
* @returns - True if the rounded x or y coordinate of the edge label is found
|
||||||
|
* in the sanitized path data string; otherwise, false.
|
||||||
|
*/
|
||||||
|
export function isLabelCoordinateInPath(point: Point, dAttr: string) {
|
||||||
const roundedX = Math.round(point.x);
|
const roundedX = Math.round(point.x);
|
||||||
const roundedY = Math.round(point.y);
|
const roundedY = Math.round(point.y);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user