Skip to content

Commit

Permalink
Merge pull request #557 from kimehta/master
Browse files Browse the repository at this point in the history
Highlight "distinguished" classes in the ERD #378
  • Loading branch information
dimitri-yatsenko authored Jan 22, 2019
2 parents 5c4b5c1 + 40280ad commit f41d474
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion datajoint/erd.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,17 @@ def __init__(self, source, context=None):
if node.startswith('`%s`' % database):
self.nodes_to_show.add(node)

for full_table_name in self.nodes_to_show:
#one entry per parent
parents = connection.dependencies.parents(full_table_name,True)

# all the foreign primary keys
# set because multiple foreign constraints can be applied on the same local attribute
foreign_primary_attributes = set(attr for parent in parents.values() for attr in parent['attr_map'].keys())

#distinguished table if table introduces atleast one primary key in the schema
self.nodes._nodes[full_table_name]['distinguished'] = foreign_primary_attributes < self.nodes._nodes[full_table_name]['primary_key']

@classmethod
def from_sequence(cls, sequence):
"""
Expand Down Expand Up @@ -260,7 +271,7 @@ def make_dot(self):
'-'*30 if q.startswith('---') else q.replace('->', '&#8594;') if '->' in q else q.split(':')[0]
for q in description if not q.startswith('#'))
node.set_tooltip('&#13;'.join(description))
node.set_label(name)
node.set_label("<<u>"+name+"</u>>" if node.get('distinguished') == 'True' else name)
node.set_color(props['color'])
node.set_style('filled')

Expand Down

0 comments on commit f41d474

Please sign in to comment.