-
Notifications
You must be signed in to change notification settings - Fork 174
Implement svg output in notebooks #29 #30
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
|
@joowani Currently the 2.7 and 3.5 tests fails because the code is using f-strings that were added in python 3.5. https://docs.python.org/3/reference/lexical_analysis.html#f-strings Do you to maintain compatibility with these python versions even if they have reached their end-of-life: |
|
Hi @benabel, Thanks for the PR! Yes I am planning to drop support for those two, and I'm also planning to switch over to github actions etc as well. I'll keep this open and re-evaluate after. |
|
Instead of implementing this method from scratch, I've decided to use python-graphviz instead (it has many more features including Jupyter notebook support) in version 6.0.0. Please see the documentation for more details. |
|
@joowani using phython-graphviz adds dependecies on python side and on system side with the graphviz binary. For users like teachers that don't have any rights on a machine this feature will be unavailable. You could use a try except and fallback to my implementation if graphviz isn't available on the system. |
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.
Awesome PR!
binarytree/__init__.py
Outdated
| """Return the svg representation on current node. | ||
| :return: String representation. | ||
| :rtype: str | unicode |
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.
This can just be str now.
binarytree/layout.py
Outdated
|
|
||
|
|
||
| def _get_coords(values): | ||
| """Generate nodes and edges relative coordinates lists |
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.
Please change to Generate the coordinates used for rendering the nodes and edges.
tests/test_layout.py
Outdated
| @@ -0,0 +1,19 @@ | |||
| from __future__ import absolute_import, unicode_literals | |||
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.
This can be removed.
binarytree/layout.py
Outdated
| """ Module containing layout related algorithms.""" | ||
|
|
||
|
|
||
| def _get_coords(values): |
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.
Since you are importing this outside of the module, should be renamed to get_coords.
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.
This is only used on layout module and test.
|
Hi @benabel, I like your idea. I've reopened the PR and left some comments. Could you please address them and rebase? Thanks again for your contribution. |
1a32744 to
a2fd4ec
Compare
|
@joowani I tried to amend the code using your suggestions, however I can't pass the doctests. |
|
@joowani In fact the doctests fails due to the graphviz doesn't seem to be installed in 2 Errors in task Run Sphinx doctest: |
|
Hi @benabel, No worries, I can take care of the clean up. Thanks again for your contribution! This is very useful. |
|
You're welcome @joowani. Thanks for sharing this package. |
This implementation use a simple algorithm in which the layout used is
based on a perfect tree of same height in which all leaves would be
regularly spaced.
This approach is ok for little trees to about 4 levels but for larger trees
with holes a better approach would be to implement the Reingold &
Tilford’s algorithm.