Skip to content

Commit

Permalink
Update tour
Browse files Browse the repository at this point in the history
  • Loading branch information
mar10 committed Nov 1, 2024
1 parent 4a27fa5 commit 5c39c23
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 87 deletions.
98 changes: 52 additions & 46 deletions docs/jupyter/take_the_tour.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@
"output_type": "stream",
"text": [
"Tree<'Organization'>\n",
"├── <__main__.Department object at 0x107bd3cb0>\n",
"│ ├── <__main__.Department object at 0x1078ea0f0>\n",
"│ │ ╰── <__main__.Person object at 0x107902180>\n",
"│ ╰── <__main__.Person object at 0x1079015b0>\n",
"├── <__main__.Department object at 0x1078eb560>\n",
"│ ╰── <__main__.Person object at 0x109ab25a0>\n",
"╰── <__main__.Person object at 0x107900980>\n"
"├── <__main__.Department object at 0x109bbf6b0>\n",
"│ ├── <__main__.Department object at 0x1078baa50>\n",
"│ │ ╰── <__main__.Person object at 0x109cb23c0>\n",
"│ ╰── <__main__.Person object at 0x109cb2300>\n",
"├── <__main__.Department object at 0x1078b8f20>\n",
"│ ╰── <__main__.Person object at 0x109cb2060>\n",
"╰── <__main__.Person object at 0x109cb1f70>\n"
]
}
],
Expand Down Expand Up @@ -221,7 +221,7 @@
{
"data": {
"text/plain": [
"Node<'Person<Alice (25)>', data_id=276365464>"
"Node<'Person<Alice (25)>', data_id=278704631>"
]
},
"execution_count": 6,
Expand Down Expand Up @@ -267,9 +267,9 @@
{
"data": {
"text/plain": [
"[Node<'Person<Claire (45)>', data_id=276365848>,\n",
" Node<'Department<Marketing>', data_id=276360022>,\n",
" Node<'Person<Alice (25)>', data_id=276365464>]"
"[Node<'Person<Claire (45)>', data_id=278704700>,\n",
" Node<'Department<Marketing>', data_id=276347122>,\n",
" Node<'Person<Alice (25)>', data_id=278704631>]"
]
},
"execution_count": 8,
Expand Down Expand Up @@ -302,8 +302,8 @@
"output_type": "stream",
"text": [
"Tree<'Organization'>\n",
"╰── Node<'Department<Development>', data_id=571ace0b-1a49-44d4-ab52-97320e945d69>\n",
" ╰── Node<'Person<Bob (35)>', data_id=b4cbb694-a18d-420b-ad03-cda9fd0bf7f9>\n"
"╰── Node<'Department<Development>', data_id=8e6ae0d7-b268-4c9d-8da8-bdc5cdcb4f8d>\n",
" ╰── Node<'Person<Bob (35)>', data_id=ad20de1f-34c4-40cc-a102-51c28fb6ec5b>\n"
]
}
],
Expand All @@ -329,7 +329,7 @@
{
"data": {
"text/plain": [
"Node<'Person<Bob (35)>', data_id=b4cbb694-a18d-420b-ad03-cda9fd0bf7f9>"
"Node<'Person<Bob (35)>', data_id=ad20de1f-34c4-40cc-a102-51c28fb6ec5b>"
]
},
"execution_count": 10,
Expand Down Expand Up @@ -457,9 +457,9 @@
"output_type": "stream",
"text": [
"Tree<\"Copy of Tree<'Organization'>\">\n",
"├── Node<'Department<Development>', data_id=276550603>\n",
"│ ╰── Node<'Department<Test>', data_id=276359695>\n",
"╰── Node<'Department<Marketing>', data_id=276360022>\n"
"├── Node<'Department<Development>', data_id=278642539>\n",
"│ ╰── Node<'Department<Test>', data_id=276347557>\n",
"╰── Node<'Department<Marketing>', data_id=276347122>\n"
]
}
],
Expand All @@ -485,8 +485,8 @@
"output_type": "stream",
"text": [
"Tree<\"Copy of Tree<'Organization'>\">\n",
"├── Node<'Department<Development>', data_id=276550603>\n",
"╰── Node<'Department<Marketing>', data_id=276360022>\n"
"├── Node<'Department<Development>', data_id=278642539>\n",
"╰── Node<'Department<Marketing>', data_id=276347122>\n"
]
}
],
Expand Down Expand Up @@ -564,14 +564,14 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Node<'Department<Development>', data_id=276550603>\n",
"├── Node<'Department<Test>', data_id=276359695>\n",
"│ ╰── Node<'Person<Claire (45)>', data_id=276365848>\n",
"╰── Node<'Person<Alice (25)>', data_id=276365464>\n",
"Node<'Department<Marketing>', data_id=276360022>\n",
"├── Node<'Person<Dave (55)>', data_id=278573658>\n",
"╰── Node<'Person<Bob (35)>', data_id=276365659>\n",
"Node<'Person<Alice (25)>', data_id=276365464>\n"
"Node<'Department<Development>', data_id=278642539>\n",
"├── Node<'Department<Test>', data_id=276347557>\n",
"│ ╰── Node<'Person<Claire (45)>', data_id=278704700>\n",
"╰── Node<'Person<Alice (25)>', data_id=278704631>\n",
"Node<'Department<Marketing>', data_id=276347122>\n",
"├── Node<'Person<Dave (55)>', data_id=278704646>\n",
"╰── Node<'Person<Bob (35)>', data_id=278704688>\n",
"Node<'Person<Alice (25)>', data_id=278704631>\n"
]
}
],
Expand All @@ -588,8 +588,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Node<'Person<Alice (25)>', data_id=276365464>, parent=None\n",
"Node<'Person<Alice (25)>', data_id=276365464>, parent=Node<'Department<Development>', data_id=276550603>\n"
"Node<'Person<Alice (25)>', data_id=278704631>, parent=None\n",
"Node<'Person<Alice (25)>', data_id=278704631>, parent=Node<'Department<Development>', data_id=278642539>\n"
]
}
],
Expand Down Expand Up @@ -618,7 +618,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Tree<'4456612640'>\n",
"Tree<'4459280720'>\n",
"├── 'A'\n",
"│ ├── 'a1'\n",
"│ ╰── 'a2'\n",
Expand Down Expand Up @@ -658,11 +658,11 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Tree<'4457449184'>\n",
"├── Node<'A', data_id=-2140708064199008729>\n",
"│ ╰── Node<\"DictWrapper<{'title': 'foo', 'id': 1}>\", data_id=4421803904>\n",
"╰── Node<'B', data_id=-6374143811137841581>\n",
" ╰── Node<\"DictWrapper<{'title': 'foo', 'id': 1}>\", data_id=4421803904>\n"
"Tree<'4459281584'>\n",
"├── Node<'A', data_id=646631547239422124>\n",
"│ ╰── Node<\"DictWrapper<{'title': 'foo', 'id': 1}>\", data_id=4459448768>\n",
"╰── Node<'B', data_id=-8358617541791855429>\n",
" ╰── Node<\"DictWrapper<{'title': 'foo', 'id': 1}>\", data_id=4459448768>\n"
]
}
],
Expand All @@ -679,16 +679,6 @@
"# tree.find(d)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Serialization\n",
"\n",
"Read the user guide for different methods to save, load, or convert a tree\n",
"to different output formats."
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -709,7 +699,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"TypedTree<'4415355264'>\n",
"TypedTree<'4459281248'>\n",
"╰── friend → Mia\n",
" ├── brother → Noah\n",
" ╰── sister → Olivia\n"
Expand All @@ -726,6 +716,22 @@
"typed_tree.print()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Serialization\n",
"\n",
"Nutree supports save/load in a compact native JSON format as well as \n",
"ZIP, RDF, DOT, and mermaid. <br>\n",
"Even conversion to and SVG, PNG is possible:\n",
"\n",
"![example](../sphinx/test_mermaid_typed.png)\n",
"\n",
"Read the [User Guide](https://nutree.readthedocs.io/en/latest/ug_serialize.html) \n",
"for different methods to save, load, or convert a tree to different output formats."
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
88 changes: 47 additions & 41 deletions docs/sphinx/take_the_tour.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ tree.print()
```

Tree<'Organization'>
├── <__main__.Department object at 0x107bd3cb0>
│ ├── <__main__.Department object at 0x1078ea0f0>
│ │ ╰── <__main__.Person object at 0x107902180>
│ ╰── <__main__.Person object at 0x1079015b0>
├── <__main__.Department object at 0x1078eb560>
│ ╰── <__main__.Person object at 0x109ab25a0>
╰── <__main__.Person object at 0x107900980>
├── <__main__.Department object at 0x109bbf6b0>
│ ├── <__main__.Department object at 0x1078baa50>
│ │ ╰── <__main__.Person object at 0x109cb23c0>
│ ╰── <__main__.Person object at 0x109cb2300>
├── <__main__.Department object at 0x1078b8f20>
│ ╰── <__main__.Person object at 0x109cb2060>
╰── <__main__.Person object at 0x109cb1f70>


Tree nodes store a reference to the object in the `node.data` attribute.
Expand Down Expand Up @@ -134,7 +134,7 @@ tree[alice]



Node<'Person<Alice (25)>', data_id=276365464>
Node<'Person<Alice (25)>', data_id=278704631>



Expand All @@ -158,9 +158,9 @@ tree.find_all(match=lambda node: "i" in node.data.name)



[Node<'Person<Claire (45)>', data_id=276365848>,
Node<'Department<Marketing>', data_id=276360022>,
Node<'Person<Alice (25)>', data_id=276365464>]
[Node<'Person<Claire (45)>', data_id=278704700>,
Node<'Department<Marketing>', data_id=276347122>,
Node<'Person<Alice (25)>', data_id=278704631>]



Expand All @@ -179,8 +179,8 @@ tree_2.print(repr="{node}")
```

