diff --git a/src/diagrams/sequence/sequenceDb.js b/src/diagrams/sequence/sequenceDb.js
index e531ed2f9..050691a6c 100644
--- a/src/diagrams/sequence/sequenceDb.js
+++ b/src/diagrams/sequence/sequenceDb.js
@@ -1,51 +1,53 @@
-import { logger } from '../../logger'
+import { logger } from '../../logger';
-let actors = {}
-let messages = []
-const notes = []
-let title = ''
+let actors = {};
+let messages = [];
+const notes = [];
+let title = '';
-export const addActor = function (id, name, description) {
+export const addActor = function(id, name, description) {
// Don't allow description nulling
- const old = actors[id]
- if (old && name === old.name && description == null) return
+ const old = actors[id];
+ if (old && name === old.name && description == null) return;
// Don't allow null descriptions, either
- if (description == null) description = name
+ if (description == null) description = name;
- actors[id] = { name: name, description: description }
-}
+ actors[id] = { name: name, description: description };
+};
-export const addMessage = function (idFrom, idTo, message, answer) {
- messages.push({ from: idFrom, to: idTo, message: message, answer: answer })
-}
+export const addMessage = function(idFrom, idTo, message, answer) {
+ messages.push({ from: idFrom, to: idTo, message: message, answer: answer });
+};
-export const addSignal = function (idFrom, idTo, message, messageType) {
- logger.debug('Adding message from=' + idFrom + ' to=' + idTo + ' message=' + message + ' type=' + messageType)
- messages.push({ from: idFrom, to: idTo, message: message, type: messageType })
-}
+export const addSignal = function(idFrom, idTo, message, messageType) {
+ logger.debug(
+ 'Adding message from=' + idFrom + ' to=' + idTo + ' message=' + message + ' type=' + messageType
+ );
+ messages.push({ from: idFrom, to: idTo, message: message, type: messageType });
+};
-export const getMessages = function () {
- return messages
-}
+export const getMessages = function() {
+ return messages;
+};
-export const getActors = function () {
- return actors
-}
-export const getActor = function (id) {
- return actors[id]
-}
-export const getActorKeys = function () {
- return Object.keys(actors)
-}
-export const getTitle = function () {
- return title
-}
+export const getActors = function() {
+ return actors;
+};
+export const getActor = function(id) {
+ return actors[id];
+};
+export const getActorKeys = function() {
+ return Object.keys(actors);
+};
+export const getTitle = function() {
+ return title;
+};
-export const clear = function () {
- actors = {}
- messages = []
-}
+export const clear = function() {
+ actors = {};
+ messages = [];
+};
export const LINETYPE = {
SOLID: 0,
@@ -69,97 +71,103 @@ export const LINETYPE = {
PAR_END: 21,
RECT_START: 22,
RECT_END: 23
-}
+};
export const ARROWTYPE = {
FILLED: 0,
OPEN: 1
-}
+};
export const PLACEMENT = {
LEFTOF: 0,
RIGHTOF: 1,
OVER: 2
-}
+};
-export const addNote = function (actor, placement, message) {
- const note = { actor: actor, placement: placement, message: message }
+export const addNote = function(actor, placement, message) {
+ const note = { actor: actor, placement: placement, message: message };
// Coerce actor into a [to, from, ...] array
- const actors = [].concat(actor, actor)
+ const actors = [].concat(actor, actor);
- notes.push(note)
- messages.push({ from: actors[0], to: actors[1], message: message, type: LINETYPE.NOTE, placement: placement })
-}
+ notes.push(note);
+ messages.push({
+ from: actors[0],
+ to: actors[1],
+ message: message,
+ type: LINETYPE.NOTE,
+ placement: placement
+ });
+};
-export const setTitle = function (titleText) {
- title = titleText
-}
+export const setTitle = function(titleText) {
+ title = titleText;
+};
-export const apply = function (param) {
+export const apply = function(param) {
if (param instanceof Array) {
- param.forEach(function (item) {
- apply(item)
- })
+ param.forEach(function(item) {
+ apply(item);
+ });
} else {
switch (param.type) {
case 'addActor':
- addActor(param.actor, param.actor, param.description)
- break
+ addActor(param.actor, param.actor, param.description);
+ break;
case 'activeStart':
- addSignal(param.actor, undefined, undefined, param.signalType)
- break
+ addSignal(param.actor, undefined, undefined, param.signalType);
+ break;
case 'activeEnd':
- addSignal(param.actor, undefined, undefined, param.signalType)
- break
+ addSignal(param.actor, undefined, undefined, param.signalType);
+ break;
case 'addNote':
- addNote(param.actor, param.placement, param.text)
- break
+ addNote(param.actor, param.placement, param.text);
+ break;
case 'addMessage':
- addSignal(param.from, param.to, param.msg, param.signalType)
- break
+ addSignal(param.from, param.to, param.msg, param.signalType);
+ break;
case 'loopStart':
- addSignal(undefined, undefined, param.loopText, param.signalType)
- break
+ addSignal(undefined, undefined, param.loopText, param.signalType);
+ break;
case 'loopEnd':
- addSignal(undefined, undefined, undefined, param.signalType)
- break
+ addSignal(undefined, undefined, undefined, param.signalType);
+ break;
case 'rectStart':
- addSignal(undefined, undefined, param.color, param.signalType)
- break
+ addSignal(undefined, undefined, param.color, param.signalType);
+ break;
case 'rectEnd':
- addSignal(undefined, undefined, undefined, param.signalType)
- break
+ addSignal(undefined, undefined, undefined, param.signalType);
+ break;
case 'optStart':
- addSignal(undefined, undefined, param.optText, param.signalType)
- break
+ addSignal(undefined, undefined, param.optText, param.signalType);
+ break;
case 'optEnd':
- addSignal(undefined, undefined, undefined, param.signalType)
- break
+ addSignal(undefined, undefined, undefined, param.signalType);
+ break;
case 'altStart':
- addSignal(undefined, undefined, param.altText, param.signalType)
- break
+ addSignal(undefined, undefined, param.altText, param.signalType);
+ break;
case 'else':
- addSignal(undefined, undefined, param.altText, param.signalType)
- break
+ addSignal(undefined, undefined, param.altText, param.signalType);
+ break;
case 'altEnd':
- addSignal(undefined, undefined, undefined, param.signalType)
- break
+ addSignal(undefined, undefined, undefined, param.signalType);
+ break;
case 'setTitle':
- setTitle(param.text)
- break
+ setTitle(param.text);
+ break;
case 'parStart':
- addSignal(undefined, undefined, param.parText, param.signalType)
- break
+ addSignal(undefined, undefined, param.parText, param.signalType);
+ break;
case 'and':
- addSignal(undefined, undefined, param.parText, param.signalType)
- break
+ addSignal(undefined, undefined, param.parText, param.signalType);
+ break;
case 'parEnd':
- addSignal(undefined, undefined, undefined, param.signalType)
- break
+ addSignal(undefined, undefined, undefined, param.signalType);
+ break;
}
}
-}
+};
export default {
addActor,
@@ -177,4 +185,4 @@ export default {
addNote,
setTitle,
apply
-}
+};
diff --git a/src/diagrams/sequence/sequenceDiagram.spec.js b/src/diagrams/sequence/sequenceDiagram.spec.js
index d9039e6c5..2ed1c411c 100644
--- a/src/diagrams/sequence/sequenceDiagram.spec.js
+++ b/src/diagrams/sequence/sequenceDiagram.spec.js
@@ -1,307 +1,316 @@
/* eslint-env jasmine */
-import { parser } from './parser/sequenceDiagram'
-import sequenceDb from './sequenceDb'
-import renderer from './sequenceRenderer'
+import { parser } from './parser/sequenceDiagram';
+import sequenceDb from './sequenceDb';
+import renderer from './sequenceRenderer';
-function addConf (conf, key, value) {
+function addConf(conf, key, value) {
if (value !== undefined) {
- conf[key] = value
+ conf[key] = value;
}
- return conf
+ return conf;
}
-describe('when parsing a sequenceDiagram', function () {
- beforeEach(function () {
- parser.yy = sequenceDb
- parser.yy.clear()
- })
- it('it should handle a sequenceDiagram defintion', function () {
- const str = 'sequenceDiagram\n' +
+describe('when parsing a sequenceDiagram', function() {
+ beforeEach(function() {
+ parser.yy = sequenceDb;
+ parser.yy.clear();
+ });
+ it('it should handle a sequenceDiagram defintion', function() {
+ const str =
+ 'sequenceDiagram\n' +
'Alice->Bob:Hello Bob, how are you?\n' +
'Note right of Bob: Bob thinks\n' +
- 'Bob-->Alice: I am good thanks!'
+ 'Bob-->Alice: I am good thanks!';
- parser.parse(str)
- const actors = parser.yy.getActors()
- expect(actors.Alice.description).toBe('Alice')
- actors.Bob.description = 'Bob'
+ parser.parse(str);
+ const actors = parser.yy.getActors();
+ expect(actors.Alice.description).toBe('Alice');
+ actors.Bob.description = 'Bob';
- const messages = parser.yy.getMessages()
+ const messages = parser.yy.getMessages();
- 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 () {
- const str = 'sequenceDiagram\n' +
+ 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() {
+ const 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!'
+ 'Bob-->Alice: I am good thanks!';
- parser.parse(str)
- const actors = parser.yy.getActors()
- expect(actors.Alice.description).toBe('Alice')
- actors.Bob.description = 'Bob'
+ parser.parse(str);
+ const actors = parser.yy.getActors();
+ expect(actors.Alice.description).toBe('Alice');
+ actors.Bob.description = 'Bob';
- const messages = parser.yy.getMessages()
- const title = parser.yy.getTitle()
+ const messages = parser.yy.getMessages();
+ const title = parser.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 () {
- const str = 'sequenceDiagram\n' +
+ 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() {
+ const str =
+ 'sequenceDiagram\n' +
'Alice->Bob:Hello Bob, how are - you?\n' +
- 'Bob-->Alice: I am good thanks!'
+ 'Bob-->Alice: I am good thanks!';
- parser.parse(str)
- const actors = parser.yy.getActors()
- expect(actors.Alice.description).toBe('Alice')
- actors.Bob.description = 'Bob'
+ parser.parse(str);
+ const actors = parser.yy.getActors();
+ expect(actors.Alice.description).toBe('Alice');
+ actors.Bob.description = 'Bob';
- const messages = parser.yy.getMessages()
+ const messages = parser.yy.getMessages();
- expect(messages.length).toBe(2)
- expect(messages[0].from).toBe('Alice')
- expect(messages[1].from).toBe('Bob')
- })
- it('it should alias participants', function () {
- const str = 'sequenceDiagram\n' +
+ expect(messages.length).toBe(2);
+ expect(messages[0].from).toBe('Alice');
+ expect(messages[1].from).toBe('Bob');
+ });
+ it('it should alias participants', function() {
+ const str =
+ 'sequenceDiagram\n' +
'participant A as Alice\n' +
'participant B as Bob\n' +
'A->B:Hello Bob, how are you?\n' +
- 'B-->A: I am good thanks!'
+ 'B-->A: I am good thanks!';
- parser.parse(str)
+ parser.parse(str);
- const actors = parser.yy.getActors()
- expect(Object.keys(actors)).toEqual(['A', 'B'])
- expect(actors.A.description).toBe('Alice')
- expect(actors.B.description).toBe('Bob')
+ const actors = parser.yy.getActors();
+ expect(Object.keys(actors)).toEqual(['A', 'B']);
+ expect(actors.A.description).toBe('Alice');
+ expect(actors.B.description).toBe('Bob');
- const messages = parser.yy.getMessages()
- expect(messages.length).toBe(2)
- expect(messages[0].from).toBe('A')
- expect(messages[1].from).toBe('B')
- })
- it('it should handle in async messages', function () {
- const str = 'sequenceDiagram\n' +
- 'Alice-xBob:Hello Bob, how are you?'
+ const messages = parser.yy.getMessages();
+ expect(messages.length).toBe(2);
+ expect(messages[0].from).toBe('A');
+ expect(messages[1].from).toBe('B');
+ });
+ it('it should handle in async messages', function() {
+ const str = 'sequenceDiagram\n' + 'Alice-xBob:Hello Bob, how are you?';
- parser.parse(str)
- const actors = parser.yy.getActors()
- expect(actors.Alice.description).toBe('Alice')
- expect(actors.Bob.description).toBe('Bob')
+ parser.parse(str);
+ const actors = parser.yy.getActors();
+ expect(actors.Alice.description).toBe('Alice');
+ expect(actors.Bob.description).toBe('Bob');
- const messages = parser.yy.getMessages()
+ const messages = parser.yy.getMessages();
- expect(messages.length).toBe(1)
- expect(messages[0].type).toBe(parser.yy.LINETYPE.SOLID_CROSS)
- })
- it('it should handle in async dotted messages', function () {
- const str = 'sequenceDiagram\n' +
- 'Alice--xBob:Hello Bob, how are you?'
+ expect(messages.length).toBe(1);
+ expect(messages[0].type).toBe(parser.yy.LINETYPE.SOLID_CROSS);
+ });
+ it('it should handle in async dotted messages', function() {
+ const str = 'sequenceDiagram\n' + 'Alice--xBob:Hello Bob, how are you?';
- parser.parse(str)
- const actors = parser.yy.getActors()
- expect(actors.Alice.description).toBe('Alice')
- expect(actors.Bob.description).toBe('Bob')
+ parser.parse(str);
+ const actors = parser.yy.getActors();
+ expect(actors.Alice.description).toBe('Alice');
+ expect(actors.Bob.description).toBe('Bob');
- const messages = parser.yy.getMessages()
+ const messages = parser.yy.getMessages();
- expect(messages.length).toBe(1)
- expect(messages[0].type).toBe(parser.yy.LINETYPE.DOTTED_CROSS)
- })
- it('it should handle in arrow messages', function () {
- const str = 'sequenceDiagram\n' +
- 'Alice->>Bob:Hello Bob, how are you?'
+ expect(messages.length).toBe(1);
+ expect(messages[0].type).toBe(parser.yy.LINETYPE.DOTTED_CROSS);
+ });
+ it('it should handle in arrow messages', function() {
+ const str = 'sequenceDiagram\n' + 'Alice->>Bob:Hello Bob, how are you?';
- parser.parse(str)
- const actors = parser.yy.getActors()
- expect(actors.Alice.description).toBe('Alice')
- expect(actors.Bob.description).toBe('Bob')
+ parser.parse(str);
+ const actors = parser.yy.getActors();
+ expect(actors.Alice.description).toBe('Alice');
+ expect(actors.Bob.description).toBe('Bob');
- const messages = parser.yy.getMessages()
+ const messages = parser.yy.getMessages();
- expect(messages.length).toBe(1)
- expect(messages[0].type).toBe(parser.yy.LINETYPE.SOLID)
- })
- it('it should handle in arrow messages', function () {
- const str = 'sequenceDiagram\n' +
- 'Alice-->>Bob:Hello Bob, how are you?'
+ expect(messages.length).toBe(1);
+ expect(messages[0].type).toBe(parser.yy.LINETYPE.SOLID);
+ });
+ it('it should handle in arrow messages', function() {
+ const str = 'sequenceDiagram\n' + 'Alice-->>Bob:Hello Bob, how are you?';
- parser.parse(str)
- const actors = parser.yy.getActors()
- expect(actors.Alice.description).toBe('Alice')
- expect(actors.Bob.description).toBe('Bob')
+ parser.parse(str);
+ const actors = parser.yy.getActors();
+ expect(actors.Alice.description).toBe('Alice');
+ expect(actors.Bob.description).toBe('Bob');
- const messages = parser.yy.getMessages()
+ const messages = parser.yy.getMessages();
- expect(messages.length).toBe(1)
- expect(messages[0].type).toBe(parser.yy.LINETYPE.DOTTED)
- })
- it('it should handle actor activation', function () {
- const str = 'sequenceDiagram\n' +
+ expect(messages.length).toBe(1);
+ expect(messages[0].type).toBe(parser.yy.LINETYPE.DOTTED);
+ });
+ it('it should handle actor activation', function() {
+ const str =
+ 'sequenceDiagram\n' +
'Alice-->>Bob:Hello Bob, how are you?\n' +
'activate Bob\n' +
- 'Bob-->>Alice:Hello Alice, I\'m fine and you?\n' +
- 'deactivate Bob'
+ "Bob-->>Alice:Hello Alice, I'm fine and you?\n" +
+ 'deactivate Bob';
- parser.parse(str)
- const actors = parser.yy.getActors()
- expect(actors.Alice.description).toBe('Alice')
- expect(actors.Bob.description).toBe('Bob')
+ parser.parse(str);
+ const actors = parser.yy.getActors();
+ expect(actors.Alice.description).toBe('Alice');
+ expect(actors.Bob.description).toBe('Bob');
- const messages = parser.yy.getMessages()
+ const messages = parser.yy.getMessages();
- expect(messages.length).toBe(4)
- expect(messages[0].type).toBe(parser.yy.LINETYPE.DOTTED)
- expect(messages[1].type).toBe(parser.yy.LINETYPE.ACTIVE_START)
- expect(messages[1].from.actor).toBe('Bob')
- expect(messages[2].type).toBe(parser.yy.LINETYPE.DOTTED)
- expect(messages[3].type).toBe(parser.yy.LINETYPE.ACTIVE_END)
- expect(messages[3].from.actor).toBe('Bob')
- })
- it('it should handle actor one line notation activation', function () {
- const str = 'sequenceDiagram\n' +
+ expect(messages.length).toBe(4);
+ expect(messages[0].type).toBe(parser.yy.LINETYPE.DOTTED);
+ expect(messages[1].type).toBe(parser.yy.LINETYPE.ACTIVE_START);
+ expect(messages[1].from.actor).toBe('Bob');
+ expect(messages[2].type).toBe(parser.yy.LINETYPE.DOTTED);
+ expect(messages[3].type).toBe(parser.yy.LINETYPE.ACTIVE_END);
+ expect(messages[3].from.actor).toBe('Bob');
+ });
+ it('it should handle actor one line notation activation', function() {
+ const str =
+ 'sequenceDiagram\n' +
'Alice-->>+Bob:Hello Bob, how are you?\n' +
- 'Bob-->>- Alice:Hello Alice, I\'m fine and you?'
+ "Bob-->>- Alice:Hello Alice, I'm fine and you?";
- parser.parse(str)
- const actors = parser.yy.getActors()
- expect(actors.Alice.description).toBe('Alice')
- expect(actors.Bob.description).toBe('Bob')
+ parser.parse(str);
+ const actors = parser.yy.getActors();
+ expect(actors.Alice.description).toBe('Alice');
+ expect(actors.Bob.description).toBe('Bob');
- const messages = parser.yy.getMessages()
+ const messages = parser.yy.getMessages();
- expect(messages.length).toBe(4)
- expect(messages[0].type).toBe(parser.yy.LINETYPE.DOTTED)
- expect(messages[1].type).toBe(parser.yy.LINETYPE.ACTIVE_START)
- expect(messages[1].from.actor).toBe('Bob')
- expect(messages[2].type).toBe(parser.yy.LINETYPE.DOTTED)
- expect(messages[3].type).toBe(parser.yy.LINETYPE.ACTIVE_END)
- expect(messages[3].from.actor).toBe('Bob')
- })
- it('it should handle stacked activations', function () {
- const str = 'sequenceDiagram\n' +
+ expect(messages.length).toBe(4);
+ expect(messages[0].type).toBe(parser.yy.LINETYPE.DOTTED);
+ expect(messages[1].type).toBe(parser.yy.LINETYPE.ACTIVE_START);
+ expect(messages[1].from.actor).toBe('Bob');
+ expect(messages[2].type).toBe(parser.yy.LINETYPE.DOTTED);
+ expect(messages[3].type).toBe(parser.yy.LINETYPE.ACTIVE_END);
+ expect(messages[3].from.actor).toBe('Bob');
+ });
+ it('it should handle stacked activations', function() {
+ const str =
+ 'sequenceDiagram\n' +
'Alice-->>+Bob:Hello Bob, how are you?\n' +
'Bob-->>+Carol:Carol, let me introduce Alice?\n' +
'Bob-->>- Alice:Hello Alice, please meet Carol?\n' +
- 'Carol->>- Bob:Oh Bob, I\'m so happy to be here!'
+ "Carol->>- Bob:Oh Bob, I'm so happy to be here!";
- parser.parse(str)
- const actors = parser.yy.getActors()
- expect(actors.Alice.description).toBe('Alice')
- expect(actors.Bob.description).toBe('Bob')
+ parser.parse(str);
+ const actors = parser.yy.getActors();
+ expect(actors.Alice.description).toBe('Alice');
+ expect(actors.Bob.description).toBe('Bob');
- const messages = parser.yy.getMessages()
+ const messages = parser.yy.getMessages();
- expect(messages.length).toBe(8)
- expect(messages[0].type).toBe(parser.yy.LINETYPE.DOTTED)
- expect(messages[1].type).toBe(parser.yy.LINETYPE.ACTIVE_START)
- expect(messages[1].from.actor).toBe('Bob')
- expect(messages[2].type).toBe(parser.yy.LINETYPE.DOTTED)
- expect(messages[3].type).toBe(parser.yy.LINETYPE.ACTIVE_START)
- expect(messages[3].from.actor).toBe('Carol')
- expect(messages[5].type).toBe(parser.yy.LINETYPE.ACTIVE_END)
- expect(messages[5].from.actor).toBe('Bob')
- expect(messages[7].type).toBe(parser.yy.LINETYPE.ACTIVE_END)
- expect(messages[7].from.actor).toBe('Carol')
- })
- it('it should handle comments in a sequenceDiagram', function () {
- const str = 'sequenceDiagram\n' +
+ expect(messages.length).toBe(8);
+ expect(messages[0].type).toBe(parser.yy.LINETYPE.DOTTED);
+ expect(messages[1].type).toBe(parser.yy.LINETYPE.ACTIVE_START);
+ expect(messages[1].from.actor).toBe('Bob');
+ expect(messages[2].type).toBe(parser.yy.LINETYPE.DOTTED);
+ expect(messages[3].type).toBe(parser.yy.LINETYPE.ACTIVE_START);
+ expect(messages[3].from.actor).toBe('Carol');
+ expect(messages[5].type).toBe(parser.yy.LINETYPE.ACTIVE_END);
+ expect(messages[5].from.actor).toBe('Bob');
+ expect(messages[7].type).toBe(parser.yy.LINETYPE.ACTIVE_END);
+ expect(messages[7].from.actor).toBe('Carol');
+ });
+ it('it should handle comments in a sequenceDiagram', function() {
+ const str =
+ 'sequenceDiagram\n' +
'Alice->Bob: Hello Bob, how are you?\n' +
'%% Comment\n' +
'Note right of Bob: Bob thinks\n' +
- 'Bob-->Alice: I am good thanks!'
+ 'Bob-->Alice: I am good thanks!';
- parser.parse(str)
- const actors = parser.yy.getActors()
- expect(actors.Alice.description).toBe('Alice')
- actors.Bob.description = 'Bob'
+ parser.parse(str);
+ const actors = parser.yy.getActors();
+ expect(actors.Alice.description).toBe('Alice');
+ actors.Bob.description = 'Bob';
- const messages = parser.yy.getMessages()
+ const messages = parser.yy.getMessages();
- expect(messages.length).toBe(3)
- expect(messages[0].from).toBe('Alice')
- expect(messages[2].from).toBe('Bob')
- })
- it('it should handle new lines in a sequenceDiagram', function () {
- const str = 'sequenceDiagram\n' +
+ expect(messages.length).toBe(3);
+ expect(messages[0].from).toBe('Alice');
+ expect(messages[2].from).toBe('Bob');
+ });
+ it('it should handle new lines in a sequenceDiagram', function() {
+ const str =
+ 'sequenceDiagram\n' +
'Alice->Bob: Hello Bob, how are you?\n\n' +
'%% Comment\n' +
'Note right of Bob: Bob thinks\n' +
- 'Bob-->Alice: I am good thanks!\n'
+ 'Bob-->Alice: I am good thanks!\n';
- parser.parse(str)
- const actors = parser.yy.getActors()
- expect(actors.Alice.description).toBe('Alice')
- actors.Bob.description = 'Bob'
+ parser.parse(str);
+ const actors = parser.yy.getActors();
+ expect(actors.Alice.description).toBe('Alice');
+ actors.Bob.description = 'Bob';
- const messages = parser.yy.getMessages()
+ const messages = parser.yy.getMessages();
- expect(messages.length).toBe(3)
- expect(messages[0].from).toBe('Alice')
- expect(messages[2].from).toBe('Bob')
- })
- it('it should handle semicolons', function () {
- const str = 'sequenceDiagram;' +
+ expect(messages.length).toBe(3);
+ expect(messages[0].from).toBe('Alice');
+ expect(messages[2].from).toBe('Bob');
+ });
+ it('it should handle semicolons', function() {
+ const str =
+ 'sequenceDiagram;' +
'Alice->Bob: Hello Bob, how are you?;' +
'Note right of Bob: Bob thinks;' +
- 'Bob-->Alice: I am good thanks!;'
+ 'Bob-->Alice: I am good thanks!;';
- parser.parse(str)
- const actors = parser.yy.getActors()
- expect(actors.Alice.description).toBe('Alice')
- actors.Bob.description = 'Bob'
+ parser.parse(str);
+ const actors = parser.yy.getActors();
+ expect(actors.Alice.description).toBe('Alice');
+ actors.Bob.description = 'Bob';
- const messages = parser.yy.getMessages()
+ const messages = parser.yy.getMessages();
- expect(messages.length).toBe(3)
- expect(messages[0].from).toBe('Alice')
- expect(messages[2].from).toBe('Bob')
- })
- it('it should handle one leading space in lines in a sequenceDiagram', function () {
- const str = 'sequenceDiagram\n' +
+ expect(messages.length).toBe(3);
+ expect(messages[0].from).toBe('Alice');
+ expect(messages[2].from).toBe('Bob');
+ });
+ it('it should handle one leading space in lines in a sequenceDiagram', function() {
+ const str =
+ 'sequenceDiagram\n' +
' Alice->Bob: Hello Bob, how are you?\n\n' +
'%% Comment\n' +
'Note right of Bob: Bob thinks\n' +
- 'Bob-->Alice: I am good thanks!'
+ 'Bob-->Alice: I am good thanks!';
- parser.parse(str)
- const actors = parser.yy.getActors()
- expect(actors.Alice.description).toBe('Alice')
- actors.Bob.description = 'Bob'
+ parser.parse(str);
+ const actors = parser.yy.getActors();
+ expect(actors.Alice.description).toBe('Alice');
+ actors.Bob.description = 'Bob';
- const messages = parser.yy.getMessages()
+ const messages = parser.yy.getMessages();
- expect(messages.length).toBe(3)
- expect(messages[0].from).toBe('Alice')
- expect(messages[2].from).toBe('Bob')
- })
- it('it should handle several leading spaces in lines in a sequenceDiagram', function () {
- const str = 'sequenceDiagram\n' +
+ expect(messages.length).toBe(3);
+ expect(messages[0].from).toBe('Alice');
+ expect(messages[2].from).toBe('Bob');
+ });
+ it('it should handle several leading spaces in lines in a sequenceDiagram', function() {
+ const str =
+ 'sequenceDiagram\n' +
' Alice->Bob: Hello Bob, how are you?\n\n' +
'%% Comment\n' +
'Note right of Bob: Bob thinks\n' +
- 'Bob-->Alice: I am good thanks!'
+ 'Bob-->Alice: I am good thanks!';
- parser.parse(str)
- const actors = parser.yy.getActors()
- expect(actors.Alice.description).toBe('Alice')
- actors.Bob.description = 'Bob'
+ parser.parse(str);
+ const actors = parser.yy.getActors();
+ expect(actors.Alice.description).toBe('Alice');
+ actors.Bob.description = 'Bob';
- const messages = parser.yy.getMessages()
+ const messages = parser.yy.getMessages();
- expect(messages.length).toBe(3)
- expect(messages[0].from).toBe('Alice')
- expect(messages[2].from).toBe('Bob')
- })
- it('it should handle several leading spaces in lines in a sequenceDiagram', function () {
- const str = 'sequenceDiagram\n' +
+ expect(messages.length).toBe(3);
+ expect(messages[0].from).toBe('Alice');
+ expect(messages[2].from).toBe('Bob');
+ });
+ it('it should handle several leading spaces in lines in a sequenceDiagram', function() {
+ const str =
+ 'sequenceDiagram\n' +
'participant Alice\n' +
'participant Bob\n' +
'Alice->John: Hello John, how are you?\n' +
@@ -311,65 +320,66 @@ describe('when parsing a sequenceDiagram', function () {
'Note right of John: Rational thoughts
prevail...\n' +
' John-->Alice: Great!\n' +
' John->Bob: How about you?\n' +
- 'Bob-->John: Jolly good!'
+ 'Bob-->John: Jolly good!';
- parser.parse(str)
- const actors = parser.yy.getActors()
- expect(actors.Alice.description).toBe('Alice')
- actors.Bob.description = 'Bob'
+ parser.parse(str);
+ const actors = parser.yy.getActors();
+ expect(actors.Alice.description).toBe('Alice');
+ actors.Bob.description = 'Bob';
- const messages = parser.yy.getMessages()
+ const messages = parser.yy.getMessages();
- expect(messages.length).toBe(8)
- expect(messages[0].from).toBe('Alice')
- expect(messages[2].from).toBe('John')
- })
- it('it should handle notes over a single actor', function () {
- const str = 'sequenceDiagram\n' +
- 'Alice->Bob: Hello Bob, how are you?\n' +
- 'Note over Bob: Bob thinks\n'
+ expect(messages.length).toBe(8);
+ expect(messages[0].from).toBe('Alice');
+ expect(messages[2].from).toBe('John');
+ });
+ it('it should handle notes over a single actor', function() {
+ const str =
+ 'sequenceDiagram\n' + 'Alice->Bob: Hello Bob, how are you?\n' + 'Note over Bob: Bob thinks\n';
- parser.parse(str)
+ parser.parse(str);
- const messages = parser.yy.getMessages()
- expect(messages[1].from).toBe('Bob')
- expect(messages[1].to).toBe('Bob')
- })
- it('it should handle notes over multiple actors', function () {
- const str = 'sequenceDiagram\n' +
+ const messages = parser.yy.getMessages();
+ expect(messages[1].from).toBe('Bob');
+ expect(messages[1].to).toBe('Bob');
+ });
+ it('it should handle notes over multiple actors', function() {
+ const str =
+ 'sequenceDiagram\n' +
'Alice->Bob: Hello Bob, how are you?\n' +
'Note over Alice,Bob: confusion\n' +
- 'Note over Bob,Alice: resolution\n'
+ 'Note over Bob,Alice: resolution\n';
- parser.parse(str)
+ parser.parse(str);
- const messages = parser.yy.getMessages()
- expect(messages[1].from).toBe('Alice')
- expect(messages[1].to).toBe('Bob')
- expect(messages[2].from).toBe('Bob')
- expect(messages[2].to).toBe('Alice')
- })
- it('it should handle loop statements', function () {
- const str = 'sequenceDiagram\n' +
+ const messages = parser.yy.getMessages();
+ expect(messages[1].from).toBe('Alice');
+ expect(messages[1].to).toBe('Bob');
+ expect(messages[2].from).toBe('Bob');
+ expect(messages[2].to).toBe('Alice');
+ });
+ it('it should handle loop statements', function() {
+ const str =
+ 'sequenceDiagram\n' +
'Alice->Bob: Hello Bob, how are you?\n\n' +
'%% Comment\n' +
'Note right of Bob: Bob thinks\n' +
'loop Multiple happy responses\n\n' +
'Bob-->Alice: I am good thanks!\n' +
- 'end'
+ 'end';
- parser.parse(str)
- const actors = parser.yy.getActors()
- expect(actors.Alice.description).toBe('Alice')
- actors.Bob.description = 'Bob'
+ parser.parse(str);
+ const actors = parser.yy.getActors();
+ expect(actors.Alice.description).toBe('Alice');
+ actors.Bob.description = 'Bob';
- const messages = parser.yy.getMessages()
+ const messages = parser.yy.getMessages();
- expect(messages.length).toBe(5)
- expect(messages[0].from).toBe('Alice')
- expect(messages[1].from).toBe('Bob')
- })
- it('it should add a rect around sequence', function () {
+ expect(messages.length).toBe(5);
+ expect(messages[0].from).toBe('Alice');
+ expect(messages[1].from).toBe('Bob');
+ });
+ it('it should add a rect around sequence', function() {
const str = `
sequenceDiagram
Alice->Bob: Hello Bob, how are you?
@@ -378,22 +388,22 @@ describe('when parsing a sequenceDiagram', function () {
Note right of Bob: Bob thinks
Bob-->Alice: I am good thanks
end
- `
+ `;
- parser.parse(str)
- const actors = parser.yy.getActors()
- expect(actors.Alice.description).toBe('Alice')
- actors.Bob.description = 'Bob'
+ parser.parse(str);
+ const actors = parser.yy.getActors();
+ expect(actors.Alice.description).toBe('Alice');
+ actors.Bob.description = 'Bob';
- const messages = parser.yy.getMessages()
- expect(messages[1].type).toEqual(parser.yy.LINETYPE.RECT_START)
- expect(messages[1].message).toBe('rgb(200, 255, 200)')
- expect(messages[2].type).toEqual(parser.yy.LINETYPE.NOTE)
- expect(messages[3].type).toEqual(parser.yy.LINETYPE.DOTTED_OPEN)
- expect(messages[4].type).toEqual(parser.yy.LINETYPE.RECT_END)
- })
+ const messages = parser.yy.getMessages();
+ expect(messages[1].type).toEqual(parser.yy.LINETYPE.RECT_START);
+ expect(messages[1].message).toBe('rgb(200, 255, 200)');
+ expect(messages[2].type).toEqual(parser.yy.LINETYPE.NOTE);
+ expect(messages[3].type).toEqual(parser.yy.LINETYPE.DOTTED_OPEN);
+ expect(messages[4].type).toEqual(parser.yy.LINETYPE.RECT_END);
+ });
- it('it should allow for nested rects', function () {
+ it('it should allow for nested rects', function() {
const str = `
sequenceDiagram
Alice->Bob: Hello Bob, how are you?
@@ -404,44 +414,46 @@ describe('when parsing a sequenceDiagram', function () {
end
Bob-->Alice: I am good thanks
end
- `
- parser.parse(str)
- const actors = parser.yy.getActors()
- expect(actors.Alice.description).toBe('Alice')
- actors.Bob.description = 'Bob'
+ `;
+ parser.parse(str);
+ const actors = parser.yy.getActors();
+ expect(actors.Alice.description).toBe('Alice');
+ actors.Bob.description = 'Bob';
- const messages = parser.yy.getMessages()
- expect(messages[1].type).toEqual(parser.yy.LINETYPE.RECT_START)
- expect(messages[1].message).toBe('rgb(200, 255, 200)')
- expect(messages[2].type).toEqual(parser.yy.LINETYPE.RECT_START)
- expect(messages[2].message).toBe('rgb(0, 0, 0)')
- expect(messages[3].type).toEqual(parser.yy.LINETYPE.NOTE)
- expect(messages[4].type).toEqual(parser.yy.LINETYPE.RECT_END)
- expect(messages[5].type).toEqual(parser.yy.LINETYPE.DOTTED_OPEN)
- expect(messages[6].type).toEqual(parser.yy.LINETYPE.RECT_END)
- })
- it('it should handle opt statements', function () {
- const str = 'sequenceDiagram\n' +
+ const messages = parser.yy.getMessages();
+ expect(messages[1].type).toEqual(parser.yy.LINETYPE.RECT_START);
+ expect(messages[1].message).toBe('rgb(200, 255, 200)');
+ expect(messages[2].type).toEqual(parser.yy.LINETYPE.RECT_START);
+ expect(messages[2].message).toBe('rgb(0, 0, 0)');
+ expect(messages[3].type).toEqual(parser.yy.LINETYPE.NOTE);
+ expect(messages[4].type).toEqual(parser.yy.LINETYPE.RECT_END);
+ expect(messages[5].type).toEqual(parser.yy.LINETYPE.DOTTED_OPEN);
+ expect(messages[6].type).toEqual(parser.yy.LINETYPE.RECT_END);
+ });
+ it('it should handle opt statements', function() {
+ const str =
+ 'sequenceDiagram\n' +
'Alice->Bob: Hello Bob, how are you?\n\n' +
'%% Comment\n' +
'Note right of Bob: Bob thinks\n' +
'opt Perhaps a happy response\n\n' +
'Bob-->Alice: I am good thanks!\n' +
- 'end'
+ 'end';
- parser.parse(str)
- const actors = parser.yy.getActors()
- expect(actors.Alice.description).toBe('Alice')
- actors.Bob.description = 'Bob'
+ parser.parse(str);
+ const actors = parser.yy.getActors();
+ expect(actors.Alice.description).toBe('Alice');
+ actors.Bob.description = 'Bob';
- const messages = parser.yy.getMessages()
+ const messages = parser.yy.getMessages();
- expect(messages.length).toBe(5)
- expect(messages[0].from).toBe('Alice')
- expect(messages[1].from).toBe('Bob')
- })
- it('it should handle alt statements', function () {
- const str = 'sequenceDiagram\n' +
+ expect(messages.length).toBe(5);
+ expect(messages[0].from).toBe('Alice');
+ expect(messages[1].from).toBe('Bob');
+ });
+ it('it should handle alt statements', function() {
+ const str =
+ 'sequenceDiagram\n' +
'Alice->Bob: Hello Bob, how are you?\n\n' +
'%% Comment\n' +
'Note right of Bob: Bob thinks\n' +
@@ -449,22 +461,23 @@ describe('when parsing a sequenceDiagram', function () {
'Bob-->Alice: I am good thanks!\n' +
'else isSick\n' +
'Bob-->Alice: Feel sick...\n' +
- 'end'
+ 'end';
- parser.parse(str)
- const actors = parser.yy.getActors()
+ parser.parse(str);
+ const actors = parser.yy.getActors();
- expect(actors.Alice.description).toBe('Alice')
- actors.Bob.description = 'Bob'
+ expect(actors.Alice.description).toBe('Alice');
+ actors.Bob.description = 'Bob';
- const messages = parser.yy.getMessages()
+ const messages = parser.yy.getMessages();
- expect(messages.length).toBe(7)
- expect(messages[0].from).toBe('Alice')
- expect(messages[1].from).toBe('Bob')
- })
- it('it should handle alt statements with multiple elses', function () {
- const str = 'sequenceDiagram\n' +
+ expect(messages.length).toBe(7);
+ expect(messages[0].from).toBe('Alice');
+ expect(messages[1].from).toBe('Bob');
+ });
+ it('it should handle alt statements with multiple elses', function() {
+ const str =
+ 'sequenceDiagram\n' +
'Alice->Bob: Hello Bob, how are you?\n\n' +
'%% Comment\n' +
'Note right of Bob: Bob thinks\n' +
@@ -474,21 +487,22 @@ describe('when parsing a sequenceDiagram', function () {
'Bob-->Alice: Feel sick...\n' +
'else default\n' +
'Bob-->Alice: :-)\n' +
- 'end'
- parser.parse(str)
- const messages = parser.yy.getMessages()
- expect(messages.length).toBe(9)
- expect(messages[1].from).toBe('Bob')
- expect(messages[2].type).toBe(parser.yy.LINETYPE.ALT_START)
- expect(messages[3].from).toBe('Bob')
- expect(messages[4].type).toBe(parser.yy.LINETYPE.ALT_ELSE)
- expect(messages[5].from).toBe('Bob')
- expect(messages[6].type).toBe(parser.yy.LINETYPE.ALT_ELSE)
- expect(messages[7].from).toBe('Bob')
- expect(messages[8].type).toBe(parser.yy.LINETYPE.ALT_END)
- })
- it('it should handle par statements a sequenceDiagram', function () {
- const str = 'sequenceDiagram\n' +
+ 'end';
+ parser.parse(str);
+ const messages = parser.yy.getMessages();
+ expect(messages.length).toBe(9);
+ expect(messages[1].from).toBe('Bob');
+ expect(messages[2].type).toBe(parser.yy.LINETYPE.ALT_START);
+ expect(messages[3].from).toBe('Bob');
+ expect(messages[4].type).toBe(parser.yy.LINETYPE.ALT_ELSE);
+ expect(messages[5].from).toBe('Bob');
+ expect(messages[6].type).toBe(parser.yy.LINETYPE.ALT_ELSE);
+ expect(messages[7].from).toBe('Bob');
+ expect(messages[8].type).toBe(parser.yy.LINETYPE.ALT_END);
+ });
+ it('it should handle par statements a sequenceDiagram', function() {
+ const str =
+ 'sequenceDiagram\n' +
'par Parallel one\n' +
'Alice->>Bob: Hello Bob, how are you?\n' +
'Bob-->>Alice: I am good thanks!\n' +
@@ -497,162 +511,170 @@ describe('when parsing a sequenceDiagram', function () {
'Bob-->>Alice: Fine!\n' +
'and Parallel three\n' +
'Alice->>Bob: What do you think about it?\n' +
- 'Bob-->>Alice: It\'s good!\n' +
- 'end'
+ "Bob-->>Alice: It's good!\n" +
+ 'end';
- parser.parse(str)
- const actors = parser.yy.getActors()
+ parser.parse(str);
+ const actors = parser.yy.getActors();
- expect(actors.Alice.description).toBe('Alice')
- expect(actors.Bob.description).toBe('Bob')
+ expect(actors.Alice.description).toBe('Alice');
+ expect(actors.Bob.description).toBe('Bob');
- const messages = parser.yy.getMessages()
+ const messages = parser.yy.getMessages();
- expect(messages.length).toBe(10)
- expect(messages[0].message).toBe('Parallel one')
- expect(messages[1].from).toBe('Alice')
- expect(messages[2].from).toBe('Bob')
- })
- it('it should handle special characters in signals', function () {
- const str = 'sequenceDiagram\n' +
- 'Alice->Bob: -:<>,;# comment'
+ expect(messages.length).toBe(10);
+ expect(messages[0].message).toBe('Parallel one');
+ expect(messages[1].from).toBe('Alice');
+ expect(messages[2].from).toBe('Bob');
+ });
+ it('it should handle special characters in signals', function() {
+ const str = 'sequenceDiagram\n' + 'Alice->Bob: -:<>,;# comment';
- parser.parse(str)
+ parser.parse(str);
- const messages = parser.yy.getMessages()
- expect(messages[0].message).toBe('-:<>,')
- })
- it('it should handle special characters in notes', function () {
- const str = 'sequenceDiagram\n' +
+ const messages = parser.yy.getMessages();
+ expect(messages[0].message).toBe('-:<>,');
+ });
+ it('it should handle special characters in notes', function() {
+ const str =
+ 'sequenceDiagram\n' +
'Alice->Bob: Hello Bob, how are you?\n' +
- 'Note right of Bob: -:<>,;# comment'
+ 'Note right of Bob: -:<>,;# comment';
- parser.parse(str)
+ parser.parse(str);
- const messages = parser.yy.getMessages()
- expect(messages[1].message).toBe('-:<>,')
- })
- it('it should handle special characters in loop', function () {
- const str = 'sequenceDiagram\n' +
+ const messages = parser.yy.getMessages();
+ expect(messages[1].message).toBe('-:<>,');
+ });
+ it('it should handle special characters in loop', function() {
+ const str =
+ 'sequenceDiagram\n' +
'Alice->Bob: Hello Bob, how are you?\n' +
'loop -:<>,;# comment\n' +
'Bob-->Alice: I am good thanks!\n' +
- 'end'
+ 'end';
- parser.parse(str)
+ parser.parse(str);
- const messages = parser.yy.getMessages()
- expect(messages[1].message).toBe('-:<>,')
- })
- it('it should handle special characters in opt', function () {
- const str = 'sequenceDiagram\n' +
+ const messages = parser.yy.getMessages();
+ expect(messages[1].message).toBe('-:<>,');
+ });
+ it('it should handle special characters in opt', function() {
+ const str =
+ 'sequenceDiagram\n' +
'Alice->Bob: Hello Bob, how are you?\n' +
'opt -:<>,;# comment\n' +
'Bob-->Alice: I am good thanks!\n' +
- 'end'
+ 'end';
- parser.parse(str)
+ parser.parse(str);
- const messages = parser.yy.getMessages()
- expect(messages[1].message).toBe('-:<>,')
- })
- it('it should handle special characters in alt', function () {
- const str = 'sequenceDiagram\n' +
+ const messages = parser.yy.getMessages();
+ expect(messages[1].message).toBe('-:<>,');
+ });
+ it('it should handle special characters in alt', function() {
+ const str =
+ 'sequenceDiagram\n' +
'Alice->Bob: Hello Bob, how are you?\n' +
'alt -:<>,;# comment\n' +
'Bob-->Alice: I am good thanks!\n' +
'else ,<>:-#; comment\n' +
'Bob-->Alice: I am good thanks!\n' +
- 'end'
+ 'end';
- parser.parse(str)
+ parser.parse(str);
- const messages = parser.yy.getMessages()
- expect(messages[1].message).toBe('-:<>,')
- expect(messages[3].message).toBe(',<>:-')
- })
- it('it should handle special characters in par', function () {
- const str = 'sequenceDiagram\n' +
+ const messages = parser.yy.getMessages();
+ expect(messages[1].message).toBe('-:<>,');
+ expect(messages[3].message).toBe(',<>:-');
+ });
+ it('it should handle special characters in par', function() {
+ const str =
+ 'sequenceDiagram\n' +
'Alice->Bob: Hello Bob, how are you?\n' +
'par -:<>,;# comment\n' +
'Bob-->Alice: I am good thanks!\n' +
'and ,<>:-#; comment\n' +
'Bob-->Alice: I am good thanks!\n' +
- 'end'
+ 'end';
- parser.parse(str)
+ parser.parse(str);
- const messages = parser.yy.getMessages()
- expect(messages[1].message).toBe('-:<>,')
- expect(messages[3].message).toBe(',<>:-')
- })
- it('it should handle no-label loop', function () {
- const str = 'sequenceDiagram\n' +
+ const messages = parser.yy.getMessages();
+ expect(messages[1].message).toBe('-:<>,');
+ expect(messages[3].message).toBe(',<>:-');
+ });
+ it('it should handle no-label loop', function() {
+ const str =
+ 'sequenceDiagram\n' +
'Alice->Bob: Hello Bob, how are you?\n' +
'loop\n' +
'Bob-->Alice: I am good thanks!\n' +
- 'end'
+ 'end';
- parser.parse(str)
+ parser.parse(str);
- const messages = parser.yy.getMessages()
- expect(messages[1].message).toBe('')
- expect(messages[2].message).toBe('I am good thanks!')
- })
- it('it should handle no-label opt', function () {
- const str = 'sequenceDiagram\n' +
+ const messages = parser.yy.getMessages();
+ expect(messages[1].message).toBe('');
+ expect(messages[2].message).toBe('I am good thanks!');
+ });
+ it('it should handle no-label opt', function() {
+ const str =
+ 'sequenceDiagram\n' +
'Alice->Bob: Hello Bob, how are you?\n' +
'opt # comment\n' +
'Bob-->Alice: I am good thanks!\n' +
- 'end'
+ 'end';
- parser.parse(str)
+ parser.parse(str);
- const messages = parser.yy.getMessages()
- expect(messages[1].message).toBe('')
- expect(messages[2].message).toBe('I am good thanks!')
- })
- it('it should handle no-label alt', function () {
- const str = 'sequenceDiagram\n' +
+ const messages = parser.yy.getMessages();
+ expect(messages[1].message).toBe('');
+ expect(messages[2].message).toBe('I am good thanks!');
+ });
+ it('it should handle no-label alt', function() {
+ const str =
+ 'sequenceDiagram\n' +
'Alice->Bob: Hello Bob, how are you?\n' +
'alt;' +
'Bob-->Alice: I am good thanks!\n' +
'else # comment\n' +
'Bob-->Alice: I am good thanks!\n' +
- 'end'
+ 'end';
- parser.parse(str)
+ parser.parse(str);
- const messages = parser.yy.getMessages()
- expect(messages[1].message).toBe('')
- expect(messages[2].message).toBe('I am good thanks!')
- expect(messages[3].message).toBe('')
- expect(messages[4].message).toBe('I am good thanks!')
- })
- it('it should handle no-label par', function () {
- const str = 'sequenceDiagram\n' +
+ const messages = parser.yy.getMessages();
+ expect(messages[1].message).toBe('');
+ expect(messages[2].message).toBe('I am good thanks!');
+ expect(messages[3].message).toBe('');
+ expect(messages[4].message).toBe('I am good thanks!');
+ });
+ it('it should handle no-label par', function() {
+ const str =
+ 'sequenceDiagram\n' +
'Alice->Bob: Hello Bob, how are you?\n' +
'par;' +
'Bob-->Alice: I am good thanks!\n' +
'and # comment\n' +
'Bob-->Alice: I am good thanks!\n' +
- 'end'
+ 'end';
- parser.parse(str)
+ parser.parse(str);
- const messages = parser.yy.getMessages()
- expect(messages[1].message).toBe('')
- expect(messages[2].message).toBe('I am good thanks!')
- expect(messages[3].message).toBe('')
- expect(messages[4].message).toBe('I am good thanks!')
- })
-})
+ const messages = parser.yy.getMessages();
+ expect(messages[1].message).toBe('');
+ expect(messages[2].message).toBe('I am good thanks!');
+ expect(messages[3].message).toBe('');
+ expect(messages[4].message).toBe('I am good thanks!');
+ });
+});
-describe('when checking the bounds in a sequenceDiagram', function () {
- let conf
- beforeEach(function () {
- parser.yy = sequenceDb
- parser.yy.clear()
+describe('when checking the bounds in a sequenceDiagram', function() {
+ let conf;
+ beforeEach(function() {
+ parser.yy = sequenceDb;
+ parser.yy.clear();
conf = {
diagramMarginX: 50,
diagramMarginY: 10,
@@ -664,131 +686,131 @@ describe('when checking the bounds in a sequenceDiagram', function () {
messageMargin: 40,
boxTextMargin: 15,
noteMargin: 25
- }
- renderer.setConf(conf)
- })
- it('it should handle a simple bound call', function () {
- renderer.bounds.init()
+ };
+ renderer.setConf(conf);
+ });
+ it('it should handle a simple bound call', function() {
+ renderer.bounds.init();
- renderer.bounds.insert(100, 100, 200, 200)
+ renderer.bounds.insert(100, 100, 200, 200);
- const bounds = renderer.bounds.getBounds()
- expect(bounds.startx).toBe(100)
- expect(bounds.starty).toBe(100)
- expect(bounds.stopx).toBe(200)
- expect(bounds.stopy).toBe(200)
- })
- it('it should handle an expanding bound', function () {
- renderer.bounds.init()
+ const bounds = renderer.bounds.getBounds();
+ expect(bounds.startx).toBe(100);
+ expect(bounds.starty).toBe(100);
+ expect(bounds.stopx).toBe(200);
+ expect(bounds.stopy).toBe(200);
+ });
+ it('it should handle an expanding bound', function() {
+ renderer.bounds.init();
- renderer.bounds.insert(100, 100, 200, 200)
- renderer.bounds.insert(25, 50, 300, 400)
+ renderer.bounds.insert(100, 100, 200, 200);
+ renderer.bounds.insert(25, 50, 300, 400);
- const bounds = renderer.bounds.getBounds()
- expect(bounds.startx).toBe(25)
- expect(bounds.starty).toBe(50)
- expect(bounds.stopx).toBe(300)
- expect(bounds.stopy).toBe(400)
- })
- it('it should handle inserts within the bound without changing the outer bounds', function () {
- renderer.bounds.init()
+ const bounds = renderer.bounds.getBounds();
+ expect(bounds.startx).toBe(25);
+ expect(bounds.starty).toBe(50);
+ expect(bounds.stopx).toBe(300);
+ expect(bounds.stopy).toBe(400);
+ });
+ it('it should handle inserts within the bound without changing the outer bounds', function() {
+ renderer.bounds.init();
- renderer.bounds.insert(100, 100, 200, 200)
- renderer.bounds.insert(25, 50, 300, 400)
- renderer.bounds.insert(125, 150, 150, 200)
+ renderer.bounds.insert(100, 100, 200, 200);
+ renderer.bounds.insert(25, 50, 300, 400);
+ renderer.bounds.insert(125, 150, 150, 200);
- const bounds = renderer.bounds.getBounds()
- expect(bounds.startx).toBe(25)
- expect(bounds.starty).toBe(50)
- expect(bounds.stopx).toBe(300)
- expect(bounds.stopy).toBe(400)
- })
- it('it should handle a loop without expanding the area', function () {
- renderer.bounds.init()
+ const bounds = renderer.bounds.getBounds();
+ expect(bounds.startx).toBe(25);
+ expect(bounds.starty).toBe(50);
+ expect(bounds.stopx).toBe(300);
+ expect(bounds.stopy).toBe(400);
+ });
+ it('it should handle a loop without expanding the area', function() {
+ renderer.bounds.init();
- renderer.bounds.insert(25, 50, 300, 400)
- renderer.bounds.verticalPos = 150
- renderer.bounds.newLoop()
- renderer.bounds.insert(125, 150, 150, 200)
+ renderer.bounds.insert(25, 50, 300, 400);
+ renderer.bounds.verticalPos = 150;
+ renderer.bounds.newLoop();
+ renderer.bounds.insert(125, 150, 150, 200);
- const loop = renderer.bounds.endLoop()
+ const loop = renderer.bounds.endLoop();
- expect(loop.startx).toBe(125 - conf.boxMargin)
- expect(loop.starty).toBe(150 - conf.boxMargin)
- expect(loop.stopx).toBe(150 + conf.boxMargin)
- expect(loop.stopy).toBe(200 + conf.boxMargin)
+ expect(loop.startx).toBe(125 - conf.boxMargin);
+ expect(loop.starty).toBe(150 - conf.boxMargin);
+ expect(loop.stopx).toBe(150 + conf.boxMargin);
+ expect(loop.stopy).toBe(200 + conf.boxMargin);
// Check bounds of first loop
- const bounds = renderer.bounds.getBounds()
+ const bounds = renderer.bounds.getBounds();
- expect(bounds.startx).toBe(25)
- expect(bounds.starty).toBe(50)
- expect(bounds.stopx).toBe(300)
- expect(bounds.stopy).toBe(400)
- })
- it('it should handle multiple loops withtout expanding the bounds', function () {
- renderer.bounds.init()
+ expect(bounds.startx).toBe(25);
+ expect(bounds.starty).toBe(50);
+ expect(bounds.stopx).toBe(300);
+ expect(bounds.stopy).toBe(400);
+ });
+ it('it should handle multiple loops withtout expanding the bounds', function() {
+ renderer.bounds.init();
- renderer.bounds.insert(100, 100, 1000, 1000)
- renderer.bounds.verticalPos = 200
- renderer.bounds.newLoop()
- renderer.bounds.newLoop()
- renderer.bounds.insert(200, 200, 300, 300)
+ renderer.bounds.insert(100, 100, 1000, 1000);
+ renderer.bounds.verticalPos = 200;
+ renderer.bounds.newLoop();
+ renderer.bounds.newLoop();
+ renderer.bounds.insert(200, 200, 300, 300);
// Check bounds of first loop
- let loop = renderer.bounds.endLoop()
+ let loop = renderer.bounds.endLoop();
- expect(loop.startx).toBe(200 - conf.boxMargin)
- expect(loop.starty).toBe(200 - conf.boxMargin)
- expect(loop.stopx).toBe(300 + conf.boxMargin)
- expect(loop.stopy).toBe(300 + conf.boxMargin)
+ expect(loop.startx).toBe(200 - conf.boxMargin);
+ expect(loop.starty).toBe(200 - conf.boxMargin);
+ expect(loop.stopx).toBe(300 + conf.boxMargin);
+ expect(loop.stopy).toBe(300 + conf.boxMargin);
// Check bounds of second loop
- loop = renderer.bounds.endLoop()
+ loop = renderer.bounds.endLoop();
- expect(loop.startx).toBe(200 - 2 * conf.boxMargin)
- expect(loop.starty).toBe(200 - 2 * conf.boxMargin)
- expect(loop.stopx).toBe(300 + 2 * conf.boxMargin)
- expect(loop.stopy).toBe(300 + 2 * conf.boxMargin)
+ expect(loop.startx).toBe(200 - 2 * conf.boxMargin);
+ expect(loop.starty).toBe(200 - 2 * conf.boxMargin);
+ expect(loop.stopx).toBe(300 + 2 * conf.boxMargin);
+ expect(loop.stopy).toBe(300 + 2 * conf.boxMargin);
// Check bounds of first loop
- const bounds = renderer.bounds.getBounds()
+ const bounds = renderer.bounds.getBounds();
- expect(bounds.startx).toBe(100)
- expect(bounds.starty).toBe(100)
- expect(bounds.stopx).toBe(1000)
- expect(bounds.stopy).toBe(1000)
- })
- it('it should handle a loop that expands the area', function () {
- renderer.bounds.init()
+ expect(bounds.startx).toBe(100);
+ expect(bounds.starty).toBe(100);
+ expect(bounds.stopx).toBe(1000);
+ expect(bounds.stopy).toBe(1000);
+ });
+ it('it should handle a loop that expands the area', function() {
+ renderer.bounds.init();
- renderer.bounds.insert(100, 100, 200, 200)
- renderer.bounds.verticalPos = 200
- renderer.bounds.newLoop()
- renderer.bounds.insert(50, 50, 300, 300)
+ renderer.bounds.insert(100, 100, 200, 200);
+ renderer.bounds.verticalPos = 200;
+ renderer.bounds.newLoop();
+ renderer.bounds.insert(50, 50, 300, 300);
- const loop = renderer.bounds.endLoop()
+ const loop = renderer.bounds.endLoop();
- expect(loop.startx).toBe(50 - conf.boxMargin)
- expect(loop.starty).toBe(50 - conf.boxMargin)
- expect(loop.stopx).toBe(300 + conf.boxMargin)
- expect(loop.stopy).toBe(300 + conf.boxMargin)
+ expect(loop.startx).toBe(50 - conf.boxMargin);
+ expect(loop.starty).toBe(50 - conf.boxMargin);
+ expect(loop.stopx).toBe(300 + conf.boxMargin);
+ expect(loop.stopy).toBe(300 + conf.boxMargin);
// Check bounds after the loop
- const bounds = renderer.bounds.getBounds()
+ const bounds = renderer.bounds.getBounds();
- expect(bounds.startx).toBe(loop.startx)
- expect(bounds.starty).toBe(loop.starty)
- expect(bounds.stopx).toBe(loop.stopx)
- expect(bounds.stopy).toBe(loop.stopy)
- })
-})
+ expect(bounds.startx).toBe(loop.startx);
+ expect(bounds.starty).toBe(loop.starty);
+ expect(bounds.stopx).toBe(loop.stopx);
+ expect(bounds.stopy).toBe(loop.stopy);
+ });
+});
-describe('when rendering a sequenceDiagram', function () {
- let conf
- beforeEach(function () {
- parser.yy = sequenceDb
- parser.yy.clear()
+describe('when rendering a sequenceDiagram', function() {
+ let conf;
+ beforeEach(function() {
+ parser.yy = sequenceDb;
+ parser.yy.clear();
conf = {
diagramMarginX: 50,
@@ -801,210 +823,213 @@ describe('when rendering a sequenceDiagram', function () {
messageMargin: 40,
boxTextMargin: 15,
noteMargin: 25
- }
- renderer.setConf(conf)
+ };
+ renderer.setConf(conf);
});
- ['tspan', 'fo', 'old', undefined].forEach(function (textPlacement) {
- it('it should handle one actor, when textPlacement is ' + textPlacement, function () {
- renderer.setConf(addConf(conf, 'textPlacement', textPlacement))
- renderer.bounds.init()
- const str = 'sequenceDiagram\n' +
- 'participant Alice'
+ ['tspan', 'fo', 'old', undefined].forEach(function(textPlacement) {
+ it('it should handle one actor, when textPlacement is ' + textPlacement, function() {
+ renderer.setConf(addConf(conf, 'textPlacement', textPlacement));
+ renderer.bounds.init();
+ const str = 'sequenceDiagram\n' + 'participant Alice';
- parser.parse(str)
- renderer.draw(str, 'tst')
+ parser.parse(str);
+ renderer.draw(str, 'tst');
- const bounds = renderer.bounds.getBounds()
- expect(bounds.startx).toBe(0)
- expect(bounds.starty).toBe(0)
- expect(bounds.stopx).toBe(conf.width)
- expect(bounds.stopy).toBe(conf.height)
- })
- })
- it('it should handle same actor with different whitespace properly', function () {
- renderer.bounds.init()
+ const bounds = renderer.bounds.getBounds();
+ expect(bounds.startx).toBe(0);
+ expect(bounds.starty).toBe(0);
+ expect(bounds.stopx).toBe(conf.width);
+ expect(bounds.stopy).toBe(conf.height);
+ });
+ });
+ it('it should handle same actor with different whitespace properly', function() {
+ renderer.bounds.init();
- const str = 'sequenceDiagram\n' +
+ const str =
+ 'sequenceDiagram\n' +
'participant Alice\n' +
'participant Alice \n' +
- 'participant Alice \n'
+ 'participant Alice \n';
- parser.parse(str)
+ parser.parse(str);
- const actors = parser.yy.getActors()
- expect(Object.keys(actors)).toEqual(['Alice'])
- })
- it('it should handle one actor and a centered note', function () {
- renderer.bounds.init()
- const str = 'sequenceDiagram\n' +
- 'participant Alice\n' +
- 'Note over Alice: Alice thinks\n'
+ const actors = parser.yy.getActors();
+ expect(Object.keys(actors)).toEqual(['Alice']);
+ });
+ it('it should handle one actor and a centered note', function() {
+ renderer.bounds.init();
+ const str = 'sequenceDiagram\n' + 'participant Alice\n' + 'Note over Alice: Alice thinks\n';
- parser.parse(str)
- renderer.draw(str, 'tst')
+ parser.parse(str);
+ renderer.draw(str, 'tst');
- const bounds = renderer.bounds.getBounds()
- expect(bounds.startx).toBe(0)
- expect(bounds.starty).toBe(0)
- expect(bounds.stopx).toBe(conf.width)
+ const bounds = renderer.bounds.getBounds();
+ expect(bounds.startx).toBe(0);
+ expect(bounds.starty).toBe(0);
+ expect(bounds.stopx).toBe(conf.width);
// 10 comes from mock of text height
- expect(bounds.stopy).toBe(conf.height + conf.boxMargin + 2 * conf.noteMargin + 10)
- })
- it('it should handle one actor and a note to the left', function () {
- renderer.bounds.init()
- const str = 'sequenceDiagram\n' +
- 'participant Alice\n' +
- 'Note left of Alice: Alice thinks'
+ expect(bounds.stopy).toBe(conf.height + conf.boxMargin + 2 * conf.noteMargin + 10);
+ });
+ it('it should handle one actor and a note to the left', function() {
+ renderer.bounds.init();
+ const str = 'sequenceDiagram\n' + 'participant Alice\n' + 'Note left of Alice: Alice thinks';
- parser.parse(str)
- renderer.draw(str, 'tst')
+ parser.parse(str);
+ renderer.draw(str, 'tst');
- const bounds = renderer.bounds.getBounds()
- expect(bounds.startx).toBe(-(conf.width / 2) - (conf.actorMargin / 2))
- expect(bounds.starty).toBe(0)
- expect(bounds.stopx).toBe(conf.width)
+ const bounds = renderer.bounds.getBounds();
+ expect(bounds.startx).toBe(-(conf.width / 2) - conf.actorMargin / 2);
+ expect(bounds.starty).toBe(0);
+ expect(bounds.stopx).toBe(conf.width);
// 10 comes from mock of text height
- expect(bounds.stopy).toBe(conf.height + conf.boxMargin + 2 * conf.noteMargin + 10)
- })
- it('it should handle one actor and a note to the right', function () {
- renderer.bounds.init()
- const str = 'sequenceDiagram\n' +
- 'participant Alice\n' +
- 'Note right of Alice: Alice thinks'
+ expect(bounds.stopy).toBe(conf.height + conf.boxMargin + 2 * conf.noteMargin + 10);
+ });
+ it('it should handle one actor and a note to the right', function() {
+ renderer.bounds.init();
+ const str = 'sequenceDiagram\n' + 'participant Alice\n' + 'Note right of Alice: Alice thinks';
- parser.parse(str)
- renderer.draw(str, 'tst')
+ parser.parse(str);
+ renderer.draw(str, 'tst');
- const bounds = renderer.bounds.getBounds()
- expect(bounds.startx).toBe(0)
- expect(bounds.starty).toBe(0)
- expect(bounds.stopx).toBe((conf.width / 2) + (conf.actorMargin / 2) + conf.width)
+ const bounds = renderer.bounds.getBounds();
+ expect(bounds.startx).toBe(0);
+ expect(bounds.starty).toBe(0);
+ expect(bounds.stopx).toBe(conf.width / 2 + conf.actorMargin / 2 + conf.width);
// 10 comes from mock of text height
- expect(bounds.stopy).toBe(conf.height + conf.boxMargin + 2 * conf.noteMargin + 10)
- })
- it('it should handle two actors', function () {
- renderer.bounds.init()
- const str = 'sequenceDiagram\n' +
- 'Alice->Bob: Hello Bob, how are you?'
+ expect(bounds.stopy).toBe(conf.height + conf.boxMargin + 2 * conf.noteMargin + 10);
+ });
+ it('it should handle two actors', function() {
+ renderer.bounds.init();
+ const str = 'sequenceDiagram\n' + 'Alice->Bob: Hello Bob, how are you?';
- parser.parse(str)
- renderer.draw(str, 'tst')
+ parser.parse(str);
+ renderer.draw(str, 'tst');
- const bounds = renderer.bounds.getBounds()
- expect(bounds.startx).toBe(0)
- expect(bounds.starty).toBe(0)
- expect(bounds.stopx).toBe(conf.width * 2 + conf.actorMargin)
- expect(bounds.stopy).toBe(0 + conf.messageMargin + conf.height)
- })
- it('it should handle two actors and two centered shared notes', function () {
- renderer.bounds.init()
- const str = 'sequenceDiagram\n' +
+ const bounds = renderer.bounds.getBounds();
+ expect(bounds.startx).toBe(0);
+ expect(bounds.starty).toBe(0);
+ expect(bounds.stopx).toBe(conf.width * 2 + conf.actorMargin);
+ expect(bounds.stopy).toBe(0 + conf.messageMargin + conf.height);
+ });
+ it('it should handle two actors and two centered shared notes', function() {
+ renderer.bounds.init();
+ const str =
+ 'sequenceDiagram\n' +
'Alice->Bob: Hello Bob, how are you?\n' +
'Note over Alice,Bob: Looks\n' +
- 'Note over Bob,Alice: Looks back\n'
+ 'Note over Bob,Alice: Looks back\n';
- parser.parse(str)
- renderer.draw(str, 'tst')
+ parser.parse(str);
+ renderer.draw(str, 'tst');
- const bounds = renderer.bounds.getBounds()
- expect(bounds.startx).toBe(0)
- expect(bounds.starty).toBe(0)
- expect(bounds.stopx).toBe(conf.width * 2 + conf.actorMargin)
- expect(bounds.stopy).toBe(conf.height + conf.messageMargin + 2 * (conf.boxMargin + 2 * conf.noteMargin + 10))
- })
- it('it should draw two actors and two messages', function () {
- renderer.bounds.init()
- const str = 'sequenceDiagram\n' +
- 'Alice->Bob: Hello Bob, how are you?\n' +
- 'Bob->Alice: Fine!'
+ const bounds = renderer.bounds.getBounds();
+ expect(bounds.startx).toBe(0);
+ expect(bounds.starty).toBe(0);
+ expect(bounds.stopx).toBe(conf.width * 2 + conf.actorMargin);
+ expect(bounds.stopy).toBe(
+ conf.height + conf.messageMargin + 2 * (conf.boxMargin + 2 * conf.noteMargin + 10)
+ );
+ });
+ it('it should draw two actors and two messages', function() {
+ renderer.bounds.init();
+ const str = 'sequenceDiagram\n' + 'Alice->Bob: Hello Bob, how are you?\n' + 'Bob->Alice: Fine!';
- parser.parse(str)
- renderer.draw(str, 'tst')
+ parser.parse(str);
+ renderer.draw(str, 'tst');
- const bounds = renderer.bounds.getBounds()
- expect(bounds.startx).toBe(0)
- expect(bounds.starty).toBe(0)
- expect(bounds.stopx).toBe(0 + conf.width * 2 + conf.actorMargin)
- expect(bounds.stopy).toBe(0 + 2 * conf.messageMargin + conf.height)
- })
- it('it should draw two actors notes to the right', function () {
- renderer.bounds.init()
- const str = 'sequenceDiagram\n' +
+ const bounds = renderer.bounds.getBounds();
+ expect(bounds.startx).toBe(0);
+ expect(bounds.starty).toBe(0);
+ expect(bounds.stopx).toBe(0 + conf.width * 2 + conf.actorMargin);
+ expect(bounds.stopy).toBe(0 + 2 * conf.messageMargin + conf.height);
+ });
+ it('it should draw two actors notes to the right', function() {
+ renderer.bounds.init();
+ const str =
+ 'sequenceDiagram\n' +
'Alice->Bob: Hello Bob, how are you?\n' +
'Note right of Bob: Bob thinks\n' +
- 'Bob->Alice: Fine!'
+ 'Bob->Alice: Fine!';
- parser.parse(str)
- renderer.draw(str, 'tst')
+ parser.parse(str);
+ renderer.draw(str, 'tst');
- const bounds = renderer.bounds.getBounds()
- expect(bounds.startx).toBe(0)
- expect(bounds.starty).toBe(0)
+ const bounds = renderer.bounds.getBounds();
+ expect(bounds.startx).toBe(0);
+ expect(bounds.starty).toBe(0);
- const expStopX = conf.actorMargin + conf.width + (conf.width / 2) + conf.noteMargin + conf.width
+ const expStopX = conf.actorMargin + conf.width + conf.width / 2 + conf.noteMargin + conf.width;
- expect(bounds.stopx).toBe(expStopX)
- expect(bounds.stopy).toBe(2 * conf.messageMargin + conf.height + conf.boxMargin + 10 + 2 * conf.noteMargin)
- })
- it('it should draw two actors notes to the left', function () {
- renderer.bounds.init()
- const str = 'sequenceDiagram\n' +
+ expect(bounds.stopx).toBe(expStopX);
+ expect(bounds.stopy).toBe(
+ 2 * conf.messageMargin + conf.height + conf.boxMargin + 10 + 2 * conf.noteMargin
+ );
+ });
+ it('it should draw two actors notes to the left', function() {
+ renderer.bounds.init();
+ const str =
+ 'sequenceDiagram\n' +
'Alice->Bob: Hello Bob, how are you?\n' +
'Note left of Alice: Bob thinks\n' +
- 'Bob->Alice: Fine!'
+ 'Bob->Alice: Fine!';
- parser.parse(str)
- renderer.draw(str, 'tst')
+ parser.parse(str);
+ renderer.draw(str, 'tst');
- const bounds = renderer.bounds.getBounds()
- expect(bounds.startx).toBe(-(conf.width / 2) - (conf.actorMargin / 2))
- expect(bounds.starty).toBe(0)
+ const bounds = renderer.bounds.getBounds();
+ expect(bounds.startx).toBe(-(conf.width / 2) - conf.actorMargin / 2);
+ expect(bounds.starty).toBe(0);
- expect(bounds.stopx).toBe(conf.width * 2 + conf.actorMargin)
- expect(bounds.stopy).toBe(2 * conf.messageMargin + conf.height + conf.boxMargin + 10 + 2 * conf.noteMargin)
- })
- it('it should draw two loops', function () {
- renderer.bounds.init()
- const str = 'sequenceDiagram\n' +
+ expect(bounds.stopx).toBe(conf.width * 2 + conf.actorMargin);
+ expect(bounds.stopy).toBe(
+ 2 * conf.messageMargin + conf.height + conf.boxMargin + 10 + 2 * conf.noteMargin
+ );
+ });
+ it('it should draw two loops', function() {
+ renderer.bounds.init();
+ const str =
+ 'sequenceDiagram\n' +
'Alice->Bob: Hello Bob, how are you?\n' +
'loop Cheers\n' +
'Bob->Alice: Fine!\n' +
- 'end'
- parser.parse(str)
- renderer.draw(str, 'tst')
+ 'end';
+ parser.parse(str);
+ renderer.draw(str, 'tst');
- const bounds = renderer.bounds.getBounds()
- expect(bounds.startx).toBe(0)
- expect(bounds.starty).toBe(0)
+ const bounds = renderer.bounds.getBounds();
+ expect(bounds.startx).toBe(0);
+ expect(bounds.starty).toBe(0);
- expect(bounds.stopx).toBe(0 + conf.width * 2 + conf.actorMargin)
- expect(bounds.stopy).toBe(0 + 2 * conf.messageMargin + conf.height + 3 * conf.boxMargin + conf.boxTextMargin)
- })
- it('it should draw background rect', function () {
- renderer.bounds.init()
+ expect(bounds.stopx).toBe(0 + conf.width * 2 + conf.actorMargin);
+ expect(bounds.stopy).toBe(
+ 0 + 2 * conf.messageMargin + conf.height + 3 * conf.boxMargin + conf.boxTextMargin
+ );
+ });
+ it('it should draw background rect', function() {
+ renderer.bounds.init();
const str = `
sequenceDiagram
Alice->Bob: Hello Bob, are you alright?
rect rgb(0, 0, 0)
Bob->Alice: I feel surrounded by darkness
end
- `
- parser.parse(str)
- renderer.draw(str, 'tst')
- const bounds = renderer.bounds.getBounds()
- expect(bounds.startx).toBe(0)
- expect(bounds.starty).toBe(0)
+ `;
+ parser.parse(str);
+ renderer.draw(str, 'tst');
+ const bounds = renderer.bounds.getBounds();
+ expect(bounds.startx).toBe(0);
+ expect(bounds.starty).toBe(0);
- expect(bounds.stopx).toBe(0 + conf.width * 2 + conf.actorMargin)
- expect(bounds.stopy).toBe(0 + 2 * conf.messageMargin + conf.height + 3 * conf.boxMargin)
- })
-})
+ expect(bounds.stopx).toBe(0 + conf.width * 2 + conf.actorMargin);
+ expect(bounds.stopy).toBe(0 + 2 * conf.messageMargin + conf.height + 3 * conf.boxMargin);
+ });
+});
-describe('when rendering a sequenceDiagram with actor mirror activated', function () {
- let conf
- beforeEach(function () {
- parser.yy = sequenceDb
- parser.yy.clear()
+describe('when rendering a sequenceDiagram with actor mirror activated', function() {
+ let conf;
+ beforeEach(function() {
+ parser.yy = sequenceDb;
+ parser.yy.clear();
conf = {
diagramMarginX: 50,
@@ -1021,24 +1046,23 @@ describe('when rendering a sequenceDiagram with actor mirror activated', functio
// Depending on css styling this might need adjustment
// Prolongs the edge of the diagram downwards
bottomMarginAdj: 1
- }
- renderer.setConf(conf)
+ };
+ renderer.setConf(conf);
});
- ['tspan', 'fo', 'old', undefined].forEach(function (textPlacement) {
- it('it should handle one actor, when textPlacement is' + textPlacement, function () {
- renderer.setConf(addConf(conf, 'textPlacement', textPlacement))
- renderer.bounds.init()
- const str = 'sequenceDiagram\n' +
- 'participant Alice'
+ ['tspan', 'fo', 'old', undefined].forEach(function(textPlacement) {
+ it('it should handle one actor, when textPlacement is' + textPlacement, function() {
+ renderer.setConf(addConf(conf, 'textPlacement', textPlacement));
+ renderer.bounds.init();
+ const str = 'sequenceDiagram\n' + 'participant Alice';
- parser.parse(str)
- renderer.draw(str, 'tst')
+ parser.parse(str);
+ renderer.draw(str, 'tst');
- const bounds = renderer.bounds.getBounds()
- expect(bounds.startx).toBe(0)
- expect(bounds.starty).toBe(0)
- expect(bounds.stopx).toBe(conf.width)
- expect(bounds.stopy).toBe(2 * conf.height + 2 * conf.boxMargin)
- })
- })
-})
+ const bounds = renderer.bounds.getBounds();
+ expect(bounds.startx).toBe(0);
+ expect(bounds.starty).toBe(0);
+ expect(bounds.stopx).toBe(conf.width);
+ expect(bounds.stopy).toBe(2 * conf.height + 2 * conf.boxMargin);
+ });
+ });
+});
diff --git a/src/diagrams/sequence/sequenceRenderer.js b/src/diagrams/sequence/sequenceRenderer.js
index 4e4b0f74d..6ebd5a52d 100644
--- a/src/diagrams/sequence/sequenceRenderer.js
+++ b/src/diagrams/sequence/sequenceRenderer.js
@@ -1,14 +1,13 @@
-import * as d3 from 'd3'
+import * as d3 from 'd3';
-import svgDraw from './svgDraw'
-import { logger } from '../../logger'
-import { parser } from './parser/sequenceDiagram'
-import sequenceDb from './sequenceDb'
+import svgDraw from './svgDraw';
+import { logger } from '../../logger';
+import { parser } from './parser/sequenceDiagram';
+import sequenceDb from './sequenceDb';
-parser.yy = sequenceDb
+parser.yy = sequenceDb;
const conf = {
-
diagramMarginX: 50,
diagramMarginY: 30,
// Margin between actors
@@ -38,7 +37,7 @@ const conf = {
textPlacement: 'tspan',
showSequenceNumbers: false
-}
+};
export const bounds = {
data: {
@@ -51,69 +50,69 @@ export const bounds = {
sequenceItems: [],
activations: [],
- init: function () {
- this.sequenceItems = []
- this.activations = []
+ init: function() {
+ this.sequenceItems = [];
+ this.activations = [];
this.data = {
startx: undefined,
stopx: undefined,
starty: undefined,
stopy: undefined
- }
- this.verticalPos = 0
+ };
+ this.verticalPos = 0;
},
- updateVal: function (obj, key, val, fun) {
+ updateVal: function(obj, key, val, fun) {
if (typeof obj[key] === 'undefined') {
- obj[key] = val
+ obj[key] = val;
} else {
- obj[key] = fun(val, obj[key])
+ obj[key] = fun(val, obj[key]);
}
},
- updateBounds: function (startx, starty, stopx, stopy) {
- const _self = this
- let cnt = 0
- function updateFn (type) {
- return function updateItemBounds (item) {
- cnt++
+ updateBounds: function(startx, starty, stopx, stopy) {
+ const _self = this;
+ let cnt = 0;
+ function updateFn(type) {
+ return function updateItemBounds(item) {
+ cnt++;
// The loop sequenceItems is a stack so the biggest margins in the beginning of the sequenceItems
- const n = _self.sequenceItems.length - cnt + 1
+ const n = _self.sequenceItems.length - cnt + 1;
- _self.updateVal(item, 'starty', starty - n * conf.boxMargin, Math.min)
- _self.updateVal(item, 'stopy', stopy + n * conf.boxMargin, Math.max)
+ _self.updateVal(item, 'starty', starty - n * conf.boxMargin, Math.min);
+ _self.updateVal(item, 'stopy', stopy + n * conf.boxMargin, Math.max);
- _self.updateVal(bounds.data, 'startx', startx - n * conf.boxMargin, Math.min)
- _self.updateVal(bounds.data, 'stopx', stopx + n * conf.boxMargin, Math.max)
+ _self.updateVal(bounds.data, 'startx', startx - n * conf.boxMargin, Math.min);
+ _self.updateVal(bounds.data, 'stopx', stopx + n * conf.boxMargin, Math.max);
if (!(type === 'activation')) {
- _self.updateVal(item, 'startx', startx - n * conf.boxMargin, Math.min)
- _self.updateVal(item, 'stopx', stopx + n * conf.boxMargin, Math.max)
+ _self.updateVal(item, 'startx', startx - n * conf.boxMargin, Math.min);
+ _self.updateVal(item, 'stopx', stopx + n * conf.boxMargin, Math.max);
- _self.updateVal(bounds.data, 'starty', starty - n * conf.boxMargin, Math.min)
- _self.updateVal(bounds.data, 'stopy', stopy + n * conf.boxMargin, Math.max)
+ _self.updateVal(bounds.data, 'starty', starty - n * conf.boxMargin, Math.min);
+ _self.updateVal(bounds.data, 'stopy', stopy + n * conf.boxMargin, Math.max);
}
- }
+ };
}
- this.sequenceItems.forEach(updateFn())
- this.activations.forEach(updateFn('activation'))
+ this.sequenceItems.forEach(updateFn());
+ this.activations.forEach(updateFn('activation'));
},
- insert: function (startx, starty, stopx, stopy) {
- const _startx = Math.min(startx, stopx)
- const _stopx = Math.max(startx, stopx)
- const _starty = Math.min(starty, stopy)
- const _stopy = Math.max(starty, stopy)
+ insert: function(startx, starty, stopx, stopy) {
+ const _startx = Math.min(startx, stopx);
+ const _stopx = Math.max(startx, stopx);
+ const _starty = Math.min(starty, stopy);
+ const _stopy = Math.max(starty, stopy);
- this.updateVal(bounds.data, 'startx', _startx, Math.min)
- this.updateVal(bounds.data, 'starty', _starty, Math.min)
- this.updateVal(bounds.data, 'stopx', _stopx, Math.max)
- this.updateVal(bounds.data, 'stopy', _stopy, Math.max)
+ this.updateVal(bounds.data, 'startx', _startx, Math.min);
+ this.updateVal(bounds.data, 'starty', _starty, Math.min);
+ this.updateVal(bounds.data, 'stopx', _stopx, Math.max);
+ this.updateVal(bounds.data, 'stopy', _stopy, Math.max);
- this.updateBounds(_startx, _starty, _stopx, _stopy)
+ this.updateBounds(_startx, _starty, _stopx, _stopy);
},
- newActivation: function (message, diagram) {
- const actorRect = parser.yy.getActors()[message.from.actor]
- const stackedSize = actorActivations(message.from.actor).length
- const x = actorRect.x + conf.width / 2 + (stackedSize - 1) * conf.activationWidth / 2
+ newActivation: function(message, diagram) {
+ const actorRect = parser.yy.getActors()[message.from.actor];
+ const stackedSize = actorActivations(message.from.actor).length;
+ const x = actorRect.x + conf.width / 2 + ((stackedSize - 1) * conf.activationWidth) / 2;
this.activations.push({
startx: x,
starty: this.verticalPos + 2,
@@ -121,59 +120,68 @@ export const bounds = {
stopy: undefined,
actor: message.from.actor,
anchored: svgDraw.anchorElement(diagram)
- })
+ });
},
- endActivation: function (message) {
+ endActivation: function(message) {
// find most recent activation for given actor
const lastActorActivationIdx = this.activations
- .map(function (activation) { return activation.actor })
- .lastIndexOf(message.from.actor)
- const activation = this.activations.splice(lastActorActivationIdx, 1)[0]
- return activation
+ .map(function(activation) {
+ return activation.actor;
+ })
+ .lastIndexOf(message.from.actor);
+ const activation = this.activations.splice(lastActorActivationIdx, 1)[0];
+ return activation;
},
- newLoop: function (title, fill) {
- this.sequenceItems.push({ startx: undefined, starty: this.verticalPos, stopx: undefined, stopy: undefined, title: title, fill: fill })
+ newLoop: function(title, fill) {
+ this.sequenceItems.push({
+ startx: undefined,
+ starty: this.verticalPos,
+ stopx: undefined,
+ stopy: undefined,
+ title: title,
+ fill: fill
+ });
},
- endLoop: function () {
- const loop = this.sequenceItems.pop()
- return loop
+ endLoop: function() {
+ const loop = this.sequenceItems.pop();
+ return loop;
},
- addSectionToLoop: function (message) {
- const loop = this.sequenceItems.pop()
- loop.sections = loop.sections || []
- loop.sectionTitles = loop.sectionTitles || []
- loop.sections.push(bounds.getVerticalPos())
- loop.sectionTitles.push(message)
- this.sequenceItems.push(loop)
+ addSectionToLoop: function(message) {
+ const loop = this.sequenceItems.pop();
+ loop.sections = loop.sections || [];
+ loop.sectionTitles = loop.sectionTitles || [];
+ loop.sections.push(bounds.getVerticalPos());
+ loop.sectionTitles.push(message);
+ this.sequenceItems.push(loop);
},
- bumpVerticalPos: function (bump) {
- this.verticalPos = this.verticalPos + bump
- this.data.stopy = this.verticalPos
+ bumpVerticalPos: function(bump) {
+ this.verticalPos = this.verticalPos + bump;
+ this.data.stopy = this.verticalPos;
},
- getVerticalPos: function () {
- return this.verticalPos
+ getVerticalPos: function() {
+ return this.verticalPos;
},
- getBounds: function () {
- return this.data
+ getBounds: function() {
+ return this.data;
}
-}
+};
const _drawLongText = (text, x, y, g, width) => {
- let textHeight = 0
- const lines = text.split(/
/ig)
+ let textHeight = 0;
+ const lines = text.split(/
/gi);
for (const line of lines) {
- const textObj = svgDraw.getTextObj()
- textObj.x = x
- textObj.y = y + textHeight
- textObj.textMargin = conf.noteMargin
- textObj.dy = '1em'
- textObj.text = line
- textObj.class = 'noteText'
- const textElem = svgDraw.drawText(g, textObj, width)
- textHeight += (textElem._groups || textElem)[0][0].getBBox().height
+ const textObj = svgDraw.getTextObj();
+ textObj.x = x;
+ textObj.y = y + textHeight;
+ textObj.textMargin = conf.noteMargin;
+ textObj.dy = '1em';
+ textObj.text = line;
+ textObj.class = 'noteText';
+ const textElem = svgDraw.drawText(g, textObj, width);
+ textHeight += (textElem._groups || textElem)[0][0].getBBox().height;
}
- return textHeight
-}
+ return textHeight;
+};
/**
* Draws an actor in the diagram with the attaced line
@@ -181,22 +189,33 @@ const _drawLongText = (text, x, y, g, width) => {
* @param pos The position if the actor in the liost of actors
* @param description The text in the box
*/
-const drawNote = function (elem, startx, verticalPos, msg, forceWidth) {
- const rect = svgDraw.getNoteRect()
- rect.x = startx
- rect.y = verticalPos
- rect.width = forceWidth || conf.width
- rect.class = 'note'
+const drawNote = function(elem, startx, verticalPos, msg, forceWidth) {
+ const rect = svgDraw.getNoteRect();
+ rect.x = startx;
+ rect.y = verticalPos;
+ rect.width = forceWidth || conf.width;
+ rect.class = 'note';
- let g = elem.append('g')
- const rectElem = svgDraw.drawRect(g, rect)
+ let g = elem.append('g');
+ const rectElem = svgDraw.drawRect(g, rect);
- const textHeight = _drawLongText(msg.message, startx - 4, verticalPos + 24, g, rect.width - conf.noteMargin)
+ const textHeight = _drawLongText(
+ msg.message,
+ startx - 4,
+ verticalPos + 24,
+ g,
+ rect.width - conf.noteMargin
+ );
- bounds.insert(startx, verticalPos, startx + rect.width, verticalPos + 2 * conf.noteMargin + textHeight)
- rectElem.attr('height', textHeight + 2 * conf.noteMargin)
- bounds.bumpVerticalPos(textHeight + 2 * conf.noteMargin)
-}
+ bounds.insert(
+ startx,
+ verticalPos,
+ startx + rect.width,
+ verticalPos + 2 * conf.noteMargin + textHeight
+ );
+ rectElem.attr('height', textHeight + 2 * conf.noteMargin);
+ bounds.bumpVerticalPos(textHeight + 2 * conf.noteMargin);
+};
/**
* Draws a message
@@ -207,70 +226,104 @@ const drawNote = function (elem, startx, verticalPos, msg, forceWidth) {
* @param txtCenter
* @param msg
*/
-const drawMessage = function (elem, startx, stopx, verticalPos, msg, sequenceIndex) {
- const g = elem.append('g')
- const txtCenter = startx + (stopx - startx) / 2
+const drawMessage = function(elem, startx, stopx, verticalPos, msg, sequenceIndex) {
+ const g = elem.append('g');
+ const txtCenter = startx + (stopx - startx) / 2;
- const textElem = g.append('text') // text label for the x axis
+ const textElem = g
+ .append('text') // text label for the x axis
.attr('x', txtCenter)
.attr('y', verticalPos - 7)
.style('text-anchor', 'middle')
.attr('class', 'messageText')
- .text(msg.message)
+ .text(msg.message);
- let textWidth = (textElem._groups || textElem)[0][0].getBBox().width
+ let textWidth = (textElem._groups || textElem)[0][0].getBBox().width;
- let line
+ let line;
if (startx === stopx) {
if (conf.rightAngles) {
- line = g.append('path').attr('d', `M ${startx},${verticalPos} H ${startx + (conf.width / 2)} V ${verticalPos + 25} H ${startx}`)
+ line = g
+ .append('path')
+ .attr(
+ 'd',
+ `M ${startx},${verticalPos} H ${startx + conf.width / 2} V ${verticalPos +
+ 25} H ${startx}`
+ );
} else {
- line = g.append('path')
- .attr('d', 'M ' + startx + ',' + verticalPos + ' C ' + (startx + 60) + ',' + (verticalPos - 10) + ' ' + (startx + 60) + ',' +
- (verticalPos + 30) + ' ' + startx + ',' + (verticalPos + 20))
+ line = g
+ .append('path')
+ .attr(
+ 'd',
+ 'M ' +
+ startx +
+ ',' +
+ verticalPos +
+ ' C ' +
+ (startx + 60) +
+ ',' +
+ (verticalPos - 10) +
+ ' ' +
+ (startx + 60) +
+ ',' +
+ (verticalPos + 30) +
+ ' ' +
+ startx +
+ ',' +
+ (verticalPos + 20)
+ );
}
- bounds.bumpVerticalPos(30)
- const dx = Math.max(textWidth / 2, 100)
- bounds.insert(startx - dx, bounds.getVerticalPos() - 10, stopx + dx, bounds.getVerticalPos())
+ bounds.bumpVerticalPos(30);
+ const dx = Math.max(textWidth / 2, 100);
+ bounds.insert(startx - dx, bounds.getVerticalPos() - 10, stopx + dx, bounds.getVerticalPos());
} else {
- line = g.append('line')
- line.attr('x1', startx)
- line.attr('y1', verticalPos)
- line.attr('x2', stopx)
- line.attr('y2', verticalPos)
- bounds.insert(startx, bounds.getVerticalPos() - 10, stopx, bounds.getVerticalPos())
+ line = g.append('line');
+ line.attr('x1', startx);
+ line.attr('y1', verticalPos);
+ line.attr('x2', stopx);
+ line.attr('y2', verticalPos);
+ bounds.insert(startx, bounds.getVerticalPos() - 10, stopx, bounds.getVerticalPos());
}
// Make an SVG Container
// Draw the line
- if (msg.type === parser.yy.LINETYPE.DOTTED || msg.type === parser.yy.LINETYPE.DOTTED_CROSS || msg.type === parser.yy.LINETYPE.DOTTED_OPEN) {
- line.style('stroke-dasharray', ('3, 3'))
- line.attr('class', 'messageLine1')
+ if (
+ msg.type === parser.yy.LINETYPE.DOTTED ||
+ msg.type === parser.yy.LINETYPE.DOTTED_CROSS ||
+ msg.type === parser.yy.LINETYPE.DOTTED_OPEN
+ ) {
+ line.style('stroke-dasharray', '3, 3');
+ line.attr('class', 'messageLine1');
} else {
- line.attr('class', 'messageLine0')
+ line.attr('class', 'messageLine0');
}
- let url = ''
+ let url = '';
if (conf.arrowMarkerAbsolute) {
- url = window.location.protocol + '//' + window.location.host + window.location.pathname + window.location.search
- url = url.replace(/\(/g, '\\(')
- url = url.replace(/\)/g, '\\)')
+ url =
+ window.location.protocol +
+ '//' +
+ window.location.host +
+ window.location.pathname +
+ window.location.search;
+ url = url.replace(/\(/g, '\\(');
+ url = url.replace(/\)/g, '\\)');
}
- line.attr('stroke-width', 2)
- line.attr('stroke', 'black')
- line.style('fill', 'none') // remove any fill colour
+ line.attr('stroke-width', 2);
+ line.attr('stroke', 'black');
+ line.style('fill', 'none'); // remove any fill colour
if (msg.type === parser.yy.LINETYPE.SOLID || msg.type === parser.yy.LINETYPE.DOTTED) {
- line.attr('marker-end', 'url(' + url + '#arrowhead)')
+ line.attr('marker-end', 'url(' + url + '#arrowhead)');
}
if (msg.type === parser.yy.LINETYPE.SOLID_CROSS || msg.type === parser.yy.LINETYPE.DOTTED_CROSS) {
- line.attr('marker-end', 'url(' + url + '#crosshead)')
+ line.attr('marker-end', 'url(' + url + '#crosshead)');
}
// add node number
if (conf.showSequenceNumbers) {
- line.attr('marker-start', 'url(' + url + '#sequencenumber)')
+ line.attr('marker-start', 'url(' + url + '#sequencenumber)');
g.append('text')
.attr('x', startx)
.attr('y', verticalPos + 4)
@@ -279,263 +332,306 @@ const drawMessage = function (elem, startx, stopx, verticalPos, msg, sequenceInd
.attr('text-anchor', 'middle')
.attr('textLength', '16px')
.attr('class', 'sequenceNumber')
- .text(sequenceIndex)
+ .text(sequenceIndex);
}
-}
+};
-export const drawActors = function (diagram, actors, actorKeys, verticalPos) {
+export const drawActors = function(diagram, actors, actorKeys, verticalPos) {
// Draw the actors
for (let i = 0; i < actorKeys.length; i++) {
- const key = actorKeys[i]
+ const key = actorKeys[i];
// Add some rendering data to the object
- actors[key].x = i * conf.actorMargin + i * conf.width
- actors[key].y = verticalPos
- actors[key].width = conf.diagramMarginX
- actors[key].height = conf.diagramMarginY
+ actors[key].x = i * conf.actorMargin + i * conf.width;
+ actors[key].y = verticalPos;
+ actors[key].width = conf.diagramMarginX;
+ actors[key].height = conf.diagramMarginY;
// Draw the box with the attached line
- svgDraw.drawActor(diagram, actors[key].x, verticalPos, actors[key].description, conf)
- bounds.insert(actors[key].x, verticalPos, actors[key].x + conf.width, conf.height)
+ svgDraw.drawActor(diagram, actors[key].x, verticalPos, actors[key].description, conf);
+ bounds.insert(actors[key].x, verticalPos, actors[key].x + conf.width, conf.height);
}
// Add a margin between the actor boxes and the first arrow
- bounds.bumpVerticalPos(conf.height)
-}
+ bounds.bumpVerticalPos(conf.height);
+};
-export const setConf = function (cnf) {
- const keys = Object.keys(cnf)
+export const setConf = function(cnf) {
+ const keys = Object.keys(cnf);
- keys.forEach(function (key) {
- conf[key] = cnf[key]
- })
-}
+ keys.forEach(function(key) {
+ conf[key] = cnf[key];
+ });
+};
-const actorActivations = function (actor) {
- return bounds.activations.filter(function (activation) {
- return activation.actor === actor
- })
-}
+const actorActivations = function(actor) {
+ return bounds.activations.filter(function(activation) {
+ return activation.actor === actor;
+ });
+};
-const actorFlowVerticaBounds = function (actor) {
+const actorFlowVerticaBounds = function(actor) {
// handle multiple stacked activations for same actor
- const actors = parser.yy.getActors()
- const activations = actorActivations(actor)
+ const actors = parser.yy.getActors();
+ const activations = actorActivations(actor);
- const left = activations.reduce(function (acc, activation) { return Math.min(acc, activation.startx) }, actors[actor].x + conf.width / 2)
- const right = activations.reduce(function (acc, activation) { return Math.max(acc, activation.stopx) }, actors[actor].x + conf.width / 2)
- return [left, right]
-}
+ const left = activations.reduce(function(acc, activation) {
+ return Math.min(acc, activation.startx);
+ }, actors[actor].x + conf.width / 2);
+ const right = activations.reduce(function(acc, activation) {
+ return Math.max(acc, activation.stopx);
+ }, actors[actor].x + conf.width / 2);
+ return [left, right];
+};
/**
* Draws a flowchart in the tag with id: id based on the graph definition in text.
* @param text
* @param id
*/
-export const draw = function (text, id) {
- parser.yy.clear()
- parser.parse(text + '\n')
+export const draw = function(text, id) {
+ parser.yy.clear();
+ parser.parse(text + '\n');
- bounds.init()
- const diagram = d3.select(`[id="${id}"]`)
+ bounds.init();
+ const diagram = d3.select(`[id="${id}"]`);
- let startx
- let stopx
- let forceWidth
+ let startx;
+ let stopx;
+ let forceWidth;
// Fetch data from the parsing
- const actors = parser.yy.getActors()
- const actorKeys = parser.yy.getActorKeys()
- const messages = parser.yy.getMessages()
- const title = parser.yy.getTitle()
- drawActors(diagram, actors, actorKeys, 0)
+ const actors = parser.yy.getActors();
+ const actorKeys = parser.yy.getActorKeys();
+ const messages = parser.yy.getMessages();
+ const title = parser.yy.getTitle();
+ drawActors(diagram, actors, actorKeys, 0);
// The arrow head definition is attached to the svg once
- svgDraw.insertArrowHead(diagram)
- svgDraw.insertArrowCrossHead(diagram)
- svgDraw.insertSequenceNumber(diagram)
+ svgDraw.insertArrowHead(diagram);
+ svgDraw.insertArrowCrossHead(diagram);
+ svgDraw.insertSequenceNumber(diagram);
- function activeEnd (msg, verticalPos) {
- const activationData = bounds.endActivation(msg)
+ function activeEnd(msg, verticalPos) {
+ const activationData = bounds.endActivation(msg);
if (activationData.starty + 18 > verticalPos) {
- activationData.starty = verticalPos - 6
- verticalPos += 12
+ activationData.starty = verticalPos - 6;
+ verticalPos += 12;
}
- svgDraw.drawActivation(diagram, activationData, verticalPos, conf, actorActivations(msg.from.actor).length)
+ svgDraw.drawActivation(
+ diagram,
+ activationData,
+ verticalPos,
+ conf,
+ actorActivations(msg.from.actor).length
+ );
- bounds.insert(activationData.startx, verticalPos - 10, activationData.stopx, verticalPos)
+ bounds.insert(activationData.startx, verticalPos - 10, activationData.stopx, verticalPos);
}
// const lastMsg
// Draw the messages/signals
- let sequenceIndex = 1
- messages.forEach(function (msg) {
- let loopData
+ let sequenceIndex = 1;
+ messages.forEach(function(msg) {
+ let loopData;
switch (msg.type) {
case parser.yy.LINETYPE.NOTE:
- bounds.bumpVerticalPos(conf.boxMargin)
+ bounds.bumpVerticalPos(conf.boxMargin);
- startx = actors[msg.from].x
- stopx = actors[msg.to].x
+ startx = actors[msg.from].x;
+ stopx = actors[msg.to].x;
if (msg.placement === parser.yy.PLACEMENT.RIGHTOF) {
- drawNote(diagram, startx + (conf.width + conf.actorMargin) / 2, bounds.getVerticalPos(), msg)
+ drawNote(
+ diagram,
+ startx + (conf.width + conf.actorMargin) / 2,
+ bounds.getVerticalPos(),
+ msg
+ );
} else if (msg.placement === parser.yy.PLACEMENT.LEFTOF) {
- drawNote(diagram, startx - (conf.width + conf.actorMargin) / 2, bounds.getVerticalPos(), msg)
+ drawNote(
+ diagram,
+ startx - (conf.width + conf.actorMargin) / 2,
+ bounds.getVerticalPos(),
+ msg
+ );
} else if (msg.to === msg.from) {
// Single-actor over
- drawNote(diagram, startx, bounds.getVerticalPos(), msg)
+ drawNote(diagram, startx, bounds.getVerticalPos(), msg);
} else {
// Multi-actor over
- forceWidth = Math.abs(startx - stopx) + conf.actorMargin
- drawNote(diagram, (startx + stopx + conf.width - forceWidth) / 2, bounds.getVerticalPos(), msg,
- forceWidth)
+ forceWidth = Math.abs(startx - stopx) + conf.actorMargin;
+ drawNote(
+ diagram,
+ (startx + stopx + conf.width - forceWidth) / 2,
+ bounds.getVerticalPos(),
+ msg,
+ forceWidth
+ );
}
- break
+ break;
case parser.yy.LINETYPE.ACTIVE_START:
- bounds.newActivation(msg, diagram)
- break
+ bounds.newActivation(msg, diagram);
+ break;
case parser.yy.LINETYPE.ACTIVE_END:
- activeEnd(msg, bounds.getVerticalPos())
- break
+ activeEnd(msg, bounds.getVerticalPos());
+ break;
case parser.yy.LINETYPE.LOOP_START:
- bounds.bumpVerticalPos(conf.boxMargin)
- bounds.newLoop(msg.message)
- bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin)
- break
+ bounds.bumpVerticalPos(conf.boxMargin);
+ bounds.newLoop(msg.message);
+ bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin);
+ break;
case parser.yy.LINETYPE.LOOP_END:
- loopData = bounds.endLoop()
+ loopData = bounds.endLoop();
- svgDraw.drawLoop(diagram, loopData, 'loop', conf)
- bounds.bumpVerticalPos(conf.boxMargin)
- break
+ svgDraw.drawLoop(diagram, loopData, 'loop', conf);
+ bounds.bumpVerticalPos(conf.boxMargin);
+ break;
case parser.yy.LINETYPE.RECT_START:
- bounds.bumpVerticalPos(conf.boxMargin)
- bounds.newLoop(undefined, msg.message)
- bounds.bumpVerticalPos(conf.boxMargin)
- break
+ bounds.bumpVerticalPos(conf.boxMargin);
+ bounds.newLoop(undefined, msg.message);
+ bounds.bumpVerticalPos(conf.boxMargin);
+ break;
case parser.yy.LINETYPE.RECT_END:
- const rectData = bounds.endLoop()
- svgDraw.drawBackgroundRect(diagram, rectData)
- bounds.bumpVerticalPos(conf.boxMargin)
- break
+ const rectData = bounds.endLoop();
+ svgDraw.drawBackgroundRect(diagram, rectData);
+ bounds.bumpVerticalPos(conf.boxMargin);
+ break;
case parser.yy.LINETYPE.OPT_START:
- bounds.bumpVerticalPos(conf.boxMargin)
- bounds.newLoop(msg.message)
- bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin)
- break
+ bounds.bumpVerticalPos(conf.boxMargin);
+ bounds.newLoop(msg.message);
+ bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin);
+ break;
case parser.yy.LINETYPE.OPT_END:
- loopData = bounds.endLoop()
+ loopData = bounds.endLoop();
- svgDraw.drawLoop(diagram, loopData, 'opt', conf)
- bounds.bumpVerticalPos(conf.boxMargin)
- break
+ svgDraw.drawLoop(diagram, loopData, 'opt', conf);
+ bounds.bumpVerticalPos(conf.boxMargin);
+ break;
case parser.yy.LINETYPE.ALT_START:
- bounds.bumpVerticalPos(conf.boxMargin)
- bounds.newLoop(msg.message)
- bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin)
- break
+ bounds.bumpVerticalPos(conf.boxMargin);
+ bounds.newLoop(msg.message);
+ bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin);
+ break;
case parser.yy.LINETYPE.ALT_ELSE:
- bounds.bumpVerticalPos(conf.boxMargin)
- loopData = bounds.addSectionToLoop(msg.message)
- bounds.bumpVerticalPos(conf.boxMargin)
- break
+ bounds.bumpVerticalPos(conf.boxMargin);
+ loopData = bounds.addSectionToLoop(msg.message);
+ bounds.bumpVerticalPos(conf.boxMargin);
+ break;
case parser.yy.LINETYPE.ALT_END:
- loopData = bounds.endLoop()
+ loopData = bounds.endLoop();
- svgDraw.drawLoop(diagram, loopData, 'alt', conf)
- bounds.bumpVerticalPos(conf.boxMargin)
- break
+ svgDraw.drawLoop(diagram, loopData, 'alt', conf);
+ bounds.bumpVerticalPos(conf.boxMargin);
+ break;
case parser.yy.LINETYPE.PAR_START:
- bounds.bumpVerticalPos(conf.boxMargin)
- bounds.newLoop(msg.message)
- bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin)
- break
+ bounds.bumpVerticalPos(conf.boxMargin);
+ bounds.newLoop(msg.message);
+ bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin);
+ break;
case parser.yy.LINETYPE.PAR_AND:
- bounds.bumpVerticalPos(conf.boxMargin)
- loopData = bounds.addSectionToLoop(msg.message)
- bounds.bumpVerticalPos(conf.boxMargin)
- break
+ bounds.bumpVerticalPos(conf.boxMargin);
+ loopData = bounds.addSectionToLoop(msg.message);
+ bounds.bumpVerticalPos(conf.boxMargin);
+ break;
case parser.yy.LINETYPE.PAR_END:
- loopData = bounds.endLoop()
- svgDraw.drawLoop(diagram, loopData, 'par', conf)
- bounds.bumpVerticalPos(conf.boxMargin)
- break
+ loopData = bounds.endLoop();
+ svgDraw.drawLoop(diagram, loopData, 'par', conf);
+ bounds.bumpVerticalPos(conf.boxMargin);
+ break;
default:
try {
// lastMsg = msg
- bounds.bumpVerticalPos(conf.messageMargin)
- const fromBounds = actorFlowVerticaBounds(msg.from)
- const toBounds = actorFlowVerticaBounds(msg.to)
- const fromIdx = fromBounds[0] <= toBounds[0] ? 1 : 0
- const toIdx = fromBounds[0] < toBounds[0] ? 0 : 1
- startx = fromBounds[fromIdx]
- stopx = toBounds[toIdx]
+ bounds.bumpVerticalPos(conf.messageMargin);
+ const fromBounds = actorFlowVerticaBounds(msg.from);
+ const toBounds = actorFlowVerticaBounds(msg.to);
+ const fromIdx = fromBounds[0] <= toBounds[0] ? 1 : 0;
+ const toIdx = fromBounds[0] < toBounds[0] ? 0 : 1;
+ startx = fromBounds[fromIdx];
+ stopx = toBounds[toIdx];
- const verticalPos = bounds.getVerticalPos()
- drawMessage(diagram, startx, stopx, verticalPos, msg, sequenceIndex)
- const allBounds = fromBounds.concat(toBounds)
- bounds.insert(Math.min.apply(null, allBounds), verticalPos, Math.max.apply(null, allBounds), verticalPos)
+ const verticalPos = bounds.getVerticalPos();
+ drawMessage(diagram, startx, stopx, verticalPos, msg, sequenceIndex);
+ const allBounds = fromBounds.concat(toBounds);
+ bounds.insert(
+ Math.min.apply(null, allBounds),
+ verticalPos,
+ Math.max.apply(null, allBounds),
+ verticalPos
+ );
} catch (e) {
- logger.error('error while drawing message', e)
+ logger.error('error while drawing message', e);
}
}
// Increment sequence counter if msg.type is a line (and not another event like activation or note, etc)
- if ([
- parser.yy.LINETYPE.SOLID_OPEN,
- parser.yy.LINETYPE.DOTTED_OPEN,
- parser.yy.LINETYPE.SOLID,
- parser.yy.LINETYPE.DOTTED,
- parser.yy.LINETYPE.SOLID_CROSS,
- parser.yy.LINETYPE.DOTTED_CROSS
- ].includes(msg.type)) {
- sequenceIndex++
+ if (
+ [
+ parser.yy.LINETYPE.SOLID_OPEN,
+ parser.yy.LINETYPE.DOTTED_OPEN,
+ parser.yy.LINETYPE.SOLID,
+ parser.yy.LINETYPE.DOTTED,
+ parser.yy.LINETYPE.SOLID_CROSS,
+ parser.yy.LINETYPE.DOTTED_CROSS
+ ].includes(msg.type)
+ ) {
+ sequenceIndex++;
}
- })
+ });
if (conf.mirrorActors) {
// Draw actors below diagram
- bounds.bumpVerticalPos(conf.boxMargin * 2)
- drawActors(diagram, actors, actorKeys, bounds.getVerticalPos())
+ bounds.bumpVerticalPos(conf.boxMargin * 2);
+ drawActors(diagram, actors, actorKeys, bounds.getVerticalPos());
}
- const box = bounds.getBounds()
+ const box = bounds.getBounds();
// Adjust line height of actor lines now that the height of the diagram is known
- logger.debug('For line height fix Querying: #' + id + ' .actor-line')
- const actorLines = d3.selectAll('#' + id + ' .actor-line')
- actorLines.attr('y2', box.stopy)
+ logger.debug('For line height fix Querying: #' + id + ' .actor-line');
+ const actorLines = d3.selectAll('#' + id + ' .actor-line');
+ actorLines.attr('y2', box.stopy);
- let height = box.stopy - box.starty + 2 * conf.diagramMarginY
+ let height = box.stopy - box.starty + 2 * conf.diagramMarginY;
if (conf.mirrorActors) {
- height = height - conf.boxMargin + conf.bottomMarginAdj
+ height = height - conf.boxMargin + conf.bottomMarginAdj;
}
- const width = (box.stopx - box.startx) + (2 * conf.diagramMarginX)
+ const width = box.stopx - box.startx + 2 * conf.diagramMarginX;
if (title) {
- diagram.append('text')
+ diagram
+ .append('text')
.text(title)
- .attr('x', ((box.stopx - box.startx) / 2) - (2 * conf.diagramMarginX))
- .attr('y', -25)
+ .attr('x', (box.stopx - box.startx) / 2 - 2 * conf.diagramMarginX)
+ .attr('y', -25);
}
if (conf.useMaxWidth) {
- diagram.attr('height', '100%')
- diagram.attr('width', '100%')
- diagram.attr('style', 'max-width:' + (width) + 'px;')
+ diagram.attr('height', '100%');
+ diagram.attr('width', '100%');
+ diagram.attr('style', 'max-width:' + width + 'px;');
} else {
- diagram.attr('height', height)
- diagram.attr('width', width)
+ diagram.attr('height', height);
+ diagram.attr('width', width);
}
- const extraVertForTitle = title ? 40 : 0
- diagram.attr('viewBox', (box.startx - conf.diagramMarginX) + ' -' + (conf.diagramMarginY + extraVertForTitle) + ' ' + width + ' ' + (height + extraVertForTitle))
-}
+ const extraVertForTitle = title ? 40 : 0;
+ diagram.attr(
+ 'viewBox',
+ box.startx -
+ conf.diagramMarginX +
+ ' -' +
+ (conf.diagramMarginY + extraVertForTitle) +
+ ' ' +
+ width +
+ ' ' +
+ (height + extraVertForTitle)
+ );
+};
export default {
bounds,
drawActors,
setConf,
draw
-}
+};