Search code examples
plantuml

PlantUML, how to add a FontColor for a column in entity


I have this my PlantUML file

@startuml
' avoid problems with angled crows feet
skinparam linetype ortho

skinparam class {
    FontColor<<generated>> #0000FF
}

entity "User" as users
{
  *id : uuid <<generated>>
  --
  *email : text <<unique>>
  password : text
}

entity "DishType" as dish_type {
  *id : uuid <<generated>>
  --
  *name : text <<unique>>
  image : text
}

entity "Dish" as dish {
  *id : uuid <<generated>>
  --
  *name : text <<unique>>
  image : text
  menu_price : float
  solo_price : float
  dish_type_id : uuid <<FK>>
}

entity "Ingredient" as ingredient {
  *id : uuid <<generated>>
  --
  *name : text <<unique>>
  available : bool
}

dish "Many" --- "One" dish_type
dish "Many" --- "Many" ingredient
@enduml

So... I want that some fields like <<unique>> or <<generated>>, <<fk>> must be red, or yellow, whatever the color. I search like skinparam class but it works only with entity all fields, not only one field.

Can you help please. Thanks you :)


Solution

  • I don't think it's possible with skinparam since stereotypes don't apply to attributes. However, maybe the new stylesheets function will support something like this.

    You could use a !function like the result below. It's not perfect, but might suit your needs. You could also do the same for the <<unique>> and other attributes.

    @startuml
    !function $generated($a)
    !return "<color:#0000ff>" + $a + " <<generated>></color>"
    !endfunction
    
    ' avoid problems with angled crows feet
    skinparam linetype ortho
    
    entity "User" as users
    {
      *$generated("id : uuid")
      --
      *email : text <<unique>>
      password : text
    }
    
    entity "DishType" as dish_type {
      *$generated("id : uuid")
      --
      *name : text <<unique>>
      image : text
    }
    
    entity "Dish" as dish {
      *$generated("id : uuid")
      --
      *name : text <<unique>>
      image : text
      menu_price : float
      solo_price : float
      dish_type_id : uuid <<FK>>
    }
    
    entity "Ingredient" as ingredient {
      *$generated("id : uuid")
      --
      *name : text <<unique>>
      available : bool
    }
    
    dish "Many" --- "One" dish_type
    dish "Many" --- "Many" ingredient
    @enduml
    

    enter image description here