mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-11-05 05:14:08 +01:00
Updated intersection calculations , Mermaid version 11.0.0-b.73
This commit is contained in:
@@ -102,9 +102,9 @@
|
|||||||
};
|
};
|
||||||
let code = `
|
let code = `
|
||||||
stateDiagram
|
stateDiagram
|
||||||
S:Stillas
|
S:S
|
||||||
T:Tiger
|
T:T
|
||||||
U:Ulv
|
U:U
|
||||||
state Z {
|
state Z {
|
||||||
state X {
|
state X {
|
||||||
Y:Ypsilon
|
Y:Ypsilon
|
||||||
@@ -115,13 +115,21 @@
|
|||||||
S --> T: angrepp
|
S --> T: angrepp
|
||||||
T --> U: Apa
|
T --> U: Apa
|
||||||
T --> V: Varg
|
T --> V: Varg
|
||||||
|
|
||||||
|
B
|
||||||
|
C
|
||||||
|
D
|
||||||
|
`;
|
||||||
|
code = `
|
||||||
|
stateDiagram
|
||||||
|
A --> B: Hello
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const positions = {
|
let positions = {
|
||||||
nodes: {
|
nodes: {
|
||||||
S: { x: 0, y: 0 },
|
S: { x: 0, y: 0 },
|
||||||
T: { x: 100, y: 100, width: 100, height: 100 },
|
T: { x: 100, y: 100, width: 100, height: 100 },
|
||||||
U: { x: 200, y: 200 },
|
U: { x: 250, y: 160 },
|
||||||
V: { x: 300, y: 120 },
|
V: { x: 300, y: 120 },
|
||||||
Z: { x: 300, y: 10, width: 160, height: 100 },
|
Z: { x: 300, y: 10, width: 160, height: 100 },
|
||||||
X: { x: 300, y: 20, width: 80, height: 60 },
|
X: { x: 300, y: 20, width: 80, height: 60 },
|
||||||
@@ -137,9 +145,17 @@
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
edge1: {
|
edge1: {
|
||||||
|
// points: [
|
||||||
|
// { x: 100, y: 100 },
|
||||||
|
// { x: 200, y: 200 },
|
||||||
|
// ],
|
||||||
points: [
|
points: [
|
||||||
{ x: 100, y: 100 },
|
{ x: 100, y: 100 },
|
||||||
{ x: 200, y: 200 },
|
{ x: 150, y: 120 },
|
||||||
|
{ x: 190.19453144073486, y: 120 },
|
||||||
|
{ x: 190.19453144073486, y: 152.1556251525879 },
|
||||||
|
{ x: 230.38906288146973, y: 152.1556251525879 },
|
||||||
|
{ x: 250, y: 160 },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
edge2: {
|
edge2: {
|
||||||
@@ -153,13 +169,18 @@
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
positions = {
|
||||||
|
nodes: {},
|
||||||
|
edges: {},
|
||||||
|
};
|
||||||
|
|
||||||
const { svg } = await mermaid.render('the-id-of-the-svg', code, undefined, positions);
|
const { svg } = await mermaid.render('the-id-of-the-svg', code, undefined, positions);
|
||||||
if (window?.calcIntersections) {
|
// if (window?.calcIntersections) {
|
||||||
console.log('Intersections', window.calcIntersections(positions, 'S', 'T'));
|
// console.log('Intersections', window.calcIntersections(positions, 'T', 'U'));
|
||||||
} else {
|
// } else {
|
||||||
console.error('calcIntersections not found');
|
// console.error('calcIntersections not found');
|
||||||
}
|
// }
|
||||||
// console.log(svg);
|
console.log(JSON.stringify(positions));
|
||||||
const elem = document.querySelector('#diagram');
|
const elem = document.querySelector('#diagram');
|
||||||
elem.innerHTML = svg;
|
elem.innerHTML = svg;
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mermaid-chart/mermaid",
|
"name": "@mermaid-chart/mermaid",
|
||||||
"version": "11.0.0-b.67",
|
"version": "11.0.0-b.72",
|
||||||
"description": "Markdown-ish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.",
|
"description": "Markdown-ish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"module": "./dist/mermaid.core.mjs",
|
"module": "./dist/mermaid.core.mjs",
|
||||||
|
|||||||
@@ -45,9 +45,21 @@ const calcIntersectionPoint = (node, point) => {
|
|||||||
return { x: intersection.x, y: intersection.y, pos };
|
return { x: intersection.x, y: intersection.y, pos };
|
||||||
};
|
};
|
||||||
|
|
||||||
const calcIntersections = (points, startNodeId, endNodeId) => {
|
const calcIntersections = (points, startNodeId, endNodeId, startNodeSize, endNodeSize) => {
|
||||||
const startNode = nodeDB.get(startNodeId);
|
const startNode = nodeDB.get(startNodeId);
|
||||||
|
if (startNodeSize) {
|
||||||
|
startNode.x = startNodeSize.width;
|
||||||
|
startNode.y = startNodeSize.width;
|
||||||
|
startNode.width = startNodeSize.width;
|
||||||
|
startNode.height = startNodeSize.height;
|
||||||
|
}
|
||||||
const endNode = nodeDB.get(endNodeId);
|
const endNode = nodeDB.get(endNodeId);
|
||||||
|
if (endNodeSize) {
|
||||||
|
endNode.x = endNodeSize.width;
|
||||||
|
endNode.y = endNodeSize.width;
|
||||||
|
endNode.width = endNodeSize.width;
|
||||||
|
endNode.height = endNodeSize.height;
|
||||||
|
}
|
||||||
// Get the intersections
|
// Get the intersections
|
||||||
const startIntersection = calcIntersectionPoint(startNode, { x: endNode.x, y: endNode.y });
|
const startIntersection = calcIntersectionPoint(startNode, { x: endNode.x, y: endNode.y });
|
||||||
const endIntersection = calcIntersectionPoint(endNode, { x: startNode.x, y: startNode.y });
|
const endIntersection = calcIntersectionPoint(endNode, { x: startNode.x, y: startNode.y });
|
||||||
@@ -62,6 +74,15 @@ const doRender = async (_elem, data4Layout, siteConfig, positions) => {
|
|||||||
const edgeLabels = elem.insert('g').attr('class', 'edgeLabels');
|
const edgeLabels = elem.insert('g').attr('class', 'edgeLabels');
|
||||||
const nodes = elem.insert('g').attr('class', 'nodes');
|
const nodes = elem.insert('g').attr('class', 'nodes');
|
||||||
|
|
||||||
|
if (!positions?.nodes || !positions?.edges) {
|
||||||
|
positions = {};
|
||||||
|
if (!positions?.nodes) {
|
||||||
|
positions.nodes = {};
|
||||||
|
}
|
||||||
|
if (!positions?.edges) {
|
||||||
|
positions.edges = {};
|
||||||
|
}
|
||||||
|
}
|
||||||
// Add positions for nodes that lack them
|
// Add positions for nodes that lack them
|
||||||
let maxY = 0;
|
let maxY = 0;
|
||||||
data4Layout.nodes.map(function (node) {
|
data4Layout.nodes.map(function (node) {
|
||||||
|
|||||||
Reference in New Issue
Block a user