Skip to content

Commit

Permalink
Merge branch 'release/8.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
knsv committed Oct 19, 2019
2 parents dd68a71 + d366605 commit 0157f66
Show file tree
Hide file tree
Showing 16 changed files with 249 additions and 46 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/release-preview-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Publish release preview package

on:
push:
branches:
- 'release/**'

jobs:
publish:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x]
steps:
- uses: actions/checkout@v1
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install Yarn
run: npm i yarn --global

- name: Install Json
run: npm i json --global

- name: Install Packages
run: yarn install

- name: Publish
run: |
PREVIEW_VERSION=$(git rev-list --count --first-parent HEAD)
VERSION=$(echo ${{github.ref}} | tail -c +20)-preview.$PREVIEW_VERSION
echo $VERSION
npm version --no-git-tag-version --allow-same-version $VERSION
npm set //npm.pkg.github.com/:_authToken ${{ secrets.GITHUB_TOKEN }}
npm set registry https://npm.pkg.github.com/knsv
json -I -f package.json -e 'this.name="@knsv/mermaid"' # Package name needs to be set to a scoped one because GitHub registry requires this
json -I -f package.json -e 'this.repository="git://github.com/knsv/mermaid"' # Repo url needs to have a specific format too
npm publish
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ Example: https://unpkg.com/[email protected]/dist/

yarn add mermaid

