Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support sequence diagrams 🚀 #34

Merged
merged 42 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
c7b06d6
feat: support sequence diagrams
ad1992 Oct 11, 2023
f7c6435
remove endArrowhead for solid and dotted stroke styles
ad1992 Oct 11, 2023
a4ec051
cleanup playground UI
ad1992 Oct 12, 2023
b73ab3e
add some sequence testcases and support name attribute in test cases
ad1992 Oct 12, 2023
7aa12c0
add playground for sequence
ad1992 Oct 12, 2023
49e3554
support actor symbols
ad1992 Oct 13, 2023
3929095
display correct text message
ad1992 Oct 13, 2023
ab3bd8f
fix types and use mermaid font size as is for better calculations
ad1992 Oct 13, 2023
ac8bbc9
support identifiers
ad1992 Oct 13, 2023
f4a9ec7
add test cases for identifier and also beautify playground a bit :p
ad1992 Oct 13, 2023
055fa6c
support notes
ad1992 Oct 13, 2023
ddf761c
support activations
ad1992 Oct 16, 2023
46238ef
fix message
ad1992 Oct 16, 2023
a8301d5
Support loops
ad1992 Oct 17, 2023
655e8e1
support alternate paths and add bg to loop labels
ad1992 Oct 17, 2023
0cff7f7
Add testcase for parallel actions
ad1992 Oct 17, 2023
c3e3133
calculate width of container based on label for loop labels
ad1992 Oct 17, 2023
e6e5980
Add a testcase for comment
ad1992 Oct 17, 2023
3c329f2
support critical regions and self loop
ad1992 Oct 18, 2023
4cd5163
use svg for arrow text as json is not consistent
ad1992 Oct 18, 2023
c749481
support background highlights
ad1992 Oct 18, 2023
0ee075a
use message json for computing arrowtype
ad1992 Oct 18, 2023
91f86a7
use note text from message json
ad1992 Oct 18, 2023
9821de2
make sure critical label doesn't overlap with loop text
ad1992 Oct 18, 2023
acd99ef
remove font customization
ad1992 Oct 19, 2023
b51406c
support box/grouping
ad1992 Oct 20, 2023
9339525
group the actor symbols
ad1992 Oct 20, 2023
1d3988c
support sequence numbers
ad1992 Oct 20, 2023
e3434ec
support grouping for actors too and move away from mermaid group rect…
ad1992 Oct 23, 2023
f882571
move computeGroupIds to flowchart as its flowchart specific
ad1992 Oct 27, 2023
af53046
assign frame id to bound text elements
ad1992 Oct 27, 2023
c02e081
upgrade exclaidraw
ad1992 Oct 27, 2023
2241625
fix styling
ad1992 Oct 31, 2023
93b36c2
cleanup
ad1992 Oct 31, 2023
2fbd480
support entity codes
ad1992 Nov 1, 2023
482d31f
update excalidraw package to use the frames api
ad1992 Nov 1, 2023
d936b04
stop using directive as we don't support custom font size hence using…
ad1992 Nov 2, 2023
e77475c
make code more typesafe
ad1992 Nov 2, 2023
add7697
update changelog and make more typesafe
ad1992 Nov 3, 2023
2a41bf3
remove unused code
ad1992 Nov 3, 2023
c9680ca
update changelog
ad1992 Nov 3, 2023
24c8369
upgrade version to 0.1.2
ad1992 Nov 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
.env.development.local
.env.test.local
.env.production.local
.vscode

npm-debug.log*
yarn-debug.log*
Expand Down
22 changes: 19 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
## 0.1.2 (2023-11-03)

## Library

### Features

