4

I'm evaluating if PlantUML can be a good alternative to GraphViz.

It's promoted as "intuitive" but honestly the very first example from the homepage is already confusing.

Why does the following create "Bob" and "Alice" twice? I'm seeing 2 nodes in the text, and 4 in the output. Also, the arrow doesn't go between the nodes, but between relations between duplications of the nodes.

Bob->Alice : hello

enter image description here

It makes zero sense to me. What is the meaning of this example, and what would be a more trivial example with just 2 nodes and an arrow between them?

Bouke Versteegh
  • 4,097
  • 1
  • 39
  • 35

2 Answers2

10

I see you have fallen for the classical trap of "The first page of the manual is not representative of the tool".(1)

Besides various UML diagrams (like the sequence diagram you encounered), PlantUML has support for various other Software development related formats (such as , Block diagram, , , Computer network diagrams, , chart, Mind maps, and ), as well as visualization of and files.

In fact, it even understands Graphviz syntax!(2)

Because of all of this, "intuitive" doesn't happen until you have some basic knowledge of PlantUML.

So back to your issue... What you are seeing isn't what you think it is.

What is that?

Relating things to Graphviz, instead of this:

digraph d {
    Bob -> Alice : hello
}

You are actually seeing this:(3)

@startuml
digraph sequenceDiagramExample {
  bobHead [ label="Bob" pos="0,1.5!" shape="record" ];
  bobPoint0 [ pos="0,0.75!" shape="point" width="0" ]
  bobFoot [ label="Bob" pos="0,0!" shape="record" ];
  aliceHead [ label="Alice" pos="1,1.5!" shape="record" ];
  alicePoint0 [ pos="1,0.75!" shape="point" width="0" ]
  aliceFoot [ label="Alice" pos="1,0!" shape="record" ];
  bobHead -> bobPoint0 -> bobFoot [ dir="none" style="dashed" ]
  aliceHead -> alicePoint0 -> aliceFoot [ dir="none" style="dashed" ]
  bobPoint0 -> alicePoint0 [ label="hello" labelloc="c" style="solid" ]
}
@enduml

Gimme an example!

What an example with just two nodes and an arrow between them looks like depends on the kind of graph chosen...

What you have to remember is that, with Graphviz, you have to apply all meaning to a diagram yourself. With PlantUML, the meaning is provided by PlantUML for you. All you need to do is tell PlantUML what you mean.

With a few basic pointers, this becomes intuitive quite quickly. You just need to know what kind of diagram you want to draw before starting...

As you can see from the examples below, PlantUML is a very powerful tool to add to your software developer toolbelt.

I hope the examples will help to make things more intuitive, and that your first misstep won't keep you from exploring PlantUML further!

Activity

@startuml
:Alice;
:Bob;
@enduml

Archimate

@startuml
archimate #Application Alice
archimate #Business Bob
Alice -> Bob
@enduml

Class

@startuml
Alice -|> Bob: Hello
@enduml

Component

@startuml
[Alice] -> [Bob]: Hello
@enduml

Deployment

@startuml
folder Alice
file Bob
Alice -> Bob: Hello
@enduml

Ditaa

@startditaa

+-------+       +-----+
|       | hello |     |
| Alice +------>| Bob |
|       |       |     |
+-------+       +-----+
@endditaa

Gantt

@startgantt
[Alice]->[Bob]
@endgantt

JSON

@startjson
{
  "Alice": ["Bob"]
}
@endjson

MindMap

@startmindmap
+ Alice
++ Bob
@endmindmap

Network

@startuml
nwdiag {
  network hello {
    Alice;
    Bob;
  }
}
@enduml

Object

@startuml
object Alice
object Bob
Alice -> Bob
@enduml

Sequence

@startuml
Bob -> Alice : hello
@enduml

State

@startuml
[*] -> Alice
Alice -> Bob: hello
Bob -> [*]
@enduml

Timing

@startuml
concise Hello
0 is Alice
+100 is Bob
@enduml

Use Case

@startuml
:Alice: -> :Bob: : Hello
@enduml

WBS

@startwbs
+ Alice
++ Bob
@endwbs

Footnotes

  1. It's not realy a classic, I just made that up. But it is something that commonly happens.
  2. Reference the manual here: https://plantuml.com/dot
  3. Rendered in neato not dot, see https://stackoverflow.com/a/53470455/153049
Potherca
  • 13,207
  • 5
  • 76
  • 94
  • 1
    Thank you very much for your extensive explanation! This is very helpful in understanding how PlantUML can be beneficial. I also hadn't realized that Plant is built on top of Graphviz, so that probably means that if graphviz can't do something (such as coloring a single field in a record without resorting to html tables), then PlantUML can also not do it. Thanks again! – Bouke Versteegh Feb 04 '21 at 16:25
  • Interesting. There are just a couple of confusing diagrams, from UML perspective, such as actor to actor, or class Alice inheriting from class Bob. – Christophe Feb 05 '21 at 16:44
  • @Christophe I have to admit I got a bit lazy and I wasn't always sure what alternative to use that would make sense from a UML perspective without making things confusing by different types of diagrams looking to much alike... For instance, the WBS is horrible.... :-/ Maybe I'll come back after the weekend and clean things up a bit :-D – Potherca Feb 05 '21 at 16:52
3

They are not “four nodes”, they are top and bottom headers for every participant in the sequence. This is useful for readability in larger sequence diagrams, see some examples here https://plantuml.com/en/sequence-diagram

You can style your diagram to comply with strict UML with

skinparam style strictuml

PlantUML output


Full code

@startuml
skinparam style strictuml
Bob -> Alice : hello
Alice -> Bob : ok
@enduml
michaeldel
  • 2,204
  • 1
  • 13
  • 19
  • So I understand PlantUML is made for sequence diagrams, not for arbitrary diagrams the way GraphViz works? Or can it do something simple like A->B which just shows two nodes and an arrow between them? – Bouke Versteegh Feb 03 '21 at 12:04
  • @BoukeVersteegh PlantUML is not limited to UML only... It started out that way but has become _very_ versatile since then. I've added an answer to demonstrate... – Potherca Feb 04 '21 at 15:58