mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-01 14:46:41 +02:00
#945 Increasing size, handling forks and joins in multiple directions
This commit is contained in:
24
dist/index.html
vendored
24
dist/index.html
vendored
@@ -420,8 +420,30 @@ class Class10 {
|
|||||||
</div>
|
</div>
|
||||||
<div class="mermaid">
|
<div class="mermaid">
|
||||||
stateDiagram
|
stateDiagram
|
||||||
s1
|
State1
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
<div class="mermaid">
|
||||||
|
stateDiagram
|
||||||
|
[*] --> First
|
||||||
|
state First {
|
||||||
|
[*] --> second
|
||||||
|
second --> [*]
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<div class="mermaid">
|
||||||
|
stateDiagram
|
||||||
|
State1: The state with a note
|
||||||
|
note right of State1
|
||||||
|
Important information! You can write
|
||||||
|
notes.
|
||||||
|
end note
|
||||||
|
State1 --> State2
|
||||||
|
note left of State2 : This is the note to the left.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<script src="./mermaid.js"></script>
|
<script src="./mermaid.js"></script>
|
||||||
<script>
|
<script>
|
||||||
mermaid.initialize({
|
mermaid.initialize({
|
||||||
|
@@ -206,7 +206,7 @@ const drawForkJoinState = (g, stateDef) => {
|
|||||||
let width = 70;
|
let width = 70;
|
||||||
let height = 7;
|
let height = 7;
|
||||||
|
|
||||||
if (Math.PI > 3 || stateDef.parentId) {
|
if (stateDef.parentId) {
|
||||||
let tmp = width;
|
let tmp = width;
|
||||||
width = height;
|
width = height;
|
||||||
height = tmp;
|
height = tmp;
|
||||||
@@ -296,6 +296,8 @@ export const drawNote = (text, g) => {
|
|||||||
* @param {*} elem
|
* @param {*} elem
|
||||||
* @param {*} stateDef
|
* @param {*} stateDef
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
let cnt = 0;
|
||||||
export const drawState = function(elem, stateDef, graph, doc) {
|
export const drawState = function(elem, stateDef, graph, doc) {
|
||||||
const id = stateDef.id;
|
const id = stateDef.id;
|
||||||
const stateInfo = {
|
const stateInfo = {
|
||||||
|
@@ -38,6 +38,7 @@ let currentDocument = documents.root;
|
|||||||
|
|
||||||
let startCnt = 0;
|
let startCnt = 0;
|
||||||
let endCnt = 0;
|
let endCnt = 0;
|
||||||
|
let stateCnt = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function called by parser when a node definition has been found.
|
* Function called by parser when a node definition has been found.
|
||||||
|
@@ -94,7 +94,7 @@ export const draw = function(text, id) {
|
|||||||
|
|
||||||
diagram.attr('height', '100%');
|
diagram.attr('height', '100%');
|
||||||
// diagram.attr('width', 'fit-content');
|
// diagram.attr('width', 'fit-content');
|
||||||
diagram.attr('style', `max-width: ${bounds.width * 1.5 + conf.padding * 2};`);
|
diagram.attr('style', `width: ${bounds.width * 3 + conf.padding * 2};`);
|
||||||
diagram.attr(
|
diagram.attr(
|
||||||
'viewBox',
|
'viewBox',
|
||||||
`${conf.padding * -1} ${conf.padding * -1} ` +
|
`${conf.padding * -1} ${conf.padding * -1} ` +
|
||||||
@@ -152,6 +152,7 @@ const renderDoc = (doc, diagram, parentId) => {
|
|||||||
|
|
||||||
total = keys.length;
|
total = keys.length;
|
||||||
let first = true;
|
let first = true;
|
||||||
|
|
||||||
for (let i = 0; i < keys.length; i++) {
|
for (let i = 0; i < keys.length; i++) {
|
||||||
const stateDef = states[keys[i]];
|
const stateDef = states[keys[i]];
|
||||||
|
|
||||||
@@ -227,11 +228,12 @@ const renderDoc = (doc, diagram, parentId) => {
|
|||||||
dagre.layout(graph);
|
dagre.layout(graph);
|
||||||
|
|
||||||
logger.debug('Graph after layout', graph.nodes());
|
logger.debug('Graph after layout', graph.nodes());
|
||||||
|
const svgElem = diagram.node();
|
||||||
|
|
||||||
graph.nodes().forEach(function(v) {
|
graph.nodes().forEach(function(v) {
|
||||||
if (typeof v !== 'undefined' && typeof graph.node(v) !== 'undefined') {
|
if (typeof v !== 'undefined' && typeof graph.node(v) !== 'undefined') {
|
||||||
logger.debug('Node ' + v + ': ' + JSON.stringify(graph.node(v)));
|
logger.warn('Node ' + v + ': ' + JSON.stringify(graph.node(v)));
|
||||||
d3.select('#' + v).attr(
|
d3.select('#' + svgElem.id + ' #' + v).attr(
|
||||||
'transform',
|
'transform',
|
||||||
'translate(' +
|
'translate(' +
|
||||||
(graph.node(v).x - graph.node(v).width / 2) +
|
(graph.node(v).x - graph.node(v).width / 2) +
|
||||||
@@ -241,15 +243,17 @@ const renderDoc = (doc, diagram, parentId) => {
|
|||||||
graph.node(v).height / 2) +
|
graph.node(v).height / 2) +
|
||||||
' )'
|
' )'
|
||||||
);
|
);
|
||||||
d3.select('#' + v).attr('data-x-shift', graph.node(v).x - graph.node(v).width / 2);
|
d3.select('#' + svgElem.id + ' #' + v).attr(
|
||||||
const dividers = document.querySelectorAll('#' + v + ' .divider');
|
'data-x-shift',
|
||||||
|
graph.node(v).x - graph.node(v).width / 2
|
||||||
|
);
|
||||||
|
const dividers = document.querySelectorAll('#' + svgElem.id + ' #' + v + ' .divider');
|
||||||
dividers.forEach(divider => {
|
dividers.forEach(divider => {
|
||||||
const parent = divider.parentElement;
|
const parent = divider.parentElement;
|
||||||
let pWidth = 0;
|
let pWidth = 0;
|
||||||
let pShift = 0;
|
let pShift = 0;
|
||||||
if (parent) {
|
if (parent) {
|
||||||
if (parent.parentElement) pWidth = parent.parentElement.getBBox().width;
|
if (parent.parentElement) pWidth = parent.parentElement.getBBox().width;
|
||||||
|
|
||||||
pShift = parseInt(parent.getAttribute('data-x-shift'), 10);
|
pShift = parseInt(parent.getAttribute('data-x-shift'), 10);
|
||||||
if (Number.isNaN(pShift)) {
|
if (Number.isNaN(pShift)) {
|
||||||
pShift = 0;
|
pShift = 0;
|
||||||
@@ -263,7 +267,7 @@ const renderDoc = (doc, diagram, parentId) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let stateBox = diagram.node().getBBox();
|
let stateBox = svgElem.getBBox();
|
||||||
|
|
||||||
graph.edges().forEach(function(e) {
|
graph.edges().forEach(function(e) {
|
||||||
if (typeof e !== 'undefined' && typeof graph.edge(e) !== 'undefined') {
|
if (typeof e !== 'undefined' && typeof graph.edge(e) !== 'undefined') {
|
||||||
@@ -272,7 +276,8 @@ const renderDoc = (doc, diagram, parentId) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
stateBox = diagram.node().getBBox();
|
stateBox = svgElem.getBBox();
|
||||||
|
console.warn('Diagram node', svgElem.id);
|
||||||
const stateInfo = {
|
const stateInfo = {
|
||||||
id: parentId ? parentId : 'root',
|
id: parentId ? parentId : 'root',
|
||||||
label: parentId ? parentId : 'root',
|
label: parentId ? parentId : 'root',
|
||||||
|
Reference in New Issue
Block a user