mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-21 16:29:40 +02:00
Merge branch 'neo-new-shapes' into sidv/configReturn
* neo-new-shapes: Mermaid version b.10 Fix for issue with incorrect calculations of which edge a line intersects with
This commit is contained in:
@@ -137,6 +137,11 @@ export const addVertex = function (
|
||||
}
|
||||
}
|
||||
const doc = yaml.load(yamlData, { schema: yaml.JSON_SCHEMA }) as NodeMetaData;
|
||||
|
||||
if (doc.shape && doc.shape !== doc.shape.toLowerCase()) {
|
||||
throw new Error(`No such shape: ${node.shape}. Shape names should be lowercase.`);
|
||||
}
|
||||
|
||||
// console.log('yamlData doc', doc);
|
||||
if (doc?.shape) {
|
||||
vertex.type = doc?.shape;
|
||||
|
@@ -30,18 +30,31 @@ let nodeDB = new Map();
|
||||
|
||||
const calcIntersectionPoint = (node, point) => {
|
||||
const intersection = node.intersect(point);
|
||||
const dx = intersection.x - node.x;
|
||||
const dy = intersection.y - node.y;
|
||||
|
||||
let pos = 'l';
|
||||
const dx = point.x - node.x;
|
||||
const dy = point.y - node.y;
|
||||
|
||||
// Determine the position of the intersection relative to the node
|
||||
if (Math.abs(dx) > Math.abs(dy)) {
|
||||
pos = dx > 0 ? 'r' : 'l'; // Right or left
|
||||
const angleRad = Math.atan2(dy, dx);
|
||||
const angleDeg = angleRad * (180 / Math.PI);
|
||||
|
||||
const halfWidth = node.width / 2;
|
||||
const halfHeight = node.height / 2;
|
||||
const criticalAngleRad = Math.atan2(halfHeight, halfWidth);
|
||||
const criticalAngleDeg = criticalAngleRad * (180 / Math.PI);
|
||||
|
||||
let pos;
|
||||
if (angleDeg >= -criticalAngleDeg && angleDeg <= criticalAngleDeg) {
|
||||
pos = 'r'; // Right
|
||||
} else if (angleDeg > criticalAngleDeg && angleDeg <= 180 - criticalAngleDeg) {
|
||||
pos = 'b'; // Bottom
|
||||
} else if (angleDeg < -criticalAngleDeg && angleDeg >= -180 + criticalAngleDeg) {
|
||||
pos = 't'; // Top
|
||||
} else {
|
||||
pos = dy > 0 ? 'b' : 't'; // Bottom or top
|
||||
pos = 'l'; // Left
|
||||
}
|
||||
|
||||
// console.log('angleDeg', angleDeg, 'pos', pos, criticalAngleDeg);
|
||||
|
||||
return { x: intersection.x, y: intersection.y, pos };
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user