10

As I've seen from the examples in PlantUML you can have certain graphical objects with text in it like

folder folder1 [
    Here you can have some explanation with
    ====
    --Markdown-- //formatting// ~~elements~~
]

which renders to

enter image description here

You can also use folder (among other elements) to group other items by nesting them:

folder folder2 {
    folder folder3 [
        text bla bla
    ]
    artifact art2 [
        more text
    ]
}

enter image description here

But currently I see no way to combine both - an object with some explaining text in it and nested elements.

Is that possible with PlantUML? (how?)

frans
  • 8,868
  • 11
  • 58
  • 132

1 Answers1

10

I can only assume that PlantUML tries to be as UML-like as possible. While it is possible to add long descriptions ([...]) to elements, I'm almost certain it was intended only for certain element types (e.g. activity elements, use cases, etc.), which generally do not contain sub-elements. However, for more formal diagrams, any "text" required to annotate or further explain a concept should be added as notes or callouts.

I ran into this issue many moons ago, and did do exactly as you are trying to do. I dug into my diagram archives and found an example that would be very close to what you want to achieve.

Thus, to answer your question, a solution for including both descriptive text and UML elements in a grouping elements such as folders, is as follows:

@startuml
skinparam rectangle<<desc>> {
    backgroundColor Transparent
    borderColor Transparent
    titleFontColor Red
    stereotypeFontColor Transparent
}

folder folder2 {
    folder folder3 [
        text bla bla
    ]
    artifact art2 [
        more text
    ]
    rectangle f2<<desc>> [
        Here you can have some explanation with
        ====
        --Markdown-- //formatting// ~~elements~~
    ]

    folder3 -[hidden]- f2
}
@enduml

enter image description here

As you will note, a connection is used to tweak text placement and may require some more complex finagling depends on the size of your text and the number of elements.

Since those early days, I have followed closer to the UML spec; see this answer for more details on comments. Not only is it easier to add comments, but PlantUML code is far simpler. That said, the following is a variant of the above using this approach.

@startuml
folder folder2 {
    folder folder3 [
        text bla bla
    ]
    artifact art2 [
        more text
    ]
}

note bottom of folder2
    Here you can have some explanation with
    ====
    --Markdown-- //formatting// ~~elements~~
end note
@enduml

enter image description here

Frelling
  • 3,287
  • 24
  • 27
  • The 1st way doesn't work for me using PlantUML 1.2018.11 while I'm constructing deployment diagrams. Haven't tried other diagram types though. Seems like by some reason skinparam can't be parsed when it comes to rectangle<>. Workarounded it with a simple transparent rectangle and a transparent arrow (acceptable in my case). The 2nd works but is not that convenient sometimes. (I just want descriptions to be inside relevant objects.) – Alexander Ites Feb 10 '21 at 10:26