Skip to content

Commit 3cd61e8

Browse files
committed
support lambdas for parent_configuration
1 parent d6ad1e7 commit 3cd61e8

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/yfiles_jupyter_graphs_for_neo4j/Yfiles_Neo4j_Graphs.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,26 +137,29 @@ def __configuration_mapper_factory(binding_key, configurations, default_mapping)
137137
def mapping(index, item: Dict):
138138
label = item["properties"]["label"] # yjg stores the neo4j node/relationship type in properties["label"]
139139
if label in configurations and binding_key in configurations.get(label):
140+
if binding_key == 'parent_configuration':
141+
# the binding may be a lambda that must be resolved first
142+
binding = configurations.get(label).get(binding_key)
143+
if callable(binding):
144+
binding = configurations.get(label).get(binding_key)(item)
145+
# parent_configuration binding may either resolve to a dict or a string
146+
if isinstance(binding, dict):
147+
group_label = binding.get('text', '')
148+
else:
149+
group_label = binding
150+
result = 'GroupNode' + group_label
140151
# mapping
141-
if callable(configurations.get(label)[binding_key]):
152+
elif callable(configurations.get(label)[binding_key]):
142153
result = configurations.get(label)[binding_key](item)
143154
# property name
144155
elif (not isinstance(configurations.get(label)[binding_key], dict) and
145156
configurations.get(label)[binding_key] in item["properties"]):
146157
result = item["properties"][configurations.get(label).get(binding_key)]
147-
# constant value or dictionary
148-
elif binding_key == 'parent_configuration':
149-
if isinstance(configurations.get(label).get(binding_key), dict):
150-
result = configurations.get(label).get(binding_key).get('text', '')
151-
else:
152-
result = configurations.get(label).get(binding_key)
153158
# constant value
154159
else:
155160
result = configurations.get(label).get(binding_key)
156-
if binding_key != 'parent_configuration':
157-
return result
158-
else:
159-
return 'GroupNode' + str(result)
161+
162+
return result
160163

161164
if binding_key == "label":
162165
return Neo4jGraphWidget.__get_neo4j_item_text(item)
@@ -183,6 +186,10 @@ def __create_group_nodes(self, configurations, widget):
183186
label = node['properties']['label']
184187
if label in configurations and key in configurations.get(label):
185188
group_node = configurations.get(label).get(key)
189+
190+
if callable(group_node):
191+
group_node = group_node(node)
192+
186193
if isinstance(group_node, str):
187194
# string or property value
188195
if group_node in node["properties"]:

0 commit comments

Comments
 (0)