#NEWLINE# def generate_flow_diagram( app ) : #NEWLINE# #INDENT# out_dir = op . join ( app . builder . outdir , '_static' ) #NEWLINE# if ( not op . isdir ( out_dir ) ) : #NEWLINE# #INDENT# os . makedirs ( out_dir ) #NEWLINE# #UNINDENT# out_fname = op . join ( out_dir , 'mne-python_flow.svg' ) #NEWLINE# make_flow_diagram = ( ( app is None ) or bool ( app . builder . config . make_flow_diagram ) ) #NEWLINE# if ( not make_flow_diagram ) : #NEWLINE# #INDENT# print ( 'Skipping flow diagram, webpage will have a missing image' ) #NEWLINE# return #NEWLINE# #UNINDENT# import pygraphviz as pgv #NEWLINE# g = pgv . AGraph ( name = title , directed = True ) #NEWLINE# for ( key , label ) in nodes . items ( ) : #NEWLINE# #INDENT# label = label . split ( '\n' ) #NEWLINE# if ( len ( label ) > 1 ) : #NEWLINE# #INDENT# label [ 0 ] = ( ( ( '<<FONT POINT-SIZE="%s">' % node_size ) + label [ 0 ] ) + '</FONT>' ) #NEWLINE# for li in range ( 1 , len ( label ) ) : #NEWLINE# #INDENT# label [ li ] = ( ( ( '<FONT POINT-SIZE="%s"><I>' % node_small_size ) + label [ li ] ) + '</I></FONT>' ) #NEWLINE# #UNINDENT# label [ ( - 1 ) ] = ( label [ ( - 1 ) ] + '>' ) #NEWLINE# label = '<BR/>' . join ( label ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# label = label [ 0 ] #NEWLINE# #UNINDENT# g . add_node ( key , shape = 'plaintext' , label = label ) #NEWLINE# #UNINDENT# for edge in edges : #NEWLINE# #INDENT# g . add_edge ( * edge [ : 2 ] ) #NEWLINE# e = g . get_edge ( * edge [ : 2 ] ) #NEWLINE# if ( len ( edge ) > 2 ) : #NEWLINE# #INDENT# e . attr [ 'label' ] = ( ( '<<I>' + '<BR ALIGN="LEFT"/>' . join ( edge [ 2 ] . split ( '\n' ) ) ) + '<BR ALIGN="LEFT"/></I>>' ) #NEWLINE# #UNINDENT# e . attr [ 'fontsize' ] = edge_size #NEWLINE# #UNINDENT# for ( these_nodes , color ) in zip ( ( sensor_space , source_space ) , ( sensor_color , source_color ) ) : #NEWLINE# #INDENT# for node in these_nodes : #NEWLINE# #INDENT# g . get_node ( node ) . attr [ 'fillcolor' ] = color #NEWLINE# g . get_node ( node ) . attr [ 'style' ] = 'filled' #NEWLINE# #UNINDENT# #UNINDENT# for ( si , subgraph ) in enumerate ( subgraphs ) : #NEWLINE# #INDENT# g . add_subgraph ( subgraph [ 0 ] , ( 'cluster%s' % si ) , label = subgraph [ 1 ] , color = 'black' ) #NEWLINE# #UNINDENT# for gr in ( g . subgraphs ( ) + [ g ] ) : #NEWLINE# #INDENT# for x in [ gr . node_attr , gr . edge_attr ] : #NEWLINE# #INDENT# x [ 'fontname' ] = font_face #NEWLINE# #UNINDENT# #UNINDENT# g . node_attr [ 'shape' ] = 'box' #NEWLINE# for ( ni , node ) in enumerate ( ( 'fwd' , 'inv' , 'trans' ) ) : #NEWLINE# #INDENT# node = g . get_node ( node ) #NEWLINE# node . attr [ 'gradientangle' ] = 270 #NEWLINE# colors = ( source_color , sensor_color ) #NEWLINE# colors = ( colors if ( ni == 0 ) else colors [ : : ( - 1 ) ] ) #NEWLINE# node . attr [ 'fillcolor' ] = ':' . join ( colors ) #NEWLINE# node . attr [ 'style' ] = 'filled' #NEWLINE# #UNINDENT# del node #NEWLINE# g . get_node ( 'legend' ) . attr . update ( shape = 'plaintext' , margin = 0 , rank = 'sink' ) #NEWLINE# l = g . add_subgraph ( [ 'legend' , 'inv' ] , name = 'legendy' ) #NEWLINE# l . graph_attr [ 'rank' ] = 'same' #NEWLINE# g . layout ( 'dot' ) #NEWLINE# g . draw ( out_fname , format = 'svg' ) #NEWLINE# return g