@@ -50,7 +50,10 @@ function addDummy(sources, targets, obj, options, directionS, directionT){
50
50
51
51
}
52
52
53
+ let id2log = id => id . replace ( / \- c o m p o n e n t s / g, '' ) . replace ( / _ _ o r i g i n / g, '' ) . replace ( / _ _ t e r m i n u s / g, '' )
54
+
53
55
function drawNodeNew ( id , label , type , properties , options ) {
56
+ //console.log(id)
54
57
let o = {
55
58
id : id ,
56
59
label : label ,
@@ -73,12 +76,26 @@ function drawNodeNew(id, label, type, properties, options){
73
76
}
74
77
o . visited = visited [ id ] ;
75
78
}
76
- else if ( visited [ id ] ) {
77
- if ( type === 'action' ) {
78
- visited [ id ] . forEach ( ( v , i ) => { visited [ id ] [ i ] ++ } ) ; // for actions, increase all index by one to point to the next activation in the array.
79
+ else {
80
+ let iid = id2log ( id )
81
+ if ( visited [ iid ] ) {
82
+ if ( type === 'action' ) {
83
+ visited [ iid ] . forEach ( ( v , i ) => { visited [ iid ] [ i ] ++ } ) ; // for actions, increase all index by one to point to the next activation in the array.
84
+ }
85
+
86
+ if ( type === 'retain' ) {
87
+ if ( ( visited [ iid ] . length >= 1 && id . endsWith ( '__origin' ) ) || ( visited [ iid ] . length === 2 && id . endsWith ( '__terminus' ) ) ) {
88
+ o . visited = visited [ iid ] ;
89
+ }
90
+ }
91
+ else {
92
+ o . visited = visited [ iid ] ;
93
+ }
94
+
79
95
}
80
- o . visited = visited [ id ] ;
96
+ //console.log("iid:", id, iid, visited[iid], o.visited)
81
97
}
98
+
82
99
}
83
100
84
101
if ( visited && ( visited [ id ] || id === 'Entry' ) )
@@ -175,16 +192,19 @@ function drawNodeNew(id, label, type, properties, options){
175
192
ports : [ ] ,
176
193
properties : { } ,
177
194
children : [ ] ,
178
- edges : [ ]
195
+ edges : [ ] ,
196
+ visited : visited ? visited [ id2log ( `${ id } -body` ) ] : undefined
179
197
} , {
180
198
id : `${ id } -handler` ,
181
199
label : 'error handler' ,
182
200
type : 'handler' ,
183
201
ports : [ ] ,
184
202
properties : { } ,
185
203
children : [ ] ,
186
- edges : [ ]
204
+ edges : [ ] ,
205
+ visited : visited ? visited [ id2log ( `${ id } -handler` ) ] : undefined
187
206
} ] ;
207
+
188
208
o . edges = [ drawEdgeNew ( `${ id } -body` , `${ id } -handler` , o , undefined , 'RIGHT' ) ] ;
189
209
}
190
210
else if ( o . type === 'Entry' || o . type === 'Exit' ) {
@@ -200,7 +220,8 @@ function drawNodeNew(id, label, type, properties, options){
200
220
o . height = 4 ;
201
221
// Dummy node's `properties` is `sources`, used to determine if the dummy is visited
202
222
if ( visited && Array . isArray ( properties ) ) {
203
- properties . forEach ( s => { // a source id
223
+ properties . forEach ( s => { // a source id
224
+ s = id2log ( s ) ;
204
225
if ( visited [ s ] ) { // if the source is visited
205
226
visited [ s ] . forEach ( a => { // find out if any of its activation was success
206
227
if ( activations [ a ] . response . success ) { // if so, dummy is visited
@@ -291,16 +312,21 @@ function drawEdgeNew(sourceId, targetId, layer, type, direction, sourcePort, tar
291
312
sourcePort : sourcePort ,
292
313
target : targetId ,
293
314
targetPort : targetPort ,
294
- visited : ( visited && visited [ sourceId ] && visited [ targetId ] )
315
+ // visited: (visited && visited[sourceId] && visited[targetId])
295
316
} ;
296
317
}
297
318
298
319
function ir2graph ( ir , gm , id , prevId , options = { } ) { // ir and graph model
299
- if ( Array . isArray ( ir ) ) {
320
+ if ( ir . type === 'sequence' || Array . isArray ( ir ) ) {
300
321
// for an array of things, prevId is the previous element
301
322
// console.log(ir, gm, id, prevId);
302
- let count = 0 , prev ;
303
- ir . forEach ( obj => {
323
+ let count = 0 , prev , array ;
324
+ if ( ir . type === 'sequence' )
325
+ array = ir . components
326
+ else
327
+ array = ir
328
+
329
+ array . forEach ( obj => {
304
330
if ( obj . options && obj . options . helper ) {
305
331
// do nothing
306
332
}
@@ -314,6 +340,7 @@ function ir2graph(ir, gm, id, prevId, options={}){ // ir and graph model
314
340
return prev ;
315
341
}
316
342
else {
343
+ //id = `${id}-${ir.type}`
317
344
if ( ir . type === 'action' ) {
318
345
let name = ir . name ;
319
346
if ( ir . displayLabel )
@@ -324,7 +351,7 @@ function ir2graph(ir, gm, id, prevId, options={}){ // ir and graph model
324
351
return [ id ] ;
325
352
}
326
353
else if ( ir . type === 'function' ) {
327
- gm . children . push ( drawNodeNew ( id , ir . exec . code , ir . type , undefined , options ) )
354
+ gm . children . push ( drawNodeNew ( id , ir . function . exec . code , ir . type , undefined , options ) )
328
355
329
356
if ( prevId )
330
357
prevId . forEach ( pid => gm . edges . push ( drawEdgeNew ( pid , id , gm ) ) ) ;
@@ -372,15 +399,15 @@ function ir2graph(ir, gm, id, prevId, options={}){ // ir and graph model
372
399
tryPart = tryCatchPart . children [ 0 ] ,
373
400
catchPart = tryCatchPart . children [ 1 ]
374
401
375
- ir2graph ( ir . body , tryPart , tryPart . id , undefined , options ) ;
376
- ir2graph ( ir . handler , catchPart , catchPart . id , undefined , options ) ;
402
+ ir2graph ( ir . body , tryPart , tryPart . id + '-components' , undefined , options ) ;
403
+ ir2graph ( ir . handler , catchPart , catchPart . id + '-components' , undefined , options ) ;
377
404
378
405
return [ gm . children [ gm . children . length - 1 ] . id ] ;
379
406
}
380
- else if ( ir . type === 'while' || ir . type === 'dowhile' ) {
407
+ else if ( ir . type === 'while' || ir . type === 'dowhile' || ir . type === 'while_nosave' || ir . type === 'dowhile_nosave' ) {
381
408
let firstTestId , firstBodyId , lastTestId , lastBodyId ;
382
409
383
- if ( ir . type === 'while' ) {
410
+ if ( ir . type === 'while' || ir . type === 'while_nosave' ) {
384
411
firstTestId = gm . children . length ;
385
412
lastTestId = ir2graph ( ir . test , gm , `${ id } -test` , undefined , options ) ;
386
413
if ( prevId ) // connect prevId to the first node in test
@@ -427,7 +454,7 @@ function ir2graph(ir, gm, id, prevId, options={}){ // ir and graph model
427
454
if ( prevId ) {
428
455
prevId . forEach ( pid => gm . edges . push ( drawEdgeNew ( pid , `${ id } __origin` , gm ) ) ) ;
429
456
}
430
- let lastNodes = ir2graph ( ir . body , gm , ` ${ id } -body` , [ `${ id } __origin` ] , options ) ;
457
+ let lastNodes = ir2graph ( ir . components , gm , id , [ `${ id } __origin` ] , options ) ;
431
458
gm . children . push ( drawNodeNew ( `${ id } __terminus` , '' , ir . type , undefined , options ) ) ;
432
459
if ( lastNodes ) {
433
460
lastNodes . forEach ( pid => gm . edges . push ( drawEdgeNew ( pid , `${ id } __terminus` , gm ) ) ) ;
@@ -440,41 +467,26 @@ function ir2graph(ir, gm, id, prevId, options={}){ // ir and graph model
440
467
441
468
return [ `${ id } __terminus` ] ;
442
469
}
443
- else if ( ir . type === 'let' ) {
444
- if ( ir . body && ir . body . length > 0 && ir . body [ 0 ] . options && ir . body [ 0 ] . options . helper === 'retry_1' ) {
445
- // retry, insert a compound node
446
- gm . children . push ( drawNodeNew ( id , ir . declarations . count , 'retry' , undefined , options ) ) ;
447
- if ( prevId ) {
448
- prevId . forEach ( pid => gm . edges . push ( drawEdgeNew ( pid , id , gm ) ) ) ;
449
- }
450
- // body is in ir.body[1].body[0].finalizer[0].body[0].body
451
- ir2graph ( ir . body [ 1 ] . body [ 0 ] . finalizer [ 0 ] . body [ 0 ] . body , gm . children [ gm . children . length - 1 ] , `${ id } -body-1-body-0-finalizer-0-body-0-body` , undefined , options ) ;
452
-
453
- return [ gm . children [ gm . children . length - 1 ] . id ] ;
454
-
455
- }
456
- else if ( ir . body && ir . body . length > 0 && ir . body [ 0 ] . test && ir . body [ 0 ] . test . length > 0 && ir . body [ 0 ] . test [ 0 ] . options && ir . body [ 0 ] . test [ 0 ] . options . helper === 'repeat_1' ) {
457
- // repeat, insert a compound node
458
- gm . children . push ( drawNodeNew ( id , ir . declarations . count , 'repeat' , undefined , options ) ) ;
459
- if ( prevId ) {
460
- prevId . forEach ( pid => gm . edges . push ( drawEdgeNew ( pid , id , gm ) ) ) ;
461
- }
462
- // body is in ir.body[0].body
463
- ir2graph ( ir . body [ 0 ] . body , gm . children [ gm . children . length - 1 ] , `${ id } -body-0-body` , undefined , options ) ;
464
-
465
- return [ gm . children [ gm . children . length - 1 ] . id ] ;
470
+ else if ( ir . type === 'retry' || ir . type === 'repeat' ) {
471
+ gm . children . push ( drawNodeNew ( id , ir . count , ir . type , undefined , options ) ) ;
472
+ if ( prevId ) {
473
+ prevId . forEach ( pid => gm . edges . push ( drawEdgeNew ( pid , id , gm ) ) ) ;
466
474
}
467
- else {
468
- // regular let
469
- let s = JSON . stringify ( ir . declarations , undefined , 4 ) ;
470
- gm . children . push ( drawNodeNew ( id , s , ir . type , undefined , options ) )
471
- if ( prevId )
472
- prevId . forEach ( pid => gm . edges . push ( drawEdgeNew ( pid , id , gm ) ) ) ;
475
+ // body is in ir.components
476
+ ir2graph ( ir . components , gm . children [ gm . children . length - 1 ] , `${ id } -components` , undefined , options ) ;
477
+
478
+ return [ gm . children [ gm . children . length - 1 ] . id ] ;
479
+ }
480
+ else if ( ir . type === 'let' ) {
481
+ // regular let
482
+ let s = JSON . stringify ( ir . declarations , undefined , 4 ) ;
483
+ gm . children . push ( drawNodeNew ( id , s , ir . type , undefined , options ) )
484
+ if ( prevId )
485
+ prevId . forEach ( pid => gm . edges . push ( drawEdgeNew ( pid , id , gm ) ) ) ;
473
486
474
- return ir2graph ( ir . body , gm , `${ id } -body` , [ id ] , options ) ;
475
- }
487
+ return ir2graph ( ir . components , gm , `${ id } -components` , [ id ] , options ) ;
476
488
}
477
- else if ( ir . type === 'literal' ) {
489
+ else if ( ir . type === 'literal' || ir . type === 'value' ) {
478
490
const s = JSON . stringify ( ir . value , undefined , 4 ) ;
479
491
gm . children . push ( drawNodeNew ( id , s , ir . type , undefined , options ) )
480
492
if ( prevId )
@@ -486,7 +498,7 @@ function ir2graph(ir, gm, id, prevId, options={}){ // ir and graph model
486
498
let lastBodyNode = ir2graph ( ir . body , gm , `${ id } -body` , prevId , undefined , options ) ;
487
499
return ir2graph ( ir . finalizer , gm , `${ id } -finalizer` , lastBodyNode , undefined , options ) ;
488
500
}
489
- else if ( typeof ir . body === 'object' ) {
501
+ else if ( typeof ir . components === 'object' ) {
490
502
// generic handler for any subgraph-via-body node
491
503
const label = capitalize ( ir . type ) ,
492
504
type = ir . type ,
@@ -499,13 +511,13 @@ function ir2graph(ir, gm, id, prevId, options={}){ // ir and graph model
499
511
if ( prevId )
500
512
prevId . forEach ( pid => gm . edges . push ( drawEdgeNew ( pid , id , gm ) ) ) ;
501
513
502
- ir2graph ( ir . body , body , `${ id } -body ` , undefined , options )
514
+ ir2graph ( ir . components , body , `${ id } -components ` , undefined , options )
503
515
504
516
return [ id ]
505
517
506
518
} else {
507
519
console . error ( 'wskflow warning! unsupported node type' , ir )
508
- }
520
+ }
509
521
}
510
522
}
511
523
@@ -533,7 +545,7 @@ function fsm2graph(ir, containerElement, acts, options){
533
545
activations . forEach ( ( a , index ) => {
534
546
if ( a . logs ) { // states recorded in logs
535
547
a . logs . forEach ( log => {
536
- if ( log . indexOf ( 'stdout: Entering state ' ) !== - 1 ) {
548
+ if ( log . indexOf ( 'stdout: Entering composition ' ) !== - 1 ) {
537
549
// a conductor path log
538
550
let path = log . substring ( log . lastIndexOf ( ' ' ) + 1 ) ;
539
551
// replace all [,],.in path to - to use as a id, as css selector cannot have those characters
@@ -564,7 +576,7 @@ function fsm2graph(ir, containerElement, acts, options){
564
576
viewOptions = Object . assign ( { renderFunctionsInView } , options )
565
577
566
578
graphData . children . push ( drawNodeNew ( 'Entry' , 'start' , 'Entry' ) ) ; // insert Entry node
567
- let lastNodes = ir2graph ( ir . composition , graphData , 'fsm ' , [ 'Entry' ] , // build the graph model, link the start of the graph to Entry
579
+ let lastNodes = ir2graph ( ir , graphData , 'composition ' , [ 'Entry' ] , // build the graph model, link the start of the graph to Entry
568
580
viewOptions ) ; // <-- options to the rendering
569
581
if ( lastNodes == undefined )
570
582
lastNodes = [ 'Entry' ] ;
@@ -665,8 +677,8 @@ function fsm2graph(ir, containerElement, acts, options){
665
677
*
666
678
*/
667
679
const isSimpleComposition = ir => {
668
- const isShort = ir . composition . length <= 2 ,
669
- numNonFuncs = numNonFunctions ( ir . composition ) ,
680
+ const isShort = ir . components ? ir . components . length <= 2 : true ,
681
+ numNonFuncs = numNonFunctions ( ir ) ,
670
682
atMostOneNonFunction = numNonFuncs <= 3
671
683
672
684
debug ( 'isSimpleComposition' , isShort , numNonFuncs )
@@ -678,6 +690,7 @@ const isSimpleComposition = ir => {
678
690
*
679
691
*/
680
692
const numNonFunctions = composition => {
693
+ if ( composition === undefined ) return 0
681
694
if ( composition . type === 'function' ) {
682
695
return 0
683
696
} else if ( composition . type ) {
0 commit comments