@@ -77,16 +77,31 @@ const wfColorAct = {
7777 inactiveBorder : "grey"
7878}
7979
80+ const containerId = 'wskflowDiv' ;
81+
8082// need to fix center
81- function graph2doms ( JSONgraph , containerId , activations ) {
83+ function graph2doms ( JSONgraph , ifReuseContainer , activations ) {
8284
8385 let zoom = d3 . behavior . zoom ( )
8486 . on ( "zoom" , redraw ) ;
8587
86- $ ( "#wskflowContainer" ) . remove ( ) ;
87- $ ( containerId ) . append ( "<div id='wskflowContainer'></div>" ) ;
88+ let containerElement ,
89+ wskflowContainer = $ ( '<div id="wskflowContainer"></div>' ) ;
90+
91+ if ( ifReuseContainer && $ ( `#${ containerId } ` ) . length > 0 ) {
92+ containerElement = $ ( `#${ containerId } ` ) ;
93+ $ ( containerElement ) . html ( '' ) . css ( 'display' , 'flex' ) . css ( 'flex' , 1 ) ;
94+ $ ( "#wskflowSVG" ) . remove ( ) ;
95+ $ ( "#qtip" ) . remove ( ) ;
96+ }
97+ else {
98+ containerElement = $ ( `<div id="${ containerId } " style="display: flex; flex: 1; width: 100%; height: 100%;"></div>` ) ;
99+ }
100+
101+ $ ( containerElement ) . append ( wskflowContainer ) ;
102+
88103
89- $ ( "# wskflowContainer" ) . css ( {
104+ $ ( wskflowContainer ) . css ( {
90105 "display" : "none" ,
91106 "flex-direction" : "column" ,
92107 "align-items" : "center" ,
@@ -99,10 +114,10 @@ function graph2doms(JSONgraph, containerId, activations){
99114 "width" : '100%' ,
100115 "height" : '100%'
101116 } ) ;
102- $ ( "# wskflowContainer" ) . addClass ( 'grabbable' ) // we want to use grab/grabbing cursor
117+ $ ( wskflowContainer ) . addClass ( 'grabbable' ) // we want to use grab/grabbing cursor
103118
104119
105- let ssvg = d3 . select ( "# wskflowContainer" )
120+ let ssvg = d3 . select ( $ ( wskflowContainer ) [ 0 ] )
106121 . append ( "svg" )
107122 . attr ( "id" , "wskflowSVG" )
108123 . style ( 'width' , '100%' ) // svg width and height changes with the size of the container
@@ -216,24 +231,24 @@ function graph2doms(JSONgraph, containerId, activations){
216231 . append ( "svg:path" )
217232 . attr ( "d" , "M852.8,558.8c0,194.5-158.2,352.8-352.8,352.8c-194.5,0-352.8-158.3-352.8-352.8c0-190.8,152.4-346.7,341.8-352.5v117.4l176.4-156.9L489,10v118C256.3,133.8,68.8,324.8,68.8,558.8C68.8,796.6,262.2,990,500,990c237.8,0,431.2-193.4,431.2-431.2H852.8z" ) ;
218233
219- $ ( "# wskflowContainer" ) . append ( "<div id='qtip'><span id='qtipArrow'>◄</span><div id='qtipContent'></div></div>" ) ;
234+ $ ( wskflowContainer ) . append ( "<div id='qtip'><span id='qtipArrow'>◄</span><div id='qtipContent'></div></div>" ) ;
220235
221236
222237 if ( activations ) {
223- $ ( "# wskflowContainer" ) . append ( "<div id='actList' style='position: absolute; display:none; background-color: rgba(0, 0, 0, 0.8); color: white; font-size: 0.75em; padding: 1ex; width:225px; right: 5px; top: 5px;'></div>" ) ;
238+ $ ( wskflowContainer ) . append ( "<div id='actList' style='position: absolute; display:none; background-color: rgba(0, 0, 0, 0.8); color: white; font-size: 0.75em; padding: 1ex; width:225px; right: 5px; top: 5px;'></div>" ) ;
224239 }
225- $ ( "#qtip" ) . css ( {
240+ $ ( wskflowContainer ) . find ( "#qtip" ) . css ( {
226241 "position" : "absolute" ,
227242 "align-items" : "center" ,
228243 "pointer-events" : "none" ,
229244 } ) ;
230- $ ( "#qtipArrow" ) . css ( {
245+ $ ( wskflowContainer ) . find ( "#qtipArrow" ) . css ( {
231246 "position" : "relative" ,
232247 "left" : "3px" ,
233248 "top" : "1px" ,
234249 "color" : "#2E4053"
235250 } ) ;
236- $ ( "#qtipContent" ) . css ( {
251+ $ ( wskflowContainer ) . find ( "#qtipContent" ) . css ( {
237252 "background-color" : wfColor . qtipBackground . normal ,
238253 "color" : "white" ,
239254 "font-size" : "0.75em" ,
@@ -348,7 +363,7 @@ function graph2doms(JSONgraph, containerId, activations){
348363
349364 function drawGraph ( nodes , links ) {
350365 console . log ( "[wskflow] in drawGraph in graph2doms" )
351-
366+
352367 // #1 add the nodes' groups
353368 var nodeData = root . selectAll ( ".node" )
354369 . data ( nodes , function ( d ) { return d . id ; } ) ;
@@ -1127,7 +1142,7 @@ function graph2doms(JSONgraph, containerId, activations){
11271142
11281143 function graphDoneCallback ( ) {
11291144 // show graph
1130- $ ( "# wskflowContainer" ) . css ( "display" , "flex" ) ;
1145+ $ ( wskflowContainer ) . css ( "display" , "flex" ) ;
11311146 }
11321147
11331148 // check if transition is complete. from https://stackoverflow.com/questions/10692100/invoke-a-callback-at-the-end-of-a-transition
@@ -1230,9 +1245,12 @@ function graph2doms(JSONgraph, containerId, activations){
12301245
12311246 // exported API
12321247 return {
1233- register : callback => handlers . push ( callback ) ,
1234- zoomToFit : ( ) => zoomToFit ( true ) ,
1235- zoom1to1 : ( ) => zoomToFit ( false )
1248+ view : $ ( containerElement ) [ 0 ] ,
1249+ controller :{
1250+ register : callback => handlers . push ( callback ) ,
1251+ zoomToFit : ( ) => zoomToFit ( true ) ,
1252+ zoom1to1 : ( ) => zoomToFit ( false )
1253+ }
12361254 }
12371255}
12381256
0 commit comments