export type ID = string ; export interface Node { id : ID ; label : string ; dependents : ID [ ] ; } function visitNode ( node , nodeDefs , edgeDefs ) { const { id , label } = node ; nodeDefs . push ( `  ${ id }[label=${ label }]` ) ; if ( node . dependents . length === 0 ) return ; const ids = node . dependents . join ( ',' ) ; edgeDefs . push ( `  ${ node . id } -> ${ ids };` ) ; } export default function createDOT ( nodes ) { const nodeDefs = [ ] ; const edgeDefs = [ ] ; const seen = { } ; for ( const node of nodes ) { if ( seen [ node . id ] ) continue ; seen [ node . id ] = true ; visitNode ( node , nodeDefs , edgeDefs ) ; } const content = [ ... nodeDefs , ... edgeDefs ] . join ( '\n' ) ; return [ 'digraph {' , content , '}' , ] . join ( '\n' ) ; }