Mermaid version b.10

This commit is contained in:
Knut Sveidqvist
2024-09-16 10:04:10 +02:00
parent 05989d06fa
commit 3730f1afbb
5 changed files with 25 additions and 8 deletions

View File

@@ -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 },

View File

@@ -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
>

View File

@@ -1,6 +1,6 @@
{
"name": "@mermaid-chart/mermaid",
"version": "11.1.0-b.7",
"version": "11.1.0-b.10",
"description": "Markdown-ish syntax for generating flowcharts, mindmaps, sequence diagrams, class diagrams, gantt charts, git graphs and more.",
"type": "module",
"module": "./dist/mermaid.core.mjs",

View File

@@ -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;

View File

@@ -34,19 +34,27 @@ const calcIntersectionPoint = (node, point) => {
const dx = point.x - node.x;
const dy = point.y - node.y;
const angle = Math.atan2(dy, dx) * (180 / Math.PI);
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 (angle > -30 && angle <= 30) {
if (angleDeg >= -criticalAngleDeg && angleDeg <= criticalAngleDeg) {
pos = 'r'; // Right
} else if (angle > 30 && angle <= 150) {
} else if (angleDeg > criticalAngleDeg && angleDeg <= 180 - criticalAngleDeg) {
pos = 'b'; // Bottom
} else if (angle <= -30 && angle > -150) {
} else if (angleDeg < -criticalAngleDeg && angleDeg >= -180 + criticalAngleDeg) {
pos = 't'; // Top
} else {
pos = 'l'; // Left
}
// console.log('angleDeg', angleDeg, 'pos', pos, criticalAngleDeg);
return { x: intersection.x, y: intersection.y, pos };
};