Skip to content

Commit

Permalink
upgrade Mermaid.js to v10
Browse files Browse the repository at this point in the history
  • Loading branch information
tamlok committed Jun 19, 2024
1 parent 84891fb commit 06c712c
Show file tree
Hide file tree
Showing 4 changed files with 1,241 additions and 791 deletions.
2 changes: 1 addition & 1 deletion src/data/extra/web/js/graphrenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class GraphRenderer extends VxWorker {
}
});

this.doRender(this.nodesToRender);
this.doRender();
}

// Interface 2.
Expand Down
29 changes: 15 additions & 14 deletions src/data/extra/web/js/mermaid.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Mermaid extends GraphRenderer {

initialize(p_callback) {
return super.initialize(() => {
mermaid.mermaidAPI.initialize({
mermaid.initialize({
startOnLoad: false,
theme: this.theme
});
Expand All @@ -26,12 +26,12 @@ class Mermaid extends GraphRenderer {

// Render @p_node as Mermaid graph.
// Return true on success.
renderOne(p_node, p_idx) {
async renderOne(p_node, p_idx) {
let graphSvg = null;
try {
graphSvg = mermaid.mermaidAPI.render('vx-mermaid-graph-' + p_idx,
p_node.textContent,
function() {});
const { svg } = await mermaid.render('vx-mermaid-graph-' + p_idx,
p_node.textContent);
graphSvg = svg;
} catch (p_err) {
console.error('failed to render Mermaid', p_err);
// Clean the container element, or Mermaid won't render the graph with
Expand Down Expand Up @@ -72,12 +72,12 @@ class Mermaid extends GraphRenderer {

// Render a graph from @p_text.
// Will append a div to @p_container and return the div.
renderTextInternal(p_container, p_text, p_idx) {
async renderTextInternal(p_container, p_text, p_idx) {
let graphSvg = null;
try {
graphSvg = mermaid.mermaidAPI.render('vx-mermaid-graph-stand-alone-' + p_idx,
p_text,
function() {});
const { svg } = await mermaid.render('vx-mermaid-graph-stand-alone-' + p_idx,
p_text);
graphSvg = svg;
} catch (p_err) {
console.error('failed to render Mermaid', p_err);
// Clean the container element, or Mermaid won't render the graph with
Expand All @@ -104,20 +104,21 @@ class Mermaid extends GraphRenderer {
}

p_container.appendChild(graphDiv);

console.log(graphDiv);
return graphDiv;
}

// p_callback(graphDiv).
renderText(p_container, p_text, p_idx, p_callback) {
if (!this.initialize(() => {
let graphDiv = this.renderTextInternal(p_container, p_text, p_idx);
async renderText(p_container, p_text, p_idx, p_callback) {
if (!this.initialize(async () => {
let graphDiv = await this.renderTextInternal(p_container, p_text, p_idx);
p_callback(graphDiv);
})) {
return;
}

let graphDiv = this.renderTextInternal(p_container, p_text, p_idx);
let graphDiv = await this.renderTextInternal(p_container, p_text, p_idx);
console.log(graphDiv);
p_callback(graphDiv);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/data/extra/web/js/mermaid/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# [mermaid](https://github.com/mermaid-js/mermaid)
v9.4.3
v10.9.1
1,999 changes: 1,224 additions & 775 deletions src/data/extra/web/js/mermaid/mermaid.min.js

Large diffs are not rendered by default.

0 comments on commit 06c712c

Please sign in to comment.