Search code examples
plantuml

PlantUML Class Diagram - field/method visibility in legend


Is it possible to have a key to the class diagram's field/method visibility labels in the legend, using the real icons?

i.e. getting the real icons in the table following diagram

@startuml
class Dummy {
-field1
#field2
~method1()
+method2()
}

legend
|= field |= method |=  |
|  -     |   -     | private |
|  #     |   #     | protected |
|  ~     |   ~     | package private |
|  +     |   +     | public |

endlegend
@enduml

Example Diagram

Things I've tried without success:


Solution

  • This is pretty good (certainly good enough for my purposes):

    @startuml
    class Dummy {
    -field1
    #field2
    ~method1()
    +method2()
    }
    
    skinparam legendBackgroundColor #ffffff
    legend
    
    |= field |= method |=  |
    |  <img:http://s.plantuml.com/private-field.png>     |   <img:http://s.plantuml.com/private-method.png>     | private |
    |  <img:http://s.plantuml.com/protected-field.png>   |   <img:http://s.plantuml.com/protected-method.png>   | protected |
    |  <img:http://s.plantuml.com/package-private-field.png>     |   <img:http://s.plantuml.com/package-private-method.png>    | package private |
    |  <img:http://s.plantuml.com/public-field.png>     |   <img:http://s.plantuml.com/public-method.png>     | public |
    
    endlegend
    @enduml
    

    Legend with icons