Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate a legend with colors in PlantUML?

I want to color classes in my class diagram, based on a certain criteria, and then display a legend, that would look roughly like:

Legend with colors

If I could add an HTML table within PlantUML's legend and endlegend, I could achieve this by changing the cell backgrounds. However, adding the HTML <table> doesn't work. I also tried using PlantUML's salt to insert a table, but I couldn't find any way to color the cells of the table.

Is there any way to achieve this?

like image 443
Masked Man Avatar asked Jun 23 '15 09:06

Masked Man


People also ask

How do I add a legend in PlantUML?

There doesn't appear to be a direct way of including a color-coded legend in a PlantUML diagram, but I figured out a workaround which is close enough. Declare classes TypeA , TypeB , TypeC inside a package LEGEND . Hide the circle, methods and members for each class. Attach "hidden" connectors between the classes.

How do you align PlantUML?

When we want to text to be center aligned we simply use the new-line character \n . If we want to have our text left aligned we use \l instead of \n . And to right align the text we use \r . Written with PlantUML 1.2017.

Is PlantUML open source?

PlantUML is free and open source and will always be. Those messages are usually generated on welcome or error images and never on fonctional diagrams.


2 Answers

I've tried nfec's solution and it was not working for me, but it started me off on a solution that did work. Here is what I got:

legend right     |Color| Type |     |<#FF0000>| Type A class|     |<#00FF00>| Type B class|     |<#0000FF>| Type C class| endlegend 

This is how it looks like:

Legend color table

like image 115
AmaDaden Avatar answered Sep 20 '22 23:09

AmaDaden


This is not perfect, but you can use a creole table. (see http://plantuml.sourceforge.net/creole.html )

@startuml class foo   legend  |= |= Type |  |<back:#FF0000>   </back>| Type A class |  |<back:#00FF00>   </back>| Type B class |  |<back:blue>   </back>| Type C class |  endlegend  @enduml 

Image showing the legend.

There are some drawing artifacts, but is it what you are expecting ?

From the plantuml forum. Where they allowed to copy this answer here.

Yes, please copy/paste our answer to StackOverflow : it would indeed by helpful

http://plantuml.sourceforge.net/qa/?qa=3596/how-to-generate-a-legend-with-colors-in-plantuml

like image 42
nfec Avatar answered Sep 21 '22 23:09

nfec