Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

PlantUML Pleasantness: Lay Out Elements With Hidden Lines

DZone's Guide to

PlantUML Pleasantness: Lay Out Elements With Hidden Lines

In this post, we take a look at how to lay things out nicely using hidden lines in PlantUML. Render your diagrams exactly how you want!

· Java Zone ·
Free Resource

Verify, standardize, and correct the Big 4 + more– name, email, phone and global addresses – try our Data Quality APIs now at Melissa Developer Portal!

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 laid out as if there was a line, but we don't see it. This gives us great flexibility on how we layout our elements.

In the following sample, we first have a PlantUML definition where we rely on the default layout:

@startuml
 
package "Core Components" {
    [Backend Client] as BackendClient
    [File Reader] as FileReader
    [Content Transform] as ContentTransform
    [Logging]
}
 
BackendClient ~~> ContentTransform : uses
FileReader ~~> ContentTransform: uses
 
@enduml


This definition renders the following diagram:

Image title

We want the Logging component at the bottom right corner of the Core Components. Using a visible line, we would connect the BackendClient to the Logging component. This would place the Logging component beneath the BackendClient, just like we want. So we add a connecting line and we add the [hidden] attribute on our line definition. The Logging component is placed where we want and we don't see the line supporting this:

@startuml
 
package "Core Components" {
    [Backend Client] as BackendClient
    [File Reader] as FileReader
    [Content Transform] as ContentTransform
    [Logging]
}
 
BackendClient ~~> ContentTransform : uses
FileReader ~~> ContentTransform: uses
 
' Layout Logging under BackendClient
BackendClient -[hidden]- Logging
 
@enduml


When we regenerate the diagram, we get the result we want:

Image title

Written with PlantUML 1.2017.16.

Developers! Quickly and easily gain access to the tools and information you need! Explore, test and combine our data quality APIs at Melissa Developer Portal – home to tools that save time and boost revenue. Our APIs verify, standardize, and correct the Big 4 + more – name, email, phone and global addresses – to ensure accurate delivery, prevent blacklisting and identify risks in real-time.

Topics:
layout ,plantuml ,result ,groovy ,diagram ,uml

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}