Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(WIP) Sequence Diagram Title Support #320

Merged
merged 2 commits into from
Mar 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31,268 changes: 15,898 additions & 15,370 deletions dist/mermaid.js

Large diffs are not rendered by default.

37 changes: 17 additions & 20 deletions dist/mermaid.min.js

Large diffs are not rendered by default.

34,040 changes: 17,284 additions & 16,756 deletions dist/mermaid.slim.js

Large diffs are not rendered by default.

29 changes: 16 additions & 13 deletions dist/mermaid.slim.min.js

Large diffs are not rendered by default.

30,460 changes: 15,494 additions & 14,966 deletions dist/mermaidAPI.js

Large diffs are not rendered by default.

34 changes: 15 additions & 19 deletions dist/mermaidAPI.min.js

Large diffs are not rendered by default.

33,144 changes: 16,836 additions & 16,308 deletions dist/mermaidAPI.slim.js

Large diffs are not rendered by default.

22 changes: 12 additions & 10 deletions dist/mermaidAPI.slim.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/diagrams/sequenceDiagram/parser/sequenceDiagram.jison
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ statement
| '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'
| title text2 'NL' {$$=[{type:'setTitle', text:$2}]}
| 'loop' restOfLine document end
{
$3.unshift({type: 'loopStart', loopText:$2, signalType: yy.LINETYPE.LOOP_START});
Expand Down
53 changes: 28 additions & 25 deletions src/diagrams/sequenceDiagram/parser/sequenceDiagram.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/diagrams/sequenceDiagram/sequenceDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
var actors = {};
var messages = [];
var notes = [];
var title = '';
var Logger = require('../../logger');
var log = new Logger.Log();

Expand Down Expand Up @@ -45,6 +46,9 @@ exports.getActor = function(id){
exports.getActorKeys = function(){
return Object.keys(actors);
};
exports.getTitle = function() {
return title;
}

exports.clear = function(){
actors = {};
Expand Down Expand Up @@ -91,6 +95,10 @@ exports.addNote = function (actor, placement, message){
messages.push({from:actors[0], to:actors[1], message:message, type:exports.LINETYPE.NOTE, placement: placement});
};

exports.setTitle = function(titleText){
title = titleText;
}


exports.parseError = function(err,hash){
global.mermaidAPI.parseError(err,hash);
Expand Down Expand Up @@ -146,6 +154,8 @@ exports.apply = function(param){
case 'altEnd':
exports.addSignal(undefined, undefined, undefined, param.signalType);
break;
case 'setTitle':
exports.setTitle(param.text);
}
}
};
20 changes: 20 additions & 0 deletions src/diagrams/sequenceDiagram/sequenceDiagram.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@ describe('when parsing a sequenceDiagram',function() {
expect(messages.length).toBe(3);
expect(messages[0].from).toBe('Alice');
expect(messages[2].from).toBe('Bob');
});
it('it should handle a sequenceDiagram definition with a title', function () {
str = 'sequenceDiagram\n' +
'title: Diagram Title\n' +
'Alice->Bob:Hello Bob, how are you?\n' +
'Note right of Bob: Bob thinks\n' +
'Bob-->Alice: I am good thanks!';

sq.parse(str);
var actors = sq.yy.getActors();
expect(actors.Alice.description).toBe('Alice');
actors.Bob.description = 'Bob';

var messages = sq.yy.getMessages();
var title = sq.yy.getTitle();

expect(messages.length).toBe(3);
expect(messages[0].from).toBe('Alice');
expect(messages[2].from).toBe('Bob');
expect(title).toBe('Diagram Title');
});
it('it should space in actor names', function () {
str = 'sequenceDiagram\n' +
Expand Down
16 changes: 13 additions & 3 deletions src/diagrams/sequenceDiagram/sequenceRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var log = new Logger.Log();
var conf = {

diagramMarginX:50,
diagramMarginY:10,
diagramMarginY:30,
// Margin between actors
actorMargin:50,
// Width of actor boxes
Expand Down Expand Up @@ -341,6 +341,7 @@ module.exports.draw = function (text, id) {
var actors = sq.yy.getActors();
var actorKeys = sq.yy.getActorKeys();
var messages = sq.yy.getMessages();
var title = sq.yy.getTitle();
module.exports.drawActors(diagram, actors, actorKeys, 0);

// The arrow head definition is attached to the svg once
Expand Down Expand Up @@ -474,7 +475,15 @@ module.exports.draw = function (text, id) {
height = height - conf.boxMargin + conf.bottomMarginAdj;
}

var width = box.stopx-box.startx+2*conf.diagramMarginX;
var width = (box.stopx - box.startx) + (2 * conf.diagramMarginX);

if(title) {
diagram.append('text')
.text(title)
.attr('x', ( ( box.stopx-box.startx) / 2 ) - ( 2 * conf.diagramMarginX ) )
.attr('y', -25);
}

if(conf.useMaxWidth) {
diagram.attr('height', '100%');
diagram.attr('width', '100%');
Expand All @@ -483,5 +492,6 @@ module.exports.draw = function (text, id) {
diagram.attr('height',height);
diagram.attr('width', width );
}
diagram.attr('viewBox', (box.startx-conf.diagramMarginX) + ' -' +conf.diagramMarginY + ' ' + width + ' ' + height);
var extraVertForTitle = title ? 40 : 0;
diagram.attr('viewBox', (box.startx - conf.diagramMarginX) + ' -' + (conf.diagramMarginY + extraVertForTitle) + ' ' + width + ' ' + (height + extraVertForTitle));
};