Update theming.md

This commit is contained in:
Neil Cuzon
2020-07-31 20:49:35 -07:00
committed by GitHub
parent 52e688df9b
commit 5265bc20f1

View File

@@ -1,21 +1,23 @@
# Theming
# Version 8.7.0: Theming
**Edit this Page** [![N|Solid](./img/GitHub-Mark-32px.png)](https://github.com/mermaid-js/mermaid/blob/develop/docs/theming.md)
With Version 8.7.0 Mermaid comes out with a system for dynamic and integrated setting of the diagram's theme. The objective of this is to increase the customizability of mermaid, by allowing for the customization of themes through the `%%init%%` directive and `initialize`. With it a site integrator can override a vast majority of attributes used when rendering a diagram.
With Version 8.7.0 Mermaid comes out with a system for dynamic and integrated configuration of the diagram themes. The objective of this is to increase the customizability of mermaid and the ease of Styling, with the customization of themes through the `%%init%%` directive and `initialize` calls.
Themes, for all intents and purposes also follow the Levels of Configuration and employ `directives` to modify configurations, as they were introduced in Version [8.6.0](./8.6.0_docs.md).
Themes follow the Levels of Configuration and employ `directives` to modify configurations, as they were introduced in Version [8.6.0](./8.6.0_docs.md).
**These Theming Configurations, similar to directives, will also be made applicable in the Live-Editor, to maximize customizability.
## Site-wide Themes
Site-wide themes are still declared via `initialize` by site owners.
Example of `Initalize` call:
Example of `Initalize` call setting `theme` to `base`:
```
mermaidAPI.initialize({
'securityLevel': 'loose', 'theme': 'base'
});
```
**Notes**: Only site owners can use the `mermaidAPI.initialize` call to set values. Site-Users will have to use `%%init%%` to modify configurations, everytime they create a diagram.
**Notes**: Only site owners can use the `mermaidAPI.initialize` call, to set values. Site-Users will have to use `%%init%%` to modify or create the theme for their diagrams.
## Themes at the Local or Current Level
When Generating a diagram using on a webpage that supports mermaid. It is also possible to override site-wide theme settings locally, for a specific diagram, using directives, as long as it is not prohibited by the `secure` array.
@@ -57,23 +59,23 @@ The easiest way to make a custom theme is to start with the base theme, and just
| -------------- | ------------------------------------------------------------------ | ----- | -------- | ---------------------------------- |
| themeVariables | Array containing objects, modifiable with the `%%init%%` directive | Array | Required | primaryColor, lineColor, textColor |
**Notes**:
Leaving it empty will set the values to default
* primaryColor- the base color for the theme
* lineColor- the line color for the theme
* textColor-the text color for the theme
**Notes:
Leaving it empty will set all variable values to default.
The minimum required to create a custom rendering would be to change the primary color. If you are using a dark background, set dark mode to true as this will affect how colors are beeing calculated. It is possiebl to override the calculations using the variable names below.
Reference over theme variables used in the base theme and their effect:
You can create your own themes, by changing any of the given variables below. If you are using a dark background, set dark mode to true to make colors more visible. It is possible to override the calculations using the variable names below, with `%%init%%` if you wish to style it differently.
## Reference over Theme Variables that can be used with base theme and their effect:
**Notes: Variables that are unique to some diagrams can be affected by changes in Theme Variables.
| name | Default value | Calc | Description |
| -------------------- | ------------------------------ | ---- | -------------------------------------------------------------------------------------------------------------------------------- |
| darkMode | false | | Helps the theme to know how to calculate colors. |
| darkMode | false | | Boolean Value that dictates how to calculate colors. "true" will activate darkmode. |
| background | #f4f4f4 | | Used to calculate color for items that should either be background colored or contrasting to the background. |
| primaryColor | #fff4dd | | Color to be used as background in nodes, other colors will be derived from this |
| fontFamily | "trebuchet ms", verdana, arial | | |
| fontSize | 16px | | |
| fontSize | 16px | | Font Size, in pixels |
| secondaryColor | based on primaryColor | * | |
| tertiaryColor | based on primaryColor | * | |
| primaryBorderColor | based on primaryColor | * | Color to be used as border in nodes using primaryColor |
@@ -83,55 +85,59 @@ Reference over theme variables used in the base theme and their effect:
| tertiaryBorderColor | based on tertiaryColor | * | Color to be used as border in nodes using tertiaryColor |
| tertiaryTextColor | based on tertiaryColor | * | Color to be used as text color in nodesusing tertiaryColor |
| noteBkgColor | #fff5ad | | Color used as background in notes |
| noteTextColor | #333 | | Text color in note rects. |
| noteBorderColor | based on noteBkgColor | * | Border color in note rects. |
| noteTextColor | #333 | | Text color in note rectangless. |
| noteBorderColor | based on noteBkgColor | * | Border color in note rectangless. |
| lineColor | based on background | * | |
| textColor | based on primaryTextColor | * | Text in diagram over the background for instance text on labels and on signals in sequence diagram or the title in gantt diagram |
| mainBkg | based on primaryColor | * | Background in flowchart objects like rects/circles, class diagram classes, sequence diagram etc |
| errorBkgColor | tertiaryColor | * | Color for syntax error message |
| errorTextColor | tertiaryTextColor | * | Color for syntax error message |
# What follows are Variables, specific to different diagrams and charts.
## Some Theme Variables serve as, or affect the Default Values for Specific Diagram Variables, unless changed using `%%init%%` .
## Flowchart
| name | Default value | Calc | Description |
| Variable | Default/ Associated Value | Calc | Description |
| -------------------- | ------------------------------ | ---- | -------------------------------------------------------------------------------------------------------------------------------- |
| nodeBorder | primaryBorderColor | * | |
| nodeBorder | primaryBorderColor | * | Node Border Color |
| clusterBkg | tertiaryColor | * | Background in subgraphs |
| clusterBorder | tertiaryBorderColor | * | |
| defaultLinkColor | lineColor | * | |
| titleColor | tertiaryTextColor | * | |
| clusterBorder | tertiaryBorderColor | * | Cluster Border Color |
| defaultLinkColor | lineColor | * | Link Color |
| titleColor | tertiaryTextColor | * | Title Color |
| edgeLabelBackground | based on secondaryColor | * | |
| nodeTextColor | primaryTextColor | * | |
| nodeTextColor | primaryTextColor | * | Color for text inside Nodes. |
# sequence diagram
| name | Default value | Calc | Description |
| --------------------- | ----------------------- | ---- | ----------- |
| actorBorder | primaryBorderColor | * | |
| actorBkg | mainBkg | * | |
| actorTextColor | primaryTextColor | * | |
| actorLineColor | grey | * | |
| labelBoxBkgColor | actorBkg | * | |
| signalColor | textColor | * | |
| signalTextColor | textColor | * | |
| labelBoxBorderColor | actorBorder | * | |
| labelTextColor | actorTextColor | * | |
| loopTextColor | actorTextColor | * | |
| activationBorderColor | based on secondaryColor | * | |
| activationBkgColor | secondaryColor | * | |
| sequenceNumberColor | based on lineColor | * | |
| actorBorder | primaryBorderColor | * | Actor Border Color |
| actorBkg | mainBkg | * | Actor Background Color |
| actorTextColor | primaryTextColor | * | Actor Text Color |
| actorLineColor | grey | * | Actor Line Color |
| labelBoxBkgColor | actorBkg | * | Label Box Background Color |
| signalColor | textColor | * | Signal Color |
| signalTextColor | textColor | * | Signal Text Color |
| labelBoxBorderColor | actorBorder | * | Label Box Border Color |
| labelTextColor | actorTextColor | * | Label Text Color |
| loopTextColor | actorTextColor | * | Loop ext Color |
| activationBorderColor | based on secondaryColor | * | Activation Border Color |
| activationBkgColor | secondaryColor | * | Activation Background Color |
| sequenceNumberColor | based on lineColor | * | Sequence Number Color |
# state colors
| name | Default value | Calc | Description |
| ------------- | ---------------- | ---- | ------------------------------------------- |
| labelColor | primaryTextColor | * | |
| altBackground | tertiaryColor | * | Used for background in deep composit states |
| altBackground | tertiaryColor | * | Used for background in deep composite states |
# class colors
| name | Default value | Calc | Description |
| --------- | ------------- | ---- | ---------------------- |
| classText | textColor | * | Text in class diagrams |
| classText | textColor | * | Color of Text in class diagrams |
# User journey colors
@@ -146,13 +152,11 @@ Reference over theme variables used in the base theme and their effect:
| fillType6 | based on primaryColor | * | Fill for 7th section in journey diagram |
| fillType7 | based on secondaryColor | * | Fill for 8th section in journey diagram |
Variables derived from the ones above:
| name | Default value | Description |
**Notes: Values are meant to create an alternating look.
**Here is an example of overriding `primaryColor` and giving everything a different look, using `%%init%%`.
# Here is an example of overriding `primaryColor` and giving everything a different look, using `%%init%%`.
```
%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#ff0000'}}}%%
graph TD
@@ -171,12 +175,13 @@ Variables derived from the ones above:
end
```
Thsi got a bit to dark and bit to colorful. With some easy steps this can be fixed:
This got a bit too dark and bit too colorful. With some easy steps this can be fixed:
* Make the primary color a little lighter
* set the teriary color to a redish shade as well
* make the edge label background differ from the subgraph by setting the edgeLabelBackground
```
%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#ffcccc', 'edgeLabelBackground':'#ffffee', 'tertiaryColor': '#fff0f0'}}}%%
graph TD
@@ -194,7 +199,9 @@ Thsi got a bit to dark and bit to colorful. With some easy steps this can be fix
G
end
```
```mermaid
```
mermaid
%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#ffcccc', 'edgeLabelBackground':'#ffffee', 'tertiaryColor': '#fff0f0'}}}%%
graph TD
A[Christmas] -->|Get money| B(Go shopping)