From 3b731282e3be4eb42fb37f1367ce89986a69cc12 Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Sat, 5 Oct 2019 12:15:14 +0200 Subject: [PATCH] #945Renabling support for descriptions --- .../integration/rendering/stateDiagram.spec.js | 15 +++++++++++++++ src/diagrams/state/parser/stateDiagram.jison | 2 +- src/diagrams/state/stateDb.js | 9 +++++---- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/cypress/integration/rendering/stateDiagram.spec.js b/cypress/integration/rendering/stateDiagram.spec.js index f1fc7cea8..f71a725cc 100644 --- a/cypress/integration/rendering/stateDiagram.spec.js +++ b/cypress/integration/rendering/stateDiagram.spec.js @@ -13,6 +13,21 @@ describe('State diagram', () => { ); 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', () => { imgSnapshotTest( ` diff --git a/src/diagrams/state/parser/stateDiagram.jison b/src/diagrams/state/parser/stateDiagram.jison index 9ab2d24db..f1ed4786b 100644 --- a/src/diagrams/state/parser/stateDiagram.jison +++ b/src/diagrams/state/parser/stateDiagram.jison @@ -109,7 +109,7 @@ line ; 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 { /*console.warn('got id', $1);yy.addRelation($1, $3);*/ diff --git a/src/diagrams/state/stateDb.js b/src/diagrams/state/stateDb.js index 266de58d4..96c7f5544 100644 --- a/src/diagrams/state/stateDb.js +++ b/src/diagrams/state/stateDb.js @@ -14,7 +14,7 @@ const extract = doc => { doc.forEach(item => { if (item.stmt === 'state') { - addState(item.id, item.type, item.doc); + addState(item.id, item.type, item.doc, item.description); } if (item.stmt === 'relation') { addRelation(item.state1.id, item.state2.id, item.description); @@ -46,7 +46,7 @@ let endCnt = 0; * @param type * @param style */ -export const addState = function(id, type, doc) { +export const addState = function(id, type, doc, descr) { console.warn('Add state', id); if (typeof currentDocument.states[id] === 'undefined') { currentDocument.states[id] = { @@ -63,6 +63,7 @@ export const addState = function(id, type, doc) { currentDocument.states[id].type = type; } } + if (descr) addDescription(id, descr.trim()); }; export const clear = function() { @@ -107,7 +108,7 @@ export const addRelation = function(_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]; let descr = _descr; if (descr[0] === ':') { @@ -144,7 +145,7 @@ export default { getStates, getRelations, addRelation, - addDescription, + // addDescription, cleanupLabel, lineType, relationType,