@@ -412,10 +412,14 @@ def write_graph(self, dotfilename='graph.dot', graph2use='hierarchical',
412
412
Parameters
413
413
----------
414
414
415
- graph2use: 'orig', 'hierarchical' (default), 'flat', 'exec'
415
+ graph2use: 'orig', 'hierarchical' (default), 'flat', 'exec', 'colored'
416
416
orig - creates a top level graph without expanding internal
417
417
workflow nodes;
418
418
flat - expands workflow nodes recursively;
419
+ hierarchical - expands workflow nodes recursively with a
420
+ notion on hierarchy;
421
+ colored - expands workflow nodes recursively with a
422
+ notion on hierarchy in color;
419
423
exec - expands workflows to depict iterables
420
424
421
425
format: 'png', 'svg'
@@ -426,7 +430,7 @@ def write_graph(self, dotfilename='graph.dot', graph2use='hierarchical',
426
430
False.
427
431
428
432
"""
429
- graphtypes = ['orig' , 'flat' , 'hierarchical' , 'exec' ]
433
+ graphtypes = ['orig' , 'flat' , 'hierarchical' , 'exec' , 'colored' ]
430
434
if graph2use not in graphtypes :
431
435
raise ValueError ('Unknown graph2use keyword. Must be one of: ' +
432
436
str (graphtypes ))
@@ -439,11 +443,17 @@ def write_graph(self, dotfilename='graph.dot', graph2use='hierarchical',
439
443
else :
440
444
base_dir = os .getcwd ()
441
445
base_dir = make_output_dir (base_dir )
442
- if graph2use == 'hierarchical' :
446
+ if graph2use == 'hierarchical' or graph2use == 'colored' :
443
447
dotfilename = os .path .join (base_dir , dotfilename )
444
- self .write_hierarchical_dotfile (dotfilename = dotfilename ,
445
- colored = False ,
446
- simple_form = simple_form )
448
+ if graph2use == 'colored' :
449
+ self .write_hierarchical_dotfile (dotfilename = dotfilename ,
450
+ colored = True ,
451
+ simple_form = simple_form )
452
+
453
+ else :
454
+ self .write_hierarchical_dotfile (dotfilename = dotfilename ,
455
+ colored = False ,
456
+ simple_form = simple_form )
447
457
format_dot (dotfilename , format = format )
448
458
else :
449
459
graph = self ._graph
@@ -454,11 +464,9 @@ def write_graph(self, dotfilename='graph.dot', graph2use='hierarchical',
454
464
export_graph (graph , base_dir , dotfilename = dotfilename ,
455
465
format = format , simple_form = simple_form )
456
466
457
- def write_hierarchical_dotfile (self , dotfilename = None , colored = True ,
467
+ def write_hierarchical_dotfile (self , dotfilename = None , colored = False ,
458
468
simple_form = True ):
459
469
dotlist = ['digraph %s{' % self .name ]
460
- if colored :
461
- dotlist .append (' ' + 'colorscheme=pastel28;' )
462
470
dotlist .append (self ._get_dot (prefix = ' ' , colored = colored ,
463
471
simple_form = simple_form ))
464
472
dotlist .append ('}' )
@@ -827,18 +835,18 @@ def _generate_flatgraph(self):
827
835
self ._graph .remove_nodes_from (nodes2remove )
828
836
logger .debug ('finished expanding workflow: %s' , self )
829
837
830
- def _get_dot (self , prefix = None , hierarchy = None , colored = True ,
831
- simple_form = True ):
838
+ def _get_dot (self , prefix = None , hierarchy = None , colored = False ,
839
+ simple_form = True , level = 0 ):
832
840
"""Create a dot file with connection info
833
841
"""
834
842
if prefix is None :
835
843
prefix = ' '
836
844
if hierarchy is None :
837
845
hierarchy = []
838
- level = (len (prefix ) / 2 ) + 1
846
+ colorset = ['#FFFFC8' ,'#0000FF' ,'#B4B4FF' ,'#E6E6FF' ,'#FF0000' ,
847
+ '#FFB4B4' ,'#FFE6E6' ,'#00A300' ,'#B4FFB4' ,'#E6FFE6' ]
848
+
839
849
dotlist = ['%slabel="%s";' % (prefix , self .name )]
840
- if colored :
841
- dotlist .append ('%scolor=%d;' % (prefix , level ))
842
850
for node in nx .topological_sort (self ._graph ):
843
851
fullname = '.' .join (hierarchy + [node .fullname ])
844
852
nodename = fullname .replace ('.' , '_' )
@@ -847,24 +855,35 @@ def _get_dot(self, prefix=None, hierarchy=None, colored=True,
847
855
if not simple_form :
848
856
node_class_name = '.' .join (node_class_name .split ('.' )[1 :])
849
857
if hasattr (node , 'iterables' ) and node .iterables :
850
- dotlist .append (('%s[label="%s", style=filled, colorscheme'
851
- '=greys7 color=2];' ) % (nodename ,
858
+ dotlist .append (('%s[label="%s", shape=box3d,'
859
+ 'style=filled, color=black, colorscheme'
860
+ '=greys7 fillcolor=2];' ) % (nodename ,
852
861
node_class_name ))
853
862
else :
854
- dotlist .append ('%s[label="%s"];' % (nodename ,
855
- node_class_name ))
863
+ if colored :
864
+ dotlist .append (('%s[label="%s", style=filled,'
865
+ ' fillcolor="%s"];' )
866
+ % (nodename ,node_class_name ,
867
+ colorset [level ]))
868
+ else :
869
+ dotlist .append (('%s[label="%s"];' )
870
+ % (nodename ,node_class_name ))
871
+
856
872
for node in nx .topological_sort (self ._graph ):
857
873
if isinstance (node , Workflow ):
858
874
fullname = '.' .join (hierarchy + [node .fullname ])
859
875
nodename = fullname .replace ('.' , '_' )
860
876
dotlist .append ('subgraph cluster_%s {' % nodename )
861
877
if colored :
878
+ dotlist .append (prefix + prefix + 'edge [color="%s"];' % (colorset [level + 1 ]))
862
879
dotlist .append (prefix + prefix + 'style=filled;' )
880
+ dotlist .append (prefix + prefix + 'fillcolor="%s";' % (colorset [level + 2 ]))
863
881
dotlist .append (node ._get_dot (prefix = prefix + prefix ,
864
882
hierarchy = hierarchy + [self .name ],
865
883
colored = colored ,
866
- simple_form = simple_form ))
884
+ simple_form = simple_form , level = level + 3 ))
867
885
dotlist .append ('}' )
886
+ if level == 6 :level = 2
868
887
else :
869
888
for subnode in self ._graph .successors_iter (node ):
870
889
if node ._hierarchy != subnode ._hierarchy :
0 commit comments