Skip to content

Commit 5e1fea9

Browse files
committed
Fixed empty iterations \n Fixed functions position
1 parent d527d26 commit 5e1fea9

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

flowgorithm.js

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
* FlowgorithmJS
3-
* @versione 0.13
3+
* @versione 0.14
4+
* @date 2019-02-19
45
*/
56
var maxW,maxH,flowX=0,funX=0;
67
var flow;
@@ -34,10 +35,11 @@ function drawFlowchart($xml,selector,options){
3435
if(options.viewDesc){
3536
var title = $xml.find('attribute[name=name]').attr('value');
3637
var desc = $xml.find('attribute[name=about]').attr('value');
37-
$output.append('<div class="desc" style="margin:0 0 1em;border-bottom:1px solid #aaa;text-align:left">'+desc+'</div><div class="info" style="border:1px dashed #ccc;padding:.5em;font-size:.85em;position:absolute;width:15%;min-width:100px;right:5px">'+
38-
'<div class="title"><strong>'+title+'</strong></div>'+
39-
'<div class="author">'+$xml.find('attribute[name=authors]').attr('value')+'</div>'+
40-
'<div class="date">'+$xml.find('attribute[name=saved]').attr('value')+'</div>'+
38+
$output.append('<div class="desc" style="margin:0;border-bottom:1px solid #aaa;text-align:left">'+desc+'</div>'+
39+
'<div class="info" style="padding:.5em 0;font-size:.85em;text-align:left">'+
40+
'<span class="title"><strong>'+title+'</strong> </span>'+
41+
'<span class="author">'+$xml.find('attribute[name=authors]').attr('value')+' </span>'+
42+
'<span class="date">'+$xml.find('attribute[name=saved]').attr('value')+' </span>'+
4143
'<a onclick="downloadSVG(\''+selector+'\',\''+title+'.svg\')" style="cursor:pointer;text-decoration:underline;color:red">Download SVG</a>'+
4244
'</div>');
4345
}
@@ -60,10 +62,6 @@ function drawFlowchart($xml,selector,options){
6062
$xml.find('function').each(function(){
6163
svg += drawFunction($(this));
6264
});
63-
$('#ttest').empty().get(0).append(svg);
64-
var x = $('#ttest').get(0).getBBox().x/100;
65-
var h = Math.max.apply(Math,flow.dim);
66-
var w = funX;
6765
$svg = $output.children('svg');
6866
$svg.get(0).innerHTML += '<g transform="translate(0,0)">'+svg+'</g>';
6967
$svg.children('g').eq(0).remove();
@@ -99,9 +97,17 @@ function drawFlowchart($xml,selector,options){
9997
var s = drawStart(txtStart);
10098
s += drawSequence($xml.children('body'));
10199
s += drawEnd(txtEnd);
100+
$('#gtest').get(0).innerHTML = '<g transform="translate(0,0)">'+s+'</g>';
101+
var fwidth = $('#gtest').children('g').get(0).getBBox().width+5;
102+
var fx = Math.abs($('#gtest').children('g').get(0).getBBox().x);
102103
var tempX = funX;
103-
funX += (maxW+102);
104-
if(maxW==0) maxW=2;
104+
if(tempX!=0){
105+
tempX+=fx;
106+
funX+=fwidth;
107+
}
108+
else{
109+
funX=fwidth-fx;
110+
}
105111
flow.dim.push(flow.Y+20);
106112
return '<g transform="translate('+(tempX)+',10)" class="function '+name+'">'+s+'</g>';
107113
};
@@ -251,6 +257,13 @@ function drawFlowchart($xml,selector,options){
251257
flow.Y += 50+options.aH;
252258
return s;
253259
};
260+
function drawEmptyBlock(){
261+
var s = '<g class="block" transform="translate(0,'+flow.Y+')">'+
262+
'<polyline class="line" points="0,0 0,'+(options.aH*3)+'" />'+
263+
'</g>';
264+
flow.Y += options.aH*3;
265+
return s;
266+
};
254267
function splitCondition(condition){
255268
condition = condition.replace(/ AND /gi," && ").replace(/ OR /gi," || ");
256269
var parts = condition.split(/&&|\|\|/);
@@ -375,7 +388,7 @@ function drawFlowchart($xml,selector,options){
375388
var s = '<g class="block" transform="translate(0,'+flow.Y+')">'+drawArrow();
376389
var oldY = flow.Y;
377390
flow.Y = 0;
378-
var contentDraw = drawSequence($content);
391+
var contentDraw = ($content.children().length>0) ? drawSequence($content) : drawEmptyBlock();
379392
var contentWidth = calcBlockWidth(contentDraw);
380393
var half = Math.max(calcBlockX(contentDraw),40);
381394
flow.Y += 25;

0 commit comments

Comments
 (0)