Added callback to be called after each diagram is rendered as described in issue #176

This commit is contained in:
knsv
2015-07-15 11:39:46 +02:00
parent a8c8f9a472
commit fcb2af780d
11 changed files with 168 additions and 39 deletions

50
dist/mermaid.js vendored
View File

@@ -31288,9 +31288,9 @@ module.exports.draw = function (text, id) {
var box = exports.bounds.getBounds();
// Adjust line height of actor lines now that the height of the diagram is known
log.info('Querying: #' + id + ' .actor-line')
log.debug('For line height fix Querying: #' + id + ' .actor-line');
var actorLines = d3.selectAll('#' + id + ' .actor-line');
actorLines.attr('y2',box.stopy)
actorLines.attr('y2',box.stopy);
var height = box.stopy - box.starty + 2*conf.diagramMarginY;
@@ -31596,8 +31596,9 @@ module.exports.mermaidAPI = mermaidAPI;
* @param nodes a css selector or an array of nodes
*/
var init = function () {
log.debug('Starting rendering diagrams');
var nodes;
if(arguments.length === 2){
if(arguments.length >= 2){
/*! sequence config was passed as #1 */
if(typeof arguments[0] !== 'undefined'){
mermaid.sequenceConfig = arguments[0];
@@ -31608,7 +31609,20 @@ var init = function () {
else{
nodes = arguments[0];
}
// if last argument is a function this is the callback function
var callback;
if(typeof arguments[arguments.length-1] === 'function'){
callback = arguments[arguments.length-1];
log.debug('Callback function found');
}else{
if(typeof mermaidAPI.getConfig().mermaid.callback === 'function'){
callback = mermaidAPI.getConfig().mermaid.callback;
log.debug('Callback function found');
}else{
log.debug('No Callback function found');
}
}
nodes = nodes === undefined ? document.querySelectorAll('.mermaid')
: typeof nodes === "string" ? document.querySelectorAll(nodes)
: nodes instanceof Node ? [nodes]
@@ -31622,9 +31636,9 @@ var init = function () {
}
log.debug('STar On Load (0): '+mermaid.startOnLoad);
log.debug('Start On Load before: '+mermaid.startOnLoad);
if(typeof mermaid.startOnLoad !== 'undefined'){
log.debug('STar On Load: '+mermaid.startOnLoad);
log.debug('Start On Load inner: '+mermaid.startOnLoad);
mermaidAPI.initialize({startOnLoad:mermaid.startOnLoad});
}
@@ -31636,6 +31650,9 @@ var init = function () {
var insertSvg = function(svgCode){
element.innerHTML = svgCode;
if(typeof callback !== 'undefined'){
callback(id);
}
};
for (i = 0; i < nodes.length; i++) {
@@ -31655,7 +31672,6 @@ var init = function () {
txt = txt.replace(/</g,'&lt;');
txt = he.decode(txt).trim();
mermaidAPI.render(id,txt,insertSvg, element);
}
@@ -31678,6 +31694,13 @@ exports.version = function(){
* @param config
*/
exports.initialize = function(config){
log.debug('Initializing mermaid');
if(typeof config.mermaid.startOnLoad !== 'undefined'){
global.mermaid.startOnLoad = config.mermaid.startOnLoad;
}
if(typeof config.mermaid.htmlLabels !== 'undefined'){
global.mermaid.htmlLabels = config.mermaid.htmlLabels;
}
mermaidAPI.initialize(config);
};
@@ -31708,7 +31731,7 @@ global.mermaid = {
init.apply(null, arguments);
},
initialize: function(config) {
mermaidAPI.initialize(config);
exports.initialize(config);
},
version: function() {
return mermaidAPI.version();
@@ -32022,6 +32045,13 @@ exports.version = function(){
return require('../package.json').version;
};
/**
* Function that renders an svg with a graph from a chart definition.
* @param id
* @param txt
* @param cb
* @param container
*/
var render = function(id, txt, cb, container){
if(typeof container !== 'undefined'){
@@ -32090,6 +32120,9 @@ var render = function(id, txt, cb, container){
if(typeof cb !== 'undefined'){
cb(d3.select('#d'+id).node().innerHTML);
}else{
log.warn('CB = undefined');
}
var node = d3.select('#d'+id).node();
@@ -32125,6 +32158,7 @@ var setConf = function(cnf){
config[lvl1Keys[i]] = {};
}
log.debug('Setting config: '+lvl1Keys[i]+' '+lvl2Keys[j]+' to '+cnf[lvl1Keys[i]][lvl2Keys[j]]);
config[lvl1Keys[i]][lvl2Keys[j]] = cnf[lvl1Keys[i]][lvl2Keys[j]];
}
}else{