keller-mark / spatialdata-vis-interop

0 stars 0 forks source link

`dump_plotting_tree` function #10

Closed keller-mark closed 1 week ago

keller-mark commented 1 week ago
def dump_plotting_tree(d):
    if isinstance(d, dict):
        expanded = dict()
        for k, v in d.items():
            if k.startswith("_"): # do we want this?
                continue
            try:
                json.dumps(v)
                expanded[k] = v
            except TypeError:
                try:
                    expanded[k] = dump_plotting_tree(v.__dict__)
                except AttributeError:
                    expanded[k] = repr(v)
        return expanded
    else:
        if isinstance(d, str):
            return d
        return repr(d)
keller-mark commented 1 week ago

Closing this, as we discussed that we do not need a JSON representation of the tree. We can just iterate over it and access things in the tree as-is