import * as dagre from 'dagre' ; import { BaseInfo , Edge , GraphModel , Node } from './dagre-model' ; /**
 * WIKI: https://github.com/dagrejs/dagre/wiki
 */ export class DagreUtils { public static modelToGraph ( model ) { const g = new dagre . graphlib . Graph ( { compound : true , multigraph : true } ) ; g . setGraph ( this . getLayout ( model ) ) ; g . setDefaultEdgeLabel ( function ( ) { return { } ; } ) ; this . updateGraph ( g , model ) ; dagre . layout ( g ) ; return g ; } public static updateBaseInfo ( g , baseInfo ) { if ( baseInfo ) { baseInfo . forEach ( ( node ) => { g . setNode ( node . name , { label : node . label , width : 18 , height : 18 } ) ; if ( node . composition ) { g . setParent ( node . name , node . composition ) ; } } ) ; } } public static updateEdges ( g , model ) { if ( model . edges ) { model . edges . forEach ( ( edge ) => { g . setEdge ( edge . from , edge . to , { name : edge . name } ) ; } ) ; } } public static updateGraph ( g , model ) { this . updateBaseInfo ( g , model . compositions ) ; this . updateBaseInfo ( g , model . nodes ) ; this . updateEdges ( g , model ) ; } public static getLayout ( model ) { const layout = model . layout ; return layout ; } }