Skip to content

Commit

Permalink
Added callback to be called after each diagram is rendered as describ…
Browse files Browse the repository at this point in the history
…ed in issue #176
  • Loading branch information
knsv committed Jul 15, 2015
1 parent a8c8f9a commit fcb2af7
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 39 deletions.
50 changes: 42 additions & 8 deletions dist/mermaid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand All @@ -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]
Expand All @@ -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});

}
Expand All @@ -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++) {
Expand All @@ -31655,7 +31672,6 @@ var init = function () {
txt = txt.replace(/</g,'&lt;');
txt = he.decode(txt).trim();


mermaidAPI.render(id,txt,insertSvg, element);
}

Expand All @@ -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);
};

Expand Down Expand Up @@ -31708,7 +31731,7 @@ global.mermaid = {
init.apply(null, arguments);
},
initialize: function(config) {
mermaidAPI.initialize(config);
exports.initialize(config);
},
version: function() {
return mermaidAPI.version();
Expand Down Expand Up @@ -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'){
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion dist/mermaid.min.js

Large diffs are not rendered by default.

50 changes: 42 additions & 8 deletions dist/mermaid.slim.js
Original file line number Diff line number Diff line change
Expand Up @@ -22072,9 +22072,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;
Expand Down Expand Up @@ -22380,8 +22380,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];
Expand All @@ -22392,7 +22393,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]
Expand All @@ -22406,9 +22420,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});

}
Expand All @@ -22420,6 +22434,9 @@ var init = function () {

var insertSvg = function(svgCode){
element.innerHTML = svgCode;
if(typeof callback !== 'undefined'){
callback(id);
}
};

for (i = 0; i < nodes.length; i++) {
Expand All @@ -22439,7 +22456,6 @@ var init = function () {
txt = txt.replace(/</g,'&lt;');
txt = he.decode(txt).trim();


mermaidAPI.render(id,txt,insertSvg, element);
}

Expand All @@ -22462,6 +22478,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);
};

Expand Down Expand Up @@ -22492,7 +22515,7 @@ global.mermaid = {
init.apply(null, arguments);
},
initialize: function(config) {
mermaidAPI.initialize(config);
exports.initialize(config);
},
version: function() {
return mermaidAPI.version();
Expand Down Expand Up @@ -22806,6 +22829,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'){
Expand Down Expand Up @@ -22874,6 +22904,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();
Expand Down Expand Up @@ -22909,6 +22942,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{
Expand Down
2 changes: 1 addition & 1 deletion dist/mermaid.slim.min.js

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions dist/mermaidAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -30955,9 +30955,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;
Expand Down Expand Up @@ -31370,6 +31370,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'){
Expand Down Expand Up @@ -31438,6 +31445,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();
Expand Down Expand Up @@ -31473,6 +31483,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{
Expand Down
17 changes: 14 additions & 3 deletions dist/mermaidAPI.slim.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/mermaidAPI.slim.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/diagrams/sequenceDiagram/sequenceRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,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.debug('For line height fix 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;
Expand Down

0 comments on commit fcb2af7

Please sign in to comment.