#NEWLINE# def dot_layout( cy_elements ) : #NEWLINE# #INDENT# '\n    Get a CyElements object and augment it (in-place) with positions,\n    widths, heights, and spline data from a dot based layout.\n\n    Returns the object.\n    ' #NEWLINE# elements = cy_elements . elements #NEWLINE# g = AGraph ( directed = True , strict = False ) #NEWLINE# elements = list ( elements ) #NEWLINE# nodes_by_id = dict ( ( ( e [ 'data' ] [ 'id' ] , e ) for e in elements if ( e [ 'group' ] == 'nodes' ) ) ) #NEWLINE# order = [ ( nodes_by_id [ e [ 'data' ] [ 'source' ] ] , nodes_by_id [ e [ 'data' ] [ 'target' ] ] ) for e in elements if ( ( e [ 'group' ] == 'edges' ) and ( e [ 'data' ] [ 'obj' ] in ( 'reach' , 'le' ) ) ) ] #NEWLINE# elements = topological_sort ( elements , order , ( lambda e : e [ 'data' ] [ 'id' ] ) ) #NEWLINE# for e in elements : #NEWLINE# #INDENT# if ( e [ 'group' ] == 'nodes' ) : #NEWLINE# #INDENT# g . add_node ( e [ 'data' ] [ 'id' ] , label = e [ 'data' ] [ 'label' ] . replace ( '\n' , '\\n' ) ) #NEWLINE# #UNINDENT# #UNINDENT# weight = { #NEWLINE# #INDENT# 'reach' : 10 , #NEWLINE# 'le' : 10 , #NEWLINE# 'id' : 1 , #NEWLINE# #UNINDENT# } #NEWLINE# constraint = { #NEWLINE# #INDENT# 'pending' : False , #NEWLINE# #UNINDENT# } #NEWLINE# for e in elements : #NEWLINE# #INDENT# if ( e [ 'group' ] == 'edges' ) : #NEWLINE# #INDENT# g . add_edge ( e [ 'data' ] [ 'source' ] , e [ 'data' ] [ 'target' ] , e [ 'data' ] [ 'id' ] , weight = weight . get ( e [ 'data' ] [ 'obj' ] , 0 ) ) #NEWLINE# #UNINDENT# #UNINDENT# clusters = defaultdict ( list ) #NEWLINE# for e in elements : #NEWLINE# #INDENT# if ( ( e [ 'group' ] == 'nodes' ) and ( e [ 'data' ] [ 'cluster' ] is not None ) ) : #NEWLINE# #INDENT# clusters [ e [ 'data' ] [ 'cluster' ] ] . append ( e [ 'data' ] [ 'id' ] ) #NEWLINE# #UNINDENT# #UNINDENT# for ( i , k ) in enumerate ( sorted ( clusters . keys ( ) ) ) : #NEWLINE# #INDENT# g . add_subgraph ( name = 'cluster_{}' . format ( i ) , nbunch = clusters [ k ] ) #NEWLINE# #UNINDENT# g . layout ( prog = 'dot' ) #NEWLINE# for e in elements : #NEWLINE# #INDENT# if ( e [ 'group' ] == 'nodes' ) : #NEWLINE# #INDENT# attr = g . get_node ( e [ 'data' ] [ 'id' ] ) . attr #NEWLINE# e [ 'position' ] = _to_position ( attr [ 'pos' ] ) #NEWLINE# e [ 'data' ] [ 'width' ] = ( 72 * float ( attr [ 'width' ] ) ) #NEWLINE# e [ 'data' ] [ 'height' ] = ( 72 * float ( attr [ 'height' ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( e [ 'group' ] == 'edges' ) : #NEWLINE# #INDENT# attr = g . get_edge ( e [ 'data' ] [ 'source' ] , e [ 'data' ] [ 'target' ] , e [ 'data' ] [ 'id' ] ) . attr #NEWLINE# e [ 'data' ] . update ( _to_edge_position ( attr [ 'pos' ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# g . draw ( 'g.png' ) #NEWLINE# return cy_elements