@@ -505,10 +505,14 @@ def write_graph(self, dotfilename='graph.dot', graph2use='hierarchical',
505
505
Parameters
506
506
----------
507
507
508
- graph2use: 'orig', 'hierarchical' (default), 'flat', 'exec'
508
+ graph2use: 'orig', 'hierarchical' (default), 'flat', 'exec', 'colored'
509
509
orig - creates a top level graph without expanding internal
510
510
workflow nodes;
511
511
flat - expands workflow nodes recursively;
512
+ hierarchical - expands workflow nodes recursively with a
513
+ notion on hierarchy;
514
+ colored - expands workflow nodes recursively with a
515
+ notion on hierarchy in color;
512
516
exec - expands workflows to depict iterables
513
517
514
518
format: 'png', 'svg'
@@ -519,7 +523,7 @@ def write_graph(self, dotfilename='graph.dot', graph2use='hierarchical',
519
523
False.
520
524
521
525
"""
522
- graphtypes = ['orig' , 'flat' , 'hierarchical' , 'exec' ]
526
+ graphtypes = ['orig' , 'flat' , 'hierarchical' , 'exec' , 'colored' ]
523
527
if graph2use not in graphtypes :
524
528
raise ValueError ('Unknown graph2use keyword. Must be one of: ' +
525
529
str (graphtypes ))
@@ -532,10 +536,10 @@ def write_graph(self, dotfilename='graph.dot', graph2use='hierarchical',
532
536
else :
533
537
base_dir = os .getcwd ()
534
538
base_dir = make_output_dir (base_dir )
535
- if graph2use == 'hierarchical' :
539
+ if graph2use in [ 'hierarchical' , 'colored' ] :
536
540
dotfilename = os .path .join (base_dir , dotfilename )
537
541
self .write_hierarchical_dotfile (dotfilename = dotfilename ,
538
- colored = False ,
542
+ colored = graph2use == "colored" ,
539
543
simple_form = simple_form )
540
544
format_dot (dotfilename , format = format )
541
545
else :
@@ -547,11 +551,9 @@ def write_graph(self, dotfilename='graph.dot', graph2use='hierarchical',
547
551
export_graph (graph , base_dir , dotfilename = dotfilename ,
548
552
format = format , simple_form = simple_form )
549
553
550
- def write_hierarchical_dotfile (self , dotfilename = None , colored = True ,
554
+ def write_hierarchical_dotfile (self , dotfilename = None , colored = False ,
551
555
simple_form = True ):
552
556
dotlist = ['digraph %s{' % self .name ]
553
- if colored :
554
- dotlist .append (' ' + 'colorscheme=pastel28;' )
555
557
dotlist .append (self ._get_dot (prefix = ' ' , colored = colored ,
556
558
simple_form = simple_form ))
557
559
dotlist .append ('}' )
@@ -1007,18 +1009,18 @@ def _generate_flatgraph(self):
1007
1009
self ._graph .remove_nodes_from (nodes2remove )
1008
1010
logger .debug ('finished expanding workflow: %s' , self )
1009
1011
1010
- def _get_dot (self , prefix = None , hierarchy = None , colored = True ,
1011
- simple_form = True ):
1012
+ def _get_dot (self , prefix = None , hierarchy = None , colored = False ,
1013
+ simple_form = True , level = 0 ):
1012
1014
"""Create a dot file with connection info
1013
1015
"""
1014
1016
if prefix is None :
1015
1017
prefix = ' '
1016
1018
if hierarchy is None :
1017
1019
hierarchy = []
1018
- level = (len (prefix ) / 2 ) + 1
1020
+ colorset = ['#FFFFC8' ,'#0000FF' ,'#B4B4FF' ,'#E6E6FF' ,'#FF0000' ,
1021
+ '#FFB4B4' ,'#FFE6E6' ,'#00A300' ,'#B4FFB4' ,'#E6FFE6' ]
1022
+
1019
1023
dotlist = ['%slabel="%s";' % (prefix , self .name )]
1020
- if colored :
1021
- dotlist .append ('%scolor=%d;' % (prefix , level ))
1022
1024
for node in nx .topological_sort (self ._graph ):
1023
1025
fullname = '.' .join (hierarchy + [node .fullname ])
1024
1026
nodename = fullname .replace ('.' , '_' )
@@ -1027,24 +1029,35 @@ def _get_dot(self, prefix=None, hierarchy=None, colored=True,
1027
1029
if not simple_form :
1028
1030
node_class_name = '.' .join (node_class_name .split ('.' )[1 :])
1029
1031
if hasattr (node , 'iterables' ) and node .iterables :
1030
- dotlist .append (('%s[label="%s", style=filled, colorscheme'
1031
- '=greys7 color=2];' ) % (nodename ,
1032
+ dotlist .append (('%s[label="%s", shape=box3d,'
1033
+ 'style=filled, color=black, colorscheme'
1034
+ '=greys7 fillcolor=2];' ) % (nodename ,
1032
1035
node_class_name ))
1033
1036
else :
1034
- dotlist .append ('%s[label="%s"];' % (nodename ,
1035
- node_class_name ))
1037
+ if colored :
1038
+ dotlist .append (('%s[label="%s", style=filled,'
1039
+ ' fillcolor="%s"];' )
1040
+ % (nodename ,node_class_name ,
1041
+ colorset [level ]))
1042
+ else :
1043
+ dotlist .append (('%s[label="%s"];' )
1044
+ % (nodename ,node_class_name ))
1045
+
1036
1046
for node in nx .topological_sort (self ._graph ):
1037
1047
if isinstance (node , Workflow ):
1038
1048
fullname = '.' .join (hierarchy + [node .fullname ])
1039
1049
nodename = fullname .replace ('.' , '_' )
1040
1050
dotlist .append ('subgraph cluster_%s {' % nodename )
1041
1051
if colored :
1052
+ dotlist .append (prefix + prefix + 'edge [color="%s"];' % (colorset [level + 1 ]))
1042
1053
dotlist .append (prefix + prefix + 'style=filled;' )
1054
+ dotlist .append (prefix + prefix + 'fillcolor="%s";' % (colorset [level + 2 ]))
1043
1055
dotlist .append (node ._get_dot (prefix = prefix + prefix ,
1044
1056
hierarchy = hierarchy + [self .name ],
1045
1057
colored = colored ,
1046
- simple_form = simple_form ))
1058
+ simple_form = simple_form , level = level + 3 ))
1047
1059
dotlist .append ('}' )
1060
+ if level == 6 :level = 2
1048
1061
else :
1049
1062
for subnode in self ._graph .successors_iter (node ):
1050
1063
if node ._hierarchy != subnode ._hierarchy :
0 commit comments