#945Renabling support for descriptions

This commit is contained in:
Knut Sveidqvist
2019-10-05 12:15:14 +02:00
parent cfc14ade2a
commit 3b731282e3
3 changed files with 21 additions and 5 deletions

View File

@@ -13,6 +13,21 @@ describe('State diagram', () => {
); );
cy.get('svg'); cy.get('svg');
}); });
it('should render a states with descriptions including multi-line descriptions', () => {
imgSnapshotTest(
`
stateDiagram
State1: This a a single line description
State2: This a a multi line description
State2: here comes the multi part
[*] --> State1
State1 --> State2
State2 --> [*]
`,
{ logLevel: 0 }
);
cy.get('svg');
});
it('should render a simple state diagrams', () => { it('should render a simple state diagrams', () => {
imgSnapshotTest( imgSnapshotTest(
` `

View File

@@ -109,7 +109,7 @@ line
; ;
statement statement
: idStatement DESCR { $$={ stmt: 'state', id: $1, type: 'default', description: $2.trim()};} : idStatement DESCR { console.warn('got id and descr', $1, $2.trim());$$={ stmt: 'state', id: $1, type: 'default', description: $2.trim()};}
| idStatement '-->' idStatement | idStatement '-->' idStatement
{ {
/*console.warn('got id', $1);yy.addRelation($1, $3);*/ /*console.warn('got id', $1);yy.addRelation($1, $3);*/

View File

@@ -14,7 +14,7 @@ const extract = doc => {
doc.forEach(item => { doc.forEach(item => {
if (item.stmt === 'state') { if (item.stmt === 'state') {
addState(item.id, item.type, item.doc); addState(item.id, item.type, item.doc, item.description);
} }
if (item.stmt === 'relation') { if (item.stmt === 'relation') {
addRelation(item.state1.id, item.state2.id, item.description); addRelation(item.state1.id, item.state2.id, item.description);
@@ -46,7 +46,7 @@ let endCnt = 0;
* @param type * @param type
* @param style * @param style
*/ */
export const addState = function(id, type, doc) { export const addState = function(id, type, doc, descr) {
console.warn('Add state', id); console.warn('Add state', id);
if (typeof currentDocument.states[id] === 'undefined') { if (typeof currentDocument.states[id] === 'undefined') {
currentDocument.states[id] = { currentDocument.states[id] = {
@@ -63,6 +63,7 @@ export const addState = function(id, type, doc) {
currentDocument.states[id].type = type; currentDocument.states[id].type = type;
} }
} }
if (descr) addDescription(id, descr.trim());
}; };
export const clear = function() { export const clear = function() {
@@ -107,7 +108,7 @@ export const addRelation = function(_id1, _id2, title) {
currentDocument.relations.push({ id1, id2, title }); currentDocument.relations.push({ id1, id2, title });
}; };
export const addDescription = function(id, _descr) { const addDescription = function(id, _descr) {
const theState = currentDocument.states[id]; const theState = currentDocument.states[id];
let descr = _descr; let descr = _descr;
if (descr[0] === ':') { if (descr[0] === ':') {
@@ -144,7 +145,7 @@ export default {
getStates, getStates,
getRelations, getRelations,
addRelation, addRelation,
addDescription, // addDescription,
cleanupLabel, cleanupLabel,
lineType, lineType,
relationType, relationType,