Skip to content

Commit

Permalink
added click option for mermaid-zenuml
Browse files Browse the repository at this point in the history
  • Loading branch information
tfsojon committed Aug 2, 2023
1 parent 2e5185f commit 87d07ac
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 120 deletions.
30 changes: 24 additions & 6 deletions content/english/mindmaps/devops/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: "DevOps"
date: 2023-07-10
weight: 1
# description
description: "Step by step guide on how to sign Git commits with a valid OpenID Connect identity"
description: "Step GOy step guide on how to sign Git commits with a valid OpenID Connect identity"
category: "Role based Mindmaps"
---

Expand Down Expand Up @@ -96,15 +96,33 @@ C4Deployment
```mermaid
zenuml
title Reply message
Client->A.method() {
B.method() {
Python->A.method() {
GO.method() {
if(condition) {
return x1
return Python
// return early
@return
A->Client: x11
A->Python: x11
}
}
return x2
return go
}
```

```mermaid
zenuml
BookLibService.Borrow(id) {
User = Python.GetUser()
if(User.isActive) {
try {
BookRepository.Update(id, onLoan, User)
receipt = new Receipt(id, dueDate)
} catch (BookNotFoundException) {
ErrorService.onException(BookNotFoundException)
} finally {
Connection.close()
}
}
return receipt
}
```
8 changes: 7 additions & 1 deletion themes/delta/assets/scss/templates/_main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1847,9 +1847,15 @@ footer {
pointer-events: none;
}
}
[data-roadmap] {
.clickable {
cursor: pointer;
user-select: none;
}
[data-mindmap] {
* {
@extend .clickable;
}
@extend .clickable;
[class^="node-line"],
.node-bkg {
transition: .3s;
Expand Down
114 changes: 1 addition & 113 deletions themes/delta/layouts/mindmaps/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,119 +81,7 @@ <h2 class="mb-4 font-weight-medium mt-5">{{ .Title }}</h2>
{{.Content}}
</div>

{{ range .Data.Pages }}
<div
class="offcanvas offcanvas-end fade"
data-bs-scroll="true"
tabindex="-1"
id="{{.Title | urlize}}"
aria-labelledby="{{.Title | urlize}}"
style="width:500px; transform:none"
>
<div class="offcanvas-header">
<h4 class="offcanvas-title" id="offcanvasExampleLabel">{{.Title}}</h4>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<div class="content">
{{.Content}}
</div>
</div>
</div>
{{ end }}

{{ if .Page.Store.Get "hasMermaid" }}
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs';
mermaid.initialize({
startOnLoad: true,
securityLevel: 'loose',
theme: 'forest',
});

import zenuml from 'https://cdn.jsdelivr.net/npm/@mermaid-js/mermaid-zenuml@0.1.0/dist/mermaid-zenuml.esm.min.mjs';
await mermaid.registerExternalDiagrams([zenuml]);

function urlize(str) {
str = str.trim();
str = str.replace(/\s+/g, '-');
str = str.replace(/[^\w-]/g, '');
str = str.replace(/-{2,}/g, '-');
str = str.toLowerCase();
return str;
}

window.addEventListener('load', (event) => {
const body = document.querySelector('body');
const contentLoader = document.querySelector('.content-loader');
const content = document.querySelector('.content');
contentLoader.remove();
content.classList.remove('content-hidden');

let addDataAttribute = (el, textID) => {
el.setAttribute('type', 'button');
el.setAttribute('data-roadmap', '');
el.setAttribute('data-bs-toggle', 'offcanvas');
el.setAttribute('data-bs-target', '#'+urlize(textID));
el.setAttribute('aria-controls', urlize(textID));
}

setTimeout(function() {
// maindmap
let mindmapNode = document.querySelectorAll('.mindmap-node:not(.section-root):not(.node)');
mindmapNode.forEach(function(el) {
let innerText = el.querySelectorAll('.text-inner-tspan');
const textArray = [];
innerText.forEach((text) => {
textArray.push(text.textContent);
});
const textID = textArray.join(' ');
let id = document.getElementById(urlize(textID));
if (id) { addDataAttribute(el, textID) }
});

// flowchart
let flowchartLabel = document.querySelectorAll('.flowchart-label');
let flowchartEdgeLabel = document.querySelectorAll('g.edgeLabel');
let flowchartLabels = [...flowchartLabel, ...flowchartEdgeLabel];
flowchartLabels.forEach(function(el) {
let nodeLabel = el.querySelectorAll('.nodeLabel');
let edgeLabel = el.querySelectorAll('.edgeLabel');
let allLabel = [...nodeLabel, ...edgeLabel];
const textArray = [];
allLabel.forEach((text) => {
textArray.push(text.textContent);
});
const textID = textArray.join(' ');
let id = document.getElementById(urlize(textID));
if (id) { addDataAttribute(el, textID) }
});

// C4Context
let personMan = document.querySelectorAll('.person-man');
let personManLabel = document.querySelectorAll('g.edgeLabel');
personMan.forEach(function(el) {

const textArray = [];
let allLabel = el.querySelectorAll('text');
allLabel.forEach((text) => {
let fontSize = window.getComputedStyle(text).fontSize;
if (fontSize == '16px') {
textArray.push(text.textContent);
}
});

const textID = textArray.join(' ');
let id = document.querySelector(`[aria-labelledby="${urlize(textID)}"]`);
if (id) { addDataAttribute(el, textID) }
});


}, 1000);
});

</script>
{{ end }}
{{ partial "mermaid-script" . }}

{{ end }}
</div>
Expand Down
125 changes: 125 additions & 0 deletions themes/delta/layouts/partials/mermaid-script.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{{ range .Data.Pages }}
<div
class="offcanvas offcanvas-end fade"
data-bs-scroll="true"
tabindex="-1"
id="{{.Title | urlize}}"
aria-labelledby="{{.Title | urlize}}"
style="width:500px; transform:none"
>
<div class="offcanvas-header">
<h4 class="offcanvas-title" id="offcanvasExampleLabel">{{.Title}}</h4>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<div class="content">
{{.Content}}
</div>
</div>
</div>
{{ end }}

{{ if .Page.Store.Get "hasMermaid" }}
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs';
mermaid.initialize({
startOnLoad: true,
securityLevel: 'loose',
theme: 'forest',
});

import zenuml from 'https://cdn.jsdelivr.net/npm/@mermaid-js/mermaid-zenuml@0.1.0/dist/mermaid-zenuml.esm.min.mjs';
await mermaid.registerExternalDiagrams([zenuml]);

function urlize(str) {
str = str.trim();
str = str.replace(/\s+/g, '-');
str = str.replace(/[^\w-]/g, '');
str = str.replace(/-{2,}/g, '-');
str = str.toLowerCase();
return str;
}

window.addEventListener('load', (event) => {
const body = document.querySelector('body');
const contentLoader = document.querySelector('.content-loader');
const content = document.querySelector('.content');
contentLoader.remove();
content.classList.remove('content-hidden');

let addDataAttribute = (el, textID) => {
el.setAttribute('type', 'button');
el.setAttribute('data-mindmap', '');
el.setAttribute('data-bs-toggle', 'offcanvas');
el.setAttribute('data-bs-target', '#'+urlize(textID));
el.setAttribute('aria-controls', urlize(textID));
}

setTimeout(function() {
// maindmap
let mindmapNode = document.querySelectorAll('.mindmap-node:not(.section-root):not(.node)');
mindmapNode.forEach(function(el) {
let innerText = el.querySelectorAll('.text-inner-tspan');
const textArray = [];
innerText.forEach((text) => {
textArray.push(text.textContent);
});
const textID = textArray.join(' ');
let id = document.getElementById(urlize(textID));
if (id) { addDataAttribute(el, textID) }
});

// flowchart
let flowchartLabel = document.querySelectorAll('.flowchart-label');
let flowchartEdgeLabel = document.querySelectorAll('g.edgeLabel');
let flowchartLabels = [...flowchartLabel, ...flowchartEdgeLabel];
flowchartLabels.forEach(function(el) {
let nodeLabel = el.querySelectorAll('.nodeLabel');
let edgeLabel = el.querySelectorAll('.edgeLabel');
let allLabel = [...nodeLabel, ...edgeLabel];
const textArray = [];
allLabel.forEach((text) => {
textArray.push(text.textContent);
});
const textID = textArray.join(' ');
let id = document.getElementById(urlize(textID));
if (id) { addDataAttribute(el, textID) }
});

// C4Context
let personMan = document.querySelectorAll('.person-man');
let personManLabel = document.querySelectorAll('g.edgeLabel');

personMan.forEach(function(el) {
const textArray = [];
let allLabel = el.querySelectorAll('text');
allLabel.forEach((text) => {
let fontSize = window.getComputedStyle(text).fontSize;
if (fontSize == '16px') {
textArray.push(text.textContent);
}
});

const textID = textArray.join(' ');
let id = document.querySelector(`[aria-labelledby="${urlize(textID)}"]`);
if (id) { addDataAttribute(el, textID) }
});

// zenuml
let zenumlParticipant = document.querySelectorAll('.zenuml .participant');
let zenumlMessageName = document.querySelectorAll('.message .name');
let allZenuml = [...zenumlParticipant, ...zenumlMessageName];

allZenuml.forEach(function(el) {
let label = el.querySelector('.name');
const textID = el.textContent;
let id = document.getElementById(urlize(el.innerText));
if (id) { addDataAttribute(el, textID) }
});


}, 1000);
});

</script>
{{ end }}

0 comments on commit 87d07ac

Please sign in to comment.