### Preview builds
Preview builds are created automatically for each release. They can be found in the [GitHub registry](https://github.com/knsv/mermaid/packages).
Make sure to configure npm to use the GitHub package registry. Steps for that can be found [here](https://help.github.com/en/articles/configuring-npm-for-use-with-github-package-registry).

If you want to get the latest preview for the next release
```
yarn add @knsv/mermaid
```


If you want to get the latest preview for a specific version
```
yarn add @knsv/mermaid@<version>
```

## Documentation

Expand Down
16 changes: 16 additions & 0 deletions cypress/integration/other/rerender.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* eslint-env jest */
describe('Rerendering', () => {

it('should be able to render and rerender a graph via API', () => {
const url = 'http://localhost:9000/rerender.html';
cy.viewport(1440, 1024);
cy.visit(url);
cy.get('#graph #A').should('have.text', 'XMas');

cy.get('body')
.find('#rerender')
.click({ force: true });

cy.get('#graph #A').should('have.text', 'Saturday');
});
});
33 changes: 33 additions & 0 deletions cypress/platform/rerender.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!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 id="graph">
</div>

<script src="./mermaid.js"></script>
<script>

mermaid.init({ startOnLoad: false });
mermaid.mermaidAPI.initialize();

rerender('XMas');

function rerender(text) {
var graphText = `graph TD
A[${text}] -->|Get money| B(Go shopping)`
var graph = mermaid.mermaidAPI.render('id', graphText);
console.log('\x1b[35m%s\x1b[0m', '>> graph', graph)
document.getElementById('graph').innerHTML=graph;
}

</script>
<button id="rerender" onclick="rerender('Saturday')">Rerender</button>

</body>
</html>
1 change: 1 addition & 0 deletions docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- [Flowchart](flowchart.md)
- [Sequence diagram](sequenceDiagram.md)
- [Class Diagram](classDiagram.md)
- [State Diagram](stateDiagram.md)
- [Gantt](gantt.md)
- [Pie Chart](pie.md)
- Guide
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta name="description" content="Markdownish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="//unpkg.com/docsify/lib/themes/vue.css">
<script src="//cdn.jsdelivr.net/npm/mermaid@8.3.1/dist/mermaid.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/mermaid@8.4.0/dist/mermaid.min.js"></script>
<!-- <script src="//localhost:9000/mermaid.js"></script> -->
<style>
.markdown-section {
Expand Down
106 changes: 68 additions & 38 deletions docs/stateDiagram.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# State diagrams

> A state diagram is a type of diagram used in computer science and related fields to describe the behavior of systems. State diagrams require that the system described is composed of a finite number of states; sometimes, this is indeed the case, while at other times this is a reasonable abstraction.
> "A state diagram is a type of diagram used in computer science and related fields to describe the behavior of systems. State diagrams require that the system described is composed of a finite number of states; sometimes, this is indeed the case, while at other times this is a reasonable abstraction." Wikipedia
Mermaid can render state diagrams with a syntax derived from plantUml, this to make the diagrams easier to use.
Mermaid can render state diagrams. The syntax tries to be compliant with the syntax used in plantUml as this will make it easier for users to
share diagrams between mermaid and plantUml.

```
stateDiagram
Expand All @@ -24,6 +25,7 @@ stateDiagram
Moving --> Crash
Crash --> [*]
```
In state diagrams systems are described in terms of its states and how the systems state can change to another state via a transitions. The example diagram above shows three states **Still**, **Moving** and **Crash**. You start in the state of Still. From Still you can change the state to Moving. In Moving you can change the state either back to Still or to Crash. There is no transition from Still to Crash.

## States

Expand All @@ -38,7 +40,7 @@ stateDiagram
s1
```

Another way is by using the state key word as per below:
Another way is by using the state keyword with a description as per below:
```
stateDiagram
state "This ia state decription" as s2
Expand All @@ -48,11 +50,23 @@ stateDiagram
state "This ia state decription" as s2
```

Another way to define a state with a description is to define the state id followed by a colon and the description:
```
stateDiagram
s2 : This ia state decription
```
```mermaid
stateDiagram
s2 : This ia state decription
```


## Transitions

Transitions are path/edges when one state passes into another. This is represented using text arrow, "-->".

Transitions from and to states that are not defined implicitly defines these states.
When you define a transition between two states and the states are not already defined the undefined states are defined with the id
from the transition. You can later add descriptions to states defined this way.

```
stateDiagram
Expand All @@ -63,7 +77,7 @@ stateDiagram
s1 --> s2
```

It is possieblt to add text to a transition.
It is possible to add text to a transition. To describe what it represents.

```
stateDiagram
Expand All @@ -74,7 +88,9 @@ stateDiagram
s1 --> s2: A transition
```

There are two special states indicating the start of the diagram and the stop of the diagram. These are written with the [*] syntax.
## Start and end

There are two special states indicating the start and stop of the diagram. These are written with the [*] syntax and the direction of the transition to it defines it either as a start or a stop state.

```
stateDiagram
Expand All @@ -90,9 +106,10 @@ stateDiagram

## Composit states

In a real world use of state diagrams you often end up with diagrams that are multi-dimensional as one state can have several internal states.
In a real world use of state diagrams you often end up with diagrams that are multi-dimensional as one state can
have several internal states. These are called composit states in this terminology.

In order to define a composit state you need to use the state keyword as per below:
In order to define a composit state you need to use the state keyword followed by and id and the body of the composit state between {}. See the example below:

```
stateDiagram
Expand All @@ -113,6 +130,44 @@ stateDiagram

You can do this in several layers:

```
stateDiagram
[*] --> First
state First {
[*] --> Second
state Second {
[*] --> second
second --> Third
state Third {
[*] --> third
third --> [*]
}
}
}
```
```mermaid
stateDiagram
[*] --> First
state First {
[*] --> Second
state Second {
[*] --> second
second --> Third
state Third {
[*] --> third
third --> [*]
}
}
}
```

You can also define transitions also between composit states:

```
stateDiagram
[*] --> First
Expand Down Expand Up @@ -150,9 +205,10 @@ stateDiagram
[*] --> thi
thi --> [*]
}
```

*You can not define transitions between internal states belonging to different composit states*

## Forks

It is possible to specify a fork in the diagram using &lt;&lt;fork&gt;&gt; &lt;&lt;join&gt;&gt;.
Expand Down Expand Up @@ -187,9 +243,9 @@ It is possible to specify a fork in the diagram using &lt;&lt;fork&gt;&gt; &lt;&

## Notes

Sometimes nothing says it better then a postit note. That is also the case in state diagrams.
Sometimes nothing says it better then a Post-it note. That is also the case in state diagrams.

Here you can't choose to put the onte to the right or to the left of a node.
Here you can choose to put the note to the *right of* or to the *left of* a node.

```
stateDiagram
Expand Down Expand Up @@ -257,30 +313,4 @@ As in plantUml you can specify concurrency using the -- symbol.

## Styling

Styling of the a sequence diagram is done by defining a number of css classes. During rendering these classes are extracted from the file located at src/themes/sequence.scss

### Classes used (TB Written)

Class | Description
--- | ---
Fakenote | Styles for the note box.
FakenoteText | Styles for the text on in the note boxes.




## Configuration

Is it possible to adjust the margins etc for the stateDiagram ... TB written

```javascript
mermaid.stateConfig = {
};
```

### Possible configuration params:

Param | Description | Default value
--- | --- | ---
TBS | Turns on/off the rendering of actors below the diagram as well as above it | false

Styling of the a state diagram is done by defining a number of css classes. During rendering these classes are extracted from the file located at src/themes/state.scss
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mermaid",
"version": "8.3.1",
"version": "8.4.0",
"description": "Markdownish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.",
"main": "dist/mermaid.core.js",
"keywords": [
Expand Down
7 changes: 4 additions & 3 deletions src/diagrams/class/classDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ export const addMember = function(className, member) {
}
};

export const addMembers = function(className, MembersArr) {
if (Array.isArray(MembersArr)) {
MembersArr.forEach(member => addMember(className, member));
export const addMembers = function(className, members) {
if (Array.isArray(members)) {
members.reverse();
members.forEach(member => addMember(className, member));
}
};

Expand Down
20 changes: 20 additions & 0 deletions src/diagrams/class/classDiagram.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,5 +262,25 @@ describe('class diagram, ', function() {
expect(testClass.methods.length).toBe(1);
expect(testClass.annotations[0]).toBe('interface');
});

it('should add bracket members in right order', function() {
const str =
'classDiagram\n' +
'class Class1 {\n' +
'int : test\n' +
'string : foo\n' +
'test()\n' +
'foo()\n' +
'}';
parser.parse(str);

const testClass = parser.yy.getClass('Class1');
expect(testClass.members.length).toBe(2);
expect(testClass.methods.length).toBe(2);
expect(testClass.members[0]).toBe('int : test');
expect(testClass.members[1]).toBe('string : foo');
expect(testClass.methods[0]).toBe('test()');
expect(testClass.methods[1]).toBe('foo()');
});
});
});
3 changes: 2 additions & 1 deletion src/diagrams/flowchart/flowRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ export const addVertices = function(vert, g, svgId) {
}
}
} else {
// create the style definition for the text, if property is a text-property
for (let i = 0; i < arr.length; i++) {
if (typeof arr[i] !== 'undefined') {
if (arr[i].match('^color:')) styleStr = styleStr + arr[i] + ';';
if (arr[i].match('^color:|^text-align:')) styleStr = styleStr + arr[i] + ';';
}
}
}
Expand Down
Loading

0 comments on commit 0157f66

Please sign in to comment.