-
-
Notifications
You must be signed in to change notification settings - Fork 16.7k
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
Rendering of mermaid diagrams broken after the 3rd slide #2863
Comments
Ok found a workaround and cause for this. As I understand, the content of reveal slides is lazy loaded. I wasnt able to find a slide-loaded or data-loaded event. Having such an event would make this an easy solution. My workaround is to look for slides that style.display is set to "block" and data-loaded attribute is set to true that have a non-rendered mermaid diagram, and start rendering the diagram object. Please see this workaround: Feature request: Other issues to think about: Thanks! |
Noticed also that the diagrams render well if transition is set to: none, fade, or slide |
Let me know if this works:
|
@Martinomagnifico The solution you provided does in fact fix most of the problems, thanks. There are still some minor quirks, for instance the diagrams become correctly aligned only on the second time the slide is viewed; but probably good enough in my case. |
Here is what I ended up using: document.querySelectorAll('.mermaid').forEach(function (mermaidDiv, i) {
let insertSvg = function(svgCode, bindFunctions){
mermaidDiv.innerHTML = svgCode;
mermaidDiv.classList.remove('mermaid');
};
let graphDefinition = mermaidDiv.textContent;
mermaid.mermaidAPI.render(`mermaid-${i}`, graphDefinition, insertSvg);
}); It's certainly less efficient than your solution because all the mermaid graphs are generated at the beginning, but it appears to fix the above mentioned issues. |
Or add Reveal.layout(); near the end of the function. The thing is that this function loads after the slide is starting to appear. So the slide is starting to change from a to b, and at that point the mermaid content is being converted to SVG. But if the content is centered, there will have been a calculation already to calculate the top of the section. Adding the SVG afterwards will then result in some alignment issues. If we add a Reveal.layout(); in the function, it will fix that:
|
By the way, @FlorianCassayre, your function works just as well. It's only some SVG's that are generated, and will hardly impact performance. |
fix seems to have worked perfectly ... thanks everyone |
I have to change
to
|
Good catch, bindFunctions is indeed not needed. @koutbo6 Seems to me that this issue can be closed. 😀 |
Hi, |
Managed to integrate mermaid into reveal4.10 and it renders perfectly.
That it, until you hit the 4th slide.
For some reason, slides 1,2,3 render the diagrams and set their size correctly.
Starting from slide 4 and beyond, the diagrams render, but they get unusually small sizes that prohibit their display.
Attached index.html in this gist illustrates the problem:
https://gist.github.com/koutbo6/44777c84fff9fe559bdf984aa065fe4d
I understand this could be a mermaid.js issue, but any idea why
Here is what the elements look like:
The text was updated successfully, but these errors were encountered: