With the Asciidoctor diagram extension we can include diagrams that are written in plain text. For example PlantUML or Ditaa diagrams. The extension offers a block processor where we include the diagram definitions in our Asciidoctor document. But there is also a block macro processor. With the block macro processor we can refer to an external file. The file is processed and the resulting image is in our output document.
Category Archives: PlantUML
PlantUML Pleasantness: Using The Built-in Icons
PlantUML has a built-in icon set we can use in our diagram definitions. The icon set is open source icon set OpenIconic. We refer to an icon using the syntax <&iconName>
.We can use an icon everywhere where we can use text in our diagrams.
PlantUML Pleasantness: Creating Our Own Sprites
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.
PlantUML Pleasantness: Layout Elements With Hidden Lines
In a previous post we learned how to use a together
block to keep elements together. We can also layout elements in a different way: using hidden lines. We define our elements and by using the keyword [hidden]
in our line definition the elements are layout as if there was a line, but we don’t see it. This gives us great flexibility on how we layout our elements.
PlantUML Pleasantness: Align Multi-line Label Text
PlantUML has some features that come from the underlying software to create diagrams. Graphviz is used by PlantUML and we can use Graphviz features in our PlantUML diagrams. For example we can align multi-line text of labels to be either center (default), left or right aligned using a Graphviz feature. When we want to text to be center aligned we simply use the new-line character \n
. If we want to have our text left aligned we use \l
instead of \n
. And to right align the text we use \r
.
PlantUML Pleasantness: Get PlantUML Definition From PNG
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:
Next we run PlantUML from the command line using the option -metadata
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
$ java -jar plantuml.jar -metadata activity.png ------------------------ activity.png @startuml ' Make a dashed line, alternative syntax for ..> (*) -[dashed]-> "Write outline" ' Make line bold and use color code "Write outline" -[bold,#008000]-> "Find example" ' Only change the color "Find example" -[#ff00ff]-> "Write blog" ' Order of line style and color can be reversed "Write blog" -[#6666ff,dashed]-> "Publish" ' Use dotted line style "Publish" -[dotted]-> (*) @enduml PlantUML version 8051(Thu Dec 01 18:52:05 CET 2016) (GPL source distribution) Java Runtime: Java(TM) SE Runtime Environment JVM: Java HotSpot(TM) 64-Bit Server VM Java Version: 1.8.0_112-b16 Operating System: Mac OS X OS Version: 10.12.1 Default Encoding: UTF-8 Language: en Country: US ------------------------ $ |
At the top we see the section @startuml..@enduml
with the PlantUML syntax that was used to generate the PNG image.
Written with PlantUML 8051.
PlantUML Pleasantness: Change Line Style And Color
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
@startuml ' Make a dashed line, alternative syntax for ..> (*) -[dashed]-> "Write outline" ' Make line bold and use color name "Write outline" -[bold,#green]-> "Find example" ' Only change the color with hexadecimal RGB code "Find example" -[#ff00ff]-> "Write blog" ' Order of line style and color can be reversed "Write blog" -[#6666ff,dashed]-> "Publish" ' Use dotted line style "Publish" -[dotted]-> (*) @enduml |
When we generate the activity diagram we see the different line styles and colors:
Written with PlantUML 8051.
PlantUML Pleasantness: Using Current Date
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]%
.
PlantUML Pleasantness: Check If PlantUML Is Up To Date
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:
1 2 3 4 5 6 7 |
$ plantuml -checkversion PlantUML version 8048 (Thu Sep 29 19:04:02 CEST 2016) Last available version for download : 8051 A newer version is available for download. $ |
We update our PlantUML and run the command again:
1 2 3 4 5 6 7 |
$ plantuml -checkversion PlantUML version 8051 (Thu Dec 01 18:52:05 CET 2016) Last available version for download : 8051 Your version is up to date. $ |
Now we use a PlantUML definition so we can generate a graphical representation of the information.
1 2 3 |
@startuml checkversion @enduml |
First we use the older version of PlantUML to generate a PNG image:
Next we use the latest version that is available:
Written with PlantUML 8051.
PlantUML Pleasantness: Generate Graphical Version Information
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.