Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: SequenceDiagram: draw activations even without explicit deactivation #5457

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 32 additions & 6 deletions cypress/integration/rendering/sequencediagram.spec.js
Expand Up @@ -231,6 +231,32 @@ context('Sequence diagram', () => {
`
);
});
it('should render a sequence diagram with activations even if there are no deactivations', () => {
renderGraph(
`
sequenceDiagram
participant a
participant b
participant c
participant d
activate d
a->>b:halloB
activate b
b->>+c:halloC
c->>+b:back
create participant e
a-->>e:createE
activate e
a-->>e:halloE
destroy e
e->>a:destroyE
a-->>d : halloD
`,
{ sequence: { useMaxWidth: false } }
);
cy.get('rect.activation0').should('have.length', 4);
cy.get('rect.activation1').should('have.length', 1);
});
context('font settings', () => {
it('should render different note fonts when configured', () => {
imgSnapshotTest(
Expand Down Expand Up @@ -517,15 +543,15 @@ context('Sequence diagram', () => {
participant E
participant G

A ->>+ B: Task 1
A ->> B: Task 1
rect rgb(178, 102, 255)
B ->>+ C: Task 2
C -->>- B: Return
end

A ->> D: Task 3
rect rgb(0, 128, 255)
D ->>+ E: Task 4
D ->> E: Task 4
rect rgb(0, 204, 0)
E ->>+ G: Task 5
G -->>- E: Return
Expand All @@ -548,15 +574,15 @@ context('Sequence diagram', () => {
participant E
participant G

A ->>+ B: Task 1
A ->> B: Task 1
opt this is an opt with a long title that will overflow
B ->>+ C: Task 2
C -->>- B: Return
end

A ->> D: Task 3
opt this is another opt with a long title that will overflow
D ->>+ E: Task 4
D ->> E: Task 4
opt this is a nested opt with a long title that will overflow
E ->>+ G: Task 5
G -->>- E: Return
Expand All @@ -580,15 +606,15 @@ context('Sequence diagram', () => {
participant E
participant G

A ->>+ B: Task 1
A ->> B: Task 1
opt this is an opt with a long title that will overflow
B ->>+ C: Task 2
C -->>- B: Return
end

A ->> D: Task 3
opt this is another opt with a long title that will overflow
D ->>+ E: Task 4
D ->> E: Task 4
opt this is a nested opt with a long title that will overflow
E ->>+ G: Task 5
G -->>- E: Return
Expand Down
17 changes: 17 additions & 0 deletions packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts
Expand Up @@ -1050,9 +1050,26 @@ export const draw = async function (_text: string, id: string, _version: string,
for (const e of messagesToDraw) {
await drawMessage(diagram, e.messageModel, e.lineStartY, diagObj);
}

// all remaining activations in 'bounds' were not drawn, because the 'deactivate' is missing -> draw them from the activation y until the bottom / the destroying of the actor
for (const actor of bounds.models.actors) {
const notDrawnActivationsForThisActor = actorActivations(actor.name);
let stopY = bounds.getVerticalPos();
let index = 0;
for (const notDrawnActivation of notDrawnActivationsForThisActor) {
if (actor.stopy) { // if actor was destroyed -> use it's last y
stopY = actor.stopy;
}

svgDraw.drawActivation(diagram, notDrawnActivation, stopY, conf, index);
index++;
}
}

if (conf.mirrorActors) {
await drawActors(diagram, actors, actorKeys, true);
}

backgrounds.forEach((e) => svgDraw.drawBackgroundRect(diagram, e));
fixLifeLineHeights(diagram, actors, actorKeys, conf);

Expand Down
2 changes: 2 additions & 0 deletions packages/mermaid/src/docs/syntax/sequenceDiagram.md
Expand Up @@ -184,6 +184,8 @@ sequenceDiagram
John-->>-Alice: I feel great!
```

If no deactivation is found for an activated actor, it is still added to the diagram.

## Notes

It is possible to add notes to a sequence diagram. This is done by the notation
Expand Down