yWorks / yfiles-jupyter-graphs

The home of the Jupyter notebook graph visualization widget powered by yFiles for HTML
https://www.yworks.com/products/yfiles-graphs-for-jupyter
Other
133 stars 14 forks source link

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

Closed yGuy closed 2 years ago

yGuy commented 2 years ago

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}}
    ]
  3. Show the widget using w.show()
  4. 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.