Legend unnecessarily extends diagram size

+1 vote
asked Feb 19, 2019 in Question / help by roxspring (260 points)

The following diagram includes a "legend right" and happens to have loads of space to the right in the diagram, but the diagram is extended downwards in order to make space for the legend. Would it be possible for the legend placement to first layout the rest of the diagram and then attempt to make use of free space before extending the diagram?

PlantUML diagram

@startuml

[Thing A1]  -> [Thing B1]

[Thing B1]  -> [Thing C1]

[Thing A1] --> [Thing A2]

[Thing A2] --> [Thing A3]

legend right

Legendary

    content

    goes

    here

endlegend

@enduml

(happy for answers to include suggestions of how I might go about implementing the feature and submitting a patch)

commented Feb 21, 2019 by albert (3,000 points)
@plantuml I see that there are a number of possibilities: "You can optionally specify to have left, right, top, bottom or center alignment for the legend. " . Test shows that one can even combine "top right" and other combinations between left / right / center and top / bottom, but I don't see a possibility to have the horizontal alignment "center" (or "middle") that would  would be beneficial here

1 Answer

0 votes
answered Apr 11 by kirchsth (780 points)

Hi roxspring,

I solved it via an invisible note, and then you can align the note via a hidden relation.

@startuml
[Thing A1]  -> [Thing B1]

[Thing B1]  -> [Thing C1]

[Thing A2] as A2

[Thing A1] --> A2

A2 --> [Thing A3]

' add legend in "invisible" note
skinparam shadowing false
skinparam note {
    backgroundcolor transparent
    bordercolor transparent
}

note as moveLegend
<#white,#white>|<color:black>**Legend**</color> |
|text |
|text |
endnote

moveLegend -[hidden]L- A2
@enduml

BR Helmut
PS.: transparent is not transparent and therefore you see a broken border of A2 (this could be entered as bug)

commented Apr 12 by The-Lu (21,440 points)

Hello all,

1/ for "transparent is not transparent", you can change transparent to #00000000 as:



2/ another workaround is to just transform legend to rectangle, and a link as your note :

@startuml
[Thing A1]  -> [Thing B1]
[Thing B1]  -> [Thing C1]
[Thing A1] --> [Thing A2]
[Thing A2] --> [Thing A3]

rectangle r [
    **Legend**
    content
    goes
    here
]

r -[hidden]L- [Thing A2]
@enduml

Regards,
Th.

commented Apr 13 by Martin (4,260 points)

Minor refinement to use a label containing a real legend in place of the note/rectangle.

...