-
-
Notifications
You must be signed in to change notification settings - Fork 125
Adding a Tree class for constructing trees in Cytoscape #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Wow great <3 . Quick question: how does it benefit having a tree structure when defining methods such as get_nodes(), get_edge() etc? |
|
@vivekvs1 The [{'data': {'id': 'a'}},
{'data': {'id': 'b'}},
{'data': {'id': 'c'}},
{'data': {'id': 'd'}}]Which would be useful if you want to temporarily modify the data field (e.g. add a different label depending on the input of the callback), but don't want to affect the Tree structure. Overall, a |
|
Oh I see. Very nice! Thanks @xhlulu |
shammamah-zz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay for using things we learn in our CS degrees! 🎉
xhluca
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the helpful review!
| Add a list of children to the current children of a Tree | ||
| :param children: List of Tree objects | ||
| """ | ||
| self.children.extend(children) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may want to assert len(children) > 1.
Is add_child a special case of add_children, which would still work when len(children) == 1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Add child is a special case of add_children. Sometimes the programmer might not know in advance how many children the tree might have (when it's decided programmatically). So they might just use add_children() with a list all the time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xhlulu Then I would recommend removing method add_child and keep only method add_children (so there's one way to add children, however many they end up being).
|
Thank you @mkcor for you reviews! |
|
💃 |
About
Ok so this one is a more experimental PR, and the last one before 0.1.0 release (which will be a separate PR, but should be quick to review).
I've thought about this for a while and it seems to be pretty useful to have a
Treeclass that can be easily constructed as a nested object, then rendered into an element. For example,running
tree.get_elements()would result in:[{'data': {'id': 'a'}}, {'data': {'id': 'b'}}, {'data': {'id': 'c'}}, {'data': {'id': 'd'}}, {'data': {'source': 'a', 'target': 'b'}}, {'data': {'source': 'a', 'target': 'd'}}, {'data': {'source': 'b', 'target': 'c'}}]With a tree class, we can use useful methods to manipulate it, such as:
get_nodes(),get_edges(): When we only want to access one type of elements from the treefind_by_id(): Using a tree traversal, retrieve a specific object in a subtreecreate_index(): Create a dictionary to easily retrieve a node in the subtree by its idAs well as more that I didn't think of.
My thought behind creating a prototype Tree class is to have a customized data structure for easily interacting with Cytoscape, which in the long term might be more appropriate than extending a tree library. For example, we can easily assign an ID to a node directly. However, there are excellent Tree libraries out there (treelib @ 357 stars seems pretty solid), writing a wrapper would indeed be possible if everyone thinks it's a good idea. In this case, there's no need to merge this class (will close this PR instead).
Please let me know your thoughts in whether we should create this class or not. Thanks!
Description of changes
dash_cytoscape.utils.Tree: New Tree objectdemos/usage-dag-edges.py: Example using the treePre-Merge checklist
npm run build:all.Reference Issues
Closes #[issue number]
Other comments