mermaid/docs/8.6.0_docs.md

5.7 KiB
Raw Blame History

Version 8.6.0 Changes

Edit this Page N|Solid

New Mermaid Live-Editor Beta

CDN

With version 8.6.0 comes the release of directives for mermaid and a new system for configurations, with the aim of establishing centralized, sane defaults and simple implementation.

the init directive is the main method of configuration for Site and Current Levels.

The three levels of are Configuration, Global, Site and Current.

Level of Configuration Description
Global Configuration Default Mermaid Configurations
Site Configuration Configurations made by site owner
Current Configuration Configurations made by Implementors

Limits to Modifying Configurations

secure Array

Parameter Description Type Required Values
secure Array of parameters excluded from init directive Array Required Any parameters

The modifiable parts of the Configuration are limited by the secure array, which is an array of immutable parameters, this array can be expanded by site owners.

Notes: secure arrays work like nesting dolls, with the Global Configurations secure array being the default and immutable list of immutable parameters, or the smallest doll, to which site owners may add to, but implementors may not modify it.

Secure Arrays

Site owners can add to the secure array using this command: mermaidAPI.initialize( { startOnLoad: true, secure: ['parameter1', 'parameter2'] } );

default values for the secure array consists of: ['secure', 'securityLevel', 'startOnLoad', 'maxTextSize']. These default values are immutable.

Implementors can only modify configurations using directives, but cannot change the secure array.

Modifying Configurations and directives:

The Two types of directives: are “init” or “initialize” and “wrap”.

Notes: All directives are enclosed in %%{ }%%.

Older versions of mermaid will not parse directives because %% will comment out the directive.

Init

init, or initialize: the init or initialize directive gives the user the ability to overwrite and change the values for configuration parameters, with respect to the secure array that is in effect.

Parameter Description Type Required Values
init modifies configurations Directive Optional Any parameters not included in the secure array

Notes:

init would be an argument-directive: %%{init: { insert argument here}}%%

The json object that is passed as {argument } must be valid, quoted json or it will be ignored. for example:

%%{init: {"theme": default, "logLevel": 1 }}%%

Configurations that are passed through init cannot change the parameters in secure arrays of higher levels. In the event of a conflict, mermaid will give priority to secure arrays and parse the request, without changing the values of the parameters in conflict.

When deployed within code, init is called before the graph/diagram description. for example: %%{init: {"theme": "default", "logLevel": 1 }}%% graph LR a-->b b-->c c-->d d-->e e-->f f-->g g-->

Wrap

Parameter Description Type Required Values
wrap a callable text-wrap function Directive Optional %%{wrap}%%

Notes:

Wrap is a function that is currently only deployable for sequence diagrams.

wrap respects manually added <br> so if the user wants to break up their text, they have full control over those breaks by adding their own <br> tags.

It is a non-argument directive and can be executed thusly:

%%{wrap}%%.

an example of text wrapping in a sequence diagram:

Image showing wrapped text

Resetting Configurations:

There are two more functions in the mermaidAPI that can be called by site owners: reset and globalReset.

reset: resets the configuration to whatever the last configuration was. This can be done to undo more recent changes to the last mermaidAPI.initialize({...}) configuration.

globalReset will reset both the current configuration AND the site configuration back to the global defaults.

Notes: both reset and globalReset are only available to site owners, as such implementors would have to edit their configs with init.

Additional Utils to mermaid

memoize: simple caching for computationally expensive functions. It reduces the rendering time for computationally intensive diagrams by about 90%.

assignWithDepth - this is an improvement on previous functions with config.js and Object.assign. The purpose of this function is to provide a sane mechanism for merging objects, similar to object.assign, but with depth.

Example of assignWithDepth:

Image showing assignWithDepth

Example of object.Assign:

Image showing object.assign without depth

calculateTextDimensions, calculateTextWidth, and calculateTextHeight - for measuring text dimensions, width and height.

Notes:For more information on usage, parameters, and return info for these new functions take a look at the jsdocs for them in the utils package.