From 96a25935acd5c7e926808beebe3d3a93500ee4b0 Mon Sep 17 00:00:00 2001 From: whyzdev Date: Sat, 17 Dec 2016 18:03:11 -0500 Subject: [PATCH] fix warnings per code climate --- .gitignore | 4 +++- src/diagrams/sequenceDiagram/svgDraw.js | 32 ++++++++++++------------- test/cli_test-output.js | 10 ++++---- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index 683edb13e..383d087d4 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,6 @@ bower_components .DS_Store .idea -coverage \ No newline at end of file +coverage + +test/tmp_* diff --git a/src/diagrams/sequenceDiagram/svgDraw.js b/src/diagrams/sequenceDiagram/svgDraw.js index defd454f1..16204c763 100644 --- a/src/diagrams/sequenceDiagram/svgDraw.js +++ b/src/diagrams/sequenceDiagram/svgDraw.js @@ -271,16 +271,14 @@ var _drawTextCandidateFunc = (function() { .attr('x', x + width / 2).attr('y', y + height / 2 + 5) .style('text-anchor', 'middle') .text(content); - for (var key in textAttrs) { - text.attr(key, textAttrs[key]); - } - }; + _setTextAttrs(text, textAttrs); + } function byTspan(content, g, x, y, width, height, textAttrs) { var text = g.append('text') .attr('x', x + width / 2).attr('y', y) .style('text-anchor', 'middle'); - var tspan = text.append('tspan') + text.append('tspan') .attr('x', x + width / 2).attr('dy', '0') .text(content); @@ -293,16 +291,13 @@ var _drawTextCandidateFunc = (function() { if (tspans.length > 0 && tspans[0].length > 0) { tspans = tspans[0]; //set y of to the mid y of the first line - text.attr('y', y + (height/2.- text[0][0].getBBox().height*(1 - 1.0/tspans.length)/2.)) + text.attr('y', y + (height/2.0 - text[0][0].getBBox().height*(1 - 1.0/tspans.length)/2.0)) .attr("dominant-baseline", "central") - .attr("alignment-baseline", "central") + .attr("alignment-baseline", "central"); } } - - for (var key in textAttrs) { - text.attr(key, textAttrs[key]); - } - }; + _setTextAttrs(text, textAttrs); + } function byFo(content, g, x, y, width, height, textAttrs) { var s = g.append('switch'); @@ -315,14 +310,19 @@ var _drawTextCandidateFunc = (function() { text.append('div').style('display', 'table-cell') .style('text-align', 'center').style('vertical-align', 'middle') - .text(content) + .text(content); byTspan(content, s, x, y, width, height, textAttrs); + _setTextAttrs(text, textAttrs); + } - for (var key in textAttrs) { - text.attr(key, textAttrs[key]); + function _setTextAttrs(toText, fromTextAttrsDict) { + for (var key in fromTextAttrsDict) { + if (fromTextAttrsDict.hasOwnProperty(key)) { + toText.attr(key, fromTextAttrsDict[key]); } - }; + } + } return function(conf) { return conf.textPlacement==='fo' ? byFo : ( diff --git a/test/cli_test-output.js b/test/cli_test-output.js index b85355655..9236cd95b 100644 --- a/test/cli_test-output.js +++ b/test/cli_test-output.js @@ -47,7 +47,7 @@ test('output of single png', function(t) { var expected = ['test.mermaid.png'] - opt = clone(singleFile) + var opt = clone(singleFile) opt.outputDir += '_png' opt.png = true @@ -64,7 +64,7 @@ test('output of multiple png', function(t) { var expected = ['test.mermaid.png', 'test2.mermaid.png', 'gantt.mermaid.png', 'sequence.mermaid.png'] - opt = clone(multiFile) + var opt = clone(multiFile) opt.outputDir += '_png' opt.png = true @@ -80,7 +80,7 @@ test('output of single svg', function(t) { var expected = ['test.mermaid.svg'] - opt = clone(singleFile) + var opt = clone(singleFile) opt.outputDir += '_svg' opt.svg = true @@ -97,7 +97,7 @@ test('output of multiple svg', function(t) { var expected = ['test.mermaid.svg', 'test2.mermaid.svg', 'gantt.mermaid.svg', 'sequence.mermaid.svg'] - opt = clone(multiFile) + var opt = clone(multiFile) opt.outputDir += '_svg' opt.svg = true @@ -154,7 +154,7 @@ function verifyFiles(expected, dir, t) { } , function(err) { t.notOk(err, 'all files passed') - var delete_tmps = true + var delete_tmps = false var _rimraf=delete_tmps ? rimraf : function(dir, f) { f(0); } _rimraf(dir, function(rmerr) { t.notOk(rmerr, 'cleaned up')