Skip to content

Instantly share code, notes, and snippets.

@masnick
Forked from jerieljan/How I Do PlantUML.md
Created November 25, 2020 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masnick/53672666516ec67fd0ba7190a60c391a to your computer and use it in GitHub Desktop.
Save masnick/53672666516ec67fd0ba7190a60c391a to your computer and use it in GitHub Desktop.
PlantUML with Style -- How I do PlantUML
# Sequence Diagram Example
@startuml
'General Defaults
!define BASEPATH ..
!include BASEPATH/globals/stylesheet.iuml
'Actor Definitions
autonumber 1 "0:"
title Sequence Diagram
A -> B: Perform Action
B --> A: (Response)
@enduml

I use PlantUML a lot. It's what I use for drawing all sorts of diagrams and it's handy because of its easy markup (once you get used to it) while making things easy to maintain as projects grow (thanks to version control)

This gist explains how I do my PlantUML workspace in a project.

  • The idea is to keep a globals directory for all diagrams to follow (like the "stylesheet" below) to keep things consistent.
  • I use a stylesheet.iuml file that keeps the use of colors consistent through use of basic FOREGROUND, BACKGROUND and ACCENT colors.
  • The style-presets.iuml file defines these colors so you can make "presets" or "themes" out of them.
  • As stated in the stylesheet.iuml, you'll need the Roboto Condensed and Inconsolata fonts for these to work properly.
  • You can choose to either run the PlantUML jar over your file/s, or use an IDE like VSCode with the PlantUML extension. Here's a preview of example-sequence.puml for example: https://imgur.com/Klk3w2F

Assume the following directory structure:

$ tree
.
├── globals
│   ├── style-presets.iuml
│   └── stylesheet.iuml
└── diagrams
    ├── example-sequence.puml
    ├── etc...

Changelog

2020-01-27:

  • Added a preview of how it looks like when it's exported / viewed with PlantUML: https://imgur.com/Klk3w2F
  • Added a quick tip to use an IDE or the PlantUML jar to get this to work.
  • Corrected the filename - example-sequence.puml. It was .iuml before. The extensions don't really matter from what I can tell though.
  • Added this changelog.
