Define color for class objects - how to define different colors?

0 votes
asked Feb 3, 2017 in To be sorted by PlantMaster (160 points)
edited Feb 3, 2017 by PlantMaster

Hello,

I like to define different background colors for the classes of a diagram.

Here is an example:

@startuml
namespace ColorTest {
 
show members
hide circle
left to right direction
 
class Usage {
              Value 1
              Value 2
              Value 3
              Value 4
              Value 5
              Value 6
              ...
         
              == Implementation Proposal ==
              Exists already in ...
       }
 
       class Package {
              + PackageName
              - Flag
              Product Version
              == Implementation Proposal ==
              Data
       }
 
       Usage "0..*" -- "0..*" Package : < contains
       (Usage, Package) .. LinkPackageToUsage
}
@enduml
 

The class Usage shall have a different background color as the class Package.

Color Test for different class objcts
 

 

Greetings,
PlantMaster

1 Answer

+1 vote
answered Feb 3, 2017 by agillesp (600 points)
selected Feb 3, 2017 by PlantMaster
 
Best answer

If you're just looking to change the background colour then the simple way would be to change the first line of the class definitions to include the colour, for example change:

        class Usage {
          :
        }

        class Package {
          :
        }

to something like:

        class Usage #red {
          :
        }

        class Package #green {
          :
        }

PlantUML supports a large number of colours by name, and these are well documented on this site. Or you can specify the colour by hex RGB value instead.
 
If you want something more comprehensive that can arbitrarily categorise classes and control a number of attributes according to category, then take a look at stereotypes. But that may be overkill for the requirement you have stated.
commented Feb 3, 2017 by PlantMaster (160 points)
Thanks! This works fine and good enough for my needs. I tryed much too complex Syntax ;-)
...