draft of activation boxes handling

This commit is contained in:
Szymon Stasik 2016-03-08 10:40:52 +01:00
parent 6c621f243d
commit 2452532557
6 changed files with 185 additions and 62 deletions

View File

@ -40,6 +40,8 @@
"right of" return 'right_of';
"over" return 'over';
"note" return 'note';
"activate" { this.begin('ID'); return 'activate'; }
"deactivate" { this.begin('ID'); return 'deactivate'; }
"title" return 'title';
"sequenceDiagram" return 'SD';
"," return ',';
@ -84,6 +86,8 @@ statement
: 'participant' actor 'AS' restOfLine 'NL' {$2.description=$4; $$=$2;}
| 'participant' actor 'NL' {$$=$2;}
| signal 'NL'
| 'activate' actor 'NL' {$$={type: 'activeStart', signalType: yy.LINETYPE.ACTIVE_START, actor: $2};}
| 'deactivate' actor 'NL' {$$={type: 'activeEnd', signalType: yy.LINETYPE.ACTIVE_END, actor: $2};}
| note_statement 'NL'
| 'title' SPACE text 'NL'
| 'loop' restOfLine document end

View File

@ -1,4 +1,4 @@
/* parser generated by jison 0.4.15 */
/* parser generated by jison 0.4.17 */
/*
Returns a Parser object of the following structure:
@ -72,51 +72,57 @@
}
*/
var sequenceDiagram = (function(){
var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o},$V0=[2,2],$V1=[1,5],$V2=[1,7],$V3=[1,8],$V4=[1,11],$V5=[1,12],$V6=[1,13],$V7=[1,14],$V8=[1,16],$V9=[1,17],$Va=[1,7,9,10,16,18,19,20,21,22,23,33],$Vb=[7,9,10,16,18,19,20,21,23,33],$Vc=[1,53];
var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o},$V0=[1,2],$V1=[1,3],$V2=[1,4],$V3=[2,4],$V4=[1,9],$V5=[1,11],$V6=[1,12],$V7=[1,14],$V8=[1,15],$V9=[1,17],$Va=[1,18],$Vb=[1,19],$Vc=[1,20],$Vd=[1,22],$Ve=[1,23],$Vf=[1,4,5,10,15,16,18,20,21,22,23,24,25,35],$Vg=[4,5,10,15,16,18,20,21,22,23,25,35],$Vh=[1,63];
var parser = {trace: function trace() { },
yy: {},
symbols_: {"error":2,"start":3,"SD":4,"document":5,"line":6,"SPACE":7,"statement":8,"NL":9,"participant":10,"actor":11,"AS":12,"restOfLine":13,"signal":14,"note_statement":15,"title":16,"text":17,"loop":18,"end":19,"opt":20,"alt":21,"else":22,"note":23,"placement":24,"text2":25,"over":26,"actor_pair":27,"spaceList":28,",":29,"left_of":30,"right_of":31,"signaltype":32,"ACTOR":33,"SOLID_OPEN_ARROW":34,"DOTTED_OPEN_ARROW":35,"SOLID_ARROW":36,"DOTTED_ARROW":37,"SOLID_CROSS":38,"DOTTED_CROSS":39,"TXT":40,"$accept":0,"$end":1},
terminals_: {2:"error",4:"SD",7:"SPACE",9:"NL",10:"participant",12:"AS",13:"restOfLine",16:"title",17:"text",18:"loop",19:"end",20:"opt",21:"alt",22:"else",23:"note",26:"over",29:",",30:"left_of",31:"right_of",33:"ACTOR",34:"SOLID_OPEN_ARROW",35:"DOTTED_OPEN_ARROW",36:"SOLID_ARROW",37:"DOTTED_ARROW",38:"SOLID_CROSS",39:"DOTTED_CROSS",40:"TXT"},
productions_: [0,[3,2],[5,0],[5,2],[6,2],[6,1],[6,1],[8,5],[8,3],[8,2],[8,2],[8,4],[8,4],[8,4],[8,7],[15,4],[15,4],[28,2],[28,1],[27,3],[27,1],[24,1],[24,1],[14,4],[11,1],[32,1],[32,1],[32,1],[32,1],[32,1],[32,1],[25,1]],
symbols_: {"error":2,"start":3,"SPACE":4,"NL":5,"SD":6,"document":7,"line":8,"statement":9,"participant":10,"actor":11,"AS":12,"restOfLine":13,"signal":14,"activate":15,"deactivate":16,"note_statement":17,"title":18,"text":19,"loop":20,"end":21,"opt":22,"alt":23,"else":24,"note":25,"placement":26,"text2":27,"over":28,"actor_pair":29,"spaceList":30,",":31,"left_of":32,"right_of":33,"signaltype":34,"ACTOR":35,"SOLID_OPEN_ARROW":36,"DOTTED_OPEN_ARROW":37,"SOLID_ARROW":38,"DOTTED_ARROW":39,"SOLID_CROSS":40,"DOTTED_CROSS":41,"TXT":42,"$accept":0,"$end":1},
terminals_: {2:"error",4:"SPACE",5:"NL",6:"SD",10:"participant",12:"AS",13:"restOfLine",15:"activate",16:"deactivate",18:"title",19:"text",20:"loop",21:"end",22:"opt",23:"alt",24:"else",25:"note",28:"over",31:",",32:"left_of",33:"right_of",35:"ACTOR",36:"SOLID_OPEN_ARROW",37:"DOTTED_OPEN_ARROW",38:"SOLID_ARROW",39:"DOTTED_ARROW",40:"SOLID_CROSS",41:"DOTTED_CROSS",42:"TXT"},
productions_: [0,[3,2],[3,2],[3,2],[7,0],[7,2],[8,2],[8,1],[8,1],[9,5],[9,3],[9,2],[9,3],[9,3],[9,2],[9,4],[9,4],[9,4],[9,7],[17,4],[17,4],[30,2],[30,1],[29,3],[29,1],[26,1],[26,1],[14,4],[11,1],[34,1],[34,1],[34,1],[34,1],[34,1],[34,1],[27,1]],
performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */) {
/* this == yyval */
var $0 = $$.length - 1;
switch (yystate) {
case 1:
case 3:
yy.apply($$[$0]);return $$[$0];
break;
case 2:
case 4:
this.$ = []
break;
case 3:
case 5:
$$[$0-1].push($$[$0]);this.$ = $$[$0-1]
break;
case 4: case 5:
case 6: case 7:
this.$ = $$[$0]
break;
case 6:
case 8:
this.$=[];
break;
case 7:
case 9:
$$[$0-3].description=$$[$0-1]; this.$=$$[$0-3];
break;
case 8:
case 10:
this.$=$$[$0-1];
break;
case 12:
this.$={type: 'activeStart', signalType: yy.LINETYPE.ACTIVE_START, actor: $$[$0-1]};
break;
case 13:
this.$={type: 'activeEnd', signalType: yy.LINETYPE.ACTIVE_END, actor: $$[$0-1]};
break;
case 16:
$$[$0-1].unshift({type: 'loopStart', loopText:$$[$0-2], signalType: yy.LINETYPE.LOOP_START});
$$[$0-1].push({type: 'loopEnd', loopText:$$[$0-2], signalType: yy.LINETYPE.LOOP_END});
this.$=$$[$0-1];
break;
case 13:
case 17:
$$[$0-1].unshift({type: 'optStart', optText:$$[$0-2], signalType: yy.LINETYPE.OPT_START});
$$[$0-1].push({type: 'optEnd', optText:$$[$0-2], signalType: yy.LINETYPE.OPT_END});
this.$=$$[$0-1];
break;
case 14:
case 18:
// Alt start
$$[$0-4].unshift({type: 'altStart', altText:$$[$0-5], signalType: yy.LINETYPE.ALT_START});
@ -130,11 +136,11 @@ case 14:
this.$=$$[$0-4];
break;
case 15:
case 19:
this.$ = [$$[$0-1], {type:'addNote', placement:$$[$0-2], actor:$$[$0-1].actor, text:$$[$0]}];
break;
case 16:
case 20:
// Coerce actor_pair into a [to, from, ...] array
$$[$0-2] = [].concat($$[$0-1], $$[$0-1]).slice(0, 2);
@ -142,49 +148,49 @@ case 16:
$$[$0-2][1] = $$[$0-2][1].actor;
this.$ = [$$[$0-1], {type:'addNote', placement:yy.PLACEMENT.OVER, actor:$$[$0-2].slice(0, 2), text:$$[$0]}];
break;
case 19:
case 23:
this.$ = [$$[$0-2], $$[$0]];
break;
case 20:
case 24:
this.$ = $$[$0];
break;
case 21:
case 25:
this.$ = yy.PLACEMENT.LEFTOF;
break;
case 22:
case 26:
this.$ = yy.PLACEMENT.RIGHTOF;
break;
case 23:
case 27:
this.$ = [$$[$0-3],$$[$0-1],{type: 'addMessage', from:$$[$0-3].actor, to:$$[$0-1].actor, signalType:$$[$0-2], msg:$$[$0]}]
break;
case 24:
case 28:
this.$={type: 'addActor', actor:$$[$0]}
break;
case 25:
case 29:
this.$ = yy.LINETYPE.SOLID_OPEN;
break;
case 26:
case 30:
this.$ = yy.LINETYPE.DOTTED_OPEN;
break;
case 27:
case 31:
this.$ = yy.LINETYPE.SOLID;
break;
case 28:
case 32:
this.$ = yy.LINETYPE.DOTTED;
break;
case 29:
case 33:
this.$ = yy.LINETYPE.SOLID_CROSS;
break;
case 30:
case 34:
this.$ = yy.LINETYPE.DOTTED_CROSS;
break;
case 31:
case 35:
this.$ = $$[$0].substring(1).trim().replace(/\\n/gm, "\n");
break;
}
},
table: [{3:1,4:[1,2]},{1:[3]},o([1,7,9,10,16,18,20,21,23,33],$V0,{5:3}),{1:[2,1],6:4,7:$V1,8:6,9:$V2,10:$V3,11:15,14:9,15:10,16:$V4,18:$V5,20:$V6,21:$V7,23:$V8,33:$V9},o($Va,[2,3]),{8:18,10:$V3,11:15,14:9,15:10,16:$V4,18:$V5,20:$V6,21:$V7,23:$V8,33:$V9},o($Va,[2,5]),o($Va,[2,6]),{11:19,33:$V9},{9:[1,20]},{9:[1,21]},{7:[1,22]},{13:[1,23]},{13:[1,24]},{13:[1,25]},{32:26,34:[1,27],35:[1,28],36:[1,29],37:[1,30],38:[1,31],39:[1,32]},{24:33,26:[1,34],30:[1,35],31:[1,36]},o([9,12,29,34,35,36,37,38,39,40],[2,24]),o($Va,[2,4]),{9:[1,38],12:[1,37]},o($Va,[2,9]),o($Va,[2,10]),{17:[1,39]},o($Vb,$V0,{5:40}),o($Vb,$V0,{5:41}),o([7,9,10,16,18,20,21,22,23,33],$V0,{5:42}),{11:43,33:$V9},{33:[2,25]},{33:[2,26]},{33:[2,27]},{33:[2,28]},{33:[2,29]},{33:[2,30]},{11:44,33:$V9},{11:46,27:45,33:$V9},{33:[2,21]},{33:[2,22]},{13:[1,47]},o($Va,[2,8]),{9:[1,48]},{6:4,7:$V1,8:6,9:$V2,10:$V3,11:15,14:9,15:10,16:$V4,18:$V5,19:[1,49],20:$V6,21:$V7,23:$V8,33:$V9},{6:4,7:$V1,8:6,9:$V2,10:$V3,11:15,14:9,15:10,16:$V4,18:$V5,19:[1,50],20:$V6,21:$V7,23:$V8,33:$V9},{6:4,7:$V1,8:6,9:$V2,10:$V3,11:15,14:9,15:10,16:$V4,18:$V5,20:$V6,21:$V7,22:[1,51],23:$V8,33:$V9},{25:52,40:$Vc},{25:54,40:$Vc},{25:55,40:$Vc},{29:[1,56],40:[2,20]},{9:[1,57]},o($Va,[2,11]),o($Va,[2,12]),o($Va,[2,13]),{13:[1,58]},{9:[2,23]},{9:[2,31]},{9:[2,15]},{9:[2,16]},{11:59,33:$V9},o($Va,[2,7]),o($Vb,$V0,{5:60}),{40:[2,19]},{6:4,7:$V1,8:6,9:$V2,10:$V3,11:15,14:9,15:10,16:$V4,18:$V5,19:[1,61],20:$V6,21:$V7,23:$V8,33:$V9},o($Va,[2,14])],
defaultActions: {27:[2,25],28:[2,26],29:[2,27],30:[2,28],31:[2,29],32:[2,30],35:[2,21],36:[2,22],52:[2,23],53:[2,31],54:[2,15],55:[2,16],59:[2,19]},
table: [{3:1,4:$V0,5:$V1,6:$V2},{1:[3]},{3:5,4:$V0,5:$V1,6:$V2},{3:6,4:$V0,5:$V1,6:$V2},o([1,4,5,10,15,16,18,20,22,23,25,35],$V3,{7:7}),{1:[2,1]},{1:[2,2]},{1:[2,3],4:$V4,5:$V5,8:8,9:10,10:$V6,11:21,14:13,15:$V7,16:$V8,17:16,18:$V9,20:$Va,22:$Vb,23:$Vc,25:$Vd,35:$Ve},o($Vf,[2,5]),{9:24,10:$V6,11:21,14:13,15:$V7,16:$V8,17:16,18:$V9,20:$Va,22:$Vb,23:$Vc,25:$Vd,35:$Ve},o($Vf,[2,7]),o($Vf,[2,8]),{11:25,35:$Ve},{5:[1,26]},{11:27,35:$Ve},{11:28,35:$Ve},{5:[1,29]},{4:[1,30]},{13:[1,31]},{13:[1,32]},{13:[1,33]},{34:34,36:[1,35],37:[1,36],38:[1,37],39:[1,38],40:[1,39],41:[1,40]},{26:41,28:[1,42],32:[1,43],33:[1,44]},o([5,12,31,36,37,38,39,40,41,42],[2,28]),o($Vf,[2,6]),{5:[1,46],12:[1,45]},o($Vf,[2,11]),{5:[1,47]},{5:[1,48]},o($Vf,[2,14]),{19:[1,49]},o($Vg,$V3,{7:50}),o($Vg,$V3,{7:51}),o([4,5,10,15,16,18,20,22,23,24,25,35],$V3,{7:52}),{11:53,35:$Ve},{35:[2,29]},{35:[2,30]},{35:[2,31]},{35:[2,32]},{35:[2,33]},{35:[2,34]},{11:54,35:$Ve},{11:56,29:55,35:$Ve},{35:[2,25]},{35:[2,26]},{13:[1,57]},o($Vf,[2,10]),o($Vf,[2,12]),o($Vf,[2,13]),{5:[1,58]},{4:$V4,5:$V5,8:8,9:10,10:$V6,11:21,14:13,15:$V7,16:$V8,17:16,18:$V9,20:$Va,21:[1,59],22:$Vb,23:$Vc,25:$Vd,35:$Ve},{4:$V4,5:$V5,8:8,9:10,10:$V6,11:21,14:13,15:$V7,16:$V8,17:16,18:$V9,20:$Va,21:[1,60],22:$Vb,23:$Vc,25:$Vd,35:$Ve},{4:$V4,5:$V5,8:8,9:10,10:$V6,11:21,14:13,15:$V7,16:$V8,17:16,18:$V9,20:$Va,22:$Vb,23:$Vc,24:[1,61],25:$Vd,35:$Ve},{27:62,42:$Vh},{27:64,42:$Vh},{27:65,42:$Vh},{31:[1,66],42:[2,24]},{5:[1,67]},o($Vf,[2,15]),o($Vf,[2,16]),o($Vf,[2,17]),{13:[1,68]},{5:[2,27]},{5:[2,35]},{5:[2,19]},{5:[2,20]},{11:69,35:$Ve},o($Vf,[2,9]),o($Vg,$V3,{7:70}),{42:[2,23]},{4:$V4,5:$V5,8:8,9:10,10:$V6,11:21,14:13,15:$V7,16:$V8,17:16,18:$V9,20:$Va,21:[1,71],22:$Vb,23:$Vc,25:$Vd,35:$Ve},o($Vf,[2,18])],
defaultActions: {5:[2,1],6:[2,2],35:[2,29],36:[2,30],37:[2,31],38:[2,32],39:[2,33],40:[2,34],43:[2,25],44:[2,26],62:[2,27],63:[2,35],64:[2,19],65:[2,20],69:[2,23]},
parseError: function parseError(str, hash) {
if (hash.recoverable) {
this.trace(str);
@ -193,7 +199,7 @@ parseError: function parseError(str, hash) {
this.message = msg;
this.hash = hash;
}
_parseError.prototype = new Error();
_parseError.prototype = Error;
throw new _parseError(str, hash);
}
@ -664,7 +670,7 @@ options: {"case-insensitive":true},
performAction: function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) {
var YYSTATE=YY_START;
switch($avoiding_name_collisions) {
case 0:return 9;
case 0:return 5;
break;
case 1:/* skip all whitespace */
break;
@ -676,64 +682,68 @@ case 4:/* skip comments */
break;
case 5: this.begin('ID'); return 10;
break;
case 6: this.begin('ALIAS'); return 33;
case 6: this.begin('ALIAS'); return 35;
break;
case 7: this.popState(); this.popState(); this.begin('LINE'); return 12;
break;
case 8: this.popState(); this.popState(); return 9;
case 8: this.popState(); this.popState(); return 5;
break;
case 9: this.begin('LINE'); return 18;
case 9: this.begin('LINE'); return 20;
break;
case 10: this.begin('LINE'); return 20;
case 10: this.begin('LINE'); return 22;
break;
case 11: this.begin('LINE'); return 21;
case 11: this.begin('LINE'); return 23;
break;
case 12: this.begin('LINE'); return 22;
case 12: this.begin('LINE'); return 24;
break;
case 13: this.popState(); return 13;
break;
case 14:return 19;
case 14:return 21;
break;
case 15:return 30;
case 15:return 32;
break;
case 16:return 31;
case 16:return 33;
break;
case 17:return 26;
case 17:return 28;
break;
case 18:return 23;
case 18:return 25;
break;
case 19:return 16;
case 19: this.begin('ID'); return 15;
break;
case 20:return 4;
case 20: this.begin('ID'); return 16;
break;
case 21:return 29;
case 21:return 18;
break;
case 22:return 9;
case 22:return 6;
break;
case 23:return 33;
case 23:return 31;
break;
case 24:return 36;
case 24:return 5;
break;
case 25:return 37;
case 25: yy_.yytext = yy_.yytext.trim(); return 35;
break;
case 26:return 34;
case 26:return 38;
break;
case 27:return 35;
case 27:return 39;
break;
case 28:return 38;
case 28:return 36;
break;
case 29:return 39;
case 29:return 37;
break;
case 30:return 40;
break;
case 31:return 9;
case 31:return 41;
break;
case 32:return 'INVALID';
case 32:return 42;
break;
case 33:return 5;
break;
case 34:return 'INVALID';
break;
}
},
rules: [/^(?:[\n]+)/i,/^(?:\s+)/i,/^(?:((?!\n)\s)+)/i,/^(?:#[^\n]*)/i,/^(?:%[^\n]*)/i,/^(?:participant\b)/i,/^(?:[^\->:\n,;]+?(?=((?!\n)\s)+as(?!\n)\s|[#\n;]|$))/i,/^(?:as\b)/i,/^(?:(?:))/i,/^(?:loop\b)/i,/^(?:opt\b)/i,/^(?:alt\b)/i,/^(?:else\b)/i,/^(?:[^#\n;]*)/i,/^(?:end\b)/i,/^(?:left of\b)/i,/^(?:right of\b)/i,/^(?:over\b)/i,/^(?:note\b)/i,/^(?:title\b)/i,/^(?:sequenceDiagram\b)/i,/^(?:,)/i,/^(?:;)/i,/^(?:[^\->:\n,;]+)/i,/^(?:->>)/i,/^(?:-->>)/i,/^(?:->)/i,/^(?:-->)/i,/^(?:-[x])/i,/^(?:--[x])/i,/^(?::[^#\n;]+)/i,/^(?:$)/i,/^(?:.)/i],
conditions: {"LINE":{"rules":[2,3,13],"inclusive":false},"ALIAS":{"rules":[2,3,7,8],"inclusive":false},"ID":{"rules":[2,3,6],"inclusive":false},"INITIAL":{"rules":[0,1,3,4,5,9,10,11,12,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32],"inclusive":true}}
rules: [/^(?:[\n]+)/i,/^(?:\s+)/i,/^(?:((?!\n)\s)+)/i,/^(?:#[^\n]*)/i,/^(?:%[^\n]*)/i,/^(?:participant\b)/i,/^(?:[^\->:\n,;]+?(?=((?!\n)\s)+as(?!\n)\s|[#\n;]|$))/i,/^(?:as\b)/i,/^(?:(?:))/i,/^(?:loop\b)/i,/^(?:opt\b)/i,/^(?:alt\b)/i,/^(?:else\b)/i,/^(?:[^#\n;]*)/i,/^(?:end\b)/i,/^(?:left of\b)/i,/^(?:right of\b)/i,/^(?:over\b)/i,/^(?:note\b)/i,/^(?:activate\b)/i,/^(?:deactivate\b)/i,/^(?:title\b)/i,/^(?:sequenceDiagram\b)/i,/^(?:,)/i,/^(?:;)/i,/^(?:[^\->:\n,;]+)/i,/^(?:->>)/i,/^(?:-->>)/i,/^(?:->)/i,/^(?:-->)/i,/^(?:-[x])/i,/^(?:--[x])/i,/^(?::[^#\n;]+)/i,/^(?:$)/i,/^(?:.)/i],
conditions: {"LINE":{"rules":[2,3,13],"inclusive":false},"ALIAS":{"rules":[2,3,7,8],"inclusive":false},"ID":{"rules":[2,3,6],"inclusive":false},"INITIAL":{"rules":[0,1,3,4,5,9,10,11,12,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34],"inclusive":true}}
});
return lexer;
})();

