Updated conf handling

Added initialize function
Moved genric configuration as clonseCssStyles till conf root
Added parse funtion to the mermaidAPI api
This commit is contained in:
knsv
2015-06-07 09:21:19 +02:00
parent 55fa62d9c0
commit 08fa19bc83
18 changed files with 427 additions and 608 deletions

158
dist/mermaid.js vendored
View File

@@ -24950,9 +24950,9 @@ process.chdir = function (dir) {
},{}],86:[function(require,module,exports){
module.exports={
"name": "mermaid",
"version": "0.4.0",
"version": "0.5.0",
"description": "Markdownish syntax for generating flowcharts, sequence diagrams and gantt charts.",
"main": "src/main.js",
"main": "src/mermaid.js",
"keywords": [
"diagram",
"markdown",
@@ -25786,7 +25786,6 @@ if (!dagreD3) {
module.exports = dagreD3;
},{"dagre-d3":2}],92:[function(require,module,exports){
(function (global){
/**
* Created by knut on 14-12-11.
*/
@@ -25861,7 +25860,7 @@ exports.addVertices = function (vert, g) {
}
var labelTypeStr = '';
if(global.mermaid.htmlLabels) {
if(conf.htmlLabels) {
labelTypeStr = 'html';
} else {
verticeText = verticeText.replace(/<br>/g, "\n");
@@ -25965,7 +25964,7 @@ exports.addEdges = function (edges, g) {
else {
var edgeText = edge.text.replace(/<br>/g, "\n");
if(typeof edge.style === 'undefined'){
if (global.mermaid.htmlLabels){
if (conf.htmlLabels){
g.setEdge(edge.start, edge.end,{labelType: "html",style: style, labelpos:'c', label: '<span style="background:#e8e8e8">'+edge.text+'</span>', arrowheadStyle: "fill: #333", arrowhead: aHead},cnt);
}else{
g.setEdge(edge.start, edge.end,{labelType: "text", style: "stroke: #333; stroke-width: 1.5px;fill:none", labelpos:'c', label: edgeText, arrowheadStyle: "fill: #333", arrowhead: aHead},cnt);
@@ -26237,14 +26236,12 @@ exports.draw = function (text, id,isDot) {
//te.text(subGraphs[subGraphs.length-i-1].title);
te.text(subG.title);
console.log('Setting subg - '+i+' to title '+subGraphs[pos].title);
}
}
}
};
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"../../d3":87,"./dagre-d3":91,"./graphDb":93,"./parser/dot":94,"./parser/flow":95}],93:[function(require,module,exports){
/**
* Created by knut on 14-11-03.
@@ -31047,6 +31044,7 @@ var he = require('he');
var mermaidAPI = require('./mermaidAPI');
var nextId = 0;
module.exports.mermaidAPI = mermaidAPI;
/**
* Function that goes through the document to find the chart definitions in there and render them.
*
@@ -31065,12 +31063,12 @@ var nextId = 0;
* c-->|No |d(Transform);
* ```
*/
/**
* Renders the mermaid diagrams
* @* param nodes- a css selector or an array of nodes
*/
var init = function () {
console.log('In mermaid.init');
var nodes;
if(arguments.length === 2){
// sequence config was passed as #1
@@ -31091,9 +31089,7 @@ var init = function () {
: nodes;
var i;
console.log('Found ',nodes.length,' nodes');
console.log('Hooo hooo');
if(typeof mermaid_config !== 'undefined'){
mermaidAPI.initialize(mermaid_config);
}
@@ -31127,14 +31123,20 @@ var init = function () {
exports.tester = function(){};
exports.init = init;
/**
* Function returning version information
* @returns {string} A string containing the version info
*/
exports.version = function(){
return require('../package.json').version;
return 'v'+require('../package.json').version;
};
exports.initialize = function(config){
mermaidAPI.initialize(config);
}
var equals = function (val, variable){
if(typeof variable === 'undefined'){
return false;
@@ -31151,6 +31153,9 @@ global.mermaid = {
init: function(sequenceConfig, nodes) {
init.apply(null, arguments);
},
initialize: function(config) {
mermaidAPI.initialize(config);
},
version: function() {
return mermaidAPI.version();
},
@@ -31167,10 +31172,8 @@ global.mermaid = {
};
exports.contentLoaded = function(){
console.log('Content loaded');
// Check state of start config mermaid namespace
console.log('Starting mermaid');
console.log('global.mermaid.startOnLoad',global.mermaid.startOnLoad);
console.log('mermaid_config',mermaid_config);
if (typeof mermaid_config !== 'undefined') {
if (equals(false, mermaid_config.htmlLabels)) {
global.mermaid.htmlLabels = false;
@@ -31187,9 +31190,18 @@ exports.contentLoaded = function(){
}
}
else {
// No config found, do autostart in this simple case
// No config found, do check API config
var config = mermaidAPI.getConfig();
if(config.startOnLoad){
global.mermaid.init();
}
}
}else{
var config = mermaidAPI.getConfig();
if(config.startOnLoad){
global.mermaid.init();
}
}
};
@@ -31228,12 +31240,11 @@ var nextId = 0;
// Default options, can be overridden at initialization time
var config = {
mermaid:{
cloneCssStyles: true
},
cloneCssStyles: true,
flowchart:{
// Default is to not set width
// width: 1200
htmlLabels:true
},
sequenceDiagram:{
diagramMarginX:50,
@@ -31289,7 +31300,7 @@ var config = {
return d.getMonth();
}]
] }
}
};
/**
* Function that parses a mermaid diagram defintion. If parsing fails the parseError callback is called and an error is
@@ -31331,6 +31342,7 @@ var parse = function(text){
return false;
}
};
exports.parse = parse;
/**
* Function returning version information
@@ -31360,7 +31372,7 @@ var render = function(id, txt,cb){
case 'graph':
flowRenderer.setConf(config.flowchart);
flowRenderer.draw(txt, id, false);
if(config.mermaid.cloneCssStyles){
if(config.cloneCssStyles){
classes = flowRenderer.getClasses(txt, false);
utils.cloneCssStyles(element.firstChild, classes);
}
@@ -31369,7 +31381,7 @@ var render = function(id, txt,cb){
case 'dotGraph':
flowRenderer.setConf(config.flowchart);
flowRenderer.draw(txt, id, true);
if(config.mermaid.cloneCssStyles) {
if(config.cloneCssStyles) {
classes = flowRenderer.getClasses(txt, true);
utils.cloneCssStyles(element.firstChild, classes);
}
@@ -31379,20 +31391,20 @@ var render = function(id, txt,cb){
seq.setConf(config.sequenceDiagram);
//}
seq.draw(txt,id);
if(config.mermaid.cloneCssStyles) {
if(config.cloneCssStyles) {
utils.cloneCssStyles(element.firstChild, []);
}
break;
case 'gantt':
gantt.setConf(config.gantt);
gantt.draw(txt,id);
if(config.mermaid.cloneCssStyles) {
if(config.cloneCssStyles) {
utils.cloneCssStyles(element.firstChild, []);
}
break;
case 'info':
info.draw(txt,id,exports.version());
if(config.mermaid.cloneCssStyles) {
if(config.cloneCssStyles) {
utils.cloneCssStyles(element.firstChild, []);
}
break;
@@ -31407,45 +31419,7 @@ var render = function(id, txt,cb){
exports.render = function(id, text,cb){
if(typeof document === 'undefined'){
//jsdom = require('jsdom').jsdom;
//console.log(jsdom);
//htmlStub = '<html><head></head><body><div class="mermaid">'+text+'</div><script src="dist/mermaid.full.js"></script><script>var mermaid_config = {startOnLoad:true}</script></body></html>';
htmlStub = '<html><head></head><body></body></html>';
// // html file skull with a container div for the d3 dataviz
//
// pass the html stub to jsDom
/* jsdom.env({
features : { QuerySelectorAll : true },
html : htmlStub,
done : function(errors, win) {
// process the html document, like if we were at client side
// code to generate the dataviz and process the resulting html file to be added here
//var d3 = require('d3');
//console.log('Here we go: '+JSON.stringify(d3));
global.document = win.document;
global.window = win;
var element = win.document.createElement('div');
element.setAttribute('id','did');
//document.
console.log(document.body.innerHTML);
//console.log('Element:',element);
//console.log(win);
//mermaid.init();
//render(win.document, 'myId', text, callback);
}
});*/
//var jsdom = require('jsdom').jsdom;
//global.document = jsdom(htmlStub);
//global.window = document.parentWindow;
//
//render(id, text, cb);
//var element = win.document.createElement('div');
//element.setAttribute('id','did');
//document.
// Todo handle rendering serverside using phantomjs
}
else{
// In browser
@@ -31459,55 +31433,41 @@ var setConf = function(cnf){
var lvl1Keys = Object.keys(cnf);
var i;
for(i=0;i<lvl1Keys.length;i++){
var lvl2Keys = Object.keys(cnf[lvl1Keys[i]]);
var j;
for(j=0;j<lvl2Keys.length;j++) {
console.log('Setting conf ',lvl1Keys[i],'-',lvl2Keys[j])
config[lvl1Keys[i]][lvl2Keys[j]] = cnf[lvl1Keys[i]][lvl2Keys[j]];
if(typeof cnf[lvl1Keys[i]] === 'object' ){
var lvl2Keys = Object.keys(cnf[lvl1Keys[i]]);
var j;
for(j=0;j<lvl2Keys.length;j++) {
//console.log('Setting conf ',lvl1Keys[i],'-',lvl2Keys[j]);
if(typeof config[lvl1Keys[i]] === 'undefined'){
config[lvl1Keys[i]] = {};
}
config[lvl1Keys[i]][lvl2Keys[j]] = cnf[lvl1Keys[i]][lvl2Keys[j]];
}
}else{
config[lvl1Keys[i]] = cnf[lvl1Keys[i]];
}
}
};
exports.initialize = function(options){
// Update default config with options supplied at initialization
console.log('In init:'+typeof options,JSON.stringify(options))
if(typeof options === 'object'){
setConf(options);
}
console.log('Done init:'+typeof options,JSON.stringify(config))
};
exports.getConfig = function(){
return config;
};
global.mermaidAPI = {
render : exports.render,
render : exports.render,
parse : exports.parse,
initialize : exports.initialize,
detectType: utils.detectType
detectType : utils.detectType
};
//var getBBox = function(selector){
// var xmin, xmax, ymin, ymax,p;
// // clean up path
// var t = d3.select(selector).attr("d"); // get svg line's code
// console.log(t)
// t = t.replace(/[a-z].*/g," ") // remove relative coords, could rather tag it for later processing to absolute!
// .replace(/[\sA-Z]+/gi," ").trim().split(" "); // remove letters and simplify spaces.
// console.log(t)
//
// for(var i in t){ // set valid initial values
// if(t[i].length>1){
// p = t[i].split(",");
// xmin = xmax = p[0]; ymin = ymax = p[1]; }
// }
// for(var i in t){ // update xmin,xmax,ymin,ymax
// p = t[i].split(",");
// if(!p[1]){ p[0]=xmin; p[1] = ymin;} // ignore relative jumps such h20 v-10
// xmin = Math.min(xmin, p[0]);
// xmax = Math.max(xmax, p[0]);
// ymin = Math.min(ymin, p[1]);
// ymax = Math.max(ymax, p[1]);
// } return [[xmin,ymax],[xmax,ymin]]; // [[left, bottom], [right, top]] as for https://github.com/mbostock/d3/wiki/Geo-Paths#bounds
//}
//var bb = getBBox("path");
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"../package.json":86,"./d3":87,"./diagrams/example/exampleDb":88,"./diagrams/example/exampleRenderer":89,"./diagrams/example/parser/example":90,"./diagrams/flowchart/flowRenderer":92,"./diagrams/flowchart/graphDb":93,"./diagrams/flowchart/parser/dot":94,"./diagrams/flowchart/parser/flow":95,"./diagrams/gantt/ganttDb":96,"./diagrams/gantt/ganttRenderer":97,"./diagrams/gantt/parser/gantt":98,"./diagrams/sequenceDiagram/parser/sequenceDiagram":99,"./diagrams/sequenceDiagram/sequenceDb":100,"./diagrams/sequenceDiagram/sequenceRenderer":101,"./utils":105}],105:[function(require,module,exports){
/**