Skip to content

trying to improve mermaid #87

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 4 additions & 3 deletions content/undergraduate/curriculum.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ metadata: none
toc: false
weight: 2
type: wide
hasMermaid: true
---

<!-- prettier-ignore-start -->
Expand Down Expand Up @@ -85,8 +86,7 @@ type: wide

## Course Prerequisites Graph

```mermaid "caption=prerequisites"
%%{ init: { 'flowchart': { 'curve': 'linear' } } }%%
{{< svg-graph >}}
flowchart TD

classDef core fill:#0072B2,stroke:none,stroke-width:2px,color:#eee,font-weight:bolder
Expand Down Expand Up @@ -232,7 +232,8 @@ click CC6 href "/undergraduate/electives" "Undergraduate Electives"

click HSS1 href "/undergraduate/electives" "Undergraduate Electives"
click HSS2 href "/undergraduate/electives" "Undergraduate Electives"
```
{{< /svg-graph >}}


## Committee

Expand Down
3 changes: 3 additions & 0 deletions layouts/partials/footer/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ <h5 class="mb-4">{{- .Name -}}</h5>
{{ end }}
</ul>
</div>
{{ if .Params.hasMermaid }}
{{ partial "footer/optional-scripts.html" . }}
{{ end }}
</footer>
54 changes: 54 additions & 0 deletions layouts/shortcodes/svg-graph.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!-- layouts/shortcodes/svg-graph.html -->
<div id="graphDiv"></div>
<style type="text/css">
#courseSvg {
width: 100%;
height: 80vh; /* This sets the height relative to the viewport height */
}

/* Media query for mobile devices */
@media (max-width: 768px) {
#courseSvg {
height: 300px; /* Utilize full viewport height on smaller screens */
width: 100%;
}
}

/* Optional: Additional styles for tablets */
@media (min-width: 769px) and (max-width: 1024px) {
#courseSvg {
height: 85vh;
width: 100%;
}
}

/* Desktop-specific styling */
@media (min-width: 1025px) {
#courseSvg {
height: 600px;
width: 100%;
}
}
</style>

<script src="https://bumbu.me/svg-pan-zoom/dist/svg-pan-zoom.min.js"></script>
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs';
mermaid.initialize({ startOnLoad: false });

const drawDiagram = async function () {
const element = document.querySelector('#graphDiv');
const graphDefinition = `{{ .Inner | safeJS }}`; // Captures content between shortcode tags
const { svg } = await mermaid.render('courseSvg', graphDefinition);
element.innerHTML = svg.replace(/( )*max-width:( 0-9\.)*px;/i, '');


let panZoom = svgPanZoom('#courseSvg', {
zoomEnabled: true,
controlIconsEnabled: true,
center: true,
zoomScaleSensitivity: 0.5,
});
};
await drawDiagram();
</script>