Tree<'Organization'>
╰── Node<'Department<Development>', data_id=571ace0b-1a49-44d4-ab52-97320e945d69>
╰── Node<'Person<Bob (35)>', data_id=b4cbb694-a18d-420b-ad03-cda9fd0bf7f9>
╰── Node<'Department<Development>', data_id=8e6ae0d7-b268-4c9d-8da8-bdc5cdcb4f8d>
╰── Node<'Person<Bob (35)>', data_id=ad20de1f-34c4-40cc-a102-51c28fb6ec5b>


now we could also search by the guid, for example
Expand All @@ -193,7 +193,7 @@ tree_2.find(data_id=str(bob.guid))



Node<'Person<Bob (35)>', data_id=b4cbb694-a18d-420b-ad03-cda9fd0bf7f9>
Node<'Person<Bob (35)>', data_id=ad20de1f-34c4-40cc-a102-51c28fb6ec5b>



Expand Down Expand Up @@ -258,9 +258,9 @@ tree_copy.print(repr="{node}")
```

Tree<"Copy of Tree<'Organization'>">
├── Node<'Department<Development>', data_id=276550603>
│ ╰── Node<'Department<Test>', data_id=276359695>
╰── Node<'Department<Marketing>', data_id=276360022>
├── Node<'Department<Development>', data_id=278642539>
│ ╰── Node<'Department<Test>', data_id=276347557>
╰── Node<'Department<Marketing>', data_id=276347122>


In-place filtering is also available:
Expand All @@ -272,8 +272,8 @@ tree_copy.print(repr="{node}")
```

