Skip to content

Instantly share code, notes, and snippets.

@jzaeske
Created June 2, 2016 20:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jzaeske/e2de8b14142818f8d8f5e74e8b6ae2b0 to your computer and use it in GitHub Desktop.
Save jzaeske/e2de8b14142818f8d8f5e74e8b6ae2b0 to your computer and use it in GitHub Desktop.
animate js-sequence-diagrams in reveal.js
function initDiagram(selector) {
// draw diagram. selector is the html element containing the diagram description
$(selector).sequenceDiagram({theme: 'hand'});
// get width and height to set the viewBox Attribute. this is needed to resize the svg via css
var w = $(selector + " svg").attr("width");
var h = $(selector + " svg").attr("height");
$(selector + " svg").attr('id', selector + "-id");
var svg = document.getElementById(selector + "-id");
svg.setAttribute("viewBox","0 0 " + w + " " + h);
// we want to animate all messages in the sequence diagram. message consinst of an arrow, a text and a box around the text.
// we can find arrows via path[marker-end]. text and box are path and rect directly before the arrow.
$(selector + " path[marker-end]").each(function(index) {
// set fragement-class and index on the arrow
var arrow = this;
$(arrow).attr('class', 'fragment');
$(arrow).attr('data-fragment-index', index)
// ... and on the text
var text = $(arrow).prev('path');
text.attr('class', 'fragment');
text.attr('data-fragment-index', index);
// ... and on the box
var rect = $(text).prev('rect');
rect.attr('class', 'fragment');
rect.attr('data-fragment-index', index);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment