@@ -172,37 +172,6 @@ function renderHierarchy(
172172 return dotContent ;
173173}
174174
175- function formatStyle ( style : { [ attribute : string ] : number | string } ) : string {
176- return [ ...Object . entries ( style ) ]
177- . map ( ( [ name , value ] ) => {
178- switch ( typeof value ) {
179- case "number" :
180- return `${ name } =${ value } ;\n` ;
181- case "string" :
182- return `${ name } ="${ value } ";\n` ;
183- }
184- } )
185- . join ( "" ) ;
186- }
187-
188- function clusterStyle ( cluster : Cluster ) : string {
189- const isSelfNested = cluster . type === cluster . parent ?. type ;
190- const penwidth = isSelfNested ? 6 : 0 ;
191- const color = "white" ;
192- switch ( cluster . type ) {
193- case "with" :
194- return formatStyle ( { penwidth, color, bgcolor : "#ffddff" } ) ;
195- case "try-complex" :
196- return formatStyle ( { penwidth, color, bgcolor : "#ddddff" } ) ;
197- case "try" :
198- return formatStyle ( { penwidth, color, bgcolor : "#ddffdd" } ) ;
199- case "finally" :
200- return formatStyle ( { penwidth, color, bgcolor : "#ffffdd" } ) ;
201- default :
202- return "" ;
203- }
204- }
205-
206175function renderSubgraphs (
207176 hierarchy : Hierarchy ,
208177 verbose : boolean ,
@@ -300,24 +269,69 @@ export function graphToDot(cfg: CFG, verbose: boolean = false): string {
300269 return dotContent ;
301270}
302271
272+ type DotAttributes = { [ attribute : string ] : number | string | undefined } ;
273+ function formatStyle ( style : DotAttributes ) : string {
274+ return [ ...Object . entries ( style ) ]
275+ . map ( ( [ name , value ] ) => {
276+ switch ( typeof value ) {
277+ case "number" :
278+ return `${ name } =${ value } ;\n` ;
279+ case "string" :
280+ return `${ name } ="${ value } ";\n` ;
281+ case "undefined" :
282+ return "" ;
283+ }
284+ } )
285+ . join ( "" ) ;
286+ }
287+
288+ function clusterStyle ( cluster : Cluster ) : string {
289+ const isSelfNested = cluster . type === cluster . parent ?. type ;
290+ const penwidth = isSelfNested ? 6 : 0 ;
291+ const color = "white" ;
292+ switch ( cluster . type ) {
293+ case "with" :
294+ return formatStyle ( { penwidth, color, bgcolor : "#ffddff" } ) ;
295+ case "try-complex" :
296+ return formatStyle ( { penwidth, color, bgcolor : "#ddddff" } ) ;
297+ case "try" :
298+ return formatStyle ( { penwidth, color, bgcolor : "#ddffdd" } ) ;
299+ case "finally" :
300+ return formatStyle ( { penwidth, color, bgcolor : "#ffffdd" } ) ;
301+ case "except" :
302+ return formatStyle ( { penwidth, color, bgcolor : "#ffdddd" } ) ;
303+ default :
304+ return "" ;
305+ }
306+ }
307+
303308function renderEdge (
304309 edge : string ,
305310 source : string ,
306311 target : string ,
307312 topGraph : CFGGraph ,
308313) {
309314 const attributes = topGraph . getEdgeAttributes ( edge ) ;
310- const penwidth = 1 ;
311- let color = "blue" ;
315+ const dotAttrs : DotAttributes = { } ;
316+ dotAttrs . penwidth = 1 ;
317+ dotAttrs . color = "blue" ;
312318 switch ( attributes . type ) {
313319 case "consequence" :
314- color = "green" ;
320+ dotAttrs . color = "green" ;
315321 break ;
316322 case "alternative" :
317- color = "red" ;
323+ dotAttrs . color = "red" ;
324+ break ;
325+ case "regular" :
326+ dotAttrs . color = "blue" ;
327+ break ;
328+ case "exception" :
329+ dotAttrs . style = "invis" ;
330+ dotAttrs . headport = "e" ;
331+ dotAttrs . tailport = "w" ;
318332 break ;
319333 default :
320- color = "blue " ;
334+ dotAttrs . color = "fuchsia " ;
321335 }
322- return ` ${ source } -> ${ target } [penwidth= ${ penwidth } color= ${ color } ];\n` ;
336+ return ` ${ source } -> ${ target } [${ formatStyle ( dotAttrs ) } ];\n` ;
323337}
0 commit comments