Tree<"Copy of Tree<'Organization'>">
├── Node<'Department<Development>', data_id=276550603>
╰── Node<'Department<Marketing>', data_id=276360022>
├── Node<'Department<Development>', data_id=278642539>
╰── Node<'Department<Marketing>', data_id=276347122>


## Mutation
Expand Down Expand Up @@ -317,14 +317,14 @@ identical data_id:
tree.print(repr="{node}", title=False)
```

Node<'Department<Development>', data_id=276550603>
├── Node<'Department<Test>', data_id=276359695>
│ ╰── Node<'Person<Claire (45)>', data_id=276365848>
╰── Node<'Person<Alice (25)>', data_id=276365464>
Node<'Department<Marketing>', data_id=276360022>
├── Node<'Person<Dave (55)>', data_id=278573658>
╰── Node<'Person<Bob (35)>', data_id=276365659>
Node<'Person<Alice (25)>', data_id=276365464>
Node<'Department<Development>', data_id=278642539>
├── Node<'Department<Test>', data_id=276347557>
│ ╰── Node<'Person<Claire (45)>', data_id=278704700>
╰── Node<'Person<Alice (25)>', data_id=278704631>
Node<'Department<Marketing>', data_id=276347122>
├── Node<'Person<Dave (55)>', data_id=278704646>
╰── Node<'Person<Bob (35)>', data_id=278704688>
Node<'Person<Alice (25)>', data_id=278704631>



Expand All @@ -333,8 +333,8 @@ for clone in tree.find_all(alice):
print(f"{clone}, parent={clone.parent}")
```

