def tree_graph(data, attrs=_attrs):
 graph = nx.DiGraph()
 id_ = attrs['id']
 children = attrs['children']
 def add_children(parent, children_):
  for data in children_:
   child = data[id_]
   graph.add_edge(parent, child)
   grandchildren = data.get(children, [])
   if grandchildren:
    add_children(child, grandchildren)
   nodedata = dict(((make_str(k), v) for (k, v) in data.items() if ((k != id_) and (k != children))))
   graph.add_node(child, **nodedata)
 root = data[id_]
 children_ = data.get(children, [])
 nodedata = dict(((make_str(k), v) for (k, v) in data.items() if ((k != id_) and (k != children))))
 graph.add_node(root, **nodedata)
 add_children(root, children_)
 return graph

def tree_graph ( data , attrs = _attrs ) : graph = nx . DiGraph ( ) id_ = attrs [ 'id' ] children = attrs [ 'children' ] def add_children ( parent , children_ ) : for data in children_ : child = data [ id_ ] graph . add_edge ( parent , child ) grandchildren = data . get ( children , [ ] ) if grandchildren : add_children ( child , grandchildren ) nodedata = dict ( ( ( make_str ( k ) , v ) for ( k , v ) in data . items ( ) if ( ( k != id_ ) and ( k != children ) ) ) ) graph . add_node ( child , ** nodedata ) root = data [ id_ ] children_ = data . get ( children , [ ] ) nodedata = dict ( ( ( make_str ( k ) , v ) for ( k , v ) in data . items ( ) if ( ( k != id_ ) and ( k != children ) ) ) ) graph . add_node ( root , ** nodedata ) add_children ( root , children_ ) return graph
return graph from tree data format .