1
1
/**
2
2
* FlowgorithmJS
3
- * @versione 0.13
3
+ * @versione 0.14
4
+ * @date 2019-02-19
4
5
*/
5
6
var maxW , maxH , flowX = 0 , funX = 0 ;
6
7
var flow ;
@@ -34,10 +35,11 @@ function drawFlowchart($xml,selector,options){
34
35
if ( options . viewDesc ) {
35
36
var title = $xml . find ( 'attribute[name=name]' ) . attr ( 'value' ) ;
36
37
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>' +
41
43
'<a onclick="downloadSVG(\'' + selector + '\',\'' + title + '.svg\')" style="cursor:pointer;text-decoration:underline;color:red">Download SVG</a>' +
42
44
'</div>' ) ;
43
45
}
@@ -60,10 +62,6 @@ function drawFlowchart($xml,selector,options){
60
62
$xml . find ( 'function' ) . each ( function ( ) {
61
63
svg += drawFunction ( $ ( this ) ) ;
62
64
} ) ;
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 ;
67
65
$svg = $output . children ( 'svg' ) ;
68
66
$svg . get ( 0 ) . innerHTML += '<g transform="translate(0,0)">' + svg + '</g>' ;
69
67
$svg . children ( 'g' ) . eq ( 0 ) . remove ( ) ;
@@ -99,9 +97,17 @@ function drawFlowchart($xml,selector,options){
99
97
var s = drawStart ( txtStart ) ;
100
98
s += drawSequence ( $xml . children ( 'body' ) ) ;
101
99
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 ) ;
102
103
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
+ }
105
111
flow . dim . push ( flow . Y + 20 ) ;
106
112
return '<g transform="translate(' + ( tempX ) + ',10)" class="function ' + name + '">' + s + '</g>' ;
107
113
} ;
@@ -251,6 +257,13 @@ function drawFlowchart($xml,selector,options){
251
257
flow . Y += 50 + options . aH ;
252
258
return s ;
253
259
} ;
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
+ } ;
254
267
function splitCondition ( condition ) {
255
268
condition = condition . replace ( / A N D / gi, " && " ) . replace ( / O R / gi, " || " ) ;
256
269
var parts = condition . split ( / & & | \| \| / ) ;
@@ -375,7 +388,7 @@ function drawFlowchart($xml,selector,options){
375
388
var s = '<g class="block" transform="translate(0,' + flow . Y + ')">' + drawArrow ( ) ;
376
389
var oldY = flow . Y ;
377
390
flow . Y = 0 ;
378
- var contentDraw = drawSequence ( $content ) ;
391
+ var contentDraw = ( $content . children ( ) . length > 0 ) ? drawSequence ( $content ) : drawEmptyBlock ( ) ;
379
392
var contentWidth = calcBlockWidth ( contentDraw ) ;
380
393
var half = Math . max ( calcBlockX ( contentDraw ) , 40 ) ;
381
394
flow . Y += 25 ;
0 commit comments