Skip to content

Commit

Permalink
added custom properties for groups (#45)
Browse files Browse the repository at this point in the history
Co-authored-by: Rosilde Corvino <[email protected]>
  • Loading branch information
rcorvino and Rosilde Corvino authored Oct 17, 2021
1 parent cd73108 commit e6264a8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions examples/demo-custom-properties-nodes-edges.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
g.define_custom_property("node", "Unemployment", "double", "0.0")
g.define_custom_property("node", "Environmental Engagements", "boolean", "false")
g.define_custom_property("node", "Mayor", "string", "")
g.define_custom_property("node", "Country", "string", "")

# Define Edge Custom Properties
'''
Expand All @@ -37,6 +38,10 @@
g.define_custom_property("edge", "Toll Free", "boolean", "true")
g.define_custom_property("edge", "Year of build", "string", "")

# Create Groups
g1 = g.add_group('group1',
custom_properties={"Country": "Kitchen"})

# Create Nodes
g.add_node('Pasta City',
custom_properties={"Population": "13000", "Unemployment": "13.7", "Environmental Engagements": "true",
Expand Down
21 changes: 20 additions & 1 deletion pyyed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def __init__(self, group_id, parent_graph, label=None, label_alignment="center",
closed="false", font_family="Dialog", underlined_text="false",
font_style="plain", font_size="12", fill="#FFCC00", transparent="false",
border_color="#000000", border_type="line", border_width="1.0", height=False,
width=False, x=False, y=False, description="", url=""):
width=False, x=False, y=False, custom_properties=None, description="", url=""):

self.label = label
if label is None:
Expand Down Expand Up @@ -217,6 +217,20 @@ def __init__(self, group_id, parent_graph, label=None, label_alignment="center",
self.description = description
self.url = url

# Handle Node Custom Properties
for name, definition in Node.custom_properties_defs.items():
if custom_properties:
for k, v in custom_properties.items():
if k not in Node.custom_properties_defs:
raise RuntimeWarning("key %s not recognised" % k)
if name == k:
setattr(self, name, custom_properties[k])
break
else:
setattr(self, name, definition.default_value)
else:
setattr(self, name, definition.default_value)

def add_node(self, node_name, **kwargs):
if node_name in self.parent_graph.existing_entities:
raise RuntimeWarning("Node %s already exists" % node_name)
Expand Down Expand Up @@ -315,6 +329,11 @@ def convert(self):
e = self.edges[edge_id].convert()
graph.append(e)

# Node Custom Properties
for name, definition in Node.custom_properties_defs.items():
node_custom_prop = ET.SubElement(node, "data", key=definition.id)
node_custom_prop.text = getattr(self, name)

return node
# ProxyAutoBoundsNode crap just draws bar at top of group

Expand Down

0 comments on commit e6264a8

Please sign in to comment.