# Style Presets
@startuml
' Preset Styles by Jeriel Jan
' Preset: Monochrome
!define STYLE_DEFAULT_ACCENT #000
!define STYLE_DEFAULT_BGC #FFF
!define STYLE_DEFAULT_FGC #000
' Preset: Material Light Blue (200)
!define STYLE_LIGHT_ACCENT #81D4FA
!define STYLE_LIGHT_BGC #FFF
!define STYLE_LIGHT_FGC #000
' Preset: Material Light Blue (800)
!define STYLE_DARK_ACCENT #0277BD
!define STYLE_DARK_BGC #FFF
!define STYLE_DARK_FGC #000
' Preset: Material Light Blue (800)
!define STYLE_MIDNIGHT_ACCENT #0277BD
!define STYLE_MIDNIGHT_BGC #000
!define STYLE_MIDNIGHT_FGC #FFF
skinparam {
' This field left intentionally blank.
}
@enduml
# Project Stylesheet
@startuml
' Load preset styles.
!define STYLEPATH .
!include STYLEPATH/style-presets.iuml
' Color Definition
' Choose the style you want by applying them here.
!define STYLE_ACCENT STYLE_DEFAULT_FGC
!define STYLE_BGC STYLE_DEFAULT_BGC
!define STYLE_FGC STYLE_DEFAULT_FGC
' RECOMMENDED STYLE
' -=- DO NOT EDIT THIS SECTION. -=-
' See Custom Style section below to override items here.
skinparam {
' Global Options
DPI 200
Shadowing false
DefaultFontName Roboto Condensed
DefaultMonospacedFontName Inconsolata
DefaultFontColor STYLE_FGC
' Styles - Borders
ArrowColor STYLE_ACCENT
ActivityBorderColor STYLE_ACCENT
ActivityDiamondBorderColor STYLE_ACCENT
ActorBorderColor STYLE_ACCENT
AgentBorderColor STYLE_ACCENT
ArtifactBorderColor STYLE_ACCENT
BoundaryBorderColor STYLE_ACCENT
ClassBorderColor STYLE_ACCENT
CloudBorderColor STYLE_ACCENT
CollectionsBorderColor STYLE_ACCENT
ComponentBorderColor STYLE_ACCENT
ControlBorderColor STYLE_ACCENT
DatabaseBorderColor STYLE_ACCENT
EntityBorderColor STYLE_ACCENT
FileBorderColor STYLE_ACCENT
FolderBorderColor STYLE_ACCENT
FrameBorderColor STYLE_ACCENT
InterfaceBorderColor STYLE_ACCENT
LegendBorderColor STYLE_ACCENT
NodeBorderColor STYLE_ACCENT
NoteBorderColor STYLE_ACCENT
ObjectBorderColor STYLE_ACCENT
PackageBorderColor STYLE_ACCENT
ParticipantBorderColor STYLE_ACCENT
PartitionBorderColor STYLE_ACCENT
QueueBorderColor STYLE_ACCENT
RectangleBorderColor STYLE_ACCENT
SequenceBoxBorderColor STYLE_ACCENT
SequenceDividerBorderColor STYLE_ACCENT
SequenceGroupBorderColor STYLE_ACCENT
SequenceLifeLineBorderColor STYLE_ACCENT
SequenceReferenceBorderColor STYLE_ACCENT
StackBorderColor STYLE_ACCENT
StateBorderColor STYLE_ACCENT
StorageBorderColor STYLE_ACCENT
SwimlaneBorderColor STYLE_ACCENT
UsecaseBorderColor STYLE_ACCENT
' Styles - Backgrounds
ActivityBackgroundColor STYLE_BGC
ActivityDiamondBackgroundColor STYLE_BGC
ActorBackgroundColor STYLE_BGC
AgentBackgroundColor STYLE_BGC
ArtifactBackgroundColor STYLE_BGC
BackgroundColor STYLE_BGC
BoundaryBackgroundColor STYLE_BGC
ClassBackgroundColor STYLE_BGC
ClassHeaderBackgroundColor STYLE_BGC
CloudBackgroundColor STYLE_BGC
CollectionsBackgroundColor STYLE_BGC
ComponentBackgroundColor STYLE_BGC
ControlBackgroundColor STYLE_BGC
DatabaseBackgroundColor STYLE_BGC
EntityBackgroundColor STYLE_BGC
FileBackgroundColor STYLE_BGC
FolderBackgroundColor STYLE_BGC
FrameBackgroundColor STYLE_BGC
IconPackageBackgroundColor STYLE_BGC
IconPrivateBackgroundColor STYLE_BGC
IconProtectedBackgroundColor STYLE_BGC
IconPublicBackgroundColor STYLE_BGC
InterfaceBackgroundColor STYLE_BGC
LegendBackgroundColor STYLE_BGC
NodeBackgroundColor STYLE_BGC
NoteBackgroundColor STYLE_BGC
ObjectBackgroundColor STYLE_BGC
PackageBackgroundColor STYLE_BGC
ParticipantBackgroundColor STYLE_BGC
PartitionBackgroundColor STYLE_BGC
QueueBackgroundColor STYLE_BGC
RectangleBackgroundColor STYLE_BGC
SequenceBoxBackgroundColor STYLE_BGC
SequenceDividerBackgroundColor STYLE_BGC
SequenceGroupBackgroundColor STYLE_BGC
SequenceGroupBodyBackgroundColor STYLE_BGC
SequenceLifeLineBackgroundColor STYLE_BGC
SequenceReferenceBackgroundColor STYLE_BGC
SequenceReferenceHeaderBackgroundColor STYLE_BGC
StackBackgroundColor STYLE_BGC
StateBackgroundColor STYLE_BGC
StereotypeABackgroundColor STYLE_BGC
StereotypeCBackgroundColor STYLE_BGC
StereotypeEBackgroundColor STYLE_BGC
StereotypeIBackgroundColor STYLE_BGC
StereotypeNBackgroundColor STYLE_BGC
StorageBackgroundColor STYLE_BGC
TitleBackgroundColor STYLE_BGC
UsecaseBackgroundColor STYLE_BGC
' -=- END OF RECOMMENDED STYLE -=-
' Other Settings
' These settings are included in the language specs, but
' it's not recommended to be applied.
'TitleBorderColor STYLE_ACCENT
'DiagramBorderColor STYLE_ACCENT
' CUSTOM STYLE
' All items below can be safely commented out.
' This will override the options listed above.
roundcorner 8
'Monochrome true
NoteFontName Roboto Condensed
NoteFontStyle Italic
'NoteBackgroundColor STYLE_BGC
}
@enduml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment