mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-10 02:49:40 +02:00
Directive support added to journey
Fixed an issue in journey svgDraw.drawText expected an attribute (textMargin) but did not receive one and raised an error: <tspan> attribute x: Expected length, "NaN". Added parseDirective to journeyDb
This commit is contained in:
@@ -224,6 +224,7 @@ erDiagram
|
|||||||
it('should render a user journey diagram', () => {
|
it('should render a user journey diagram', () => {
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
`
|
`
|
||||||
|
%%{init: { 'logLevel': 0, 'theme': '${theme}'} }%%
|
||||||
journey
|
journey
|
||||||
title My working day
|
title My working day
|
||||||
section Go to work
|
section Go to work
|
||||||
@@ -232,8 +233,7 @@ erDiagram
|
|||||||
Do work: 1: Me, Cat
|
Do work: 1: Me, Cat
|
||||||
section Go home
|
section Go home
|
||||||
Go downstairs: 5: Me
|
Go downstairs: 5: Me
|
||||||
Sit down: 5: Me `,
|
Sit down: 5: Me `
|
||||||
{theme}
|
|
||||||
);
|
);
|
||||||
cy.get('svg');
|
cy.get('svg');
|
||||||
});
|
});
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
import mermaidAPI from '../../mermaidAPI';
|
||||||
|
|
||||||
let title = '';
|
let title = '';
|
||||||
let currentSection = '';
|
let currentSection = '';
|
||||||
|
|
||||||
@@ -5,6 +7,10 @@ const sections = [];
|
|||||||
const tasks = [];
|
const tasks = [];
|
||||||
const rawTasks = [];
|
const rawTasks = [];
|
||||||
|
|
||||||
|
export const parseDirective = function(statement, context, type) {
|
||||||
|
mermaidAPI.parseDirective(statement, context, type);
|
||||||
|
};
|
||||||
|
|
||||||
export const clear = function() {
|
export const clear = function() {
|
||||||
sections.length = 0;
|
sections.length = 0;
|
||||||
tasks.length = 0;
|
tasks.length = 0;
|
||||||
@@ -111,6 +117,7 @@ const getActors = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
parseDirective,
|
||||||
clear,
|
clear,
|
||||||
setTitle,
|
setTitle,
|
||||||
getTitle,
|
getTitle,
|
||||||
|
@@ -70,7 +70,8 @@ function drawActorLegend(diagram) {
|
|||||||
x: 40,
|
x: 40,
|
||||||
y: yPos + 7,
|
y: yPos + 7,
|
||||||
fill: '#666',
|
fill: '#666',
|
||||||
text: person
|
text: person,
|
||||||
|
textMargin: conf.boxTextMargin | 5
|
||||||
};
|
};
|
||||||
svgDraw.drawText(diagram, labelData);
|
svgDraw.drawText(diagram, labelData);
|
||||||
|
|
||||||
|
@@ -5,12 +5,24 @@
|
|||||||
*/
|
*/
|
||||||
%lex
|
%lex
|
||||||
%options case-insensitive
|
%options case-insensitive
|
||||||
|
|
||||||
|
// Directive states
|
||||||
|
%x OPEN_DIRECTIVE
|
||||||
|
%x TYPE_DIRECTIVE
|
||||||
|
%x ARG_DIRECTIVE
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
|
\%\%\{ { this.begin('OPEN_DIRECTIVE'); return 'open_directive'; }
|
||||||
|
<OPEN_DIRECTIVE>((?:(?!\}\%\%)[^:.])*) { this.begin('TYPE_DIRECTIVE'); return 'type_directive'; }
|
||||||
|
<TYPE_DIRECTIVE>":" { this.popState(); this.begin('ARG_DIRECTIVE'); return ':'; }
|
||||||
|
<TYPE_DIRECTIVE,ARG_DIRECTIVE>\}\%\% { this.popState(); this.popState(); return 'close_directive'; }
|
||||||
|
<ARG_DIRECTIVE>((?:(?!\}\%\%).|\n)*) return 'arg_directive';
|
||||||
|
\%%(?!\{)[^\n]* /* skip comments */
|
||||||
|
[^\}]\%\%[^\n]* /* skip comments */
|
||||||
[\n]+ return 'NL';
|
[\n]+ return 'NL';
|
||||||
\s+ /* skip whitespace */
|
\s+ /* skip whitespace */
|
||||||
\#[^\n]* /* skip comments */
|
\#[^\n]* /* skip comments */
|
||||||
\%%[^\n]* /* skip comments */
|
|
||||||
|
|
||||||
"journey" return 'journey';
|
"journey" return 'journey';
|
||||||
"title"\s[^#\n;]+ return 'title';
|
"title"\s[^#\n;]+ return 'title';
|
||||||
@@ -31,6 +43,7 @@
|
|||||||
|
|
||||||
start
|
start
|
||||||
: journey document 'EOF' { return $2; }
|
: journey document 'EOF' { return $2; }
|
||||||
|
| directive start
|
||||||
;
|
;
|
||||||
|
|
||||||
document
|
document
|
||||||
@@ -45,8 +58,32 @@ line
|
|||||||
| EOF { $$=[];}
|
| EOF { $$=[];}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
directive
|
||||||
|
: openDirective typeDirective closeDirective 'NL'
|
||||||
|
| openDirective typeDirective ':' argDirective closeDirective 'NL'
|
||||||
|
;
|
||||||
|
|
||||||
statement
|
statement
|
||||||
: title {yy.setTitle($1.substr(6));$$=$1.substr(6);}
|
: title {yy.setTitle($1.substr(6));$$=$1.substr(6);}
|
||||||
| section {yy.addSection($1.substr(8));$$=$1.substr(8);}
|
| section {yy.addSection($1.substr(8));$$=$1.substr(8);}
|
||||||
| taskName taskData {yy.addTask($1, $2);$$='task';}
|
| taskName taskData {yy.addTask($1, $2);$$='task';}
|
||||||
|
| directive
|
||||||
;
|
;
|
||||||
|
|
||||||
|
openDirective
|
||||||
|
: open_directive { yy.parseDirective('%%{', 'open_directive'); }
|
||||||
|
;
|
||||||
|
|
||||||
|
typeDirective
|
||||||
|
: type_directive { yy.parseDirective($1, 'type_directive'); }
|
||||||
|
;
|
||||||
|
|
||||||
|
argDirective
|
||||||
|
: arg_directive { $1 = $1.trim().replace(/'/g, '"'); yy.parseDirective($1, 'arg_directive'); }
|
||||||
|
;
|
||||||
|
|
||||||
|
closeDirective
|
||||||
|
: close_directive { yy.parseDirective('}%%', 'close_directive', 'sequence'); }
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
@@ -16,6 +16,7 @@ const themes = {
|
|||||||
gantt,
|
gantt,
|
||||||
classDiagram,
|
classDiagram,
|
||||||
'classDiagram-v2': classDiagram,
|
'classDiagram-v2': classDiagram,
|
||||||
|
class: classDiagram,
|
||||||
stateDiagram,
|
stateDiagram,
|
||||||
state: stateDiagram,
|
state: stateDiagram,
|
||||||
git,
|
git,
|
||||||
|
Reference in New Issue
Block a user