mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-09 10:36:43 +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:
@@ -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 },
|
||||
|
@@ -338,7 +338,7 @@ flowchart TD
|
||||
|
||||
|
||||
</pre>
|
||||
<pre id="diagram" class="mermaid">
|
||||
<pre id="diagram" class="mermaid2">
|
||||
---
|
||||
title: hello2
|
||||
config:
|
||||
@@ -426,7 +426,12 @@ flowchart LR
|
||||
|
||||
</pre
|
||||
>
|
||||
<pre id="diagram3" class="mermaid">
|
||||
flowchart TB
|
||||
c1-->a2
|
||||
|
||||
</pre
|
||||
>
|
||||
<pre id="diagram3" class="mermaid2">
|
||||
flowchart TB
|
||||
c1-->a2
|
||||
@@ -439,6 +444,7 @@ flowchart TB
|
||||
subgraph three
|
||||
c1-->c2
|
||||
end
|
||||
c2
|
||||
</pre
|
||||
>
|
||||
|
||||
|
@@ -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