Merge pull request #2981 from Zumbala/develop
Sequence autonumbering and Git fix options parsing
This commit is contained in:
commit
fa514bc7bc
|
@ -385,8 +385,7 @@
|
||||||
A -->|Get money| B1[(Go shopping 1)]
|
A -->|Get money| B1[(Go shopping 1)]
|
||||||
A -->|Get money| B2[(Go shopping 2)]
|
A -->|Get money| B2[(Go shopping 2)]
|
||||||
A -->|Get money| B3[(Go shopping 3)]
|
A -->|Get money| B3[(Go shopping 3)]
|
||||||
C[(Let me think...<br />Do I want something for work,<br />something to spend every free second with,<br />or
|
C[(Let me think...<br />Do I want something for work,<br />something to spend every free second with,<br />or something to get around?)]
|
||||||
something to get around?)]
|
|
||||||
B1 --> C
|
B1 --> C
|
||||||
B2 --> C
|
B2 --> C
|
||||||
B3 --> C
|
B3 --> C
|
||||||
|
@ -518,8 +517,10 @@
|
||||||
sequenceDiagram
|
sequenceDiagram
|
||||||
autonumber
|
autonumber
|
||||||
Alice->>John: Hello John,<br>how are you?
|
Alice->>John: Hello John,<br>how are you?
|
||||||
|
autonumber 50 10
|
||||||
Alice->>John: John,<br />can you hear me?
|
Alice->>John: John,<br />can you hear me?
|
||||||
John-->>Alice: Hi Alice,<br />I can hear you!
|
John-->>Alice: Hi Alice,<br />I can hear you!
|
||||||
|
autonumber off
|
||||||
John-->>Alice: I feel great!
|
John-->>Alice: I feel great!
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -601,10 +602,11 @@
|
||||||
gitGraph:
|
gitGraph:
|
||||||
options
|
options
|
||||||
{
|
{
|
||||||
"nodeSpacing": 150,
|
"nodeSpacing": 50,
|
||||||
"nodeRadius": 10
|
"nodeRadius": 5
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
branch master
|
||||||
commit
|
commit
|
||||||
branch newbranch
|
branch newbranch
|
||||||
checkout newbranch
|
checkout newbranch
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
participant Alice
|
participant Alice
|
||||||
participant Bob
|
participant Bob
|
||||||
participant John as John<br />Second Line
|
participant John as John<br />Second Line
|
||||||
|
autonumber 10 10
|
||||||
rect rgb(200, 220, 100)
|
rect rgb(200, 220, 100)
|
||||||
rect rgb(200, 255, 200)
|
rect rgb(200, 255, 200)
|
||||||
Alice ->> Bob: Hello Bob, how are you?
|
Alice ->> Bob: Hello Bob, how are you?
|
||||||
|
@ -39,14 +40,17 @@
|
||||||
Bob-x John:wrap: John! Are you still debating about how you're doing? How long does it take??
|
Bob-x John:wrap: John! Are you still debating about how you're doing? How long does it take??
|
||||||
Note over John: After a few more moments, John<br />finally snaps out of it.
|
Note over John: After a few more moments, John<br />finally snaps out of it.
|
||||||
end
|
end
|
||||||
|
autonumber off
|
||||||
alt either this
|
alt either this
|
||||||
Alice->>+John: Yes
|
Alice->>+John: Yes
|
||||||
John-->>-Alice: OK
|
John-->>-Alice: OK
|
||||||
else or this
|
else or this
|
||||||
|
autonumber
|
||||||
Alice->>John: No
|
Alice->>John: No
|
||||||
else or this will happen
|
else or this will happen
|
||||||
Alice->John: Maybe
|
Alice->John: Maybe
|
||||||
end
|
end
|
||||||
|
autonumber 200
|
||||||
par this happens in parallel
|
par this happens in parallel
|
||||||
Alice -->> Bob: Parallel message 1
|
Alice -->> Bob: Parallel message 1
|
||||||
and
|
and
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -43,9 +43,9 @@
|
||||||
"BT" return 'DIR';
|
"BT" return 'DIR';
|
||||||
":" return ':';
|
":" return ':';
|
||||||
"^" return 'CARET'
|
"^" return 'CARET'
|
||||||
"options"\r?\n this.begin("options");
|
"options"\r?\n this.begin("options"); //
|
||||||
<options>"end"\r?\n this.popState();
|
<options>[ \r\n\t]+"end" this.popState(); // not used anymore in the renderer, fixed for backward compatibility
|
||||||
<options>[^\n]+\r?\n return 'OPT';
|
<options>[\s\S]+(?=[ \r\n\t]+"end") return 'OPT'; //
|
||||||
["] this.begin("string");
|
["] this.begin("string");
|
||||||
<string>["] this.popState();
|
<string>["] this.popState();
|
||||||
<string>[^"]* return 'STR';
|
<string>[^"]* return 'STR';
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
<INITIAL,ID,ALIAS,LINE,arg_directive,type_directive,open_directive>\#[^\n]* /* skip comments */
|
<INITIAL,ID,ALIAS,LINE,arg_directive,type_directive,open_directive>\#[^\n]* /* skip comments */
|
||||||
\%%(?!\{)[^\n]* /* skip comments */
|
\%%(?!\{)[^\n]* /* skip comments */
|
||||||
[^\}]\%\%[^\n]* /* skip comments */
|
[^\}]\%\%[^\n]* /* skip comments */
|
||||||
|
[0-9]+(?=[ \n]+) return 'NUM';
|
||||||
"participant" { this.begin('ID'); return 'participant'; }
|
"participant" { this.begin('ID'); return 'participant'; }
|
||||||
"actor" { this.begin('ID'); return 'participant_actor'; }
|
"actor" { this.begin('ID'); return 'participant_actor'; }
|
||||||
<ID>[^\->:\n,;]+?(?=((?!\n)\s)+"as"(?!\n)\s|[#\n;]|$) { yytext = yytext.trim(); this.begin('ALIAS'); return 'ACTOR'; }
|
<ID>[^\->:\n,;]+?(?=((?!\n)\s)+"as"(?!\n)\s|[#\n;]|$) { yytext = yytext.trim(); this.begin('ALIAS'); return 'ACTOR'; }
|
||||||
|
@ -58,9 +59,10 @@
|
||||||
"deactivate" { this.begin('ID'); return 'deactivate'; }
|
"deactivate" { this.begin('ID'); return 'deactivate'; }
|
||||||
"title"\s[^#\n;]+ return 'title';
|
"title"\s[^#\n;]+ return 'title';
|
||||||
"title:"\s[^#\n;]+ return 'legacy_title';
|
"title:"\s[^#\n;]+ return 'legacy_title';
|
||||||
"accDescription"\s[^#\n;]+ return 'accDescription';
|
"accDescription"\s[^#\n;]+ return 'accDescription';
|
||||||
"sequenceDiagram" return 'SD';
|
"sequenceDiagram" return 'SD';
|
||||||
"autonumber" return 'autonumber';
|
"autonumber" return 'autonumber';
|
||||||
|
"off" return 'off';
|
||||||
"," return ',';
|
"," return ',';
|
||||||
";" return 'NEWLINE';
|
";" return 'NEWLINE';
|
||||||
[^\+\->:\n,;]+((?!(\-x|\-\-x|\-\)|\-\-\)))[\-]*[^\+\->:\n,;]+)* { yytext = yytext.trim(); return 'ACTOR'; }
|
[^\+\->:\n,;]+((?!(\-x|\-\-x|\-\)|\-\-\)))[\-]*[^\+\->:\n,;]+)* { yytext = yytext.trim(); return 'ACTOR'; }
|
||||||
|
@ -115,7 +117,10 @@ statement
|
||||||
| 'participant_actor' actor 'AS' restOfLine 'NEWLINE' {$2.type='addActor';$2.description=yy.parseMessage($4); $$=$2;}
|
| 'participant_actor' actor 'AS' restOfLine 'NEWLINE' {$2.type='addActor';$2.description=yy.parseMessage($4); $$=$2;}
|
||||||
| 'participant_actor' actor 'NEWLINE' {$2.type='addActor'; $$=$2;}
|
| 'participant_actor' actor 'NEWLINE' {$2.type='addActor'; $$=$2;}
|
||||||
| signal 'NEWLINE'
|
| signal 'NEWLINE'
|
||||||
| autonumber {yy.enableSequenceNumbers()}
|
| autonumber NUM NUM 'NEWLINE' { $$= {type:'sequenceIndex',sequenceIndex: Number($2), sequenceIndexStep:Number($3), sequenceVisible:true, signalType:yy.LINETYPE.AUTONUMBER};}
|
||||||
|
| autonumber NUM 'NEWLINE' { $$ = {type:'sequenceIndex',sequenceIndex: Number($2), sequenceIndexStep:1, sequenceVisible:true, signalType:yy.LINETYPE.AUTONUMBER};}
|
||||||
|
| autonumber off 'NEWLINE' { $$ = {type:'sequenceIndex', sequenceVisible:false, signalType:yy.LINETYPE.AUTONUMBER};}
|
||||||
|
| autonumber 'NEWLINE' {$$ = {type:'sequenceIndex', sequenceVisible:true, signalType:yy.LINETYPE.AUTONUMBER}; }
|
||||||
| 'activate' actor 'NEWLINE' {$$={type: 'activeStart', signalType: yy.LINETYPE.ACTIVE_START, actor: $2};}
|
| 'activate' actor 'NEWLINE' {$$={type: 'activeStart', signalType: yy.LINETYPE.ACTIVE_START, actor: $2};}
|
||||||
| 'deactivate' actor 'NEWLINE' {$$={type: 'activeEnd', signalType: yy.LINETYPE.ACTIVE_END, actor: $2};}
|
| 'deactivate' actor 'NEWLINE' {$$={type: 'activeEnd', signalType: yy.LINETYPE.ACTIVE_END, actor: $2};}
|
||||||
| note_statement 'NEWLINE'
|
| note_statement 'NEWLINE'
|
||||||
|
|
|
@ -125,6 +125,9 @@ export const getTitle = function () {
|
||||||
export const enableSequenceNumbers = function () {
|
export const enableSequenceNumbers = function () {
|
||||||
sequenceNumbersEnabled = true;
|
sequenceNumbersEnabled = true;
|
||||||
};
|
};
|
||||||
|
export const disableSequenceNumbers = function () {
|
||||||
|
sequenceNumbersEnabled = false;
|
||||||
|
};
|
||||||
export const showSequenceNumbers = () => sequenceNumbersEnabled;
|
export const showSequenceNumbers = () => sequenceNumbersEnabled;
|
||||||
|
|
||||||
export const setWrap = function (wrapSetting) {
|
export const setWrap = function (wrapSetting) {
|
||||||
|
@ -178,6 +181,7 @@ export const LINETYPE = {
|
||||||
RECT_END: 23,
|
RECT_END: 23,
|
||||||
SOLID_POINT: 24,
|
SOLID_POINT: 24,
|
||||||
DOTTED_POINT: 25,
|
DOTTED_POINT: 25,
|
||||||
|
AUTONUMBER: 26,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const ARROWTYPE = {
|
export const ARROWTYPE = {
|
||||||
|
@ -333,6 +337,19 @@ export const apply = function (param) {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
switch (param.type) {
|
switch (param.type) {
|
||||||
|
case 'sequenceIndex':
|
||||||
|
messages.push({
|
||||||
|
from: undefined,
|
||||||
|
to: undefined,
|
||||||
|
message: {
|
||||||
|
start: param.sequenceIndex,
|
||||||
|
step: param.sequenceIndexStep,
|
||||||
|
visible: param.sequenceVisible,
|
||||||
|
},
|
||||||
|
wrap: false,
|
||||||
|
type: param.signalType,
|
||||||
|
});
|
||||||
|
break;
|
||||||
case 'addParticipant':
|
case 'addParticipant':
|
||||||
addActor(param.actor, param.actor, param.description, 'participant');
|
addActor(param.actor, param.actor, param.description, 'participant');
|
||||||
break;
|
break;
|
||||||
|
@ -425,6 +442,7 @@ export default {
|
||||||
autoWrap,
|
autoWrap,
|
||||||
setWrap,
|
setWrap,
|
||||||
enableSequenceNumbers,
|
enableSequenceNumbers,
|
||||||
|
disableSequenceNumbers,
|
||||||
showSequenceNumbers,
|
showSequenceNumbers,
|
||||||
getMessages,
|
getMessages,
|
||||||
getActors,
|
getActors,
|
||||||
|
|
|
@ -47,6 +47,7 @@ Note right of Bob: Bob thinks
|
||||||
Bob-->Alice: I am good thanks!`;
|
Bob-->Alice: I am good thanks!`;
|
||||||
|
|
||||||
mermaidAPI.parse(str);
|
mermaidAPI.parse(str);
|
||||||
|
renderer.draw(str, 'tst'); // needs to be rendered for the correct value of visibility autonumbers
|
||||||
expect(parser.yy.showSequenceNumbers()).toBe(false);
|
expect(parser.yy.showSequenceNumbers()).toBe(false);
|
||||||
});
|
});
|
||||||
it('it should show sequence numbers when autonumber is enabled', function () {
|
it('it should show sequence numbers when autonumber is enabled', function () {
|
||||||
|
@ -58,6 +59,7 @@ Note right of Bob: Bob thinks
|
||||||
Bob-->Alice: I am good thanks!`;
|
Bob-->Alice: I am good thanks!`;
|
||||||
|
|
||||||
mermaidAPI.parse(str);
|
mermaidAPI.parse(str);
|
||||||
|
renderer.draw(str, 'tst'); // needs to be rendered for the correct value of visibility autonumbers
|
||||||
expect(parser.yy.showSequenceNumbers()).toBe(true);
|
expect(parser.yy.showSequenceNumbers()).toBe(true);
|
||||||
});
|
});
|
||||||
it('it should handle a sequenceDiagram definition with a title:', function () {
|
it('it should handle a sequenceDiagram definition with a title:', function () {
|
||||||
|
@ -1676,6 +1678,7 @@ Note right of Bob: Bob thinks
|
||||||
Bob-->Alice: I am good thanks!`;
|
Bob-->Alice: I am good thanks!`;
|
||||||
|
|
||||||
mermaidAPI.parse(str1);
|
mermaidAPI.parse(str1);
|
||||||
|
renderer.draw(str1, 'tst'); // needs to be rendered for the correct value of visibility autonumbers
|
||||||
expect(parser.yy.showSequenceNumbers()).toBe(true);
|
expect(parser.yy.showSequenceNumbers()).toBe(true);
|
||||||
|
|
||||||
const str2 = `
|
const str2 = `
|
||||||
|
@ -1685,6 +1688,7 @@ Note right of Bob: Bob thinks
|
||||||
Bob-->Alice: I am good thanks!`;
|
Bob-->Alice: I am good thanks!`;
|
||||||
|
|
||||||
mermaidAPI.parse(str2);
|
mermaidAPI.parse(str2);
|
||||||
|
renderer.draw(str2, 'tst');
|
||||||
expect(parser.yy.showSequenceNumbers()).toBe(false);
|
expect(parser.yy.showSequenceNumbers()).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -329,7 +329,7 @@ const boundMessage = function (diagram, msgModel) {
|
||||||
* @param {float} lineStarty - The Y coordinate at which the message line starts
|
* @param {float} lineStarty - The Y coordinate at which the message line starts
|
||||||
*/
|
*/
|
||||||
const drawMessage = function (diagram, msgModel, lineStarty) {
|
const drawMessage = function (diagram, msgModel, lineStarty) {
|
||||||
const { startx, stopx, starty, message, type, sequenceIndex } = msgModel;
|
const { startx, stopx, starty, message, type, sequenceIndex, sequenceVisible } = msgModel;
|
||||||
let textDims = utils.calculateTextDimensions(message, messageFont(conf));
|
let textDims = utils.calculateTextDimensions(message, messageFont(conf));
|
||||||
const textObj = svgDraw.getTextObj();
|
const textObj = svgDraw.getTextObj();
|
||||||
textObj.x = startx;
|
textObj.x = startx;
|
||||||
|
@ -432,7 +432,7 @@ const drawMessage = function (diagram, msgModel, lineStarty) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// add node number
|
// add node number
|
||||||
if (sequenceDb.showSequenceNumbers() || conf.showSequenceNumbers) {
|
if (sequenceVisible || conf.showSequenceNumbers) {
|
||||||
line.attr('marker-start', 'url(' + url + '#sequencenumber)');
|
line.attr('marker-start', 'url(' + url + '#sequencenumber)');
|
||||||
diagram
|
diagram
|
||||||
.append('text')
|
.append('text')
|
||||||
|
@ -637,6 +637,7 @@ export const draw = function (text, id) {
|
||||||
|
|
||||||
// Draw the messages/signals
|
// Draw the messages/signals
|
||||||
let sequenceIndex = 1;
|
let sequenceIndex = 1;
|
||||||
|
let sequenceIndexStep = 1;
|
||||||
let messagesToDraw = Array();
|
let messagesToDraw = Array();
|
||||||
messages.forEach(function (msg) {
|
messages.forEach(function (msg) {
|
||||||
let loopModel, noteModel, msgModel;
|
let loopModel, noteModel, msgModel;
|
||||||
|
@ -741,12 +742,19 @@ export const draw = function (text, id) {
|
||||||
bounds.bumpVerticalPos(loopModel.stopy - bounds.getVerticalPos());
|
bounds.bumpVerticalPos(loopModel.stopy - bounds.getVerticalPos());
|
||||||
bounds.models.addLoop(loopModel);
|
bounds.models.addLoop(loopModel);
|
||||||
break;
|
break;
|
||||||
|
case parser.yy.LINETYPE.AUTONUMBER:
|
||||||
|
sequenceIndex = msg.message.start || sequenceIndex;
|
||||||
|
sequenceIndexStep = msg.message.step || sequenceIndexStep;
|
||||||
|
if (msg.message.visible) parser.yy.enableSequenceNumbers();
|
||||||
|
else parser.yy.disableSequenceNumbers();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
try {
|
try {
|
||||||
// lastMsg = msg
|
// lastMsg = msg
|
||||||
msgModel = msg.msgModel;
|
msgModel = msg.msgModel;
|
||||||
msgModel.starty = bounds.getVerticalPos();
|
msgModel.starty = bounds.getVerticalPos();
|
||||||
msgModel.sequenceIndex = sequenceIndex;
|
msgModel.sequenceIndex = sequenceIndex;
|
||||||
|
msgModel.sequenceVisible = parser.yy.showSequenceNumbers();
|
||||||
let lineStarty = boundMessage(diagram, msgModel);
|
let lineStarty = boundMessage(diagram, msgModel);
|
||||||
messagesToDraw.push({ messageModel: msgModel, lineStarty: lineStarty });
|
messagesToDraw.push({ messageModel: msgModel, lineStarty: lineStarty });
|
||||||
bounds.models.addMessage(msgModel);
|
bounds.models.addMessage(msgModel);
|
||||||
|
@ -768,7 +776,7 @@ export const draw = function (text, id) {
|
||||||
parser.yy.LINETYPE.DOTTED_POINT,
|
parser.yy.LINETYPE.DOTTED_POINT,
|
||||||
].includes(msg.type)
|
].includes(msg.type)
|
||||||
) {
|
) {
|
||||||
sequenceIndex++;
|
sequenceIndex = sequenceIndex + sequenceIndexStep;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -224,7 +224,7 @@ export const decodeEntities = function (text) {
|
||||||
*/
|
*/
|
||||||
const render = function (id, _txt, cb, container) {
|
const render = function (id, _txt, cb, container) {
|
||||||
configApi.reset();
|
configApi.reset();
|
||||||
let txt = _txt;
|
let txt = _txt.replace(/\r\n?/g, '\n'); // parser problems on CRLF ignore all CR and leave LF;;
|
||||||
const graphInit = utils.detectInit(txt);
|
const graphInit = utils.detectInit(txt);
|
||||||
if (graphInit) {
|
if (graphInit) {
|
||||||
directiveSanitizer(graphInit);
|
directiveSanitizer(graphInit);
|
||||||
|
|
Loading…
Reference in New Issue