Skip to content

Commit

Permalink
minor changes sugegsted by flake8 linter
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesscottbrown committed Dec 21, 2020
1 parent cb65690 commit 9530327
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 30 deletions.
3 changes: 2 additions & 1 deletion examples/demo-custom-properties-nodes-edges.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
All Custom Properties definitions should be populated into the 'Manage Custom Properties Menu'
To select Nodes & Edges based on Custom Properties open yEd 'Tools Menu' -> 'Select Elements' and define criteria in the 'Nodes' and 'Edges' tabs
To select Nodes & Edges based on Custom Properties open yEd 'Tools Menu' -> 'Select Elements' and define criteria in
the 'Nodes' and 'Edges' tabs
""")
print(40 * "=")
print("")
21 changes: 13 additions & 8 deletions examples/demo-url-description-groups-nodes-edges.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,26 @@
g = pyyed.Graph()

# Create GroupNode
italy = g.add_group("Italy", description="Italy, country of south-central Europe, occupying a peninsula that juts deep into the Mediterranean Sea.", url="https://en.wikipedia.org/wiki/Italy")
italy = g.add_group("Italy", description="Italy, country of south-central Europe, occupying a peninsula that juts deep into the Mediterranean Sea.",
url="https://en.wikipedia.org/wiki/Italy")

# Create Nodes
italy.add_node("Turin", description="Turin is the capital city of Piedmont in northern Italy, known for its refined architecture and cuisine.", url="http://www.comune.torino.it")
italy.add_node("Brescia", description="Brescia is a city in the northern Italian region of Lombardy.", url="https://www.comune.brescia.it/Pagine/default.aspx")
italy.add_node("Ivrea", description="Ivrea is a town and comune of the Metropolitan City of Turin in the Piedmont region of northwestern Italy.", url="https://www.comune.ivrea.to.it/")
italy.add_node("Savona", description="Savona is a port city in Liguria, northwest Italy.", url="https://www.comune.savona.it/it/")
italy.add_node("Turin", description="Turin is the capital city of Piedmont in northern Italy, known for its refined architecture and cuisine.",
url="http://www.comune.torino.it")
italy.add_node("Brescia", description="Brescia is a city in the northern Italian region of Lombardy.",
url="https://www.comune.brescia.it/Pagine/default.aspx")
italy.add_node("Ivrea", description="Ivrea is a town and comune of the Metropolitan City of Turin in the Piedmont region of northwestern Italy.",
url="https://www.comune.ivrea.to.it/")
italy.add_node("Savona", description="Savona is a port city in Liguria, northwest Italy.",
url="https://www.comune.savona.it/it/")

# Create Edges
italy.add_edge("Turin", "Brescia", label='E64', arrowhead="none",
description="Length 246 km (153 mi)", url="https://en.wikipedia.org/wiki/European_route_E64")
description="Length 246 km (153 mi)", url="https://en.wikipedia.org/wiki/European_route_E64")
italy.add_edge("Turin", "Ivrea", label='E612', arrowhead="none",
description="Length 54 km (34 mi)", url="https://en.wikipedia.org/wiki/European_route_E612")
description="Length 54 km (34 mi)", url="https://en.wikipedia.org/wiki/European_route_E612")
italy.add_edge("Turin", "Savona", label='E717', arrowhead="none",
description="Length 141 km (88 mi)", url="https://en.wikipedia.org/wiki/European_route_E717")
description="Length 141 km (88 mi)", url="https://en.wikipedia.org/wiki/European_route_E717")

# Write Graph
g.write_graph('demo-url-description-groups-nodes-edges.graphml', pretty_print=True)
Expand Down
2 changes: 0 additions & 2 deletions examples/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,3 @@
g.add_edge('foo', 'MY_Group')

print(g.get_graph())


25 changes: 11 additions & 14 deletions pyyed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ def __init__(self, scope, name, property_type, default_value):
self.property_type = property_type
self.default_value = default_value
self.id = "%s_%s" % (self.scope, self.name)

def convert(self):

custom_prop_key = ET.Element("key", id=self.id)
custom_prop_key.set("for", self.scope)
custom_prop_key.set("attr.name", self.name)
custom_prop_key.set("attr.type", self.property_type)

return custom_prop_key
return custom_prop_key


class Group:
Expand Down Expand Up @@ -218,9 +218,9 @@ def convert(self):


class Node:

custom_properties_defs = {}

def __init__(self, node_name, label=None, label_alignment="center", shape="rectangle", font_family="Dialog",
underlined_text="false", font_style="plain", font_size="12",
shape_fill="#FF0000", transparent="false", border_color="#000000",
Expand Down Expand Up @@ -327,12 +327,12 @@ def convert(self):
ET.SubElement(shape, "y:Shape", type=self.shape)

if self.UML:
UML = ET.SubElement(shape, "y:UML")
UML = ET.SubElement(shape, "y:UML")

attributes = ET.SubElement(UML, "y:AttributeLabel", type=self.shape)
attributes = ET.SubElement(UML, "y:AttributeLabel", type=self.shape)
attributes.text = self.UML["attributes"]

methods = ET.SubElement(UML, "y:MethodLabel", type=self.shape)
methods = ET.SubElement(UML, "y:MethodLabel", type=self.shape)
methods.text = self.UML["methods"]

stereotype = self.UML["stereotype"] if "stereotype" in self.UML else ""
Expand All @@ -352,14 +352,14 @@ def convert(self):
node_custom_prop.text = getattr(self, name)

return node

@classmethod
def set_custom_properties_defs(cls, custom_property):
cls.custom_properties_defs[custom_property.name] = custom_property


class Edge:

custom_properties_defs = {}

def __init__(self, node1, node2, label="", arrowhead="standard", arrowfoot="none",
Expand Down Expand Up @@ -475,7 +475,7 @@ def __init__(self, directed="directed", graph_id="G"):
self.existing_entities = {self.graph_id: self}

self.groups = {}

self.custom_properties = []

self.graphml = ""
Expand Down Expand Up @@ -521,7 +521,7 @@ def construct_graphml(self):
node_key.set("for", "edge")
node_key.set("attr.name", "description")
node_key.set("attr.type", "string")

# Definition: Custom Properties for Nodes and Edges
for prop in self.custom_properties:
graphml.append(prop.convert())
Expand Down Expand Up @@ -607,6 +607,3 @@ def define_custom_property(self, scope, name, property_type, default_value):
Node.set_custom_properties_defs(custom_property)
elif scope == "edge":
Edge.set_custom_properties_defs(custom_property)



2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
url='https://github.com/jamesscottbrown/pyyed',

packages=['pyyed'],

requires=[]
)
8 changes: 4 additions & 4 deletions tests/test_pyyed.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ def test_numeric_node_ids():

assert g.nodes[1].label == "Node1"
assert g.nodes[2].label == "Node2"

node1 = g.edges['1'].node1
node2 = g.edges['1'].node2

assert g.nodes[node1].label == "Node1"
assert g.nodes[node2].label == "Node2"

Expand All @@ -112,7 +112,7 @@ def test_multiple_edges():
g.add_node('a', font_family="Zapfino")
g.add_node('b', font_family="Zapfino")
g.add_node('c', font_family="Zapfino")

g.add_edge('a', 'b')
g.add_edge('a', 'b')
g.add_edge('a', 'c')
Expand All @@ -126,7 +126,7 @@ def test_multiple_edges():

assert g.nodes[e2.node1].label == "a"
assert g.nodes[e2.node2].label == "b"

assert g.nodes[e3.node1].label == "a"
assert g.nodes[e3.node2].label == "c"

Expand Down

0 comments on commit 9530327

Please sign in to comment.