Skip to main content

Sequence Diagrams

Sequence diagrams are created by setting shape: sequence_diagram on an object.

alicebob What does it meanto be well-adjusted?The ability to play bridge orgolf as if they were games.

Rules

Unlike other tools, there is no special syntax to learn for sequence diagrams. The rules are also almost exactly the same as everywhere else in D2, with two notable differences.

Scoping

Children of sequence diagrams share the same scope throughout the sequence diagram.

For example:

Office chatterAliceBobbyawkward small talkicebreaker attemptunfortunate outcome uhm, hioh, hellowhat did you have for lunch?that's personal

Outside of a sequence diagram, there would be multiple instances of alice and bob, since they have different container scopes. But when nested under shape: sequence_diagram, they refer to the same alice and bob.

Ordering

Elsewhere in D2, there is no notion of order. If you define a connection after another, there is no guarantee is will visually appear after. However, in sequence diagrams, order matters. The order in which you define everything is the order they will appear.

This includes actors. You don't have to explicitly define actors (except when they first appear in a group), but if you want to define a specific order, you should.

info

An actor in D2 is also known elsewhere as "participant".

Features

Sequence diagrams are D2 objects

Like every other object in D2, they can be contained, connected, relabeled, re-styled, and treated like any other object.

Before and after becoming friendsOffice chatter in 2007Office chatter in 2012AliceBobbyAliceBobby Fiveyearslaterawkward small talkicebreaker attemptunfortunate outcomeuhm, hioh, hellowhat did you have for lunch?that's personalWant to play with ChatGPT?Yes!Write a play...about 2 friends...who find love...in a sequence diagram

Spans

Spans convey a beginning and end to an interaction within a sequence diagram.

info

A span in D2 is also known elsewhere as a "lifespan", "activation box", and "activation bar".

You can specify a span by connecting a nested object on an actor.

alicebob

Groups

Groups help you label a subset of the sequence diagram.

info

A group in D2 is also known elsewhere as a "fragment", "edge group", and "frame".

We saw an example of this in an earlier example when explaining scoping rules. More formally, a group is a container within a sequence_diagram shape which is not connected to anything but has connections or objects inside.

caution

Due to the unique scoping rules in sequence diagrams, when you are within a group, the objects you reference in connections must exist at the top-level. Notice in the above example that alice and bob are explicitly declared before group declarations.

alicebobshower thoughtslife advice A physicist is an atom's way of knowing about atoms.Today is the first day of the rest of your life.If all else fails, lower your standards.

Notes

Notes are declared by defining a nested object on an actor with no connections going to it.

alicebobimportant insight Chocolate chip.In the eyes of my dog, I'm a man.Cold hands, no gloves.

Self-messages

Self-referential messages can be declared from an actor to the themselves.

sonfatherfriend Can I borrow your car?Never lend your car to anyone to whom you have given birth.internal debate ensues

Customization

You can style shapes and connections like any other. Here we make some messages dashed and set the shape on an actor.

scoreritemResponseitemessayRubricconceptitemOutcome getItem() itemgetRubric()rubricapplyTo(essayResp)match(essayResponse)scorenewgetNormalMinimum()getNormalMaximum()setScore(score)setFeedback(missingConcepts)

Lifeline edges (those lines going from top-down) inherit the actor's stroke and stroke-dash styles.

alicebob What does it meanto be well-adjusted?The ability to play bridge orgolf as if they were games.

Glossary

sequence diagram glossary