var graph = require('./diagrams/flowchart/graphDb'); var flow = require('./diagrams/flowchart/parser/flow'); var utils = require('./utils'); var flowRenderer = require('./diagrams/flowchart/flowRenderer'); var seq = require('./diagrams/sequenceDiagram/sequenceRenderer'); var info = require('./diagrams/example/exampleRenderer'); var infoParser = require('./diagrams/example/parser/example'); var flowParser = require('./diagrams/flowchart/parser/flow'); var dotParser = require('./diagrams/flowchart/parser/dot'); var sequenceParser = require('./diagrams/sequenceDiagram/parser/sequenceDiagram'); var sequenceDb = require('./diagrams/sequenceDiagram/sequenceDb'); var infoDb = require('./diagrams/example/exampleDb'); var gantt = require('./diagrams/gantt/ganttRenderer'); var ganttParser = require('./diagrams/gantt/parser/gantt'); var ganttDb = require('./diagrams/gantt/ganttDb'); var d3 = require('./d3'); var nextId = 0; /** * Function that parses a mermaid diagram defintion. If parsing fails the parseError callback is called and an error is * thrown and * @param text */ var parse = function(text){ var graphType = utils.detectType(text); var parser; switch(graphType){ case 'graph': parser = flowParser; parser.parser.yy = graph; break; case 'dotGraph': parser = dotParser; parser.parser.yy = graph; break; case 'sequenceDiagram': parser = sequenceParser; parser.parser.yy = sequenceDb; break; case 'info': parser = infoParser; parser.parser.yy = infoDb; break; case 'gantt': parser = ganttParser; parser.parser.yy = ganttDb; break; } try{ parser.parse(text); return true; } catch(err){ return false; } }; /** * Function returning version information * @returns {string} A string containing the version info */ exports.version = function(){ return require('../package.json').version; }; var render = function(id, txt,cb){ d3.select('body').append('div') .attr('id', 'd'+id) .append('svg') .attr('id', id) .attr('width','100%') .attr('xmlns','http://www.w3.org/2000/svg') .append('g'); //console.log(d3.select('#d'+id).node().innerHTML); var element = d3.select('#d'+id).node(); var graphType = utils.detectType(txt); var classes = {}; switch(graphType){ case 'graph': classes = flowRenderer.getClasses(txt, false); if(typeof mermaid.flowchartConfig === 'object'){ flowRenderer.setConf(mermaid.flowchartConfig); } flowRenderer.draw(txt, id, false); utils.cloneCssStyles(element.firstChild, classes); graph.bindFunctions(); break; case 'dotGraph': classes = flowRenderer.getClasses(txt, true); flowRenderer.draw(txt, id, true); utils.cloneCssStyles(element.firstChild, classes); break; case 'sequenceDiagram': if(typeof mermaid.sequenceConfig === 'object'){ seq.setConf(mermaid.sequenceConfig); } seq.draw(txt,id); utils.cloneCssStyles(element.firstChild, []); break; case 'gantt': if(typeof mermaid.ganttConfig === 'object'){ gantt.setConf(mermaid.ganttConfig); } gantt.draw(txt,id); utils.cloneCssStyles(element.firstChild, []); break; case 'info': info.draw(txt,id,exports.version()); utils.cloneCssStyles(element.firstChild, []); break; } //console.log(document.body.innerHTML); cb(d3.select('#d'+id).node().innerHTML); if(typeof d3.select('#d'+id).node().remove === 'function'){ d3.select('#d'+id).node().remove(); } }; exports.render = function(id, text,cb){ if(typeof document === 'undefined'){ //jsdom = require('jsdom').jsdom; //console.log(jsdom); //htmlStub = '