Skip to content

Commit 1ad9e75

Browse files
committed
Merge pull request #318 from ciekawy/activation_draft
activations doc + few fixes
2 parents e9c6db4 + d070029 commit 1ad9e75

File tree

2 files changed

+73
-11
lines changed

2 files changed

+73
-11
lines changed

docs/content/sequenceDiagram.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,55 @@ There are six types of arrows currently supported:
7272
--x which will render a dotted line with a cross at the end (async)
7373

7474

75+
## Activations
76+
It is possible to activate and deactivate an actor. (de)activation can be dedicated declarations:
77+
78+
```
79+
sequenceDiagram
80+
Alice->>John: Hello John, how are you?
81+
activate John
82+
John-->>Alice: Great!
83+
deactivate John
84+
```
85+
86+
Renders to the diagram below:
87+
88+
```mermaid
89+
sequenceDiagram
90+
Alice->>John: Hello John, how are you?
91+
activate John
92+
John-->>Alice: Great!
93+
deactivate John
94+
```
95+
96+
There is also a shortcut notation by appending `+`/`-` suffix to the message arrow:
97+
98+
```
99+
sequenceDiagram
100+
Alice->>+John: Hello John, how are you?
101+
John-->>-Alice: Great!
102+
```
103+
104+
Activations can be stacked for same actor:
105+
106+
```
107+
sequenceDiagram
108+
Alice->>+John: Hello John, how are you?
109+
Alice->>+John: John, can yoy hear me?
110+
John-->>-Alice: Hi Alice, I can hear you!
111+
John-->>-Alice: I feel great!
112+
```
113+
114+
Stacked activations look like this:
115+
116+
```mermaid
117+
sequenceDiagram
118+
Alice->>+John: Hello John, how are you?
119+
Alice->>+John: John, can yoy hear me?
120+
John-->>-Alice: Hi Alice, I can hear you!
121+
John-->>-Alice: I feel great!
122+
```
123+
75124
## Notes
76125
It is possible to add notes to a sequence diagram. This is done by the notation
77126
Note [ right of | left of | over ] [Actor]: Text in note content

src/diagrams/sequenceDiagram/sequenceRenderer.js

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,19 @@ module.exports.draw = function (text, id) {
347347
svgDraw.insertArrowHead(diagram);
348348
svgDraw.insertArrowCrossHead(diagram);
349349

350+
function activeEnd(msg, verticalPos) {
351+
var activationData = exports.bounds.endActivation(msg);
352+
if(activationData.starty + 18 > verticalPos) {
353+
activationData.starty = verticalPos - 6;
354+
verticalPos += 12;
355+
}
356+
svgDraw.drawActivation(diagram, activationData, verticalPos, conf);
357+
358+
exports.bounds.insert(activationData.startx, verticalPos -10, activationData.stopx, verticalPos);
359+
}
360+
361+
var lastMsg;
362+
350363
// Draw the messages/signals
351364
messages.forEach(function(msg){
352365
var loopData;
@@ -374,15 +387,10 @@ module.exports.draw = function (text, id) {
374387
}
375388
break;
376389
case sq.yy.LINETYPE.ACTIVE_START:
377-
// exports.bounds.bumpVerticalPos(conf.boxMargin);
378390
exports.bounds.newActivation(msg, diagram);
379-
// exports.bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin);
380391
break;
381392
case sq.yy.LINETYPE.ACTIVE_END:
382-
var activationData = exports.bounds.endActivation(msg);
383-
svgDraw.drawActivation(diagram, activationData, exports.bounds.getVerticalPos(), conf);
384-
385-
exports.bounds.insert(activationData.startx, exports.bounds.getVerticalPos() -10, activationData.stopx, exports.bounds.getVerticalPos());
393+
activeEnd(msg, exports.bounds.getVerticalPos());
386394
break;
387395
case sq.yy.LINETYPE.LOOP_START:
388396
exports.bounds.bumpVerticalPos(conf.boxMargin);
@@ -426,14 +434,19 @@ module.exports.draw = function (text, id) {
426434
break;
427435
default:
428436
try {
437+
lastMsg = msg;
429438
exports.bounds.bumpVerticalPos(conf.messageMargin);
430439
var fromBounds = actorFlowVerticaBounds(msg.from);
431440
var toBounds = actorFlowVerticaBounds(msg.to);
432-
var forward = fromBounds[0] < toBounds[0];
433-
startx = fromBounds[forward?1:0];
434-
stopx = toBounds[forward?0:1];
435-
436-
drawMessage(diagram, startx, stopx, exports.bounds.getVerticalPos(), msg);
441+
var fromIdx = fromBounds[0] <= toBounds[0]?1:0;
442+
var toIdx = fromBounds[0] < toBounds[0]?0:1;
443+
startx = fromBounds[fromIdx];
444+
stopx = toBounds[toIdx];
445+
446+
var verticalPos = exports.bounds.getVerticalPos();
447+
drawMessage(diagram, startx, stopx, verticalPos, msg);
448+
var allBounds = fromBounds.concat(toBounds);
449+
exports.bounds.insert(Math.min.apply(null, allBounds), verticalPos, Math.max.apply(null, allBounds), verticalPos);
437450
} catch (e) {
438451
console.error('error while drawing message', e);
439452
}

0 commit comments

Comments
 (0)