Node<'Person<Alice (25)>', data_id=276365464>, parent=None
Node<'Person<Alice (25)>', data_id=276365464>, parent=Node<'Department<Development>', data_id=276550603>
Node<'Person<Alice (25)>', data_id=278704631>, parent=None
Node<'Person<Alice (25)>', data_id=278704631>, parent=Node<'Department<Development>', data_id=278642539>


## Special Data Types
Expand All @@ -353,7 +353,7 @@ tree_str.add("B")
tree_str.print()
```

Tree<'4456612640'>
Tree<'4459280720'>
├── 'A'
│ ├── 'a1'
│ ╰── 'a2'
Expand Down Expand Up @@ -383,18 +383,13 @@ tree.print(repr="{node}")
# tree.find(d)
```

Tree<'4457449184'>
├── Node<'A', data_id=-2140708064199008729>
│ ╰── Node<"DictWrapper<{'title': 'foo', 'id': 1}>", data_id=4421803904>
╰── Node<'B', data_id=-6374143811137841581>
╰── Node<"DictWrapper<{'title': 'foo', 'id': 1}>", data_id=4421803904>
Tree<'4459281584'>
├── Node<'A', data_id=646631547239422124>
│ ╰── Node<"DictWrapper<{'title': 'foo', 'id': 1}>", data_id=4459448768>
╰── Node<'B', data_id=-8358617541791855429>
╰── Node<"DictWrapper<{'title': 'foo', 'id': 1}>", data_id=4459448768>


## Serialization

Read the user guide for different methods to save, load, or convert a tree
to different output formats.

## Typed Trees

The `TypedTree` subclass adds a 'kind' attribute to the nodes, and related
Expand All @@ -412,12 +407,23 @@ typed_tree.add("Mia", kind="friend").add("Noah", kind="brother").up().add(
typed_tree.print()
```

TypedTree<'4415355264'>
TypedTree<'4459281248'>
╰── friend → Mia
├── brother → Noah
╰── sister → Olivia


## Serialization

Nutree supports save/load in a compact native JSON format as well as
ZIP, RDF, DOT, and mermaid. <br>
Even conversion to and SVG, PNG is possible:

![example](../sphinx/test_mermaid_typed.png)

Read the [User Guide](https://nutree.readthedocs.io/en/latest/ug_serialize.html)
for different methods to save, load, or convert a tree to different output formats.

# Typing

Nutree comes fully typed (passing [pyright](https://microsoft.github.io/pyright/#/)
Expand Down
4 changes: 4 additions & 0 deletions docs/sphinx/ug_serialize.rst
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,7 @@ Reading can then be implemnted using :meth:`~nutree.tree.Tree.from_dict()`::

.. seealso :: This example tree only contains plain string data.
Read :doc:`ug_objects` on how to (de)serialize arbitrary objects.
.. seealso :: Read :doc:`ug_graphs` on how to create graphical outputs
in PNG or SVG format.

0 comments on commit 5c39c23

Please sign in to comment.