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: Add packet diagram #4839

Merged
merged 31 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c41594d
feat: Add packet diagram
sidharthv96 Sep 14, 2023
afd7cf5
fix: Types and nomenclature
sidharthv96 Sep 14, 2023
38d9c6d
test: Add unit tests
sidharthv96 Sep 14, 2023
75f1f92
test: Add rendering tests
sidharthv96 Sep 14, 2023
043729f
feat: Support showBits
sidharthv96 Sep 14, 2023
136f1c5
fix: Diagram DB types
sidharthv96 Sep 14, 2023
0ff3ba3
Add mini-live editing to example.html
sidharthv96 Sep 18, 2023
5661509
Add mini-live editing to example.html
sidharthv96 Sep 18, 2023
3e3519e
docs: Add packet to index
sidharthv96 Sep 19, 2023
ce6bfcb
Merge branch 'next' into feat/948_packetDiagram
sidharthv96 Nov 14, 2023
7c79bbd
refactor: Address review comments
sidharthv96 Nov 14, 2023
b88d1df
fix(packet): Grammar whitespace
sidharthv96 Nov 14, 2023
659db9f
chore: Add types and minimums for packet config
sidharthv96 Nov 14, 2023
9925b9b
feat: Add title support to packetDiagram
sidharthv96 Nov 14, 2023
1a8743e
refactor: Separate default options in styles
sidharthv96 Nov 14, 2023
068a74a
chore: Fix magic number
sidharthv96 Nov 14, 2023
fc400ea
fix: Langium formatting
sidharthv96 Nov 14, 2023
b6983e4
Add title to tests
sidharthv96 Nov 14, 2023
113a400
Add DiagramRenderer type
sidharthv96 Nov 14, 2023
f9df193
chore: Fix imports
sidharthv96 Nov 14, 2023
99313fe
fix editor build
sidharthv96 Nov 15, 2023
f15d24b
Merge branch 'next' into feat/948_packetDiagram
sidharthv96 Nov 15, 2023
0d7644c
refactor: Fix types
sidharthv96 Nov 15, 2023
088fc39
Fix SVG width
sidharthv96 Nov 15, 2023
784a853
feat: Add theming to packet
sidharthv96 Nov 15, 2023
480645d
fix: Add language to codeblock
sidharthv96 Nov 15, 2023
a8105f0
fix: Use configureSvgSize
sidharthv96 Nov 16, 2023
bca645f
test: Add packet and xychart into mermaidAPI test
sidharthv96 Nov 16, 2023
96ae4a5
chore: Remove unnecessary(?) mocks.
sidharthv96 Nov 16, 2023
7ef61d5
test: Add packet test for title, accTitle, accDescr
sidharthv96 Nov 16, 2023
5cc20b5
Merge branch 'next' into feat/948_packetDiagram
sidharthv96 Jan 23, 2024
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 .build/jsonSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const MERMAID_CONFIG_DIAGRAM_KEYS = [
'gitGraph',
'c4',
'sankey',
'packet',
] as const;

