#NEWLINE# def setup_labels( self , size = None , color = None , shadow = None ) : #NEWLINE# #INDENT# 'Sets up coordinates for labels wrt SVG file (2D flatmap)' #NEWLINE# if ( self . layer == 'multi_layer' ) : #NEWLINE# #INDENT# label_layers = [ ] #NEWLINE# for L in self . layer_names : #NEWLINE# #INDENT# label_layers . append ( self . layers [ L ] . setup_labels ( ) ) #NEWLINE# self . svg . getroot ( ) . insert ( 0 , label_layers [ ( - 1 ) ] ) #NEWLINE# #UNINDENT# return label_layers #NEWLINE# #UNINDENT# if ( self . layer in config . sections ( ) ) : #NEWLINE# #INDENT# dlayer = self . layer #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# import warnings #NEWLINE# warnings . warn ( ( 'No defaults set for display layer %s; Using defaults for ROIs in options.cfg file' % self . layer ) ) #NEWLINE# dlayer = 'rois' #NEWLINE# #UNINDENT# if ( size is None ) : #NEWLINE# #INDENT# size = config . get ( dlayer , 'labelsize' ) #NEWLINE# #UNINDENT# if ( color is None ) : #NEWLINE# #INDENT# color = tuple ( map ( float , config . get ( dlayer , 'labelcolor' ) . split ( ',' ) ) ) #NEWLINE# #UNINDENT# if ( shadow is None ) : #NEWLINE# #INDENT# shadow = self . shadow #NEWLINE# #UNINDENT# alpha = color [ 3 ] #NEWLINE# color = ( 'rgb(%d, %d, %d)' % ( ( color [ 0 ] * 255 ) , ( color [ 1 ] * 255 ) , ( color [ 2 ] * 255 ) ) ) #NEWLINE# try : #NEWLINE# #INDENT# layer = _find_layer ( self . svg , ( '%s_labels' % self . layer ) ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# layer = _make_layer ( self . svg . getroot ( ) , ( '%s_labels' % self . layer ) ) #NEWLINE# #UNINDENT# ( labelpos , candidates ) = ( [ ] , [ ] ) #NEWLINE# for roi in list ( self . rois . values ( ) ) : #NEWLINE# #INDENT# for ( i , pos ) in enumerate ( roi . get_labelpos ( ) ) : #NEWLINE# #INDENT# labelpos . append ( pos ) #NEWLINE# candidates . append ( ( roi , i ) ) #NEWLINE# #UNINDENT# #UNINDENT# ( w , h ) = self . svgshape #NEWLINE# nolabels = set ( candidates ) #NEWLINE# txtstyle = ( 'font-family:sans;font-size:%s;font-weight:bold;font-style:italic;fill:%s;fill-opacity:%f;text-anchor:middle;' % ( size , color , alpha ) ) #NEWLINE# for text in layer . findall ( ( './/{%s}text' % svgns ) ) : #NEWLINE# #INDENT# x = float ( text . get ( 'x' ) ) #NEWLINE# y = float ( text . get ( 'y' ) ) #NEWLINE# text . attrib [ 'style' ] = txtstyle #NEWLINE# text . attrib [ 'data-ptidx' ] = str ( self . kdt . query ( ( ( x / w ) , ( 1 - ( y / h ) ) ) ) [ 1 ] ) #NEWLINE# ( pts , cand ) = ( [ ] , [ ] ) #NEWLINE# for ( p , c ) in zip ( labelpos , candidates ) : #NEWLINE# #INDENT# if ( c [ 0 ] . name == text . text ) : #NEWLINE# #INDENT# pts . append ( ( ( p [ 0 ] * w ) , ( ( 1 - p [ 1 ] ) * h ) ) ) #NEWLINE# cand . append ( c ) #NEWLINE# #UNINDENT# #UNINDENT# ( d , idx ) = cKDTree ( pts ) . query ( ( x , y ) ) #NEWLINE# nolabels . remove ( cand [ idx ] ) #NEWLINE# #UNINDENT# for ( roi , i ) in nolabels : #NEWLINE# #INDENT# ( x , y ) = roi . get_labelpos ( ) [ i ] #NEWLINE# text = etree . SubElement ( layer , ( '{%s}text' % svgns ) ) #NEWLINE# text . text = roi . name #NEWLINE# text . attrib [ 'x' ] = str ( ( x * w ) ) #NEWLINE# text . attrib [ 'y' ] = str ( ( ( 1 - y ) * h ) ) #NEWLINE# if ( self . shadow > 0 ) : #NEWLINE# #INDENT# text . attrib [ 'filter' ] = 'url(#dropshadow)' #NEWLINE# #UNINDENT# text . attrib [ 'style' ] = txtstyle #NEWLINE# text . attrib [ 'data-ptidx' ] = str ( self . kdt . query ( ( x , y ) ) [ 1 ] ) #NEWLINE# #UNINDENT# self . labels = layer #NEWLINE# return layer