mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-28 07:03:17 +08:00
Merge branch 'develop' into bug/5059_fix_external_connection_after_updating_edges
This commit is contained in:
commit
f5ef0b600e
@ -571,4 +571,14 @@ class C13["With Città foreign language"]
|
|||||||
{ logLevel: 1, flowchart: { htmlLabels: false } }
|
{ logLevel: 1, flowchart: { htmlLabels: false } }
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
it('should render a simple class diagram with style definition', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`
|
||||||
|
classDiagram-v2
|
||||||
|
class Class10
|
||||||
|
style Class10 fill:#f9f,stroke:#333,stroke-width:4px
|
||||||
|
`,
|
||||||
|
{ logLevel: 1, flowchart: { htmlLabels: false } }
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -766,9 +766,30 @@ Beginner's tip—a full example using interactive links in an HTML page:
|
|||||||
|
|
||||||
## Styling
|
## Styling
|
||||||
|
|
||||||
### Styling a node
|
### Styling a node (v\<MERMAID_RELEASE_VERSION>+)
|
||||||
|
|
||||||
It is possible to apply specific styles such as a thicker border or a different background color to individual nodes. This is done by predefining classes in css styles that can be applied from the graph definition using the `cssClass` statement or the `:::` short hand.
|
It is possible to apply specific styles such as a thicker border or a different background color to an individual node using the `style` keyword.
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
classDiagram
|
||||||
|
class Animal
|
||||||
|
class Mineral
|
||||||
|
style Animal fill:#f9f,stroke:#333,stroke-width:4px
|
||||||
|
style Mineral fill:#bbf,stroke:#f66,stroke-width:2px,color:#fff,stroke-dasharray: 5 5
|
||||||
|
```
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
classDiagram
|
||||||
|
class Animal
|
||||||
|
class Mineral
|
||||||
|
style Animal fill:#f9f,stroke:#333,stroke-width:4px
|
||||||
|
style Mineral fill:#bbf,stroke:#f66,stroke-width:2px,color:#fff,stroke-dasharray: 5 5
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Classes
|
||||||
|
|
||||||
|
More convenient than defining the style every time is to define a class of styles and attach this class to the nodes that
|
||||||
|
should have a different look. This is done by predefining classes in css styles that can be applied from the graph definition using the `cssClass` statement or the `:::` short hand.
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<style>
|
<style>
|
||||||
|
@ -1013,6 +1013,7 @@ const class_box = (parent, node) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
rect
|
rect
|
||||||
|
.attr('style', node.style)
|
||||||
.attr('class', 'outer title-state')
|
.attr('class', 'outer title-state')
|
||||||
.attr('x', -maxWidth / 2 - halfPadding)
|
.attr('x', -maxWidth / 2 - halfPadding)
|
||||||
.attr('y', -(maxHeight / 2) - halfPadding)
|
.attr('y', -(maxHeight / 2) - halfPadding)
|
||||||
|
@ -84,6 +84,7 @@ export const addClass = function (_id: string) {
|
|||||||
methods: [],
|
methods: [],
|
||||||
members: [],
|
members: [],
|
||||||
annotations: [],
|
annotations: [],
|
||||||
|
styles: [],
|
||||||
domId: MERMAID_DOM_ID_PREFIX + name + '-' + classCounter,
|
domId: MERMAID_DOM_ID_PREFIX + name + '-' + classCounter,
|
||||||
} as ClassNode;
|
} as ClassNode;
|
||||||
|
|
||||||
@ -214,7 +215,7 @@ export const cleanupLabel = function (label: string) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by parser when a special node is found, e.g. a clickable element.
|
* Called by parser when assigning cssClass to a class
|
||||||
*
|
*
|
||||||
* @param ids - Comma separated list of ids
|
* @param ids - Comma separated list of ids
|
||||||
* @param className - Class to add
|
* @param className - Class to add
|
||||||
@ -456,6 +457,20 @@ export const addClassesToNamespace = function (id: string, classNames: string[])
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const setCssStyle = function (id: string, styles: string[]) {
|
||||||
|
const thisClass = classes[id];
|
||||||
|
if (!styles || !thisClass) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (const s of styles) {
|
||||||
|
if (s.includes(',')) {
|
||||||
|
thisClass.styles.push(...s.split(','));
|
||||||
|
} else {
|
||||||
|
thisClass.styles.push(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
setAccTitle,
|
setAccTitle,
|
||||||
getAccTitle,
|
getAccTitle,
|
||||||
@ -492,4 +507,5 @@ export default {
|
|||||||
addClassesToNamespace,
|
addClassesToNamespace,
|
||||||
getNamespace,
|
getNamespace,
|
||||||
getNamespaces,
|
getNamespaces,
|
||||||
|
setCssStyle,
|
||||||
};
|
};
|
||||||
|
@ -56,5 +56,18 @@ describe('class diagram, ', function () {
|
|||||||
expect(parser.yy.getClass('Class01').cssClasses[0]).toBe('exClass');
|
expect(parser.yy.getClass('Class01').cssClasses[0]).toBe('exClass');
|
||||||
expect(parser.yy.getClass('Class02').cssClasses[0]).toBe('exClass');
|
expect(parser.yy.getClass('Class02').cssClasses[0]).toBe('exClass');
|
||||||
});
|
});
|
||||||
|
it('should be possible to apply a style to an individual node', function () {
|
||||||
|
const str =
|
||||||
|
'classDiagram\n' +
|
||||||
|
'class Class01\n class Class02\n style Class01 fill:#f9f,stroke:#333,stroke-width:4px';
|
||||||
|
|
||||||
|
parser.parse(str);
|
||||||
|
|
||||||
|
const styleElements = parser.yy.getClass('Class01').styles;
|
||||||
|
|
||||||
|
expect(styleElements[0]).toBe('fill:#f9f');
|
||||||
|
expect(styleElements[1]).toBe('stroke:#333');
|
||||||
|
expect(styleElements[2]).toBe('stroke-width:4px');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -409,6 +409,7 @@ class C13["With Città foreign language"]
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
"methods": [],
|
"methods": [],
|
||||||
|
"styles": [],
|
||||||
"type": "",
|
"type": "",
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
|
@ -104,7 +104,7 @@ export const addClasses = function (
|
|||||||
*/
|
*/
|
||||||
const cssClassStr = vertex.cssClasses.join(' ');
|
const cssClassStr = vertex.cssClasses.join(' ');
|
||||||
|
|
||||||
const styles = { labelStyle: '', style: '' }; //getStylesFromArray(vertex.styles);
|
const styles = getStylesFromArray(vertex.styles);
|
||||||
|
|
||||||
// Use vertex id as text in the box if no text is provided by the graph definition
|
// Use vertex id as text in the box if no text is provided by the graph definition
|
||||||
const vertexText = vertex.label ?? vertex.id;
|
const vertexText = vertex.label ?? vertex.id;
|
||||||
|
@ -10,6 +10,7 @@ export interface ClassNode {
|
|||||||
members: ClassMember[];
|
members: ClassMember[];
|
||||||
annotations: string[];
|
annotations: string[];
|
||||||
domId: string;
|
domId: string;
|
||||||
|
styles: string[];
|
||||||
parent?: string;
|
parent?: string;
|
||||||
link?: string;
|
link?: string;
|
||||||
linkTarget?: string;
|
linkTarget?: string;
|
||||||
|
@ -60,6 +60,7 @@ Function arguments are optional: 'call <callback_name>()' simply executes 'callb
|
|||||||
<string>["] this.popState();
|
<string>["] this.popState();
|
||||||
<string>[^"]* return "STR";
|
<string>[^"]* return "STR";
|
||||||
<*>["] this.begin("string");
|
<*>["] this.begin("string");
|
||||||
|
"style" return 'STYLE';
|
||||||
|
|
||||||
<INITIAL,namespace>"namespace" { this.begin('namespace'); return 'NAMESPACE'; }
|
<INITIAL,namespace>"namespace" { this.begin('namespace'); return 'NAMESPACE'; }
|
||||||
<namespace>\s*(\r?\n)+ { this.popState(); return 'NEWLINE'; }
|
<namespace>\s*(\r?\n)+ { this.popState(); return 'NEWLINE'; }
|
||||||
@ -127,6 +128,10 @@ line was introduced with 'click'.
|
|||||||
<*>\- return 'MINUS';
|
<*>\- return 'MINUS';
|
||||||
<*>"." return 'DOT';
|
<*>"." return 'DOT';
|
||||||
<*>\+ return 'PLUS';
|
<*>\+ return 'PLUS';
|
||||||
|
":" return 'COLON';
|
||||||
|
"," return 'COMMA';
|
||||||
|
\# return 'BRKT';
|
||||||
|
"#" return 'BRKT';
|
||||||
<*>\% return 'PCT';
|
<*>\% return 'PCT';
|
||||||
<*>"=" return 'EQUALS';
|
<*>"=" return 'EQUALS';
|
||||||
<*>\= return 'EQUALS';
|
<*>\= return 'EQUALS';
|
||||||
@ -198,6 +203,7 @@ line was introduced with 'click'.
|
|||||||
[\uFFD2-\uFFD7\uFFDA-\uFFDC]
|
[\uFFD2-\uFFD7\uFFDA-\uFFDC]
|
||||||
return 'UNICODE_TEXT';
|
return 'UNICODE_TEXT';
|
||||||
<*>\s return 'SPACE';
|
<*>\s return 'SPACE';
|
||||||
|
\s return 'SPACE';
|
||||||
<*><<EOF>> return 'EOF';
|
<*><<EOF>> return 'EOF';
|
||||||
|
|
||||||
/lex
|
/lex
|
||||||
@ -254,6 +260,7 @@ statement
|
|||||||
| memberStatement
|
| memberStatement
|
||||||
| annotationStatement
|
| annotationStatement
|
||||||
| clickStatement
|
| clickStatement
|
||||||
|
| styleStatement
|
||||||
| cssClassStatement
|
| cssClassStatement
|
||||||
| noteStatement
|
| noteStatement
|
||||||
| direction
|
| direction
|
||||||
@ -365,10 +372,26 @@ clickStatement
|
|||||||
| CLICK className HREF STR STR LINK_TARGET {$$ = $1;yy.setLink($2, $4, $6);yy.setTooltip($2, $5);}
|
| CLICK className HREF STR STR LINK_TARGET {$$ = $1;yy.setLink($2, $4, $6);yy.setTooltip($2, $5);}
|
||||||
;
|
;
|
||||||
|
|
||||||
cssClassStatement
|
styleStatement
|
||||||
: CSSCLASS STR alphaNumToken {yy.setCssClass($2, $3);}
|
:STYLE ALPHA stylesOpt {$$ = $STYLE;yy.setCssStyle($2,$stylesOpt);}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
cssClassStatement
|
||||||
|
: CSSCLASS STR ALPHA {yy.setCssClass($2, $3);}
|
||||||
|
;
|
||||||
|
|
||||||
|
stylesOpt
|
||||||
|
: style {$$ = [$style]}
|
||||||
|
| stylesOpt COMMA style {$stylesOpt.push($style);$$ = $stylesOpt;}
|
||||||
|
;
|
||||||
|
|
||||||
|
style
|
||||||
|
: styleComponent
|
||||||
|
| style styleComponent {$$ = $style + $styleComponent;}
|
||||||
|
;
|
||||||
|
|
||||||
|
styleComponent: ALPHA | NUM | COLON | UNIT | SPACE | BRKT | STYLE | PCT | LABEL;
|
||||||
|
|
||||||
commentToken : textToken | graphCodeTokens ;
|
commentToken : textToken | graphCodeTokens ;
|
||||||
|
|
||||||
textToken : textNoTagsToken | TAGSTART | TAGEND | '==' | '--' | PCT | DEFAULT;
|
textToken : textNoTagsToken | TAGSTART | TAGEND | '==' | '--' | PCT | DEFAULT;
|
||||||
|
@ -518,9 +518,22 @@ Beginner's tip—a full example using interactive links in an HTML page:
|
|||||||
|
|
||||||
## Styling
|
## Styling
|
||||||
|
|
||||||
### Styling a node
|
### Styling a node (v<MERMAID_RELEASE_VERSION>+)
|
||||||
|
|
||||||
It is possible to apply specific styles such as a thicker border or a different background color to individual nodes. This is done by predefining classes in css styles that can be applied from the graph definition using the `cssClass` statement or the `:::` short hand.
|
It is possible to apply specific styles such as a thicker border or a different background color to an individual node using the `style` keyword.
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
classDiagram
|
||||||
|
class Animal
|
||||||
|
class Mineral
|
||||||
|
style Animal fill:#f9f,stroke:#333,stroke-width:4px
|
||||||
|
style Mineral fill:#bbf,stroke:#f66,stroke-width:2px,color:#fff,stroke-dasharray: 5 5
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Classes
|
||||||
|
|
||||||
|
More convenient than defining the style every time is to define a class of styles and attach this class to the nodes that
|
||||||
|
should have a different look. This is done by predefining classes in css styles that can be applied from the graph definition using the `cssClass` statement or the `:::` short hand.
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<style>
|
<style>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user