diff --git a/cypress/platform/knsv-pos.html b/cypress/platform/knsv-pos.html index 34499a958..8f2b78652 100644 --- a/cypress/platform/knsv-pos.html +++ b/cypress/platform/knsv-pos.html @@ -208,8 +208,6 @@ }, edge1: { points: [ - // { x: 37.61160659790039, y: 24 }, - { x: 44.31547546386719, y: 38 }, { x: 44.31547546386719, y: 51.5 }, { x: 45.487048339120996, y: 54.32842712474619 }, diff --git a/cypress/platform/knsv2.html b/cypress/platform/knsv2.html index 1cd3282da..33e01e2ba 100644 --- a/cypress/platform/knsv2.html +++ b/cypress/platform/knsv2.html @@ -338,7 +338,7 @@ flowchart TD -
+--- title: hello2 config: @@ -426,7 +426,12 @@ flowchart LR++flowchart TB + c1-->a2 +flowchart TB c1-->a2 @@ -439,6 +444,7 @@ flowchart TB subgraph three c1-->c2 end + c2diff --git a/packages/mermaid/src/diagrams/flowchart/flowDb.ts b/packages/mermaid/src/diagrams/flowchart/flowDb.ts index 78260e967..08bf7e5ef 100644 --- a/packages/mermaid/src/diagrams/flowchart/flowDb.ts +++ b/packages/mermaid/src/diagrams/flowchart/flowDb.ts @@ -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; diff --git a/packages/mermaid/src/rendering-util/layout-algorithms/fixed/index.js b/packages/mermaid/src/rendering-util/layout-algorithms/fixed/index.js index 8c059fcfc..75c5b9db6 100644 --- a/packages/mermaid/src/rendering-util/layout-algorithms/fixed/index.js +++ b/packages/mermaid/src/rendering-util/layout-algorithms/fixed/index.js @@ -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 }; };