yWorks/yfiles-jupyter-graphs

Do not require "properties" to be specified by default for nodes

Closed this issue · 0 comments

yGuy commented

Describe the bug
For simple cases, it should not be required to provide "properties" for nodes.

To Reproduce
Steps to reproduce the behavior:

  1. Start with the introduction sample
  2. Omit "properties" from one of the nodes:
w.nodes = [
    {"id": 0},
    {"id": "one", "properties": {"firstName": "Bravo", "label": "Person B"}},
    {"id": 2.0, "properties": {"firstName": "Charlie", "label": "Person C", "has_hat": False}},
    {"id": True, "properties": {"firstName": "Delta", "label": "Person D", "likes_pizza": True}}
]
  1. Show the widget using w.show()
  2. Observe the error
File /opt/conda/lib/python3.9/site-packages/yfiles_jupyter_graphs/widget.py:976, in GraphWidget.default_element_label_mapping(index, element)
    939 @staticmethod
    940 def default_element_label_mapping(index: int, element: TDict):
    941     """The default label mapping for graph elements.
    942 
    943     Element (dict) should have key properties which itself should be a dict.
   (...)
    974 
    975     """
--> 976     properties = element['properties']
    977     return str(properties.get('label', properties.get('yf_label', index)))

Expected behavior
This should be required by default. Some people have nodes without properties and it would still be useful.