Fix for issue #150.

This commit is contained in:
knsv 2015-05-30 13:00:04 +02:00
parent 3f0ead3e0a
commit 173a2b12aa
13 changed files with 99 additions and 97 deletions

View File

@ -17028,73 +17028,37 @@ exports.draw = function (text, id,isDot) {
// Index nodes // Index nodes
graph.indexNodes('sunGraph'+i); graph.indexNodes('sunGraph'+i);
//setTimeout(function(){ for(i=0;i<subGraphs.length;i++){
var i = 0; var pos = graph.getDepthFirstPos(i);
//subGraphs.forEach(function(subG) { subG = subGraphs[i];
for(i=0;i<subGraphs.length;i++){
var pos = graph.getDepthFirstPos(i);
subG = subGraphs[i];
//var clusterRects = document.querySelectorAll('#' + id + ' .clusters rect'); if (subG.title !== 'undefined') {
//var clusters = document.querySelectorAll('#' + id + ' .cluster'); var clusterRects = document.querySelectorAll('#' + id + ' #' + subG.id + ' rect');
//console.log('looking up: #' + id + ' #' + subG.id)
var clusterEl = document.querySelectorAll('#' + id + ' #' + subG.id);
var xPos = clusterRects[0].x.baseVal.value;
var yPos = clusterRects[0].y.baseVal.value;
var width = clusterRects[0].width.baseVal.value;
var cluster = d3.select(clusterEl[0]);
var te = cluster.append('text');
te.attr('x', xPos + width / 2);
te.attr('y', yPos + 14);
te.attr('fill', 'black');
te.attr('stroke', 'none');
te.attr('id', id + 'Text');
te.style('text-anchor', 'middle');
//if (subG.title !== 'undefined') { if(typeof subG.title === 'undefined'){
// var xPos = clusterRects[i].x.baseVal.value; te.text('Undef');
// var yPos = clusterRects[i].y.baseVal.value; }else{
// var width = clusterRects[i].width.baseVal.value; //te.text(subGraphs[subGraphs.length-i-1].title);
// var cluster = d3.select(clusters[i]); te.text(subG.title);
// var te = cluster.append('text');
// te.attr('x', xPos + width / 2);
// te.attr('y', yPos + 14);
// te.attr('fill', 'black');
// te.attr('stroke', 'none');
// te.attr('id', id + 'Text');
// te.style('text-anchor', 'middle');
//
// if(typeof subGraphs[graph.getDepthFirstPos(i)] === 'undefined'){
// te.text('Undef');
// }else{
// //te.text(subGraphs[subGraphs.length-i-1].title);
// te.text(subGraphs[pos].title);
//
// console.log('Setting subg - '+i+' to title '+subGraphs[pos].title);
// }
//}
console.log('Setting subg - '+i+' to title '+subGraphs[pos].title);
if (subG.title !== 'undefined') {
var clusterRects = document.querySelectorAll('#' + id + ' #' + subG.id + ' rect');
//console.log('looking up: #' + id + ' #' + subG.id)
var clusterEl = document.querySelectorAll('#' + id + ' #' + subG.id);
var xPos = clusterRects[0].x.baseVal.value;
var yPos = clusterRects[0].y.baseVal.value;
var width = clusterRects[0].width.baseVal.value;
var cluster = d3.select(clusterEl[0]);
var te = cluster.append('text');
te.attr('x', xPos + width / 2);
te.attr('y', yPos + 14);
te.attr('fill', 'black');
te.attr('stroke', 'none');
te.attr('id', id + 'Text');
te.style('text-anchor', 'middle');
if(typeof subG.title === 'undefined'){
te.text('Undef');
}else{
//te.text(subGraphs[subGraphs.length-i-1].title);
te.text(subG.title);
console.log('Setting subg - '+i+' to title '+subGraphs[pos].title);
}
} }
} }
// i = i + 1; }
//});
//},20);
//console.log('GTPOD:'+graph.getDepthFirstPos('subGraph0'));
}; };
@ -17120,7 +17084,8 @@ var funs = [];
* @param style * @param style
*/ */
exports.addVertex = function (id, text, type, style) { exports.addVertex = function (id, text, type, style) {
var txt;
if(typeof id === 'undefined'){ if(typeof id === 'undefined'){
return; return;
} }
@ -17132,7 +17097,14 @@ exports.addVertex = function (id, text, type, style) {
vertices[id] = {id: id, styles: [], classes:[]}; vertices[id] = {id: id, styles: [], classes:[]};
} }
if (typeof text !== 'undefined') { if (typeof text !== 'undefined') {
vertices[id].text = text.trim(); txt = text.trim();
// strip quotes if string starts and exnds with a quote
if(txt[0] === '"' && txt[txt.length-1] === '"'){
txt = txt.substring(1,txt.length-1);
}
vertices[id].text = txt;
} }
if (typeof type !== 'undefined') { if (typeof type !== 'undefined') {
vertices[id].type = type; vertices[id].type = type;
@ -17163,6 +17135,11 @@ exports.addLink = function (start, end, type, linktext) {
if (typeof linktext !== 'undefined') { if (typeof linktext !== 'undefined') {
edge.text = linktext.trim(); edge.text = linktext.trim();
// strip quotes if string starts and exnds with a quote
if(edge.text[0] === '"' && edge.text[edge.text.length-1] === '"'){
edge.text = edge.text.substring(1,edge.text.length-1);
}
} }
if (typeof type !== 'undefined') { if (typeof type !== 'undefined') {
@ -19352,7 +19329,7 @@ module.exports.draw = function (text, id) {
w = elem.offsetWidth; w = elem.offsetWidth;
if (typeof w === 'undefined') { if (typeof w === 'undefined') {
w = 800; w = 1200;
} }
var taskArray = gantt.yy.getTasks(); var taskArray = gantt.yy.getTasks();
@ -19360,11 +19337,16 @@ module.exports.draw = function (text, id) {
// Set height based on number of tasks // Set height based on number of tasks
var h = taskArray.length * (conf.barHeight + conf.barGap) + 2 * conf.topPadding; var h = taskArray.length * (conf.barHeight + conf.barGap) + 2 * conf.topPadding;
elem.style.height = h + 'px'; //elem.style.height = h + 'px';
elem.setAttribute('height', h); //elem.setAttribute('height', h);
elem.setAttribute('height', "100%");
// Set viewBox
elem.setAttribute('viewBox','0 0 '+w+' '+h);
var svg = d3.select('#' + id); var svg = d3.select('#' + id);
var dateFormat = d3.time.format("%Y-%m-%d"); var dateFormat = d3.time.format("%Y-%m-%d");
var startDate = d3.min(taskArray, function (d) { var startDate = d3.min(taskArray, function (d) {

View File

@ -28511,7 +28511,7 @@ module.exports.draw = function (text, id) {
w = elem.offsetWidth; w = elem.offsetWidth;
if (typeof w === 'undefined') { if (typeof w === 'undefined') {
w = 800; w = 1200;
} }
var taskArray = gantt.yy.getTasks(); var taskArray = gantt.yy.getTasks();
@ -28519,11 +28519,14 @@ module.exports.draw = function (text, id) {
// Set height based on number of tasks // Set height based on number of tasks
var h = taskArray.length * (conf.barHeight + conf.barGap) + 2 * conf.topPadding; var h = taskArray.length * (conf.barHeight + conf.barGap) + 2 * conf.topPadding;
elem.style.height = h + 'px'; elem.setAttribute('height', "100%");
elem.setAttribute('height', h); // Set viewBox
elem.setAttribute('viewBox','0 0 '+w+' '+h);
var svg = d3.select('#' + id); var svg = d3.select('#' + id);
var dateFormat = d3.time.format("%Y-%m-%d"); var dateFormat = d3.time.format("%Y-%m-%d");
var startDate = d3.min(taskArray, function (d) { var startDate = d3.min(taskArray, function (d) {

File diff suppressed because one or more lines are too long

11
dist/mermaid.js vendored
View File

@ -28511,7 +28511,7 @@ module.exports.draw = function (text, id) {
w = elem.offsetWidth; w = elem.offsetWidth;
if (typeof w === 'undefined') { if (typeof w === 'undefined') {
w = 800; w = 1200;
} }
var taskArray = gantt.yy.getTasks(); var taskArray = gantt.yy.getTasks();
@ -28519,11 +28519,14 @@ module.exports.draw = function (text, id) {
// Set height based on number of tasks // Set height based on number of tasks
var h = taskArray.length * (conf.barHeight + conf.barGap) + 2 * conf.topPadding; var h = taskArray.length * (conf.barHeight + conf.barGap) + 2 * conf.topPadding;
elem.style.height = h + 'px'; elem.setAttribute('height', "100%");
elem.setAttribute('height', h); // Set viewBox
elem.setAttribute('viewBox','0 0 '+w+' '+h);
var svg = d3.select('#' + id); var svg = d3.select('#' + id);
var dateFormat = d3.time.format("%Y-%m-%d"); var dateFormat = d3.time.format("%Y-%m-%d");
var startDate = d3.min(taskArray, function (d) { var startDate = d3.min(taskArray, function (d) {

2
dist/mermaid.min.js vendored

File diff suppressed because one or more lines are too long

11
dist/mermaid.slim.js vendored
View File

@ -19295,7 +19295,7 @@ module.exports.draw = function (text, id) {
w = elem.offsetWidth; w = elem.offsetWidth;
if (typeof w === 'undefined') { if (typeof w === 'undefined') {
w = 800; w = 1200;
} }
var taskArray = gantt.yy.getTasks(); var taskArray = gantt.yy.getTasks();
@ -19303,11 +19303,14 @@ module.exports.draw = function (text, id) {
// Set height based on number of tasks // Set height based on number of tasks
var h = taskArray.length * (conf.barHeight + conf.barGap) + 2 * conf.topPadding; var h = taskArray.length * (conf.barHeight + conf.barGap) + 2 * conf.topPadding;
elem.style.height = h + 'px'; elem.setAttribute('height', "100%");
elem.setAttribute('height', h); // Set viewBox
elem.setAttribute('viewBox','0 0 '+w+' '+h);
var svg = d3.select('#' + id); var svg = d3.select('#' + id);
var dateFormat = d3.time.format("%Y-%m-%d"); var dateFormat = d3.time.format("%Y-%m-%d");
var startDate = d3.min(taskArray, function (d) { var startDate = d3.min(taskArray, function (d) {

File diff suppressed because one or more lines are too long

11
dist/mermaidAPI.js vendored
View File

@ -28178,7 +28178,7 @@ module.exports.draw = function (text, id) {
w = elem.offsetWidth; w = elem.offsetWidth;
if (typeof w === 'undefined') { if (typeof w === 'undefined') {
w = 800; w = 1200;
} }
var taskArray = gantt.yy.getTasks(); var taskArray = gantt.yy.getTasks();
@ -28186,11 +28186,14 @@ module.exports.draw = function (text, id) {
// Set height based on number of tasks // Set height based on number of tasks
var h = taskArray.length * (conf.barHeight + conf.barGap) + 2 * conf.topPadding; var h = taskArray.length * (conf.barHeight + conf.barGap) + 2 * conf.topPadding;
elem.style.height = h + 'px'; elem.setAttribute('height', "100%");
elem.setAttribute('height', h); // Set viewBox
elem.setAttribute('viewBox','0 0 '+w+' '+h);
var svg = d3.select('#' + id); var svg = d3.select('#' + id);
var dateFormat = d3.time.format("%Y-%m-%d"); var dateFormat = d3.time.format("%Y-%m-%d");
var startDate = d3.min(taskArray, function (d) { var startDate = d3.min(taskArray, function (d) {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -98,6 +98,7 @@ cli.prototype.parse = function(argv, next) {
if (options.ganttConfig) { if (options.ganttConfig) {
console.log('Got conf1'+options.ganttConfig);
options.ganttConfig = checkConfig(options.ganttConfig) options.ganttConfig = checkConfig(options.ganttConfig)
console.log('Got conf'+options.ganttConfig); console.log('Got conf'+options.ganttConfig);
} }
@ -128,10 +129,11 @@ cli.prototype.parse = function(argv, next) {
function checkConfig(configPath) { function checkConfig(configPath) {
try { try {
var text = fs.readFileSync(configPath, 'utf8') var text = fs.readFileSync(configPath, 'utf8');
JSON.parse(text) JSON.parse(text)
return text return text
} catch (e) { } catch (e) {
console.log(e);
return null; return null;
} }
} }

View File

@ -44,7 +44,7 @@ var page = webpage.create()
console.log('options'); console.log('options');
console.log(options.ganttConfig); console.log(phantom.args.length);
page.content = [ page.content = [
'<html>' '<html>'
@ -70,6 +70,8 @@ files.forEach(function(file) {
, svgContent , svgContent
, allElements , allElements
console.log('Gantconfig: '+options.ganttConfig);
// this JS is executed in this statement is sandboxed, even though it doesn't // this JS is executed in this statement is sandboxed, even though it doesn't
// look like it. we need to serialize then unserialize the svgContent that's // look like it. we need to serialize then unserialize the svgContent that's
// taken from the DOM // taken from the DOM
@ -230,17 +232,18 @@ function executeInPage(data) {
} }
if(typeof ganttConfig !== undefined && ganttConfig !== 'undefined'){ if(typeof ganttConfig !== undefined && ganttConfig !== 'undefined'){
console.log('Got ganttConfig');
sc = document.createElement("script") sc = document.createElement("script")
scContent = document.createTextNode('mermaid.ganttConfig = JSON.parse(' + JSON.stringify(ganttConfig) + ');') scContent = document.createTextNode('mermaid.ganttConfig = JSON.parse(' + JSON.stringify(ganttConfig) + ');')
sc.appendChild(scContent) sc.appendChild(scContent)
document.body.appendChild(sc) document.body.appendChild(sc)
}else{ }else{
console.log('No gantt config'); console.log('NO gantt config');
} }
mermaid.init(); mermaid.init();
console.log(document.body.outerHTML);
svg = document.querySelector('svg') svg = document.querySelector('svg')
svgValue = xmlSerializer.serializeToString(svg) svgValue = xmlSerializer.serializeToString(svg)

View File

@ -3,7 +3,7 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<script src="../dist/mermaid.full.js"></script> <script src="../dist/mermaid.js"></script>
<link rel="stylesheet" href="../dist/mermaid.forest.css"/> <link rel="stylesheet" href="../dist/mermaid.forest.css"/>
<script> <script>
var mermaid_config = { var mermaid_config = {