Skip to content

Commit

Permalink
Merge pull request #42 from SynBioDex/36-remove_duplicate_arrows
Browse files Browse the repository at this point in the history
Remove duplicate edges from UML figure
  • Loading branch information
bbartley authored Sep 28, 2021
2 parents 6027db5 + 30f0b29 commit b053858
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions sbol_factory/uml_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import sbol3 as sbol

from math import inf
import posixpath
import os
import graphviz
from math import inf
from collections import OrderedDict


class UMLFactory:
"""
Expand All @@ -27,13 +29,14 @@ def generate(self, output_path):
continue
class_name = sbol.utils.parse_class_name(class_uri)
dot = graphviz.Digraph(class_name)
# dot.graph_attr['splines'] = 'ortho'
#dot.graph_attr['splines'] = 'ortho'

# Order matters here, as the label for an entity
# will depend on the last rendering method called
self._generate(class_uri, self.draw_abstraction_hierarchy, dot)
self._generate(class_uri, self.draw_class_definition, dot)
dot_source_sanitized = dot.source.replace('\\\\', '\\')
dot_source_sanitized = remove_duplicates(dot_source_sanitized)
source = graphviz.Source(dot_source_sanitized)
outfile = f'{class_name}_abstraction_hierarchy'
source.render(posixpath.join(output_path, outfile))
Expand Down Expand Up @@ -249,14 +252,14 @@ def create_association(dot_graph, subject_uri, object_uri, label):
subject_node = format_qname(subject_uri).replace(':', '_')
object_node = format_qname(object_uri).replace(':', '_')
association_relationship = {
'label' : None,
'xlabel' : None,
'arrowtail' : 'odiamond',
'arrowhead' : 'vee',
'fontname' : 'Bitstream Vera Sans',
'fontsize' : '8',
'dir' : 'both'
}
association_relationship['label'] = label
association_relationship['xlabel'] = label
dot_graph.edge(subject_node, object_node, **association_relationship)
qname = format_qname(object_uri)
label = '{' + qname + '|}'
Expand All @@ -266,14 +269,14 @@ def create_composition(dot_graph, subject_uri, object_uri, label):
subject_node = format_qname(subject_uri).replace(':', '_')
object_node = format_qname(object_uri).replace(':', '_')
composition_relationship = {
'label' : None,
'xlabel' : None,
'arrowtail' : 'diamond',
'arrowhead' : 'vee',
'fontname' : 'Bitstream Vera Sans',
'fontsize' : '8',
'dir' : 'both'
}
composition_relationship['label'] = label
composition_relationship['xlabel'] = label
dot_graph.edge(subject_node, object_node, **composition_relationship)
qname = format_qname(object_uri)
label = '{' + qname + '|}'
Expand All @@ -294,3 +297,10 @@ def create_inheritance(dot_graph, superclass_uri, subclass_uri):
label = '{' + qname + '|}'
create_uml_record(dot_graph, superclass_uri, label)

def remove_duplicates(dot_source):
d = OrderedDict()
entries = dot_source.split('\n')
for e in entries:
d[e] = None
dot_source = '\n'.join(list(d.keys()))
return dot_source

0 comments on commit b053858

Please sign in to comment.