Compare commits

...

668 Commits
8.4.1 ... 8.5.1

Author SHA1 Message Date
Knut Sveidqvist
9470a4f1ed Release 8.5.1, bumped version in package.json 2020-05-17 10:04:09 +02:00
Knut Sveidqvist
9da027cf74 Fix for intersect issues for start/end state 2020-05-17 09:34:56 +02:00
Knut Sveidqvist
45e9988700 Lint fix 2020-05-16 21:59:13 +02:00
Knut Sveidqvist
1f9b4703e8 Updated url in docs to use latest version of mermaid 2020-05-16 20:00:44 +02:00
Knut Sveidqvist
c21b61bbd2 Bug fixes in new functionality, intersections not taken into account in nodes used by new graph engine. Graph flowchart not usable when integrating using mermaid.core. Incorrect flwochart docs 2020-05-16 19:58:22 +02:00
Knut Sveidqvist
0ac48a431a Merge pull request #1409 from mermaid-js/1408_mermaid_on_diet
1408 mermaid on diet
2020-05-13 19:32:56 +02:00
Knut Sveidqvist
7b15fefcaa #1408 Mocking new module in tests 2020-05-13 19:21:53 +02:00
Knut Sveidqvist
6d076284e8 #1408 Removing crypto-random-string and he 2020-05-13 19:14:18 +02:00
Knut Sveidqvist
d7d248fd04 Merge pull request #1388 from mermaid-js/1386_finetuning_rendering_engine
1386 finetuning rendering engine
2020-05-13 17:36:12 +02:00
Knut Sveidqvist
a636aa592b Merge pull request #1392 from hikerpig/feature/remove-lodash
Replace lodash with specific implementations
2020-05-13 17:34:37 +02:00
Knut Sveidqvist
1fc6603f41 Merge branch 'develop' into feature/remove-lodash 2020-05-13 17:34:26 +02:00
Knut Sveidqvist
d36a233cbf Merge pull request #1400 from markotibold/patch-1
Fix a typo; d is close to s.
2020-05-13 17:32:32 +02:00
Knut Sveidqvist
2a11f42318 Merge pull request #1401 from spopida/feature/1390_avoid_wildcard_d3_imports
Do explicit imports for d3 instead of wildcards
2020-05-13 17:31:10 +02:00
GDFaber
e23383be41 Merge pull request #1407 from zakhenry/patch-1
docs(classDiagram): typo
2020-05-13 16:46:21 +02:00
Zak Henry
36a47febc2 docs(classDiagram): typo 2020-05-13 14:57:51 +01:00
Adrian Hall
053a86c0d4 Do explicit imports for d3 instead of wildcards 2020-05-11 07:10:04 +01:00
Marko Tibold
3ded1b6c6e Fix a typo; d is close to s. 2020-05-11 07:53:47 +02:00
hikerpig
28ea68fe7f Replace lodash with specific implementations, #1389 2020-05-07 21:35:34 +08:00
Knut Sveidqvist
6203c27244 #1386 Updated docs 2020-05-06 18:58:26 +02:00
Knut Sveidqvist
57fb800c77 Merge branch 'develop' into 1386_finetuning_rendering_engine 2020-05-06 18:51:55 +02:00
Knut Sveidqvist
9a3ec31191 #1386 Adding support for click events and links 2020-05-06 18:51:12 +02:00
Knut Sveidqvist
8ef3aee7e7 Merge pull request #1384 from mapio/patch-1
Updated the mkdocs-mermaid-plugin link
2020-05-06 17:40:10 +02:00
Knut Sveidqvist
a20e6086cc #1386 Adding subroutine support for new rendering engine 2020-05-03 21:52:44 +02:00
Knut Sveidqvist
66fa8a7595 Merge branch 'develop' into 1386_finetuning_rendering_engine 2020-05-03 13:31:46 +02:00
Knut Sveidqvist
a8f9e3f0b0 #1386 Adding some docs and adjusted sizing for state diagrams 2020-05-03 13:31:09 +02:00
Massimo Santini
215905213b Updated the mkdocs-mermaid-plugin link
It appears that https://github.com/sebastienwarin/mkdocs-mermaid-plugin has been more recently updated and is more feature rich (allowing for options to override the mermaid rendering defaults).
2020-05-02 02:15:47 +02:00
Knut Sveidqvist
f8865c1413 Merge pull request #1383 from mermaid-js/1382_hiearchy_fix
#1382 Fix for lost parentage for nodes in deep structure
2020-05-01 19:32:37 +02:00
Knut Sveidqvist
67aed51742 #1382 Fix for lost parentage for nodes in deep structure 2020-05-01 19:18:07 +02:00
Knut Sveidqvist
2be2b10e59 #1334 Adding docs for user journey to side nav 2020-05-01 16:04:44 +02:00
Knut Sveidqvist
ed5e194b8e Merge branch 'master' into develop 2020-05-01 15:58:52 +02:00
Knut Sveidqvist
a6b4cb24b8 Tmo disabling of coveralls 2020-05-01 15:16:39 +02:00
Knut Sveidqvist
4276fc0b0b Merge pull request #1379 from spopida/bug/1362_NaN_rendering_ERD
Change ERD fontSize config to an integer to prevent NaN errors
2020-05-01 15:14:33 +02:00
Knut Sveidqvist
0d10957441 Merge pull request #1374 from russellgeraghty/feature/docs-fixes
Feature/docs fixes
2020-05-01 15:12:13 +02:00
Knut Sveidqvist
368720538c Merge branch 'develop' of github.com:mermaid-js/mermaid into develop 2020-05-01 15:10:50 +02:00
Adrian Hall
d068a460bd Change ERD fontSize config to an integer to prevent NaN errors 2020-04-30 15:55:14 +01:00
Russell Geraghty
346ff199c6 Updated doc link 2020-04-28 08:45:41 +01:00
Russell Geraghty
480a4a9d38 Match title to example 2020-04-28 08:42:43 +01:00
Russell Geraghty
77cfd0e1a6 Colours 2020-04-28 08:40:48 +01:00
Russell Geraghty
950af2e753 Tidy up documentation, correct rendering in test 2020-04-28 08:28:16 +01:00
Knut Sveidqvist
aa2845a730 Merge pull request #1373 from phschaer/patch-1
expanded documentation on date formats for gantt
2020-04-27 19:51:13 +02:00
Knut Sveidqvist
aedf066337 Disabling coveralls temporarilly 2020-04-27 19:50:49 +02:00
Philipp Schaer
b975cf3ed4 fixed typo in code block 2020-04-27 17:29:22 +02:00
Philipp Schaer
f2af5ce7eb updated documentation on date formatting for gantt
Rearragend the existing information and added new context information on the date formating process for Gantt charts. The former documentation was not clear on the difference between input and output formatting.
2020-04-27 17:27:03 +02:00
Knut Sveidqvist
fa612b731c Renaming some tests to diffrentiate the old implementation from the impl via the new rendering engine 2020-04-26 17:48:07 +02:00
Knut Sveidqvist
0933268e61 Merge pull request #1371 from jgreywolf/1234-RefactorClassDiagramScaling
1234 refactor class diagram scaling
2020-04-26 17:23:14 +02:00
Knut Sveidqvist
3aa5fc0cc2 Merge pull request #1365 from dany74q/feature/sequence-diagrams-improvements
Feature/sequence diagrams improvements
2020-04-26 17:21:55 +02:00
Knut Sveidqvist
397f57accb Merge pull request #1334 from russellgeraghty/feature/user-journey
Feature/user journey
2020-04-26 17:17:33 +02:00
Knut Sveidqvist
e3b1944e31 Merge pull request #1370 from mermaid-js/feature/1295_generic_rendering_engine
Feature/1295 generic rendering engine
2020-04-26 16:55:11 +02:00
Knut Sveidqvist
507582f40b #1295 Bugfix for descriptions 2020-04-26 16:01:17 +02:00
Justin Greywolf
08e015a951 1234-RefactorDiagramScaling
Changed implementation to ensure that viewport is aligned correctly, rather than increasing size
2020-04-26 06:10:18 -07:00
Justin Greywolf
ef17f4eacb 1274-adjust diagram viewbox 2020-04-26 05:51:03 -07:00
Justin Greywolf
3d185dc622 Merge pull request #20 from mermaid-js/develop
ll
2020-04-26 05:38:45 -07:00
Knut Sveidqvist
76b4b88e4b #1295 Alternating graph directions for subgraphs 2020-04-26 12:57:45 +02:00
Knut Sveidqvist
fd37edc53f #1295 Adding support for forks and joins 2020-04-26 10:07:25 +02:00
Knut Sveidqvist
5662c06a33 #1295 Adding support for multiline descriptions for states 2020-04-26 09:47:47 +02:00
Knut Sveidqvist
0aede618ec #1295 Adding support for multiline descriptions for states 2020-04-25 17:01:20 +02:00
Knut Sveidqvist
e52d4ce033 #1295 Removing invalid title for concurrency clusters 2020-04-25 14:18:23 +02:00
Knut Sveidqvist
b646672d3e #1295 Fix for statediagram labels 2020-04-25 14:12:35 +02:00
Knut Sveidqvist
a1a7d44fd7 #1295 for Multi line labels separated with \n 2020-04-25 14:12:04 +02:00
Knut Sveidqvist
25ea221a6a #1295 Rendering tests for stateDiagram v2 2020-04-25 14:11:05 +02:00
Danny Shemesh
38ee4f556e Added (& pretty-printed) sequence diagram docs
This commit adds documentation to new config variables that were
introduced as part of this PR, namely, the font settings for actors,
messages and notes.

I've also linted the markdown document.
2020-04-23 18:39:23 +03:00
Danny Shemesh
862f20ef20 Added cypress e2e tests for suggested improvements
This commits adds e2e tests for the suggested improvements.
I've went over the generated screenshots and they look good to me.
2020-04-23 18:31:22 +03:00
Danny Shemesh
5c902001b9 Merge branch 'develop' of github.com:mermaid-js/mermaid into develop 2020-04-23 17:08:25 +03:00
Danny Shemesh
5f6887b316 Sequence diagram fixes & improvements
This commit fixes some bugs, and I believe, improves upon the current
implementation.

In no particular order, it adds:

1. Control over note font size, family and alignment (now defaults to
center)
2. Dynamic actor resizing - actor's width will now scale if its
description is bigger than the static configured width
3. Dynamic actor margins - the margin between actors will now be
dynamically calculated by taking into account the width of connecting
messages or notes
4. Fixed a small visual annoyance where a loop arrow would intersect
with the text it loops on
5. Fixed a bug where if global config -> fontFamily wasn't defined, it
would override the actorFontFamily with an undefined
6. Removed some stale / commented out code
7. Added missing config variables to the global config object in mermaidAPI.js
8. Added messageFontSize, messageFontFamily to control message (non-note)
font settings
9. Memoized the actor widths in a pre-calculation that takes notes and
signals lengths into account
10. Removed redundant console.log lines
11. Extracted out actor width & margin calculation to getMaxMessageWidthPerActor, and
calculateActorMargins
2020-04-23 16:50:00 +03:00
Knut Sveidqvist
45b96bd568 Merge pull request #1364 from dany74q/feature/extract-line-break-regex
Feature/Extracted out the commonly used line break regex
2020-04-23 07:13:57 +02:00
Danny Shemesh
197d006860 Extracted out the commonly used line break regex
This commit extract the commonly used /br\s*\/?>/gi regex to common.js,
in order to keep the code more DRY.
2020-04-23 07:55:28 +03:00
Danny Shemesh
49f8aac6a9 Fixed outdated doc strings
This commit fixes some outdated docstrings, replacing the description
and @params where necessary.
2020-04-23 07:55:09 +03:00
Danny Shemesh
22dd50a047 Extracted out the commonly used line break regex
This commit extract the commonly used /br\s*\/?>/gi regex to common.js,
in order to keep the code more DRY.
2020-04-23 07:20:47 +03:00
Knut Sveidqvist
81d9b5afd6 #1295 Linting 2020-04-22 20:05:36 +02:00
Knut Sveidqvist
59f3d2a11e #1295 Fix for edges in subgraphs and handling of concurrent states in statediagram-v2 2020-04-22 20:03:41 +02:00
Adrian Hall
134a170a61 Update docs to include ER diagram descriptions 2020-04-17 14:24:44 +01:00
Adrian Hall
681f006ae1 Tiny tweaks to docs for ER diagram 2020-04-17 14:24:44 +01:00
Adrian Hall
36abfcc79b Escape the pipes in the syntax table 2020-04-17 14:24:44 +01:00
Russell Geraghty
249a14f84a Merge remote-tracking branch 'upstream/develop' into feature/user-journey 2020-04-17 07:30:53 +01:00
Knut Sveidqvist
10fdc45dea Merge pull request #1356 from mermaid-js/feature/1295_generic_rendering_engine
Feature/1295 generic rendering engine
2020-04-16 20:16:37 +02:00
Knut Sveidqvist
e8e7b419b5 #1295 Lint fixes 2020-04-16 19:57:56 +02:00
Knut Sveidqvist
955fc58773 Merge pull request #1351 from adutton/patch-1
Show source code in later examples
2020-04-16 19:50:53 +02:00
Knut Sveidqvist
2da3d83420 Merge pull request #1355 from spopida/develop
Update docs to include ER diagram descriptions
2020-04-16 19:50:05 +02:00
Knut Sveidqvist
c3f2e8dde1 #1295 Render fix for flowchart, correct marker handling and some cleanup 2020-04-16 19:44:11 +02:00
Adrian Hall
4e4c80b7fa Update docs to include ER diagram descriptions 2020-04-16 12:19:04 +01:00
GDFaber
3e776c8c41 Merge pull request #1353 from TomWright/mermaid-server
Add HTTP Server implementation to related projects.
2020-04-15 22:10:52 +02:00
Tom Wright
7c82e4b6c1 Add mermaid-server to integrations.md 2020-04-15 21:00:47 +01:00
Tom Wright
12d26d5a3d Add HTTP Server implementation to related projects. 2020-04-15 19:29:17 +01:00
Aaron Dutton
d228769b1b Show source code in later examples
The first few examples on the page show source code but the later ones didn't
2020-04-14 15:15:10 -07:00
Russell Geraghty
433f88b459 Merge remote-tracking branch 'upstream/develop' into feature/user-journey 2020-04-13 20:08:20 +01:00
Knut Sveidqvist
704d56d193 #1295 Updates mermaid-graphlib 2020-04-13 16:25:10 +02:00
Knut Sveidqvist
5f4da6e0bc Merge branch 'develop' into feature/1295_generic_rendering_engine 2020-04-11 18:53:47 +02:00
Knut Sveidqvist
0ce89d53d7 Adding ERD diagram section to the docs 2020-04-11 18:50:57 +02:00
Knut Sveidqvist
5bdffd7d20 Merge branch 'master' into develop 2020-04-11 18:10:53 +02:00
Knut Sveidqvist
5996920249 Merge branch 'release/8.5.0' 2020-04-11 18:03:42 +02:00
Knut Sveidqvist
f0119085e4 Updating mermaid to version 8.5.0 2020-04-11 18:02:05 +02:00
Knut Sveidqvist
22e17172dd #1295 Recursive rendering, draft 2020-04-11 17:16:01 +02:00
Knut Sveidqvist
6ec731e263 Merge pull request #1345 from GDFaber/feature/1343_add_flowchart_subroutine_shape
Add flowchart subroutine node shape
2020-04-11 14:12:20 +02:00
Knut Sveidqvist
7cd8b6f938 Merge pull request #1336 from GDFaber/feature/1290_hide_or_style_gantt_today_marker
#1290 Hide/style today marker in gantt diagram
2020-04-11 14:04:31 +02:00
Knut Sveidqvist
a4a19845d4 Merge pull request #1335 from GDFaber/bug/1271_fix_autonumber_position_for_multiline_texts
#1271 Fix autonumber positioning in sequence diagrams with multiline texts
2020-04-11 14:01:24 +02:00
Knut Sveidqvist
fffb0eafde Merge pull request #1332 from Soptq/stateRenderer
Add useMaxWidth to stateRenderer
2020-04-11 11:58:22 +02:00
GDFaber
10f60e2807 Merge pull request #1346 from spopida/develop
Fix docs for ER diagrams
2020-04-10 16:18:49 +02:00
Adrian Hall
3db27e6017 Tiny tweaks to docs for ER diagram 2020-04-10 11:47:29 +01:00
Adrian Hall
91b64798bb Escape the pipes in the syntax table 2020-04-10 11:40:39 +01:00
Knut Sveidqvist
8455db6fae #1295 Moving graph operations into mermaid-graplib and adding tests 2020-04-10 07:27:04 +02:00
Marc Faber
530648e937 Trigger tests once more 2020-04-10 00:28:33 +02:00
Marc Faber
7f67435cb9 #1343 Add flowchart subroutine node shape 2020-04-10 00:14:41 +02:00
Marc Faber
d8eba411ec Trigger tests once more 2020-04-05 02:29:41 +02:00
Marc Faber
dcfa903176 #1290 Hide/style today marker in gantt diagram 2020-04-05 01:59:18 +02:00
Marc Faber
fc70a8e145 #1271 Fix autonumber positioning in sequence diagrams with multiline texts 2020-04-04 21:53:31 +02:00
Russell Geraghty
e4a2d7dfb7 Updated API 2020-04-04 17:50:02 +01:00
Russell Geraghty
f081527731 User journey handler 2020-04-04 16:38:30 +01:00
GDFaber
9f8a0234aa Merge pull request #1333 from spopida/bug/1327_flowchart_cutoff
Prevent un-labelled edges that are left of the left-most vertex from being cut off the diagram
2020-04-04 05:54:32 +02:00
Knut Sveidqvist
857c860952 #1295 Lint fix 2020-04-02 19:50:21 +02:00
Knut Sveidqvist
cff68fc062 #1295 Better way of finding suitable child in cluster to point to 2020-04-02 19:48:28 +02:00
Knut Sveidqvist
365c741864 #1295 Fix for intersection calculation for edges to clusters and adding concurrency in stateDiagrams as clusters 2020-04-02 19:35:12 +02:00
Justin Greywolf
366f9db8a8 Merge pull request #19 from mermaid-js/develop
Merge into fork
2020-04-02 09:49:20 -07:00
Adrian Hall
9d5303c59d Prevent un-labelled edges that are left of the left-most vertex from being cut off the diagram 2020-04-02 15:29:12 +01:00
Soptq
c527392e21 Add useMaxWidth to stateRenderer 2020-04-01 15:12:45 +08:00
Knut Sveidqvist
933cc333cc #1295 Backwards compatability 2020-03-30 22:08:48 +02:00
Knut Sveidqvist
e72c3b2c86 #1295 Re-enabling state diagram tests 2020-03-30 21:40:14 +02:00
Knut Sveidqvist
231c849451 Merge pull request #1326 from mermaid-js/feature/1295_generic_rendering_engine
Feature/1295 generic rendering engine
2020-03-30 21:14:20 +02:00
Knut Sveidqvist
a5af248715 Merge branch 'develop' into feature/1295_generic_rendering_engine 2020-03-30 19:15:17 +02:00
Knut Sveidqvist
8fede48e7b Merge pull request #1324 from spopida/feature/1309_erDiagram_PlantUML
Feature/1309 er diagram plant uml
2020-03-30 19:11:53 +02:00
Knut Sveidqvist
d0492ec7bd Merge pull request #1323 from Pepper-Wood/bug/1294_nonfunctioning_callback_in_docs
Docs workaround for failing callback() section
2020-03-30 19:09:14 +02:00
Knut Sveidqvist
b5399202b6 Merge pull request #1307 from mermaid-js/dependabot/npm_and_yarn/acorn-5.7.4
Bump acorn from 5.7.3 to 5.7.4
2020-03-30 19:07:22 +02:00
Knut Sveidqvist
240077ffe8 #1295 Adding note support to state diagrams 2020-03-29 14:20:49 +02:00
Adrian Hall
eee9a1661f Merge branch 'develop' into feature/1309_erDiagram_PlantUML 2020-03-29 08:55:19 +01:00
Adrian Hall
9199546dca Alter ERD syntax for compatibility with PlantUML 2020-03-29 08:42:20 +01:00
Kathryn DiPippo
e0d97d44aa Docs workaround for failing callback() section 2020-03-29 00:55:14 -04:00
Knut Sveidqvist
5fbb69e7c5 #1295 Styling of composite states 2020-03-28 17:34:23 +01:00
Knut Sveidqvist
3a6aa8f820 #1295 Lint fix 2020-03-28 14:03:22 +01:00
Knut Sveidqvist
44ae5c86a7 #1295 Lint fix 2020-03-28 14:02:01 +01:00
Knut Sveidqvist
85f47e1693 #1295 Styling of start/end nodes, arrows and regular states 2020-03-28 13:59:41 +01:00
Knut Sveidqvist
9a96f8b155 Merge pull request #1315 from rmedaer/feature/multiline-sequence-message-alignment
Feature/Multiline sequence message alignment
2020-03-25 20:31:37 +01:00
Knut Sveidqvist
391dc06013 Merge branch 'develop' into feature/1295_generic_rendering_engine 2020-03-25 20:28:10 +01:00
Knut Sveidqvist
598b392878 #1295 Lint fixes 2020-03-25 20:26:53 +01:00
Knut Sveidqvist
9e75993658 Merge pull request #1314 from rmedaer/feature/multiline-sequence-message
Feature/Multiline sequence message
2020-03-25 20:22:31 +01:00
Knut Sveidqvist
159a3a3706 #1295 Start shape and handling of setting a unique start id per cluster level 2020-03-25 20:16:27 +01:00
Raphael Medaer
cbdb2e6e6f Align left/center/right multiline messages 2020-03-24 22:17:11 +01:00
Raphael Medaer
d409da2201 Multiline sequence message
This commit allow user to write multiline messages in sequence diagram.
For instance:

```
sequenceDiagram
	Alice->>+John: Hello John<br>How are you?<br>I mean...<br>Are you OK today?
	Alice->>+John: John, can you hear me?
	John-->>-Alice: Hi Alice, I can hear you!<br>Keep calm!<br>I'm there.
	John-->>-Alice: And I feel great!
```
2020-03-24 18:26:56 +01:00
Knut Sveidqvist
c7aa67b07a #1295 Lint fix 2020-03-22 23:06:32 +01:00
Knut Sveidqvist
5b302ae2e6 #1295 Applying new rendering engine for stateDiagrams 2020-03-22 21:45:14 +01:00
Knut Sveidqvist
df2925e51c #1295 Fix for edges form clusters 2020-03-22 16:08:57 +01:00
Knut Sveidqvist
02b19fed27 Merge branch 'develop' into feature/1295_generic_rendering_engine 2020-03-22 14:44:43 +01:00
Knut Sveidqvist
17f06564a2 #1295 Added the flowchart shapes 2020-03-18 22:08:19 +01:00
Knut Sveidqvist
6ddd394e33 Merge pull request #1308 from spopida/feature/117_er_diagram
Feature/117 er diagram
2020-03-18 20:32:12 +01:00
Adrian Hall
d3f78299e7 Add integration tests, basic docs, and fix multi-diagram bug 2020-03-18 16:53:26 +00:00
Adrian Hall
3e76b2374c Initial documentation for ER diagrams 2020-03-18 09:31:10 +00:00
Adrian Hall
a3b97f7c24 Remove roleB - only roleA is labelled 2020-03-17 10:16:19 +00:00
Adrian Hall
4f50e36e5b Tidy up for lint 2020-03-17 09:48:32 +00:00
Adrian Hall
a0bbbe1404 Merge branch 'develop' into feature/117_er_diagram 2020-03-17 09:28:10 +00:00
Adrian Hall
50f983871b Add labels to relationships (needs further tidy up) 2020-03-17 09:25:16 +00:00
Adrian Hall
2d3b02df6a Minor tidy up 2020-03-16 10:08:43 +00:00
Knut Sveidqvist
4010c89899 #1295 'arrow' renamed to 'arrow_point' 2020-03-16 08:02:32 +01:00
Knut Sveidqvist
215e930da4 #1295 Markers implmented, the gereric pattern and diagram specific for flowcharts. 2020-03-16 07:55:02 +01:00
Knut Sveidqvist
5b74d75011 #1295 Arrow head start 2020-03-14 18:13:34 +01:00
Knut Sveidqvist
9266eaef16 #1295 Small fix for import 2020-03-14 17:49:02 +01:00
Knut Sveidqvist
963a0ce6ef #1295 Edges between subgraphs 2020-03-14 17:38:35 +01:00
Knut Sveidqvist
5f5e453fb3 Small for for merge issue 2020-03-14 08:56:47 +01:00
Knut Sveidqvist
0cacd111df Merge branch 'develop' into feature/1295_generic_rendering_engine 2020-03-14 08:51:11 +01:00
Knut Sveidqvist
d86a7ccf3e Restoring docs README 2020-03-14 08:49:30 +01:00
Knut Sveidqvist
35ea4d1a00 Merge branch 'develop' into feature/1295_generic_rendering_engine 2020-03-14 08:44:49 +01:00
Knut Sveidqvist
10583610bd Lint fixes 2020-03-14 08:36:49 +01:00
Knut Sveidqvist
55816a09fe Merge pull request #1303 from NeilCuzon/develop
Gantt Documentation expanded.
2020-03-14 08:35:31 +01:00
Knut Sveidqvist
ad288be2ee 1295 Lint fixes 2020-03-14 08:24:45 +01:00
dependabot[bot]
c9071ff724 Bump acorn from 5.7.3 to 5.7.4
Bumps [acorn](https://github.com/acornjs/acorn) from 5.7.3 to 5.7.4.
- [Release notes](https://github.com/acornjs/acorn/releases)
- [Commits](https://github.com/acornjs/acorn/compare/5.7.3...5.7.4)

Signed-off-by: dependabot[bot] <support@github.com>
2020-03-13 23:07:17 +00:00
Neil Cuzon
96b8dce982 Update README.md 2020-03-11 18:59:06 -07:00
Adrian Hall
1e498eccb6 Change rendering algorithm 2020-03-11 22:17:11 +00:00
Knut Sveidqvist
da048cbc7b 1295 Handling labels of clusters 2020-03-11 20:25:55 +01:00
Knut Sveidqvist
7bd5529bb7 1295 Support for subgraphs with wide labels 2020-03-11 19:52:57 +01:00
Knut Sveidqvist
1b64af143e #1295 Drawing edges between nodes 2020-03-11 17:36:30 +01:00
Neil Cuzon
d2685f2544 Update README.md 2020-03-10 19:42:11 -07:00
Neil Cuzon
83c6aef078 Update README.md 2020-03-10 19:26:26 -07:00
Neil Cuzon
a9570f7298 Update README.md 2020-03-10 19:24:55 -07:00
Neil Cuzon
71e0a788d1 Update mermaidAPI.md 2020-03-10 19:16:24 -07:00
Neil Cuzon
e6910d3c52 Update SUMMARY.md 2020-03-10 19:15:44 -07:00
Neil Cuzon
9a6e4ba77f Update README.md 2020-03-10 19:14:46 -07:00
Adrian Hall
bab4649a1e Use markers with rounded crows feet 2020-03-10 13:48:53 +00:00
NeilCuzon
5a763230e5 Revert "Revert "Revert "Revert "Revert "Update README.md"""""
This reverts commit 09e6804761.
2020-03-09 23:26:00 -07:00
NeilCuzon
09e6804761 Revert "Revert "Revert "Revert "Update README.md""""
This reverts commit a414aa27b6.
2020-03-09 23:25:55 -07:00
NeilCuzon
a414aa27b6 Revert "Revert "Revert "Update README.md"""
This reverts commit c598fd9ec4.
2020-03-09 23:25:28 -07:00
NeilCuzon
c598fd9ec4 Revert "Revert "Update README.md""
This reverts commit d28e3374c7.
2020-03-09 23:25:24 -07:00
NeilCuzon
a8eeb7f76a Revert "Revert "Delete README.md""
This reverts commit c3e9ae0ca0.
2020-03-09 23:25:19 -07:00
NeilCuzon
d28e3374c7 Revert "Update README.md"
This reverts commit 71cfec91af.
2020-03-09 23:23:44 -07:00
NeilCuzon
c3e9ae0ca0 Revert "Delete README.md"
This reverts commit b085222253.
2020-03-09 23:23:27 -07:00
Neil Cuzon
71cfec91af Update README.md 2020-03-09 23:02:14 -07:00
Neil Cuzon
b085222253 Delete README.md 2020-03-09 22:55:03 -07:00
Adrian Hall
29b6e00071 clean up for eslint 2020-03-09 12:36:43 +00:00
Adrian Hall
9aacc85a16 Working experimental version using markers 2020-03-08 22:22:33 +00:00
Knut Sveidqvist
aa32d454c9 #1295 First draft of generic renderer applied to flowcharts. 2020-03-08 09:49:41 +01:00
Neil Cuzon
d3b69abd87 Update gantt.md 2020-03-07 16:54:49 -08:00
Neil Cuzon
df88300e6e Update README.md 2020-03-07 16:50:39 -08:00
Neil Cuzon
e90ed7a853 Update gantt.md 2020-03-07 16:46:59 -08:00
Neil Cuzon
fdaf13bdc4 Update gantt.md 2020-03-07 16:26:22 -08:00
Neil Cuzon
d96d40e0b0 Update gantt.md 2020-03-07 16:23:51 -08:00
Neil Cuzon
5dae0c14d9 Add files via upload 2020-03-07 16:22:55 -08:00
Neil Cuzon
5cd54c4831 Update gantt.md 2020-03-07 16:21:07 -08:00
Neil Cuzon
4caa02474c Update gantt.md 2020-03-07 16:17:11 -08:00
Neil Cuzon
005defbb5c Add files via upload 2020-03-07 16:17:03 -08:00
Adrian Hall
061045016f Minor tidy up of prototype code 2020-03-07 11:05:56 +00:00
Neil Cuzon
997353ab71 Update gantt.md 2020-03-07 00:59:39 -08:00
Neil Cuzon
1570ed4610 Update mermaidAPI.md 2020-03-05 17:34:06 -08:00
Knut Sveidqvist
25e2d78311 #1295 Start renderer 2020-03-04 20:35:59 +01:00
Adrian Hall
1e2d014ac9 Basic rendering for ER diagrams 2020-03-03 21:44:18 +00:00
Neil Cuzon
a0b1d16e79 Update SUMMARY.md 2020-03-02 16:47:08 -08:00
Adrian Hall
6985391437 Minor clean up for eslint 2020-03-02 11:46:07 +00:00
Adrian Hall
e90f58a0a7 Merge branch 'develop' into feature/117_er_diagram 2020-03-02 10:48:32 +00:00
Adrian Hall
0555fca5d8 Initial parsing logic for ER diagrams 2020-03-02 10:03:55 +00:00
GDFaber
2a55e74e11 Merge pull request #1287 from mermaid-js/revert-1281-feature/1249_BlockComments
Revert "Multiline comments" - accidentally merged
2020-02-29 21:40:55 +01:00
GDFaber
94ace2348f Revert "Multiline comments" 2020-02-29 21:32:20 +01:00
GDFaber
2b58a2a176 Merge pull request #1286 from woehrl01/patch-1
Update README.md (fix broken image link)
2020-02-29 21:29:51 +01:00
Lukas Wöhrl
7bc82365c6 Update README.md 2020-02-29 20:55:20 +01:00
Knut Sveidqvist
de11dc43ab Merge pull request #1285 from mermaid-js/bug/1269_fix_label_background_on_safari
Bug/1269 fix label background on safari
2020-02-29 15:49:23 +01:00
Knut Sveidqvist
756927b6f8 #1269 Fix for build issue - lint 2020-02-29 15:39:21 +01:00
Neil Cuzon
5693c69457 Update README.md 2020-02-29 00:07:47 -08:00
Neil Cuzon
cda41a1506 Update README.md 2020-02-29 00:04:38 -08:00
Neil Cuzon
890298457a Update README.md 2020-02-29 00:03:42 -08:00
Justin Greywolf
ccfc7351e7 Merge pull request #18 from mermaid-js/develop
Merge
2020-02-28 09:52:44 -08:00
GDFaber
df6c5dd22e Merge pull request #1282 from joebordes/patch-1
add crm/erp category with corebos in the docs
2020-02-27 18:23:29 +01:00
erelling
60f23c838b Merge pull request #1281 from mermaid-js/feature/1249_BlockComments
Multiline comments
2020-02-27 15:19:15 +01:00
Knut Sveidqvist
dcd807c49b Merge pull request #1270 from NeilCuzon/develop
Edited n00b-GettingStarted.md and smaller edits to README.md and n00b-overview.md
2020-02-27 15:06:31 +01:00
Joe Bordes
575b921a15 add crm/erp category with corebos 2020-02-27 12:59:30 +01:00
Neil Cuzon
67473f07b1 Update n00b-gettingStarted.md 2020-02-27 01:07:25 -08:00
Neil Cuzon
3aa368b630 Update n00b-gettingStarted.md 2020-02-27 01:06:38 -08:00
Neil Cuzon
4e044d66b4 Update n00b-gettingStarted.md 2020-02-27 01:05:23 -08:00
Neil Cuzon
065a5d2a47 Update n00b-overview.md 2020-02-27 00:53:20 -08:00
Neil Cuzon
5103da09c5 Update README.md 2020-02-27 00:37:24 -08:00
Neil Cuzon
33ea1d44fb Merge branch 'develop' into develop 2020-02-27 00:32:17 -08:00
Erik Ellingsen
e62027b73c Multiline comments 2020-02-27 00:02:25 +01:00
erelling
26c43667aa Suggestion in comment 2020-02-26 23:10:18 +01:00
erelling
92fbc26852 Suggestion in comment 2020-02-26 23:09:04 +01:00
erelling
a4e488a1eb Suggestion from comment 2020-02-26 23:07:11 +01:00
Knut Sveidqvist
0ee9c69ddf #1269 Work around for inaccurate bounding box results in Safari. Fix for multiple lines 2020-02-26 20:53:08 +01:00
Knut Sveidqvist
dd5e6c18d5 #1269 Work around for inaccurate bounding box results in Safari. 2020-02-26 20:01:53 +01:00
Knut Sveidqvist
737e95c3f9 Merge pull request #1278 from jgreywolf/1264-UpdatedDocumentationFoUsages
1264-Update documentation
2020-02-26 17:45:40 +01:00
Justin Greywolf
4b064dc19f 1264-Update documentation
Reorder main readme.md file, add link to integrations - and add list of areas where mermaid is used
2020-02-25 13:11:08 -08:00
Knut Sveidqvist
f2e5c913d6 Merge pull request #1275 from ginomempin/docs/add-section-parallel-blocks-for-sequence-diagrams
Add section on showing parallel blocks for sequence diagrams
2020-02-25 19:27:44 +01:00
Knut Sveidqvist
8758bd57ca Merge pull request #1274 from GDFaber/bug/apply_default_class_to_flowchart_nodes
Fix applying default class to flowchart nodes
2020-02-25 19:20:52 +01:00
Knut Sveidqvist
73e31373a8 Merge pull request #1273 from mvandermade/patch-1
Removed GitBook, add howto contribute docs.
2020-02-25 19:17:53 +01:00
GDFaber
990e620dc7 Merge pull request #1268 from jgreywolf/1169-RefactorGetRowsFunctionality
1169 refactor get rows functionality
2020-02-25 19:14:22 +01:00
Marc Faber
9103e58314 Trigger tests once more 2020-02-25 19:01:33 +01:00
Neil Cuzon
a26fe71171 Update README.md 2020-02-24 11:19:50 -08:00
Neil Cuzon
7a44e46d6d Update n00b-overview.md 2020-02-23 23:16:13 -08:00
gino
b376e4da1f docs: Fix typo "possiebl" 2020-02-24 13:51:15 +09:00
gino
f8481f8d4c docs: Fix markdown lint MD012 and MD022
MD012 Multiple Consecutive Blanks
https://github.com/DavidAnson/markdownlint/blob/master/doc/Rules.md#md012---multiple-consecutive-blank-lines

MD022 Headings should be surrounded by blank lines
https://github.com/DavidAnson/markdownlint/blob/master/doc/Rules.md#md022---headings-should-be-surrounded-by-blank-lines
2020-02-24 13:49:18 +09:00
gino
54f55cc021 #425: Add documentation on using par for sequence diagrams
Support for `par` was already added here:
https://github.com/mermaid-js/mermaid/issues/425

But is not in the docs:
https://mermaid-js.github.io/mermaid/#/sequenceDiagram
2020-02-24 13:41:47 +09:00
Marc Faber
a7a4f38d58 Trigger tests again 2020-02-24 01:43:21 +01:00
Marc Faber
d67e49400f #684 Fix applying default class to flowchart nodes 2020-02-24 01:31:39 +01:00
mvandermade
6789f2c1e3 Removed GitBook, add howto contribute docs.
Also added the online submission step-by-step via github.com.
2020-02-23 10:47:51 +01:00
NeilCuzon
e8a3ffcb41 Merge pull request #2 from NeilCuzon/NeilCuzon-patch-2
Updated noob-gettingStarted.md
2020-02-22 23:24:05 -08:00
NeilCuzon
9607c743a0 Updated noob-gettingStarted.md
updated documentation for noob-gettingStarted.md. 
-added a new screenshot and edited directions for copying markdown code from live editor
-made some alterations with the instructions in effort to make it more n00b friendly.
-added link to Atom-mermaid plugin
2020-02-22 23:20:50 -08:00
NeilCuzon
553b964ab8 Update n00b-gettingStarted.md 2020-02-22 23:11:51 -08:00
NeilCuzon
72ac408429 Update n00b-gettingStarted.md 2020-02-22 23:10:42 -08:00
NeilCuzon
8456905960 Update n00b-gettingStarted.md 2020-02-22 23:10:08 -08:00
NeilCuzon
13261c974a Update n00b-gettingStarted.md 2020-02-22 23:09:06 -08:00
NeilCuzon
eafabdce36 Update n00b-gettingStarted.md 2020-02-22 23:07:45 -08:00
NeilCuzon
d02a57744c Add files via upload 2020-02-22 23:04:33 -08:00
NeilCuzon
58374add90 Update n00b-gettingStarted.md 2020-02-22 23:03:42 -08:00
NeilCuzon
a52d501ba2 Update n00b-gettingStarted.md 2020-02-22 23:03:11 -08:00
NeilCuzon
702abbad6d Add files via upload 2020-02-22 23:01:35 -08:00
NeilCuzon
2d0edb5270 Update n00b-gettingStarted.md 2020-02-22 22:24:39 -08:00
NeilCuzon
7aab34b540 Update n00b-gettingStarted.md 2020-02-22 22:16:26 -08:00
NeilCuzon
d637a13f59 Update n00b-gettingStarted.md 2020-02-22 22:16:00 -08:00
NeilCuzon
17f99aeed8 Updated n00b-gettingStarted.md
this section had some outdated info regarding the live editor and its capabilities. 
-replaced and outdated screenshot
-edited the documentation to make it a little more n00b friendly. 
-added a link to the Atom mermaid plugin

-Neil
2020-02-22 19:21:37 -08:00
NeilCuzon
8729414da9 Merge pull request #1 from NeilCuzon/NeilCuzon-patch-1
Update README.md
2020-02-21 22:00:50 -08:00
NeilCuzon
cd8b7e5528 Update README.md
Hi, I love your program and how it reimagines the whole dynamic of creating diagrams and graphs, I also like the wit of the documentation, but I had some small trouble in initially figuring out what the application was about. 

I propose a few line changes to clarify the purpose of the application and an additional a link to the syntax section of docs to  hopefully decrease the friction and increase the interest in using the product.  
I changed:
-"__mermaid is a Javascript based diagramming and charting tool. It generates diagrams flowcharts and more, using markdown-inspired text for ease and speed.__"
and I added:
-"__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).__"


More power to you and your team.
-Neil
2020-02-21 21:11:21 -08:00
Justin Greywolf
6d74c5663f 1169- break out getRows
Moved getRows function from `state/stateRenderer.js` and `state/shapes.js` into `common/common.js`. Broke out section into small one line functions for replacing line breaks, then moved the `sanitize` function from `utils.js` to this new module as there is shared functionality
2020-02-21 13:49:05 -08:00
Justin Greywolf
5ccca5e329 Merge pull request #17 from mermaid-js/develop
Merge
2020-02-21 12:35:38 -08:00
Knut Sveidqvist
6c7b7b796e Docs updated to new version 2020-02-21 10:49:52 +01:00
Knut Sveidqvist
4ee3cea6ce Setting version to 8.4.8 2020-02-21 10:31:11 +01:00
Knut Sveidqvist
1c07e550bb Merge pull request #1267 from mermaid-js/bug/1261_removal_of_cosole.log-calls
Bug/1261 removal of console.log calls
2020-02-21 10:23:37 +01:00
Knut Sveidqvist
50c71ebb01 #1261 Removal of emojis making rendering tests give false warnings from time to time 2020-02-21 10:08:52 +01:00
Knut Sveidqvist
348d086c11 #1261 Tmp reversal of build.yml to get make release possible 2020-02-21 10:00:36 +01:00
Knut Sveidqvist
89c1853977 #1261 Removed calls to console.log 2020-02-21 09:50:04 +01:00
Knut Sveidqvist
3acff54837 Merge pull request #1260 from mermaid-js/chris579-patch-1
Build action fix
2020-02-17 17:13:25 +01:00
Christian Klemm
c7466f7a1a adj 2020-02-16 19:54:29 +01:00
Christian Klemm
6420ad9f69 Merge remote-tracking branch 'origin/chris579-patch-1' into chris579-patch-1 2020-02-16 19:47:55 +01:00
Christian Klemm
b30823d5ac mermaid upgrade 2020-02-16 19:47:14 +01:00
Christian Klemm
864472d648 Update build.yml 2020-02-16 19:41:52 +01:00
Christian Klemm
36b02ec008 adj 2020-02-16 19:32:10 +01:00
Knut Sveidqvist
aad080aa1b Merge pull request #1259 from mermaid-js/bug/1257_autonumbering
#1257 Adding the autonumber keyword + tests and docs
2020-02-16 17:13:59 +01:00
Christian Klemm
7b7a6e10f8 adj 2020-02-16 17:11:13 +01:00
Christian Klemm
aeccf92375 Update build.yml 2020-02-16 16:52:15 +01:00
Christian Klemm
f90d271739 Update build.yml 2020-02-16 16:40:43 +01:00
Christian Klemm
9c2fde940d Update build.yml 2020-02-16 16:35:59 +01:00
Christian Klemm
2b57cc6be8 Update build.yml 2020-02-16 16:31:37 +01:00
Christian Klemm
b62819e3fb Update build.yml 2020-02-16 16:26:29 +01:00
Christian Klemm
3eb5f2c65b Update build.yml 2020-02-16 16:10:47 +01:00
Christian Klemm
41be7f951c Update build.yml 2020-02-16 16:04:20 +01:00
Christian Klemm
7812fdb6ed Merge pull request #1258 from mermaid-js/actions-fix
Actions fix
2020-02-16 15:54:55 +01:00
Christian Klemm
4eeb2a0583 lockfile update 2020-02-16 15:46:45 +01:00
Knut Sveidqvist
3dd0c537ee Font update for e2e tests 2020-02-16 15:39:52 +01:00
Christian Klemm
e0aa42f695 Update package.json 2020-02-16 15:39:20 +01:00
Christian Klemm
5dddf2f757 Update build.yml 2020-02-16 15:38:52 +01:00
Knut Sveidqvist
f8137ea7c1 #1257 Adding the autonumber keyword + tests and docs 2020-02-16 15:26:08 +01:00
Knut Sveidqvist
cf6f1a083e Upgarding version in docs 2020-02-16 14:19:27 +01:00
Knut Sveidqvist
f9cfeacc67 Version bump 2020-02-16 13:56:37 +01:00
Knut Sveidqvist
98229a47b2 Renabling build for node 10 2020-02-16 12:46:23 +01:00
Knut Sveidqvist
530ace1507 Disabling e2e tests in github actions 2020-02-16 12:39:05 +01:00
Knut Sveidqvist
792c657ff2 Modified build.yml 2020-02-16 09:42:57 +01:00
Knut Sveidqvist
5aa07439a8 Modified build.yml 2020-02-16 09:40:35 +01:00
Knut Sveidqvist
bf2862f164 Updated packages 2020-02-16 09:30:08 +01:00
Knut Sveidqvist
d9ef227435 Updated packages, trying to fix e2e tests in build 2020-02-16 09:17:17 +01:00
Knut Sveidqvist
324c845dc4 Disabling Static tests action due to issues with cypress 2020-02-16 09:06:05 +01:00
Knut Sveidqvist
5d0c44e84b Adding @babel/preset-env inorder to help build action 2020-02-16 08:54:17 +01:00
GDFaber
01a71c3dbb Merge pull request #1254 from xbojch/patch-1
Typos
2020-02-15 23:54:05 +01:00
Bojan Bedrac
b018f026e3 Typo
- fixes a typo
2020-02-13 15:51:00 +01:00
Knut Sveidqvist
0a38e3557d Merge pull request #1248 from DCsunset/bug/1247_ssr_error
Bug/1247 Fix "window is not defined" with ssr
2020-02-11 07:02:50 +01:00
DCsunset
6f450272b8 #1247 fix "window is not defined" with ssr 2020-02-06 20:26:09 -08:00
Knut Sveidqvist
7e01f9be6e Merge pull request #1245 from mermaid-js/feature/1224_styling_of_subgraphs
Feature/1224 styling of subgraphs
2020-02-05 20:06:22 +01:00
Knut Sveidqvist
00d2a1fe9f Merge branch 'develop' of github.com:mermaid-js/mermaid into develop 2020-02-05 19:42:13 +01:00
Knut Sveidqvist
18d0d435c6 Merge pull request #1241 from jgreywolf/1240-ClassDiagramRefactor
1240 class diagram refactor
2020-02-05 19:42:01 +01:00
Knut Sveidqvist
f298c154e2 Merge branch 'develop' of github.com:mermaid-js/mermaid into develop 2020-02-05 19:40:18 +01:00
Knut Sveidqvist
822df37f8c #1224 Possibility to style text color of nodes and subgraphs as well as apply classes to subgraphs 2020-02-05 19:39:50 +01:00
Knut Sveidqvist
73cac95255 Merge pull request #1238 from GDFaber/feature/962_flowchart_line_label_color_from_linkstyle
Set text color for flowchart link labels according to linkStyle definitions
2020-02-05 19:36:12 +01:00
Marc Faber
a0e7789d50 #962 added color setting for default link style 2020-02-04 22:07:10 +01:00
Justin Greywolf
c825b37cc6 1240-refactor for class renderer
prep for future functionality work
2020-02-03 16:04:59 -08:00
Marc Faber
2dd4aa31e5 #962 moved "style from array" function to utils.js, added unit test 2020-02-04 00:24:50 +01:00
Marc Faber
c95adfaf74 #962 Set text color for flowchart link labels according to linkStyle definitions 2020-02-02 22:59:59 +01:00
Justin Greywolf
9da8ea5967 Merge pull request #16 from mermaid-js/develop
Merge from parent
2020-01-30 10:20:14 -08:00
Knut Sveidqvist
4d5ecc5518 Merge pull request #1203 from jgreywolf/1179-SupportGenericTypesForMembers
1179 support generic types for members
2020-01-29 21:08:41 +01:00
Knut Sveidqvist
963a0fcd77 Merge branch 'develop' into 1179-SupportGenericTypesForMembers 2020-01-29 21:08:31 +01:00
Ashish Jain
fbd8dfa5be Merge pull request #1230 from mermaid-js/bug/1223_multiple_transitions_in_statediagram
Bug/1223 multiple transitions in statediagram
2020-01-29 21:02:14 +01:00
Knut Sveidqvist
c43f791b29 #1223 Removing/updating some logging, adding current.html to .gitignore 2020-01-29 20:44:15 +01:00
Ashish Jain
39b873cd5f Merge pull request #1229 from mermaid-js/bug/1217_fix_for_keyword_as_in_stateDiagram
#1217 Better matching of words beginning with as as matching token
2020-01-29 20:24:28 +01:00
Knut Sveidqvist
ec90537181 #1223 Adding support for multiple transitions to a node from another node 2020-01-29 20:01:21 +01:00
Knut Sveidqvist
4709195a1d #1223 Adding support for multiple transitions to a node from another node 2020-01-29 19:57:59 +01:00
Knut Sveidqvist
0082c23a90 #1217 Better matchingof words beginning with as as matching token AS in stateDiagram's state definition. 2020-01-29 19:05:51 +01:00
Knut Sveidqvist
c7b559f449 Update todo.md 2020-01-27 20:28:43 +01:00
Knut Sveidqvist
d571c7e08e Merge pull request #1225 from jgreywolf/1058-ClassDiagramScaling
1058 class diagram scaling
2020-01-27 20:14:39 +01:00
Knut Sveidqvist
b6f0b25f24 Merge pull request #1222 from GDFaber/bug/1218_fix_link_click_events
Fix anchor and script support in link click events
2020-01-27 20:13:07 +01:00
Knut Sveidqvist
5ea6bd5980 Merge branch 'develop' into bug/1218_fix_link_click_events 2020-01-27 20:06:00 +01:00
Knut Sveidqvist
ea29b67c5c Merge pull request #1221 from mermaid-js/bug/1216_dodging_huge_diagrams
#1216 Fix for issue when mermaid freezes the browser tab due to large…
2020-01-27 20:01:54 +01:00
Knut Sveidqvist
1f851bc04c Merge pull request #1219 from GDFaber/feature/487_flowchart_node_text_color_from_style
#487 Set text color for flowchart nodes according to style definitions
2020-01-27 20:01:19 +01:00
Justin Greywolf
0921007d92 1058-Set diagram dimensions appropriately
Make sure height and width are set so that all of the diagram is displayed
2020-01-27 10:27:05 -08:00
Justin Greywolf
4a2e0bfa00 Merge branch 'develop' into 1179-SupportGenericTypesForMembers 2020-01-27 09:44:12 -08:00
Justin Greywolf
8ebc587fb5 Merge pull request #15 from mermaid-js/develop
Merge from parent
2020-01-27 09:43:46 -08:00
Marc Faber
c7b46f4fba #1218 Fix anchor and script support in link click events 2020-01-26 16:56:42 +01:00
Knut Sveidqvist
4ad354a561 #1216 Fix for issue when mermaid freezes the browser tab due to large diagrams 2020-01-25 13:35:11 +01:00
Justin Greywolf
587592449a 1179 Add ability to use generics for members
Created new class to handle parsing of members with regex to handle determining type of member and the different elements within.  Also moved addTSpan in drawClass method to this new file.  Finally, I added a "catch all" section in case something fails in the regex to make sure everything gets formatted correctly.

Added more tests and documentation

updating gitignore

Tired of constantly having to ignore files and stash/pop when switching between branches
2020-01-24 16:01:04 -08:00
Justin Greywolf
425b071a50 Merge pull request #14 from mermaid-js/develop
merge from
2020-01-24 15:58:42 -08:00
Marc Faber
4dd72e6793 Trigger tests again 2020-01-24 01:42:46 +01:00
Marc Faber
d2d4a24229 #487 Set text color for flowchart nodes according to style definitions 2020-01-24 01:24:47 +01:00
Knut Sveidqvist
4805394e61 New version in the docs 2020-01-22 19:22:37 +01:00
Knut Sveidqvist
5cbd723f8d Merge branch 'release/8.4.6' 2020-01-22 19:07:20 +01:00
Knut Sveidqvist
28153656d7 Updated docs with info on chaining of nodes and using ::: to attach a class 2020-01-22 18:52:16 +01:00
Knut Sveidqvist
d2eaf16751 Updating version to 8.4.6 2020-01-22 18:33:33 +01:00
Knut Sveidqvist
e0d98b2e14 Merge pull request #1214 from GDFaber/bug/1212_apply_classDef_to_flowchart_nodes_with_links
Fix styling of flowchart nodes with links when class definitions are assigned
2020-01-22 17:59:53 +01:00
Marc Faber
c38f053294 #1212 Class definition is not applied to flowchart nodes with links 2020-01-19 18:10:14 +01:00
Knut Sveidqvist
921d274579 Merge pull request #1208 from mermaid-js/feature/Issue-1206_Parsing_Crashing_Browser_In_Class_Diagram
Feature/issue 1206 parsing crashing browser in class diagram
2020-01-15 20:55:21 +01:00
Ashish Jain
c9f95a1866 Merge pull request #1207 from mermaid-js/bug/1205_activations_error
#1205 Adding parsing exception for then an inactive participant is inactivated
2020-01-15 20:48:36 +01:00
Ashish Jain
99469f8404 #1206 Added test case to verify parsing fails to allow EOF until first '{' is closed 2020-01-15 20:34:41 +01:00
Ashish Jain
417d2c0336 #1206 Added test case to verify parsing fails to allow another '{' until first one is closed 2020-01-15 20:33:23 +01:00
Ashish Jain
2a3de1a090 #1206 Updated the classDiagram JISON to not allow EOF or another '{' until first one is closed 2020-01-15 20:29:13 +01:00
Knut Sveidqvist
d9318c5af3 #1205 Adding parsing exception for then an inactive participant is inactivated 2020-01-15 20:27:31 +01:00
Justin Greywolf
0e02cf5c86 Merge pull request #1195 from fgrandel/bug/1193_allow_multiple_relations
fix(#1193): render multiple relations
2020-01-15 09:29:02 -08:00
Knut Sveidqvist
45277affe8 Merge pull request #1204 from GDFaber/bug/1196_keep_flowchart_label_text_when_style_is_applied
Keep flowchart node label text (if already defined) when a style is applied
2020-01-15 18:27:48 +01:00
Knut Sveidqvist
c564a843fa Merge pull request #1202 from GDFaber/bug/1200_unify_regex_for_br_tags
Unify regex for finding <br> tags throughout mermaid
2020-01-15 16:53:06 +01:00
Knut Sveidqvist
efa810da91 Merge pull request #1199 from GDFaber/bug/fix_mermaidAPI_configuration_example_in_the_docs
Fix mermaidAPI configuration example in the docs
2020-01-15 16:50:11 +01:00
Knut Sveidqvist
c0e1c90497 Merge pull request #1198 from GDFaber/bug/add_docs_and_defaults_for_node_spacing
Add docs and default values for node spacing in mermaidAPI
2020-01-15 16:48:58 +01:00
Marc Faber
b1bfdec473 #1196 Keep flowchart node label text (if already defined) when a style is applied 2020-01-14 23:37:30 +01:00
Justin Greywolf
244f423baf Merge pull request #1194 from fgrandel/bug/1192_relation_cut_off
fix(#1192): relation got cut off
2020-01-14 09:35:00 -08:00
Justin Greywolf
8897b32cd3 Merge pull request #13 from mermaid-js/develop
sync
2020-01-13 16:01:40 -08:00
Marc Faber
5493fadc9e #1200 Unify regex for finding <br> tags throughout mermaid 2020-01-13 22:04:47 +01:00
Knut Sveidqvist
eade3d0a2d Merge pull request #1178 from jgreywolf/1119-SpecifyMethodReturnTypeInClassDiagram
1119 specify method return type in class diagram
2020-01-13 19:55:47 +01:00
Marc Faber
36f9eca33e Example 2 is not shown in mermaidAPI configuration section of the docs 2020-01-12 14:38:57 +01:00
Marc Faber
4dd90e56b1 Add docs and default values for node spacing in mermaidAPI 2020-01-12 14:09:24 +01:00
Knut Sveidqvist
5e7484a12d Update mermaidAPI.md 2020-01-12 01:04:15 -08:00
Knut Sveidqvist
fdbc44e41b Update mermaidAPI.md 2020-01-12 01:03:46 -08:00
Knut Sveidqvist
e0d16dcb22 Version 8.4.5 2020-01-11 10:07:41 +01:00
Knut Sveidqvist
0a5ee0634f Merge branch 'master' of github.com:mermaid-js/mermaid
# Conflicts:
#	docs/classDiagram.md
2020-01-11 09:47:51 +01:00
Justin Greywolf
fa1331ffd5 Fix after removing other code 2020-01-10 10:24:04 -08:00
Justin Greywolf
57b5b9a7a6 Added conditional to fallback to old style 2020-01-10 09:50:21 -08:00
Justin Greywolf
58fbfc3c38 1119 Support method return types
Small refactor to split out logic for determining method display text and style. Updated documentation
Used regex to parse method statements in class diagrams to extract discrete elements to set display appropriately. Added tests and updated docs
2020-01-10 09:50:21 -08:00
Justin Greywolf
0af5e0b795 Address code style issues 2020-01-10 09:50:21 -08:00
Justin Greywolf
d7771eb4b6 1119 Add ability to define return type for methods
Updated ClassRenderer to check for `[]` to indicate return type for method. Small refactor to split out logic for determining method display text and style. Updated documentation
2020-01-10 09:50:21 -08:00
Justin Greywolf
fc0902c290 Merge pull request #12 from mermaid-js/develop
sync
2020-01-10 09:47:16 -08:00
Florian Grandel
75890f88fa fix(#1193): render multiple relations 2020-01-09 17:00:34 +01:00
Florian Grandel
9a6b07e1e1 fix(#1192): relation got cut off 2020-01-09 16:24:47 +01:00
Knut Sveidqvist
ce02d1dc98 Merge pull request #1190 from mermaid-js/Issue-1092_Mangled_Multiple_Class_Diagrams
#1092 Fix for mangling of multiple classDiagrams
2020-01-08 21:05:42 +01:00
Knut Sveidqvist
7760e63b47 Merge pull request #1189 from GDFaber/maintenance/1182_flowchart_remove_newDagreD3
Maintenance/Remove "newDagreD3" switch from the flowchart renderer
2020-01-08 20:56:54 +01:00
Christian Klemm
a483f2466f added artifact to build action 2020-01-08 20:52:39 +01:00
Ashish Jain
48c345a403 #1092 Fix for mangling of multiple classDiagrams 2020-01-08 20:48:57 +01:00
Marc Faber
82b79aa332 Trigger tests once more 2020-01-08 20:42:58 +01:00
Marc Faber
ffbf9f265f #1182: remove "newDagreD3" switch from the flowchart renderer 2020-01-08 20:27:33 +01:00
Knut Sveidqvist
144f65c459 Merge pull request #1176 from GDFaber/feature/1152_flowchart_node_spacing
Feature/Add node spacing to flowchart configuration
2020-01-08 18:16:03 +01:00
Ashish Jain
18204586e1 Merge pull request #1188 from GDFaber/feature/743_gantt_multiline_section_titles
Feature/Handle multiline section titles in gantt diagrams
2020-01-08 18:06:29 +01:00
Marc Faber
1f3c970e7a Trigger tests once more 2020-01-08 14:03:16 +01:00
Marc Faber
1cfd93640c #743 handle multiline section titles in gantt diagrams 2020-01-08 13:50:58 +01:00
Marc Faber
553ea4971f Trigger tests one more time 2020-01-07 01:24:24 +01:00
Justin Greywolf
ac8b01a94c Merge pull request #11 from mermaid-js/develop
sync
2020-01-06 10:08:43 -08:00
Marc Faber
b3934c9788 #1152 add node spacing to flowchart configuration 2020-01-05 22:03:53 +01:00
Knut Sveidqvist
37ae863443 Merge pull request #1170 from jgreywolf/1064-ClickEventInClassDiagram
1064 click event in class diagram
2020-01-05 12:07:34 +01:00
Knut Sveidqvist
f57356006d Merge pull request #1171 from mermaid-js/feature/Issue-1146_Dashed_Line_For_Class_Diagram
Feature/issue 1146 dashed line for class diagram
2020-01-05 12:02:36 +01:00
Justin Greywolf
591a104c80 1064 Class diagram interactivity docs
Updated documentation for Class Diagram with details for interactivity
2020-01-03 10:14:07 -08:00
Justin Greywolf
38097c9095 code style 2020-01-02 11:27:56 -08:00
Justin Greywolf
7f31e624ca Addressing code style issues 2020-01-02 11:24:06 -08:00
Justin Greywolf
e6fbfcb1e8 1064 Adding tooltip and function calls to click evens in class diagrams 2020-01-02 11:06:29 -08:00
Justin Greywolf
00687f21cd Merge pull request #10 from mermaid-js/develop
sync fork
2020-01-02 11:05:54 -08:00
Ashish Jain
96fc0d043e #1146 Added cypress test for dash line (dependecy) rendering 2020-01-02 19:57:11 +01:00
Ashish Jain
190353785e #1146 Added jest test for dash line (dependecy) parsing 2020-01-02 19:51:25 +01:00
Ashish Jain
f54adb4a3e #1146 Updated classDiagram documentation with new relation types 2020-01-02 19:35:22 +01:00
Ashish Jain
f2a5d92398 #1146 Added stroke-dasharray style for Dependency relation 2020-01-02 19:29:17 +01:00
Ashish Jain
b14c768fa2 #1146 Fix for dashed line (Dependency) support for classDiagram 2020-01-02 19:25:31 +01:00
Ashish Jain
851d2f2d91 Merge pull request #1168 from mermaid-js/feature/834_linking_to_multiple_nodes
#834 Using & as a separator for the multiple nodes
2020-01-02 19:13:22 +01:00
Knut Sveidqvist
4e6aad5115 #834 Using & as a separator for the multiple nodes 2020-01-02 18:52:50 +01:00
Knut Sveidqvist
7bd1408de0 Merge pull request #1165 from jgreywolf/1064-ClickEventInClassDiagram
1064 click event in class diagram
2020-01-02 08:10:48 -08:00
Justin Greywolf
d63eb396e1 Fix code style issues 2020-01-02 07:59:36 -08:00
Knut Sveidqvist
465e99ab5d Merge pull request #1167 from mermaid-js/feature/921_adding_interaction_tests
Adding interaction tests for gantt callbacks with arguments
2020-01-01 03:41:14 -08:00
Knut Sveidqvist
33916cfbd3 Adding interaction tests for gantt callbacks with arguments 2020-01-01 12:03:29 -08:00
Knut Sveidqvist
a1626927cc Merge pull request #1136 from keenanjt33/feature/921_callback_params
Gantt: Add support for callback with parameters
2020-01-01 00:29:00 -08:00
Knut Sveidqvist
75e2abe242 Merge pull request #1166 from GDFaber/feature/flowchart_add_cylindric_shape
#1154 Flow diagram DB shape request
2020-01-01 00:24:56 -08:00
Knut Sveidqvist
2db8075e3f Merge pull request #1163 from GDFaber/bug/891_make_link_clickable_on_the_entire_node
Bug/Clicking on a link only works directly on the node text
2019-12-31 07:58:47 -08:00
Knut Sveidqvist
413876644c Merge pull request #1162 from sdankel/bug/1060_date_infinite_loop
Fix infinite loop caused by date iteration
2019-12-31 07:57:16 -08:00
Knut Sveidqvist
d5e9f2e23e Merge pull request #1156 from gene1wood/extend_br_tag_regex
Extend the `br` tag regex
2019-12-31 07:56:21 -08:00
Marc Faber
bc59d015e6 #1154 Flow diagram DB shape request 2019-12-31 16:30:03 +01:00
Justin Greywolf
2decf94ad0 1064- Add click functionality to class diagrams
modified interaction functionality from flowcharts to work with class diagrams
2019-12-30 17:27:20 -08:00
Justin Greywolf
b52744ae18 Merge pull request #9 from mermaid-js/develop
update fork
2019-12-30 17:26:40 -08:00
Knut Sveidqvist
6cbbf0af2f Merge pull request #1159 from DavertMik/develop
Check tests on PR
2019-12-29 08:47:08 +01:00
Christian Klemm
5d7ef149aa Merge pull request #1161 from wfnuser/fix/typos-in-flowDb
Error typos in flowDb
2019-12-26 16:26:02 +01:00
Marc Faber
7ce0974767 #891 Clicking on a link only works directly on the node text 2019-12-26 15:38:53 +01:00
Sophie Dankel
7b12c7a07d Fix infinite loop caused by date iteration 2019-12-24 19:01:29 -08:00
Christian Klemm
728e3fd2f0 Added task list to pull request template 2019-12-24 23:37:18 +01:00
wfnuser
4eedeebd46 other/typos in flowDb 2019-12-24 16:14:42 +08:00
Michael Bodnarchuk
85fb12155b Create checks.yml (#1)
* Create checks.yml

* Update checks.yml
2019-12-24 00:08:38 +02:00
Justin Greywolf
f99daa696e Merge pull request #8 from mermaid-js/develop
merge from base
2019-12-23 12:21:44 -08:00
Gene Wood
b4f9dd46a9 Add tests for <br \t> case
This adds tests for the case where
* multiple pieces of whitespace are used
* one of those whitespace characters is a tab
2019-12-23 08:52:15 -08:00
Nacho
ffe16f89bb Merge pull request #1157
Fix mispelling
2019-12-23 11:33:49 -05:00
Gene Wood
7604d92d5c Fix mispelling 2019-12-23 08:11:47 -08:00
Gene Wood
3abd77a1e6 Extend the br tag regex
This extends the `br` tag regex to accommodate an arbitrary amount of
any type of whitespace instead of a single space character, which holds
more closely to the HTML spec[1]

This extends the fix to #702 added in #1153

[1]: http://www.w3.org/TR/REC-xml/#sec-starttags
2019-12-23 08:02:11 -08:00
Knut Sveidqvist
d96b79a9ba Merge pull request #1153 from GDFaber/bug/702_br_tags_in_sequence_diagrams
Bug/702 br tags in sequence diagrams
2019-12-23 10:04:30 +01:00
Knut Sveidqvist
14bb888c21 Merge pull request #1151 from Progressive-Insurance/bug/git-graph-clear
Git graph not clearing
2019-12-23 10:03:16 +01:00
Knut Sveidqvist
c8f59ea1a7 Merge pull request #1140 from jdavis61/docs/1124_incorrect_include
Removed docs reference to mermaidAPI.js
2019-12-23 08:56:40 +01:00
Marc Faber
233520b797 #702 improve handling of different "br" tag notations for multiline texts in sequence diagrams 2019-12-21 20:39:32 +01:00
GDFaber
061d31af33 Merge pull request #6 from mermaid-js/develop
sync fork
2019-12-21 00:02:01 +01:00
Matthew Schott
ec742d3180 fix git graph not clearing 2019-12-20 14:48:36 -05:00
Nacho
1bc62cfba4 Merge pull request #1150 2019-12-19 13:45:21 -05:00
erinleck@gmail.com
028d9a2667 changes tick contrast for gantt chart 2019-12-19 09:52:46 -07:00
Knut Sveidqvist
d53e00ffe0 Change of broken docs 2019-12-18 19:43:35 +01:00
Knut Sveidqvist
b90fcc1b71 test commit 2019-12-18 19:40:50 +01:00
Knut Sveidqvist
a4e7305d52 #834 Adding unit tests and rendering tests 2019-12-18 19:13:56 +01:00
Knut Sveidqvist
a3378f8d03 Merge pull request #1149 from mermaid-js/other/1143_utilze_browser_console_object_better
#1143 Adding support in grammar for multiple nodes in dependency decl…
2019-12-18 18:41:45 +01:00
Knut Sveidqvist
5716d163ec Merge branch 'develop' into other/1143_utilze_browser_console_object_better 2019-12-18 18:41:14 +01:00
Knut Sveidqvist
42ef035241 #834 Using space as separator, simplfifying the grammar some more, reomving some logging 2019-12-18 18:36:34 +01:00
Knut Sveidqvist
b6157195b3 Merge pull request #1148 from mermaid-js/other/1142_simplify_flowshart_grammar
#1142 Simplified arrows/edges in the grammar
2019-12-18 18:12:55 +01:00
GDFaber
b8ee68034d Merge pull request #5 from mermaid-js/develop
fork sync
2019-12-16 17:18:15 +01:00
Knut Sveidqvist
6598b1b10d #1143 Adding support in grammar for multiple nodes in dependency declarations 2019-12-15 18:10:52 +01:00
Knut Sveidqvist
4ff4058244 #1142 Simplified arrows/edges in the grammar 2019-12-15 13:34:35 +01:00
Knut Sveidqvist
dddd5af830 Merge pull request #1144 from mermaid-js/other/1143_utilze_browser_console_object_better
#1143 Fixing up the color output of the logger
2019-12-15 10:09:27 +01:00
Knut Sveidqvist
26fac9507e #1143 Fixing up the color putput of the logger 2019-12-15 09:50:24 +01:00
GDFaber
1f1c9698ce Merge pull request #4 from mermaid-js/develop
sync my fork
2019-12-15 02:18:38 +01:00
GitHub actions
56f7459617 Release 8.4.4 2019-12-14 08:50:41 +00:00
GitHub actions
86604b5de1 Bump version 8.4.4 2019-12-14 08:50:41 +00:00
Knut Sveidqvist
0544dbe891 Merge branch 'master' into develop 2019-12-14 09:27:38 +01:00
Knut Sveidqvist
6365cea0b2 Upgrading docs to 8.4.4 2019-12-14 09:26:21 +01:00
Knut Sveidqvist
7fef13346e Bumping version to 8.4.4 2019-12-14 09:00:53 +01:00
Knut Sveidqvist
81216e6ece Merge branch 'release/8.4.4' 2019-12-14 08:52:40 +01:00
James Davis
1d0b305332 Readded call to mermaidAPI in docs 2019-12-12 22:25:07 -05:00
James Davis
c10ccc011f Removed reference to mermaidAPI.js 2019-12-12 07:47:36 -05:00
Christian Klemm
3fe7995060 Merge pull request #1137 from mermaid-js/master
Master sync
2019-12-12 01:30:51 +01:00
Knut Sveidqvist
c441d04e8a Merge branch 'itprdev-issue-552' into develop 2019-12-11 21:31:33 +01:00
Knut Sveidqvist
52d84a99ac #552 Adding docs 2019-12-11 21:28:07 +01:00
Knut Sveidqvist
fcf20215a6 #552 Adding rendering test 2019-12-11 21:12:48 +01:00
Knut Sveidqvist
aa2f9622f8 Merge branch 'issue-552' of https://github.com/itprdev/mermaid into itprdev-issue-552 2019-12-11 21:10:11 +01:00
Knut Sveidqvist
1811318dea #1088 Adding rendering tests 2019-12-11 20:17:51 +01:00
Knut Sveidqvist
5eb50cb2b6 Merge pull request #1132 from GDFaber/develop_Bugfixes_linkStyle_910_1088
Flow: Bugfixes for link style
2019-12-11 20:04:32 +01:00
Knut Sveidqvist
f6ef6ff7db Merge pull request #1130 from GDFaber/develop
Flow: Add stadium shape for nodes
2019-12-11 19:48:47 +01:00
Knut Sveidqvist
2f33a80e1e Merge pull request #1131 from jgreywolf/1104(b)-SupportForAbstractMethodInClassDiagram
Class: Support for abstract methods
2019-12-11 19:43:32 +01:00
Justin Greywolf
363d49b655 Renumber render tests 2019-12-11 10:34:51 -08:00
Justin Greywolf
de8c6d5572 Merge branch 'develop' into 1104(b)-SupportForAbstractMethodInClassDiagram 2019-12-11 10:31:27 -08:00
Justin Greywolf
9406bda93d Merge pull request #7 from mermaid-js/develop
update fork
2019-12-11 10:24:17 -08:00
Knut Sveidqvist
d17a447a5f Merge pull request #1128 from mermaid-js/bug/1123_Upgrade_serialize-javascript
#1127 Ugrading of webpack and adding newer terser-webpack-plugin
2019-12-11 19:18:45 +01:00
Knut Sveidqvist
5b4e95484e Merge pull request #1120 from jgreywolf/1063-GenericTypeSupportInClassDiagrams
Class: Generic type support
2019-12-11 19:09:19 +01:00
Knut Sveidqvist
bebea41e19 Merge pull request #1121 from mermaid-js/pr_template
Add pull request template
2019-12-11 19:04:29 +01:00
Keenan Tullis
442474fc44 Merge branch 'develop' of https://github.com/mermaid-js/mermaid into feature/921_callback_params 2019-12-10 19:13:02 -05:00
Keenan Tullis
0d9112a4c1 Adds basic documentation for interaction with gantt 2019-12-10 19:04:42 -05:00
Keenan Tullis
d504e00e18 Adds simple tests for parsing callbacks wrt args 2019-12-10 18:27:06 -05:00
Justin Greywolf
74c8e7fad9 another style fix 2019-12-10 15:21:25 -08:00
Justin Greywolf
4b781d3827 remove extra space 2019-12-10 15:18:26 -08:00
Justin Greywolf
9fbcc5c32d Code style fix 2019-12-10 15:12:37 -08:00
Keenan Tullis
c7ec8190fb Gantt callback: default to node id as callback arg 2019-12-10 15:25:28 -05:00
Christian Klemm
b73a6d84ee Set release drafter sorting direction 2019-12-10 20:52:00 +01:00
Justin Greywolf
2eaa7f1ab6 Generic Type support for classes
Fixed typos after refactor
2019-12-10 11:39:25 -08:00
Marc Faber
608445e64f #910 set correct position and style for edge labels when using linkStyle, #1088 handle multiline texts in edge labels when using linkStyle 2019-12-10 03:51:37 +01:00
Marc Faber
1f4be77662 Revert "#910 set correct position and style for edge labels when using linkStyle, #1088 handle multiline texts in edge labels when using linkStyle" - Sorry, forgot to push to a new branch.
This reverts commit 0deae4abf9.
2019-12-10 03:48:12 +01:00
Marc Faber
0deae4abf9 #910 set correct position and style for edge labels when using linkStyle, #1088 handle multiline texts in edge labels when using linkStyle 2019-12-10 03:34:40 +01:00
Justin Greywolf
5b2f9351c7 Add support for abstract methods
Added logic to allow rendering of a method name with italics or underline based on modifier at beginning of name to set css style
2019-12-09 18:13:06 -08:00
Justin Greywolf
6fdf30357c 1104-Add support to designate a method as abstract
Added logic to allow rendering of a method name with italics or underline based on modifier at beginning of name to set css style
2019-12-09 17:41:26 -08:00
Justin Greywolf
cf5d7478fc Merge pull request #6 from mermaid-js/develop
Merge
2019-12-09 11:42:26 -08:00
Marc Faber
9a0df5afb0 #723 Add stadium shape for flowchart nodes 2019-12-08 16:51:47 +01:00
GDFaber
813b2fcb38 Merge pull request #3 from mermaid-js/develop
sync develop branch
2019-12-08 16:43:28 +01:00
Christian Klemm
08cbc0f187 Merge pull request #1129 from mermaid-js/master
Master sync
2019-12-08 13:14:32 +01:00
Knut Sveidqvist
d8251c8f79 Merge pull request #1126 from mermaid-js/bug/935_styling_of_dotted_think_links
#935 Fix for stylink of links. Default theme colors are picked up and…
2019-12-08 10:51:28 +01:00
Knut Sveidqvist
5ea70baa6f #1127 Ugrading of webpack and adding newer terser-webpack-plugin 2019-12-08 10:42:41 +01:00
Knut Sveidqvist
d23ce9fb63 #935 Fix for stylink of links. Default theme colors are picked up and styling via themeCSS works 2019-12-08 10:10:03 +01:00
Knut Sveidqvist
ddf8016a0c Merge pull request #1125 from mermaid-js/bug/903_flochart_escaping_in_non_html_mode
Bug/903 flowchart escaping in non html mode
2019-12-08 09:57:48 +01:00
Knut Sveidqvist
ab191abd5a #903 Fix for broken build 2019-12-07 15:06:44 +01:00
Knut Sveidqvist
c2e5e94b37 #903 Allowing >,< and = characters in svg. Updating xss tests to handle both htmlLabels and non htmlLabels 2019-12-07 12:19:45 +01:00
Justin Greywolf
6a9b251be1 Fix code style errors 2019-12-06 20:35:22 -08:00
Christian Klemm
6b5185abfb Create pull_request_template.md 2019-12-06 21:41:16 +01:00
Justin Greywolf
2a41280076 Add support for Generic class definitions
Added support in parser to translate characters surrounded by `~` into generic type definition ie: `Class01~T~` would turn into `Class01<T>`
2019-12-05 12:59:22 -08:00
Justin Greywolf
91d986970b Merge pull request #5 from mermaid-js/develop
Develop
2019-12-05 12:58:48 -08:00
Christian Klemm
b4192bba7a Added skip changelog label to release drafter 2019-12-04 19:35:25 +01:00
Knut Sveidqvist
9fe0aa0604 Merge pull request #1116 from mermaid-js/bug/1110_state_diagram_rendering_composit_state
Bug/1110 state diagram rendering composit state
2019-12-04 19:15:06 +01:00
Knut Sveidqvist
fc528749f8 Merge pull request #1114 from mermaid-js/feature/1112_revert_offical_dagre_d3
Feature/1112 Revert to offical dagre d3
2019-12-04 19:14:35 +01:00
Knut Sveidqvist
5c71a3c85b #1110 Fix for transparent rect under edge title, was misaligned 2019-12-04 18:20:28 +01:00
Knut Sveidqvist
94e768dd01 #1110 Cleanup and removal of loggings 2019-12-04 18:04:56 +01:00
Knut Sveidqvist
0fb91d6bcc #1110 Fixing height issue 2019-12-03 23:38:51 +01:00
Knut Sveidqvist
02854881b4 #1110 Zoom in a bit 2019-12-03 22:48:55 +01:00
Christian Klemm
4254781391 Adjusted imports 2019-12-03 22:09:43 +01:00
Christian Klemm
31f4f4096e upgraded packages 2019-12-03 22:05:39 +01:00
Christian Klemm
e95e016378 switched to official dagre d3 2019-12-03 21:59:28 +01:00
Knut Sveidqvist
c337c9128c Merge branch 'master' into bug/1110_state_diagram_rendering_composit_state 2019-12-03 21:04:18 +01:00
Knut Sveidqvist
5a38562bfc #1110 Handling case with concurrency lines 2019-12-03 20:59:17 +01:00
Justin Greywolf
a3dd0e5f7d Merge pull request #4 from mermaid-js/develop
Merge from main
2019-12-02 16:00:32 -08:00
Knut Sveidqvist
fcd1e106a5 #1110 Handling case when title is less wide then subgraph 2019-12-02 21:22:22 +01:00
Knut Sveidqvist
346328156a #1110 Adding tests for this case and some calcuations for width 2019-12-02 21:10:37 +01:00
Christian Klemm
3239f99ea8 Set develop branch for release drafter 2019-12-02 14:48:16 +01:00
Christian Klemm
93c32d3f29 Set develop branch for release drafter 2019-12-02 14:47:34 +01:00
Christian Klemm
98449dac3f Set develop branch for release drafter 2019-12-02 14:43:55 +01:00
Knut Sveidqvist
32b60edda7 Merge branch 'develop' 2019-12-01 13:36:04 +01:00
Knut Sveidqvist
823c95bd9c Updated mermaid version 2019-12-01 13:34:43 +01:00
Knut Sveidqvist
e99d872f2b Create FUNDING.yml 2019-12-01 09:15:56 +01:00
Knut Sveidqvist
de8f8b02dc Merge branch 'master' into develop 2019-12-01 07:54:02 +01:00
Knut Sveidqvist
eec45dfff9 Merge branch 'release/8.4.3' 2019-12-01 07:52:44 +01:00
Knut Sveidqvist
cce86c8e96 Merge pull request #1107 from chris579/feature/1106_release_management
Feature/1106 Release management
2019-12-01 07:34:59 +01:00
Christian Klemm
aabdc47c38 small fixes 2019-12-01 01:06:00 +01:00
Knut Sveidqvist
cb07a729e5 Merge pull request #1098 from mermaid-js/feature/1053_documentation-update
Feature/1053 documentation update
2019-12-01 00:42:41 +01:00
Knut Sveidqvist
df10f7fbe7 Merge pull request #1103 from penenkel/patch-2
Bug/1030 Adjust babel config to account for IE11
2019-12-01 00:42:02 +01:00
Knut Sveidqvist
71c531240f Merge pull request #1089 from jgreywolf/1073-CommentsInClassDiagrams
Bug/1073 Comments in class diagrams
2019-12-01 00:39:33 +01:00
Christian Klemm
1e83207dac small fixes 2019-12-01 00:39:09 +01:00
Christian Klemm
3311fcdc8e Reenable yarn install 2019-12-01 00:21:12 +01:00
Christian Klemm
f368be925f Removed release branch deletion 2019-12-01 00:18:49 +01:00
Christian Klemm
075c57ca06 Check out branches 2019-12-01 00:03:06 +01:00
Christian Klemm
49fc80d506 Prepare git for push 2019-11-30 23:54:42 +01:00
Christian Klemm
74fc2fcfa9 Release tag fixes 2019-11-30 23:49:04 +01:00
Christian Klemm
7cc427e28d Disable yarn install 2019-11-30 23:36:13 +01:00
Christian Klemm
87c571412c version fix 2019-11-30 23:35:39 +01:00
Christian Klemm
ab093b2cde Remove v from release tag 2019-11-30 23:28:48 +01:00
Christian Klemm
bbc4ede768 Added first workflows 2019-11-30 23:23:09 +01:00
penenkel
64c20dc528 Bug/1030 Adjust babel config to account for IE11
An attempt at adding IE11 compatibility (`ie >= 11`) while preserving the current requirements (`current node`) and following browserlist [best practices](https://github.com/browserslist/browserslist#best-practices) (`defaults`).
2019-11-29 23:06:49 +01:00
Knut Sveidqvist
50ea9bda89 Removed loggin 2019-11-28 11:41:54 -05:00
Nacho
2cf8c4e37a Absolute URIs in readme images 2019-11-28 11:41:54 -05:00
Knut Sveidqvist
fe4719f656 Added analytics for docs 2019-11-28 11:41:54 -05:00
James A. Bednar
1d43b7b316 Fixed typos 2019-11-28 11:41:54 -05:00
Itprdev
78e4fead49 Feature request 552. Gnatt chart task with multiple dependencies 2019-11-28 16:53:33 +02:00
Nacho
02d5143ff2 Merge pull request #1095 from mermaid-js/fixes/readme-uris
Absolute URIs in readme images
2019-11-28 08:28:12 -05:00
Erik Ellingsen
d9c92b2c6d syntax error 2019-11-28 13:22:02 +01:00
Erik Ellingsen
27ac9bbaf3 polish 2019-11-28 13:14:29 +01:00
Erik Ellingsen
11cdd393f2 Knuts comments 2019-11-28 13:13:26 +01:00
Erik Ellingsen
1ca8578035 polish 2019-11-28 13:07:14 +01:00
Erik Ellingsen
2516718882 Clarification 2019-11-28 13:06:16 +01:00
Erik Ellingsen
5283314c4f Polish 2019-11-28 13:03:58 +01:00
Erik Ellingsen
dcae8da0d1 Better header 2019-11-28 13:01:24 +01:00
Erik Ellingsen
34f2a1a02f polish 2019-11-28 13:00:12 +01:00
Erik Ellingsen
ee5a68a23c Better intro 2019-11-28 12:59:34 +01:00
Erik Ellingsen
6c706ccd9f Diagram references 2019-11-28 12:57:55 +01:00
Erik Ellingsen
94106f5825 Added syntax reference link 2019-11-28 12:53:33 +01:00
Erik Ellingsen
72ab2b8011 Added coming soon 2019-11-28 12:44:37 +01:00
Erik Ellingsen
8978ab5917 Links added 2019-11-28 12:43:55 +01:00
Erik Ellingsen
94577316f9 Drafting advanced usage 2019-11-28 12:38:42 +01:00
Erik Ellingsen
91650fb052 Script bug and clarifications 2019-11-28 12:34:26 +01:00
Knut Sveidqvist
e9aa037230 Removed loggin 2019-11-27 20:15:21 +01:00
Nacho
871e6f691c Absolute URIs in readme images 2019-11-27 14:12:34 -05:00
Knut Sveidqvist
fe60836a89 Added analytics for docs 2019-11-27 20:08:54 +01:00
Knut Sveidqvist
bea2e73b82 #1065 Updated dependency of dagre-d3 to unofficial release 2019-11-27 19:09:14 +01:00
Nacho
481e55e8da Merge pull request #1090 from jgreywolf/1074-CommentsDocumentation
Bug/1074 Comments documentation
2019-11-27 11:23:50 -05:00
Justin Greywolf
d26a67297a Updated documentation with comment syntax 2019-11-26 15:34:52 -08:00
Justin Greywolf
753bd7e1d9 Update class diagrams to handle comments
updated regex in parser to correctly handle comments in class diagrams.  Also updated flowchart parser to remove unused elements for comments, as well as modifying the regex to match
2019-11-26 11:23:07 -08:00
Justin Greywolf
b57492c1c6 Initial checkin 2019-11-26 11:22:21 -08:00
Justin Greywolf
4ff5c3b455 Merge pull request #3 from mermaid-js/develop
Develop
2019-11-26 11:20:20 -08:00
Knut Sveidqvist
f62c47a757 Updating version to 8.4.3 2019-11-23 13:10:27 +01:00
Knut Sveidqvist
a85bb0d86f Merge pull request #1086 from chris579/bug/1085_coveralls_build_fix
Bug/1085 Coveralls not working for GitHub builds
2019-11-21 20:58:49 +01:00
Knut Sveidqvist
5736d523dd Merge pull request #1081 from jgreywolf/Bug1061-CannotMarkMembersAsProtectedInClassDiagram
Bug/1061 Cannot mark members as protected in class diagram
2019-11-21 20:54:15 +01:00
Justin Greywolf
5004b5723d Added separate render test 2019-11-21 11:17:53 -08:00
Knut Sveidqvist
ad2802d8e8 Merge pull request #1084 from mermaid-js/bug/1078_handling_of_arrowMarkerAbsolute
Bug/1078 handling of arrow marker absolute
2019-11-20 21:50:50 +01:00
Christian Klemm
3fedd452a5 added parallel build support 2019-11-20 21:18:19 +01:00
Christian Klemm
292bc3c4e5 Switched to coveralls action 2019-11-20 21:11:48 +01:00
Knut Sveidqvist
512ba8e733 Merge pull request #1077 from mermaid-js/bug/1076_remove_jest_packages
Bug/1076 Remove jest packages
2019-11-20 19:42:55 +01:00
Knut Sveidqvist
9a87ff684d Removed logging 2019-11-20 19:33:42 +01:00
Knut Sveidqvist
f79fc21bfc Merge branch 'develop' into bug/1078_handling_of_arrowMarkerAbsolute 2019-11-20 19:22:10 +01:00
Knut Sveidqvist
ffddd58b6b Merge branch 'develop' of github.com:knsv/mermaid into develop 2019-11-20 19:21:34 +01:00
Knut Sveidqvist
087e5eaa32 #1055 Fix for tests 2019-11-20 19:21:19 +01:00
Knut Sveidqvist
cbd27831df #1078 Lint fixes 2019-11-20 19:14:32 +01:00
Knut Sveidqvist
f6028b63b6 #1078 Using the configuration of the arrowMarkerAbsolute 2019-11-20 19:06:46 +01:00
Justin Greywolf
a60e01db97 Corrected typo in test 2019-11-19 13:02:08 -08:00
Justin Greywolf
68c2ea38c9 Bug1061-CannotMarkMembersAsProtectedInClassDiagram
Using # to indicate protected status of a member or method causing parser error when not used inside class declaration brackets {}.  Removed '#' from `LABEL` regex
2019-11-19 12:49:59 -08:00
Justin Greywolf
3469cfca2f Merge pull request #2 from mermaid-js/develop
Develop
2019-11-19 12:49:39 -08:00
Christian Klemm
afd189d24c removed packages 2019-11-19 21:02:56 +01:00
Knut Sveidqvist
06cb09c267 Merge pull request #1049 from mermaid-js/feature/1048_build_workflows
Feature/1048 Build workflows
2019-11-19 19:45:27 +01:00
Nacho
e461b57a48 Merge pull request #1075 from jbednar/master
Fixed typos
2019-11-19 08:33:22 -05:00
James A. Bednar
eca9d49575 Fixed typos 2019-11-18 09:32:39 -06:00
Nacho
15a37a5062 Merge pull request #1070 from GDFaber/develop
Bug/1062 Parallelogram shaped nodes are not in documentation
2019-11-18 08:41:24 -05:00
Christian Klemm
3f8f9eb92c remove debugging 2019-11-17 22:20:53 +01:00
Christian Klemm
33de2bda9e cypress cache folder fix 2019-11-17 22:13:02 +01:00
Christian Klemm
94d913fbab debug 2019-11-17 22:04:50 +01:00
Christian Klemm
beb1fcc176 debug 2019-11-17 21:58:53 +01:00
Christian Klemm
1e1a6e3a2d debug 2019-11-17 21:54:15 +01:00
Christian Klemm
6e7c21e439 debug 2019-11-17 21:47:05 +01:00
Christian Klemm
cfe9aaf639 adjusts 2019-11-17 21:41:55 +01:00
Christian Klemm
69e701befb adjusts 2019-11-17 21:27:30 +01:00
Christian Klemm
5174a085b7 test path pattern adjust 2019-11-17 21:21:25 +01:00
Christian Klemm
15fab69eca cache adjusts 2019-11-17 21:03:08 +01:00
Christian Klemm
20b103a0fb cache adjusts 2019-11-17 21:00:55 +01:00
Christian Klemm
8ebe7ee81a cache adjusts 2019-11-17 20:57:55 +01:00
Marc Faber
1d747f664b #1062 added parallelogram nodes to documentation 2019-11-17 17:37:30 +01:00
GDFaber
dbf5988c28 Merge pull request #2 from mermaid-js/develop
sync fork
2019-11-17 17:14:49 +01:00
Christian Klemm
31ab0e4b7d Clear cache 2019-11-12 22:15:49 +01:00
Christian Klemm
35ea7083bb fix cypress cache 2019-11-12 22:12:53 +01:00
Christian Klemm
bf90e8bf44 switched caching method 2019-11-12 22:10:16 +01:00
Christian Klemm
b1305644f4 fixed cypress cache folder 2019-11-12 22:04:47 +01:00
Christian Klemm
34707a057b temp delete cache 2019-11-12 21:58:05 +01:00
Christian Klemm
f5e90252f1 force reinstalling packages 2019-11-12 21:52:50 +01:00
Christian Klemm
e75acf69aa Adjusted cache location 2019-11-12 21:43:11 +01:00
Christian Klemm
3ad3fc2622 Cache adjusts 2019-11-12 21:24:35 +01:00
Christian Klemm
a59468d6c1 Caching adjusts 2019-11-12 21:20:05 +01:00
Christian Klemm
86e63b1614 Add caching 2019-11-12 21:14:42 +01:00
Knut Sveidqvist
3f8f9f6711 #1055 Better selectors 2019-11-08 20:15:48 +01:00
Knut Sveidqvist
d01f494277 Merge branch 'master' into develop 2019-11-08 19:32:54 +01:00
Knut Sveidqvist
4db525c6a9 #1050 Merge of PR 2019-11-08 11:42:26 +01:00
Erik Ellingsen
8b5f8b0cb4 grammar 2019-11-08 10:36:41 +01:00
Erik Ellingsen
d0c9b5e98f grammar 2019-11-08 10:35:38 +01:00
Knut Sveidqvist
e313625ccb Fixing the conflict 2019-11-08 08:54:48 +01:00
erelling
7dead548f3 Update n00b-gettingStarted.md 2019-11-08 01:59:44 +01:00
erelling
8db46ff762 Update n00b-overview.md 2019-11-08 01:57:18 +01:00
erelling
93f54a997a Update n00b-gettingStarted.md 2019-11-08 01:53:58 +01:00
erelling
1353491952 Update n00b-gettingStarted.md 2019-11-08 01:47:34 +01:00
erelling
00802ffe7a Update n00b-gettingStarted.md 2019-11-08 01:45:29 +01:00
erelling
78e556aaf7 Update n00b-gettingStarted.md 2019-11-08 01:44:12 +01:00
erelling
e34988d65a Update n00b-gettingStarted.md 2019-11-08 01:32:09 +01:00
erelling
07f5c7c89c Update n00b-gettingStarted.md 2019-11-08 01:31:21 +01:00
erelling
7319d8941a Update n00b-gettingStarted.md 2019-11-08 01:25:41 +01:00
erelling
3d7933135b Update n00b-gettingStarted.md 2019-11-08 01:23:33 +01:00
erelling
a778472461 Update n00b-gettingStarted.md 2019-11-08 01:21:50 +01:00
erelling
cbe2a7446d Update n00b-gettingStarted.md 2019-11-08 01:17:21 +01:00
erelling
8251dc5cd1 Update n00b-gettingStarted.md 2019-11-08 01:16:16 +01:00
erelling
5a4103a248 Update n00b-gettingStarted.md 2019-11-08 01:15:41 +01:00
erelling
d7996f5c1a Update n00b-gettingStarted.md 2019-11-08 01:14:38 +01:00
erelling
db4229f033 Update n00b-gettingStarted.md 2019-11-08 01:13:14 +01:00
erelling
e103664963 Update n00b-gettingStarted.md 2019-11-08 01:12:14 +01:00
erelling
fbf3936ddc Update n00b-overview.md 2019-11-08 01:11:07 +01:00
erelling
62d03f1976 Update n00b-overview.md 2019-11-08 01:10:24 +01:00
erelling
f3ea159c6b Update n00b-overview.md 2019-11-08 01:08:14 +01:00
erelling
3c99294a3a Update n00b-overview.md 2019-11-08 01:06:57 +01:00
erelling
7a2a8cffbb Update n00b-overview.md 2019-11-08 01:06:20 +01:00
erelling
6d90f87b2f Update n00b-overview.md 2019-11-08 01:04:21 +01:00
erelling
f506d24a82 Update n00b-overview.md 2019-11-08 01:01:37 +01:00
Erik Ellingsen
ddb0d23ca7 grammar 2019-11-08 00:04:53 +01:00
Erik Ellingsen
763be9bb95 better instruction 2019-11-07 23:52:47 +01:00
Erik Ellingsen
77109144e7 grammar 2019-11-07 23:47:34 +01:00
Erik Ellingsen
840e7bd985 clarification 2019-11-07 23:47:08 +01:00
Erik Ellingsen
a6c12f4b25 clarification 2019-11-07 23:46:30 +01:00
Erik Ellingsen
e8e9a4d07b simplification 2019-11-07 23:45:23 +01:00
Erik Ellingsen
ba00182ce4 Clarification 2019-11-07 23:44:47 +01:00
Erik Ellingsen
2ad78ee3b8 grammar 2019-11-07 23:42:56 +01:00
Erik Ellingsen
4995d59499 Knuts comments 2019-11-07 23:42:07 +01:00
Erik Ellingsen
d58ef7aa36 Removed redundant heading 2019-11-07 23:40:13 +01:00
Erik Ellingsen
dc59632fb3 Polishing 2019-11-07 23:37:46 +01:00
Erik Ellingsen
1542e15a1b Introduction and getting started howtos 2019-11-07 23:15:53 +01:00
Ashish Jain
5b5be40dd5 Fixing the binding function error 2019-11-07 22:09:34 +01:00
Knut Sveidqvist
1ecf0f4c23 Updated version 2019-11-07 21:16:43 +01:00
Knut Sveidqvist
fa7d1ac554 #1023 Fix for interaction tests 2019-11-07 19:42:09 +01:00
Knut Sveidqvist
48ce7a9b78 #1023 Fix for tests 2019-11-07 19:19:44 +01:00
Knut Sveidqvist
09bf54f9af #1038 Updated prefix for the internal dom id 2019-11-07 19:14:06 +01:00
Erik Ellingsen
43b9bcdb0b version update 2019-11-07 18:39:57 +01:00
MATSUDA Takashi
aac915b285 #1044 fix: Multiple class diagrams are not rendered correctly 2019-11-05 18:00:52 +09:00
MATSUDA Takashi
7208f045c1 add test for multiple class diagram 2019-11-05 17:54:52 +09:00
MATSUDA Takashi
f7a3c42da1 e2e support multiple diagram 2019-11-05 17:54:52 +09:00
Christian Klemm
4d1c53eb1e added percy token 2019-11-03 19:40:15 +01:00
Christian Klemm
7bcc9b19ac fixed vars 2019-11-03 18:30:01 +01:00
Christian Klemm
7cfc729679 added coveralls vars 2019-11-03 18:28:27 +01:00
Christian Klemm
ec3b68ad28 Added build workflow 2019-11-03 15:20:10 +01:00
162 changed files with 16601 additions and 4608 deletions

12
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1,12 @@
# These are supported funding model platforms
github: [knsv]
#patreon: # Replace with a single Patreon username
#open_collective: # Replace with a single Open Collective username
#ko_fi: # Replace with a single Ko-fi username
#tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
#community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
#liberapay: # Replace with a single Liberapay username
#issuehunt: # Replace with a single IssueHunt username
#otechie: # Replace with a single Otechie username
#custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

3
.github/pr-labeler.yml vendored Normal file
View File

@@ -0,0 +1,3 @@
'Type: Bug / Error': 'bug/*'
'Type: Enhancement': 'feature/*'
'Type: Other': 'other/*'

13
.github/pull_request_template.md vendored Normal file
View File

@@ -0,0 +1,13 @@
## :bookmark_tabs: Summary
Brief description about the content of your PR.
Resolves #<your issue id here>
## :straight_ruler: Design Decisions
Describe the way your implementation works or what design decisions you made if applicable.
### :clipboard: Tasks
Make sure you
- [ ] :book: have read the [contribution guidelines](https://github.com/mermaid-js/mermaid/blob/develop/CONTRIBUTING.md)
- [ ] :computer: have added unit/e2e tests (if appropriate)
- [ ] :bookmark: targeted `develop` branch

25
.github/release-drafter.yml vendored Normal file
View File

@@ -0,0 +1,25 @@
name-template: '$NEXT_PATCH_VERSION'
tag-template: '$NEXT_PATCH_VERSION'
categories:
- title: '🚀 Features'
labels:
- 'Type: Enhancement'
- title: '🐛 Bug Fixes'
labels:
- 'Type: Bug / Error'
- title: '🧰 Maintenance'
label: 'Type: Other'
change-template: '- $TITLE (#$NUMBER) @$AUTHOR'
sort-by: title
sort-direction: ascending
branches:
- develop
exclude-labels:
- 'Skip changelog'
no-changes-template: 'This release contains minor changes and bugfixes.'
template: |
# Release Notes
$CHANGES
🎉 **Thanks to all contributors helping with this release!** 🎉

64
.github/workflows/build.yml vendored Normal file
View File

@@ -0,0 +1,64 @@
name: Build
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.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: Cache Node Modules
uses: actions/cache@v1
with:
path: .cache
key: ${{ runner.OS }}-build-${{ hashFiles('**/yarn.lock') }}
- name: Install Packages
run: |
yarn config set cache-folder $GITHUB_WORKSPACE/.cache/yarn
yarn install --frozen-lockfile
env:
CYPRESS_CACHE_FOLDER: .cache/Cypress
- name: Run Build
run: yarn build
- name: Upload Build as Artifact
uses: actions/upload-artifact@v1
with:
name: dist
path: dist
- name: Run Unit Tests
run: |
yarn test --coverage
#- name: Upload Test Results
# uses: coverallsapp/github-action@v1.0.1
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
# parallel: true
# - name: Run E2E Tests
# run: yarn e2e
# env:
# PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }}
# CYPRESS_CACHE_FOLDER: .cache/Cypress
#- name: Post Upload Test Results
# uses: coverallsapp/github-action@master
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
# parallel-finished: true

19
.github/workflows/checks vendored Normal file
View File

@@ -0,0 +1,19 @@
on: [push]
name: Static analysis
jobs:
test:
runs-on: ubuntu-latest
name: check tests
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: testomatio/check-tests@stable
with:
framework: cypress
tests: "./cypress/integration/**/**.spec.js"
token: ${{ secrets.GITHUB_TOKEN }}
has-tests-label: true

13
.github/workflows/pr-labeler.yml vendored Normal file
View File

@@ -0,0 +1,13 @@
name: Apply labels to PR
on:
pull_request:
types: [opened]
jobs:
pr-labeler:
runs-on: ubuntu-latest
steps:
- name: Label PR
uses: TimonVS/pr-labeler-action@v3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

15
.github/workflows/release-draft.yml vendored Normal file
View File

@@ -0,0 +1,15 @@
name: Draft Release
on:
push:
branches:
- develop
jobs:
draft-release:
runs-on: ubuntu-latest
steps:
- name: Draft Release
uses: toolmantim/release-drafter@v5.2.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -8,15 +8,12 @@ on:
jobs:
publish:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x]
steps:
- uses: actions/checkout@v1
- name: Setup Node.js ${{ matrix.node-version }}
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
node-version: 10.x
- name: Install Yarn
run: npm i yarn --global
@@ -24,7 +21,7 @@ jobs:
run: npm i json --global
- name: Install Packages
run: yarn install
run: yarn install --frozen-lockfile
- name: Publish
run: |

46
.github/workflows/release-publish.yml vendored Normal file
View File

@@ -0,0 +1,46 @@
name: Publish release
on:
release:
types: [published]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: fregante/setup-git-token@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 10.x
- name: Install Yarn
run: npm i yarn --global
- name: Install Json
run: npm i json --global
- name: Install Packages
run: yarn install --frozen-lockfile
- name: Prepare release
run: |
VERSION=${GITHUB_REF:10}
echo "Preparing release $VERSION"
git checkout -t origin/release/$VERSION
npm version --no-git-tag-version --allow-same-version $VERSION
git add package.json
git commit -m "Bump version $VERSION"
git checkout -t origin/master
git merge -m "Release $VERSION" --no-ff release/$VERSION
git push --no-verify
- name: Publish
run: |
npm set //registry.npmjs.org/:_authToken $NPM_TOKEN
npm publish
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

8
.gitignore vendored
View File

@@ -12,3 +12,11 @@ yarn-error.log
token
package-lock.json
dist/classTest.html
dist/sequenceTest.html
.vscode/
cypress/platform/current.html
cypress/platform/experimental.html

View File

@@ -1,8 +0,0 @@
{
"typescript.format.enable": false,
"typescript.reportStyleChecksAsWarnings": false,
"typescript.validate.enable": false,
"javascript.validate.enable": false,
"editor.formatOnSave": false,
"editor.snippetSuggestions": "top"
}

View File

@@ -5,13 +5,50 @@
<!-- </Remove this in the future> -->
# 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)
<!-- <Main description> -->
__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/).
<!-- </Main description> -->
:trophy: _"The most exciting use of technology"_ - [JS Open Source Awards (2019)](https://osawards.com/javascript/#nominees)
: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 diagram
This version comes with a new diagram type, user journey diagrams.
## 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).
<!-- </Main description> -->
__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).__
<table>
<!-- <Flowchart> -->
<tr><td colspan=2 align="center">
@@ -27,7 +64,7 @@ C -->|One| D[Result 1]
C -->|Two| E[Result 2]
</pre></td>
<td align="center">
<img src="./img/gray-flow.png" />
<img src="https://raw.githubusercontent.com/mermaid-js/mermaid/master/img/gray-flow.png" />
</td>
</tr>
<!-- </Flowchart> -->
@@ -49,7 +86,7 @@ John->>Bob: How about you?
Bob-->>John: Jolly good!
</pre></td>
<td align="center">
<img src="./img/gray-sequence.png" />
<img src="https://raw.githubusercontent.com/mermaid-js/mermaid/master/img/gray-sequence.png" />
</td>
</tr>
<!-- </Sequence> -->
@@ -70,7 +107,7 @@ Parallel 3 : des5, after des3, 1d
Parallel 4 : des6, after des4, 1d
</pre></td>
<td align="center">
<img src="./img/gray-gantt.png" />
<img src="https://raw.githubusercontent.com/mermaid-js/mermaid/master/img/gray-gantt.png" />
</td>
</tr>
<!-- </Gantt> -->
@@ -99,7 +136,7 @@ class Class10 {
}
</pre></td>
<td align="center">
<img src="./img/gray-class.png" />
<img src="https://raw.githubusercontent.com/mermaid-js/mermaid/master/img/gray-class.png" />
</td>
</tr>
<!-- </Class> -->
@@ -119,7 +156,7 @@ Moving --> Crash
Crash --> [*]
</pre></td>
<td align="center">
<img src="./img/gray-state.png" />
<img src="https://raw.githubusercontent.com/mermaid-js/mermaid/master/img/gray-state.png" />
</td>
</tr>
<!-- </State> -->
@@ -133,10 +170,10 @@ Crash --> [*]
pie
"Dogs" : 386
"Cats" : 85
"Rats" : 15
"Rats" : 15
</pre></td>
<td align="center">
<img src="./img/gray-pie.png" />
<img src="https://raw.githubusercontent.com/mermaid-js/mermaid/master/img/gray-pie.png" />
</td>
</tr>
<!-- </Pie> -->
@@ -149,12 +186,37 @@ pie
<td colspan="2" align="center"><i>Coming soon!</i></td>
</tr>
<!-- </Git> -->
<!-- <Journey> -->
<tr><td colspan=2 align="center">
<b>User Journey</b><br />
[<a href="http://mermaid-js.github.io/mermaid/#/user-journey">docs</a> - <a href="https://mermaidjs.github.io/mermaid-live-editor/#/edit/eyJjb2RlIjoic3RhdGVEaWFncmFtXG4gICAgWypdIC0tPiBTdGlsbFxuICAgIFN0aWxsIC0tPiBbKl1cbiAgICBTdGlsbCAtLT4gTW92aW5nXG4gICAgTW92aW5nIC0tPiBTdGlsbFxuICAgIE1vdmluZyAtLT4gQ3Jhc2hcbiAgICBDcmFzaCAtLT4gWypdIiwibWVybWFpZCI6eyJ0aGVtZSI6ImRlZmF1bHQifX0">live editor</a>]
</td></tr>
<tr>
<td>
<pre>
journey
title My working day
section Go to work
Make tea: 5: Me
Go upstairs: 3: Me
Do work: 1: Me, Cat
section Go home
Go downstairs: 5: Me
Sit down: 3: Me
</pre></td>
<td align="center">
<img alt="User Journey Diagram" src="img/gray-user-journey.png" />
</td>
</tr>
<!-- </Journey> -->
</table>
## Related projects
## Related projects
- [Command Line Interface](https://github.com/mermaid-js/mermaid.cli)
- [Live Editor](https://github.com/mermaid-js/mermaid-live-editor)
- [HTTP Server](https://github.com/TomWright/mermaid-server)
# Contributors [![Help wanted](https://img.shields.io/github/labels/mermaid-js/mermaid/Help%20wanted!)](https://github.com/mermaid-js/mermaid/issues?q=is%3Aissue+is%3Aopen+label%3A%22Help+wanted%21%22) [![Contributors](https://img.shields.io/github/contributors/mermaid-js/mermaid)](https://github.com/mermaid-js/mermaid/graphs/contributors) [![Commits](https://img.shields.io/github/commit-activity/m/mermaid-js/mermaid)](https://github.com/mermaid-js/mermaid/graphs/contributors)

View File

@@ -3,9 +3,7 @@ module.exports = {
[
'@babel/preset-env',
{
targets: {
node: 'current'
}
targets: "defaults, ie >= 11, current node"
}
]
]

View File

@@ -26,3 +26,9 @@ export const imgSnapshotTest = (graphStr, options, api) => {
cy.get('svg');
cy.percySnapshot();
};
export const renderGraph = (graphStr, options, api) => {
const url = mermaidUrl(graphStr, options, api);
cy.visit(url);
};

View File

@@ -0,0 +1,100 @@
import { renderGraph } from '../../helpers/util';
/* eslint-env jest */
describe('Configuration', () => {
describe('arrowMarkerAbsolute', () => {
it('should handle default value false of arrowMarkerAbsolute', () => {
renderGraph(
`graph TD
A[Christmas] -->|Get money| B(Go shopping)
B --> C{Let me think}
C -->|One| D[Laptop]
C -->|Two| E[iPhone]
C -->|Three| F[fa:fa-car Car]
`,
{ }
);
// Check the marker-end property to make sure it is properly set to
// start with #
cy.get('.edgePath path').first().should('have.attr', 'marker-end')
.should('exist')
.and('include', 'url(#');
});
it('should handle default value false of arrowMarkerAbsolute', () => {
renderGraph(
`graph TD
A[Christmas] -->|Get money| B(Go shopping)
B --> C{Let me think}
C -->|One| D[Laptop]
C -->|Two| E[iPhone]
C -->|Three| F[fa:fa-car Car]
`,
{ }
);
// Check the marker-end property to make sure it is properly set to
// start with #
cy.get('.edgePath path').first().should('have.attr', 'marker-end')
.should('exist')
.and('include', 'url(#');
});
it('should handle arrowMarkerAbsolute excplicitly set to false', () => {
renderGraph(
`graph TD
A[Christmas] -->|Get money| B(Go shopping)
B --> C{Let me think}
C -->|One| D[Laptop]
C -->|Two| E[iPhone]
C -->|Three| F[fa:fa-car Car]
`,
{
arrowMarkerAbsolute: false
}
);
// Check the marker-end property to make sure it is properly set to
// start with #
cy.get('.edgePath path').first().should('have.attr', 'marker-end')
.should('exist')
.and('include', 'url(#');
});
it('should handle arrowMarkerAbsolute excplicitly set to "false" as false', () => {
renderGraph(
`graph TD
A[Christmas] -->|Get money| B(Go shopping)
B --> C{Let me think}
C -->|One| D[Laptop]
C -->|Two| E[iPhone]
C -->|Three| F[fa:fa-car Car]
`,
{
arrowMarkerAbsolute: "false"
}
);
// Check the marker-end property to make sure it is properly set to
// start with #
cy.get('.edgePath path').first().should('have.attr', 'marker-end')
.should('exist')
.and('include', 'url(#');
});
it('should handle arrowMarkerAbsolute set to true', () => {
renderGraph(
`graph TD
A[Christmas] -->|Get money| B(Go shopping)
B --> C{Let me think}
C -->|One| D[Laptop]
C -->|Two| E[iPhone]
C -->|Three| F[fa:fa-car Car]
`,
{
arrowMarkerAbsolute: true
}
);
cy.get('.edgePath path').first().should('have.attr', 'marker-end')
.should('exist')
.and('include', 'url(http://localhost');
});
});
});

View File

@@ -16,7 +16,7 @@ describe('Interaction', () => {
cy.viewport(1440, 1024);
cy.visit(url);
cy.get('body')
.find('g#s1Function')
.find('g[id="1Function"]')
.click();
cy.get('.created-by-click').should('have.text', 'Clicked By Flow');
@@ -38,7 +38,7 @@ describe('Interaction', () => {
cy.viewport(1440, 1024);
cy.visit(url);
cy.get('body')
.find('g#s2URL')
.find('g[id="2URL"]')
.click();
cy.location().should(location => {
@@ -70,7 +70,7 @@ describe('Interaction', () => {
expect(location.href).to.eq('http://localhost:9000/webpackUsage.html');
});
});
it('should handle a click on a task with a bound function', () => {
it('should handle a click on a task with a bound function without args', () => {
const url = 'http://localhost:9000/click_security_loose.html';
cy.viewport(1440, 1024);
cy.visit(url);
@@ -78,9 +78,20 @@ describe('Interaction', () => {
.find('rect#cl2')
.click({ force: true });
cy.get('.created-by-gant-click').should('have.text', 'Clicked By Gant');
cy.get('.created-by-gant-click').should('have.text', 'Clicked By Gant cl2');
});
it('should handle a click on a task with a bound function', () => {
it('should handle a click on a task with a bound function with args', () => {
const url = 'http://localhost:9000/click_security_loose.html';
cy.viewport(1440, 1024);
cy.visit(url);
cy.get('body')
.find('rect#cl3')
.click({ force: true });
cy.get('.created-by-gant-click').should('have.text', 'Clicked By Gant test1 test2 test3');
});
it('should handle a click on a task with a bound function without args', () => {
const url = 'http://localhost:9000/click_security_loose.html';
cy.viewport(1440, 1024);
cy.visit(url);
@@ -88,8 +99,19 @@ describe('Interaction', () => {
.find('text#cl2-text')
.click({ force: true });
cy.get('.created-by-gant-click').should('have.text', 'Clicked By Gant');
cy.get('.created-by-gant-click').should('have.text', 'Clicked By Gant cl2');
});
it('should handle a click on a task with a bound function with args ', () => {
const url = 'http://localhost:9000/click_security_loose.html';
cy.viewport(1440, 1024);
cy.visit(url);
cy.get('body')
.find('text#cl3-text')
.click({ force: true });
cy.get('.created-by-gant-click').should('have.text', 'Clicked By Gant test1 test2 test3');
});
});
describe('Interaction - security level tight', () => {
@@ -108,7 +130,7 @@ describe('Interaction', () => {
cy.viewport(1440, 1024);
cy.visit(url);
cy.get('body')
.find('g#s1Function')
.find('g[id="1Function"]')
.click();
cy.get('.created-by-click').should('not.have.text', 'Clicked By Flow');
@@ -130,7 +152,7 @@ describe('Interaction', () => {
cy.viewport(1440, 1024);
cy.visit(url);
cy.get('body')
.find('g#s2URL')
.find('g[id="2URL"]')
.click();
cy.location().should(location => {
@@ -170,7 +192,7 @@ describe('Interaction', () => {
.find('rect#cl2')
.click({ force: true });
cy.get('.created-by-gant-click').should('not.have.text', 'Clicked By Gant');
cy.get('.created-by-gant-click').should('not.have.text', 'Clicked By Gant cl2');
});
it('should handle a click on a task with a bound function', () => {
const url = 'http://localhost:9000/click_security_strict.html';
@@ -180,7 +202,7 @@ describe('Interaction', () => {
.find('text#cl2-text')
.click({ force: true });
cy.get('.created-by-gant-click').should('not.have.text', 'Clicked By Gant');
cy.get('.created-by-gant-click').should('not.have.text', 'Clicked By Gant cl2');
});
});
@@ -200,7 +222,7 @@ describe('Interaction', () => {
cy.viewport(1440, 1024);
cy.visit(url);
cy.get('body')
.find('g#s1Function')
.find('g[id="1Function"]')
.click();
cy.get('.created-by-click').should('not.have.text', 'Clicked By Flow');
@@ -226,7 +248,7 @@ describe('Interaction', () => {
.find('rect#cl2')
.click({ force: true });
cy.get('.created-by-gant-click').should('not.have.text', 'Clicked By Gant');
cy.get('.created-by-gant-click').should('not.have.text', 'Clicked By Gant cl2');
});
it('should handle a click on a task with a bound function', () => {
const url = 'http://localhost:9000/click_security_strict.html';
@@ -236,7 +258,7 @@ describe('Interaction', () => {
.find('text#cl2-text')
.click({ force: true });
cy.get('.created-by-gant-click').should('not.have.text', 'Clicked By Gant');
cy.get('.created-by-gant-click').should('not.have.text', 'Clicked By Gant cl2');
});
});
});

View File

@@ -9,8 +9,27 @@ describe('XSS', () => {
const url = mermaidUrl(str,{}, true);
cy.visit(url);
cy.wait(1000).then(()=>{
cy.get('.mermaid').should('exist');
});
cy.get('svg')
cy.percySnapshot()
// cy.percySnapshot()
})
it('should handle xss in tags in non-html mode', () => {
const str = 'eyJjb2RlIjoiXG5ncmFwaCBMUlxuICAgICAgQi0tPkQoPGltZyBvbmVycm9yPWxvY2F0aW9uPWBqYXZhc2NyaXB0XFx1MDAzYXhzc0F0dGFja1xcdTAwMjhkb2N1bWVudC5kb21haW5cXHUwMDI5YCBzcmM9eD4pOyIsIm1lcm1haWQiOnsidGhlbWUiOiJkZWZhdWx0IiwiZmxvd2NoYXJ0Ijp7Imh0bWxMYWJlbHMiOmZhbHNlfX19';
const url = mermaidUrl(str,{
"theme": "default",
"flowchart": {
"htmlMode": false
}
}, true);
cy.visit(url);
// cy.get('svg')
// cy.percySnapshot()
cy.get('.malware').should('not.exist');
})
})

View File

@@ -2,7 +2,7 @@
import { imgSnapshotTest } from '../../helpers/util';
describe('Class diagram', () => {
it('should render a simple class diagram', () => {
it('1: should render a simple class diagram', () => {
imgSnapshotTest(
`
classDiagram
@@ -14,11 +14,16 @@ describe('Class diagram', () => {
Class09 --> C2 : Where am i?
Class09 --* C3
Class09 --|> Class07
Class12 <|.. Class08
Class11 ..>Class12
Class07 : equals()
Class07 : Object[] elementData
Class01 : size()
Class01 : int chimp
Class01 : int gorilla
Class01 : -int privateChimp
Class01 : +int publicGorilla
Class01 : #int protectedMarmoset
Class08 <--> C2: Cool label
class Class10 {
&lt;&lt;service&gt;&gt;
@@ -26,11 +31,12 @@ describe('Class diagram', () => {
test()
}
`,
{}
{logLevel : 1}
);
cy.get('svg');
});
it('should render a simple class diagrams with cardinality', () => {
it('2: should render a simple class diagrams with cardinality', () => {
imgSnapshotTest(
`
classDiagram
@@ -58,4 +64,245 @@ describe('Class diagram', () => {
);
cy.get('svg');
});
it('should render a simple class diagram with different visibilities', () => {
imgSnapshotTest(
`
classDiagram
Class01 <|-- AveryLongClass : Cool
&lt;&lt;interface&gt;&gt; Class01
Class01 : -int privateMethod()
Class01 : +int publicMethod()
Class01 : #int protectedMethod()
Class01 : -int privateChimp
Class01 : +int publicGorilla
Class01 : #int protectedMarmoset
`,
{}
);
cy.get('svg');
});
it('should render multiple class diagrams', () => {
imgSnapshotTest(
[
`
classDiagram
Class01 "1" <|--|> "*" AveryLongClass : Cool
&lt;&lt;interface&gt;&gt; Class01
Class03 "1" *-- "*" Class04
Class05 "1" o-- "many" Class06
Class07 "1" .. "*" Class08
Class09 "1" --> "*" C2 : Where am i?
Class09 "*" --* "*" C3
Class09 "1" --|> "1" Class07
Class07 : equals()
Class07 : Object[] elementData
Class01 : size()
Class01 : int chimp
Class01 : int gorilla
Class08 "1" <--> "*" C2: Cool label
class Class10 {
&lt;&lt;service&gt;&gt;
int id
test()
}
`,
`
classDiagram
Class01 "1" <|--|> "*" AveryLongClass : Cool
&lt;&lt;interface&gt;&gt; Class01
Class03 "1" *-- "*" Class04
Class05 "1" o-- "many" Class06
Class07 "1" .. "*" Class08
Class09 "1" --> "*" C2 : Where am i?
Class09 "*" --* "*" C3
Class09 "1" --|> "1" Class07
Class07 : equals()
Class07 : Object[] elementData
Class01 : size()
Class01 : int chimp
Class01 : int gorilla
Class08 "1" <--> "*" C2: Cool label
class Class10 {
&lt;&lt;service&gt;&gt;
int id
test()
}
`,
],
{}
);
cy.get('svg');
});
it('4: should render a simple class diagram with comments', () => {
imgSnapshotTest(
`
classDiagram
%% this is a comment
Class01 <|-- AveryLongClass : Cool
&lt;&lt;interface&gt;&gt; Class01
Class03 *-- Class04
Class05 o-- Class06
Class07 .. Class08
Class09 --> C2 : Where am i?
Class09 --* C3
Class09 --|> Class07
Class07 : equals()
Class07 : Object[] elementData
Class01 : size()
Class01 : int chimp
Class01 : int gorilla
Class08 <--> C2: Cool label
class Class10 {
&lt;&lt;service&gt;&gt;
int id
test()
}
`,
{}
);
cy.get('svg');
});
it('5: should render a simple class diagram with abstract method', () => {
imgSnapshotTest(
`
classDiagram
Class01 <|-- AveryLongClass : Cool
Class01 : someMethod()*
`,
{}
);
cy.get('svg');
});
it('6: should render a simple class diagram with static method', () => {
imgSnapshotTest(
`
classDiagram
Class01 <|-- AveryLongClass : Cool
Class01 : someMethod()$
`,
{}
);
cy.get('svg');
});
it('7: should render a simple class diagram with Generic class', () => {
imgSnapshotTest(
`
classDiagram
class Class01~T~
Class01 : size()
Class01 : int chimp
Class01 : int gorilla
Class08 <--> C2: Cool label
class Class10~T~ {
&lt;&lt;service&gt;&gt;
int id
test()
}
`,
{}
);
cy.get('svg');
});
it('8: should render a simple class diagram with Generic class and relations', () => {
imgSnapshotTest(
`
classDiagram
Class01~T~ <|-- AveryLongClass : Cool
Class03~T~ *-- Class04~T~
Class01 : size()
Class01 : int chimp
Class01 : int gorilla
Class08 <--> C2: Cool label
class Class10~T~ {
&lt;&lt;service&gt;&gt;
int id
test()
}
`,
{}
);
cy.get('svg');
});
it('9: should render a simple class diagram with clickable link', () => {
imgSnapshotTest(
`
classDiagram
Class01~T~ <|-- AveryLongClass : Cool
Class03~T~ *-- Class04~T~
Class01 : size()
Class01 : int chimp
Class01 : int gorilla
Class08 <--> C2: Cool label
class Class10~T~ {
&lt;&lt;service&gt;&gt;
int id
test()
}
link class01 "google.com" "A Tooltip"
`,
{}
);
cy.get('svg');
});
it('10: should render a simple class diagram with clickable callback', () => {
imgSnapshotTest(
`
classDiagram
Class01~T~ <|-- AveryLongClass : Cool
Class03~T~ *-- Class04~T~
Class01 : size()
Class01 : int chimp
Class01 : int gorilla
Class08 <--> C2: Cool label
class Class10~T~ {
&lt;&lt;service&gt;&gt;
int id
test()
}
callback class01 "functionCall" "A Tooltip"
`,
{}
);
cy.get('svg');
});
it('11: should render a simple class diagram with return type on method', () => {
imgSnapshotTest(
`
classDiagram
class Class10~T~ {
int[] id
test(int[] ids) bool
testArray() bool[]
}
`,
{}
);
cy.get('svg');
});
it('12: should render a simple class diagram with generic types', () => {
imgSnapshotTest(
`
classDiagram
class Class10~T~ {
int[] id
List~int~ ids
test(List~int~ ids) List~bool~
testArray() bool[]
}
`,
{}
);
cy.get('svg');
});
});

View File

@@ -2,19 +2,20 @@
import { imgSnapshotTest } from '../../helpers/util';
describe('State diagram', () => {
it('should render a flowchart full of circles', () => {
it('should render a state with states in it', () => {
imgSnapshotTest(
`
stateDiagram
State1: The state with a note
note right of State1
Important information! You\ncan write
notes with multiple lines...
Here is another line...
And another line...
end note
stateDiagram
state PersonalizedCockpit {
Other
state Parent {
C
}
}
`,
{}
{
logLevel: 0,
}
);
});
});

View File

@@ -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');
});
});

View File

@@ -1,7 +1,7 @@
/* eslint-env jest */
import { imgSnapshotTest } from '../../helpers/util';
describe('Flowcart', () => {
describe('Flowchart', () => {
it('1: should render a simple flowchart no htmlLabels', () => {
imgSnapshotTest(
`graph TD
@@ -14,6 +14,7 @@ describe('Flowcart', () => {
{ flowchart: { htmlLabels: false } }
);
});
it('2: should render a simple flowchart with htmlLabels', () => {
imgSnapshotTest(
`graph TD
@@ -26,6 +27,7 @@ describe('Flowcart', () => {
{ flowchart: { htmlLabels: true } }
);
});
it('3: should render a simple flowchart with line breaks', () => {
imgSnapshotTest(
`
@@ -55,7 +57,7 @@ describe('Flowcart', () => {
);
});
it('4: should style nodes via a class.', () => {
it('5: should style nodes via a class.', () => {
imgSnapshotTest(
`
graph TD
@@ -71,7 +73,7 @@ describe('Flowcart', () => {
);
});
it('5: should render a flowchart full of circles', () => {
it('6: should render a flowchart full of circles', () => {
imgSnapshotTest(
`
graph LR
@@ -99,7 +101,8 @@ describe('Flowcart', () => {
{}
);
});
it('6: should render a flowchart full of icons', () => {
it('7: should render a flowchart full of icons', () => {
imgSnapshotTest(
`
graph TD
@@ -170,7 +173,7 @@ describe('Flowcart', () => {
);
});
it('7: should render labels with numbers at the start', () => {
it('8: should render labels with numbers at the start', () => {
imgSnapshotTest(
`
graph TB;subgraph "number as labels";1;end;
@@ -178,7 +181,8 @@ describe('Flowcart', () => {
{}
);
});
it('8: should render subgraphs', () => {
it('9: should render subgraphs', () => {
imgSnapshotTest(
`
graph TB
@@ -190,7 +194,7 @@ describe('Flowcart', () => {
);
});
it('9: should render subgraphs with a title startign with a digit', () => {
it('10: should render subgraphs with a title starting with a digit', () => {
imgSnapshotTest(
`
graph TB
@@ -202,7 +206,7 @@ describe('Flowcart', () => {
);
});
it('10: should render styled subgraphs', () => {
it('11: should render styled subgraphs', () => {
imgSnapshotTest(
`
graph TB
@@ -237,7 +241,7 @@ describe('Flowcart', () => {
);
});
it('11: should render a flowchart with ling sames and class definitoins', () => {
it('12: should render a flowchart with long names and class definitions', () => {
imgSnapshotTest(
`graph LR
sid-B3655226-6C29-4D00-B685-3D5C734DC7E1["
@@ -339,7 +343,7 @@ describe('Flowcart', () => {
);
});
it('12: should render color of styled nodes', () => {
it('13: should render color of styled nodes', () => {
imgSnapshotTest(
`
graph LR
@@ -356,4 +360,315 @@ describe('Flowcart', () => {
}
);
});
it('14: should render hexagons', () => {
imgSnapshotTest(
`
graph TD
A[Christmas] -->|Get money| B(Go shopping)
B --> C{{Let me think...<br />Do I want something for work,<br />something to spend every free second with,<br />or something to get around?}}
C -->|One| D[Laptop]
C -->|Two| E[iPhone]
C -->|Three| F[Car]
click A "index.html#link-clicked" "link test"
click B testClick "click test"
classDef someclass fill:#f96;
class A someclass;
class C someclass;
`,
{
listUrl: false,
listId: 'color styling',
logLevel: 0
}
);
});
it('15: should render a simple flowchart with comments', () => {
imgSnapshotTest(
`graph TD
A[Christmas] -->|Get money| B(Go shopping)
B --> C{Let me think}
%% this is a comment
C -->|One| D[Laptop]
C -->|Two| E[iPhone]
C -->|Three| F[fa:fa-car Car]
`,
{ flowchart: { htmlLabels: false } }
);
});
it('16: Render Stadium shape', () => {
imgSnapshotTest(
` graph TD
A([stadium shape test])
A -->|Get money| B([Go shopping])
B --> C([Let me think...<br />Do I want something for work,<br />something to spend every free second with,<br />or something to get around?])
C -->|One| D([Laptop])
C -->|Two| E([iPhone])
C -->|Three| F([Car<br/>wroom wroom])
click A "index.html#link-clicked" "link test"
click B testClick "click test"
classDef someclass fill:#f96;
class A someclass;
class C someclass;
`,
{ flowchart: { htmlLabels: false } }
);
});
it('17: Render multiline texts', () => {
imgSnapshotTest(
`graph LR
A1[Multi<br>Line] -->|Multi<br>Line| B1(Multi<br>Line)
C1[Multi<br/>Line] -->|Multi<br/>Line| D1(Multi<br/>Line)
E1[Multi<br />Line] -->|Multi<br />Line| F1(Multi<br />Line)
A2[Multi<br>Line] -->|Multi<br>Line| B2(Multi<br>Line)
C2[Multi<br/>Line] -->|Multi<br/>Line| D2(Multi<br/>Line)
E2[Multi<br />Line] -->|Multi<br />Line| F2(Multi<br />Line)
linkStyle 0 stroke:DarkGray,stroke-width:2px
linkStyle 1 stroke:DarkGray,stroke-width:2px
linkStyle 2 stroke:DarkGray,stroke-width:2px
`,
{ flowchart: { htmlLabels: false } }
);
});
it('18: Chaining of nodes', () => {
imgSnapshotTest(
`graph LR
a --> b --> c
`,
{ flowchart: { htmlLabels: false } }
);
});
it('19: Multiple nodes and chaining in one statement', () => {
imgSnapshotTest(
`graph LR
a --> b & c--> d
`,
{ flowchart: { htmlLabels: false } }
);
});
it('20: Multiple nodes and chaining in one statement', () => {
imgSnapshotTest(
`graph TD
A[ h ] -- hello --> B[" test "]:::exClass & C --> D;
classDef exClass background:#bbb,border:1px solid red;
`,
{ flowchart: { htmlLabels: false } }
);
});
it('21: Render cylindrical shape', () => {
imgSnapshotTest(
`graph LR
A[(cylindrical<br />shape<br />test)]
A -->|Get money| B1[(Go shopping 1)]
A -->|Get money| B2[(Go shopping 2)]
A -->|Get money| B3[(Go shopping 3)]
C[(Let me think...<br />Do I want something for work,<br />something to spend every free second with,<br />or something to get around?)]
B1 --> C
B2 --> C
B3 --> C
C -->|One| D[(Laptop)]
C -->|Two| E[(iPhone)]
C -->|Three| F[(Car)]
click A "index.html#link-clicked" "link test"
click B testClick "click test"
classDef someclass fill:#f96;
class A someclass;`,
{ flowchart: { htmlLabels: false } }
);
});
it('22: Render a simple flowchart with nodeSpacing set to 100', () => {
imgSnapshotTest(
`graph TD
A[Christmas] -->|Get money| B(Go shopping)
B --> C{Let me think}
%% this is a comment
C -->|One| D[Laptop]
C -->|Two| E[iPhone]
C -->|Three| F[fa:fa-car Car]
`,
{ flowchart: { nodeSpacing: 50 } }
);
});
it('23: Render a simple flowchart with rankSpacing set to 100', () => {
imgSnapshotTest(
`graph TD
A[Christmas] -->|Get money| B(Go shopping)
B --> C{Let me think}
%% this is a comment
C -->|One| D[Laptop]
C -->|Two| E[iPhone]
C -->|Three| F[fa:fa-car Car]
`,
{ flowchart: { rankSpacing: '100' } }
);
});
it('24: Keep node label text (if already defined) when a style is applied', () => {
imgSnapshotTest(
`graph LR
A(( )) -->|step 1| B(( ))
B(( )) -->|step 2| C(( ))
C(( )) -->|step 3| D(( ))
linkStyle 1 stroke:greenyellow,stroke-width:2px
style C fill:greenyellow,stroke:green,stroke-width:4px
`,
{ flowchart: { htmlLabels: false } }
);
});
it('25: Handle link click events (link, anchor, mailto, other protocol, script)', () => {
imgSnapshotTest(
`graph TB
TITLE["Link Click Events<br>(click the nodes below)"]
A[link test]
B[anchor test]
C[mailto test]
D[other protocol test]
E[script test]
TITLE --> A & B & C & D & E
click A "https://mermaid-js.github.io/mermaid/#/" "link test"
click B "#link-clicked" "anchor test"
click C "mailto:user@user.user" "mailto test"
click D "notes://do-your-thing/id" "other protocol test"
click E "javascript:alert('test')" "script test"
`,
{ securityLevel: 'loose' }
);
});
it('26: Set text color of nodes and links according to styles when html labels are enabled', () => {
imgSnapshotTest(
`graph LR
A[red<br>text] -->|red<br>text| B(blue<br>text)
C[/red<br/>text/] -->|blue<br/>text| D{blue<br/>text}
E{{default<br />style}} -->|default<br />style| F([default<br />style])
linkStyle default color:Sienna;
linkStyle 0 color:red;
linkStyle 1 stroke:DarkGray,stroke-width:2px,color:#0000ff
style A color:red;
style B color:blue;
style C stroke:#ff0000,fill:#ffcccc,color:#ff0000
style D stroke:#0000ff,fill:#ccccff,color:#0000ff
click B "index.html#link-clicked" "link test"
click D testClick "click test"
`,
{ flowchart: { htmlLabels: true } }
);
});
it('27: Set text color of nodes and links according to styles when html labels are disabled', () => {
imgSnapshotTest(
`graph LR
A[red<br>text] -->|red<br>text| B(blue<br>text)
C[/red<br/>text/] -->|blue<br/>text| D{blue<br/>text}
E{{default<br />style}} -->|default<br />style| F([default<br />style])
linkStyle default color:Sienna;
linkStyle 0 color:red;
linkStyle 1 stroke:DarkGray,stroke-width:2px,color:#0000ff
style A color:red;
style B color:blue;
style C stroke:#ff0000,fill:#ffcccc,color:#ff0000
style D stroke:#0000ff,fill:#ccccff,color:#0000ff
click B "index.html#link-clicked" "link test"
click D testClick "click test"
`,
{ 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
subgraph id1 [title is set]
A-->B
end
subgraph id2 [title]
E
end
B-->C
subgraph id3
C-->D
end
class id3,id2,A redBg;
class id3,A whiteTxt;
classDef redBg fill:#622;
classDef whiteTxt color: white;
`,
{ flowchart: { htmlLabels: false } }
);
});
it('31: should not slice off edges that are to the left of the left-most vertex', () => {
imgSnapshotTest(
`graph TD
work --> sleep
sleep --> work
eat --> sleep
work --> eat
`,
{ flowchart: { htmlLabels: false } }
);
});
it('32: Render Subroutine shape', () => {
imgSnapshotTest(
`graph LR
A[[subroutine shape test]]
A -->|Get money| B[[Go shopping]]
B --> C[[Let me think...<br />Do I want something for work,<br />something to spend every free second with,<br />or something to get around?]]
C -->|One| D[[Laptop]]
C -->|Two| E[[iPhone]]
C -->|Three| F[[Car<br/>wroom wroom]]
click A "index.html#link-clicked" "link test"
click B testClick "click test"
classDef someclass fill:#f96;
class A someclass;
class C someclass;
`,
{ flowchart: { htmlLabels: false } }
);
});
});

View File

@@ -1,7 +1,7 @@
/* eslint-env jest */
import { imgSnapshotTest } from '../../helpers/util.js';
describe('Sequencediagram', () => {
describe('Gantt diagram', () => {
it('should render a gantt chart', () => {
imgSnapshotTest(
`
@@ -38,4 +38,126 @@ describe('Sequencediagram', () => {
{}
);
});
it('Handle multiline section titles with different line breaks', () => {
imgSnapshotTest(
`
gantt
dateFormat YYYY-MM-DD
axisFormat %d/%m
title GANTT diagram with multiline section titles
excludes weekdays 2014-01-10
section A section<br>multiline
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<br/>multiline
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<br />multiline
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 Last section<br />multiline
Describe gantt syntax : after doc1, 3d
Add gantt diagram to demo page : 20h
Add another diagram to demo page : 48h
`,
{}
);
});
it('Multiple dependencies syntax', () => {
imgSnapshotTest(
`
gantt
dateFormat YYYY-MM-DD
axisFormat %d/%m
title Adding GANTT diagram to mermaid
excludes weekdays 2014-01-10
apple :a, 2017-07-20, 1w
banana :crit, b, 2017-07-23, 1d
cherry :active, c, after b a, 1d
`,
{}
);
});
it('should render a gantt chart for issue #1060', () => {
imgSnapshotTest(
`
gantt
excludes weekdays 2017-01-10
title Projects Timeline
section asdf
specs :done, :ps, 2019-05-10, 50d
Plasma :pc, 2019-06-20, 60d
Rollup :or, 2019-08-20, 50d
section CEL
plasma-chamber :done, :pc, 2019-05-20, 60d
Plasma Implementation (Rust) :por, 2019-06-20, 120d
Predicates (Atomic Swap) :pred, 2019-07-20, 60d
section DEX
History zkSNARK :hs, 2019-08-10, 40d
Exit :vs, after hs, 60d
PredicateSpec :ps, 2019-09-1, 20d
PlasmaIntegration :pi, after ps,40d
section Events
ETHBoston :done, :eb, 2019-09-08, 3d
DevCon :active, :dc, 2019-10-08, 3d
section Plasma Calls & updates
OVM :ovm, 2019-07-12, 120d
Plasma call 26 :pc26, 2019-08-21, 1d
Plasma call 27 :pc27, 2019-09-03, 1d
Plasma call 28 :pc28, 2019-09-17, 1d
`,
{}
);
});
it('should hide today marker', () => {
imgSnapshotTest(
`
gantt
title Hide today marker (vertical line should not be visible)
dateFormat YYYY-MM-DD
axisFormat %d
todayMarker off
section Section1
Today: 1, -1h
`,
{}
);
});
it('should style today marker', () => {
imgSnapshotTest(
`
gantt
title Style today marker (vertical line should be 5px wide and half-transparent blue)
dateFormat YYYY-MM-DD
axisFormat %d
todayMarker stroke-width:5px,stroke:#00f,opacity:0.5
section Section1
Today: 1, -1h
`,
{}
);
});
});

View File

@@ -2,20 +2,20 @@
import { imgSnapshotTest } from '../../helpers/util.js';
describe('Sequencediagram', () => {
it('should render a simple git graph', () => {
imgSnapshotTest(
`
gitGraph:
commit
branch newbranch
checkout newbranch
commit
commit
checkout master
commit
commit
merge newbranch`,
{ logLevel: 0 }
);
});
// it('should render a simple git graph', () => {
// imgSnapshotTest(
// `
// gitGraph:
// commit
// branch newbranch
// checkout newbranch
// commit
// commit
// checkout master
// commit
// commit
// merge newbranch`,
// { logLevel: 0 }
// );
// });
});

View File

@@ -0,0 +1,31 @@
/* eslint-env jest */
import { imgSnapshotTest } from '../../helpers/util.js';
describe('User journey diagram', () => {
it('Simple test', () => {
imgSnapshotTest(
`journey
title Adding journey diagram functionality to mermaid
section Order from website
`,
{}
);
});
it('should render a user journey chart', () => {
imgSnapshotTest(
`
journey
title My working day
section Go to work
Make tea: 5: Me
Go upstairs: 3: Me
Do work: 1: Me, Cat
section Go home
Go downstairs: 5: Me
Sit down: 3: Me
`,
{}
);
});
});

View File

@@ -2,8 +2,8 @@
import { imgSnapshotTest } from '../../helpers/util';
context('Aliasing', () => {
it('should render a simple sequence diagrams', () => {
context('Sequence diagram', () => {
it('should render a simple sequence diagram', () => {
imgSnapshotTest(
`
sequenceDiagram
@@ -32,6 +32,158 @@ context('Aliasing', () => {
{}
);
});
it('should handle different line breaks', () => {
imgSnapshotTest(
`
sequenceDiagram
participant 1 as multiline<br>using #lt;br#gt;
participant 2 as multiline<br/>using #lt;br/#gt;
participant 3 as multiline<br />using #lt;br /#gt;
participant 4 as multiline<br \t/>using #lt;br \t/#gt;
1->>2: multiline<br>using #lt;br#gt;
note right of 2: multiline<br>using #lt;br#gt;
2->>3: multiline<br/>using #lt;br/#gt;
note right of 3: multiline<br/>using #lt;br/#gt;
3->>4: multiline<br />using #lt;br /#gt;
note right of 4: multiline<br />using #lt;br /#gt;
4->>1: multiline<br />using #lt;br /#gt;
note right of 1: multiline<br \t/>using #lt;br \t/#gt;
`,
{}
);
});
it('should render loops with a slight margin', () => {
imgSnapshotTest(
`
sequenceDiagram
Alice->>Bob: Extremely utterly long line of longness which had preivously overflown the actor box as it is much longer than what it should be
loop Loopy
Bob->>Alice: Pasten
end `,
{}
);
});
context('font settings', () => {
it('should render different note fonts when configured', () => {
imgSnapshotTest(
`
sequenceDiagram
Alice->>Bob: I'm short
note left of Alice: I should have bigger fonts
Bob->>Alice: Short as well
`,
{ sequence: { noteFontSize: 18, noteFontFamily: 'Arial' } }
);
});
it('should render different message fonts when configured', () => {
imgSnapshotTest(
`
sequenceDiagram
Alice->>Bob: I'm short
Bob->>Alice: Short as well
`,
{ sequence: { messageFontSize: 18, messageFontFamily: 'Arial' } }
);
});
it('should render different actor fonts when configured', () => {
imgSnapshotTest(
`
sequenceDiagram
Alice->>Bob: I'm short
Bob->>Alice: Short as well
`,
{ sequence: { actorFontSize: 18, actorFontFamily: 'Arial' } }
);
});
it('should render notes aligned to the left when configured', () => {
imgSnapshotTest(
`
sequenceDiagram
Alice->>Bob: I'm short
note left of Alice: I am left aligned
Bob->>Alice: Short as well
`,
{ sequence: { noteAlign: 'left' } }
);
});
it('should render notes aligned to the right when configured', () => {
imgSnapshotTest(
`
sequenceDiagram
Alice->>Bob: I'm short
note left of Alice: I am right aligned
Bob->>Alice: Short as well
`,
{ sequence: { noteAlign: 'right' } }
);
});
});
context('auth width scaling', () => {
it('should render long actor descriptions', () => {
imgSnapshotTest(
`
sequenceDiagram
participant A as Extremely utterly long line of longness which had preivously overflown the actor box as it is much longer than what it should be
A->>Bob: Hola
Bob-->A: Pasten !
`,
{}
);
});
it('should render long notes left of actor', () => {
imgSnapshotTest(
`
sequenceDiagram
Alice->>Bob: Hola
Note left of Alice: Extremely utterly long line of longness which had preivously overflown the actor box as it is much longer than what it should be
Bob->>Alice: I'm short though
`,
{}
);
});
it('should render long notes right of actor', () => {
imgSnapshotTest(
`
sequenceDiagram
Alice->>Bob: Hola
Note right of Alice: Extremely utterly long line of longness which had preivously overflown the actor box as it is much longer than what it should be
Bob->>Alice: I'm short though
`,
{}
);
});
it('should render long notes over actor', () => {
imgSnapshotTest(
`
sequenceDiagram
Alice->>Bob: Hola
Note over Alice: Extremely utterly long line of longness which had preivously overflown the actor box as it is much longer than what it should be
Bob->>Alice: I'm short though
`,
{}
);
});
it('should render long messages from an actor to the left to one to the right', () => {
imgSnapshotTest(
`
sequenceDiagram
Alice->>Bob: Extremely utterly long line of longness which had preivously overflown the actor box as it is much longer than what it should be
Bob->>Alice: I'm short though
`,
{}
);
});
it('should render long messages from an actor to the right to one to the left', () => {
imgSnapshotTest(
`
sequenceDiagram
Alice->>Bob: I'm short
Bob->>Alice: Extremely utterly long line of longness which had preivously overflown the actor box as it is much longer than what it should be
`,
{}
);
});
});
context('background rects', () => {
it('should render a single and nested rects', () => {
imgSnapshotTest(
@@ -129,5 +281,51 @@ context('Aliasing', () => {
{}
);
});
it('should render autonumber when configured with such', () => {
imgSnapshotTest(
`
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!
`,
{ sequence: { actorMargin: 50, showSequenceNumbers: true } }
);
});
it('should render autonumber when autonumber keyword is used', () => {
imgSnapshotTest(
`
sequenceDiagram
autonumber
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!
`,
{}
);
});
it('should render autonumber with different line breaks', () => {
imgSnapshotTest(
`
sequenceDiagram
autonumber
Alice->>John: Hello John,<br>how are you?
Alice->>John: John,<br/>can you hear me?
John-->>Alice: Hi Alice,<br />I can hear you!
John-->>Alice: I feel great!
`,
{}
);
});
});
});

View File

@@ -0,0 +1,358 @@
/* eslint-env jest */
import { imgSnapshotTest } from '../../helpers/util';
describe('State diagram', () => {
it('v2 should render a simple info', () => {
imgSnapshotTest(
`
info
`,
{ logLevel: 1 }
);
cy.get('svg');
});
it('v2 should render a simple state diagrams', () => {
imgSnapshotTest(
`
stateDiagram-v2
[*] --> State1
State1 --> [*]
`,
{ logLevel: 0 }
);
cy.get('svg');
});
it('v2 should render a long descriptions instead of id when available', () => {
imgSnapshotTest(
`
stateDiagram-v2
[*] --> S1
state "Some long name" as S1
`,
{ logLevel: 0 }
);
cy.get('svg');
});
it('v2 should render a long descriptions with additional descriptions', () => {
imgSnapshotTest(
`
stateDiagram-v2
[*] --> S1
state "Some long name" as S1: The description
`,
{ logLevel: 0 }
);
cy.get('svg');
});
it('v2 should render a single state with short descr', () => {
imgSnapshotTest(
`
stateDiagram-v2
state "A long long name" as long1
state "A" as longlonglongid
`,
{ logLevel: 0 }
);
cy.get('svg');
});
it('v2 should render a transition descrions with new lines', () => {
imgSnapshotTest(
`
stateDiagram-v2
[*] --> S1
S1 --> S2: long line using<br/>should work
S1 --> S3: long line using <br>should work
S1 --> S4: long line using \\nshould work
`,
{ logLevel: 0 }
);
cy.get('svg');
});
it('v2 should render a state with a note', () => {
imgSnapshotTest(
`
stateDiagram-v2
State1: The state with a note
note right of State1
Important information! You can write
notes.
end note
`,
{ logLevel: 0 }
);
cy.get('svg');
});
it('v2 should render a state with on the left side when so specified', () => {
imgSnapshotTest(
`
stateDiagram-v2
State1: The state with a note with minus - and plus + in it
note left of State1
Important information! You can write
notes with . and in them.
end note
`,
{ logLevel: 0 }
);
cy.get('svg');
});
it('v2 should render a state with a note together with another state', () => {
imgSnapshotTest(
`
stateDiagram-v2
State1: The state with a note +,-
note right of State1
Important information! You can write +,-
notes.
end note
State1 --> State2 : With +,-
note left of State2 : This is the note +,-<br/>
`,
{ logLevel: 0 }
);
cy.get('svg');
});
it('v2 should render a note with multiple lines in it', () => {
imgSnapshotTest(
`
stateDiagram-v2
State1: The state with a note
note right of State1
Important information! You\ncan write
notes with multiple lines...
Here is another line...
And another line...
end note
`,
{}
);
});
it('v2 should handle multiline notes with different line breaks', () => {
imgSnapshotTest(
`
stateDiagram-v2
State1
note right of State1
Line1<br>Line2<br/>Line3<br />Line4<br />Line5
end note
`,
{}
);
});
it('v2 should render a states with descriptions including multi-line descriptions', () => {
imgSnapshotTest(
`
stateDiagram-v2
State1: This a a single line description
State2: This a a multi line description
State2: here comes the multi part
[*] --> State1
State1 --> State2
State2 --> [*]
`,
{ logLevel: 0 }
);
cy.get('svg');
});
it('v2 should render a simple state diagrams', () => {
imgSnapshotTest(
`
stateDiagram-v2
[*] --> State1
State1 --> State2
State1 --> State3
State1 --> [*]
`,
{ logLevel: 0 }
);
cy.get('svg');
});
it('v2 should render a simple state diagrams with labels', () => {
imgSnapshotTest(
`
stateDiagram-v2
[*] --> State1
State1 --> State2 : Transition 1
State1 --> State3 : Transition 2
State1 --> State4 : Transition 3
State1 --> State5 : Transition 4
State2 --> State3 : Transition 5
State1 --> [*]
`,
{ logLevel: 0 }
);
cy.get('svg');
});
it('v2 should render state descriptions', () => {
imgSnapshotTest(
`
stateDiagram-v2
state "Long state description" as XState1
state "Another Long state description" as XState2
XState2 : New line
XState1 --> XState2
`,
{ logLevel: 0 }
);
cy.get('svg');
});
it('v2 should render composit states', () => {
imgSnapshotTest(
`
stateDiagram-v2
[*] --> NotShooting: Pacifist
NotShooting --> A
NotShooting --> B
NotShooting --> C
state NotShooting {
[*] --> Idle: Yet another long long öong öong öong label
Idle --> Configuring : EvConfig
Configuring --> Idle : EvConfig EvConfig EvConfig EvConfig EvConfig
}
`,
{ logLevel: 0 }
);
cy.get('svg');
});
it('v2 should render multiple composit states', () => {
imgSnapshotTest(
`
stateDiagram-v2
[*]-->TV
state TV {
[*] --> Off: Off to start with
On --> Off : Turn off
Off --> On : Turn on
}
TV--> Console
state Console {
[*] --> Off2: Off to start with
On2--> Off2 : Turn off
Off2 --> On2 : Turn on
On2-->Playing
state Playing {
Alive --> Dead
Dead-->Alive
}
}
`,
{ logLevel: 0 }
);
});
it('v2 should render forks in composit states', () => {
imgSnapshotTest(
`
stateDiagram-v2
[*]-->TV
state TV {
state fork_state &lt;&lt;fork&gt;&gt;
[*] --> fork_state
fork_state --> State2
fork_state --> State3
state join_state &lt;&lt;join&gt;&gt;
State2 --> join_state
State3 --> join_state
join_state --> State4
State4 --> [*]
}
`,
{ logLevel: 0 }
);
});
it('v2 should render forks and joins', () => {
imgSnapshotTest(
`
stateDiagram-v2
state fork_state &lt;&lt;fork&gt;&gt;
[*] --> fork_state
fork_state --> State2
fork_state --> State3
state join_state &lt;&lt;join&gt;&gt;
State2 --> join_state
State3 --> join_state
join_state --> State4
State4 --> [*]
`,
{ logLevel: 0 }
);
cy.get('svg');
});
it('v2 should render concurrency states', () => {
imgSnapshotTest(
`
stateDiagram-v2
[*] --> Active
state Active {
[*] --> NumLockOff
NumLockOff --> NumLockOn : EvNumLockPressed
NumLockOn --> NumLockOff : EvNumLockPressed
--
[*] --> CapsLockOff
CapsLockOff --> CapsLockOn : EvCapsLockPressed
CapsLockOn --> CapsLockOff : EvCapsLockPressed
--
[*] --> ScrollLockOff
ScrollLockOff --> ScrollLockOn : EvCapsLockPressed
ScrollLockOn --> ScrollLockOff : EvCapsLockPressed
}
`,
{ logLevel: 0 }
);
cy.get('svg');
});
it('v2 should render a state with states in it', () => {
imgSnapshotTest(
`
stateDiagram-v2
state PilotCockpit {
state Parent {
C
}
}
`,
{
logLevel: 0,
}
);
});
it('v2 Simplest composit state', () => {
imgSnapshotTest(
`
stateDiagram-v2
state Parent {
C
}
`,
{
logLevel: 0,
}
);
});
it('v2 should handle multiple arrows from one node to another', () => {
imgSnapshotTest(
`
stateDiagram-v2
a --> b: Start
a --> b: Stop
`,
{
logLevel: 0,
}
);
});
});

View File

@@ -106,6 +106,34 @@ describe('State diagram', () => {
);
cy.get('svg');
});
it('should render a note with multiple lines in it', () => {
imgSnapshotTest(
`
stateDiagram
State1: The state with a note
note right of State1
Important information! You\ncan write
notes with multiple lines...
Here is another line...
And another line...
end note
`,
{}
);
});
it('should handle multiline notes with different line breaks', () => {
imgSnapshotTest(
`
stateDiagram
State1
note right of State1
Line1<br>Line2<br/>Line3<br />Line4<br />Line5
end note
`,
{}
);
});
it('should render a states with descriptions including multi-line descriptions', () => {
imgSnapshotTest(
`
@@ -276,4 +304,45 @@ describe('State diagram', () => {
);
cy.get('svg');
});
it('should render a state with states in it', () => {
imgSnapshotTest(
`
stateDiagram
state PilotCockpit {
state Parent {
C
}
}
`,
{
logLevel: 0,
}
);
});
it('Simplest composit state', () => {
imgSnapshotTest(
`
stateDiagram
state Parent {
C
}
`,
{
logLevel: 0,
}
);
});
it('should handle multiple arrows from one node to another', () => {
imgSnapshotTest(
`
stateDiagram
a --> b: Start
a --> b: Stop
`,
{
logLevel: 0,
}
);
});
});

View File

@@ -49,9 +49,11 @@
section Clickable
Visit mermaidjs :active, cl1, 2014-01-07,2014-01-10
Calling a Callback (look at the console log) :cl2, after cl1, 3d
Calling a Callback with args :cl3, after cl1, 3d
click cl1 href "http://localhost:9000/webpackUsage.html"
click cl2 call clickByGantt("test", test, test)
click cl2 call clickByGantt()
click cl3 call clickByGantt("test1", test2, test3)
section Last section
Describe gantt syntax :after doc1, 3d
@@ -69,11 +71,14 @@
document.getElementsByTagName('body')[0].appendChild(div)
}
function clickByGantt(elemName) {
function clickByGantt(arg1, arg2, arg3) {
const div = document.createElement('div')
div.className = 'created-by-gant-click'
div.style = 'padding: 20px; background: green; color: white;'
div.innerText = 'Clicked By Gant'
if (arg1) div.innerText += ' ' + arg1;
if (arg2) div.innerText += ' ' + arg2;
if (arg3) div.innerText += ' ' + arg3;
document.getElementsByTagName('body')[0].appendChild(div)
}

View File

@@ -49,9 +49,11 @@
section Clickable
Visit mermaidjs :active, cl1, 2014-01-07,2014-01-10
Calling a Callback (look at the console log) :cl2, after cl1, 3d
Calling a Callback with args :cl3, after cl1, 3d
click cl1 href "http://localhost:9000/webpackUsage.html"
click cl2 call clickByGantt("test", test, test)
click cl2 call clickByGantt()
click cl3 call clickByGantt("test1", test2, test3)
section Last section
Describe gantt syntax :after doc1, 3d
@@ -69,11 +71,14 @@
document.getElementsByTagName('body')[0].appendChild(div)
}
function clickByGantt(elemName) {
function clickByGantt(arg1, arg2, arg3) {
const div = document.createElement('div')
div.className = 'created-by-gant-click'
div.style = 'padding: 20px; background: green; color: white;'
div.innerText = 'Clicked By Gant'
if (arg1) div.innerText += ' ' + arg1;
if (arg2) div.innerText += ' ' + arg2;
if (arg3) div.innerText += ' ' + arg3;
document.getElementsByTagName('body')[0].appendChild(div)
}

View File

@@ -0,0 +1,282 @@
<html>
<head>
<link
href="https://fonts.googleapis.com/css?family=Montserrat&display=swap"
rel="stylesheet"
/>
<link href="https://fonts.googleapis.com/css?family=Noto+Sans+SC&display=swap" rel="stylesheet">
<style>
body {
background: rgb(221, 208, 208);
font-family: 'Arial';
}
h1 { color: white;}
.mermaid2 {
display: none;
}
</style>
</head>
<body>
<h1>info below</h1>
<div class="mermaid2" style="width: 100%; height: 20%;">
flowchart LR
a --> b
subgraph b [Test]
c --> d -->e
end
</div>
<div class="mermaid2" style="width: 100%; height: 20%;">
flowchart LR
a --> b
subgraph id1 [Test]
a --apa--> c
b
c-->b
b-->H
end
G-->H
G-->c
</div>
<div class="mermaid2" style="width: 50%; height: 20%;">
flowchart LR
A{{A}}-->B{{B}};
click A callback "Tooltip"
click B "http://www.github.com" "This is a link"
</div>
<div class="mermaid2" style="width: 50%; height: 20%;">
flowchart TD
A[Christmas] -->|Get money| B(Go shopping)
B --> C{Let me think}
C -->|One| D[Laptop]
C -->|Two| E[iPhone]
C -->|Three| F[fa:fa-car Car]
</div>
<div class="mermaid2" style="width: 50%; height: 20%;">
stateDiagram-v2
[*]-->TV
state TV {
state fork_state &lt;&lt;fork&gt;&gt;
[*] --> fork_state
fork_state --> State2
fork_state --> State3
state join_state &lt;&lt;join&gt;&gt;
State2 --> join_state
State3 --> join_state
join_state --> State4
State4 --> [*]
}
</div>
<div class="mermaid mermaid-apa" style="width: 100%; height: 20%;">
stateDiagram-v2
[*] --> Still
Still --> [*]
</div>
<div class="mermaid2" style="width: 100%; height: 100%;">
stateDiagram-v2
[*] --> Still
Still --> [*]
Still --> Moving
Moving --> Still
Moving --> Crash
Crash --> [*]
</div>
<div class="mermaid2" style="width: 100%; height: 100%;">
stateDiagram-v2
[*] --> First
First --> Third
First --> sec
state First {
[*] --> fir
fir --> [*]
}
state Second {
[*] --> sec
sec --> [*]
}
state Third {
[*] --> thi
thi --> [*]
}
thi --> sec
</div>
<div class="mermaid2" style="width: 100%; height: 100%;">
flowchart TD
subgraph A
a
end
subgraph B
b
end
subgraph C
subgraph D
d
end
end
A -- oAo --o B
A --> C
</div>
<div class="mermaid2" style="width: 100%; height: 100%;">
flowchart TD
subgraph A
a
end
subgraph B
b
end
c-->A
c-->B
</div>
<div class="mermaid2" style="width: 100%; height: 100%;">
stateDiagram-v2
[*] --> First
First --> Second
First --> Third
state First {
[*] --> fir
fir --> [*]
}
state Second {
[*] --> sec
sec --> [*]
}
state Third {
[*] --> thi
thi --> [*]
}
</div>
<div class="mermaid2" style="width: 100%; height: 100%;">
stateDiagram-v2
[*]-->TV
state TV {
[*] --> Off: Off to start with
On --> Off : Turn off
Off --> On : Turn on
}
TV--> Console
state Console {
[*] --> Off2: Off to start with
On2--> Off2 : Turn off
Off2 --> On2 : Turn on
On2-->Playing
state Playing {
Alive --> Dead
Dead-->Alive
}
}
</div>
<div style="display: flex;flex-direction:column;width: 100%; height: 100%">
<div class="mermaid2" style="width: 100%; height: 100%;">
stateDiagram-v2
state apa {
[*] --> Still
Still --> [*]
Still --> Moving
Moving --> Still
Moving --> Crash
Crash --> [*]
}
</div>
<div class="mermaid2" style="width: 100%; height: 100%">
flowchart TB
a --> b
subgraph id1 [Test]
a --apa--> c
b
c-->b
b-->H
end
G-->H
G-->id1
id1 --> I
I --> G
</div>
<div class="mermaid2" style="width: 100%; height: 100%">
flowchart RL
a --> b
subgraph id1 [Test]
a --apa--> c
b
c-->b
b-->H
end
G-->H
G-->id1
id1 --> I
I --> G
</div>
<div class="mermaid2" style="width: 100%; height: 100%">
flowchart RL
subgraph id1 [Test]
a
end
b-->id1
</div>
<div class="mermaid2" style="width: 100%; height: 100%">
flowchart RL
subgraph id1 [Test1]
a
end
subgraph id2 [Test2]
b
end
a --> id2
a --> b
b-->id1
id1 --> id2
</div>
new:
<div class="mermaid2" style="width: 100%; height: 100%">
flowchart LR
a <--> b
b o--o c
c x--x d
a21([In the box]) --> b2
b2((b2)) --o c2
c2(c2) --x d2 --> id1{{This is the text in the box}} --> A[(cylindrical<br />shape<br />test)]
</div>
old:
<div class="mermaid2" style="width: 100%; height: 100%">
graph LR
a((a)) --> b --> id1{{This is the text in the box}}
A[(cylindrical<br />shape<br />test)]
</div>
</div>
<script src="./mermaid.js"></script>
<script>
mermaid.initialize({
// theme: 'dark',
// arrowMarkerAbsolute: true,
// themeCSS: '.edgePath .path {stroke: red;} .arrowheadPath {fill: red;}',
logLevel: 0,
flowchart: { curve: 'linear', "htmlLabels": false },
// gantt: { axisFormat: '%m/%d/%Y' },
sequence: { actorMargin: 50, showSequenceNumbers: true },
// sequenceDiagram: { actorMargin: 300 } // deprecated
fontFamily: '"arial", sans-serif',
curve: 'linear',
securityLevel: 'loose'
});
function callback(){alert('It worked');}
</script>
</body>
</html>

View File

@@ -2,11 +2,11 @@
<head>
<script src="/e2e.js"></script>
<link href="https://fonts.googleapis.com/css?family=Mansalva&display=swap" rel="stylesheet" />
<link href="https://fonts.googleapis.com/css?family=Noto+Sans+SC&display=swap" rel="stylesheet">
<style>
body {
/* font-family: 'Mansalva', cursive;
font-family: 'Mansalva', cursive; */
font-family: 'times';
/* font-family: 'Mansalva', cursive;*/
font-family: 'Mansalva', cursive;
}
/* .mermaid-main-font {
font-family: "trebuchet ms", verdana, arial;
@@ -33,7 +33,8 @@
// "themeCSS": ":root { --mermaid-font-family: \"trebuchet ms\", verdana, arial;}",
// fontFamily: '\"trebuchet ms\", verdana, arial;'
// fontFamily: '"Comic Sans MS", "Comic Sans", cursive'
fontFamily: '"Mansalva", cursive'
// fontFamily: '"Mansalva", cursive',
fontFamily: '"Noto Sans SC", sans-serif'
});
</script>
</body>

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,41 @@
<html>
<head>
<link
href="https://fonts.googleapis.com/css?family=Montserrat&display=swap"
rel="stylesheet"
/>
</head>
<body>
<h1>User Journey</h1>
<div class="mermaid">
journey
title Go shopping
section Get to the shops
Get car keys:5: Dad
Get into car:5: Dad, Mum, Child 1, Child 2
Really drive to supermarket:3: Dad
section Do shopping
Do actual shop:3: Mum
Get in the way:2: Dad, Child 1, Child 2
Pay: 2: Dad
section Go home
Lose keys:3: Dad
Get cross:1: Dad, Child 1
Find keys:4: Mum
Get into car:4: Dad, Mum, Child 1, Child 2
Drive home:3: Dad
</div>
<script src="./mermaid.js"></script>
<script>
mermaid.initialize({
theme: 'forest',
logLevel: 3,
journey: { taskMargin: 30 },
});
</script>
</body>
</html>

View File

@@ -14,13 +14,23 @@ const contentLoaded = function() {
const graphObj = JSON.parse(Base64.decode(graphBase64));
// const graph = 'hello'
console.log(graphObj);
const div = document.createElement('div');
div.id = 'block';
div.className = 'mermaid';
div.innerHTML = graphObj.code;
document.getElementsByTagName('body')[0].appendChild(div);
if (Array.isArray(graphObj.code)) {
const numCodes = graphObj.code.length;
for (let i = 0; i < numCodes; i++) {
const div = document.createElement('div');
div.id = 'block' + i;
div.className = 'mermaid';
div.innerHTML = graphObj.code[i];
document.getElementsByTagName('body')[0].appendChild(div);
}
} else {
const div = document.createElement('div');
div.id = 'block';
div.className = 'mermaid';
div.innerHTML = graphObj.code;
document.getElementsByTagName('body')[0].appendChild(div);
}
global.mermaid.initialize(graphObj.mermaid);
// console.log('graphObj.mermaid', graphObj.mermaid)
global.mermaid.init();
}
};
@@ -31,23 +41,53 @@ const contentLoadedApi = function() {
const graphBase64 = document.location.href.substr(pos);
const graphObj = JSON.parse(Base64.decode(graphBase64));
// const graph = 'hello'
const div = document.createElement('div');
div.id = 'block';
div.className = 'mermaid';
// div.innerHTML = graphObj.code
document.getElementsByTagName('body')[0].appendChild(div);
global.mermaid.initialize(graphObj.mermaid);
if (Array.isArray(graphObj.code)) {
const numCodes = graphObj.code.length;
const divs = [];
let div;
for (let i = 0; i < numCodes; i++) {
div = document.createElement('div');
div.id = 'block' + i;
div.className = 'mermaid';
// div.innerHTML = graphObj.code
document.getElementsByTagName('body')[0].appendChild(div);
divs[i] = div;
}
mermaid2.render(
'newid',
graphObj.code,
(svgCode, bindFunctions) => {
div.innerHTML = svgCode;
mermaid2.initialize(graphObj.mermaid);
bindFunctions(div);
},
div
);
for (let i = 0; i < numCodes; i++) {
mermaid2.render(
'newid' + i,
graphObj.code[i],
(svgCode, bindFunctions) => {
div.innerHTML = svgCode;
bindFunctions(div);
},
divs[i]
);
}
} else {
const div = document.createElement('div');
div.id = 'block';
div.className = 'mermaid';
// div.innerHTML = graphObj.code
console.warn('graphObj.mermaid', graphObj.mermaid);
document.getElementsByTagName('body')[0].appendChild(div);
mermaid2.initialize(graphObj.mermaid);
mermaid2.render(
'newid',
graphObj.code,
(svgCode, bindFunctions) => {
div.innerHTML = svgCode;
if (bindFunctions) bindFunctions(div);
},
div
);
}
}
};

View File

@@ -28,7 +28,10 @@
div.id = 'the-malware'
div.className = 'malware'
div.innerHTML = 'XSS Succeeded'
document.getElementsByTagName('body')[0].appendChild(div)
document.getElementsByTagName('body')[0].appendChild(div);
// const el = document.querySelector('.mermaid');
// el.parentNode.removeChild(el);
throw new Error('XSS Succeded');
}
</script>
</head>

283
dist/index.html vendored
View File

@@ -16,6 +16,9 @@
<div class="mermaid">
info
</div>
<hr/>
<div class="mermaid">
gantt
title Exclusive end dates (Manual date should end on 3d)
@@ -25,7 +28,6 @@
2 Days: 1, 2019-01-01,2d
Manual Date: 2, 2019-01-01,2019-01-03
</div>
<div class="mermaid">
gantt
title Inclusive end dates (Manual date should end on 4th)
@@ -36,6 +38,27 @@
2 Days: 1, 2019-01-01,2d
Manual Date: 2, 2019-01-01,2019-01-03
</div>
<div class="mermaid">
gantt
title Hide today marker (vertical line should not be visible)
dateFormat YYYY-MM-DD
axisFormat %d
todayMarker off
section Section1
Today: 1, -1h
</div>
<div class="mermaid">
gantt
title Style today marker (vertical line should be 5px wide and half-transparent blue)
dateFormat YYYY-MM-DD
axisFormat %d
todayMarker stroke-width:5px,stroke:#00f,opacity:0.5
section Section1
Today: 1, -1h
</div>
<hr/>
<div class="mermaid">
graph LR
sid-B3655226-6C29-4D00-B685-3D5C734DC7E1["
@@ -289,16 +312,125 @@ graph TB
style 456ac9b0d15a8b7f1e71073221059886 fill:#f9f,stroke:#333,stroke-width:4px
</div>
<div class="mermaid">
graph TD
A[Christmas] -->|Get money| B(Go shopping)
B --> C{{Let me think...<br />Do I want something for work,<br />something to spend every free second with,<br />or something to get around?}}
C -->|One| D[Laptop]
C -->|Two| E[iPhone]
C -->|Three| F[Car]
click A "index.html#link-clicked" "link test"
click B testClick "click test"
classDef someclass fill:#f96;
class A someclass;
graph TD
A[Christmas] -->|Get money| B(Go shopping)
B --> C{{Let me think...<br />Do I want something for work,<br />something to spend every free second with,<br />or something to get around?}}
C -->|One| D[Laptop]
C -->|Two| E[iPhone]
C -->|Three| F[Car]
click A "index.html#link-clicked" "link test"
click B testClick "click test"
classDef someclass fill:#f96;
class A someclass;
class C someclass;
</div>
<div class="mermaid">
graph TD
A([stadium shape test])
A -->|Get money| B([Go shopping])
B --> C([Let me think...<br />Do I want something for work,<br />something to spend every free second with,<br />or something to get around?])
C -->|One| D([Laptop])
C -->|Two| E([iPhone])
C -->|Three| F([Car<br/>wroom wroom])
click A "index.html#link-clicked" "link test"
click B testClick "click test"
classDef someclass fill:#f96;
class A someclass;
class C someclass;
</div>
<div class="mermaid">
graph LR
A[[subroutine shape test]]
A -->|Get money| B[[Go shopping]]
B --> C[[Let me think...<br />Do I want something for work,<br />something to spend every free second with,<br />or something to get around?]]
C -->|One| D[[Laptop]]
C -->|Two| E[[iPhone]]
C -->|Three| F[[Car<br/>wroom wroom]]
click A "index.html#link-clicked" "link test"
click B testClick "click test"
classDef someclass fill:#f96;
class A someclass;
class C someclass;
</div>
<div class="mermaid">
graph LR
A[(cylindrical<br />shape<br />test)]
A -->|Get money| B1[(Go shopping 1)]
A -->|Get money| B2[(Go shopping 2)]
A -->|Get money| B3[(Go shopping 3)]
C[(Let me think...<br />Do I want something for work,<br />something to spend every free second with,<br />or something to get around?)]
B1 --> C
B2 --> C
B3 --> C
C -->|One| D[(Laptop)]
C -->|Two| E[(iPhone)]
C -->|Three| F[(Car)]
click A "index.html#link-clicked" "link test"
click B testClick "click test"
classDef someclass fill:#f96;
class A someclass;
</div>
<div class="mermaid">
graph LR
A1[Multi<br>Line] -->|Multi<br>Line| B1(Multi<br>Line)
C1[Multi<br/>Line] -->|Multi<br/>Line| D1(Multi<br/>Line)
E1[Multi<br />Line] -->|Multi<br />Line| F1(Multi<br />Line)
A2[Multi<br>Line] -->|Multi<br>Line| B2(Multi<br>Line)
C2[Multi<br/>Line] -->|Multi<br/>Line| D2(Multi<br/>Line)
E2[Multi<br />Line] -->|Multi<br />Line| F2(Multi<br />Line)
linkStyle 0 stroke:DarkGray,stroke-width:2px
linkStyle 1 stroke:DarkGray,stroke-width:2px
linkStyle 2 stroke:DarkGray,stroke-width:2px
</div>
<div class="mermaid">
graph LR
A(( )) -->|step 1| B(( ))
B(( )) -->|step 2| C(( ))
C(( )) -->|step 3| D(( ))
linkStyle 1 stroke:greenyellow,stroke-width:2px
style C fill:greenyellow,stroke:green,stroke-width:4px
</div>
<div class="mermaid">
graph TB
TITLE["Link Click Events<br>(click the nodes below)"]
A[link test]
B[anchor test]
C[mailto test]
D[other protocol test]
E[script test]
TITLE --> A & B & C & D & E
click A "https://mermaid-js.github.io/mermaid/#/" "link test"
click B "#link-clicked" "anchor test"
click C "mailto:user@user.user" "mailto test"
click D "notes://do-your-thing/id" "other protocol test"
click E "javascript:alert('test')" "script test"
</div>
<hr/>
<div class="mermaid">
graph LR
A[red<br>text] -->|red<br>text| B(blue<br>text)
C[/red<br/>text/] -->|blue<br/>text| D{blue<br/>text}
E{{default<br />style}} -->|default<br />style| F([default<br />style])
linkStyle default color:Sienna;
linkStyle 0 color:red;
linkStyle 1 stroke:DarkGray,stroke-width:2px,color:#0000ff
style A color:red;
style B color:blue;
style C stroke:#ff0000,fill:#ffcccc,color:#ff0000
style D stroke:#0000ff,fill:#ccccff,color:#0000ff
click B "index.html#link-clicked" "link test"
click D testClick "click test"
</div>
<div class="mermaid">
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
</div>
<hr/>
@@ -331,6 +463,29 @@ and
Alice -->> John: Parallel message 2
end
</div>
<div class="mermaid">
sequenceDiagram
participant 1 as multiline<br>using #lt;br#gt;
participant 2 as multiline<br/>using #lt;br/#gt;
participant 3 as multiline<br />using #lt;br /#gt;
participant 4 as multiline<br />using #lt;br /#gt;
1->>2: multiline<br>using #lt;br#gt;
note right of 2: multiline<br>using #lt;br#gt;
2->>3: multiline<br/>using #lt;br/#gt;
note right of 3: multiline<br/>using #lt;br/#gt;
3->>4: multiline<br />using #lt;br /#gt;
note right of 4: multiline<br />using #lt;br /#gt;
4->>1: multiline<br />using #lt;br /#gt;
note right of 1: multiline<br />using #lt;br /#gt;
</div>
<div class="mermaid">
sequenceDiagram
autonumber
Alice->>John: Hello John,<br>how are you?
Alice->>John: John,<br/>can you hear me?
John-->>Alice: Hi Alice,<br />I can hear you!
John-->>Alice: I feel great!
</div>
<hr/>
@@ -372,6 +527,37 @@ Describe gantt syntax :after doc1, 3d
Add gantt diagram to demo page : 20h
Add another diagram to demo page : 48h
</div>
<div class="mermaid">
gantt
dateFormat YYYY-MM-DD
axisFormat %d/%m
title GANTT diagram with multiline section titles
excludes weekdays 2014-01-10
section A section<br>multiline
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<br/>multiline
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<br />multiline
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 Last section<br />multiline
Describe gantt syntax : after doc1, 3d
Add gantt diagram to demo page : 20h
Add another diagram to demo page : 48h
</div>
<hr/>
@@ -408,9 +594,9 @@ Class09 "0" --* "1..n" C3
Class09 --|> Class07
Class07 : equals()
Class07 : Object[] elementData
Class01 : size()
Class01 : int chimp
Class01 : int gorilla
Class01 : #size()
Class01 : -int chimp
Class01 : +int gorilla
Class08 <--> C2: Cool label
class Class10 {
&lt;&lt;service&gt;&gt;
@@ -418,20 +604,58 @@ class Class10 {
size()
}
</div>
<div class="mermaid">
classDiagram
class Class01~T~
Class01 : #size()
Class01 : -int chimp
Class01 : +int gorilla
class Class10~T~ {
&lt;&lt;service&gt;&gt;
int id
size()
}
</div>
<div class="mermaid">
classDiagram
Class01~T~ <|-- AveryLongClass : Cool
&lt;&lt;interface&gt;&gt; Class01
Class03~T~ "0" *-- "0..n" Class04
Class05 "1" o-- "many" Class06
Class07~T~ .. 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
class Class10 {
&lt;&lt;service&gt;&gt;
int id
size()
}
</div>
<div class="mermaid">
stateDiagram
State1
</div>
</div>
<hr>
<div class="mermaid">
stateDiagram
[*] --> First
state First {
[*] --> second
second --> [*]
}
</div>
<hr>
<div class="mermaid">
stateDiagram
[*] --> First
state First {
[*] --> second
second --> [*]
}
</div>
<div class="mermaid">
stateDiagram
State1: The state with a note
@@ -441,8 +665,16 @@ class Class10 {
end note
State1 --> State2
note left of State2 : This is the note to the left.
</div>
</div>
<div class="mermaid">
stateDiagram
State1
note right of State1
Line1<br>Line2<br/>Line3<br />Line4<br />Line5
end note
</div>
<h1 id="link-clicked">Anchor for "link-clicked" test</h1>
<script src="./mermaid.js"></script>
<script>
@@ -450,6 +682,7 @@ class Class10 {
theme: 'forest',
// themeCSS: '.node rect { fill: red; }',
logLevel: 3,
securityLevel: 'loose',
flowchart: { curve: 'basis' },
gantt: { axisFormat: '%m/%d/%Y' },
sequence: { actorMargin: 50 },

View File

@@ -1,36 +1,9 @@
[![Build Status](https://travis-ci.org/knsv/mermaid.svg?branch=master)](https://travis-ci.org/knsv/mermaid)
# 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 wich 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 enabledClosed 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.
@@ -39,7 +12,38 @@ 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.
**Mermaid was nomiated and won the JS Open Source Awards (2019) in the catory The most existing 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.**
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.5
With version 8.5 there are some bug fixes and enhancements, plus a new diagram type, entity relationship diagrams.
![Image showing the new ER diagram type](./img/er.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
@@ -50,8 +54,8 @@ graph TD;
B-->D;
C-->D;
```
![Flowchart](./img/flow.png)
![Flowchart](./img/flow.png)
### Sequence diagram
@@ -68,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
@@ -85,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
@@ -106,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
@@ -133,6 +137,17 @@ merge newbranch
![Git graph](./img/git.png)
### Entity Relationship Diagram - :exclamation: experimental
```
erDiagram
CUSTOMER ||--o{ ORDER : places
ORDER ||--|{ LINE-ITEM : contains
CUSTOMER }|..|{ DELIVERY-ADDRESS : uses
```
![ER diagram](./img/simple-er.png)
## Installation
@@ -152,12 +167,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)
@@ -165,72 +178,72 @@ 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 hard time keeping up. To remedy this
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
with the future development mermaid.
with the future development of mermaid.
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).

View File

@@ -12,10 +12,19 @@
- [Sequence diagram](sequenceDiagram.md)
- [Class Diagram](classDiagram.md)
- [State Diagram](stateDiagram.md)
- [Entity Relationship Diagram](entityRelationshipDiagram.md)
- [User Journey](user-journey.md)
- [Gantt](gantt.md)
- [Pie Chart](pie.md)
- Guide
- [Development](development.md)
- [mermaidAPI](mermaidAPI.md)
- [Changelog](CHANGELOG.md)
- [Changelog](CHANGELOG.md)
- I'm a n00b
- [overview](n00b-overview.md)
- [Getting started - easier](n00b-gettingStarted.md)
- [Diagram syntax intro](n00b-syntaxReference.md)
- [Advanced usage](n00b-advanced.md)

View File

@@ -29,7 +29,7 @@ Mermaid can render class diagrams.
+bool is_wild
+run()
}
```
```mermaid
classDiagram
@@ -52,8 +52,8 @@ Mermaid can render class diagrams.
class Zebra{
+bool is_wild
+run()
}
}
```
## Syntax
@@ -105,55 +105,120 @@ Naming convention: a class name should be composed of alphanumeric (unicode allo
UML provides mechanisms to represent class members, such as attributes and methods, and additional information about them.
#### 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 is it optional:
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.
- `+` Public
- `-` Private
- `#` Protected
- `~` Package
Mermaid distinguishes between attributes and functions/methods based on if the **parenthesis** `()` are present or not. The one with `()` are treated as functions/methods, and others as attributes.
There are two ways to define the members of a class, and regardless of the 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:
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:
```
class BankAccount
BankAccount : +String owner
BankAccount : +BigDecimal balance
BankAccount : +deposit(amount)
BankAccount : +withdrawl(amount)
BankAccount : +withdrawal(amount)
```
```mermaid
``` mermaid
classDiagram
class BankAccount
BankAccount : +String owner
BankAccount : +BigDecimal balance
BankAccount : +deposit(amount)
BankAccount : +withdrawl(amount)
```
```
- 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
+BigDecimal balance
+deposit(amount)
+deposit(amount) bool
+withdrawl(amount)
}
```
```mermaid
classDiagram
class BankAccount{
+String owner
+BigDecimal balance
+deposit(amount) bool
+withdrawl(amount) int
}
```
#### 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
+BigDecimal balance
+deposit(amount) bool
+withdrawl(amount) int
}
```
```mermaid
classDiagram
class BankAccount{
+String owner
+BigDecimal balance
+deposit(amount)
+withdrawl(amount)
}```
+deposit(amount) bool
+withdrawl(amount) int
}
```
#### 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:
```
classDiagram
class Square~Shape~{
int id
List~int~ position
setPoints(List~int~ points)
getPoints() List~int~
}
Square : -List~string~ messages
Square : +setMessages(List~string~ messages)
Square : +getMessages() List~string~
```
```mermaid
classDiagram
class Square~Shape~{
int id
List~int~ position
setPoints(List~int~ points)
getPoints() List~int~
}
Square : -List~string~ messages
Square : +setMessages(List~string~ messages)
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
- `-` Private
- `#` Protected
- `~` 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.
A relationship is a general term covering the specific types of logical connections found on class and object diagrams.
```
[classA][Arrow][ClassB]:LabelText
```
@@ -161,22 +226,26 @@ A relationship is a general term covering the specific types of logical connecti
There are different types of relations defined for classes under UML which are currently supported:
Type | Description
--- | ---
<\|--| Inheritance
*-- | Composition
o-- | Aggregation
--> | Association
-- | Link
--- | ---
<\|-- | Inheritance
*-- | Composition
o-- | Aggregation
--> | Association
-- | Link (Solid)
..> | Dependency
..\|> | Realization
.. | Link (Dashed)
<!--- TODO ..> Dependency--->
```
classDiagram
classA <|-- classB
classC *-- classD
classE o-- classF
classG <-- classH
classI <.. classJ
classK .. classL
classI -- classJ
classK <.. classL
classM <|.. classN
classO .. classP
```
@@ -186,34 +255,40 @@ classA <|-- classB
classC *-- classD
classE o-- classF
classG <-- classH
classI <.. classJ
classK .. classL
classI -- classJ
classK <.. classL
classM <|.. classN
classO .. classP
```
We can use the arrowheads in opposite directions as well :
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
classC --* classD
classE --o classF
classG <--> classH
classI ..> classJ
classK .. classL
classA --|> classB : Inheritance
classC --* classD : Composition
classE --o classF : Aggregation
classG --> classH : Association
classI -- classJ : Link(Solid)
classK ..> classL : Dependency
classM ..|> classN : Realization
classO .. classP : Link(Dashed)
```
```mermaid
classDiagram
classA --|> classB
classC --* classD
classE --o classF
classG <--> classH
classI ..> classJ
classK .. classL
classA --|> classB : Inheritance
classC --* classD : Composition
classE --o classF : Aggregation
classG --> classH : Association
classI -- classJ : Link(Solid)
classK ..> classL : Dependency
classM ..|> classN : Realization
classO .. classP : Link(Dashed)
```
## Labels on Relations
## Labels on Relations
It is possible to add a label text to a relation:
```
@@ -234,7 +309,7 @@ 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.
Multiplicity notations are placed near the ends of an association.
The different cardinality options are :
- `0..1` Zero or one
@@ -243,7 +318,7 @@ The different cardinality options are :
- `1..*` One or more
- `*` Many
- `n` n {where n>1}
- `0..n` zeor to n {where n>1}
- `0..n` zero to n {where n>1}
- `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.
@@ -262,7 +337,7 @@ classDiagram
Student "1" --> "1..*" Course
Galaxy --> "many" Star : Contains
```
## Annotations on classes
## 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
@@ -322,7 +397,115 @@ class Color{
}
```
## Comments
Comments can be entered within a class diagram, which will be ignored by the parser. Comments need to be on their own line, and must be prefaced with `%%` (double percent signs). Any text after the start of the comment to the next newline will be treated as a comment, including any class diagram syntax
```
classDiagram
%% This whole line is a comment classDiagram class Shape <<interface>>
class Shape{
<<interface>>
noOfVertices
draw()
}
```
## Interaction
It is possible to bind a click event to a node, the click can lead to either a javascript callback or to a link which will be opened in a new browser tab. **Note**: This functionality is disabled when using `securityLevel='strict'` and enabled when using `securityLevel='loose'`.
You would define these actions on a separate line after all classes have been declared.
```
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.)
### Examples:
*URL Link:*
```
classDiagram
class Shape
link Shape "http://www.github.com" "This is a tooltip for a link"
```
*Callback:*
```
classDiagram
class Shape
callback Shape "callbackFunction" "This is a tooltip for a callback"
```
```
<script>
var callbackFunction = function(){
alert('A callback was triggered');
}
<script>
```
```mermaid
classDiagram
class Class01
class Class02
callback Class01 "callbackFunction" "Callback tooltip"
link Class02 "http://www.github.com" "This is a link"
```
> **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">
classDiagram
Animal <|-- Duck
Animal <|-- Fish
Animal <|-- Zebra
Animal : +int age
Animal : +String gender
Animal: +isMammal()
Animal: +mate()
class Duck{
+String beakColor
+swim()
+quack()
}
class Fish{
-int sizeInFeet
-canEat()
}
class Zebra{
+bool is_wild
+run()
}
callback Duck callback "Tooltip"
click Zebra "http://www.github.com" "This is a link"
</div>
<script>
var callback = function(){
alert('A callback was triggered');
}
var config = {
startOnLoad:true,
securityLevel:'loose',
};
mermaid.initialize(config);
</script>
</body>
```
## Styling
@@ -334,7 +517,7 @@ 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 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

View File

@@ -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

View File

@@ -0,0 +1,80 @@
# Entity Relationship Diagrams
> An entityrelationship 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. Currently you can only define entities and relationships, but not attributes.
## 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:
```
<first-entity> <relationship> <second-entity> : <relationship-label>
```
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

View File

@@ -5,7 +5,7 @@ pie title NETFLIX
"Time spent looking for movie" : 90
"Time spent watching it" : 10
```
``` mermaid
```mermaid
pie title NETFLIX
"Time spent looking for movie" : 90
"Time spent watching it" : 10
@@ -21,7 +21,7 @@ pie title What Voldemort doesn't have?
"FRIENDS" : 2
"FAMILY" : 3
"NOSE" : 45
```
```
## Basic sequence diagram
```
@@ -35,8 +35,6 @@ sequenceDiagram
Bob-->Alice: Checking with John...
Alice->John: Yes... John, how are you?
```
```mermaid
sequenceDiagram
Alice ->> Bob: Hello Bob, how are you?
@@ -49,9 +47,15 @@ sequenceDiagram
Alice->John: Yes... John, how are you?
```
## Basic flowchart
```
graph LR
A[Square Rect] -- Link text --> B((Circle))
A --> C(Round Rect)
B --> D{Rhombus}
C --> D
```
```mermaid
graph LR
A[Square Rect] -- Link text --> B((Circle))
@@ -63,6 +67,29 @@ graph LR
## Larger flowchart with some styling
```
graph TB
sq[Square shape] --> ci((Circle shape))
subgraph A
od>Odd shape]-- Two line<br/>edge comment --> ro
di{Diamond with <br/> line break} -.-> ro(Rounded<br>square<br>shape)
di==>ro2(Rounded square shape)
end
%% Notice that no text in shape are added here instead that is appended further down
e --> od3>Really long text with linebreak<br>in an Odd shape]
%% Comments after double percent signs
e((Inner / circle<br>and some odd <br>special characters)) --> f(,.?!+-*ز)
cyr[Cyrillic]-->cyr2((Circle shape Начало));
classDef green fill:#9f6,stroke:#333,stroke-width:2px;
classDef orange fill:#f96,stroke:#333,stroke-width:4px;
class sq,e green
class di orange
```
```mermaid
graph TB
sq[Square shape] --> ci((Circle shape))
@@ -90,6 +117,21 @@ graph TB
## Loops, alt and opt
```
sequenceDiagram
loop Daily query
Alice->>Bob: Hello Bob, how are you?
alt is sick
Bob->>Alice: Not so good :(
else is well
Bob->>Alice: Feeling fresh like a daisy
end
opt Extra response
Bob->>Alice: Thanks for asking
end
end
```
```mermaid
sequenceDiagram
loop Daily query
@@ -109,6 +151,19 @@ sequenceDiagram
## Message to self in loop
```
sequenceDiagram
participant Alice
participant Bob
Alice->>John: Hello John, how are you?
loop Healthcheck
John->>John: Fight against hypochondria
end
Note right of John: Rational thoughts<br/>prevail...
John-->>Alice: Great!
John->>Bob: How about you?
Bob-->>John: Jolly good!
```
```mermaid
sequenceDiagram
participant Alice

View File

@@ -35,6 +35,9 @@ Possible directions are:
* TD - same as TB
## flowchart
This renders a flowchart in the same way as graph but with a new rendering method opening up for long requested features as more arrow types, multi directional arrows and link to and from subgraphs. Apart from the graph type flowchart/graph the syntax is the same. This is currently experimental but when the beta persioid is over both the graph and flowchart keyswords will render in the new way. This means it is ok to start betat testing flowcharts.
## Nodes & shapes
@@ -78,6 +81,39 @@ graph LR
id1(This is the text in the box)
```
### A stadium-shaped node
```
graph LR
id1([This is the text in the box])
```
```mermaid
graph LR
id1([This is the text in the box])
```
### A node in a subroutine shape
```
graph LR
id1[[This is the text in the box]]
```
```mermaid
graph LR
id1[[This is the text in the box]]
```
### A node in a cylindrical shape
```
graph LR
id1[(Database)]
```
```mermaid
graph LR
id1[(Database)]
```
### A node in the form of a circle
```
@@ -123,6 +159,28 @@ graph LR
id1{{This is the text in the box}}
```
### Parallelogram
```
graph TD
id1[/This is the text in the box/]
```
```mermaid
graph TD
id1[/This is the text in the box/]
```
### Parallelogram alt
```
graph TD
id1[\This is the text in the box\]
```
```mermaid
graph TD
id1[\This is the text in the box\]
```
### Trapezoid
```
@@ -174,7 +232,7 @@ graph LR
```
graph LR
A-- This is the text ---B
A-- This is the text! ---B
```
```mermaid
graph LR
@@ -270,6 +328,71 @@ graph LR
A -- text --> B -- text2 --> C
```
It is also possible to declare multiple nodes links in the same line as per below:
```
graph LR
a --> b & c--> d
```
```mermaid
graph LR
a --> b & c--> d
```
You can then describe dependencies in a very expressive way. Like the onliner below:
```
graph TB
A & B--> C & D
```
```mermaid
graph TB
A & B--> C & D
```
If you describe the same diagram using the the basic syntax, it will take four lines. A
word of warning, one could go overboard with this making the graph harder to read in
markdown form. The Swedish word `lagom` comes to mind. It means, not to much and not to little.
This goes for expressive syntaxes as well.
```
graph TB
A --> C
A --> D
B --> C
B --> D
```
## Beta: New arrow types
When using flowchart instead of graph there is the are new types of arrows supported as per below:
```
flowchart LR
A --o B
B --x C
```
```mermaid
flowchart LR
A --o B
B --x C
```
## Beta: multi directional arrows
When using flowchart instead of graph there is the possibility to use multidirectional arrows.
```
flowchart LR
A o--o B
B <--> C
C x--x D
```
```mermaid
flowchart LR
A o--o B
B <--> C
C x--x D
```
## Special characters that break syntax
@@ -334,6 +457,60 @@ graph TB
end
```
You can also set an excplicit id for the subgraph.
```
graph TB
c1-->a2
subgraph ide1 [one]
a1-->a2
end
```
```mermaid
graph TB
c1-->a2
subgraph id1 [one]
a1-->a2
end
```
## Beta: flowcharts
With the graphtype flowcharts it is also possible to set edges to and from subgraphs as in the graph below.
```
flowchart TB
c1-->a2
subgraph one
a1-->a2
end
subgraph two
b1-->b2
end
subgraph three
c1-->c2
end
one --> two
three --> two
two --> c2
```
```mermaid
flowchart TB
c1-->a2
subgraph one
a1-->a2
end
subgraph two
b1-->b2
end
subgraph three
c1-->c2
end
one --> two
three --> two
two --> c2
```
## Interaction
@@ -350,10 +527,10 @@ Examples of tooltip usage below:
```
<script>
var callback = function(){
alert('A callback was triggered');
}
<script>
var callback = function(){
alert('A callback was triggered');
}
</script>
```
```
@@ -366,35 +543,37 @@ graph LR;
The tooltip text is surrounded in double quotes. The styles of the tooltip are set by the class .mermaidTooltip.
```mermaid
graph LR;
graph LR
A-->B;
click A callback "Tooltip"
click B "http://www.github.com" "This is a link"
```
> **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:
```
<body>
<div class="mermaid">
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"
</div>
<script>
var callback = function(){
var callback = function(){
alert('A callback was triggered');
}
var config = {
startOnLoad:true,
flowchart:{
useMaxWidth:true,
htmlLabels:true,
curve:'cardinal',
},
securityLevel:'loose',
startOnLoad:true,
flowchart:{
useMaxWidth:true,
htmlLabels:true,
curve:'cardinal',
},
securityLevel:'loose',
};
mermaid.initialize(config);
@@ -402,6 +581,16 @@ Beginners tip, a full example using interactive links in a html context:
</body>
```
### Comments
Comments can be entered within a flow diagram, which will be ignored by the parser. Comments need to be on their own line, and must be prefaced with `%%` (double percent signs). Any text after the start of the comment to the next newline will be treated as a comment, including any flow syntax
```
graph LR
%% this is a comment A -- text --> B{node}
A -- text --> B -- text2 --> C
```
## Styling and classes
### Styling links
@@ -412,7 +601,7 @@ Instead of ids, the order number of when the link was defined in the graph is us
defined in the linkStyle statement will belong to the fourth link in the graph:
```
linkStyle 3 stroke:#ff3,stroke-width:4px;
linkStyle 3 stroke:#ff3,stroke-width:4px,color:red;
```
@@ -424,13 +613,13 @@ It is possible to apply specific styles such as a thicker border or a different
graph LR
id1(Start)-->id2(Stop)
style id1 fill:#f9f,stroke:#333,stroke-width:4px
style id2 fill:#ccf,stroke:#f66,stroke-width:2px,stroke-dasharray: 5, 5
style id2 fill:#bbf,stroke:#f66,stroke-width:2px,color:#fff,stroke-dasharray: 5, 5
```
```mermaid
graph LR
id1(Start)-->id2(Stop)
style id1 fill:#f9f,stroke:#333,stroke-width:4px
style id2 fill:#ccf,stroke:#f66,stroke-width:2px,stroke-dasharray: 5, 5
style id2 fill:#bbf,stroke:#f66,stroke-width:2px,color:#fff,stroke-dasharray: 5, 5
```
@@ -458,6 +647,19 @@ It is also possible to attach a class to a list of nodes in one statement:
class nodeId1,nodeId2 className;
```
A shorter form of adding a class is to attach the classname to the node using the `:::`operator as per below:
```
graph LR
A:::someclass --> B
classDef someclass fill:#f96;
```
```mermaid
graph LR
A:::someclass --> B
classDef someclass fill:#f96;
```
### Css classes

View File

@@ -1,8 +1,19 @@
# Gantt diagrams
> A Gantt chart is a type of bar chart, first developed by Karol Adamiecki in 1896, and independently by Henry Gantt in the 1910s, that illustrates a project schedule. Gantt charts illustrate the start and finish dates of the terminal elements and summary elements of a project.
Mermaid can render Gantt diagrams.
> A Gantt chart is a type of bar chart, first developed by Karol Adamiecki in 1896, and independently by Henry Gantt in the 1910s, that illustrates a project schedule and the amount of time it would take for any one project to finish. Gantt charts illustrate number of days between the start and finish dates of the terminal elements and summary elements of a project.
## A note to users
Gannt Charts will record each scheduled task as one continuous bar that extends from the left to the right. The x axis represents time and the y records the different tasks and the order in which they are to be completed.
It is important to remember that when a date, day or collection of dates specific to a task are "excluded", the Gannt Chart will accomodate those changes by extending an equal number of day, towards the right, not by creating a gap inside the task.
As shown here ![](https://github.com/NeilCuzon/mermaid/blob/develop/docs/img/Gantt-excluded-days-within.png)
However, if the excluded date/s is between two tasks that are set to start consecutively, the excluded dates will be skipped graphically and left blank, and the following task will begin after the end of the excluded date/s.
As shown here ![](https://github.com/NeilCuzon/mermaid/blob/develop/docs/img/Gantt-long-weekend-look.png)
A Gantt chart is useful for tracking the amount of time it would take before a project is finished, but it can also be used to graphically represent "non-working days, with a few tweaks.
Mermaid can render Gantt diagrams as SVG, PNG or a MarkDown link that can be pasted into docs.
```
gantt
@@ -30,9 +41,12 @@ gantt
```
gantt
dateFormat YYYY-MM-DD
title Adding GANTT diagram functionality to mermaid
dateFormat :YYYY-MM-DD
title :Adding GANTT diagram functionality to mermaid
excludes :excludes the named dates/days from being included in a charted task..
(Accepts specific dates in YYYY-MM-DD format, days of the week ("sunday") or "weekends", but not the word "weekdays".)
section A section
Completed task :done, des1, 2014-01-06,2014-01-08
Active task :active, des2, 2014-01-09, 3d
@@ -87,6 +101,20 @@ gantt
Add another diagram to demo page :48h
```
It is possible to set multiple depenendenies separated by space:
```
gantt
apple :a, 2017-07-20, 1w
banana :crit, b, 2017-07-23, 1d
cherry :active, c, after b a, 1d
```
```
gantt
apple :a, 2017-07-20, 1w
banana :crit, b, 2017-07-23, 1d
cherry :active, c, after b a, 1d
```
### Title
Tbd
@@ -99,23 +127,21 @@ Tbd
## Setting dates
Tbd
`dateFormat` defines the format of the date **input** of your gantt elements. How these dates are represented in the rendered chart **output** are defined by `axisFormat`.
### Date format
### Input date format
The default date format is YYYY-MM-DD. You can define your ``dateFormat``. For example:
The default input date format is `YYYY-MM-DD`. You can define your custom ``dateFormat``.
```
dateFormat YYYY MM DD
dateFormat YYYY-MM-DD
```
The following formating options are supported:
### Diagram definition
```
Input Example Description:
```
YYYY 2014 4 digit year
YY 14 2 digit year
Q 1..4 Quarter of year. Sets month to first month in quarter.
@@ -126,8 +152,6 @@ Do 1st..31st Day of month with ordinal
DDD DDDD 1..365 Day of year
X 1410715640.579 Unix timestamp
x 1410715640579 Unix ms timestamp
Input Example Description
H HH 0..23 24 hour time
h hh 1..12 12 hour time used with a A.
a A am pm Post or ante meridiem
@@ -141,8 +165,15 @@ Z ZZ +12:00 Offset from UTC as +-HH:mm, +-HHmm, or Z
More info in: http://momentjs.com/docs/#/parsing/string-format/
### Output date format on the axis
### Scale
The default output date format is YYYY-MM-DD. You can define your custom ``axisFormat``, like `2020-Q1` for the first quarter of the year 2020.
```
axisFormat %Y-%m-%d
```
The following formating strings are supported:
```
%a - abbreviated weekday name.
@@ -173,6 +204,23 @@ More info in: http://momentjs.com/docs/#/parsing/string-format/
More info in: https://github.com/mbostock/d3/wiki/Time-Formatting
## Comments
Comments can be entered within a gantt chart, which will be ignored by the parser. Comments need to be on their own line, and must be prefaced with `%%` (double percent signs). Any text after the start of the comment to the next newline will be treated as a comment, including any diagram syntax
```
gantt
title A Gantt Diagram
%% this is a comment
dateFormat YYYY-MM-DD
section Section
A task :a1, 2014-01-01, 30d
Another task :after a1 , 20d
section Another
Task in sec :2014-01-12 , 12d
another task : 24d
```
## Styling
@@ -271,3 +319,48 @@ Param | Descriotion | Default value
--- | --- | ---
mirrorActor|Turns on/off the rendering of actors below the diagram as well as above it|false
bottomMarginAdj|Adjusts how far down the graph ended. Wide borders styles with css could generate unwantewd clipping which is why this config param exists.|1
## Interaction
It is possible to bind a click event to a task, the click can lead to either a javascript callback or to a link which will be opened in the current browser tab. **Note**: This functionality is disabled when using `securityLevel='strict'` and enabled when using `securityLevel='loose'`.
```
click taskId call callback(arguments)
click taskId href URL
```
* taskId is the id of the task
* callback is the name of a javascript function defined on the page displaying the graph, the function will be called with the taskId as the parameter if no other arguments are specified..
Beginners tip, a full example using interactive links in an html context:
```
<body>
<div class="mermaid">
gantt
dateFormat YYYY-MM-DD
section Clickable
Visit mermaidjs :active, cl1, 2014-01-07, 3d
Print arguments :cl2, after cl1, 3d
Print task :cl3, after cl2, 3d
click cl1 href "https://mermaidjs.github.io/"
click cl2 call printArguments("test1", "test2", test3)
click cl3 call printTask()
</div>
<script>
var printArguments = function(arg1, arg2, arg3) {
alert('printArguments called with arguments: ' + arg1 + ', ' + arg2 + ', ' + arg3);
}
var printTask = function(taskId) {
alert('taskId: ' + taskId);
}
var config = {
startOnLoad:true,
securityLevel:'loose',
};
mermaid.initialize(config);
</script>
</body>
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

BIN
docs/img/er.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

BIN
docs/img/n00b-firstFlow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 KiB

BIN
docs/img/simple-er.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

View File

@@ -7,8 +7,21 @@
<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.4.0/dist/mermaid.min.js"></script>
<!-- <script src="//localhost:9000/mermaid.js"></script> -->
<script src="//cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
<!-- <script src="http://localhost:9000/mermaid.js"></script> -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-153180559-1', 'auto');
if(location) {
ga('send', 'pageview', location.hash);
}
</script>
<style>
.markdown-section {
max-width: 1200px;
@@ -43,8 +56,18 @@
var num = 0;
mermaid.initialize({ logLevel:0, startOnLoad: false, themeCSS:'.label { font-family: Source Sans Pro,Helvetica Neue,Arial,sans-serif; }' });
</script>
<script>
window.onhashchange = function(a) {
//code
if(location) {
ga('send', 'pageview', location.hash);
}
}
</script>
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
<script src="//unpkg.com/docsify/lib/plugins/search.min.js"></script>
<scrpt src="//unpkg.com/docsify/lib/plugins/ga.min.js"></scrpt>
</body>
</html>
<!-- -->

140
docs/integrations.md Normal file
View File

@@ -0,0 +1,140 @@
# Integrations
The following is a list of different integrations and plugins where mermaid is being used
## Productivity
- [GitLab](https://docs.gitlab.com/ee/user/markdown.html#diagrams-and-flowcharts) (**Native support**)
- [GitHub](https://github.com)
- [Github action: Compile mermaid to image](https://github.com/neenjaw/compile-mermaid-markdown-action)
- [svg-generator](https://github.com/SimonKenyonShepard/mermaidjs-github-svg-generator)
- [GitBook](http://gitbook.com)
- [Mermaid Plugin](https://github.com/JozoVilcek/gitbook-plugin-mermaid)
- [Markdown with Mermaid CLI](https://github.com/miao1007/gitbook-plugin-mermaid-cli)
- [Mermaid plugin for GitBook](https://github.com/wwformat/gitbook-plugin-mermaid-pdf)
- [Atlassian Products](https://www.atlassian.com)
- [Mermaid Plugin for Confluence](https://marketplace.atlassian.com/apps/1214124/mermaid-plugin-for-confluence?hosting=server&tab=overview)
- [CloudScript.io Addon](https://marketplace.atlassian.com/apps/1219878/cloudscript-io-mermaid-addon?hosting=cloud&tab=overview)
- [Auto convert diagrams in Jira](https://github.com/coddingtonbear/jirafs-mermaid)
- [Redmine](https://redmine.org)
- [Mermaid Macro](https://www.redmine.org/plugins/redmine_mermaid_macro)
- [redmine-mermaid](https://github.com/styz/redmine_mermaid)
- [markdown-for-mermaid-plugin](https://github.com/jamieh-mongolian/markdown-for-mermaid-plugin)
## CRM/ERP/Similar
- [coreBOS](http://blog.corebos.org/blog/december2019)
## Blogs
- [Wordpress](https://wordpress.org)
- [WordPress Markdown Editor](https://wordpress.org/plugins/wp-githuber-md)
- [WP-ReliableMD](https://wordpress.org/plugins/wp-reliablemd/)
- [Hexo](https://hexo.io)
- [hexo-filter-mermid-diagrams](https://github.com/webappdevelp/hexo-filter-mermaid-diagrams)
- [hexo-tag-mermaid](https://github.com/JameChou/hexo-tag-mermaid)
- [hexo-mermaid-diagrams](https://github.com/mslxl/hexo-mermaid-diagrams)
## CMS
- [VuePress](https://vuepress.vuejs.org/)
- [Plugin for Mermaid.js](https://github.com/eFrane/vuepress-plugin-mermaidjs)
- [vuepress-plugin-mermaidjs-cli](https://github.com/gwleclerc/vuepress-plugin-mermaidjs-cli)
- [Grav CMS](https://getgrav.org/)
- [Mermaid Diagrams](https://github.com/DanielFlaum/grav-plugin-mermaid-diagrams)
- [Gitlab Markdown Adapter](https://github.com/Goutte/grav-plugin-gitlab-markdown-adapter)
## Communication
- [Discourse](https://discourse.org)
- [Mermaid Plugin](https://github.com/pnewell/discourse-mermaid), [And](https://github.com/unfoldingWord-dev/discourse-mermaid)
- [Mattermost](https://mattermost.com/)
- [Mermaid Plugin](https://github.com/SpikeTings/Mermaid)
- [phpBB](https://phpbb.com)
- [phpbb-ext-mermaid](https://github.com/AlfredoRamos/phpbb-ext-mermaid)
- [NodeBB](https://nodebb.org)
- [Mermaid Plugin](https://www.npmjs.com/package/nodebb-plugin-mermaid)
## Wikis
- [Media Wiki](https://www.mediawiki.org/wiki/Extension:Mermaid)
- [Semantic Media Wiki](https://semantic-mediawiki.org)
- [Mermaid Plugin](https://github.com/SemanticMediaWiki/Mermaid)
- [FosWiki](https://foswiki.org)
- [Mermaid Plugin](https://foswiki.org/Extensions/MermaidPlugin)
- [DokuWiki](https://dokuwiki.org)
- [Flowcharts](https://www.dokuwiki.org/plugin:flowcharts?s[]=mermaid)
- [TiddlyWiki](https://tiddlywiki.com/)
- [mermaid-tw5-plugin](https://github.com/michaeljmcd/mermaid-tw5-plugin)
## Editor Plugins
- [Vs Code](https://code.visualstudio.com/)
- [Markdown Preview Mermaid Support](https://marketplace.visualstudio.com/items?itemName=bierner.markdown-mermaid)
- [Mermaid Preview](https://marketplace.visualstudio.com/items?itemName=vstirbu.vscode-mermaid-preview)
- [Mermaid Markdown Syntax Highlighting](https://marketplace.visualstudio.com/items?itemName=bpruitt-goddard.mermaid-markdown-syntax-highlighting)
- [Mermaid Editor](https://marketplace.visualstudio.com/items?itemName=tomoyukim.vscode-mermaid-editor)
- [Mermaid Export](https://marketplace.visualstudio.com/items?itemName=Gruntfuggly.mermaid-export)
- [Markdown PDF](https://marketplace.visualstudio.com/items?itemName=yzane.markdown-pdf)
- [Preview](https://marketplace.visualstudio.com/items?itemName=searKing.preview-vscode)
- [Preview Sequence Diagrams](https://marketplace.visualstudio.com/items?itemName=arichika.previewseqdiag-vscode)
- [Markdown-It](https://github.com/markdown-it/markdown-it)
- [Textual UML Parser](https://github.com/manastalukdar/markdown-it-textual-uml)
- [Mermaid Plugin](https://github.com/tylingsoft/markdown-it-mermaid)
- [md-it-mermaid](https://github.com/iamcco/md-it-mermaid)
- [markdown-it-mermaid-fence-new](https://github.com/Revomatico/markdown-it-mermaid-fence-new)
- [markdown-it-mermaid-less](https://github.com/searKing/markdown-it-mermaid-less)
- [Atom](https://atom.io)
- [Markdown Preview Enhanced](https://atom.io/packages/markdown-preview-enhanced)
- [Atom Mermaid](https://atom.io/packages/atom-mermaid)
- [Language Mermaid Syntax Highlighter](https://atom.io/packages/language-mermaid)
- [Sublime Text 3](https://sublimetext.com)
- [Mermaid Package](https://packagecontrol.io/packages/Mermaid)
- [Astah](http://astah.net)
- [Export to Mermaid](https://github.com/Avens666/Astah_Jude_UML_export_to_Markdown-mermaid-Plantuml-)
- [Light Table](http://lighttable.com/)
- [Mermaid Plugin](https://github.com/cldwalker/Mermaid)
- [Draw.io](http://draw.io) - [Plugin](https://github.com/nopeslide/drawio_mermaid_plugin)
- [Inkdrop](http://inkdrop.app) - [Plugin](https://github.com/inkdropapp/inkdrop-mermaid)
- [Vim](https://vim.org)
- [Vim Diagram Syntax](https://github.com/zhaozg/vim-diagram)
- [Brackets](http://brackets.io/)
- [Mermaid Preview](https://s3.amazonaws.com/extend.brackets/alanhohn.mermaid-preview/alanhohn.mermaid-preview-1.0.2.zip)
- [Iodide](https://github.com/iodide-project/iodide)
- [iodide-mermaid-plugin](https://github.com/iodide-project/iodide-mermaid-plugin)
## Document Generation
- [Sphinx](https://www.sphinx-doc.org/en/master/)
- [sphinxcontrib-mermaid](https://github.com/mgaitan/sphinxcontrib-mermaid)
- [remark.js](https://remark.js.org/)
- [remark-mermaid](https://github.com/temando/remark-mermaid)
- [jSDoc](https://jsdoc.app/)
- [jsdoc-mermaid](https://github.com/Jellyvision/jsdoc-mermaid)
- [MkDocs](https://mkdocs.org)
- [MarkdownMermaid](https://github.com/sebastienwarin/mkdocs-mermaid-plugin)
- [Type Doc](https://typedoc.org/)
- [typedoc-plugin-mermaid](https://www.npmjs.com/package/typedoc-plugin-mermaid)
## Chrome Extensions
- [Mermaid Diagrams](https://chrome.google.com/webstore/detail/mermaid-diagrams/phfcghedmopjadpojhmmaffjmfiakfil)
- [GitHub + Mermaid](https://chrome.google.com/webstore/detail/github-%2B-mermaid/goiiopgdnkogdbjmncgedmgpoajilohe)
- [Mermaid Markdown](https://chrome.google.com/webstore/detail/mermaid-markdown/mboeoikjijmjcjgpccghbcoegikliijg)
- [Monkeys](https://chrome.google.com/webstore/detail/monkeys-mermaid-for-githu/cplfdpoajbclbgphaphphcldamfkjlgi)
- [Asciidoctor Live Preview](https://chrome.google.com/webstore/detail/asciidoctorjs-live-previe/iaalpfgpbocpdfblpnhhgllgbdbchmia) __works in the new IE as well__
- [Chrome Diagrammer](https://chrome.google.com/webstore/detail/chrome-diagrammer/bkpbgjmkomfoakfklcjeoegkklgjnnpk)
- [Diagram Tab](https://github.com/khafast/diagramtab)
## Other
- [Jekyll](https://jekyllrb.com/)
- [jekyll-mermaid](https://rubygems.org/gems/jekyll-mermaid)
- [jekyll-mermaid-diagrams](https://github.com/fuzhibo/jekyll-mermaid-diagrams)
- [Reveal.js](https://github.com/hakimel/reveal.js)
- [reveal.js-mermaid-plugin](https://github.com/ludwick/reveal.js-mermaid-plugin)
- [Bisheng](https://www.npmjs.com/package/bisheng)
- [bisheng-plugin-mermaid](https://github.com/yct21/bisheng-plugin-mermaid)
- [Reveal CK](https://github.com/jedcn/reveal-ck)
- [reveal-ck-mermaid-plugin](https://github.com/tmtm/reveal-ck-mermaid-plugin)
- [mermaid-server: Generate diagrams using a HTTP request](https://github.com/TomWright/mermaid-server)

BIN
docs/liveEditorOptions.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

View File

@@ -19,7 +19,7 @@ These are the default options which can be overridden with the initialization ca
<pre>
mermaid.initialize({
flowchart:{
htmlLabels: false
htmlLabels: false
}
});
</pre>
@@ -27,7 +27,7 @@ mermaid.initialize({
**Example 2:**
<pre>
<script>
&lt;script>
var config = {
startOnLoad:true,
flowchart:{
@@ -39,10 +39,10 @@ mermaid.initialize({
securityLevel:'loose',
};
mermaid.initialize(config);
</script>
&lt;/script>
</pre>
A summary of all options and their defaults is found [here](https://github.com/knsv/mermaid/blob/master/docs/mermaidAPI.md#mermaidapi-configuration-defaults). A description of each option follows below.
A summary of all options and their defaults is found [here][2]. A description of each option follows below.
## theme
@@ -105,6 +105,18 @@ Flag for setting whether or not a html tag should be used for rendering labels
on the edges.
**Default value true**.
### nodeSpacing
Defines the spacing between nodes on the same level (meaning horizontal spacing for
TB or BT graphs, and the vertical spacing for LR as well as RL graphs).
**Default value 50**.
### rankSpacing
Defines the spacing between nodes on different levels (meaning vertical spacing for
TB or BT graphs, and the horizontal spacing for LR as well as RL graphs).
**Default value 50**.
### curve
How mermaid renders curves for flowcharts. Possible values are
@@ -162,6 +174,14 @@ margin around notes.
Space between messages.
**Default value 35**.
### messageAlign
Multiline message alignment. Possible values are:
- left
- center **default**
- right
### mirrorActors
mirror actors under diagram.
@@ -189,6 +209,41 @@ This will display arrows that start and begin at the same node as right angles,
This will show the node numbers
**Default value false**.
### actorFontSize
This sets the font size of the actor's description
**Default value 14**.
### actorFontFamily
This sets the font family of the actor's description
**Default value "Open-Sans", "sans-serif"**.
### noteFontSize
This sets the font size of actor-attached notes.
**Default value 14**.
### noteFontFamily
This sets the font family of actor-attached notes.
**Default value "trebuchet ms", verdana, arial**.
### noteAlign
This sets the text alignment of actor-attached notes.
**Default value center**.
### messageFontSize
This sets the font size of actor messages.
**Default value 16**.
### messageFontFamily
This sets the font family of actor messages.
**Default value "trebuchet ms", verdana, arial**.
## gantt
The object containing configurations specific for gantt diagrams\*
@@ -243,6 +298,117 @@ The number of alternating section styles.
Datetime format of the axis. This might need adjustment to match your locale and preferences
**Default value '%Y-%m-%d'**.
## journey
The object containing configurations specific for sequence diagrams
### diagramMarginX
margin to the right and left of the sequence diagram.
**Default value 50**.
### diagramMarginY
margin to the over and under the sequence diagram.
**Default value 10**.
### actorMargin
Margin between actors.
**Default value 50**.
### width
Width of actor boxes
**Default value 150**.
### height
Height of actor boxes
**Default value 65**.
### boxMargin
Margin around loop boxes
**Default value 10**.
### boxTextMargin
margin around the text in loop/alt/opt boxes
**Default value 5**.
### noteMargin
margin around notes.
**Default value 10**.
### messageMargin
Space between messages.
**Default value 35**.
### messageAlign
Multiline message alignment. Possible values are:
- left
- center **default**
- right
### bottomMarginAdj
Depending on css styling this might need adjustment.
Prolongs the edge of the diagram downwards.
**Default value 1**.
### useMaxWidth
when this flag is set the height and width is set to 100% and is then scaling with the
available space if not the absolute space required is used.
**Default value true**.
### rightAngles
This will display arrows that start and begin at the same node as right angles, rather than a curve
**Default value false**.
## er
The object containing configurations specific for entity relationship diagrams
### diagramPadding
The amount of padding around the diagram as a whole so that embedded diagrams have margins, expressed in pixels
### layoutDirection
Directional bias for layout of entities. Can be either 'TB', 'BT', 'LR', or 'RL',
where T = top, B = bottom, L = left, and R = right.
### minEntityWidth
The mimimum width of an entity box, expressed in pixels
### minEntityHeight
The minimum height of an entity box, expressed in pixels
### entityPadding
The minimum internal padding between the text in an entity box and the enclosing box borders, expressed in pixels
### stroke
Stroke color of box edges and lines
### fill
Fill color of entity boxes
### fontSize
Font size (expressed as an integer representing a number of pixels)
## render
Function that renders an svg with a graph from a chart definition. Usage example below.
@@ -263,11 +429,12 @@ mermaidAPI.initialize({
### Parameters
- `id` the id of the element to be rendered
- `txt` the graph definition
- `_txt`
- `cb` callback which is called after rendering is finished with the svg code as inparam.
- `container` selector to element in which a div with the graph temporarily will be inserted. In one is
provided a hidden div will be inserted in the body of the page instead. The element will be removed when rendering is
completed.
- `txt` the graph definition
##
@@ -275,7 +442,7 @@ mermaidAPI.initialize({
<pre>
<script>
&lt;script>
var config = {
theme:'default',
logLevel:'fatal',
@@ -297,6 +464,7 @@ mermaidAPI.initialize({
boxTextMargin:5,
noteMargin:10,
messageMargin:35,
messageAlign:'center',
mirrorActors:true,
bottomMarginAdj:1,
useMaxWidth:true,
@@ -317,8 +485,9 @@ mermaidAPI.initialize({
}
};
mermaid.initialize(config);
</script>
&lt;/script>
</pre>
[1]: https://github.com/knsv/mermaid/blob/master/docs/mermaidAPI.md#render
[2]: https://github.com/knsv/mermaid/blob/master/docs/mermaidAPI.md#mermaidapi-configuration-defaults

21
docs/n00b-advanced.md Normal file
View File

@@ -0,0 +1,21 @@
# Advanced n00b mermaid (Coming soon..)
## splitting mermaid code from html
A more condensed html code can be achieved by embedding the mermaid code in its own .js file, which is referenced like so:
```
stuff stuff
</div>
</body>
</html>
```
The actual mermaid file could for example look like this:
```
mermaid content...
```
---
## mermaid configuration options
...

167
docs/n00b-gettingStarted.md Normal file
View File

@@ -0,0 +1,167 @@
# A basic mermaid User-Guide for Beginners
Creating diagrams and charts, using mermaid code is simple.
But how is the code turned into a diagram in a web page? This is done with the use of a mermaid renderer.
Thankfully the mermaid renderer is very accessible, in essence it is a piece of javascript that can be called.
Most widely used web browsers, such as Firefox, Chrome and Safari, can render mermaid, Internet Explorer however cannot. The web browser also needs access to the online mermaid renderer which it downloads from https://cdn.jsdelivr.net/npm/mermaid
# For beginners, there are three relatively easy ways you can use mermaid:
1. Using the mermaid [live editor](https://mermaid-js.github.io/mermaid-live-editor/)
2. Using a mermaid plugin, such as that for Confluence or [Atom](https://atom.io/packages/atom-mermaid).
3. Calling mermaid renderer with HTML, deployed in a friendly browser.
# Following either of these examples, you can get started with creating your own diagrams using mermaid code.
## 1. The mermaid live editor:
A great way to get started with mermaid is to visit [The mermaid live editor](https://mermaidjs.github.io/mermaid-live-editor).
In the `Code` section one can write or edit raw mermaid code, and instantly `Preview` the rendered result on the panel beside it.
![Flowchart](./img/n00b-liveEditor.png)
You can also copy the code from the code section and paste it into either a mermaid plugin or in inside an html file, which will be taught in numbers 2 and 3.
It is also an easier way to develop diagrams. You can also click "Copy Markdown" to copy the markdown code for the diagram, that can then be pasted directly into your documentation.
![Flowchart](./img/liveEditorOptions.png)
The `Mermaid configuration` is for controlling mermaid behaviour. An easy introduction to mermaid configuration is found in the [Advanced usage](n00b-advanced.md) section. A complete configuration reference cataloguing default values is found on the [mermaidAPI](mermaidAPI.md) page.
## 2. Using mermaid plugins:
Thanks to the growing popularity of mermaid, many plugins already exist which incorporate a mermaid renderer. An extensive list can be found [here](integrations.md).
One example in the list is the [Atlassian Confluence mermaid plugin](https://marketplace.atlassian.com/apps/1214124/mermaid-plugin-for-confluence?hosting=server&tab=overview)
When the mermaid plugin is installed on a Confluence server, one can insert a mermaid object into any Confluence page.
# Here is a step by step process for using the mermaid-Confluence plugin:
---
- In a Confluence page, Add Other macros.
![Flowchart](./img/n00b-Confluence1.png)
---
- Search for mermaid.
![Flowchart](./img/n00b-Confluence2.png)
---
- The mermaid object appears. Paste your mermaid code into it.
![Flowchart](./img/n00b-Confluence3.png)
---
- Save the page and the diagram appears.
![Flowchart](./img/n00b-Confluence4.png)
---
## 3. mermaid using any web server (or just a browser):
This method can be used with any common web server. Apache, IIS, nginx, node express [...], you pick your favourite.
We do not need to install anything on the server, apart from a program (like Notepad++) that can generate an html file, which is then deployed by a web browser (such as Firefox, Chrome, Safari, but not Internet Explorer).
So if you want to really simplify things when testing this out, don't use a web server at all but just create the file locally and drag it into your browser window. It is the browser which does all the work of rendering mermaid!
# Here are instructions for creating an html file with mermaid code:
# Note that all this is written in the html `<body>` section of the web page.
When writing the html file, we give the web browser three instructions inside the html code:
a. A reference for fetching the online mermaid renderer, which is written in Javascript.
b. The mermaid code for the diagram we want to create.
c. The `mermaid.initialize()` command to start the rendering process.
This is what needs to go into the html file:
# a. The reference to the mermaid renderer has to be contained in a `<script src>` tag like so:
```
<body>
<script src="https://cdn.jsdelivr.net/npm/mermaid@8.4.0/dist/mermaid.min.js"></script>
</body>
```
# b. The embedded mermaid code is similarly placed inside a `<div>` tag:
```
<body>
Here is a mermaid diagram:
<div class="mermaid">
graph TD
A[Client] --> B[Load Balancer]
B --> C[Server01]
B --> D[Server02]
</div>
</body>
```
(take note that every mermaid chart/graph/diagram, has to have separate `<div>` tags.)
# c. When initializing mermaid using `mermaid.initialize()`, mermaid takes all the `<div class="mermaid">` tags it can find in the html body and starts to render them one by one. This is done like so:
```
<body>
<script>mermaid.initialize({startOnLoad:true});</script>
</body>
```
# *Finally*
# If the three steps mentioned are followed you will end up with something like this:
```
<html>
<body>
<script src="https://cdn.jsdelivr.net/npm/mermaid@8.4.0/dist/mermaid.min.js"></script>
<script>mermaid.initialize({startOnLoad:true});</script>
Here is one mermaid diagram:
<div class="mermaid">
graph TD
A[Client] --> B[Load Balancer]
B --> C[Server1]
B --> D[Server2]
</div>
And here is another:
<div class="mermaid">
graph TD
A[Client] -->|tcp_123| B(Load Balancer)
B -->|tcp_456| C[Server1]
B -->|tcp_456| D[Server2]
</div>
</body>
</html>
```
# Save this to a html file and fetch it with a browser from the web server (or just drag it into your web browser window) and voila!
---
**Three additional comments from Knut Sveidqvist, creator of mermaid:**
- In early versions of mermaid, the `<script src>` tag was invoked in the `<head>` part of the web page. Nowdays we can place it directly in `<body>` as seen above. However, older parts of the documentation frequently reflects the previous way which still works.
- We initialize the mermaid rendering with `mermaid.initialize()` directly in the html code. In principle this could be done through placing `mermaid.initialize()` inside of `mermaid.min.js`. We would then eliminate the need for this explicit line in the html. However, there are use cases where we do want to separate the two steps. Sometimes we want full control over when we start looking for `<div>`tags inside the web page with `mermaid.initialize()`, for example when we think that all `<div>` tags may not have been loaded by the time `mermaid.min.js` runs.
- In the example above, `mermaid.min.js` is called using an absolute path. Even worse, the example includes the mermaid version number which of course will change as time goes by. However, the example makes it easy to understand what is going on - even though it is perhaps doomed in a way we do not want in a production environment. When going from testing mermaid out to getting serious with it, I would suggest one of the following approaches for calling `mermaid.min.js`:
1. If you do not enter a specific version, you automatically get the latest one.
2. If you really need a specific version, hard code it (this is rare but it happens).
3. If you need to know the current mermaid version, replace a mermaid code block with the word `info` and the version will be returned like [this](https://mermaid-js.github.io/mermaid-live-editor/#/edit/eyJjb2RlIjoiaW5mb1xuXG4iLCJtZXJtYWlkIjp7InRoZW1lIjoiZGVmYXVsdCJ9fQ==)

29
docs/n00b-overview.md Normal file
View File

@@ -0,0 +1,29 @@
# Overview for n00bs
mermaid is a tool that aims to make diagrams and flowcharts for documentation, easier.
with mermaid, diagrams can be created through comments like this in a script:
```
graph TD
A[Client] --> B[Load Balancer]
B --> C[Server01]
B --> D[Server02]
```
And they are rendered into this and made part of the documentation:
![Flowchart](./img/n00b-firstFlow.png)
Most of the similar visuals that you might need to create can be scripted in a similar way, with a varitety of different symbols and chart types available.
Since the diagram source is text based, it can be part of production scripts (and other pieces of code). So less time needs be spent on documenting as a separate task.
Comparing with Visio and similar applications, mermaid is a really fast way to create good visualizations. This is especially apparent when editing a complex visualisations, a process that usually takes hours in a desktop application, but only takes minutes (or even less if generation has been scripted) with mermaid.
mermaid can potentially cut down the amount of time and effort spent on the process of creating diagrams, to a fraction of what you usually put in.
However, a lot of the mermaid documentation is geared to professional frontend developers, presuming a skill set which I simply do not have.
If you need some basic instructions and introductions, here are a few good places to start:
For information on how to use mermaid, click [here](https://mermaid-js.github.io/mermaid/#/n00b-gettingStarted), or you can try out the mermaid [live editor](https://mermaid-js.github.io/mermaid-live-editor/), alternatively, you could also view the [integrations and uses](https://github.com/mermaid-js/mermaid/blob/develop/docs/integrations.md) for mermaid.

View File

@@ -0,0 +1,11 @@
## Diagram syntax reference
Having already [gotten started](n00b-gettingStarted.md), existing diagram syntax documentation was easy enough to follow even for a n00b like me..
- [Flowchart](flowchart.md)
- [Sequence diagram](sequenceDiagram.md)
- [Class Diagram](classDiagram.md)
- [State Diagram](stateDiagram.md)
- [Gantt](gantt.md)
- [Pie Chart](pie.md)

View File

@@ -9,6 +9,7 @@ sequenceDiagram
Alice->>John: Hello John, how are you?
John-->>Alice: Great!
```
```mermaid
sequenceDiagram
Alice->>John: Hello John, how are you?
@@ -31,6 +32,7 @@ sequenceDiagram
Alice->>John: Hello John, how are you?
John-->>Alice: Great!
```
```mermaid
sequenceDiagram
participant John
@@ -50,6 +52,7 @@ sequenceDiagram
A->>J: Hello John, how are you?
J->>A: Great!
```
```mermaid
sequenceDiagram
participant A as Alice
@@ -68,15 +71,14 @@ Messages can be of two displayed either solid or with a dotted line.
There are six types of arrows currently supported:
Type | Description
--- | ---
-> | Solid line without arrow
--> | Dotted line without arrow
->> | Solid line with arrowhead
-->> | Dotted line with arrowhead
-x | Solid line with a cross at the end (async)
--x | Dotted line with a cross at the end (async)
| Type | Description |
| ---- | ------------------------------------------- |
| -> | Solid line without arrow |
| --> | Dotted line without arrow |
| ->> | Solid line with arrowhead |
| -->> | Dotted line with arrowhead |
| -x | Solid line with a cross at the end (async) |
| --x | Dotted line with a cross at the end (async) |
## Activations
@@ -89,6 +91,7 @@ sequenceDiagram
John-->>Alice: Great!
deactivate John
```
```mermaid
sequenceDiagram
Alice->>John: Hello John, how are you?
@@ -104,6 +107,7 @@ sequenceDiagram
Alice->>+John: Hello John, how are you?
John-->>-Alice: Great!
```
```mermaid
sequenceDiagram
Alice->>+John: Hello John, how are you?
@@ -119,6 +123,7 @@ sequenceDiagram
John-->>-Alice: Hi Alice, I can hear you!
John-->>-Alice: I feel great!
```
```mermaid
sequenceDiagram
Alice->>+John: Hello John, how are you?
@@ -127,7 +132,6 @@ sequenceDiagram
John-->>-Alice: I feel great!
```
## Notes
It is possible to add notes to a sequence diagram. This is done by the notation
@@ -140,6 +144,7 @@ sequenceDiagram
participant John
Note right of John: Text in note
```
```mermaid
sequenceDiagram
participant John
@@ -153,13 +158,13 @@ sequenceDiagram
Alice->John: Hello John, how are you?
Note over Alice,John: A typical interaction
```
```mermaid
sequenceDiagram
Alice->John: Hello John, how are you?
Note over Alice,John: A typical interaction
```
## Loops
It is possible to express loops in a sequence diagram. This is done by the notation
@@ -179,6 +184,7 @@ sequenceDiagram
John-->Alice: Great!
end
```
```mermaid
sequenceDiagram
Alice->John: Hello John, how are you?
@@ -187,7 +193,6 @@ sequenceDiagram
end
```
## Alt
It is possible to express alternative paths in a sequence diagram. This is done by the notation
@@ -222,6 +227,7 @@ sequenceDiagram
Bob->>Alice: Thanks for asking
end
```
```mermaid
sequenceDiagram
Alice->>Bob: Hello Bob, how are you?
@@ -235,15 +241,63 @@ sequenceDiagram
end
```
## Parallel
It is possible to show actions that are happening in parallel.
This is done by the notation
```
par [Action 1]
... statements ...
and [Action 2]
... statements ...
and [Action N]
... statements ...
end
```
See the example below:
```mermaid
sequenceDiagram
par Alice to Bob
Alice->>Bob: Hello guys!
and Alice to John
Alice->>John: Hello guys!
end
Bob-->>Alice: Hi Alice!
John-->>Alice: Hi Alice!
```
It is also possible to nest parallel blocks.
```mermaid
sequenceDiagram
par Alice to Bob
Alice->>Bob: Go help John
and Alice to John
Alice->>John: I want this done today
par John to Charlie
John->>Charlie: Can we do this today?
and John to Diana
John->>Diana: Can you help us today?
end
end
```
## Background Highlighting
It is possible to highlight flows by providing colored background rects. This is done by the notation
The colors are defined using rgb and rgba syntax.
```
rect rgb(0, 255, 0)
... content ...
end
```
```
rect rgba(0, 0, 255, .1)
... content ...
@@ -271,116 +325,161 @@ sequenceDiagram
```
## Comments
Comments can be entered within a sequence diagram, which will be ignored by the parser. Comments need to be on their own line, and must be prefaced with `%%` (double percent signs). Any text after the start of the comment to the next newline will be treated as a comment, including any diagram syntax
```
sequenceDiagram
Alice->>John: Hello John, how are you?
%% this is a comment
John-->>Alice: Great!
```
## sequenceNumbers
It is possible to get a sequence number attached to each arrow in a sequence diagram. This can be configured when adding mermaid to the website as shown below:
```
<script>
mermaid.initialize({
sequence: { showSequenceNumbers: true },
});
</script>
```
It can also be be turned on via the diagram code as in the diagram:
```
sequenceDiagram
autonumber
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!
```
```mermaid
sequenceDiagram
autonumber
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!
```
## 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
Styling of 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
Class | Description
--- | ---
actor | Style for the actor box at the top of the diagram.
text.actor | Styles for text in the actor box at the top of the diagram.
actor-line | The vertical line for an actor.
messageLine0 | Styles for the solid message line.
messageLine1 | Styles for the dotted message line.
messageText | Defines styles for the text on the message arrows.
labelBox | Defines styles label to left in a loop.
labelText | Styles for the text in label for loops.
loopText | Styles for the text in the loop box.
loopLine | Defines styles for the lines in the loop box.
note | Styles for the note box.
noteText | Styles for the text on in the note boxes.
| Class | Description |
| ------------ | ----------------------------------------------------------- |
| actor | Style for the actor box at the top of the diagram. |
| text.actor | Styles for text in the actor box at the top of the diagram. |
| actor-line | The vertical line for an actor. |
| messageLine0 | Styles for the solid message line. |
| messageLine1 | Styles for the dotted message line. |
| messageText | Defines styles for the text on the message arrows. |
| labelBox | Defines styles label to left in a loop. |
| labelText | Styles for the text in label for loops. |
| loopText | Styles for the text in the loop box. |
| loopLine | Defines styles for the lines in the loop box. |
| note | Styles for the note box. |
| noteText | Styles for the text on in the note boxes. |
### Sample stylesheet
```css
body {
background: white;
}
.actor {
stroke: #CCCCFF;
fill: #ECECFF;
stroke: #ccccff;
fill: #ececff;
}
text.actor {
fill:black;
stroke:none;
fill: black;
stroke: none;
font-family: Helvetica;
}
.actor-line {
stroke:grey;
stroke: grey;
}
.messageLine0 {
stroke-width:1.5;
stroke-dasharray: "2 2";
marker-end:"url(#arrowhead)";
stroke:black;
stroke-width: 1.5;
stroke-dasharray: '2 2';
marker-end: 'url(#arrowhead)';
stroke: black;
}
.messageLine1 {
stroke-width:1.5;
stroke-dasharray: "2 2";
stroke:black;
stroke-width: 1.5;
stroke-dasharray: '2 2';
stroke: black;
}
#arrowhead {
fill:black;
fill: black;
}
.messageText {
fill:black;
stroke:none;
fill: black;
stroke: none;
font-family: 'trebuchet ms', verdana, arial;
font-size:14px;
font-size: 14px;
}
.labelBox {
stroke: #CCCCFF;
fill: #ECECFF;
stroke: #ccccff;
fill: #ececff;
}
.labelText {
fill:black;
stroke:none;
fill: black;
stroke: none;
font-family: 'trebuchet ms', verdana, arial;
}
.loopText {
fill:black;
stroke:none;
fill: black;
stroke: none;
font-family: 'trebuchet ms', verdana, arial;
}
.loopLine {
stroke-width:2;
stroke-dasharray: "2 2";
marker-end:"url(#arrowhead)";
stroke: #CCCCFF;
stroke-width: 2;
stroke-dasharray: '2 2';
marker-end: 'url(#arrowhead)';
stroke: #ccccff;
}
.note {
stroke: #decc93;
stroke: #CCCCFF;
stroke: #ccccff;
fill: #fff5ad;
}
.noteText {
fill:black;
stroke:none;
fill: black;
stroke: none;
font-family: 'trebuchet ms', verdana, arial;
font-size:14px;
font-size: 14px;
}
```
## Configuration
Is it possible to adjust the margins for rendering the sequence diagram.
@@ -391,19 +490,25 @@ How to use the CLI is described in the [mermaidCLI](mermaidCLI.html) page.
```javascript
mermaid.sequenceConfig = {
diagramMarginX:50,
diagramMarginY:10,
boxTextMargin:5,
noteMargin:10,
messageMargin:35,
mirrorActors:true
diagramMarginX: 50,
diagramMarginY: 10,
boxTextMargin: 5,
noteMargin: 10,
messageMargin: 35,
mirrorActors: true
};
```
### Possible configuration params:
Param | Description | Default value
--- | --- | ---
mirrorActor | Turns on/off the rendering of actors below the diagram as well as above it | false
bottomMarginAdj | Adjusts how far down the graph ended. Wide borders styles with css could generate unwantewd clipping which is why this config param exists. | 1
| Param | Description | Default value |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------ |
| mirrorActor | Turns on/off the rendering of actors below the diagram as well as above it | false |
| bottomMarginAdj | Adjusts how far down the graph ended. Wide borders styles with css could generate unwanted clipping which is why this config param exists. | 1 |
| actorFontSize | Sets the font size for the actor's description | 14 |
| actorFontFamily | Sets the font family for the actor's description | "Open-Sans", "sans-serif" |
| noteFontSize | Sets the font size for actor-attached notes | 14 |
| noteFontFamily | Sets the font family for actor-attached notes | "trebuchet ms", verdana, arial |
| noteAlign | Sets the text alignment for text in actor-attached notes | center |
| messageFontSize | Sets the font size for actor<->actor messages | 16 |
| messageFontFamily | Sets the font family for actor<->actor messages | "trebuchet ms", verdana, arial |

View File

@@ -5,7 +5,7 @@
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.
```markdown
stateDiagram
stateDiagram-v2
[*] --> Still
Still --> [*]
@@ -15,6 +15,16 @@ stateDiagram
Crash --> [*]
```
```mermaid
stateDiagram-v2
[*] --> Still
Still --> [*]
Still --> Moving
Moving --> Still
Moving --> Crash
Crash --> [*]
```
```mermaid
stateDiagram
[*] --> Still
@@ -30,39 +40,39 @@ In state diagrams systems are described in terms of its states and how the syste
## States
A state can be declares in multiple ways. The simplest way is to define a state id as a description.
A state can be declared in multiple ways. The simplest way is to define a state id as a description.
```markdown
stateDiagram
stateDiagram-v2
s1
```
```mermaid
stateDiagram
stateDiagram-v2
s1
```
Another way is by using the state keyword with a description as per below:
```markdown
stateDiagram
stateDiagram-v2
state "This is a state description" as s2
```
```mermaid
stateDiagram
stateDiagram-v2
state "This is a state description" as s2
```
Another way to define a state with a description is to define the state id followed by a colon and the description:
```markdown
stateDiagram
stateDiagram-v2
s2 : This is a state description
```
```mermaid
stateDiagram
stateDiagram-v2
s2 : This is a state description
```
@@ -73,24 +83,24 @@ Transitions are path/edges when one state passes into another. This is represent
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.
```markdown
stateDiagram
stateDiagram-v2
s1 --> s2
```
```mermaid
stateDiagram
stateDiagram-v2
s1 --> s2
```
It is possible to add text to a transition. To describe what it represents.
```markdown
stateDiagram
stateDiagram-v2
s1 --> s2: A transition
```
```mermaid
stateDiagram
stateDiagram-v2
s1 --> s2: A transition
```
@@ -99,13 +109,13 @@ stateDiagram
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.
```markdown
stateDiagram
stateDiagram-v2
[*] --> s1
s1 --> [*]
```
```mermaid
stateDiagram
stateDiagram-v2
[*] --> s1
s1 --> [*]
```
@@ -118,7 +128,7 @@ have several internal states. These are called composite states in this terminol
In order to define a composite state you need to use the state keyword followed by and id and the body of the composite state between \{\}. See the example below:
```markdown
stateDiagram
stateDiagram-v2
[*] --> First
state First {
[*] --> second
@@ -127,7 +137,7 @@ stateDiagram
```
```mermaid
stateDiagram
stateDiagram-v2
[*] --> First
state First {
[*] --> second
@@ -138,7 +148,7 @@ stateDiagram
You can do this in several layers:
```markdown
stateDiagram
stateDiagram-v2
[*] --> First
state First {
@@ -157,14 +167,14 @@ stateDiagram
```
```mermaid
stateDiagram
stateDiagram-v2-v2
[*] --> First
state First {
[*] --> Second
state Second {
[*] --> second
second --> Third
[*] --> second2
second2 --> Third
state Third {
[*] --> third
@@ -177,7 +187,7 @@ stateDiagram
You can also define transitions also between composite states:
```markdown
stateDiagram
stateDiagram-v2
[*] --> First
First --> Second
First --> Third
@@ -197,7 +207,7 @@ stateDiagram
```
```mermaid
stateDiagram
stateDiagram-v2
[*] --> First
First --> Second
First --> Third
@@ -223,7 +233,7 @@ stateDiagram
It is possible to specify a fork in the diagram using &lt;&lt;fork&gt;&gt; &lt;&lt;join&gt;&gt;.
```markdown
stateDiagram
stateDiagram-v2
state fork_state <<fork>>
[*] --> fork_state
fork_state --> State2
@@ -237,7 +247,7 @@ It is possible to specify a fork in the diagram using &lt;&lt;fork&gt;&gt; &lt;&
```
```mermaid
stateDiagram
stateDiagram-v2
state fork_state <<fork>>
[*] --> fork_state
fork_state --> State2
@@ -258,7 +268,7 @@ Sometimes nothing says it better then a Post-it note. That is also the case in s
Here you can choose to put the note to the *right of* or to the *left of* a node.
```markdown
stateDiagram
stateDiagram-v2
State1: The state with a note
note right of State1
Important information! You can write
@@ -269,7 +279,7 @@ Here you can choose to put the note to the *right of* or to the *left of* a node
```
```mermaid
stateDiagram
stateDiagram-v2
State1: The state with a note
note right of State1
Important information! You can write
@@ -285,7 +295,7 @@ Here you can choose to put the note to the *right of* or to the *left of* a node
As in plantUml you can specify concurrency using the -- symbol.
```markdown
stateDiagram
stateDiagram-v2
[*] --> Active
state Active {
@@ -304,7 +314,7 @@ As in plantUml you can specify concurrency using the -- symbol.
```
```mermaid
stateDiagram
stateDiagram-v2
[*] --> Active
state Active {
@@ -322,6 +332,21 @@ As in plantUml you can specify concurrency using the -- symbol.
}
```
## Comments
Comments can be entered within a state diagram chart, which will be ignored by the parser. Comments need to be on their own line, and must be prefaced with `%%` (double percent signs). Any text after the start of the comment to the next newline will be treated as a comment, including any diagram syntax
```
stateDiagram-v2
[*] --> Still
Still --> [*]
%% this is a comment
Still --> Moving
Moving --> Still %% another comment
Moving --> Crash
Crash --> [*]
```
## Styling
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

View File

@@ -159,14 +159,13 @@ The main idea of the API is to be able to call a render function with the graph
will render the graph and call a callback with the resulting svg code. With this approach it is up to the site creator to
fetch the graph definition from the site (perhaps from a textarea), render it and place the graph somewhere in the site.
To do this, include mermaidAPI on your web website instead of mermaid.js. The example below show an outline of how this
could be used. The example just logs the resulting svg to the javascript console.
The example below show an outline of how this could be used. The example just logs the resulting svg to the javascript console.
```html
<script src="mermaidAPI.js"></script>
<script src="mermaid.js"></script>
<script>
mermaidAPI.initialize({
mermaid.mermaidAPI.initialize({
startOnLoad:false
});
$(function(){
@@ -178,7 +177,7 @@ could be used. The example just logs the resulting svg to the javascript console
};
var graphDefinition = 'graph TB\na-->b';
var graph = mermaidAPI.render('graphDiv', graphDefinition, insertSvg);
var graph = mermaid.mermaidAPI.render('graphDiv', graphDefinition, insertSvg);
});
</script>
```

34
docs/user-journey.md Normal file
View File

@@ -0,0 +1,34 @@
# User Journey Diagram
> User journeys describe at a high level of detail exactly what steps different users take to complete a specific task within a system, application or website. This technique shows the current (as-is) user workflow, and reveals areas of improvement for the to-be workflow. (Wikipedia)
Mermaid can render user journey diagrams:
```markdown
journey
title My working day
section Go to work
Make tea: 5: Me
Go upstairs: 3: Me
Do work: 1: Me, Cat
section Go home
Go downstairs: 5: Me
Sit down: 5: Me
```
```mermaid
journey
title My working day
section Go to work
Make tea: 5: Me
Go upstairs: 3: Me
Do work: 1: Me, Cat
section Go home
Go downstairs: 5: Me
Sit down: 5: Me
```
Each user journey is split into sections, these describe the part of the task
the user is trying to complete.
Tasks syntax is `Task name: <score>: <comma separated list of actors>`

BIN
img/gray-journey.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

BIN
img/gray-user-journey.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

View File

@@ -1,6 +1,6 @@
{
"name": "mermaid",
"version": "8.4.1",
"version": "8.5.1",
"description": "Markdownish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.",
"main": "dist/mermaid.core.js",
"keywords": [
@@ -13,7 +13,7 @@
"git graph"
],
"scripts": {
"build": "webpack --progress --colors",
"build": "webpack --progress --colors -p",
"postbuild": "documentation build src/mermaidAPI.js --shallow -f md --markdown-toc false -o docs/mermaidAPI.md",
"build:watch": "yarn build --watch",
"minify": "minify ./dist/mermaid.js > ./dist/mermaid.min.js",
@@ -24,10 +24,11 @@
"e2e": "start-server-and-test dev http://localhost:9000/ cypress",
"e2e-upd": "yarn lint && jest e2e -u --config e2e/jest.config.js",
"dev": "webpack-dev-server --config webpack.config.e2e.js",
"test": "yarn lint && jest src",
"test": "yarn lint && jest src/.*",
"test:watch": "jest --watch src",
"prepublishOnly": "yarn build && yarn release && yarn test && yarn e2e",
"prepush": "yarn test"
"prepush": "yarn test",
"prepare": "yarn build"
},
"repository": {
"type": "git",
@@ -49,45 +50,44 @@
"@braintree/sanitize-url": "^3.1.0",
"crypto-random-string": "^3.0.1",
"d3": "^5.7.0",
"dagre-d3": "dagrejs/dagre-d3",
"dagre": "^0.8.4",
"dagre-d3": "^0.6.4",
"entity-decode": "^2.0.2",
"graphlib": "^2.1.7",
"he": "^1.2.0",
"lodash": "^4.17.11",
"minify": "^4.1.1",
"moment-mini": "^2.22.1",
"prettier": "^1.18.2",
"scope-css": "^1.2.1"
},
"devDependencies": {
"documentation": "^12.0.1",
"eslint": "^6.3.0",
"eslint-config-prettier": "^6.3.0",
"eslint-plugin-prettier": "^3.1.0",
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.2.0",
"@babel/preset-env": "^7.8.4",
"@babel/register": "^7.0.0",
"@percy/cypress": "^2.0.1",
"@percy/cypress": "*",
"babel-core": "7.0.0-bridge.0",
"babel-jest": "^23.6.0",
"babel-jest": "^24.9.0",
"babel-loader": "^8.0.4",
"coveralls": "^3.0.2",
"css-loader": "^2.0.1",
"css-to-string-loader": "^0.1.3",
"cypress": "3.4.0",
"cypress": "4.0.1",
"documentation": "^12.0.1",
"eslint": "^6.3.0",
"eslint-config-prettier": "^6.3.0",
"eslint-plugin-prettier": "^3.1.0",
"husky": "^1.2.1",
"identity-obj-proxy": "^3.0.0",
"jest": "^23.6.0",
"jest-environment-puppeteer": "^4.2.0",
"jest-image-snapshot": "^2.8.2",
"jest-puppeteer": "^4.2.0",
"jest": "^24.9.0",
"jison": "^0.4.18",
"moment": "^2.23.0",
"node-sass": "^4.12.0",
"prettier": "^1.18.2",
"puppeteer": "^1.17.0",
"sass-loader": "^7.1.0",
"start-server-and-test": "^1.10.0",
"webpack": "^4.27.1",
"start-server-and-test": "^1.10.6",
"terser-webpack-plugin": "^2.2.2",
"webpack": "^4.41.2",
"webpack-bundle-analyzer": "^3.7.0",
"webpack-cli": "^3.1.2",
"webpack-dev-server": "^3.4.1",
"webpack-node-externals": "^1.7.2",
@@ -100,5 +100,9 @@
"ignore": [
"babel-core"
]
}
},
"sideEffects": [
"**/*.css",
"**/*.scss"
]
}

View File

@@ -0,0 +1,3 @@
module.exports = function(txt) {
return txt;
};

View File

@@ -0,0 +1,136 @@
# Cluster handling
Dagre does not support edges between nodes and clusters or between clusters to other clusters. In order to remedy this shortcoming the dagre wrapper implements a few work-arounds.
In the diagram below there are two clusters and there are no edges to nodes outside the own cluster.
```mermaid
flowchart
subgraph C1
a --> b
end
subgraph C2
c
end
C1 --> C2
```
In this case the dagre-wrapper will transform the graph to the graph below.
```mermaid
flowchart
C1 --> C2
```
The new nodes C1 and C2 are a special type of nodes, clusterNodes. ClusterNodes have have the nodes in the cluster including the cluster attached in a graph object.
When rendering this diagram it it beeing rendered recursivly. The diagram is rendered by the dagre-mermaid:render function which in turn will be used to render the node C1 and the node C2. The result of those renderings will be inserted as nodes in the "root" diagram. With this recursive approach it would be possible to have different layout direction for each cluster.
```
{ clusterNode: true, graph }
```
*Data for a clusterNode*
When a cluster has edges to or from some of its nodes leading outside the cluster the approach of recursive rendering can not be used as the layout of the graph needs to take responsibility for nodes outside of the cluster.
```mermaid
flowchart
subgraph C1
a
end
subgraph C2
b
end
a --> C2
```
To handle this case a special type of edge is inserted. The edge to/from the cluster is replaced with an edge to/from a node in the cluster which is tagged with toCluster/fromCluster. When rendering this edge the intersection between the edge and the border of the cluster is calculated making the edge start/stop there. In practice this renders like an an edge to/from the cluster.
In the diagram above the root diagram would be rendered with C1 whereas C2 would be rendered recursively.
Of these two approaches the top one renders better and is used when possible. When this is not possible, ie an edge is added crossing the border the non recursive approach is used.
# Graph objects and their properties
Explains the representation of various objects used to render the flow charts and what the properties mean. This ofc from the perspective of the dagre-wrapper.
## node
Sample object:
```json
{
"shape":"rect",
"labelText":"Test",
"rx":0,
"ry":0,
"class":"default",
"style":"",
"id":"Test",
"type":"group",
"padding":15}
```
This is set by the renderer of the diagram and insert the data that the wrapper neds for rendering.
| property | description |
| ---------- | ----------------------------------------------------------------------------------------------------------- |
| labelStyle | Css styles for the label. User for instance for stylling the labels for clusters |
| shape | The shape of the node. |
| labelText | The text on the label |
| rx | The corner radius - maybe part of the shape instead? Used for rects. |
| ry | The corner radius - maybe part of the shape instead? Used for rects. |
| classes | Classes to be set for the shape. Not used |
| style | Css styles for the actual shape |
| id | id of the shape |
| type | if set to group then this node indicates *a cluster*. |
| padding | Padding. Passed from the render as this might differ between different diagrams. Maybe obsolete. |
# edge
arrowType sets the type of arrows to use. The following arrow types are currently supported:
arrow_cross
double_arrow_cross
arrow_point
double_arrow_point
arrow_circle
double_arrow_circle
Lets try to make these types semantic free so that diagram type semantics does not find its way in to this more generic layer.
Required edgeData for proper rendering:
| property | description |
| ---------- | ---------------------------------------- |
| id | Id of the edge |
| arrowHead | overlap between arrowHead and arrowType? |
| arrowType | overlap between arrowHead and arrowType? |
| style | |
| labelStyle | |
| label | overlap between label and labelText? |
| labelPos | |
| labelType | overlap between label and labelText? |
# Markers
Define what markers that should be included in the diagram with the insert markers function. The function takes two arguments, first the element in which the markers should be included and a list of the markers that should be added.
Ex:
insertMarkers(el, ['point', 'circle'])
The example above adds the markers point and cross. This means that edges with the arrowTypes arrow_cross, double_arrow_cross, arrow_point and double_arrow_cross will get the corresponding markers but arrowType arrow_cross will have no impact.
Current markers:
* point - the standard arrow from flowcharts
* circle - Arrows ending with circle
* cross - arrows starting and ending with a cross
// Todo - in case of common renderer
# Common functions used by the renderer to be implemented by the Db
getDirection
getClasses

View File

@@ -0,0 +1,210 @@
import intersectRect from './intersect/intersect-rect';
import { logger as log } from '../logger'; // eslint-disable-line
import createLabel from './createLabel';
const rect = (parent, node) => {
log.trace('Creating subgraph rect for ', node.id, node);
// Add outer g element
const shapeSvg = parent
.insert('g')
.attr('class', 'cluster')
.attr('id', node.id);
// add the rect
const rect = shapeSvg.insert('rect', ':first-child');
// Create the label and insert it after the rect
const label = shapeSvg.insert('g').attr('class', 'cluster-label');
const text = label.node().appendChild(createLabel(node.labelText, node.labelStyle));
// Get the size of the label
const bbox = text.getBBox();
const padding = 0 * node.padding;
const halfPadding = padding / 2;
log.trace('Data ', node, JSON.stringify(node));
// center the rect around its coordinate
rect
.attr('rx', node.rx)
.attr('ry', node.ry)
.attr('x', node.x - node.width / 2 - halfPadding)
.attr('y', node.y - node.height / 2 - halfPadding)
.attr('width', node.width + padding)
.attr('height', node.height + padding);
// Center the label
label.attr(
'transform',
'translate(' +
(node.x - bbox.width / 2) +
', ' +
(node.y - node.height / 2 - node.padding / 3 + 3) +
')'
);
const rectBox = rect.node().getBBox();
node.width = rectBox.width;
node.height = rectBox.height;
node.intersect = function(point) {
return intersectRect(node, point);
};
return shapeSvg;
};
/**
* Non visiable cluster where the note is group with its
*/
const noteGroup = (parent, node) => {
// Add outer g element
const shapeSvg = parent
.insert('g')
.attr('class', 'note-cluster')
.attr('id', node.id);
// add the rect
const rect = shapeSvg.insert('rect', ':first-child');
const padding = 0 * node.padding;
const halfPadding = padding / 2;
// center the rect around its coordinate
rect
.attr('rx', node.rx)
.attr('ry', node.ry)
.attr('x', node.x - node.width / 2 - halfPadding)
.attr('y', node.y - node.height / 2 - halfPadding)
.attr('width', node.width + padding)
.attr('height', node.height + padding)
.attr('fill', 'none');
const rectBox = rect.node().getBBox();
node.width = rectBox.width;
node.height = rectBox.height;
node.intersect = function(point) {
return intersectRect(node, point);
};
return shapeSvg;
};
const roundedWithTitle = (parent, node) => {
// Add outer g element
const shapeSvg = parent
.insert('g')
.attr('class', node.classes)
.attr('id', node.id);
// add the rect
const rect = shapeSvg.insert('rect', ':first-child');
// Create the label and insert it after the rect
const label = shapeSvg.insert('g').attr('class', 'cluster-label');
const innerRect = shapeSvg.append('rect');
const text = label.node().appendChild(createLabel(node.labelText, node.labelStyle));
// Get the size of the label
const bbox = text.getBBox();
const padding = 0 * node.padding;
const halfPadding = padding / 2;
// center the rect around its coordinate
rect
.attr('class', 'outer')
.attr('x', node.x - node.width / 2 - halfPadding)
.attr('y', node.y - node.height / 2 - halfPadding)
.attr('width', node.width + padding)
.attr('height', node.height + padding);
innerRect
.attr('class', 'inner')
.attr('x', node.x - node.width / 2 - halfPadding)
.attr('y', node.y - node.height / 2 - halfPadding + bbox.height - 1)
.attr('width', node.width + padding)
.attr('height', node.height + padding - bbox.height - 3);
// Center the label
label.attr(
'transform',
'translate(' +
(node.x - bbox.width / 2) +
', ' +
(node.y - node.height / 2 - node.padding / 3 + 3) +
')'
);
const rectBox = rect.node().getBBox();
node.width = rectBox.width;
node.height = rectBox.height;
node.intersect = function(point) {
return intersectRect(node, point);
};
return shapeSvg;
};
const divider = (parent, node) => {
// Add outer g element
const shapeSvg = parent
.insert('g')
.attr('class', node.classes)
.attr('id', node.id);
// add the rect
const rect = shapeSvg.insert('rect', ':first-child');
const padding = 0 * node.padding;
const halfPadding = padding / 2;
// center the rect around its coordinate
rect
.attr('class', 'divider')
.attr('x', node.x - node.width / 2 - halfPadding)
.attr('y', node.y - node.height / 2)
.attr('width', node.width + padding)
.attr('height', node.height + padding);
const rectBox = rect.node().getBBox();
node.width = rectBox.width;
node.height = rectBox.height;
node.intersect = function(point) {
return intersectRect(node, point);
};
return shapeSvg;
};
const shapes = { rect, roundedWithTitle, noteGroup, divider };
let clusterElems = {};
export const insertCluster = (elem, node) => {
log.trace('Inserting cluster');
const shape = node.shape || 'rect';
clusterElems[node.id] = shapes[shape](elem, node);
};
export const getClusterTitleWidth = (elem, node) => {
const label = createLabel(node.labelText, node.labelStyle);
elem.node().appendChild(label);
const width = label.getBBox().width;
elem.node().removeChild(label);
return width;
};
export const clear = () => {
clusterElems = {};
};
export const positionCluster = node => {
log.info('Position cluster');
const el = clusterElems[node.id];
el.attr('transform', 'translate(' + node.x + ', ' + node.y + ')');
};

View File

@@ -0,0 +1,29 @@
const createLabel = (vertexText, style, isTitle) => {
const svgLabel = document.createElementNS('http://www.w3.org/2000/svg', 'text');
svgLabel.setAttribute('style', style.replace('color:', 'fill:'));
let rows = [];
if (typeof vertexText === 'string') {
rows = vertexText.split(/\\n|\n|<br\s*\/?>/gi);
} else if (Array.isArray(vertexText)) {
rows = vertexText;
} else {
rows = [];
}
for (let j = 0; j < rows.length; j++) {
const tspan = document.createElementNS('http://www.w3.org/2000/svg', 'tspan');
tspan.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve');
tspan.setAttribute('dy', '1em');
tspan.setAttribute('x', '0');
if (isTitle) {
tspan.setAttribute('class', 'title-row');
} else {
tspan.setAttribute('class', 'row');
}
tspan.textContent = rows[j].trim();
svgLabel.appendChild(tspan);
}
return svgLabel;
};
export default createLabel;

242
src/dagre-wrapper/edges.js Normal file
View File

@@ -0,0 +1,242 @@
import { logger } from '../logger'; // eslint-disable-line
import createLabel from './createLabel';
import { line, curveBasis } from 'd3';
import { getConfig } from '../config';
let edgeLabels = {};
export const clear = () => {
edgeLabels = {};
};
export const insertEdgeLabel = (elem, edge) => {
// Create the actual text element
const labelElement = createLabel(edge.label, edge.labelStyle);
// Create outer g, edgeLabel, this will be positioned after graph layout
const edgeLabel = elem.insert('g').attr('class', 'edgeLabel');
// Create inner g, label, this will be positioned now for centering the text
const label = edgeLabel.insert('g').attr('class', 'label');
label.node().appendChild(labelElement);
// Center the label
const bbox = labelElement.getBBox();
label.attr('transform', 'translate(' + -bbox.width / 2 + ', ' + -bbox.height / 2 + ')');
// Make element accessible by id for positioning
edgeLabels[edge.id] = edgeLabel;
// Update the abstract data of the edge with the new information about its width and height
edge.width = bbox.width;
edge.height = bbox.height;
};
export const positionEdgeLabel = edge => {
logger.info('Moving label', edge.id, edge.label, edgeLabels[edge.id]);
if (edge.label) {
const el = edgeLabels[edge.id];
el.attr('transform', 'translate(' + edge.x + ', ' + edge.y + ')');
}
};
// const getRelationType = function(type) {
// switch (type) {
// case stateDb.relationType.AGGREGATION:
// return 'aggregation';
// case stateDb.relationType.EXTENSION:
// return 'extension';
// case stateDb.relationType.COMPOSITION:
// return 'composition';
// case stateDb.relationType.DEPENDENCY:
// return 'dependency';
// }
// };
const outsideNode = (node, point) => {
const x = node.x;
const y = node.y;
const dx = Math.abs(point.x - x);
const dy = Math.abs(point.y - y);
const w = node.width / 2;
const h = node.height / 2;
if (dx > w || dy > h) {
return true;
}
return false;
};
const intersection = (node, outsidePoint, insidePoint) => {
logger.trace('intersection o:', outsidePoint, ' i:', insidePoint, node);
const x = node.x;
const y = node.y;
const dx = Math.abs(x - insidePoint.x);
const w = node.width / 2;
let r = insidePoint.x < outsidePoint.x ? w - dx : w + dx;
const dy = Math.abs(y - insidePoint.y);
const h = node.height / 2;
let q = insidePoint.y < outsidePoint.y ? h - dy : h - dy;
const Q = Math.abs(outsidePoint.y - insidePoint.y);
const R = Math.abs(outsidePoint.x - insidePoint.x);
if (Math.abs(y - outsidePoint.y) * w > Math.abs(x - outsidePoint.x) * h || false) { // eslint-disable-line
// Intersection is top or bottom of rect.
r = (R * q) / Q;
return {
x: insidePoint.x < outsidePoint.x ? insidePoint.x + r : insidePoint.x - r,
y: insidePoint.y + q
};
} else {
q = (Q * r) / R;
r = (R * q) / Q;
return {
x: insidePoint.x < outsidePoint.x ? insidePoint.x + r : insidePoint.x + dx - w,
y: insidePoint.y < outsidePoint.y ? insidePoint.y + q : insidePoint.y - q
};
}
};
//(edgePaths, e, edge, clusterDb, diagramtype, graph)
export const insertEdge = function(elem, e, edge, clusterDb, diagramType, graph) {
let points = edge.points;
const tail = graph.node(e.v);
var head = graph.node(e.w);
if (head.intersect && tail.intersect) {
points = points.slice(1, edge.points.length - 1);
points.unshift(tail.intersect(points[0]));
points.push(head.intersect(points[points.length - 1]));
}
if (edge.toCluster) {
logger.trace('edge', edge);
logger.trace('to cluster', clusterDb[edge.toCluster]);
points = [];
let lastPointOutside;
let isInside = false;
edge.points.forEach(point => {
const node = clusterDb[edge.toCluster].node;
if (!outsideNode(node, point) && !isInside) {
logger.trace('inside', edge.toCluster, point, lastPointOutside);
// First point inside the rect
const insterection = intersection(node, lastPointOutside, point);
logger.trace('intersect', insterection);
points.push(insterection);
isInside = true;
} else {
if (!isInside) points.push(point);
}
lastPointOutside = point;
});
}
if (edge.fromCluster) {
logger.trace('edge', edge);
logger.trace('from cluster', clusterDb[edge.toCluster]);
const updatedPoints = [];
let lastPointOutside;
let isInside = false;
for (let i = points.length - 1; i >= 0; i--) {
const point = points[i];
const node = clusterDb[edge.fromCluster].node;
if (!outsideNode(node, point) && !isInside) {
logger.trace('inside', edge.toCluster, point);
// First point inside the rect
const insterection = intersection(node, lastPointOutside, point);
// logger.trace('intersect', intersection(node, lastPointOutside, point));
updatedPoints.unshift(insterection);
// points.push(insterection);
isInside = true;
} else {
// at the outside
logger.trace('Outside point', point);
if (!isInside) updatedPoints.unshift(point);
}
lastPointOutside = point;
}
points = updatedPoints;
}
// The data for our line
const lineData = points.filter(p => !Number.isNaN(p.y));
// This is the accessor function we talked about above
const lineFunction = line()
.x(function(d) {
return d.x;
})
.y(function(d) {
return d.y;
})
.curve(curveBasis);
const svgPath = elem
.append('path')
.attr('d', lineFunction(lineData))
.attr('id', edge.id)
.attr('class', 'transition' + (edge.classes ? ' ' + edge.classes : ''));
// DEBUG code, adds a red circle at each edge coordinate
// edge.points.forEach(point => {
// elem
// .append('circle')
// .style('stroke', 'red')
// .style('fill', 'red')
// .attr('r', 1)
// .attr('cx', point.x)
// .attr('cy', point.y);
// });
let url = '';
if (getConfig().state.arrowMarkerAbsolute) {
url =
window.location.protocol +
'//' +
window.location.host +
window.location.pathname +
window.location.search;
url = url.replace(/\(/g, '\\(');
url = url.replace(/\)/g, '\\)');
}
logger.info('arrowType', edge.arrowType);
switch (edge.arrowType) {
case 'arrow_cross':
svgPath.attr('marker-end', 'url(' + url + '#' + diagramType + '-crossEnd' + ')');
break;
case 'double_arrow_cross':
svgPath.attr('marker-end', 'url(' + url + '#' + diagramType + '-crossEnd' + ')');
svgPath.attr('marker-start', 'url(' + url + '#' + diagramType + '-crossStart' + ')');
break;
case 'arrow_point':
svgPath.attr('marker-end', 'url(' + url + '#' + diagramType + '-pointEnd' + ')');
break;
case 'double_arrow_point':
svgPath.attr('marker-end', 'url(' + url + '#' + diagramType + '-pointEnd' + ')');
svgPath.attr('marker-start', 'url(' + url + '#' + diagramType + '-pointStart' + ')');
break;
case 'arrow_barb':
svgPath.attr('marker-end', 'url(' + url + '#' + diagramType + '-barbEnd' + ')');
break;
case 'double_arrow_barb':
svgPath.attr('marker-end', 'url(' + url + '#' + diagramType + '-barnEnd' + ')');
svgPath.attr('marker-start', 'url(' + url + '#' + diagramType + '-barbStart' + ')');
break;
case 'arrow_circle':
svgPath.attr('marker-end', 'url(' + url + '#' + diagramType + '-circleEnd' + ')');
break;
case 'double_arrow_circle':
svgPath.attr('marker-end', 'url(' + url + '#' + diagramType + '-circleEnd' + ')');
svgPath.attr('marker-start', 'url(' + url + '#' + diagramType + '-circleStart' + ')');
break;
default:
}
};

156
src/dagre-wrapper/index.js Normal file
View File

@@ -0,0 +1,156 @@
import dagre from 'dagre';
import graphlib from 'graphlib';
import insertMarkers from './markers';
import { updateNodeBounds } from './shapes/util';
import {
clear as clearGraphlib,
clusterDb,
adjustClustersAndEdges,
findNonClusterChild
} from './mermaid-graphlib';
import { insertNode, positionNode, clear as clearNodes, setNodeElem } from './nodes';
import { insertCluster, clear as clearClusters } from './clusters';
import { insertEdgeLabel, positionEdgeLabel, insertEdge, clear as clearEdges } from './edges';
import { logger as log } from '../logger';
const recursiveRender = (_elem, graph, diagramtype, parentCluster) => {
log.info('Graph in recursive render:', graphlib.json.write(graph), parentCluster);
const dir = graph.graph().rankdir;
log.warn('Dir in recursive render - dir:', dir);
const elem = _elem.insert('g').attr('class', 'root'); // eslint-disable-line
if (!graph.nodes()) {
log.trace('No nodes found for', graph);
} else {
log.trace('Recursive render', graph.nodes());
}
if (graph.edges().length > 0) {
log.trace('Recursive edges', graph.edge(graph.edges()[0]));
}
const clusters = elem.insert('g').attr('class', 'clusters'); // eslint-disable-line
const edgePaths = elem.insert('g').attr('class', 'edgePaths');
const edgeLabels = elem.insert('g').attr('class', 'edgeLabels');
const nodes = elem.insert('g').attr('class', 'nodes');
// Insert nodes, this will insert them into the dom and each node will get a size. The size is updated
// to the abstract node and is later used by dagre for the layout
graph.nodes().forEach(function(v) {
const node = graph.node(v);
if (typeof parentCluster !== 'undefined') {
const data = JSON.parse(JSON.stringify(parentCluster.clusterData));
// data.clusterPositioning = true;
log.trace('Setting data for cluster', data);
graph.setNode(parentCluster.id, data);
graph.setParent(v, parentCluster.id, data);
}
log.trace('(Insert) Node ' + v + ': ' + JSON.stringify(graph.node(v)));
if (node && node.clusterNode) {
// const children = graph.children(v);
log.trace('Cluster identified', v, node, graph.node(v));
const newEl = recursiveRender(nodes, node.graph, diagramtype, graph.node(v));
updateNodeBounds(node, newEl);
setNodeElem(newEl, node);
log.warn('Recursive render complete', newEl, node);
} else {
if (graph.children(v).length > 0) {
// This is a cluster but not to be rendered recusively
// Render as before
log.trace('Cluster - the non recursive path', v, node.id, node, graph);
log.trace(findNonClusterChild(node.id, graph));
clusterDb[node.id] = { id: findNonClusterChild(node.id, graph), node };
// insertCluster(clusters, graph.node(v));
} else {
log.trace('Node - the non recursive path', v, node.id, node);
insertNode(nodes, graph.node(v), dir);
}
}
});
// Insert labels, this will insert them into the dom so that the width can be calculated
// Also figure out which edges point to/from clusters and adjust them accordingly
// Edges from/to clusters really points to the first child in the cluster.
// TODO: pick optimal child in the cluster to us as link anchor
graph.edges().forEach(function(e) {
const edge = graph.edge(e.v, e.w, e.name);
log.trace('Edge ' + e.v + ' -> ' + e.w + ': ' + JSON.stringify(e));
log.trace('Edge ' + e.v + ' -> ' + e.w + ': ', e, ' ', JSON.stringify(graph.edge(e)));
// Check if link is either from or to a cluster
log.trace('Fix', clusterDb, 'ids:', e.v, e.w, 'Translateing: ', clusterDb[e.v], clusterDb[e.w]);
insertEdgeLabel(edgeLabels, edge);
});
graph.edges().forEach(function(e) {
log.info('Edge ' + e.v + ' -> ' + e.w + ': ' + JSON.stringify(e));
});
log.info('#############################################');
log.info('### Layout ###');
log.info('#############################################');
log.info(graph);
dagre.layout(graph);
log.trace('Graph after layout:', graphlib.json.write(graph));
// Move the nodes to the correct place
graph.nodes().forEach(function(v) {
const node = graph.node(v);
// log.trace('Position ' + v + ': ' + JSON.stringify(graph.node(v)));
log.trace(
'Position ' + v + ': (' + node.x,
',' + node.y,
') width: ',
node.width,
' height: ',
node.height
);
if (node && node.clusterNode) {
// clusterDb[node.id].node = node;
positionNode(node);
} else {
// Non cluster node
if (graph.children(v).length > 0) {
// A cluster in the non-recurive way
// positionCluster(node);
insertCluster(clusters, node);
clusterDb[node.id].node = node;
} else {
positionNode(node);
}
}
});
// Move the edge labels to the correct place after layout
graph.edges().forEach(function(e) {
const edge = graph.edge(e);
log.info('Edge ' + e.v + ' -> ' + e.w + ': ' + JSON.stringify(edge), edge);
insertEdge(edgePaths, e, edge, clusterDb, diagramtype, graph);
positionEdgeLabel(edge);
});
return elem;
};
export const render = (elem, graph, markers, diagramtype, id) => {
insertMarkers(elem, markers, diagramtype, id);
clearNodes();
clearEdges();
clearClusters();
clearGraphlib();
log.warn('Graph before:', graphlib.json.write(graph));
adjustClustersAndEdges(graph);
log.warn('Graph after:', graphlib.json.write(graph));
log.warn('Graph ever after:', graph.graph());
recursiveRender(elem, graph, diagramtype);
};
// const shapeDefinitions = {};
// export const addShape = ({ shapeType: fun }) => {
// shapeDefinitions[shapeType] = fun;
// };
// const arrowDefinitions = {};
// export const addArrow = ({ arrowType: fun }) => {
// arrowDefinitions[arrowType] = fun;
// };

View File

@@ -0,0 +1,7 @@
module.exports = {
node: require('./intersect-node'),
circle: require('./intersect-circle'),
ellipse: require('./intersect-ellipse'),
polygon: require('./intersect-polygon'),
rect: require('./intersect-rect')
};

View File

@@ -0,0 +1,17 @@
/*
* Borrowed with love from from dagrge-d3. Many thanks to cpettitt!
*/
import node from './intersect-node.js';
import circle from './intersect-circle.js';
import ellipse from './intersect-ellipse.js';
import polygon from './intersect-polygon.js';
import rect from './intersect-rect.js';
export default {
node,
circle,
ellipse,
polygon,
rect
};

View File

@@ -0,0 +1,7 @@
import intersectEllipse from './intersect-ellipse';
function intersectCircle(node, rx, point) {
return intersectEllipse(node, rx, rx, point);
}
export default intersectCircle;

View File

@@ -0,0 +1,24 @@
function intersectEllipse(node, rx, ry, point) {
// Formulae from: http://mathworld.wolfram.com/Ellipse-LineIntersection.html
var cx = node.x;
var cy = node.y;
var px = cx - point.x;
var py = cy - point.y;
var det = Math.sqrt(rx * rx * py * py + ry * ry * px * px);
var dx = Math.abs((rx * ry * px) / det);
if (point.x < cx) {
dx = -dx;
}
var dy = Math.abs((rx * ry * py) / det);
if (point.y < cy) {
dy = -dy;
}
return { x: cx + dx, y: cy + dy };
}
export default intersectEllipse;

View File

@@ -0,0 +1,70 @@
/*
* Returns the point at which two lines, p and q, intersect or returns
* undefined if they do not intersect.
*/
function intersectLine(p1, p2, q1, q2) {
// Algorithm from J. Avro, (ed.) Graphics Gems, No 2, Morgan Kaufmann, 1994,
// p7 and p473.
var a1, a2, b1, b2, c1, c2;
var r1, r2, r3, r4;
var denom, offset, num;
var x, y;
// Compute a1, b1, c1, where line joining points 1 and 2 is F(x,y) = a1 x +
// b1 y + c1 = 0.
a1 = p2.y - p1.y;
b1 = p1.x - p2.x;
c1 = p2.x * p1.y - p1.x * p2.y;
// Compute r3 and r4.
r3 = a1 * q1.x + b1 * q1.y + c1;
r4 = a1 * q2.x + b1 * q2.y + c1;
// Check signs of r3 and r4. If both point 3 and point 4 lie on
// same side of line 1, the line segments do not intersect.
if (r3 !== 0 && r4 !== 0 && sameSign(r3, r4)) {
return /*DONT_INTERSECT*/;
}
// Compute a2, b2, c2 where line joining points 3 and 4 is G(x,y) = a2 x + b2 y + c2 = 0
a2 = q2.y - q1.y;
b2 = q1.x - q2.x;
c2 = q2.x * q1.y - q1.x * q2.y;
// Compute r1 and r2
r1 = a2 * p1.x + b2 * p1.y + c2;
r2 = a2 * p2.x + b2 * p2.y + c2;
// Check signs of r1 and r2. If both point 1 and point 2 lie
// on same side of second line segment, the line segments do
// not intersect.
if (r1 !== 0 && r2 !== 0 && sameSign(r1, r2)) {
return /*DONT_INTERSECT*/;
}
// Line segments intersect: compute intersection point.
denom = a1 * b2 - a2 * b1;
if (denom === 0) {
return /*COLLINEAR*/;
}
offset = Math.abs(denom / 2);
// The denom/2 is to get rounding instead of truncating. It
// is added or subtracted to the numerator, depending upon the
// sign of the numerator.
num = b1 * c2 - b2 * c1;
x = num < 0 ? (num - offset) / denom : (num + offset) / denom;
num = a2 * c1 - a1 * c2;
y = num < 0 ? (num - offset) / denom : (num + offset) / denom;
return { x: x, y: y };
}
function sameSign(r1, r2) {
return r1 * r2 > 0;
}
export default intersectLine;

View File

@@ -0,0 +1,5 @@
module.exports = intersectNode;
function intersectNode(node, point) {
return node.intersect(point);
}

View File

@@ -0,0 +1,61 @@
/* eslint "no-console": off */
import intersectLine from './intersect-line';
export default intersectPolygon;
/*
* Returns the point ({x, y}) at which the point argument intersects with the
* node argument assuming that it has the shape specified by polygon.
*/
function intersectPolygon(node, polyPoints, point) {
var x1 = node.x;
var y1 = node.y;
var intersections = [];
var minX = Number.POSITIVE_INFINITY;
var minY = Number.POSITIVE_INFINITY;
polyPoints.forEach(function(entry) {
minX = Math.min(minX, entry.x);
minY = Math.min(minY, entry.y);
});
var left = x1 - node.width / 2 - minX;
var top = y1 - node.height / 2 - minY;
for (var i = 0; i < polyPoints.length; i++) {
var p1 = polyPoints[i];
var p2 = polyPoints[i < polyPoints.length - 1 ? i + 1 : 0];
var intersect = intersectLine(
node,
point,
{ x: left + p1.x, y: top + p1.y },
{ x: left + p2.x, y: top + p2.y }
);
if (intersect) {
intersections.push(intersect);
}
}
if (!intersections.length) {
console.log('NO INTERSECTION FOUND, RETURN NODE CENTER', node);
return node;
}
if (intersections.length > 1) {
// More intersections, find the one nearest to edge end point
intersections.sort(function(p, q) {
var pdx = p.x - point.x;
var pdy = p.y - point.y;
var distp = Math.sqrt(pdx * pdx + pdy * pdy);
var qdx = q.x - point.x;
var qdy = q.y - point.y;
var distq = Math.sqrt(qdx * qdx + qdy * qdy);
return distp < distq ? -1 : distp === distq ? 0 : 1;
});
}
return intersections[0];
}

View File

@@ -0,0 +1,32 @@
const intersectRect = (node, point) => {
var x = node.x;
var y = node.y;
// Rectangle intersection algorithm from:
// http://math.stackexchange.com/questions/108113/find-edge-between-two-boxes
var dx = point.x - x;
var dy = point.y - y;
var w = node.width / 2;
var h = node.height / 2;
var sx, sy;
if (Math.abs(dy) * w > Math.abs(dx) * h) {
// Intersection is top or bottom of rect.
if (dy < 0) {
h = -h;
}
sx = dy === 0 ? 0 : (h * dx) / dy;
sy = h;
} else {
// Intersection is left or right of rect.
if (dx < 0) {
w = -w;
}
sx = w;
sy = dx === 0 ? 0 : (w * dy) / dx;
}
return { x: x + sx, y: y + sy };
};
export default intersectRect;

View File

@@ -0,0 +1,260 @@
/**
* Setup arrow head and define the marker. The result is appended to the svg.
*/
import { logger } from '../logger';
// Only add the number of markers that the diagram needs
const insertMarkers = (elem, markerArray, type, id) => {
markerArray.forEach(markerName => {
markers[markerName](elem, type, id);
});
};
const extension = (elem, type, id) => {
logger.trace('Making markers for ', id);
elem
.append('defs')
.append('marker')
.attr('id', type + '-extensionStart')
.attr('class', 'extension ' + type)
.attr('refX', 0)
.attr('refY', 7)
.attr('markerWidth', 190)
.attr('markerHeight', 240)
.attr('orient', 'auto')
.append('path')
.attr('d', 'M 1,7 L18,13 V 1 Z');
elem
.append('defs')
.append('marker')
.attr('id', type + '-extensionEnd ' + type)
.attr('class', 'extension ' + type)
.attr('refX', 19)
.attr('refY', 7)
.attr('markerWidth', 20)
.attr('markerHeight', 28)
.attr('orient', 'auto')
.append('path')
.attr('d', 'M 1,1 V 13 L18,7 Z'); // this is actual shape for arrowhead
};
const composition = (elem, type) => {
elem
.append('defs')
.append('marker')
.attr('id', type + '-compositionStart')
.attr('class', 'extension ' + type)
.attr('refX', 0)
.attr('refY', 7)
.attr('markerWidth', 190)
.attr('markerHeight', 240)
.attr('orient', 'auto')
.append('path')
.attr('d', 'M 18,7 L9,13 L1,7 L9,1 Z');
elem
.append('defs')
.append('marker')
.attr('id', type + '-compositionEnd')
.attr('class', 'extension ' + type)
.attr('refX', 19)
.attr('refY', 7)
.attr('markerWidth', 20)
.attr('markerHeight', 28)
.attr('orient', 'auto')
.append('path')
.attr('d', 'M 18,7 L9,13 L1,7 L9,1 Z');
};
const aggregation = (elem, type) => {
elem
.append('defs')
.append('marker')
.attr('id', type + '-aggregationStart')
.attr('class', 'extension ' + type)
.attr('refX', 0)
.attr('refY', 7)
.attr('markerWidth', 190)
.attr('markerHeight', 240)
.attr('orient', 'auto')
.append('path')
.attr('d', 'M 18,7 L9,13 L1,7 L9,1 Z');
elem
.append('defs')
.append('marker')
.attr('id', type + '-aggregationEnd')
.attr('class', type)
.attr('refX', 19)
.attr('refY', 7)
.attr('markerWidth', 20)
.attr('markerHeight', 28)
.attr('orient', 'auto')
.append('path')
.attr('d', 'M 18,7 L9,13 L1,7 L9,1 Z');
};
const dependency = (elem, type) => {
elem
.append('defs')
.append('marker')
.attr('id', type + '-dependencyStart')
.attr('class', 'extension ' + type)
.attr('refX', 0)
.attr('refY', 7)
.attr('markerWidth', 190)
.attr('markerHeight', 240)
.attr('orient', 'auto')
.append('path')
.attr('d', 'M 5,7 L9,13 L1,7 L9,1 Z');
elem
.append('defs')
.append('marker')
.attr('id', type + '-dependencyEnd')
.attr('class', type)
.attr('refX', 19)
.attr('refY', 7)
.attr('markerWidth', 20)
.attr('markerHeight', 28)
.attr('orient', 'auto')
.append('path')
.attr('d', 'M 18,7 L9,13 L14,7 L9,1 Z');
};
const point = (elem, type) => {
elem
.append('marker')
.attr('id', type + '-pointEnd')
.attr('class', type)
.attr('viewBox', '0 0 10 10')
.attr('refX', 10)
.attr('refY', 5)
.attr('markerUnits', 'strokeWidth')
.attr('markerWidth', 8)
.attr('markerHeight', 8)
.attr('orient', 'auto')
.append('path')
.attr('d', 'M 0 0 L 10 5 L 0 10 z')
.attr('class', 'arrowMarkerPath')
.style('stroke-width', 1)
.style('stroke-dasharray', '1,0');
elem
.append('marker')
.attr('id', type + '-pointStart')
.attr('class', type)
.attr('viewBox', '0 0 10 10')
.attr('refX', 0)
.attr('refY', 5)
.attr('markerUnits', 'strokeWidth')
.attr('markerWidth', 8)
.attr('markerHeight', 8)
.attr('orient', 'auto')
.append('path')
.attr('d', 'M 0 5 L 10 10 L 10 0 z')
.attr('class', 'arrowMarkerPath')
.style('stroke-width', 1)
.style('stroke-dasharray', '1,0');
};
const circle = (elem, type) => {
elem
.append('marker')
.attr('id', type + '-circleEnd')
.attr('class', type)
.attr('viewBox', '0 0 10 10')
.attr('refX', 11)
.attr('refY', 5)
.attr('markerUnits', 'strokeWidth')
.attr('markerWidth', 7)
.attr('markerHeight', 7)
.attr('orient', 'auto')
.append('circle')
.attr('cx', '5')
.attr('cy', '5')
.attr('r', '5')
.attr('class', 'arrowMarkerPath')
.style('stroke-width', 1)
.style('stroke-dasharray', '1,0');
elem
.append('marker')
.attr('id', type + '-circleStart')
.attr('class', type)
.attr('viewBox', '0 0 10 10')
.attr('refX', -1)
.attr('refY', 5)
.attr('markerUnits', 'strokeWidth')
.attr('markerWidth', 7)
.attr('markerHeight', 7)
.attr('orient', 'auto')
.append('circle')
.attr('cx', '5')
.attr('cy', '5')
.attr('r', '5')
.attr('class', 'arrowMarkerPath')
.style('stroke-width', 1)
.style('stroke-dasharray', '1,0');
};
const cross = (elem, type) => {
elem
.append('marker')
.attr('id', type + '-crossEnd')
.attr('class', type)
.attr('viewBox', '0 0 11 11')
.attr('refX', 12)
.attr('refY', 5.2)
.attr('markerUnits', 'strokeWidth')
.attr('markerWidth', 7)
.attr('markerHeight', 7)
.attr('orient', 'auto')
.append('path')
.attr('stroke', 'black')
.attr('d', 'M 1,1 l 9,9 M 10,1 l -9,9')
.attr('class', 'arrowMarkerPath')
.style('stroke-width', 2)
.style('stroke-dasharray', '1,0');
elem
.append('marker')
.attr('id', type + '-crossStart')
.attr('class', type)
.attr('viewBox', '0 0 11 11')
.attr('refX', -1)
.attr('refY', 5.2)
.attr('markerUnits', 'strokeWidth')
.attr('markerWidth', 7)
.attr('markerHeight', 7)
.attr('orient', 'auto')
.append('path')
.attr('stroke', 'black')
.attr('d', 'M 1,1 l 9,9 M 10,1 l -9,9')
.attr('class', 'arrowMarkerPath')
.style('stroke-width', 2)
.style('stroke-dasharray', '1,0');
};
const barb = (elem, type) => {
elem
.append('defs')
.append('marker')
.attr('id', type + '-barbEnd')
.attr('refX', 19)
.attr('refY', 7)
.attr('markerWidth', 20)
.attr('markerHeight', 14)
.attr('markerUnits', 0)
.attr('orient', 'auto')
.append('path')
.attr('d', 'M 19,7 L9,13 L14,7 L9,1 Z');
};
// TODO rename the class diagram markers to something shape descriptive and semanitc free
const markers = {
extension,
composition,
aggregation,
dependency,
point,
circle,
cross,
barb
};
export default insertMarkers;

View File

@@ -0,0 +1,403 @@
/**
* Decorates with functions required by mermaids dagre-wrapper.
*/
import { logger as log } from '../logger';
import graphlib from 'graphlib';
export let clusterDb = {};
let decendants = {};
let parents = {};
export const clear = () => {
decendants = {};
parents = {};
clusterDb = {};
};
const isDecendant = (id, ancenstorId) => {
// if (id === ancenstorId) return true;
log.debug(
'In isDecendant',
ancenstorId,
' ',
id,
' = ',
decendants[ancenstorId].indexOf(id) >= 0
);
if (decendants[ancenstorId].indexOf(id) >= 0) return true;
return false;
};
const edgeInCluster = (edge, clusterId) => {
log.info('Decendants of ', clusterId, ' is ', decendants[clusterId]);
log.info('Edge is ', edge);
// Edges to/from the cluster is not in the cluster, they are in the parent
if (edge.v === clusterId) return false;
if (edge.w === clusterId) return false;
if (!decendants[clusterId]) {
log.debug('Tilt, ', clusterId, ',not in decendants');
return false;
}
log.info('Here ');
if (decendants[clusterId].indexOf(edge.v) >= 0) return true;
if (isDecendant(edge.v, clusterId)) return true;
if (isDecendant(edge.w, clusterId)) return true;
if (decendants[clusterId].indexOf(edge.w) >= 0) return true;
return false;
};
const copy = (clusterId, graph, newGraph, rootId) => {
log.info(
'Copying children of ',
clusterId,
'root',
rootId,
'data',
graph.node(clusterId),
rootId
);
const nodes = graph.children(clusterId) || [];
// Include cluster node if it is not the root
if (clusterId !== rootId) {
nodes.push(clusterId);
}
log.debug('Copying (nodes) clusterId', clusterId, 'nodes', nodes);
nodes.forEach(node => {
if (graph.children(node).length > 0) {
copy(node, graph, newGraph, rootId);
} else {
const data = graph.node(node);
log.info('cp ', node, ' to ', rootId, ' with parent ', clusterId); //,node, data, ' parent is ', clusterId);
newGraph.setNode(node, data);
log.debug('Setting parent', node, graph.parent(node));
if (rootId !== graph.parent(node)) {
newGraph.setParent(node, graph.parent(node));
}
if (clusterId !== rootId && node !== clusterId) {
log.debug('Setting parent', node, clusterId);
newGraph.setParent(node, clusterId);
} else {
log.info('In copy ', clusterId, 'root', rootId, 'data', graph.node(clusterId), rootId);
log.debug(
'Not Setting parent for node=',
node,
'cluster!==rootId',
clusterId !== rootId,
'node!==clusterId',
node !== clusterId
);
}
const edges = graph.edges(node);
log.debug('Copying Edges', edges);
edges.forEach(edge => {
log.info('Edge', edge);
const data = graph.edge(edge.v, edge.w, edge.name);
log.info('Edge data', data, rootId);
try {
// Do not copy edges in and out of the root cluster, they belong to the parent graph
if (edgeInCluster(edge, rootId)) {
log.info('Copying as ', edge.v, edge.w, data, edge.name);
newGraph.setEdge(edge.v, edge.w, data, edge.name);
log.info('newGraph edges ', newGraph.edges(), newGraph.edge(newGraph.edges()[0]));
} else {
log.info(
'Skipping copy of edge ',
edge.v,
'-->',
edge.w,
' rootId: ',
rootId,
' clusterId:',
clusterId
);
}
} catch (e) {
log.error(e);
}
});
}
log.debug('Removing node', node);
graph.removeNode(node);
});
};
export const extractDecendants = (id, graph) => {
// log.debug('Extracting ', id);
const children = graph.children(id);
let res = [].concat(children);
for (let i = 0; i < children.length; i++) {
parents[children[i]] = id;
res = res.concat(extractDecendants(children[i], graph));
}
return res;
};
/**
* Validates the graph, checking that all parent child relation points to existing nodes and that
* edges between nodes also ia correct. When not correct the function logs the discrepancies.
* @param {graphlib graph} g
*/
export const validate = graph => {
const edges = graph.edges();
log.trace('Edges: ', edges);
for (let i = 0; i < edges.length; i++) {
if (graph.children(edges[i].v).length > 0) {
log.trace('The node ', edges[i].v, ' is part of and edge even though it has children');
return false;
}
if (graph.children(edges[i].w).length > 0) {
log.trace('The node ', edges[i].w, ' is part of and edge even though it has children');
return false;
}
}
return true;
};
/**
* Finds a child that is not a cluster. When faking a edge between a node and a cluster.
* @param {Finds a } id
* @param {*} graph
*/
export const findNonClusterChild = (id, graph) => {
// const node = graph.node(id);
log.trace('Searching', id);
const children = graph.children(id);
if (children.length < 1) {
log.trace('This is a valid node', id);
return id;
}
for (let i = 0; i < children.length; i++) {
const _id = findNonClusterChild(children[i], graph);
if (_id) {
log.trace('Found replacement for', id, ' => ', _id);
return _id;
}
}
};
const getAnchorId = id => {
if (!clusterDb[id]) {
return id;
}
// If the cluster has no external connections
if (!clusterDb[id].externalConnections) {
return id;
}
// Return the replacement node
if (clusterDb[id]) {
return clusterDb[id].id;
}
return id;
};
export const adjustClustersAndEdges = (graph, depth) => {
if (!graph || depth > 10) {
log.debug('Opting out, no graph ');
return;
} else {
log.debug('Opting in, graph ');
}
// Go through the nodes and for each cluster found, save a replacment node, this can be used when
// faking a link to a cluster
graph.nodes().forEach(function(id) {
const children = graph.children(id);
if (children.length > 0) {
log.trace(
'Cluster identified',
id,
' Replacement id in edges: ',
findNonClusterChild(id, graph)
);
decendants[id] = extractDecendants(id, graph);
clusterDb[id] = { id: findNonClusterChild(id, graph), clusterData: graph.node(id) };
}
});
// Check incoming and outgoing edges for each cluster
graph.nodes().forEach(function(id) {
const children = graph.children(id);
const edges = graph.edges();
if (children.length > 0) {
log.debug('Cluster identified', id, decendants);
edges.forEach(edge => {
// log.debug('Edge, decendants: ', edge, decendants[id]);
// Check if any edge leaves the cluster (not the actual cluster, thats a link from the box)
if (edge.v !== id && edge.w !== id) {
// Any edge where either the one of the nodes is decending to the cluster but not the other
// if (decendants[id].indexOf(edge.v) < 0 && decendants[id].indexOf(edge.w) < 0) {
const d1 = isDecendant(edge.v, id);
const d2 = isDecendant(edge.w, id);
// d1 xor d2 - if either d1 is true and d2 is false or the other way around
if (d1 ^ d2) {
log.debug('Edge: ', edge, ' leaves cluster ', id);
log.debug('Decendants of ', id, ': ', decendants[id]);
clusterDb[id].externalConnections = true;
}
}
});
}
});
extractor(graph, 0);
// For clusters with incoming and/or outgoing edges translate those edges to a real node
// in the cluster inorder to fake the edge
graph.edges().forEach(function(e) {
const edge = graph.edge(e);
log.trace('Edge ' + e.v + ' -> ' + e.w + ': ' + JSON.stringify(e));
log.trace('Edge ' + e.v + ' -> ' + e.w + ': ' + JSON.stringify(graph.edge(e)));
let v = e.v;
let w = e.w;
// Check if link is either from or to a cluster
log.trace('Fix', clusterDb, 'ids:', e.v, e.w, 'Translateing: ', clusterDb[e.v], clusterDb[e.w]);
if (clusterDb[e.v] || clusterDb[e.w]) {
log.trace('Fixing and trixing - removing', e.v, e.w, e.name);
v = getAnchorId(e.v);
w = getAnchorId(e.w);
graph.removeEdge(e.v, e.w, e.name);
if (v !== e.v) edge.fromCluster = e.v;
if (w !== e.w) edge.toCluster = e.w;
log.trace('Replacing with', v, w, e.name);
graph.setEdge(v, w, edge, e.name);
}
});
log.debug('Adjusted Graph', graphlib.json.write(graph));
log.trace(clusterDb);
// Remove references to extracted cluster
// graph.edges().forEach(edge => {
// if (isDecendant(edge.v, clusterId) || isDecendant(edge.w, clusterId)) {
// graph.removeEdge(edge);
// }
// });
};
export const extractor = (graph, depth) => {
log.debug('extractor - ', depth, graphlib.json.write(graph), graph.children('D'));
if (depth > 10) {
log.error('Bailing out');
return;
}
// For clusters without incoming and/or outgoing edges, create a new cluster-node
// containing the nodes and edges in the custer in a new graph
// for (let i = 0;)
let nodes = graph.nodes();
let hasChildren = false;
for (let i = 0; i < nodes.length; i++) {
const node = nodes[i];
const children = graph.children(node);
hasChildren = hasChildren || children.length > 0;
}
if (!hasChildren) {
log.debug('Done, no node has children', graph.nodes());
return;
}
// const clusters = Object.keys(clusterDb);
// clusters.forEach(clusterId => {
log.debug('Nodes = ', nodes, depth);
for (let i = 0; i < nodes.length; i++) {
const node = nodes[i];
log.debug(
'Extracting node',
node,
clusterDb,
clusterDb[node] && !clusterDb[node].externalConnections,
!graph.parent(node),
graph.node(node),
graph.children('D'),
' Depth ',
depth
);
// Note that the node might have been removed after the Object.keys call so better check
// that it still is in the game
if (!clusterDb[node]) {
// Skip if the node is not a cluster
log.debug('Not a cluster', node, depth);
// break;
} else if (
!clusterDb[node].externalConnections &&
!graph.parent(node) &&
graph.children(node) &&
graph.children(node).length > 0
) {
log.debug(
'Cluster without external connections, without a parent and with children',
node,
depth
);
const graphSettings = graph.graph();
const clusterGraph = new graphlib.Graph({
multigraph: true,
compound: true
})
.setGraph({
rankdir: graphSettings.rankdir === 'TB' ? 'LR' : 'TB',
// Todo: set proper spacing
nodesep: 50,
ranksep: 50,
marginx: 8,
marginy: 8
})
.setDefaultEdgeLabel(function() {
return {};
});
log.debug('Old graph before copy', graphlib.json.write(graph));
copy(node, graph, clusterGraph, node);
graph.setNode(node, {
clusterNode: true,
id: node,
clusterData: clusterDb[node].clusterData,
labelText: clusterDb[node].labelText,
graph: clusterGraph
});
log.debug('New graph after copy', graphlib.json.write(clusterGraph));
log.debug('Old graph after copy', graphlib.json.write(graph));
} else {
log.debug(
'Cluster ** ',
node,
' **not meeting the criteria !externalConnections:',
!clusterDb[node].externalConnections,
' no parent: ',
!graph.parent(node),
' children ',
graph.children(node) && graph.children(node).length > 0,
graph.children('D'),
depth
);
log.debug(clusterDb);
}
}
nodes = graph.nodes();
log.debug('New list of nodes', nodes);
for (let i = 0; i < nodes.length; i++) {
const node = nodes[i];
const data = graph.node(node);
log.debug(' Now next leveö', node, data);
if (data.clusterNode) {
extractor(data.graph, depth + 1);
}
}
};

View File

@@ -0,0 +1,428 @@
import graphlib from 'graphlib';
import dagre from 'dagre';
import { validate, adjustClustersAndEdges, extractDecendants } from './mermaid-graphlib';
import { setLogLevel, logger } from '../logger';
describe('Graphlib decorations', () => {
let g;
beforeEach(function () {
setLogLevel(1);
g = new graphlib.Graph({
multigraph: true,
compound: true
});
g.setGraph({
rankdir: 'TB',
nodesep: 10,
ranksep: 10,
marginx: 8,
marginy: 8
});
g.setDefaultEdgeLabel(function () {
return {};
});
});
describe('validate', function () {
it('Validate should detect edges between clusters', function () {
/*
subgraph C1
a --> b
end
subgraph C2
c
end
C1 --> C2
*/
g.setNode('a', { data:1});
g.setNode('b', { data: 2 });
g.setNode('c', { data: 3 });
g.setParent('a', 'C1');
g.setParent('b', 'C1');
g.setParent('c', 'C2');
g.setEdge('a', 'b');
g.setEdge('C1', 'C2');
console.log(g.nodes())
expect(validate(g)).toBe(false);
});
it('Validate should not detect edges between clusters after adjustment', function () {
/*
subgraph C1
a --> b
end
subgraph C2
c
end
C1 --> C2
*/
g.setNode('a', {});
g.setNode('b', {});
g.setNode('c', {});
g.setParent('a', 'C1');
g.setParent('b', 'C1');
g.setParent('c', 'C2');
g.setEdge('a', 'b');
g.setEdge('C1', 'C2');
console.log(g.nodes())
adjustClustersAndEdges(g);
logger.info(g.edges())
expect(validate(g)).toBe(true);
});
it('Validate should detect edges between clusters and transform clusters GLB4', function () {
/*
a --> b
subgraph C1
subgraph C2
a
end
b
end
C1 --> c
*/
g.setNode('a', { data: 1 });
g.setNode('b', { data: 2 });
g.setNode('c', { data: 3 });
g.setNode('C1', { data: 4 });
g.setNode('C2', { data: 5 });
g.setParent('a', 'C2');
g.setParent('b', 'C1');
g.setParent('C2', 'C1');
g.setEdge('a', 'b', { name: 'C1-internal-link' });
g.setEdge('C1', 'c', { name: 'C1-external-link' });
adjustClustersAndEdges(g);
logger.info(g.nodes())
expect(g.nodes().length).toBe(2);
expect(validate(g)).toBe(true);
});
it('Validate should detect edges between clusters and transform clusters GLB5', function () {
/*
a --> b
subgraph C1
a
end
subgraph C2
b
end
C1 -->
*/
g.setNode('a', { data: 1 });
g.setNode('b', { data: 2 });
g.setParent('a', 'C1');
g.setParent('b', 'C2');
// g.setEdge('a', 'b', { name: 'C1-internal-link' });
g.setEdge('C1', 'C2', { name: 'C1-external-link' });
logger.info(g.nodes())
adjustClustersAndEdges(g);
logger.info(g.nodes())
expect(g.nodes().length).toBe(2);
expect(validate(g)).toBe(true);
});
it('adjustClustersAndEdges GLB6', function () {
/*
subgraph C1
a
end
C1 --> b
*/
g.setNode('a', { data: 1 });
g.setNode('b', { data: 2 });
g.setNode('C1', { data: 3 });
g.setParent('a', 'C1');
g.setEdge('C1', 'b', { data: 'link1' }, '1');
// logger.info(g.edges())
adjustClustersAndEdges(g);
logger.info(g.edges())
expect(g.nodes()).toEqual(['b', 'C1']);
expect(g.edges().length).toBe(1);
expect(validate(g)).toBe(true);
expect(g.node('C1').clusterNode).toBe(true);
const C1Graph = g.node('C1').graph;
expect(C1Graph.nodes()).toEqual(['a']);
});
it('adjustClustersAndEdges GLB7', function () {
/*
subgraph C1
a
end
C1 --> b
C1 --> c
*/
g.setNode('a', { data: 1 });
g.setNode('b', { data: 2 });
g.setNode('c', { data: 3 });
g.setParent('a', 'C1');
g.setNode('C1', { data: 4 });
g.setEdge('C1', 'b', { data: 'link1' }, '1');
g.setEdge('C1', 'c', { data: 'link2' }, '2');
logger.info(g.node('C1'))
adjustClustersAndEdges(g);
logger.info(g.edges())
expect(g.nodes()).toEqual(['b', 'c', 'C1']);
expect(g.nodes().length).toBe(3);
expect(g.edges().length).toBe(2);
expect(g.edges().length).toBe(2);
const edgeData = g.edge(g.edges()[1]);
expect(edgeData.data).toBe('link2');
expect(validate(g)).toBe(true);
const C1Graph = g.node('C1').graph;
expect(C1Graph.nodes()).toEqual(['a']);
});
it('adjustClustersAndEdges GLB8', function () {
/*
subgraph A
a
end
subgraph B
b
end
subgraph C
c
end
A --> B
A --> C
*/
g.setNode('a', { data: 1 });
g.setNode('b', { data: 2 });
g.setNode('c', { data: 3 });
g.setParent('a', 'A');
g.setParent('b', 'B');
g.setParent('c', 'C');
g.setEdge('A', 'B', { data: 'link1' }, '1');
g.setEdge('A', 'C', { data: 'link2' }, '2');
// logger.info(g.edges())
adjustClustersAndEdges(g);
expect(g.nodes()).toEqual(['A', 'B', 'C']);
expect(g.edges().length).toBe(2);
expect(g.edges().length).toBe(2);
const edgeData = g.edge(g.edges()[1]);
expect(edgeData.data).toBe('link2');
expect(validate(g)).toBe(true);
const CGraph = g.node('C').graph;
expect(CGraph.nodes()).toEqual(['c']);
});
it('adjustClustersAndEdges the extracted graphs shall contain the correct data GLB10', function () {
/*
subgraph C
subgraph D
d
end
end
*/
g.setNode('C', { data: 1 });
g.setNode('D', { data: 2 });
g.setNode('d', { data: 3 });
g.setParent('d', 'D');
g.setParent('D', 'C');
// logger.info('Graph before', g.node('D'))
// logger.info('Graph before', graphlib.json.write(g))
adjustClustersAndEdges(g);
// logger.info('Graph after', graphlib.json.write(g), g.node('C').graph)
const CGraph = g.node('C').graph;
const DGraph = CGraph.node('D').graph;
expect(CGraph.nodes()).toEqual(['D']);
expect(DGraph.nodes()).toEqual(['d']);
expect(g.nodes()).toEqual(['C']);
expect(g.nodes().length).toBe(1);
});
it('adjustClustersAndEdges the extracted graphs shall contain the correct data GLB11', function () {
/*
subgraph A
a
end
subgraph B
b
end
subgraph C
subgraph D
d
end
end
A --> B
A --> C
*/
g.setNode('C', { data: 1 });
g.setNode('D', { data: 2 });
g.setNode('d', { data: 3 });
g.setNode('B', { data: 4 });
g.setNode('b', { data: 5 });
g.setNode('A', { data: 6 });
g.setNode('a', { data: 7 });
g.setParent('a', 'A');
g.setParent('b', 'B');
g.setParent('d', 'D');
g.setParent('D', 'C');
g.setEdge('A', 'B', { data: 'link1' }, '1');
g.setEdge('A', 'C', { data: 'link2' }, '2');
logger.info('Graph before', g.node('D'))
logger.info('Graph before', graphlib.json.write(g))
adjustClustersAndEdges(g);
logger.trace('Graph after', graphlib.json.write(g))
expect(g.nodes()).toEqual(['C', 'B', 'A']);
expect(g.nodes().length).toBe(3);
expect(g.edges().length).toBe(2);
const AGraph = g.node('A').graph;
const BGraph = g.node('B').graph;
const CGraph = g.node('C').graph;
// logger.info(CGraph.nodes());
const DGraph = CGraph.node('D').graph;
// logger.info('DG', CGraph.children('D'));
logger.info('A', AGraph.nodes());
expect(AGraph.nodes().length).toBe(1);
expect(AGraph.nodes()).toEqual(['a']);
logger.trace('Nodes', BGraph.nodes())
expect(BGraph.nodes().length).toBe(1);
expect(BGraph.nodes()).toEqual(['b']);
expect(CGraph.nodes()).toEqual(['D']);
expect(CGraph.nodes().length).toEqual(1);
expect(AGraph.edges().length).toBe(0);
expect(BGraph.edges().length).toBe(0);
expect(CGraph.edges().length).toBe(0);
expect(DGraph.nodes()).toEqual(['d']);
expect(DGraph.edges().length).toBe(0);
// expect(CGraph.node('D')).toEqual({ data: 2 });
expect(g.edges().length).toBe(2);
// expect(g.edges().length).toBe(2);
// const edgeData = g.edge(g.edges()[1]);
// expect(edgeData.data).toBe('link2');
// expect(validate(g)).toBe(true);
});
it('adjustClustersAndEdges the extracted graphs shall contain the correct links GLB20', function () {
/*
a --> b
subgraph b [Test]
c --> d -->e
end
*/
g.setNode('a', { data: 1 });
g.setNode('b', { data: 2 });
g.setNode('c', { data: 3 });
g.setNode('d', { data: 3 });
g.setNode('e', { data: 3 });
g.setParent('c', 'b');
g.setParent('d', 'b');
g.setParent('e', 'b');
g.setEdge('a', 'b', { data: 'link1' }, '1');
g.setEdge('c', 'd', { data: 'link2' }, '2');
g.setEdge('d', 'e', { data: 'link2' }, '2');
logger.info('Graph before', graphlib.json.write(g))
adjustClustersAndEdges(g);
const bGraph = g.node('b').graph;
// logger.trace('Graph after', graphlib.json.write(g))
logger.info('Graph after', graphlib.json.write(bGraph));
expect(bGraph.nodes().length).toBe(3);
expect(bGraph.edges().length).toBe(2);
});
it('adjustClustersAndEdges the extracted graphs shall contain the correct links GLB21', function () {
/*
state a {
state b {
state c {
e
}
}
}
*/
g.setNode('a', { data: 1 });
g.setNode('b', { data: 2 });
g.setNode('c', { data: 3 });
g.setNode('e', { data: 3 });
g.setParent('b', 'a');
g.setParent('c', 'b');
g.setParent('e', 'c');
logger.info('Graph before', graphlib.json.write(g))
adjustClustersAndEdges(g);
const aGraph = g.node('a').graph;
const bGraph = aGraph.node('b').graph;
logger.info('Graph after', graphlib.json.write(aGraph));
const cGraph = bGraph.node('c').graph;
// logger.trace('Graph after', graphlib.json.write(g))
expect(aGraph.nodes().length).toBe(1);
expect(bGraph.nodes().length).toBe(1);
expect(cGraph.nodes().length).toBe(1);
expect(bGraph.edges().length).toBe(0);
});
});
});
describe('extractDecendants', function () {
let g;
beforeEach(function () {
setLogLevel(1);
g = new graphlib.Graph({
multigraph: true,
compound: true
});
g.setGraph({
rankdir: 'TB',
nodesep: 10,
ranksep: 10,
marginx: 8,
marginy: 8
});
g.setDefaultEdgeLabel(function () {
return {};
});
});
it('Simple case of one level decendants GLB9', function () {
/*
subgraph A
a
end
subgraph B
b
end
subgraph C
c
end
A --> B
A --> C
*/
g.setNode('a', { data: 1 });
g.setNode('b', { data: 2 });
g.setNode('c', { data: 3 });
g.setParent('a', 'A');
g.setParent('b', 'B');
g.setParent('c', 'C');
g.setEdge('A', 'B', { data: 'link1' }, '1');
g.setEdge('A', 'C', { data: 'link2' }, '2');
// logger.info(g.edges())
const d1 = extractDecendants('A',g)
const d2 = extractDecendants('B',g)
const d3 = extractDecendants('C',g)
expect(d1).toEqual(['a']);
expect(d2).toEqual(['b']);
expect(d3).toEqual(['c']);
});
});

556
src/dagre-wrapper/nodes.js Normal file
View File

@@ -0,0 +1,556 @@
import intersect from './intersect/index.js';
import { select } from 'd3';
import { logger } from '../logger'; // eslint-disable-line
import { labelHelper, updateNodeBounds, insertPolygonShape } from './shapes/util';
import createLabel from './createLabel';
import note from './shapes/note';
const question = (parent, node) => {
const { shapeSvg, bbox } = labelHelper(parent, node);
const w = bbox.width + node.padding;
const h = bbox.height + node.padding;
const s = w + h;
const points = [
{ x: s / 2, y: 0 },
{ x: s, y: -s / 2 },
{ x: s / 2, y: -s },
{ x: 0, y: -s / 2 }
];
const questionElem = insertPolygonShape(shapeSvg, s, s, points);
updateNodeBounds(node, questionElem);
node.intersect = function(point) {
logger.warn('Intersect called');
return intersect.polygon(node, points, point);
};
return shapeSvg;
};
const hexagon = (parent, node) => {
const { shapeSvg, bbox } = labelHelper(parent, node);
const f = 4;
const h = bbox.height + node.padding;
const m = h / f;
const w = bbox.width + 2 * m + node.padding;
const points = [
{ x: m, y: 0 },
{ x: w - m, y: 0 },
{ x: w, y: -h / 2 },
{ x: w - m, y: -h },
{ x: m, y: -h },
{ x: 0, y: -h / 2 }
];
const hex = insertPolygonShape(shapeSvg, w, h, points);
updateNodeBounds(node, hex);
node.intersect = function(point) {
return intersect.polygon(node, point);
};
return shapeSvg;
};
const rect_left_inv_arrow = (parent, node) => {
const { shapeSvg, bbox } = labelHelper(parent, node);
const w = bbox.width + node.padding;
const h = bbox.height + node.padding;
const points = [
{ x: -h / 2, y: 0 },
{ x: w, y: 0 },
{ x: w, y: -h },
{ x: -h / 2, y: -h },
{ x: 0, y: -h / 2 }
];
const el = insertPolygonShape(shapeSvg, w, h, points);
updateNodeBounds(node, el);
node.intersect = function(point) {
return intersect.polygon(node, point);
};
return shapeSvg;
};
const lean_right = (parent, node) => {
const { shapeSvg, bbox } = labelHelper(parent, node);
const w = bbox.width + node.padding;
const h = bbox.height + node.padding;
const points = [
{ x: (-2 * h) / 6, y: 0 },
{ x: w - h / 6, y: 0 },
{ x: w + (2 * h) / 6, y: -h },
{ x: h / 6, y: -h }
];
const el = insertPolygonShape(shapeSvg, w, h, points);
updateNodeBounds(node, el);
node.intersect = function(point) {
return intersect.polygon(node, point);
};
return shapeSvg;
};
const lean_left = (parent, node) => {
const { shapeSvg, bbox } = labelHelper(parent, node);
const w = bbox.width + node.padding;
const h = bbox.height + node.padding;
const points = [
{ x: (2 * h) / 6, y: 0 },
{ x: w + h / 6, y: 0 },
{ x: w - (2 * h) / 6, y: -h },
{ x: -h / 6, y: -h }
];
const el = insertPolygonShape(shapeSvg, w, h, points);
updateNodeBounds(node, el);
node.intersect = function(point) {
return intersect.polygon(node, point);
};
return shapeSvg;
};
const trapezoid = (parent, node) => {
const { shapeSvg, bbox } = labelHelper(parent, node);
const w = bbox.width + node.padding;
const h = bbox.height + node.padding;
const points = [
{ x: (-2 * h) / 6, y: 0 },
{ x: w + (2 * h) / 6, y: 0 },
{ x: w - h / 6, y: -h },
{ x: h / 6, y: -h }
];
const el = insertPolygonShape(shapeSvg, w, h, points);
updateNodeBounds(node, el);
node.intersect = function(point) {
return intersect.polygon(node, point);
};
return shapeSvg;
};
const inv_trapezoid = (parent, node) => {
const { shapeSvg, bbox } = labelHelper(parent, node);
const w = bbox.width + node.padding;
const h = bbox.height + node.padding;
const points = [
{ x: h / 6, y: 0 },
{ x: w - h / 6, y: 0 },
{ x: w + (2 * h) / 6, y: -h },
{ x: (-2 * h) / 6, y: -h }
];
const el = insertPolygonShape(shapeSvg, w, h, points);
updateNodeBounds(node, el);
node.intersect = function(point) {
return intersect.polygon(node, point);
};
return shapeSvg;
};
const rect_right_inv_arrow = (parent, node) => {
const { shapeSvg, bbox } = labelHelper(parent, node);
const w = bbox.width + node.padding;
const h = bbox.height + node.padding;
const points = [
{ x: 0, y: 0 },
{ x: w + h / 2, y: 0 },
{ x: w, y: -h / 2 },
{ x: w + h / 2, y: -h },
{ x: 0, y: -h }
];
const el = insertPolygonShape(shapeSvg, w, h, points);
updateNodeBounds(node, el);
node.intersect = function(point) {
return intersect.polygon(node, point);
};
return shapeSvg;
};
const cylinder = (parent, node) => {
const { shapeSvg, bbox } = labelHelper(parent, node);
const w = bbox.width + node.padding;
const rx = w / 2;
const ry = rx / (2.5 + w / 50);
const h = bbox.height + ry + node.padding;
const shape =
'M 0,' +
ry +
' a ' +
rx +
',' +
ry +
' 0,0,0 ' +
w +
' 0 a ' +
rx +
',' +
ry +
' 0,0,0 ' +
-w +
' 0 l 0,' +
h +
' a ' +
rx +
',' +
ry +
' 0,0,0 ' +
w +
' 0 l 0,' +
-h;
const el = shapeSvg
.attr('label-offset-y', ry)
.insert('path', ':first-child')
.attr('d', shape)
.attr('transform', 'translate(' + -w / 2 + ',' + -(h / 2 + ry) + ')');
updateNodeBounds(node, el);
node.intersect = function(point) {
const pos = intersect.rect(node, point);
const x = pos.x - node.x;
if (
rx != 0 &&
(Math.abs(x) < node.width / 2 ||
(Math.abs(x) == node.width / 2 && Math.abs(pos.y - node.y) > node.height / 2 - ry))
) {
// ellipsis equation: x*x / a*a + y*y / b*b = 1
// solve for y to get adjustion value for pos.y
let y = ry * ry * (1 - (x * x) / (rx * rx));
if (y != 0) y = Math.sqrt(y);
y = ry - y;
if (point.y - node.y > 0) y = -y;
pos.y += y;
}
return pos;
};
return shapeSvg;
};
const rect = (parent, node) => {
const { shapeSvg, bbox, halfPadding } = labelHelper(parent, node, 'node ' + node.classes);
logger.trace('Classes = ', node.classes);
// add the rect
const rect = shapeSvg.insert('rect', ':first-child');
rect
.attr('class', 'basic label-container')
.attr('rx', node.rx)
.attr('ry', node.ry)
.attr('x', -bbox.width / 2 - halfPadding)
.attr('y', -bbox.height / 2 - halfPadding)
.attr('width', bbox.width + node.padding)
.attr('height', bbox.height + node.padding);
updateNodeBounds(node, rect);
node.intersect = function(point) {
return intersect.rect(node, point);
};
return shapeSvg;
};
const rectWithTitle = (parent, node) => {
// const { shapeSvg, bbox, halfPadding } = labelHelper(parent, node, 'node ' + node.classes);
let classes;
if (!node.classes) {
classes = 'node default';
} else {
classes = 'node ' + node.classes;
}
// Add outer g element
const shapeSvg = parent
.insert('g')
.attr('class', classes)
.attr('id', node.id);
// Create the title label and insert it after the rect
const rect = shapeSvg.insert('rect', ':first-child');
// const innerRect = shapeSvg.insert('rect');
const innerLine = shapeSvg.insert('line');
const label = shapeSvg.insert('g').attr('class', 'label');
const text2 = node.labelText.flat();
logger.info('Label text', text2[0]);
const text = label.node().appendChild(createLabel(text2[0], node.labelStyle, true));
const textRows = text2.slice(1, text2.length);
let titleBox = text.getBBox();
const descr = label
.node()
.appendChild(createLabel(textRows.join('<br/>'), node.labelStyle, true));
logger.info(descr);
const halfPadding = node.padding / 2;
select(descr).attr('transform', 'translate( 0' + ', ' + (titleBox.height + halfPadding) + ')');
// Get the size of the label
// Bounding box for title and text
const bbox = label.node().getBBox();
// Center the label
label.attr(
'transform',
'translate(' + -bbox.width / 2 + ', ' + (-bbox.height / 2 - halfPadding + 3) + ')'
);
rect
.attr('class', 'outer title-state')
.attr('x', -bbox.width / 2 - halfPadding)
.attr('y', -bbox.height / 2 - halfPadding)
.attr('width', bbox.width + node.padding)
.attr('height', bbox.height + node.padding);
innerLine
.attr('class', 'divider')
.attr('x1', -bbox.width / 2 - halfPadding)
.attr('x2', bbox.width / 2 + halfPadding)
.attr('y1', -bbox.height / 2 - halfPadding + titleBox.height + halfPadding)
.attr('y2', -bbox.height / 2 - halfPadding + titleBox.height + halfPadding);
updateNodeBounds(node, rect);
node.intersect = function(point) {
return intersect.rect(node, point);
};
return shapeSvg;
};
const stadium = (parent, node) => {
const { shapeSvg, bbox } = labelHelper(parent, node);
const h = bbox.height + node.padding;
const w = bbox.width + h / 4 + node.padding;
// add the rect
const rect = shapeSvg
.insert('rect', ':first-child')
.attr('rx', h / 2)
.attr('ry', h / 2)
.attr('x', -w / 2)
.attr('y', -h / 2)
.attr('width', w)
.attr('height', h);
updateNodeBounds(node, rect);
node.intersect = function(point) {
return intersect.rect(node, point);
};
return shapeSvg;
};
const circle = (parent, node) => {
const { shapeSvg, bbox, halfPadding } = labelHelper(parent, node);
const circle = shapeSvg.insert('circle', ':first-child');
// center the circle around its coordinate
circle
.attr('rx', node.rx)
.attr('ry', node.ry)
.attr('r', bbox.width / 2 + halfPadding)
.attr('width', bbox.width + node.padding)
.attr('height', bbox.height + node.padding);
updateNodeBounds(node, circle);
node.intersect = function(point) {
return intersect.circle(node, node.rx, point);
};
return shapeSvg;
};
const subroutine = (parent, node) => {
const { shapeSvg, bbox } = labelHelper(parent, node);
const w = bbox.width + node.padding;
const h = bbox.height + node.padding;
const points = [
{ x: 0, y: 0 },
{ x: w, y: 0 },
{ x: w, y: -h },
{ x: 0, y: -h },
{ x: 0, y: 0 },
{ x: -8, y: 0 },
{ x: w + 8, y: 0 },
{ x: w + 8, y: -h },
{ x: -8, y: -h },
{ x: -8, y: 0 }
];
const el = insertPolygonShape(shapeSvg, w, h, points);
updateNodeBounds(node, el);
node.intersect = function(point) {
return intersect.polygon(node, point);
};
return shapeSvg;
};
const start = (parent, node) => {
const shapeSvg = parent
.insert('g')
.attr('class', 'node default')
.attr('id', node.id);
const circle = shapeSvg.insert('circle', ':first-child');
// center the circle around its coordinate
circle
.attr('class', 'state-start')
.attr('r', 7)
.attr('width', 14)
.attr('height', 14);
updateNodeBounds(node, circle);
node.intersect = function(point) {
return intersect.circle(node, 7, point);
};
return shapeSvg;
};
const forkJoin = (parent, node, dir) => {
const shapeSvg = parent
.insert('g')
.attr('class', 'node default')
.attr('id', node.id);
let width = 70;
let height = 10;
if (dir === 'LR') {
width = 10;
height = 70;
}
const shape = shapeSvg
.append('rect')
.style('stroke', 'black')
.style('fill', 'black')
.attr('x', (-1 * width) / 2)
.attr('y', (-1 * height) / 2)
.attr('width', width)
.attr('height', height)
.attr('class', 'fork-join');
updateNodeBounds(node, shape);
node.height = node.height + node.padding / 2;
node.width = node.width + node.padding / 2;
node.intersect = function(point) {
return intersect.rect(node, point);
};
return shapeSvg;
};
const end = (parent, node) => {
const shapeSvg = parent
.insert('g')
.attr('class', 'node default')
.attr('id', node.id);
const innerCircle = shapeSvg.insert('circle', ':first-child');
const circle = shapeSvg.insert('circle', ':first-child');
circle
.attr('class', 'state-start')
.attr('r', 7)
.attr('width', 14)
.attr('height', 14);
innerCircle
.attr('class', 'state-end')
.attr('r', 5)
.attr('width', 10)
.attr('height', 10);
updateNodeBounds(node, circle);
node.intersect = function(point) {
return intersect.circle(node, 7, point);
};
return shapeSvg;
};
const shapes = {
question,
rect,
rectWithTitle,
circle,
stadium,
hexagon,
rect_left_inv_arrow,
lean_right,
lean_left,
trapezoid,
inv_trapezoid,
rect_right_inv_arrow,
cylinder,
start,
end,
note,
subroutine,
fork: forkJoin,
join: forkJoin
};
let nodeElems = {};
export const insertNode = (elem, node, dir) => {
nodeElems[node.id] = shapes[node.shape](elem, node, dir);
};
export const setNodeElem = (elem, node) => {
nodeElems[node.id] = elem;
};
export const clear = () => {
nodeElems = {};
};
export const positionNode = node => {
const el = nodeElems[node.id];
logger.trace(
'Transforming node',
node,
'translate(' + (node.x - node.width / 2 - 5) + ', ' + (node.y - node.height / 2 - 5) + ')'
);
const padding = 8;
if (node.clusterNode) {
el.attr(
'transform',
'translate(' +
(node.x - node.width / 2 - padding) +
', ' +
(node.y - node.height / 2 - padding) +
')'
);
} else {
el.attr('transform', 'translate(' + node.x + ', ' + node.y + ')');
}
};

View File

@@ -0,0 +1,54 @@
/**
* Setup arrow head and define the marker. The result is appended to the svg.
*/
// import { logger } from '../logger';
// Only add the number of markers that the diagram needs
const insertPatterns = (elem, patternArray, type, id) => {
patternArray.forEach(patternName => {
patterns[patternName](elem, type, id);
});
};
{
/* <svg height="10" width="10" xmlns="http://www.w3.org/2000/svg" version="1.1">
{' '}
<defs>
{' '}
<pattern id="circles-1" patternUnits="userSpaceOnUse" width="10" height="10">
{' '}
<image
xlink:href="data:image/svg+xml;base64,PHN2ZyB4bWxucz0naHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmcnIHdpZHRoPScxMCcgaGVpZ2h0PScxMCc+CiAgPHJlY3Qgd2lkdGg9JzEwJyBoZWlnaHQ9JzEwJyBmaWxsPSJ3aGl0ZSIgLz4KICA8Y2lyY2xlIGN4PSIxIiBjeT0iMSIgcj0iMSIgZmlsbD0iYmxhY2siLz4KPC9zdmc+"
x="0"
y="0"
width="10"
height="10"
>
{' '}
</image>{' '}
</pattern>{' '}
</defs>{' '}
</svg>; */
}
const dots = (elem, type) => {
elem
.append('defs')
.append('marker')
.attr('id', type + '-barbEnd')
.attr('refX', 19)
.attr('refY', 7)
.attr('markerWidth', 20)
.attr('markerHeight', 14)
.attr('markerUnits', 0)
.attr('orient', 'auto')
.append('path')
.attr('d', 'M 19,7 L9,13 L14,7 L9,1 Z');
};
// TODO rename the class diagram markers to something shape descriptive and semanitc free
const patterns = {
dots
};
export default insertPatterns;

View File

@@ -0,0 +1,29 @@
import { updateNodeBounds, labelHelper } from './util';
import { logger } from '../../logger'; // eslint-disable-line
import intersect from '../intersect/index.js';
const note = (parent, node) => {
const { shapeSvg, bbox, halfPadding } = labelHelper(parent, node, 'node ' + node.classes);
logger.info('Classes = ', node.classes);
// add the rect
const rect = shapeSvg.insert('rect', ':first-child');
rect
.attr('rx', node.rx)
.attr('ry', node.ry)
.attr('x', -bbox.width / 2 - halfPadding)
.attr('y', -bbox.height / 2 - halfPadding)
.attr('width', bbox.width + node.padding)
.attr('height', bbox.height + node.padding);
updateNodeBounds(node, rect);
node.intersect = function(point) {
return intersect.rect(node, point);
};
return shapeSvg;
};
export default note;

View File

@@ -0,0 +1,51 @@
import createLabel from '../createLabel';
export const labelHelper = (parent, node, _classes) => {
let classes;
if (!_classes) {
classes = 'node default';
} else {
classes = _classes;
}
// Add outer g element
const shapeSvg = parent
.insert('g')
.attr('class', classes)
.attr('id', node.id);
// Create the label and insert it after the rect
const label = shapeSvg.insert('g').attr('class', 'label');
const text = label.node().appendChild(createLabel(node.labelText, node.labelStyle));
// Get the size of the label
const bbox = text.getBBox();
const halfPadding = node.padding / 2;
// Center the label
label.attr('transform', 'translate(' + -bbox.width / 2 + ', ' + -bbox.height / 2 + ')');
return { shapeSvg, bbox, halfPadding, label };
};
export const updateNodeBounds = (node, element) => {
const bbox = element.node().getBBox();
node.width = bbox.width;
node.height = bbox.height;
};
export function insertPolygonShape(parent, w, h, points) {
return parent
.insert('polygon', ':first-child')
.attr(
'points',
points
.map(function(d) {
return d.x + ',' + d.y;
})
.join(' ')
)
.attr('class', 'label-container')
.attr('transform', 'translate(' + -w / 2 + ',' + h / 2 + ')');
}

View File

@@ -1,7 +1,31 @@
import { select } from 'd3';
import { logger } from '../../logger';
import { getConfig } from '../../config';
import common from '../common/common';
import utils from '../../utils';
const MERMAID_DOM_ID_PREFIX = 'classid-';
const config = getConfig();
let relations = [];
let classes = {};
let classCounter = 0;
let funs = [];
const splitClassNameAndType = function(id) {
let genericType = '';
let className = id;
if (id.indexOf('~') > 0) {
let split = id.split('~');
className = split[0];
genericType = split[1];
}
return { className: className, type: genericType };
};
/**
* Function called by parser when a node definition has been found.
@@ -9,20 +33,41 @@ let classes = {};
* @public
*/
export const addClass = function(id) {
let classId = splitClassNameAndType(id);
// Only add class if not exists
if (typeof classes[id] !== 'undefined') return;
if (typeof classes[classId.className] !== 'undefined') return;
classes[id] = {
id: id,
classes[classId.className] = {
id: classId.className,
type: classId.type,
cssClasses: [],
methods: [],
members: [],
annotations: []
annotations: [],
domId: MERMAID_DOM_ID_PREFIX + classId.className + '-' + classCounter
};
classCounter++;
};
/**
* Function to lookup domId from id in the graph definition.
* @param id
* @public
*/
export const lookUpDomId = function(id) {
const classKeys = Object.keys(classes);
for (let i = 0; i < classKeys.length; i++) {
if (classes[classKeys[i]].id === id) {
return classes[classKeys[i]].domId;
}
}
};
export const clear = function() {
relations = [];
classes = {};
funs = [];
funs.push(setupToolTips);
};
export const getClass = function(id) {
@@ -40,6 +85,10 @@ export const addRelation = function(relation) {
logger.debug('Adding relation: ' + JSON.stringify(relation));
addClass(relation.id1);
addClass(relation.id2);
relation.id1 = splitClassNameAndType(relation.id1).className;
relation.id2 = splitClassNameAndType(relation.id2).className;
relations.push(relation);
};
@@ -51,7 +100,8 @@ export const addRelation = function(relation) {
* @public
*/
export const addAnnotation = function(className, annotation) {
classes[className].annotations.push(annotation);
const validatedClassName = splitClassNameAndType(className).className;
classes[validatedClassName].annotations.push(annotation);
};
/**
@@ -64,7 +114,9 @@ export const addAnnotation = function(className, annotation) {
* @public
*/
export const addMember = function(className, member) {
const theClass = classes[className];
const validatedClassName = splitClassNameAndType(className).className;
const theClass = classes[validatedClassName];
if (typeof member === 'string') {
// Member can contain white spaces, we trim them out
const memberString = member.trim();
@@ -72,7 +124,7 @@ export const addMember = function(className, member) {
if (memberString.startsWith('<<') && memberString.endsWith('>>')) {
// Remove leading and trailing brackets
theClass.annotations.push(memberString.substring(2, memberString.length - 2));
} else if (memberString.endsWith(')')) {
} else if (memberString.indexOf(')') > 0) {
theClass.methods.push(memberString);
} else if (memberString) {
theClass.members.push(memberString);
@@ -89,12 +141,97 @@ export const addMembers = function(className, members) {
export const cleanupLabel = function(label) {
if (label.substring(0, 1) === ':') {
return label.substr(2).trim();
return label.substr(1).trim();
} else {
return label.trim();
}
};
/**
* Called by parser when a special node is found, e.g. a clickable element.
* @param ids Comma separated list of ids
* @param className Class to add
*/
export const setCssClass = function(ids, className) {
ids.split(',').forEach(function(_id) {
let id = _id;
if (_id[0].match(/\d/)) id = MERMAID_DOM_ID_PREFIX + id;
if (typeof classes[id] !== 'undefined') {
classes[id].cssClasses.push(className);
}
});
};
/**
* Called by parser when a link is found. Adds the URL to the vertex data.
* @param ids Comma separated list of ids
* @param linkStr URL to create a link for
* @param tooltip Tooltip for the clickable element
*/
export const setLink = function(ids, linkStr, tooltip) {
ids.split(',').forEach(function(_id) {
let id = _id;
if (_id[0].match(/\d/)) id = MERMAID_DOM_ID_PREFIX + id;
if (typeof classes[id] !== 'undefined') {
classes[id].link = utils.formatUrl(linkStr, config);
if (tooltip) {
classes[id].tooltip = common.sanitizeText(tooltip, config);
}
}
});
setCssClass(ids, 'clickable');
};
/**
* Called by parser when a click definition is found. Registers an event handler.
* @param ids Comma separated list of ids
* @param functionName Function to be called on click
* @param tooltip Tooltip for the clickable element
*/
export const setClickEvent = function(ids, functionName, tooltip) {
ids.split(',').forEach(function(id) {
setClickFunc(id, functionName, tooltip);
});
setCssClass(ids, 'clickable');
};
const setClickFunc = function(domId, functionName, tooltip) {
let id = domId;
let elemId = lookUpDomId(id);
if (config.securityLevel !== 'loose') {
return;
}
if (typeof functionName === 'undefined') {
return;
}
if (typeof classes[id] !== 'undefined') {
if (tooltip) {
classes[id].tooltip = common.sanitizeText(tooltip, config);
}
funs.push(function() {
const elem = document.querySelector(`[id="${elemId}"]`);
if (elem !== null) {
elem.addEventListener(
'click',
function() {
window[functionName](elemId);
},
false
);
}
});
}
};
export const bindFunctions = function(element) {
funs.forEach(function(fun) {
fun(element);
});
};
export const lineType = {
LINE: 0,
DOTTED_LINE: 1
@@ -107,8 +244,52 @@ export const relationType = {
DEPENDENCY: 3
};
const setupToolTips = function(element) {
let tooltipElem = select('.mermaidTooltip');
if ((tooltipElem._groups || tooltipElem)[0][0] === null) {
tooltipElem = select('body')
.append('div')
.attr('class', 'mermaidTooltip')
.style('opacity', 0);
}
const svg = select(element).select('svg');
const nodes = svg.selectAll('g.node');
nodes
.on('mouseover', function() {
const el = select(this);
const title = el.attr('title');
// Dont try to draw a tooltip if no data is provided
if (title === null) {
return;
}
const rect = this.getBoundingClientRect();
tooltipElem
.transition()
.duration(200)
.style('opacity', '.9');
tooltipElem
.html(el.attr('title'))
.style('left', rect.left + (rect.right - rect.left) / 2 + 'px')
.style('top', rect.top - 14 + document.body.scrollTop + 'px');
el.classed('hover', true);
})
.on('mouseout', function() {
tooltipElem
.transition()
.duration(500)
.style('opacity', 0);
const el = select(this);
el.classed('hover', false);
});
};
funs.push(setupToolTips);
export default {
addClass,
bindFunctions,
clear,
getClass,
getClasses,
@@ -119,5 +300,9 @@ export default {
addMembers,
cleanupLabel,
lineType,
relationType
relationType,
setClickEvent,
setCssClass,
setLink,
lookUpDomId
};

View File

@@ -2,13 +2,13 @@
import { parser } from './parser/classDiagram';
import classDb from './classDb';
describe('class diagram, ', function() {
describe('when parsing an info graph it', function() {
beforeEach(function() {
describe('class diagram, ', function () {
describe('when parsing an info graph it', function () {
beforeEach(function () {
parser.yy = classDb;
});
it('should handle relation definitions', function() {
it('should handle relation definitions', function () {
const str =
'classDiagram\n' +
'Class01 <|-- Class02\n' +
@@ -19,7 +19,8 @@ describe('class diagram, ', function() {
parser.parse(str);
});
it('should handle relation definition of different types and directions', function() {
it('should handle relation definition of different types and directions', function () {
const str =
'classDiagram\n' +
'Class11 <|.. Class12\n' +
@@ -31,7 +32,7 @@ describe('class diagram, ', function() {
parser.parse(str);
});
it('should handle cardinality and labels', function() {
it('should handle cardinality and labels', function () {
const str =
'classDiagram\n' +
'Class01 "1" *-- "many" Class02 : contains\n' +
@@ -40,6 +41,90 @@ describe('class diagram, ', function() {
parser.parse(str);
});
it('should handle visibility for methods and members', function() {
const str =
'classDiagram\n' +
'class TestClass\n' +
'TestClass : -int privateMember\n' +
'TestClass : +int publicMember\n' +
'TestClass : #int protectedMember\n' +
'TestClass : -privateMethod()\n' +
'TestClass : +publicMethod()\n' +
'TestClass : #protectedMethod()\n';
parser.parse(str);
});
it('should handle generic class', function() {
const str =
'classDiagram\n' +
'class Car~T~\n' +
'Driver -- Car : drives >\n' +
'Car *-- Wheel : have 4 >\n' +
'Car -- Person : < owns';
parser.parse(str);
});
it('should break when another `{`is encountered before closing the first one while defining generic class with brackets', function() {
const str =
'classDiagram\n' +
'class Dummy_Class~T~ {\n' +
'String data\n' +
' void methods()\n' +
'}\n' +
'\n' +
'class Dummy_Class {\n' +
'class Flight {\n' +
' flightNumber : Integer\n' +
' departureTime : Date\n' +
'}';
let testPased =false;
try{
parser.parse(str);
}catch (error){
console.log(error.name);
testPased = true;
}
expect(testPased).toBe(true);
});
it('should break when EOF is encountered before closing the first `{` while defining generic class with brackets', function() {
const str =
'classDiagram\n' +
'class Dummy_Class~T~ {\n' +
'String data\n' +
' void methods()\n' +
'}\n' +
'\n' +
'class Dummy_Class {\n';
let testPased =false;
try{
parser.parse(str);
}catch (error){
console.log(error.name);
testPased = true;
}
expect(testPased).toBe(true);
});
it('should handle generic class with brackets', function() {
const str =
'classDiagram\n' +
'class Dummy_Class~T~ {\n' +
'String data\n' +
' void methods()\n' +
'}\n' +
'\n' +
'class Flight {\n' +
' flightNumber : Integer\n' +
' departureTime : Date\n' +
'}';
parser.parse(str);
});
it('should handle class definitions', function() {
const str =
'classDiagram\n' +
@@ -51,7 +136,7 @@ describe('class diagram, ', function() {
parser.parse(str);
});
it('should handle method statements', function() {
it('should handle method statements', function () {
const str =
'classDiagram\n' +
'Object <|-- ArrayList\n' +
@@ -61,7 +146,8 @@ describe('class diagram, ', function() {
parser.parse(str);
});
it('should handle parsing of method statements grouped by brackets', function() {
it('should handle parsing of method statements grouped by brackets', function () {
const str =
'classDiagram\n' +
'class Dummy_Class {\n' +
@@ -77,7 +163,37 @@ describe('class diagram, ', function() {
parser.parse(str);
});
it('should handle parsing of separators', function() {
it('should handle return types on methods', function () {
const str =
'classDiagram\n' +
'Object <|-- ArrayList\n' +
'Object : equals()\n' +
'Object : -Object[] objects\n' +
'Object : +getObjects() Object[]\n' +
'ArrayList : Dummy elementData\n' +
'ArrayList : getDummy() Dummy';
parser.parse(str);
});
it('should handle return types on methods grouped by brackets', function () {
const str =
'classDiagram\n' +
'class Dummy_Class {\n' +
'string data\n' +
'getDummy() Dummy\n' +
'}\n' +
'\n' +
'class Flight {\n' +
' int flightNumber\n' +
' datetime departureTime\n' +
' getDepartureTime() datetime\n' +
'}';
parser.parse(str);
});
it('should handle parsing of separators', function () {
const str =
'classDiagram\n' +
'class Foo1 {\n' +
@@ -109,14 +225,205 @@ describe('class diagram, ', function() {
parser.parse(str);
});
it('should handle a comment', function () {
const str =
'classDiagram\n' +
'class Class1 {\n' +
'%% Comment\n' +
'int : test\n' +
'string : foo\n' +
'test()\n' +
'foo()\n' +
'}';
parser.parse(str);
});
it('should handle comments at the start', function () {
const str =
'%% Comment\n' +
'classDiagram\n' +
'class Class1 {\n' +
'int : test\n' +
'string : foo\n' +
'test()\n' +
'foo()\n' +
'}';
parser.parse(str);
});
it('should handle comments at the end', function () {
const str =
'classDiagram\n' +
'class Class1 {\n' +
'int : test\n' +
'string : foo\n' +
'test()\n' +
'foo()\n' +
'\n}' +
'%% Comment\n';
parser.parse(str);
});
it('should handle comments at the end no trailing newline', function () {
const str =
'classDiagram\n' +
'class Class1 {\n' +
'int : test\n' +
'string : foo\n' +
'test()\n' +
'foo()\n' +
'}\n' +
'%% Comment';
parser.parse(str);
});
it('should handle a comment with multiple line feeds', function () {
const str =
'classDiagram\n\n\n' +
'%% Comment\n\n' +
'class Class1 {\n' +
'int : test\n' +
'string : foo\n' +
'test()\n' +
'foo()\n' +
'}';
parser.parse(str);
});
it('should handle a comment with mermaid class diagram code in them', function () {
const str =
'classDiagram\n' +
'%% Comment Class01 <|-- Class02\n' +
'class Class1 {\n' +
'int : test\n' +
'string : foo\n' +
'test()\n' +
'foo()\n' +
'}';
parser.parse(str);
});
it('should handle a comment inside brackets', function () {
const str =
'classDiagram\n' +
'class Class1 {\n' +
'%% Comment Class01 <|-- Class02\n' +
'int : test\n' +
'string : foo\n' +
'test()\n' +
'foo()\n' +
'}';
parser.parse(str);
});
it('should handle click statement with link', function () {
const str =
'classDiagram\n' +
'class Class1 {\n' +
'%% Comment Class01 <|-- Class02\n' +
'int : test\n' +
'string : foo\n' +
'test()\n' +
'foo()\n' +
'}\n' +
'link Class01 "google.com" ';
parser.parse(str);
});
it('should handle click statement with link and tooltip', function () {
const str =
'classDiagram\n' +
'class Class1 {\n' +
'%% Comment Class01 <|-- Class02\n' +
'int : test\n' +
'string : foo\n' +
'test()\n' +
'foo()\n' +
'}\n' +
'link Class01 "google.com" "A Tooltip" ';
parser.parse(str);
});
it('should handle click statement with callback', function () {
const str =
'classDiagram\n' +
'class Class1 {\n' +
'%% Comment Class01 <|-- Class02\n' +
'int : test\n' +
'string : foo\n' +
'test()\n' +
'foo()\n' +
'}\n' +
'callback Class01 "functionCall" ';
parser.parse(str);
});
it('should handle click statement with callback and tooltip', function () {
const str =
'classDiagram\n' +
'class Class1 {\n' +
'%% Comment Class01 <|-- Class02\n' +
'int : test\n' +
'string : foo\n' +
'test()\n' +
'foo()\n' +
'}\n' +
'callback Class01 "functionCall" "A Tooltip" ';
parser.parse(str);
});
it('should handle dashed relation definition of different types and directions', function () {
const str =
'classDiagram\n' +
'Class11 <|.. Class12\n' +
'Class13 <.. Class14\n' +
'Class15 ..|> Class16\n' +
'Class17 ..> Class18\n' +
'Class19 .. Class20';
parser.parse(str);
});
it('should handle generic types in members', function () {
const str =
'classDiagram\n' +
'class Car~T~\n' +
'Car : -List~Wheel~ wheels\n' +
'Car : +setWheels(List~Wheel~ wheels)\n' +
'Car : +getWheels() List~Wheel~';
parser.parse(str);
});
it('should handle generic types in members in class with brackets', function () {
const str =
'classDiagram\n' +
'class Car {\n' +
'List~Wheel~ wheels\n' +
'setWheels(List~Wheel~ wheels)\n' +
'+getWheels() List~Wheel~\n' +
'}';
parser.parse(str);
});
});
describe('when fetching data from an classDiagram graph it', function() {
beforeEach(function() {
describe('when fetching data from a classDiagram graph it', function () {
beforeEach(function () {
parser.yy = classDb;
parser.yy.clear();
});
it('should handle relation definitions EXTENSION', function() {
it('should handle relation definitions EXTENSION', function () {
const str = 'classDiagram\n' + 'Class01 <|-- Class02';
parser.parse(str);
@@ -129,7 +436,8 @@ describe('class diagram, ', function() {
expect(relations[0].relation.type2).toBe('none');
expect(relations[0].relation.lineType).toBe(classDb.lineType.LINE);
});
it('should handle relation definitions AGGREGATION and dotted line', function() {
it('should handle relation definitions AGGREGATION and dotted line', function () {
const str = 'classDiagram\n' + 'Class01 o.. Class02';
parser.parse(str);
@@ -142,7 +450,8 @@ describe('class diagram, ', function() {
expect(relations[0].relation.type2).toBe('none');
expect(relations[0].relation.lineType).toBe(classDb.lineType.DOTTED_LINE);
});
it('should handle relation definitions COMPOSITION on both sides', function() {
it('should handle relation definitions COMPOSITION on both sides', function () {
const str = 'classDiagram\n' + 'Class01 *--* Class02';
parser.parse(str);
@@ -155,7 +464,8 @@ describe('class diagram, ', function() {
expect(relations[0].relation.type2).toBe(classDb.relationType.COMPOSITION);
expect(relations[0].relation.lineType).toBe(classDb.lineType.LINE);
});
it('should handle relation definitions no types', function() {
it('should handle relation definitions no types', function () {
const str = 'classDiagram\n' + 'Class01 -- Class02';
parser.parse(str);
@@ -168,7 +478,8 @@ describe('class diagram, ', function() {
expect(relations[0].relation.type2).toBe('none');
expect(relations[0].relation.lineType).toBe(classDb.lineType.LINE);
});
it('should handle relation definitions with type only on right side', function() {
it('should handle relation definitions with type only on right side', function () {
const str = 'classDiagram\n' + 'Class01 --|> Class02';
parser.parse(str);
@@ -182,7 +493,7 @@ describe('class diagram, ', function() {
expect(relations[0].relation.lineType).toBe(classDb.lineType.LINE);
});
it('should handle multiple classes and relation definitions', function() {
it('should handle multiple classes and relation definitions', function () {
const str =
'classDiagram\n' +
'Class01 <|-- Class02\n' +
@@ -208,7 +519,22 @@ describe('class diagram, ', function() {
expect(relations[3].relation.lineType).toBe(classDb.lineType.DOTTED_LINE);
});
it('should handle class annotations', function() {
it('should handle generic class with relation definitions', function () {
const str = 'classDiagram\n' + 'Class01~T~ <|-- Class02';
parser.parse(str);
const relations = parser.yy.getRelations();
expect(parser.yy.getClass('Class01').id).toBe('Class01');
expect(parser.yy.getClass('Class01').type).toBe('T');
expect(parser.yy.getClass('Class02').id).toBe('Class02');
expect(relations[0].relation.type1).toBe(classDb.relationType.EXTENSION);
expect(relations[0].relation.type2).toBe('none');
expect(relations[0].relation.lineType).toBe(classDb.lineType.LINE);
});
it('should handle class annotations', function () {
const str = 'classDiagram\n' + 'class Class1\n' + '<<interface>> Class1';
parser.parse(str);
@@ -219,7 +545,7 @@ describe('class diagram, ', function() {
expect(testClass.annotations[0]).toBe('interface');
});
it('should handle class annotations with members and methods', function() {
it('should handle class annotations with members and methods', function () {
const str =
'classDiagram\n' +
'class Class1\n' +
@@ -235,7 +561,7 @@ describe('class diagram, ', function() {
expect(testClass.annotations[0]).toBe('interface');
});
it('should handle class annotations in brackets', function() {
it('should handle class annotations in brackets', function () {
const str = 'classDiagram\n' + 'class Class1 {\n' + '<<interface>>\n' + '}';
parser.parse(str);
@@ -246,7 +572,7 @@ describe('class diagram, ', function() {
expect(testClass.annotations[0]).toBe('interface');
});
it('should handle class annotations in brackets with members and methods', function() {
it('should handle class annotations in brackets with members and methods', function () {
const str =
'classDiagram\n' +
'class Class1 {\n' +
@@ -263,7 +589,7 @@ describe('class diagram, ', function() {
expect(testClass.annotations[0]).toBe('interface');
});
it('should add bracket members in right order', function() {
it('should add bracket members in right order', function () {
const str =
'classDiagram\n' +
'class Class1 {\n' +
@@ -282,5 +608,64 @@ describe('class diagram, ', function() {
expect(testClass.methods[0]).toBe('test()');
expect(testClass.methods[1]).toBe('foo()');
});
it('should handle abstract methods', function () {
const str = 'classDiagram\n' + 'class Class1\n' + 'Class1 : someMethod()*';
parser.parse(str);
const testClass = parser.yy.getClass('Class1');
expect(testClass.annotations.length).toBe(0);
expect(testClass.members.length).toBe(0);
expect(testClass.methods.length).toBe(1);
expect(testClass.methods[0]).toBe('someMethod()*');
});
it('should handle static methods', function () {
const str = 'classDiagram\n' + 'class Class1\n' + 'Class1 : someMethod()$';
parser.parse(str);
const testClass = parser.yy.getClass('Class1');
expect(testClass.annotations.length).toBe(0);
expect(testClass.members.length).toBe(0);
expect(testClass.methods.length).toBe(1);
expect(testClass.methods[0]).toBe('someMethod()$');
});
it('should associate link and css appropriately', function () {
const str = 'classDiagram\n' + 'class Class1\n' + 'Class1 : someMethod()\n' + 'link Class1 "google.com"';
parser.parse(str);
const testClass = parser.yy.getClass('Class1');
expect(testClass.link).toBe('about:blank');//('google.com'); security needs to be set to 'loose' for this to work right
expect(testClass.cssClasses.length).toBe(1);
expect(testClass.cssClasses[0]).toBe('clickable');
});
it('should associate link with tooltip', function () {
const str = 'classDiagram\n' + 'class Class1\n' + 'Class1 : someMethod()\n' + 'link Class1 "google.com" "A tooltip"';
parser.parse(str);
const testClass = parser.yy.getClass('Class1');
expect(testClass.link).toBe('about:blank');//('google.com'); security needs to be set to 'loose' for this to work right
expect(testClass.tooltip).toBe('A tooltip');
expect(testClass.cssClasses.length).toBe(1);
expect(testClass.cssClasses[0]).toBe('clickable');
});
it('should associate callback appropriately', function () {
spyOn(classDb, 'setClickEvent');
const str = 'classDiagram\n' + 'class Class1\n' + 'Class1 : someMethod()\n' + 'callback Class1 "functionCall"';
parser.parse(str);
expect(classDb.setClickEvent).toHaveBeenCalledWith('Class1', 'functionCall', undefined);
});
it('should associate callback with tooltip', function () {
spyOn(classDb, 'setClickEvent');
const str = 'classDiagram\n' + 'class Class1\n' + 'Class1 : someMethod()\n' + 'callback Class1 "functionCall" "A tooltip"';
parser.parse(str);
expect(classDb.setClickEvent).toHaveBeenCalledWith('Class1', 'functionCall', 'A tooltip');
});
});
});

View File

@@ -1,16 +1,16 @@
import * as d3 from 'd3';
import { select } from 'd3';
import dagre from 'dagre';
import graphlib from 'graphlib';
import { logger } from '../../logger';
import classDb from './classDb';
import utils from '../../utils';
import classDb, { lookUpDomId } from './classDb';
import { parser } from './parser/classDiagram';
import svgDraw from './svgDraw';
parser.yy = classDb;
const idCache = {};
let idCache = {};
const padding = 20;
let classCnt = 0;
const conf = {
dividerMargin: 10,
padding: 5,
@@ -135,269 +135,6 @@ const insertMarkers = function(elem) {
.attr('d', 'M 18,7 L9,13 L14,7 L9,1 Z');
};
let edgeCount = 0;
let total = 0;
const drawEdge = function(elem, path, relation) {
const getRelationType = function(type) {
switch (type) {
case classDb.relationType.AGGREGATION:
return 'aggregation';
case classDb.relationType.EXTENSION:
return 'extension';
case classDb.relationType.COMPOSITION:
return 'composition';
case classDb.relationType.DEPENDENCY:
return 'dependency';
}
};
path.points = path.points.filter(p => !Number.isNaN(p.y));
// The data for our line
const lineData = path.points;
// This is the accessor function we talked about above
const lineFunction = d3
.line()
.x(function(d) {
return d.x;
})
.y(function(d) {
return d.y;
})
.curve(d3.curveBasis);
const svgPath = elem
.append('path')
.attr('d', lineFunction(lineData))
.attr('id', 'edge' + edgeCount)
.attr('class', 'relation');
let url = '';
if (conf.arrowMarkerAbsolute) {
url =
window.location.protocol +
'//' +
window.location.host +
window.location.pathname +
window.location.search;
url = url.replace(/\(/g, '\\(');
url = url.replace(/\)/g, '\\)');
}
if (relation.relation.type1 !== 'none') {
svgPath.attr(
'marker-start',
'url(' + url + '#' + getRelationType(relation.relation.type1) + 'Start' + ')'
);
}
if (relation.relation.type2 !== 'none') {
svgPath.attr(
'marker-end',
'url(' + url + '#' + getRelationType(relation.relation.type2) + 'End' + ')'
);
}
let x, y;
const l = path.points.length;
// Calculate Label position
let labalPosition = utils.calcLabelPosition(path.points);
x = labalPosition.x;
y = labalPosition.y;
let p1_card_x, p1_card_y;
// p1_card_padd_x = conf.padding * 2,
// p1_card_padd_y = conf.padding;
let p2_card_x, p2_card_y;
// p2_card_padd_x = conf.padding * 2,
// p2_card_padd_y = -conf.padding / 2;
if (l % 2 !== 0 && l > 1) {
let cardinality_1_point = utils.calcCardinalityPosition(
relation.relation.type1 !== 'none',
path.points,
path.points[0]
);
let cardinality_2_point = utils.calcCardinalityPosition(
relation.relation.type2 !== 'none',
path.points,
path.points[l - 1]
);
logger.debug('cardinality_1_point ' + JSON.stringify(cardinality_1_point));
logger.debug('cardinality_2_point ' + JSON.stringify(cardinality_2_point));
p1_card_x = cardinality_1_point.x;
p1_card_y = cardinality_1_point.y;
p2_card_x = cardinality_2_point.x;
p2_card_y = cardinality_2_point.y;
}
if (typeof relation.title !== 'undefined') {
const g = elem.append('g').attr('class', 'classLabel');
const label = g
.append('text')
.attr('class', 'label')
.attr('x', x)
.attr('y', y)
.attr('fill', 'red')
.attr('text-anchor', 'middle')
.text(relation.title);
window.label = label;
const bounds = label.node().getBBox();
g.insert('rect', ':first-child')
.attr('class', 'box')
.attr('x', bounds.x - conf.padding / 2)
.attr('y', bounds.y - conf.padding / 2)
.attr('width', bounds.width + conf.padding)
.attr('height', bounds.height + conf.padding);
}
logger.info('Rendering relation ' + JSON.stringify(relation));
if (typeof relation.relationTitle1 !== 'undefined' && relation.relationTitle1 !== 'none') {
const g = elem.append('g').attr('class', 'cardinality');
g.append('text')
.attr('class', 'type1')
.attr('x', p1_card_x)
.attr('y', p1_card_y)
.attr('fill', 'black')
.attr('font-size', '6')
.text(relation.relationTitle1);
}
if (typeof relation.relationTitle2 !== 'undefined' && relation.relationTitle2 !== 'none') {
const g = elem.append('g').attr('class', 'cardinality');
g.append('text')
.attr('class', 'type2')
.attr('x', p2_card_x)
.attr('y', p2_card_y)
.attr('fill', 'black')
.attr('font-size', '6')
.text(relation.relationTitle2);
}
edgeCount++;
};
const drawClass = function(elem, classDef) {
logger.info('Rendering class ' + classDef);
const addTspan = function(textEl, txt, isFirst) {
const tSpan = textEl
.append('tspan')
.attr('x', conf.padding)
.text(txt);
if (!isFirst) {
tSpan.attr('dy', conf.textHeight);
}
};
const id = 'classId' + (classCnt % total);
const classInfo = {
id: id,
label: classDef.id,
width: 0,
height: 0
};
// add class group
const g = elem
.append('g')
.attr('id', id)
.attr('class', 'classGroup');
// add title
const title = g
.append('text')
.attr('y', conf.textHeight + conf.padding)
.attr('x', 0);
// add annotations
let isFirst = true;
classDef.annotations.forEach(function(member) {
const titleText2 = title.append('tspan').text('«' + member + '»');
if (!isFirst) titleText2.attr('dy', conf.textHeight);
isFirst = false;
});
// add class title
const classTitle = title
.append('tspan')
.text(classDef.id)
.attr('class', 'title');
// If class has annotations the title needs to have an offset of the text height
if (!isFirst) classTitle.attr('dy', conf.textHeight);
const titleHeight = title.node().getBBox().height;
const membersLine = g
.append('line') // text label for the x axis
.attr('x1', 0)
.attr('y1', conf.padding + titleHeight + conf.dividerMargin / 2)
.attr('y2', conf.padding + titleHeight + conf.dividerMargin / 2);
const members = g
.append('text') // text label for the x axis
.attr('x', conf.padding)
.attr('y', titleHeight + conf.dividerMargin + conf.textHeight)
.attr('fill', 'white')
.attr('class', 'classText');
isFirst = true;
classDef.members.forEach(function(member) {
addTspan(members, member, isFirst);
isFirst = false;
});
const membersBox = members.node().getBBox();
const methodsLine = g
.append('line') // text label for the x axis
.attr('x1', 0)
.attr('y1', conf.padding + titleHeight + conf.dividerMargin + membersBox.height)
.attr('y2', conf.padding + titleHeight + conf.dividerMargin + membersBox.height);
const methods = g
.append('text') // text label for the x axis
.attr('x', conf.padding)
.attr('y', titleHeight + 2 * conf.dividerMargin + membersBox.height + conf.textHeight)
.attr('fill', 'white')
.attr('class', 'classText');
isFirst = true;
classDef.methods.forEach(function(method) {
addTspan(methods, method, isFirst);
isFirst = false;
});
const classBox = g.node().getBBox();
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);
const rectWidth = rect.node().getBBox().width;
// Center title
// We subtract the width of each text element from the class box width and divide it by 2
title.node().childNodes.forEach(function(x) {
x.setAttribute('x', (rectWidth - x.getBBox().width) / 2);
});
membersLine.attr('x2', rectWidth);
methodsLine.attr('x2', rectWidth);
classInfo.width = rectWidth;
classInfo.height = classBox.height + conf.padding + 0.5 * conf.dividerMargin;
idCache[id] = classInfo;
classCnt++;
return classInfo;
};
export const setConf = function(cnf) {
const keys = Object.keys(cnf);
@@ -405,19 +142,21 @@ export const setConf = function(cnf) {
conf[key] = cnf[key];
});
};
/**
* Draws a flowchart in the tag with id: id based on the graph definition in text.
* @param text
* @param id
*/
export const draw = function(text, id) {
idCache = {};
parser.yy.clear();
parser.parse(text);
logger.info('Rendering diagram ' + text);
/// / Fetch the default direction, use TD if none was found
const diagram = d3.select(`[id='${id}']`);
// Fetch the default direction, use TD if none was found
const diagram = select(`[id='${id}']`);
insertMarkers(diagram);
// Layout graph, Create a new directed graph
@@ -437,14 +176,16 @@ export const draw = function(text, id) {
const classes = classDb.getClasses();
const keys = Object.keys(classes);
total = keys.length;
for (let i = 0; i < keys.length; i++) {
const classDef = classes[keys[i]];
const node = drawClass(diagram, classDef);
const node = svgDraw.drawClass(diagram, classDef, conf);
idCache[node.id] = node;
// Add nodes to the graph. The first argument is the node id. The second is
// metadata about the node. In this case we're going to add labels to each of
// our nodes.
g.setNode(node.id, node);
logger.info('Org height: ' + node.height);
}
@@ -453,15 +194,21 @@ export const draw = function(text, id) {
logger.info(
'tjoho' + getGraphId(relation.id1) + getGraphId(relation.id2) + JSON.stringify(relation)
);
g.setEdge(getGraphId(relation.id1), getGraphId(relation.id2), {
relation: relation
});
g.setEdge(
getGraphId(relation.id1),
getGraphId(relation.id2),
{
relation: relation
},
relation.title || 'DEFAULT'
);
});
dagre.layout(g);
g.nodes().forEach(function(v) {
if (typeof v !== 'undefined' && typeof g.node(v) !== 'undefined') {
logger.debug('Node ' + v + ': ' + JSON.stringify(g.node(v)));
d3.select('#' + v).attr(
select('#' + lookUpDomId(v)).attr(
'transform',
'translate(' +
(g.node(v).x - g.node(v).width / 2) +
@@ -471,16 +218,30 @@ export const draw = function(text, id) {
);
}
});
g.edges().forEach(function(e) {
if (typeof e !== 'undefined' && typeof g.edge(e) !== 'undefined') {
logger.debug('Edge ' + e.v + ' -> ' + e.w + ': ' + JSON.stringify(g.edge(e)));
drawEdge(diagram, g.edge(e), g.edge(e).relation);
svgDraw.drawEdge(diagram, g.edge(e), g.edge(e).relation, conf);
}
});
diagram.attr('height', '100%');
diagram.attr('width', `${g.graph().width * 1.5 + 20}`);
diagram.attr('viewBox', '-10 -10 ' + (g.graph().width + 20) + ' ' + (g.graph().height + 20));
const svgBounds = diagram.node().getBBox();
const width = svgBounds.width + padding * 2;
const height = svgBounds.height + padding * 2;
if (conf.useMaxWidth) {
diagram.attr('width', '100%');
diagram.attr('style', `max-width: ${width}px;`);
} else {
diagram.attr('height', height);
diagram.attr('width', width);
}
// Ensure the viewBox includes the whole svgBounds area with extra space for padding
const vBox = `${svgBounds.x - padding} ${svgBounds.y - padding} ${width} ${height}`;
logger.debug(`viewBox ${vBox}`);
diagram.attr('viewBox', vBox);
};
export default {

View File

@@ -6,14 +6,16 @@
/* lexical grammar */
%lex
%x string struct
%x string generic struct
%%
\%\%[^\n]* /* do nothing */
\%\%[^\n]*\n* /* do nothing */
\n+ return 'NEWLINE';
\s+ /* skip whitespace */
"classDiagram" return 'CLASS_DIAGRAM';
[\{] { this.begin("struct"); /*console.log('Starting struct');*/return 'STRUCT_START';}
<struct><<EOF>> return "EOF_IN_STRUCT";
<struct>[\{] return "OPEN_IN_STRUCT";
<struct>\} { /*console.log('Ending struct');*/this.popState(); return 'STRUCT_STOP';}}
<struct>[\n] /* nothing */
<struct>[^\{\}\n]* { /*console.log('lex-member: ' + yytext);*/ return "MEMBER";}
@@ -21,8 +23,14 @@
"class" return 'CLASS';
//"click" return 'CLICK';
"callback" return 'CALLBACK';
"link" return 'LINK';
"<<" return 'ANNOTATION_START';
">>" return 'ANNOTATION_END';
[~] this.begin("generic");
<generic>[~] this.popState();
<generic>[^~]* return "GENERICTYPE";
["] this.begin("string");
<string>["] this.popState();
<string>[^"]* return "STR";
@@ -36,7 +44,7 @@
\s*o return 'AGGREGATION';
\-\- return 'LINE';
\.\. return 'DOTTED_LINE';
":"[^#\n;]+ return 'LABEL';
":"[^\n;]+ return 'LABEL';
\- return 'MINUS';
"." return 'DOT';
\+ return 'PLUS';
@@ -136,6 +144,8 @@ statements
className
: alphaNumToken className { $$=$1+$2; }
| alphaNumToken { $$=$1; }
| alphaNumToken GENERICTYPE className { $$=$1+'~'+$2+$3; }
| alphaNumToken GENERICTYPE { $$=$1+'~'+$2; }
;
statement
@@ -144,6 +154,7 @@ statement
| classStatement
| methodStatement
| annotationStatement
| clickStatement
;
classStatement
@@ -193,6 +204,13 @@ lineType
| DOTTED_LINE {$$=yy.lineType.DOTTED_LINE;}
;
clickStatement
: CALLBACK className STR {$$ = $1;yy.setClickEvent($2, $3, undefined);}
| CALLBACK className STR STR {$$ = $1;yy.setClickEvent($2, $3, $4);}
| LINK className STR {$$ = $1;yy.setLink($2, $3, undefined);}
| LINK className STR STR {$$ = $1;yy.setLink($2, $3, $4);}
;
commentToken : textToken | graphCodeTokens ;
textToken : textNoTagsToken | TAGSTART | TAGEND | '==' | '--' | PCT | DEFAULT;

View File

@@ -0,0 +1,412 @@
import { line, curveBasis } from 'd3';
import { lookUpDomId, relationType } from './classDb';
import utils from '../../utils';
import { logger } from '../../logger';
let edgeCount = 0;
export const drawEdge = function(elem, path, relation, conf) {
const getRelationType = function(type) {
switch (type) {
case relationType.AGGREGATION:
return 'aggregation';
case relationType.EXTENSION:
return 'extension';
case relationType.COMPOSITION:
return 'composition';
case relationType.DEPENDENCY:
return 'dependency';
}
};
path.points = path.points.filter(p => !Number.isNaN(p.y));
// The data for our line
const lineData = path.points;
// This is the accessor function we talked about above
const lineFunction = line()
.x(function(d) {
return d.x;
})
.y(function(d) {
return d.y;
})
.curve(curveBasis);
const svgPath = elem
.append('path')
.attr('d', lineFunction(lineData))
.attr('id', 'edge' + edgeCount)
.attr('class', 'relation');
let url = '';
if (conf.arrowMarkerAbsolute) {
url =
window.location.protocol +
'//' +
window.location.host +
window.location.pathname +
window.location.search;
url = url.replace(/\(/g, '\\(');
url = url.replace(/\)/g, '\\)');
}
if (relation.relation.lineType == 1) {
svgPath.attr('class', 'relation dashed-line');
}
if (relation.relation.type1 !== 'none') {
svgPath.attr(
'marker-start',
'url(' + url + '#' + getRelationType(relation.relation.type1) + 'Start' + ')'
);
}
if (relation.relation.type2 !== 'none') {
svgPath.attr(
'marker-end',
'url(' + url + '#' + getRelationType(relation.relation.type2) + 'End' + ')'
);
}
let x, y;
const l = path.points.length;
// Calculate Label position
let labelPosition = utils.calcLabelPosition(path.points);
x = labelPosition.x;
y = labelPosition.y;
let p1_card_x, p1_card_y;
let p2_card_x, p2_card_y;
if (l % 2 !== 0 && l > 1) {
let cardinality_1_point = utils.calcCardinalityPosition(
relation.relation.type1 !== 'none',
path.points,
path.points[0]
);
let cardinality_2_point = utils.calcCardinalityPosition(
relation.relation.type2 !== 'none',
path.points,
path.points[l - 1]
);
logger.debug('cardinality_1_point ' + JSON.stringify(cardinality_1_point));
logger.debug('cardinality_2_point ' + JSON.stringify(cardinality_2_point));
p1_card_x = cardinality_1_point.x;
p1_card_y = cardinality_1_point.y;
p2_card_x = cardinality_2_point.x;
p2_card_y = cardinality_2_point.y;
}
if (typeof relation.title !== 'undefined') {
const g = elem.append('g').attr('class', 'classLabel');
const label = g
.append('text')
.attr('class', 'label')
.attr('x', x)
.attr('y', y)
.attr('fill', 'red')
.attr('text-anchor', 'middle')
.text(relation.title);
window.label = label;
const bounds = label.node().getBBox();
g.insert('rect', ':first-child')
.attr('class', 'box')
.attr('x', bounds.x - conf.padding / 2)
.attr('y', bounds.y - conf.padding / 2)
.attr('width', bounds.width + conf.padding)
.attr('height', bounds.height + conf.padding);
}
logger.info('Rendering relation ' + JSON.stringify(relation));
if (typeof relation.relationTitle1 !== 'undefined' && relation.relationTitle1 !== 'none') {
const g = elem.append('g').attr('class', 'cardinality');
g.append('text')
.attr('class', 'type1')
.attr('x', p1_card_x)
.attr('y', p1_card_y)
.attr('fill', 'black')
.attr('font-size', '6')
.text(relation.relationTitle1);
}
if (typeof relation.relationTitle2 !== 'undefined' && relation.relationTitle2 !== 'none') {
const g = elem.append('g').attr('class', 'cardinality');
g.append('text')
.attr('class', 'type2')
.attr('x', p2_card_x)
.attr('y', p2_card_y)
.attr('fill', 'black')
.attr('font-size', '6')
.text(relation.relationTitle2);
}
edgeCount++;
};
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,
label: classDef.id,
width: 0,
height: 0
};
// add class group
const g = elem
.append('g')
.attr('id', lookUpDomId(id))
.attr('class', cssClassStr);
// add title
let title;
if (classDef.link) {
title = g
.append('svg:a')
.attr('xlink:href', classDef.link)
.attr('target', '_blank')
.append('text')
.attr('y', conf.textHeight + conf.padding)
.attr('x', 0);
} else {
title = g
.append('text')
.attr('y', conf.textHeight + conf.padding)
.attr('x', 0);
}
// add annotations
let isFirst = true;
classDef.annotations.forEach(function(member) {
const titleText2 = title.append('tspan').text('«' + member + '»');
if (!isFirst) titleText2.attr('dy', conf.textHeight);
isFirst = false;
});
let classTitleString = classDef.id;
if (classDef.type !== undefined && classDef.type !== '') {
classTitleString += '<' + classDef.type + '>';
}
const classTitle = title
.append('tspan')
.text(classTitleString)
.attr('class', 'title');
// If class has annotations the title needs to have an offset of the text height
if (!isFirst) classTitle.attr('dy', conf.textHeight);
const titleHeight = title.node().getBBox().height;
const membersLine = g
.append('line') // text label for the x axis
.attr('x1', 0)
.attr('y1', conf.padding + titleHeight + conf.dividerMargin / 2)
.attr('y2', conf.padding + titleHeight + conf.dividerMargin / 2);
const members = g
.append('text') // text label for the x axis
.attr('x', conf.padding)
.attr('y', titleHeight + conf.dividerMargin + conf.textHeight)
.attr('fill', 'white')
.attr('class', 'classText');
isFirst = true;
classDef.members.forEach(function(member) {
addTspan(members, member, isFirst, conf);
isFirst = false;
});
const membersBox = members.node().getBBox();
const methodsLine = g
.append('line') // text label for the x axis
.attr('x1', 0)
.attr('y1', conf.padding + titleHeight + conf.dividerMargin + membersBox.height)
.attr('y2', conf.padding + titleHeight + conf.dividerMargin + membersBox.height);
const methods = g
.append('text') // text label for the x axis
.attr('x', conf.padding)
.attr('y', titleHeight + 2 * conf.dividerMargin + membersBox.height + conf.textHeight)
.attr('fill', 'white')
.attr('class', 'classText');
isFirst = true;
classDef.methods.forEach(function(method) {
addTspan(methods, method, isFirst, conf);
isFirst = false;
});
const classBox = g.node().getBBox();
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);
const rectWidth = rect.node().getBBox().width;
// Center title
// We subtract the width of each text element from the class box width and divide it by 2
title.node().childNodes.forEach(function(x) {
x.setAttribute('x', (rectWidth - x.getBBox().width) / 2);
});
if (classDef.tooltip) {
title.insert('title').text(classDef.tooltip);
}
membersLine.attr('x2', rectWidth);
methodsLine.attr('x2', rectWidth);
classInfo.width = rectWidth;
classInfo.height = classBox.height + conf.padding + 0.5 * conf.dividerMargin;
return classInfo;
};
export const parseMember = function(text) {
const fieldRegEx = /^(\+|-|~|#)?(\w+)(~\w+~|\[\])?\s+(\w+)$/;
const methodRegEx = /^(\+|-|~|#)?(\w+)\s?\(\s*(\w+(~\w+~|\[\])?\s*(\w+)?)?\s*\)\s?([*|$])?\s?(\w+(~\w+~|\[\])?)?\s*$/;
let fieldMatch = text.match(fieldRegEx);
let methodMatch = text.match(methodRegEx);
if (fieldMatch) {
return buildFieldDisplay(fieldMatch);
} else if (methodMatch) {
return buildMethodDisplay(methodMatch);
} else {
return buildLegacyDisplay(text);
}
};
const buildFieldDisplay = function(parsedText) {
let visibility = parsedText[1] ? parsedText[1].trim() : '';
let fieldType = parsedText[2] ? parsedText[2].trim() : '';
let genericType = parsedText[3] ? parseGenericTypes(parsedText[3]) : '';
let fieldName = parsedText[4] ? parsedText[4].trim() : '';
return {
displayText: visibility + fieldType + genericType + ' ' + fieldName,
cssStyle: ''
};
};
const buildMethodDisplay = function(parsedText) {
let cssStyle = '';
let displayText = parsedText;
let visibility = parsedText[1] ? parsedText[1].trim() : '';
let methodName = parsedText[2] ? parsedText[2].trim() : '';
let parameters = parsedText[3] ? parseGenericTypes(parsedText[3]) : '';
let classifier = parsedText[6] ? parsedText[6].trim() : '';
let returnType = parsedText[7] ? ' : ' + parseGenericTypes(parsedText[7]).trim() : '';
displayText = visibility + methodName + '(' + parameters + ')' + returnType;
cssStyle = parseClassifier(classifier);
let member = {
displayText: displayText,
cssStyle: cssStyle
};
return member;
};
const buildLegacyDisplay = function(text) {
// if for some reason we dont have any match, use old format to parse text
let memberText = '';
let cssStyle = '';
let returnType = '';
let methodStart = text.indexOf('(');
let methodEnd = text.indexOf(')');
if (methodStart > 1 && methodEnd > methodStart && methodEnd <= text.length) {
let parsedText = text.match(/(\+|-|~|#)?(\w+)/);
let visibility = parsedText[1] ? parsedText[1].trim() : '';
let methodName = parsedText[2];
let parameters = text.substring(methodStart + 1, methodEnd);
let classifier = text.substring(methodEnd, methodEnd + 1);
cssStyle = parseClassifier(classifier);
memberText = visibility + methodName + '(' + parseGenericTypes(parameters.trim()) + ')';
if (methodEnd < memberText.length) {
returnType = text.substring(methodEnd + 2).trim();
if (returnType !== '') {
returnType = ' : ' + parseGenericTypes(returnType);
}
}
} else {
// finally - if all else fails, just send the text back as written (other than parsing for generic types)
memberText = parseGenericTypes(text);
}
let member = {
displayText: memberText + returnType,
cssStyle: cssStyle
};
return member;
};
const addTspan = function(textEl, txt, isFirst, conf) {
let member = parseMember(txt);
const tSpan = textEl
.append('tspan')
.attr('x', conf.padding)
.text(member.displayText);
if (member.cssStyle !== '') {
tSpan.attr('style', member.cssStyle);
}
if (!isFirst) {
tSpan.attr('dy', conf.textHeight);
}
};
const parseGenericTypes = function(text) {
let cleanedText = text;
if (text.indexOf('~') != -1) {
cleanedText = cleanedText.replace('~', '<');
cleanedText = cleanedText.replace('~', '>');
return parseGenericTypes(cleanedText);
} else {
return cleanedText;
}
};
const parseClassifier = function(classifier) {
switch (classifier) {
case '*':
return 'font-style:italic;';
case '$':
return 'text-decoration:underline;';
default:
return '';
}
};
export default {
drawClass,
drawEdge,
parseMember
};

View File

@@ -0,0 +1,152 @@
/* eslint-env jasmine */
import svgDraw from './svgDraw';
describe('class member Renderer, ', function () {
describe('when parsing text to build method display string', function () {
it('should handle simple method declaration', function () {
const str = 'foo()';
let actual = svgDraw.parseMember(str);
expect(actual.displayText).toBe('foo()');
expect(actual.cssStyle).toBe('');
});
it('should handle public visibility', function () {
const str = '+foo()';
let actual = svgDraw.parseMember(str);
expect(actual.displayText).toBe('+foo()');
expect(actual.cssStyle).toBe('');
});
it('should handle private visibility', function () {
const str = '-foo()';
let actual = svgDraw.parseMember(str);
expect(actual.displayText).toBe('-foo()');
expect(actual.cssStyle).toBe('');
});
it('should handle protected visibility', function () {
const str = '#foo()';
let actual = svgDraw.parseMember(str);
expect(actual.displayText).toBe('#foo()');
expect(actual.cssStyle).toBe('');
});
it('should handle package/internal visibility', function () {
const str = '~foo()';
let actual = svgDraw.parseMember(str);
expect(actual.displayText).toBe('~foo()');
expect(actual.cssStyle).toBe('');
});
it('should ignore unknown character for visibility', function () {
const str = '!foo()';
let actual = svgDraw.parseMember(str);
expect(actual.displayText).toBe('foo()');
expect(actual.cssStyle).toBe('');
});
it('should handle abstract classifier', function () {
const str = 'foo()*';
let actual = svgDraw.parseMember(str);
expect(actual.displayText).toBe('foo()');
expect(actual.cssStyle).toBe('font-style:italic;');
});
it('should handle static classifier', function () {
const str = 'foo()$';
let actual = svgDraw.parseMember(str);
expect(actual.displayText).toBe('foo()');
expect(actual.cssStyle).toBe('text-decoration:underline;');
});
it('should ignore unknown character for classifier', function () {
const str = 'foo()!';
let actual = svgDraw.parseMember(str);
expect(actual.displayText).toBe('foo()');
expect(actual.cssStyle).toBe('');
});
it('should handle simple method declaration with parameters', function () {
const str = 'foo(int id)';
let actual = svgDraw.parseMember(str);
expect(actual.displayText).toBe('foo(int id)');
expect(actual.cssStyle).toBe('');
});
it('should handle simple method declaration with single item in parameters', function () {
const str = 'foo(id)';
let actual = svgDraw.parseMember(str);
expect(actual.displayText).toBe('foo(id)');
expect(actual.cssStyle).toBe('');
});
it('should handle simple method declaration with single item in parameters with extra spaces', function () {
const str = ' foo ( id) ';
let actual = svgDraw.parseMember(str);
expect(actual.displayText).toBe('foo(id)');
expect(actual.cssStyle).toBe('');
});
it('should handle method declaration with return value', function () {
const str = 'foo(id) int';
let actual = svgDraw.parseMember(str);
expect(actual.displayText).toBe('foo(id) : int');
expect(actual.cssStyle).toBe('');
});
it('should handle method declaration with generic return value', function () {
const str = 'foo(id) List~int~';
let actual = svgDraw.parseMember(str);
expect(actual.displayText).toBe('foo(id) : List<int>');
expect(actual.cssStyle).toBe('');
});
it('should handle method declaration with generic parameter', function () {
const str = 'foo(List~int~)';
let actual = svgDraw.parseMember(str);
expect(actual.displayText).toBe('foo(List<int>)');
expect(actual.cssStyle).toBe('');
});
it('should handle method declaration with all possible markup', function () {
const str = '+foo ( List~int~ ids )* List~Item~';
let actual = svgDraw.parseMember(str);
expect(actual.displayText).toBe('+foo(List<int> ids) : List<Item>');
expect(actual.cssStyle).toBe('font-style:italic;');
});
});
describe('when parsing text to build field display string', function () {
it('should handle simple field declaration', function () {
const str = 'int[] ids';
let actual = svgDraw.parseMember(str);
expect(actual.displayText).toBe('int[] ids');
expect(actual.cssStyle).toBe('');
});
it('should handle field declaration with generic type', function () {
const str = 'List~int~ ids';
let actual = svgDraw.parseMember(str);
expect(actual.displayText).toBe('List<int> ids');
expect(actual.cssStyle).toBe('');
});
});
});

View File

@@ -0,0 +1,42 @@
export const getRows = s => {
if (!s) return 1;
let str = breakToPlaceholder(s);
str = str.replace(/\\n/g, '#br#');
return str.split('#br#');
};
export const sanitizeText = (text, config) => {
let txt = text;
let htmlLabels = true;
if (
config.flowchart &&
(config.flowchart.htmlLabels === false || config.flowchart.htmlLabels === 'false')
)
htmlLabels = false;
if (config.securityLevel !== 'loose' && htmlLabels) {
// eslint-disable-line
txt = breakToPlaceholder(txt);
txt = txt.replace(/</g, '&lt;').replace(/>/g, '&gt;');
txt = txt.replace(/=/g, '&equals;');
txt = placeholderToBreak(txt);
}
return txt;
};
export const lineBreakRegex = /<br\s*\/?>/gi;
const breakToPlaceholder = s => {
return s.replace(lineBreakRegex, '#br#');
};
const placeholderToBreak = s => {
return s.replace(/#br#/g, '<br/>');
};
export default {
getRows,
sanitizeText,
lineBreakRegex
};

77
src/diagrams/er/erDb.js Normal file
View File

@@ -0,0 +1,77 @@
/**
*
*/
import { logger } from '../../logger';
let entities = {};
let relationships = [];
let title = '';
const Cardinality = {
ZERO_OR_ONE: 'ZERO_OR_ONE',
ZERO_OR_MORE: 'ZERO_OR_MORE',
ONE_OR_MORE: 'ONE_OR_MORE',
ONLY_ONE: 'ONLY_ONE'
};
const Identification = {
NON_IDENTIFYING: 'NON_IDENTIFYING',
IDENTIFYING: 'IDENTIFYING'
};
const addEntity = function(name) {
if (typeof entities[name] === 'undefined') {
entities[name] = name;
logger.debug('Added new entity :', name);
}
};
const getEntities = () => entities;
/**
* Add a relationship
* @param entA The first entity in the relationship
* @param rolA The role played by the first entity in relation to the second
* @param entB The second entity in the relationship
* @param rSpec The details of the relationship between the two entities
*/
const addRelationship = function(entA, rolA, entB, rSpec) {
let rel = {
entityA: entA,
roleA: rolA,
entityB: entB,
relSpec: rSpec
};
relationships.push(rel);
logger.debug('Added new relationship :', rel);
};
const getRelationships = () => relationships;
// Keep this - TODO: revisit...allow the diagram to have a title
const setTitle = function(txt) {
title = txt;
};
const getTitle = function() {
return title;
};
const clear = function() {
entities = {};
relationships = [];
title = '';
};
export default {
Cardinality,
Identification,
addEntity,
getEntities,
addRelationship,
getRelationships,
clear,
setTitle,
getTitle
};

Some files were not shown because too many files have changed in this diff Show More