- Support Sequence Diagrams [#34](https://github.com/excalidraw/mermaid-to-excalidraw/pull/34) by [@ad1992](https://github.com/ad1992).

## Playground

**_This section lists the updates made to the playground and will not affect the integration._**

### Chore

- Adding an example of Complex Decisions & Subprocesses Charts in playground [#31](https://github.com/excalidraw/mermaid-to-excalidraw/pull/31) by [@DYNAMICMORTAL](https://github.com/DYNAMICMORTAL).

## 0.1.1 (2023-09-21)

### Fixes

- Support module resolution nodenext so type module works in host [#30](https://github.com/excalidraw/mermaid-to-excalidraw/pull/30) by [@ad1992](https://github.com/ad1992)
- Support module resolution nodenext so type module works in host [#30](https://github.com/excalidraw/mermaid-to-excalidraw/pull/30) by [@ad1992](https://github.com/ad1992).

### Build

- Don't minify build output [#29](https://github.com/excalidraw/mermaid-to-excalidraw/pull/29) by [@ad1992](https://github.com/ad1992)
- Don't minify build output [#29](https://github.com/excalidraw/mermaid-to-excalidraw/pull/29) by [@ad1992](https://github.com/ad1992).

### Chore

- use excalidraw v0.16.0 [#28](https://github.com/excalidraw/mermaid-to-excalidraw/pull/28) by [@ad1992](https://github.com/ad1992)
- use excalidraw v0.16.0 [#28](https://github.com/excalidraw/mermaid-to-excalidraw/pull/28) by [@ad1992](https://github.com/ad1992).

## 0.1.0 (2023-09-13)

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@excalidraw/mermaid-to-excalidraw",
"version": "0.1.1",
"version": "0.1.2",
"description": "Mermaid to Excalidraw Diagrams",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -27,7 +27,7 @@
"devDependencies": {
"@babel/core": "7.12.0",
"@excalidraw/eslint-config": "1.0.3",
"@excalidraw/excalidraw": "0.16.0",
"@excalidraw/excalidraw": "0.16.1-6920-d3d0bd0",
"@parcel/transformer-sass": "2.9.1",
"@types/mermaid": "9.2.0",
"@types/react": "18.2.14",
Expand Down
49 changes: 30 additions & 19 deletions playground/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,26 @@
<body>
<section id="custom-test">
<h1>Custom Test</h1>
<ul>
<li>
Support only flowchart diagram (the input must started with
"flowchart")
</li>
<li>
See supported and unsupported features at
<a
target="_blank"
href="https://github.com/excalidraw/mermaid-to-excalidraw/pull/1#issue-1686226562"
>PR's description</a
>
</li>
</ul>
Supports only
<a target="_blank" href="https://mermaid.js.org/syntax/flowchart.html"
>Flowchart</a
>
and
<a
target="_blank"
href="https://mermaid.js.org/syntax/sequenceDiagram.html"
>
Sequence </a
>diagrams.
<br />
<textarea
id="mermaid-input"
rows="10"
cols="50"
style="margin-top: 1rem"
placeholder="Input Mermaid Syntax"
></textarea
><br />
<label for="font-size-input">Custom Font Size: </label>
<input type="number" id="font-size-input" value="20" /><br />
<button id="render-excalidraw-btn">Render to Excalidraw</button>
<div id="custom-diagram"></div>
<details id="parsed-data-details">
Expand All @@ -48,8 +44,23 @@ <h1>Custom Test</h1>
id="diagram-loading-spinner"
width="50"
/>
<div id="flowchart-container"></div>
<div id="unsupported"></div>
<h2>Flowchart Diagrams</h2>
<details>
<summary>Flowchart Examples</summary>
<div id="flowchart-container"></div>
</details>

<h2>Sequence Diagrams</h2>
<details>
<summary>Sequence Diagram Examples</summary>
<div id="sequence-container"></div>
</details>
<h2 style="margin-top: 50px">Unsupported diagrams</h2>
<details>
<summary>Unsupported Diagram Examples</summary>
<div id="unsupported"></div>
</details>

<script
crossorigin
src="https://unpkg.com/react@18/umd/react.development.js"
Expand All @@ -60,7 +71,7 @@ <h1>Custom Test</h1>
></script>
<script
crossorigin
src="https://unpkg.com/@excalidraw/[email protected].0/dist/excalidraw.development.js"
src="https://unpkg.com/@excalidraw/[email protected].1-6920-d3d0bd0/dist/excalidraw.development.js"
></script>
<script type="module" src="index.ts"></script>
</body>
Expand Down
59 changes: 36 additions & 23 deletions playground/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,46 @@ mermaid.initialize({ startOnLoad: false });

import "./initCustomTest";
import { renderExcalidraw } from "./initExcalidraw.js";
import { SEQUENCE_DIAGRAM_TESTCASES } from "./testcases/sequence.js";

let indexOffset = 0;
(async () => {
// Render flowchart diagrams
const flowchartContainer = document.getElementById("flowchart-container")!;
document.body.appendChild(flowchartContainer);
await Promise.all(
FLOWCHART_DIAGRAM_TESTCASES.map((diagramDefinition, i) => {
return renderDiagram(flowchartContainer, diagramDefinition, i);
FLOWCHART_DIAGRAM_TESTCASES.map((defination, index) => {
const name = `Test ${index + 1}`;
return renderDiagram(flowchartContainer, name, defination, index);
})
);

indexOffset += FLOWCHART_DIAGRAM_TESTCASES.length;
// Render Sequence diagrams
const sequenceContainer = document.getElementById("sequence-container")!;
await Promise.all(
SEQUENCE_DIAGRAM_TESTCASES.map(({ name, defination }, index) => {
return renderDiagram(
sequenceContainer,
name,
defination,
index + indexOffset
);
})
);
indexOffset += SEQUENCE_DIAGRAM_TESTCASES.length;
// Render unsupported diagrams
const unsupportedContainer = document.getElementById("unsupported")!;
unsupportedContainer.innerHTML = `
<h1 style="margin-top: 50px">Unsupported diagrams</h1>
<p>Unsupported diagram will be rendered as SVG image.</p>
`;
const indexOffset = FLOWCHART_DIAGRAM_TESTCASES.length;
document.body.appendChild(unsupportedContainer);
await Promise.all(
UNSUPPORTED_DIAGRAM_TESTCASES.map((diagramDefinition, i) => {
UNSUPPORTED_DIAGRAM_TESTCASES.map((testcase, index) => {
const { name, defination } = testcase;

return renderDiagram(
unsupportedContainer,
diagramDefinition,
i + indexOffset
name,
defination,
index + indexOffset
);
})
);
Expand All @@ -44,30 +59,31 @@ import { renderExcalidraw } from "./initExcalidraw.js";

async function renderDiagram(
containerEl: HTMLElement,
name: string,
diagramDefinition: string,
i: number
) {
const diagramContainerEl = document.createElement("div");
diagramContainerEl.id = `diagram-container-${i}`;
diagramContainerEl.innerHTML = `<h2 style="margin-top: 50px">Test #${i + 1}
diagramContainerEl.innerHTML = `<h2 style="margin-top: 50px; color:#f06595;">${name}
</h2>
<div id="diagram-${i}"></div>

<pre style="font-size:16px; font-weight:600;font-style:italic;background:#eeeef1;width:40vw;padding:5px" id="mermaid-syntax-${i}"></pre>

<button id="diagram-btn-${i}" data="${i}">Render to Excalidraw</button>
<details style="margin-top: 20px">
<summary>Mermaid syntax</summary>
<pre id="mermaid-syntax-${i}"></pre>
</details>
<div id="diagram-${i}" style="width:50%"></div>

<details style="margin-top: 10px">
<summary>Parsed data from parseMermaid</summary>
<pre id="parsed-${i}"></pre>
<summary>View Parsed data from parseMermaid</summary>
<pre style="font-size:16px; background:#eeeef1;width:40vw;padding:5px" id="parsed-${i}"></pre>
</details>`;

const btn = diagramContainerEl.querySelector(`#diagram-btn-${i}`)!;

btn.addEventListener("click", async () => {
const data = btn.getAttribute("data");
const pd = document.getElementById(`parsed-${data}`)!;
renderExcalidraw(pd.innerHTML);
renderExcalidraw(pd.textContent!);
});

const diagramEl = diagramContainerEl.querySelector(`#diagram-${i}`)!;
Expand All @@ -87,10 +103,7 @@ async function renderDiagram(

// Get parsed data
try {
const data = await parseMermaid(diagramDefinition, {
fontSize: DEFAULT_FONT_SIZE,
});

const data = await parseMermaid(diagramDefinition);
const parsedDataViewerEl = diagramContainerEl.querySelector(
`#parsed-${i}`
)!;
Expand Down
15 changes: 3 additions & 12 deletions playground/initCustomTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,22 @@ btn.addEventListener("click", async () => {
const mermaidInput = document.getElementById(
"mermaid-input"
) as HTMLInputElement;
const fontSizeInput = document.getElementById(
"font-size-input"
) as HTMLInputElement;

const diagramDefinition = mermaidInput.value;
const customFontSize = Number(fontSizeInput.value);

// Render Mermaid diagram
const diagramEl = document.getElementById("custom-diagram")!;
const { svg } = await mermaid.render(
`custom-digaram`,
`%%{init: {"themeVariables": {"fontSize": "${customFontSize}px"}} }%%\n${diagramDefinition}`
);
const { svg } = await mermaid.render("custom-digaram", diagramDefinition);
diagramEl.innerHTML = svg;

// Parse Mermaid diagram and render to Excalidraw
const parsedData = await parseMermaid(diagramDefinition, {
fontSize: customFontSize,
});
const parsedData = await parseMermaid(diagramDefinition);

const parsedDataEl = document.getElementById("custom-parsed-data")!;
parsedDataEl.parentElement!.style.display = "block";
parsedDataEl.innerText = JSON.stringify(parsedData, null, 2);

renderExcalidraw(JSON.stringify(parsedData), customFontSize);
renderExcalidraw(JSON.stringify(parsedData));
} catch (e) {
errorEl.setAttribute("style", "display: block");
errorEl.innerHTML = String(e);
Expand Down
17 changes: 16 additions & 1 deletion playground/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ body {
max-width: 48%;
}
}

button {
height: 40px;
font-size: 16px;
background: #4dabf7;
border: 1px solid #a5d8ff;
box-shadow: none;
border-radius: 2px;
color: white;
cursor: pointer;
}
#excalidraw {
width: 50vw;
height: 100vh;
Expand Down Expand Up @@ -46,3 +55,9 @@ body {
margin-top: 20px;
}
}

a {
color: #0071ce;
font-weight: 600;
text-decoration: none;
}
Loading
Loading