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

More tips and tricks for custom classes #320

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.22.2] - 2024-11-11
### Added:
- Tree Export: Print tree to allow alias.
- Tree Export: Mermaid diagram to include theme.
### Fixed:
- Misc: Doctest for docstrings, docstring to indicate usage prefers `node_name` to `name`.
- Misc: Documentation to include tips and tricks on working with custom classes.
- Tree Export: Mermaid diagram title to add newline.
- Tree Helper: Get tree diff string replacement bug when the path change is substring of another path.

Expand Down Expand Up @@ -686,7 +689,8 @@ ignore null attribute columns.
- Utility Iterator: Tree traversal methods.
- Workflow To Do App: Tree use case with to-do list implementation.

[Unreleased]: https://github.com/kayjan/bigtree/compare/0.22.1...HEAD
[Unreleased]: https://github.com/kayjan/bigtree/compare/0.22.2...HEAD
[0.22.2]: https://github.com/kayjan/bigtree/compare/0.22.1...0.22.2
[0.22.1]: https://github.com/kayjan/bigtree/compare/0.22.0...0.22.1
[0.22.0]: https://github.com/kayjan/bigtree/compare/0.21.3...0.22.0
[0.21.3]: https://github.com/kayjan/bigtree/compare/0.21.2...0.21.3
Expand Down
2 changes: 1 addition & 1 deletion bigtree/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.22.1"
__version__ = "0.22.2"

from bigtree.binarytree.construct import list_to_binarytree
from bigtree.dag.construct import dataframe_to_dag, dict_to_dag, list_to_dag
Expand Down
37 changes: 37 additions & 0 deletions docs/others/work_with_classes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Working with Classes

Custom classes can be assigned to Node as `data` attribute, or any other attribute name.

```python
from bigtree import Node


class Folder:
def __init__(self, name: str):
self.name = name

def __str__(self):
return f"Folder<{self.name}>"

class File:
def __init__(self, name: str):
self.name = name

def __str__(self):
return f"File<{self.name}>"

folder_documents = Node("My Documents", data=Folder("Documents"))
file_photo1 = Node("photo1.jpg", data=File("photo.jpg"))
file_photo2 = Node("photo2.jpg", data=File("photo.jpg"))
folder_documents.children = [file_photo1, file_photo2]

folder_documents.show()
# My Documents
# ├── photo1.jpg
# └── photo2.jpg

folder_documents.show(alias="data")
# Folder<Documents>
# ├── File<photo.jpg>
# └── File<photo.jpg>
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ nav:
- others/nodes.md
- others/merging_trees.md
- others/weighted_trees.md
- others/work_with_classes.md

theme:
name: material
Expand Down
Loading