Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-wrap, inline config, initialization, dark theme tweaks, etc #1458

Merged
merged 8 commits into from
Jun 14, 2020
Next Next commit
Added auto wrap option (and grammar) for sequenceDiagrams
Added inline config and init(ialization) grammar
Added reinitialize functionality to mermaidAPI (not to be confused with initialize)
Added actorFontWeight, noteFontWeight, messageFontWeight, wrapEnabled, wrapPadding
Added wrapLabel and breakWord functions to intelligently wrap text based on a pixel-based width instead of column-based
  - The implementation is largely from Carys Mills: https://medium.com/@CarysMills/wrapping-svg-text-without-svg-2-ecbfb58f7ba4
  - Made slight modifications for mermaid-js
Fixed dark theme color inconsistencies for sequence diagrams
Removed !important from sequence scss as this prevents any client overrides
Fixed various invalid css values in sequence scss which prevented proper rendering of various elements
Added detectInit to utils for initialization json detection
Updated detectType to support the existence or absence of the intialization configuration
Updated calculateTextWidth to include fontWeight
  • Loading branch information
chrismoran-bkt committed Jun 8, 2020
commit bd11663e0a19fcc4a2e4104405ec4fddb2dff98f
743 changes: 410 additions & 333 deletions dist/mermaid.core.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/mermaid.core.js.map

Large diffs are not rendered by default.

749 changes: 413 additions & 336 deletions dist/mermaid.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/mermaid.js.map

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions dist/mermaid.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/mermaid.min.js.map

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions docs/mermaidAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ This sets the font size of the actor's description
This sets the font family of the actor's description
**Default value "Open-Sans", "sans-serif"**.

### actorFontWeight

This sets the font weight of the actor's description
\*\*Default value 400.

### noteFontSize

This sets the font size of actor-attached notes.
Expand All @@ -229,6 +234,11 @@ This sets the font size of actor-attached notes.
This sets the font family of actor-attached notes.
**Default value "trebuchet ms", verdana, arial**.

### noteFontWeight

This sets the font weight of the note's description
\*\*Default value 400.

### noteAlign

This sets the text alignment of actor-attached notes.
Expand All @@ -244,6 +254,21 @@ This sets the font size of actor messages.
This sets the font family of actor messages.
**Default value "trebuchet ms", verdana, arial**.

### messageFontWeight

This sets the font weight of the message's description
\*\*Default value 400.

### wrapEnabled

This sets the auto-wrap state for the diagram
\*\*Default value false.

### wrapPadding

This sets the auto-wrap padding for the diagram (sides only)
\*\*Default value 15.

## gantt

The object containing configurations specific for gantt diagrams\*
Expand Down
16 changes: 15 additions & 1 deletion src/diagrams/sequence/parser/sequenceDiagram.jison
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@
"title" return 'title';
"sequenceDiagram" return 'SD';
"autonumber" return 'autonumber';
"init" return 'INIT';
"initialize" return 'INIT';
"conf" return 'conf';
"config" return 'conf';
"configure" return 'conf';
"configuration" return 'conf';
"wrap" return 'wrap';
"nowrap" return 'nowrap';
"," return ',';
";" return 'NL';
[^\+\->:\n,;]+ { yytext = yytext.trim(); return 'ACTOR'; }
Expand All @@ -74,6 +82,7 @@
start
: SPACE start
| NL start
| INIT text3 start
| SD document { yy.apply($2);return $2; }
;

Expand All @@ -85,17 +94,20 @@ document
line
: SPACE statement { $$ = $2 }
| statement { $$ = $1 }
| NL { $$=[];}
| NL { $$=[]; }
;

statement
: 'participant' actor 'AS' restOfLine 'NL' {$2.description=$4; $$=$2;}
| 'participant' actor 'NL' {$$=$2;}
| signal 'NL'
| autonumber {yy.enableSequenceNumbers()}
| wrap {yy.enableWrap()}
| nowrap {yy.disableWrap()}
| 'activate' actor 'NL' {$$={type: 'activeStart', signalType: yy.LINETYPE.ACTIVE_START, actor: $2};}
| 'deactivate' actor 'NL' {$$={type: 'activeEnd', signalType: yy.LINETYPE.ACTIVE_END, actor: $2};}
| note_statement 'NL'
| conf text3 'NL' {$$=[{type:'config', config:$2}]}
| title text2 'NL' {$$=[{type:'setTitle', text:$2}]}
| 'loop' restOfLine document end
{
Expand Down Expand Up @@ -197,4 +209,6 @@ signaltype

text2: TXT {$$ = $1.substring(1).trim().replace(/\\n/gm, "\n");} ;

text3: TXT {$$ = JSON.parse($1.substring(1).trim().replace(/\\n/gm, "\n").replace(/'/gm, "\""));} ;

%%
25 changes: 25 additions & 0 deletions src/diagrams/sequence/sequenceDb.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { logger } from '../../logger';
import { getConfig, setConfig } from '../../config';

let prevActor = undefined;
let actors = {};
let messages = [];
const notes = [];
let title = '';
let sequenceNumbersEnabled = false;
let wrapEnabled = false;

export const addActor = function(id, name, description) {
// Don't allow description nulling
Expand Down Expand Up @@ -92,6 +94,16 @@ export const enableSequenceNumbers = function() {
};
export const showSequenceNumbers = () => sequenceNumbersEnabled;

export const enableWrap = function() {
wrapEnabled = true;
};

export const disableWrap = function() {
wrapEnabled = false;
};

export const autoWrap = () => wrapEnabled;

export const clear = function() {
actors = {};
messages = [];
Expand Down Expand Up @@ -213,6 +225,16 @@ export const apply = function(param) {
case 'parEnd':
addSignal(undefined, undefined, undefined, param.signalType);
break;
case 'config':
try {
let cfg = param.config;
let _config = getConfig();
let config = Object.assign(_config, cfg);
setConfig(config);
} catch (error) {
logger.error('Error: unable to parse config');
}
break;
}
}
};
Expand All @@ -221,8 +243,11 @@ export default {
addActor,
addMessage,
addSignal,
enableWrap,
disableWrap,
enableSequenceNumbers,
showSequenceNumbers,
autoWrap,
getMessages,
getActors,
getActor,
Expand Down
Loading