diff --git a/.gitignore b/.gitignore index 69f442484..58579d79b 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,5 @@ dist/classTest.html dist/sequenceTest.html .vscode/ -cypress/platform/current.html \ No newline at end of file +cypress/platform/current.html +cypress/platform/experimental.html \ No newline at end of file diff --git a/README.md b/README.md index d09567c52..83fe09ec7 100644 --- a/README.md +++ b/README.md @@ -5,13 +5,46 @@ # mermaid [![Build Status](https://travis-ci.org/mermaid-js/mermaid.svg?branch=master)](https://travis-ci.org/mermaid-js/mermaid) [![NPM](https://img.shields.io/npm/v/mermaid)](https://www.npmjs.com/package/mermaid) [![Coverage Status](https://coveralls.io/repos/github/mermaid-js/mermaid/badge.svg?branch=master)](https://coveralls.io/github/mermaid-js/mermaid?branch=master) [![Join our Slack!](https://img.shields.io/static/v1?message=join%20chat&color=9cf&logo=slack&label=slack)](https://join.slack.com/t/mermaid-talk/shared_invite/enQtNzc4NDIyNzk4OTAyLWVhYjQxOTI2OTg4YmE1ZmJkY2Y4MTU3ODliYmIwOTY3NDJlYjA0YjIyZTdkMDMyZTUwOGI0NjEzYmEwODcwOTE) [![This project is using Percy.io for visual regression testing.](https://percy.io/static/images/percy-badge.svg)](https://percy.io/Mermaid/mermaid) + -__Generate diagrams, charts, graphs or flows from markdown-like text via javascript.__ -See our [documentation](http://mermaid-js.github.io/mermaid/) and start simplifying yours. Play in our [live editor](https://mermaidjs.github.io/mermaid-live-editor/) or jump straight to the [installation and usage](http://mermaid-js.github.io/mermaid/#/usage). +__mermaid is a Javascript based diagramming and charting tool. It generates diagrams flowcharts and more, using markdown-inspired text for ease and speed.__ + +Check out the list of [Integrations and Usages of Mermaid](https://github.com/mermaid-js/mermaid/blob/develop/docs/integrations.md) + +For more information and help in getting started, please view our [documentation](http://mermaid-js.github.io/mermaid/) and start simplifying yours. Alternatively, you can also play with our [live editor](https://mermaidjs.github.io/mermaid-live-editor/). + + +:trophy: **Mermaid was nominated and won the [JS Open Source Awards (2019)](https://osawards.com/javascript/#nominees) in the category "The most exciting use of technology"!!! Thanks to all involved, people committing pull requests, people answering questions and special thanks to Tyler Long who is helping me maintain the project.** + +## New diagrams in 8.4 + +With version 8.4 class diagrams have got some new features, bug fixes and documentation. Another new feature in 8.4 is the new diagram type, state diagrams. + +![Image show the two new diagram types](./docs/img/new-diagrams.png) + +## Special note regarding version 8.2 + +In version 8.2 a security improvement was introduced. A securityLevel configuration was introduced which sets the level of trust to be used on the parsed diagrams. + +- **true**: (default) tags in text are encoded, click functionality is disabled +- false: tags in text are allowed, click functionality is enabled + +Closed issues: + +⚠️ **Note** : This changes the default behaviour of mermaid so that after upgrade to 8.2, if the securityLevel is not configured, tags in flowcharts are encoded as tags and clicking is prohibited. + +If your application is taking resposibility for the diagram source security you can set the securityLevel accordingly. By doing this clicks and tags are again allowed. + +```javascript +mermaidAPI.initialize({ + securityLevel: 'loose' +}); +``` + +For more information and help in getting started, please view our [documentation](http://mermaid-js.github.io/mermaid/) and start simplifying yours. Play with our [live editor](https://mermaidjs.github.io/mermaid-live-editor/) or jump straight to the [installation and usage](http://mermaid-js.github.io/mermaid/#/usage). -:trophy: _"The most exciting use of technology"_ - [JS Open Source Awards (2019)](https://osawards.com/javascript/#nominees) - +__The following are some examples of the diagrams, charts and graphs that can be made using mermaid and the Markdown-inspired text specific to it. Click here jump into the [text syntax](https://mermaid-js.github.io/mermaid/#/n00b-syntaxReference).__
diff --git a/cypress/integration/rendering/erDiagram.spec.js b/cypress/integration/rendering/erDiagram.spec.js new file mode 100644 index 000000000..dcfcdc11a --- /dev/null +++ b/cypress/integration/rendering/erDiagram.spec.js @@ -0,0 +1,91 @@ +/* eslint-env jest */ +import { imgSnapshotTest } from '../../helpers/util'; + +describe('Entity Relationship Diagram', () => { + it('should render a simple ER diagram', () => { + imgSnapshotTest( + ` + erDiagram + CUSTOMER ||--o{ ORDER : places + ORDER ||--|{ LINE-ITEM : contains + `, + {logLevel : 1} + ); + cy.get('svg'); + }); + + it('should render an ER diagram with a recursive relationship', () => { + imgSnapshotTest( + ` + erDiagram + CUSTOMER ||..o{ CUSTOMER : refers + CUSTOMER ||--o{ ORDER : places + ORDER ||--|{ LINE-ITEM : contains + `, + {logLevel : 1} + ); + cy.get('svg'); + }); + + it('should render an ER diagram with multiple relationships between the same two entities', () => { + imgSnapshotTest( + ` + erDiagram + CUSTOMER ||--|{ ADDRESS : "invoiced at" + CUSTOMER ||--|{ ADDRESS : "receives goods at" + `, + {logLevel : 1} + ); + cy.get('svg'); + }); + + it('should render a cyclical ER diagram', () => { + imgSnapshotTest( + ` + erDiagram + A ||--|{ B : likes + B ||--|{ C : likes + C ||--|{ A : likes + `, + {logLevel : 1} + ); + cy.get('svg'); + }); + + it('should render a not-so-simple ER diagram', () => { + imgSnapshotTest( + ` + erDiagram + CUSTOMER }|..|{ DELIVERY-ADDRESS : has + CUSTOMER ||--o{ ORDER : places + CUSTOMER ||--o{ INVOICE : "liable for" + DELIVERY-ADDRESS ||--o{ ORDER : receives + INVOICE ||--|{ ORDER : covers + ORDER ||--|{ ORDER-ITEM : includes + PRODUCT-CATEGORY ||--|{ PRODUCT : contains + PRODUCT ||--o{ ORDER-ITEM : "ordered in" + `, + {logLevel : 1} + ); + cy.get('svg'); + }); + + it('should render multiple ER diagrams', () => { + imgSnapshotTest( + [ + ` + erDiagram + CUSTOMER ||--o{ ORDER : places + ORDER ||--|{ LINE-ITEM : contains + `, + ` + erDiagram + CUSTOMER ||--o{ ORDER : places + ORDER ||--|{ LINE-ITEM : contains + ` + ], + {logLevel : 1} + ); + cy.get('svg'); + }); +}); diff --git a/cypress/integration/rendering/flowchart.spec.js b/cypress/integration/rendering/flowchart.spec.js index bc6c68f6e..c88129ddc 100644 --- a/cypress/integration/rendering/flowchart.spec.js +++ b/cypress/integration/rendering/flowchart.spec.js @@ -524,7 +524,8 @@ describe('Flowchart', () => { { flowchart: { htmlLabels: false } } ); }); -it('25: Handle link click events (link, anchor, mailto, other protocol, script)', () => { + + it('25: Handle link click events (link, anchor, mailto, other protocol, script)', () => { imgSnapshotTest( `graph TB TITLE["Link Click Events
(click the nodes below)"] @@ -583,6 +584,39 @@ it('25: Handle link click events (link, anchor, mailto, other protocol, script)' { flowchart: { htmlLabels: false } } ); }); + + it('28: Apply default class to all nodes which do not have another class assigned (htmlLabels enabled)', () => { + imgSnapshotTest( + `graph TD + A[myClass1] --> B[default] & C[default] + B[default] & C[default] --> D[myClass2] + classDef default stroke-width:2px,fill:none,stroke:silver + classDef node color:red + classDef myClass1 color:#0000ff + classDef myClass2 stroke:#0000ff,fill:#ccccff + class A myClass1 + class D myClass2 + `, + { flowchart: { htmlLabels: true } } + ); + }); + + it('29: Apply default class to all nodes which do not have another class assigned (htmlLabels disabled)', () => { + imgSnapshotTest( + `graph TD + A[myClass1] --> B[default] & C[default] + B[default] & C[default] --> D[myClass2] + classDef default stroke-width:2px,fill:none,stroke:silver + classDef node color:red + classDef myClass1 color:#0000ff + classDef myClass2 stroke:#0000ff,fill:#ccccff + class A myClass1 + class D myClass2 + `, + { flowchart: { htmlLabels: false } } + ); + }); + it('30: Possibility to style text color of nodes and subgraphs as well as apply classes to subgraphs', () => { imgSnapshotTest( `graph LR diff --git a/cypress/platform/current.html b/cypress/platform/current.html index f854ddcb0..2f5ec32b4 100644 --- a/cypress/platform/current.html +++ b/cypress/platform/current.html @@ -20,16 +20,8 @@

info below

- sequenceDiagram - Alice->>John: Hello John, how are you? - loop Healthcheck - John->>John: Fight against hypochondria - end - Note right of John: Rational thoughts! - John-->>Alice: Great! - John->>Bob: How about you? - Bob-->>John: Jolly good! - + flowchart LR + A --> B
diff --git a/dist/index.html b/dist/index.html index e28890ce7..46af0d709 100644 --- a/dist/index.html +++ b/dist/index.html @@ -384,6 +384,17 @@ graph TB click B "index.html#link-clicked" "link test" click D testClick "click test" +
+ graph TD + A[myClass1] --> B[default] & C[default] + B[default] & C[default] --> D[myClass2] + classDef default stroke-width:2px,fill:none,stroke:silver + classDef node color:red + classDef myClass1 color:#0000ff + classDef myClass2 stroke:#0000ff,fill:#ccccff + class A myClass1 + class D myClass2 +

diff --git a/docs/README.md b/docs/README.md index 59eb159e3..4fb40e62b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,38 +1,9 @@ +# Mermaid + [![Build Status](https://travis-ci.org/mermaid-js/mermaid.svg?branch=master)](https://travis-ci.org/mermaid-js/mermaid) [![Coverage Status](https://coveralls.io/repos/github/knsv/mermaid/badge.svg?branch=master)](https://coveralls.io/github/knsv/mermaid?branch=master) [![Join the chat at https://gitter.im/knsv/mermaid](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/knsv/mermaid?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -# mermaid - -## New diagrams in 8.4 - -With version 8.4 class diagrams has got some new features, bug fixes and documentation. Another new feature in 8.4 is the new diagram -type, state diagrams. - -![Image show the two new diagram types](./img/new-diagrams.png) - - -## Special note regarding version 8.2 - -In version 8.2 a security improvement was introduced. A securityLevel configuration was introduced which sets the level of trust to be used on the parsed diagrams. - -* **true**: (default) tags in text are encoded, click functionality is disabled -* false: tags in text are allowed, click functionality is enabled - -Closed issues: - -⚠️ **Note** : This changes the default behaviour of mermaid so that after upgrade to 8.2, if the securityLevel is not configured, tags in flowcharts are encoded as tags and clicking is prohibited. - -If your application is taking resposibility for the diagram source security you can set the securityLevel accordingly. By doing this clicks and tags are again allowed. - -```javascript - mermaidAPI.initialize({ - securityLevel: 'loose' - }); -``` - -**🖖 Keep a steady pulse: mermaid needs more Collaborators [#866](https://github.com/knsv/mermaid/issues/866)** - ![banner](./img/header.png) Generation of diagrams and flowcharts from text in a similar manner as markdown. @@ -41,8 +12,39 @@ Ever wanted to simplify documentation and avoid heavy tools like Visio when expl This is why mermaid was born, a simple markdown-like script language for generating charts from text via javascript. +Check out the list of [Integrations and Usages of Mermaid](./integrations.md) + **Mermaid was nominated and won the JS Open Source Awards (2019) in the category "The most exciting use of technology"!!! Thanks to all involved, people committing pull requests, people answering questions and special thanks to Tyler Long who is helping me maintain the project.** +## New diagrams in 8.4 + +With version 8.4 class diagrams have got some new features, bug fixes and documentation. Another new feature in 8.4 is the new diagram type, state diagrams. + +![Image show the two new diagram types](./img/new-diagrams.png) + +## Special note regarding version 8.2 + +In version 8.2 a security improvement was introduced. A securityLevel configuration was introduced which sets the level of trust to be used on the parsed diagrams. + +- **true**: (default) tags in text are encoded, click functionality is disabled +- false: tags in text are allowed, click functionality is enabled + +Closed issues: + +⚠️ **Note** : This changes the default behaviour of mermaid so that after upgrade to 8.2, if the securityLevel is not configured, tags in flowcharts are encoded as tags and clicking is prohibited. + +If your application is taking resposibility for the diagram source security you can set the securityLevel accordingly. By doing this clicks and tags are again allowed. + +```javascript +mermaidAPI.initialize({ + securityLevel: 'loose' +}); +``` + +**🖖 Keep a steady pulse: mermaid needs more Collaborators [#866](https://github.com/knsv/mermaid/issues/866)** + +## Diagrams + ### Flowchart ``` @@ -52,8 +54,8 @@ graph TD; B-->D; C-->D; ``` -![Flowchart](./img/flow.png) +![Flowchart](./img/flow.png) ### Sequence diagram @@ -70,8 +72,8 @@ sequenceDiagram John->>Bob: How about you? Bob-->>John: Jolly good! ``` -![Sequence diagram](./img/sequence.png) +![Sequence diagram](./img/sequence.png) ### Gantt diagram @@ -87,8 +89,8 @@ Active task :active, des2, 2014-01-09, 3d Future task : des3, after des2, 5d Future task2 : des4, after des3, 5d ``` -![Gantt diagram](./img/gantt.png) +![Gantt diagram](./img/gantt.png) ### Class diagram - :exclamation: experimental @@ -108,8 +110,8 @@ Class01 : int chimp Class01 : int gorilla Class08 <--> C2: Cool label ``` -![Class diagram](./img/class.png) +![Class diagram](./img/class.png) ### Git graph - :exclamation: experimental @@ -135,7 +137,6 @@ merge newbranch ![Git graph](./img/git.png) - ## Installation ### CDN @@ -154,12 +155,10 @@ Example: https://unpkg.com/mermaid@7.1.0/dist/ yarn add mermaid ``` - ## Documentation https://mermaidjs.github.io - ## Sibling projects - [mermaid CLI](https://github.com/mermaidjs/mermaid.cli) @@ -167,8 +166,7 @@ https://mermaidjs.github.io - [mermaid webpack demo](https://github.com/mermaidjs/mermaid-webpack-demo) - [mermaid Parcel demo](https://github.com/mermaidjs/mermaid-parcel-demo) - -# Request for assistance +## Request for assistance Things are piling up and I have a hard time keeping up. To remedy this it would be great if we could form a core team of developers to cooperate @@ -178,61 +176,62 @@ As part of this team you would get write access to the repository and would represent the project when answering questions and issues. Together we could continue the work with things like: -* adding more types of diagrams like mindmaps, ert diagrams, etc. -* improving existing diagrams + +- Adding more types of diagrams like mindmaps, ert diagrams, etc. +- Improving existing diagrams Don't hesitate to contact me if you want to get involved. +## For contributors -# For contributors +### Setup -## Setup +``` +yarn install +``` - yarn install +### Build +``` +yarn build:watch +``` -## Build +### Lint - yarn build:watch - - -## Lint - - yarn lint +``` +yarn lint +``` We use [eslint](https://eslint.org/). We recommend you installing [editor plugins](https://eslint.org/docs/user-guide/integrations) so you can get real time lint result. +### Test +``` +yarn test +``` +Manual test in browser: open `dist/index.html` -## Test - - yarn test - -Manual test in browser: - - open dist/index.html - - -## Release +### Release For those who have the permission to do so: Update version number in `package.json`. - npm publish +``` +npm publish +``` Command above generates files into the `dist` folder and publishes them to npmjs.org. - -# Credits +## Credits Many thanks to the [d3](http://d3js.org/) and [dagre-d3](https://github.com/cpettitt/dagre-d3) projects for providing the graphical layout and drawing libraries! Thanks also to the [js-sequence-diagram](http://bramp.github.io/js-sequence-diagrams) project for usage of the grammar for the sequence diagrams. Thanks to Jessica Peter for inspiration and starting point for gantt rendering. -*Mermaid was created by Knut Sveidqvist for easier documentation.* +_Mermaid was created by Knut Sveidqvist for easier documentation._ -*[Tyler Long](https://github.com/tylerlong) has became a collaborator since April 2017.* +_[Tyler Long](https://github.com/tylerlong) has became a collaborator since April 2017._ Here is the full list of the projects [contributors](https://github.com/knsv/mermaid/graphs/contributors). diff --git a/docs/development.md b/docs/development.md index af2805afd..1a26f91e8 100644 --- a/docs/development.md +++ b/docs/development.md @@ -3,9 +3,31 @@ ## Updating the documentation -We write documention with GitBook. +Please continue writing documentation at [mermaid-js/mermaid/docs](https://github.com/mermaid-js/mermaid/tree/develop/docs). -Please continue with the [mermaid-gitbook](https://github.com/mermaidjs/mermaid-gitbook) project. +We publish documentation using GitHub Pages. + + +### Questions and/or suggestions ? +After logging in at [GitHub.com](https://www.github.com), open or append to an issue [using the GitHub issue tracker of the mermaid-js repository](https://github.com/mermaid-js/mermaid/issues?q=is%3Aissue+is%3Aopen+label%3A%22Area%3A+Documentation%22). + +### How to contribute a suggestion +Markdown is used to format the text, for more information about Markdown [see the GitHub Markdown help page](https://help.github.com/en/github/writing-on-github/basic-writing-and-formatting-syntax). + +If you want to use an editor on your own computer, you may follow these steps: +* Find the Markdown file (.md) to edit in the [mermaid-js/mermaid/docs](https://github.com/mermaid-js/mermaid/tree/develop/docs) directory on the develop branch. +* Create a fork of the develop branch. +* Make changes or add new documentation. +* Commit changes to your fork and push it to GitHub. +* Create a pull request of your fork. + +If you don't have such editor on your computer, you may follow these steps: +* Login at [GitHub.com](https://www.github.com). +* Navigate to [mermaid-js/mermaid/docs](https://github.com/mermaid-js/mermaid/tree/develop/docs). +* To edit a file, click the pencil icon at the top-right of the file contents panel. +* Describe what you changed in the "Propose file change" section, located at the bottom of the page. +* Submit your changes by clicking the button "Propose file change" at the bottom (by automatic creation of a fork and a new branch). +* Create a pull request of your newly forked branch, by clicking the green "Create pull request" button. ## How to add a new diagram type diff --git a/docs/entityRelationshipDiagram.md b/docs/entityRelationshipDiagram.md new file mode 100644 index 000000000..da5bf4b0d --- /dev/null +++ b/docs/entityRelationshipDiagram.md @@ -0,0 +1,80 @@ +# Entity Relationship Diagrams + +> An entity–relationship model (or ER model) describes interrelated things of interest in a specific domain of knowledge. A basic ER model is composed of entity types (which classify the things of interest) and specifies relationships that can exist between entities (instances of those entity types). Wikipedia. + +Note that practitioners of ER modelling almost always refer to entity types simply as entities. For example the CUSTOMER entity type would be referred to simply as the CUSTOMER entity. This is so common it would be inadvisable to do anything else, but technically an entity is an abstract *instance* of an entity type, and this is what an ER diagram shows - abstract instances, and the relationships between them. This is why entities are always named using singular nouns. + +Mermaid can render ER diagrams +``` +erDiagram + CUSTOMER ||--o{ ORDER : places + ORDER ||--|{ LINE-ITEM : contains + CUSTOMER }|..|{ : DELIVERY-ADDRESS : uses +``` +```mermaid +erDiagram + CUSTOMER ||--o{ ORDER : places + ORDER ||--|{ LINE-ITEM : contains + CUSTOMER }|..|{ : DELIVERY-ADDRESS : uses +``` + +Entity names are often capitalised, although there is no accepted standard on this, and it is not required in Mermaid. + +Relationships between entities are represented by lines with end markers representing cardinality. Mermaid uses the most popular crow's foot notation. The crow's foot intuitively conveys the possibility of many instances of the entity that it connects to. + +## Status + +ER diagrams are a new feature in Mermaid and are **experimental**. There are likely to be a few bugs and constraints, and enhancements will be made in due course. + +## Syntax + +### Entities and Relationships + +Mermaid syntax for ER diagrams is compatible with PlantUML, with an extension to label the relationship. Each statement consists of the following parts, all of which are mandatory: +``` + : +``` +Where: + +- `first-entity` is the name of an entity. Names must begin with an alphabetic character and may also contain digits and hyphens +- `relationship` describes the way that both entities inter-relate. See below. +- `second-entity` is the name of the other entity +- `relationship-label` describes the relationship from the perspective of the first entity. + +For example: + +``` + PROPERTY ||--|{ ROOM : contains +``` + +This statement can be read as *a property contains one or more rooms, and a room is part of one and only one property*. You can see that the label here is from the first entity's perspective: a property contains a room, but a room does not contain a property. When considered from the perspective of the second entity, the equivalent label is usually very easy to infer. (Some ER diagrams label relationships from both perspectives, but this is not supported here, and is usually superfluous). + +### Relationship Syntax + +The `relationship` part of each statement can be broken down into three sub-components: + +- the cardinality of the first entity with respect to the second, +- whether the relationship confers identity on a 'child' entity +- the cardinality of the second entity with respect to the first + +Cardinality is a property that describes how many elements of another entity can be related to the entity in question. In the above example a `PROPERTY` can have one or more `ROOM` instances associated to it, whereas a `ROOM` can only be associated with one `PROPERTY`. In each cardinality marker there are two characters. The outermost character represents a maximum value, and the innermost character represents a minimum value. The table below summarises possible cardinalities. + +| Value (left) | Value (right) | Meaning | +|:------------:|:-------------:|--------------------------------------------------------| +| `|o` | `o|` | Zero or one | +| `||` | `||` | Exactly one | +| `}o` | `o{` | Zero or more (no upper limit) | +| `}|` | `|{` | One or more (no upper limit) | + +### Identification + +Relationships may be classified as either *identifying* or *non-identifying* and these are rendered with either solid or dashed lines respectively. This is relevant when one of the entities in question can not have independent existence without the other. For example a firm that insures people to drive cars might need to store data on `NAMED-DRIVER`s. In modelling this we might start out by observing that a `CAR` can be driven by many `PERSON` instances, and a `PERSON` can drive many `CAR`s - both entities can exist without the other, so this is a non-identifying relationship that we might specify in Mermaid as: `PERSON }|..|{ CAR : "driver"`. Note the two dots in the middle of the relationship that will result in a dashed line being drawn between the two entities. But when this many-to-many relationship is resolved into two one-to-many relationships, we observe that a `NAMED-DRIVER` cannot exist without both a `PERSON` and a `CAR` - the relationships become identifying and would be specified using hyphens, which translate to a solid line: + +``` + CAR ||--o{ NAMED-DRIVER : allows + PERSON ||--o{ NAMED-DRIVER : is +``` +### Other Things + +- If you want the relationship label to be more than one word, you must use double quotes around the phrase +- If you don't want a label at all on a relationship, you must use an empty double-quoted string diff --git a/docs/flowchart.md b/docs/flowchart.md index ee4f0e130..59083fece 100644 --- a/docs/flowchart.md +++ b/docs/flowchart.md @@ -425,10 +425,10 @@ Examples of tooltip usage below: ``` ``` ``` @@ -448,28 +448,30 @@ graph LR; ``` > **Success** The tooltip functionality and the ability to link to urls are available from version 0.5.2. +?> Due to limitations with how Docsify handles JavaScript callback functions, an alternate working demo for the above code can be viewed at [this jsfiddle](https://jsfiddle.net/s37cjoau/3/). + Beginners tip, a full example using interactive links in a html context: ```
graph LR; - A-->B; - click A callback "Tooltip" - click B "http://www.github.com" "This is a link" + A-->B; + click A callback "Tooltip" + click B "http://www.github.com" "This is a link"
+