Skip to content
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

[Survey] Enable node-wide ranking in tree.show() #163

Open
caesar0301 opened this issue Jul 12, 2020 · 2 comments
Open

[Survey] Enable node-wide ranking in tree.show() #163

caesar0301 opened this issue Jul 12, 2020 · 2 comments

Comments

@caesar0301
Copy link
Owner

This is a proposed feature by Fahri Basegmez. I want to know if any others require this feature. I have a better implementation of a node ordering based on data property which could be customized by uses a lot.

Quoting the email:

I am using your treelib library and like it a lot. When I print a tree using tree.show() >sometimes I would like to control the way nodes are ordered. To be able to do that I modified >the source in a few places as shown below.

In node.py

Line 46
def init(self, tag=None, identifier=None, expanded=True, data=None, rank=0):

added the following line to Node. init ()
self.rank = rank

In tree.py

Line 214
if key is None:
def key(node):
return node.rank

Line 366
def create_node(self, tag=None, identifier=None, parent=None, data=None, rank=0):

Line 371 (in create_node()
node = self.node_class(tag=tag, identifier=identifier, data=data, rank=rank)

If a user never defines a rank then tree.show() behaves like it currently does. By adding ranks >to the desired nodes, print order of the nodes can be manipulated.

If you think this could be a useful modification please don't hesitate to use these changes.

Best regards,

Fahri Basegmez

P.S. print_rank or display_rank may be a better name than rank? Feel free to use whatever you >like.

In addition to these, a "use_rank = T/F" argument can be added to tree.show method.

@salman0149
Copy link

I feel this would be a good feature addition ,since i was also looking for a similar use case in which the nodes should be shown in the creation order rather than alphabeticaly.

@antipodite
Copy link

Yes, this would be a useful feature for my use case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants