Producing graphs with graphviz.

For examples see here


In [13]:
from simpleRM.core import DataProvider
from pprint import pprint

ROOT = '../requirements/simpleSE.yml'
dp = DataProvider(ROOT)


pprint(dp.requirements)


OrderedDict([('A01', A01 parent:ROOT children:None,level:0),
             ('A02', A02 parent:ROOT children:['R006'],level:0),
             ('R006', R006 parent:A02 children:None,level:1),
             ('A03',
              A03 parent:ROOT children:['R009c', 'R008', 'R009'],level:0),
             ('R008',
              R008 parent:A03 children:['R008c', 'R008a', 'R008b', 'R008d'],level:1),
             ('R008a', R008a parent:R008 children:None,level:2),
             ('R008b', R008b parent:R008 children:None,level:2),
             ('R008c', R008c parent:R008 children:None,level:2),
             ('R008d', R008d parent:R008 children:None,level:2),
             ('R009', R009 parent:A03 children:['R009a', 'R009b'],level:1),
             ('R009a', R009a parent:R009 children:None,level:2),
             ('R009b', R009b parent:R009 children:None,level:2),
             ('R009c', R009c parent:A03 children:None,level:1),
             ('A04', A04 parent:ROOT children:None,level:0),
             ('A05', A05 parent:ROOT children:['R004'],level:0),
             ('R004', R004 parent:A05 children:None,level:1),
             ('A06', A06 parent:ROOT children:None,level:0),
             ('A07', A07 parent:ROOT children:['R003'],level:0),
             ('R003', R003 parent:A07 children:None,level:1),
             ('A08', A08 parent:ROOT children:['R004a'],level:0),
             ('R004a', R004a parent:A08 children:None,level:1),
             ('A09', A09 parent:ROOT children:['R007'],level:0),
             ('R007', R007 parent:A09 children:None,level:1),
             ('A10', A10 parent:ROOT children:['R011'],level:0),
             ('R011', R011 parent:A10 children:None,level:1)])

In [24]:
from graphviz import Digraph

dot = Digraph(comment='dependencies', format='svg')

dot.node('ROOT','root',color='red',style='filled')

# requirements
for req in dp.requirements.values():
    dot.node(req.tag,req.tag,URL='foo')
    if req.parent =='ROOT':
        dot.edge('ROOT',req.tag)
    
# dependencies
for req in dp.requirements.values():
    if req.children is not None:
        for child in req.children:
            dot.edge(req.tag, child)
    
dot.render('test')
#print(dot.source)
dot


Out[24]:
%3 ROOT root A01 A01 ROOT->A01 A02 A02 ROOT->A02 A03 A03 ROOT->A03 A04 A04 ROOT->A04 A05 A05 ROOT->A05 A06 A06 ROOT->A06 A07 A07 ROOT->A07 A08 A08 ROOT->A08 A09 A09 ROOT->A09 A10 A10 ROOT->A10 R006 R006 A02->R006 R008 R008 A03->R008 R009 R009 A03->R009 R009c R009c A03->R009c R008a R008a R008->R008a R008b R008b R008->R008b R008c R008c R008->R008c R008d R008d R008->R008d R009a R009a R009->R009a R009b R009b R009->R009b R004 R004 A05->R004 R003 R003 A07->R003 R004a R004a A08->R004a R007 R007 A09->R007 R011 R011 A10->R011