This repository contains an example that demonstrates (see demo) how to animate (mermaid) diagrams in (reveal-md) presentations using fragments. The approach adds classes and data attributes to the rendered graph (SVG) elements. It may also be used in reveal.js.
My goal is to create a library that can be installed using npm. Therefore, I would like to collect requirements. Please create an issue to add your requirements and join the discussion. For example, one important point of discussion is, how/where the animations should be defined or associated with the graph (elements).
I've implemented two approaches:
-
Define a JavaScript function (see reveal-mermaid-animation-handlers.js) that calls the API of the library (see reveal-mermaid-animation.js)
-
Define a code block in a new/custom language (
mermaid-animation
), which is translated in API calls by the library. For example, after the code block (languagemermaid
) of your graphgraph TD; A-->B;
you define the animation (order) of nodes and edges in another code block (language
mermaid
) on the same slideA A-->B B
The line number defines, in which step a node/edge should be shown in the animation (i.e. adds class
fragment
and sets attributedata-fragment-index
on the SVG element of the rendered node/edge). In the example, NodeA
is shown in the first step, the edgeA-->B
and the nodeB
are shown in the second step.
npm install
npm start
Open http://localhost:1948/presentation.md
Thanks to the authors of reveal-md-scripts. I'm using a modified version of their reveal-mermaid.js. I dispatch events, when the graph is rendered or attached.