Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PlantUML: nested components with text possible?

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?)

like image 913
frans Avatar asked Aug 21 '17 10:08

frans


People also ask

How do I add a note in PlantUML?

It is possible to put notes on message using the note left or note right keywords just after the message. You can have a multi-line note using the end note keywords.

How do you use Alt in PlantUML?

You have to add an end statement to close the alt block. As a side note: You do not need to add the square brackets in your alt statements. PlantUML renders those itself.

What is PUML format?

File created by PlantUML, a UML diagram creator used within programs like Sublime Text Editor or programming language like HTML; same as the . PU file; contains code referenced by PlantUML to create diagram images that can be generated as . PNG or .

How do you underline in PlantUML?

<u> or <u:#AAAAAA> or <u:[[color|colorName]]> for underline. <i> for italic. <s> or <s:#AAAAAA> or <s:[[color|colorName]]> for strike text. <w> or <w:#AAAAAA> or <w:[[color|colorName]]> for wave underline text.


1 Answers

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

like image 120
Frelling Avatar answered Sep 21 '22 21:09

Frelling