Lifelines
Last updated
Was this helpful?
Last updated
Was this helpful?
Lifelines are the basic building block for sequence diagrams. They represent the participants that send and receive messages in sequence diagrams. The lifeline consists of a head with a name and a line drawn vertically down from the head. The default head is a rectangle with a name in it. PlantUML draws a foot as well. The foot is nice aesthetically but is not an official part of UML. We will leave it in our examples for aesthetic reasons.
Use the "participant" keyword followed by a name to declare a default lifeline. Lifelines automatically appear left to right in order of declaration.
Properties following the participant_type affect the format of the lifeline head. To declare a lifeline, you must only use the participant_type and name properties. There is some wiggle room with the property order. For the sake of consistency and best practice, we will keep them in the below order throughout this book. Below is a list of lifeline properties.
participant_type - determines the head shape based on its classifier
name - the text that appears in the head of the lifeline
display_name - a method for formatting name, comes after name
formatted_name - used in place of name and display_name
variable_name - used as a variable for a lifeline with a long name
back_ground_color - sets the background color of the head
stereotype - allows for the head to display a stereotype
order_number - adjusts the horizontal order of lifelines
There are several options for participant_type. Replace participant with any other participant_type. The options are indicative of UML classifiers. PlantUML will change the header shape accordingly. Below is a list of participant types.
participant
actor
boundary
control
entity
database
collections
queue
The name is simply text that appears in the head of the lifeline. The name can be a single word without quotation marks or it can be a string with quotation marks. The string method supports line breaks.
The background_color property allows you to change the background color of the lifeline head. You can define colors with a standard color name or hex code. Create a gradient by using two colors. Notice that these colors can be used on any participant_type.
Example: Background Color
The stereotype property gives the ability to add a stereotype to the lifeline head. You can emphasize stereotype text with creole syntax and color it with markup. It is also possible to embed a colored circle with an internal character or both. Define colors with a standard color name or hex code.
The order_number property allows you to arrange lifelines regardless of their order in the code.
You can create a sequence diagram without declaring lifelines. However, the lifelines will only have default properties. Lifelines are automatically generated as they appear in messages. This can be useful if you assemble a quick sequence diagram without bells or whistles.
A participant can create another participant, therefore starting a new lifeline. The creation commands are below.
create - creates a lifeline on the following message line
** - shortcut for create that is used on the message line
The new lifeline will not visually exist in the sequence diagram until created. However, if you want to adjust the new lifeline properties, you must declare the lifeline beforehand. Undeclared lifelines that are created with the create command have default properties just like the undeclared lifelines example above.
It is possible to hide the lifeline foot. It is also possible to hide lifelines that do not send or receive messages. You can do both the following hide commands.
hide footbox - hides the lifeline foot from the sequence diagram drawing
hide unlinked - hides all inactive lifelines
The display_name property follows the "as" keyword. It can be used to display text in the head that is entirely different from the name. The display_name property supports creole syntax for emphasis and markup language for color. You can define colors with a standard color name or hex code. Oddly PlantUML does not support emphasis with markup in the lifeline head. This lack of markup options does not align with all PlantUML text fields. Luckily, we can combine markup and creole. See for a list of creole and markup options.
The formatted_name property replaces name and display_name. Similar to display_name it supports creole syntax for emphasis and markup language for color. You can define colors with a standard color name or hex code. Once again, PlantUML does not support emphasis with markup in the lifeline head. However, we can still combine markup and creole. See for a list of creole and markup options.
A variable_name is just that, a variable. You can assign a lifeline to a variable using the "as" keyword. This practice eases utilization of a lifeline with a formatted_name. Otherwise, you have to type the entire lifeline name, including formatting, every time you use that lifeline. To show this we will pass a few messages between our lifelines. Messages will not be explained here. See the section for an in-depth explanation.
Use the create command on the line before the creation message. Use the ** shortcut command immediately following the name of the created lifeline in the message line. To comply with UML standards, be sure to draw the creation message with a dashed line and an open arrowhead. See lines 11 and 16 below. Messages are thoroughly covered in the section.