parrt / lolviz

A simple Python data-structure visualization tool for lists of lists, lists, dictionaries; primarily for use in Jupyter notebooks / presentations
BSD 3-Clause "New" or "Revised" License
829 stars 47 forks source link

implement multi child tree #28

Open sunyiwei24601 opened 2 years ago

sunyiwei24601 commented 2 years ago

Hi, I was looking for a package to visualize Tree Search Algorithm Recently and I found this repository and really liked it. But for tree visualization, the treeviz function can only support binary tree with child name left and right.

So I made some modification to support multi children and specifying child name. I add 2 new parameters for treeviz(), childfields and show_all_children. The variable name in childfields will be recognized as child node. And if show_all_children=False, it will only visualize the child names exist, else it will show all the names in childfieds.

I know you may be busy and this repository hasn't been updated for a long time. You can check these modification anytime free. I am so glad to receive any suggestions from you.

parrt commented 2 years ago

interesting...let me try it on a bunch of existing stuff.

parrt commented 2 years ago

Hiya. What about trees with children fields, which I think is more common than left, mid, right or whatever?

sunyiwei24601 commented 2 years ago

Hiya. What about trees with children fields, which I think is more common than left, mid, right or whatever?

Yes, I did consider such implementation before. If I didn't misunderstand you, you mean such a structure of trees:

class Tree:
    def __init__(self, **children):
        self.children = children

My current implementation can not handle such situations. I would like to add a new parameter for treeviz() function called dict_children_fields=("children"). For a field in this tuple (if its type is dictionary), we will recognize every key of this dict as a child which need to be visualized. But the treeviz function may be too complicated due to too many specified parameters. If you have other plans, I'm glad to hear them.

sunyiwei24601 commented 2 years ago

@parrt Hi, I just push my new implementation. You can check it out while free. To visualize trees with children fields, I create a new function treeplusviz(maybe it's not a good name haha), which will regard each in children field as a child of parent tree node.

parrt commented 2 years ago

Hi sorry for delay. I just started a new job and will be in a bootcamp for a couple of weeks!