55import logging
66import inspect
77from .table import Table
8+ from .dependencies import topo_sort
89from .user_tables import Manual , Imported , Computed , Lookup , Part
910from .errors import DataJointError
1011from .table import lookup_class_name
@@ -38,6 +39,7 @@ class _AliasNode:
3839
3940
4041def _get_tier (table_name ):
42+ """given the table name, return"""
4143 if not table_name .startswith ("`" ):
4244 return _AliasNode
4345 else :
@@ -70,19 +72,22 @@ def __init__(self, *args, **kwargs):
7072
7173 class Diagram (nx .DiGraph ):
7274 """
73- Entity relationship diagram.
75+ Schema diagram showing tables and foreign keys between in the form of a directed
76+ acyclic graph (DAG). The diagram is derived from the connection.dependencies object.
7477
7578 Usage:
7679
7780 >>> diag = Diagram(source)
7881
79- source can be a base table object, a base table class, a schema, or a module that has a schema.
82+ source can be a table object, a table class, a schema, or a module that has a schema.
8083
8184 >>> diag.draw()
8285
8386 draws the diagram using pyplot
8487
8588 diag1 + diag2 - combines the two diagrams.
89+ diag1 - diag2 - differente between diagrams
90+ diag1 * diag2 - intersction of diagrams
8691 diag + n - expands n levels of successors
8792 diag - n - expands n levels of predecessors
8893 Thus dj.Diagram(schema.Table)+1-1 defines the diagram of immediate ancestors and descendants of schema.Table
@@ -91,7 +96,8 @@ class Diagram(nx.DiGraph):
9196 Only those tables that are loaded in the connection object are displayed
9297 """
9398
94- def __init__ (self , source , context = None ):
99+ def __init__ (self , source = None , context = None ):
100+
95101 if isinstance (source , Diagram ):
96102 # copy constructor
97103 self .nodes_to_show = set (source .nodes_to_show )
@@ -152,7 +158,7 @@ def from_sequence(cls, sequence):
152158
153159 def add_parts (self ):
154160 """
155- Adds to the diagram the part tables of tables already included in the diagram
161+ Adds to the diagram the part tables of all master tables already in the diagram
156162 :return:
157163 """
158164
@@ -244,6 +250,10 @@ def __mul__(self, arg):
244250 self .nodes_to_show .intersection_update (arg .nodes_to_show )
245251 return self
246252
253+ def topo_sort (self ):
254+ """return nodes in lexicographical topological order"""
255+ return topo_sort (self )
256+
247257 def _make_graph (self ):
248258 """
249259 Make the self.graph - a graph object ready for drawing
0 commit comments