diff --git a/docs/source/tutorials/cli_usage/graph_demo_1.demo.sh b/docs/source/tutorials/cli_usage/graph_demo_1.demo.sh new file mode 100644 index 0000000000000000000000000000000000000000..3509a48c3fcbdff388bdb41f0450405cba44c3f3 --- /dev/null +++ b/docs/source/tutorials/cli_usage/graph_demo_1.demo.sh @@ -0,0 +1 @@ +treevalue graph -t 'tree_demo.t1' -o 'only_t1.dat.svg' \ No newline at end of file diff --git a/docs/source/tutorials/cli_usage/graph_demo_2.demo.sh b/docs/source/tutorials/cli_usage/graph_demo_2.demo.sh new file mode 100644 index 0000000000000000000000000000000000000000..710798c2a3b3846046b4869f2209b27825b3adf2 --- /dev/null +++ b/docs/source/tutorials/cli_usage/graph_demo_2.demo.sh @@ -0,0 +1 @@ +treevalue graph -t 'tree_demo.*' -o 't1_t2_t3.dat.svg' \ No newline at end of file diff --git a/docs/source/tutorials/cli_usage/graph_demo_3.demo.sh b/docs/source/tutorials/cli_usage/graph_demo_3.demo.sh new file mode 100644 index 0000000000000000000000000000000000000000..9e705f2f7e184bb3c8de33dd96a00061639850e3 --- /dev/null +++ b/docs/source/tutorials/cli_usage/graph_demo_3.demo.sh @@ -0,0 +1 @@ +treevalue graph -t 'node_share_demo.*' -o 'shared_nodes.dat.svg' diff --git a/docs/source/tutorials/cli_usage/graph_demo_4.demo.sh b/docs/source/tutorials/cli_usage/graph_demo_4.demo.sh new file mode 100644 index 0000000000000000000000000000000000000000..aa1d02fb2fe9b993543e793645c6838c516bbf04 --- /dev/null +++ b/docs/source/tutorials/cli_usage/graph_demo_4.demo.sh @@ -0,0 +1,5 @@ +treevalue graph \ + -t 'node_share_demo.*' \ + -o 'shared_nodes_with_cfg.dat.svg' \ + -T 'Graph to Show the Shared Nodes' \ + -c 'bgcolor=#ffffff00' diff --git a/docs/source/tutorials/cli_usage/graph_demo_5.demo.sh b/docs/source/tutorials/cli_usage/graph_demo_5.demo.sh new file mode 100644 index 0000000000000000000000000000000000000000..6d42ebe4eedf461462731eb01a5d05bf22b4e6ba --- /dev/null +++ b/docs/source/tutorials/cli_usage/graph_demo_5.demo.sh @@ -0,0 +1,5 @@ +treevalue graph \ + -t 'node_share_demo.*' \ + -o 'shared_nodes.dat.png' \ + -T 'PNG Formatted Graph' \ + -c 'bgcolor=#ffffff00' diff --git a/docs/source/tutorials/cli_usage/graph_demo_6.demo.sh b/docs/source/tutorials/cli_usage/graph_demo_6.demo.sh new file mode 100644 index 0000000000000000000000000000000000000000..059328cce6fd15e308e558ff0f4297fd724328c5 --- /dev/null +++ b/docs/source/tutorials/cli_usage/graph_demo_6.demo.sh @@ -0,0 +1,5 @@ +treevalue graph \ + -t 'node_share_demo.*' \ + -o 'shared_nodes.dat.gv' \ + -T 'PNG Formatted Graph' \ + -c 'bgcolor=#ffffff00' diff --git a/docs/source/tutorials/cli_usage/graph_demo_7.demo.sh b/docs/source/tutorials/cli_usage/graph_demo_7.demo.sh new file mode 100644 index 0000000000000000000000000000000000000000..bf30c896fb8795af47a3e56e94f44a2bf4d57102 --- /dev/null +++ b/docs/source/tutorials/cli_usage/graph_demo_7.demo.sh @@ -0,0 +1,5 @@ +treevalue graph \ + -t 'node_share_demo.*' \ + -O \ + -T 'PNG Formatted Graph' \ + -c 'bgcolor=#ffffff00' diff --git a/docs/source/tutorials/cli_usage/index.rst b/docs/source/tutorials/cli_usage/index.rst index dcdd29d90da9de349c5f643414321f01891d56ca..e4d19d0cc850f193afcff022ec724e55f2b5122f 100644 --- a/docs/source/tutorials/cli_usage/index.rst +++ b/docs/source/tutorials/cli_usage/index.rst @@ -1,4 +1,4 @@ -Cli Usage +CLI Usage ====================== From treevalue version ``0.1.0``, simple CLI (Command \ @@ -219,4 +219,129 @@ binary trees can be imported and then drawn to graphs. * API Documentation of :ref:`apidoc_tree_tree_loads`. * API Documentation of :ref:`apidoc_tree_tree_graphics`. +Draw One Graph For One Tree +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Before drawing the first graph, we prepare the ``tree_demo.py`` \ +mentioned in :ref:`cli_usage_export`. + +.. literalinclude:: tree_demo.py + :language: python + :linenos: + +We can draw the graph of ``t1`` with the following command + +.. literalinclude:: graph_demo_1.demo.sh + :language: shell + :linenos: + +The dumped graph ``only_t1.dat.svg`` should be like this + +.. image:: only_t1.dat.svg + :align: center + + +Draw One Graph For Multiple Trees +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Actually we can put several trees into one graph, just like \ +the following command + +.. literalinclude:: graph_demo_2.demo.sh + :language: shell + :linenos: + +The dumped graph ``t1_t2_t3.dat.svg`` should contains 3 trees, \ +like this + +.. image:: t1_t2_t3.dat.svg + :align: center + +Sometime, the trees will share some common nodes (with the same \ +``Tree`` object id), this relation will also be displayed in \ +graph. In another python script ``node_share_demo.py`` + +.. literalinclude:: node_share_demo.py + :language: python + :linenos: + +The dumped graph ``shared_nodes.dat.svg`` should be like + +.. image:: shared_nodes.dat.svg + :align: center + +The arrow from ``nt3`` named ``first`` is pointed to ``nt1``, \ +the arrow named ``another`` is pointed to ``nt1.x``, and so on. + + +Graph with Configurations +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Sometime we need to assign the title of the dumped graph, \ +or you may think that the white background look prominent in \ +the grey page background. So you can dump the graph like this + +.. literalinclude:: graph_demo_4.demo.sh + :language: shell + :linenos: + +The dumped graph ``shared_nodes_with_cfg.dat.svg`` should be \ +like this + +.. image:: shared_nodes_with_cfg.dat.svg + :align: center + +We can see the title and the background color is changed \ +because of the ``-T`` and ``-c`` command. The transparent \ +background looks better than the ``shared_nodes.dat.svg`` \ +in the grey page background. + + +Graph of Different Formats +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +If you do not need svg format, you can dump it to png format \ +like this + +.. literalinclude:: graph_demo_5.demo.sh + :language: python + :linenos: + +The dumped graph ``shared_nodes.dat.png`` should be like this, \ +its format is ``png``. + +.. image:: shared_nodes.dat.png + :align: center + +Besides, if the graphviz code (``gv`` format) is just all \ +what you need, you can dump the ``gv`` source code with the \ +following command line. + +.. literalinclude:: graph_demo_6.demo.sh + :language: python + :linenos: + +The dumped source code ``shared_nodes.dat.gv`` should be like \ +this + +.. literalinclude:: shared_nodes.dat.gv + :language: graphviz + :linenos: + +Or if you need to put it to the ``stdout``, you can do like this + +.. literalinclude:: graph_demo_7.demo.sh + :language: python + :linenos: + +The output in ``stdout`` should almost the same like the \ +source code file ``shared_nodes.dat.gv``. + +.. note:: + When ``-O`` option is used, the ``-o`` will be ignored. + +Reuse the Value Nodes +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + diff --git a/docs/source/tutorials/cli_usage/node_share_demo.py b/docs/source/tutorials/cli_usage/node_share_demo.py new file mode 100644 index 0000000000000000000000000000000000000000..7b5836bc14183ee321f38911ff86d14de5f4242f --- /dev/null +++ b/docs/source/tutorials/cli_usage/node_share_demo.py @@ -0,0 +1,10 @@ +from treevalue import FastTreeValue + +nt1 = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) +nt2 = FastTreeValue({'a': 11, 'b': 24, 'x': {'c': 30, 'd': 47}}) +nt3 = FastTreeValue({ + 'first': nt1, + 'second': nt2, + 'another': nt1.x, + 'sum': nt1 + nt2, +})