View File

@ -65,7 +65,9 @@ exports.LINETYPE = {
ALT_ELSE : 13 ,
ALT_END : 14 ,
OPT_START : 15 ,
OPT_END : 16
OPT_END : 16 ,
ACTIVE_START : 17 ,
ACTIVE_END : 18
};
exports.ARROWTYPE = {
@ -100,11 +102,19 @@ exports.apply = function(param){
exports.apply(item);
});
} else {
// log.debug(param);
// console.info(param);
switch(param.type){
case 'addActor':
exports.addActor(param.actor, param.actor, param.description);
break;
case 'activeStart':
console.info(param);
exports.addSignal(param.actor, undefined, undefined, param.signalType);
break;
case 'activeEnd':
console.info(param);
exports.addSignal(param.actor, undefined, undefined, param.signalType);
break;
case 'addNote':
exports.addNote(param.actor,param.placement, param.text);
break;

View File

@ -130,7 +130,7 @@ describe('when parsing a sequenceDiagram',function() {
});
it('it should handle in arrow messages', function () {
var str = 'sequenceDiagram\n' +
'Alice-->>Bob:Hello Bob, how are you?';
'Alice-->>Bob:Hello Bob, how are you?';
sq.parse(str);
var actors = sq.yy.getActors();
@ -142,6 +142,32 @@ describe('when parsing a sequenceDiagram',function() {
expect(messages.length).toBe(1);
expect(messages[0].type).toBe(sq.yy.LINETYPE.DOTTED);
});
it('it should handle actor activation', function () {
var str = 'sequenceDiagram\n' +
'Alice-->>Bob:Hello Bob, how are you?\n' +
'activate Bob\n' +
'Alice-->>Bob:Hello Bob, how are you?\n' +
'deactivate Bob';
sq.parse(str);
var actors = sq.yy.getActors();
expect(actors.Alice.description).toBe('Alice');
expect(actors.Bob.description).toBe('Bob');
var messages = sq.yy.getMessages();
expect(messages.length).toBe(4);
console.log('msg', messages[0]);
expect(messages[0].type).toBe(sq.yy.LINETYPE.DOTTED);
console.log('msg', messages[1]);
expect(messages[1].type).toBe(sq.yy.LINETYPE.ACTIVE_START);
expect(messages[1].from.actor).toBe('Bob');
console.log('msg', messages[2]);
expect(messages[2].type).toBe(sq.yy.LINETYPE.DOTTED);
console.log('msg', messages[3]);
expect(messages[3].type).toBe(sq.yy.LINETYPE.ACTIVE_END);
expect(messages[3].from.actor).toBe('Bob');
});
it('it should handle comments in a sequenceDiagram', function () {
str = 'sequenceDiagram\n' +
'Alice->Bob: Hello Bob, how are you?\n'+

View File

@ -43,8 +43,10 @@ exports.bounds = {
verticalPos:0,
list: [],
activations: [],
init : function(){
this.list = [];
this.activations = [],
this.data = {
startx:undefined,
stopx :undefined,
@ -96,6 +98,16 @@ exports.bounds = {
this.updateLoops(_startx,_starty,_stopx,_stopy);
},
newActivation:function(message){
console.debug("new activation", message);
this.activations.push({startx:undefined,starty:this.verticalPos,stopx:undefined,stopy:undefined, actor: message.from.actor});
},
endActivation:function(){
var activation = this.activations.pop();
console.debug("render end activation", activation);
//loop.stopy = exports.bounds.getVerticalPos();
return activation;
},
newLoop:function(title){
this.list.push({startx:undefined,starty:this.verticalPos,stopx:undefined,stopy:undefined, title:title});
},
@ -328,6 +340,19 @@ module.exports.draw = function (text, id) {
forceWidth);
}
break;
case sq.yy.LINETYPE.ACTIVE_START:
console.info('ACTIVE_START', msg);
// exports.bounds.bumpVerticalPos(conf.boxMargin);
exports.bounds.newActivation(msg);
// exports.bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin);
break;
case sq.yy.LINETYPE.ACTIVE_END:
console.info('ACTIVE_END', msg);
var activationData = exports.bounds.endActivation();
// svgDraw.drawActivation(diagram, activationData, conf);
// exports.bounds.bumpVerticalPos(conf.boxMargin);
break;
case sq.yy.LINETYPE.LOOP_START:
exports.bounds.bumpVerticalPos(conf.boxMargin);
exports.bounds.newLoop(msg.message);

View File

@ -121,6 +121,54 @@ exports.drawActor = function(elem, left, verticalPos, description,conf){
;
};
/**
* Draws an actor in the diagram with the attaced line
* @param center - The center of the the actor
* @param pos The position if the actor in the list of actors
* @param description The text in the box
*/
exports.drawActivation = function(elem,bounds,conf){
var rect = exports.getNoteRect();
rect.x = left;
rect.y = verticalPos;
rect.fill = '#ffffff';
rect.width = conf.width;
rect.height = conf.height;
rect.class = 'actor';
exports.drawRect(g, rect);
// drawBox(bounds.startx, bounds.starty, bounds.stopx , bounds.starty);
// drawBox(bounds.stopx , bounds.starty, bounds.stopx , bounds.stopy );
// drawBox(bounds.startx, bounds.stopy , bounds.stopx , bounds.stopy );
// drawBox(bounds.startx, bounds.starty, bounds.startx, bounds.stopy );
// var txt = exports.getTextObj();
// txt.text = labelText;
// txt.x = bounds.startx;
// txt.y = bounds.starty;
// txt.labelMargin = 1.5 * 10; // This is the small box that says "loop"
// txt.class = 'labelText'; // Its size & position are fixed.
// txt.fill = 'white';
//
// exports.drawLabel(g,txt);
//
// txt = exports.getTextObj();
// txt.text = '[ ' + bounds.title + ' ]';
// txt.x = bounds.startx + (bounds.stopx - bounds.startx)/2;
// txt.y = bounds.starty + 1.5 * conf.boxMargin;
// txt.anchor = 'middle';
// txt.class = 'loopText';
//
// exports.drawText(g,txt);
//
// if(typeof bounds.elseText !== 'undefined') {
// txt.text = '[ ' + bounds.elseText + ' ]';
// txt.y = bounds.elsey + 1.5 * conf.boxMargin;
// exports.drawText(g, txt);
// }
};
/**
* Draws an actor in the diagram with the attaced line
* @param center - The center of the the actor