mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
Merge branch 'develop' of github.com:mermaid-js/mermaid into develop
This commit is contained in:
commit
77541102af
@ -305,4 +305,52 @@ describe('Class diagram', () => {
|
||||
);
|
||||
cy.get('svg');
|
||||
});
|
||||
|
||||
it('13: should render a simple class diagram with css classes applied', () => {
|
||||
imgSnapshotTest(
|
||||
`
|
||||
classDiagram
|
||||
class Class10 {
|
||||
int[] id
|
||||
List~int~ ids
|
||||
test(List~int~ ids) List~bool~
|
||||
testArray() bool[]
|
||||
}
|
||||
|
||||
cssClass "Class10" exClass
|
||||
`,
|
||||
{}
|
||||
);
|
||||
cy.get('svg');
|
||||
});
|
||||
|
||||
it('14: should render a simple class diagram with css classes applied directly', () => {
|
||||
imgSnapshotTest(
|
||||
`
|
||||
classDiagram
|
||||
class Class10:::exClass {
|
||||
int[] id
|
||||
List~int~ ids
|
||||
test(List~int~ ids) List~bool~
|
||||
testArray() bool[]
|
||||
}
|
||||
`,
|
||||
{}
|
||||
);
|
||||
cy.get('svg');
|
||||
});
|
||||
|
||||
it('15: should render a simple class diagram with css classes applied two multiple classes', () => {
|
||||
imgSnapshotTest(
|
||||
`
|
||||
classDiagram
|
||||
class Class10
|
||||
class Class20
|
||||
|
||||
cssClass "Class10, class20" exClass
|
||||
`,
|
||||
{}
|
||||
);
|
||||
cy.get('svg');
|
||||
});
|
||||
});
|
||||
|
41
dist/info.html
vendored
41
dist/info.html
vendored
@ -1,41 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title>Mermaid Quick Test Page</title>
|
||||
<link rel="icon" type="image/png" href="data:image/png;base64,iVBORw0KGgo=">
|
||||
</head>
|
||||
<body>
|
||||
<div class="mermaid">info
|
||||
showInfo
|
||||
</div>
|
||||
<script src="./mermaid.js"></script>
|
||||
<script>
|
||||
mermaid.initialize({
|
||||
theme: 'forest',
|
||||
// themeCSS: '.node rect { fill: red; }',
|
||||
logLevel: 1,
|
||||
flowchart: { curve: 'linear' },
|
||||
gantt: { axisFormat: '%m/%d/%Y' },
|
||||
sequence: { actorMargin: 50 },
|
||||
// sequenceDiagram: { actorMargin: 300 } // deprecated
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
function ganttTestClick(a, b, c){
|
||||
console.log("a:", a)
|
||||
console.log("b:", b)
|
||||
console.log("c:", c)
|
||||
}
|
||||
function testClick(nodeId) {
|
||||
console.log("clicked", nodeId)
|
||||
var originalBgColor = document.querySelector('body').style.backgroundColor
|
||||
document.querySelector('body').style.backgroundColor = 'yellow'
|
||||
setTimeout(function() {
|
||||
document.querySelector('body').style.backgroundColor = originalBgColor
|
||||
}, 100)
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
25405
dist/mermaid.core.js
vendored
25405
dist/mermaid.core.js
vendored
File diff suppressed because one or more lines are too long
1
dist/mermaid.core.js.map
vendored
1
dist/mermaid.core.js.map
vendored
File diff suppressed because one or more lines are too long
73647
dist/mermaid.js
vendored
73647
dist/mermaid.js
vendored
File diff suppressed because one or more lines are too long
1
dist/mermaid.js.map
vendored
1
dist/mermaid.js.map
vendored
File diff suppressed because one or more lines are too long
32
dist/mermaid.min.js
vendored
32
dist/mermaid.min.js
vendored
File diff suppressed because one or more lines are too long
1
dist/mermaid.min.js.map
vendored
1
dist/mermaid.min.js.map
vendored
File diff suppressed because one or more lines are too long
202
dist/xssi.html
vendored
202
dist/xssi.html
vendored
@ -1,202 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title>Mermaid Quick Test Page</title>
|
||||
<link rel="icon" type="image/png" href="data:image/png;base64,iVBORw0KGgo=">
|
||||
<script>
|
||||
function xss(x){
|
||||
alert(x + ' cause an xss attack');
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
.label text { fill: red}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="mermaid">
|
||||
info
|
||||
</div>
|
||||
<div class="mermaid">
|
||||
graph LR;
|
||||
alert`xss`-->B;
|
||||
click B "javaSc
|
||||
ript:alert`salt`" "This is a tooltip for a link"
|
||||
</div>
|
||||
<div class="mermaid">
|
||||
graph LR;
|
||||
alert`xss`-->B;
|
||||
click B "java
|
||||
script:alert`xss`" "This is a tooltip for a link"
|
||||
</div>
|
||||
<div class="mermaid">
|
||||
graph LR;
|
||||
alert`base64`-->B;
|
||||
click B "data:image/png;base64,HNjcmlwdD5hbGVydCgiSGVsbG8iKTs8L3NjcmlwdD4="
|
||||
</div>
|
||||
<img src=xss.png />
|
||||
<div class="mermaid">
|
||||
graph TD
|
||||
A["<strong>If bold then xss</strong>Christmas"] -->|Get <strong>If bold then xss</strong> money| B(Go <strong>If bold then xss</strong> shopping)
|
||||
B --> C{Let me thinksssss<br/>ssssssssssssssssssssss<br />sssssssssssssssssssssssssss}
|
||||
C -->|One| D[Laptop]
|
||||
C -->|Two| E[iPhone]
|
||||
C -->|Three| F[Car]
|
||||
</div>
|
||||
<div class="mermaid">
|
||||
graph TB
|
||||
subgraph "<strong>If bold then xss</strong>"
|
||||
a1-->a2
|
||||
end
|
||||
</div>
|
||||
<div class="mermaid">
|
||||
graph TD
|
||||
A[Click on] -->|Get happines| BBBB(Clickable)
|
||||
BBBB --> C{Let me think}
|
||||
C -->|One| D[Laptop]
|
||||
C -->|Two| E[iPhone]
|
||||
C -->|Three| F[Car]
|
||||
click A "http://localhost:9000/index.html#link-clicked" "link test"
|
||||
click BBBB testClick "click test"
|
||||
click C "javascript:alert" "link test"
|
||||
classDef someclass fill:#f96;
|
||||
class A someclass;
|
||||
</div>
|
||||
<div class="mermaid">
|
||||
graph LR;
|
||||
alert`md5_salt`-->B;
|
||||
click alert`md5_salt` eval "Tooltip for a callback"
|
||||
click B "javascript:alert`salt`" "This is a tooltip for a link"
|
||||
</div>
|
||||
<div class="mermaid">
|
||||
gantt
|
||||
dateFormat YYYY-MM-DD
|
||||
axisFormat %d/%m
|
||||
title Adding GANTT diagram to mermaid
|
||||
excludes weekdays 2014-01-10
|
||||
|
||||
section A section
|
||||
Completed task :done, des1, 2014-01-06,2014-01-08
|
||||
Active task :active, des2, 2014-01-09, 3d
|
||||
Future task : des3, after des2, 5d
|
||||
Future task2 : des4, after des3, 5d
|
||||
|
||||
section Critical tasks
|
||||
Completed task in the critical line :crit, done, 2014-01-06,24h
|
||||
Implement parser and jison :crit, done, after des1, 2d
|
||||
Create tests for parser :crit, active, 3d
|
||||
Future task in critical line :crit, 5d
|
||||
Create tests for renderer :2d
|
||||
Add to mermaid :1d
|
||||
|
||||
section Documentation
|
||||
Describe gantt syntax :active, a1, after des1, 3d
|
||||
Add gantt diagram to demo page :after a1 , 20h
|
||||
Add another diagram to demo page :doc1, after a1 , 48h
|
||||
|
||||
section Clickable
|
||||
Visit mermaidjs :active, cl1, 2014-01-07,2014-01-10
|
||||
Calling a Callback (look at the console log) :cl2, after cl1, 3d
|
||||
|
||||
click cl1 href "javascript:alert`salt`"
|
||||
click cl2 call ganttTestClick("test", test, test)
|
||||
|
||||
section Last section
|
||||
Describe gantt syntax :after doc1, 3d
|
||||
Add gantt diagram to demo page : 20h
|
||||
Add another diagram to demo page : 48h
|
||||
</div>
|
||||
<div class="mermaid">
|
||||
sequenceDiagram
|
||||
participant "Alice"
|
||||
participant Bob
|
||||
participant John as John<br/>Second Line
|
||||
Alice ->> Bob: Hello Bob, how are you?
|
||||
Bob-->>John: How about you <strong>If bold then xss</strong>John?
|
||||
Bob--x Alice: I am good thanks!
|
||||
Bob-x John: I am good thanks!
|
||||
Note right of John: Bob thinks a long<br/>long time, so long<br/>that the text does<br/>not fit on a row.
|
||||
Bob-->Alice: Checking with John...
|
||||
alt either this
|
||||
Alice->>John: Yes
|
||||
else or this
|
||||
Alice->>John: No
|
||||
else or this will happen
|
||||
Alice->John: Maybe
|
||||
end
|
||||
par this happens in parallel
|
||||
Alice -->> Bob: Parallel message 1
|
||||
and
|
||||
Alice -->> John: Parallel message 2
|
||||
end
|
||||
</div>
|
||||
|
||||
<div class="mermaid">
|
||||
classDiagram
|
||||
Class01 <|-- AveryLongClass : Co<strong>If bold then xss</strong>ol
|
||||
Class03 "0" *-- "0..n" Class04
|
||||
Class05 "1" o-- "many" Class06
|
||||
Class07 .. Class08
|
||||
Class09 "many" --> "1" C2 : Where am i?
|
||||
Class09 "0" --* "1..n" C3
|
||||
Class09 --|> Class07
|
||||
Class07 : equals()
|
||||
Class07 : Object[] elementData
|
||||
Class01 : size()
|
||||
Class01 : int chimp
|
||||
Class01 : int gorilla
|
||||
Class08 <--> C2: Cool label
|
||||
</div>
|
||||
<div class="mermaid">
|
||||
graph LR
|
||||
|
||||
SavePropertyController --> SavePropertyCommand
|
||||
SavePropertyCommand --> SavePropertyCommandHandler
|
||||
SavePropertyCommandHandler --> EventElastica[elastica.postupdate]
|
||||
SavePropertyCommandHandler --> EventProperty[property.postdisable]
|
||||
|
||||
SavePropertyController --> Exceptions
|
||||
Exceptions --> ExceptionList(SecurityException<br/>EmptyRequestBodyException<br/>Throwable)
|
||||
|
||||
classDef Ui fill:#FFFFFF
|
||||
classDef object fill:#1E98EC
|
||||
classDef event fill:#ECB11E
|
||||
|
||||
class EventElastica,EventProperty event
|
||||
class SavePropertyCommand,SavePropertyCommandHandler object
|
||||
class SavePropertyController Ui
|
||||
</div>
|
||||
|
||||
<script src="./mermaid.js"></script>
|
||||
<!-- <script src="//cdn.jsdelivr.net/npm/mermaid@8.2.1/dist/mermaid.min.js"></script> -->
|
||||
<script>
|
||||
mermaid.initialize({
|
||||
theme: 'forest',
|
||||
// themeCSS: '.node rect { fill: red; }',
|
||||
logLevel: 4,
|
||||
flowchart: { htmlLabels: false, curve: 'linear' },
|
||||
gantt: { axisFormat: '%m/%d/%Y' },
|
||||
sequence: { actorMargin: 50 },
|
||||
// sequenceDiagram: { actorMargin: 300 } // deprecated
|
||||
securityLevel:'strict',
|
||||
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
function ganttTestClick(a, b, c){
|
||||
console.log("a:", a)
|
||||
console.log("b:", b)
|
||||
console.log("c:", c)
|
||||
}
|
||||
function testClick(nodeId) {
|
||||
console.log("clicked", nodeId)
|
||||
var originalBgColor = document.querySelector('body').style.backgroundColor
|
||||
document.querySelector('body').style.backgroundColor = 'yellow'
|
||||
setTimeout(function() {
|
||||
document.querySelector('body').style.backgroundColor = originalBgColor
|
||||
}, 100)
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -1,8 +1,9 @@
|
||||
# Class diagrams
|
||||
|
||||
**Edit this Page** [![N|Solid](./img/GitHub-Mark-32px.png)](https://github.com/mermaid-js/mermaid/blob/develop/docs/classDiagram.md)
|
||||
|
||||
> "In software engineering, a class diagram in the Unified Modeling Language (UML) is a type of static structure diagram that describes the structure of a system by showing the system's classes, their attributes, operations (or methods), and the relationships among objects."
|
||||
Wikipedia
|
||||
> Wikipedia
|
||||
|
||||
The class diagram is the main building block of object-oriented modeling. It is used for general conceptual modeling of the structure of the application, and for detailed modeling translating the models into programming code. Class diagrams can also be used for data modeling. The classes in a class diagram represent both the main elements, interactions in the application, and the classes to be programmed.
|
||||
|
||||
@ -32,6 +33,7 @@ Mermaid can render class diagrams.
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
```mermaid
|
||||
classDiagram
|
||||
Animal <|-- Duck
|
||||
@ -63,9 +65,10 @@ Mermaid can render class diagrams.
|
||||
|
||||
UML provides mechanisms to represent class members, such as attributes and methods, and additional information about them.
|
||||
A single instance of a class in the diagram contains three compartments:
|
||||
|
||||
- The top compartment contains the name of the class. It is printed in bold and centered, and the first letter is capitalized. It may also contain optional annotation text describing the nature of the class.
|
||||
- The middle compartment contains the attributes of the class. They are left-aligned and the first letter is lowercase.
|
||||
- The bottom compartment contains the operations the class can execute. They are also left-aligned and the first letter is lowercase.
|
||||
The bottom compartment contains the operations the class can execute. They are also left-aligned and the first letter is lowercase.
|
||||
|
||||
```
|
||||
classDiagram
|
||||
@ -74,7 +77,9 @@ classDiagram
|
||||
BankAccount : +Bigdecimal balance
|
||||
BankAccount : +deposit(amount)
|
||||
BankAccount : +withdrawl(amount)
|
||||
|
||||
```
|
||||
|
||||
```mermaid
|
||||
classDiagram
|
||||
class BankAccount
|
||||
@ -83,9 +88,11 @@ classDiagram
|
||||
BankAccount : +deposit(amount)
|
||||
BankAccount : +withdrawl(amount)
|
||||
```
|
||||
|
||||
## Define a class
|
||||
|
||||
There are two ways to define a class:
|
||||
|
||||
- Explicitly defining a class using keyword **class** like `class Animal`. This defines the Animal class
|
||||
- Define two classes via a **relationship** between them `Vehicle <|-- Car`. This defines two classes Vehicle and Car along with their relationship.
|
||||
|
||||
@ -94,6 +101,7 @@ classDiagram
|
||||
class Animal
|
||||
Vehicle <|-- Car
|
||||
```
|
||||
|
||||
```mermaid
|
||||
classDiagram
|
||||
class Animal
|
||||
@ -108,8 +116,8 @@ UML provides mechanisms to represent class members, such as attributes and metho
|
||||
|
||||
Mermaid distinguishes between attributes and functions/methods based on if the **parenthesis** `()` are present or not. The ones with `()` are treated as functions/methods, and others as attributes.
|
||||
|
||||
|
||||
There are two ways to define the members of a class, and regardless of whichever syntax is used to define the members, the output will still be same. The two different ways are :
|
||||
|
||||
- Associate a member of a class using **:** (colon) followed by member name, useful to define one member at a time. For example:
|
||||
|
||||
```
|
||||
@ -130,6 +138,7 @@ There are two ways to define the members of a class, and regardless of whichever
|
||||
```
|
||||
|
||||
- Associate members of a class using **{}** brackets, where members are grouped within curly brackets. Suitable for defining multiple members at once. For example:
|
||||
|
||||
```
|
||||
class BankAccount{
|
||||
+String owner
|
||||
@ -138,6 +147,7 @@ class BankAccount{
|
||||
+withdrawl(amount)
|
||||
}
|
||||
```
|
||||
|
||||
```mermaid
|
||||
classDiagram
|
||||
class BankAccount{
|
||||
@ -149,8 +159,10 @@ class BankAccount{
|
||||
```
|
||||
|
||||
#### Return Type
|
||||
|
||||
Optionally you can end the method/function definition with the data type that will be returned (note: there must be a space between the final `)` of the method definition and return type
|
||||
example:
|
||||
|
||||
```
|
||||
class BankAccount{
|
||||
+String owner
|
||||
@ -159,6 +171,7 @@ class BankAccount{
|
||||
+withdrawl(amount) int
|
||||
}
|
||||
```
|
||||
|
||||
```mermaid
|
||||
classDiagram
|
||||
class BankAccount{
|
||||
@ -170,6 +183,7 @@ class BankAccount{
|
||||
```
|
||||
|
||||
#### Generic Types
|
||||
|
||||
Members can be defined using generic types, such as `List<int>`, for fields, parameters and return types by enclosing the type within `~` (**tilde**). Note: **nested** type declarations (such as `List<List<int>>`) are not currently supported
|
||||
|
||||
This can be done as part of either class definition method:
|
||||
@ -203,9 +217,11 @@ Square : +getMessages() List~string~
|
||||
```
|
||||
|
||||
#### Return Type
|
||||
|
||||
Optionally you can end the method/function definition with the data type that will be returned
|
||||
|
||||
#### Visibility
|
||||
|
||||
To specify the visibility of a class member (i.e. any attribute or method), these notations may be placed before the member's name, but it is optional:
|
||||
|
||||
- `+` Public
|
||||
@ -214,28 +230,30 @@ To specify the visibility of a class member (i.e. any attribute or method), thes
|
||||
- `~` Package/Internal
|
||||
|
||||
> _note_ you can also include additional _classifers_ to a method definition by adding the following notations to the end of the method, i.e.: after the `()`:
|
||||
|
||||
> - `*` Abstract e.g.: `someAbstractMethod()*`
|
||||
> - `$` Static e.g.: `someStaticMethod()$`
|
||||
|
||||
|
||||
## Defining Relationship
|
||||
|
||||
A relationship is a general term covering the specific types of logical connections found on class and object diagrams.
|
||||
|
||||
```
|
||||
[classA][Arrow][ClassB]:LabelText
|
||||
```
|
||||
|
||||
There are different types of relations defined for classes under UML which are currently supported:
|
||||
|
||||
Type | Description
|
||||
--- | ---
|
||||
<\|-- | Inheritance
|
||||
*-- | Composition
|
||||
o-- | Aggregation
|
||||
--> | Association
|
||||
-- | Link (Solid)
|
||||
..> | Dependency
|
||||
..\|> | Realization
|
||||
.. | Link (Dashed)
|
||||
| Type | Description |
|
||||
| ----- | ------------- |
|
||||
| <\|-- | Inheritance |
|
||||
| \*-- | Composition |
|
||||
| o-- | Aggregation |
|
||||
| --> | Association |
|
||||
| -- | Link (Solid) |
|
||||
| ..> | Dependency |
|
||||
| ..\|> | Realization |
|
||||
| .. | Link (Dashed) |
|
||||
|
||||
```
|
||||
classDiagram
|
||||
@ -262,7 +280,9 @@ classM <|.. classN
|
||||
classO .. classP
|
||||
|
||||
```
|
||||
|
||||
We can use the labels to describe nature of relation between two classes. Also, arrowheads can be used in opposite directions as well :
|
||||
|
||||
```
|
||||
classDiagram
|
||||
classA --|> classB : Inheritance
|
||||
@ -286,33 +306,38 @@ classI -- classJ : Link(Solid)
|
||||
classK ..> classL : Dependency
|
||||
classM ..|> classN : Realization
|
||||
classO .. classP : Link(Dashed)
|
||||
|
||||
|
||||
```
|
||||
|
||||
## Labels on Relations
|
||||
|
||||
It is possible to add a label text to a relation:
|
||||
|
||||
```
|
||||
[classA][Arrow][ClassB]:LabelText
|
||||
```
|
||||
|
||||
```
|
||||
classDiagram
|
||||
classA <|-- classB : implements
|
||||
classC *-- classD : composition
|
||||
classE o-- classF : association
|
||||
```
|
||||
|
||||
```mermaid
|
||||
classDiagram
|
||||
classA <|-- classB : implements
|
||||
classE o-- classF : association
|
||||
|
||||
```
|
||||
|
||||
## Cardinality / Multiplicity on relations
|
||||
|
||||
Multiplicity or cardinality in class diagrams indicates the number of instances of one class linked to one instance of the other class. For example, one company will have one or more employees, but each employee works for just one company.
|
||||
|
||||
Multiplicity notations are placed near the ends of an association.
|
||||
|
||||
The different cardinality options are :
|
||||
|
||||
- `0..1` Zero or one
|
||||
- `1` Only 1
|
||||
- `0..1` Zero or One
|
||||
@ -323,31 +348,38 @@ The different cardinality options are :
|
||||
- `1..n` one to n {where n>1}
|
||||
|
||||
Cardinality can be easily defined by placing cardinality text within qoutes `"` before(optional) and after(optional) a given arrow.
|
||||
|
||||
```
|
||||
[classA] "cardinality1" [Arrow] "cardinality2" [ClassB]:LabelText
|
||||
```
|
||||
|
||||
```
|
||||
classDiagram
|
||||
Customer "1" --> "*" Ticket
|
||||
Student "1" --> "1..*" Course
|
||||
Galaxy --> "many" Star : Contains
|
||||
```
|
||||
|
||||
```mermaid
|
||||
classDiagram
|
||||
Customer "1" --> "*" Ticket
|
||||
Student "1" --> "1..*" Course
|
||||
Galaxy --> "many" Star : Contains
|
||||
```
|
||||
|
||||
## Annotations on classes
|
||||
|
||||
It is possible to annotate classes with a specific marker text which is like meta-data for the class, giving a clear indication about its nature. Some common annotations examples could be:
|
||||
|
||||
- `<<Interface>>` To represent an Interface class
|
||||
- `<<abstract>>` To represent an abstract class
|
||||
- `<<Service>>` To represent a service class
|
||||
- `<<enumeration>>` To represent an enum
|
||||
|
||||
Annotations are defined within the opening `<<` and closing `>>`. There are two ways to add an annotation to a class and regardless of the syntax used output will be same. The two ways are :
|
||||
- In a ***separate line*** after a class is defined. For example:
|
||||
|
||||
- In a **_separate line_** after a class is defined. For example:
|
||||
|
||||
```
|
||||
classDiagram
|
||||
class Shape
|
||||
@ -361,7 +393,8 @@ class Shape
|
||||
Shape : noOfVertices
|
||||
Shape : draw()
|
||||
```
|
||||
- In a ***nested structure*** along with class definition. For example:
|
||||
|
||||
- In a **_nested structure_** along with class definition. For example:
|
||||
|
||||
```
|
||||
classDiagram
|
||||
@ -423,14 +456,14 @@ You would define these actions on a separate line after all classes have been de
|
||||
action className "reference" "tooltip"
|
||||
```
|
||||
|
||||
* _action_ is either `link` or `callback`, depending on which type of interaction you want to have called
|
||||
* _className_ is the id of the node that the action will be associated with
|
||||
* _reference_ is either the url link, or the function name for callback. (note: callback function will be called with the nodeId as parameter).
|
||||
* (_optional_) tooltip is a string to be displayed when hovering over element (note: The styles of the tooltip are set by the class .mermaidTooltip.)
|
||||
- _action_ is either `link` or `callback`, depending on which type of interaction you want to have called
|
||||
- _className_ is the id of the node that the action will be associated with
|
||||
- _reference_ is either the url link, or the function name for callback. (note: callback function will be called with the nodeId as parameter).
|
||||
- (_optional_) tooltip is a string to be displayed when hovering over element (note: The styles of the tooltip are set by the class .mermaidTooltip.)
|
||||
|
||||
### Examples:
|
||||
### Examples
|
||||
|
||||
*URL Link:*
|
||||
_URL Link:_
|
||||
|
||||
```
|
||||
classDiagram
|
||||
@ -438,7 +471,7 @@ class Shape
|
||||
link Shape "http://www.github.com" "This is a tooltip for a link"
|
||||
```
|
||||
|
||||
*Callback:*
|
||||
_Callback:_
|
||||
|
||||
```
|
||||
classDiagram
|
||||
@ -465,6 +498,7 @@ classDiagram
|
||||
> **Success** The tooltip functionality and the ability to link to urls are available from version 0.5.2.
|
||||
|
||||
Beginners tip, a full example using interactive links in an html context:
|
||||
|
||||
```
|
||||
<body>
|
||||
<div class="mermaid">
|
||||
@ -510,26 +544,71 @@ Beginners tip, a full example using interactive links in an html context:
|
||||
|
||||
## Styling
|
||||
|
||||
Styling of the class diagram is done by defining a number of css classes. During rendering these classes are extracted from the file located at src/themes/class.scss
|
||||
### Styling a node
|
||||
|
||||
### Styling Classes used
|
||||
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 as in the example
|
||||
below:
|
||||
|
||||
Class | Description
|
||||
--- | ---
|
||||
g.classGroup text | Styles for general class text
|
||||
classGroup .title | Styles for general class title
|
||||
g.classGroup rect | Styles for class diagram rectangle
|
||||
g.classGroup line | Styles for class diagram line
|
||||
.classLabel .box | Styles for class label box
|
||||
.classLabel .label | Styles for class label text
|
||||
composition | Styles for componsition arrow head and arrow line
|
||||
aggregation | Styles for aggregation arrow head and arrow line(dashed or solid)
|
||||
dependency | Styles for dependency arrow head and arrow line
|
||||
```html
|
||||
<style>
|
||||
.cssClass > rect{
|
||||
fill:#FF0000;
|
||||
stroke:#FFFF00;
|
||||
stroke-width:4px;
|
||||
}
|
||||
</style>
|
||||
```
|
||||
|
||||
Then attaching that class to a specific node as per below:
|
||||
|
||||
```
|
||||
cssClass "nodeId1" cssClass;
|
||||
```
|
||||
|
||||
### Sample stylesheet
|
||||
It is also possible to attach a class to a list of nodes in one statement:
|
||||
|
||||
```
|
||||
cssClass "nodeId1,nodeId2" cssClass;
|
||||
```
|
||||
|
||||
A shorter form of adding a class is to attach the classname to the node using the `:::` operator as per below:
|
||||
|
||||
```
|
||||
classDiagram
|
||||
class Animal:::cssClass
|
||||
```
|
||||
|
||||
Or:
|
||||
|
||||
```
|
||||
classDiagram
|
||||
class Animal:::cssClass {
|
||||
-int sizeInFeet
|
||||
-canEat()
|
||||
}
|
||||
```
|
||||
|
||||
?> cssClasses cannot be added using this shorthand method at the same time as a relation statement.
|
||||
|
||||
?> Due to limitations with existing markup for class diagrams, it is not currently possible to define css classes within the diagram itself. ***Coming soon!***
|
||||
|
||||
### Default Styles
|
||||
|
||||
The main styling of the class diagram is done with a preset number of css classes. During rendering these classes are extracted from the file located at src/themes/class.scss. The classes used here are described below:
|
||||
|
||||
| Class | Description |
|
||||
| ------------------ | ----------------------------------------------------------------- |
|
||||
| g.classGroup text | Styles for general class text |
|
||||
| classGroup .title | Styles for general class title |
|
||||
| g.classGroup rect | Styles for class diagram rectangle |
|
||||
| g.classGroup line | Styles for class diagram line |
|
||||
| .classLabel .box | Styles for class label box |
|
||||
| .classLabel .label | Styles for class label text |
|
||||
| composition | Styles for componsition arrow head and arrow line |
|
||||
| aggregation | Styles for aggregation arrow head and arrow line(dashed or solid) |
|
||||
| dependency | Styles for dependency arrow head and arrow line |
|
||||
|
||||
#### Sample stylesheet
|
||||
|
||||
```css
|
||||
body {
|
||||
@ -619,10 +698,8 @@ g.classGroup line {
|
||||
#extensionEnd {
|
||||
@include composition;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
## Configuration
|
||||
`Coming soon`
|
||||
|
||||
`Coming soon`
|
||||
|
@ -1,3 +1,3 @@
|
||||
# mermaid CLI
|
||||
|
||||
mermaid CLI has been moved to [mermaid.cli](https://github.com/mermaidjs/mermaid.cli). Please read its documentation instead.
|
||||
mermaid CLI has been moved to [mermaid-cli](https://github.com/mermaid-js/mermaid-cli). Please read its documentation instead.
|
||||
|
@ -26,6 +26,7 @@ const splitClassNameAndType = function(id) {
|
||||
if (id.indexOf('~') > 0) {
|
||||
let split = id.split('~');
|
||||
className = split[0];
|
||||
|
||||
genericType = split[1];
|
||||
}
|
||||
|
||||
@ -51,6 +52,7 @@ export const addClass = function(id) {
|
||||
annotations: [],
|
||||
domId: MERMAID_DOM_ID_PREFIX + classId.className + '-' + classCounter
|
||||
};
|
||||
|
||||
classCounter++;
|
||||
};
|
||||
|
||||
|
60
src/diagrams/class/classDiagram-styles.spec.js
Normal file
60
src/diagrams/class/classDiagram-styles.spec.js
Normal file
@ -0,0 +1,60 @@
|
||||
/* eslint-env jasmine */
|
||||
import { parser } from './parser/classDiagram';
|
||||
import classDb from './classDb';
|
||||
|
||||
describe('class diagram, ', function() {
|
||||
describe('when parsing data from a classDiagram it', function() {
|
||||
beforeEach(function() {
|
||||
parser.yy = classDb;
|
||||
parser.yy.clear();
|
||||
});
|
||||
|
||||
it('should be possible to apply a css class to a class directly', function() {
|
||||
const str = 'classDiagram\n' + 'class Class01:::exClass';
|
||||
|
||||
parser.parse(str);
|
||||
|
||||
expect(parser.yy.getClass('Class01').cssClasses[0]).toBe('exClass');
|
||||
});
|
||||
|
||||
it('should be possible to apply a css class to a class directly with struct', function () {
|
||||
const str =
|
||||
'classDiagram\n' +
|
||||
'class Class1:::exClass {\n' +
|
||||
'int : test\n' +
|
||||
'string : foo\n' +
|
||||
'test()\n' +
|
||||
'foo()\n' +
|
||||
'}';
|
||||
parser.parse(str);
|
||||
|
||||
const testClass = parser.yy.getClass('Class1');
|
||||
expect(testClass.cssClasses[0]).toBe('exClass');
|
||||
});
|
||||
|
||||
it('should be possible to apply a css class to a class with relations', function() {
|
||||
const str = 'classDiagram\n' + 'Class01 <|-- Class02\ncssClass "Class01" exClass';
|
||||
|
||||
parser.parse(str);
|
||||
|
||||
expect(parser.yy.getClass('Class01').cssClasses[0]).toBe('exClass');
|
||||
});
|
||||
|
||||
it('should be possible to apply a cssClass to a class', function() {
|
||||
const str = 'classDiagram\n' + 'class Class01\n cssClass "Class01" exClass';
|
||||
|
||||
parser.parse(str);
|
||||
|
||||
expect(parser.yy.getClass('Class01').cssClasses[0]).toBe('exClass');
|
||||
});
|
||||
|
||||
it('should be possible to apply a cssClass to a comma separated list of classes', function() {
|
||||
const str = 'classDiagram\n' + 'class Class01\n class Class02\n cssClass "Class01,Class02" exClass';
|
||||
|
||||
parser.parse(str);
|
||||
|
||||
expect(parser.yy.getClass('Class01').cssClasses[0]).toBe('exClass');
|
||||
expect(parser.yy.getClass('Class02').cssClasses[0]).toBe('exClass');
|
||||
});
|
||||
});
|
||||
});
|
@ -14,7 +14,7 @@
|
||||
<type_directive>":" { this.popState(); this.begin('arg_directive'); return ':'; }
|
||||
<type_directive,arg_directive>\}\%\% { this.popState(); this.popState(); return 'close_directive'; }
|
||||
<arg_directive>((?:(?!\}\%\%).|\n)*) return 'arg_directive';
|
||||
\%\%(?!\{)*[^\n]*(\r?\n)+ /* skip comments */
|
||||
\%\%(?!\{)*[^\n]*(\r?\n?)+ /* skip comments */
|
||||
\%\%[^\n]*(\r?\n)* /* skip comments */
|
||||
(\r?\n)+ return 'NEWLINE';
|
||||
\s+ /* skip whitespace */
|
||||
@ -27,10 +27,8 @@
|
||||
<struct>[\n] /* nothing */
|
||||
<struct>[^{}\n]* { /*console.log('lex-member: ' + yytext);*/ return "MEMBER";}
|
||||
|
||||
|
||||
|
||||
"class" return 'CLASS';
|
||||
//"click" return 'CLICK';
|
||||
"cssClass" return 'CSSCLASS';
|
||||
"callback" return 'CALLBACK';
|
||||
"link" return 'LINK';
|
||||
"<<" return 'ANNOTATION_START';
|
||||
@ -51,7 +49,8 @@
|
||||
\s*o return 'AGGREGATION';
|
||||
\-\- return 'LINE';
|
||||
\.\. return 'DOTTED_LINE';
|
||||
":"[^\n;]+ return 'LABEL';
|
||||
":"{1}[^:\n;]+ return 'LABEL';
|
||||
":"{3} return 'STYLE_SEPARATOR';
|
||||
\- return 'MINUS';
|
||||
"." return 'DOT';
|
||||
\+ return 'PLUS';
|
||||
@ -177,8 +176,8 @@ statements
|
||||
;
|
||||
|
||||
className
|
||||
: alphaNumToken className { $$=$1+$2; }
|
||||
| alphaNumToken { $$=$1; }
|
||||
: alphaNumToken { $$=$1; }
|
||||
| alphaNumToken className { $$=$1+$2; }
|
||||
| alphaNumToken GENERICTYPE className { $$=$1+'~'+$2+$3; }
|
||||
| alphaNumToken GENERICTYPE { $$=$1+'~'+$2; }
|
||||
;
|
||||
@ -190,12 +189,15 @@ statement
|
||||
| methodStatement
|
||||
| annotationStatement
|
||||
| clickStatement
|
||||
| cssClassStatement
|
||||
| directive
|
||||
;
|
||||
|
||||
classStatement
|
||||
: CLASS className {yy.addClass($2);}
|
||||
| CLASS className STYLE_SEPARATOR alphaNumToken {yy.addClass($2);yy.setCssClass($2, $4);}
|
||||
| CLASS className STRUCT_START members STRUCT_STOP {/*console.log($2,JSON.stringify($4));*/yy.addClass($2);yy.addMembers($2,$4);}
|
||||
| CLASS className STYLE_SEPARATOR alphaNumToken STRUCT_START members STRUCT_STOP {yy.addClass($2);yy.setCssClass($2, $4);yy.addMembers($2,$6);}
|
||||
;
|
||||
|
||||
annotationStatement
|
||||
@ -247,6 +249,10 @@ clickStatement
|
||||
| LINK className STR STR {$$ = $1;yy.setLink($2, $3, $4);}
|
||||
;
|
||||
|
||||
cssClassStatement
|
||||
: CSSCLASS STR alphaNumToken {yy.setCssClass($2, $3);}
|
||||
;
|
||||
|
||||
commentToken : textToken | graphCodeTokens ;
|
||||
|
||||
textToken : textNoTagsToken | TAGSTART | TAGEND | '==' | '--' | PCT | DEFAULT;
|
||||
@ -254,4 +260,5 @@ textToken : textNoTagsToken | TAGSTART | TAGEND | '==' | '--' | PCT | DEFA
|
||||
textNoTagsToken: alphaNumToken | SPACE | MINUS | keywords ;
|
||||
|
||||
alphaNumToken : UNICODE_TEXT | NUM | ALPHA;
|
||||
|
||||
%%
|
||||
|
@ -147,11 +147,6 @@ export const drawEdge = function(elem, path, relation, conf) {
|
||||
export const drawClass = function(elem, classDef, conf) {
|
||||
logger.info('Rendering class ' + classDef);
|
||||
|
||||
let cssClassStr = 'classGroup ';
|
||||
if (classDef.cssClasses.length > 0) {
|
||||
cssClassStr = cssClassStr + classDef.cssClasses.join(' ');
|
||||
}
|
||||
|
||||
const id = classDef.id;
|
||||
const classInfo = {
|
||||
id: id,
|
||||
@ -164,7 +159,7 @@ export const drawClass = function(elem, classDef, conf) {
|
||||
const g = elem
|
||||
.append('g')
|
||||
.attr('id', lookUpDomId(id))
|
||||
.attr('class', cssClassStr);
|
||||
.attr('class', 'classGroup');
|
||||
|
||||
// add title
|
||||
let title;
|
||||
@ -249,12 +244,19 @@ export const drawClass = function(elem, classDef, conf) {
|
||||
});
|
||||
|
||||
const classBox = g.node().getBBox();
|
||||
var cssClassStr = ' ';
|
||||
|
||||
if (classDef.cssClasses.length > 0) {
|
||||
cssClassStr = cssClassStr + classDef.cssClasses.join(' ');
|
||||
}
|
||||
|
||||
const rect = g
|
||||
.insert('rect', ':first-child')
|
||||
.attr('x', 0)
|
||||
.attr('y', 0)
|
||||
.attr('width', classBox.width + 2 * conf.padding)
|
||||
.attr('height', classBox.height + conf.padding + 0.5 * conf.dividerMargin);
|
||||
.attr('height', classBox.height + conf.padding + 0.5 * conf.dividerMargin)
|
||||
.attr('class', cssClassStr);
|
||||
|
||||
const rectWidth = rect.node().getBBox().width;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user