From 5c39c235268d0c7b992d8a12290321d659a9e2ce Mon Sep 17 00:00:00 2001 From: Martin Wendt Date: Fri, 1 Nov 2024 13:12:41 +0100 Subject: [PATCH] Update tour --- docs/jupyter/take_the_tour.ipynb | 98 +++++++++++++++++--------------- docs/sphinx/take_the_tour.md | 88 +++++++++++++++------------- docs/sphinx/ug_serialize.rst | 4 ++ 3 files changed, 103 insertions(+), 87 deletions(-) diff --git a/docs/jupyter/take_the_tour.ipynb b/docs/jupyter/take_the_tour.ipynb index 31df4b8..76032a3 100644 --- a/docs/jupyter/take_the_tour.ipynb +++ b/docs/jupyter/take_the_tour.ipynb @@ -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" ] } ], @@ -221,7 +221,7 @@ { "data": { "text/plain": [ - "Node<'Person', data_id=276365464>" + "Node<'Person', data_id=278704631>" ] }, "execution_count": 6, @@ -267,9 +267,9 @@ { "data": { "text/plain": [ - "[Node<'Person', data_id=276365848>,\n", - " Node<'Department', data_id=276360022>,\n", - " Node<'Person', data_id=276365464>]" + "[Node<'Person', data_id=278704700>,\n", + " Node<'Department', data_id=276347122>,\n", + " Node<'Person', data_id=278704631>]" ] }, "execution_count": 8, @@ -302,8 +302,8 @@ "output_type": "stream", "text": [ "Tree<'Organization'>\n", - "╰── Node<'Department', data_id=571ace0b-1a49-44d4-ab52-97320e945d69>\n", - " ╰── Node<'Person', data_id=b4cbb694-a18d-420b-ad03-cda9fd0bf7f9>\n" + "╰── Node<'Department', data_id=8e6ae0d7-b268-4c9d-8da8-bdc5cdcb4f8d>\n", + " ╰── Node<'Person', data_id=ad20de1f-34c4-40cc-a102-51c28fb6ec5b>\n" ] } ], @@ -329,7 +329,7 @@ { "data": { "text/plain": [ - "Node<'Person', data_id=b4cbb694-a18d-420b-ad03-cda9fd0bf7f9>" + "Node<'Person', data_id=ad20de1f-34c4-40cc-a102-51c28fb6ec5b>" ] }, "execution_count": 10, @@ -457,9 +457,9 @@ "output_type": "stream", "text": [ "Tree<\"Copy of Tree<'Organization'>\">\n", - "├── Node<'Department', data_id=276550603>\n", - "│ ╰── Node<'Department', data_id=276359695>\n", - "╰── Node<'Department', data_id=276360022>\n" + "├── Node<'Department', data_id=278642539>\n", + "│ ╰── Node<'Department', data_id=276347557>\n", + "╰── Node<'Department', data_id=276347122>\n" ] } ], @@ -485,8 +485,8 @@ "output_type": "stream", "text": [ "Tree<\"Copy of Tree<'Organization'>\">\n", - "├── Node<'Department', data_id=276550603>\n", - "╰── Node<'Department', data_id=276360022>\n" + "├── Node<'Department', data_id=278642539>\n", + "╰── Node<'Department', data_id=276347122>\n" ] } ], @@ -564,14 +564,14 @@ "name": "stdout", "output_type": "stream", "text": [ - "Node<'Department', data_id=276550603>\n", - "├── Node<'Department', data_id=276359695>\n", - "│ ╰── Node<'Person', data_id=276365848>\n", - "╰── Node<'Person', data_id=276365464>\n", - "Node<'Department', data_id=276360022>\n", - "├── Node<'Person', data_id=278573658>\n", - "╰── Node<'Person', data_id=276365659>\n", - "Node<'Person', data_id=276365464>\n" + "Node<'Department', data_id=278642539>\n", + "├── Node<'Department', data_id=276347557>\n", + "│ ╰── Node<'Person', data_id=278704700>\n", + "╰── Node<'Person', data_id=278704631>\n", + "Node<'Department', data_id=276347122>\n", + "├── Node<'Person', data_id=278704646>\n", + "╰── Node<'Person', data_id=278704688>\n", + "Node<'Person', data_id=278704631>\n" ] } ], @@ -588,8 +588,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "Node<'Person', data_id=276365464>, parent=None\n", - "Node<'Person', data_id=276365464>, parent=Node<'Department', data_id=276550603>\n" + "Node<'Person', data_id=278704631>, parent=None\n", + "Node<'Person', data_id=278704631>, parent=Node<'Department', data_id=278642539>\n" ] } ], @@ -618,7 +618,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Tree<'4456612640'>\n", + "Tree<'4459280720'>\n", "├── 'A'\n", "│ ├── 'a1'\n", "│ ╰── 'a2'\n", @@ -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" ] } ], @@ -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": {}, @@ -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" @@ -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.
\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": {}, diff --git a/docs/sphinx/take_the_tour.md b/docs/sphinx/take_the_tour.md index 0dba23b..0c9cea4 100644 --- a/docs/sphinx/take_the_tour.md +++ b/docs/sphinx/take_the_tour.md @@ -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. @@ -134,7 +134,7 @@ tree[alice] - Node<'Person', data_id=276365464> + Node<'Person', data_id=278704631> @@ -158,9 +158,9 @@ tree.find_all(match=lambda node: "i" in node.data.name) - [Node<'Person', data_id=276365848>, - Node<'Department', data_id=276360022>, - Node<'Person', data_id=276365464>] + [Node<'Person', data_id=278704700>, + Node<'Department', data_id=276347122>, + Node<'Person', data_id=278704631>] @@ -179,8 +179,8 @@ tree_2.print(repr="{node}") ``` Tree<'Organization'> - ╰── Node<'Department', data_id=571ace0b-1a49-44d4-ab52-97320e945d69> - ╰── Node<'Person', data_id=b4cbb694-a18d-420b-ad03-cda9fd0bf7f9> + ╰── Node<'Department', data_id=8e6ae0d7-b268-4c9d-8da8-bdc5cdcb4f8d> + ╰── Node<'Person', data_id=ad20de1f-34c4-40cc-a102-51c28fb6ec5b> now we could also search by the guid, for example @@ -193,7 +193,7 @@ tree_2.find(data_id=str(bob.guid)) - Node<'Person', data_id=b4cbb694-a18d-420b-ad03-cda9fd0bf7f9> + Node<'Person', data_id=ad20de1f-34c4-40cc-a102-51c28fb6ec5b> @@ -258,9 +258,9 @@ tree_copy.print(repr="{node}") ``` Tree<"Copy of Tree<'Organization'>"> - ├── Node<'Department', data_id=276550603> - │ ╰── Node<'Department', data_id=276359695> - ╰── Node<'Department', data_id=276360022> + ├── Node<'Department', data_id=278642539> + │ ╰── Node<'Department', data_id=276347557> + ╰── Node<'Department', data_id=276347122> In-place filtering is also available: @@ -272,8 +272,8 @@ tree_copy.print(repr="{node}") ``` Tree<"Copy of Tree<'Organization'>"> - ├── Node<'Department', data_id=276550603> - ╰── Node<'Department', data_id=276360022> + ├── Node<'Department', data_id=278642539> + ╰── Node<'Department', data_id=276347122> ## Mutation @@ -317,14 +317,14 @@ identical data_id: tree.print(repr="{node}", title=False) ``` - Node<'Department', data_id=276550603> - ├── Node<'Department', data_id=276359695> - │ ╰── Node<'Person', data_id=276365848> - ╰── Node<'Person', data_id=276365464> - Node<'Department', data_id=276360022> - ├── Node<'Person', data_id=278573658> - ╰── Node<'Person', data_id=276365659> - Node<'Person', data_id=276365464> + Node<'Department', data_id=278642539> + ├── Node<'Department', data_id=276347557> + │ ╰── Node<'Person', data_id=278704700> + ╰── Node<'Person', data_id=278704631> + Node<'Department', data_id=276347122> + ├── Node<'Person', data_id=278704646> + ╰── Node<'Person', data_id=278704688> + Node<'Person', data_id=278704631> @@ -333,8 +333,8 @@ for clone in tree.find_all(alice): print(f"{clone}, parent={clone.parent}") ``` - Node<'Person', data_id=276365464>, parent=None - Node<'Person', data_id=276365464>, parent=Node<'Department', data_id=276550603> + Node<'Person', data_id=278704631>, parent=None + Node<'Person', data_id=278704631>, parent=Node<'Department', data_id=278642539> ## Special Data Types @@ -353,7 +353,7 @@ tree_str.add("B") tree_str.print() ``` - Tree<'4456612640'> + Tree<'4459280720'> ├── 'A' │ ├── 'a1' │ ╰── 'a2' @@ -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 @@ -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.
+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/#/) diff --git a/docs/sphinx/ug_serialize.rst b/docs/sphinx/ug_serialize.rst index 16acad3..022392d 100644 --- a/docs/sphinx/ug_serialize.rst +++ b/docs/sphinx/ug_serialize.rst @@ -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.