/**
Expand Down
4 changes: 2 additions & 2 deletions .esbuild/build.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { build } from 'esbuild';
import { mkdir, writeFile } from 'node:fs/promises';
import { MermaidBuildOptions, defaultOptions, getBuildConfig } from './util.js';
import { packageOptions } from '../.build/common.js';
import { generateLangium } from '../.build/generateLangium.js';
import { MermaidBuildOptions, defaultOptions, getBuildConfig } from './util.js';

const shouldVisualize = process.argv.includes('--visualize');

Expand Down Expand Up @@ -56,7 +56,7 @@ const main = async () => {
await generateLangium();
await mkdir('stats').catch(() => {});
const packageNames = Object.keys(packageOptions) as (keyof typeof packageOptions)[];
// it should build `parser` before `mermaid` because it's a dependecy
// it should build `parser` before `mermaid` because it's a dependency
for (const pkg of packageNames) {
await buildPackage(pkg).catch(handler);
}
Expand Down
21 changes: 0 additions & 21 deletions __mocks__/c4Renderer.js

This file was deleted.

16 changes: 0 additions & 16 deletions __mocks__/classRenderer-v2.js

This file was deleted.

13 changes: 0 additions & 13 deletions __mocks__/classRenderer.js

This file was deleted.

1 change: 0 additions & 1 deletion __mocks__/dagre-d3.ts

This file was deleted.

3 changes: 0 additions & 3 deletions __mocks__/entity-decode/browser.ts

This file was deleted.

16 changes: 0 additions & 16 deletions __mocks__/erRenderer.js

This file was deleted.

24 changes: 0 additions & 24 deletions __mocks__/flowRenderer-v2.js

This file was deleted.

16 changes: 0 additions & 16 deletions __mocks__/ganttRenderer.js

This file was deleted.

13 changes: 0 additions & 13 deletions __mocks__/gitGraphRenderer.js

This file was deleted.

15 changes: 0 additions & 15 deletions __mocks__/journeyRenderer.js

This file was deleted.

8 changes: 0 additions & 8 deletions __mocks__/pieRenderer.ts

This file was deleted.

13 changes: 0 additions & 13 deletions __mocks__/requirementRenderer.js

This file was deleted.

13 changes: 0 additions & 13 deletions __mocks__/sankeyRenderer.js

This file was deleted.

23 changes: 0 additions & 23 deletions __mocks__/sequenceRenderer.js

This file was deleted.

22 changes: 0 additions & 22 deletions __mocks__/stateRenderer-v2.js

This file was deleted.

67 changes: 67 additions & 0 deletions cypress/integration/rendering/packet.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { imgSnapshotTest } from '../../helpers/util';

describe('packet structure', () => {
it('should render a simple packet diagram', () => {
imgSnapshotTest(
`packet-beta
title Hello world
0-10: "hello"
`
);
});

it('should render a complex packet diagram', () => {
imgSnapshotTest(
`packet-beta
0-15: "Source Port"
16-31: "Destination Port"
32-63: "Sequence Number"
64-95: "Acknowledgment Number"
96-99: "Data Offset"
100-105: "Reserved"
106: "URG"
107: "ACK"
108: "PSH"
109: "RST"
110: "SYN"
111: "FIN"
112-127: "Window"
128-143: "Checksum"
144-159: "Urgent Pointer"
160-191: "(Options and Padding)"
192-223: "data"
`
);
});

it('should render a complex packet diagram with showBits false', () => {
imgSnapshotTest(
`
---
title: "Packet Diagram"
config:
packet:
showBits: false
---
packet-beta
0-15: "Source Port"
16-31: "Destination Port"
32-63: "Sequence Number"
64-95: "Acknowledgment Number"
96-99: "Data Offset"
100-105: "Reserved"
106: "URG"
107: "ACK"
108: "PSH"
109: "RST"
110: "SYN"
111: "FIN"
112-127: "Window"
128-143: "Checksum"
144-159: "Urgent Pointer"
160-191: "(Options and Padding)"
192-223: "data"
`
);
});
});
49 changes: 38 additions & 11 deletions demos/dev/example.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,24 @@
<html>
<head>
<title>Mermaid development page</title>
<style>
.container {
display: flex;
flex-direction: row;
}

#code {
max-width: 30vw;
width: 30vw;
}

#dynamicDiagram {
padding-left: 2em;
flex: 1;
}
</style>
</head>
<body>
<pre class="mermaid">info</pre>

<pre id="diagram" class="mermaid">
graph TB
a --> b
Expand All @@ -15,22 +29,35 @@
c --> d
</pre>

<div id="dynamicDiagram"></div>
<hr />
Type code to view diagram:
<div class="container">
<textarea name="code" id="code" cols="30" rows="10"></textarea>
<div id="dynamicDiagram"></div>
</div>
<pre class="mermaid">info</pre>

<script type="module">
import mermaid from '/mermaid.esm.mjs';
mermaid.parseError = function (err, hash) {
console.error('Mermaid error: ', err);
};
async function render(str) {
const { svg } = await mermaid.render('dynamic', str);
document.getElementById('dynamicDiagram').innerHTML = svg;
}
const storeKey = window.location.pathname;
const code = localStorage.getItem(storeKey);
if (code) {
document.getElementById('code').value = code;
await render(code);
}
mermaid.initialize({
startOnLoad: true,
logLevel: 0,
});
const value = `graph TD\nHello --> World`;
const el = document.getElementById('dynamicDiagram');
const { svg } = await mermaid.render('dd', value);
console.log(svg);
el.innerHTML = svg;
document.getElementById('code').addEventListener('input', async (e) => {
const value = e.target.value;
localStorage.setItem(storeKey, value);
await render(value);
});
</script>

<script src="/dev/reload.js"></script>
Expand Down
Loading
Loading