How to style types in PlantUML class diagram?

670 Views Asked by At

In PlantUML you can style all classes like this:

@startuml

<style>
  classDiagram {
    class {
      FontColor blue
      BackgroundColor yellow
      header {
        FontSize 20
        FontColor violet
        FontStyle bold
      }
    }
  }
</style>

abstract        abstract
abstract class  "abstract class"
annotation      annotation
class           class
class           class_stereo  <<stereotype>>
entity          entity
enum            enum
exception       exception
interface       interface
metaclass       metaclass
protocol        protocol
stereotype      stereotype
struct          struct

@enduml

This applies to all "classes", meaning not only the class, but annotation, entity etc. as well.

Is there a way to style the "classes" individually, e.g. only adjust interface, but leave the other styles as they are?

1

There are 1 best solutions below

1
On BEST ANSWER

You can define and use custom styles like this:

@startuml

<style>
  classDiagram {
    class {
      .style1 {
        FontColor blue
        BackgroundColor yellow
        header {
          FontSize 20
          FontColor violet
          FontStyle bold
        }
      }
      .style2 {
        BackgroundColor lightblue
      }
    }
  }
</style>

hide <<style1>> stereotype
hide <<style2>> stereotype
' hide circle

class C0 {
}
interface C1 <<style1>> {
}
class C2 <<style2>> {
}

@enduml