diff --git a/cypress/integration/rendering/sequencediagram.spec.js b/cypress/integration/rendering/sequencediagram.spec.js index 1285a0832d..e9e55f08dc 100644 --- a/cypress/integration/rendering/sequencediagram.spec.js +++ b/cypress/integration/rendering/sequencediagram.spec.js @@ -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( @@ -517,7 +543,7 @@ 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 @@ -525,7 +551,7 @@ context('Sequence diagram', () => { 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 @@ -548,7 +574,7 @@ 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 @@ -556,7 +582,7 @@ context('Sequence diagram', () => { 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 @@ -580,7 +606,7 @@ 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 @@ -588,7 +614,7 @@ context('Sequence diagram', () => { 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 diff --git a/packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts b/packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts index 98fdcddc40..bc4d21c792 100644 --- a/packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts +++ b/packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts @@ -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); diff --git a/packages/mermaid/src/docs/syntax/sequenceDiagram.md b/packages/mermaid/src/docs/syntax/sequenceDiagram.md index 4fc25bd12e..575a6e2de6 100644 --- a/packages/mermaid/src/docs/syntax/sequenceDiagram.md +++ b/packages/mermaid/src/docs/syntax/sequenceDiagram.md @@ -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