diff --git a/cypress/integration/rendering/stateDiagram.spec.js b/cypress/integration/rendering/stateDiagram.spec.js index 777359bd7..55c131da2 100644 --- a/cypress/integration/rendering/stateDiagram.spec.js +++ b/cypress/integration/rendering/stateDiagram.spec.js @@ -31,10 +31,10 @@ describe('State diagram', () => { imgSnapshotTest( ` stateDiagram - State1: The state with a note + State1: The state with a note with minus - and plus + in it note left of State1 Important information! You can write - notes. + notes with . and in them. end note `, { logLevel: 0 } @@ -45,12 +45,13 @@ describe('State diagram', () => { imgSnapshotTest( ` stateDiagram - State1: The state with a note + State1: The state with a note +,- note right of State1 - Important information! You can write + Important information! You can write +,- notes. end note - State1 --> State2 + State1 --> State2 : With +,- + note left of State2 : This is the note +,-
`, { logLevel: 0 } ); diff --git a/src/diagrams/state/parser/stateDiagram.jison b/src/diagrams/state/parser/stateDiagram.jison index 4a5c9c963..b05eb8c9c 100644 --- a/src/diagrams/state/parser/stateDiagram.jison +++ b/src/diagrams/state/parser/stateDiagram.jison @@ -65,14 +65,15 @@ [^"]* { console.log('Floating note text: ', yytext);return "NOTE_TEXT";} [^\n]* {this.popState();console.log('Floating note ID', yytext);return "ID";} \s*[^:\n\s\-]+ { this.popState();this.pushState('NOTE_TEXT');console.log('Got ID for note', yytext);return 'ID';} -\s*":"[^\+\-:\n,;]+ { this.popState();console.log('Got NOTE_TEXT for note',yytext);return 'NOTE_TEXT';} -\s*[^\+\-:,;]+"end note" { this.popState();console.log('Got NOTE_TEXT for note',yytext);yytext = yytext.slice(0,-8).trim();return 'NOTE_TEXT';} +\s*":"[^:\n;]+ { this.popState();console.log('Got NOTE_TEXT for note',yytext);yytext = yytext.substr(2).trim();return 'NOTE_TEXT';} +\s*[^:;]+"end note" { this.popState();console.log('Got NOTE_TEXT for note',yytext);yytext = yytext.slice(0,-8).trim();return 'NOTE_TEXT';} "stateDiagram"\s+ { console.log('Got state diagram', yytext,'#');return 'SD'; } "hide empty description" { console.log('HIDE_EMPTY', yytext,'#');return 'HIDE_EMPTY'; } "[*]" { console.log('EDGE_STATE=',yytext); return 'EDGE_STATE';} [^:\n\s\-\{]+ { console.log('=>ID=',yytext); return 'ID';} -\s*":"[^\+\->:\n,;]+ { yytext = yytext.trim(); console.log('Descr = ', yytext); return 'DESCR'; } +// \s*":"[^\+\->:\n;]+ { yytext = yytext.trim(); console.log('Descr = ', yytext); return 'DESCR'; } +\s*":"[^:\n;]+ { yytext = yytext.trim(); console.log('Descr = ', yytext); return 'DESCR'; } "-->" return '-->'; "--" return 'CONCURRENT'; <> return 'NL'; diff --git a/src/diagrams/state/shapes.js b/src/diagrams/state/shapes.js index 359404c73..8da33e594 100644 --- a/src/diagrams/state/shapes.js +++ b/src/diagrams/state/shapes.js @@ -205,16 +205,15 @@ const _drawLongText = (_text, x, y, g) => { if (txt.length > 0) { const span = textElem.append('tspan'); + span.text(txt); const textBounds = span.node().getBBox(); textHeight += textBounds.height; span.attr('x', x + conf.noteMargin); - span.attr('y', y + textHeight + 1.75 * conf.noteMargin); - span.text(txt); - - textWidth = Math.max(textBounds.width, textWidth); + span.attr('y', y + textHeight + 1.25* conf.noteMargin); + // textWidth = Math.max(textBounds.width, textWidth); } } - return { textWidth, textHeight }; + return { textWidth: textElem.node().getBBox().width, textHeight }; }; /** @@ -226,6 +225,7 @@ const _drawLongText = (_text, x, y, g) => { export const drawNote = (text, g) => { g.attr('class', 'note'); + console.warn('Text of note', text); const note = g .append('rect') .attr('x', 0) @@ -233,7 +233,7 @@ export const drawNote = (text, g) => { const rectElem = g.append('g'); const { textWidth, textHeight } = _drawLongText(text, 0, 0, rectElem); - + console.warn('Text of note', text, textWidth); note.attr('height', textHeight + 2 * conf.noteMargin); note.attr('width', textWidth + conf.noteMargin * 2); diff --git a/src/diagrams/state/stateDiagram.spec.js b/src/diagrams/state/stateDiagram.spec.js index d3e1bf93c..ee3152682 100644 --- a/src/diagrams/state/stateDiagram.spec.js +++ b/src/diagrams/state/stateDiagram.spec.js @@ -8,7 +8,7 @@ describe('state diagram, ', function() { parser.yy = stateDb; }); - fit('super simple', function() { + it('super simple', function() { const str = ` stateDiagram [*] --> State1 @@ -58,7 +58,7 @@ describe('state diagram, ', function() { scale 350 width [*] --> State1 State1 --> [*] - State1 : this is a string + State1 : this is a string with - in it State1 : this is another string State1 --> State2 @@ -71,7 +71,16 @@ describe('state diagram, ', function() { it('description after second state', function() { const str = `stateDiagram\n scale 350 width - [*] --> State1 : This is the description + [*] --> State1 : This is the description with - in it + State1 --> [*] + `; + + parser.parse(str); + }); + it('shall handle descriptions inkluding minus signs', function() { + const str = `stateDiagram\n + scale 350 width + [*] --> State1 : This is the description +-! State1 --> [*] `;