Skip to content

Commit 130ca46

Browse files
authored
Merge pull request #138 from antmendoza/added-mermaidjs
added support to mermaidjs
2 parents bdaf08f + cddd87a commit 130ca46

File tree

9 files changed

+6887
-6799
lines changed

9 files changed

+6887
-6799
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,20 @@ if (!injectionStateValidator(injectionState)) {
176176
injectionStateValidator.errors.forEach(error => console.error(error.message));
177177
}
178178
```
179+
180+
181+
#### Generate workflow diagram
182+
183+
It is possible to generate the workflow diagram with [Mermaid](https://github.com/mermaid-js/mermaid)
184+
185+
186+
```
187+
const workflow = workflowBuilder()
188+
.id("helloworld")
189+
....
190+
.build();
191+
192+
const mermaidSourceCode = new MermaidDiagram(workflow).sourceCode();
193+
```
194+
195+
[Here](./examples/browser/mermaid.html) you can see a full example that uses mermaid in the browser to generate the workflow diagram.

examples/browser/mermaid.html

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Serveless Workflow JS SDK</title>
6+
<base href="/">
7+
<meta name="viewport" content="width=device-width, initial-scale=1">
8+
</head>
9+
<body>
10+
<!--
11+
Run http-server from the project root then navigate to http://localhost:8080/examples/browser/index.html
12+
-->
13+
<div id="mermaid" class="mermaid"></div>
14+
<script src="../../dist/umd/index.umd.js"></script>
15+
<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
16+
<script>mermaid.initialize({startOnLoad:true});</script>
17+
<script type="text/javascript">
18+
(() => {
19+
const { workflowBuilder, injectstateBuilder, MermaidDiagram } = serverWorkflowSdk;
20+
const mermaidDiv = document.getElementById('mermaid');
21+
const workflow = workflowBuilder()
22+
.id("helloworld")
23+
.version("1.0")
24+
.specVersion("0.7")
25+
.name("Hello World Workflow")
26+
.description("Inject Hello World")
27+
.start("Hello State")
28+
.states([
29+
injectstateBuilder()
30+
.name("Hello State")
31+
.data({
32+
"result": "Hello World!"
33+
})
34+
.end(true)
35+
.build()
36+
])
37+
.build();
38+
39+
const mermaidSourceCode = new MermaidDiagram(workflow).sourceCode();
40+
mermaidDiv.innerHTML = mermaidSourceCode;
41+
})();
42+
</script>
43+
44+
45+
46+
</body>
47+
</html>

0 commit comments

Comments
 (0)