PlantUML mostly does a good job organizing elements and arrows in the resulting diagram.
But we can help PlantUML by defining the arrow direction in our PlantUML definition.
We can use the keywords up
, down
, left
and right
inside the arrow definition.
In the following example we have five rectangles connected with arrows.
We define the arrow direction for each arrow.
Continue reading →
PlantUML supports sprites to be used in diagrams.
A sprite is text encoded monochrome graphic we can reference using the syntax <$spriteName>
.
The sprite is defined using hexadecimal values.
We can define a set of hexadecimal values to create our sprite, but we can also generate the correct values from for example a PNG image.
We start with a simple example where we create a small triangle using hexadecimal values:
Continue reading →
We have a lot of ways to customize our PlantUML diagrams.
We can change the colors and we can even set gradients as color.
A gradient has two colors and a direction.
The direction of the gradient is set by the separator between the two colors.
We can use the following separators to set the gradient direction:
-
/
: direction top left to bottom right
-
\
: direction bottom left to top right
-
|
: direction left to right
-
-
: direction top to bottom
Continue reading →
When we generate a PNG version of our PlantUML definition the original definition is stored in the PNG image.
We can extract the definition using the command line option -metadata
.
We need to provide the PNG file and in the output we see the original PlantUML definition.
The following PNG image (activity.png
) is created with PlantUML:
Continue reading →
We can change the line style and color when we "draw" the line in our PlantUML definition.
We must set the line style and color between square brackets ([]
).
We can choose the following line styles: bold
, plain
, dotted
and dashed
.
The color is either a color name or a hexadecimal RGB code prefixed with a hash (#
).
In the following example activity diagram we apply different styles and colors to the lines:
Continue reading →
In PlantUML we can use the special variable %date%
to get the current date and time.
The default format shows day of the week, date, time and timezone.
We can change the date format by specifying our format with the Java SimpleDateFromat symbols.
For example to only get the hours and minutes we would write %date[HH:mm]%
.
In the following example we use the %date%
variable as is and with a custom format:
Continue reading →
With the command line option -checkversion
we can see if we have the latest PlantUML version.
The command prints to the console our current PlantUML version and latest version that is available.
Inside a PlantUML definition we can use the command checkversion
and generate for example a PNG image with information about our PlantUML version and the latest version that can be downloaded.
First we use the command line option -checkversion
for an out-of-date version:
Continue reading →
If we want to know which version of PlantUML we are using we can use the command line option -version
.
PlantUML will print the version and also some extra information like the machine name, memory and more.
But we can also create a PlantUML definition with the command version
and we can transform it to a graphical presentation like a PNG image.
This can be handy if we use PlantUML in an environment like Asciidoctor with diagram support and we want to know which version of PlantUML is used.
In our first example we run PlantUML from the command line and use the -version
option:
Continue reading →
PlantUML has a fun command to create a Sudoku puzzle.
We must use sudoku
in our PlantUML definition and a random puzzle is generated.
We can even give a seed value for a given Sudoku so it is generated again.
In the following example PlantUML definition we use the sudoku
command:
@startuml
sudoku
@enduml
Continue reading →
With PlantUML we can include external files in our definition with the !include
directive.
We specify the file name and the content is included in our PlantUML definition.
The included file can also have multiple @startuml ... @enduml
sections and we can refer to individual sections with the !include
directive.
We must append to the include file name an exclamation mark (!
) followed by either a number or identifier.
If we use a number we specify which section we want to include, where section are numbered starting from 0
.
So to get the second section from a file commons.puml
we would write !include commons.puml!1
.
Alternatively we can use identifiers in the include file.
We append to @startuml
an identifier as (id=idValue)
.
Then from the definition that is including the file we refer to the identifier after an exclamation mark (!
).
If our included file commons.puml
has a section with id user
then we would include it as !include commons.puml!user
.
In the following example PlantUML definition we define the file to be included.
We have two sections with @startuml ... @enduml
which both have an identifier:
Continue reading →
To change the styling of our generated diagrams with PlantUML we can use the skinparam
command. We can set for example font size, style, color, background colors and much more. We can change the style for a specific element or for the whole diagram. We can even set specific styling options for stereotypes. The settings for the stereotype are then applied to all elements in our diagram with that stereotype. We must append <<stereotype name>>
to the skin parameter name.
In the following example PlantUML description we apply custom background colors to each stereotype:
Continue reading →
When we write a PlantUML definition the generated graphical diagram is laid out by PlantUML.
In a previous post we learned how to move elements using the length of the connection.
But we can also use a together
block with all elements that should be at the same level.
PlantUML will try to keep the elements together when the diagram is drawn.
In the following sample PlantUML definition we want the PostgresDB and Mail elements to be at the same level, so we group them using a together
block:
Continue reading →