5
5
import logging
6
6
import inspect
7
7
from .table import Table
8
+ from .dependencies import topo_sort
8
9
from .user_tables import Manual , Imported , Computed , Lookup , Part
9
10
from .errors import DataJointError
10
11
from .table import lookup_class_name
@@ -38,6 +39,7 @@ class _AliasNode:
38
39
39
40
40
41
def _get_tier (table_name ):
42
+ """given the table name, return"""
41
43
if not table_name .startswith ("`" ):
42
44
return _AliasNode
43
45
else :
@@ -70,19 +72,22 @@ def __init__(self, *args, **kwargs):
70
72
71
73
class Diagram (nx .DiGraph ):
72
74
"""
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.
74
77
75
78
Usage:
76
79
77
80
>>> diag = Diagram(source)
78
81
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.
80
83
81
84
>>> diag.draw()
82
85
83
86
draws the diagram using pyplot
84
87
85
88
diag1 + diag2 - combines the two diagrams.
89
+ diag1 - diag2 - differente between diagrams
90
+ diag1 * diag2 - intersction of diagrams
86
91
diag + n - expands n levels of successors
87
92
diag - n - expands n levels of predecessors
88
93
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):
91
96
Only those tables that are loaded in the connection object are displayed
92
97
"""
93
98
94
- def __init__ (self , source , context = None ):
99
+ def __init__ (self , source = None , context = None ):
100
+
95
101
if isinstance (source , Diagram ):
96
102
# copy constructor
97
103
self .nodes_to_show = set (source .nodes_to_show )
@@ -152,7 +158,7 @@ def from_sequence(cls, sequence):
152
158
153
159
def add_parts (self ):
154
160
"""
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
156
162
:return:
157
163
"""
158
164
@@ -244,6 +250,10 @@ def __mul__(self, arg):
244
250
self .nodes_to_show .intersection_update (arg .nodes_to_show )
245
251
return self
246
252
253
+ def topo_sort (self ):
254
+ """return nodes in lexicographical topological order"""
255
+ return topo_sort (self )
256
+
247
257
def _make_graph (self ):
248
258
"""
249
259
Make the self.graph - a graph object ready for drawing
0 commit comments