Skip to content

Commit

Permalink
Merge pull request #34 from pyiron/consistent_order
Browse files Browse the repository at this point in the history
Render stuff in alphabetical order by default
  • Loading branch information
liamhuber authored Jan 11, 2024
2 parents f27223a + 43e5716 commit dd90bea
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pyiron_ontology/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
A tree structure for ontologically-informed workflows
"""

from numpy import argsort


class NodeTree:
def __init__(self, value, parent=None):
Expand All @@ -14,8 +16,13 @@ def __init__(self, value, parent=None):
if parent is not None:
parent.children.append(self)

def render(self, depth=0):
def render(self, depth=0, order_alphabetically=True):
tabs = "".join(["\t"] * depth)
print(f"{tabs}{self.value.name}")
for child in self.children:
children = (
[self.children[n] for n in argsort([str(c.value) for c in self.children])]
if order_alphabetically
else self.children
)
for child in children:
child.render(depth=depth + 1)

0 comments on commit dd90bea

Please sign in to comment.