mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
added grammar
This commit is contained in:
parent
96735dd543
commit
912e850db4
@ -98,6 +98,7 @@ Class01 : size()
|
|||||||
Class01 : int chimp
|
Class01 : int chimp
|
||||||
Class01 : int gorilla
|
Class01 : int gorilla
|
||||||
Class08 <--> C2: Cool label
|
Class08 <--> C2: Cool label
|
||||||
|
<<interface>> Class01
|
||||||
```
|
```
|
||||||
![Class diagram](./img/class.png)
|
![Class diagram](./img/class.png)
|
||||||
|
|
||||||
|
1
dist/index.html
vendored
1
dist/index.html
vendored
@ -411,6 +411,7 @@ Class01 : size()
|
|||||||
Class01 : int chimp
|
Class01 : int chimp
|
||||||
Class01 : int gorilla
|
Class01 : int gorilla
|
||||||
Class08 <--> C2: Cool label
|
Class08 <--> C2: Cool label
|
||||||
|
<<interface>> Class01
|
||||||
</div>
|
</div>
|
||||||
<script src="./mermaid.js"></script>
|
<script src="./mermaid.js"></script>
|
||||||
<script>
|
<script>
|
||||||
|
@ -44,6 +44,10 @@ export const addRelation = function(relation) {
|
|||||||
relations.push(relation);
|
relations.push(relation);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const addAnnotation = function(className, annotation) {
|
||||||
|
classes[className].annotations.push(annotation);
|
||||||
|
};
|
||||||
|
|
||||||
export const addMember = function(className, member) {
|
export const addMember = function(className, member) {
|
||||||
const theClass = classes[className];
|
const theClass = classes[className];
|
||||||
if (typeof member === 'string') {
|
if (typeof member === 'string') {
|
||||||
@ -86,6 +90,7 @@ export default {
|
|||||||
clear,
|
clear,
|
||||||
getClass,
|
getClass,
|
||||||
getClasses,
|
getClasses,
|
||||||
|
addAnnotation,
|
||||||
getRelations,
|
getRelations,
|
||||||
addRelation,
|
addRelation,
|
||||||
addMember,
|
addMember,
|
||||||
|
@ -264,9 +264,6 @@ const drawClass = function(elem, classDef) {
|
|||||||
.attr('y', conf.textHeight + conf.padding)
|
.attr('y', conf.textHeight + conf.padding)
|
||||||
.attr('x', 0);
|
.attr('x', 0);
|
||||||
|
|
||||||
// TODO: remove testing code
|
|
||||||
classDef.annotations = ['interface', 'injected'];
|
|
||||||
|
|
||||||
// add annotations
|
// add annotations
|
||||||
let isFirst = true;
|
let isFirst = true;
|
||||||
classDef.annotations.forEach(function(member) {
|
classDef.annotations.forEach(function(member) {
|
||||||
@ -276,11 +273,12 @@ const drawClass = function(elem, classDef) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// add class title
|
// add class title
|
||||||
title
|
const classTitle = title
|
||||||
.append('tspan')
|
.append('tspan')
|
||||||
.text(classDef.id)
|
.text(classDef.id)
|
||||||
.attr('class', 'title')
|
.attr('class', 'title');
|
||||||
.attr('dy', conf.textHeight);
|
|
||||||
|
if (!isFirst) classTitle.attr('dy', conf.textHeight);
|
||||||
|
|
||||||
const titleHeight = title.node().getBBox().height;
|
const titleHeight = title.node().getBBox().height;
|
||||||
|
|
||||||
@ -334,7 +332,6 @@ const drawClass = function(elem, classDef) {
|
|||||||
|
|
||||||
// Center title
|
// Center title
|
||||||
title.node().childNodes.forEach(function(x) {
|
title.node().childNodes.forEach(function(x) {
|
||||||
console.dir(x.getBBox());
|
|
||||||
x.setAttribute('x', (classBox.width + 2 * conf.padding - x.getBBox().width) / 2);
|
x.setAttribute('x', (classBox.width + 2 * conf.padding - x.getBBox().width) / 2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
|
|
||||||
"class" return 'CLASS';
|
"class" return 'CLASS';
|
||||||
|
"<<" return 'ANNOTATION_START';
|
||||||
|
">>" return 'ANNOTATION_END';
|
||||||
["] this.begin("string");
|
["] this.begin("string");
|
||||||
<string>["] this.popState();
|
<string>["] this.popState();
|
||||||
<string>[^"]* return "STR";
|
<string>[^"]* return "STR";
|
||||||
@ -131,7 +133,6 @@ statements
|
|||||||
| statement NEWLINE statements
|
| statement NEWLINE statements
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
className
|
className
|
||||||
: alphaNumToken className { $$=$1+$2; }
|
: alphaNumToken className { $$=$1+$2; }
|
||||||
| alphaNumToken { $$=$1; }
|
| alphaNumToken { $$=$1; }
|
||||||
@ -142,6 +143,7 @@ statement
|
|||||||
| relationStatement LABEL { $1.title = yy.cleanupLabel($2); yy.addRelation($1); }
|
| relationStatement LABEL { $1.title = yy.cleanupLabel($2); yy.addRelation($1); }
|
||||||
| classStatement
|
| classStatement
|
||||||
| methodStatement
|
| methodStatement
|
||||||
|
| annotationStatement
|
||||||
;
|
;
|
||||||
|
|
||||||
classStatement
|
classStatement
|
||||||
@ -149,6 +151,10 @@ classStatement
|
|||||||
| CLASS className STRUCT_START members STRUCT_STOP {/*console.log($2,JSON.stringify($4));*/yy.addClass($2);yy.addMembers($2,$4);}
|
| CLASS className STRUCT_START members STRUCT_STOP {/*console.log($2,JSON.stringify($4));*/yy.addClass($2);yy.addMembers($2,$4);}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
annotationStatement
|
||||||
|
: ANNOTATION_START alphaNumToken ANNOTATION_END className { yy.addAnnotation($4,$2); }
|
||||||
|
;
|
||||||
|
|
||||||
members
|
members
|
||||||
: MEMBER { $$ = [$1]; }
|
: MEMBER { $$ = [$1]; }
|
||||||
| MEMBER members { $2.push($1);$$=$2;}
|
| MEMBER members { $2.push($1);$$=$2;}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user