1/** js sequence diagrams 2 * https://bramp.github.io/js-sequence-diagrams/ 3 * (c) 2012-2017 Andrew Brampton (bramp.net) 4 * Simplified BSD license. 5 */ 6/*global Diagram, _ */ 7 8if (typeof Raphael == 'undefined' && typeof Snap == 'undefined') { 9 throw new Error('Raphael or Snap.svg is required to be included.'); 10} 11 12if (_.isEmpty(Diagram.themes)) { 13 // If you are using stock js-sequence-diagrams you should never see this. This only 14 // happens if you have removed the built in themes. 15 throw new Error('No themes were registered. Please call registerTheme(...).'); 16} 17 18// Set the default hand/simple based on which theme is available. 19Diagram.themes.hand = Diagram.themes.snapHand || Diagram.themes.raphaelHand; 20Diagram.themes.simple = Diagram.themes.snapSimple || Diagram.themes.raphaelSimple; 21 22/* Draws the diagram. Creates a SVG inside the container 23* container (HTMLElement|string) DOM element or its ID to draw on 24* options (Object) 25*/ 26Diagram.prototype.drawSVG = function(container, options) { 27 var defaultOptions = { 28 theme: 'hand' 29 }; 30 31 options = _.defaults(options || {}, defaultOptions); 32 33 if (!(options.theme in Diagram.themes)) { 34 throw new Error('Unsupported theme: ' + options.theme); 35 } 36 37 // TODO Write tests for this check 38 var div = _.isString(container) ? document.getElementById(container) : container; 39 if (div === null || !div.tagName) { 40 throw new Error('Invalid container: ' + container); 41 } 42 43 var Theme = Diagram.themes[options.theme]; 44 new Theme(this, options, function(drawing) { 45 drawing.draw(div); 46 }); 47}; // end of drawSVG 48