Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix gantt and sequence digram cli cfg #435

Merged
merged 2 commits into from
Dec 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions lib/phantomscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ function executeInPage(data) {
var xmlSerializer = new XMLSerializer()
, contents = data.contents
, sequenceConfig = JSON.stringify(data.sequenceConfig)
, ganttConfig = JSON.stringify(data.ganttConfig).replace(/"(function.*)}"/, "$1")
, ganttConfig = JSON.stringify(data.ganttConfig).replace(/"(function.*})"/, "$1")
, toRemove
, el
, elContent
Expand All @@ -222,35 +222,28 @@ function executeInPage(data) {
, height
, confWidth = data.confWidth

toRemove = document.getElementsByClassName('mermaid')
var toRemove = document.getElementsByClassName('mermaid')
if (toRemove && toRemove.length) {
for (var i = 0, len = toRemove.length; i < len; i++) {
toRemove[i].parentNode.removeChild(toRemove[i])
}
}

el = document.createElement("div")
var el = document.createElement("div")
el.className = 'mermaid'
elContent = document.createTextNode(contents)
el.appendChild(elContent)
//el.innerText = '<b>hello</b>\uD800' //contents;

el.appendChild(document.createTextNode(contents))
document.body.appendChild(el)

var config = {
sequenceDiagram: sequenceConfig,
sequenceDiagram: JSON.parse(sequenceConfig),
flowchart: {useMaxWidth: false},
logLevel: 1
};

mermaid.initialize(config);

//console.log('after initialize',sequenceConfig);

sc = document.createElement("script")
scContent = document.createTextNode('mermaid.ganttConfig = ' + ganttConfig + ';')
sc.appendChild(scContent)

var sc = document.createElement("script")
sc.appendChild(document.createTextNode('mermaid.ganttConfig = ' + ganttConfig + ';'))
document.body.appendChild(sc)

mermaid.init();
Expand Down
4 changes: 2 additions & 2 deletions src/diagrams/sequenceDiagram/sequenceRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ var conf = {
// width of activation box
activationWidth:10,

//text placement as: tspan | fo | <else> only text as before
textPlacement: 'fo',
//text placement as: tspan | fo | old only text as before
textPlacement: 'tspan',
};

exports.bounds = {
Expand Down
2 changes: 1 addition & 1 deletion src/diagrams/sequenceDiagram/svgDraw.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,6 @@ var _drawTextCandidateFunc = (function() {

return function(conf) {
return conf.textPlacement==='fo' ? byFo : (
conf.textPlacement==='tspan' ? byTspan : byText);
conf.textPlacement==='old' ? byText: byTspan);
};
})();
3 changes: 1 addition & 2 deletions src/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ function Log(level) {
args.unshift('[' + formatTime(new Date()) + '] ');
console.log.apply(console, args.map(function(a){
if (typeof a === "object") {
if (a.stack !== undefined) { return a.stack; }
return JSON.stringify(a, null, 2);
return a.toString() + JSON.stringify(a, null, 2);
}
return a;
}));
Expand Down
40 changes: 22 additions & 18 deletions test/cli_test-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,27 @@ var isWin = /^win/.test(process.platform);
var phantomCmd;
if(isWin){
phantomCmd = 'node_modules/.bin/phantomjs.cmd'
console.log('is win');
console.log('is win');
console.log('is win')
}
else{
phantomCmd = 'node_modules/.bin/phantomjs'
}
var singleFile = {
files: [fileTestMermaid]
, outputDir: path.join(process.cwd(),'test/tmp2/')
, outputDir: path.join(process.cwd(),'test/tmp_single')
, phantomPath: path.join(process.cwd(),phantomCmd)
, width : 1200
, css: path.join(__dirname, '..', 'dist', 'mermaid.css')
, sequenceConfig: null
, ganttConfig: null
}
, multiFile = {
files: [path.join('test','fixtures','test.mermaid'), path.join('test','fixtures','test2.mermaid')]
, outputDir: 'test/tmp2/'
files: [path.join('test','fixtures','test.mermaid'),
path.join('test','fixtures','test2.mermaid'),
path.join('test','fixtures','gantt.mermaid'),
path.join('test','fixtures','sequence.mermaid'),
]
, outputDir: 'test/tmp_multi'
, phantomPath: path.join(process.cwd(),phantomCmd)
, width : 1200
, css: path.join(__dirname, '..', 'dist', 'mermaid.css')
Expand All @@ -45,6 +48,7 @@ test('output of single png', function(t) {
var expected = ['test.mermaid.png']

opt = clone(singleFile)
opt.outputDir += '_png'
opt.png = true

mermaid.process(opt.files, opt, function(code) {
Expand All @@ -57,9 +61,11 @@ test('output of single png', function(t) {
test('output of multiple png', function(t) {
t.plan(3)

var expected = ['test.mermaid.png', 'test2.mermaid.png']
var expected = ['test.mermaid.png', 'test2.mermaid.png',
'gantt.mermaid.png', 'sequence.mermaid.png']

opt = clone(multiFile)
opt.outputDir += '_png'
opt.png = true

mermaid.process(opt.files, opt, function(code) {
Expand All @@ -75,6 +81,7 @@ test('output of single svg', function(t) {
var expected = ['test.mermaid.svg']

opt = clone(singleFile)
opt.outputDir += '_svg'
opt.svg = true

mermaid.process(opt.files, opt, function(code) {
Expand All @@ -87,9 +94,11 @@ test('output of single svg', function(t) {
test('output of multiple svg', function(t) {
t.plan(3)

var expected = ['test.mermaid.svg', 'test2.mermaid.svg']
var expected = ['test.mermaid.svg', 'test2.mermaid.svg',
'gantt.mermaid.svg', 'sequence.mermaid.svg']

opt = clone(multiFile)
opt.outputDir += '_svg'
opt.svg = true

mermaid.process(opt.files, opt, function(code) {
Expand All @@ -110,28 +119,22 @@ test('output including CSS', function(t) {
, two

opt.png = true
opt.outputDir += '_css_png'
opt2.png = true
opt2.outputDir += '_css_png'


mermaid.process(opt.files, opt, function(code) {
t.equal(code, 0, 'has clean exit code')
filename = path.join(opt.outputDir, path.basename(expected[0]))
one = fs.statSync(filename)
//console.log('one: '+opt.files[0]);

opt2.css = path.join('test','fixtures','test.css')
//console.log(opt2.css);

console.log('Generating #2');
//console.log('two: '+opt2.files[0]);
console.log('Generating #2');
mermaid.process(opt2.files, opt2, function(code) {
t.equal(code, 0, 'has clean exit code')
two = fs.statSync(filename)

//console.log('one: '+one.size);
//console.log('two: '+two.size);


t.notEqual(one.size, two.size)

verifyFiles(expected, opt.outputDir, t)
Expand All @@ -151,8 +154,9 @@ function verifyFiles(expected, dir, t) {
}
, function(err) {
t.notOk(err, 'all files passed')

rimraf(dir, function(rmerr) {
var delete_tmps = true
var _rimraf=delete_tmps ? rimraf : function(dir, f) { f(0); }
_rimraf(dir, function(rmerr) {
t.notOk(rmerr, 'cleaned up')
t.end()
})
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/gantt.mermaid
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
gantt
dateFormat YYYY-MM-DD
title Adding GANTT diagram functionality to mermaid
section A section
Completed task :done, des1, 2014-01-06,2014-01-08
Active task :active, des2, 2014-01-09, 3d
Future task : des3, after des2, 5d
Future task2 : des4, after des3, 5d