Skip to content

Commit d0dfa7c

Browse files
authored
Merge pull request #320 from kayjan/docs/more-tips
More tips and tricks for custom classes
2 parents 4e85c7a + f1dd40b commit d0dfa7c

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

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

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

689-
[Unreleased]: https://github.com/kayjan/bigtree/compare/0.22.1...HEAD
692+
[Unreleased]: https://github.com/kayjan/bigtree/compare/0.22.2...HEAD
693+
[0.22.2]: https://github.com/kayjan/bigtree/compare/0.22.1...0.22.2
690694
[0.22.1]: https://github.com/kayjan/bigtree/compare/0.22.0...0.22.1
691695
[0.22.0]: https://github.com/kayjan/bigtree/compare/0.21.3...0.22.0
692696
[0.21.3]: https://github.com/kayjan/bigtree/compare/0.21.2...0.21.3

bigtree/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.22.1"
1+
__version__ = "0.22.2"
22

33
from bigtree.binarytree.construct import list_to_binarytree
44
from bigtree.dag.construct import dataframe_to_dag, dict_to_dag, list_to_dag

docs/others/work_with_classes.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Working with Classes
2+
3+
Custom classes can be assigned to Node as `data` attribute, or any other attribute name.
4+
5+
```python
6+
from bigtree import Node
7+
8+
9+
class Folder:
10+
def __init__(self, name: str):
11+
self.name = name
12+
13+
def __str__(self):
14+
return f"Folder<{self.name}>"
15+
16+
class File:
17+
def __init__(self, name: str):
18+
self.name = name
19+
20+
def __str__(self):
21+
return f"File<{self.name}>"
22+
23+
folder_documents = Node("My Documents", data=Folder("Documents"))
24+
file_photo1 = Node("photo1.jpg", data=File("photo.jpg"))
25+
file_photo2 = Node("photo2.jpg", data=File("photo.jpg"))
26+
folder_documents.children = [file_photo1, file_photo2]
27+
28+
folder_documents.show()
29+
# My Documents
30+
# ├── photo1.jpg
31+
# └── photo2.jpg
32+
33+
folder_documents.show(alias="data")
34+
# Folder<Documents>
35+
# ├── File<photo.jpg>
36+
# └── File<photo.jpg>
37+
```

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ nav:
5959
- others/nodes.md
6060
- others/merging_trees.md
6161
- others/weighted_trees.md
62+
- others/work_with_classes.md
6263

6364
theme:
6465
name: material

0 commit comments

Comments
 (0)