mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-20 07:49:43 +02:00
#1022 Fix for long names for state diagrams
This commit is contained in:
@@ -13,6 +13,30 @@ describe('State diagram', () => {
|
|||||||
);
|
);
|
||||||
cy.get('svg');
|
cy.get('svg');
|
||||||
});
|
});
|
||||||
|
it('should render a long descriptions instead of id when available', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`
|
||||||
|
stateDiagram
|
||||||
|
|
||||||
|
[*] --> S1
|
||||||
|
state "Some long name" as S1
|
||||||
|
`,
|
||||||
|
{ logLevel: 0 }
|
||||||
|
);
|
||||||
|
cy.get('svg');
|
||||||
|
});
|
||||||
|
it('should render a long descriptions with additional descriptions', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`
|
||||||
|
stateDiagram
|
||||||
|
|
||||||
|
[*] --> S1
|
||||||
|
state "Some long name" as S1: The description
|
||||||
|
`,
|
||||||
|
{ logLevel: 0 }
|
||||||
|
);
|
||||||
|
cy.get('svg');
|
||||||
|
});
|
||||||
it('should render a single state with short descr', () => {
|
it('should render a single state with short descr', () => {
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
`
|
`
|
||||||
|
@@ -133,7 +133,17 @@ statement
|
|||||||
/* console.warn('Adding document for state without id ', $1);*/
|
/* console.warn('Adding document for state without id ', $1);*/
|
||||||
$$={ stmt: 'state', id: $1, type: 'default', description: '', doc: $3 }
|
$$={ stmt: 'state', id: $1, type: 'default', description: '', doc: $3 }
|
||||||
}
|
}
|
||||||
| STATE_DESCR AS ID { $$={stmt: 'state', id: $3, type: 'default', description: $1.trim()};}
|
| STATE_DESCR AS ID {
|
||||||
|
var id=$3;
|
||||||
|
var description = $1.trim();
|
||||||
|
if($3.match(':')){
|
||||||
|
var parts = $3.split(':');
|
||||||
|
id=parts[0];
|
||||||
|
description = [description, parts[1]];
|
||||||
|
}
|
||||||
|
$$={stmt: 'state', id: id, type: 'default', description: description};
|
||||||
|
|
||||||
|
}
|
||||||
| STATE_DESCR AS ID STRUCT_START document STRUCT_STOP
|
| STATE_DESCR AS ID STRUCT_START document STRUCT_STOP
|
||||||
{
|
{
|
||||||
//console.warn('Adding document for state with id ', $3, $4); yy.addDocument($3);
|
//console.warn('Adding document for state with id ', $3, $4); yy.addDocument($3);
|
||||||
|
@@ -76,7 +76,7 @@ export const drawDescrState = (g, stateDef) => {
|
|||||||
.attr('y', getConfig().state.textHeight + 1.5 * getConfig().state.padding)
|
.attr('y', getConfig().state.textHeight + 1.5 * getConfig().state.padding)
|
||||||
.attr('font-size', getConfig().state.fontSize)
|
.attr('font-size', getConfig().state.fontSize)
|
||||||
.attr('class', 'state-title')
|
.attr('class', 'state-title')
|
||||||
.text(stateDef.id);
|
.text(stateDef.descriptions[0]);
|
||||||
|
|
||||||
const titleBox = title.node().getBBox();
|
const titleBox = title.node().getBBox();
|
||||||
const titleHeight = titleBox.height;
|
const titleHeight = titleBox.height;
|
||||||
@@ -94,8 +94,12 @@ export const drawDescrState = (g, stateDef) => {
|
|||||||
.attr('class', 'state-description');
|
.attr('class', 'state-description');
|
||||||
|
|
||||||
let isFirst = true;
|
let isFirst = true;
|
||||||
|
let isSecond = true;
|
||||||
stateDef.descriptions.forEach(function(descr) {
|
stateDef.descriptions.forEach(function(descr) {
|
||||||
addTspan(description, descr, isFirst);
|
if (!isFirst) {
|
||||||
|
addTspan(description, descr, isSecond);
|
||||||
|
isSecond = false;
|
||||||
|
}
|
||||||
isFirst = false;
|
isFirst = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -64,7 +64,14 @@ export const addState = function(id, type, doc, descr, note) {
|
|||||||
currentDocument.states[id].type = type;
|
currentDocument.states[id].type = type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (descr) addDescription(id, descr.trim());
|
if (descr) {
|
||||||
|
if (typeof descr === 'string') addDescription(id, descr.trim());
|
||||||
|
|
||||||
|
if (typeof descr === 'object') {
|
||||||
|
descr.forEach(des => addDescription(id, des.trim()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (note) currentDocument.states[id].note = note;
|
if (note) currentDocument.states[id].note = note;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user