tree: add render_node arg to __print_backend - #227
Conversation
This let us do inversion of control[1], passing in a callback function
that gives more flexibility into how the node is rendered when using
show() and save2file().
**Example:**
```py
def render_node(node):
if node.level > 2:
return node.my_property
return node.some_other_property
tree.show(render_node=render_node)
```
[1]: https://en.wikipedia.org/wiki/Inversion_of_control
|
Just added some unit tests. |
|
I'd find this useful. I see this was created almost a year ago, any updates on getting this merged and released? |
Same to me, I will spend time to fix the conflicts first, and add more uts. |
Let me know if there's anything I can do to help :) Happy to rebase and fix conflicts |
|
This would indeed be very helpful, @rix1 can you rebase again. Maybe it gets merged this time 🤷 |
|
@rix1 just rebase and have the tests pass and it can be merged |
Fantastic! Thanks 🙏 What should we do about 1) the docs, and 1.5) if you agree on the deprecation of the now competing APIs, how do you want to do this? Just let me know if you want to increase the API surface or simplify by marking |
|
This looks good! Just a few quick requests and let's get this merged.
|
This let us do inversion of control, passing in a callback function that gives more flexibility into how the node is rendered when using
show()andsave2file(). Essentially replaces the need fordata_property- but we should probably keep it for backwards compatibility.The callback function right now expect a
stringto be returned. I was thinking on maybe supportingNonewhich could also replace the need for thefilterargument: ReturnNoneto avoid the Node to be rendered. Let me know what you think @liamlundy or @caesar0301 :)Example:
See unit test in 626f439 for an actual example.
Checklist
scripts/flake8.sh.show()API.